/* Flip Screener design tokens: the ONLY file with colour, font and shadow literals
   (tests/test_design_system.py refuses them in every other style sheet).

   The look follows shadcn/ui (SPEC "Design decisions of 24 Nov 2026", the point of 26 Nov 2026;
   mapping and licences in docs/design/shadcn-mapping.md). Three tiers:
     1. THEME   shadcn's variable names and roles (--background, --foreground, --primary, --muted,
                --border, --input, --ring, --radius …) with the slate neutral base, one brand primary
                (the navy of the brand sheet) and our semantic families (success / caution / danger /
                info). A dark theme later redefines ONLY this tier (light only today: SPEC, no dark mode).
     2. ROLES   the --color-… names every rule uses (unchanged since the first design system, so the
                pages keep working); each is a var() of the theme tier.
     3. SCALES  type, space, shape, shadow, icons, layout.
   Contrast (WCAG AA, sRGB relative luminance): text 4.5:1 on its background, input borders and the
   focus ring 3:1 against white; the value stands beside each colour.

   Loaded first by base.html. Its first line fixes the order of the cascade layers, so a rule in
   a later layer wins over an earlier one however specific its selector is:
     tokens -> base (elements) -> legacy (kept empty: for an old sheet while pages move) -> components
     (one section per macro of _components.html / _forms.html) -> pages (page grids only) ->
     utilities -> print
   Templates and components use the ROLE tokens (--color-…), never the theme tier directly.
   Colour means judgement: success / caution / danger only for verdicts, warning tiers and form
   errors; work states (case status, document and quote states) are neutral. */

@layer tokens, base, legacy, components, pages, utilities, print;

/* Inter 4.1 (SIL OFL 1.1), self-hosted in static/fonts/ with its licence (SECURITY.md "Copied
   files"). One variable file for every weight; numbers in tabular figures (font-variant-numeric). */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../fonts/InterVariable-4.1.woff2") format("woff2");
}

@layer tokens {
  :root {
    color-scheme: light; /* no dark mode: the browser must not darken form controls */

    /* ================================================================ 1. THEME (shadcn names) */
    --radius: 0.625rem;                 /* 10 px; sm / md / lg / xl derive from it as in shadcn */
    --background: #ffffff;
    --foreground: #020817;              /* slate-950: 20.0:1 on white */
    --card: #ffffff;
    --card-foreground: #020817;
    --popover: #ffffff;
    --popover-foreground: #020817;
    --primary: #1e3a5c;                 /* the ONE brand colour (navy of the brand sheet): 11.6:1 on white */
    --primary-foreground: #f8fafc;      /* 11.1:1 on primary */
    --secondary: #f1f5f9;               /* slate-100 */
    --secondary-foreground: #0f172a;
    --muted: #f1f5f9;
    --muted-foreground: #5b6b80;        /* slate-500, darkened: 5.4:1 on white, 5.0:1 on muted (AA) */
    --accent: #f1f5f9;
    --accent-foreground: #0f172a;
    --destructive: #b91c1c;             /* red-700: 6.5:1 on white */
    --border: #e2e8f0;                  /* slate-200: dividers and card edges (decoration) */
    --border-strong: #cbd5e1;           /* slate-300 */
    --input: #8391a6;                   /* field borders 3.2:1 on white (WCAG 1.4.11; shadcn's is lighter) */
    --ring: #3a6ea5;                    /* focus ring 5.3:1 on white */
    --brand-tint: #eef2f7;              /* selected option, focus column, "someone must act" */
    --chart-1: #1e3a5c;
    --chart-2: #3a6ea5;
    --chart-3: #7c9cc4;
    --chart-4: #047857;
    --chart-5: #b45309;

    /* semantic families (ours; shadcn has only destructive): text / tint / border / solid */
    --success: #047857;        --success-tint: #ecfdf5; --success-border: #a7f3d0; /* 5.2:1 on its tint */
    --caution: #b45309;        --caution-tint: #fffbeb; --caution-border: #fcd34d; --caution-solid: #f59e0b; /* 4.8:1 */
    --danger: #b91c1c;         --danger-tint: #fef2f2;  --danger-border: #fecaca;  /* 5.9:1 on its tint */
    --info: #475569;           --info-tint: #f8fafc;    --info-border: #cbd5e1;    /* info is neutral */
    --neutral: #334155;        /* neutral badge text, 9.5:1 on muted */

    /* ================================================================ 2. ROLES (used by every rule) */
    --color-bg: var(--background);
    --color-surface: var(--card);
    --color-surface-sunken: color-mix(in srgb, var(--muted) 60%, var(--background)); /* table head, read-only field */
    --color-surface-muted: var(--muted);
    --color-popover: var(--popover);
    --color-border: var(--border);
    --color-border-strong: var(--border-strong);
    --color-field-border: var(--input);
    --color-field-border-hover: var(--muted-foreground);
    --color-text: var(--foreground);
    --color-text-muted: var(--muted-foreground);
    --color-text-inverse: var(--primary-foreground);
    --color-text-inverse-muted: color-mix(in srgb, var(--primary-foreground) 80%, transparent);
    --color-inverse-hover: color-mix(in srgb, var(--primary-foreground) 10%, transparent);
    --color-inverse-current: color-mix(in srgb, var(--primary-foreground) 16%, transparent);
    --color-link: var(--primary);
    --color-primary: var(--primary);
    --color-primary-hover: color-mix(in srgb, var(--primary) 90%, var(--background)); /* shadcn: primary/90 */
    --color-primary-active: var(--primary);
    --color-on-primary: var(--primary-foreground);
    --color-secondary: var(--secondary);
    --color-on-secondary: var(--secondary-foreground);
    --color-accent: var(--accent);               /* hover of an outline or ghost button, a menu row */
    --color-on-accent: var(--accent-foreground);
    --color-brand: var(--primary);
    --color-brand-tint: var(--brand-tint);
    --color-focus: var(--ring);

    --color-success-text: var(--success);
    --color-success-bg: var(--success-tint);
    --color-success-border: var(--success-border);
    --color-success-solid: var(--success);
    --color-caution-text: var(--caution);
    --color-caution-bg: var(--caution-tint);
    --color-caution-border: var(--caution-border);
    --color-caution-solid: var(--caution-solid);
    --color-danger-text: var(--danger);
    --color-danger-bg: var(--danger-tint);
    --color-danger-border: var(--danger-border);
    --color-danger-solid: var(--destructive); /* also negative numbers in tables (6.2:1 on the table head) */
    --color-info-text: var(--info);
    --color-info-bg: var(--info-tint);
    --color-info-border: var(--info-border);
    --color-info-solid: var(--info);
    --color-neutral-text: var(--neutral);
    --color-neutral-bg: var(--secondary);
    --color-neutral-border: var(--border);
    --color-action-text: var(--primary); /* "someone must act": brand tint, not a judgement */
    --color-action-bg: var(--brand-tint);

    /* ================================================================ 3. SCALES */
    /* ---------------------------------------------------------------- type */
    --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --font-numeric: tabular-nums lining-nums; /* font-variant-numeric of every number */

    --text-xs: 0.75rem;   /* 12 px: badges, footnotes */
    --text-sm: 0.875rem;  /* 14 px: the UI size of shadcn (body, tables, buttons, labels) */
    --text-md: 1rem;      /* 16 px: inputs on a phone (iOS zooms below), card titles */
    --text-lg: 1.125rem;  /* 18 px: h3 */
    --text-xl: 1.25rem;   /* 20 px: h2 */
    --text-2xl: 1.5rem;   /* 24 px: h1, key figures */
    --text-3xl: 1.875rem; /* 30 px */

    --leading-tight: 1.2;
    --leading-snug: 1.4;
    --leading-body: 1.5;
    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;
    --tracking-tight: -0.015em; /* headings (shadcn: tracking-tight) */
    --tracking-caps: 0.04em;
    --measure: 68ch;

    /* ---------------------------------------------------------------- space (4-px grid) */
    --space-1: 0.25rem; /*  4 */
    --space-2: 0.5rem;  /*  8 */
    --space-3: 0.75rem; /* 12 */
    --space-4: 1rem;    /* 16 */
    --space-5: 1.5rem;  /* 24 */
    --space-6: 2rem;    /* 32 */
    --space-7: 3rem;    /* 48 */
    --space-8: 4rem;    /* 64 */

    /* ---------------------------------------------------------------- shape (shadcn radius scale) */
    --radius-sm: calc(var(--radius) - 4px);  /*  6 px: checkboxes, small chips */
    --radius-md: calc(var(--radius) - 2px);  /*  8 px: buttons, fields, tabs */
    --radius-lg: var(--radius);              /* 10 px: alerts, tables, menus */
    --radius-xl: calc(var(--radius) + 4px);  /* 14 px: cards */
    --radius-pill: 999px;                    /* badges */
    --border-thin: 1px;
    --border-thick: 2px;
    --border-accent: 4px;
    --shadow-xs: 0 1px 2px 0 color-mix(in srgb, #000000 5%, transparent);
    --shadow-sm: 0 1px 3px 0 color-mix(in srgb, #000000 10%, transparent), 0 1px 2px -1px color-mix(in srgb, #000000 10%, transparent);
    --shadow-md: 0 4px 6px -1px color-mix(in srgb, #000000 10%, transparent), 0 2px 4px -2px color-mix(in srgb, #000000 10%, transparent);
    --shadow-1: var(--shadow-xs); /* the first names, same roles */
    --shadow-2: var(--shadow-md);

    /* ---------------------------------------------------------------- icons (lucide, static/icons/) */
    /* drawn as a CSS mask in currentColor: no markup, no data: address (SECURITY rule 4, CSP img-src 'self') */
    --icon-chevron-down: url("../icons/chevron-down.svg");
    --icon-chevron-right: url("../icons/chevron-right.svg");
    --icon-check: url("../icons/check.svg");
    --icon-x: url("../icons/x.svg");
    --icon-triangle-alert: url("../icons/triangle-alert.svg");
    --icon-info: url("../icons/info.svg");
    --icon-circle-check: url("../icons/circle-check.svg");
    --icon-circle-x: url("../icons/circle-x.svg");
    --icon-circle-minus: url("../icons/circle-minus.svg");
    --icon-contrast: url("../icons/contrast.svg");
    --icon-diamond: url("../icons/diamond.svg");
    --icon-arrow-up-right: url("../icons/arrow-up-right.svg");
    --icon-plus: url("../icons/plus.svg");
    --icon-printer: url("../icons/printer.svg");
    --icon-menu: url("../icons/menu.svg");

    /* ---------------------------------------------------------------- layout */
    --page-max: 75rem;  /* 1200 px */
    --form-max: 45rem;  /*  720 px */
    --narrow-max: 32rem;
    --page-pad: var(--space-5);
    --page-pad-sm: var(--space-4);
    --control-height: 2.25rem;    /* 36 px: shadcn h-9 (buttons and fields) */
    --control-height-sm: 2rem;    /* 32 px: h-8 */
    --control-height-lg: 2.5rem;  /* 40 px: h-10 */
    --topbar-height: 3.5rem;
    --mark-size: 1.5rem;
    /* the focus ring: 2 px of the page's background, then 2 px of the ring colour at full strength
       (5.3:1 on white, WCAG 2.4.7 / 1.4.11; review of 26 Nov 2026: shadcn's soft 35 % ring gave 1.6:1).
       Every rule that sets `outline: none` draws this instead (tests/test_design_system.py). */
    --focus-ring: 0 0 0 2px var(--color-bg), 0 0 0 4px var(--color-focus);
    --focus-ring-danger: 0 0 0 2px var(--color-bg), 0 0 0 4px var(--color-danger-solid);
    /* breakpoints cannot be custom properties in @media: the two in use are 40rem and 64rem */
  }
  /* a touch screen: every control 40 px high (shadcn h-10), so a finger hits it */
  @media (pointer: coarse) {
    :root { --control-height: 2.5rem; --control-height-sm: 2.25rem; }
  }
}

@layer print {
  @media print {
    :root {
      /* paper: black on white, no tints; meaning stays in the badge icons and words */
      --color-bg: #fff;
      --color-surface: #fff;
      --color-surface-sunken: #fff;
      --color-surface-muted: #fff;
      --color-text: #000;
      --color-text-muted: #333;
      --color-border: #999;
      --color-border-strong: #000;
      --color-link: #000;
      --color-primary: #000;
      --color-brand-tint: #fff;
      --color-success-text: #000; --color-success-bg: #fff; --color-success-border: #000; --color-success-solid: #000;
      --color-caution-text: #000; --color-caution-bg: #fff; --color-caution-border: #000; --color-caution-solid: #000;
      --color-danger-text: #000;  --color-danger-bg: #fff;  --color-danger-border: #000;  --color-danger-solid: #000;
      --color-info-text: #333;    --color-info-bg: #fff;    --color-info-border: #000;    --color-info-solid: #333;
      --color-neutral-text: #000; --color-neutral-bg: #fff; --color-neutral-border: #000;
      --color-action-text: #000;  --color-action-bg: #fff;
      --shadow-xs: none;
      --shadow-sm: none;
      --shadow-md: none;
    }
  }
}
