/* ════════════════════════════════════════════════════════════════════════════
   sleeppi-tokens.css — SleepPi semantic token shim  (PROTOTYPE / SAMPLE)
   ----------------------------------------------------------------------------
   Import order: base → THIS SHIM → theme palettes (sleeppi-themes.css) →
   component/prototype CSS (oscar-webtui.css).

   Provides (a) DEFAULT values for every --sp-* token (fallback = calm dark, so
   the prototype renders even with no theme attribute), (b) the WebTUI plumbing
   bridge (--background0..3 / --foreground0..2 / border / font), and (c) the
   ENGINE-GLUE ALIASES: the legacy var names the components + graph engine read
   (--bg, --panel, --c-flow, --ev-*, ...) are redefined as var(--sp-*), so
   switching `html[data-webtui-theme]` re-themes chrome AND graphs with no engine
   change. Theme files only need to override --sp-* tokens.

   Colour rules baked in: O₂ absent / audit-only / missing-data use MUTED neutral
   tokens (never status-crit red). Pulse is a labelled coral/red trace only.
   ════════════════════════════════════════════════════════════════════════════ */

:root {
  /* ── WebTUI/prototype plumbing (font is theme-invariant; colours bridge to --sp-*) */
  --font-family: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --font-size: 13px;
  --line-height: 1.5;
  --ui: var(--font-family);

  /* ── SleepPi semantic aliases (defaults — calm dark fallback) ─────────────── */
  --sp-page-bg: #1a1b26;
  --sp-panel-bg: #1f2335;
  --sp-panel-bg-alt: #24283b;
  --sp-text-primary: #c0caf5;
  --sp-text-secondary: #a9b1d6;
  --sp-text-muted: #565f89;
  --sp-border: #2f334d;
  --sp-border-table: #292e42;
  --sp-separator: #262a3f;
  --sp-status-ok: #9ece6a;
  --sp-status-info: #7aa2f7;
  --sp-status-warn: #e0af68;
  --sp-status-crit: #f7768e;
  --sp-status-muted: #565f89;
  --sp-faint-strength: 0.45;
  --sp-glow-strength: 0.5;

  /* ── graph evidence tokens (defaults) ─────────────────────────────────────── */
  --sp-graph-flow: #c0caf5;
  --sp-graph-pressure: #9ece6a;
  --sp-graph-leak: #e0af68;
  --sp-graph-flow-limitation: #7dcfff;
  --sp-graph-snore: #cf9de0;
  --sp-graph-spo2: #7aa2f7;
  --sp-graph-pulse: #f7768e;
  --sp-graph-event-flag: #7aa2f7;
  --sp-graph-rera: #9ece6a;
  --sp-graph-pulse-spike: #ff9e64;
  --sp-graph-glasgow-v2: #bb9af7;
  --sp-graph-glasgow-v1-audit: #565f89;   /* audit-only → muted, NOT severity */
  --sp-graph-ned-drop: #db6b8f;
  --sp-graph-artifact: #565f89;            /* muted, never alarming */
  --sp-graph-session-gap: rgba(192,202,245,0.05);
  --sp-graph-grid: #232742;
  --sp-graph-axis: #3b4261;
  --sp-graph-cursor: #7aa2f7;
  --sp-graph-selection: #7aa2f7;
  --sp-graph-window-highlight: rgba(122,162,247,0.16);

  /* ── interpretation / guardrail tokens (defaults) ─────────────────────────── */
  --sp-airway-burden: #bb9af7;
  --sp-autonomic-burden: #ff9e64;
  --sp-oxygen-guardrail: #7aa2f7;
  --sp-leak-guardrail: #e0af68;
  --sp-central-watch: #7dcfff;
  --sp-data-quality: #9ece6a;
  --sp-absent-o2-neutral: #565f89;         /* O₂ absent = neutral/muted, NOT red */
  --sp-experimental-badge: #ff9e64;        /* proxy/experimental — distinct from canonical */
  --sp-audit-only-badge: #565f89;          /* audit-only — muted, not severity */

  /* ── surface-separation tokens (defaults fall back to existing --sp-* so other
        themes render identically; per-theme overrides create layered surfaces) ── */
  --sp-app-chrome-bg: var(--sp-panel-bg-alt);       /* menubar/tabs/status/date/footer chrome */
  --sp-rail-bg: var(--sp-page-bg);                  /* left rail zone (defaults to canvas) */
  --sp-panel-bg-raised: var(--sp-panel-bg);         /* most-raised surface (active blocks) */
  --sp-panel-header-bg: var(--sp-panel-bg-alt);     /* panel/card header */
  --sp-graph-bg: var(--sp-panel-bg);                /* graph CONTAINER surface (main) */
  --sp-graph-lane-bg: var(--sp-panel-bg);           /* graph LANE plot surface (was --panel) */
  --sp-graph-lane-alt-bg: var(--sp-graph-lane-bg);  /* alternating lane tint */
  --sp-graph-lane-header-bg: var(--sp-panel-bg-alt);/* lane title bar (was --head) */
  --sp-inspector-bg: var(--sp-panel-bg);            /* right inspector surface */
  --sp-border-strong: var(--sp-border);             /* definition where tone alone isn't enough */
  --sp-shadow-subtle: none;                         /* optional lift on raised panels */

  /* ── WebTUI plumbing bridge (from --sp-*) ─────────────────────────────────── */
  --background0: var(--sp-page-bg);
  --background1: var(--sp-panel-bg);
  --background2: var(--sp-panel-bg-alt);
  --background3: var(--sp-panel-bg-alt);
  --foreground0: var(--sp-text-primary);
  --foreground1: var(--sp-text-secondary);
  --foreground2: var(--sp-text-muted);
  --box-border-color: var(--sp-border);
  --table-border-color: var(--sp-border-table);
  --separator-color: var(--sp-separator);

  /* ── ENGINE-GLUE ALIASES: legacy names the JS/components read → --sp-* ─────── */
  --bg: var(--sp-page-bg);
  --bg2: var(--sp-app-chrome-bg);           /* chrome surface (was --sp-panel-bg-alt) */
  --panel: var(--sp-graph-lane-bg);         /* graph plot/lane fill (was --sp-panel-bg) */
  --panel-alt: var(--sp-panel-bg-alt);
  --head: var(--sp-graph-lane-header-bg);   /* graph lane header (was --sp-panel-bg-alt) */
  --border: var(--sp-border);
  --border-lt: var(--sp-border);
  --border-dim: var(--sp-separator);
  --text: var(--sp-text-primary);
  --text-sec: var(--sp-text-secondary);
  --text-mut: var(--sp-text-muted);
  --text-dim: var(--sp-text-muted);
  --link: var(--sp-status-info);
  --accent: var(--sp-graph-selection);
  --sel: color-mix(in srgb, var(--sp-graph-selection) 16%, transparent);
  --sel-border: var(--sp-graph-selection);

  --grid: var(--sp-graph-grid);
  --grid-strong: var(--sp-graph-axis);
  --gap-band: var(--sp-graph-session-gap);
  --c-flow: var(--sp-graph-flow);
  --c-pres: var(--sp-graph-pressure);
  --c-leak: var(--sp-graph-leak);
  --c-fl: var(--sp-graph-flow-limitation);
  --c-glas: var(--sp-graph-glasgow-v2);
  --c-ned: var(--sp-graph-ned-drop);
  --c-snore: var(--sp-graph-snore);
  --c-spo2: var(--sp-graph-spo2);
  --c-pulse: var(--sp-graph-pulse);
  --c-clean: var(--sp-data-quality);
  --c-leak-thr: var(--sp-leak-guardrail);
  --c-therapy: var(--sp-graph-selection);
  --ev-OA: var(--sp-status-crit);          /* scored obstructive event — red is a real event, not missing data */
  --ev-H: var(--sp-status-warn);
  --ev-CA: var(--sp-status-info);
  --ev-RE: var(--sp-graph-rera);
  --ev-FL: var(--sp-graph-flow-limitation);
  --ok: var(--sp-status-ok);
  --warn: var(--sp-status-warn);
  --crit: var(--sp-status-crit);
  --idle: var(--sp-absent-o2-neutral);
}
