/* ==========================================================================
   PFC 2.0 — DESIGN TOKENS  (Plan §11.6, WP-2.3)
   The single source of visual truth: color, spacing, type, radius, shadow.
   Rules for every future page:
     * Use these custom properties — never hard-coded hex, px, or font names.
     * Semantic status hues (success/warn/error/info) mean the same thing
       everywhere: chips, flashes, and (later) the dispatch timeline.
   Light theme is the base. Dark mode is derived at the bottom and is nearly
   free because only the *semantic* aliases are re-pointed, not the raw palette.
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* ---- Raw palette (never used directly in components — alias below) ------ */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #020617;

  --indigo-50:  #eef2ff;
  --indigo-100: #e0e7ff;
  --indigo-300: #a5b4fc;
  --indigo-500: #6366f1;
  --indigo-600: #4f46e5;
  --indigo-700: #4338ca;

  --green-50:  #ecfdf5;
  --green-200: #a7f3d0;
  --green-500: #10b981;
  --green-600: #059669;
  --green-700: #047857;

  --amber-50:  #fffbeb;
  --amber-200: #fde68a;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
  --amber-700: #b45309;

  --red-50:  #fef2f2;
  --red-200: #fecaca;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --red-700: #b91c1c;

  --sky-50:  #eff6ff;
  --sky-200: #bfdbfe;
  --sky-500: #3b82f6;
  --sky-600: #2563eb;
  --sky-700: #1d4ed8;

  /* ---- Typography -------------------------------------------------------- */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
               Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  --text-xs:   0.75rem;   /* 12px */
  --text-sm:   0.8125rem; /* 13px — dense tables */
  --text-base: 0.875rem;  /* 14px — app default */
  --text-md:   1rem;      /* 16px */
  --text-lg:   1.125rem;  /* 18px */
  --text-xl:   1.375rem;  /* 22px */
  --text-2xl:  1.75rem;   /* 28px — page titles */

  --leading-tight:  1.25;
  --leading-normal: 1.5;

  --weight-normal:   400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;

  /* Tabular figures keep numeric columns aligned in tables (§11.6). */
  --numeric: tabular-nums;

  /* ---- Spacing scale (4px base) ----------------------------------------- */
  --space-1:  0.25rem;  /*  4px */
  --space-2:  0.5rem;   /*  8px */
  --space-3:  0.75rem;  /* 12px */
  --space-4:  1rem;     /* 16px */
  --space-5:  1.25rem;  /* 20px */
  --space-6:  1.5rem;   /* 24px */
  --space-8:  2rem;     /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */

  /* ---- Radius ----------------------------------------------------------- */
  --radius-sm:  4px;
  --radius-md:  6px;
  --radius-lg:  10px;
  --radius-xl:  14px;
  --radius-full: 999px;

  /* ---- Shadow ----------------------------------------------------------- */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 2px 4px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.12);

  /* ---- Layout ----------------------------------------------------------- */
  --sidebar-width: 244px;
  --topbar-height: 56px;
  --content-max: 1180px;

  /* ---- Motion ----------------------------------------------------------- */
  --transition-fast: 120ms ease;
  --transition: 180ms ease;

  /* ======================================================================
     SEMANTIC ALIASES (light) — components use ONLY these.
     ====================================================================== */
  --color-bg:            var(--slate-100);
  --color-surface:       #ffffff;
  --color-surface-2:     var(--slate-50);   /* subtle fills, table stripes */
  --color-sidebar-bg:    var(--slate-900);  /* dark rail on light theme */
  --color-sidebar-fg:    var(--slate-300);
  --color-sidebar-fg-strong: #ffffff;
  --color-sidebar-active-bg: rgba(99, 102, 241, 0.18);
  --color-sidebar-hover-bg:  rgba(255, 255, 255, 0.06);

  --color-border:        var(--slate-200);
  --color-border-strong: var(--slate-300);

  --color-text:          var(--slate-800);
  --color-text-muted:    var(--slate-500);
  --color-text-subtle:   var(--slate-400);
  --color-heading:       var(--slate-900);

  --color-primary:          var(--indigo-600);
  --color-primary-hover:    var(--indigo-700);
  --color-primary-contrast: #ffffff;
  --color-primary-soft-bg:  var(--indigo-50);

  --color-focus-ring: rgba(79, 70, 229, 0.45);
  /* Backdrop scrim behind modals / the off-canvas sidebar. */
  --color-scrim: rgba(2, 6, 23, 0.5);

  /* Status: fg (text/icon), bg (soft fill), border, solid (strong hue) */
  --color-success-fg:     var(--green-700);
  --color-success-bg:     var(--green-50);
  --color-success-border: var(--green-200);
  --color-success-solid:  var(--green-600);

  --color-warn-fg:     var(--amber-700);
  --color-warn-bg:     var(--amber-50);
  --color-warn-border: var(--amber-200);
  --color-warn-solid:  var(--amber-500);

  --color-error-fg:     var(--red-700);
  --color-error-bg:     var(--red-50);
  --color-error-border: var(--red-200);
  --color-error-solid:  var(--red-600);

  --color-info-fg:     var(--sky-700);
  --color-info-bg:     var(--sky-50);
  --color-info-border: var(--sky-200);
  --color-info-solid:  var(--sky-600);

  --color-neutral-fg:     var(--slate-600);
  --color-neutral-bg:     var(--slate-100);
  --color-neutral-border: var(--slate-300);
  --color-neutral-solid:  var(--slate-500);
}

/* ==========================================================================
   DARK MODE — re-point semantic aliases only. Two triggers:
     1) OS preference, when the user hasn't forced a theme (data-theme="auto")
     2) explicit data-theme="dark" (the top-bar toggle)
   The raw palette above is unchanged; only the aliases move.
   ========================================================================== */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --color-bg:            var(--slate-950);
    --color-surface:       var(--slate-900);
    --color-surface-2:     var(--slate-800);
    --color-sidebar-bg:    #0b1220;
    --color-sidebar-fg:    var(--slate-400);
    --color-sidebar-fg-strong: #ffffff;
    --color-sidebar-active-bg: rgba(99, 102, 241, 0.28);
    --color-sidebar-hover-bg:  rgba(255, 255, 255, 0.05);

    --color-border:        var(--slate-700);
    --color-border-strong: var(--slate-600);

    --color-text:          var(--slate-200);
    --color-text-muted:    var(--slate-400);
    --color-text-subtle:   var(--slate-500);
    --color-heading:       #f8fafc;

    --color-primary:          var(--indigo-500);
    --color-primary-hover:    var(--indigo-300);
    --color-primary-contrast: var(--slate-950);
    --color-primary-soft-bg:  rgba(99, 102, 241, 0.14);

    --color-focus-ring: rgba(129, 140, 248, 0.55);
    --color-scrim: rgba(0, 0, 0, 0.6);

    --color-success-fg: var(--green-200); --color-success-bg: rgba(16,185,129,0.14); --color-success-border: rgba(16,185,129,0.35);
    --color-warn-fg:    var(--amber-200); --color-warn-bg:    rgba(245,158,11,0.14); --color-warn-border:    rgba(245,158,11,0.35);
    --color-error-fg:   var(--red-200);   --color-error-bg:   rgba(239,68,68,0.15);  --color-error-border:   rgba(239,68,68,0.38);
    --color-info-fg:    var(--sky-200);   --color-info-bg:    rgba(59,130,246,0.15);  --color-info-border:    rgba(59,130,246,0.38);
    --color-neutral-fg: var(--slate-300); --color-neutral-bg: rgba(148,163,184,0.14); --color-neutral-border: rgba(148,163,184,0.32);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  --color-bg:            var(--slate-950);
  --color-surface:       var(--slate-900);
  --color-surface-2:     var(--slate-800);
  --color-sidebar-bg:    #0b1220;
  --color-sidebar-fg:    var(--slate-400);
  --color-sidebar-fg-strong: #ffffff;
  --color-sidebar-active-bg: rgba(99, 102, 241, 0.28);
  --color-sidebar-hover-bg:  rgba(255, 255, 255, 0.05);

  --color-border:        var(--slate-700);
  --color-border-strong: var(--slate-600);

  --color-text:          var(--slate-200);
  --color-text-muted:    var(--slate-400);
  --color-text-subtle:   var(--slate-500);
  --color-heading:       #f8fafc;

  --color-primary:          var(--indigo-500);
  --color-primary-hover:    var(--indigo-300);
  --color-primary-contrast: var(--slate-950);
  --color-primary-soft-bg:  rgba(99, 102, 241, 0.14);

  --color-focus-ring: rgba(129, 140, 248, 0.55);
  --color-scrim: rgba(0, 0, 0, 0.6);

  --color-success-fg: var(--green-200); --color-success-bg: rgba(16,185,129,0.14); --color-success-border: rgba(16,185,129,0.35);
  --color-warn-fg:    var(--amber-200); --color-warn-bg:    rgba(245,158,11,0.14); --color-warn-border:    rgba(245,158,11,0.35);
  --color-error-fg:   var(--red-200);   --color-error-bg:   rgba(239,68,68,0.15);  --color-error-border:   rgba(239,68,68,0.38);
  --color-info-fg:    var(--sky-200);   --color-info-bg:    rgba(59,130,246,0.15);  --color-info-border:    rgba(59,130,246,0.38);
  --color-neutral-fg: var(--slate-300); --color-neutral-bg: rgba(148,163,184,0.14); --color-neutral-border: rgba(148,163,184,0.32);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
}
