/* ═══════════════════════════════════════════════════════════════════════════
   tokens.css — THE single source of truth for the site's design tokens.

   Loaded FIRST by every page (index.html and each standalone page: login,
   reset, welcome, …) so that style.css, login.css and the page stylesheets can
   use these custom properties. It is on the public static allowlist in
   SecurityConfig, because unauthenticated pages need it too.

   Rules of thumb (see docs/ui-consistency-audit.md):
     • Don't write a hex literal in any other stylesheet. If a colour you need
       isn't here, use the nearest semantic token rather than inventing a shade.
     • Identity: primary blue #3b82f6, Tailwind "slate" neutrals, Inter. No dark mode.
     • Every text/fill pair below has been checked to WCAG AA (≥ 4.5:1) unless
       a comment says otherwise.
     • The "Nest Egg" logo's gold and cream belong to the logo only, so they are
       deliberately NOT tokens here. Its teal IS (--brand-teal, since 5.14.0).
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    /* ── Neutrals (Tailwind slate) ─────────────────────────────────────────── */
    --bg:             #f1f5f9;   /* page background behind cards */
    --surface:        #ffffff;   /* cards, dialogs, inputs, table bodies */
    --surface-2:      #f8fafc;   /* the ONE off-white: table headers, row hover, subtle panels */
    --border:         #e2e8f0;   /* default 1px borders and dividers */
    --border-subtle:  #f1f5f9;   /* faint row separators inside a card */
    --border-strong:  #cbd5e1;   /* emphasised borders, totals rules, switch tracks, scrollbars */
    --text:           #0f172a;   /* body text (17.8:1 on white) */
    /* Secondary text. Darkened from slate-500 (#64748b, only 4.34:1 on --bg) so it
       passes AA on both --bg (5.24:1) and --surface (5.7:1). */
    --text-muted:     #5b6779;
    /* De-emphasised text (replaces the old #94a3b8, which was only 2.6:1). Slate-500:
       4.76:1 on white. Use on --surface; prefer --text-muted on --bg. */
    --text-subtle:    #64748b;
    /* Text or icons sitting on a solid coloured fill (primary/danger buttons, nav). */
    --on-solid:       #ffffff;

    /* ── Header band ──────────────────────────────────────────────────────────
       ONE value shared by the app navbar, the login-family header band and the
       email header (templates/email/layout.html copies it inline, because email
       clients don't support CSS variables). Slate-800: login pages and emails
       already used this colour. It gives white nav text 14.6:1 and makes
       translucent-white inactive tabs readable. */
    --nav-bg:         #1e293b;

    /* ── Brand / interactive ──────────────────────────────────────────────── */
    --primary:        #3b82f6;   /* buttons, links, active states */
    --primary-h:      #2563eb;   /* hover/pressed */
    --primary-lite:   #eff6ff;   /* selected rows, soft primary panels */
    /* Solid fills that carry WHITE TEXT (primary buttons, the login button, chat
       bubbles, chips). #3b82f6 under white text is only 3.68:1, which fails WCAG
       AA, so text-bearing fills use one step deeper: #2563eb is 5.17:1 and its
       hover #1d4ed8 is 6.70:1 (user decision 2026-11-10). --primary stays the
       brand blue for links, focus rings, accents, charts and fills without text. */
    --primary-solid:   #2563eb;
    --primary-solid-h: #1d4ed8;
    /* Blue TEXT (links, clickable cells, the "Active only" pill label). #3b82f6 as
       text on white is only 3.67:1 (fails AA for small text); #2563eb is 5.17:1. */
    --link:            var(--primary-solid);
    --link-h:          var(--primary-solid-h);
    --border-focus:   #3b82f6;   /* input border when focused */

    /* ── Semantic tones ───────────────────────────────────────────────────────
       Each tone has:
         --{tone}         solid fill or strong accent (bars, left borders, icons)
         --{tone}-h       hover for solid buttons (only where a button uses it)
         --{tone}-bg      soft fill for badges and callouts (the Tailwind -100 shade)
         --{tone}-border  border of a soft badge or callout
         --{tone}-text    text on the soft fill AND coloured text on white (≥ 4.5:1) */
    --success:        #16a34a;
    --success-h:      #15803d;
    --success-bg:     #dcfce7;
    --success-border: #86efac;
    --success-text:   #15803d;   /* 4.57:1 on --success-bg, 5.0:1 on white */

    --warning:        #f59e0b;   /* amber-500: fills/borders only; too light for text */
    --warning-h:      #d97706;
    --warning-bg:     #fef3c7;
    --warning-bg-subtle: #fffbeb; /* the palest amber. Unused since 5.14.0 (help strips and warnings went white); kept for compatibility */
    --warning-border: #fcd34d;
    --warning-text:   #92400e;   /* 6.4:1 on --warning-bg */

    /* Danger solid is red-600, not red-500 (#ef4444): red-500 fails as text and
       under white button text (3.76:1). Red-600 is 4.83:1 either way. */
    --danger:         #dc2626;
    --danger-h:       #b91c1c;
    --danger-bg:      #fee2e2;
    --danger-border:  #fca5a5;
    --danger-text:    #b91c1c;   /* 5.3:1 on --danger-bg */

    --info:           #2563eb;
    --info-bg:        #dbeafe;
    --info-border:    #93c5fd;
    --info-text:      #1e40af;   /* 7.2:1 on --info-bg */

    --neutral:        #64748b;
    --neutral-bg:     #f1f5f9;
    --neutral-border: #cbd5e1;
    --neutral-text:   #475569;   /* 6.9:1 on --neutral-bg */

    --accent:         #7c3aed;   /* purple, for "you"/premium/special highlights */
    --accent-h:       #6d28d9;
    --accent-bg:      #f3e8ff;
    --accent-border:  #d8b4fe;
    --accent-text:    #6d28d9;   /* 6.0:1 on --accent-bg */

    /* ── Dark tooltip/popover chips (e.g. the dashboard hover tips) ───────── */
    --tooltip-bg:     #1e293b;
    --tooltip-text:   #f8fafc;

    /* ── Legacy names ─────────────────────────────────────────────────────────
       Kept as ALIASES so existing CSS and inline styles keep working while
       everything migrates. New code should use the semantic names above. */
    --danger-lite:    var(--danger-bg);
    --green-bg:       var(--success-bg);
    --green-text:     var(--success-text);
    --gray-bg:        var(--neutral-bg);
    --gray-text:      var(--neutral-text);
    --purple-bg:      var(--accent-bg);
    --purple-text:    var(--accent);

    /* ── Chart palette ────────────────────────────────────────────────────────
       Read by chart-theme.js (getComputedStyle), which hands them to every
       Chart.js chart and the hand-drawn bars. Validated with the dataviz skill's
       validate_palette.js against the white card surface (2026-11-10).

       Categorical series, used in this FIXED order, never cycled (a 9th series is
       folded into "Other" in --chart-other). Primary blue first, then the dataviz
       reference order. Every hard check passes: worst adjacent colour-blind ΔE 9.1,
       normal-vision ΔE 19.6. Aqua, yellow and magenta are under 3:1 on white, so a
       chart using them must also show a legend or the numbers (they all do). */
    --chart-1: #3b82f6;   /* blue (= --primary) */
    --chart-2: #eb6834;   /* orange */
    --chart-3: #1baf7a;   /* aqua */
    --chart-4: #eda100;   /* yellow */
    --chart-5: #e87ba4;   /* magenta */
    --chart-6: #008300;   /* green */
    --chart-7: #6250d6;   /* violet */
    --chart-8: #e34948;   /* red */
    --chart-other: #94a3b8;  /* "Other" / unclassified slices, cash (a fill, never text) */

    /* Fixed two-way splits. Each pair is distinct from the other so the two
       dashboard donuts never seem to mean the same thing. */
    --chart-mandatory:     var(--chart-1);  /* committed spend: blue */
    --chart-discretionary: var(--chart-2);  /* could flex: orange. Blue/orange passes every check. */
    --chart-sheltered:     var(--chart-6);  /* ISA/pension/Premium Bonds: green */
    --chart-taxable:       var(--chart-8);  /* red: taxable is the "bad" side (5.17.2, user request).
                                               Green/red is weak for red-green colour-blind users, so the
                                               donut keeps its legend with values; never rely on colour alone. */

    /* Income-tax bands: ONE single-hue blue ramp, light → dark as the rate rises
       (passes the ordinal checks: monotone lightness, visible steps, light end
       2.1:1 on white). Shared by the dashboard Income & Tax card and the Tax
       calculator, which used to disagree (Basic blue vs purple, Additional red
       vs dark red). Scottish bands slot into the same ramp by rate. */
    --chart-band-personal:     #86b6ef;  /* 0%: Personal Allowance */
    --chart-band-basic:        #3987e5;  /* 20% */
    --chart-band-intermediate: #2a78d6;  /* 21% (Scotland) */
    --chart-band-higher:       #256abf;  /* 40–42% */
    --chart-band-advanced:     #1c5cab;  /* 45% (Scotland) */
    --chart-band-additional:   #104281;  /* 45–48% top rate */
    /* The other 0% allowances (savings starting rate, PSA, dividend allowance):
       pale tints so they read as "free" bands, distinct from the Personal Allowance. */
    --chart-allow-starting: #bbf7d0;
    --chart-allow-psa:      #a5f3fc;
    --chart-allow-dividend: #ddd6fe;

    /* Tax cost on savings interest (5.38.0): the "Accounts vs Interest Rates" bubble
       edges. A traffic light of how much the next pound of interest loses to tax,
       deliberately NOT the blue band ramp above (that shows band membership, this
       shows cost). Additional is a dark crimson, not a literal scarlet, because
       scarlet is too close to --danger to tell apart on a 3px ring. */
    --chart-taxcost-free:       var(--success);  /* 0%: tax-free wrapper or within allowances */
    --chart-taxcost-basic:      var(--warning);  /* basic rate */
    --chart-taxcost-higher:     var(--danger);   /* higher rate */
    --chart-taxcost-additional: #9f1239;         /* additional rate (and the 60% taper zone) */
    --chart-taxcost-unknown:    var(--neutral);  /* no owner / no tax figure */
    /* The bubbles' own fill: one translucent neutral, so colour only ever means tax. */
    --chart-rate-bubble:        rgba(59, 130, 246, 0.28);

    /* Chart chrome: recessive grid and axes, readable ticks. */
    --chart-grid: #eef2f6;          /* gridlines: just visible on white */
    --chart-axis: var(--border);    /* axis baseline */
    --chart-text: var(--text-muted);/* tick labels, legend text */

    /* ── Brand teal (5.14.0, user decision "option C") ─────────────────────────
       The deep teal of the Nest Egg logo, promoted from logo-only to THE brand
       accent. It replaced the warm amber/cream, which looked dated beside the
       slate-and-blue app. Use it for BRAND moments only: the welcome/login/
       security calls to action, the AI Advisor nav tab and the help strip's
       icon. Information inside the app stays blue (--info / --primary) and
       warnings stay amber (--warning). */
    --brand-teal:         #1A6B80;  /* = logo.svg teal. White text on it: 6.1:1 (AA) */
    --brand-teal-h:       #145566;  /* hover/pressed fill. White text: 8.2:1 */
    --brand-teal-lite:    #ecf6f8;  /* soft fill: highlighted cards, secondary-button hover */
    --brand-teal-wash:    #f5fafb;  /* barely-there section background */
    --brand-teal-border:  #a9d3dc;  /* soft card/divider border */
    --brand-teal-on-dark: #7cc7d6;  /* teal TEXT on the slate navbar: 7.6:1 on --nav-bg */

    /* ── Welcome / Security marketing brand ───────────────────────────────────
       The names the marketing stylesheets use. Since 5.14.0 they all point at
       the brand teal above (they were amber/stone until then). */
    --brand-accent:        var(--brand-teal);       /* CTA fill (carries white text) */
    --brand-accent-h:      var(--brand-teal-h);
    --brand-accent-text:   var(--brand-teal);       /* teal text on white: 6.1:1 */
    --brand-accent-soft:   var(--brand-teal-lite);
    --brand-accent-wash:   var(--brand-teal-wash);
    --brand-accent-border: var(--brand-teal-border);
    --brand-ink:           var(--text);             /* marketing headings: the app's slate-900 */

    /* ── Typography ───────────────────────────────────────────────────────── */
    --font-sans:   'Inter', system-ui, -apple-system, sans-serif;
    --fs-2xs:  10px;   /* tiny badges, chart keys */
    --fs-xs:   11px;   /* badges, uppercase eyebrows */
    --fs-sm:   12px;   /* meta text, helper text, small buttons */
    --fs-base: 13px;   /* tables, nav, labels. Kept at 13px: at 14px the widest tables (Accounts) no longer fit 1440px. Body copy is --fs-md (14px). */
    --fs-md:   14px;   /* body copy, inputs, buttons, card titles */
    --fs-lg:   16px;
    --fs-xl:   20px;   /* page titles */
    --fs-2xl:  24px;
    --fs-3xl:  30px;   /* the one hero figure (dashboard Net worth) */
    --lh-tight:   1.2;
    --lh-base:    1.5;
    --lh-relaxed: 1.65;

    /* ── Radius ───────────────────────────────────────────────────────────── */
    --radius-xs:   4px;    /* tiny controls, tags */
    --radius-sm:   6px;    /* buttons, inputs, callouts */
    --radius:      10px;   /* cards, dialogs */
    --radius-pill: 999px;  /* badges, switches, chips */

    /* ── Elevation ────────────────────────────────────────────────────────── */
    --shadow-sm:  0 1px 2px rgba(15,23,42,.06);
    --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:  0 4px 12px rgba(0,0,0,.08);
    --shadow-lg:  0 20px 60px rgba(0,0,0,.25);         /* modals */
    --shadow-pop: 0 6px 20px rgba(0,0,0,.25);          /* dropdowns, popovers, dark tips */
    /* Focus ring for inputs/buttons: primary at 35%, clearly visible (the old
       rings were 12–15% and hard to see). */
    --focus-ring: 0 0 0 3px rgba(59,130,246,.35);
    --backdrop:   rgba(15,23,42,.45);                  /* modal backdrop (slate-tinted) */

    /* ── Spacing (4px grid) ───────────────────────────────────────────────── */
    --space-1:  4px;
    --space-2:  8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-7: 28px;
    --space-8: 32px;
}
