/* ==========================================================================
   HOUSE TOKENS — instrument-panel system, night (default) + day
   Single source of truth for every operator-facing HTML surface
   (Atlas hub, Tango, LMS, Purchases, operational reports). Copy this block verbatim into
   the page <style>, or link it; never re-declare a hex value in page CSS.
   Exception: personal health reports use a light clinical-dashboard style, not the
   instrument panel (Mitch, 25 Oct 2026; brief in specialist/doctor/references/synthesis.md).
   Validate after any edit:  python3 scripts/contrast_check.py references/tokens.css
   Staged 260925. Palette origin: comms session 260623 (night) + Atlas rules 260624.
   Day palette is a TUNED variant (hues darkened for AA), not an inversion.
   ========================================================================== */

/* ---- Night (default). Applies with no JS and when data-theme="dark". ---- */
:root {
  color-scheme: dark;

  /* Surfaces: elevation is carried by tone, not by shadow. */
  --ground:   #0F1A2B;  /* page background, zero noise */
  --panel:    #142338;  /* card / section surface */
  --panel-2:  #182B45;  /* raised: popover, hover row, selected */
  --rail:     #243A56;  /* borders, dividers, gridlines, tracks */

  /* Ink */
  --ink:      #D7E0EC;  /* primary text */
  --ink-2:    #9AABC3;  /* secondary text: labels, captions, axis ticks */
  --ink-3:    #5E708A;  /* NON-TEXT only: de-emphasised marks, sparklines, disabled */

  /* Semantic axis 1: who acts (human <-> machine). Reserved; one hue, one meaning. */
  --machine:  #38D2C0;  /* automated path, AI action, no human gate */
  --gate:     #F0A641;  /* human-in-the-loop gate, needs-you. Shape + label, never a status dot */

  /* Semantic axis 2: status, matching the universal legend (green, yellow, red, grey). */
  --st-ok:    #62C370;  /* on track, healthy, fresh */
  --st-warn:  #E8CD4A;  /* attention, degraded, aging */
  --st-bad:   #E2645C;  /* blocked, failed, stale, forbidden */
  --st-idle:  #8391A6;  /* inactive, n/a, unknown */
  --st-ok-bg:   rgb(98 195 112 / .14);
  --st-warn-bg: rgb(232 205 74 / .14);
  --st-bad-bg:  rgb(226 100 92 / .14);
  --st-idle-bg: rgb(131 145 166 / .14);

  /* Data series. Never teal, amber or status hues for "series N".
     Default is ONE highlight (--cat-1) against --ink-3; use more only for <=4 true categories. */
  --cat-1:    #7AA7FF;  /* blue: the highlighted series */
  --cat-2:    #B79CFF;  /* violet */
  --cat-3:    #F291B5;  /* rose */
  --cat-4:    #C9B37E;  /* sand */
  --cat-other:#8391A6;  /* "other" bucket, comparison series */
  --wash:     .12;      /* area-fill opacity */

  --focus:    #8AB4FF;  /* focus ring, distinct from every semantic hue */
  --scrim:    rgb(6 12 22 / .6);
  --shadow-pop: 0 8px 24px rgb(0 0 0 / .45);  /* popovers/toggletips ONLY */
}

/* ---- Day. Set by the pre-paint script (stored choice, else OS preference). ---- */
:root[data-theme="light"] {
  color-scheme: light;

  --ground:   #F3F6FA;
  --panel:    #FFFFFF;
  --panel-2:  #EAF0F7;
  --rail:     #CFD9E6;

  --ink:      #13233A;
  --ink-2:    #4B5D76;
  --ink-3:    #8C9BB0;

  --machine:  #0A7F73;
  --gate:     #B25B00;

  --st-ok:    #2E7D32;
  --st-warn:  #8F7400;
  --st-bad:   #C2362D;
  --st-idle:  #66758B;
  --st-ok-bg:   rgb(46 125 50 / .10);
  --st-warn-bg: rgb(143 116 0 / .12);
  --st-bad-bg:  rgb(194 54 45 / .10);
  --st-idle-bg: rgb(102 117 139 / .10);

  --cat-1:    #2F6FE0;
  --cat-2:    #7A55D6;
  --cat-3:    #C2457A;
  --cat-4:    #8C7440;
  --cat-other:#66758B;
  --wash:     .10;

  --focus:    #1F5FD6;
  --scrim:    rgb(19 35 58 / .35);
  --shadow-pop: 0 8px 24px rgb(19 35 58 / .18);
}

/* ---- Theme-independent ---- */
:root {
  /* Type: system stack for prose (fast, offline, native); mono for identifiers only. */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  /* Scale: 14px operate-density base, ~1.2 ratio. Hero is the ONE big number per view. */
  --fs-xs: 0.75rem;   /* 12 axis ticks, footnotes */
  --fs-sm: 0.8125rem; /* 13 labels, table cells */
  --fs-md: 0.875rem;  /* 14 body */
  --fs-lg: 1rem;      /* 16 panel titles */
  --fs-xl: 1.25rem;   /* 20 section titles */
  --fs-2xl: 1.5rem;   /* 24 page title */
  --fs-hero: 3rem;    /* 48 the single lead figure */
  --lh-tight: 1.2;
  --lh-body: 1.5;
  --tracking-caps: 0.08em; /* UPPERCASE structural layer only */

  /* Space: 4px base */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;
  --gutter: 16px;          /* phone side gutter */
  --measure: 72ch;         /* max prose line length */

  /* Radius: a hierarchy, never one radius on everything */
  --r-chip: 3px;  --r-ctl: 6px;  --r-panel: 10px;  --r-pill: 999px;

  /* Motion: enter <= 360ms, exit ~half, nothing >= 500ms */
  --dur-instant: 80ms;
  --dur-fast:   140ms;   /* hover, press, toggletip exit */
  --dur-base:   220ms;   /* toggletip/popover enter, row expand */
  --dur-slow:   360ms;   /* view transition, chart data update */
  --ease-out:  cubic-bezier(.22, 1, .36, 1);   /* entering */
  --ease-in:   cubic-bezier(.55, 0, 1, .45);   /* leaving */
  --ease-std:  cubic-bezier(.4, 0, .2, 1);     /* moving between states */
  --move-1: 4px;  --move-2: 8px;               /* translate distances */

  /* Marks (dataviz) */
  --mark-line: 2px;  --mark-bar-max: 24px;  --mark-dot: 8px;  --mark-gap: 2px;

  /* Hit targets */
  --target-min: 44px;  /* touch; 24px is the WCAG 2.2 AA floor, 44 is the house bar */
}

/* Reduced motion: remove travel, keep short opacity fades. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --move-1: 0px; --move-2: 0px;
    --dur-base: 120ms; --dur-slow: 120ms;
  }
}

/* ---- Base usage (optional; keeps pages consistent) ---- */
html { background: var(--ground); }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font: var(--fs-md)/var(--lh-body) var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
.num, td.num, .figure { font-variant-numeric: tabular-nums; }
.id, code, kbd, samp { font-family: var(--font-mono); font-size: .95em; }
.caps { text-transform: uppercase; letter-spacing: var(--tracking-caps); font-size: var(--fs-xs); font-weight: 600; color: var(--ink-2); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-chip); }

/* Instrument grid texture: control-plane pages only (protocols, spines, pipelines). */
.instrument-grid {
  background-color: var(--ground);
  background-image:
    radial-gradient(ellipse at 50% 0%, transparent 0%, var(--ground) 75%),
    linear-gradient(var(--rail) 1px, transparent 1px),
    linear-gradient(90deg, var(--rail) 1px, transparent 1px);
  background-size: 100% 100%, 64px 64px, 64px 64px;
}

/* Day by OS preference when no choice is stored (same values as the block above). */
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) {
  color-scheme: light;

  --ground:   #F3F6FA;
  --panel:    #FFFFFF;
  --panel-2:  #EAF0F7;
  --rail:     #CFD9E6;

  --ink:      #13233A;
  --ink-2:    #4B5D76;
  --ink-3:    #8C9BB0;

  --machine:  #0A7F73;
  --gate:     #B25B00;

  --st-ok:    #2E7D32;
  --st-warn:  #8F7400;
  --st-bad:   #C2362D;
  --st-idle:  #66758B;
  --st-ok-bg:   rgb(46 125 50 / .10);
  --st-warn-bg: rgb(143 116 0 / .12);
  --st-bad-bg:  rgb(194 54 45 / .10);
  --st-idle-bg: rgb(102 117 139 / .10);

  --cat-1:    #2F6FE0;
  --cat-2:    #7A55D6;
  --cat-3:    #C2457A;
  --cat-4:    #8C7440;
  --cat-other:#66758B;
  --wash:     .10;

  --focus:    #1F5FD6;
  --scrim:    rgb(19 35 58 / .35);
  --shadow-pop: 0 8px 24px rgb(19 35 58 / .18);
} }
