/**
 * Dark Mode — a theme layer over the existing UI (Part 8/9 of the ticket),
 * not a redesign. Every component already reads its colors from the
 * --color-* custom properties defined in variables.css (confirmed by
 * inspecting every component .css file — only ~13 hardcoded hex values
 * exist outside variables.css, and those are text-on-saturated-color
 * contexts like white text on the sidebar/buttons that are correct in
 * both themes and were left alone). This file only redefines those same
 * tokens for dark mode, so every card/table/form/modal/badge picks up
 * the new palette automatically with zero per-component changes.
 *
 * --color-primary (sidebar/auth background, dark navy) and --color-accent
 * intentionally keep their brand identity across both themes per the
 * ticket's own "keep existing Guepardo/Transport System blue" — only the
 * neutral surface/text/border tokens and the badge tint backgrounds
 * change.
 *
 * Three-way Light/Dark/System toggle (assets/js/theme.js sets
 * data-theme="dark"|"light" on <html>, or removes it for "System"):
 *   - System: @media (prefers-color-scheme: dark), guarded so an explicit
 *     data-theme="light" always wins over the OS preference.
 *   - Dark: :root[data-theme="dark"] always applies regardless of OS
 *     preference.
 */

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        /* --color-accent/--color-accent-hover deliberately NOT overridden —
           the light-mode blue (#2563eb) already gives white button text a
           5.17:1 contrast ratio against itself, comfortably passing WCAG
           AA, and keeps the same brand blue in both themes per the
           ticket's "keep existing Guepardo/Transport System blue". */
        --color-success: #34d399;
        --color-success-bg: #052e1b;
        --color-warning: #fbbf24;
        --color-warning-bg: #452505;
        --color-danger: #f87171;
        --color-danger-bg: #450a0a;
        --color-info: #38bdf8;
        --color-info-bg: #0c3a52;

        --color-bg: #111827;
        --color-surface: #1f2937;
        --color-surface-subtle: #263244;
        --color-neutral-bg: #374151;
        --color-text: #f3f4f6;
        --color-text-muted: #9ca3af;
        --color-border: #4b5563;

        --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4);
        --shadow-elevated: 0 8px 24px rgba(0, 0, 0, 0.5);
    }
}

:root[data-theme="dark"] {
    --color-success: #34d399;
    --color-success-bg: #052e1b;
    --color-warning: #fbbf24;
    --color-warning-bg: #452505;
    --color-danger: #f87171;
    --color-danger-bg: #450a0a;
    --color-info: #38bdf8;
    --color-info-bg: #0c3a52;

    --color-bg: #111827;
    --color-surface: #1f2937;
    --color-surface-subtle: #263244;
    --color-neutral-bg: #374151;
    --color-text: #f3f4f6;
    --color-text-muted: #9ca3af;
    --color-border: #4b5563;

    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-elevated: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* -- Bootstrap's own chrome (modals, dropdowns, alerts, pagination, form
   controls) gets its dark styling from Bootstrap 5.3's native color-mode
   support — assets/js/theme.js mirrors data-theme onto data-bs-theme so
   both systems stay in sync from one source of truth. Only a few
   Bootstrap surfaces need a nudge to match our surface tokens exactly
   rather than Bootstrap's own default dark gray. Written once and reused
   under both the explicit-dark and System-preference selectors below. */
:root[data-theme="dark"] .modal-content,
:root[data-theme="dark"] .form-control,
:root[data-theme="dark"] .form-select,
:root[data-theme="dark"] .form-control:focus,
:root[data-theme="dark"] .form-select:focus {
    background-color: var(--color-surface);
    color: var(--color-text);
}
:root[data-theme="dark"] .form-control,
:root[data-theme="dark"] .form-select,
:root[data-theme="dark"] .dropdown-menu {
    border-color: var(--color-border);
}
:root[data-theme="dark"] .dropdown-menu {
    background-color: var(--color-surface);
}
:root[data-theme="dark"] .table {
    color: var(--color-text);
}
/* Skeleton loading placeholder's middle stop needs a touch more contrast against the darker surface. */
:root[data-theme="dark"] .skeleton {
    background: linear-gradient(90deg, var(--color-neutral-bg) 25%, var(--color-surface-subtle) 37%, var(--color-neutral-bg) 63%);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .modal-content,
    :root:not([data-theme="light"]) .form-control,
    :root:not([data-theme="light"]) .form-select,
    :root:not([data-theme="light"]) .form-control:focus,
    :root:not([data-theme="light"]) .form-select:focus {
        background-color: var(--color-surface);
        color: var(--color-text);
    }
    :root:not([data-theme="light"]) .form-control,
    :root:not([data-theme="light"]) .form-select,
    :root:not([data-theme="light"]) .dropdown-menu {
        border-color: var(--color-border);
    }
    :root:not([data-theme="light"]) .dropdown-menu {
        background-color: var(--color-surface);
    }
    :root:not([data-theme="light"]) .table {
        color: var(--color-text);
    }
    :root:not([data-theme="light"]) .skeleton {
        background: linear-gradient(90deg, var(--color-neutral-bg) 25%, var(--color-surface-subtle) 37%, var(--color-neutral-bg) 63%);
    }
}

/* Header navigation: the navy rows are identical in both themes; only the
   white dropdown/search/notification panels follow the surface tokens (they
   already do), plus a lighter blue for active text on dark surfaces. */
:root[data-theme="dark"] {
    --nav-accent-text: #60a5fa;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --nav-accent-text: #60a5fa;
    }
}
