/* Components: one section per macro of templates/_components.html and _forms.html, in the same
   order and with the same name, plus the page chrome of base.html (skip link, top bar, page).
   The recipes follow shadcn/ui (docs/design/shadcn-mapping.md names the shadcn component and
   variant of each section): h-9 controls, 14 px text, rounded-md controls and rounded-xl cards,
   1 px borders, shadow-xs / shadow-sm, a 3 px soft focus ring, lucide icons as CSS masks.
   Naming: block .btn, element .btn__label, modifier .btn--primary. State comes from HTML where it
   can: :disabled, [aria-current], [aria-invalid], [open].
   Only var(--…) tokens: no colour literals (tests/test_design_system.py). */

@layer components {
  /* ---------------------------------------------------------------- icon (ui.icon) */
  /* The one way to draw an icon: a lucide SVG (static/icons/, tokens --icon-…) as a mask filled with
     currentColor. Every pseudo-element that shows an icon joins this list and sets --icon. */
  .icon, .badge::before, .alert::before, .verdict__title::before, .verdict__chip::before,
  .disclosure__summary::after, .select::after, .breadcrumb__sep::before, .ext-link::after,
  .steps__item--done .steps__no::before, .topmenu__toggle::before, .btn__icon, .filters__more > summary::after, .new-manual::after, .warning__more > summary::after, .todo__item::after {
    content: ""; display: inline-block; flex: none; width: 1rem; height: 1rem;
    background-color: currentColor;
    -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .icon { vertical-align: -0.125em; }
  .icon--chevron-down { --icon: var(--icon-chevron-down); }
  .icon--chevron-right { --icon: var(--icon-chevron-right); }
  .icon--check { --icon: var(--icon-check); }
  .icon--x { --icon: var(--icon-x); }
  .icon--triangle-alert { --icon: var(--icon-triangle-alert); }
  .icon--info { --icon: var(--icon-info); }
  .icon--circle-check { --icon: var(--icon-circle-check); }
  .icon--circle-x { --icon: var(--icon-circle-x); }
  .icon--circle-minus { --icon: var(--icon-circle-minus); }
  .icon--contrast { --icon: var(--icon-contrast); }
  .icon--diamond { --icon: var(--icon-diamond); }
  .icon--arrow-up-right { --icon: var(--icon-arrow-up-right); }
  .icon--plus { --icon: var(--icon-plus); }
  .icon--printer { --icon: var(--icon-printer); }
  .icon--menu { --icon: var(--icon-menu); }

  /* ---------------------------------------------------------------- chrome: skip link, top bar, page */
  .skip-link {
    position: absolute; left: var(--space-2); top: -10rem; z-index: 30;
    padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); box-shadow: var(--shadow-md);
    background: var(--color-surface); color: var(--color-link); font-weight: var(--weight-medium);
  }
  .skip-link:focus { top: var(--space-2); }

  /* the site header of shadcn: the page's own background, a hairline under it, quiet links */
  .topbar { position: relative; background: var(--color-bg); color: var(--color-text); border-bottom: var(--border-thin) solid var(--color-border); }
  .topbar__inner {
    max-width: var(--page-max); margin: 0 auto; padding: 0 var(--page-pad); min-height: var(--topbar-height);
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4);
  }
  .wordmark {
    display: inline-flex; align-items: center; gap: var(--space-2); margin-right: var(--space-3);
    color: inherit; text-decoration: none; font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); white-space: nowrap;
  }
  .wordmark:hover { text-decoration: none; }
  .wordmark__mark { width: var(--mark-size); height: var(--mark-size); flex: none; }
  .wordmark__mark .mark-bg { fill: var(--color-primary); }
  .wordmark__mark .mark-fg { fill: var(--color-on-primary); stroke: var(--color-on-primary); }
  .topnav { display: flex; gap: var(--space-1); flex: 1; }
  .topnav a {
    color: var(--color-text-muted); text-decoration: none; font-size: var(--text-sm); font-weight: var(--weight-medium);
    padding: var(--space-1) var(--space-3); border-radius: var(--radius-md); white-space: nowrap; transition: color 0.15s, background-color 0.15s;
  }
  .topnav a:hover { color: var(--color-text); }
  .topnav a[aria-current="page"] { color: var(--color-text); background: var(--color-accent); }
  /* "1 Pendenz": a link with a small count chip (someone must act: the brand, not a judgement) */
  .counter {
    display: inline-flex; align-items: center; gap: var(--space-2); white-space: nowrap; min-height: var(--control-height-sm);
    padding: 0 var(--space-3) 0 var(--space-2); border-radius: var(--radius-md);
    color: var(--color-text); text-decoration: none; font-size: var(--text-sm); font-weight: var(--weight-medium);
  }
  .counter:hover { background: var(--color-accent); }
  .counter__n {
    display: inline-grid; place-items: center; min-width: 1.25rem; height: 1.25rem; padding: 0 var(--space-1);
    border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-variant-numeric: var(--font-numeric);
    background: var(--color-secondary); color: var(--color-on-secondary);
  }
  .counter--due .counter__n { background: var(--color-primary); color: var(--color-on-primary); }
  .topbar__user { color: var(--color-text-muted); font-size: var(--text-sm); white-space: nowrap; }
  .topbar__logout { margin: 0; }

  .page { max-width: var(--page-max); margin: 0 auto; padding: var(--space-6) var(--page-pad) var(--space-8); }
  .page--narrow { max-width: calc(var(--narrow-max) + 2 * var(--page-pad)); }
  .stack > * + * { margin-top: var(--space-4); }
  .section { margin-top: var(--space-7); scroll-margin-top: var(--space-8); }
  .section > h2 { font-size: var(--text-xl); }
  .section__head {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: var(--space-3); margin-bottom: var(--space-4);
  }
  .section__head > h2 { font-size: var(--text-xl); }
  .section-intro { color: var(--color-text-muted); font-size: var(--text-sm); max-width: var(--measure); margin-bottom: var(--space-3); }
  .lead { color: var(--color-text-muted); max-width: var(--measure); margin-bottom: var(--space-5); }
  .hint { color: var(--color-text-muted); font-size: var(--text-sm); font-weight: var(--weight-regular); line-height: var(--leading-snug); }

  /* the phone menu (base.html): hidden on a wide screen, where the top bar shows everything; on a phone
     an outline icon button opens a popover under the bar (shadcn Dropdown Menu, a native <details>) */
  .topmenu { display: none; }
  .topmenu__toggle {
    --icon: var(--icon-menu);
    display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--control-height-sm);
    padding: 0 var(--space-3); cursor: pointer; list-style: none; border-radius: var(--radius-md);
    font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text);
    background: var(--color-bg); border: var(--border-thin) solid var(--color-border); box-shadow: var(--shadow-xs);
  }
  .topmenu__toggle::-webkit-details-marker { display: none; }
  .topmenu[open] > .topmenu__toggle { --icon: var(--icon-x); background: var(--color-accent); }
  .topmenu__panel {
    position: absolute; left: var(--page-pad-sm); right: var(--page-pad-sm); top: calc(100% + var(--space-1)); z-index: 20;
    padding: var(--space-1); background: var(--color-popover); color: var(--color-text);
    border: var(--border-thin) solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  }
  .topmenu__panel nav { display: grid; }
  .topmenu__panel nav a {
    padding: var(--space-2) var(--space-2); border-radius: var(--radius-sm); color: var(--color-text); text-decoration: none;
    font-size: var(--text-sm); font-weight: var(--weight-medium);
  }
  .topmenu__panel nav a:hover, .topmenu__panel nav a[aria-current="page"] { background: var(--color-accent); }
  .topmenu__user {
    margin-top: var(--space-1); padding: var(--space-2) var(--space-2) var(--space-1); font-size: var(--text-xs); color: var(--color-text-muted);
    border-top: var(--border-thin) solid var(--color-border);
  }
  .topmenu__panel form { margin: 0; }
  .topmenu__panel form .btn { width: 100%; justify-content: flex-start; padding-inline: var(--space-2); }
  @media (max-width: 40rem) {
    .topbar__inner { flex-wrap: nowrap; padding: var(--space-2) var(--page-pad-sm); gap: var(--space-2); }
    .topnav, .topbar__user, .topbar__logout { display: none; }
    .wordmark { margin-right: auto; min-width: 0; }
    .counter__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .topmenu { display: block; }
    .page { padding: var(--space-5) var(--page-pad-sm) var(--space-7); }
    .section { margin-top: var(--space-6); }
  }

  /* ---------------------------------------------------------------- card (ui.card; .card also as a plain layout class) */
  /* shadcn Card: rounded-xl, border, shadow-sm; header (title, one description, an action at the right),
     content, footer. A plain .card pads its content directly. */
  .card {
    background: var(--color-surface); color: var(--color-text); border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-xl); box-shadow: var(--shadow-sm); padding: var(--space-5);
  }
  /* hidden form inputs take no room: spacing counts only from a visible element on */
  .card > :not(input[type="hidden"], [hidden]) ~ * { margin-top: var(--space-3); }
  .card__title, h2.card__title, h3.card__title { font-size: var(--text-md); font-weight: var(--weight-semibold); line-height: var(--leading-tight); letter-spacing: var(--tracking-tight); }
  .card--slots { padding: var(--space-5) 0; }
  .card.card--slots > :not(input[type="hidden"]) ~ * { margin-top: var(--space-5); }
  .card__header {
    display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; gap: var(--space-1) var(--space-4); padding: 0 var(--space-5);
  }
  .card__header:has(> .card__action) { grid-template-columns: minmax(0, 1fr) auto; }
  .card__header > .card__action { grid-column: 2; grid-row: 1 / span 2; align-self: start; }
  .card__description { font-size: var(--text-sm); color: var(--color-text-muted); }
  .card__content { padding: 0 var(--space-5); }
  .card__content > :not(input[type="hidden"]) ~ * { margin-top: var(--space-3); }
  .card__footer {
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); padding: var(--space-4) var(--space-5) 0;
    border-top: var(--border-thin) solid var(--color-border);
  }
  .card__footer > .actions { margin-top: 0; }
  @media (max-width: 40rem) {
    .card { padding: var(--space-4); }
    .card--slots { padding: var(--space-4) 0; }
    .card__header, .card__content { padding-inline: var(--space-4); }
    .card__footer { padding-inline: var(--space-4); }
  }

  /* ---------------------------------------------------------------- button (ui.button) */
  /* shadcn Button. primary = default (filled), secondary = outline, quiet = ghost, danger = destructive
     drawn as an outline (SPEC: never filled), link = link. Sizes: default h-9, small h-8. */
  .btn {
    --btn-bg: var(--color-bg); --btn-fg: var(--color-text); --btn-line: var(--color-border); --btn-shadow: var(--shadow-xs);
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    min-height: var(--control-height); padding: var(--space-1) var(--space-4);
    font: inherit; font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: var(--leading-tight);
    text-align: center; text-decoration: none; cursor: pointer; white-space: nowrap;
    color: var(--btn-fg); background: var(--btn-bg); border: var(--border-thin) solid var(--btn-line); border-radius: var(--radius-md);
    box-shadow: var(--btn-shadow); transition: color 0.15s, background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
  }
  .btn:hover { --btn-bg: var(--color-accent); --btn-fg: var(--color-on-accent); text-decoration: none; }
  .btn:focus-visible { outline: none; border-color: var(--color-focus); box-shadow: var(--focus-ring); }
  .btn--primary { --btn-bg: var(--color-primary); --btn-fg: var(--color-on-primary); --btn-line: var(--color-primary); }
  .btn--primary:hover { --btn-bg: var(--color-primary-hover); --btn-fg: var(--color-on-primary); --btn-line: var(--color-primary-hover); }
  .btn--quiet { --btn-bg: transparent; --btn-line: transparent; --btn-shadow: none; padding-inline: var(--space-3); }
  .btn--danger { --btn-fg: var(--color-danger-text); --btn-line: var(--color-danger-border); }
  .btn--danger:hover { --btn-bg: var(--color-danger-bg); --btn-fg: var(--color-danger-text); }
  .btn--link {
    --btn-bg: transparent; --btn-line: transparent; --btn-shadow: none; --btn-fg: var(--color-link);
    min-height: 0; padding: 0; text-underline-offset: 4px;
  }
  .btn--link:hover { --btn-bg: transparent; --btn-fg: var(--color-link); text-decoration: underline; }
  .btn--small { min-height: var(--control-height-sm); padding: 0 var(--space-3); gap: 0.375rem; font-size: var(--text-sm); }
  .btn:disabled { opacity: 0.5; cursor: progress; }
  .btn__icon { width: 1rem; height: 1rem; }

  /* ---------------------------------------------------------------- actions (ui.actions) */
  .actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-4); }
  @media (max-width: 40rem) {
    .actions { flex-direction: column; align-items: stretch; }
    .actions > .btn:not(.btn--quiet):not(.btn--link) { width: 100%; }
  }
  /* sticky: on a phone the one primary button of a long form stays at the bottom of the screen */
  @media (max-width: 52rem) {
    .actions--sticky {
      position: sticky; bottom: 0; z-index: 5; margin-inline: calc(-1 * var(--page-pad-sm));
      padding: var(--space-3) var(--page-pad-sm); background: var(--color-bg);
      border-top: var(--border-thin) solid var(--color-border); box-shadow: var(--shadow-md);
    }
    .actions--sticky > .btn { width: 100%; }
    /* a field has the focus (the keyboard is up): the bar goes back to the end of the form */
    form:has(input:not([type=radio]):not([type=checkbox]):focus, select:focus, textarea:focus) .actions--sticky { position: static; box-shadow: none; }
    /* a field the browser scrolls to is not hidden under the bar */
    html:has(.actions--sticky) { scroll-padding-bottom: 6rem; }
  }

  /* ---------------------------------------------------------------- tabs (ui.tabs) */
  /* shadcn Tabs, default variant: a muted pill list, the current trigger raised on the background */
  .tabs {
    display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0; max-width: 100%; padding: 3px;
    background: var(--color-surface-muted); border-radius: var(--radius-lg); color: var(--color-text-muted);
  }
  .tabs__trigger {
    display: inline-flex; align-items: center; gap: 0.375rem; min-height: calc(var(--control-height) - 6px); padding: 0 var(--space-3);
    border: var(--border-thin) solid transparent; border-radius: var(--radius-md);
    font-size: var(--text-sm); font-weight: var(--weight-medium); white-space: nowrap; text-decoration: none;
    color: var(--color-text-muted); transition: color 0.15s, background-color 0.15s;
  }
  .tabs__trigger:hover { color: var(--color-text); text-decoration: none; }
  .tabs__trigger[aria-current] { color: var(--color-text); background: var(--color-bg); box-shadow: var(--shadow-sm); }
  .tabs__trigger:focus-visible { outline: none; border-color: var(--color-focus); box-shadow: var(--focus-ring); }
  .tabs__count {
    display: inline-grid; place-items: center; min-width: 1.25rem; height: 1.25rem; padding: 0 0.3rem; border-radius: var(--radius-pill);
    font-size: var(--text-xs); font-variant-numeric: var(--font-numeric); background: var(--color-bg); color: var(--color-text-muted);
  }
  .tabs__trigger[aria-current] .tabs__count { background: var(--color-surface-muted); }

  /* ---------------------------------------------------------------- badge (ui.badge): tone, icon, word */
  /* shadcn Badge: a pill, text-xs, font-medium, an optional 12 px icon. neutral = secondary; action =
     brand tint; a verdict or warning tier = an outline in its tone WITH its own lucide icon, so it reads
     in grey and on paper too. */
  .badge {
    --badge-fg: var(--color-neutral-text); --badge-bg: var(--color-neutral-bg); --badge-line: transparent;
    display: inline-flex; align-items: center; gap: var(--space-1); padding: 0.125rem var(--space-2);
    border-radius: var(--radius-pill); border: var(--border-thin) solid var(--badge-line);
    font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1rem; letter-spacing: 0; white-space: nowrap; vertical-align: middle;
    color: var(--badge-fg); background: var(--badge-bg);
  }
  .badge::before { width: 0.75rem; height: 0.75rem; }
  .badge--neutral::before { display: none; }
  .badge--action { --badge-fg: var(--color-action-text); --badge-bg: var(--color-action-bg); }
  /* the dot of "someone must act" is a plain circle, not an icon */
  .badge--action::before { width: 0.375rem; height: 0.375rem; border-radius: 50%; -webkit-mask: none; mask: none; }
  .badge--survives { --icon: var(--icon-circle-check); --badge-fg: var(--color-success-text); --badge-bg: var(--color-success-bg); --badge-line: var(--color-success-border); }
  .badge--narrow { --icon: var(--icon-contrast); --badge-fg: var(--color-caution-text); --badge-bg: var(--color-caution-bg); --badge-line: var(--color-caution-border); }
  .badge--rejected { --icon: var(--icon-circle-x); --badge-fg: var(--color-danger-text); --badge-bg: var(--color-danger-bg); --badge-line: var(--color-danger-border); }
  .badge--no-threshold { --icon: var(--icon-circle-minus); --badge-fg: var(--color-info-text); --badge-bg: var(--color-info-bg); --badge-line: var(--color-info-border); }
  .badge--critical { --icon: var(--icon-triangle-alert); --badge-fg: var(--color-danger-text); --badge-bg: var(--color-danger-bg); --badge-line: var(--color-danger-border); }
  .badge--check { --icon: var(--icon-diamond); --badge-fg: var(--color-caution-text); --badge-bg: var(--color-caution-bg); --badge-line: var(--color-caution-border); }
  .badge--info { --icon: var(--icon-info); --badge-fg: var(--color-info-text); --badge-bg: var(--color-info-bg); --badge-line: var(--color-info-border); }

  /* ---------------------------------------------------------------- alert (ui.alert) */
  /* shadcn Alert: icon | title, description; rounded-lg, border, px-4 py-3, text-sm. A tone tints it. */
  .alert {
    --icon: var(--icon-info); --alert-bg: var(--color-surface); --alert-line: var(--color-border); --alert-accent: var(--color-text);
    --alert-title: var(--color-text);
    display: grid; grid-template-columns: 1rem minmax(0, 1fr); align-items: start; gap: 0.125rem var(--space-3);
    padding: var(--space-3) var(--space-4); color: var(--color-text);
    background: var(--alert-bg); border: var(--border-thin) solid var(--alert-line); border-radius: var(--radius-lg); font-size: var(--text-sm);
  }
  .alert::before { grid-column: 1; grid-row: 1; margin-top: 0.125rem; color: var(--alert-accent); }
  .alert > * { grid-column: 2; }
  * + .alert { margin-top: var(--space-3); }
  .alert__title { font-weight: var(--weight-medium); color: var(--alert-title); letter-spacing: var(--tracking-tight); }
  /* the box spans the content width like every block beside it; its text keeps a readable measure */
  .alert__body { max-width: calc(var(--measure) + 10rem); line-height: var(--leading-body); }
  .alert__title + .alert__body { color: var(--color-text-muted); }
  .alert__body > * + * { margin-top: var(--space-2); }
  .alert__body a { color: inherit; }
  .alert--success { --icon: var(--icon-circle-check); --alert-bg: var(--color-success-bg); --alert-line: var(--color-success-border); --alert-accent: var(--color-success-text); --alert-title: var(--color-success-text); }
  .alert--caution { --icon: var(--icon-triangle-alert); --alert-bg: var(--color-caution-bg); --alert-line: var(--color-caution-border); --alert-accent: var(--color-caution-text); --alert-title: var(--color-caution-text); }
  .alert--danger { --icon: var(--icon-circle-x); --alert-bg: var(--color-danger-bg); --alert-line: var(--color-danger-border); --alert-accent: var(--color-danger-text); --alert-title: var(--color-danger-text); }
  .alert--caution .alert__title + .alert__body, .alert--danger .alert__title + .alert__body, .alert--success .alert__title + .alert__body { color: var(--color-text); }

  /* ---------------------------------------------------------------- stat and stat row (ui.stat, ui.stat_row) */
  /* the key-figure card of shadcn's dashboard: a muted label, a large number, at most ONE line under it */
  .stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: var(--space-4); }
  .stat {
    display: grid; align-content: start; gap: var(--space-1);
    background: linear-gradient(to top, color-mix(in srgb, var(--color-primary) 4%, var(--color-surface)), var(--color-surface));
    border: var(--border-thin) solid var(--color-border); border-radius: var(--radius-xl); padding: var(--space-4) var(--space-5); box-shadow: var(--shadow-xs);
  }
  .stat__label { font-size: var(--text-sm); color: var(--color-text-muted); }
  .stat__value {
    font-size: var(--text-2xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight);
    line-height: var(--leading-tight); white-space: nowrap; font-variant-numeric: var(--font-numeric);
  }
  .stat__value > .badge { font-size: var(--text-sm); padding: 0.125rem var(--space-3); }
  .stat__unit { margin-right: var(--space-1); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text-muted); letter-spacing: 0; }
  .stat__sub { margin-top: var(--space-1); font-size: var(--text-sm); color: var(--color-text-muted); text-wrap: balance; }
  .stat--negative .stat__value { color: var(--color-danger-solid); }
  @media (max-width: 40rem) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
    .stat { padding: var(--space-3); }
    .stat__value { font-size: var(--text-xl); }
    .stat__sub { font-size: var(--text-xs); }
  }

  /* ---------------------------------------------------------------- verdict banner (ui.verdict) */
  /* an Alert grown to a card: the label, the verdict word with its icon and, at the right, the chip of
     the critical warnings; one line under it. Tinted in the tone of the verdict. */
  .verdict {
    --v: var(--color-info-text); --icon: var(--icon-circle-minus);
    padding: var(--space-4) var(--space-5); border-radius: var(--radius-xl); border: var(--border-thin) solid var(--color-info-border);
    background: var(--color-info-bg);
  }
  .verdict--survives { --v: var(--color-success-text); --icon: var(--icon-circle-check); background: var(--color-success-bg); border-color: var(--color-success-border); }
  .verdict--narrow { --v: var(--color-caution-text); --icon: var(--icon-contrast); background: var(--color-caution-bg); border-color: var(--color-caution-border); }
  .verdict--rejected { --v: var(--color-danger-text); --icon: var(--icon-circle-x); background: var(--color-danger-bg); border-color: var(--color-danger-border); }
  .verdict__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-3); }
  .verdict__eyebrow { flex-basis: 100%; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text-muted); }
  .verdict__title, h2.verdict__title, h3.verdict__title {
    display: flex; align-items: center; gap: var(--space-2); margin: 0; margin-right: auto;
    font-size: var(--text-2xl); letter-spacing: var(--tracking-tight); color: var(--v);
  }
  .verdict__title::before { width: 1.5rem; height: 1.5rem; }
  .verdict__chip {
    --icon: var(--icon-triangle-alert);
    display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--control-height-sm); padding: 0 var(--space-3);
    border-radius: var(--radius-md); font-size: var(--text-sm); font-weight: var(--weight-medium); text-decoration: none;
    color: var(--color-danger-text); background: var(--color-surface); border: var(--border-thin) solid var(--color-danger-border); box-shadow: var(--shadow-xs);
  }
  .verdict__chip:hover { background: var(--color-danger-bg); text-decoration: none; }
  .verdict__body { margin-top: var(--space-2); font-size: var(--text-sm); color: var(--color-text); }
  .verdict__body > * + * { margin-top: var(--space-1); }
  @media (max-width: 40rem) {
    .verdict { padding: var(--space-3) var(--space-4); }
    .verdict__title, h2.verdict__title, h3.verdict__title { font-size: var(--text-xl); }
    .verdict__title::before { width: 1.25rem; height: 1.25rem; }
  }

  /* ---------------------------------------------------------------- next step (ui.next_step) */
  /* a Card: the label as its description above the title, the content, the actions as its footer row */
  .next-step {
    padding: var(--space-5); background: var(--color-surface);
    border: var(--border-thin) solid var(--color-border); border-radius: var(--radius-xl); box-shadow: var(--shadow-sm);
  }
  .next-step__eyebrow { font-size: var(--text-sm); color: var(--color-text-muted); }
  h2.next-step__title, h3.next-step__title { margin: var(--space-1) 0 0; font-size: var(--text-lg); letter-spacing: var(--tracking-tight); }
  .next-step__body { max-width: calc(var(--measure) + 10rem); }
  .next-step__body > * { margin-top: var(--space-3); }
  .next-step__body > .actions { margin-top: var(--space-4); }
  @media (max-width: 40rem) { .next-step { padding: var(--space-4); } }

  /* ---------------------------------------------------------------- page header (ui.page_header) */
  /* shadcn Breadcrumb above the one h1 (text-2xl, semibold, tight), ONE description line, the actions at the right */
  .page-header {
    display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
    gap: var(--space-4); margin-bottom: var(--space-5);
  }
  .page-header__main { min-width: 0; flex: 1 1 24rem; }
  .breadcrumb { margin-bottom: var(--space-2); font-size: var(--text-sm); color: var(--color-text-muted); }
  .breadcrumb__list { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; margin: 0; padding: 0; list-style: none; }
  .breadcrumb__list > li { margin: 0; display: inline-flex; align-items: center; }
  .breadcrumb__link { color: var(--color-text-muted); font-weight: var(--weight-regular); text-decoration: none; transition: color 0.15s; }
  .breadcrumb__link:hover { color: var(--color-text); text-decoration: none; }
  .breadcrumb__sep::before { --icon: var(--icon-chevron-right); width: 0.875rem; height: 0.875rem; }
  .page-header__title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
  .page-header__title h1 { overflow-wrap: anywhere; font-size: var(--text-2xl); letter-spacing: var(--tracking-tight); }
  .page-header__meta { margin-top: var(--space-1); font-size: var(--text-sm); color: var(--color-text-muted); }
  .page-header__meta span + span::before { content: "·"; margin: 0 var(--space-2); }
  .page-header__actions { margin-top: 0; }
  @media (max-width: 40rem) {
    .page-header h1 { font-size: var(--text-xl); }
    .page-header__actions { width: 100%; }
    /* printing from a phone is rare: the print button gives its room to the verdict (the browser's menu prints) */
    .page-header__actions > [data-print] { display: none; }
  }

  /* ---------------------------------------------------------------- disclosure (ui.disclosure) */
  /* shadcn Accordion on a native <details>: rows divided by a hairline, the trigger text-sm medium,
     its chevron at the right turning on open. One aligned row for every summary:
     marker (fixed width) | title (wraps under itself) | count | chevron */
  .disclosure { border-top: var(--border-thin) solid var(--color-border); border-bottom: var(--border-thin) solid var(--color-border); }
  .disclosure + .disclosure { border-top: 0; }
  .disclosure__summary {
    --icon: var(--icon-chevron-down);
    display: flex; align-items: flex-start; gap: var(--space-3);
    padding: var(--space-4) 0; cursor: pointer; list-style: none; border-radius: var(--radius-sm);
    font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text); line-height: var(--leading-snug);
  }
  .disclosure__summary::-webkit-details-marker { display: none; }
  .disclosure__summary::after { margin-top: 0.125rem; color: var(--color-text-muted); transition: transform 0.2s; }
  .disclosure[open] > .disclosure__summary::after { transform: rotate(180deg); }
  .disclosure__summary:hover .disclosure__title { text-decoration: underline; text-underline-offset: 4px; }
  .disclosure__summary:focus-visible { outline: none; box-shadow: var(--focus-ring); }
  .disclosure__title { flex: 1 1 auto; min-width: 0; }
  .disclosure__marker { display: flex; flex: none; width: 6.5rem; }
  .disclosure__note { font-weight: var(--weight-regular); color: var(--color-text-muted); }
  .disclosure__count {
    flex: none; display: inline-grid; place-items: center; min-width: 1.5rem; height: 1.25rem; padding: 0 var(--space-2); border-radius: var(--radius-pill);
    font-size: var(--text-xs); font-weight: var(--weight-medium); font-variant-numeric: var(--font-numeric);
    color: var(--color-neutral-text); background: var(--color-neutral-bg);
  }
  .disclosure__body { padding: 0 0 var(--space-4); font-size: var(--text-sm); }
  .disclosure__body > * + * { margin-top: var(--space-3); }
  /* wide_open: always open beside the form on a wide screen (forms.js opens it), a disclosure on a phone */
  @media (min-width: 52.01rem) {
    .disclosure--wide-open { border: 0; }
    .disclosure--wide-open > .disclosure__summary { display: none; }
    .disclosure--wide-open > .disclosure__body { padding: 0; }
  }
  @media (max-width: 40rem) {
    .disclosure__marker { width: 5.75rem; }
    .disclosure__summary { gap: var(--space-2); }
  }

  /* quiet: shadcn Collapsible with a small text trigger inside a row (no rules); its body on a muted panel */
  .disclosure--quiet, .disclosure--quiet + .disclosure--quiet { border: 0; }
  .disclosure--quiet > .disclosure__summary {
    display: inline-flex; align-items: center; gap: var(--space-1); padding: var(--space-1) 0;
    font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-link);
  }
  .disclosure--quiet > .disclosure__summary::after { order: 2; margin-top: 0; width: 0.875rem; height: 0.875rem; color: inherit; }
  .disclosure--quiet > .disclosure__body {
    padding: var(--space-3); margin-bottom: var(--space-2); font-size: var(--text-sm);
    background: var(--color-surface-sunken); border: var(--border-thin) solid var(--color-border); border-radius: var(--radius-md);
  }

  /* ---------------------------------------------------------------- quote (ui.quote_reveal) */
  .quote-reveal { display: inline; }
  .quote-reveal__summary {
    display: inline; cursor: pointer; list-style: none; margin-left: var(--space-2);
    font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-link); text-decoration: underline; text-underline-offset: 4px;
  }
  .quote-reveal__summary::-webkit-details-marker { display: none; }
  .quote-reveal[open] > .quote { display: block; margin-top: var(--space-1); }

  /* ---------------------------------------------------------------- external link (ui.ext_link) */
  .ext-link::after { --icon: var(--icon-arrow-up-right); width: 0.875em; height: 0.875em; margin-left: 0.125em; vertical-align: -0.0625em; }

  /* ---------------------------------------------------------------- empty state (ui.empty_state) */
  /* shadcn Empty: a dashed outline, the title, one line, the one action */
  .empty {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3) var(--space-4);
    padding: var(--space-5); border: var(--border-thin) dashed var(--color-border-strong); border-radius: var(--radius-lg);
  }
  .empty__title { font-size: var(--text-md); font-weight: var(--weight-medium); letter-spacing: var(--tracking-tight); }
  .empty__text { margin-top: var(--space-1); color: var(--color-text-muted); font-size: var(--text-sm); max-width: var(--measure); }
  .empty__steps { margin-top: var(--space-3); padding-left: var(--space-5); font-size: var(--text-sm); }
  .empty__steps > li::marker { font-weight: var(--weight-medium); color: var(--color-text-muted); }

  /* ---------------------------------------------------------------- key-value list (ui.kv) */
  /* a Card holding a description list: label | value, rows divided by a hairline */
  .kv {
    display: grid; grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr); gap: 0;
    padding: var(--space-1) var(--space-5); background: var(--color-surface); font-size: var(--text-sm);
    border: var(--border-thin) solid var(--color-border); border-radius: var(--radius-xl); box-shadow: var(--shadow-xs);
  }
  .kv dt, .kv dd { padding: var(--space-3) 0; }
  .kv dt { padding-right: var(--space-5); } /* the hairline runs on under both columns */
  .kv dt:not(:first-of-type), .kv dt:not(:first-of-type) + dd { border-top: var(--border-thin) solid var(--color-border); }
  .kv dt { color: var(--color-text-muted); }
  .kv dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: var(--font-numeric); }
  @media (max-width: 40rem) {
    .kv { grid-template-columns: minmax(0, 1fr); padding: var(--space-1) var(--space-4); }
    .kv dt { padding-bottom: 0; padding-right: 0; }
    .kv dd { padding-top: var(--space-1); }
    .kv dt:not(:first-of-type) + dd { border-top: 0; }
  }

  /* ---------------------------------------------------------------- section navigation (ui.section_nav) */
  /* the Tabs list look for the links to the sections of a long page; a wide screen only: on a phone the
     titled sections and disclosures are the menu */
  .section-nav {
    display: flex; flex-wrap: nowrap; gap: 0; width: fit-content; max-width: 100%; margin: var(--space-5) 0; padding: 3px;
    overflow-x: auto; scrollbar-width: none; background: var(--color-surface-muted); border-radius: var(--radius-lg);
  }
  .section-nav a {
    flex: none; display: inline-flex; align-items: center; min-height: calc(var(--control-height) - 6px); padding: 0 0.625rem;
    border-radius: var(--radius-md); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text-muted); text-decoration: none;
    transition: color 0.15s, background-color 0.15s;
  }
  .section-nav a:hover { color: var(--color-text); background: var(--color-bg); box-shadow: var(--shadow-sm); }
  .section-nav a:focus-visible { outline: none; box-shadow: var(--focus-ring); }
  @media (max-width: 40rem) { .section-nav { display: none; } }

  /* ---------------------------------------------------------------- steps of a form (ui.steps) */
  /* One line at every width: numbered circles joined by a line, equally spaced; never wraps. Work states
     are neutral (SPEC design decision 1): done is a brand-tinted check, never green. */
  .steps__list { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 0; }
  .steps__item { flex: 1 1 0; min-width: 0; display: flex; align-items: center; margin: 0; }
  .steps__item + .steps__item { margin-top: 0; }
  .steps__item:last-child { flex: 0 1 auto; }
  /* the line to the next step fills the rest of the item */
  .steps__item:not(:last-child)::after {
    content: ""; flex: 1 1 auto; min-width: var(--space-3); height: var(--border-thin); margin: 0 var(--space-2);
    background: var(--color-border-strong);
  }
  .steps__item--done:not(:last-child)::after { background: var(--color-primary); }
  .steps__step {
    flex: none; display: inline-flex; align-items: center; gap: var(--space-2); min-width: 0; max-width: 100%; padding: var(--space-1);
    font: inherit; font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: var(--leading-tight);
    text-align: left; white-space: nowrap; color: var(--color-text-muted); background: none; border: 0; border-radius: var(--radius-md);
  }
  .steps__title { overflow: hidden; text-overflow: ellipsis; }
  button.steps__step { cursor: pointer; color: var(--color-text); }
  button.steps__step:hover { background: var(--color-accent); }
  button.steps__step:focus-visible { outline: none; box-shadow: var(--focus-ring); }
  .steps__no {
    flex: none; display: inline-grid; place-items: center; width: 1.75rem; height: 1.75rem; border-radius: 50%;
    font-size: var(--text-xs); font-weight: var(--weight-semibold); font-variant-numeric: var(--font-numeric);
    color: var(--color-text-muted); background: var(--color-surface); border: var(--border-thin) solid var(--color-border-strong);
  }
  .steps__item--current { flex-grow: 1.6; }
  .steps__item--current .steps__step { color: var(--color-text); font-weight: var(--weight-semibold); }
  .steps__item--current .steps__no { color: var(--color-on-primary); background: var(--color-primary); border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-brand-tint); }
  .steps__item--done .steps__no { font-size: 0; color: var(--color-primary); background: var(--color-brand-tint); border-color: var(--color-primary); }
  .steps__item--done .steps__no { position: relative; }
  /* the number stays for screen readers (font-size 0); the check sits on top of it, centred */
  .steps__item--done .steps__no::before { --icon: var(--icon-check); position: absolute; inset: 0; margin: auto; width: 0.875rem; height: 0.875rem; }
  .steps__item--reachable .steps__no { border-color: var(--color-primary); color: var(--color-primary); }
  /* wide: every title in full, the lines take what is left */
  @media (min-width: 52.01rem) { .steps__item, .steps__item--current { flex: 1 1 auto; } }
  /* narrower: only the current step keeps its title (the others are read out) */
  @media (max-width: 52rem) {
    .steps__item:not(.steps__item--current) .steps__title {
      position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
    }
    .steps__item:not(.steps__item--current) .steps__step { gap: 0; }
    /* the current title is never cut: the lines give way */
    .steps__item--current { flex: 0 0 auto; }
    .steps__item--current .steps__step { flex: none; }
    .steps__item--current .steps__title { overflow: visible; }
  }
  @media (max-width: 26rem) {
    .steps__no { width: 1.5rem; height: 1.5rem; }
    .steps__item:not(:last-child)::after { min-width: var(--space-2); margin: 0 var(--space-1); }
  }

  /* ---------------------------------------------------------------- sticky summary (ui.sticky_summary) */
  /* The core figures in one line at the top of the screen. Without JavaScript (or with after=none) it
     sticks in the flow. With after=…, forms.js marks <html class="js"> and switches the bar between
     hidden (the full figures are on screen) and shown (they have scrolled away); fixed, so the
     switch never moves the page. */
  .sticky-summary {
    position: sticky; top: 0; z-index: 6; padding: var(--space-2) 0;
    background: color-mix(in srgb, var(--color-bg) 92%, transparent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
    border-bottom: var(--border-thin) solid var(--color-border);
  }
  .sticky-summary__inner { max-width: var(--page-max); margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-6); }
  .sticky-summary__extra { flex: 1 1 100%; min-width: 0; }
  .sticky-summary__items { display: flex; flex: 1 1 auto; min-width: 0; gap: var(--space-2) var(--space-6); margin: 0; }
  .sticky-summary__item { display: grid; gap: 0; min-width: 0; }
  .sticky-summary__item dt { font-size: var(--text-xs); color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sticky-summary__item dd {
    margin: 0; font-size: var(--text-sm); font-weight: var(--weight-semibold); font-variant-numeric: var(--font-numeric); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; line-height: var(--leading-snug);
  }
  .sticky-summary__item dd > .badge { font-size: var(--text-xs); }
  .sticky-summary__item--negative dd { color: var(--color-danger-solid); }
  .sticky-summary__action { flex: none; margin-left: auto; }
  html.js .sticky-summary--after {
    position: fixed; left: 0; right: 0; margin: 0; padding: var(--space-2) var(--page-pad); box-shadow: var(--shadow-sm);
    transform: translateY(-110%); visibility: hidden;
    transition: transform 0.18s ease-out, visibility 0s linear 0.18s;
  }
  html.js .sticky-summary--after.is-shown { transform: none; visibility: visible; transition: transform 0.18s ease-out; }
  html:has(.sticky-summary) { scroll-padding-top: 5rem; }
  @media (max-width: 40rem) {
    html.js .sticky-summary--after { padding: var(--space-2) var(--page-pad-sm); }
    .sticky-summary__items { gap: var(--space-3); justify-content: space-between; }
    .sticky-summary__item dt { white-space: normal; overflow: visible; line-height: var(--leading-tight); }
    .sticky-summary__item { flex: 1 1 auto; }
    .sticky-summary__item:last-child:not(:first-child) { flex: none; text-align: right; }
    .sticky-summary__action, .sticky-summary__item--wide { display: none; }
    /* a field has the focus (the keyboard is up): the bar steps aside */
    html:has(main input:not([type=radio]):not([type=checkbox]):focus, main select:focus, main textarea:focus) .sticky-summary--after { visibility: hidden; }
  }
  @media (prefers-reduced-motion: reduce) { html.js .sticky-summary--after { transition: none; } }

  /* ---------------------------------------------------------------- how-to steps (ui.howto_steps) */
  .howto-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); list-style: none; padding: 0; margin: 0 0 var(--space-5); }
  .howto-steps__item { display: flex; align-items: flex-start; gap: var(--space-3); }
  .howto-steps__item + .howto-steps__item { margin-top: 0; }
  .howto-steps__n {
    flex: none; display: inline-flex; align-items: center; justify-content: center; width: 1.75rem; height: 1.75rem; border-radius: 50%;
    font-size: var(--text-xs); font-weight: var(--weight-semibold); font-variant-numeric: var(--font-numeric); color: var(--color-text);
    background: var(--color-surface); border: var(--border-thin) solid var(--color-border-strong);
  }
  .howto-steps__body { display: grid; gap: 2px; min-width: 0; padding-top: 0.15rem; }
  .howto-steps__title { font-weight: var(--weight-medium); }
  .howto-steps__text { font-size: var(--text-sm); color: var(--color-text-muted); line-height: var(--leading-snug); }
  .howto-steps__item--current .howto-steps__n { color: var(--color-on-primary); background: var(--color-primary); border-color: var(--color-primary); }
  .howto-steps__item--done .howto-steps__n { color: var(--color-text-muted); }
  .howto-steps__item--done .howto-steps__title { color: var(--color-text-muted); font-weight: var(--weight-regular); }
  @media (max-width: 40rem) {
    .howto-steps { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
    /* titles only (no texts): three short columns, number over title, so the page's action stays on the first screen */
    .howto-steps:not(:has(.howto-steps__text)) { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
    .howto-steps:not(:has(.howto-steps__text)) .howto-steps__item { flex-direction: column; align-items: center; gap: var(--space-1); text-align: center; }
    .howto-steps:not(:has(.howto-steps__text)) .howto-steps__title { font-size: var(--text-xs); }
    .howto-steps:has(.howto-steps__item--current) { display: flex; gap: var(--space-3); }
    .howto-steps:has(.howto-steps__item--current) .howto-steps__item:not(.howto-steps__item--current) .howto-steps__title { display: none; }
  }

  /* ---------------------------------------------------------------- drop area (ui.dropzone) */
  .dropzone {
    position: relative; display: grid; justify-items: center; gap: var(--space-1); padding: var(--space-7) var(--space-4);
    text-align: center; background: var(--color-surface-sunken); border: var(--border-thick) dashed var(--color-field-border);
    border-radius: var(--radius-xl); transition: border-color 0.15s, background-color 0.15s;
  }
  .dropzone:hover, .dropzone:focus-within { border-color: var(--color-primary); background: var(--color-brand-tint); }
  .dropzone__title { font-size: var(--text-lg); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); color: var(--color-text); }
  .dropzone__text { color: var(--color-text-muted); }
  .dropzone__touch { display: none; }
  @media (pointer: coarse) {
    .dropzone__fine { display: none; }
    .dropzone__touch { display: inline; }
  }
  @media (max-width: 40rem) {
    .dropzone { padding: var(--space-5) var(--space-3); }
    .dropzone .field { margin-top: var(--space-1); }
  }
  .dropzone .field { width: 100%; max-width: 28rem; margin-top: var(--space-3); justify-items: center; }
  .dropzone .field > label { font-weight: var(--weight-regular); color: var(--color-text-muted); }
  /* the native file input covers the whole area: a file dropped anywhere on it is taken */
  .dropzone input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
  .dropzone:has(input[type="file"]:focus-visible) { box-shadow: var(--focus-ring); }
  .dropzone .field-error { position: relative; }

  /* ---------------------------------------------------------------- tables (classes, no macro) */
  /* shadcn Table in the data-table frame: rounded-lg border, a muted head row in foreground medium (no
     capitals), rows divided by hairlines, hover muted/50, the total row like TableFooter. */
  .table-wrap {
    overflow-x: auto; background: var(--color-surface); border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-lg);
  }
  * + .table-wrap { margin-top: var(--space-3); }
  .data { width: 100%; font-size: var(--text-sm); line-height: var(--leading-snug); }
  .data th, .data td {
    padding: var(--space-2) var(--space-3); text-align: left; vertical-align: top;
    border-bottom: var(--border-thin) solid var(--color-border);
  }
  .data thead th {
    height: 2.5rem; font-size: var(--text-sm); font-weight: var(--weight-medium); letter-spacing: 0;
    color: var(--color-text); background: var(--color-surface-sunken); vertical-align: middle;
  }
  .data tbody th { font-weight: var(--weight-regular); }
  .data td, .data tbody th { font-variant-numeric: var(--font-numeric); }
  .data .num { text-align: right; white-space: nowrap; }
  .data .num .cell-sub { white-space: nowrap; }
  .data tbody tr:last-child > * { border-bottom: 0; }
  .data tr.sub > * { color: var(--color-text-muted); }
  .data tr.sub > th { padding-left: var(--space-6); }
  .data tr.total > * { font-weight: var(--weight-semibold); background: var(--color-surface-sunken); border-top: var(--border-thin) solid var(--color-border-strong); }
  .data .col-focus { background: color-mix(in srgb, var(--color-brand-tint) 70%, var(--color-surface)); }
  .data thead .col-focus { color: var(--color-primary); background: var(--color-brand-tint); }
  .data tbody tr:hover > * { background-color: var(--color-surface-sunken); }
  .data tbody tr:hover > .col-focus { background-color: var(--color-brand-tint); }
  .data .cell-sub { display: block; margin-top: 2px; color: var(--color-text-muted); font-size: var(--text-xs); font-weight: var(--weight-regular); }
  .data .title-cell a { color: var(--color-text); font-weight: var(--weight-medium); text-decoration: none; }
  .data .title-cell a:hover { text-decoration: underline; }
  .data .col-check { width: 2.5rem; padding-right: 0; }
  .data input[type="checkbox"] { width: 1rem; height: 1rem; margin: 0; accent-color: var(--color-primary); }
  .table-note { margin-top: var(--space-3); font-size: var(--text-sm); color: var(--color-text-muted); max-width: calc(var(--measure) + 10rem); }
  .table-bar {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-3);
    margin: var(--space-4) 0 var(--space-2); font-size: var(--text-sm); color: var(--color-text-muted);
  }
  @media (max-width: 40rem) {
    .data { font-size: 0.8125rem; }
    .data th, .data td { padding-left: var(--space-2); padding-right: var(--space-2); }
    /* phone: the first column (after the checkbox) stays, the others scroll sideways */
    .data--sticky tr > :first-child, .data--sticky .col-check + * {
      position: sticky; left: 0; z-index: 1; background: var(--color-surface);
      box-shadow: 1px 0 0 var(--color-border); min-width: 8.5rem; max-width: 11rem;
    }
    .data--sticky tr > .col-check { min-width: 2.5rem; max-width: 2.5rem; box-shadow: none; z-index: 2; }
    .data--sticky .col-check + * { left: 2.5rem; }
    .data--sticky thead tr > *:is(:first-child, .col-check + *) { background: var(--color-surface-sunken); }
    .data--sticky tr.total > :first-child { background: var(--color-surface-sunken); }
    /* .data--cards: on a phone every row is a card (title first, then each cell with its column
       name from data-label); the checkbox sits at the card's top right */
    .data--cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    /* the cards are as wide as the list, not as the table's content (at 375 px they were 374 px) */
    .data--cards, .data--cards tbody { display: block; width: 100%; }
    .data--cards .badge { white-space: normal; max-width: 100%; }
    .data--cards tbody tr {
      position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start;
      gap: var(--space-2) var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: var(--border-thin) solid var(--color-border);
    }
    .data--cards tbody tr:last-child { border-bottom: 0; }
    /* !important: the utilities layer's .num (right-aligned) comes later in the cascade */
    .data.data--cards tbody tr > * { display: block; padding: 0; border: 0; text-align: left !important; white-space: normal; }
    .data.data--cards tbody .title-cell { grid-column: 1 / -1; padding-right: var(--space-7); }
    .data.data--cards tbody .col-check { position: absolute; top: var(--space-3); right: var(--space-4); width: auto; }
    .data--cards td[data-label]::before {
      content: attr(data-label); display: block; margin-bottom: 2px; font-size: var(--text-xs); color: var(--color-text-muted);
    }
    .data--cards .num .cell-sub { white-space: normal; }
    .data--cards tbody tr:hover > * { background-color: transparent; }
  }

  /* ---------------------------------------------------------------- forms (_forms.html: field, choice, error_summary) */
  /* shadcn Field: label (text-sm, medium), the control, ONE description (behind the "?"), the error */
  .form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5) var(--space-5); }
  .form-grid > .field--wide { grid-column: 1 / -1; }
  .form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }  /* three values of one thing: Z low, base, high */
  :not(input[type="hidden"]) + .form-grid { margin-top: var(--space-4); }
  .form-stack > :not(input[type="hidden"], [hidden]) ~ * { margin-top: var(--space-4); }
  @media (max-width: 40rem) { .form-grid { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); } }

  .form-section {
    background: var(--color-surface); border: var(--border-thin) solid var(--color-border); border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm); padding: var(--space-5); margin: 0 0 var(--space-5);
  }
  .form-section > legend { float: left; width: 100%; margin-bottom: var(--space-4); }
  .form-section > legend + * { clear: both; }
  .form-section__title { font-size: var(--text-lg); letter-spacing: var(--tracking-tight); }
  @media (max-width: 40rem) { .form-section { padding: var(--space-4); } }

  .field { position: relative; display: grid; gap: var(--space-2); align-content: start; min-width: 0; }
  .field > label { font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: var(--leading-snug); }
  .field--has-help > label { padding-right: var(--space-6); }
  /* the "?" at the end of the label line (a ghost icon button); its text opens as a popover panel
     between the label and the control */
  .field__help > summary {
    position: absolute; top: -0.125rem; right: 0; display: inline-grid; place-items: center; width: 1.25rem; height: 1.25rem;
    cursor: pointer; list-style: none; border-radius: 50%; font-size: var(--text-xs); font-weight: var(--weight-semibold);
    color: var(--color-text-muted); border: var(--border-thin) solid var(--color-border-strong); background: var(--color-surface);
  }
  .field__help > summary::-webkit-details-marker { display: none; }
  .field__help > summary:hover, .field__help[open] > summary { color: var(--color-text); background: var(--color-accent); }
  .field__help > summary:focus-visible { outline: none; border-color: var(--color-focus); box-shadow: var(--focus-ring); }
  .field__help-text {
    padding: var(--space-2) var(--space-3); max-width: var(--measure); font-size: var(--text-sm); line-height: var(--leading-snug);
    color: var(--color-text); background: var(--color-popover);
    border: var(--border-thin) solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  }
  .field__help-text > p + p { margin-top: var(--space-2); }
  .field__optional { font-weight: var(--weight-regular); color: var(--color-text-muted); }
  /* The one look of a text field and a select (shadcn Input / Select trigger): every field of the macros
     and the inventory's filter row (.filters, the one place with hand-written labels). As tall as a button
     (--control-height); 16 px text on a phone (iOS zooms below), 14 px from 40rem; a select never draws
     the browser's own control (appearance none) and shows the lucide chevron of .select. */
  :is(.field, .filters) :is(input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea) {
    width: 100%; min-height: var(--control-height); padding: 0 var(--space-3); margin: 0;
    font-size: var(--text-md); font-weight: var(--weight-regular); line-height: var(--leading-tight);
    color: var(--color-text); font-variant-numeric: var(--font-numeric);
    background-color: var(--color-surface); border: var(--border-thin) solid var(--color-field-border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs); transition: border-color 0.15s, box-shadow 0.15s;
  }
  @media (min-width: 40.01rem) {
    :is(.field, .filters) :is(input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea) { font-size: var(--text-sm); }
  }
  :is(.field, .filters) :is(input, textarea)::placeholder { color: var(--color-text-muted); }
  .field textarea { min-height: 4rem; padding: var(--space-2) var(--space-3); line-height: var(--leading-body); resize: vertical; }
  :is(.field, .filters) input[type="search"] { -webkit-appearance: none; appearance: none; }
  /* a select sits in <span class="select">, whose ::after draws the chevron */
  .select { --icon: var(--icon-chevron-down); position: relative; display: block; color: var(--color-text-muted); }
  .select::after { position: absolute; top: 50%; right: var(--space-3); margin-top: -0.5rem; pointer-events: none; opacity: 0.8; }
  :is(.field, .filters) select {
    -webkit-appearance: none; appearance: none; padding-right: calc(var(--space-6) + var(--space-4)); cursor: pointer; text-overflow: ellipsis;
  }
  .field input[type="file"] { font-size: var(--text-sm); padding: var(--space-2) 0; color: var(--color-text-muted); }
  /* the browser's "choose file" button in the look of an outline button */
  .field input[type="file"]::file-selector-button {
    min-height: var(--control-height-sm); margin-right: var(--space-3); padding: 0 var(--space-3); cursor: pointer;
    font: inherit; font-weight: var(--weight-medium); color: var(--color-text);
    background: var(--color-surface); border: var(--border-thin) solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-xs);
  }
  .field input[type="file"]::file-selector-button:hover { background: var(--color-accent); }
  :is(.field, .filters) :is(input, select, textarea):hover { border-color: var(--color-field-border-hover); }
  :is(.field, .filters) :is(input, select, textarea):focus { outline: none; border-color: var(--color-focus); box-shadow: var(--focus-ring); }
  .field input[readonly] { background: var(--color-surface-sunken); color: var(--color-text-muted); box-shadow: none; }
  .field input[inputmode="numeric"], .field input[inputmode="decimal"] { text-align: right; }
  /* the unit beside a number (shadcn Input Group): one bordered box, the unit as a quiet addon inside it */
  .affix {
    display: flex; align-items: stretch; min-height: var(--control-height); background: var(--color-surface);
    border: var(--border-thin) solid var(--color-field-border); border-radius: var(--radius-md); box-shadow: var(--shadow-xs);
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  .affix:hover { border-color: var(--color-field-border-hover); }
  .affix:focus-within { border-color: var(--color-focus); box-shadow: var(--focus-ring); }
  .field .affix > input:not([type="checkbox"]), .field .affix > input:not([type="checkbox"]):focus, .field .affix > input:not([type="checkbox"]):hover {
    min-width: 0; min-height: calc(var(--control-height) - 2px); border: 0; border-radius: var(--radius-md); background: transparent; box-shadow: none;
  }
  .affix__unit {
    display: inline-flex; align-items: center; justify-content: center; min-width: 2.75rem; padding: 0 var(--space-3); white-space: nowrap;
    color: var(--color-text-muted); font-size: var(--text-sm);
    border-left: var(--border-thin) solid var(--color-border);
  }
  .affix--pre .affix__unit { order: -1; border-left: 0; border-right: var(--border-thin) solid var(--color-border); }
  .affix--none .affix__unit { color: var(--color-text-muted); }
  .field__hint { font-size: var(--text-sm); color: var(--color-text-muted); line-height: var(--leading-snug); }
  .field-error { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-danger-text); }
  .field--error input:not([type="checkbox"], [type="radio"]), .field--error select, .field--error textarea, .field--error .affix {
    border-color: var(--color-danger-solid);
  }
  .field--error :is(input, select, textarea):focus, .field--error .affix:focus-within {
    border-color: var(--color-danger-solid); box-shadow: var(--focus-ring-danger);
  }

  /* forms.choice: shadcn Radio Group; with cards each option is a bordered field card */
  .choice { display: grid; gap: var(--space-2); }
  .choice > legend { margin-bottom: var(--space-2); font-size: var(--text-sm); font-weight: var(--weight-medium); }
  .choice__option {
    display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); cursor: pointer;
    background: var(--color-surface); border: var(--border-thin) solid var(--color-border); border-radius: var(--radius-lg);
    font-size: var(--text-sm); transition: border-color 0.15s, background-color 0.15s;
  }
  .choice__option:hover { background: var(--color-surface-sunken); }
  /* the radio drawn by CSS: a 16 px ring with a shadow-xs, an 8 px dot when chosen */
  .choice__option input[type="radio"] {
    -webkit-appearance: none; appearance: none; flex: none; display: inline-grid; place-items: center;
    width: 1rem; height: 1rem; margin: 0.125rem 0 0; border-radius: 50%; cursor: pointer;
    background: var(--color-surface); border: var(--border-thin) solid var(--color-field-border); box-shadow: var(--shadow-xs);
  }
  .choice__option input[type="radio"]::before {
    content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--color-primary); transform: scale(0);
    transition: transform 0.12s;
  }
  .choice__option input[type="radio"]:checked { border-color: var(--color-primary); }
  .choice__option input[type="radio"]:checked::before { transform: scale(1); }
  .choice__option input[type="radio"]:focus-visible { outline: none; } /* its option card draws the ring (:has) */
  .choice__option:has(input:checked) {
    border-color: var(--color-primary); background: color-mix(in srgb, var(--color-brand-tint) 60%, var(--color-surface));
  }
  .choice--error .choice__option { border-color: var(--color-danger-solid); }
  /* selection cards (forms.choice with cards): side by side, a bold label, an amount and one line under it */
  .choice--cards { grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: var(--space-3); min-width: 0; }
  .choice--cards > legend { grid-column: 1 / -1; float: left; width: 100%; }
  .choice--cards > .field__hint, .choice--cards > .field-error { grid-column: 1 / -1; }
  /* the help line sits under its legend like a field's hint, not a whole grid gap away */
  .choice--cards > legend + .field__hint { margin-top: calc(-1 * var(--space-3)); }
  .choice--cards .choice__option { padding: var(--space-4); }
  .choice__option:has(input:focus-visible) { border-color: var(--color-focus); box-shadow: var(--focus-ring); }
  .choice__body { display: grid; gap: 2px; min-width: 0; }
  .choice__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
  .choice__label { font-weight: var(--weight-medium); }
  .choice__amount { font-weight: var(--weight-semibold); font-variant-numeric: var(--font-numeric); white-space: nowrap; }
  .choice__note { font-size: var(--text-sm); color: var(--color-text-muted); line-height: var(--leading-snug); }

  .error-summary { margin-bottom: var(--space-5); }
  .error-summary:focus { outline: none; box-shadow: var(--focus-ring); }
}

/* ---------------------------------------------------------------- place (templates/_place.html) */
/* Kanton und Gemeinde from the address: a quiet read-only line as tall as a field, "ändern" at its
   right; the two selects open below it. */
@layer components {
  .place { display: grid; gap: var(--space-2); min-width: 0; }
  .place__label { font-size: var(--text-sm); font-weight: var(--weight-medium); }
  /* the place in one line, "ändern" at the right, where it was found in a quiet line under it */
  .place__summary {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 2px var(--space-3);
    min-height: var(--control-height); padding: var(--space-2) var(--space-3); cursor: pointer; list-style: none;
    background: var(--color-surface-sunken); border: var(--border-thin) solid var(--color-border); border-radius: var(--radius-md);
  }
  .place__summary::-webkit-details-marker { display: none; }
  .place__summary:hover { border-color: var(--color-field-border); }
  .place__summary:focus-visible { outline: none; box-shadow: var(--focus-ring); }
  .place__value { font-weight: var(--weight-medium); }
  .place__note, .place__hint { font-size: var(--text-sm); color: var(--color-text-muted); }
  .place__note { grid-column: 1 / -1; grid-row: 2; }
  .place__sep { display: none; }
  .place__change { grid-column: 2; grid-row: 1; }
  .place__note--alone { grid-column: 1; grid-row: 1; }
  .place__change { justify-self: end; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-link); text-decoration: underline; text-underline-offset: 4px; }
  .place__fields { margin-top: var(--space-3); }
  .place__hint + .place__fields { margin-top: 0; }
  .place__outside { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-danger-text); }
}
