/* ============================================================================
   K6 TERMINAL — central design tokens (brandbook v1.2, 2026-08-19; tokens ongewijzigd sinds v1.1)
   ----------------------------------------------------------------------------
   The ONE design authority for k6trading.app is docs/brandbook/k6_terminal.html
   (Decision #86: every older design canon is retired). This file is its
   executable form: change a token here → the whole app recolors.

   LIGHT is canonical; DARK is a full toggle via html[data-theme="dark"]
   (existing early_theme.js / k6_theme localStorage mechanism).

   Load order contract: this file is injected on EVERY page AFTER tokens.css
   (and after tokens_unified.css on surfaces that link it). The compat layer
   below remaps the legacy variable names onto Terminal values, so all
   existing surfaces recolor without reauthoring. Selectors deliberately
   mirror the legacy files' selectors so ties resolve by source order (this
   file last = Terminal wins) — do not "simplify" them.
   ========================================================================== */

/* ─── 1. Terminal tokens — LIGHT (canonical) ─────────────────────────── */
:root {
  --t-bg:    #FAFAF8;
  --t-panel: #FFFFFF;
  --t-panel2:#F2F1EE;
  --t-line:  #E7E5E0;
  --t-line2: #EFEEEA;
  --t-ink:   #202329;
  /* ink2 and warn carry a deliberate AA reserve: every semantic ink must
     clear 4.5:1 on the TINTED panels below (--*-soft / --u-*-bg), not just
     on --t-panel. The brandbook's original #6A6F78 / #B45309 held 5.0:1 on
     white and then failed on their own 10-11% washes. See
     tests/test_terminal_contrast.py — it recomputes the whole matrix. */
  --t-ink2:  #666B73;
  --t-dim:   #9094A0;
  --t-faint: #B0B4BD;
  --t-ghost: #C3C7CE;
  --t-pos:   #1F7A52;
  --t-neg:   #C22F36;
  --t-warn:  #AB4F09;
  --t-info:  #2F5FD0;
  --t-areaop:.14;
  --t-shadow:0 1px 2px #2023290f, 0 8px 24px #20232908;
  /* On-fill text for accent/pos/neg fills; flips with the theme. */
  --t-onfill:#FFFFFF;
  /* Type — Inter + JetBrains Mono, both self-hosted. */
  --t-sans: 'Inter', -apple-system, 'Segoe UI', system-ui, sans-serif;
  --t-mono: 'JetBrains Mono', Consolas, 'Cascadia Mono', ui-monospace, monospace;
}

/* ─── 2. Terminal tokens — DARK (full toggle) ────────────────────────── */
html[data-theme="dark"],
[data-theme="dark"] {
  --t-bg:    #0B0B0D;
  --t-panel: #101115;
  --t-panel2:#15161A;
  --t-line:  #1A1B1F;
  --t-line2: #141519;
  --t-ink:   #D7D9DE;
  --t-ink2:  #8E919A;
  --t-dim:   #5C5F66;
  --t-faint: #4A4D54;
  --t-ghost: #3D4149;
  --t-pos:   #46C78C;
  /* Dark red is the one semantic ink that had to move a visible amount.
     #E5484D held 4.8:1 on the bare panel but only 3.7:1 on the 16% info
     wash under an open row — and weakening that wash to compensate would
     have cost the "this row is open" signal (measured: it needs 5% to
     pass, at which point it is invisible). Lightening the ink instead
     keeps the wash untouched at full strength. */
  --t-neg:   #FF5C61;
  --t-warn:  #EAB308;
  --t-info:  #6EA8FE;
  --t-areaop:.18;
  --t-shadow:none;
  /* Dark fills are light → readable pairing is near-black text. */
  --t-onfill:#0B0B0D;
}

/* ============================================================================
   3. COMPAT LAYER — legacy variable names → Terminal values.
   Covers tokens.css (v1/v2 names) and tokens_unified.css (--u-* + remaps).
   Derived aliases in those files (--surface, --text-*, --status-*, …) read
   var(--panel)/var(--pos)/… and follow automatically.
   ========================================================================== */

/* ── 3a. Light — beats tokens.css :root (order) and tokens_unified's
   html[data-design="unified"] scope (matching selector, later order).
   The [data-instrument="noir"] variants match the noir instrument block's
   (0,2,1) specificity in tokens_unified.css — without them noir would beat
   this remap in light mode and /partner/pce would render a hybrid palette. */
:root,
html[data-design="unified"],
html[data-design="unified"][data-instrument="noir"] {
  /* Surfaces + lines */
  --bg:            var(--t-bg);
  --ground:        var(--t-bg);
  --panel:         var(--t-panel);
  --panel-2:       var(--t-panel2);
  --border:        var(--t-line);
  --border-2:      var(--t-ghost);
  --border-strong: var(--t-ghost);
  --border-soft:   var(--t-line2);
  /* Foreground scale */
  /* Muted TEXT aliases map to ink2, not dim: legacy fg-3/muted carry 10-12px
     labels and the dim greys sit at ~3:1 (AA-fail). --t-dim stays available
     for surfaces that opt in deliberately (phase 3 reauthoring). */
  --fg:   var(--t-ink);
  --fg-2: var(--t-ink2);
  --fg-3: var(--t-ink2);
  --fg-4: var(--t-ink2);
  --ink:   var(--t-ink);
  --ink-2: var(--t-ink2);
  --ink-3: var(--t-ink2);
  /* Accent — Terminal has ONE action colour: info-blue. */
  --accent:       var(--t-info);
  --accent-hover: color-mix(in srgb, var(--t-info) 86%, var(--t-ink));
  --accent-soft:  color-mix(in srgb, var(--t-info) 10%, var(--t-panel));
  --accent-fg:    var(--t-onfill);
  --accent-ink:   var(--t-onfill);
  /* Semantics + tinted surfaces */
  --pos:       var(--t-pos);
  --pos-soft:  color-mix(in srgb, var(--t-pos) 11%, var(--t-panel));
  --neg:       var(--t-neg);
  --neg-soft:  color-mix(in srgb, var(--t-neg) 10%, var(--t-panel));
  --warn:      var(--t-warn);
  --warn-soft: color-mix(in srgb, var(--t-warn) 11%, var(--t-panel));
  /* Shadows */
  --shadow-sm: var(--t-shadow);
  --shadow-md: var(--t-shadow);
  /* Type (unified names; tokens.css pages inherit via body rule below) */
  --font-display: var(--t-sans);
  --font-sans:    var(--t-sans);
  --font-mono:    var(--t-mono);
  --mono:         var(--t-mono);
  --sans:         var(--t-sans);
  /* Per-category launcher spines (/home) — one calm Terminal voice. */
  --home-accent-ops:      var(--t-pos);
  --home-accent-research: var(--t-warn);
  --home-accent-finance:  var(--t-info);
  --home-accent-system:   var(--t-dim);
}

/* Unified --u-* names (only exist under the unified scope). */
html[data-design="unified"],
html[data-design="unified"][data-instrument="noir"] {
  --u-ink:    var(--t-ink);
  --u-ink-2:  var(--t-ink2);
  --u-muted:  var(--t-ink2); /* AA — see the fg-3 note above */
  --u-line:   var(--t-line);
  --u-paper:  var(--t-bg);
  --u-panel:  var(--t-panel);
  --u-accent: var(--t-info);
  --u-pos: var(--t-pos); --u-pos-bg: color-mix(in srgb, var(--t-pos) 11%, var(--t-panel));
  --u-neg: var(--t-neg); --u-neg-bg: color-mix(in srgb, var(--t-neg) 10%, var(--t-panel));
  --u-att: var(--t-warn); --u-att-bg: color-mix(in srgb, var(--t-warn) 11%, var(--t-panel));
  --u-f: var(--t-sans);
  --u-m: var(--t-mono);
  --text-1: var(--t-ink);
  --text-2: var(--t-ink2);
  --text-3: var(--t-ink2);
  --surface: var(--t-panel);
}

/* ── 3b. Dark — must re-state the full remap: tokens.css and
   tokens_unified.css both define these names inside their own dark blocks
   (stamped on <html> AND <body>), which would otherwise win on descendants. */
[data-theme="dark"],
html[data-design="unified"][data-theme="dark"],
html[data-design="unified"] [data-theme="dark"] {
  --bg:            var(--t-bg);
  --ground:        var(--t-bg);
  --panel:         var(--t-panel);
  --panel-2:       var(--t-panel2);
  --border:        var(--t-line);
  --border-2:      var(--t-ghost);
  --border-strong: var(--t-ghost);
  --border-soft:   var(--t-line2);
  --fg:   var(--t-ink);
  --fg-2: var(--t-ink2);
  --fg-3: var(--t-ink2);
  --fg-4: var(--t-ink2);
  --ink:   var(--t-ink);
  --ink-2: var(--t-ink2);
  --ink-3: var(--t-ink2);
  --accent:       var(--t-info);
  --accent-hover: color-mix(in srgb, var(--t-info) 86%, var(--t-ink));
  --accent-soft:  color-mix(in srgb, var(--t-info) 16%, var(--t-panel));
  --accent-fg:    var(--t-onfill);
  --accent-ink:   var(--t-onfill);
  --pos:       var(--t-pos);
  --pos-soft:  color-mix(in srgb, var(--t-pos) 15%, var(--t-panel));
  --neg:       var(--t-neg);
  --neg-soft:  color-mix(in srgb, var(--t-neg) 14%, var(--t-panel));
  --warn:      var(--t-warn);
  --warn-soft: color-mix(in srgb, var(--t-warn) 14%, var(--t-panel));
  --shadow-sm: var(--t-shadow);
  --shadow-md: var(--t-shadow);
  --home-accent-ops:      var(--t-pos);
  --home-accent-research: var(--t-warn);
  --home-accent-finance:  var(--t-info);
  --home-accent-system:   var(--t-dim);
}
html[data-design="unified"][data-theme="dark"],
html[data-design="unified"] [data-theme="dark"] {
  --u-ink:    var(--t-ink);
  --u-ink-2:  var(--t-ink2);
  --u-muted:  var(--t-ink2);
  --u-line:   var(--t-line);
  --u-paper:  var(--t-bg);
  --u-panel:  var(--t-panel);
  --u-accent: var(--t-info);
  --u-pos: var(--t-pos); --u-pos-bg: color-mix(in srgb, var(--t-pos) 15%, var(--t-panel));
  --u-neg: var(--t-neg); --u-neg-bg: color-mix(in srgb, var(--t-neg) 14%, var(--t-panel));
  --u-att: var(--t-warn); --u-att-bg: color-mix(in srgb, var(--t-warn) 14%, var(--t-panel));
  --u-f: var(--t-sans);
  --u-m: var(--t-mono);
  --text-1: var(--t-ink);
  --text-2: var(--t-ink2);
  --text-3: var(--t-ink2);
  --surface: var(--t-panel);
}

/* ── 3c. .k6-shell accent re-pin — tokens.css recomputes --accent per tool
   ON the shell element (data-tool hues) and tokens_unified re-pins it again;
   both are element-level definitions that beat any inherited value, so the
   Terminal accent must be re-pinned at the same (or matching) selectors. */
.k6-shell,
html[data-design="unified"] .k6-shell {
  --accent:       var(--t-info);
  --accent-hover: color-mix(in srgb, var(--t-info) 86%, var(--t-ink));
  --accent-soft:  color-mix(in srgb, var(--t-info) 10%, var(--t-panel));
  --accent-fg:    var(--t-onfill);
  --accent-ink:   var(--t-onfill);
}
[data-theme="dark"] .k6-shell,
html[data-design="unified"][data-theme="dark"] .k6-shell,
html[data-design="unified"] [data-theme="dark"] .k6-shell {
  --accent:       var(--t-info);
  --accent-hover: color-mix(in srgb, var(--t-info) 86%, var(--t-ink));
  --accent-soft:  color-mix(in srgb, var(--t-info) 16%, var(--t-panel));
  --accent-fg:    var(--t-onfill);
  --accent-ink:   var(--t-onfill);
}
