/* ────────────────────────────────────────────────────────────────────────────
   SEMANTIC THEME LAYER
   ────────────────────────────────────────────────────────────────────────────
   Maps the raw primitives from tokens.css onto role-based names, then exposes
   those roles to Tailwind through `@theme inline` so they become utilities
   (`bg-background`, `text-muted-foreground`, `rounded-lg`, …).

   This file is HAND-OWNED and stable. `figma-sync` regenerates tokens.css
   underneath it; the mapping below is what survives a re-sync. If a Figma
   variable has no counterpart here, add the mapping once and every component
   picks it up.

   Rule for component authors: only ever use the names defined in this file.
   ──────────────────────────────────────────────────────────────────────────── */

:root {
  /* Surfaces */
  --background: var(--ui-color-neutral-50);
  --foreground: var(--ui-color-neutral-950);
  --card: oklch(1 0 0);
  --card-foreground: var(--ui-color-neutral-950);
  --popover: oklch(1 0 0);
  --popover-foreground: var(--ui-color-neutral-950);

  /* Actions */
  --primary: var(--ui-color-brand-600);
  --primary-foreground: var(--ui-color-neutral-50);
  --secondary: var(--ui-color-neutral-100);
  --secondary-foreground: var(--ui-color-neutral-900);
  --accent: var(--ui-color-brand-50);
  --accent-foreground: var(--ui-color-brand-700);

  /* Quiet content */
  --muted: var(--ui-color-neutral-100);
  --muted-foreground: var(--ui-color-neutral-500);

  /* Status */
  --destructive: var(--ui-color-danger-500);
  --destructive-foreground: var(--ui-color-neutral-50);
  --success: var(--ui-color-success-500);
  --success-foreground: var(--ui-color-neutral-50);
  --warning: var(--ui-color-warning-500);
  --warning-foreground: var(--ui-color-neutral-950);

  /* Lines and focus */
  --border: var(--ui-color-neutral-200);
  --input: var(--ui-color-neutral-200);
  --ring: var(--ui-color-brand-500);

  /* Modal scrim. Deliberately identical in both themes: a scrim's job is to
     darken whatever is behind it, so inverting it in dark mode would make the
     dialog harder to pick out, not easier. */
  --overlay: oklch(0 0 0 / 0.5);

  /* Charts */
  --chart-1: var(--ui-color-chart-1);
  --chart-2: var(--ui-color-chart-2);
  --chart-3: var(--ui-color-chart-3);
  --chart-4: var(--ui-color-chart-4);
  --chart-5: var(--ui-color-chart-5);

  /* Sidebar / app shell — kept separate so a product can tint its navigation
     without disturbing the content surfaces. */
  --sidebar: var(--ui-color-neutral-100);
  --sidebar-foreground: var(--ui-color-neutral-900);
  --sidebar-primary: var(--ui-color-brand-600);
  --sidebar-primary-foreground: var(--ui-color-neutral-50);
  --sidebar-accent: var(--ui-color-neutral-200);
  --sidebar-accent-foreground: var(--ui-color-neutral-900);
  --sidebar-border: var(--ui-color-neutral-200);
  --sidebar-ring: var(--ui-color-brand-500);
}

.dark {
  /* Dark mode is not an inversion — surfaces lift toward the light end while
     text stops short of pure white, which keeps large dark areas from
     vibrating against the type. */
  --background: var(--ui-color-neutral-950);
  --foreground: var(--ui-color-neutral-100);
  --card: var(--ui-color-neutral-900);
  --card-foreground: var(--ui-color-neutral-100);
  --popover: var(--ui-color-neutral-900);
  --popover-foreground: var(--ui-color-neutral-100);

  --primary: var(--ui-color-brand-400);
  --primary-foreground: var(--ui-color-neutral-950);
  --secondary: var(--ui-color-neutral-800);
  --secondary-foreground: var(--ui-color-neutral-100);
  --accent: var(--ui-color-brand-950);
  --accent-foreground: var(--ui-color-brand-200);

  --muted: var(--ui-color-neutral-800);
  --muted-foreground: var(--ui-color-neutral-400);

  --destructive: var(--ui-color-danger-500);
  --destructive-foreground: var(--ui-color-neutral-50);
  --success: var(--ui-color-success-500);
  --success-foreground: var(--ui-color-neutral-950);
  --warning: var(--ui-color-warning-500);
  --warning-foreground: var(--ui-color-neutral-950);

  /* Borders in dark mode are translucent white rather than a fixed grey, so
     they stay visible on top of any surface tint. */
  --border: oklch(1 0 0 / 12%);
  --input: oklch(1 0 0 / 16%);
  --ring: var(--ui-color-brand-400);

  --sidebar: var(--ui-color-neutral-900);
  --sidebar-foreground: var(--ui-color-neutral-100);
  --sidebar-primary: var(--ui-color-brand-400);
  --sidebar-primary-foreground: var(--ui-color-neutral-950);
  --sidebar-accent: var(--ui-color-neutral-800);
  --sidebar-accent-foreground: var(--ui-color-neutral-100);
  --sidebar-border: oklch(1 0 0 / 12%);
  --sidebar-ring: var(--ui-color-brand-400);
}

/* Expose the semantic layer to Tailwind. `inline` means the utilities resolve
   to `var(--background)` rather than a frozen value, so switching .dark or
   overriding a variable at runtime re-themes without a rebuild. */
@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);

  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);

  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);

  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-success: var(--success);
  --color-success-foreground: var(--success-foreground);
  --color-warning: var(--warning);
  --color-warning-foreground: var(--warning-foreground);

  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);
  --color-overlay: var(--overlay);

  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);

  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-ring);

  --radius-sm: var(--ui-radius-sm);
  --radius-md: var(--ui-radius-md);
  --radius-lg: var(--ui-radius-lg);
  --radius-xl: var(--ui-radius-xl);

  --spacing: var(--ui-space-base);

  --font-sans: var(--ui-font-sans);
  --font-mono: var(--ui-font-mono);

  --shadow-xs: var(--ui-shadow-xs);
  --shadow-sm: var(--ui-shadow-sm);
  --shadow-md: var(--ui-shadow-md);
  --shadow-lg: var(--ui-shadow-lg);
  --shadow-xl: var(--ui-shadow-xl);
}
