/* =========================================================================
 * QUANT–DESK Terminal — design tokens
 *
 * Theming rule (DESIGN.md §6): light tokens on bare :root; dark under
 * @media (prefers-color-scheme: dark) guarded by :root:not([data-theme="light"]),
 * and again under :root[data-theme="dark"]. Every colour token has its
 * definition on bare :root first — nothing is defined ONLY inside a media or
 * [data-theme] block. The two dark blocks must stay identical; the contrast
 * script (assets/terminal/_dev/contrast.py) fails if they drift.
 *
 * terminal.html ships <html data-theme="dark"> so a first run with no stored
 * preference is dark with no flash; boot.js then applies the stored choice
 * ("system" removes the attribute and lets the OS decide).
 *
 * Up / down are teal / vermilion — separated on the blue–yellow axis, so they
 * stay apart under protanopia and deuteranopia (validated with the dataviz
 * validator: candle pair CVD ΔE 12.5 dark / 12.2 light, normal-vision ΔE
 * 27.4 / 26.9; text pair CVD ΔE 13.1 dark / 10.4 light). They are never the
 * only signal: every up/down value carries a sign and ▲/▼ (ui.fmt.change).
 *
 * MEASURED CONTRAST (WCAG 2.x relative luminance) — generated by
 *   python3 assets/terminal/_dev/contrast.py
 * Text needs >= 4.5:1, UI glyphs / control boundaries >= 3:1, on every
 * surface they are used on (surface, surface-2, raised, sunken, chart).
 * Numbers are the WORST ratio across those surfaces.
 *
 *   token / pair                                    role   light   dark
 *   --c-text                                        text   15.26  11.55
 *   --c-text-2                                      text    7.24   7.00
 *   --c-text-3                                      text    5.34   5.16
 *   --c-accent                                      text    5.16   6.47
 *   --c-up                                          text    5.67   6.92
 *   --c-down                                        text    5.11   5.61
 *   --c-ok                                          text    5.54   7.02
 *   --c-warn                                        text    5.81   8.25
 *   --c-crit                                        text    5.26   5.27
 *   --c-candle-up                                   glyph   4.15   6.13
 *   --c-candle-down                                 glyph   4.03   5.51
 *   --c-control-border                              glyph   3.34   3.40
 *   --c-focus                                       glyph   5.31   6.47
 *   --c-plan-entry                                  glyph   5.85   7.61
 *   --c-plan-stop                                   glyph   5.79   6.20
 *   --c-plan-target                                 glyph   6.11   8.25
 *   --c-event-flag                                  glyph   6.40   9.71
 *   --c-stop-bg                                     glyph   5.88   3.54
 *   --c-accent-fg on --c-accent-bg                  text    5.85   4.72
 *   --c-accent-fg on --c-accent-bg-hover            text    7.56   5.90
 *   --c-stop-fg on --c-stop-bg                      text    5.88   5.17
 *   --c-stop-fg on --c-stop-bg-hover                text    7.70   6.66
 *   --c-live-fg on --c-live-bg                      text    9.95   9.59
 *   --c-ok on --c-ok-bg                             text    5.29   6.79
 *   --c-warn on --c-warn-bg                         text    5.67   7.92
 *   --c-crit on --c-crit-bg                         text    4.75   5.20
 *   --c-accent on --c-accent-soft                   text    4.95   5.35
 *   --c-text on --c-selected                        text   15.26  11.55
 *   --c-text on --c-up-soft                         text   15.75  11.32
 *   --c-text on --c-down-soft                       text   15.21  12.39
 *   --c-paper-fg on --c-surface                     text    8.68   8.85
 * (full per-surface table: run the script)
 * ========================================================================= */

:root {
  color-scheme: light;

  /* ---- type ---------------------------------------------------------- */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
             "Noto Sans", "Liberation Sans", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Mono", "Roboto Mono",
               Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", monospace;
  --fs-2xs: 10px;
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-md: 13px;
  --fs-lg: 15px;
  --fs-xl: 18px;
  --fs-2xl: 22px;
  --lh-tight: 1.2;
  --lh: 1.4;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
  --tracking-caps: 0.04em;

  /* ---- space, radii, sizes ------------------------------------------- */
  --sp-0: 2px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --r-1: 3px;
  --r-2: 4px;
  --r-3: 6px;
  --r-4: 8px;
  --r-pill: 999px;
  --h-topbar: 48px;
  --h-topbar-compact: 44px;
  --h-status: 24px;
  --w-rail: 44px;
  --w-side: 320px;
  --w-side-overlay: 340px;
  --h-tabs: 32px;
  --h-control: 28px;
  --h-control-sm: 24px;
  --h-row: 26px;
  --icon: 18px;
  --icon-sm: 14px;
  --bottom-default: 240px;
  --chart-min: 160px;
  --gutter: 1px;                 /* hairline gap between docked regions */

  /* ---- motion (information only) ------------------------------------- */
  --t-fast: 80ms;
  --t-med: 140ms;
  --flash: 600ms;

  /* ---- layers -------------------------------------------------------- */
  --z-rail: 10;
  --z-overlay-panel: 30;
  --z-drawer: 60;
  --z-modal: 70;
  --z-menu: 80;
  --z-toast: 90;
  --z-tip: 100;

  /* ==== COLOUR — light ================================================ */
  --c-bg: #e9ecf0;               /* page plane: the hairline gaps between regions */
  --c-surface: #ffffff;          /* bars, rails, panels */
  --c-surface-2: #f5f6f8;        /* panel headers, table headers, tab strips */
  --c-raised: #ffffff;           /* menus, modals, toasts (with shadow) */
  --c-sunken: #f2f4f7;           /* inputs, code, wells */
  --c-chart: #ffffff;            /* chart background */
  --c-hover: #eef1f5;            /* row / button hover wash */
  --c-selected: #e4ebf6;         /* selected row / active rail item */
  --c-border: #dce0e6;           /* hairlines between regions and rows */
  --c-border-strong: #c7cdd6;    /* table header rule, raised outlines */
  --c-control-border: #7d8694;   /* input / button boundary (>= 3:1) */
  --c-grid: #eef0f3;             /* chart grid (recessive by design) */

  --c-text: #12151a;
  --c-text-2: #444c58;
  --c-text-3: #5b6371;           /* muted — still >= 4.5:1 */
  --c-text-inverse: #ffffff;

  --c-accent: #1a5fd0;           /* links, active tab text, selected glyphs */
  --c-accent-bg: #1a5fd0;        /* primary button fill */
  --c-accent-bg-hover: #154fb0;
  --c-accent-fg: #ffffff;
  --c-accent-soft: #e3edfc;      /* active tab / chip wash */
  --c-focus: #1a5fd0;

  --c-up: #006b60;               /* up text: teal */
  --c-down: #b8390c;             /* down text: vermilion */
  --c-candle-up: #0f8c7c;
  --c-candle-down: #d9531e;
  --c-up-soft: #dff2ef;          /* quote-flash wash */
  --c-down-soft: #fbe6dc;

  --c-ok: #17712f;               /* PASS, confirmed */
  --c-ok-bg: #e2f3e6;
  --c-warn: #845500;             /* WARN, stale, degraded */
  --c-warn-bg: #fdf0d5;
  --c-crit: #c42424;             /* FAIL, INCIDENT, halted */
  --c-crit-bg: #fce3e3;
  --c-info: #1a5fd0;
  --c-info-bg: #e3edfc;

  --c-stop-bg: #c8102e;          /* the STOP button */
  --c-stop-bg-hover: #a70d26;
  --c-stop-fg: #ffffff;
  --c-live-bg: #f0b429;          /* LIVE badge: real money */
  --c-live-fg: #1a1204;
  --c-paper-fg: #444c58;         /* PAPER badge: outline only */

  --c-scrim: rgba(18, 21, 26, 0.38);
  --c-shadow: rgba(18, 21, 26, 0.16);
  --shadow-1: 0 1px 2px var(--c-shadow);
  --shadow-2: 0 6px 24px var(--c-shadow), 0 1px 3px var(--c-shadow);

  /* chart roles (read by the chart build through ui.cssVar) */
  --c-chart-text: #444c58;
  --c-chart-crosshair: #5b6371;
  --c-volume-up: rgba(15, 140, 124, 0.28);
  --c-volume-down: rgba(217, 83, 30, 0.28);
  --c-plan-entry: #1a5fd0;
  --c-plan-stop: #c42424;
  --c-plan-target: #17712f;
  --c-event-flag: #845500;

  /* categorical series (indicators) — dataviz reference palette, light steps.
     Next to candles prefer 1, 4, 5, 7: slots 2 and 3 sit near down / up. */
  --c-series-1: #2a78d6;
  --c-series-2: #eb6834;
  --c-series-3: #1baf7a;
  --c-series-4: #eda100;
  --c-series-5: #e87ba4;
  --c-series-6: #008300;
  --c-series-7: #4a3aa7;
  --c-series-8: #e34948;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --c-bg: #0b0d11;
    --c-surface: #12151b;
    --c-surface-2: #171b22;
    --c-raised: #1d222b;
    --c-sunken: #0e1115;
    --c-chart: #0f1216;
    --c-hover: #1b2029;
    --c-selected: #1f2a3b;
    --c-border: #232833;
    --c-border-strong: #313744;
    --c-control-border: #6b7487;
    --c-grid: #1a1e26;

    --c-text: #e3e6eb;
    --c-text-2: #aeb5c0;
    --c-text-3: #8b93a1;
    --c-text-inverse: #0b0d11;

    --c-accent: #6aa6ff;
    --c-accent-bg: #2f6fde;
    --c-accent-bg-hover: #2760c4;
    --c-accent-fg: #ffffff;
    --c-accent-soft: #1d3050;
    --c-focus: #6aa6ff;

    --c-up: #2ebfa5;
    --c-down: #ff6a3d;
    --c-candle-up: #22a590;
    --c-candle-down: #e8603a;
    --c-up-soft: #12302b;
    --c-down-soft: #3a1c12;

    --c-ok: #4cc26a;
    --c-ok-bg: #12291b;
    --c-warn: #e8b23a;
    --c-warn-bg: #2d2410;
    --c-crit: #ff5c5c;
    --c-crit-bg: #3d1719;
    --c-info: #6aa6ff;
    --c-info-bg: #16243a;

    --c-stop-bg: #d42037;
    --c-stop-bg-hover: #b51a2f;
    --c-stop-fg: #ffffff;
    --c-live-bg: #e8b23a;
    --c-live-fg: #1a1204;
    --c-paper-fg: #aeb5c0;

    --c-scrim: rgba(0, 0, 0, 0.55);
    --c-shadow: rgba(0, 0, 0, 0.5);

    --c-chart-text: #aeb5c0;
    --c-chart-crosshair: #8b93a1;
    --c-volume-up: rgba(34, 165, 144, 0.30);
    --c-volume-down: rgba(232, 96, 58, 0.30);
    --c-plan-entry: #6aa6ff;
    --c-plan-stop: #ff5c5c;
    --c-plan-target: #4cc26a;
    --c-event-flag: #e8b23a;

    --c-series-1: #3987e5;
    --c-series-2: #d95926;
    --c-series-3: #199e70;
    --c-series-4: #c98500;
    --c-series-5: #d55181;
    --c-series-6: #008300;
    --c-series-7: #9085e9;
    --c-series-8: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --c-bg: #0b0d11;
  --c-surface: #12151b;
  --c-surface-2: #171b22;
  --c-raised: #1d222b;
  --c-sunken: #0e1115;
  --c-chart: #0f1216;
  --c-hover: #1b2029;
  --c-selected: #1f2a3b;
  --c-border: #232833;
  --c-border-strong: #313744;
  --c-control-border: #6b7487;
  --c-grid: #1a1e26;

  --c-text: #e3e6eb;
  --c-text-2: #aeb5c0;
  --c-text-3: #8b93a1;
  --c-text-inverse: #0b0d11;

  --c-accent: #6aa6ff;
  --c-accent-bg: #2f6fde;
  --c-accent-bg-hover: #2760c4;
  --c-accent-fg: #ffffff;
  --c-accent-soft: #1d3050;
  --c-focus: #6aa6ff;

  --c-up: #2ebfa5;
  --c-down: #ff6a3d;
  --c-candle-up: #22a590;
  --c-candle-down: #e8603a;
  --c-up-soft: #12302b;
  --c-down-soft: #3a1c12;

  --c-ok: #4cc26a;
  --c-ok-bg: #12291b;
  --c-warn: #e8b23a;
  --c-warn-bg: #2d2410;
  --c-crit: #ff5c5c;
  --c-crit-bg: #3d1719;
  --c-info: #6aa6ff;
  --c-info-bg: #16243a;

  --c-stop-bg: #d42037;
  --c-stop-bg-hover: #b51a2f;
  --c-stop-fg: #ffffff;
  --c-live-bg: #e8b23a;
  --c-live-fg: #1a1204;
  --c-paper-fg: #aeb5c0;

  --c-scrim: rgba(0, 0, 0, 0.55);
  --c-shadow: rgba(0, 0, 0, 0.5);

  --c-chart-text: #aeb5c0;
  --c-chart-crosshair: #8b93a1;
  --c-volume-up: rgba(34, 165, 144, 0.30);
  --c-volume-down: rgba(232, 96, 58, 0.30);
  --c-plan-entry: #6aa6ff;
  --c-plan-stop: #ff5c5c;
  --c-plan-target: #4cc26a;
  --c-event-flag: #e8b23a;

  --c-series-1: #3987e5;
  --c-series-2: #d95926;
  --c-series-3: #199e70;
  --c-series-4: #c98500;
  --c-series-5: #d55181;
  --c-series-6: #008300;
  --c-series-7: #9085e9;
  --c-series-8: #e66767;
}
