/**
 * Premarke Design System v3
 * Calm, precise, accessible. Light and dark themes (dark = html.dark-mode).
 * Pages should only use the tokens and components defined here.
 */

/* ===== TOKENS: LIGHT (default) ===== */
/* Manrope, self-hosted variable font (weights 200–800). SIL Open Font License: /assets/fonts/manrope/OFL.txt */
@font-face {
    font-family: "Manrope";
    font-style: normal;
    font-weight: 200 800;
    font-display: swap;
    src: url("/assets/fonts/manrope/manrope-latin-ext-wght-normal.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "Manrope";
    font-style: normal;
    font-weight: 200 800;
    font-display: swap;
    src: url("/assets/fonts/manrope/manrope-latin-wght-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    color-scheme: light;

    /* Brand */
    --primary: #047857;
    --primary-hover: #065F46;
    --primary-soft: rgba(4, 120, 87, 0.10);
    --primary-light: var(--primary-soft);      /* legacy alias */
    --primary-dark: #065F46;                    /* legacy alias */
    --primary-glow: transparent;                /* legacy alias: glows are disabled */
    --on-primary: #FFFFFF;

    --secondary: #3B4A63;
    --secondary-light: rgba(59, 74, 99, 0.10);
    --secondary-dark: #1F2A3C;
    --secondary-glow: transparent;
    --accent: #1D4ED8;
    --accent-light: rgba(29, 78, 216, 0.10);
    --accent-glow: transparent;

    /* Outcomes */
    --yes: #047857;
    --yes-hover: #065F46;
    --yes-soft: rgba(4, 120, 87, 0.10);
    --no: #B91C1C;
    --no-hover: #991B1B;
    --no-soft: rgba(185, 28, 28, 0.09);

    /* Surfaces */
    --bg-base: #F6F7F9;
    --bg-subtle: #F9FAFB;
    --bg-card: #FFFFFF;
    --bg-elevated: #FFFFFF;
    --bg-muted: #F1F3F6;
    --bg-hover: #EEF1F5;

    /* Text */
    --text-primary: #0B1220;
    --text-secondary: #475467;
    --text-muted: #667085;

    /* Borders */
    --border-light: #E4E7EC;
    --border-medium: #D0D5DD;

    /* Status */
    --success: #047857;
    --success-soft: rgba(4, 120, 87, 0.10);
    --error: #B91C1C;
    --error-soft: rgba(185, 28, 28, 0.08);
    --warning: #B45309;
    --warning-soft: rgba(180, 83, 9, 0.10);
    --info: #1D4ED8;
    --info-soft: rgba(29, 78, 216, 0.08);

    /*
     * Status text sitting ON its own soft tint (badges, pills).
     * The tint lifts the background, so a colour that clears 4.5:1 against the page can fall under
     * it inside a badge: --success measured 4.45:1 and --warning 4.10:1 there at 13px. These are
     * the same hues a shade deeper, used only where the soft background is behind the text, so the
     * brand colours themselves are untouched. Dark theme never had the problem (7.9 and 9.3).
     */
    --success-on-soft: #047655;
    --error-on-soft: var(--error);
    --warning-on-soft: #A74D08;
    --info-on-soft: var(--info);

    /* Legacy aliases still referenced by some page styles (theme-aware) */
    --white: var(--bg-card);
    --black: var(--text-primary);
    --border: var(--border-light);
    --success-light: var(--success-soft);
    --error-light: var(--error-soft);
    --warning-light: var(--warning-soft);
    --info-light: var(--info-soft);
    --gray-50: var(--bg-subtle);
    --gray-100: var(--bg-muted);
    --gray-200: var(--border-light);
    --gray-300: var(--border-medium);
    --gray-400: var(--text-muted);
    --gray-500: var(--text-muted);
    --gray-600: var(--text-secondary);
    --gray-700: var(--text-secondary);
    --gray-800: var(--text-primary);
    --gray-900: var(--text-primary);

    /* Focus */
    --focus-ring: 0 0 0 3px rgba(4, 120, 87, 0.45);

    /* Typography */
    --font-family: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

    --text-xs: 0.8125rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;
    --text-5xl: 3rem;
    --text-6xl: 3.5rem;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;
    --space-20: 5rem;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-xl: 12px;
    --radius-2xl: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 2px 6px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-lg: 0 8px 20px rgba(16, 24, 40, 0.08), 0 2px 6px rgba(16, 24, 40, 0.04);
    --shadow-xl: 0 16px 40px rgba(16, 24, 40, 0.12), 0 4px 10px rgba(16, 24, 40, 0.05);
    --shadow-glow: none;

    /* Layout */
    --container-max: 1200px;
    --nav-height: 4rem;

    /* Motion */
    --transition-fast: 120ms ease;
    --transition-normal: 200ms ease;
    --transition-slow: 300ms ease;
}

/* ===== TOKENS: DARK ===== */
.dark-mode {
    color-scheme: dark;

    --primary: #10B981;
    --primary-hover: #34D399;
    --primary-soft: rgba(16, 185, 129, 0.14);
    --primary-dark: #059669;
    --on-primary: #03140D;

    --secondary: #A5B4CB;
    --secondary-light: rgba(165, 180, 203, 0.12);
    --accent: #7AA2F7;
    --accent-light: rgba(122, 162, 247, 0.14);

    --yes: #34D399;
    --yes-hover: #6EE7B7;
    --yes-soft: rgba(52, 211, 153, 0.14);
    --no: #F87171;
    --no-hover: #FCA5A5;
    --no-soft: rgba(248, 113, 113, 0.14);

    --bg-base: #0B0F16;
    --bg-subtle: #0F141C;
    --bg-card: #121821;
    --bg-elevated: #171E29;
    --bg-muted: #1A2230;
    --bg-hover: #202938;

    --text-primary: #F2F4F7;
    --text-secondary: #B3BCC9;
    --text-muted: #8A96A8;

    --border-light: #232C3A;
    --border-medium: #313C4D;

    --success: #34D399;
    --success-soft: rgba(52, 211, 153, 0.14);
    --error: #F87171;
    --error-soft: rgba(248, 113, 113, 0.14);
    --warning: #FBBF24;
    --warning-soft: rgba(251, 191, 36, 0.12);
    --info: #7AA2F7;
    --info-soft: rgba(122, 162, 247, 0.14);

    /* Dark badges already clear AA comfortably, so the text keeps the plain status colour. */
    --success-on-soft: var(--success);
    --error-on-soft: var(--error);
    --warning-on-soft: var(--warning);
    --info-on-soft: var(--info);

    --focus-ring: 0 0 0 3px rgba(52, 211, 153, 0.5);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.55);
}

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

html {
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    font-weight: 400;
    color: var(--text-primary);
    background: var(--bg-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

body > main, body > .page { flex: 1 0 auto; }

h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.015em;
}

p { color: var(--text-secondary); }

a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }

img, svg { max-width: 100%; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus { outline: none; }
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

::selection {
    background: var(--primary-soft);
    color: var(--text-primary);
}

/* Show content once scripts render the nav; always show after 1.2s even if JS fails */
body.prevent-skeleton-flash:not(.content-ready) {
    opacity: 0;
    animation: sm-reveal 0s linear 1.2s forwards;
}
body.prevent-skeleton-flash.content-ready {
    opacity: 1;
    transition: opacity 150ms ease-in;
}
@keyframes sm-reveal { to { opacity: 1; } }

.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

.skip-link {
    position: absolute;
    left: var(--space-4);
    top: -100px;
    z-index: 1000;
    background: var(--bg-card);
    color: var(--text-primary);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}
.skip-link:focus { top: var(--space-2); }

/* ===== LAYOUT ===== */
.container {
    width: 100%;
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 var(--space-6);
}
.container-md { max-width: 880px; }

.page {
    padding-top: var(--space-8);
    padding-bottom: var(--space-16);
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-8);
}

.page-title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.page-subtitle {
    margin-top: var(--space-2);
    font-size: var(--text-base);
    color: var(--text-secondary);
}

.section { margin-bottom: var(--space-10); }

.section-title {
    font-size: var(--text-lg);
    font-weight: 700;
    margin-bottom: var(--space-4);
}

.eyebrow {
    display: inline-block;
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary);
}

/* ===== NAVIGATION ===== */
.navbar {
    height: var(--nav-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    height: 100%;
}

.navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    text-decoration: none;
    color: var(--text-primary);
    flex-shrink: 0;
}
.navbar-brand:hover { color: var(--text-primary); }

.brand-mark { width: 28px; height: 28px; display: block; }

.brand-wordmark { display: block; height: 22px; width: auto; color: var(--text-primary); }
.site-footer .brand-wordmark { height: 20px; }

.navbar-menu {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    list-style: none;
    margin-right: auto;
    margin-left: var(--space-6);
}

.navbar-menu a {
    display: inline-flex;
    align-items: center;
    height: 2.25rem;
    padding: 0 var(--space-3);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: var(--text-sm);
    transition: color var(--transition-fast), background-color var(--transition-fast);
}
.navbar-menu a:hover { color: var(--text-primary); background: var(--bg-muted); }
.navbar-menu a.active,
.navbar-menu a[aria-current="page"] { color: var(--text-primary); background: var(--bg-muted); font-weight: 600; }

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

.navbar .navbar-toggle { display: none; }

.nav-notifications { position: relative; }
.nav-unread-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 1.125rem;
    height: 1.125rem;
    padding: 0 0.25rem;
    border-radius: var(--radius-full);
    background: var(--primary);
    color: var(--on-primary);
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1.125rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 0 0 2px var(--bg-card);
    pointer-events: none;
}

.mobile-menu {
    display: none;
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99;
    background: var(--bg-card);
    border-top: 1px solid var(--border-light);
    padding: var(--space-4) var(--space-4) var(--space-8);
    overflow-y: auto;
}
.mobile-menu.open { display: block; }
.mobile-menu ul { list-style: none; }
.mobile-menu a,
.mobile-menu button.mobile-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-3) var(--space-3);
    border: 0;
    background: none;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-base);
    font-weight: 500;
    text-decoration: none;
    text-align: left;
    cursor: pointer;
}
.mobile-menu a:hover, .mobile-menu button.mobile-menu-item:hover { background: var(--bg-muted); }
.mobile-menu a[aria-current="page"] { background: var(--bg-muted); font-weight: 600; }
.mobile-menu-divider { height: 1px; background: var(--border-light); margin: var(--space-3) 0; }
.mobile-menu-actions { display: grid; gap: var(--space-2); margin-top: var(--space-4); }
body.menu-open { overflow: hidden; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 2.5rem;
    padding: 0 var(--space-4);
    font-family: var(--font-family);
    font-size: var(--text-sm);
    font-weight: 600;
    line-height: 1.2;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn .icon { width: 1rem; height: 1rem; }

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

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border-medium);
    box-shadow: var(--shadow-sm);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-muted); color: var(--text-primary); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-muted); color: var(--text-primary); }

.btn-danger { background: var(--error); color: #FFFFFF; }
.dark-mode .btn-danger { color: #1A0505; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.92); }

.btn-yes { background: var(--yes-soft); color: var(--yes); border-color: transparent; }
.btn-yes:hover:not(:disabled), .btn-yes.selected, .btn-yes[aria-pressed="true"] { background: var(--yes); color: var(--on-primary); }
.btn-no { background: var(--no-soft); color: var(--no); border-color: transparent; }
.btn-no:hover:not(:disabled), .btn-no.selected, .btn-no[aria-pressed="true"] { background: var(--no); color: #FFFFFF; }
.dark-mode .btn-no:hover:not(:disabled), .dark-mode .btn-no.selected, .dark-mode .btn-no[aria-pressed="true"] { color: #1A0505; }

.btn-sm { min-height: 2rem; padding: 0 var(--space-3); font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn-lg { min-height: 3rem; padding: 0 var(--space-6); font-size: var(--text-base); }
.btn-block { width: 100%; }
.btn-icon { width: 2.5rem; padding: 0; }
.btn-icon.btn-sm { width: 2rem; }

/* ===== USER MENU ===== */
.user-menu { position: relative; }

.user-button {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2) var(--space-1) var(--space-1);
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-full);
    cursor: pointer;
    color: var(--text-secondary);
}
.user-button:hover { background: var(--bg-muted); }
.user-button:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full);
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--text-xs);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    min-width: 240px;
    z-index: 110;
    display: none;
}
.user-dropdown.open { display: block; }

.user-dropdown-header { padding: var(--space-4); border-bottom: 1px solid var(--border-light); }
.user-dropdown-name { font-weight: 600; color: var(--text-primary); }
.user-dropdown-email { font-size: var(--text-sm); color: var(--text-muted); overflow-wrap: anywhere; }
.user-dropdown-role { font-size: var(--text-xs); color: var(--primary); font-weight: 600; margin-top: var(--space-1); }
.user-dropdown-menu { padding: var(--space-2); }

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: none;
    border: none;
    border-radius: var(--radius-md);
    text-align: left;
    text-decoration: none;
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
}
.user-dropdown-item:hover { background: var(--bg-muted); color: var(--text-primary); }
.user-dropdown-item .icon { width: 1rem; height: 1rem; color: var(--text-muted); }
.user-dropdown-item.logout-btn { color: var(--error); }
.user-dropdown-item.logout-btn .icon { color: var(--error); }
.user-dropdown-divider { height: 1px; background: var(--border-light); margin: var(--space-2) 0; }

/* ===== FOOTER ===== */
.site-footer {
    margin-top: auto;
    border-top: 1px solid var(--border-light);
    background: var(--bg-card);
    padding: var(--space-10) 0 var(--space-8);
    font-size: var(--text-sm);
}
.site-footer-grid {
    display: grid;
    grid-template-columns: 2fr repeat(3, 1fr);
    gap: var(--space-8);
}
.site-footer h2 {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: var(--space-3);
    font-weight: 600;
}
.site-footer ul { list-style: none; display: grid; gap: var(--space-2); }
.site-footer a { color: var(--text-secondary); text-decoration: none; }
.site-footer a:hover { color: var(--text-primary); }
.site-footer-about { color: var(--text-secondary); max-width: 36ch; margin-top: var(--space-3); }
.site-footer ul.site-footer-social { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.site-footer-social a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    transition: color var(--transition-fast), border-color var(--transition-fast), background-color var(--transition-fast);
}
.site-footer-social a:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.site-footer-social .icon { width: 1rem; height: 1rem; }
.site-footer-handle { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }
.site-footer-bottom {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-8);
    padding-top: var(--space-6);
    border-top: 1px solid var(--border-light);
    color: var(--text-muted);
}
.site-footer-bottom p { color: var(--text-muted); }

/* ===== CARDS ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}
.card-interactive { transition: border-color var(--transition-fast), box-shadow var(--transition-fast); }
.card-interactive:hover { border-color: var(--border-medium); box-shadow: var(--shadow-md); }
.card-header { padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--border-light); }
.card-title { font-size: var(--text-base); font-weight: 700; }
.card-subtitle { font-size: var(--text-sm); color: var(--text-secondary); margin-top: var(--space-1); }
.card-body { padding: var(--space-6); }
.card-footer { padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border-light); background: var(--bg-subtle); border-radius: 0 0 var(--radius-xl) var(--radius-xl); }

/* ===== FORMS ===== */
.form-group { margin-bottom: var(--space-5); }

.form-label {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
    font-size: var(--text-sm);
}
.form-label .optional { color: var(--text-muted); font-weight: 400; }

.form-input, .form-select, .form-textarea {
    width: 100%;
    /* An <input> carries an intrinsic width from its `size` attribute, and a grid or flex child
       will not shrink past its intrinsic minimum. Inside a one-column .form-row at 320px that made
       the field wider than its track and pushed the whole page sideways, even though width:100%
       says otherwise. */
    min-width: 0;
    min-height: 2.75rem;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-card);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: var(--text-base);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-select {
    appearance: none;
    padding-right: 2.25rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
}
.form-select option { background: var(--bg-card); color: var(--text-primary); }

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-muted); opacity: 1; }
.form-input:disabled, .form-input[readonly] { background: var(--bg-muted); color: var(--text-secondary); cursor: not-allowed; }
.form-input[aria-invalid="true"] { border-color: var(--error); }

.form-help { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-2); }
.form-error { font-size: var(--text-sm); color: var(--error); margin-top: var(--space-2); }

.input-group { position: relative; display: flex; align-items: stretch; }
.input-group .form-input { flex: 1; }
.input-group .input-addon {
    display: flex;
    align-items: center;
    padding: 0 var(--space-3);
    color: var(--text-secondary); /* --text-muted on --bg-muted is below 4.5:1 */
    font-size: var(--text-sm);
    font-weight: 600;
    border: 1px solid var(--border-medium);
    background: var(--bg-muted);
}
.input-group .input-addon:last-child { border-left: 0; border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.input-group .input-addon:first-child { border-right: 0; border-radius: var(--radius-md) 0 0 var(--radius-md); }
.input-group .input-addon:last-child ~ .form-input,
.input-group .form-input:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }

.form-check {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    cursor: pointer;
    /* The label is the target for the checkbox inside it, and a single line of text made that
       target 21px tall — under the 24px WCAG 2.2 (2.5.8) minimum. Rows with more text are already
       taller, so this only lifts the short ones. */
    min-height: 1.5rem;
}
.form-check input[type="checkbox"], .form-check input[type="radio"] {
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0.15rem;
    accent-color: var(--primary);
    flex-shrink: 0;
    cursor: pointer;
}

/* Legacy glass/glow helpers are now plain surfaces */

/* ===== ICONS ===== */
.icon {
    width: 1.25rem;
    height: 1.25rem;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}
.icon-sm { width: 1rem; height: 1rem; }

.icon-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-lg);
    background: var(--primary-soft);
    color: var(--primary);
    flex-shrink: 0;
}

/* ===== TOASTS ===== */
.toast-container {
    position: fixed;
    top: calc(var(--nav-height) + var(--space-3));
    right: var(--space-4);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: min(380px, calc(100vw - 2rem));
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-left: 3px solid var(--text-muted);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: toast-in 160ms ease-out;
    pointer-events: auto;
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--error); }
.toast-warning { border-left-color: var(--warning); }
.toast-info { border-left-color: var(--info); }
.toast-icon { display: flex; margin-top: 1px; }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--error); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--info); }
.toast-content { flex: 1; min-width: 0; }
.toast-title { font-weight: 600; font-size: var(--text-sm); color: var(--text-primary); }
.toast-message { font-size: var(--text-sm); color: var(--text-secondary); line-height: 1.45; overflow-wrap: anywhere; }
.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    border-radius: var(--radius-sm);
    display: flex;
}
.toast-close:hover { background: var(--bg-muted); color: var(--text-primary); }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== BADGES ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 0.125rem var(--space-2);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    background: var(--bg-muted);
    color: var(--text-secondary);
}
.badge .icon { width: 0.75rem; height: 0.75rem; }
.badge-success, .badge-primary { background: var(--success-soft); color: var(--success-on-soft); }
.badge-error { background: var(--error-soft); color: var(--error-on-soft); }
.badge-warning { background: var(--warning-soft); color: var(--warning-on-soft); }
.badge-info { background: var(--info-soft); color: var(--info-on-soft); }
.badge-neutral, .badge-secondary { background: var(--bg-muted); color: var(--text-secondary); }
.admin-badge { background: var(--bg-muted); color: var(--text-secondary); }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ===== TABS ===== */
.tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--border-light);
    overflow-x: auto;
    scrollbar-width: none;
    margin-bottom: var(--space-6);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-3);
    margin-bottom: -1px;
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
}
.tab:hover { color: var(--text-primary); }
.tab.active, .tab[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab .icon { width: 1rem; height: 1rem; }

/* Segmented control (pill style) */
.segmented {
    display: inline-flex;
    padding: 3px;
    background: var(--bg-muted);
    border-radius: var(--radius-lg);
    gap: 2px;
    max-width: 100%;
    overflow-x: auto;
}
.segmented button {
    border: 0;
    background: none;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}
.segmented button.active, .segmented button[aria-selected="true"] {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

/* ===== TABLES ===== */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    background: var(--bg-card);
}
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th {
    text-align: left;
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-subtle);
    white-space: nowrap;
}
.table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--bg-subtle); }
.table .text-right, .table th.text-right { text-align: right; }

/* ===== STATS ===== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-4);
}
.stat {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    min-width: 0;
}
.stat-label { font-size: var(--text-sm); color: var(--text-secondary); font-weight: 500; }
.stat-value {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-top: var(--space-1);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
    letter-spacing: -0.02em;
}
.stat-sub { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-1); }

/* Probability bar */
.prob-bar {
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--no-soft);
    overflow: hidden;
}
.prob-bar > span { display: block; height: 100%; background: var(--yes); border-radius: inherit; }

/* ===== ALERTS ===== */
.alert {
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    background: var(--bg-subtle);
    color: var(--text-primary);
    font-size: var(--text-sm);
}
.alert .icon { width: 1.125rem; height: 1.125rem; margin-top: 1px; }
.alert-title { font-weight: 600; }
.alert p { color: inherit; }
.alert-info { background: var(--info-soft); border-color: transparent; }
.alert-info .icon { color: var(--info); }
.alert-success { background: var(--success-soft); border-color: transparent; }
.alert-success .icon { color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: transparent; }
.alert-warning .icon { color: var(--warning); }
.alert-error { background: var(--error-soft); border-color: transparent; }
.alert-error .icon { color: var(--error); }

/* ===== EMPTY / LOADING ===== */
.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    color: var(--text-secondary);
}
.empty-state-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border-radius: var(--radius-full);
    background: var(--bg-muted);
    color: var(--text-muted);
    margin-bottom: var(--space-4);
}
.empty-state-icon .icon { width: 1.5rem; height: 1.5rem; }
.empty-state-title { font-size: var(--text-base); font-weight: 600; color: var(--text-primary); }
.empty-state-text { margin: var(--space-2) auto 0; max-width: 42ch; font-size: var(--text-sm); color: var(--text-secondary); }
.empty-state .btn { margin-top: var(--space-5); }

.skeleton {
    display: block;
    background: linear-gradient(90deg, var(--bg-muted) 25%, var(--bg-hover) 50%, var(--bg-muted) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s ease-in-out infinite;
    border-radius: var(--radius-md);
    min-height: 1em;
}

.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}

/* ===== MODAL ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(11, 18, 32, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}
.modal-backdrop[hidden] { display: none; }
.modal {
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
}
.modal-header { padding: var(--space-5) var(--space-6) 0; }
.modal-title { font-size: var(--text-lg); font-weight: 700; }
.modal-body { padding: var(--space-4) var(--space-6); color: var(--text-secondary); font-size: var(--text-sm); }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-6) var(--space-5);
}

/* Key/value list */
.kv { display: grid; gap: var(--space-2); font-size: var(--text-sm); }
.kv-row { display: flex; justify-content: space-between; gap: var(--space-4); }
.kv-row dt, .kv-row .kv-label { color: var(--text-secondary); }
.kv-row dd, .kv-row .kv-value { color: var(--text-primary); font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* ===== UTILITIES ===== */
.num { font-variant-numeric: tabular-nums; }
.table td, dd { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: 0.925em; overflow-wrap: anywhere; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.text-center { text-align: center; }
.text-right { text-align: right; }

.font-semibold { font-weight: 600; }

.text-primary { color: var(--primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-success { color: var(--success) !important; }
.text-error { color: var(--error) !important; }
.text-yes { color: var(--yes) !important; }
.text-no { color: var(--no) !important; }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }

.rounded { border-radius: var(--radius-md); }

.shadow { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }

.grid { display: grid; }

.hidden { display: none !important; }
[hidden] { display: none !important; }
.block { display: block; }

/* ===== ANIMATIONS (kept subtle) ===== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
/* legacy names: no-ops so old markup doesn't glow or float */
@keyframes pulse-glow { from { opacity: 1; } to { opacity: 1; } }
@keyframes float { from { transform: none; } to { transform: none; } }
@keyframes gradient-shift { from { opacity: 1; } to { opacity: 1; } }

@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;
    }
}

/*
 * Higher contrast on request (Windows high-contrast, macOS "Increase contrast").
 *
 * The palette already clears WCAG AA everywhere, so this is not a fallback for a failing theme:
 * it firms up the parts that are deliberately quiet — hairline borders, muted secondary text and
 * the soft tints behind badges — for people who have asked the operating system for more.
 */
@media (prefers-contrast: more) {
    :root,
    :root.dark-mode {
        --border-light: var(--border-medium);
        --text-muted: var(--text-secondary);
    }

    .badge, .btn-secondary, .card, .form-input, .form-select {
        border-width: 2px;
    }

    .prob-bar { outline: 1px solid var(--border-medium); }
}

/*  ===== RESPONSIVE =====
    One breakpoint scale for the whole public site. Pages define their own layout rules in their
    <head>, but only at these widths, so a layout never changes shape at a width nothing else does.

      1024  wide two-column layouts stack (market detail aside, guide contents, footer)
       900  the navigation collapses into the hamburger, and side-by-side page layouts stack.
             assets/js/modern-nav.js mirrors this as NAV_COLLAPSE_WIDTH
       768  tablet: container padding and heading sizes come down
       640  phone: form rows, button rows and card grids go to a single column
       480  small phone: tighter padding, smaller figures
*/
@media (max-width: 1024px) {
    .site-footer-grid { grid-template-columns: 1fr 1fr; }
    .site-footer-brand { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
    .navbar-menu { display: none; }
    .navbar-actions .nav-desktop-only { display: none; }
    .navbar .navbar-toggle { display: inline-flex; }
}

@media (max-width: 768px) {
    .container { padding: 0 var(--space-4); }
    .page { padding-top: var(--space-6); padding-bottom: var(--space-12); }
    .page-title { font-size: var(--text-2xl); }
        .card-body { padding: var(--space-5); }
    .card-header { padding: var(--space-4) var(--space-5); }
    .modal-backdrop { align-items: flex-end; padding: 0; }
    .modal { max-width: none; border-radius: var(--radius-2xl) var(--radius-2xl) 0 0; }
    .toast-container { left: var(--space-4); right: var(--space-4); width: auto; }
}

@media (max-width: 480px) {
    .site-footer-grid { grid-template-columns: 1fr 1fr; gap: var(--space-6); }
    .site-footer-bottom { flex-direction: column; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .stat { padding: var(--space-4); }
    .stat-value { font-size: var(--text-xl); }
}

/* ===== SCROLLBAR ===== */
* { scrollbar-color: var(--border-medium) transparent; }
