/* ============================================================
   FAMS — FleetOps Design System
   "The Executive Dashboard" visual language: authoritative,
   crisp, tactile. Dense but perfectly structured. Surfaces are
   flat at rest and elevate only on interaction, so operational
   signals — not decoration — carry the eye.
   ============================================================ */

/* Google Fonts: Inter only. Hierarchy is achieved through weight
   and size; no competing typeface is introduced. */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ===================== THEME TOKENS ===================== */
:root {
    /* Semantic color roles */
    --background: #f3f3f3;          /* Cool Paper — the background floor */
    --surface: #ffffff;             /* Surface White — cards, sheets, dialogs */
    --border: #d1d5db;              /* Slate Border — structural divider */
    --foreground: #111827;          /* Midnight Ink — primary text */
    --foreground-secondary: #4b5563;/* supporting text */
    --foreground-muted: #6b7280;    /* micro-labels, eyebrow, table metadata */
    --primary: #111827;             /* Midnight Ink — actions, active nav */
    --on-primary: #ffffff;          /* text on a --primary fill */
    --accent: #0b132b;              /* Deep Navy — identity accent only */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* Strict Status Contrast Rule.
       The base status colors above are for fills and large graphical
       elements ONLY. Anything under 14px — chip text, captions, table
       metadata — must use these AA-safe 700-level variants. */
    --success-text: #047857;
    --warning-text: #b45309;
    --danger-text: #b91c1c;
    --info-text: #1d4ed8;

    /* 10% tint fills backing status chips and icon tiles */
    --success-tint: rgba(16, 185, 129, 0.10);
    --warning-tint: rgba(245, 158, 11, 0.10);
    --danger-tint: rgba(239, 68, 68, 0.10);
    --info-tint: rgba(59, 130, 246, 0.10);
    --accent-tint: rgba(11, 19, 43, 0.06);
    --neutral-tint: rgba(107, 114, 128, 0.10);

    /* Session peach — the one-off expired-session surface. Deliberately
       outside the semantic palette so an expired session never reads as
       a `danger` failure. Do not reuse it. */
    --session-peach-bg: #fff8f3;
    --session-peach-border: #fbd9b8;

    /* Fixed document palette — printed/exported artifacts (visitor passes,
       permit stubs) that render as physical objects. These deliberately do
       NOT flip with the theme: a pass must look identical on screen and on
       paper, so they are declared once here and never re-declared in the
       dark blocks. Do not use them for interactive UI. */
    --doc-surface: #152539;
    --doc-surface-alt: #1b2f4a;
    --doc-on-surface: #ffffff;
    --doc-accent: #e4b96a;
    --doc-rule: #dfe1db;
    --doc-muted: #5c636f;

    /* Categorical identity — for things that are *entities*, not states:
       a facility, a report type, a notification kind. Mirrors
       `ChartTokens.categorical` in assets/js/chart-tokens.js; change both
       in the same commit. Never use these to signal severity. */
    --cat-1: #1d4ed8;  --cat-1-tint: rgba(29, 78, 216, 0.10);
    --cat-2: #0891b2;  --cat-2-tint: rgba(8, 145, 178, 0.10);
    --cat-3: #047857;  --cat-3-tint: rgba(4, 120, 87, 0.10);
    --cat-4: #b45309;  --cat-4-tint: rgba(180, 83, 9, 0.10);
    --cat-5: #7c3aed;  --cat-5-tint: rgba(124, 58, 237, 0.10);
    --cat-6: #be185d;  --cat-6-tint: rgba(190, 24, 93, 0.10);
    --cat-7: #0f766e;  --cat-7-tint: rgba(15, 118, 110, 0.10);
    --cat-8: #6b7280;  --cat-8-tint: rgba(107, 114, 128, 0.10);

    /* Typography — Inter everywhere, including data. */
    --font-display: 'Inter', system-ui, sans-serif;
    --font-interface: 'Inter', system-ui, sans-serif;
    --font-data: 'Inter', system-ui, sans-serif;

    /* Spacing scale (4px) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 12px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* Shape — semantic radii only. No custom border radii. */
    --radius-sm: 4px;               /* micro elements */
    --radius-md: 6px;               /* chips */
    --radius: 12px;                 /* controls: inputs, selects, buttons */
    --radius-lg: 16px;              /* cards, dialogs, large surfaces */
    --radius-control: var(--radius);
    --radius-card: var(--radius-lg);
    --radius-stat: 24px;            /* KPI stat cards */

    /* Elevation — structural, never ambient. Surfaces rest flat. */
    --shadow-resting: 0 1px 2px 0 rgb(0 0 0 / 0.03);
    --shadow-lifted: 0 1px 3px 0 rgb(0 0 0 / 0.04);
    --shadow-raised: 0 4px 6px -1px rgb(0 0 0 / 0.05);
    /* Overlay elevation — floating layers only (menus, dropdowns, popovers).
       Defined here so no page needs its own rgba fallback. */
    --shadow-dropdown: 0 8px 24px rgb(0 0 0 / 0.12);
    /* Tactile lift — the expansive shadow paired with the hover spring */
    --shadow-tactile: 0 12px 24px -6px rgb(17 24 39 / 0.12), 0 4px 8px -4px rgb(17 24 39 / 0.08);
    /* Tactile inset top highlight — the hairline that catches light along
       the top edge of a panel. 0.06 on dark. */
    --inset-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.8);

    /* Focus */
    --focus-ring: 0 0 0 2px var(--background), 0 0 0 4px var(--primary);

    /* Layout */
    --sidebar-width: 235px;
    --header-height: 64px;

    /* Motion */
    --motion-fast: 150ms ease;
    --motion-medium: 200ms ease;
    /* The Tactile Physics Rule — KPI cards spring on this exact curve */
    --motion-spring: 280ms cubic-bezier(0.32, 0.72, 0, 1);

    /* ===== Backward-compatible aliases (existing markup) ===== */
    --bg: var(--background);
    --bg-card: var(--surface);
    --text: var(--foreground);
    --text-muted: var(--foreground-secondary);
    --primary-light: #374151;       /* hover lift for a Midnight Ink fill */
    --primary-dark: var(--primary);
    --accent-light: var(--accent);
    --shadow: var(--shadow-resting);
    --shadow-lg: var(--shadow-raised);
    --transition: var(--motion-medium);
}

/* Dark theme — via system preference OR manual [data-theme="dark"] override.
   The dark palette is derived, not specified: same semantic roles, status
   hues lifted for contrast on a deep neutral ground, and `--primary`
   inverting to a light fill whose text is carried by `--on-primary`. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --background: #0f1115;
        --surface: #17191e;
        --border: #2b2f36;
        --foreground: #f3f4f6;
        --foreground-secondary: #9ca3af;
        --foreground-muted: #6b7280;
        --primary: #f3f4f6;
        --on-primary: #111827;
        --primary-light: #d1d5db;
        --accent: #9db2e8;
        --success: #34d399;
        --warning: #fbbf24;
        --danger: #f87171;
        --info: #60a5fa;
        --success-text: #6ee7b7;
        --warning-text: #fcd34d;
        --danger-text: #fca5a5;
        --info-text: #93c5fd;
        --success-tint: rgba(52, 211, 153, 0.14);
        --warning-tint: rgba(251, 191, 36, 0.14);
        --danger-tint: rgba(248, 113, 113, 0.14);
        --info-tint: rgba(96, 165, 250, 0.14);
        --accent-tint: rgba(157, 178, 232, 0.12);
        --neutral-tint: rgba(156, 163, 175, 0.14);
        --session-peach-bg: #27150a;
        --session-peach-border: #7c3f16;
        --inset-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.06);
        --shadow-resting: 0 1px 2px 0 rgb(0 0 0 / 0.4);
        --shadow-lifted: 0 1px 3px 0 rgb(0 0 0 / 0.5);
        --shadow-raised: 0 4px 6px -1px rgb(0 0 0 / 0.5);
        --shadow-dropdown: 0 8px 24px rgb(0 0 0 / 0.6);
        --shadow-tactile: 0 12px 24px -6px rgb(0 0 0 / 0.55), 0 4px 8px -4px rgb(0 0 0 / 0.4);
        /* Categorical identity, lifted for a dark ground. */
        --cat-1: #60a5fa;  --cat-1-tint: rgba(96, 165, 250, 0.14);
        --cat-2: #22d3ee;  --cat-2-tint: rgba(34, 211, 238, 0.14);
        --cat-3: #34d399;  --cat-3-tint: rgba(52, 211, 153, 0.14);
        --cat-4: #fbbf24;  --cat-4-tint: rgba(251, 191, 36, 0.14);
        --cat-5: #a78bfa;  --cat-5-tint: rgba(167, 139, 250, 0.14);
        --cat-6: #f472b6;  --cat-6-tint: rgba(244, 114, 182, 0.14);
        --cat-7: #2dd4bf;  --cat-7-tint: rgba(45, 212, 191, 0.14);
        --cat-8: #9ca3af;  --cat-8-tint: rgba(156, 163, 175, 0.14);
    }
}

/* Manual dark override (takes precedence over system preference) */
[data-theme="dark"] {
    --background: #0f1115;
    --surface: #17191e;
    --border: #2b2f36;
    --foreground: #f3f4f6;
    --foreground-secondary: #9ca3af;
    --foreground-muted: #6b7280;
    --primary: #f3f4f6;
    --on-primary: #111827;
    --primary-light: #d1d5db;
    --accent: #9db2e8;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --info: #60a5fa;
    --success-text: #6ee7b7;
    --warning-text: #fcd34d;
    --danger-text: #fca5a5;
    --info-text: #93c5fd;
    --success-tint: rgba(52, 211, 153, 0.14);
    --warning-tint: rgba(251, 191, 36, 0.14);
    --danger-tint: rgba(248, 113, 113, 0.14);
    --info-tint: rgba(96, 165, 250, 0.14);
    --accent-tint: rgba(157, 178, 232, 0.12);
    --neutral-tint: rgba(156, 163, 175, 0.14);
    --session-peach-bg: #27150a;
    --session-peach-border: #7c3f16;
    --inset-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.06);
    --shadow-resting: 0 1px 2px 0 rgb(0 0 0 / 0.4);
    --shadow-lifted: 0 1px 3px 0 rgb(0 0 0 / 0.5);
    --shadow-raised: 0 4px 6px -1px rgb(0 0 0 / 0.5);
    --shadow-dropdown: 0 8px 24px rgb(0 0 0 / 0.6);
    --shadow-tactile: 0 12px 24px -6px rgb(0 0 0 / 0.55), 0 4px 8px -4px rgb(0 0 0 / 0.4);
    /* Categorical identity, lifted for a dark ground. */
    --cat-1: #60a5fa;  --cat-1-tint: rgba(96, 165, 250, 0.14);
    --cat-2: #22d3ee;  --cat-2-tint: rgba(34, 211, 238, 0.14);
    --cat-3: #34d399;  --cat-3-tint: rgba(52, 211, 153, 0.14);
    --cat-4: #fbbf24;  --cat-4-tint: rgba(251, 191, 36, 0.14);
    --cat-5: #a78bfa;  --cat-5-tint: rgba(167, 139, 250, 0.14);
    --cat-6: #f472b6;  --cat-6-tint: rgba(244, 114, 182, 0.14);
    --cat-7: #2dd4bf;  --cat-7-tint: rgba(45, 212, 191, 0.14);
    --cat-8: #9ca3af;  --cat-8-tint: rgba(156, 163, 175, 0.14);
}

/* Manual light override (takes precedence over system preference).
   Explicit light must render identically to the default (:root) — the
   sidebar keeps the same quiet floor in both, with no separate brand
   gradient, so picking "light" never changes the layout's identity. */
[data-theme="light"] {
    --background: #f3f3f3;
    --surface: #ffffff;
    --border: #d1d5db;
    --foreground: #111827;
    --foreground-secondary: #4b5563;
    --foreground-muted: #6b7280;
    --primary: #111827;
    --on-primary: #ffffff;
    --accent: #0b132b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --success-text: #047857;
    --warning-text: #b45309;
    --danger-text: #b91c1c;
    --info-text: #1d4ed8;
    --success-tint: rgba(16, 185, 129, 0.10);
    --warning-tint: rgba(245, 158, 11, 0.10);
    --danger-tint: rgba(239, 68, 68, 0.10);
    --info-tint: rgba(59, 130, 246, 0.10);
    --accent-tint: rgba(11, 19, 43, 0.06);
    --neutral-tint: rgba(107, 114, 128, 0.10);
    --session-peach-bg: #fff8f3;
    --session-peach-border: #fbd9b8;
    --inset-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.8);
    --shadow-resting: 0 1px 2px 0 rgb(0 0 0 / 0.03);
    --shadow-lifted: 0 1px 3px 0 rgb(0 0 0 / 0.04);
    --shadow-raised: 0 4px 6px -1px rgb(0 0 0 / 0.05);
    --shadow-dropdown: 0 8px 24px rgb(0 0 0 / 0.12);
    --shadow-tactile: 0 12px 24px -6px rgb(17 24 39 / 0.12), 0 4px 8px -4px rgb(17 24 39 / 0.08);
    /* Categorical identity back to the light series. */
    --cat-1: #1d4ed8;  --cat-1-tint: rgba(29, 78, 216, 0.10);
    --cat-2: #0891b2;  --cat-2-tint: rgba(8, 145, 178, 0.10);
    --cat-3: #047857;  --cat-3-tint: rgba(4, 120, 87, 0.10);
    --cat-4: #b45309;  --cat-4-tint: rgba(180, 83, 9, 0.10);
    --cat-5: #7c3aed;  --cat-5-tint: rgba(124, 58, 237, 0.10);
    --cat-6: #be185d;  --cat-6-tint: rgba(190, 24, 93, 0.10);
    --cat-7: #0f766e;  --cat-7-tint: rgba(15, 118, 110, 0.10);
    --cat-8: #6b7280;  --cat-8-tint: rgba(107, 114, 128, 0.10);
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===================== BASE ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-interface);
    background: var(--background);
    color: var(--foreground);
    line-height: 1.5;
    min-height: 100vh;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--foreground-secondary); }

/* Typographic hierarchy — Display 22 / Title 18 / Lead 16 / Body 14 /
   Label 12 / Caption 11. All Inter; hierarchy comes from weight and size. */
h1, h2, h3, h4, h5, h6 { font-family: var(--font-display); }

h1 { font-size: 22px; line-height: 1.25; font-weight: 600; }
h2 { font-size: 18px; line-height: 1.3; font-weight: 600; }
h3 { font-size: 16px; line-height: 1.35; font-weight: 500; }
h4 { font-size: 14px; line-height: 1.4; font-weight: 600; }
h5, h6 { font-size: 12px; line-height: 1.4; font-weight: 500; }

/* The Data Alignment Rule.
   Anything compared or scanned vertically — tables, currency, plates,
   IDs, timestamps — uses tabular figures so columns line up. */
.font-data,
.table td.numeric,
.data {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

/* Focus treatment — visible 2px ring on all interactive elements */
:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ===== LOGIN PAGE ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    /* The floor stays plain — no decorative gradients compete with the
       form. Depth comes from the card's resting shadow instead. */
    background: var(--background);
    padding: var(--space-5);
}

.login-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-raised);
    width: 100%;
    max-width: 440px;
    overflow: hidden;
}

.login-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--space-8) var(--space-6) var(--space-6);
    text-align: center;
}

.login-header .logo {
    width: 56px;
    height: 56px;
    background: var(--primary);
    color: var(--on-primary);
    border-radius: var(--radius-control);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--space-4);
    font-size: 22px;
    font-weight: 600;
}

.login-header h1 { font-size: 22px; margin-bottom: 4px; font-weight: 600; }
.login-header p { color: var(--foreground-secondary); font-size: 13px; }

.login-form { padding: var(--space-6); }

/* ===== FORMS ===== */
.form-group { margin-bottom: var(--space-5); }
.form-group label {
    display: block;
    font-family: var(--font-interface);
    font-weight: 500;
    font-size: 12px;
    margin-bottom: var(--space-2);
    color: var(--foreground-secondary);
}

.form-control {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    font-size: 14px;
    font-family: var(--font-interface);
    background: var(--surface);
    color: var(--foreground);
    transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--primary);
}

/* Chrome paints autofilled fields its own yellow, which fights the
   Surface color. Re-assert ours with the inset-shadow trick, since the
   background itself can't be overridden. */
.form-control:-webkit-autofill,
.form-control:-webkit-autofill:hover,
.form-control:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--foreground);
    -webkit-box-shadow: 0 0 0 1000px var(--surface) inset;
    box-shadow: 0 0 0 1000px var(--surface) inset;
    transition: background-color 5000s ease-in-out 0s;
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23666' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-control { resize: vertical; min-height: 100px; }

/* Password field with a custom show/hide (eye) toggle.
   Edge/IE render their own native reveal button; hide it so we don't get
   two eyes, and so the control is identical across all browsers. */
.password-field { position: relative; display: flex; align-items: center; }
.password-field .form-control { padding-right: 44px; }
.password-field input::-ms-reveal,
.password-field input::-ms-clear { display: none; }

.password-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--foreground-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: color var(--motion-fast), background var(--motion-fast);
}
.password-toggle:hover { color: var(--foreground); }
.password-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--background), 0 0 0 3px var(--primary);
}
.password-toggle svg { width: 18px; height: 18px; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font-interface);
    cursor: pointer;
    transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast);
    text-decoration: none;
    min-height: 40px;
    white-space: nowrap;
}

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

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-light); color: var(--on-primary); }

/* Accent = Deep Navy, reserved for identity surfaces. It is not a
   general emphasis color — primary carries action everywhere else. */
.btn-accent { background: var(--accent); color: #ffffff; }
.btn-accent:hover:not(:disabled) { filter: brightness(1.25); }

.btn-success { background: var(--success); color: #ffffff; }
.btn-success:hover:not(:disabled) { filter: brightness(1.08); }

.btn-danger { background: var(--danger); color: #ffffff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }

.btn-outline {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--foreground);
}
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); background: var(--surface); }

.btn-sm { padding: var(--space-2) var(--space-4); font-size: 13px; min-height: 32px; }
.btn-block { width: 100%; }

/* ===== APP LAYOUT ===== */
.app-layout { display: flex; min-height: 100vh; }

/* The sidebar is deliberately plain: the same Cool Paper ground as the
   page, separated by a single Slate Border. Active navigation is carried
   by a Midnight Ink fill, not by a colored edge. */

/* Global SVG icon sizing — icons.js generates <svg class="icon"> */
.icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    vertical-align: middle;
}

.sidebar {
    width: var(--sidebar-width);
    padding-left: 5px;
    background: var(--background);
    color: var(--foreground);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 100;
    transition: transform var(--motion-medium);
}

.sidebar-header {
    flex-shrink: 0;
    padding: 12px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.sidebar-header .logo-sm {
    width: 39px;
    height: 39px;
    background: var(--primary);
    color: var(--on-primary);
    border-radius: var(--radius-control);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-header h2 { font-size: 16px; line-height: 1.2; font-weight: 600; }
.sidebar-header small { color: var(--foreground-secondary); font-size: 12px; }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;            /* Firefox */
    -ms-overflow-style: none;          /* IE/Edge */
    padding: var(--space-1) 0;
}
.sidebar-nav::-webkit-scrollbar { display: none; /* Chrome/Safari/Opera */ }

.nav-section {
    padding: var(--space-1) var(--space-4) var(--space-1);
    font-family: var(--font-interface);
    font-size: 11px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--foreground-muted);
    margin-top: var(--space-2);
}

.nav-section:first-child { margin-top: 0; padding-top: var(--space-1); }

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-control);
    margin-left: 8px;
    margin-right: 8px;
    color: var(--foreground-secondary);
    transition: background var(--motion-fast), color var(--motion-fast);
    font-size: 13.5px;
    min-height: 36px;
}

.nav-item:hover { background: var(--neutral-tint); color: var(--foreground); }

/* Active navigation is carried by a Midnight Ink fill. One state, one
   color — and no colored edge bars. */
.nav-item.active {
    background: var(--primary);
    color: var(--on-primary);
    font-weight: 500;
}

.nav-item.active .icon { color: var(--on-primary); opacity: 1; }

.nav-item .icon { 
    width: 18px; 
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-align: center; 
    font-size: 14.5px; 
    opacity: 0.85;
}

.nav-item .icon svg {
    display: block;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}

.top-header {
    height: var(--header-height);
    background: var(--background);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-6);
    position: sticky;
    top: 0;
    z-index: 50;
    gap: var(--space-4);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    min-width: 0;
}

/* Date & time block (stacked, left-aligned) */
.header-datetime {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--space-3);
    line-height: 1.25;
    min-width: 0;
}

/* Date + time stay stacked together as one unit, as before. */
.header-clock {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
}

.header-date {
    font-size: 12px;
    color: var(--foreground-secondary);
    font-weight: 400;
    white-space: nowrap;
}

.header-time {
    font-size: 13px;
    font-weight: 700;
    margin-left: 35px;
    color: var(--primary);
    font-family: var(--font-data);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Global inactivity countdown. Same row, same scale and tone as the
   date/time above it: 12px secondary tabular figures. Warning bands reuse
   the system text variants — never a new color, never a new shape. */
.header-session {
    font-size: 12px;
    font-weight: 400;
    color: var(--foreground-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.header-session.session-warn {
    color: var(--warning-text);
    font-weight: 600;
}

.header-session.session-critical {
    color: var(--danger-text);
    font-weight: 700;
}

.header-actions { display: flex; align-items: center; gap: var(--space-4); }

/* Two circular icon buttons (bell + theme) */
.header-icon-circles {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.icon-circle {
    position: relative;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--foreground-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--motion-fast), color var(--motion-fast), border-color var(--motion-fast), box-shadow var(--motion-fast);
    padding: 0;
}

.icon-circle:hover {
    background: var(--background);
    color: var(--foreground);
    border-color: var(--primary);
    box-shadow: var(--shadow-resting);
}

.icon-circle:focus-visible {
    box-shadow: 0 0 0 2px var(--background), 0 0 0 3px var(--primary);
}

.icon-circle svg { width: 15px; height: 15px; }

/* Red dot badge for unread notifications */
.notif-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    border: 2px solid var(--surface);
}

.theme-toggle[data-theme="dark"] .icon-sun,
.theme-toggle:not([data-theme="dark"]) .icon-moon { display: none; }

/* ===== NOTIFICATION DROPDOWN ===== */
.notif-wrapper {
    position: relative;
}

.notif-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 340px;
    max-width: calc(100vw - 24px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-raised);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity var(--motion-fast), transform var(--motion-fast), visibility var(--motion-fast);
    z-index: 400;
    overflow: hidden;
}

.notif-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.notif-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
}

.notif-header h3 {
    font-size: 14px;
    font-family: var(--font-display);
}

.notif-mark-all {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-interface);
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    min-height: 28px;
}
.notif-mark-all:hover { text-decoration: underline; }

.notif-list {
    max-height: 360px;
    overflow-y: auto;
}

.notif-item {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--motion-fast);
    text-align: left;
}
.notif-item:hover { background: var(--background); }
.notif-item.unread { background: var(--info-tint); }
.notif-item .notif-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    background: var(--info-tint);
    color: var(--info-text);
}
.notif-item .notif-icon.success { background: var(--success-tint); color: var(--success-text); }
.notif-item .notif-icon.danger { background: var(--danger-tint); color: var(--danger-text); }
.notif-item .notif-icon.warning, .notif-item .notif-icon.approval { background: var(--warning-tint); color: var(--warning-text); }
.notif-item .notif-icon.conflict { background: var(--danger-tint); color: var(--danger-text); }

.notif-item .notif-content { min-width: 0; flex: 1; }
.notif-item .notif-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--foreground);
    line-height: 1.3;
}
.notif-item .notif-msg {
    font-size: 12.5px;
    color: var(--foreground-secondary);
    line-height: 1.4;
    margin-top: 2px;
    word-break: break-word;
}
.notif-item .notif-time {
    font-size: 11px;
    color: var(--foreground-muted);
    margin-top: 4px;
    font-family: var(--font-data);
}

.notif-empty {
    text-align: center;
    padding: var(--space-8) var(--space-5);
    color: var(--foreground-secondary);
    font-size: 13px;
}
.notif-empty .icon { font-size: 2rem; opacity: 0.3; display: block; margin-bottom: var(--space-2); }

.notif-footer {
    padding: var(--space-3);
    border-top: 1px solid var(--border);
    text-align: center;
}
.notif-footer a {
    font-size: 12.5px;
    font-weight: 600;
}

/* Notification count badge next to the bell */
.notif-count {
    position: absolute;
    top: -4px;
    right: -6px;
    background: var(--danger);
    color: #fff;
    font-family: var(--font-data);
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    padding: 3px 5px;
    border-radius: 999px;
    border: 2px solid var(--surface);
    min-width: 16px;
    text-align: center;
}

/* User profile pill */
.user-menu {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    cursor: pointer;
    padding: 5px 10px 5px 5px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    transition: background var(--motion-fast), border-color var(--motion-fast), box-shadow var(--motion-fast);
    min-height: 44px;
    user-select: none;
}

.user-menu:hover {
    background: var(--background);
    border-color: var(--primary);
    box-shadow: var(--shadow-resting);
}

.user-avatar {
    width: 30px;
    height: 30px;
    background: var(--primary);
    color: var(--on-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
}

.user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
    overflow: hidden;
}
.user-name {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}
.user-role {
    font-size: 10.5px;
    color: var(--foreground-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.user-chevron {
    display: flex;
    align-items: center;
    color: var(--foreground-secondary);
    margin-left: 2px;
    transition: transform var(--motion-fast);
}
.user-chevron svg { width: 10px; height: 10px; }

/* ===== USER DROPDOWN MENU ===== */
.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 240px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-raised);
    padding: var(--space-2);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity var(--motion-fast), transform var(--motion-fast), visibility var(--motion-fast);
    z-index: 300;
}

.user-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-menu.open .user-chevron { transform: rotate(90deg); }

.user-dropdown-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
}

.user-avatar-sm {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: var(--on-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.user-dropdown-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
}

.user-dropdown-name { font-size: 14px; font-weight: 700; color: var(--foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-dropdown-role { font-size: 12px; color: var(--foreground-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.user-dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: var(--space-2) 0;
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-3) var(--space-3);
    border: none;
    background: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-interface);
    color: var(--foreground);
    cursor: pointer;
    text-align: left;
    transition: background var(--motion-fast), color var(--motion-fast);
}

.user-dropdown-item:hover { background: var(--background); color: var(--danger); }

.user-dropdown-icon { display: flex; align-items: center; color: var(--foreground-secondary); transition: color var(--motion-fast); }
.user-dropdown-item:hover .user-dropdown-icon { color: var(--danger); }
.user-dropdown-icon svg { width: 18px; height: 18px; }

.page-content { padding: var(--space-6); }

/* ===== CARDS & STATS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(240px, 1fr));
    gap: var(--space-5);
    margin-bottom: var(--space-6);
}

/* KPI stat card. Severity is never carried by a colored edge bar — the
   10% tone icon chip and the value itself do that work. */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-stat);
    padding: var(--space-5);
    box-shadow: var(--shadow-resting);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    transition: box-shadow var(--motion-spring), transform var(--motion-spring),
                border-color var(--motion-spring);
}

.stat-card:hover { box-shadow: var(--shadow-lifted); }

/* The Tactile Physics Rule.
   Interactive KPI cards spring; base cards only take a slight lift. */
.stat-card.interactive,
.stat-card[href],
.stat-card[role="button"] {
    cursor: pointer;
}

.stat-card.interactive:hover,
.stat-card[href]:hover,
.stat-card[role="button"]:hover {
    transform: translateY(-3px) scale(1.004);
    box-shadow: var(--shadow-tactile);
    border-color: color-mix(in srgb, var(--primary) 25%, var(--border));
}

.stat-card.interactive:active,
.stat-card[href]:active,
.stat-card[role="button"]:active {
    transform: translateY(-1px) scale(0.995);
    box-shadow: var(--shadow-lifted);
}

/* Linked cards get a visible focus ring naming their destination. */
.stat-card.interactive:focus-visible,
.stat-card[href]:focus-visible,
.stat-card[role="button"]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    background: var(--neutral-tint);
    color: var(--foreground-secondary);
}

.stat-icon svg {
    width: 22px;
    height: 22px;
    display: block;
}

/* Tone chips: 10% tint fill, AA-safe text variant. */
.stat-icon.blue { background: var(--info-tint); color: var(--info-text); }
.stat-icon.green { background: var(--success-tint); color: var(--success-text); }
.stat-icon.orange { background: var(--warning-tint); color: var(--warning-text); }
.stat-icon.red { background: var(--danger-tint); color: var(--danger-text); }
.stat-icon.purple { background: var(--accent-tint); color: var(--accent); }
.stat-icon.teal { background: var(--info-tint); color: var(--info-text); }

.stat-info h3 {
    font-size: 30px;
    font-weight: 600;
    line-height: 1.1;
    font-family: var(--font-interface);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    color: var(--foreground);
}

.stat-info p { color: var(--foreground-secondary); font-size: 12px; margin-top: var(--space-1); }

/* Optional 11px note pill and muted trend caption on a stat card. */
.stat-note {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
    padding: 2px 8px;
    border-radius: var(--radius-md);
    background: var(--neutral-tint);
    color: var(--foreground-secondary);
    margin-top: var(--space-1);
}

.stat-trend {
    font-size: 11px;
    color: var(--foreground-muted);
    margin-top: 2px;
}

.stat-trend.up { color: var(--success-text); }
.stat-trend.down { color: var(--danger-text); }

/* Dashboard panel. Flat at rest with a hairline inset highlight along the
   top edge; the header sits on a hover/30 wash. */
.card {
    padding: 13px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--inset-highlight), var(--shadow-resting);
    margin-bottom: var(--space-6);
}

.card-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    background: color-mix(in srgb, var(--background) 30%, transparent);
}

.card-header h3 { font-size: 15px; font-weight: 600; font-family: var(--font-interface); }
.card-header .text-muted { margin-top: 2px; font-size: 12px; color: var(--foreground-secondary); }

/* "View … →" action links live in the header, never as a floating footer. */
.card-header .card-action {
    font-size: 12px;
    font-weight: 500;
    color: var(--foreground-secondary);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.card-header .card-action:hover { color: var(--primary); }

.card-body { padding: var(--space-5); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-6); }

/* ===== TABLES ===== */
.table-responsive { overflow-x: auto; }

table { width: 100%; border-collapse: separate; border-spacing: 0; }

table th {
    background: var(--background);
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-family: var(--font-interface);
    font-weight: 400;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--foreground-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}

/* 44px minimum row height for touch-friendly tables */
table tbody tr { min-height: 44px; }

/* Numeric / data / timestamp columns use tabular figures so values line
   up when scanned vertically. */
table td.numeric,
table td.data,
table td:has(.data) {
    font-family: var(--font-interface);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

table tr:hover { background: var(--neutral-tint); }

/* ===== STATUS BADGES (text + color + shape) ===== */
/* One state = one color, globally. Background is a 10% tint of the signal
   color; the text uses the AA-safe variant, because these run at 11px —
   well under the 14px threshold where the base status colors are legal. */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--radius-md);
    font-family: var(--font-interface);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
}

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

/* Semantic badge mapping */
.badge-pending, .badge-in_progress, .badge-investigating, .badge-awaiting_review {
    background: var(--warning-tint);
    color: var(--warning-text);
}
.badge-warning {
    background: var(--warning-tint);
    color: var(--warning-text);
}
.badge-approved, .badge-active, .badge-completed, .badge-checked_in, .badge-available, .badge-online {
    background: var(--success-tint);
    color: var(--success-text);
}
.badge-rejected, .badge-cancelled, .badge-expired, .badge-failed, .badge-overdue, .badge-offline {
    background: var(--danger-tint);
    color: var(--danger-text);
}
.badge-draft, .badge-disabled, .badge-archived, .badge-inactive {
    background: var(--neutral-tint);
    color: var(--foreground-secondary);
}
.badge-scheduled, .badge-held, .badge-checked_out {
    background: var(--info-tint);
    color: var(--info-text);
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(18, 20, 23, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-5);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--motion-fast), visibility var(--motion-fast);
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-raised);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(8px);
    transition: transform var(--motion-fast);
}

.modal-overlay.active .modal { transform: translateY(0); }

.modal-lg { max-width: 900px; }
.modal-xl { max-width: 1200px; width: 95vw; height: 90vh; }

.modal-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-header h3 { font-size: 16px; font-family: var(--font-display); }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: var(--foreground-secondary);
    padding: var(--space-1);
    min-height: 32px;
    min-width: 32px;
    border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--foreground); background: var(--background); }
.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}
.modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    flex-shrink: 0;
}

.modal form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

@media (max-width: 768px) {
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal, .modal-lg, .modal-xl {
        max-width: 100%;
        width: 100%;
        max-height: 92vh;
        height: 92vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
    .modal-body { padding: var(--space-4); }
}

/* ===== CHARTS ===== */
/* Vertical rhythm is maintained through the canonical height classes
   rather than per-page pixel values. */
.chart-container { position: relative; height: 300px; padding: var(--space-4); }
.chart-h-sm { height: 220px; }
.chart-h-md { height: 260px; }
.chart-h-lg { height: 300px; }

/* Ultra-thin but highly visible, so interactive overflow is discoverable. */
.page-content,
.notif-list,
.modal-body,
.table-responsive,
.detail-scroll,
.schedule-scroll,
.reservations-scroll,
.pending-scroll {
    scrollbar-width: thin;
    scrollbar-color: var(--foreground-muted) transparent;
}

.page-content::-webkit-scrollbar,
.notif-list::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.table-responsive::-webkit-scrollbar,
.detail-scroll::-webkit-scrollbar,
.schedule-scroll::-webkit-scrollbar,
.reservations-scroll::-webkit-scrollbar,
.pending-scroll::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.page-content::-webkit-scrollbar-track,
.notif-list::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track,
.table-responsive::-webkit-scrollbar-track,
.detail-scroll::-webkit-scrollbar-track,
.schedule-scroll::-webkit-scrollbar-track,
.reservations-scroll::-webkit-scrollbar-track,
.pending-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.page-content::-webkit-scrollbar-thumb,
.notif-list::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.table-responsive::-webkit-scrollbar-thumb,
.detail-scroll::-webkit-scrollbar-thumb,
.schedule-scroll::-webkit-scrollbar-thumb,
.reservations-scroll::-webkit-scrollbar-thumb,
.pending-scroll::-webkit-scrollbar-thumb {
    background: var(--foreground-muted);
    border-radius: 999px;
}

/* ===== TOAST ===== */
.toast-container { position: fixed; top: var(--space-5); right: var(--space-5); z-index: 2000; display: flex; flex-direction: column; gap: var(--space-2); }

.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-3) var(--space-5);
    box-shadow: var(--shadow-raised);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 280px;
    animation: toastIn var(--motion-medium);
    font-size: 14px;
}

/* Severity is carried by a tinted icon chip plus role="alert" — never by
   a colored edge bar. app.js emits the glyph as the first span. */
.toast > span:first-child {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-control);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
    background: var(--info-tint);
    color: var(--info-text);
}

.toast.success > span:first-child { background: var(--success-tint); color: var(--success-text); }
.toast.error > span:first-child { background: var(--danger-tint); color: var(--danger-text); }
.toast.warning > span:first-child { background: var(--warning-tint); color: var(--warning-text); }

@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== SEARCH & FILTERS ===== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    flex-wrap: wrap;
}

.search-box {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-2) var(--space-4);
    flex: 1;
    max-width: 400px;
    min-height: 40px;
}

.search-box .search-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--foreground-secondary);
}

.search-box .search-icon svg {
    width: 16px;
    height: 16px;
}

.search-box input {
    border: none;
    background: none;
    outline: none;
    flex: 1;
    font-size: 14px;
    font-family: var(--font-interface);
    color: var(--foreground);
}

.filter-group { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-5);
    color: var(--foreground-secondary);
}

.empty-state .icon { font-size: 3rem; margin-bottom: var(--space-4); opacity: 0.3; display: block; }

/* ===== LOADING ===== */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: var(--space-10) auto;
}

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

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .loading-overlay { background: rgba(18, 20, 23, 0.6); }
}
[data-theme="dark"] .loading-overlay { background: rgba(18, 20, 23, 0.6); }

/* ===== PAGINATION ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-4);
}

.pagination button {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--foreground);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-family: var(--font-interface);
    transition: background var(--motion-fast), color var(--motion-fast);
    min-height: 32px;
}

.pagination button:hover, .pagination button.active {
    background: var(--primary);
    color: var(--on-primary);
    border-color: var(--primary);
}

/* ===== RESPONSIVE ===== */
.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--foreground-secondary);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}
.menu-toggle:hover {
    background: var(--background);
    color: var(--foreground);
    border-color: var(--primary);
}
.menu-toggle svg {
    width: 18px;
    height: 18px;
}

@media (max-width: 992px) {
    .grid-2 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-raised); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-box { max-width: 100%; }
    .page-content { padding: var(--space-4); }
    .top-header { padding: 0 var(--space-4); }

    /* Backdrop shown behind the open sidebar — clicking it closes the menu */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(17, 24, 39, 0.45);
        z-index: 90; /* below .sidebar's z-index: 100, above page content */
    }
    .sidebar-backdrop.open { display: block; }

    .page-title, h1.page-title { font-size: 18px; }
}

@media (max-width: 600px) {
    .header-datetime { display: none; }
    .user-meta { display: none; }
    .user-chevron { display: none; }
    .user-menu { padding: var(--space-1); border-radius: 50%; min-height: 40px; min-width: 40px; justify-content: center; }
    .header-actions { gap: var(--space-2); }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .page-content { padding: var(--space-4); }
    .page-title, h1.page-title { font-size: 16px; }
}

/* ===== ANALYTICS ===== */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--space-6);
}

.confidence-bar {
    height: 8px;
    background: var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-top: var(--space-2);
}

/* Single-hue meter. Gradient fills read as decoration; a flat fill reads
   as a measured value. */
.confidence-fill {
    height: 100%;
    background: var(--success);
    border-radius: var(--radius-sm);
    transition: width var(--motion-medium);
}

.prediction-card {
    background: var(--surface);
    color: var(--foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-6);
    box-shadow: var(--inset-highlight), var(--shadow-resting);
}

.prediction-card h4 {
    opacity: 1;
    color: var(--foreground-muted);
    font-size: 11px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: var(--space-2);
    font-family: var(--font-interface);
}
.prediction-card .value {
    color: var(--foreground);
    font-size: 30px;
    font-weight: 600;
    line-height: 1.1;
    font-family: var(--font-interface);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}
.prediction-card .confidence { opacity: 1; color: var(--foreground-secondary); font-size: 13px; margin-top: var(--space-2); }

/* ===== DASHBOARD: WEEKLY SCHEDULE + PENDING + MOST RESERVED ===== */
.dashboard-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    align-items: stretch;
}
.schedule-col {
    flex: 3 1 480px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}
.schedule-card {
    display: flex;
    flex-direction: column;
    flex: 1;
}
.schedule-card .card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}
.side-col {
    flex: 1 1 260px;
    min-width: 240px;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.search-box-full { max-width: none; width: 100%; }

.week-nav { display: flex; gap: var(--space-2); flex-shrink: 0; }
.btn-icon { width: 32px; height: 32px; min-height: 32px; padding: 0; }

.hide-scrollbar { scrollbar-width: none; -ms-overflow-style: none; }
.hide-scrollbar::-webkit-scrollbar { display: none; width: 0; height: 0; }

.schedule-scroll { flex: 1; min-height: 320px; max-height: none; overflow-y: auto; }

/* Reservations table — show ~5 rows, scrollable with hidden scrollbar */
.reservations-scroll { max-height: 260px; overflow-y: auto; }

/* Keep table headers fixed while only the body rows scroll */
.reservations-scroll thead th,
.schedule-scroll thead th,
.pending-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--background);
    box-shadow: 0 1px 0 var(--border);
}

.schedule-table { table-layout: fixed; }
.schedule-table th,
.schedule-table td {
    font-size: 11.5px;
    padding: var(--space-2) var(--space-1);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.schedule-table th:first-child,
.schedule-table td.facility-name {
    width: 92px;
    text-align: left;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.25;
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;
    padding-left: var(--space-3);
}
.schedule-table td.data { color: var(--foreground-muted); }
.schedule-table .badge {
    font-size: 9.5px;
    padding: 3px 7px;
    white-space: normal;
    line-height: 1.2;
    text-align: center;
}
.schedule-table .badge::before { display: none; }

/* Pending (for approval) */
.pending-scroll {
    max-height: 250px; /* approximately 3 rows */
    overflow-y: auto;
    overflow-x: hidden;

    /* Hide scrollbar but keep scrolling functional */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.pending-scroll::-webkit-scrollbar {
    display: none;
}

.pending-table {
    width: 100%;
    table-layout: fixed;
}

.pending-table th,
.pending-table td {
    font-size: 11.5px;
    padding: var(--space-2) var(--space-1);
    vertical-align: middle;
    line-height: 1.3;
    overflow-wrap: break-word;
}

.pending-table th:first-child,
.pending-table td:first-child {
    width: 34%;
    font-weight: 600;
}

.pending-table td.data {
    color: var(--foreground-muted);
    font-size: 11px;
}

.pending-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.btn-compact {
    font-size: 10.5px;
    padding: 3px 8px;
    min-height: 0;
    height: auto;
    line-height: 1.4;
}

/* Most Reserved */
.reserved-row { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-4); }
.reserved-row:last-child { margin-bottom: 0; }
.reserved-name {
    flex: 0 0 90px;
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reserved-bar {
    flex: 1;
    height: 8px;
    background: var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.reserved-fill {
    height: 100%;
    border-radius: var(--radius-sm);
    background: var(--info);
    transition: width var(--motion-medium);
}
.reserved-pct {
    flex: 0 0 36px;
    text-align: right;
    font-size: 12.5px;
    font-weight: 600;
    font-family: var(--font-interface);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}


/* ===== CONTRACT MANAGEMENT MODULES ===== */
.contracts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    align-items: stretch;
}
.contracts-grid .full-width { grid-column: 1 / -1; }

.contract-module {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-resting);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.contract-module-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}
.contract-module-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-control);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    background: var(--neutral-tint);
    color: var(--foreground-secondary);
}
.contract-module-icon.green { background: var(--success-tint); color: var(--success-text); }
.contract-module-icon.blue { background: var(--info-tint); color: var(--info-text); }
.contract-module-icon.orange { background: var(--warning-tint); color: var(--warning-text); }
.contract-module-icon.red { background: var(--danger-tint); color: var(--danger-text); }
.contract-module-header h3 { font-size: 15px; font-weight: 600; font-family: var(--font-interface); }
.contract-module-header p { font-size: 12px; color: var(--foreground-secondary); margin-top: 2px; }
.contract-module-body { padding: var(--space-4) var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); flex: 1; }
.module-action {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 13.5px;
    font-weight: 500;
    font-family: var(--font-interface);
    color: var(--foreground);
    cursor: pointer;
    text-align: left;
    transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast);
    min-height: 40px;
}
.module-action:hover {
    background: var(--neutral-tint);
    border-color: var(--primary);
    color: var(--primary);
}
.module-action .action-count {
    font-family: var(--font-interface);
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--foreground-secondary);
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 9px;
    flex-shrink: 0;
}
.module-action .action-arrow { color: var(--foreground-muted); font-size: 14px; flex-shrink: 0; }

@media (max-width: 768px) {
    .contracts-grid { grid-template-columns: 1fr; }
}

/* ===== CONTRACT SECTIONS (stacked full-width) ===== */
.contract-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-resting);
    margin-bottom: var(--space-6);
    overflow: hidden;
}
.contract-section-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}
.contract-section-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-control);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    background: var(--neutral-tint);
    color: var(--foreground-secondary);
}
.contract-section-icon.green { background: var(--success-tint); color: var(--success-text); }
.contract-section-icon.blue { background: var(--info-tint); color: var(--info-text); }
.contract-section-icon.orange { background: var(--warning-tint); color: var(--warning-text); }
.contract-section-icon.red { background: var(--danger-tint); color: var(--danger-text); }
.contract-section-icon.purple { background: var(--accent-tint); color: var(--accent); }
.contract-section-header h3 { font-size: 16px; font-weight: 600; font-family: var(--font-interface); }
.contract-section-header p { font-size: 12px; color: var(--foreground-secondary); margin-top: 2px; }
.contract-section-body { padding: var(--space-5); }

.section-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}
.section-tools .section-count {
    font-family: var(--font-data);
    font-size: 12px;
    color: var(--foreground-secondary);
}

/* Table action buttons — tinted chips, AA-safe text. */
.actions-cell { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.btn-action { min-height: 32px; padding: var(--space-2) var(--space-3); font-size: 12.5px; }
.btn-action.edit { background: var(--info-tint); color: var(--info-text); border: 1px solid transparent; }
.btn-action.edit:hover { background: var(--info); color: #fff; }
.btn-action.delete { background: var(--danger-tint); color: var(--danger-text); border: 1px solid transparent; }
.btn-action.delete:hover { background: var(--danger); color: #fff; }
.btn-action.renew { background: var(--success-tint); color: var(--success-text); border: 1px solid transparent; }
.btn-action.renew:hover { background: var(--success); color: #fff; }
.btn-action.extend { background: var(--info-tint); color: var(--info-text); border: 1px solid transparent; }
.btn-action.extend:hover { background: var(--info); color: #fff; }
.btn-action.terminate { background: var(--danger-tint); color: var(--danger-text); border: 1px solid transparent; }
.btn-action.terminate:hover { background: var(--danger); color: #fff; }
.btn-action.status { background: var(--warning-tint); color: var(--warning-text); border: 1px solid transparent; }
.btn-action.status:hover { background: var(--warning); color: #fff; }

.contract-table { table-layout: fixed; }
.contract-table th, .contract-table td { overflow-wrap: break-word; }

/* History dropdown */
.history-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }
.history-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--foreground);
    font-size: 13.5px;
    font-weight: 500;
    font-family: var(--font-interface);
    cursor: pointer;
    transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast);
    min-height: 40px;
}
.history-toggle:hover { background: var(--neutral-tint); border-color: var(--primary); color: var(--primary); }
.history-toggle.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.history-toggle .toggle-arrow { margin-left: var(--space-1); transition: transform var(--motion-fast); }
.history-toggle.active .toggle-arrow { transform: rotate(180deg); }

.history-dropdown-wrap {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.history-panel { display: none; margin-top: var(--space-2); }
.history-panel.open { display: block; }
.history-panel table { margin-top: var(--space-2); }
.history-empty { text-align: center; padding: var(--space-8); color: var(--foreground-secondary); font-size: 13px; }
.history-empty .icon { font-size: 2rem; opacity: 0.3; display: block; margin-bottom: var(--space-2); }
.history-body {
    font-size: 14px;
    color: var(--foreground);
    line-height: 1.6;
}
.history-detail {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
}
.history-detail p { margin-bottom: var(--space-2); }
.history-detail p:last-child { margin-bottom: 0; }

@media (max-width: 768px) {
    .contract-table { table-layout: auto; }
}

/* ===== QR CODE ===== */
.qr-display {
    text-align: center;
    padding: var(--space-8);
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin: var(--space-4) 0;
}

.qr-code-text {
    font-family: var(--font-data);
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: 2px;
    padding: var(--space-4);
    border: 1px dashed var(--primary);
    border-radius: var(--radius);
    display: inline-block;
    word-break: break-all;
}