/* ========== DESIGN TOKENS ========== */
:root {
    --font: 'Inter', -apple-system, sans-serif;
    --grid: 8px;
    --radius-s: 6px;
    --radius-m: 10px;
    --radius-l: 14px;
    --transition: 0.15s ease;
}

/* Light theme */
[data-theme="light"] {
    --bg-primary: #FFFFFF;
    --bg-secondary: #F4F5F7;
    --bg-tertiary: #E8EAED;
    --bg-input: #FFFFFF;
    --border: #D1D5DB;
    --border-focus: #2563EB;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;
    --accent: #2563EB;
    --accent-hover: #1D4ED8;
    --accent-light: #EFF6FF;
    --success: #059669;
    --success-bg: #ECFDF5;
    --danger: #DC2626;
    --danger-bg: #FEF2F2;
    --warning: #D97706;
    --warning-bg: #FFFBEB;
    --shadow-s: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-m: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-l: 0 4px 16px rgba(0,0,0,0.10);
    --chart-grid: rgba(0,0,0,0.06);
    --chart-line: #2563EB;
    --chart-fill: rgba(37,99,235,0.08);
}

/* Dark theme */
[data-theme="dark"] {
    --bg-primary: #111827;
    --bg-secondary: #1F2937;
    --bg-tertiary: #374151;
    --bg-input: #1F2937;
    --border: #374151;
    --border-focus: #3B82F6;
    --text-primary: #F9FAFB;
    --text-secondary: #9CA3AF;
    --text-muted: #6B7280;
    --accent: #3B82F6;
    --accent-hover: #2563EB;
    --accent-light: #1E3A5F;
    --success: #34D399;
    --success-bg: #064E3B;
    --danger: #F87171;
    --danger-bg: #7F1D1D;
    --warning: #FBBF24;
    --warning-bg: #78350F;
    --shadow-s: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-m: 0 2px 8px rgba(0,0,0,0.4);
    --shadow-l: 0 4px 16px rgba(0,0,0,0.5);
    --chart-grid: rgba(255,255,255,0.06);
    --chart-line: #3B82F6;
    --chart-fill: rgba(59,130,246,0.1);
}

/* ========== RESET & BASE ========== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; line-height: 1.5; }
body {
    font-family: var(--font);
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: background var(--transition), color var(--transition);
    min-height: 100vh;
}

/* ========== TYPOGRAPHY ========== */
h1 { font-size: 1.5rem; font-weight: 600; line-height: 1.3; }
h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
h3 { font-size: 1rem; font-weight: 600; line-height: 1.4; }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.857rem; }
.text-xs { font-size: 0.786rem; }

/* ========== PAGES ========== */
.page { display: none; min-height: 100vh; }
.page.active { display: grid; }

/* ========== LOGIN / REGISTER PAGE ========== */
.page-auth {
    grid-template-columns: 1fr 1fr;
}

.auth-brand {
    background: var(--accent);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 48px;
    color: #fff;
}
.auth-brand h1 { font-size: 2rem; margin-bottom: 8px; }
.auth-brand p { opacity: 0.8; font-size: 1rem; }

.auth-form-wrap {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 48px;
    background: var(--bg-primary);
}

.auth-form { width: 100%; max-width: 400px; }
.auth-form h2 { margin-bottom: 24px; }

/* ========== APP LAYOUT ========== */
.page-app {
    grid-template-columns: 240px 1fr;
    grid-template-rows: 56px 1fr;
}

/* ========== SIDEBAR ========== */
.sidebar {
    grid-row: 1 / -1;
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: background var(--transition);
}

.sidebar-logo {
    height: 56px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    font-weight: 600;
    font-size: 1.07rem;
    border-bottom: 1px solid var(--border);
    color: var(--accent);
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-s);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.929rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.sidebar-link:hover { background: var(--bg-secondary); color: var(--text-primary); }
.sidebar-link.active { background: var(--accent-light); color: var(--accent); }
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-s);
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.857rem;
}

.sidebar-user-info { flex: 1; }
.sidebar-user-name { font-weight: 500; color: var(--text-primary); }
.sidebar-user-email { color: var(--text-muted); font-size: 0.786rem; }

/* ========== TOPBAR ========== */
.topbar {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.14rem; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ========== MAIN CONTENT ========== */
.main-content {
    padding: 24px;
    overflow-y: auto;
}

/* ========== FORM ELEMENTS ========== */
.form-group { margin-bottom: 16px; }
.form-group.form-inline { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.form-group.form-inline label { min-width: 140px; margin-bottom: 0; white-space: nowrap; }
.form-group.form-inline .form-input { max-width: 260px; }

.form-group label {
    display: block;
    font-size: 0.857rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-s);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.929rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.form-input::placeholder { color: var(--text-muted); }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-hint {
    font-size: 0.786rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-error {
    font-size: 0.786rem;
    color: var(--danger);
    margin-top: 4px;
    display: none;
}

/* ========== BUTTONS ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 40px;
    padding: 0 20px;
    border: none;
    border-radius: var(--radius-s);
    font-family: var(--font);
    font-size: 0.929rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-light); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 0.857rem; }
.btn-block { width: 100%; }

.form-footer {
    margin-top: 16px;
    font-size: 0.857rem;
    color: var(--text-secondary);
}
.form-footer a {
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}
.form-footer a:hover { text-decoration: underline; }

/* ========== STAT CARDS ========== */
.stats-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 16px;
    margin-bottom: 24px;
}
.stats-row .stat-card { flex: 1; }

.stat-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    padding: 16px 20px;
}

.stat-card-label {
    font-size: 0.786rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 4px;
}

.stat-card-value { font-size: 1.5rem; font-weight: 600; }
.stat-card-sub { font-size: 0.786rem; color: var(--text-secondary); margin-top: 2px; }
.stat-positive { color: var(--success); }
.stat-negative { color: var(--danger); }

/* ========== CHART ========== */
.chart-wrap {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    padding: 20px;
    margin-bottom: 24px;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.chart-header h3 { font-size: 1rem; }

.chart-period {
    display: flex;
    gap: 4px;
}

.chart-period button {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-s);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.786rem;
    cursor: pointer;
    transition: all var(--transition);
}
.chart-period button.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.chart-period button:hover:not(.active) {
    background: var(--bg-tertiary);
}

.chart-container {
    position: relative;
    height: 240px;
}

/* ========== TABLE ========== */
.table-wrap {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    overflow: hidden;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.table-header h3 { font-size: 1rem; }

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

thead th {
    text-align: left;
    padding: 10px 20px;
    font-size: 0.786rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

tbody td {
    padding: 12px 20px;
    font-size: 0.929rem;
    border-bottom: 1px solid var(--border);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); cursor: pointer; }
tbody tr:hover { background: var(--bg-secondary); }

/* ========== BADGES ========== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 0.786rem;
    font-weight: 500;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ========== MONOSPACE ========== */
.mono {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.857rem;
}

/* ========== ACTIONS ========== */
.actions { display: flex; gap: 6px; }

/* ========== BACK LINK ========== */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
    border-radius: var(--radius-s);
    text-decoration: none;
    font-size: 0.8rem;
    font-family: inherit;
    padding: 5px 12px;
    cursor: pointer;
    margin-bottom: 16px;
    transition: opacity var(--transition);
}
.back-link:hover { opacity: 0.85; }
.back-link svg { width: 14px; height: 14px; }

/* ========== MODAL ========== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-primary);
    border-radius: var(--radius-l);
    padding: 32px;
    width: 100%;
    max-width: 520px;
    box-shadow: var(--shadow-l);
}
.modal h2 { margin-bottom: 24px; }
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* ========== THEME TOGGLE ========== */
.theme-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    transition: color var(--transition);
}
.theme-toggle:hover { color: var(--text-primary); }
.theme-toggle svg { width: 20px; height: 20px; }

/* ========== AUTO-REFRESH TOGGLE ========== */
.auto-refresh-toggle {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px 12px;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    font-family: inherit;
    transition: all var(--transition);
    border-radius: var(--radius-s);
}
.auto-refresh-toggle:hover { border-color: var(--accent); color: var(--text-primary); }
.auto-refresh-toggle .refresh-icon { font-size: 1.1rem; line-height: 1; }
.auto-refresh-toggle.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.auto-refresh-toggle.active:hover { opacity: 0.85; }
.auto-refresh-toggle.active .refresh-icon {
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ========== TOAST ========== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius-s);
    font-size: 0.857rem;
    font-weight: 500;
    z-index: 2000;
    transform: translateY(80px);
    opacity: 0;
    transition: all 0.3s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }

/* ========== SETTINGS ========== */
.settings-section {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    padding: 24px;
    margin-bottom: 16px;
}
.settings-section h3 { margin-bottom: 16px; }
.settings-form { max-width: 400px; }

/* ========== WORKER GROUP ROWS ========== */
.worker-group-row {
    background: rgba(37,99,235,0.12) !important;
}
.worker-group-row:hover {
    background: rgba(37,99,235,0.2) !important;
}
.worker-group-row td {
    font-weight: 500;
    color: #1e40af;
}
[data-theme="dark"] .worker-group-row {
    background: rgba(88,166,255,0.18) !important;
}
[data-theme="dark"] .worker-group-row:hover {
    background: rgba(88,166,255,0.28) !important;
}
[data-theme="dark"] .worker-group-row td {
    color: #a8cfff;
}
