/* ==========================================================================
   Quiet Utility - design-system.css
   Version 1.3.0

   One zero-dependency stylesheet for dashboards, workbenches, family command
   centers, media utilities, and printable documents.

   Usage
     <link rel="stylesheet" href="design-system.css">
     or inline the file contents into a <style> block (Python generators).

   Cascade layers
     @layer reset, tokens, base, components, utilities;
     Any unlayered project CSS loaded after this file overrides cleanly.

   Theme switches (set on <html> or any container)
     (none)                  Follows the OS: light or dark.
     data-theme="light"      Forces light.
     data-theme="dark"       Forces dark.
     data-surface="media"    Dark-default, true-neutral surface for photo and
                             media tools. Combine with data-theme="light" to
                             opt back into light.
   Print always renders crisp light paper, regardless of theme.

   Contents
     1.  Tokens - non-color (type, space, layout, radii, motion)
     2.  Tokens - color: light (default)
     3.  Tokens - color: dark (OS preference and explicit)
     4.  Tokens - color: media surface (dark default, true neutral)
     5.  Reset and base typography
     6.  Layout primitives
     7.  Page header and meta
     8.  Zones and section headings
     9.  Summary: lede, KPI strip, and callouts
     10. Quick actions and checklists
     11. Buttons
     12. Badges and status dots
     13. Tabs
     14. Disclosures
     15. Data tables
     16. Filter bar and form controls
     17. Item lists (triage rows)
     18. Empty, stale, and loading states
     19. Meters, bar lists, and sparklines
     20. Dialogs, panels, and footer
     21. Prose (rendered Markdown)
     22. Utilities
     23. Forced Colors Mode and reduced motion
     24. Print and PDF (US Letter)

   Copy rules for everything built on this file: simple dashes only (never
   em dashes), and always the Oxford comma.
   ========================================================================== */

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


/* ==========================================================================
   1-4. Tokens (non-color, light, dark, and media surface)
   ========================================================================== */

@layer tokens {
  :root {
    /* Automatically adapt native UI (scrollbars, form controls, canvas) to
       the OS preference by default. Explicit themes override below. */
    color-scheme: light dark;

    /* Type families. System faces first so every file renders refined offline
       and from file:// with zero network requests. */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans",
      "Helvetica Neue", "DejaVu Sans", Arial, sans-serif;
    --font-display: "Iowan Old Style", "Charter", "Bitstream Charter",
      "Sitka Text", Cambria, "Noto Serif", "DejaVu Serif", Georgia, serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono",
      Menlo, Consolas, "Liberation Mono", monospace;

    /* Type scale (rem). Base is 16px on screen; print rescales the root. */
    --fs-xs: 0.75rem;     /* 12 - labels, table headers, badges */
    --fs-sm: 0.875rem;    /* 14 - meta, tables, buttons, inputs (fine pointer) */
    --fs-md: 1rem;        /* 16 - body */
    --fs-lg: 1.125rem;    /* 18 - summary lede, h3 */
    --fs-xl: 1.375rem;    /* 22 - section titles (h2) */
    --fs-2xl: 1.75rem;    /* 28 - page title (phone), KPI values */
    --fs-3xl: 2.25rem;    /* 36 - page title (desktop) */

    --lh-tight: 1.2;
    --lh-snug: 1.35;
    --lh-body: 1.6;

    --fw-regular: 400;
    --fw-medium: 500;
    --fw-semibold: 600;

    --tracking-tight: -0.012em;
    --tracking-label: 0.06em;

    /* Spacing scale (4px base). */
    --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 */
    --space-9: 6rem;      /* 96 */

    /* Layout. Breakpoints (used literally in media queries):
       40em = 640px (tablet), 60em = 960px (desktop), 80em = 1280px (wide). */
    --container: 72rem;        /* 1152px - dashboards, documents */
    --container-wide: 90rem;   /* 1440px - workbenches, media tools */
    --measure: 42rem;          /* 672px - prose and summary ledes */
    --gutter: 1rem;            /* page inline padding, grows with viewport */
    --zone-gap: 2rem;          /* vertical gap between anatomy zones */

    /* Controls. 44px on touch; tightened to 36px for fine pointers below. */
    --control-h: 2.75rem;
    --control-h-sm: 2.25rem;
    --control-fs: 1rem;        /* 16px avoids iOS focus zoom on inputs */

    /* Radii, hairlines, and elevation. */
    --radius-xs: 0.25rem;      /* 4 - focus rings, small tags */
    --radius-sm: 0.375rem;     /* 6 - buttons, inputs */
    --radius-md: 0.625rem;     /* 10 - panels, callouts, empty states */
    --radius-lg: 1rem;         /* 16 - media cards, sheets */
    --radius-pill: 999px;      /* badges, meters */
    --hairline-w: 1px;

    /* Motion. */
    --dur-fast: 120ms;
    --dur: 180ms;
    --ease: cubic-bezier(0.2, 0, 0, 1);
  }

  @media (min-width: 40em) {
    :root {
      --gutter: 1.5rem;
    }
  }

  @media (min-width: 60em) {
    :root {
      --gutter: 2rem;
      --zone-gap: 3rem;
    }
  }

  @media (pointer: fine) and (min-width: 40em) {
    :root {
      --control-h: 2.25rem;
      --control-h-sm: 1.875rem;
      --control-fs: 0.875rem;
    }
  }

  /* 2. Color: light (default palette; :root keeps color-scheme: light dark) */
  :root,
  [data-theme="light"] {
    --bg: #FAF9F7;
    --surface: #FFFFFF;
    --surface-subtle: #F3F2EE;
    --surface-raised: #FFFFFF;
    --row-hover: #F6F5F2;

    --hairline: #E8E6E1;
    --border: #D9D6CF;
    --border-strong: #B9B5AC;
    --control-border: #8B877E; /* >= 3:1 WCAG 1.4.11 on --surface and --bg */

    --text: #1C1B19;
    --text-secondary: #4E4B46;
    --text-muted: #6B6760;

    --accent: #0E6178;
    --accent-hover: #0A4F62;
    --accent-soft: #E3EFF2;
    --accent-text: #0C5A70;
    --text-on-accent: #FFFFFF;

    --ok: #2A7448;
    --ok-soft: #E7F2EA;
    --warn: #8F5B00;
    --warn-soft: #F8EDD9;
    --bad: #B3322A;
    --bad-soft: #F8E6E3;
    --info: #4A5D78;
    --info-soft: #EBEFF4;

    --focus: #0E6178;
    --selection: rgba(14, 97, 120, 0.16);
    --scrollbar-thumb: #7D7970; /* >= 3:1 WCAG 1.4.11 on track and bg */
    --scrollbar-track: #F3F2EE;
    --shadow-pop: 0 10px 30px -12px rgba(28, 27, 25, 0.18),
      0 1px 2px rgba(28, 27, 25, 0.06);
  }

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

  /* 3. Color: dark (OS preference and explicit override; keep identical) */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      color-scheme: dark;

      --bg: #131312;
      --surface: #1B1B19;
      --surface-subtle: #242422;
      --surface-raised: #20201E;
      --row-hover: #1F1F1D;

      --hairline: #2A2927;
      --border: #383733;
      --border-strong: #55534E;
      --control-border: #6A6861; /* >= 3:1 WCAG 1.4.11 on --surface and --bg */

      --text: #ECEAE6;
      --text-secondary: #BDB9B2;
      --text-muted: #96928A;

      --accent: #6CB8CC;
      --accent-hover: #8CCAD9;
      --accent-soft: rgba(108, 184, 204, 0.14);
      --accent-text: #7FC3D5;
      --text-on-accent: #0B2229;

      --ok: #6FC28E;
      --ok-soft: rgba(111, 194, 142, 0.14);
      --warn: #E3B456;
      --warn-soft: rgba(227, 180, 86, 0.14);
      --bad: #F08A7E;
      --bad-soft: rgba(240, 138, 126, 0.14);
      --info: #A3B4CC;
      --info-soft: rgba(163, 180, 204, 0.14);

      --focus: #7FC3D5;
      --selection: rgba(108, 184, 204, 0.28);
      --scrollbar-thumb: #6D6B64; /* >= 3:1 WCAG 1.4.11 on track and surface */
      --scrollbar-track: #131312;
      --shadow-pop: 0 12px 32px -12px rgba(0, 0, 0, 0.6);
    }
  }

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

    --bg: #131312;
    --surface: #1B1B19;
    --surface-subtle: #242422;
    --surface-raised: #20201E;
    --row-hover: #1F1F1D;

    --hairline: #2A2927;
    --border: #383733;
    --border-strong: #55534E;
    --control-border: #6A6861;

    --text: #ECEAE6;
    --text-secondary: #BDB9B2;
    --text-muted: #96928A;

    --accent: #6CB8CC;
    --accent-hover: #8CCAD9;
    --accent-soft: rgba(108, 184, 204, 0.14);
    --accent-text: #7FC3D5;
    --text-on-accent: #0B2229;

    --ok: #6FC28E;
    --ok-soft: rgba(111, 194, 142, 0.14);
    --warn: #E3B456;
    --warn-soft: rgba(227, 180, 86, 0.14);
    --bad: #F08A7E;
    --bad-soft: rgba(240, 138, 126, 0.14);
    --info: #A3B4CC;
    --info-soft: rgba(163, 180, 204, 0.14);

    --focus: #7FC3D5;
    --selection: rgba(108, 184, 204, 0.28);
    --scrollbar-thumb: #6D6B64;
    --scrollbar-track: #131312;
    --shadow-pop: 0 12px 32px -12px rgba(0, 0, 0, 0.6);
  }

  /* 4. Color: media surface (dark default, true neutral).
     Zero warm or cool cast so photos are judged against honest grays.
     Add data-theme="light" to the same element to opt back into light. */
  [data-surface="media"]:not([data-theme="light"]) {
    color-scheme: only dark;

    --bg: #0B0B0B;
    --surface: #141414;
    --surface-subtle: #1F1F1F;
    --surface-raised: #1A1A1A;
    --row-hover: #1A1A1A;

    --hairline: #242424;
    --border: #333333;
    --border-strong: #525252;
    --control-border: #666666;

    --text: #EDEDED;
    --text-secondary: #B5B5B5;
    --text-muted: #8F8F8F;

    --accent: #6CB8CC;
    --accent-hover: #8CCAD9;
    --accent-soft: rgba(108, 184, 204, 0.14);
    --accent-text: #7FC3D5;
    --text-on-accent: #0B2229;

    --ok: #6FC28E;
    --ok-soft: rgba(111, 194, 142, 0.14);
    --warn: #E3B456;
    --warn-soft: rgba(227, 180, 86, 0.14);
    --bad: #F08A7E;
    --bad-soft: rgba(240, 138, 126, 0.14);
    --info: #A3B4CC;
    --info-soft: rgba(163, 180, 204, 0.14);

    --focus: #7FC3D5;
    --selection: rgba(108, 184, 204, 0.28);
    --scrollbar-thumb: #6B6B6B;
    --scrollbar-track: #0B0B0B;
    --shadow-pop: 0 12px 32px -12px rgba(0, 0, 0, 0.7);
  }

  /* Any element that switches theme paints its own background and re-binds
     inherited browser-UI color properties. */
  [data-theme],
  [data-surface] {
    background-color: var(--bg);
    color: var(--text);
    accent-color: var(--accent);
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  }
}


/* ==========================================================================
   5. Reset and base typography
   ========================================================================== */

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  h1, h2, h3, h4, h5, h6,
  p, ul, ol, dl, dd, figure, blockquote, pre {
    margin: 0;
  }
}

@layer base {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    accent-color: var(--accent);
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  }

  /* Keep focused elements clear of optional sticky bars (WCAG 2.4.11). */
  html:has(.page-header--sticky) {
    scroll-padding-top: 5.5rem;
  }

  @media (max-width: 39.99em) {
    html:has(.actions--sticky) {
      scroll-padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
    }
  }

  body {
    margin: 0;
    min-height: 100vh;
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--fs-md);
    line-height: var(--lh-body);
    overflow-wrap: break-word;
    font-kerning: normal;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  h1, h2, h3, h4, h5, h6 {
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
    text-wrap: balance;
  }

  p {
    text-wrap: pretty;
  }

  img, svg, video, canvas, picture {
    display: block;
    max-width: 100%;
  }

  img, video {
    height: auto;
  }

  button, input, select, textarea {
    font: inherit;
    color: inherit;
    letter-spacing: inherit;
  }

  table {
    border-collapse: collapse;
    width: 100%;
  }

  hr {
    height: 0;
    margin: var(--space-6) 0;
    border: 0;
    border-top: var(--hairline-w) solid var(--hairline);
  }

  a {
    color: var(--accent-text);
    text-decoration-line: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
  }

  a:hover {
    text-decoration-thickness: 2px;
  }

  :where(a, code) {
    overflow-wrap: anywhere;
  }

  code, kbd, samp, pre {
    font-family: var(--font-mono);
    font-size: 0.9em;
  }

  code {
    padding: 0.1em 0.35em;
    border-radius: var(--radius-xs);
    background: var(--surface-subtle);
  }

  strong, b {
    font-weight: var(--fw-semibold);
  }

  small {
    font-size: var(--fs-sm);
  }

  ::selection {
    background: var(--selection);
  }

  /* Leave hidden="until-found" intact so Find-in-Page can reveal panels. */
  [hidden]:not([hidden="until-found"]) {
    display: none !important;
  }

  :focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
  }

  input[type="checkbox"],
  input[type="radio"] {
    width: 1.125rem;
    height: 1.125rem;
    margin: 0;
    accent-color: var(--accent);
    flex: none;
  }
}


/* ==========================================================================
   6-21. Components and layout primitives
   ========================================================================== */

@layer components {
  /* 6. Layout primitives */
  .page {
    width: 100%;
    max-width: var(--container);
    margin-inline: auto;
    padding: var(--space-5) var(--gutter) var(--space-8);
  }

  .page--wide { max-width: var(--container-wide); }
  .page--narrow { max-width: calc(var(--measure) + 2 * var(--gutter)); }

  .stack {
    display: flex;
    flex-direction: column;
    gap: var(--gap, var(--space-4));
  }

  .cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--gap, var(--space-3));
  }

  .split {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
  }

  .grid-auto {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    grid-template-columns: repeat(auto-fit, minmax(min(var(--min, 16rem), 100%), 1fr));
    gap: var(--gap, var(--space-5));
  }

  .flow > * + * {
    margin-top: var(--flow-space, 1em);
  }

  .skip-link {
    position: fixed;
    top: var(--space-2);
    left: var(--space-2);
    z-index: 100;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--text-on-accent);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    text-decoration: none;
    transform: translateY(-200%);
  }

  .skip-link:focus {
    transform: none;
  }

  /* 7. Page header and meta */
  .page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4) var(--space-5);
    padding-bottom: var(--space-5);
    border-bottom: var(--hairline-w) solid var(--hairline);
  }

  .page-header__main {
    min-width: 0;
    flex: 1 1 20rem;
  }

  .eyebrow {
    margin-bottom: var(--space-2);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
  }

  .page-header__title {
    font-family: var(--font-display);
    font-size: var(--fs-2xl);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
    letter-spacing: var(--tracking-tight);
    string-set: doc-title content();
  }

  @media (min-width: 60em) {
    .page-header__title { font-size: var(--fs-3xl); }
  }

  .meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-3);
    margin-top: var(--space-3);
    padding: 0;
    list-style: none;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
  }

  .meta > li:not(:last-child)::after {
    /* Fallback for browsers without `/` alt text syntax, then silence for AT. */
    content: "\00B7";
    content: "\00B7" / "";
    margin-inline-start: var(--space-3);
    color: var(--border-strong);
  }

  .page-header__tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  /* Optional: pin the header for long workbenches. */
  .page-header--sticky {
    position: sticky;
    top: 0;
    z-index: 20;
    padding-top: var(--space-3);
    background: var(--bg);
  }

  /* 8. Zones and section headings
     Canonical order: header -> summary -> actions -> detail. */
  .zone {
    margin-top: var(--zone-gap);
  }

  .page-header + .zone {
    margin-top: var(--space-5);
  }

  .zone-title {
    margin-bottom: var(--space-3);
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    letter-spacing: var(--tracking-label);
    line-height: var(--lh-snug);
    text-transform: uppercase;
  }

  .section-title {
    font-family: var(--font-display);
    font-size: var(--fs-xl);
    font-weight: var(--fw-semibold);
    letter-spacing: var(--tracking-tight);
    line-height: var(--lh-tight);
  }

  .section-title--sm {
    font-family: var(--font-sans);
    font-size: var(--fs-lg);
    letter-spacing: 0;
  }

  .section-head {
    margin-bottom: var(--space-4);
  }

  .section-lede {
    max-width: var(--measure);
    margin-top: var(--space-1);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
  }

  .section + .section {
    margin-top: var(--space-7);
  }

  /* 9. Summary: lede, KPI strip, and callouts */
  .summary__lede {
    max-width: var(--measure);
    color: var(--text);
    font-size: var(--fs-lg);
    line-height: var(--lh-snug);
  }

  .summary__lede + .kpi-strip,
  .summary__lede + .callout,
  .callout + .kpi-strip {
    margin-top: var(--space-5);
  }

  .kpi-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 var(--space-5);
    margin: 0;
  }

  @media (min-width: 40em) {
    .kpi-strip {
      grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
      gap: 0 var(--space-6);
    }
  }

  .kpi {
    min-width: 0;
    padding: var(--space-4) 0;
    border-top: var(--hairline-w) solid var(--hairline);
  }

  .kpi__label {
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    line-height: var(--lh-snug);
  }

  .kpi__value {
    margin-top: var(--space-1);
    color: var(--text);
    font-size: var(--fs-2xl);
    font-weight: var(--fw-semibold);
    font-variant-numeric: tabular-nums;
    letter-spacing: var(--tracking-tight);
    line-height: var(--lh-tight);
    overflow-wrap: anywhere;
  }

  .kpi__delta,
  .kpi__note {
    margin-top: var(--space-1);
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
    line-height: var(--lh-snug);
  }

  .kpi__note { color: var(--text-muted); }

  .callout {
    --callout-rule: var(--border-strong);
    --callout-bg: var(--surface-subtle);
    padding: var(--space-4) var(--space-5);
    border-inline-start: 3px solid var(--callout-rule);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    background: var(--callout-bg);
    color: var(--text);
    font-size: var(--fs-sm);
  }

  .callout__title {
    margin-bottom: var(--space-1);
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-snug);
  }

  .callout > * + * { margin-top: var(--space-2); }

  .callout--accent { --callout-rule: var(--accent); --callout-bg: var(--accent-soft); }
  .callout--ok     { --callout-rule: var(--ok);     --callout-bg: var(--ok-soft); }
  .callout--warn   { --callout-rule: var(--warn);   --callout-bg: var(--warn-soft); }
  .callout--bad    { --callout-rule: var(--bad);    --callout-bg: var(--bad-soft); }
  .callout--info   { --callout-rule: var(--info);   --callout-bg: var(--info-soft); }

  /* 10. Quick actions and checklists */
  .actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  .actions + .checklist,
  .actions + .callout {
    margin-top: var(--space-5);
  }

  .actions__spacer { flex: 1 1 auto; }

  @media (max-width: 39.99em) {
    .actions > .btn { flex: 1 1 calc(50% - var(--space-2)); }
    .actions > .btn--primary { flex-basis: 100%; }
    .actions__spacer { display: none; }

    .actions--sticky {
      position: sticky;
      bottom: 0;
      z-index: 20;
      margin-inline: calc(var(--gutter) * -1);
      padding: var(--space-3) var(--gutter);
      padding-bottom: max(var(--space-3), env(safe-area-inset-bottom, 0px));
      border-top: var(--hairline-w) solid var(--hairline);
      background: var(--bg);
      box-shadow: var(--shadow-pop);
    }
  }

  .checklist {
    display: grid;
    gap: var(--space-3);
    max-width: var(--measure);
    padding: 0;
    list-style: none;
  }

  .checklist > li {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .checklist input[type="checkbox"] {
    margin-top: 0.2em;
  }

  .checklist label {
    cursor: pointer;
  }

  .checklist input:checked + label {
    color: var(--text-muted);
    text-decoration: line-through;
    text-decoration-color: var(--border-strong);
  }

  .checklist__meta {
    display: block;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
  }

  /* 11. Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--control-h);
    padding: 0 var(--space-4);
    border: var(--hairline-w) solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--dur-fast) var(--ease),
      border-color var(--dur-fast) var(--ease),
      color var(--dur-fast) var(--ease);
  }

  .btn--primary {
    background: var(--accent);
    color: var(--text-on-accent);
  }
  .btn--primary:hover:not(:disabled, [aria-disabled="true"]) {
    background: var(--accent-hover);
  }

  .btn--secondary {
    border-color: var(--control-border);
    background: var(--surface);
  }
  .btn--secondary:hover:not(:disabled, [aria-disabled="true"]) {
    border-color: var(--text-muted);
    background: var(--surface-subtle);
  }

  .btn--ghost { color: var(--text-secondary); }
  .btn--ghost:hover:not(:disabled, [aria-disabled="true"]) {
    background: var(--surface-subtle);
    color: var(--text);
  }

  .btn--danger {
    background: var(--bad-soft);
    color: var(--bad);
  }
  .btn--danger:hover:not(:disabled, [aria-disabled="true"]) {
    background: var(--bad);
    color: var(--surface);
  }

  .btn--sm {
    min-height: var(--control-h-sm);
    padding: 0 var(--space-3);
    font-size: var(--fs-sm);
  }

  .btn--block { width: 100%; }

  .btn:disabled,
  .btn[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
  }

  .btn[aria-busy="true"] {
    cursor: progress;
    opacity: 0.7;
  }

  .btn[aria-pressed="true"] {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-text);
  }

  /* 12. Badges and status dots
     Every badge carries a text label so status survives grayscale printing. */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-pill);
    background: var(--surface-subtle);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    line-height: 1.5;
    white-space: nowrap;
    vertical-align: middle;
  }

  .badge--accent { background: var(--accent-soft); color: var(--accent-text); }
  .badge--ok     { background: var(--ok-soft);     color: var(--ok); }
  .badge--warn   { background: var(--warn-soft);   color: var(--warn); }
  .badge--bad    { background: var(--bad-soft);    color: var(--bad); }
  .badge--info   { background: var(--info-soft);   color: var(--info); }

  .dot {
    display: inline-block;
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: currentColor;
    vertical-align: middle;
  }

  .dot--ok   { color: var(--ok); }
  .dot--warn { color: var(--warn); }
  .dot--bad  { color: var(--bad); }
  .dot--info { color: var(--info); }

  /* 13. Tabs
     Each panel starts with an h2.print-only title so print expands panels
     into sequential, titled sections. Keep panels free of padding/borders so
     hidden="until-found" renders no empty strip when inactive. */
  .tab-list {
    display: flex;
    gap: var(--space-1);
    margin-bottom: var(--space-6);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    border-bottom: var(--hairline-w) solid var(--hairline);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .tab-list::-webkit-scrollbar { display: none; }

  .tab {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: var(--control-h);
    margin-bottom: -1px;
    padding: 0 var(--space-3);
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--dur-fast) var(--ease),
      border-color var(--dur-fast) var(--ease);
  }

  .tab:first-child { margin-inline-start: calc(var(--space-3) * -1); }
  .tab:hover { color: var(--text); }

  .tab[aria-selected="true"] {
    border-bottom-color: var(--accent);
    color: var(--text);
  }

  .tab__count {
    min-width: 1.25rem;
    padding: 0 0.375rem;
    border-radius: var(--radius-pill);
    background: var(--surface-subtle);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-variant-numeric: tabular-nums;
    text-align: center;
  }

  .tab-panel:focus-visible {
    outline-offset: 6px;
  }

  .tab-panel[hidden="until-found"] {
    padding: 0;
    border: 0;
    margin: 0;
  }

  .tab-panel > .print-only + * {
    margin-top: 0;
  }

  /* 14. Disclosures (<details>) */
  .disclosure {
    border-top: var(--hairline-w) solid var(--hairline);
  }

  .disclosure:last-child {
    border-bottom: var(--hairline-w) solid var(--hairline);
  }

  .disclosure > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-height: var(--control-h);
    padding: var(--space-3) 0;
    font-weight: var(--fw-medium);
    list-style: none;
    cursor: pointer;
  }

  .disclosure > summary::-webkit-details-marker { display: none; }

  .disclosure > summary::after {
    content: "";
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    margin-inline-end: var(--space-1);
    border-right: 1.5px solid var(--text-muted);
    border-bottom: 1.5px solid var(--text-muted);
    transform: translateY(-25%) rotate(45deg);
    transition: transform var(--dur) var(--ease);
  }

  .disclosure[open] > summary::after {
    transform: translateY(25%) rotate(-135deg);
  }

  .disclosure > summary:hover { color: var(--accent-text); }

  .disclosure__hint {
    margin-inline-start: auto;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
  }

  .disclosure__body {
    max-width: var(--measure);
    padding-bottom: var(--space-5);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
  }

  .disclosure__body > * + * { margin-top: var(--space-3); }

  /* 15. Data tables */
  .table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    container-type: inline-size;
  }

  @media (max-width: 39.99em) {
    /* Bleed to the screen edge on phones so columns get every pixel. */
    .table-wrap {
      width: auto;
      margin-inline: calc(var(--gutter) * -1);
      padding-inline: var(--gutter);
    }

    /* Sticky tables handle gutter padding on first/last cells so scrolled
       columns never peek into the left gutter behind the pinned column. */
    .table-wrap:has(> .data-table--sticky) {
      padding-inline: 0;
    }

    .data-table--sticky th:first-child,
    .data-table--sticky td:first-child,
    .data-table--sticky thead th:first-child > button {
      padding-inline-start: var(--gutter);
    }

    .data-table--sticky thead th:first-child:has(> button) {
      padding-inline-start: 0;
    }

    .data-table--sticky th:last-child,
    .data-table--sticky td:last-child,
    .data-table--sticky thead th:last-child > button {
      padding-inline-end: var(--gutter);
    }

    .data-table--sticky thead th:last-child:has(> button) {
      padding-inline-end: 0;
    }
  }

  .data-table {
    --table-bg: var(--bg);
    width: 100%;
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
    line-height: var(--lh-snug);
  }

  .data-table caption {
    padding-bottom: var(--space-3);
    caption-side: top;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    text-align: left;
  }

  .data-table th,
  .data-table td {
    padding: var(--space-3);
    border-bottom: var(--hairline-w) solid var(--hairline);
    text-align: left;
    vertical-align: baseline;
  }

  .data-table th:first-child,
  .data-table td:first-child { padding-inline-start: var(--space-2); }

  .data-table th:last-child,
  .data-table td:last-child { padding-inline-end: var(--space-2); }

  .data-table thead th {
    border-bottom-color: var(--border);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    white-space: nowrap;
  }

  /* Sortable column headers (<th scope="col"><button>...</button></th>). */
  .data-table thead th:has(> button) {
    padding: 0;
  }

  .data-table thead th > button {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    width: 100%;
    min-height: var(--control-h-sm);
    padding: var(--space-3);
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: inherit;
    white-space: nowrap;
    cursor: pointer;
  }

  .data-table thead th:first-child > button { padding-inline-start: var(--space-2); }
  .data-table thead th:last-child > button { padding-inline-end: var(--space-2); }
  .data-table thead th.num > button { justify-content: flex-end; }
  .data-table thead th > button:hover,
  .data-table thead th[aria-sort] > button { color: var(--text); }

  .data-table thead th[aria-sort="ascending"] > button::after {
    content: "\2191";
    content: "\2191" / "";
    color: var(--accent-text);
  }

  .data-table thead th[aria-sort="descending"] > button::after {
    content: "\2193";
    content: "\2193" / "";
    color: var(--accent-text);
  }

  .data-table tbody th {
    font-weight: var(--fw-medium);
  }

  .data-table tbody tr:hover > * {
    background: var(--row-hover);
  }

  .data-table tfoot td,
  .data-table tfoot th {
    border-top: var(--hairline-w) solid var(--border);
    border-bottom: 0;
    font-weight: var(--fw-semibold);
  }

  .data-table .num,
  .data-table th.num {
    text-align: right;
    white-space: nowrap;
  }

  .data-table__sub {
    display: block;
    color: var(--text-muted);
    font-size: var(--fs-xs);
    font-weight: var(--fw-regular);
  }

  .data-table--compact th,
  .data-table--compact td {
    padding-top: var(--space-2);
    padding-bottom: var(--space-2);
  }

  /* Sticky headers and first column for wide numeric tables. Separate border
     model prevents cell borders from disappearing while scrolling. */
  .data-table--sticky {
    border-collapse: separate;
    border-spacing: 0;
  }

  .data-table--sticky tbody:has(+ tfoot) tr:last-child > * {
    border-bottom: 0;
  }

  .data-table--sticky thead th {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    background: var(--table-bg);
  }

  .data-table--sticky th:first-child,
  .data-table--sticky td:first-child {
    position: sticky;
    inset-inline-start: 0;
    z-index: 1;
    background: var(--table-bg);
  }

  .data-table--sticky thead th:first-child {
    z-index: 3;
  }

  .data-table--sticky tbody tr:hover > *:first-child {
    background: var(--row-hover);
  }

  /* Card-stack layout: responds to .table-wrap width via container query so
     tables adapt inside sidebars and split panels as well as phones.
     Requires data-label="Column name" on every td. */
  @container (inline-size < 40em) {
    .data-table--stack thead {
      display: none;
    }

    .data-table--stack,
    .data-table--stack tbody,
    .data-table--stack tr,
    .data-table--stack th,
    .data-table--stack td {
      display: block;
    }

    .data-table--stack tr {
      padding: var(--space-3) 0;
      border-bottom: var(--hairline-w) solid var(--hairline);
    }

    .data-table--stack tbody th,
    .data-table--stack td {
      display: flex;
      justify-content: space-between;
      gap: var(--space-4);
      padding: var(--space-1) 0;
      border: 0;
      text-align: right;
    }

    .data-table--stack tbody th {
      font-size: var(--fs-md);
      text-align: left;
    }

    .data-table--stack td::before {
      content: attr(data-label);
      color: var(--text-muted);
      font-size: var(--fs-xs);
      text-align: left;
    }

    .data-table--stack tbody tr:hover > * { background: none; }
  }

  /* 16. Filter bar and form controls */
  .filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
  }

  .filter-bar > .input { flex: 1 1 14rem; }
  .filter-bar > .select { flex: 0 1 12rem; }

  .filter-bar__summary {
    margin-inline-start: auto;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
  }

  .field {
    display: grid;
    gap: var(--space-1);
  }

  .field__label {
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
  }

  .field__hint {
    color: var(--text-muted);
    font-size: var(--fs-xs);
  }

  .field__error {
    color: var(--bad);
    font-size: var(--fs-xs);
  }

  .input,
  .select,
  .textarea {
    width: 100%;
    min-height: var(--control-h);
    padding: 0 var(--space-3);
    border: var(--hairline-w) solid var(--control-border);
    border-radius: var(--radius-sm);
    background-color: var(--surface);
    color: var(--text);
    font-size: var(--control-fs);
    transition: border-color var(--dur-fast) var(--ease),
      box-shadow var(--dur-fast) var(--ease);
  }

  .textarea {
    min-height: 6rem;
    padding: var(--space-2) var(--space-3);
    line-height: var(--lh-body);
    resize: vertical;
  }

  .input::placeholder,
  .textarea::placeholder {
    color: var(--text-muted);
  }

  .input:hover:not(:disabled),
  .select:hover:not(:disabled),
  .textarea:hover:not(:disabled) {
    border-color: var(--text-muted);
  }

  .input:focus-visible,
  .select:focus-visible,
  .textarea:focus-visible {
    border-color: var(--accent);
    outline: 2px solid var(--focus);
    outline-offset: 1px;
    box-shadow: 0 0 0 3px var(--accent-soft);
  }

  .input[aria-invalid="true"] {
    border-color: var(--bad);
  }

  .input:disabled,
  .select:disabled,
  .textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .check {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--control-h);
    font-size: var(--fs-sm);
    cursor: pointer;
  }

  .chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: var(--control-h-sm);
    padding: 0 var(--space-3);
    border: var(--hairline-w) solid var(--control-border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    cursor: pointer;
  }

  .chip:hover:not(:disabled) { border-color: var(--text-muted); }

  .chip[aria-pressed="true"] {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-text);
  }

  /* 17. Item lists (triage rows) */
  .item-list {
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: var(--hairline-w) solid var(--hairline);
  }

  .item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-3) var(--space-4);
    padding: var(--space-4) 0;
    border-bottom: var(--hairline-w) solid var(--hairline);
  }

  .item__thumb {
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    border-radius: var(--radius-sm);
    background: var(--surface-subtle);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    object-fit: cover;
  }

  .item__body { min-width: 0; }

  .item__title {
    overflow: hidden;
    font-weight: var(--fw-medium);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .item__meta {
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
  }

  .item__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    grid-column: 1 / -1;
  }

  .item__actions > .btn { flex: 1 1 0; }

  @media (min-width: 40em) {
    .item { grid-template-columns: auto minmax(0, 1fr) auto auto; }
    .item__actions { grid-column: auto; }
    .item__actions > .btn { flex: none; }
  }

  /* 18. Empty, stale, and loading states */
  .empty-state {
    display: grid;
    justify-items: center;
    gap: var(--space-2);
    padding: var(--space-7) var(--space-5);
    border: var(--hairline-w) dashed var(--border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    text-align: center;
  }

  .empty-state__title {
    color: var(--text);
    font-family: var(--font-display);
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
  }

  .empty-state > p { max-width: 32rem; }
  .empty-state > .btn { margin-top: var(--space-2); }

  .stale-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin-top: var(--space-4);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    background: var(--warn-soft);
    color: var(--text);
    font-size: var(--fs-sm);
  }

  .stale-banner > strong { color: var(--warn); }
  .stale-banner > .btn { margin-inline-start: auto; }

  .skeleton {
    display: block;
    height: 0.875em;
    border-radius: var(--radius-xs);
    background: var(--surface-subtle);
    animation: ds-pulse 1.6s var(--ease) infinite;
  }

  @keyframes ds-pulse {
    50% { opacity: 0.5; }
  }

  /* 19. Meters, bar lists, and sparklines
     Charts stay subtle: one hue (accent) plus status colors for meaning. */
  .meter {
    --value: 0%;
    --meter-fill: var(--accent);
    position: relative;
    height: 0.375rem;
    overflow: hidden;
    border-radius: var(--radius-pill);
    background: var(--surface-subtle);
  }

  .meter > span {
    display: block;
    width: var(--value);
    height: 100%;
    border-radius: inherit;
    background: var(--meter-fill);
  }

  /* Optional target marker: style="--target: 50%". */
  .meter[style*="--target"]::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--target);
    width: 2px;
    background: var(--text);
    opacity: 0.55;
  }

  .meter--ok   { --meter-fill: var(--ok); }
  .meter--warn { --meter-fill: var(--warn); }
  .meter--bad  { --meter-fill: var(--bad); }
  .meter--info { --meter-fill: var(--info); }

  .bar-list {
    display: grid;
    gap: var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .bar-list__row {
    display: grid;
    grid-template-columns: minmax(6.5rem, 11rem) minmax(0, 1fr) 4.5rem;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--fs-sm);
  }

  .bar-list__label {
    overflow: hidden;
    color: var(--text-secondary);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .bar-list__value {
    font-variant-numeric: tabular-nums;
    text-align: right;
  }

  @media (max-width: 39.99em) {
    .bar-list__row {
      grid-template-columns: minmax(0, 1fr) auto;
      gap: var(--space-1) var(--space-3);
    }

    .bar-list__row > .meter {
      grid-column: 1 / -1;
      order: 2;
    }
  }

  .sparkline {
    display: inline-block;
    width: 5rem;
    height: 1.25rem;
    overflow: visible;
    color: var(--text-muted);
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.5;
    vertical-align: middle;
  }

  .sparkline.is-pos { color: var(--ok); }
  .sparkline.is-neg { color: var(--bad); }

  .legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
    color: var(--text-muted);
    font-size: var(--fs-xs);
  }

  /* 20. Dialogs, panels, and footer
     Never set display unconditionally on dialog; open state uses dialog[open]. */
  .dialog {
    width: min(30rem, calc(100vw - 2 * var(--gutter)));
    max-width: none;
    max-height: calc(100dvh - 2 * var(--space-5));
    padding: var(--space-5);
    border: var(--hairline-w) solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-raised);
    color: var(--text);
    box-shadow: var(--shadow-pop);
  }

  .dialog:modal {
    overscroll-behavior: contain;
  }

  .dialog::backdrop {
    background: rgba(19, 19, 18, 0.52);
    overflow: hidden;
    overscroll-behavior: contain;
  }

  .dialog__title {
    font-family: var(--font-display);
    font-size: var(--fs-xl);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
    letter-spacing: var(--tracking-tight);
  }

  .dialog__body {
    margin-top: var(--space-3);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
  }

  .dialog__body > * + * {
    margin-top: var(--space-3);
  }

  .dialog__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-5);
  }

  /* Panels are the exception, not the default. Prefer spacing and hairlines. */
  .panel {
    padding: var(--space-5);
    border: var(--hairline-w) solid var(--hairline);
    border-radius: var(--radius-md);
    background: var(--surface);
  }

  .panel--flush { padding: 0; overflow: hidden; }

  .panel--media {
    border-radius: var(--radius-lg);
  }

  .page-footer {
    margin-top: var(--space-8);
    padding-top: var(--space-4);
    border-top: var(--hairline-w) solid var(--hairline);
    color: var(--text-muted);
    font-size: var(--fs-xs);
  }

  /* 21. Prose (rendered Markdown)
     Wrap any GFM-rendered HTML in <main class="page prose"> and it adopts the
     canonical anatomy with zero extra classes. */
  .prose {
    font-size: var(--fs-md);
    line-height: var(--lh-body);
  }

  .prose > * + * { margin-top: var(--space-4); }

  .prose > h1 {
    font-family: var(--font-display);
    font-size: var(--fs-2xl);
    letter-spacing: var(--tracking-tight);
    string-set: doc-title content();
  }

  @media (min-width: 60em) {
    .prose > h1 { font-size: var(--fs-3xl); }
  }

  .prose > h1 + p {
    margin-top: var(--space-3);
    padding-bottom: var(--space-5);
    border-bottom: var(--hairline-w) solid var(--hairline);
    color: var(--text-muted);
    font-size: var(--fs-sm);
  }

  .prose > h1 + p strong {
    color: var(--text-secondary);
    font-weight: var(--fw-medium);
  }

  .prose h2 {
    margin-top: var(--space-7);
    font-family: var(--font-display);
    font-size: var(--fs-xl);
    letter-spacing: var(--tracking-tight);
  }

  .prose > h1 + p + h2 { margin-top: var(--space-5); }

  .prose h3 {
    margin-top: var(--space-6);
    font-size: var(--fs-lg);
  }

  .prose h4 {
    margin-top: var(--space-5);
    font-size: var(--fs-md);
  }

  .prose p,
  .prose ul,
  .prose ol,
  .prose blockquote {
    max-width: var(--measure);
  }

  .prose ul,
  .prose ol {
    padding-inline-start: 1.25rem;
  }

  .prose li + li { margin-top: var(--space-2); }

  .prose li::marker { color: var(--text-muted); }

  /* Keep .contains-task-list separate so older CSS parsers without :has()
     still drop the list marker on task lists. */
  .prose ul.contains-task-list {
    padding-inline-start: 0;
    list-style: none;
  }

  .prose ul:has(> li.task-list-item) {
    padding-inline-start: 0;
    list-style: none;
  }

  .prose .task-list-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .prose .task-list-item input { margin-top: 0.3em; }

  .prose blockquote {
    padding: var(--space-4) var(--space-5);
    border-inline-start: 3px solid var(--border-strong);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    background: var(--surface-subtle);
    font-size: var(--fs-sm);
    line-height: var(--lh-body);
  }

  /* Elevate only the executive summary lede directly beneath ## Summary. */
  .prose > h1 + p + h2 + blockquote,
  .prose > h1 + h2 + blockquote {
    border-inline-start-color: var(--accent);
    background: var(--accent-soft);
    font-size: var(--fs-lg);
    line-height: var(--lh-snug);
  }

  .prose blockquote > * + * { margin-top: var(--space-2); }

  .prose hr {
    margin: var(--space-7) 0;
    border-top-color: var(--border);
  }

  .prose table {
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
    line-height: var(--lh-snug);
  }

  .prose th,
  .prose td {
    padding: var(--space-3);
    border-bottom: var(--hairline-w) solid var(--hairline);
    vertical-align: baseline;
  }

  .prose th:first-child,
  .prose td:first-child { padding-inline-start: var(--space-2); }

  .prose thead th {
    border-bottom-color: var(--border);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    text-align: left;
    white-space: nowrap;
  }

  .prose th[align="right"],
  .prose td[align="right"],
  .prose thead th[align="right"],
  .prose th.num,
  .prose td.num {
    text-align: right;
    white-space: nowrap;
  }

  .prose th[align="center"],
  .prose td[align="center"],
  .prose thead th[align="center"] {
    text-align: center;
  }

  .prose pre {
    padding: var(--space-4);
    overflow-x: auto;
    border-radius: var(--radius-md);
    background: var(--surface-subtle);
    line-height: var(--lh-snug);
  }

  .prose pre code {
    padding: 0;
    background: none;
  }

  .prose img {
    border-radius: var(--radius-md);
  }

  @media (max-width: 39.99em) {
    .prose table {
      display: block;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }
  }
}


/* ==========================================================================
   22. Utilities
   ========================================================================== */

@layer utilities {
  .num,
  .tabular {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
  }

  .mono { font-family: var(--font-mono); }
  .muted { color: var(--text-muted); }
  .secondary { color: var(--text-secondary); }
  .is-pos { color: var(--ok); }
  .is-neg { color: var(--bad); }
  .is-warn { color: var(--warn); }
  .nowrap { white-space: nowrap; }
  .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .align-right { text-align: right; }

  .visually-hidden:where(:not(:focus-within, :active)) {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }

  .print-only { display: none; }
  /* .screen-only is hidden in print (section 24). */
}


/* ==========================================================================
   23. Forced Colors Mode and reduced motion
   ========================================================================== */

@media (forced-colors: active) {
  .btn--primary,
  .btn--secondary,
  .btn--danger,
  .badge,
  .chip,
  .callout,
  .meter,
  .dialog {
    border: 1px solid CanvasText;
  }

  .btn--primary,
  .btn[aria-pressed="true"],
  .chip[aria-pressed="true"] {
    border-color: Highlight;
  }

  .meter > span {
    background: Highlight;
    forced-color-adjust: none;
  }

  .meter[style*="--target"]::after {
    background: CanvasText;
    opacity: 1;
    forced-color-adjust: none;
  }

  .dot {
    border: 1px solid CanvasText;
  }

  .tab[aria-selected="true"] {
    border-bottom-color: Highlight;
  }

  :focus-visible,
  .input:focus-visible,
  .select:focus-visible,
  .textarea:focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
    box-shadow: none;
  }
}

@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;
  }
}


/* ==========================================================================
   24. Print and PDF (US Letter)
   Works with browser Print-to-PDF (Chrome, Safari, and Firefox) and
   WeasyPrint. Chrome: uncheck "Headers and footers" in the print dialog, or
   pass --no-pdf-header-footer when printing headless.
   ========================================================================== */

@page {
  size: letter;
  margin: 0.6in 0.65in 0.75in;

  @bottom-left {
    content: string(doc-title);
    color: #555555;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans",
      "DejaVu Sans", Arial, sans-serif;
    font-size: 8pt;
  }

  @bottom-right {
    content: "Page " counter(page) " of " counter(pages);
    color: #555555;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans",
      "DejaVu Sans", Arial, sans-serif;
    font-size: 8pt;
  }
}

@media print {
  /* Crisp light paper. Unlayered and placed last so it beats every theme
     and surface rule above. */
  :root:root,
  [data-theme][data-theme],
  [data-surface][data-surface] {
    color-scheme: light;

    --bg: #FFFFFF;
    --surface: #FFFFFF;
    --surface-subtle: #F2F2F0;
    --surface-raised: #FFFFFF;
    --row-hover: transparent;

    --hairline: #D9D9D6;
    --border: #BFBFBB;
    --border-strong: #8C8C88;
    --control-border: #757570;

    --text: #111111;
    --text-secondary: #333333;
    --text-muted: #555555;

    --accent: #0E6178;
    --accent-hover: #0E6178;
    --accent-soft: #E6F0F2;
    --accent-text: #0E6178;
    --text-on-accent: #FFFFFF;

    --ok: #1F6B3E;
    --ok-soft: #EAF3EC;
    --warn: #7A4E00;
    --warn-soft: #F8EFDE;
    --bad: #A12A23;
    --bad-soft: #F8E8E6;
    --info: #3E4F66;
    --info-soft: #EDF0F4;

    --focus: transparent;
    --shadow-pop: none;
    --zone-gap: 1.75rem;
  }

  /* Rescale the whole rem system: 1rem = 10pt body text on paper. */
  html {
    font-size: 10pt;
  }

  body {
    min-height: 0;
    background: #FFFFFF;
    color: var(--text);
    line-height: 1.45;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .page,
  .page--wide,
  .page--narrow {
    max-width: none;
    padding: 0;
  }

  /* Hide interactive-only chrome. */
  .screen-only,
  [data-print="hide"],
  .skip-link,
  .page-header__tools,
  .actions,
  .filter-bar,
  .tab-list,
  .item__actions,
  .btn,
  .chip,
  .stale-banner > .btn,
  .empty-state > .btn,
  dialog {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }

  /* Expand every tab panel (including hidden="until-found") into a
     sequential, titled section. @layer reset !important outranks @layer base
     !important under CSS Cascade Layers; unlayered rule handles older engines. */
  @layer reset {
    .tab-panel,
    .tab-panel[hidden] {
      display: block !important;
      content-visibility: visible !important;
    }
  }

  .tab-panel,
  .tab-panel[hidden] {
    display: block !important;
    content-visibility: visible !important;
  }

  .tab-panel + .tab-panel {
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: var(--hairline-w) solid var(--border);
  }

  .tab-panel > .print-only {
    margin-bottom: var(--space-4);
  }

  /* Expand every disclosure. The showcase script also opens closed
     <details> on beforeprint for browsers without ::details-content. */
  .disclosure > summary {
    min-height: 0;
    padding: var(--space-3) 0 var(--space-1);
    font-weight: var(--fw-semibold);
  }

  .disclosure > summary::after {
    display: none;
  }

  .disclosure__body {
    max-width: none;
    padding-bottom: var(--space-3);
  }

  /* Sticky and scrolling containers flatten on paper. */
  .page-header--sticky,
  .actions--sticky {
    position: static;
    box-shadow: none;
  }

  .table-wrap {
    margin: 0;
    padding: 0;
    overflow: visible;
    container-type: normal;
  }

  .data-table--sticky {
    border-collapse: collapse;
  }

  .data-table--sticky thead th,
  .data-table--sticky th:first-child,
  .data-table--sticky td:first-child {
    position: static;
    background: transparent;
  }

  /* Unwrap sortable header buttons on paper so repeated thead rows clone cleanly. */
  .data-table thead th:has(> button) {
    padding: var(--space-3);
  }

  .data-table thead th:first-child:has(> button) {
    padding-inline-start: var(--space-2);
  }

  .data-table thead th:last-child:has(> button) {
    padding-inline-end: var(--space-2);
  }

  .data-table thead th > button {
    display: contents;
  }

  .data-table thead th[aria-sort] > button {
    color: inherit;
  }

  .data-table thead th[aria-sort] > button::after {
    display: none;
  }

  .prose table {
    display: table;
  }

  /* Page-break hygiene. */
  thead { display: table-header-group; }
  tfoot { display: table-row-group; }

  /* Avoid double hairlines where lists or disclosures meet section dividers. */
  .item-list > .item:last-child,
  .disclosure:last-child {
    border-bottom: 0;
  }

  tr,
  .kpi,
  .callout,
  .item,
  .bar-list__row,
  .empty-state,
  .checklist > li,
  .disclosure > summary,
  figure,
  img,
  pre,
  blockquote {
    break-inside: avoid;
  }

  h1, h2, h3, h4,
  .zone-title,
  .section-head,
  .disclosure > summary {
    break-after: avoid;
  }

  p, li {
    orphans: 3;
    widows: 3;
  }

  .page-break-before { break-before: page; }
  .page-break-after { break-after: page; }
  .keep-together { break-inside: avoid; }

  /* Grayscale legibility: status gets an outline, never color alone. */
  .badge {
    border: var(--hairline-w) solid currentColor;
  }

  .callout {
    border-inline-start-width: 3pt;
  }

  .data-table tbody tr:hover > * {
    background: none;
  }

  .page-header {
    border-bottom-color: var(--border);
  }

  .kpi__value {
    font-size: var(--fs-xl);
  }

  /* Links: inherit color; reveal external URLs inside prose. */
  a {
    color: inherit;
    text-decoration-color: var(--border-strong);
  }

  .prose a[href^="http"]::after {
    content: " (" attr(href) ")";
    color: var(--text-muted);
    font-size: 0.85em;
    word-break: break-all;
  }

  .page-footer {
    margin-top: var(--space-6);
  }

  * {
    box-shadow: none !important;
  }
}

/* Separate rule: an unknown pseudo-element would invalidate a whole list. */
@media print {
  details::details-content {
    display: block;
    content-visibility: visible;
  }
}
