/* ==========================================================================
   Design quality baseline: base layer
   Version 1.0, 24 Nov 2026

   Load order:
     1. baseline.css            (this file: never edited per project)
     2. brands/<project>.css    (the brand layer: colours, fonts, corners)
     3. the project's own CSS   (layout and one-off pieces, tokens only)

   Every value a component needs is a token. Components never use a raw
   colour, size, shadow or duration. Check the brand with:
     node check-contrast.mjs brands/<project>.css
   ========================================================================== */

@layer reset, tokens, base, components, utilities;

/* --------------------------------------------------------------------------
   1. Reset
   -------------------------------------------------------------------------- */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  img, picture, video, canvas, svg { display: block; max-width: 100%; height: auto; }
  input, button, textarea, select { font: inherit; color: inherit; }
  button { cursor: pointer; }
  p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }
  table { border-collapse: collapse; }
}

/* --------------------------------------------------------------------------
   2. Tokens that never change between projects.
      The brand layer supplies colour, fonts, corners and link style.
      Fallbacks below are the neutral template, so the page never breaks
      if a brand token is missing.
   -------------------------------------------------------------------------- */
@layer tokens {
  :root {
    /* Type scale (rem; 1rem = 16px). Fluid sizes shrink between 360px and 1280px. */
    --text-xs: 0.8125rem;                                   /* 13px: short bold labels and badges only */
    --text-sm: 0.9375rem;                                   /* 15px: captions, nav, eyebrows */
    --text-md: 1rem;                                        /* 16px: smallest running text, all inputs */
    --text-base: 1.125rem;                                  /* 18px: body */
    --text-lg: 1.25rem;                                     /* 20px: lead paragraph */
    --text-xl: clamp(1.25rem, 1.15rem + 0.45vw, 1.375rem);  /* 20 to 22px: card titles */
    --text-2xl: clamp(1.5rem, 1.3rem + 0.9vw, 1.75rem);     /* 24 to 28px: h3 */
    --text-3xl: clamp(1.875rem, 1.25rem + 2.75vw, 3.125rem);/* 30 to 50px: h2 */
    --text-4xl: clamp(2.375rem, 1.45rem + 4.1vw, 4.25rem);  /* 38 to 68px: h1 */
    --text-display: clamp(3.5rem, 1.6rem + 8.5vw, 7rem);    /* 56 to 112px: one statement per screen */

    --leading-tight: 1.08;   /* headings */
    --leading-snug: 1.3;     /* labels, buttons, short lines */
    --leading-body: 1.65;    /* reading text */
    --tracking-heading: -0.015em;
    --tracking-label: 0.08em;
    --measure: 65ch;         /* longest line of reading text */

    /* Spacing: a 4px grid. Use these steps only. */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;   /* the smallest inside padding of any container */
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;
    --space-9: 96px;
    --space-10: 128px;
    --gutter: clamp(16px, 4vw, 32px);     /* page side padding */
    --section: clamp(64px, 8vw, 110px);   /* space above and below a section */
    --max-width: 1240px;
    --inset: max(var(--space-4), 1rem);   /* minimum padding inside a box */

    /* Touch */
    --target: 44px;   /* minimum size of anything you tap */

    /* Corners (the brand picks values; nested corners use --radius-inner) */
    --radius-pill: 999px;

    /* Depth: one scale. A card is a surface + ring; shadow adds lift only. */
    --ring: 0 0 0 1px rgb(var(--shadow-rgb, 16 24 40) / 0.10);
    --shadow-1: 0 1px 2px rgb(var(--shadow-rgb, 16 24 40) / 0.06),
                0 1px 1px rgb(var(--shadow-rgb, 16 24 40) / 0.04);
    --shadow-2: 0 2px 4px rgb(var(--shadow-rgb, 16 24 40) / 0.06),
                0 10px 20px -6px rgb(var(--shadow-rgb, 16 24 40) / 0.12);
    --shadow-3: 0 4px 8px rgb(var(--shadow-rgb, 16 24 40) / 0.06),
                0 24px 48px -12px rgb(var(--shadow-rgb, 16 24 40) / 0.20);
    --text-depth: 0 1px 1px rgb(var(--shadow-rgb, 16 24 40) / 0.07);  /* faint lift for text in boxes */
    --text-depth-dark: 0 1px 2px rgb(0 0 0 / 0.30);                    /* text on dark grounds */

    /* Motion */
    --dur-fast: 120ms;   /* colour and opacity changes */
    --dur: 200ms;        /* most UI movement */
    --dur-slow: 320ms;   /* panels, page-level moves */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --press: 0.97;       /* scale on press */

    /* Layers */
    --z-raised: 10;
    --z-sticky: 100;
    --z-overlay: 200;
    --z-modal: 300;
    --z-toast: 400;

    /* Focus ring */
    --focus-width: 3px;
    --focus-offset: 2px;
  }
}

/* --------------------------------------------------------------------------
   3. Base elements
   -------------------------------------------------------------------------- */
@layer base {
  html {
    color-scheme: light;
    scroll-padding-top: var(--space-8);
  }
  body {
    min-height: 100vh;
    background: var(--bg, #FFFFFF);
    color: var(--text, #344054);
    font-family: var(--font-body, system-ui, sans-serif);
    font-size: var(--text-base);
    line-height: var(--leading-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-optical-sizing: auto;
  }

  h1, h2, h3, h4, h5, h6 {
    color: var(--heading, #101828);
    font-family: var(--font-heading, system-ui, sans-serif);
    font-weight: 700;
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-heading);
    text-wrap: balance;
  }
  h1 { font-size: var(--text-4xl); }
  h2 { font-size: var(--text-3xl); }
  h3 { font-size: var(--text-2xl); font-weight: 600; }
  h4 { font-size: var(--text-xl); font-weight: 600; }
  h5, h6 { font-size: var(--text-base); font-weight: 600; }

  p, li, dd, blockquote, figcaption { text-wrap: pretty; }
  p, li { max-width: var(--measure); }
  strong, b { font-weight: 600; }
  small { font-size: var(--text-sm); }

  /* Links: the brand sets whether they are underlined at rest.
     When they are not, links inside sentences must be semibold too,
     so colour is never the only signal (WCAG 1.4.1). */
  a {
    color: var(--accent-text, #1A5FCC);
    text-decoration-line: var(--link-decoration, underline);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    transition-property: color, text-decoration-color;
    transition-duration: var(--dur-fast);
    transition-timing-function: ease;
  }
  :where(p, li, td, dd, figcaption) a { font-weight: var(--link-inline-weight, inherit); }
  a:focus-visible, a:active { color: var(--heading, #101828); text-decoration-line: underline; }
  @media (hover: hover) {
    a:hover { color: var(--heading, #101828); text-decoration-line: underline; }
  }

  /* Focus: always visible, always the focus token, never the raw accent. */
  :focus-visible {
    outline: var(--focus-width) solid var(--focus, #101828);
    outline-offset: var(--focus-offset);
  }
  :focus:not(:focus-visible) { outline: none; } /* audit-ok: mouse focus only; keyboard focus keeps its ring */

  ::selection { background: var(--accent-wash, #EEF4FE); color: var(--heading, #101828); }

  hr { border: 0; border-top: 1px solid var(--line, #E4E7EC); }

  img, video { border-radius: var(--radius-media, 12px); }
  img { outline: 1px solid rgb(var(--shadow-rgb, 16 24 40) / 0.08); outline-offset: -1px; }

  /* Numbers that line up or change */
  table, .price, time, [data-tabular] { font-variant-numeric: tabular-nums; }

  /* Dark bands: one class swaps the colour roles, so components need no dark variants. */
  .on-dark {
    --bg: var(--dark-bg, #101828);
    --bg-alt: var(--dark-bg-deep, #0B111C);
    --surface: var(--dark-bg-deep, #0B111C);
    --heading: var(--dark-heading, #FFFFFF);
    --text: var(--dark-text, #E4E7EC);
    --text-muted: var(--dark-muted, #B3BAC5);
    --line: var(--dark-line, #344054);
    --line-strong: var(--dark-line-strong, #7D8796);
    --line-strong-alt: var(--dark-line-strong, #7D8796);
    --accent-text: var(--dark-accent-text, #8AB8FF);
    --focus: var(--dark-focus, #FFFFFF);
    --text-depth: var(--text-depth-dark);
    background: var(--bg);
    color: var(--text);
    color-scheme: dark;
  }
  .on-dark-deep { --bg: var(--dark-bg-deep, #0B111C); }

  /* The alternate ground: controls switch to the stronger border automatically. */
  .ground-alt { background: var(--bg-alt, #F4F6F8); --line-strong: var(--line-strong-alt, #7D8796); }
  .ground-wash { background: var(--accent-wash, #EEF4FE); --line-strong: var(--line-strong-alt, #7D8796); }
}

/* --------------------------------------------------------------------------
   4. Components
   -------------------------------------------------------------------------- */
@layer components {

  /* Skip link: first thing in <body> */
  .skip-link {
    position: absolute; left: var(--space-4); top: -100px; z-index: var(--z-toast);
    padding: var(--space-3) var(--space-4);
    background: var(--surface, #FFFFFF); color: var(--heading, #101828);
    font-weight: 600; box-shadow: var(--shadow-2);
  }
  .skip-link:focus { top: var(--space-4); }

  /* Layout */
  .container { width: min(100% - 2 * var(--gutter), var(--max-width)); margin-inline: auto; }
  .section { padding-block: var(--section); }
  .stack { display: flex; flex-direction: column; gap: var(--stack-gap, var(--space-4)); }
  .cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cluster-gap, var(--space-3)); }
  .grid { display: grid; gap: var(--grid-gap, var(--space-6)); grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--grid-min, 18rem)), 1fr)); }

  /* Text styles */
  .lead { font-size: var(--text-lg); color: var(--text); }
  .muted { color: var(--text-muted, #5D6675); }
  .eyebrow, .label {
    font-family: var(--font-body, system-ui, sans-serif);
    font-size: var(--text-xs); font-weight: 600; line-height: var(--leading-snug);
    letter-spacing: var(--tracking-label); text-transform: uppercase;
  }
  .eyebrow { font-size: var(--text-sm); letter-spacing: 0.1em; color: var(--accent-text); }
  .display {
    font-family: var(--font-heading, system-ui, sans-serif);
    font-size: var(--text-display); font-weight: 700; line-height: 0.9;
    letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
  }

  /* Buttons ------------------------------------------------------------- */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    min-height: var(--target); min-width: var(--target);
    padding: var(--space-3) var(--space-5);
    border: 1px solid transparent; border-radius: var(--radius-button, 6px);
    font-family: var(--font-heading, system-ui, sans-serif);
    font-size: var(--text-md); font-weight: 600; line-height: var(--leading-snug);
    text-decoration: none; text-align: center;
    -webkit-tap-highlight-color: transparent; touch-action: manipulation;
    transition-property: background-color, border-color, color, box-shadow, transform;
    transition-duration: var(--dur-fast), var(--dur-fast), var(--dur-fast), var(--dur), var(--dur);
    transition-timing-function: var(--ease-out);
  }
  .btn:active { transform: scale(var(--press)); }
  .btn--primary { background: var(--accent, #1F6FEB); color: var(--on-accent, #FFFFFF); }
  .btn--secondary { background: transparent; color: var(--heading, #101828); border-color: var(--line-strong, #8A94A3); }
  .btn--ghost { background: transparent; color: var(--accent-text, #1A5FCC); }
  @media (hover: hover) {
    .btn--primary:hover { box-shadow: var(--shadow-2); color: var(--on-accent, #FFFFFF); }
    .btn--secondary:hover { border-color: var(--heading, #101828); color: var(--heading, #101828); }
    .btn--ghost:hover { background: var(--accent-wash, #EEF4FE); color: var(--heading, #101828); }
  }
  .btn[aria-disabled="true"], .btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
  .btn[aria-busy="true"] { cursor: progress; }
  .btn[aria-busy="true"]::after {
    content: ""; width: 1em; height: 1em; border-radius: 50%;
    border: 2px solid currentColor; border-right-color: transparent;
    animation: baseline-spin 0.8s linear infinite;
  }
  @keyframes baseline-spin { to { transform: rotate(360deg); } }

  /* Icon-only button: always give it aria-label */
  .icon-btn {
    display: inline-grid; place-items: center;
    width: var(--target); height: var(--target);
    border: 1px solid transparent; border-radius: var(--radius-button, 6px);
    background: transparent; color: var(--heading, #101828);
    transition-property: background-color, transform; transition-duration: var(--dur-fast);
  }
  .icon-btn svg { width: 20px; height: 20px; }
  .icon-btn:active { transform: scale(var(--press)); }
  @media (hover: hover) { .icon-btn:hover { background: var(--bg-alt, #F4F6F8); } }

  /* Cards ---------------------------------------------------------------
     A card stands off its ground by surface colour and a 1px ring.
     Put cards on the alternate ground where you can. One card style per page. */
  .card {
    --card-pad: clamp(var(--space-4), 3vw, var(--space-5));
    --radius-inner: max(0px, calc(var(--radius-card, 8px) - var(--card-pad)));
    position: relative;
    display: flex; flex-direction: column; gap: var(--space-3);
    padding: var(--card-pad);
    background: var(--surface, #FFFFFF);
    border-radius: var(--radius-card, 8px);
    box-shadow: var(--ring), var(--shadow-1);
    color: var(--text);
    text-shadow: var(--text-depth);
  }
  .card > img, .card > picture img { border-radius: var(--radius-inner); }
  .card h3, .card h4 { font-size: var(--text-xl); font-weight: 600; }
  .card--accent { box-shadow: inset 3px 0 0 var(--accent, #1F6FEB), var(--ring), var(--shadow-1); }
  /* A whole-card link: put the link on the title and stretch it */
  .card--link a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
  .card--link a:focus-visible { outline: none; } /* audit-ok: the whole card shows the ring instead */
  .card--link:has(a:focus-visible) { outline: var(--focus-width) solid var(--focus, #101828); outline-offset: var(--focus-offset); }
  @media (hover: hover) and (prefers-reduced-motion: no-preference) {
    .card--link { transition-property: transform, box-shadow; transition-duration: var(--dur); transition-timing-function: var(--ease-out); }
    .card--link:hover { transform: translateY(-2px); box-shadow: var(--ring), var(--shadow-2); }
  }
  .card--link:active { transform: scale(0.99); }

  /* Pills: chips, status, counters. Never at a container's edge. -------- */
  .pill {
    position: relative;
    display: inline-flex; align-items: center; gap: var(--space-1);
    min-height: 28px; padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-pill);
    background: var(--bg-alt, #F4F6F8); color: var(--heading, #101828);
    font-size: var(--text-xs); font-weight: 600; line-height: 1.2; white-space: nowrap;
  }
  /* Tappable pills keep a 44px hit area without looking bigger */
  button.pill, a.pill { border: 0; text-decoration: none; }
  button.pill::before, a.pill::before { content: ""; position: absolute; inset: -8px -4px; }
  .pill--success { background: var(--success-wash); color: var(--success); }
  .pill--info { background: var(--info-wash); color: var(--info); }
  .pill--warning { background: var(--warning-wash); color: var(--warning); }
  .pill--danger { background: var(--danger-wash); color: var(--danger); }

  /* Forms ----------------------------------------------------------------
     Label above, hint under the label, error under the field.
     Inputs are 16px or larger so phones never zoom in. */
  .field { display: flex; flex-direction: column; gap: var(--space-2); max-width: 36rem; }
  .field > label, .field > legend { font-weight: 600; color: var(--heading, #101828); font-size: var(--text-md); }
  .field .hint { font-size: var(--text-sm); color: var(--text-muted, #5D6675); }
  .input, .field input:not([type="checkbox"], [type="radio"]), .field select, .field textarea {
    width: 100%; min-height: var(--target);
    padding: var(--space-2) var(--space-3);
    background: var(--surface, #FFFFFF); color: var(--heading, #101828);
    border: 1px solid var(--line-strong, #8A94A3); border-radius: var(--radius-button, 6px);
    font-size: max(16px, var(--text-md)); line-height: var(--leading-snug);
    transition-property: border-color, box-shadow; transition-duration: var(--dur-fast);
  }
  .field textarea { min-height: 7.5rem; resize: vertical; }
  .field ::placeholder { color: var(--text-muted, #5D6675); opacity: 1; }
  .field :is(input, select, textarea):focus-visible {
    outline: var(--focus-width) solid var(--focus, #101828); outline-offset: 0;
    border-color: var(--focus, #101828);
  }
  .field [aria-invalid="true"] { border-color: var(--danger, #B42318); border-width: 2px; }
  .field .error { display: flex; gap: var(--space-2); align-items: baseline; color: var(--danger, #B42318); font-size: var(--text-sm); font-weight: 600; }
  .field .error::before { content: "!"; display: inline-grid; place-items: center; flex: none; width: 1.2em; height: 1.2em; border-radius: 50%; background: var(--danger, #B42318); color: var(--surface, #FFFFFF); font-size: 0.75em; }
  .check { display: flex; align-items: center; gap: var(--space-3); min-height: var(--target); cursor: pointer; }
  .check input { width: 20px; height: 20px; flex: none; accent-color: var(--accent-text, #1A5FCC); }

  /* Notices: a 3px line down the left edge, never across the top */
  .notice {
    padding: var(--space-4) var(--space-5);
    background: var(--info-wash); color: var(--text);
    box-shadow: inset 3px 0 0 var(--info);
    border-radius: var(--radius-card, 8px);
  }
  .notice strong { color: var(--heading); }
  .notice--success { background: var(--success-wash); box-shadow: inset 3px 0 0 var(--success); }
  .notice--warning { background: var(--warning-wash); box-shadow: inset 3px 0 0 var(--warning); }
  .notice--danger  { background: var(--danger-wash);  box-shadow: inset 3px 0 0 var(--danger); }

  /* Tables */
  .table { width: 100%; font-size: var(--text-md); }
  .table th, .table td { padding: var(--space-3) var(--space-4); text-align: left; border-bottom: 1px solid var(--line, #E4E7EC); vertical-align: top; }
  .table th { color: var(--heading); font-weight: 600; }
  .table-wrap { overflow-x: auto; }   /* tables scroll inside their box, never the page */

  /* Motion with a pause button (anything that moves for more than 5 seconds) */
  [data-paused="true"] * { animation-play-state: paused !important; }
}

/* --------------------------------------------------------------------------
   5. Utilities
   -------------------------------------------------------------------------- */
@layer utilities {
  .visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .tabular { font-variant-numeric: tabular-nums; }
  .balance { text-wrap: balance; }
}

/* --------------------------------------------------------------------------
   6. User settings: these always win
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .btn:active, .icon-btn:active, .card--link:active { transform: none; }
}

@media (prefers-contrast: more) {
  :root { --line: var(--line-strong); --text-muted: var(--text); --line-strong: var(--text); --line-strong-alt: var(--text); }
  .card { box-shadow: 0 0 0 1px var(--line-strong); text-shadow: none; }
}

@media (prefers-reduced-transparency: reduce) {
  [data-glass] { backdrop-filter: none !important; background: var(--surface) !important; }
}

@media (forced-colors: active) {
  :focus-visible { outline-color: Highlight; }
  .btn, .icon-btn, .pill, .card, .notice { border: 1px solid CanvasText; }
  .field .error::before { forced-color-adjust: none; }
}

@media print {
  .on-dark { --bg: #FFFFFF; --text: #000000; --heading: #000000; background: #FFFFFF; color: #000000; } /* audit-ok: print */
  .skip-link, [data-no-print] { display: none !important; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.85em; }
  .card { box-shadow: none; border: 1px solid #000000; break-inside: avoid; } /* audit-ok: print */
}
