/* ===========================================================================
 * @fiveforge/tokens — the FiveForge theme sheet.
 *
 * SINGLE SOURCE OF TRUTH for every design token in a FiveForge SaaS app:
 * color (light + dark), typography hooks, radius scale, touch target.
 * Values mirror packages/tokens/tokens.json — change BOTH when tuning.
 *
 * Consume from an app's globals.css, after Tailwind:
 *
 *   @import "tailwindcss";
 *   @import "tw-animate-css";
 *   @import "shadcn/tailwind.css";
 *   @import "@fiveforge/tokens/theme.css";
 *   @source "../node_modules/@fiveforge/ui/src";   (adjust relative path)
 *
 * Fonts: the brand typeface is Geist (+ Geist Mono). Apps load it via
 * next/font with the variables --font-geist-sans / --font-geist-mono on
 * <html>; this sheet picks those up and falls back to the system stack.
 *
 * Raw (non-Tailwind) consumers — server-rendered HTML, email — can load this
 * sheet directly and read every token from `:root` / `.dark`, plus the
 * `.tap-target` helper. Browsers discard the `@theme inline` block, so nothing
 * may be defined ONLY there; it re-exports `:root` values under Tailwind's
 * names and adds no values of its own.
 *
 * First principle (docs/design-system.md): ONE DIAL PER VALUE. Never
 * hardcode in an app a value this sheet covers.
 * ======================================================================== */

@custom-variant dark (&:is(.dark *));

@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --font-sans: var(--font-sans-stack);
  --font-mono: var(--font-mono-stack);
  --font-heading: var(--font-sans);
  --color-sidebar-ring: var(--sidebar-ring);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar: var(--sidebar);
  --color-chart-5: var(--chart-5);
  --color-chart-4: var(--chart-4);
  --color-chart-3: var(--chart-3);
  --color-chart-2: var(--chart-2);
  --color-chart-1: var(--chart-1);
  --color-success: var(--success);
  --color-success-foreground: var(--success-foreground);
  --color-warning: var(--warning);
  --color-warning-foreground: var(--warning-foreground);
  --color-info: var(--info);
  --color-info-foreground: var(--info-foreground);
  --color-ring: var(--ring);
  --color-input: var(--input);
  --color-border: var(--border);
  --color-destructive: var(--destructive);
  --color-accent-foreground: var(--accent-foreground);
  --color-accent: var(--accent);
  --color-muted-foreground: var(--muted-foreground);
  --color-muted: var(--muted);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-secondary: var(--secondary);
  --color-primary-foreground: var(--primary-foreground);
  --color-primary: var(--primary);
  --color-popover-foreground: var(--popover-foreground);
  --color-popover: var(--popover);
  --color-card-foreground: var(--card-foreground);
  --color-card: var(--card);
  /* The scale itself is defined in `:root` below, not here — see the note
     there. This block only re-exports it under Tailwind's names, exactly as
     `--color-*` re-exports the raw color tokens. The names deliberately differ
     from the raw ones: Tailwind also emits these declarations, so a shared name
     would leave two same-specificity rules whose winner depends on whether the
     app imported this sheet after `tailwindcss`. */
  --radius-sm: var(--radius-scale-sm);
  --radius-md: var(--radius-scale-md);
  --radius-lg: var(--radius-scale-lg);
  --radius-xl: var(--radius-scale-xl);
  --radius-2xl: var(--radius-scale-2xl);
  --radius-3xl: var(--radius-scale-3xl);
  --radius-4xl: var(--radius-scale-4xl);
}

:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0 0);
  --primary: oklch(0.38 0.20 295);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.96 0.008 295);
  --secondary-foreground: oklch(0.30 0.12 295);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.543 0 0);
  --accent: oklch(0.96 0.008 295);
  --accent-foreground: oklch(0.30 0.12 295);
  --destructive: oklch(0.521 0.245 27.325);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.50 0.18 295);
  --chart-1: oklch(0.50 0.22 295);
  --chart-2: oklch(0.60 0.12 195);
  --chart-3: oklch(0.55 0.18 340);
  --chart-4: oklch(0.75 0.16 85);
  --chart-5: oklch(0.60 0.14 165);

  /* Semantic status tokens — tuned to the purple system's lightness/chroma
     discipline. Base values are legible AS TEXT on a tinted (/10) background
     (the Badge pattern), so they sit a touch darker than the chart anchors.
     The `-foreground` pairs are the on-solid-fill text color. One dial each.

     Lightness is set by WCAG AA, not by eye: each is the highest L that still
     measures >= 4.5:1 as 12px text on its own /10 tint over the WORST realistic
     base — the muted page background, not the white card. Solving against the
     card alone left the Badge at 4.44:1 wherever it sits on page chrome. The
     earlier values were tuned for the same pattern but never measured, and sat
     at 3.3-4.0:1 — warning was the worst at 3.29:1. Verified with
     @axe-core/playwright against the showcase; re-measure if you retune. */
  --success: oklch(0.504 0.13 165); /* emerald, anchored to --chart-5 (165) */
  --success-foreground: oklch(0.985 0 0);
  --warning: oklch(0.529 0.13 85); /* amber (~85) */
  --warning-foreground: oklch(0.985 0 0);
  --info: oklch(0.504 0.15 230); /* blue (~230) */
  --info-foreground: oklch(0.985 0 0);

  /* Minimum tappable control size. One dial — bump to 48px if field testing
     wants it. Exposed as a value and applied via the `.tap-target` helper. */
  --touch-target: 44px;

  /* Radius. `--radius` is the ONE dial; the scale is a fixed multiplier set.
     Defined HERE rather than in `@theme inline` because browsers drop unknown
     at-rules wholesale: a consumer that loads this sheet raw (server-rendered
     HTML, email) sees `:root` but never sees `@theme`. Tailwind consumers get
     the same values re-exported above, so there is still one dial. */
  --radius: 0.625rem;
  --radius-scale-sm: calc(var(--radius) * 0.6);
  --radius-scale-md: calc(var(--radius) * 0.8);
  --radius-scale-lg: var(--radius);
  --radius-scale-xl: calc(var(--radius) * 1.4);
  --radius-scale-2xl: calc(var(--radius) * 1.8);
  --radius-scale-3xl: calc(var(--radius) * 2.2);
  --radius-scale-4xl: calc(var(--radius) * 2.6);

  /* Brand typeface stacks, for the same reason. Apps set --font-geist-sans /
     --font-geist-mono via next/font; everyone else gets the fallback. */
  --font-sans-stack: var(--font-geist-sans, ui-sans-serif, system-ui, sans-serif);
  --font-mono-stack: var(--font-geist-mono, ui-monospace, SFMono-Regular, Menlo, monospace);

  --sidebar: oklch(0.985 0 0);
  --sidebar-foreground: oklch(0.145 0 0);
  --sidebar-primary: oklch(0.38 0.20 295);
  --sidebar-primary-foreground: oklch(0.985 0 0);
  --sidebar-accent: oklch(0.96 0.008 295);
  --sidebar-accent-foreground: oklch(0.30 0.12 295);
  --sidebar-border: oklch(0.922 0 0);
  --sidebar-ring: oklch(0.50 0.18 295);
}

.dark {
  --background: oklch(0.145 0.015 295);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.17 0.02 295);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.17 0.02 295);
  --popover-foreground: oklch(0.985 0 0);
  /* Dark primary carries TWO jobs that pull opposite ways: it is a solid fill
     behind --primary-foreground (buttons, default Badge) and it is TEXT on the
     card (links, text-primary). Darkening it for white button text pushed the
     text use down to 3.9:1. Pairing a brighter fill with a DARK foreground
     satisfies both — 5.1:1 on the fill, 4.8:1 as text — and is the usual
     dark-theme convention for a vivid accent. Keep the foreground dark if you
     retune --primary upward. */
  --primary: oklch(0.65 0.26 295);
  --primary-foreground: oklch(0.145 0 0);
  --secondary: oklch(0.25 0.03 295);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.25 0.03 295);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.25 0.03 295);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.704 0.191 22.216);
  --border: oklch(0.28 0.035 295);
  --input: oklch(0.28 0.035 295);
  --ring: oklch(0.55 0.20 295);
  --chart-1: oklch(0.62 0.26 295);
  --chart-2: oklch(0.75 0.14 195);
  --chart-3: oklch(0.65 0.22 340);
  --chart-4: oklch(0.80 0.16 85);
  --chart-5: oklch(0.65 0.18 165);

  /* Status tokens — brighter in dark so they stay legible as text on the
     dark tinted background (mirrors how --destructive lifts 0.532 → 0.704).
     These already clear AA on the /15 dark tint (5.3-7.5:1); unlike the light
     ramp they needed no correction. */
  --success: oklch(0.72 0.15 165);
  --success-foreground: oklch(0.145 0.02 165);
  --warning: oklch(0.80 0.15 85);
  --warning-foreground: oklch(0.20 0.02 85);
  --info: oklch(0.70 0.15 230);
  --info-foreground: oklch(0.145 0.02 230);

  --sidebar: oklch(0.155 0.025 295);
  --sidebar-foreground: oklch(0.985 0 0);
  --sidebar-primary: oklch(0.68 0.26 295);
  --sidebar-primary-foreground: oklch(0.145 0 0);
  --sidebar-accent: oklch(0.25 0.04 295);
  --sidebar-accent-foreground: oklch(0.985 0 0);
  --sidebar-border: oklch(0.28 0.035 295);
  --sidebar-ring: oklch(0.55 0.20 295);
}

@layer base {
  * {
    @apply border-border outline-ring/50;
  }
  body {
    @apply bg-background text-foreground;
  }
  html {
    @apply font-sans;
  }
  /* Minimum tappable target — apply to any control a thumb hits in the field.
     One dial: change --touch-target above to retune every consumer at once. */
  .tap-target {
    min-height: var(--touch-target);
    min-width: var(--touch-target);
  }
}
