/* PT-1269 (docs/ui-review-2026-11.md section 4): design tokens in three tiers, primitive -> semantic -> component.
   Layered, so any unlayered page rule still wins. Theme = space toggle: `var(--when-light, A) var(--when-dark, B)`
   picks A or B, the toggle follows the OS unless <html data-theme="light|dark"> (theme.js) or a nested
   [data-theme] element (/styleguide) forces one. Hex colours live only here (tests/test_ui_ratchets.py). */
@layer tokens.primitive, tokens.semantic, tokens.component;

@font-face {
  font-family: "Inter";
  src: url("/static/fonts/inter-var-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@layer tokens.primitive {
  :root, [data-theme] {
    --when-light: initial;
    --when-dark: ;

    --neutral-0: #ffffff;
    --neutral-1: #f6f8fa;
    --neutral-2: #eef1f4;
    --neutral-3: #e2e7ec;
    --neutral-4: #cdd5dd;
    --neutral-5: #a7b2bd;
    --neutral-6: #7c8794;
    --neutral-7: #5b6673;
    --neutral-8: #3a4350;
    --neutral-9: #262d37;
    --neutral-10: #1a2028;
    --neutral-11: #11151b;

    --blue-50: #e0f2fe;
    --blue-200: #bae6fd;
    --blue-300: #7dd3fc;
    --blue-400: #38bdf8;
    --blue-700: #0369a1;
    --blue-900: #0c2a3d;
    --blue-800: #164e6e;
    --slate-900: #0f172a;
    --green-50: #dcfce7;
    --green-200: #bbf7d0;
    --green-400: #4ade80;
    --green-700: #137a39;
    --green-900: #16321f;
    --green-800: #1f5130;
    --amber-50: #fef3c7;
    --amber-200: #fde68a;
    --amber-400: #fbbf24;
    --amber-700: #ad4f08;
    --amber-900: #3a3420;
    --amber-800: #5c4a1a;
    --red-50: #fde2e2;
    --red-200: #fecaca;
    --red-400: #f87171;
    --red-700: #b91c1c;
    --red-900: #3a1d1d;
    --red-800: #5f2a2a;

    --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.8125rem;
    --font-size-base: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.375rem;
    --font-size-2xl: 1.75rem;
    --font-weight-regular: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --line-height-text: 1.5;
    --line-height-heading: 1.2;

    --space-050: 0.125rem;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-12: 3rem;
    --space-16: 4rem;

    --radius-control: 6px;
    --radius-card: 10px;
    --radius-dialog: 16px;
    --radius-pill: 999px;

    --duration-state: 120ms;
    --duration-enter: 200ms;
    --duration-sheet: 320ms;
    --ease-standard: cubic-bezier(0.2, 0, 0, 1);

    /* Media queries cannot read custom properties: these document the 3 breakpoints for JS and comments. */
    --breakpoint-sm: 480px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 1100px;
    --content-max: 1200px;
    --text-max: 72ch;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --when-light: ; --when-dark: initial; }
  }
  [data-theme="light"] { --when-light: initial; --when-dark: ; }
  [data-theme="dark"] { --when-light: ; --when-dark: initial; }
  @media (prefers-reduced-motion: reduce) {
    :root, [data-theme] { --duration-state: 0ms; --duration-enter: 0ms; --duration-sheet: 0ms; }
  }
}

@layer tokens.semantic {
  :root { color-scheme: light dark; }
  [data-theme="light"] { color-scheme: light; }
  [data-theme="dark"] { color-scheme: dark; }
  :root, [data-theme] {
    --surface-0: var(--when-light, var(--neutral-1)) var(--when-dark, var(--neutral-11));
    --surface-1: var(--when-light, var(--neutral-0)) var(--when-dark, var(--neutral-10));
    --surface-2: var(--when-light, var(--neutral-2)) var(--when-dark, var(--neutral-9));
    --text-1: var(--when-light, var(--neutral-11)) var(--when-dark, var(--neutral-1));
    --text-2: var(--when-light, var(--neutral-8)) var(--when-dark, var(--neutral-4));
    --text-3: var(--when-light, var(--neutral-7)) var(--when-dark, var(--neutral-5));
    --border-1: var(--when-light, var(--neutral-3)) var(--when-dark, var(--neutral-9));
    --border-2: var(--when-light, var(--neutral-4)) var(--when-dark, var(--neutral-8));
    --border-control: var(--neutral-6);

    --accent: var(--when-light, var(--blue-700)) var(--when-dark, var(--blue-400));
    --on-accent: var(--when-light, var(--neutral-0)) var(--when-dark, var(--slate-900));
    --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--surface-1));

    --status-info-fg: var(--when-light, var(--blue-700)) var(--when-dark, var(--blue-300));
    --status-info-bg: var(--when-light, var(--blue-50)) var(--when-dark, var(--blue-900));
    --status-info-border: var(--when-light, var(--blue-200)) var(--when-dark, var(--blue-800));
    --status-good-fg: var(--when-light, var(--green-700)) var(--when-dark, var(--green-400));
    --status-good-bg: var(--when-light, var(--green-50)) var(--when-dark, var(--green-900));
    --status-good-border: var(--when-light, var(--green-200)) var(--when-dark, var(--green-800));
    --status-warn-fg: var(--when-light, var(--amber-700)) var(--when-dark, var(--amber-400));
    --status-warn-bg: var(--when-light, var(--amber-50)) var(--when-dark, var(--amber-900));
    --status-warn-border: var(--when-light, var(--amber-200)) var(--when-dark, var(--amber-800));
    --status-bad-fg: var(--when-light, var(--red-700)) var(--when-dark, var(--red-400));
    --status-bad-bg: var(--when-light, var(--red-50)) var(--when-dark, var(--red-900));
    --status-bad-border: var(--when-light, var(--red-200)) var(--when-dark, var(--red-800));

    --shadow-color: var(--when-light, 16 24 40) var(--when-dark, 0 0 0);
    --elevation-flat: 0 0 0 1px var(--border-1);
    --elevation-raised: 0 1px 2px rgb(var(--shadow-color) / 0.06), 0 1px 3px rgb(var(--shadow-color) / 0.1);
    --elevation-overlay: 0 4px 8px -2px rgb(var(--shadow-color) / 0.1), 0 12px 24px -4px rgb(var(--shadow-color) / 0.14);
    --elevation-modal: 0 8px 16px -4px rgb(var(--shadow-color) / 0.14), 0 24px 48px -12px rgb(var(--shadow-color) / 0.3);

    --focus-ring-width: 2px;
    --focus-ring-offset: 2px;
    --focus-ring-color: var(--accent);
    --target-min: 36px;

    /* Legacy names (style.css era, values unchanged); W3 migrates the pages to the names above and drops these. */
    --bg: var(--when-light, #ffffff) var(--when-dark, #12141a);
    --fg: var(--when-light, #1a1a1a) var(--when-dark, #f0f0f0);
    --muted: var(--when-light, #5f6875) var(--when-dark, #9aa0aa);
    --border: var(--when-light, #e5e7eb) var(--when-dark, #2a2d36);
    --good-bg: var(--when-light, #dcfce7) var(--when-dark, #16321f);
    --good: var(--when-light, #15803d) var(--when-dark, #4ade80);
    --bad-bg: var(--when-light, #fde2e2) var(--when-dark, #3a1d1d);
    --bad: var(--when-light, #b91c1c) var(--when-dark, #f87171);
    --locked-bg: var(--when-light, #fef3c7) var(--when-dark, #3a3420);
    --warn: var(--when-light, #b45309) var(--when-dark, #fbbf24);
    /* Categorical chart palette (dataviz skill, CVD-validated): fixed per technology, never cycled. */
    --series-teplo: var(--when-light, #eb6834) var(--when-dark, #d95926);
    --series-voda: var(--when-light, #2a78d6) var(--when-dark, #3987e5);
    --series-ee: var(--when-light, #cc8400) var(--when-dark, #c98500);
    --series-pristupy: var(--when-light, #4a3aa7) var(--when-dark, #a093ec);
    --series-wb: var(--when-light, #50a470) var(--when-dark, #199e70);
    --series-baterie: var(--when-light, #008300) var(--when-dark, #36ba5d);
    --chart-grid: var(--when-light, #e1e0d9) var(--when-dark, #2c2c2a);
    --chart-baseline: var(--when-light, #c3c2b7) var(--when-dark, #383835);
    --flow-pv: var(--series-ee);
    --flow-grid: var(--series-voda);
    --flow-battery: var(--series-baterie);
    --flow-home: var(--series-pristupy);
    --flow-tuv: var(--series-teplo);
    --card: var(--bg);
    --surface: var(--bg);
    --surface-alt: var(--surface-2);
    --text: var(--fg);
    --line: var(--border);
    --ok: var(--good);
    --warn-bg: var(--locked-bg);
  }
  @media (pointer: coarse) {
    :root, [data-theme] { --target-min: 44px; }
  }
}

@layer tokens.component {
  :root, [data-theme] {
    --button-height: var(--target-min);
    --button-radius: var(--radius-control);
    --field-font-size: var(--font-size-md);
    --field-radius: var(--radius-control);
    --card-bg: var(--surface-1);
    --card-radius: var(--radius-card);
    --card-shadow: var(--elevation-raised);
    --pill-radius: var(--radius-pill);
    --dialog-radius: var(--radius-dialog);
    --dialog-shadow: var(--elevation-modal);
    --table-bg: var(--surface-1);
    --table-head-bg: var(--surface-1);
    --table-border: var(--border-1);
    --table-head-border: var(--border-2);
    --table-row-hover: color-mix(in srgb, var(--accent) 6%, var(--surface-1));
    --table-row-selected: var(--accent-soft);
    --table-cell-py: var(--space-2);
    --table-cell-px: var(--space-3);
    --table-font-size: var(--font-size-base);
    --table-min-width: 34rem;
  }
}

/* PT-1277: higher-contrast preference raises muted text and hairlines; forced colours hand colour to the system. */
@layer tokens.semantic {
  @media (prefers-contrast: more) {
    :root, [data-theme] {
      --text-3: var(--text-2);
      --border-1: var(--border-control);
      --border-2: var(--border-control);
      --focus-ring-width: 3px;
    }
  }
  @media (forced-colors: active) {
    :root, [data-theme] {
      --focus-ring-color: Highlight;
      --border-1: CanvasText;
      --border-2: CanvasText;
      --border-control: CanvasText;
      --accent: LinkText;
      --on-accent: Canvas;
      --text-1: CanvasText;
      --text-2: CanvasText;
      --text-3: CanvasText;
    }
  }
}
