/* ==========================================================================
   V2 Design System — canonical token stylesheet (reference implementation)
   Copied from the Link-to-web-saas-v2 reference tokens (docs/reference/link-to-web-design-system/foundation.md)
   (incl. Appendix B component-stage additions, 2026-06-12).

   Rules (foundation §1):
   - Two tiers: primitive → semantic. No component tokens.
   - Every themed token appears in all three theme blocks below.
   - Locked CLAUDE.md tokens keep their exact names/values — never redefined.
   - Components consume var(--…) only; zero hardcoded colors in component CSS.
   ========================================================================== */

/* == Midnight (default dark) — matches :root ============================== */
:root,
[data-theme="midnight"] {
  /* -- Locked CLAUDE.md palette (immovable) ------------------------------ */
  --bg: #04060d;
  --surface: #0b0f1a;
  --stroke: #1e2a45;
  --text: #e8eaf0;
  --muted: #8a94a6;
  --blue: #16a3ff;
  --orange: #ff9a1f;
  --required-text: #ff9a1f; /* "(required)" labels: 9.02:1 on --surface */
  --chart-bar: #519ced;   /* admin bars: dataviz reference blue ramp, validated 3:1+ on this surface (D-109) */
  --chart-track: #1b2333;
  --red: #ef4444;
  --green: #22c55e;
  --yellow: #eab308;
  --panel-bg: rgba(11, 15, 26, .92);

  /* -- Surfaces & elevation (foundation §2) ------------------------------ */
  --elev-0: var(--bg);       /* page canvas */
  --elev-1: var(--surface);  /* card / panel */
  --elev-2: #121a2b;         /* nested card, hover-raised, input-on-card */
  --elev-3: #1a243d;         /* dropdown, popover, drawer, modal */
  --elev-4: #212f4f;         /* toast, tooltip, dropdown-on-modal */
  --shadow-1: 0 1px 3px rgba(0, 0, 0, .5);
  --shadow-2: 0 4px 12px rgba(0, 0, 0, .45);
  --shadow-3: 0 8px 24px rgba(0, 0, 0, .5);

  /* -- Borders (foundation §2.3, §4.3) ----------------------------------- */
  --stroke-strong: #2c3b5e;
  --border-w: 1px;
  --border-w-strong: 2px;

  /* -- Text tiers (foundation §5.3) --------------------------------------- */
  --text-2: #aab4c8;         /* secondary; minimum tier on --elev-3/4 */
  --text-floor: 12px;
  --font-weight-body: 400;

  /* -- Accent ramp + focus (foundation §5.5, §9.3) ------------------------ */
  --blue-fill: #16a3ff;
  --blue-fill-text: #04060d; /* dark text — white on #16a3ff is 2.72:1, fail */
  --blue-hover: #3db1ff;
  --blue-active: #0e8fe2;
  --focus: #16a3ff;

  /* -- Destructive ramp (foundation Appendix B.2) ------------------------- */
  --red-fill: #ef4444;
  --red-fill-text: #04060d;  /* dark text — white on #ef4444 is 3.76:1, fail */
  --red-hover: #f36b6b;
  --red-active: #e23d3d;

  /* -- Interaction state layers (foundation §9.1) ------------------------- */
  --state-hover: rgba(255, 255, 255, .06);
  --state-active: rgba(255, 255, 255, .10);
  --state-selected: rgba(22, 163, 255, .10); /* composites to #0c1e31 on --surface */

  /* -- Status badge triplets (foundation §5.4) ---------------------------- */
  --status-blue-bg: #0c2135;
  --status-blue-border: #0e3b5f;
  --status-blue-text: #5cbdff;
  --status-green-bg: #0e2522;
  --status-green-border: #12462e;
  --status-green-text: #4ade80;
  --status-yellow-bg: #262318;
  --status-yellow-border: #4e4015;
  --status-yellow-text: #facc15;
  --status-orange-bg: #28201b;
  --status-orange-border: #54391c;
  --status-orange-text: #ffb558;
  --status-red-bg: #26151f;
  --status-red-border: #4f1f27;
  --status-red-text: #f87171;

  /* -- Glass (foundation §6) ----------------------------------------------- */
  --glass-bg: var(--panel-bg);
  --glass-blur: 12px;

  /* -- Overlay scrim (foundation Appendix B.1) ----------------------------- */
  --scrim: rgba(0, 0, 0, .60);

  /* -- Chart inks (foundation Appendix B.3) -------------------------------- */
  --chart-1: #33b1ff; /* blue    */
  --chart-2: #be95ff; /* purple  */
  --chart-3: #3ddbd9; /* teal    */
  --chart-4: #ff7eb6; /* magenta */
  --chart-5: #f1c21b; /* gold    */
  --chart-6: #6fdc8c; /* green   */
  --chart-grid: #182440; /* quieter than --stroke */

  /* -- Touch / control geometry (themed; foundation §4.3, §10, App. B.4) --- */
  --tap-min: 44px;
  --chip-h: 32px;

  /* ========================================================================
     Non-themed structural tokens — identical in all themes (foundation §1).
     Declared once here; the light/field blocks override colors/effects only.
     ======================================================================== */

  /* -- Spacing — 4px grid, 12 steps (foundation §4.1) ----------------------- */
  --space-0: 0;
  --space-2: 2px;
  --space-4: 4px;
  --space-6: 6px;
  --space-8: 8px;
  --space-12: 12px;
  --space-16: 16px;
  --space-20: 20px;
  --space-24: 24px;
  --space-32: 32px;
  --space-48: 48px;
  --space-64: 64px;

  /* -- Type scale (foundation §3.1) — each step is one composite token:
        size / line-height / tracking are applied together, never recombined */
  --font-1-size: 0.75rem;   --font-1-lh: 16px; --font-1-track: 0.32px;
  --font-2-size: 0.875rem;  --font-2-lh: 20px; --font-2-track: 0.16px;
  --font-3-size: 1rem;      --font-3-lh: 24px; --font-3-track: 0;
  --font-4-size: 1.125rem;  --font-4-lh: 26px; --font-4-track: 0;
  --font-5-size: 1.25rem;   --font-5-lh: 28px; --font-5-track: -0.01em;
  --font-6-size: 1.5rem;    --font-6-lh: 32px; --font-6-track: -0.01em;
  --font-7-size: 1.75rem;   --font-7-lh: 36px; --font-7-track: -0.015em;
  --font-8-size: 2rem;      --font-8-lh: 40px; --font-8-track: -0.02em;

  /* -- Font stacks (foundation §3.5) — self-hosted Inter variable ----------- */
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  /* -- Radius (foundation §4.2) --------------------------------------------- */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* -- Motion (foundation §7.1) — two easings only; identical in all themes - */
  --dur-instant: 0ms;
  --dur-fast: 100ms;
  --dur-base: 150ms;
  --dur-slow: 250ms;
  --dur-deliberate: 400ms;                    /* nothing above except scrim */
  --ease-out: cubic-bezier(0, 0, 0.38, 0.9);  /* entrances, state changes */
  --ease-in: cubic-bezier(0.2, 0, 1, 0.9);    /* exits */
  --ease-linear: linear;                      /* spinners, progress, scrim */

  /* -- Z-index ladder (foundation §1) — identical in all themes ------------- */
  --z-rail: 100;
  --z-topbar: 200;
  --z-notice: 300;
  --z-aqbar: 400;
  --z-dropdown: 1000;
  --z-sticky: 1100;
  --z-overlay: 1200;
  --z-modal: 1300;
  --z-toast: 1400;

  /* -- Breakpoints (foundation §11) — custom properties cannot drive media
        queries; values are duplicated literally in @media rules:
          --bp-tablet: 768px   --bp-desktop: 980px   --bp-wide: 1280px
        Mobile-first, min-width only. 375–430px is the design baseline. ------ */
}

/* == Light ================================================================= */
[data-theme="light"] {
  /* -- Locked CLAUDE.md palette ------------------------------------------- */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --stroke: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --blue: #0284c7;
  --orange: #ea580c;
  --required-text: #c2410c; /* "(required)" labels: 5.18:1 on --surface, 4.73:1 on --bg (brand #ea580c is 3.56:1, fails) */
  --chart-bar: #2370cd;   /* admin bars: dataviz reference blue ramp, validated 3:1+ on this surface (D-109) */
  --chart-track: #e2e8f0;
  --red: #dc2626;
  --green: #16a34a;
  --yellow: #ca8a04;
  --panel-bg: rgba(255, 255, 255, .95);

  /* -- Surfaces & elevation ------------------------------------------------ */
  --elev-0: var(--bg);
  --elev-1: var(--surface);
  --elev-2: #ffffff;
  --elev-3: #ffffff;
  --elev-4: #ffffff;
  --shadow-1: 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-2: 0 4px 12px rgba(15, 23, 42, .12);
  --shadow-3: 0 12px 32px rgba(15, 23, 42, .16);

  /* -- Borders -------------------------------------------------------------- */
  --stroke-strong: #cbd5e1;
  --border-w: 1px;
  --border-w-strong: 2px;

  /* -- Text tiers ------------------------------------------------------------ */
  --text-2: #3f4c63;
  --text-floor: 12px;
  --font-weight-body: 400;

  /* -- Accent ramp + focus ----------------------------------------------------
        Fill darkened one step from locked --blue #0284c7 (white there = 4.10:1,
        fails AA at 14px); locked #0284c7 stays the link/icon accent. ---------- */
  --blue-fill: #0369a1;
  --blue-fill-text: #ffffff; /* 5.93:1 */
  --blue-hover: #035e91;
  --blue-active: #02527f;
  --focus: #0284c7;

  /* -- Destructive ramp (App. B.2) --------------------------------------------- */
  --red-fill: #dc2626;
  --red-fill-text: #ffffff;  /* 4.83:1 */
  --red-hover: #c81e1e;      /* 5.74:1 w/ white */
  --red-active: #b21a1a;     /* 6.87:1 w/ white */

  /* -- Interaction state layers ------------------------------------------------- */
  --state-hover: rgba(15, 23, 42, .05);
  --state-active: rgba(15, 23, 42, .09);
  --state-selected: rgba(2, 132, 199, .08); /* composites to #ebf5fb on #fff */

  /* -- Status badge triplets ------------------------------------------------------ */
  --status-blue-bg: #e6f3f9;
  --status-blue-border: #a6d4eb;
  --status-blue-text: #075e8a;
  --status-green-bg: #e8f6ed;
  --status-green-border: #addfc0;
  --status-green-text: #166534;
  --status-yellow-bg: #faf3e6;
  --status-yellow-border: #ecd6a7;
  --status-yellow-text: #854d0e;
  --status-orange-bg: #fdeee7;
  --status-orange-border: #f8c5aa;
  --status-orange-text: #9a3a08;
  --status-red-bg: #fce9e9;
  --status-red-border: #f3b3b3;
  --status-red-text: #b91c1c;

  /* -- Glass ------------------------------------------------------------------ */
  --glass-bg: var(--panel-bg);
  --glass-blur: 12px;

  /* -- Overlay scrim (App. B.1) -------------------------------------------------- */
  --scrim: rgba(15, 23, 42, .45);

  /* -- Chart inks (App. B.3) ------------------------------------------------------ */
  --chart-1: #0f62fe; /* blue    */
  --chart-2: #6929c4; /* purple  */
  --chart-3: #007d79; /* teal    */
  --chart-4: #9f1853; /* magenta */
  --chart-5: #b28600; /* ochre — 3.33:1 floor case: marks/strokes only, never chart text */
  --chart-6: #198038; /* green   */
  --chart-grid: #e2e8f0; /* = --stroke */

  /* -- Touch / control geometry ------------------------------------------------- */
  --tap-min: 44px;
  --chip-h: 32px;
}

/* == Field (max-contrast outdoor) — a posture, not a palette swap (§10) ==== */
[data-theme="field"] {
  /* -- Locked CLAUDE.md palette ------------------------------------------- */
  --bg: #ffffff;
  --surface: #f5f5f5;
  --stroke: #c0c0c0;   /* decorative only — never load-bearing in field */
  --text: #000000;
  --muted: #333333;    /* aliased to --text-2: field has no third text tier */
  --blue: #0055cc;
  --orange: #c04000;
  --required-text: #b03a00; /* "(required)" labels: 5.58:1 on --surface */
  --chart-bar: #1757ac;   /* admin bars: dataviz reference blue ramp step 600, validated (band, chroma, 3:1+) on #f5f5f5 (D-109) */
  --chart-track: #d9d9d9;
  --red: #cc0000;
  --green: #006600;
  --yellow: #806600;
  --panel-bg: rgba(245, 245, 245, .97);

  /* -- Surfaces & elevation — flat; 2px borders carry every boundary ------- */
  --elev-0: var(--bg);
  --elev-1: var(--surface);
  --elev-2: #f5f5f5;
  --elev-3: #ffffff;
  --elev-4: #ffffff;
  --shadow-1: none;
  --shadow-2: none;
  --shadow-3: none;

  /* -- Borders — 2px floor for anything that carries meaning ---------------- */
  --stroke-strong: #4d4d4d;
  --border-w: 2px;
  --border-w-strong: 3px;

  /* -- Text tiers -------------------------------------------------------------- */
  --text-2: #333333;
  --text-floor: 14px;
  --font-weight-body: 500; /* key glanceable data: 20–24px / 700 (§10) */

  /* -- Accent ramp + focus ---------------------------------------------------------
        Focus ring in field is 3px solid #000 with 2px offset — the width/offset
        override lives in the :focus-visible rule, not a token (foundation §9.3). */
  --blue-fill: #0055cc;
  --blue-fill-text: #ffffff; /* 6.62:1 */
  --blue-hover: #0049b0;
  --blue-active: #003d94;
  --focus: #000000;

  /* -- Destructive ramp (App. B.2) ---------------------------------------------------- */
  --red-fill: #cc0000;
  --red-fill-text: #ffffff;  /* 5.89:1 */
  --red-hover: #b00000;      /* 7.38:1 w/ white */
  --red-active: #940000;     /* 9.30:1 w/ white */

  /* -- Interaction state layers ----------------------------------------------------------
        Selected state is never a tint in field: 2px #000 border + check icon (§9.1). */
  --state-hover: rgba(0, 0, 0, .06);
  --state-active: rgba(0, 0, 0, .12);
  --state-selected: transparent;

  /* -- Status badge triplets — no tints: white chip, 2px ink border + ink text,
        mandatory icon + label (§5.4) ---------------------------------------------- */
  --status-blue-bg: #ffffff;
  --status-blue-border: #0055cc;
  --status-blue-text: #0055cc;
  --status-green-bg: #ffffff;
  --status-green-border: #006600;
  --status-green-text: #006600;
  --status-yellow-bg: #ffffff;
  --status-yellow-border: #806600;
  --status-yellow-text: #806600;
  --status-orange-bg: #ffffff;
  --status-orange-border: #c04000;
  --status-orange-text: #c04000;
  --status-red-bg: #ffffff;
  --status-red-border: #cc0000;
  --status-red-text: #cc0000;

  /* -- Glass kill switch (§6.3) — zero translucency outdoors -------------------- */
  --glass-bg: var(--panel-bg);
  --glass-blur: 0;

  /* -- Overlay scrim (App. B.1) — ≥60% black, never backdrop-filter --------------- */
  --scrim: rgba(0, 0, 0, .60);

  /* -- Chart inks (App. B.3) — field caps at 4 series; 5/6 alias 1/2 --------------- */
  --chart-1: #002d9c; /* blue    */
  --chart-2: #6929c4; /* purple  */
  --chart-3: #005c5c; /* teal    */
  --chart-4: #99004d; /* magenta */
  --chart-5: var(--chart-1);
  --chart-6: var(--chart-2);
  --chart-grid: #c0c0c0; /* = --stroke; decorative — meaning-bearing axes use --stroke-strong */

  /* -- Touch / control geometry — glove rule ----------------------------------------- */
  --tap-min: 48px;
  --chip-h: 48px;
}
