/* ============================================================
   MFD Buddy — design-tokens.css  (REFACTORED — June 2026)

   ARCHITECTURE PRINCIPLE:
   Every colour, shadow, and spacing value used anywhere in the app
   must be defined here as a semantic token, then referenced by
   var(). No hardcoded hex values anywhere in style.css or
   component CSS. Templates should only use these variables.

   TOKEN TIERS:
   1. Primitive tokens  — raw values, referenced ONLY by semantic tokens
   2. Semantic tokens   — what components use (surface-0/1/2, text-1/2/muted, etc.)
   3. Component tokens  — optional, derived from semantic for specific components

   DARK MODE:
   A single override block on html[data-theme="dark"] flips all
   semantic tokens. Components never need their own dark-mode rule
   if they use only semantic tokens.
   ============================================================ */


/* ──────────────────────────────────────────────────────────────
   TIER 1 — PRIMITIVE PALETTE  (never use in components directly)
   ────────────────────────────────────────────────────────────── */
:root {
  /* Brand navy scale */
  --_navy-900: #050412;   /* deepest — body bg dark */
  --_navy-800: #07060f;   /* very deep */
  --_navy-700: #0a0820;   /* deep */
  --_navy-600: #0f0c29;   /* standard surface-1 dark */
  --_navy-500: #1a1550;   /* elevated surface-2 dark */
  --_navy-400: #241e6b;   /* hover states dark */

  /* Brand gold scale */
  --_gold-600: #a07f10;   /* deep, AA-safe on cream */
  --_gold-500: #c9a227;   /* standard gold, AA on cream */
  --_gold-400: #d4a843;   /* warm mid */
  --_gold-300: #e8c84a;   /* primary accent */
  --_gold-200: #f5d96b;   /* soft highlight */
  --_gold-100: #fff8dc;   /* tint, light bg use only */
  --_gold-50:  #fdf9ee;   /* near-white cream */

  /* Brand cream scale */
  --_cream-100: #fdf9ee;
  --_cream-200: #f5edcc;
  --_cream-300: #ede5b8;

  /* Status primitives */
  --_green-900: #064e3b;
  --_green-800: #065f46;
  --_green-600: #059669;
  --_green-400: #34d399;
  --_green-300: #4ade80;
  --_green-100: #d1fae5;

  --_amber-900: #78350f;
  --_amber-800: #92400e;
  --_amber-600: #d97706;
  --_amber-400: #fbbf24;
  --_amber-200: #fde68a;
  --_amber-100: #fef3c7;

  --_red-900:  #7f1d1d;
  --_red-600:  #dc2626;
  --_red-400:  #f87171;
  --_red-100:  #fee2e2;

  --_blue-900: #1e3a5f;
  --_blue-600: #1d4ed8;
  --_blue-400: #60a5fa;
  --_blue-200: #bfdbfe;

  --_purple-900: #1e1040;
  --_purple-600: #6d28d9;
  --_purple-400: #a78bfa;
  --_purple-100: #ede9fe;
}


/* ──────────────────────────────────────────────────────────────
   TIER 2 — SEMANTIC TOKENS  (use these in all components)

   surface-0  = page background (deepest layer)
   surface-1  = card / panel background
   surface-2  = elevated card / table header / sidebar
   text-1     = primary text (headings, values)
   text-2     = secondary text (labels, sub-headings)
   text-muted = muted / placeholder / helper text
   accent     = brand gold — CTA, highlights, icons
   accent-soft= lighter accent for borders, hover states
   ────────────────────────────────────────────────────────────── */
:root {
  /* ── Light mode (default) ── */
  --surface-0:    #fffdf5;                    /* page body */
  --surface-1:    var(--_cream-100);          /* cards */
  --surface-2:    var(--_cream-200);          /* elevated cards, table heads */

  --text-1:       #1a0f3c;                    /* headings, strong values */
  --text-2:       #4b4070;                    /* labels, secondary content */
  --text-muted:   #6b6080;                    /* helper, placeholder */
  --text-accent:  var(--accent);              /* deliberate gold text — opt-in only */

  --accent:       var(--_gold-300);           /* #e8c84a */
  --accent-deep:  var(--_gold-500);           /* #c9a227 — AA-safe on cream */
  --accent-soft:  var(--_gold-200);           /* #f5d96b — highlights */
  --accent-tint:  rgba(232, 200, 74, 0.12);   /* subtle bg fills */
  --accent-glow:  rgba(232, 200, 74, 0.35);   /* box-shadow glows */

  /* Borders */
  --border-subtle:  rgba(15, 12, 41, 0.08);
  --border:         rgba(15, 12, 41, 0.12);
  --border-strong:  rgba(232, 200, 74, 0.55);
  --border-accent:  rgba(232, 200, 74, 0.30);

  /* Shadows — surface-aware */
  --sh-1: 0 1px 4px rgba(15, 12, 41, 0.06);
  --sh-2: 0 4px 16px rgba(15, 12, 41, 0.10), 0 1px 4px rgba(15, 12, 41, 0.06);
  --sh-3: 0 8px 32px rgba(15, 12, 41, 0.14), 0 2px 8px rgba(15, 12, 41, 0.07);
  --sh-glow: 0 8px 32px rgba(232, 200, 74, 0.25);

  /* Status — semantic */
  --status-success-bg:    var(--_green-100);
  --status-success-text:  var(--_green-600);
  --status-success-border:var(--_green-600);

  --status-warning-bg:    var(--_amber-100);
  --status-warning-text:  var(--_amber-800);
  --status-warning-border:var(--_amber-600);

  --status-danger-bg:     var(--_red-100);
  --status-danger-text:   var(--_red-600);
  --status-danger-border: var(--_red-600);

  --status-info-bg:       #e8f4fd;
  --status-info-text:     var(--_blue-600);
  --status-info-border:   var(--_blue-600);

  /* Progress / bars */
  --track-bg:     var(--_cream-200);
  --track-fill:   var(--_gold-300);
}


/* ──────────────────────────────────────────────────────────────
   TIER 2 — DARK MODE OVERRIDES  (single block, no exceptions)
   ────────────────────────────────────────────────────────────── */
html[data-theme="dark"],
body.dark-mode {
  --surface-0:    var(--_navy-800);    /* #07060f */
  --surface-1:    var(--_navy-600);    /* #0f0c29 */
  --surface-2:    var(--_navy-500);    /* #1a1550 */

  --text-1:       #f0e8d0;    /* primary — warm cream, high contrast headings/values */
  --text-2:       #b8ae98;    /* secondary — warm stone, labels/sub-headings (NOT gold) */
  --text-muted:   #8a8272;    /* muted — warm neutral, helper/placeholder, AA-compliant */
  --text-accent:  var(--accent); /* deliberate gold text — highlights, CTAs, active states ONLY */

  /* Slate variant — a cooler secondary dark-mode text/surface family used
     across several legacy template-local stylesheets (tables, admin panels,
     calculator result cards). Kept distinct from --text-1/2/muted (warm
     cream) rather than merged, since merging would visibly shift hue. */
  --text-1-slate:    #e2e8f0;
  --text-2-slate:    #cbd5e1;
  --text-muted-slate:#94a3b8;
  --surface-1-slate: var(--_navy-600);   /* #0f0c29 — same as --surface-1, alias for clarity */
  --surface-2-slate: #252d4a;
  --surface-3-slate: #0a0818;
  --border-slate:    #252d4a;

  --accent:       var(--_gold-300);    /* unchanged — bright enough on dark */
  --accent-deep:  var(--_gold-400);
  --accent-soft:  var(--_gold-200);
  --accent-tint:  rgba(232, 200, 74, 0.10);
  --accent-glow:  rgba(232, 200, 74, 0.20);

  --border-subtle:  rgba(232, 200, 74, 0.06);
  --border:         rgba(232, 200, 74, 0.12);
  --border-strong:  rgba(232, 200, 74, 0.50);
  --border-accent:  rgba(232, 200, 74, 0.25);

  --sh-1: 0 1px 4px rgba(0, 0, 0, 0.25);
  --sh-2: 0 4px 16px rgba(0, 0, 0, 0.40), 0 1px 4px rgba(0, 0, 0, 0.20);
  --sh-3: 0 8px 32px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.30);
  --sh-glow: 0 8px 32px rgba(232, 200, 74, 0.15);

  --status-success-bg:    var(--_green-900);
  --status-success-text:  var(--_green-300);
  --status-success-border:var(--_green-400);

  --status-warning-bg:    var(--_amber-900);
  --status-warning-text:  var(--_amber-200);
  --status-warning-border:var(--_amber-400);

  --status-danger-bg:     var(--_red-900);
  --status-danger-text:   var(--_red-400);
  --status-danger-border: var(--_red-400);

  --status-info-bg:       var(--_blue-900);
  --status-info-text:     var(--_blue-200);
  --status-info-border:   var(--_blue-400);

  --track-bg:   var(--_navy-500);
  --track-fill: var(--_gold-300);
}


/* ──────────────────────────────────────────────────────────────
   TIER 2 — LEGACY ALIAS MAP
   Maps old template tokens (--gold, --navy, --ink, etc.) to
   semantically equivalent new tokens. Allows templates to
   continue working without a find/replace sweep. Remove aliases
   as templates are migrated to semantic names.
   ────────────────────────────────────────────────────────────── */
:root {
  --navy:    var(--_navy-600);
  --navy-m:  var(--_navy-700);
  --navy-l:  var(--_navy-600);
  --navy-ll: var(--_navy-500);
  --gold:    var(--accent);
  --gold-d:  var(--accent-deep);
  --gold-l:  var(--accent-soft);
  --gold-xl: #fff8dc;           /* light-only tint, no dark equivalent needed */
  --gold-p:  var(--accent-tint);
  --cream:   var(--surface-1);
  --cream-d: var(--surface-2);
  --ink:     var(--text-1);
  --muted:   var(--text-muted);
  --muted-d: rgba(255, 255, 255, 0.42);
  --border:  var(--border-accent);
  --brd:     var(--border);
  --brd2:    var(--border-accent);
  --card-brd:var(--border);
  --r:       12px;
  --shd:     var(--sh-2);
  --shd-lg:  var(--sh-3);
  --shd-dk:  0 8px 40px rgba(0, 0, 0, 0.5);
  --success: var(--_green-600);
  --success-l:var(--_green-300);
  --danger:  var(--_red-600);
  --danger-l:var(--_red-400);
  --warn:    var(--_amber-600);
  --info:    var(--_blue-600);
}

/* Dark-mode alias flip — legacy token overrides */
html[data-theme="dark"],
body.dark-mode {
  --navy:    var(--_navy-600);
  --navy-m:  var(--_navy-600);
  --navy-l:  var(--_navy-600);
  --navy-ll: var(--_navy-500);
  --gold:    var(--accent);
  --gold-d:  var(--accent-deep);
  --gold-l:  var(--accent-soft);
  --gold-xl: rgba(232, 200, 74, 0.08);  /* tint gets dimmed in dark */
  --cream:   var(--surface-1);
  --cream-d: var(--surface-2);
  --ink:     var(--text-1);
  --muted:   var(--text-muted);
  --border:  var(--border-accent);
}


/* ──────────────────────────────────────────────────────────────
   TIER 2 — TYPOGRAPHY, SPACING, RADIUS (theme-independent)
   ────────────────────────────────────────────────────────────── */
:root {
  --font-serif: 'Cormorant Garamond', Georgia, serif;
  --font-sans:  'DM Sans', 'DM Mono', 'Segoe UI', system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', monospace;

  /* ── Spacing scale (4px base grid) ── */
  /* Core stops */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-7:  28px;   /* NEW: page-header padding, large cards */
  --sp-8:  32px;
  --sp-9:  36px;   /* NEW: section-level gaps */
  --sp-10: 40px;
  --sp-12: 48px;   /* NEW: hero sections, generous page padding */
  --sp-16: 64px;   /* NEW: page-level vertical rhythm */

  /* Half-stops (for tight UI components only) */
  --sp-1h: 6px;    /* NEW: icon gaps, tight pill padding */
  --sp-2h: 10px;   /* NEW: badge padding, filter inputs */
  --sp-3h: 14px;   /* NEW: nav pill horizontal padding — replaces 14px magic number */
  --sp-4h: 18px;   /* NEW: panel headers, compact card padding */

  /* Container widths */
  --mx:    1400px;  /* main app pages (matches base.html layout) */
  --mx-sm:  900px;  /* settings, narrow forms */
  --mx-lg: 1600px;  /* dashboard — wide data layout */
  --my:    var(--sp-6); /* default page vertical margin: 24px */

  /* Vertical rhythm system — use for section/component spacing */
  --rhythm-tight:   var(--sp-4);   /* 16px — between list items */
  --rhythm-base:    var(--sp-5);   /* 20px — between sibling components */
  --rhythm-loose:   var(--sp-8);   /* 32px — between card groups */
  --rhythm-section: var(--sp-10);  /* 40px — between named page sections */

  /* ── Migration guide (off-scale → token) ──
     5px   → --sp-1  (4px)   rounding down; imperceptible
     6px   → --sp-1h (6px)   exact match
     10px  → --sp-2h (10px)  exact match
     11px  → --sp-3  (12px)  rounding up 1px; imperceptible
     13px  → --sp-3  (12px)  rounding down 1px
     14px  → --sp-3h (14px)  exact match
     15px  → --sp-4  (16px)  rounding up 1px
     18px  → --sp-4h (18px)  exact match
     22px  → --sp-6  (24px)  rounding up 2px
     26px  → --sp-7  (28px)  rounding up 2px
     30px  → --sp-8  (32px)  rounding up 2px
     36px  → --sp-9  (36px)  exact match
  */

  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   24px;
  --r-pill: 50px;

  /* Z-index stacking */
  --z-nav:      100;
  --z-dropdown: 200;
  --z-overlay:  300;
  --z-modal:    500;
  --z-toast:   9000;
  --z-top:     9999;
}


/* ──────────────────────────────────────────────────────────────
   GLOBAL: BODY + HTML
   ────────────────────────────────────────────────────────────── */

/* Body background: theme-responsive gradient using primitive tokens */
html[data-theme="light"] body,
html:not([data-theme]) body {
  background: linear-gradient(
    145deg,
    var(--_cream-200) 0%,
    var(--_cream-100) 40%,
    #fffdf5 70%,
    var(--_cream-200) 100%
  );
  color: var(--text-1);
}

html[data-theme="dark"] body,
body.dark-mode {
  background: linear-gradient(
    145deg,
    var(--_navy-800) 0%,
    var(--_navy-600) 45%,
    var(--_navy-500) 80%,
    var(--_navy-800) 100%
  );
  color: var(--text-1);
}

/* Smooth transitions for theme switching (not on html root — avoids FOUC) */
body,
.card, .calc-card, .panel, .page-hdr, .sum-card, .whatif-card, .stat-card {
  transition: background-color 0.22s ease, color 0.22s ease, border-color 0.22s ease;
}

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


/* ──────────────────────────────────────────────────────────────
   COMPONENT TOKENS — Button, Card, Input primitives
   These derive from semantic tokens and define the "design system"
   that every component draws from.
   ────────────────────────────────────────────────────────────── */

/* ── Buttons ── */
.m3-btn {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--r-pill);
  font-weight: 700; font-size: 0.875rem;
  font-family: var(--font-sans);
  text-decoration: none; border: none; cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  white-space: nowrap;
}
.m3-btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: var(--_navy-600);
  box-shadow: 0 4px 12px var(--accent-glow);
  letter-spacing: 0.02em;
}
.m3-btn-primary:hover {
  background: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: var(--sh-3);
}
.m3-btn-ghost {
  background: transparent;
  color: var(--text-1);
  border: 1.5px solid var(--border-accent);
}
.m3-btn-ghost:hover {
  background: var(--accent-tint);
  border-color: var(--accent);
  color: var(--text-1);
}
.m3-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}


/* ── Cards — Elevation Scale ──
   surface-1 = base card (most common)
   surface-2 = elevated / highlighted card
   accent gradient = premium card (hero values only)
   ── */
.card-base {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card-elevated {
  background: var(--surface-2);
  border: 1px solid var(--border-accent);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
}
.card-premium {
  background: linear-gradient(135deg, var(--surface-2), var(--surface-1));
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-glow);
}
/* Highlighted sum cards — premium gold, not blinding */
.card-highlighted {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  border: 1px solid var(--accent-deep);
  color: var(--_navy-600);
  box-shadow: 0 6px 24px var(--accent-glow);
}


/* ── Form inputs ── */
.input-base {
  background: var(--surface-1);
  color: var(--text-1);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font-sans);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.input-base:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
.input-base::placeholder {
  color: var(--text-muted);
}


/* ── Status boxes ── */
.status-box {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  border-left: 4px solid;
  font-size: 0.9rem;
}
.status-success {
  background: var(--status-success-bg);
  color: var(--status-success-text);
  border-left-color: var(--status-success-border);
}
.status-warning {
  background: var(--status-warning-bg);
  color: var(--status-warning-text);
  border-left-color: var(--status-warning-border);
}
.status-danger {
  background: var(--status-danger-bg);
  color: var(--status-danger-text);
  border-left-color: var(--status-danger-border);
}
.status-info {
  background: var(--status-info-bg);
  color: var(--status-info-text);
  border-left-color: var(--status-info-border);
}


/* ── Theme toggle ── */
.m3-theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  background: transparent;
  border: 1.5px solid var(--border-accent);
  border-radius: 50%;
  cursor: pointer; font-size: 16px;
  color: var(--text-1);
  transition: background 0.2s ease, border-color 0.2s ease;
  flex-shrink: 0;
}
.m3-theme-toggle:hover {
  background: var(--accent-tint);
  border-color: var(--accent);
}
.m3-theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.m3-sun, .m3-moon { line-height: 1; display: block; }
html[data-theme="light"]  .m3-moon { display: none; }
html[data-theme="dark"]   .m3-sun  { display: none; }
html:not([data-theme])    .m3-moon { display: none; }


/* ── Table wrapper ── */
.m3-tbl-wrap {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-1);
}
.m3-tbl-wrap table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
}


/* ── Footer ── */
.m3-footer {
  margin-top: 40px;
  padding: var(--sp-5) var(--sp-6);
  border-top: 1px solid var(--border-accent);
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex; flex-direction: column; gap: 6px;
  text-align: center; line-height: 1.55;
}
.m3-footer-disclaimer { font-size: 0.75rem; opacity: 0.7; }


/* ── Nav drop button ── */
.nav-drop-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}


/* ── Focus ring (global) ── */
:focus-visible:not(.navbar-brand):not(.navbar-brand *) {
  outline: 2px solid var(--border-strong);
  outline-offset: 2px;
}


/* ── Print ── */
@media print {
  .navbar, .m3-footer, .m3-share-row, .btn-back { display: none !important; }
  body {
    background: white !important;
    color: black !important;
    padding: 0 !important;
  }
}


/* ──────────────────────────────────────────────────────────────
   CHART PALETTE TOKENS  (consumed by calc-core.js themeTokens())
   Defines both the data-series colours (--c1..--c5) and the
   semantic chart-chrome tokens (grid, tick, tooltip).
   calc-core.js reads these via getComputedStyle — no hardcoded
   hex values should remain in that file after migration.
   ────────────────────────────────────────────────────────────── */
:root {
  /* Data series — 5 distinct, accessible colours */
  --c1: var(--_gold-300);          /* #e8c84a — brand gold */
  --c2: var(--_blue-400);          /* #60a5fa — blue */
  --c3: var(--_green-400);         /* #34d399 — teal-green */
  --c4: #fb923c;                   /* orange */
  --c5: var(--_purple-400);        /* #a78bfa — purple */
  --c6: #f472b6;                   /* pink */
  --c7: #818cf8;                   /* indigo */

  /* Chart chrome */
  --chart-grid:        rgba(15, 12, 41, 0.07);
  --chart-grid-border: rgba(15, 12, 41, 0.12);
  --chart-tick:        var(--text-muted);
  --chart-label:       var(--text-2);
  --chart-tooltip-bg:  #ffffff;
  --chart-tooltip-title: var(--text-1);
  --chart-tooltip-body:  var(--text-2);
  --chart-tooltip-border: rgba(15, 12, 41, 0.10);
}

html[data-theme="dark"],
body.dark-mode {
  --chart-grid:        rgba(232, 200, 74, 0.07);
  --chart-grid-border: rgba(232, 200, 74, 0.12);
  --chart-tick:        #a39771;
  --chart-label:       var(--text-2);        /* warm stone in dark, secondary in light */
  --chart-tooltip-bg:  var(--_navy-500);
  --chart-tooltip-title: var(--_gold-300);
  --chart-tooltip-body:  #d9cf9a;
  --chart-tooltip-border: rgba(232, 200, 74, 0.22);
}


/* ──────────────────────────────────────────────────────────────
   INTERACTION TOKENS  (hover, focus, active states)
   All micro-interaction timings and easing in one place.
   ────────────────────────────────────────────────────────────── */
:root {
  /* Timing */
  --duration-fast:    100ms;
  --duration-base:    180ms;
  --duration-slow:    300ms;
  --duration-enter:   220ms;
  --duration-exit:    160ms;

  /* Easing */
  --ease-out:      cubic-bezier(0.16, 1, 0.3, 1);   /* snappy decelerate */
  --ease-in-out:   cubic-bezier(0.4, 0, 0.2, 1);    /* material-style */
  --ease-spring:   cubic-bezier(0.34, 1.56, 0.64, 1); /* subtle spring */

  /* Interaction surfaces */
  --hover-overlay:  rgba(232, 200, 74, 0.06);   /* light hover wash */
  --active-overlay: rgba(232, 200, 74, 0.12);   /* press state */
  --focus-ring:     0 0 0 3px rgba(232, 200, 74, 0.35);
  --focus-ring-offset: 2px;
}

html[data-theme="dark"],
body.dark-mode {
  --hover-overlay:  rgba(232, 200, 74, 0.05);
  --active-overlay: rgba(232, 200, 74, 0.10);
  --focus-ring:     0 0 0 3px rgba(232, 200, 74, 0.28);
}


/* ──────────────────────────────────────────────────────────────
   COMPONENT ELEVATION TOKENS
   Defined once; every card/panel references these.
   ────────────────────────────────────────────────────────────── */
:root {
  /* Elevation 0 — inset / sunken (input fields, code blocks) */
  --elevation-0: inset 0 1px 3px rgba(15, 12, 41, 0.06);

  /* Elevation 1 — flat card (default surface-1 cards) */
  --elevation-1: 0 1px 3px rgba(15, 12, 41, 0.06), 0 1px 2px rgba(15, 12, 41, 0.04);

  /* Elevation 2 — raised card (hover state, dropdowns) */
  --elevation-2: 0 4px 16px rgba(15, 12, 41, 0.10), 0 1px 4px rgba(15, 12, 41, 0.06);

  /* Elevation 3 — floating (modals, popovers) */
  --elevation-3: 0 12px 32px rgba(15, 12, 41, 0.14), 0 4px 8px rgba(15, 12, 41, 0.08);

  /* Elevation 4 — premium card (hero values, highlighted results) */
  --elevation-4: 0 8px 28px rgba(232, 200, 74, 0.18), 0 2px 8px rgba(232, 200, 74, 0.08);
}

html[data-theme="dark"],
body.dark-mode {
  --elevation-0: inset 0 1px 3px rgba(0, 0, 0, 0.30);
  --elevation-1: 0 1px 3px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.20);
  --elevation-2: 0 4px 16px rgba(0, 0, 0, 0.40), 0 1px 6px rgba(0, 0, 0, 0.25);
  --elevation-3: 0 12px 40px rgba(0, 0, 0, 0.55), 0 4px 12px rgba(0, 0, 0, 0.35);
  --elevation-4: 0 8px 28px rgba(232, 200, 74, 0.12), 0 2px 8px rgba(232, 200, 74, 0.06);
}


/* ──────────────────────────────────────────────────────────────
   MISSING TOKEN FIXES (June 2026 full-template audit)

   These 22 tokens were used in templates but defined nowhere in
   any CSS file — they silently fell back to empty/inherited values.
   Now formally defined and mapped to the semantic tier.
   ────────────────────────────────────────────────────────────── */

/* ── --brand-* ALIASES (dropped in refactor, still used in billing + base) ── */
:root {
  --brand-navy:       var(--_navy-600);          /* #0f0c29 */
  --brand-navy-mid:   var(--_navy-500);          /* #1a1550 */
  --brand-navy-deep:  var(--_navy-800);          /* #07060f */
  --brand-gold:       var(--_gold-500);          /* #c9a227 — AA-safe on cream */
  --brand-gold-soft:  var(--_gold-300);          /* #e8c84a */
  --brand-gold-deep:  var(--_gold-600);          /* #a07f10 */
  --brand-gold-light: var(--_gold-200);          /* #f5d96b */
  --brand-cream:      var(--surface-1);
  --brand-cream-mid:  var(--surface-2);
}

/* ── Card shadow — defined locally in 15+ templates with identical values ── */
/* Centralised here; templates can remove their local :root blocks */
:root {
  --card-shd:  0 4px 20px rgba(15, 12, 41, 0.11), 0 1px 5px rgba(15, 12, 41, 0.06);
  --card-bg:   var(--surface-1);
  --card:      var(--surface-1);   /* settings.html shorthand */
}

/* ── Status background shorthands (billing cluster) ── */
:root {
  --success-bg:  var(--status-success-bg);
  --danger-bg:   var(--status-danger-bg);
}

/* ── Auth page tokens (login, register, forgot, reset_password) ── */
/* These templates define their own :root with --bg / --surface / --text
   which hard-codes a dark navy look. We formalise them here so the
   auth pages pick up both light AND dark mode correctly. */
:root {
  --bg:      var(--surface-0);
  --surface: var(--surface-1);
  --text:    var(--text-1);
}

/* ── Status colours (client_portal, regret_calculator) ── */
:root {
  --green:   var(--status-success-text);   /* #059669 light / #34d399 dark */
  --red:     var(--status-danger-text);    /* #dc2626 light / #f87171 dark */
  --red-d:   var(--_red-600);              /* deeper red for strong emphasis */
  --red-xl:  var(--status-danger-bg);      /* very light red bg fill */
}

html[data-theme="dark"], body.dark-mode {
  --green: var(--_green-300);
  --red:   var(--_red-400);
  --red-xl:var(--_red-900);
}

/* ── Gold shorthands (landing, client_portal) ── */
:root {
  --gold-dark:  var(--_gold-500);    /* #c9a227 — landing.html uses this */
  --gold-light: rgba(201, 168, 76, 0.15);  /* client_portal tint */
}

/* ── Chart/muted text tier 3 (billing cluster) ── */
:root {
  --text-3:  var(--text-muted);  /* same as --text-muted; billing uses --text-3 */
}

/* ── PDF template tokens (financial_plan_pdf.html — print-only) ── */
/* These are intentionally light-mode-fixed for PDF output */
:root {
  --gray:   #64748b;
  --light:  #f8f9fa;
  --white:  #ffffff;
}

/* ── Surface tier extension ── */
:root {
  --surface-3: var(--surface-2);   /* billing_invoices uses surface-3 as a "disabled" tier — maps to surface-2 */
}

/* ── Page-level spacing tokens (dashboard.html, index.html) ── */
/* --mx and --my are used for container max-width / vertical margin.
   Defined here to prevent silent empty fallback. */
:root {
  --mx: 1280px;   /* max content width */
  --my: 24px;     /* vertical page margin */
}

/* ── Chat / AI assistant tokens (ai_wealth_assistant.html) ── */
:root {
  --chat-brd:   rgba(232, 200, 74, 0.18);
  --chat-brd-h: rgba(232, 200, 74, 0.45);
  --chat-card:  rgba(253, 249, 238, 0.85);  /* light-mode frosted card */
}
html[data-theme="dark"], body.dark-mode {
  --chat-card:  rgba(15, 12, 41, 0.85);     /* dark-mode frosted card */
  --chat-brd:   rgba(232, 200, 74, 0.15);
  --chat-brd-h: rgba(232, 200, 74, 0.40);
}

/* ── Tenant branding tokens (base.html) ── */
/* These are injected server-side via Jinja {{ tenant.primary_color }}.
   Defaults below are used when no tenant override is present. */
:root {
  --tenant-primary:   var(--accent);       /* falls back to brand gold */
  --tenant-secondary: var(--accent-deep);
}

/* ── Colour picker token (add_edit_client.html) ── */
/* --rcolor is set dynamically from Jinja: {{ rcolor }}.
   Default = accent so the picker always has a valid starting colour. */
:root {
  --rcolor: var(--accent);
}

/* ── Dark mode flips for card + auth tokens ── */
html[data-theme="dark"], body.dark-mode {
  --card-shd: 0 4px 20px rgba(0, 0, 0, 0.35), 0 1px 5px rgba(0, 0, 0, 0.20);
  --card-bg:  var(--surface-1);
  --card:     var(--surface-1);
  --bg:       var(--surface-0);
  --surface:  var(--surface-1);
  --text:     var(--text-1);
  --text-3:   var(--text-muted);
  --gold-dark:  var(--_gold-400);
  --gold-light: rgba(232, 200, 74, 0.12);
}


/* ──────────────────────────────────────────────────────────────
   TIER 3 — NAVBAR COMPONENT TOKENS  (July 2026 refactor)

   All navbar rules in base.html reference ONLY these tokens.
   Dark-mode adaptation is automatic — no body.dark-mode overrides
   needed in base.html or anywhere else.
   ────────────────────────────────────────────────────────────── */
:root {
  /* Nav link colours */
  --nav-link:             var(--_navy-600);      /* link text light */
  --nav-link-hover-bg:    var(--surface-2);
  --nav-active-bg:        var(--accent);         /* gold active pill */
  --nav-active-text:      var(--_navy-600);      /* dark text on gold */

  /* Brand identity */
  --nav-brand-name:       var(--_navy-600);
  --nav-brand-sub:        #9ca3af;               /* neutral sub-label */
  --nav-brand-icon-bg:    linear-gradient(135deg, var(--_navy-700), var(--_navy-500));

  /* Dropdown */
  --nav-drop-bg:          #ffffff;               /* white in light mode */
  --nav-drop-link:        var(--_navy-600);
  --nav-drop-hover-bg:    var(--surface-2);
  --nav-drop-hover-link:  var(--_gold-600);      /* AA-safe gold on cream */

  /* Ghost pills (Settings / Logout) */
  --nav-pill-border:      rgba(15, 12, 41, 0.15);
  --nav-pill-hover-bg:    var(--_cream-200);

  /* Admin pill — intentionally always dark navy for visual hierarchy */
  --nav-admin-bg:         linear-gradient(135deg, var(--_navy-500), var(--_navy-600));
  --nav-admin-hover-bg:   linear-gradient(135deg, var(--_navy-400), var(--_navy-500));
  --nav-admin-border:     rgba(232, 200, 74, 0.28);

  /* Hamburger */
  --nav-ham-bg:           var(--accent);
  --nav-ham-bars:         var(--_navy-600);
}

html[data-theme="dark"],
body.dark-mode {
  --nav-link:             var(--accent);              /* gold links */
  --nav-link-hover-bg:    rgba(232, 200, 74, 0.10);
  --nav-active-bg:        rgba(232, 200, 74, 0.22);
  --nav-active-text:      var(--accent);

  --nav-brand-name:       var(--accent);
  --nav-brand-sub:        rgba(255, 255, 255, 0.40);
  --nav-brand-icon-bg:    linear-gradient(135deg, var(--_navy-500), var(--_navy-600));

  --nav-drop-bg:          var(--_navy-600);           /* dark navy dropdown */
  --nav-drop-link:        var(--_gold-200);
  --nav-drop-hover-bg:    rgba(232, 200, 74, 0.13);
  --nav-drop-hover-link:  var(--accent);

  --nav-pill-border:      rgba(232, 200, 74, 0.25);
  --nav-pill-hover-bg:    rgba(232, 200, 74, 0.10);

  --nav-admin-border:     rgba(232, 200, 74, 0.42);

  --nav-ham-bg:           rgba(232, 200, 74, 0.15);
  --nav-ham-bars:         var(--accent);
}
