/* ========== Global Reset & Variables ========== */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #161822;
    --bg-card: #1c1f2e;
    --bg-hover: #252840;
    --bg-sidebar: #13151f;
    --border: #2a2d3e;
    --border-light: #353850;
    --text-primary: #e4e6f0;
    --text-secondary: #8b8fa3;
    --text-dim: #5c6078;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.08);
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 24px rgba(0,0,0,0.25);
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
}

/* ========== Layout ========== */
.app {
    display: flex;
    height: 100vh;
}

/* ========== Sidebar ========== */
.sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow-y: auto;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.logo {
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--border);
}

.logo-icon {
    font-size: 28px;
    margin-bottom: 4px;
}

.logo h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-sub {
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 400;
}

/* ========== Filter Sections ========== */
.filter-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.filter-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.date-group {
    margin-bottom: 10px;
}

.date-group label {
    display: block;
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 4px;
    font-weight: 500;
}

.input-field {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    transition: var(--transition);
}

.input-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Quick date buttons */
.quick-dates {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 6px;
    margin-top: 10px;
}

.quick-btn {
    padding: 6px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
}

.quick-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.quick-btn.active {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent-hover);
}

/* Group list */
.group-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 10px;
}

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 12px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    transition: var(--transition);
}

.link-btn:hover {
    color: var(--accent-hover);
}

.group-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.group-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.group-item:hover {
    background: var(--bg-hover);
}

.group-item input[type="checkbox"] {
    appearance: none;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-light);
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
    flex-shrink: 0;
}

.group-item input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.group-item input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: -1px;
    left: 2px;
    font-size: 11px;
    color: white;
    font-weight: 700;
}

.group-item label {
    font-size: 13px;
    cursor: pointer;
    flex: 1;
    color: var(--text-primary);
}

.group-item .group-id {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 500;
}

.loading-mini {
    text-align: center;
    padding: 20px;
    color: var(--text-dim);
    font-size: 13px;
}

/* Query button */
.query-btn {
    margin: 16px 20px 20px;
    padding: 12px;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    border: none;
    border-radius: var(--radius);
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: 'Inter', sans-serif;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.query-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.query-btn:active {
    transform: translateY(0);
}

.query-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ========== Main Content ========== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-bar {
    padding: 14px 28px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
}

.status-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: var(--accent-glow);
    color: var(--accent-hover);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.status-badge.querying {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
    border-color: rgba(245, 158, 11, 0.2);
    animation: pulse 1.5s ease-in-out infinite;
}

.status-badge.done {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
    border-color: rgba(34, 197, 94, 0.2);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.status-text {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ========== Stats Row ========== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 20px 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    text-align: center;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent-hover);
    line-height: 1.2;
}

.stat-warning .stat-value { color: var(--warning); }
.stat-danger .stat-value { color: var(--danger); }

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}

/* ========== Content Area ========== */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 0 28px 28px;
}

.content-area::-webkit-scrollbar {
    width: 6px;
}

.content-area::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60vh;
    color: var(--text-dim);
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.empty-state p {
    font-size: 14px;
}

/* Loading state */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60vh;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-sub {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 4px;
}

/* ========== Section Card ========== */
.section-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 20px;
    overflow: hidden;
}

.section-title {
    font-size: 15px;
    font-weight: 600;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

/* ========== Data Table ========== */
.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    padding: 10px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    background: rgba(0,0,0,0.15);
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 12px 16px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr {
    transition: var(--transition);
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-success {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
}

.detail-btn {
    padding: 5px 14px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--accent);
    font-size: 12px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    transition: var(--transition);
}

.detail-btn:hover {
    background: var(--accent);
    color: white;
}

.detail-btn.active {
    background: var(--accent);
    color: white;
}

/* ========== Detail Card ========== */
.detail-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 16px;
    overflow: hidden;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,0.1);
}

.detail-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.detail-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 18px;
    cursor: pointer;
    transition: var(--transition);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.detail-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.detail-table th {
    position: sticky;
    top: 0;
    z-index: 1;
}

/* No data message */
.no-alarm {
    padding: 40px;
    text-align: center;
    color: var(--text-dim);
    font-size: 14px;
}

.no-alarm .no-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .sidebar {
        width: 260px;
        min-width: 260px;
    }

    .stats-row {
        grid-template-columns: 1fr;
        padding: 16px;
    }
}

/* ========== Settings Link ========== */
.settings-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0 20px 20px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: var(--transition);
    font-family: 'Inter', sans-serif;
}

.settings-link:hover {
    border-color: var(--accent);
    color: var(--accent-hover);
    background: var(--accent-glow);
}

/* ========== Settings Page ========== */
.settings-nav {
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    gap: 4px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    font-family: 'Inter', sans-serif;
    transition: var(--transition);
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-glow);
    color: var(--accent-hover);
    border-left: 3px solid var(--accent);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.settings-form {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-row label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-row .hint {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.section-title .hint {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 400;
    margin-left: 8px;
}

.save-area {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 20px;
}

.save-btn {
    padding: 10px 32px;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    border: none;
    border-radius: var(--radius);
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.save-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.save-status {
    font-size: 13px;
    color: var(--success);
    font-weight: 500;
}

.rule-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.rule-text {
    font-size: 13px;
    color: var(--text-primary);
    font-family: monospace;
}

.rule-del {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: var(--transition);
}

.rule-del:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}
