@import "tailwindcss";
@import "katex/dist/katex.min.css";
@plugin "@tailwindcss/typography";

/* ------------------------------------------------------------------ */
/* Tailwind theme — font stacks (drives Tailwind font-sans / font-mono) */
/* Cross-platform OS-native stacks per DESIGN.md §Typography.          */
/* ------------------------------------------------------------------ */
@theme {
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace;
}

/* ------------------------------------------------------------------ */
/* Design tokens — shared structural vars                              */
/* ------------------------------------------------------------------ */
:root {
  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Transition */
  --transition: 0.18s ease;
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Score gradient per-theme knobs (overridden in [data-theme="light"]). */
  /* See DESIGN.md §Score Gradient — fg saturation/lightness + bg alpha mul   */
  /* let yellow mids stay legible on warm-cream without re-coding the brand   */
  /* HSL. Light theme also boosts saturation so the mid hue (≈60 olive) gets  */
  /* enough chroma to read on the SVG ring stroke / large display digits.    */
  --score-fg-s: 70%;
  --score-fg-l: 45%;
  --score-bg-a-mul: 1;
}

/* ------------------------------------------------------------------ */
/* Dark theme (default)                                                */
/* ------------------------------------------------------------------ */
:root,
[data-theme="dark"] {
  /* Backgrounds */
  --bg: #0c0c1a;
  --bg-card: #12122b;
  --bg-card2: #16163a;
  --bg-deep: #09091a;

  /* Accent */
  --accent: #816DF8;
  --accent-dim: rgba(129, 109, 248, 0.12);
  --accent-dark: #5B3FD6;
  --purple: #a78bfa;
  --green: #0F9C7E;
  --yellow: #fbbf24;
  --cyan: #22d3ee;

  /* Text — 3-step ladder + on-filled (named tokens per DESIGN.md §Text) */
  --text: #e2e8f0;
  --text-muted: #8896aa;
  --text-dim: #7a8195;
  --text-on-filled: #ffffff;

  /* Borders — three steps per DESIGN.md §Hairline borders */
  --border: rgba(129, 109, 248, 0.10);
  --border-md: rgba(129, 109, 248, 0.18);
  --border-strong: rgba(129, 109, 248, 0.28);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px rgba(129, 109, 248, 0.25);
  --shadow-glow-soft: 0 0 12px rgba(129, 109, 248, 0.20);

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #816DF8 0%, #a78bfa 100%);
  --gradient-accent: linear-gradient(135deg, #0F9C7E 0%, #06b6d4 100%);
  --gradient-warm: linear-gradient(135deg, #fbbf24 0%, #ef4444 100%);
  --gradient-surface: linear-gradient(135deg, rgba(129, 109, 248, 0.08) 0%, rgba(167, 139, 250, 0.05) 100%);

  /* Deep saturated pass / fail — boolean badges (DESIGN.md §Semantic) */
  --pass: rgb(45, 104, 62);
  --fail: rgb(151, 31, 44);

  /* Overlay / tooltip backdrop */
  --overlay-bg: rgba(0, 0, 0, 0.82);

  /* Glassmorphic surface — sticky top-nav (DESIGN.md §Surface) */
  --surface-glass: rgba(18, 18, 43, 0.7);

  /* Semantic color tokens */
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.08);
  --danger-border: rgba(239, 68, 68, 0.20);
  --danger-bg-strong: rgba(239, 68, 68, 0.75);
  --warning-color: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.08);
  --warning-border: rgba(245, 158, 11, 0.20);
  --warning-text: #b45309;
  --info: #60a5fa;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.08);
  --success-border: rgba(16, 185, 129, 0.20);

  /* Compare palette — per-model slot */
  --compare-0-dot: #818cf8;
  --compare-0-border: rgba(99, 102, 241, 0.30);
  --compare-0-bg: rgba(99, 102, 241, 0.06);
  --compare-0-bg-header: rgba(99, 102, 241, 0.10);
  --compare-1-dot: #34d399;
  --compare-1-border: rgba(16, 185, 129, 0.30);
  --compare-1-bg: rgba(16, 185, 129, 0.06);
  --compare-1-bg-header: rgba(16, 185, 129, 0.10);
  --compare-2-dot: #fbbf24;
  --compare-2-border: rgba(245, 158, 11, 0.30);
  --compare-2-bg: rgba(245, 158, 11, 0.06);
  --compare-2-bg-header: rgba(245, 158, 11, 0.10);

  /* Chart colors */
  --chart-latency: #60a5fa;
  --chart-ttft: #34d399;
  --chart-tpot: #a78bfa;
  --chart-token: #94a3b8;

  /* KPI card gradients */
  --kpi-grad-0: linear-gradient(135deg, #6366f1, #8b5cf6);
  --kpi-grad-1: linear-gradient(135deg, #10b981, #06b6d4);
  --kpi-grad-2: linear-gradient(135deg, #f59e0b, #f97316);
  --kpi-grad-3: linear-gradient(135deg, #ec4899, #8b5cf6);

  /* Chat bubble tokens */
  --bubble-user-bg: rgba(99, 102, 241, 0.12);
  --bubble-user-bg-hl: rgba(99, 102, 241, 0.22);
  --bubble-user-border: rgba(99, 102, 241, 0.25);
  --bubble-user-border-hl: rgba(99, 102, 241, 0.60);
  --bubble-user-icon-bg: rgba(99, 102, 241, 0.20);
  --bubble-user-icon-border: rgba(99, 102, 241, 0.35);
  --bubble-user-color: #818cf8;
  --bubble-bot-bg: rgba(16, 185, 129, 0.10);
  --bubble-bot-bg-hl: rgba(16, 185, 129, 0.18);
  --bubble-bot-border: rgba(16, 185, 129, 0.25);
  --bubble-bot-border-hl: rgba(16, 185, 129, 0.55);
  --bubble-bot-icon-bg: rgba(16, 185, 129, 0.15);
  --bubble-bot-icon-border: rgba(16, 185, 129, 0.30);
  --bubble-bot-color: #34d399;
  --bubble-reasoning-bg: rgba(16, 185, 129, 0.06);
  --bubble-reasoning-bg-hl: rgba(16, 185, 129, 0.12);
  --bubble-reasoning-border: rgba(16, 185, 129, 0.25);
  --bubble-reasoning-border-hl: rgba(16, 185, 129, 0.45);
  --bubble-reasoning-icon-bg: rgba(16, 185, 129, 0.10);
  --bubble-reasoning-icon-border: rgba(16, 185, 129, 0.25);
  --bubble-reasoning-color: #34d399;
  --bubble-tool-bg: rgba(245, 158, 11, 0.05);
  --bubble-tool-bg-hl: rgba(245, 158, 11, 0.12);
  --bubble-tool-border: rgba(245, 158, 11, 0.25);
  --bubble-tool-border-hl: rgba(245, 158, 11, 0.50);
  --bubble-tool-icon-bg: rgba(245, 158, 11, 0.15);
  --bubble-tool-icon-border: rgba(245, 158, 11, 0.30);
  --bubble-tool-color: #fbbf24;
  --bubble-system-bg: rgba(148, 163, 184, 0.06);
  --bubble-system-bg-hl: rgba(148, 163, 184, 0.12);
  --bubble-system-border: rgba(148, 163, 184, 0.20);
  --bubble-system-border-hl: rgba(148, 163, 184, 0.40);
  --bubble-system-icon-bg: rgba(148, 163, 184, 0.12);
  --bubble-system-icon-border: rgba(148, 163, 184, 0.25);
  --bubble-system-color: rgba(148, 163, 184, 1);

  /* Media player */
  --media-video-bg: #000000;
}

/* ------------------------------------------------------------------ */
/* Light theme                                                         */
/* ------------------------------------------------------------------ */
[data-theme="light"] {
  /* Backgrounds — warm-cream surface ladder (DESIGN.md §Surface, warm console) */
  --bg: #faf9f5;
  --bg-card: #ffffff;
  --bg-card2: #f5f0e7;
  --bg-deep: #f0ebe1;

  /* Accent — keep same hue, tune lightness for light bg */
  --accent: #6c57e8;
  --accent-dim: rgba(108, 87, 232, 0.14);
  --accent-dark: #4f3ec8;
  --purple: #7c6be0;
  --green: #0a8a6e;
  --yellow: #d97706;
  --cyan: #0891b2;

  /* Text — warm-ink ladder (DESIGN.md §Text, warm console) */
  --text: #141413;
  --text-muted: #6c6a64;
  --text-dim: #8e8b82;
  --text-on-filled: #ffffff;

  /* Borders — solid warm-grey hairlines, NOT translucent violet (DESIGN.md §Hairlines). */
  /* Translucent violet at 0.20 alpha composites to near-invisible on white cards; solid */
  /* warm-grey gives every card a definite boundary. */
  --border: #e6dfd8;
  --border-md: #d6cdbe;
  --border-strong: #c1b6a3;

  /* Shadows — two-stop warm-ink stacks (matches text colour, not slate). */
  /* Slate drops on cream read as a cool-grey smudge and break the warm canvas. */
  --shadow-sm: 0 1px 2px rgba(20, 20, 19, 0.04), 0 4px 12px rgba(20, 20, 19, 0.06);
  --shadow: 0 4px 16px rgba(20, 20, 19, 0.07), 0 12px 32px rgba(20, 20, 19, 0.05);
  --shadow-lg: 0 12px 24px rgba(20, 20, 19, 0.09), 0 24px 48px rgba(20, 20, 19, 0.07);
  --shadow-glow: 0 0 20px rgba(108, 87, 232, 0.22);
  --shadow-glow-soft: 0 0 12px rgba(108, 87, 232, 0.18);

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #6c57e8 0%, #7c6be0 100%);
  --gradient-accent: linear-gradient(135deg, #0a8a6e 0%, #0891b2 100%);
  --gradient-warm: linear-gradient(135deg, #d97706 0%, #dc2626 100%);
  --gradient-surface: linear-gradient(135deg, rgba(108, 87, 232, 0.06) 0%, rgba(124, 107, 224, 0.03) 100%);

  /* Deep saturated pass / fail */
  --pass: rgb(16, 108, 55);
  --fail: rgb(180, 30, 42);

  /* Overlay / tooltip backdrop */
  --overlay-bg: rgba(0, 0, 0, 0.55);

  /* Glassmorphic surface — warm-tinted (DESIGN.md §Surface, warm console) */
  --surface-glass: rgba(250, 249, 245, 0.80);

  /* Score gradient — darker fg lightness + higher saturation + boosted bg   */
  /* alpha so yellow mids stay legible on warm-cream. The +15pt saturation    */
  /* bump compensates for the lightness compression at mid hues (≈60 olive). */
  /* See DESIGN.md §Score Gradient. */
  --score-fg-s: 85%;
  --score-fg-l: 32%;
  --score-bg-a-mul: 1.6;

  /* Semantic color tokens */
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.07);
  --danger-border: rgba(220, 38, 38, 0.22);
  --danger-bg-strong: rgba(220, 38, 38, 0.70);
  --warning-color: #d97706;
  --warning-bg: rgba(217, 119, 6, 0.08);
  --warning-border: rgba(217, 119, 6, 0.22);
  --warning-text: #92400e;
  --info: #3b82f6;
  --success: #059669;
  --success-bg: rgba(5, 150, 105, 0.08);
  --success-border: rgba(5, 150, 105, 0.22);

  /* Compare palette — per-model slot */
  --compare-0-dot: #6c57e8;
  --compare-0-border: rgba(108, 87, 232, 0.35);
  --compare-0-bg: rgba(108, 87, 232, 0.07);
  --compare-0-bg-header: rgba(108, 87, 232, 0.12);
  --compare-1-dot: #0a8a6e;
  --compare-1-border: rgba(10, 138, 110, 0.35);
  --compare-1-bg: rgba(10, 138, 110, 0.07);
  --compare-1-bg-header: rgba(10, 138, 110, 0.12);
  --compare-2-dot: #d97706;
  --compare-2-border: rgba(217, 119, 6, 0.35);
  --compare-2-bg: rgba(217, 119, 6, 0.07);
  --compare-2-bg-header: rgba(217, 119, 6, 0.12);

  /* Chart colors — light-theme palette is deeper + more saturated than dark's */
  /* counterpart, because warm-cream bg (`--bg-card` / `--bg-deep`) compresses */
  /* cool hues via simultaneous contrast. Mid-tone slate blue / violet read    */
  /* as washed-out on cream; pulling lightness down and saturation up restores */
  /* the "data-bearing" punch of the same hue family. */
  --chart-latency: #2563eb;
  --chart-ttft: #047857;
  --chart-tpot: #5b48e0;
  --chart-token: #5a6378;

  /* KPI card gradients — saturated enough to work on both themes */
  --kpi-grad-0: linear-gradient(135deg, #6366f1, #8b5cf6);
  --kpi-grad-1: linear-gradient(135deg, #10b981, #06b6d4);
  --kpi-grad-2: linear-gradient(135deg, #f59e0b, #f97316);
  --kpi-grad-3: linear-gradient(135deg, #ec4899, #8b5cf6);

  /* Chat bubble tokens */
  --bubble-user-bg: rgba(108, 87, 232, 0.10);
  --bubble-user-bg-hl: rgba(108, 87, 232, 0.20);
  --bubble-user-border: rgba(108, 87, 232, 0.30);
  --bubble-user-border-hl: rgba(108, 87, 232, 0.65);
  --bubble-user-icon-bg: rgba(108, 87, 232, 0.15);
  --bubble-user-icon-border: rgba(108, 87, 232, 0.40);
  --bubble-user-color: #6c57e8;
  --bubble-bot-bg: rgba(10, 138, 110, 0.10);
  --bubble-bot-bg-hl: rgba(10, 138, 110, 0.20);
  --bubble-bot-border: rgba(10, 138, 110, 0.30);
  --bubble-bot-border-hl: rgba(10, 138, 110, 0.60);
  --bubble-bot-icon-bg: rgba(10, 138, 110, 0.15);
  --bubble-bot-icon-border: rgba(10, 138, 110, 0.35);
  --bubble-bot-color: #0a8a6e;
  --bubble-reasoning-bg: rgba(10, 138, 110, 0.08);
  --bubble-reasoning-bg-hl: rgba(10, 138, 110, 0.14);
  --bubble-reasoning-border: rgba(10, 138, 110, 0.28);
  --bubble-reasoning-border-hl: rgba(10, 138, 110, 0.50);
  --bubble-reasoning-icon-bg: rgba(10, 138, 110, 0.12);
  --bubble-reasoning-icon-border: rgba(10, 138, 110, 0.28);
  --bubble-reasoning-color: #0a8a6e;
  --bubble-tool-bg: rgba(180, 100, 0, 0.07);
  --bubble-tool-bg-hl: rgba(180, 100, 0, 0.14);
  --bubble-tool-border: rgba(180, 100, 0, 0.28);
  --bubble-tool-border-hl: rgba(180, 100, 0, 0.50);
  --bubble-tool-icon-bg: rgba(180, 100, 0, 0.12);
  --bubble-tool-icon-border: rgba(180, 100, 0, 0.32);
  --bubble-tool-color: #b26200;
  --bubble-system-bg: rgba(90, 99, 120, 0.08);
  --bubble-system-bg-hl: rgba(90, 99, 120, 0.14);
  --bubble-system-border: rgba(90, 99, 120, 0.22);
  --bubble-system-border-hl: rgba(90, 99, 120, 0.45);
  --bubble-system-icon-bg: rgba(90, 99, 120, 0.14);
  --bubble-system-icon-border: rgba(90, 99, 120, 0.28);
  --bubble-system-color: #5a6378;

  /* Media player */
  --media-video-bg: #0d0d0d;
}

/* ------------------------------------------------------------------ */
/* Base                                                                */
/* ------------------------------------------------------------------ */
html {
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition-base), color var(--transition-base);
}

#root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------------ */
/* Typography utility classes — aligned to DESIGN.md §Typography 12-token */
/* These give us a single source of truth so Tabs / Toolbars / new pages */
/* don't re-hand-write `text-sm font-medium`, `text-xs ... uppercase`, etc. */
/* ------------------------------------------------------------------ */
@layer utilities {
  .type-display-xl     { @apply text-2xl font-bold tracking-tight; }
  .type-title-md       { @apply text-base font-bold; }
  .type-body-sm        { @apply text-sm; }
  .type-body-sm-strong { @apply text-sm font-medium; }
  .type-body-xs        { @apply text-xs; }
  .type-label-xs       { @apply text-xs font-semibold uppercase tracking-wider text-[var(--text-muted)]; }
  .type-table-xs       { @apply text-[10px] font-semibold uppercase tracking-wider text-[var(--text-dim)]; }
  .type-caption-mono   { @apply text-xs font-mono tabular-nums; }
  .type-code           { @apply text-[13px] font-mono; }
  .type-button-sm      { @apply text-xs font-medium; }
  .type-button-md      { @apply text-sm font-medium; }
  .type-button-lg      { @apply text-base font-medium; }
}

/* ------------------------------------------------------------------ */
/* Utility classes                                                     */
/* ------------------------------------------------------------------ */

/* Glass card */
.glass-card {
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

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

.gradient-text-accent {
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Glow button */
.btn-glow {
  box-shadow: 0 0 0 0 var(--accent-dim);
  transition: box-shadow var(--transition), transform var(--transition);
}
.btn-glow:hover {
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

/* Card hover lift */
.card-hover {
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}

/* Page fade-in animation */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page-enter {
  animation: fadeInUp var(--transition-slow) ease-out forwards;
}

/* Stagger children */
.stagger-children > * {
  animation: fadeInUp var(--transition-slow) ease-out both;
}
.stagger-children > *:nth-child(1) { animation-delay: 0ms; }
.stagger-children > *:nth-child(2) { animation-delay: 60ms; }
.stagger-children > *:nth-child(3) { animation-delay: 120ms; }
.stagger-children > *:nth-child(4) { animation-delay: 180ms; }
.stagger-children > *:nth-child(5) { animation-delay: 240ms; }
.stagger-children > *:nth-child(6) { animation-delay: 300ms; }

/* KPI gradient cards */
.kpi-card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.kpi-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--gradient-surface);
  pointer-events: none;
}
.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}

/* Skeleton pulse animation */
@keyframes skeletonPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

.skeleton-pulse {
  animation: skeletonPulse 1.5s ease-in-out infinite;
}

/* ------------------------------------------------------------------ */
/* Scrollbar                                                           */
/* ------------------------------------------------------------------ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 3px; }

/* ------------------------------------------------------------------ */
/* Reduced-motion fallback — WCAG 2.1 SC 2.3.3                         */
/* Honors user/OS preference for less animation; keeps layout intact.  */
/* ------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
