/* =====================================================================
   VWS UI — design tokens
   ---------------------------------------------------------------------
   Every colour, radius, shadow, font and spacing value used by the VWS
   hub and the grid control panels comes from here. Components never use
   raw values. A theme is just a set of overrides of these variables.

   Theme selection (on <html>):
     data-theme="dark" | "light"   forced choice
     (no attribute)                follows the operating system
   Brand overrides (per install, e.g. a hosted grid):
     set --accent (and optionally --accent-2, --brand-name) in theme.css.
   ===================================================================== */

:root {
  /* ---- Typography ---------------------------------------------------- */
  --font-sans: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --fs-2xs: 0.6875rem;  /* 11px */
  --fs-xs: 0.75rem;     /* 12px */
  --fs-sm: 0.8125rem;   /* 13px */
  --fs-md: 0.875rem;    /* 14px  base UI text */
  --fs-lg: 1rem;        /* 16px */
  --fs-xl: 1.25rem;     /* 20px */
  --fs-2xl: 1.625rem;   /* 26px  KPI values */
  --fs-3xl: 2.125rem;   /* 34px */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
  --lh-tight: 1.2;
  --lh-normal: 1.45;
  --tracking-caps: 0.06em;

  /* ---- Spacing (4px grid) ------------------------------------------- */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

  /* ---- Shape ------------------------------------------------------- */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-pill: 999px;

  /* ---- Sizes ------------------------------------------------------- */
  --control-h: 32px;
  --control-h-sm: 26px;
  --control-h-lg: 40px;
  --row-h: 36px;
  --row-h-compact: 30px;
  --sidebar-w: 248px;
  --topbar-h: 56px;
  --detail-w: 380px;

  /* ---- Motion ------------------------------------------------------ */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 360ms;

  /* ---- Brand (override per install) --------------------------------- */
  --accent: #7c5cff;          /* VWS violet */
  --accent-2: #22d3ee;        /* VWS cyan: live data, links, secondary highlights */
  --on-accent: #ffffff;

  /* ---- Status (meaning never changes between themes) ---------------- */
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --info: #60a5fa;
  --stale: #8790ad;

  /* ---- Dark theme (default) ---------------------------------------- */
  color-scheme: dark;
  --bg: #090c15;
  --bg-glow-1: rgba(124, 92, 255, 0.16);
  --bg-glow-2: rgba(34, 211, 238, 0.08);
  --surface-0: #0d111c;       /* sidebar, top bar */
  --surface-1: #121726;       /* cards, panels */
  --surface-2: #192034;       /* raised: buttons, hovered rows */
  --surface-3: #232b44;       /* pressed, selected neutral */
  --field: #0c101b;           /* inputs, sunken wells */
  --glass: rgba(18, 23, 38, 0.72);
  --border: rgba(150, 165, 215, 0.11);
  --border-strong: rgba(150, 165, 215, 0.22);
  --text: #e7ebf8;
  --text-2: #a1aac8;
  --text-3: #6d7699;
  --text-inverse: #0b0e17;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.38), 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  --shadow-3: 0 18px 48px rgba(0, 0, 0, 0.55);
  --highlight-edge: rgba(255, 255, 255, 0.05);   /* 1px top light on cards */
  --scrim: rgba(3, 5, 12, 0.62);

  /* ---- Derived (follow the accent automatically) ------------------- */
  --accent-hover: color-mix(in oklab, var(--accent) 82%, white);
  --accent-soft: color-mix(in oklab, var(--accent) 18%, transparent);
  --accent-softer: color-mix(in oklab, var(--accent) 9%, transparent);
  --accent-text: color-mix(in oklab, var(--accent) 62%, white);
  --accent-2-soft: color-mix(in oklab, var(--accent-2) 16%, transparent);
  --ok-soft: color-mix(in oklab, var(--ok) 16%, transparent);
  --warn-soft: color-mix(in oklab, var(--warn) 16%, transparent);
  --err-soft: color-mix(in oklab, var(--err) 16%, transparent);
  --info-soft: color-mix(in oklab, var(--info) 16%, transparent);
  --stale-soft: color-mix(in oklab, var(--stale) 18%, transparent);
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px color-mix(in oklab, var(--accent) 70%, white);
  --brand-gradient: linear-gradient(120deg, var(--accent-2) 0%, color-mix(in oklab, var(--accent) 60%, var(--accent-2)) 45%, var(--accent) 100%);
}

/* ---- Light theme: shared by "system light" and forced light ---------- */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --accent: #6a4cf0;
    --accent-2: #0891b2;
    --ok: #059669;
    --warn: #b45309;
    --err: #dc2626;
    --info: #2563eb;
    --stale: #7a819a;
    --bg: #f3f5fb;
    --bg-glow-1: rgba(106, 76, 240, 0.10);
    --bg-glow-2: rgba(8, 145, 178, 0.06);
    --surface-0: #ffffff;
    --surface-1: #ffffff;
    --surface-2: #f1f3f9;
    --surface-3: #e5e9f3;
    --field: #ffffff;
    --glass: rgba(255, 255, 255, 0.78);
    --border: rgba(22, 30, 60, 0.10);
    --border-strong: rgba(22, 30, 60, 0.18);
    --text: #12162a;
    --text-2: #4a5273;
    --text-3: #7a82a1;
    --text-inverse: #ffffff;
    --shadow-1: 0 1px 2px rgba(20, 28, 60, 0.06);
    --shadow-2: 0 6px 20px rgba(20, 28, 60, 0.08), 0 1px 2px rgba(20, 28, 60, 0.05);
    --shadow-3: 0 18px 48px rgba(20, 28, 60, 0.18);
    --highlight-edge: rgba(255, 255, 255, 0.9);
    --scrim: rgba(18, 22, 42, 0.38);
    --accent-text: color-mix(in oklab, var(--accent) 88%, black);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --accent: #6a4cf0;
  --accent-2: #0891b2;
  --ok: #059669;
  --warn: #b45309;
  --err: #dc2626;
  --info: #2563eb;
  --stale: #7a819a;
  --bg: #f3f5fb;
  --bg-glow-1: rgba(106, 76, 240, 0.10);
  --bg-glow-2: rgba(8, 145, 178, 0.06);
  --surface-0: #ffffff;
  --surface-1: #ffffff;
  --surface-2: #f1f3f9;
  --surface-3: #e5e9f3;
  --field: #ffffff;
  --glass: rgba(255, 255, 255, 0.78);
  --border: rgba(22, 30, 60, 0.10);
  --border-strong: rgba(22, 30, 60, 0.18);
  --text: #12162a;
  --text-2: #4a5273;
  --text-3: #7a82a1;
  --text-inverse: #ffffff;
  --shadow-1: 0 1px 2px rgba(20, 28, 60, 0.06);
  --shadow-2: 0 6px 20px rgba(20, 28, 60, 0.08), 0 1px 2px rgba(20, 28, 60, 0.05);
  --shadow-3: 0 18px 48px rgba(20, 28, 60, 0.18);
  --highlight-edge: rgba(255, 255, 255, 0.9);
  --scrim: rgba(18, 22, 42, 0.38);
  --accent-text: color-mix(in oklab, var(--accent) 88%, black);
}

/* ---- Density: compact tables/forms for power users -------------------- */
:root[data-density="compact"] {
  --control-h: 28px;
  --row-h: 30px;
  --fs-md: 0.8125rem;
}

/* ---- Accessibility -------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur: 0ms; --dur-slow: 0ms; }
}
