/* ============================================================
   o9 Solver Visualizer — Design System
   main.css: tokens, reset, typography, base elements
   Palette: deep indigo base + amber "flow" accent.
   Token NAMES kept from the reference (--airflow/--cyan) so shared
   components resolve; VALUES retuned to the o9 brand.
   ============================================================ */

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  /* o9 brand — amber flow accent (primary/active) */
  --airflow: #F5A623;
  --airflow-dim: #c67f10;
  --airflow-bright: #ffbe4d;
  --airflow-subtle: rgba(245, 166, 35, 0.15);
  --airflow-glow: rgba(245, 166, 35, 0.3);
  /* indigo secondary */
  --cyan: #6366F1;
  --cyan-dim: #4f46e5;
  --cyan-subtle: rgba(99, 102, 241, 0.15);

  /* Supply-chain node accent tokens (used by ArchDiagram node.color) */
  --supplier: #f59e0b;   /* amber  — suppliers            */
  --dc: #6366f1;         /* indigo — distribution centres */
  --lc: #22d3ee;         /* cyan   — customer-facing LCs  */
  --solver: #a855f7;     /* purple — the solver engine    */
  --rule: #38bdf8;       /* sky    — rule engine          */
  --demand: #f472b6;     /* pink   — demand signal        */

  /* Background layers — indigo-tinted dark */
  --bg-0: #0a0c18;
  --bg-1: #0f1226;
  --bg-2: #161a33;
  --bg-3: #1e2444;
  --bg-4: #2a3157;
  --bg-5: #3a4270;

  /* Borders */
  --border-subtle: #111827;
  --border-default: #1e2d42;
  --border-muted: #2e3d56;
  --border-emphasis: #4a5f7a;

  /* Text */
  --text-primary: #e2e8f4;
  --text-secondary: #8a9ab8;
  --text-muted: #5a6e8c;
  --text-disabled: #3a4e6a;
  --text-inverse: #07090f;
  --text-on-accent: #ffffff;

  /* Semantic colors */
  --green: #22c55e;
  --green-dim: #16a34a;
  --green-subtle: rgba(34, 197, 94, 0.15);
  --red: #ef4444;
  --red-dim: #dc2626;
  --red-subtle: rgba(239, 68, 68, 0.15);
  --yellow: #eab308;
  --yellow-dim: #a16207;
  --yellow-subtle: rgba(234, 179, 8, 0.15);
  --orange: #f97316;
  --orange-dim: #c2410c;
  --orange-subtle: rgba(249, 115, 22, 0.15);
  --purple: #a855f7;
  --purple-dim: #7c3aed;
  --purple-subtle: rgba(168, 85, 247, 0.15);

  /* Task state colors */
  --state-success: var(--green);
  --state-failed: var(--red);
  --state-running: var(--airflow);
  --state-queued: var(--yellow);
  --state-skipped: var(--purple);
  --state-up-for-retry: var(--orange);
  --state-upstream-failed: var(--red-dim);
  --state-none: var(--text-muted);
  --state-scheduled: var(--cyan);
  --state-deferred: var(--purple-dim);
  --state-removed: var(--text-disabled);

  /* Glassmorphism */
  --glass-bg: rgba(11, 15, 26, 0.8);
  --glass-border: rgba(30, 45, 66, 0.7);
  --glass-hover: rgba(17, 24, 39, 0.95);

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.7);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.8);
  --shadow-glow: 0 0 24px rgba(1, 124, 238, 0.3);
  --shadow-glow-cyan: 0 0 20px rgba(0, 199, 212, 0.25);

  /* Radius */
  --radius-xs: 3px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;

  /* Typography */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", "Fira Code", "JetBrains Mono", Consolas, "Courier New", monospace;

  /* Font sizes */
  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 20px;
  --text-3xl: 24px;
  --text-4xl: 30px;
  --text-5xl: 36px;
  --text-6xl: 48px;

  /* Line heights */
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* Transitions */
  --ease-fast: 100ms ease;
  --ease-base: 200ms ease;
  --ease-slow: 300ms ease;
  --ease-bounce: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: 200ms cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: 300ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Z-index scale */
  --z-base: 0;
  --z-raised: 10;
  --z-dropdown: 100;
  --z-overlay: 200;
  --z-modal: 300;
  --z-tooltip: 400;
  --z-notification: 500;

  /* Gradients */
  --gradient-brand: linear-gradient(135deg, var(--airflow) 0%, var(--cyan) 100%);
  --gradient-brand-warm: linear-gradient(135deg, var(--airflow) 0%, var(--purple) 100%);
  --gradient-flow: linear-gradient(90deg, var(--airflow) 0%, var(--cyan) 50%, var(--green) 100%);
}

/* ── Light theme overrides ──────────────────────────────────── */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg-0: #f0f4ff;
    --bg-1: #f8faff;
    --bg-2: #ffffff;
    --bg-3: #eef2fb;
    --bg-4: #e4ebf7;
    --bg-5: #d6e0f0;
    --border-subtle: #e4ebf7;
    --border-default: #d0daf0;
    --border-muted: #b8c8e0;
    --border-emphasis: #8a9ab8;
    --text-primary: #0d1a2e;
    --text-secondary: #3a4e6a;
    --text-muted: #5a6e8c;
    --text-disabled: #8a9ab8;
    --glass-bg: rgba(248, 250, 255, 0.9);
    --glass-border: rgba(208, 218, 240, 0.8);
    --glass-hover: rgba(238, 242, 251, 0.95);
    --shadow-xs: 0 1px 2px rgba(13, 26, 46, 0.08);
    --shadow-sm: 0 2px 6px rgba(13, 26, 46, 0.1);
    --shadow-md: 0 4px 16px rgba(13, 26, 46, 0.12);
    --shadow-lg: 0 8px 32px rgba(13, 26, 46, 0.15);
    --shadow-glow: 0 0 24px rgba(1, 124, 238, 0.2);
    --airflow-subtle: rgba(1, 124, 238, 0.1);
    --cyan-subtle: rgba(0, 199, 212, 0.1);
  }
}

:root[data-theme="light"] {
  --bg-0: #f0f4ff;
  --bg-1: #f8faff;
  --bg-2: #ffffff;
  --bg-3: #eef2fb;
  --bg-4: #e4ebf7;
  --bg-5: #d6e0f0;
  --border-subtle: #e4ebf7;
  --border-default: #d0daf0;
  --border-muted: #b8c8e0;
  --border-emphasis: #8a9ab8;
  --text-primary: #0d1a2e;
  --text-secondary: #3a4e6a;
  --text-muted: #5a6e8c;
  --text-disabled: #8a9ab8;
  --glass-bg: rgba(248, 250, 255, 0.9);
  --glass-border: rgba(208, 218, 240, 0.8);
  --glass-hover: rgba(238, 242, 251, 0.95);
  --shadow-xs: 0 1px 2px rgba(13, 26, 46, 0.08);
  --shadow-sm: 0 2px 6px rgba(13, 26, 46, 0.1);
  --shadow-md: 0 4px 16px rgba(13, 26, 46, 0.12);
  --shadow-lg: 0 8px 32px rgba(13, 26, 46, 0.15);
  --shadow-glow: 0 0 24px rgba(245, 166, 35, 0.2);
  --airflow-subtle: rgba(245, 166, 35, 0.12);
  --cyan-subtle: rgba(99, 102, 241, 0.1);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  background: var(--bg-1);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  overflow: hidden;
  height: 100vh;
  user-select: none;
}

/* Allow text selection in content regions */
.canvas, .detail-panel, .code-block, .json-viewer {
  user-select: text;
}

a {
  color: var(--airflow-bright);
  text-decoration: none;
  transition: color var(--ease-fast);
}
a:hover { color: var(--cyan); text-decoration: underline; }

img, svg { display: block; max-width: 100%; }

button {
  font-family: var(--font-ui);
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: var(--font-ui);
  font-size: var(--text-base);
}

ul, ol { list-style: none; }

/* ── Typography ─────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  line-height: var(--leading-tight);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  text-wrap: balance;
}

h1 { font-size: var(--text-5xl); }
h2 { font-size: var(--text-4xl); }
h3 { font-size: var(--text-3xl); }
h4 { font-size: var(--text-2xl); }
h5 { font-size: var(--text-xl); }
h6 { font-size: var(--text-lg); }

p {
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  font-size: var(--text-base);
}

code, pre, .mono {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

code {
  background: var(--bg-3);
  color: var(--cyan);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-default);
}

pre {
  background: var(--bg-0);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  padding: var(--space-4);
  overflow-x: auto;
  line-height: 1.6;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-primary);
}

/* ── Scrollbars ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--bg-5);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--border-emphasis); }
::-webkit-scrollbar-corner { background: transparent; }

/* ── Focus ──────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--airflow);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* ── Selection ──────────────────────────────────────────────── */
::selection {
  background: rgba(1, 124, 238, 0.25);
  color: var(--text-primary);
}

/* ── Utility Classes ────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-airflow { color: var(--airflow-bright); }
.text-cyan { color: var(--cyan); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-orange { color: var(--orange); }
.text-purple { color: var(--purple); }

.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.tabular { font-variant-numeric: tabular-nums; }

.hidden { display: none !important; }
.invisible { visibility: hidden; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Gradient text ──────────────────────────────────────────── */
.gradient-text {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Skeleton loading ───────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-3) 0%, var(--bg-4) 50%, var(--bg-3) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Dividers ───────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border-default);
  margin: var(--space-4) 0;
}

.divider-v {
  width: 1px;
  background: var(--border-default);
  align-self: stretch;
}

/* ── Status dots ────────────────────────────────────────────── */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.status-dot.success { background: var(--state-success); }
.status-dot.failed  { background: var(--state-failed); }
.status-dot.running { background: var(--state-running); animation: pulse 1.5s infinite; }
.status-dot.queued  { background: var(--state-queued); }
.status-dot.skipped { background: var(--state-skipped); }
.status-dot.deferred { background: var(--state-deferred); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.3); }
}
