/* ================= JW TERMINAL THEME KIT — TOKENS =================
   The single source of truth for every color, size, and layer in the app.
   Loaded BEFORE terminal.css (see index.html). Rules of the kit:

   1. THEME-VARYING tokens (colors) live in the first two blocks and every
      token MUST be defined in both — test/theme.test.mjs fails the build
      on a missing dark counterpart.
   2. STRUCTURAL tokens (type, radius, z-index, shadows, spacing, motion)
      are theme-invariant and live in the third block.
   3. terminal.css and JS renderers reference tokens, never literals —
      no hex colors and no raw z-index numbers outside this file (also
      test-enforced). Charts resolve tokens at draw time via cssVar().
   4. Browser floor (contract/browser-floor.json, Safari 17 since 2026-09-05):
      color-mix() and nesting are allowed now; every colour still ORIGINATES
      as a token in this file, so the theme kit stays the single source. The
      tint tokens (up-bg/down-bg, chart fills and bars, skel-shine) are DERIVED
      from their base with color-mix(in srgb, var(--base) P%, transparent),
      which is byte-identical to the rgba() they replaced and moves with the
      base when a theme is edited. Canvas consumers go through chartColor(),
      which resolves a mix to an exact rgba(); the contrast ratchet evaluates
      the same syntax.

   data-theme is stamped on <html> by an inline head script (stored
   preference, default dark) before paint. */

:root {
  color-scheme: light;
  --bg: #f6f7f9; --card: #ffffff; --border: #e5e7eb; --border-soft: #f0f1f3;
  --hover: #f3f4f6; --input-border: #8d95a3; --skel: #e9ecf0; --skel-shine: color-mix(in srgb, var(--card) 75%, transparent);
  --text: #1a1d21; --text-2: #374151; --muted: #656c7a; --faint: #5f6673;
  --up: #047857; --up-bg: #ecfdf5; --down: #d31f1f; --down-strong: #b91c1c; --down-bg: #fef2f2;
  --link: #0e7490; --accent: #0e7490;
  --on-accent: #ffffff;
  --brand-grad: linear-gradient(120deg, #0284c7, #0e7490 55%, #155e75);
  /* CRISP, not glow (Wesley, 2026-09-12): every accent shadow is a hard offset
     2px right and 3px down with zero blur, in the same accent-tinted edge
     colour the hero tiles use for their border — the soft 14–22% glow under
     the tiles and the blurred halo behind the logo are gone. Both names kept
     so nothing that references them moves. */
  --brand-glow: drop-shadow(2px 3px 0 color-mix(in srgb, var(--accent) 32%, var(--border)));
  --shadow-stat: 2px 3px 0 color-mix(in srgb, var(--accent) 32%, var(--border));
  --warn-bg: #fffbeb; --warn-border: #fcd34d;
  --warn-chip-bg: #fef3c7; --warn-chip-text: #92400e;
  --info-chip-bg: #dbeafe; --info-chip-text: #1e40af;
  /* elevation — black shadows read as lift on a light page but vanish on a
     dark one, so the ladder is theme-varying (dark goes heavier) */
  --shadow-toast: 0 6px 20px rgba(0,0,0,.25);
  --shadow-pop: 0 8px 28px rgba(0,0,0,.28);
  --shadow-overlay: 0 20px 60px rgba(0,0,0,.3);
  --shadow-modal: 0 24px 60px rgba(0,0,0,.32);
  --shadow-drawer: -8px 0 30px rgba(0,0,0,.18);
  --backdrop: rgba(15,23,42,.35);
  --backdrop-strong: rgba(15,23,42,.45);
  /* chart tone series — must match the text tones (--up/--down) per theme or
     the same gain paints two different greens on one screen. Resolved into
     canvas via chartColor(). */
  --chart-pos: #047857; --chart-neg: #d31f1f; --chart-neg-fill: color-mix(in srgb, var(--down) 12%, transparent); --chart-pos-fill: color-mix(in srgb, var(--up) 12%, transparent); --chart-pos-soft: color-mix(in srgb, var(--chart-pos) 60%, transparent); --chart-neg-soft: color-mix(in srgb, var(--chart-neg) 60%, transparent);
  --chart-up-bar: color-mix(in srgb, var(--up) 75%, transparent); --chart-down-bar: color-mix(in srgb, var(--down) 75%, transparent);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1116; --card: #161a21; --border: #262c37; --border-soft: #1e242d;
  --hover: #1f2530; --input-border: #616a7c; --skel: #1e242d; --skel-shine: rgba(255,255,255,.08);
  --text: #e7eaf0; --text-2: #c6ccd8; --muted: #98a1b3; --faint: #868fa1;
  --up: #34d399; --up-bg: color-mix(in srgb, var(--up) 13%, transparent); --down: #f87171; --down-strong: #fca5a5; --down-bg: color-mix(in srgb, var(--down) 13%, transparent);
  --link: #22d3ee; --accent: #22d3ee;
  --on-accent: #0e1116;
  --brand-grad: linear-gradient(120deg, #67e8f9, #22d3ee 55%, #38bdf8);
  --brand-glow: drop-shadow(2px 3px 0 color-mix(in srgb, var(--accent) 32%, var(--border)));
  --shadow-stat: 2px 3px 0 color-mix(in srgb, var(--accent) 32%, var(--border));
  --warn-bg: #241f0d; --warn-border: #5c4d1a;
  --warn-chip-bg: #3a2f10; --warn-chip-text: #fbbf24;
  --info-chip-bg: #152740; --info-chip-text: #93c5fd;
  --shadow-toast: 0 6px 20px rgba(0,0,0,.55);
  --shadow-pop: 0 8px 28px rgba(0,0,0,.6);
  --shadow-overlay: 0 20px 60px rgba(0,0,0,.65);
  --shadow-modal: 0 24px 60px rgba(0,0,0,.68);
  --shadow-drawer: -8px 0 30px rgba(0,0,0,.5);
  --backdrop: rgba(0,0,0,.55);
  --backdrop-strong: rgba(0,0,0,.65);
  --chart-pos: #34d399; --chart-neg: #f87171; --chart-neg-fill: color-mix(in srgb, var(--down) 12%, transparent); --chart-pos-fill: color-mix(in srgb, var(--up) 12%, transparent); --chart-pos-soft: color-mix(in srgb, var(--chart-pos) 60%, transparent); --chart-neg-soft: color-mix(in srgb, var(--chart-neg) 60%, transparent);
  --chart-up-bar: color-mix(in srgb, var(--up) 70%, transparent); --chart-down-bar: color-mix(in srgb, var(--down) 70%, transparent);
}

/* ---- structural tokens (theme-invariant) ---- */
:root {
  /* typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* numbers: system mono + tabular so $34,000.00 and −$60.00 share a width.
     No webfont — CSP font-src is 'self' and this file must not fetch. */
  --font-num: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", "Liberation Mono", Menlo, Monaco, Consolas, monospace;
  /* DECIDED 2026-09-05: desktop stays at 10/11px; phones read these two steps
     one px larger (the pointer-coarse lift in terminal.css, mobile review F-13).
     v2.60.0 shipped 11/12px for every pointer (rendered audit F26 — 243 text
     nodes at 10px on the Futures tab at 1280) and Wesley reverted it the same
     day on sight: too big at desktop density. Measured cost had been page
     height Overview +5%, Futures +4%, Portfolio +1%. test/theme.test.mjs pins
     the split so neither half drifts silently. */
  --fs-2xs: 10px;   /* micro labels, table sub-text */
  --fs-xs: 11px;    /* section labels, small notes */
  --fs-sm: 12px;    /* chips, buttons, table cells */
  --fs-md: 13px;    /* dense body (tables, lists) */
  --fs-base: 14px;  /* page base */
  --fs-lg: 15px;    /* emphasized body */
  --fs-xl: 17px;    /* small stat numbers */
  --fs-2xl: 20px;   /* index-tile numbers */
  --fs-stat: 26px;  /* hero stat numbers */
  --tap-min: 44px;  /* touch-target floor (Apple HIG / Material) — pointer-coarse
                       controls take it as min-height, bare-glyph ✕ buttons as
                       min-width too; e2e/mobile-standards.spec.mjs holds it */
  --fs-touch: 16px; /* input floor under coarse pointers — iOS Safari zooms the
                       whole page on focusing any input below 16px */
  /* half-pixel one-offs (9.5–13.5) are legacy — migrate in Phase B, don't add new ones */

  /* line-height scale (defined for new code + Phase B migration — the file
     had 8 ad-hoc values; these three are the intended rhythm) */
  --lh-tight: 1.2;  /* stat numbers, single-line headings */
  --lh-base: 1.55;  /* dense UI prose (popovers, trees, descriptions) */
  --lh-prose: 1.68; /* long-form reading (insights, briefs) */

  /* radii */
  --r-xs: 6px;      /* inputs, small buttons */
  --r-sm: 8px;      /* stat tiles, inner blocks */
  --r-md: 10px;     /* small cards */
  --r-lg: 12px;     /* cards, modals */
  --r-pill: 999px;  /* chips, pills, toast */

  /* sticky chrome: the tab bar's rendered height. The DEFAULT here is the
     desktop bar; 02-tabs.js republishes the live value on the root element
     from a ResizeObserver (62px coarse, 46px on narrow desktops), so the
     section strip sticks exactly under it and a jumped-to card's
     scroll-margin lands it under both. Read it, never hardcode 48. */
  --tabbar-h: 48px;

  /* z-index ladder — take the next named slot, never a bare number */
  --z-cell: 1;               /* sticky first table column — a LOCAL context:
                                above sibling cells, below everything real */
  --z-sticky: 40;            /* sticky tab bar */
  --z-backdrop: 49;          /* drawer backdrops */
  --z-drawer: 50;            /* symphony/ticker drawers */
  --z-chip: 60;              /* error chip */
  --z-toast: 70;             /* toast pill */
  --z-overlay-backdrop: 79;  /* palette/doc backdrops */
  --z-overlay: 80;           /* palette, doc modal */
  --z-popover: 300;          /* ⓘ info popovers */
  --z-splash: 400;           /* boot splash — over the whole app for a few
                                seconds; only the vintage gate (inline 9999,
                                must work without this file) may sit above */

  /* elevation + backdrops live in the THEME blocks above (dark needs heavier
     values — a black shadow over a near-black page carries no lift) */

  /* brand (grad, glow, on-accent) lives in the THEME blocks — a bright ice
     wash on dark and a darker steel on light, so the wordmark stays readable
     on both grounds. */

  /* spacing scale (defined for new code + Phase B migration) */
  --sp-0: 2px; --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;

  /* breakpoints — CSS custom properties can't drive @media conditions, so
     these live here as the single documented list (v3's Tailwind theme reads
     them): 560 phone padding/stacks · 620 low-priority column collapse ·
     720 two-col grids · 860 CFTC/conviction row collapse · 900 dense stat grids */

  /* motion */
  --t-fast: .18s; --t-med: .25s;
  --t-slow: .45s; /* full-screen exits (boot splash) — .25s reads as a glitch at that size */

  /* chart series — resolved into canvas via chartColor() (Chart.js can't
     parse var() strings). The pos/neg tone series is THEME-VARYING and lives
     in the blocks above; the identity series below stays invariant. */
  --chart-line: var(--accent); --chart-line-fill: color-mix(in srgb, var(--chart-line) 8%, transparent);
  --chart-ai: #a855f7; --chart-alt: #0ea5e9; --chart-warm: #f59e0b; --chart-cool: #06b6d4;
  --chart-vol: rgba(148,163,184,0.35);

  /* categorical palette (allocation donut order — append, don't reorder) */
  --cat-1: var(--accent); --cat-2: #0ea5e9; --cat-3: #a855f7; --cat-4: #059669;
  --cat-5: #f59e0b; --cat-6: #dc2626; --cat-7: #14b8a6; --cat-8: #8b5cf6;
  --cat-9: #f97316; --cat-10: #3b82f6; --cat-11: #84cc16;
}
