/* ============================================================
   Matrix 2.0 WebUI design tokens v4: the Claude look (warm paper, warm ink, clay accent)

   Brief
   - Warm neutrals (paper #faf9f5, ink #141413), one clay accent, three semantic colors.
   - Every title in a serif (--font-serif): panel, dialog and section titles, the verdict, big numbers.
     Body text in the system sans, ids and code in mono. A title is never sans.
   - Light is the default; dark (#262624) swaps values on the same tokens.
   - Content sits on the paper (Claude Code): no boxed panels, rows split by 1px lines;
     secondary buttons are a soft fill without an outline; the current tab is a filled pill.
     Shadows only on overlays.
   - Accent is for links / focus / active tab / what can be clicked.
     Selection uses a neutral fill; the page's primary button is dark-on-light.
   ============================================================ */

:root, [data-theme="light"] {
  /* neutrals: warm paper and warm ink (the Claude look), never a blue-grey */
  --bg: #faf9f5;
  --panel: #ffffff;
  --panel-deep: #f5f4ed;
  --line: #e8e6dc;
  --line-soft: #f0eee6;
  --line-hi: #d1cfc5;
  --ink: #141413;
  --ink-2: #3d3d3a;  /* secondary text (~11:1 on white) */
  --ink-3: #73726c;  /* muted: captions, table heads, hints (~4.8:1 on white) */

  /* selection + primary button */
  --sel: rgba(20, 20, 19, 0.05);
  --sel-hi: rgba(20, 20, 19, 0.09);
  --primary-bg: #141413;
  --primary-bg-hi: #3d3d3a;
  --on-primary: #faf9f5;

  /* the only accent: clay */
  --accent: #b85636;      /* clay, darkened to 4.75:1 on white so it can be text */
  --accent-hi: #9e4a2e;
  --accent-soft: rgba(184, 86, 54, 0.10);
  --accent-line: rgba(184, 86, 54, 0.35);
  --on-accent: #ffffff;

  /* semantic */
  --pass: #177a4d;  --pass-soft: rgba(23, 122, 77, 0.09);   --pass-line: rgba(23, 122, 77, 0.30);
  --warn: #9a6200;  --warn-soft: rgba(176, 116, 0, 0.10);   --warn-line: rgba(176, 116, 0, 0.32);
  --fail: #bf3a33;  --fail-soft: rgba(191, 58, 51, 0.08);   --fail-line: rgba(191, 58, 51, 0.30);
  --on-warn: #ffffff;

  /* misc */
  --wash: rgba(20, 20, 19, 0.025);
  --scrim: rgba(20, 20, 19, 0.36);
  --mat: #0c0d10;
  --code-bg: #f0eee6;
  /* code tokens: GitHub light (highlight.js classes in matrix.css) */
  --hl-keyword: #cf222e; --hl-string: #0a3069; --hl-comment: #6e7781; --hl-title: #8250df;
  --hl-number: #0550ae; --hl-builtin: #953800; --hl-attr: #0550ae; --hl-meta: #116329;
  --shadow-overlay: 0 12px 36px rgba(20, 20, 19, 0.12), 0 1px 3px rgba(20, 20, 19, 0.06);
  --ring: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent);

  /* chart palette: eight hues at one lightness and one chroma (OKLCH), so no series shouts;
     the order keeps neighbours far apart on the wheel */
  --chart-1: oklch(0.60 0.13 258);  --chart-2: oklch(0.60 0.11 160);  --chart-3: oklch(0.70 0.12 75);   --chart-4: oklch(0.60 0.14 20);
  --chart-5: oklch(0.58 0.12 300);  --chart-6: oklch(0.64 0.10 220);  --chart-7: oklch(0.64 0.13 45);   --chart-8: oklch(0.62 0.10 185);
  --chart-other: #aab1bd;
  /* telemetry: three meanings, not a rainbow. Warm = waiting, blue = the loader working
     (darker = the main work), grey = the rest. */
  --tel-wait: #c4574a;
  --tel-io-1: #c38a2e;   --tel-io-2: #e3c78e;
  --tel-work-1: #4d72aa; --tel-work-2: #86a1c8; --tel-work-3: #bccbe0;
  --tel-other-1: #8a8880; --tel-other-2: #d1cfc5;

  --radius: 10px;
  --radius-sm: 6px;
  --radius-pill: 999px;

  --t-fast: 80ms;
  --t: 120ms ease;
  --t-layer: 180ms ease;

  --z-sticky: 20;
  --z-header: 40;
  --z-fab: 100;
  --z-modal: 1000;
  --z-drawer: 1100;
  --z-dialog: 1150;
  --z-toast: 1200;

  /* type scale: caption < body < section < page < stat; from body up each step is 1.25x */
  --fs-xs: 0.75rem;     /* 12.9 px: labels, table heads, captions */
  --fs-sm: 0.8125rem;   /* 14.0 px: body, table cells, controls */
  --fs-md: 1rem;        /* 17.2 px: section titles, key numbers */
  --fs-lg: 1.25rem;     /* 21.5 px: page titles, a page's conclusion */
  --fs-xl: 1.5625rem;   /* 26.9 px: stat values */

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-serif: ui-serif, "New York", Charter, Georgia, "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --bg: #262624;
  --panel: #30302e;
  --panel-deep: #2b2b29;
  --line: #44433f;
  --line-soft: #3a3a37;
  --line-hi: #5a5953;
  --ink: #faf9f5;
  --ink-2: #c2c0b6;
  --ink-3: #9c9a92;

  --sel: rgba(250, 249, 245, 0.06);
  --sel-hi: rgba(250, 249, 245, 0.10);
  --primary-bg: #faf9f5;
  --primary-bg-hi: #ffffff;
  --on-primary: #141413;

  --accent: #e0886a;      /* 4.97:1 on the dark panel */
  --accent-hi: #eba187;
  --accent-soft: rgba(224, 136, 106, 0.14);
  --accent-line: rgba(224, 136, 106, 0.42);
  --on-accent: #141413;

  --pass: #5cc08c;  --pass-soft: rgba(92, 192, 140, 0.12);  --pass-line: rgba(92, 192, 140, 0.34);
  --warn: #dcae52;  --warn-soft: rgba(220, 174, 82, 0.12);  --warn-line: rgba(220, 174, 82, 0.34);
  --fail: #e98680;  --fail-soft: rgba(233, 134, 128, 0.12); --fail-line: rgba(233, 134, 128, 0.34);
  --on-warn: #0f1013;

  --wash: rgba(250, 249, 245, 0.03);
  --scrim: rgba(0, 0, 0, 0.55);
  --code-bg: #1f1e1d;
  /* code tokens: GitHub dark */
  --hl-keyword: #ff7b72; --hl-string: #a5d6ff; --hl-comment: #8b949e; --hl-title: #d2a8ff;
  --hl-number: #79c0ff; --hl-builtin: #ffa657; --hl-attr: #79c0ff; --hl-meta: #7ee787;
  --shadow-overlay: 0 12px 36px rgba(0, 0, 0, 0.5);

  --chart-1: oklch(0.74 0.11 258);  --chart-2: oklch(0.74 0.10 160);  --chart-3: oklch(0.80 0.11 75);   --chart-4: oklch(0.74 0.12 20);
  --chart-5: oklch(0.74 0.10 300);  --chart-6: oklch(0.76 0.09 220);  --chart-7: oklch(0.76 0.11 45);   --chart-8: oklch(0.76 0.09 185);
  --chart-other: #5b626d;
  --tel-wait: #e0846f;
  --tel-io-1: #d9a54a;   --tel-io-2: #8a6d34;
  --tel-work-1: #8eaee0; --tel-work-2: #6683b3; --tel-work-3: #46597d;
  --tel-other-1: #9c9a92; --tel-other-2: #4a4945;
}

/* ------------------------------------------------------------
   Legacy aliases: existing markup and JS templates reference these
   names. They resolve to the tokens above so both themes stay in sync.
   ------------------------------------------------------------ */
:root, [data-theme="light"], [data-theme="dark"] {
  --card: var(--panel);
  --card-hover: var(--panel-deep);
  --surface-1: var(--panel-deep);
  --surface-2: var(--panel-deep);
  --surface-3: var(--sel);
  --border: var(--line);
  --border-strong: var(--line-hi);
  --border-subtle: var(--line-soft);
  --text: var(--ink);
  --text-muted: var(--ink-2);
  --text-subtle: var(--ink-3);

  --accent-hover: var(--accent-hi);
  --accent-fg: var(--accent);
  --accent-border: var(--accent-line);
  --accent-glow: var(--accent-soft);
  --accent-gradient: var(--primary-bg);

  --success: var(--pass);
  --success-soft: var(--pass-soft);
  --success-border: var(--pass-line);
  --warning: var(--warn);
  --warning-soft: var(--warn-soft);
  --warning-border: var(--warn-line);
  --on-warning: var(--on-warn);
  --danger: var(--fail);
  --danger-soft: var(--fail-soft);
  --danger-border: var(--fail-line);

  --purple: var(--chart-5);
  --header-bg: var(--panel);
  --input-bg: var(--panel);
  --table-stripe: transparent;
  --table-hover: var(--wash);
  --shadow: none;
  --chat-agent-bg: var(--panel);
  --chat-agent-border: var(--line);
  --code-text: var(--ink);

  --radius-md: var(--radius);
  --radius-lg: var(--radius);
  --space-2: 8px;
}
