/*
 * QPM design tokens — the single source of every colour, size, radius, shadow
 * and duration in the Web UI (ADR-0033 §2, UI_STYLE_GUIDE §2-§4).
 *
 * Two layers, and the distinction matters:
 *
 *  - GUIDE tokens (`--bg`, `--card`, `--fg`, `--accent`, `--r-m`, …) are the
 *    values of UI_STYLE_GUIDE §2-§4 verbatim, per theme. `guide-tokens.spec.ts`
 *    compares them with the guide's tables, so the file cannot drift from it.
 *  - SEMANTIC tokens (`--color-surface`, `--color-text-primary`, …) name a
 *    ROLE. Components reference only these. `:root[data-theme='dark']`
 *    re-points the guide layer, which is the whole dual-theme mechanism.
 *
 * `-ink` tokens are the AA-safe TEXT variants of guide colours (owner decision
 * 2026-09-23, #863, option A): the guide colour stays for fills, icons and
 * decorative lines; text and control edges use the `-ink` value so the
 * contrast spec holds without being weakened.
 */

:root {
  /* ---- Guide §2.1 — light theme ---- */
  --bg: #ffffff;
  --panel: #ffffff;
  --card: #ffffff;
  --card-2: #f4f2ef;
  --card-3: #efece8;
  --line: #e9e5e0;
  --line-2: #ddd8d1;
  --fg: #1d1d20;
  --fg-2: #6b655e;
  --fg-3: #9c958c;
  --on-accent: #0a0a0f;

  /* ---- Guide §2.3 — accent and statuses, same in both themes ---- */
  --accent: #6666ff;
  --accent-hover: #7575ff;
  --accent-2: #a7b5ff;
  --accent-soft: rgb(102 102 255 / 0.1);
  --accent-soft-2: rgb(102 102 255 / 0.18);
  --ok: #2e9e6b;
  --ok-soft: rgb(46 158 107 / 0.12);
  --err: #d64550;
  --err-soft: rgb(214 69 80 / 0.08);
  --warn: #b45309;
  --info: #2563eb;

  /* ---- AA-safe text variants (-ink), light ---- */
  --accent-ink: #3a3fc9;
  --ok-ink: #277858;
  --err-ink: #cc2934;
  --warn-ink: #ae5009;
  --info-ink: #1f60eb;
  --fg-3-ink: #8e877e;
  --line-control: #8c8780;

  /* ---- Status tints: the guide's -soft over the card, flattened so the
         contrast spec can measure text on them ---- */
  --ok-tint: #e6f3ed;
  --err-tint: #fcf0f1;
  --warn-tint: #f8eee6;
  --info-tint: #e9effd;
  --accent-tint: #f0f0ff;

  /* Approved qpm.ai brand (#1671): original blue artwork on a neutral plate. */
  --logo-ink: #6666ff;
  --logo-plate: #d9d9d9;
  --brand-hero: #f0efff;
  --brand-headline: #6666ff;
  --brand-logo-width: 90px;
  --brand-logo-height: 40px;
  --brand-logo-compact-width: 65px;
  --brand-logo-compact-height: 29px;

  /* ---- Semantic: surfaces ---- */
  --color-canvas: var(--bg);
  --color-surface: var(--card);
  --color-surface-raised: var(--card);
  --color-surface-sunken: var(--card-2);
  --color-surface-muted: var(--card-2);
  --color-surface-inverse: var(--fg);

  /* ---- Sidebar: the guide's --panel in BOTH themes (§6). It follows the theme
         through the guide layer; it is never painted with flip tokens
         (`-inverse`, `-on-accent`). ---- */
  --color-sidebar-bg: var(--panel);
  --color-sidebar-text: var(--fg-2);
  --color-sidebar-text-muted: var(--fg-2);
  --color-sidebar-hover: var(--card-2);
  --color-sidebar-selected: var(--accent-soft);
  --color-sidebar-border: var(--line);

  /* Auth palette follows the approved light hero, independently of navigation. */
  --color-slab-bg: var(--brand-hero);
  --color-slab-text: #1d1d20;
  --color-slab-text-muted: #5c5c66;
  --color-slab-border: #d8d9f4;

  /* ---- Semantic: text ---- */
  --color-text-primary: var(--fg);
  --color-text-secondary: var(--fg-2);
  --color-text-muted: var(--fg-2);
  --color-text-placeholder: var(--fg-3-ink);
  --color-text-inverse: var(--card);
  --color-text-on-accent: var(--on-accent);

  /* ---- Semantic: borders. `strong` draws the boundary of a control and must
         reach 3:1 (WCAG 1.4.11), hence the -ink value rather than --line-2. ---- */
  --color-border-subtle: var(--line);
  --color-border-strong: var(--line-control);
  --color-border-disabled: var(--line);

  /* ---- Semantic: accent (§2.3) ---- */
  --color-accent: var(--accent);
  --color-accent-hover: var(--accent-hover);
  --color-accent-active: var(--accent-hover);
  --color-accent-subtle: var(--accent-tint);
  --color-accent-selected: var(--accent-soft-2);
  --color-accent-text: var(--accent-ink);
  --color-focus-ring: var(--accent);

  /* ---- Semantic: status (§2.3, §10.5) ---- */
  --color-success: var(--ok-ink);
  --color-success-bg: var(--ok-tint);
  --color-success-text: var(--ok-ink);
  --color-warning: var(--warn-ink);
  --color-warning-bg: var(--warn-tint);
  --color-warning-text: var(--warn-ink);
  --color-error: var(--err-ink);
  --color-error-bg: var(--err-tint);
  --color-error-text: var(--err-ink);
  --color-info: var(--info-ink);
  --color-info-bg: var(--info-tint);
  --color-info-text: var(--info-ink);
  --color-ai: var(--accent-ink);
  --color-ai-bg: var(--accent-tint);
  --color-ai-text: var(--accent-ink);

  /* ---- Catalog accent hues (UC-2.18 builder node colour, ADR-0024) ----
     The ten values in CATALOG_COLOR_OPTIONS / WORKSPACE_COLOR_OPTIONS /
     PROJECT_COLOR_OPTIONS are stored on a state/type row but nothing rendered
     them: `data-color` was set on the node with no CSS behind it. These name a
     DECORATIVE accent (a node's left rail + dot), never the sole carrier of
     meaning (§6.3 — the node also shows name, key and badges), so they are held
     to the 3:1 non-text guidance rather than the 4.5:1 text floor and are not
     swept by the contrast spec. Light values are the mid-saturation step; the
     dark block lifts each one so it stays visible on the near-black node. */
  --color-catalog-slate: #64748b;
  --color-catalog-red: #dc2626;
  --color-catalog-orange: #ea580c;
  --color-catalog-amber: #d97706;
  --color-catalog-green: #16a34a;
  --color-catalog-teal: #0d9488;
  --color-catalog-blue: #2563eb;
  --color-catalog-violet: #7c3aed;
  --color-catalog-pink: #db2777;
  --color-catalog-gray: #6b7280;

  /* ---- Typography (§7) ---- */
  --font-sans: var(--font-manrope), ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-heading: var(--font-sora), var(--font-manrope), ui-sans-serif, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --text-2xs: 0.6875rem;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  /* Steps of the guide's type table (§3, §5) that the rem scale above does not carry. They were
     scoped to the assistant page (#704); the guide is one system, so they live here (#897). */
  --text-guide-meta: 11.5px;
  --text-guide-chip: 12.5px;
  --text-guide-ui: 13px;
  --text-guide-ui-lg: 13.5px;
  --text-guide-lead: 15px;
  --text-guide-display: 22px;

  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.55;
  --leading-relaxed: 1.625;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  /* «Body strong» по §7.2 — подписи и важные значения: ступень между semibold и bold,
     которой в стандартной лестнице весов нет имени. Названа по роли, а не по имени
     начертания, потому что ни одна поставляемая гарнитура не несёт face 650.
     #662 AC-2 (решение владельца 2026-09-12): прежде этот комментарий утверждал, что
     650 предписан для H2 и H3 — в продукте такого не было никогда, и §7.2 приведена к
     фактической лестнице (заголовки — 600). В заголовках эта ступень не применяется. */
  --weight-strong: 650;
  --weight-bold: 700;
  --weight-extrabold: 800;

  /* ---- Spacing (§8) ---- */
  --space-0: 0;
  --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-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* ---- Radii (guide §4) ---- */
  --r-s: 10px;
  --r-m: 14px;
  --r-l: 18px;
  --radius-xs: 6px;
  /* §5.6: the assistant mark in a panel header. */
  --r-mark: 8px;
  --radius-sm: var(--r-s);
  --radius-md: var(--r-s);
  --radius-lg: var(--r-m);
  --radius-xl: var(--r-l);
  --radius-modal: 20px;
  --radius-composer: 22px;
  --radius-pill: 99px;

  /* ---- Shadows (guide §4). The dark block redefines --shadow / --shadow-lg. ---- */
  --shadow: 0 1px 2px rgb(30 25 20 / 0.04), 0 4px 16px rgb(30 25 20 / 0.05);
  --shadow-lg: 0 8px 20px rgb(30 25 20 / 0.08), 0 24px 60px rgb(30 25 20 / 0.12);
  --shadow-accent: 0 2px 8px rgb(102 102 255 / 0.28);
  --shadow-xs: var(--shadow);
  --shadow-sm: var(--shadow);
  --shadow-md: var(--shadow);
  --shadow-xl: var(--shadow-lg);

  /* ---- Motion (§9). `prefers-reduced-motion` zeroes these below. ---- */
  --duration-instant: 80ms;
  --duration-fast: 140ms;
  --duration-normal: 220ms;
  --easing-standard: cubic-bezier(0.2, 0, 0.2, 1);

  /* ---- Layout ---- */
  --control-height-sm: 32px;
  --control-height-md: 36px;
  /* 44px is the WCAG 2.5.5 / §30 touch-target floor; it is the DEFAULT
     control height rather than a mobile-only override, so a control cannot
     ship below it by forgetting a media query. */
  --control-height-lg: 44px;
  /* §5.1 button: 34px tall, 14px side padding. On a touch screen the hit area is still 44×44 (§10.7)
     — an invisible layer, not a taller box. */
  --button-height: 34px;
  /* §10.7: the row gap of a wrapping row of buttons on a touch screen — at least the hit layer's overhang above and
     below the SMALLEST hit-layered button, the 32px `sm` one (44px − 32px = 12px; a 34px button needs 10px), so the
     layers of two wrapped rows never overlap and a tap reaches the button it is on (#1660). Used only inside
     `@media (pointer: coarse)`. */
  --touch-row-gap: max(var(--space-2), calc(var(--control-height-lg) - var(--control-height-sm)));
  --button-padding-inline: 14px;
  --focus-ring-width: 3px;
  --focus-ring-offset: 2px;
  /* #662 фаза 5: было 75rem (1200px). На экране 1920 под контент отведено 1672px, то есть
     472px простаивали, и из-за этого таблицы получали колонки по 141px, в которых дата не
     помещалась. 100rem заполняют широкий экран и остаются потолком для очень широких. */
  --content-max-width: 100rem;
  --reading-max-width: 46rem;

  /* ---- Breakpoints (§20/§30). Single source for media queries; CSS cannot
         interpolate a variable inside `@media`, so these exist to be read by
         JS (the /dev/ui viewport switcher, responsive E2E) and to document
         the contract in one place. Component CSS repeats the literal, and
         `tokens.spec.ts` asserts the two agree. ---- */
  --breakpoint-xs: 390px;
  --breakpoint-sm: 768px;
  --breakpoint-md: 1024px;
  --breakpoint-lg: 1280px;
  --breakpoint-xl: 1440px;

  /* ---- Z-index scale ----
     Two steps sit BELOW the popup layers, and they are two rather than one on purpose.

     `--z-raised` — sticky chrome that belongs to the CONTENT: a virtualised table's
     sticky `thead`, the rich-editor toolbar, a column resize handle, the bulk-action
     bar. Each of these sticks to `top: 0` inside a container that scrolls UNDER the
     application top bar, so it must stay below it.

     `--z-base` — the application top bar itself.

     Both exist because #662 (phase 2) replaced the app's literal `z-index: 5` on
     `.shell-topbar` with `--z-sticky` (30) and thereby lifted the sticky bar ABOVE
     `.qpm-menu` (`--z-dropdown`, 20): the board card's quick-actions menu became
     unclickable on a phone, because the opaque top bar painted over it. Sticky chrome
     is not a popup, so it needs steps below the popup layers, and the scale had none.
     One step was not enough: collapsing the top bar and the content chrome onto the
     same value makes the tie break by DOM order, and content comes after the shell —
     which would let a sticky table head paint over the top bar instead of under it. */
  --z-raised: 5;
  --z-base: 10;
  --z-dropdown: 20;
  --z-sticky: 30;
  --z-overlay: 40;
  --z-dialog: 50;
  --z-toast: 60;
}

/*
 * Dark theme (guide §2.2, §4). Re-points the GUIDE layer; the semantic layer
 * follows through var(). Accent and statuses keep their guide fills; their
 * -ink text variants move up so text stays AA on the dark surfaces.
 */
:root[data-theme='dark'] {
  --color-slab-bg: #201f24;
  --color-slab-text: #f0eef2;
  --color-slab-text-muted: #a8a4b0;
  --color-slab-border: #3a3941;
  --brand-headline: #a7b5ff;

  --bg: #141316;
  --panel: #1b1a1e;
  --card: #201f24;
  --card-2: #28272d;
  --card-3: #302f36;
  --line: #2c2b31;
  --line-2: #3a3941;
  --fg: #f0eef2;
  --fg-2: #a8a4b0;
  --fg-3: #726e7b;
  --on-accent: #0a0a0f;

  --accent-ink: #a7b5ff;
  --ok-ink: #43c287;
  --err-ink: #d67f83;
  --warn-ink: #f0a544;
  --info-ink: #7aa2f7;
  --fg-3-ink: #7b7784;
  --line-control: #797880;

  --ok-tint: #233631;
  --err-tint: #3d252b;
  --warn-tint: #3b281f;
  --info-tint: #212b48;
  --accent-tint: #2b2b47;

  --color-text-inverse: var(--bg);

  --shadow: 0 1px 2px rgb(0 0 0 / 0.2), 0 4px 16px rgb(0 0 0 / 0.25);
  --shadow-lg: 0 8px 20px rgb(0 0 0 / 0.3), 0 24px 60px rgb(0 0 0 / 0.45);

  /* Catalog accent hues, lifted so the node's rail and dot stay visible on the
     dark surface. */
  --color-catalog-slate: #94a3b8;
  --color-catalog-red: #f87171;
  --color-catalog-orange: #fb923c;
  --color-catalog-amber: #fbbf24;
  --color-catalog-green: #4ade80;
  --color-catalog-teal: #2dd4bf;
  --color-catalog-blue: #60a5fa;
  --color-catalog-violet: #a78bfa;
  --color-catalog-pink: #f472b6;
  --color-catalog-gray: #9ca3af;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-instant: 0ms;
    --duration-fast: 0ms;
    --duration-normal: 0ms;
  }
}
