/*
 * Shared styles: base, layout and the components every page uses.
 * Tokens come from /theme/theme.css (linked first). Colours, font sizes and
 * spacing are var(--token) only; 0 and 1px hairlines are the only literals
 * (test/stylesheet-literals.test.js greps every public/css/*.css file).
 *
 * CLASS CONTRACT (views and public/js/ depend on these names)
 *
 *   Layout        .site-header > .site-brand (> .site-logo + title text) + .site-menu
 *                 .site-main (.site-main-wide for tables)  .breadcrumbs (nav > ol > li)
 *                 .back-link (every "Back to ..." link, one style)  .stack (vertical rhythm)  .lede  .muted  .meta
 *                 Rhythm: blocks sit --space-4 apart; a heading has --space-5 above it and less below
 *                 (--space-3 under an h1, --space-2 under an h2/h3), except inside a .card. Paragraph text is
 *                 capped at --measure. A .field-hint under a button or .btn-row sits --space-2 below it.
 *                 Cards and rows use --card-pad inside and --list-gap between them.
 *   Front photo   .front-split (public.css; only when branding holds a photo) > .hero + .front-photo (> img) + .front-cta + .front-signin (only when sign-in is on; holds the .sign-in-card).
 *                 One column on a phone in that order; from 48em two columns, photo on the right, top aligned.
 *                 A .site-main holding one is as wide as .site-main-wide. No other page uses it.
 *   Buttons       .btn plus one of .btn-primary .btn-secondary .btn-quiet .btn-danger;
 *                 .btn-inline (not full width)  .btn-row (buttons, or forms holding one, side by side
 *                 while every label fits on one line; a button whose label does not fit goes on its own
 *                 line at full width; buttons in a row share a height)
 *                 Works on <a> and <button>.
 *   Reachable     form[data-reachable] (public signup, member and admin person forms) carries the "every person must
 *                 be reachable" rule to the browser; the server check stays the authority. Value "household" means
 *                 the person is already in a household (name only); empty otherwise. Marked fields (data-reach):
 *                 "name" (the name input), "contact" (every email and phone input and every address street line,
 *                 including rows cloned from templates), "household" (the .field around the household select of the add form: a
 *                 chosen value means name only), "submit" (the submit button) and "hint" (the .submit-hint
 *                 <p aria-live="polite">, rendered empty, the button's aria-describedby points at it). Wrap the
 *                 two in .submit-row (src/views/fragments/forms.js submitRow). site.js, on load, input, change
 *                 and htmx swaps, sets aria-disabled="true" on the button (inactive look, still focusable) and
 *                 writes what is missing into the hint; a submit attempt then is stopped before htmx and focus
 *                 goes to the first missing field. Without JavaScript nothing is disabled.
 *   Forms         form.form  .field (label + .field-hint + control + .field-error)
 *                 .field-label  .field-hint  .field-error  .required-mark
 *                 error state: aria-invalid="true" on the control
 *                 .field-pair (two columns)  .check-row (label wrapping a checkbox or radio)
 *                 .hp (honeypot, off screen)
 *   "+" pattern   Without JavaScript everything is shown and the buttons below are hidden.
 *                 With JavaScript (public/js/head.js adds class "js" to <html>, public/js/site.js
 *                 does the rest by event delegation, so later-added content needs no rebinding):
 *
 *                 Reveal sections
 *                 .optional        a section the server ALWAYS renders visible (no `hidden`),
 *                                  with data-open="true" when it holds a value or an error.
 *                                  It has an id. On load JS sets `hidden` on every .optional
 *                                  that lacks data-open="true".
 *                 .reveal          button, aria-controls=<id of the .optional>, aria-expanded
 *                                  (JS sets "false" for a collapsed section, "true" for an open
 *                                  one). It is shown only while the section is collapsed: JS sets
 *                                  `hidden` on it when the section is open. Click: shows the
 *                                  section, hides the button, focuses the first field.
 *                 .remove-section  button inside an .optional (type="button"). JS only. Click:
 *                                  clears every field in the section (text/textarea emptied,
 *                                  select to its first option, checkbox/radio unticked,
 *                                  aria-invalid removed; error text is left alone), hides the
 *                                  section, shows the .reveal button and focuses it.
 *
 *                 Add another (repeating rows)
 *                 .repeat-rows     container, id required. data-next-index="<n>" is the next
 *                                  unused row number (server-set; JS increments it). Optional
 *                                  data-max="<n>": at most n .repeat-row children; the add
 *                                  button is hidden at the max and shown again after a removal.
 *                 .repeat-row      one row (direct child of .repeat-rows)
 *                 <template class="row-template" id=...>  holds one blank .repeat-row. In the
 *                                  attributes name, id, for, aria-controls, aria-describedby
 *                                  and value the text __N__ stands for the row number: the
 *                                  template writes name="phone___N__" (that is `phone_` then
 *                                  `__N__`) and the clone gets name="phone_3". Server-rendered
 *                                  rows use the same pattern with their own numbers (phone_0,
 *                                  phone_1, ...). The server must parse whatever numbers
 *                                  arrive (not contiguous, not in order) and ignore rows whose
 *                                  fields are all empty.
 *                 .add-another     button, data-template=<template id>, data-target=<.repeat-rows
 *                                  id>. Click: clones the template, replaces every __N__ with
 *                                  data-next-index, appends the row, focuses its first field.
 *                 .remove-row      button inside a .repeat-row. Click: removes the row, focuses
 *                                  the matching .add-another button.
 *                 .add-buttons     container for several .reveal / .add-another buttons
 *
 *                 Login tick
 *                 input[type=checkbox][data-requires=<id of a field>]: ticked, the field gets
 *                 `required` and aria-required="true" and the .required-mark inside
 *                 label[for=<field id>] loses `hidden`; unticked reverses it. Applied on load.
 *                 Write the mark as <span class="required-mark" hidden>(required)</span>.
 *
 *                 Copy
 *                 .copy-value      inline wrapper: the value (a link, or any element) then
 *                                  the button, so the icon sits right after the value.
 *                 .copy-btn        button, data-copy="<text to copy>", aria-label and title
 *                                  naming what is copied. Optional
 *                                  data-copy-select=<id of the element showing the value>
 *                                  (default: the button's previous sibling element). Holds two
 *                                  aria-hidden svgs: .icon-copy (shown) and .icon-check (shown
 *                                  instead while data-copied="true"). Click: writes to the
 *                                  clipboard, announces "Copied" and shows the check mark for
 *                                  2 seconds. If the clipboard is unavailable it selects the
 *                                  value element's text and announces "Press and hold to copy".
 *                                  Fragment: src/views/fragments/copy.js.
 *
 *                 Submit on change
 *                 form[data-autosubmit]  a plain (non-htmx) form whose radios, checkboxes and selects
 *                                  take effect when changed: JS submits the form on `change`
 *                                  (once; later changes wait for the page load). Under .js its
 *                                  submit button is not drawn; without JavaScript it is the way
 *                                  to submit. Used by the menu's text-size picker.
 *                 .live-region     role="status" aria-live="polite" element, visually hidden;
 *                                  the layout renders one at the end of <body>.
 *   After swaps   htmx swaps (public/js/site.js listens for htmx:afterSwap and, for
 *                 out-of-band hx-swap-oob replacements, htmx:oobAfterSwap on document). In the
 *                 swapped-in content, an element with data-focus gets focus (JS gives it
 *                 tabindex="-1" when it is not focusable); an element with data-announce="text"
 *                 has its text put in .live-region. Nothing moves focus while the user is typing
 *                 in a field inside the element that sent the request. No hx-on, no inline script.
 *   Content       .card  .card-list (ul of cards)  .list (ul)  .list-row (a or div row;
 *                 children .list-row-main, .list-row-meta)  .avatar  .chip  .letter
 *                 .details (dl, each dt/dd pair in a div)
 *                 .tabs (nav > ul > li > a, one row that scrolls sideways when it does not fit; the selected link has aria-current="page" from the server,
 *                 aria-selected="true" once site.js runs)  .tab-count (badge inside a tab or heading)
 *   Tabs          src/views/fragments/tabs.js renders .tabset[data-tabs][data-tabs-param="tab"]:
 *                 a nav.tabs whose links carry data-tab="slug" and href="?param=slug", then one
 *                 section.tab-panel[data-tab-panel="slug"] per tab, the starting one also marked
 *                 data-selected, each opening with h2.tab-panel-heading. Without JavaScript every
 *                 panel shows as a stacked section. site.js (every [data-tabs], marked
 *                 data-tabs-ready) adds role tablist/tab/tabpanel, aria-selected, aria-controls,
 *                 aria-labelledby and roving tabindex, hides the other panels with [hidden], and on
 *                 selection calls history.replaceState with only that set's param changed. Under the
 *                 .js class the panel headings are visually hidden (the tab list shows them) and
 *                 panels without data-selected are not drawn.
 *   Alerts        .alert plus .alert-error / .alert-info / .alert-success;
 *                 .error-summary (an .alert-error holding a list of links to fields)
 *   Notices       The status notice an in-place (HTMX) answer shows at the top of the region it changed
 *                 (src/views/fragments/notice.js): an .alert-success with data-announce="<text>" (site.js
 *                 puts it in .live-region once, so it has no role) and data-dismiss="5000". site.js
 *                 removes a data-dismiss element that arrives in a swap after that many ms, pausing while
 *                 the pointer is over it or focus is in it and restarting the full time when they leave.
 *                 It first gets .is-fading (opacity transition, --duration-fade); with
 *                 prefers-reduced-motion it is removed at once. <html data-dismiss-ms="<ms>"> overrides
 *                 the delay (tests only). Notices in a full page load are never touched. An error notice
 *                 is an .alert-error role="alert" and never goes away on its own.
 *                 A request that got no answer (network error, timeout) makes site.js insert
 *                 <p class="alert alert-error" role="alert" data-failure> at the top of the request's
 *                 region (after its heading); the next request from that region removes it.
 *   Working state While a request is in flight htmx adds .htmx-request to the form (or to the element named by
 *                 hx-indicator) and hx-disabled-elt="find button[type=submit]" disables the form's submit
 *                 button; the button looks busy (cursor, --opacity-busy). site.js sets aria-busy="true" on the
 *                 request's target for the same time. .htmx-indicator is a line hidden until it carries
 *                 .htmx-request ("Searching..." in the directory and admin people searches, pointed at by
 *                 hx-indicator on the search form). htmx's own indicator styles are off.
 *   Tables        .table-scroll wraps a <table> so it scrolls sideways on a phone
 *   Paging        .pager (nav: Previous, "Page n of m", Next)
 *   Form region   .form-region (an error summary and its form, replaced as one by HTMX; has a stable id; same spacing as page siblings)
 *   Results       .results (a search's count, list and pager, replaced as one by HTMX; has a stable id)
 *   Menu          .menu (the menu page's stack: more room under its heading)
 *   Helpers       .visually-hidden (alias .sr-only)  [hidden] always wins
 */

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

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-family);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
}

h1, h2, h3 {
  margin: 0;
  font-weight: var(--font-weight-heading);
  line-height: var(--lh-heading);
  text-wrap: balance;
}
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }
p { margin: 0 0 var(--space-2); }
.site-main p, .site-main .lede { max-width: var(--measure); }

a {
  color: var(--accent);
  text-underline-offset: var(--border-w);
}
a:hover { color: var(--accent-hover); }

:focus-visible,
.error-summary:focus {
  outline: var(--focus-w) solid var(--focus);
  outline-offset: var(--border-w);
}

.visually-hidden, .sr-only, .live-region, .js .tab-panel-heading {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- Layout ---------- */

.site-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.site-brand {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: 1;
  min-width: 0;
  color: var(--ink);
  font-weight: var(--font-weight-heading);
  text-decoration: none;
}
.site-brand:hover { color: var(--ink); }
.site-logo { width: var(--logo); height: var(--logo); flex: none; }
.site-menu {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--tap);
  padding: 0 var(--space-2);
  border: var(--border-w) solid var(--control-border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-small);
  font-weight: var(--font-weight-strong);
  text-decoration: none;
  cursor: pointer;
}
.site-menu:hover { color: var(--ink); background: var(--chip); }

.site-main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-4) var(--gutter) var(--space-5);
}
.site-main-wide { max-width: var(--max-width-wide); }
.site-main > * + * { margin-top: var(--space-4); }
/* A heading belongs to what follows it: more room above than below. */
:is(.site-main, .stack, .form-region, .results, .tab-panel) > * + h2 { margin-top: var(--space-5); }
.site-main :is(h1, h2, h3) + * { margin-top: var(--space-2); }
.site-main h1 + * { margin-top: var(--space-3); }
.card :is(h1, h2, h3) + * { margin-top: 0; }
.js .tab-panel-heading + * { margin-top: 0; }

.stack > * + * { margin-top: var(--space-2); }
.lede { color: var(--muted); }
.muted, .meta { color: var(--muted); }
.meta { font-size: var(--fs-small); }

.breadcrumbs { font-size: var(--fs-small); color: var(--muted); }
.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}
.breadcrumbs li + li::before { content: "/"; margin-right: var(--space-1); }
.breadcrumbs a { color: var(--muted); }

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  font-size: var(--fs-small);
  font-weight: var(--font-weight-strong);
  text-decoration: none;
}

/* ---------- Buttons ---------- */

:where(button) {
  font: inherit;
  cursor: pointer;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  width: 100%;
  min-height: var(--control-h);
  margin: 0;
  padding: 0 var(--space-3);
  border: var(--border-w) solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: var(--font-weight-strong);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-secondary { background: var(--surface); color: var(--accent); border-color: var(--accent); }
.btn-secondary:hover { background: var(--accent-soft); color: var(--accent); }
.btn-quiet { background: transparent; color: var(--accent); border-color: var(--line); }
.btn-quiet:hover { background: var(--chip); color: var(--accent); }
.btn-danger { background: var(--surface); color: var(--error); border-color: var(--error); }
.btn-danger:hover { background: var(--error-soft); color: var(--error); }
.btn-inline { width: auto; display: inline-flex; }
/* Not sendable yet (form[data-reachable]): inactive look, still focusable, the focus ring unchanged. */
.btn[aria-disabled="true"], .btn[aria-disabled="true"]:hover { background: var(--chip); color: var(--muted); border-color: var(--line); cursor: not-allowed; }
/* Each item keeps the width of its label (flex-basis auto), so a row that does not fit wraps whole
   buttons onto their own lines, which then grow to full width; items in a row stretch to one height. */
.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.btn-row > * { flex: 1 1 auto; margin: 0; }
.btn-row > form { display: flex; }
.btn-row .btn { flex: 1 1 auto; width: auto; display: flex; }

/* ---------- Forms ---------- */

.form { display: grid; gap: var(--space-3); }
.field { display: grid; gap: var(--space-1); margin: 0; }
fieldset.field { min-width: 0; padding: 0; border: 0; }
.field-label, .field > label { font-weight: var(--font-weight-strong); }
.required-mark { font-weight: 400; color: var(--muted); font-size: var(--fs-small); }
.field-hint { margin: 0; color: var(--muted); font-size: var(--fs-small); line-height: var(--lh-body); }
.btn + .field-hint, .btn-row + .field-hint { margin-top: var(--space-2); }
.submit-hint:empty { margin: 0; }
.field-error { margin: 0; color: var(--error); font-weight: var(--font-weight-strong); font-size: var(--fs-small); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }

:where(input:not([type="checkbox"], [type="radio"], [type="hidden"]), select, textarea) {
  display: block;
  width: 100%;
  min-height: var(--control-h);
  margin: 0;
  padding: 0 var(--space-2);
  border: var(--border-w) solid var(--control-border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
:where(textarea) {
  min-height: calc(var(--control-h) * 2);
  padding: var(--space-2);
  resize: vertical;
}
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--error);
}

input[type="checkbox"], input[type="radio"] {
  flex: none;
  width: var(--check);
  height: var(--check);
  margin: 0;
  accent-color: var(--accent);
}
.check-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--card-pad);
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 400;
  cursor: pointer;
}
.check-row strong { display: block; }
.js form[data-autosubmit] button[type="submit"] { display: none; }
.hp { position: absolute; left: -100%; width: 1px; height: 1px; overflow: hidden; }

/* ---------- The "+" pattern ---------- */

.reveal, .add-another, .copy-btn { display: none; }
.js .reveal, .js .add-another { display: flex; }
.js .copy-btn { display: inline-flex; }

.reveal, .add-another {
  align-items: center;
  gap: var(--space-1);
  width: 100%;
  min-height: var(--control-h);
  margin: 0;
  padding: 0 var(--space-3);
  border: var(--border-w) dashed var(--control-border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: var(--font-weight-strong);
  text-align: left;
  cursor: pointer;
}
/* The round "+" before the label; decorative, so the accessible name stays the text. */
.reveal::before, .add-another::before {
  content: "+";
  content: "+" / "";
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--icon);
  height: var(--icon);
  padding: var(--border-w);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  line-height: 1;
}
.reveal:hover, .add-another:hover { background: var(--accent-soft); }
.reveal:hover::before, .add-another:hover::before { background: var(--surface); }
.reveal[aria-expanded="true"] { background: var(--accent-soft); }

.optional {
  display: grid;
  gap: var(--space-2);
  padding: var(--card-pad);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.repeat-rows { display: grid; gap: var(--space-2); }
.repeat-row { display: grid; gap: var(--space-2); }
.remove-row {
  justify-self: start;
  min-height: var(--tap);
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-small);
  text-decoration: underline;
  text-underline-offset: var(--border-w);
  cursor: pointer;
}
.add-buttons { display: grid; gap: var(--space-1); }

/* One list of phones or emails (views/fragments/forms.js): each row a small card with its Main tick and Remove. */
.contact-list { gap: var(--space-2); }
.contact-list .repeat-row, #address-rows .repeat-row {
  padding: var(--space-2) var(--card-pad);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.contact-list .repeat-row { grid-template-columns: 1fr auto; align-items: center; }
.contact-list .repeat-row > .field { grid-column: 1 / -1; }
.check-main { padding: 0; border: 0; background: transparent; align-items: center; }
.remove-row { display: none; }
.js .remove-row { display: inline-flex; align-items: center; }
.remove-section { display: none; }
.js .remove-section {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  min-height: var(--tap);
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-small);
  text-decoration: underline;
  text-underline-offset: var(--border-w);
  cursor: pointer;
}

/* A link-like icon right after a value. The hit area is --tap square, but the negative margin
   gives back the padding so the line stays tight. */
.copy-btn {
  flex: none;
  align-items: center;
  justify-content: flex-start;
  box-sizing: border-box;
  min-width: var(--tap);
  min-height: var(--tap);
  /* The hit area is finger-sized but grows only right and vertically, never back over
     the value it follows, so a tap on the number still calls and a tap on the icon copies. */
  margin: calc((var(--icon) - var(--tap)) / 2) calc(var(--icon) - var(--tap)) calc((var(--icon) - var(--tap)) / 2) var(--space-1);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--accent);
  font: inherit;
  vertical-align: middle;
  cursor: pointer;
}
.copy-btn svg { width: var(--icon); height: var(--icon); }
.copy-btn .icon-check, .copy-btn[data-copied] .icon-copy { display: none; }
.copy-btn[data-copied] .icon-check { display: block; }
.copy-btn:hover svg { stroke-width: 2.5; }
.copy-value { display: inline; min-width: 0; }

/* ---------- Content ---------- */

.card {
  display: grid;
  gap: var(--space-2);
  padding: var(--card-pad);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.card-list, .list { display: grid; gap: var(--list-gap); margin: 0; padding: 0; list-style: none; }
.card-list > li { margin: 0; }

.list-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-2);
  align-items: center;
  min-height: calc(var(--tap) + var(--space-3));
  padding: var(--space-2) var(--card-pad);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
}
a.list-row:hover { background: var(--chip); color: var(--ink); }
.list-row-main { min-width: 0; }
.list-row-main strong { display: block; }
.list-row-meta { display: block; color: var(--muted); font-size: var(--fs-small); overflow-wrap: anywhere; }

.avatar {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  flex: none;
  border-radius: 50%;
  background: var(--chip);
  color: var(--ink);
  font-size: var(--fs-small);
  font-weight: var(--font-weight-strong);
}
.chip {
  display: inline-block;
  padding: 0 var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--chip);
  color: var(--ink);
  font-size: var(--fs-small);
}
.letter {
  padding-top: var(--space-1);
  color: var(--muted);
  font-size: var(--fs-small);
  font-weight: var(--font-weight-strong);
}

.details { display: grid; gap: var(--space-2); margin: 0; }
.details > div {
  display: grid;
  gap: 1px;
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--line);
}
.details > div:last-child { padding-bottom: 0; border-bottom: 0; }
.details dt { color: var(--muted); font-size: var(--fs-small); }
.details dd { margin: 0; overflow-wrap: anywhere; }

/* One row that scrolls sideways when the tabs do not fit; the padding (given back sideways by the
   negative margin) keeps the focus ring of the pills from being clipped. */
.tabs {
  --tabs-room: calc(var(--focus-w) + var(--border-w));
  margin-inline: calc(var(--tabs-room) * -1);
  padding: var(--tabs-room);
  overflow-x: auto;
  scrollbar-width: thin;
}
.tabs ul { display: flex; flex-wrap: nowrap; gap: var(--space-1); width: max-content; margin: 0; padding: 0; list-style: none; }
.tabs a {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--tap);
  padding: 0 var(--space-2);
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-small);
  font-weight: var(--font-weight-strong);
  text-decoration: none;
}
.tabs a { white-space: nowrap; }
.tabs a[aria-current="page"], .tabs a[aria-selected="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.tab-count {
  min-width: var(--space-4);
  padding: 0 var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--chip);
  color: var(--ink);
  font-size: var(--fs-small);
  text-align: center;
}
.tabs a[aria-current="page"] .tab-count, .tabs a[aria-selected="true"] .tab-count { background: var(--on-accent); color: var(--accent); }
/* No flash before site.js runs: only the selected panel (data-selected, kept in step by site.js) is drawn. Without JS (no .js class) all show. */
.js .tabset > .tab-panel:not([data-selected]) { display: none; }
.tabset > .tab-panel > .tab-panel-heading { margin-top: 0; }

/* ---------- Alerts ---------- */

.alert {
  padding: var(--space-2) var(--space-3);
  border-left: calc(var(--border-w) * 2) solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--ink);
  font-size: var(--fs-small);
}
.alert > :last-child { margin-bottom: 0; }
/* A card is a grid: its gap already spaces the notice, and margins do not collapse into it. */
.card > .alert { margin-bottom: 0; }
.alert-error, .error-summary { border-left-color: var(--error); background: var(--error-soft); }
.alert-success { border-left-color: var(--success); background: var(--success-soft); }
.alert a { color: var(--ink); font-weight: var(--font-weight-strong); }
.alert[data-dismiss] { transition: opacity var(--duration-fade) ease-out; }
.alert.is-fading { opacity: 0; }
@media (prefers-reduced-motion: reduce) {
  .alert[data-dismiss] { transition: none; }
}

/* ---------- Working state (htmx request classes) ---------- */

.htmx-request button[type="submit"], button.htmx-request { cursor: progress; opacity: var(--opacity-busy); }
[aria-busy="true"] { cursor: progress; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: block; }
.error-summary ul { margin: var(--space-1) 0 0; padding-left: var(--space-3); }

.site-main > .results { margin-top: var(--space-2); }
.form-region > * + * { margin-top: var(--space-4); }
.results > * + * { margin-top: var(--space-4); }
.results > .card-list { margin-top: 0; }
.pager { display: flex; gap: var(--space-3); align-items: center; margin-top: var(--space-3); }

/* ---------- Tables ---------- */

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-small); }
th, td {
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

/* ---------- Desktop ---------- */

@media (min-width: 48em) {
  .btn { width: auto; }
  .btn-row > * { flex: 0 1 auto; }
  .btn-row .btn { flex: 0 1 auto; }
  .tabs { margin-inline: 0; padding-inline: 0; overflow: visible; }
  .tabs ul { flex-wrap: wrap; width: auto; }
}

/* Standard: add buttons sit side by side only when each has room for its label. */
[data-mode="standard"] .add-buttons { grid-template-columns: repeat(auto-fit, minmax(calc(var(--tap) * 5), 1fr)); }
