/*
 * Maestria design tokens.
 *
 * Theme: light and dark both come from `color-scheme` + light-dark().
 * By default the OS decides (prefers-color-scheme). Setting
 * data-theme="light" | "dark" on <html> forces one, and the classes
 * .theme-light / .theme-dark force a theme on any subtree (used by the
 * component sheet to show both themes side by side).
 *
 * Colors are OKLCH so every hue has the same perceived lightness, which keeps
 * workspace and status colors equally readable in both themes.
 */

:root {
  color-scheme: light dark;

  /* Type */
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --fs-2xs: 11px;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 15px;
  --fs-md: 16px;
  --fs-lg: 18px;
  --fs-xl: 22px;
  --fs-2xl: 28px;
  --lh-tight: 1.25;
  --lh: 1.5;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --tracking-tight: -0.011em;
  --tracking-caps: 0.06em;

  /* Space (4px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;

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

  /* Layout */
  --sidebar-w-min: 248px;
  --sidebar-w-max: 496px;                /* 2x the minimum; the resizer in sidebar.js reads both */
  --sidebar-w: var(--sidebar-w-min);     /* the resizer overrides this on <html> (CSSOM, CSP-safe) */
  --topbar-h: 56px;
  --bottomnav-h: 60px;
  --content-max: 1240px;
  --tap: 44px;          /* minimum touch target */
  --control-h: 40px;    /* default control height; 34px on desktop */
  --control-h-sm: 32px; /* 28px on desktop */

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

  /* Neutrals: warm paper in light, cool graphite in dark */
  --bg:          light-dark(oklch(0.978 0.003 85),  oklch(0.165 0.006 260));
  --surface:     light-dark(oklch(1 0 0),           oklch(0.205 0.007 260));
  --surface-2:   light-dark(oklch(0.966 0.004 85),  oklch(0.235 0.008 260));
  --surface-3:   light-dark(oklch(0.94 0.005 85),   oklch(0.275 0.009 260));
  --sunken:      light-dark(oklch(0.968 0.004 85),  oklch(0.145 0.006 260));
  --line:        light-dark(oklch(0.912 0.005 85),  oklch(0.285 0.009 260));
  --line-strong: light-dark(oklch(0.84 0.007 85),   oklch(0.37 0.011 260));
  --text:        light-dark(oklch(0.21 0.008 85),   oklch(0.94 0.004 260));
  --text-2:      light-dark(oklch(0.42 0.008 85),   oklch(0.77 0.008 260));
  --text-3:      light-dark(oklch(0.52 0.008 85),   oklch(0.65 0.01 260));

  /* Primary actions are "ink": the text color, inverted. Color is reserved for meaning. */
  --ink:         light-dark(oklch(0.23 0.01 85),    oklch(0.93 0.005 260));
  --ink-hover:   light-dark(oklch(0.33 0.01 85),    oklch(0.84 0.006 260));
  --on-ink:      light-dark(oklch(0.99 0 0),        oklch(0.17 0.006 260));

  --meter:       light-dark(oklch(0.6 0.035 255),   oklch(0.7 0.035 255));  /* neutral usage bars */
  --link:        light-dark(oklch(0.47 0.15 255),   oklch(0.79 0.11 255));
  --focus:       light-dark(oklch(0.58 0.17 255),   oklch(0.72 0.14 255));
  --danger:      light-dark(oklch(0.54 0.19 25),    oklch(0.55 0.19 25));
  --danger-hover:light-dark(oklch(0.48 0.18 25),    oklch(0.5 0.18 25));
  --on-danger:   oklch(0.99 0 0);
  --scrim:       light-dark(oklch(0.2 0.01 85 / 0.32), oklch(0.05 0 0 / 0.6));

  --shadow-1: light-dark(0 1px 2px oklch(0.2 0.01 85 / 0.05), 0 1px 2px oklch(0 0 0 / 0.4));
  --shadow-2: light-dark(0 1px 2px oklch(0.2 0.01 85 / 0.06), 0 1px 2px oklch(0 0 0 / 0.5)),
              light-dark(0 8px 24px -8px oklch(0.2 0.01 85 / 0.14), 0 12px 32px -8px oklch(0 0 0 / 0.6));
}

:root[data-theme="light"], .theme-light { color-scheme: light; }
:root[data-theme="dark"],  .theme-dark  { color-scheme: dark; }

@media (min-width: 1024px) {
  :root {
    --fs-base: 14px;
    --control-h: 34px;
    --control-h-sm: 28px;
  }
}

/*
 * Tones. One mechanism for workspace colors and status colors:
 * an element sets --tone-h (hue) and --tone-c (chroma), and gets
 *   --tone       solid (dots, bars, swatches)
 *   --tone-ink   readable text on --tone-tint or on surfaces (AA in both themes)
 *   --tone-tint  soft background
 *   --tone-line  soft border
 * --tone-l / --tone-l-dark tune the solid lightness for hues that look
 * muddy at the default (amber, lime).
 */
[data-ws], [data-status], [data-tone] {
  --tone-c: 0.14;
  --tone-h: 255;
  --tone-l: 0.6;        /* reset here so nested tones never inherit a tweak */
  --tone-l-dark: 0.72;
  --tone:      light-dark(oklch(var(--tone-l) var(--tone-c) var(--tone-h)),
                          oklch(var(--tone-l-dark) var(--tone-c) var(--tone-h)));
  --tone-ink:  light-dark(oklch(0.45 calc(var(--tone-c) * 0.85) var(--tone-h)),
                          oklch(0.84 calc(var(--tone-c) * 0.6) var(--tone-h)));
  --tone-tint: light-dark(oklch(0.958 calc(var(--tone-c) * 0.22) var(--tone-h)),
                          oklch(0.27 calc(var(--tone-c) * 0.32) var(--tone-h)));
  --tone-line: light-dark(oklch(0.86 calc(var(--tone-c) * 0.45) var(--tone-h)),
                          oklch(0.38 calc(var(--tone-c) * 0.5) var(--tone-h)));
}

/* Workspace palette: the 10 colors a user can pick for a workspace. */
[data-ws="blue"],   [data-tone="blue"]   { --tone-h: 255; --tone-c: 0.15; }
[data-ws="sky"],    [data-tone="sky"]    { --tone-h: 225; --tone-c: 0.12; }
[data-ws="teal"],   [data-tone="teal"]   { --tone-h: 190; --tone-c: 0.11; }
[data-ws="green"],  [data-tone="green"]  { --tone-h: 150; --tone-c: 0.13; }
[data-ws="amber"],  [data-tone="amber"]  { --tone-h: 75;  --tone-c: 0.15; --tone-l: 0.74; --tone-l-dark: 0.8; }
[data-ws="orange"], [data-tone="orange"] { --tone-h: 48;  --tone-c: 0.16; --tone-l: 0.66; }
[data-ws="rose"],   [data-tone="rose"]   { --tone-h: 15;  --tone-c: 0.16; }
[data-ws="pink"],   [data-tone="pink"]   { --tone-h: 350; --tone-c: 0.14; }
[data-ws="violet"], [data-tone="violet"] { --tone-h: 300; --tone-c: 0.14; }
[data-ws="slate"],  [data-tone="slate"]  { --tone-h: 255; --tone-c: 0.03; --tone-l: 0.55; }
/* Not a workspace colour: a true red, for chat thread swatches (rose and pink sit too close). */
[data-tone="red"] { --tone-h: 27; --tone-c: 0.19; }

/* Status semantics. */
[data-status="working"] { --tone-h: 255; --tone-c: 0.15; }
[data-status="idle"]    { --tone-h: 255; --tone-c: 0.015; --tone-l: 0.68; --tone-l-dark: 0.58; }
[data-status="needs"]   { --tone-h: 75;  --tone-c: 0.15; --tone-l: 0.74; --tone-l-dark: 0.8; }
[data-status="blocked"] { --tone-h: 25;  --tone-c: 0.17; }
[data-status="review"]  { --tone-h: 300; --tone-c: 0.14; }
[data-status="done"]    { --tone-h: 150; --tone-c: 0.13; }
[data-status="offline"] { --tone-h: 255; --tone-c: 0.01; --tone-l: 0.62; --tone-l-dark: 0.52; }
[data-status="ok"]      { --tone-h: 150; --tone-c: 0.13; }
[data-status="warn"]    { --tone-h: 75;  --tone-c: 0.15; --tone-l: 0.74; --tone-l-dark: 0.8; }
[data-status="danger"]  { --tone-h: 25;  --tone-c: 0.17; }
[data-status="info"]    { --tone-h: 255; --tone-c: 0.12; }
