/* ═══════════════════════════════════════════════════════════════════════
   DESIGN TOKENS — Single source of truth for ALL runtime design tokens
   ═══════════════════════════════════════════════════════════════════════
   • Tailwind v4 @theme (in base.njk) references these via var() to generate
     utility classes (bg-background, text-foreground, border-border, etc.)
   • Handwritten component CSS also uses var() directly.
   • shadcn/ui compatible aliases at the bottom enable tweakcn theme swaps
     and direct use of shadcn/blocks HTML.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;

  /* ── Font stacks (→ @theme --font-*) ───────────────────────────────── */
  --font-stack-sans: 'Space Grotesk', sans-serif; /* Crucent (was Inter Tight) */
  --font-stack-heading: 'Inter Tight', sans-serif;
  --font-stack-body: 'Hubot Sans', 'Inter Tight', sans-serif;
  --font-stack-mono: 'JetBrains Mono', monospace;
  --font-stack-serif: 'Instrument Serif', Georgia, Cambria, 'Times New Roman', Times, serif;
  --font-heading: var(--font-stack-heading);
  --font-body: var(--font-stack-body);
  --font-mono: var(--font-stack-mono);

  /* ── Type scale (--fs-*) → @theme maps to --text-* ─────────────────── */
  --fs-micro: 0.5rem; /*  8px — fine print, decorative counters */
  --fs-caption: 0.5625rem; /*  9px — card badges, skill tags */
  --fs-label: 0.625rem; /* 10px — filter chips, small labels */
  --fs-detail: 0.65rem; /* ~10.4px — detail tables, chart labels, log meta */
  --fs-chip: 0.6875rem; /* 11px — neo-chip base */
  --fs-xs: 0.75rem; /* 12px — small text, meta info */
  --fs-meta: 0.8125rem; /* 13px — hero stat labels, compact meta */
  --fs-btn: 0.875rem; /* 14px — buttons, inputs */
  --fs-body: 1rem; /* 16px — base body */
  --fs-subhead: 1.125rem; /* 18px — sub-headings, card metrics */
  --fs-title: 1.25rem; /* 20px — card titles, step numbers */
  --fs-display: 1.5rem; /* 24px — section stats, lg headings */
  --fs-hero: clamp(2rem, 4.5vw, 3.25rem); /* 32–52px — hero headline */
  --fs-section: clamp(2rem, 4vw, 3rem); /* 32–48px — section headlines */
  --fs-ghost: clamp(72px, 12vw, 140px); /* decorative ghost text */

  /* ── Border widths (sm / md / lg scale) ─────────────────────────────── */
  --border-width-sm: 1px;
  --border-width-md: 2px;
  --border-width-lg: 3px;
  --border-width-thin: var(--border-width-sm); /* alias → sm (1px) */
  --border-width-base: var(--border-width-md); /* alias → md (2px) */

  /* ── Control heights ────────────────────────────────────────────────── */
  --h-control-sm: 34px; /* nav buttons, theme toggle, small inputs */

  /* ── Radius ─────────────────────────────────────────────────────────── */
  --radius: 1px;
  --radius-neo: var(--radius);

  /* ── Shadow scale (neo tokens = source of truth) ─────────────────── */
  --shadow-neo-sm: 1px 1px 0 var(--border);
  --shadow-neo: 2px 2px 0 var(--border);
  --shadow-neo-md: 3px 3px 0 var(--border);
  --shadow-neo-hover: 4px 4px 0 var(--border);
  --shadow-neo-lg: 6px 6px 0 oklch(0 0 0 / 0.2);

  /* ── Background (Standard Default) ────────────────────────────────────────────────────────── */
  --background: oklch(0.985 0.002 85);
  --secondary: oklch(0.955 0.012 75);
  --card: oklch(1 0 0);
  --background-inverse: oklch(28.271% 0.00839 75.191);
  --muted: oklch(0.94 0.011 85); /* warm-tinted (was neutral) */

  /* ── Foreground (Standard Default) ─────────────────────────────────────────────────────────────── */
  --foreground: oklch(0.18 0 0);
  --muted-foreground: oklch(0.42 0.02 55);
  --ink-subtle: oklch(0.35 0 0);

  /* ── Border ──────────────────────────────────────────────────────────── */
  --border: oklch(0.145 0 0);
  --border-fg: oklch(1 0 0);
  --input: oklch(0.89 0.02 70);
  --border-subtle: oklch(0.935 0 0);

  /* ── Dark base ───────────────────────────────────────────────────────── */
  --dark: oklch(0.13 0 0);

  /* ── Primary (Standard Default) ─────────────────────────────────────────────────── */
  --primary: oklch(0.7 0.19 55.15); /* warm muted amber */
  --primary-foreground: oklch(0.15 0.04 55); /* dark warm — WCAG AA 7.4:1 on primary */

  /* ── Extended accent colors + Destructive ─────────────────────────────────────────── */
  --destructive: oklch(0.53 0.22 25); /* deepened for WCAG AA — uses destructive-foreground */
  --accent-orange: oklch(0.68 0.2 45);
  --accent-blue: oklch(0.55 0.2 264);
  --accent-amber: oklch(0.78 0.17 85);
  --accent-green: oklch(0.65 0.19 145);
  --accent-yellow: oklch(0.82 0.16 97);
  --accent-purple: oklch(0.45 0.2 295);

  /* ── Fills — derived from accent base via relative color syntax ────── */
  --fill-blue: oklch(from var(--accent-blue) 0.97 0.015 h);
  --fill-green: oklch(from var(--accent-green) 0.97 0.015 h);
  --fill-amber: oklch(from var(--accent-amber) 0.97 0.02 h);
  --fill-yellow: oklch(from var(--accent-yellow) 0.97 0.02 h);
  --fill-purple: oklch(from var(--accent-purple) 0.97 0.015 h);
  --fill-red: oklch(from var(--destructive) 0.97 0.015 h);
  --fill-orange: oklch(from var(--accent-orange) 0.97 0.02 h);

  /* ── On-fill text — WCAG-safe dark text on fill-tint backgrounds ───── */
  --on-fill-blue: oklch(from var(--accent-blue) calc(l - 0.2) calc(c - 0.05) h);
  --on-fill-green: oklch(from var(--accent-green) calc(l - 0.25) calc(c - 0.04) h);
  --on-fill-amber: oklch(from var(--accent-amber) calc(l - 0.3) calc(c - 0.05) h);
  --on-fill-orange: oklch(from var(--accent-orange) calc(l - 0.18) calc(c - 0.05) h);
  --on-fill-purple: oklch(from var(--accent-purple) calc(l - 0.17) calc(c - 0.08) h);
  --on-fill-red: oklch(from var(--destructive) calc(l - 0.15) calc(c - 0.04) h);

  /* ── Module colors — aliases to accent base + derived text ─────────── */
  --module-mrp: var(--accent-blue);
  --module-mrp-text: var(--on-fill-blue);
  --module-erp: var(--accent-purple);
  --module-erp-text: var(--on-fill-purple);
  --module-crm: var(--accent-orange);
  --module-crm-text: var(--on-fill-orange);
  --module-hr: var(--accent-green);
  --module-hr-text: var(--on-fill-green);
  --module-finance: var(--accent-amber);
  --module-finance-text: var(--on-fill-amber);
  --module-procurement: var(--destructive);
  --module-procurement-text: var(--on-fill-red);
  /* Unique-hue modules (no accent base match) */
  --module-logistics: oklch(0.55 0.12 195);
  --module-logistics-text: oklch(0.42 0.08 195);
  --module-quality: oklch(0.55 0.24 350);
  --module-quality-text: oklch(0.38 0.18 350);
  --module-analytics: oklch(from var(--accent-blue) calc(l - 0.1) calc(c - 0.02) h);
  --module-analytics-text: oklch(0.28 0.1 264);
  --module-devops: oklch(0.55 0.04 240);
  --module-devops-text: oklch(0.35 0.03 240);

  /* ── Warm palette ────────────────────────────────────────────────────── */
  --warm-50: oklch(0.985 0.002 85);
  --warm-100: oklch(0.955 0.012 75);
  --warm-200: oklch(0.89 0.02 70);
  --warm-300: oklch(0.82 0.03 75);
  --warm-400: oklch(0.45 0.02 55);
  --warm-500: oklch(0.18 0 0);

  /* ── Stats ───────────────────────────────────────────────────────────── */
  --stats-bar: oklch(0.92 0.18 95);
  --stats-card-1: oklch(0.92 0.15 95);
  --stats-card-2: oklch(0.78 0.15 45);
  --stats-card-3: oklch(0.78 0.14 250);
  --stats-card-4: oklch(0.8 0.14 150);

  /* ── Chip foreground (WCAG-safe text on solid fills) ─────────────────── */
  --chip-fg-on-light: oklch(0.13 0.02 75); /* dark text on warm/bright chip bgs */
  --chip-fg-on-dark: oklch(0.99 0.003 85); /* light text on cool/deep chip bgs */

  /* ── Overlays / UI ───────────────────────────────────────────────────── */
  --overlay-backdrop: oklch(0 0 0 / 0.5);
  --tap-highlight: oklch(0 0 0 / 0.1);
  --ghost-img-filter: brightness(0);
  --ghost-ink: oklch(0 0 0 / 0.04);
  --ghost-ink-mid: oklch(0 0 0 / 0.05);
  --ghost-ink-strong: oklch(0 0 0 / 0.06);
  --pattern-ink: oklch(0 0 0 / 0.035);
  --pattern-ink-mid: oklch(0 0 0 / 0.05);

  /* ── Selection (warm yellow tint) ────────────────────────────────────── */
  --selection-bg: oklch(0.88 0.13 90);
  --selection-dark-bg: oklch(0.86 0.13 90);
  --selection-warm-bg: oklch(0.84 0.13 90);
  --selection-card-bg: oklch(0.9 0.12 90);
  --selection-stats-bg: oklch(0.88 0.1 90);

  /* ── Extended: decorative gold (derived from primary — theme-responsive) ── */
  --gold: color-mix(in oklch, var(--primary) 35%, var(--muted-foreground));

  /* ── Extended: panel decorative (accent panel ghost/text) ─────────────── */
  --panel-overlay: oklch(0 0 0 / 0.08);
  --panel-foreground: var(--primary);

  /* ── Extended: inverted surfaces (steps, ticker, code blocks) ────────── */
  --surface-invert: oklch(0.15 0 0);
  --surface-invert-muted: oklch(1 0 0 / 0.5);
  --primary-hover: oklch(0.62 0.17 55.15);
  --code: oklch(0.1 0 0);
  --code-header: oklch(0.14 0 0);

  /* ── Hero backdrop hatching (decorative bleed fills) ─────────────────── */
  --hero-backdrop-left: oklch(0.88 0.015 75);
  --hero-backdrop-right: oklch(0.58 0.19 55);
  --hero-hatch-left: oklch(0.8 0.025 75 / 0.45);
  --hero-hatch-right: oklch(0.5 0.17 55 / 0.3);
  --hero-hatch-spacing: 10px;
  --hero-hatch-width: 1px;

  /* ── Hero / decorative ───────────────────────────────────────────────── */
  --hero-flip-a: oklch(0.38 0.15 264);
  --hero-flip-b: oklch(0.52 0.16 55);
  --background-inverse-30: oklch(1 0 0 / 0.3);
  --background-inverse-20: oklch(1 0 0 / 0.2);

  /* ── Header tints (governance/agents cards) ──────────────────────────── */
  --surface-header-alt: oklch(0.92 0.028 15);
  --surface-header-warm: oklch(0.965 0.045 95);
  --surface-header-alt-blue: oklch(0.92 0.03 240);
  --surface-header-alt-green: oklch(0.92 0.03 145);

  /* ── Animation / transitions ───────────────────────────────────────── */
  --duration-fast: 150ms;
  --duration-quick: 250ms;
  --duration-base: 300ms;
  --duration-medium: 400ms;
  --duration-moderate: 500ms;
  --duration-slow: 600ms;
  --duration-slower: 1000ms;
  --easing-default: cubic-bezier(0.22, 1, 0.36, 1);
  --easing-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* ── Layout widths ─────────────────────────────────────────────────── */
  --sidebar-lg: 350px;
  --sidebar-md: 280px;

  /* ── Z-index scale ─────────────────────────────────────────────────── */
  --z-base: 1;
  --z-above: 2;
  --z-content: 3;
  --z-local: 10;
  --z-raised: 11;
  --z-component: 40;
  --z-dropdown: 50;
  --z-sticky: 60;
  --z-overlay: 100;
  --z-modal: 200;
  --z-toast: 300;
  --z-skip: 9999;

  /* ── Focus / outline ───────────────────────────────────────────────── */
  --outline-width: 2px;
  --outline-offset: 2px;
  --outline-color: var(--border);

  /* ── Spacing scale ─────────────────────────────────────────────────── */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* ── Trust tier colors ─────────────────────────────────────────────── */
  --trust-gold-bg: oklch(0.92 0.12 95);
  --trust-gold-fg: oklch(0.45 0.12 75);
  --trust-gold-border: oklch(0.65 0.15 80);
  --trust-certified-bg: oklch(0.92 0.08 150);
  --trust-certified-fg: oklch(0.35 0.12 150);
  --trust-certified-border: oklch(0.55 0.15 150);
  --trust-sandbox-bg: oklch(0.92 0.06 250);
  --trust-sandbox-fg: oklch(0.35 0.1 250);
  --trust-sandbox-border: oklch(0.55 0.12 250);

  /* ── Hard shadow (neo-brutalist — largest solid offset) ────────────── */
  --shadow-hard: var(--shadow-neo-hover);
  --shadow-hard-accent: 6px 6px 0 var(--primary);

  /* ── Standard Default — Derived Tokens ──────────────────────────────────
     These tokens derive from core standard tokens above. A tweakcn/Basecoat
     theme export only needs to set the core 15 (background, foreground,
     card, primary, secondary, muted, destructive, border, input, ring,
     + foreground variants) — these derive automatically.
     ──────────────────────────────────────────────────────────────────── */
  --card-foreground: var(--foreground);
  --popover: var(--card);
  --popover-foreground: var(--foreground);
  --secondary-foreground: var(--foreground);
  --accent: var(--secondary);
  --accent-foreground: var(--foreground);
  --destructive-foreground: var(--border-fg);
  --ring: var(--accent-purple); /* purple focus — avoids red=error confusion */
  --radius: var(--radius-neo);

  /* ── Charts (5-slot scale for Recharts / shadcn charts) ── */
  --chart-1: var(--stats-card-1);
  --chart-2: var(--stats-card-2);
  --chart-3: var(--stats-card-3);
  --chart-4: var(--stats-card-4);
  --chart-5: var(--accent-orange);

  /* ── Sidebar (Basecoat sidebar component tokens) ── */
  --sidebar: var(--secondary);
  --sidebar-foreground: var(--foreground);
  --sidebar-primary: var(--primary);
  --sidebar-primary-foreground: var(--primary-foreground);
  --sidebar-accent: var(--muted);
  --sidebar-accent-foreground: var(--foreground);
  --sidebar-border: var(--border-subtle);
  --sidebar-ring: var(--accent-purple);

  /* ── Fonts (Basecoat expects these at :root) ── */
  --font-sans: var(--font-stack-sans);
  --font-serif: var(--font-stack-serif);
  --font-mono: var(--font-stack-mono);

  /* ── Shadow scale (Basecoat / Tailwind v4 compatible) ── */
  --shadow-2xs: 0 1px 3px 0px oklch(0 0 0 / 0.05);
  --shadow-xs: 0 1px 3px 0px oklch(0 0 0 / 0.05);
  --shadow-sm: var(--shadow-neo-sm); /* ← alias → neo layer */
  --shadow-base: var(--shadow-neo); /* ← alias → neo layer */
  --shadow: var(--shadow-neo); /* ← alias → neo layer */
  --shadow-md: var(--shadow-neo-md); /* ← alias → neo layer */
  --shadow-hover: var(--shadow-neo-hover); /* ← alias → neo layer */
  --shadow-lg: var(--shadow-neo-lg); /* ← alias → neo layer */
  --shadow-xl: 0 1px 3px 0px oklch(0 0 0 / 0.1), 0 8px 10px -1px oklch(0 0 0 / 0.1);
  --shadow-2xl: 0 1px 3px 0px oklch(0 0 0 / 0.25);
}

/* ═══════════════════════════════════════════════════════════════════════
   DARK MODE — Class-based toggle (html.dark)
   ═══════════════════════════════════════════════════════════════════════ */
html.dark {
  color-scheme: dark;

  --background: oklch(0.27 0.025 45);
  --secondary: oklch(0.19 0.012 50);
  --card: oklch(0.23 0.022 40);
  --background-inverse: oklch(0.98 0.002 85);
  --muted: oklch(0.22 0.012 50);

  --foreground: oklch(0.97 0.002 85);
  --muted-foreground: oklch(0.66 0.01 90.4); /* bumped L 0.63→0.66 for WCAG AA 4.8:1 */
  --ink-subtle: oklch(0.65 0.01 75);

  --border: oklch(0.58 0.09 78.67);
  --border-fg: oklch(0.13 0.005 60);
  --input: oklch(0.26 0.008 60);
  --border-subtle: oklch(0.22 0.006 60);
  --dark: oklch(0.11 0.005 50);

  --primary: oklch(0.82 0.35 39); /* dark-mode warm orange-red (was red 0.84 0.2 25) */
  --primary-foreground: oklch(0.15 0.04 39); /* dark warm — WCAG AA 11.3:1 on primary */

  --overlay-backdrop: oklch(0 0 0 / 0.65);
  --tap-highlight: oklch(1 0 0 / 0.08);
  --ghost-img-filter: brightness(0) invert(1);
  --ghost-ink: oklch(1 0 0 / 0.06);
  --ghost-ink-mid: oklch(1 0 0 / 0.08);
  --ghost-ink-strong: oklch(1 0 0 / 0.12);
  --pattern-ink: oklch(1 0 0 / 0.04);
  --pattern-ink-mid: oklch(1 0 0 / 0.06);

  --selection-bg: oklch(0.12 0.13 90);
  --selection-dark-bg: oklch(0.14 0.13 90);
  --selection-warm-bg: oklch(0.16 0.13 90);
  --selection-card-bg: oklch(0.1 0.12 90);
  --selection-stats-bg: oklch(0.12 0.1 90);

  --destructive: oklch(0.65 0.22 25);
  --accent-orange: oklch(0.7 0.2 45);
  --accent-blue: oklch(0.58 0.2 264);
  --accent-amber: oklch(0.8 0.17 85);
  --accent-green: oklch(0.68 0.19 145);
  --accent-yellow: oklch(0.85 0.16 97);
  --accent-purple: oklch(0.5 0.2 295);

  /* Module aliases + on-fill auto-derive from dark accent overrides above.
     Only unique-hue modules need explicit dark overrides. */
  --on-fill-blue: oklch(from var(--accent-blue) calc(l + 0.3) calc(c - 0.1) h);
  --on-fill-green: oklch(from var(--accent-green) calc(l + 0.2) calc(c - 0.09) h);
  --on-fill-amber: oklch(from var(--accent-amber) calc(l + 0.1) calc(c - 0.05) h);
  --on-fill-orange: oklch(from var(--accent-orange) calc(l + 0.15) calc(c - 0.05) h);
  --on-fill-purple: oklch(from var(--accent-purple) calc(l + 0.35) calc(c - 0.1) h);
  --on-fill-red: oklch(from var(--destructive) calc(l + 0.2) calc(c - 0.08) h);
  --module-logistics: oklch(0.58 0.12 195);
  --module-logistics-text: oklch(0.82 0.08 195);
  --module-quality: oklch(0.58 0.24 350);
  --module-quality-text: oklch(0.85 0.14 350);
  --module-analytics: oklch(from var(--accent-blue) calc(l - 0.08) calc(c - 0.02) h);
  --module-analytics-text: oklch(0.85 0.1 264);
  --module-devops: oklch(0.58 0.04 240);
  --module-devops-text: oklch(0.82 0.03 240);

  /* ── Extended dark overrides ── */
  --gold: color-mix(in oklch, var(--primary) 45%, var(--muted-foreground));
  --panel-overlay: oklch(0 0 0 / 0.15);
  --panel-foreground: oklch(0.13 0 0);
  --surface-invert: oklch(0.13 0 0);
  --surface-invert-muted: oklch(0 0 0 / 0.5);
  --primary-hover: oklch(0.75 0.32 39);
  --code: oklch(0.1 0 0);
  --code-header: oklch(0.14 0 0);

  /* ── Hero hatching dark ── */
  --hero-backdrop-left: oklch(0.09 0 0);
  --hero-backdrop-right: oklch(0.5 0.22 55);
  --hero-hatch-left: oklch(0.35 0.03 75 / 0.55);
  --hero-hatch-right: oklch(0.4 0.18 55 / 0.3);

  --hero-flip-a: oklch(0.75 0.12 264);
  --hero-flip-b: oklch(0.82 0.12 55);
  --background-inverse-30: oklch(0 0 0 / 0.4);
  --background-inverse-20: oklch(0 0 0 / 0.3);

  --surface-header-alt: oklch(0.32 0.04 15);
  --surface-header-warm: oklch(0.38 0.06 95);
  --surface-header-alt-blue: oklch(0.32 0.04 240);
  --surface-header-alt-green: oklch(0.32 0.04 145);

  --warm-50: oklch(0.2 0.006 75);
  --warm-100: oklch(0.24 0.01 75);
  --warm-200: oklch(0.3 0.012 70);
  --warm-300: oklch(0.36 0.015 75);
  --warm-400: oklch(0.55 0.02 55);
  --warm-500: oklch(0.92 0.002 85);

  --stats-bar: oklch(0.22 0.12 95);
  --stats-card-1: oklch(0.28 0.1 95);
  --stats-card-2: oklch(0.34 0.12 45);
  --stats-card-3: oklch(0.34 0.12 250);
  --stats-card-4: oklch(0.36 0.12 150);

  /* Fills — derived (dark: low lightness tints) */
  --fill-blue: oklch(from var(--accent-blue) 0.22 0.02 h);
  --fill-green: oklch(from var(--accent-green) 0.22 0.02 h);
  --fill-amber: oklch(from var(--accent-amber) 0.22 0.025 h);
  --fill-yellow: oklch(from var(--accent-yellow) 0.22 0.025 h);
  --fill-purple: oklch(from var(--accent-purple) 0.22 0.02 h);
  --fill-red: oklch(from var(--destructive) 0.22 0.02 h);
  --fill-orange: oklch(from var(--accent-orange) 0.22 0.025 h);

  --shadow-neo-lg: 8px 8px 0 oklch(0 0 0 / 0.5);

  /* ── Trust tier (dark) ─────────────────────────────────────────────── */
  --trust-gold-bg: oklch(0.32 0.08 95);
  --trust-gold-fg: oklch(0.88 0.1 80);
  --trust-gold-border: oklch(0.5 0.1 80);
  --trust-certified-bg: oklch(0.28 0.06 150);
  --trust-certified-fg: oklch(0.85 0.08 150);
  --trust-certified-border: oklch(0.45 0.1 150);
  --trust-sandbox-bg: oklch(0.28 0.04 250);
  --trust-sandbox-fg: oklch(0.82 0.06 250);
  --trust-sandbox-border: oklch(0.42 0.08 250);

  /* ── Basecoat / shadcn dark overrides ────────────────────────────────── */
  --card-foreground: var(--foreground);
  --popover: var(--card);
  --popover-foreground: var(--foreground);
  --secondary-foreground: var(--foreground);
  --accent: var(--secondary);
  --accent-foreground: var(--foreground);
  --destructive-foreground: var(--border-fg);
  --chart-5: var(--accent-orange);

  /* Sidebar (dark) */
  --sidebar: var(--secondary);
  --sidebar-foreground: var(--foreground);
  --sidebar-primary: var(--primary);
  --sidebar-primary-foreground: var(--primary-foreground);
  --sidebar-accent: var(--muted);
  --sidebar-accent-foreground: var(--foreground);
  --sidebar-border: var(--border-subtle);
  --sidebar-ring: var(--accent-purple);
}
