/*
 * Design tokens: the only place where colors, spacing, type sizes and motion get a literal value.
 * A brand (web/css/brand.css, or web/brands/<name>/css/brand.css chosen by BRAND=<name>) redefines the
 * --color-* values and nothing else; docs/DESIGN.md explains the scale.
 * Breakpoints are not tokens (custom properties do not work in @media): 37.5em, 56.25em, 75em.
 * Color mode: every color is light-dark(light, dark); the system chooses, <html data-theme="light|dark">
 * forces one. Needs Chrome 123 / Firefox 120 / Safari 17.5 (2024); nothing else in web/ is newer.
 *
 * Contrast pairs proved by scripts/check-contrast.py for every brand, light and dark (WCAG 2.x, fg on bg).
 * Pairs name tokens, never colors, so the list stays true when a brand swaps the palette:
 * pair: --color-text on --color-surface min 4.5 — text on surface
 * pair: --color-text on --color-bg min 4.5 — text on page
 * pair: --color-text-muted on --color-surface min 4.5 — muted text on surface
 * pair: --color-text-muted on --color-bg min 4.5 — muted text on page
 * pair: --color-text-muted on --color-surface-sunken min 4.5 — muted text on sunken surface
 * pair: --color-on-action on --color-action min 4.5 — primary button text
 * pair: --color-on-action on --color-action-hover min 4.5 — primary button text on hover
 * pair: --color-action on --color-surface min 4.5 — link on surface
 * pair: --color-action on --color-bg min 4.5 — link on page
 * pair: --color-action on --color-action-tint min 4.5 — selected item
 * pair: --color-success on --color-surface min 4.5 — success text
 * pair: --color-danger on --color-surface min 4.5 — error text
 * pair: --color-warning on --color-surface min 4.5 — warning text
 * pair: --color-info on --color-surface min 4.5 — info text
 * pair: --color-success-strong on --color-success-tint min 4.5 — success alert
 * pair: --color-danger-strong on --color-danger-tint min 4.5 — error alert
 * pair: --color-warning-strong on --color-warning-tint min 4.5 — warning alert
 * pair: --color-info-strong on --color-info-tint min 4.5 — info alert
 * pair: --color-on-nav on --color-nav min 4.5 — sidebar text
 * pair: --color-on-action on --color-danger min 4.5 — danger button text
 * pair: --color-border-strong on --color-surface min 3 — field border (non-text)
 * pair: --color-action on --color-surface-sunken min 3 — progress bar on its track
 * pair: --color-track-suporte on --color-track-suporte-tint min 4.5 — Suporte track icon
 * pair: --color-track-implantacao on --color-track-implantacao-tint min 4.5 — Implantação track icon
 * pair: --color-track-vendas on --color-track-vendas-tint min 4.5 — Vendas track icon
 * pair: --color-track-implantacao on --color-surface-sunken min 3 — Implantação progress bar
 * pair: --color-track-vendas on --color-surface-sunken min 3 — Vendas progress bar
 * pair: --color-on-nav on --color-nav-hover min 4.5 — sidebar text on a hovered item
 * pair: --color-on-nav on --color-nav-active min 4.5 — sidebar text on the current item
 * pair: --color-brand on --color-nav min 3 — brand marker on the sidebar (non-text)
 * pair: --color-text on --color-surface-raised min 4.5 — text on a raised card
 * pair: --color-text-muted on --color-surface-raised min 4.5 — muted text on a raised card
 * pair: --color-text-inverse on --color-surface-inverse min 4.5 — tooltip and toast text
 * pair: --color-focus on --color-surface min 3 — focus ring on surface
 * pair: --color-focus on --color-bg min 3 — focus ring on page
 */
@layer tokens {
  :root {
    color-scheme: light dark;

    /* Color: surfaces and text. -raised is a card on the page; -inverse flips for tooltips and toasts. */
    --color-bg: light-dark(#f6f8fa, #0f172a);
    --color-surface: light-dark(#ffffff, #1e293b);
    --color-surface-raised: light-dark(#ffffff, #263447);
    --color-surface-sunken: light-dark(#eef2f6, #182335);
    --color-surface-inverse: light-dark(#0f172a, #f1f5f9);
    --color-border: light-dark(#dfe5ec, #334155);
    --color-border-strong: light-dark(#6b7787, #8b97a5);
    --color-text: light-dark(#0f172a, #f1f5f9);
    --color-text-muted: light-dark(#475569, #b6c2d0);
    --color-text-inverse: light-dark(#f8fafc, #0f172a);

    /* Color: action and brand. The brand hues are decorative (icons, markers, charts), never text. */
    --color-action: light-dark(#0f766e, #2dd4bf);
    --color-action-hover: light-dark(#115e59, #5eead4);
    --color-action-tint: light-dark(#e6f4f2, #134e4a);
    --color-on-action: light-dark(#ffffff, #0f172a);
    --color-focus: var(--color-action);
    --color-brand: #14b8a6;
    --color-brand-2: light-dark(#1d4ed8, #60a5fa);
    --color-brand-3: light-dark(#7c3aed, #c4b5fd);
    --color-nav: #0b4f4a;
    --color-nav-hover: #115e59;
    --color-nav-active: #0f766e;
    --color-on-nav: #ffffff;

    /* Color: status. A -tint background always takes the -strong text, never the base color. */
    --color-success: light-dark(#15803d, #4ade80);
    --color-success-tint: light-dark(#dcfce7, #0f3b2e);
    --color-success-strong: light-dark(#14532d, #bbf7d0);
    --color-danger: light-dark(#b91c1c, #f87171);
    --color-danger-tint: light-dark(#fee2e2, #4a1515);
    --color-danger-strong: light-dark(#7f1d1d, #fecaca);
    --color-warning: light-dark(#b45309, #fbbf24);
    --color-warning-tint: light-dark(#fef3c7, #452a06);
    --color-warning-strong: light-dark(#78350f, #fde68a);
    --color-info: light-dark(#1d4ed8, #60a5fa);
    --color-info-tint: light-dark(#dbeafe, #14325a);
    --color-info-strong: light-dark(#1e3a8a, #bfdbfe);
    --color-scrim: light-dark(rgb(15 23 42 / 0.45), rgb(0 0 0 / 0.6));
    /* Track identity: darker shades of each track's seed accent, legible on their tint. */
    --color-track-suporte: light-dark(#0f766e, #2dd4bf);
    --color-track-suporte-tint: light-dark(#ccfbf1, #0f3b36);
    --color-track-implantacao: light-dark(#1d4ed8, #60a5fa);
    --color-track-implantacao-tint: light-dark(#dbeafe, #14325a);
    --color-track-vendas: light-dark(#c2410c, #fb923c);
    --color-track-vendas-tint: light-dark(#ffedd5, #4a2008);

    /* Type scale: nothing below 13px */
    --text-xs: 0.8125rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: clamp(1.125rem, 1.05rem + 0.3vw, 1.25rem);
    --text-xl: clamp(1.375rem, 1.2rem + 0.8vw, 1.75rem);
    --text-2xl: clamp(1.75rem, 1.4rem + 1.5vw, 2.25rem);
    --text-3xl: clamp(2.25rem, 1.8rem + 2vw, 3rem);
    --leading-none: 1;
    --leading-tight: 1.2;
    --leading-normal: 1.45;
    --leading-relaxed: 1.6;
    --weight-regular: 400;
    --weight-medium: 500;
    --weight-bold: 700;
    --tracking-tight: -0.01em;
    --tracking-wide: 0.06em;

    /* Spacing: base 4, rhythm 8 */
    --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;
    --space-20: 5rem;

    /* Shape */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 999rem;
    --border-width: 1px;
    --focus-ring: 2px solid var(--color-focus);
    --focus-offset: 2px;
    /* Controls (buttons, inputs, header buttons) share one height: 44px, the touch minimum. */
    --control-height: 2.75rem;
    --control-height-sm: 2rem;

    /* Elevation: a shadow is never the only state signal; dark mode leans on the surface steps instead. */
    --shadow-1: light-dark(0 1px 2px rgb(15 23 42 / 0.06), 0 1px 2px rgb(0 0 0 / 0.4));
    --shadow-2: light-dark(0 4px 12px rgb(15 23 42 / 0.08), 0 4px 12px rgb(0 0 0 / 0.45));
    --shadow-3: light-dark(0 16px 40px rgb(15 23 42 / 0.16), 0 16px 40px rgb(0 0 0 / 0.6));

    /* Layout */
    /* The main area fills the window: no empty side bands on wide screens (Jorge, 2026-11-02). */
    --content-max: none;
    --content-narrow: 48rem;
    --nav-width: 16rem;

    /* Motion: only transform and opacity animate */
    --duration-fast: 120ms;
    --duration-base: 200ms;
    --duration-slow: 300ms;
    --ease-out: cubic-bezier(0.2, 0, 0, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

    /* Stacking */
    --z-sticky: 10;
    --z-drawer: 40;
    --z-popover: 45;
    --z-modal: 50;
    --z-toast: 60;
  }

  /* A page or a user setting forces one mode; the system preference decides otherwise. */
  :root[data-theme="light"] {
    color-scheme: light;
  }

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