/* Design tokens — single source of truth for both visual directions and both themes.
   Every color, spacing, radius, shadow, motion duration is a token. No literals in components. */

:root {
  /* Type */
  --font-sans: "Inter", "Inter Tight", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-display: "Inter Tight", "Inter", -apple-system, sans-serif;

  --fs-10: 10px;
  --fs-11: 11px;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-15: 15px;
  --fs-16: 16px;
  --fs-18: 18px;
  --fs-22: 22px;
  --fs-28: 28px;
  --fs-36: 36px;
  --fs-48: 48px;

  --lh-tight: 1.1;
  --lh-snug: 1.25;
  --lh-normal: 1.4;
  --lh-loose: 1.55;

  /* Spacing — 4px base */
  --s-0: 0px;
  --s-1: 2px;
  --s-2: 4px;
  --s-3: 6px;
  --s-4: 8px;
  --s-5: 10px;
  --s-6: 12px;
  --s-8: 16px;
  --s-10: 20px;
  --s-12: 24px;
  --s-16: 32px;
  --s-20: 40px;
  --s-24: 48px;
  --s-32: 64px;

  /* Radii */
  --r-0: 0px;
  --r-1: 2px;
  --r-2: 4px;
  --r-3: 6px;
  --r-4: 8px;
  --r-5: 10px;
  --r-6: 12px;
  --r-pill: 999px;

  /* Motion */
  --dur-1: 80ms;
  --dur-2: 140ms;
  --dur-3: 220ms;
  --dur-4: 320ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-inout: cubic-bezier(0.5, 0, 0.2, 1);

  /* z-index scale */
  --z-base: 1;
  --z-sticky: 50;
  --z-popover: 100;
  --z-modal: 200;
  --z-toast: 300;
}

/* DARK theme — operator default. Designed intentionally, not inverted. */
:root[data-theme="dark"] {
  /* Surface scale (deepest → highest elevation) */
  --bg-canvas: #0a0c0f;
  --bg-base: #0e1116;
  --bg-raised: #14181f;
  --bg-elevated: #1a1f28;
  --bg-overlay: #232934;
  --bg-input: #0c0f14;

  /* Lines */
  --line-1: #222932;
  --line-2: #2c3440;
  --line-3: #3c4755;
  --line-strong: #556070;

  /* Text */
  --text-1: #edf0f5;
  --text-2: #c4ccd8;
  --text-3: #8e9aac;
  --text-4: #667384;
  --text-disabled: #445060;

  /* Brand accent — single anchor color, used sparingly */
  --accent: #7cf6c8;     /* mint signal — derives from "live" semantic */
  --accent-soft: #1f3a32;
  --accent-text: #062017;

  /* Status semantics — color + ALWAYS paired with an icon/shape in components */
  --st-queued-fg: #b8c0cc;
  --st-queued-bg: #1a1f28;
  --st-queued-line: #2a3340;

  --st-running-fg: #6ec3ff;
  --st-running-bg: #0f1f30;
  --st-running-line: #1f3e5e;

  --st-succeeded-fg: #6cd9a3;
  --st-succeeded-bg: #0f2418;
  --st-succeeded-line: #1f4732;

  --st-failed-fg: #ff8a82;
  --st-failed-bg: #2a0f10;
  --st-failed-line: #5a1e21;

  --st-blocked-fg: #f5b86b;
  --st-blocked-bg: #2a1d0c;
  --st-blocked-line: #543a1a;

  /* Action class */
  --ac-read: #6ec3ff;
  --ac-write-safe: #6cd9a3;
  --ac-write-external: #f5b86b;
  --ac-destructive: #ff8a82;

  /* Health */
  --hl-healthy: #6cd9a3;
  --hl-degraded: #f5b86b;
  --hl-offline: #7a8494;

  /* Score axis colors — for routing 6-dim viz */
  --score-pos: #6cd9a3;
  --score-neg: #ff8a82;
  --score-neutral: #455161;

  --shadow-1: 0 1px 0 rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-2: 0 4px 12px rgba(0,0,0,0.4), 0 1px 0 rgba(255,255,255,0.02) inset;
  --shadow-3: 0 12px 32px rgba(0,0,0,0.55), 0 1px 0 rgba(255,255,255,0.03) inset;

  --focus-ring: 0 0 0 2px var(--bg-canvas), 0 0 0 4px var(--accent);
}

/* LIGHT theme — equally first-class. Warm-cool neutral, restrained. */
:root[data-theme="light"] {
  --bg-canvas: #f5f6f7;
  --bg-base: #ffffff;
  --bg-raised: #fbfbfc;
  --bg-elevated: #ffffff;
  --bg-overlay: #ffffff;
  --bg-input: #f8f9fa;

  --line-1: #ebedf0;
  --line-2: #dde1e6;
  --line-3: #c4cad2;
  --line-strong: #99a1ad;

  --text-1: #0d1117;
  --text-2: #3a424d;
  --text-3: #6c7480;
  --text-4: #8a909a;
  --text-disabled: #b8bdc4;

  --accent: #0e8e63;
  --accent-soft: #d6f0e4;
  --accent-text: #ffffff;

  --st-queued-fg: #4a5260;
  --st-queued-bg: #eef0f3;
  --st-queued-line: #d8dde3;

  --st-running-fg: #0a5fbf;
  --st-running-bg: #e2efff;
  --st-running-line: #b6d2f3;

  --st-succeeded-fg: #0e7a4d;
  --st-succeeded-bg: #d8f1e3;
  --st-succeeded-line: #aedcc4;

  --st-failed-fg: #b3221c;
  --st-failed-bg: #fde2e1;
  --st-failed-line: #f3b9b6;

  --st-blocked-fg: #8a5510;
  --st-blocked-bg: #fcecd2;
  --st-blocked-line: #ebcb95;

  --ac-read: #0a5fbf;
  --ac-write-safe: #0e7a4d;
  --ac-write-external: #8a5510;
  --ac-destructive: #b3221c;

  --hl-healthy: #0e7a4d;
  --hl-degraded: #8a5510;
  --hl-offline: #6c7480;

  --score-pos: #0e7a4d;
  --score-neg: #b3221c;
  --score-neutral: #c4cad2;

  --shadow-1: 0 1px 0 rgba(15,20,30,0.04), 0 1px 2px rgba(15,20,30,0.05);
  --shadow-2: 0 4px 12px rgba(15,20,30,0.06), 0 1px 0 rgba(15,20,30,0.04);
  --shadow-3: 0 12px 32px rgba(15,20,30,0.10), 0 1px 0 rgba(15,20,30,0.04);

  --focus-ring: 0 0 0 2px var(--bg-canvas), 0 0 0 4px var(--accent);
}

/* DIRECTION B (Telemetry) overrides — applied via [data-direction="telemetry"] */
:root[data-direction="telemetry"][data-theme="dark"] {
  --bg-canvas: #08090c;
  --bg-base: #0c0e13;
  --bg-raised: #11141b;
  --bg-elevated: #161a23;
  --line-1: #1a1f2a;
  --line-2: #232a37;
  --accent: #d6a35a;       /* amber instrument */
  --accent-soft: #3a2a14;
  --accent-text: #1a1206;
}
:root[data-direction="telemetry"][data-theme="light"] {
  --accent: #b07a1a;
  --accent-soft: #f4e6c9;
}

/* Reset + base */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: var(--lh-normal);
  color: var(--text-1);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
::selection { background: var(--accent); color: var(--accent-text); }

/* ── Tooltip ── */
.tt {
  background: var(--bg-overlay);
  border: 1px solid var(--line-2);
  border-radius: var(--r-3);
  color: var(--text-1);
  font-size: var(--fs-12);
  line-height: var(--lh-loose);
  padding: var(--s-3) var(--s-5);
  box-shadow: var(--shadow-2);
  white-space: normal;
  text-align: left;
  font-family: var(--font-sans);
  font-weight: 400;
  pointer-events: none;
  animation: tt-in var(--dur-2) var(--ease-out);
}
@keyframes tt-in { from { opacity: 0; transform: translate(-50%,-90%); } to { opacity: 1; transform: translate(-50%,-100%); } }
.tt--bottom { animation: tt-in-b var(--dur-2) var(--ease-out); }
@keyframes tt-in-b { from { opacity: 0; transform: translate(-50%, 4px); } to { opacity: 1; transform: translate(-50%, 0); } }
.tt strong { color: var(--accent); font-weight: 600; }
.tt code  { font-family: var(--font-mono); font-size: var(--fs-11); background: var(--bg-input); padding: 1px 4px; border-radius: 3px; border: 1px solid var(--line-1); }

/* Scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--line-3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--line-3); border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
