/*
 * Bridge — shared theme tokens.
 *
 * Light theme: the legacy page variables below keep exactly the values every
 * page already declared, so light rendering is unchanged.
 *
 * The other semantic tokens (--surface-*, --text-strong, --*-bg, --*-text,
 * --*-border, …) are only defined for the dark theme. Call sites always use
 * them with their original light colour as fallback, e.g.
 *     background: var(--green-bg, #DEF7EC);
 * so light stays pixel-identical while dark gets a consistent palette.
 *
 * The theme is selected with <html data-theme="dark|light">, set before first
 * paint by brand_head.html and live-updated by static/js/hub-theme.js.
 */

:root {
    --bg-page: #F9FAFB;
    --bg-white: #FFFFFF;
    --bg-thead: #F9FBFC;
    --text-dark: #0A0A0A;
    --text-body: #4A5565;
    --text-secondary: #6A7282;
    --text-header: #364153;
    --border-color: #E5E7EB;
    --blue-primary: #3B82F6;
    --blue-hover: #2563EB;
}

html[data-theme="dark"] {
    color-scheme: dark;

    /* Legacy page variables (index, nouvelle_mission, esn_form, bulk, error) */
    --bg-page: #0F1115;
    --bg-white: #171A21;          /* surface: cards, tables, modals */
    --bg-thead: #1B1F27;
    --text-dark: #F3F4F6;
    --text-body: #C4CAD4;
    --text-secondary: #9AA3B2;
    --text-header: #D5DAE1;
    --border-color: #2A303B;
    --blue-primary: #3B82F6;
    --blue-hover: #2563EB;
    --green-primary: #10B981;

    /* login.html variables */
    --bg: #0F1115;
    --card-bg: #171A21;
    --text-main: #F3F4F6;
    --text-muted: #9AA3B2;
    --primary: #60A5FA;
    --primary-hover: #93C5FD;

    /* Neutral surfaces & text */
    --surface-subtle: #1B1F27;    /* table hover, footers, soft panels */
    --surface-muted: #232833;     /* chips, secondary buttons */
    --surface-strong: #2D3340;    /* tracks, separators used as fills */
    --surface-raised: #1E222B;    /* dropdowns, popovers */
    --input-bg: #12151B;
    --disabled-bg: #3D4554;
    --text-strong: #E5E7EB;
    --text-faint: #6B7385;
    --border-subtle: #232833;
    --border-strong: #3D4554;
    --overlay: rgba(0, 0, 0, 0.65);
    --focus-ring-soft: rgba(255, 255, 255, 0.10);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 40px -8px rgba(0, 0, 0, 0.6);

    /* Status families: tinted background / readable text / border */
    --blue-bg: rgba(59, 130, 246, 0.14);
    --blue-bg-strong: rgba(59, 130, 246, 0.22);
    --blue-text: #93C5FD;
    --blue-border: rgba(59, 130, 246, 0.40);

    --sky-bg: rgba(14, 165, 233, 0.14);
    --sky-text: #7DD3FC;
    --sky-border: rgba(14, 165, 233, 0.40);

    --green-bg: rgba(16, 185, 129, 0.15);
    --green-text: #6EE7B7;
    --green-border: rgba(16, 185, 129, 0.40);

    --amber-bg: rgba(245, 158, 11, 0.15);
    --amber-text: #FCD34D;
    --amber-border: rgba(245, 158, 11, 0.40);

    --orange-bg: rgba(249, 115, 22, 0.15);
    --orange-text: #FDBA74;
    --orange-border: rgba(249, 115, 22, 0.40);

    --red-bg: rgba(239, 68, 68, 0.15);
    --red-bg-strong: rgba(239, 68, 68, 0.26);
    --red-text: #FCA5A5;
    --red-border: rgba(239, 68, 68, 0.40);

    --indigo-bg: rgba(99, 102, 241, 0.18);
    --indigo-text: #A5B4FC;
    --indigo-border: rgba(99, 102, 241, 0.45);

    --purple-bg: rgba(139, 92, 246, 0.18);
    --purple-text: #C4B5FD;
    --purple-border: rgba(139, 92, 246, 0.45);

    --pink-bg: rgba(217, 70, 143, 0.16);
    --pink-text: #F9A8D4;
    --pink-border: rgba(217, 70, 143, 0.45);
}

/*
 * Dark-only element defaults. Wrapped in :where() so they carry no
 * specificity: any explicit page rule still wins; these only fill the gaps
 * (unstyled inputs, placeholders, scrollbars, selection…).
 */
:where(html[data-theme="dark"]) body {
    background-color: var(--bg-page);
    color: var(--text-dark);
}

:where(html[data-theme="dark"]) :where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="submit"], [type="button"]), select, textarea) {
    background-color: var(--input-bg);
    color: var(--text-dark);
    border-color: var(--border-strong);
}

:where(html[data-theme="dark"]) :where(input, textarea)::placeholder {
    color: var(--text-faint);
    opacity: 1;
}

:where(html[data-theme="dark"]) :where(input, select, textarea, button):disabled {
    opacity: 0.6;
}

:where(html[data-theme="dark"]) option {
    background-color: var(--surface-raised);
    color: var(--text-dark);
}

:where(html[data-theme="dark"]) input:-webkit-autofill {
    -webkit-text-fill-color: var(--text-dark);
    -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset;
    caret-color: var(--text-dark);
}

:where(html[data-theme="dark"]) ::selection {
    background: rgba(59, 130, 246, 0.45);
    color: #FFFFFF;
}

:where(html[data-theme="dark"]) a:not([class]) {
    color: #93C5FD;
}

html[data-theme="dark"] {
    scrollbar-color: #3D4554 var(--bg-page);
}

:where(html[data-theme="dark"]) ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

:where(html[data-theme="dark"]) ::-webkit-scrollbar-track {
    background: var(--bg-page);
}

:where(html[data-theme="dark"]) ::-webkit-scrollbar-thumb {
    background: #3D4554;
    border-radius: 6px;
    border: 2px solid var(--bg-page);
}

:where(html[data-theme="dark"]) ::-webkit-scrollbar-thumb:hover {
    background: #4B5466;
}

/* Raster images (profile photos) look harsh on dark: soften slightly. */
:where(html[data-theme="dark"]) img:not([src$=".svg"]) {
    filter: brightness(0.92);
}

/*
 * Smooth switch: hub-theme.js adds .theme-transition for ~250 ms around a
 * live theme change only, so regular hover/animation transitions are not
 * affected. Disabled for users asking for reduced motion.
 */
@media (prefers-reduced-motion: no-preference) {
    html.theme-transition,
    html.theme-transition *,
    html.theme-transition *::before,
    html.theme-transition *::after {
        transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease,
            fill 200ms ease, stroke 200ms ease, box-shadow 200ms ease !important;
    }
}
