/* MatterData — the single stylesheet.
   No framework, no build step, no inline <style> (the CSP forbids it).

   Design system: docs/09-design-system.md, which is binding. The short version:
   the page is a canvas, the content is the product, the UI gets out of the way.
   Neutral greys carry structure, blue carries links, black carries the one
   primary action, and the tenant's --accent is decorative only (§5): it never
   colours text, never fills a control, never signals state, and is never the
   only signal for anything. TestAccentIsContained fails the build if a fourth
   `var(--accent)` selector appears.

   Light is the default. Dark is opt-in and comes from a server-set cookie
   rendered as <html data-theme="dark"> — never from prefers-color-scheme, so
   there is no flash and the user's explicit choice always wins (§9).

   The engine serves this file from /static/app.<content-hash>.css and the one
   tenant-configured property from /theme.css (engine/internal/httpd/assets.go).
   It is embedded in the binary: ADR-4 is one static binary with no runtime
   file dependencies.

   Sections marked "slice 2" style markup the renderer does not emit yet
   (report tables, pagination, dialogs, stats). They are kept because the
   design system is the spec for them and re-deriving CSS from prose later is
   how a design system rots.
*/

/* ------------------------------------------------------------------ tokens */

:root {
  /* Tenant knob. /theme.css overrides this one value, nothing else. */
  --accent: #1d5b3a;

  /* Type scale (16px root). Six sizes; a seventh means the design is wrong. */
  --text-xs: 0.75rem;    /* 12 — tags, badges, table meta */
  --text-sm: 0.8125rem;  /* 13 — help texts, captions, column labels */
  --text-base: 0.9375rem;/* 15 — body copy, all controls */
  --text-lg: 1.125rem;   /* 18 — h2 */
  --text-xl: 1.5rem;     /* 24 — h1 */
  --text-2xl: 2rem;      /* 32 — stat numbers, error codes */

  /* Spacing scale — 4px base, six steps. */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;

  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;

  --maxw: 68rem;         /* the content column; the header and footer always */
  --maxw-narrow: 40rem;  /* a page's `width: narrow` — a reading measure */
  --maxw-wide: 90rem;    /* a page's `width: wide` (decision 0075) */
  --pane-w: 18rem;       /* a page's `aside` pane from 48rem up (decision 0075) */
  --control-h: 2.125rem; /* 34px — one height for inputs and buttons */
  --agenda-time-w: 4.5rem; /* the time cell of an agenda entry (§6.3, Agenda) */
  --card-min-w: 16rem;     /* the narrowest a card of the cards layout gets (§6.3, Cards) */
  --card-media-ratio: 16 / 9; /* the shape of a card's picture, fixed so a late image shifts nothing */
  --picture-min-w: 9rem;   /* the narrowest a picture of the editor's picker gets (decision 0111) */

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Light — the default for everyone, always. */
:root,
[data-theme="light"] {
  color-scheme: light;

  --bg: #ffffff;         /* the canvas */
  --surface: #ffffff;    /* cards, dialogs, table body */
  --surface-2: #fafafa;  /* the quiet fill: notes, hover, a banded table row */
  --surface-3: #f0f0f0;  /* one step up, and only where --surface-2 is taken */
  --border: #e6e6e6;     /* hairlines */
  --border-strong: #949494; /* control boundaries — 3:1 against --bg (WCAG 1.4.11) */

  --fg: #101010;         /* 18.9:1 on --bg */
  --fg-muted: #616161;   /*  6.1:1 on --bg — safe for real copy */
  --fg-subtle: #767676;  /*  4.5:1 — the quietest text that still passes AA */

  --link: #0b57d0;       /*  5.9:1 — links are blue, like the platform's own */
  --link-hover: #08429c;

  --solid-bg: #101010;   /* the one hot button: black */
  --solid-fg: #ffffff;
  --solid-bg-hover: #333333;

  --danger: #b42318;
  --danger-bg: #fef3f2;
  --warn: #8a5300;
  --warn-bg: #fff9ed;
  --ok: #0a6a3c;
  --ok-bg: #f0faf4;

  --ring: #0b57d0;       /* focus is blue and neutral, never the tenant accent */
  --shadow-lg: 0 10px 38px rgba(0, 0, 0, .12), 0 2px 8px rgba(0, 0, 0, .08);
  --backdrop: rgba(17, 17, 17, .38);
}

/* Dark — opt-in, same structure, same contrast promises. */
[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0a0a0a;
  --surface: #111111;
  --surface-2: #191919;
  --surface-3: #242424;
  --border: #272727;
  --border-strong: #6b6b6b; /* 3:1 against --bg */

  --fg: #ededed;         /* 16.4:1 on --bg */
  --fg-muted: #a1a1a1;   /*  7.4:1 */
  --fg-subtle: #8f8f8f;  /*  5.4:1 — the quietest text that still passes AA */

  --link: #8ab4f8;       /* 10.1:1 */
  --link-hover: #adc9fb;

  --solid-bg: #ededed;   /* black inverts to white; still not the accent */
  --solid-fg: #0a0a0a;
  --solid-bg-hover: #ffffff;

  --danger: #ff7b70;
  --danger-bg: #2a1512;
  --warn: #e8b046;
  --warn-bg: #241c0c;
  --ok: #4ec38a;
  --ok-bg: #0e2018;

  --ring: #8ab4f8;
  --shadow-lg: 0 10px 38px rgba(0, 0, 0, .6);
  --backdrop: rgba(0, 0, 0, .62);
}

/* Chart colour scale (docs/09 §6.15). A scale is three anchors — blue,
   purple, amber — and the steps between them are mixed in OKLab, so a
   different look is three custom properties and nothing else. A chart with k
   series takes k steps spread over the scale: one the first, two the first
   and last, three the first, middle and last, four those and the two a third
   of the way between. Few series stay far apart and a series never sits
   beside a near copy. Each anchor is at least 3:1 against --surface
   (TestChartAnchorsContrast); a step between two anchors of one scheme is
   lighter or darker than the darker of them by no more than they differ, so
   it stays above the same floor. Hue is never the only signal: series 3 and
   4 also carry a texture, a line series a dash. It is never the tenant accent
   (TestChartsNeverUseTheAccent). */
:root,
[data-theme="light"] {
  --chart-from: #003d5c;
  --chart-mid:  #a14e9a;
  --chart-to:   #c98300;
}
[data-theme="dark"] {
  --chart-from: #386880;
  --chart-mid:  #a14e9a;
  --chart-to:   #ffa600;
}
.chart {
  --chart-1: var(--chart-from);
  --chart-2: var(--chart-to);
  --chart-3: var(--chart-to);
  --chart-4: var(--chart-to);
}
.chart.chart-n3 { --chart-2: var(--chart-mid); }
.chart.chart-n4 {
  --chart-2: color-mix(in oklab, var(--chart-mid) 66.667%, var(--chart-from));
  --chart-3: color-mix(in oklab, var(--chart-to) 33.333%, var(--chart-mid));
}

/* ------------------------------------------------------------------- base */

* { box-sizing: border-box; }

/* `hidden` means hidden, whatever the element's own `display` says. The
   browser's rule for it is a plain `display: none` in the user-agent sheet, so
   any author rule that sets `display` wins against it: `.field { display:
   grid }` kept every `show_when:` field on screen while form.js had set
   `hidden` on it (decision 0037 §6), and `.btn` did the same to the invitation's
   copy button. One rule here instead of a `[hidden]` twin beside every block. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
@media (hover: hover) and (pointer: fine) { a:hover { color: var(--link-hover); } }

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

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }
h1, h2, h3, h4 { text-wrap: balance; }
h1 { font-size: var(--text-xl); font-weight: 600; margin: 0 0 var(--s1); }
h2 { font-size: var(--text-lg); font-weight: 600; margin: 0 0 var(--s2); }
h3 { font-size: var(--text-base); font-weight: 600; margin: 0 0 var(--s2); }
p { margin: 0 0 var(--s3); text-wrap: pretty; }
.lead { color: var(--fg-muted); margin: 0 0 var(--s4); }
.hint { color: var(--fg-muted); font-size: var(--text-sm); }

hr { border: 0; border-top: 1px solid var(--border); margin: var(--s5) 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Hidden with the `.sr-only` clip, never by moving it off-screen: a link at
   `left: -9999px` is 9999px of scrollable width in a right-to-left document,
   where the overflow is on the left. Clipped, it stays in the viewport at its
   static position and is still focusable; focus unclips it at the corner. */
.skip-link {
  position: absolute; z-index: 100;
  width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  background: var(--surface); color: var(--fg);
  border: 0; border-radius: var(--radius);
}
.skip-link:focus {
  width: auto; height: auto; margin: 0; overflow: visible; clip: auto;
  display: inline-flex; align-items: center; min-height: 44px;
  inset-inline-start: var(--s2); top: var(--s2);
  border: 1px solid var(--border);
  padding: var(--s2) var(--s4);
}

/* -------------------------------------------------------------- top bar */

/* The header is chrome, so it is quiet: two thin rows, one hairline, no fill
   other than the page background. Row 1 is identity, row 2 is navigation. */
.topbar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: relative;
}
/* The tenant's accent, allowed use #1: a 2px identity stripe that carries no
   text, no meaning and no state. */
.topbar::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 2px;
  background: var(--accent);
}

.topbar-row {
  max-width: var(--maxw); margin: 0 auto; padding: 0 var(--s5);
  display: flex; align-items: center; gap: var(--s4);
}
.topbar-identity { min-height: 3rem; }

.brand { display: flex; align-items: center; gap: var(--s2); text-decoration: none; color: inherit; }
/* Allowed accent use #2: the brand mark. A shape, never a label. */
.brand-mark {
  width: 0.875rem; height: 0.875rem; border-radius: 3px;
  background: var(--accent); flex: none;
}
.brand-name { font-weight: 600; font-size: var(--text-base); letter-spacing: -0.01em; }

.bar-end { margin-inline-start: auto; display: flex; align-items: center; gap: var(--s2); }
/* The account menu (§6.8). The address, the role and log out were three things
   side by side in the identity row; they are one control now, because two of
   the three were labels nobody acts on and the third is pressed roughly once a
   day. What is left in the row is a mark, an address and a chevron. */
.account-trigger {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: var(--control-h); max-width: 18rem;
  padding: var(--s1) var(--s2); border-radius: var(--radius);
  font-size: var(--text-sm); color: var(--fg-muted); cursor: pointer;
}
@media (hover: hover) and (pointer: fine) { .account-trigger:hover { background: var(--surface-2); color: var(--fg); } }
.popover-toggle:focus-visible + .account-trigger { outline: 2px solid var(--ring); outline-offset: 2px; }
/* An initial and not a face: the session knows an address and nothing else, and
   a login's profile row belongs to the app rather than to the chrome. Never the
   tenant accent — §5 keeps it off any surface carrying a glyph. */
.account-mark {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: var(--text-xs); font-weight: 500; color: var(--fg);
}
.account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-trigger .chevron { flex: none; color: var(--fg-subtle); }
.popover-toggle:checked + .account-trigger .chevron { transform: rotate(180deg); }
.account > .popover { min-width: 14rem; }

/* The app-wide scope selector (docs/09 §6.12, spec §5.2). A form, because the
   value it changes lives on the server and mutates state — so it goes through
   the one CSRF check and works with JavaScript off. Two controls side by side,
   both at --text-sm so the header keeps its 3rem row: the native <select> the
   engine's form fields already style, and a small secondary button. No accent
   anywhere — the scope is state, and §5's containment rule keeps state off the
   accent. */
.scope-switch { display: flex; align-items: center; gap: var(--s2); }
.scope-switch select {
  font-size: var(--text-sm);
  padding: calc(var(--s1) + 1px) var(--s2);
  max-width: 12rem;
}

/* The zone control (spec §7.11). Two shapes: a selector where the page follows
   its reader, and a plain word where the page names a zone of its own. Both
   sit beside the scope switch, because both answer a question about the whole
   page rather than about anything on it.

   No accent anywhere: a zone is neither a state nor an affordance, and
   docs/09's load-bearing rule allows the accent only on surfaces with no text,
   no state and no affordance. --fg-muted is the same weight the role badge in
   the same row carries. */
.tz-switch { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); min-width: 0; }
.tz-switch select {
  font-size: var(--text-sm);
  padding: calc(var(--s1) + 1px) var(--s2);
  max-width: 12rem;
}
/* The language selector (decision 0072 §5). The scope switch's shape and for
   its reasons: a form, a native <select> and a small secondary button, so it
   goes through the one CSRF check and works with JavaScript off. Each option
   is a language named in itself. No accent: a language is state. */
.lang-switch { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); min-width: 0; }
.lang-switch select {
  font-size: var(--text-sm);
  padding: calc(var(--s1) + 1px) var(--s2);
  max-width: 12rem;
}
/* The language links of a public page (decision 0072 §5). Each language of
   the page is an address of its own, so the control is a list of plain links
   and not a form: nothing is stored by following one. The current language is
   marked by weight and an underline as well as aria-current, never by colour
   alone, and no accent, for the selector's reason above. */
.lang-list { list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s1); margin: 0; padding: 0; }
.lang-list a {
  display: inline-flex; align-items: center; min-height: var(--control-h);
  padding: 0 var(--s2);
  color: var(--fg-muted); text-decoration: none; font-size: var(--text-sm);
}
@media (hover: hover) and (pointer: fine) { .lang-list a:hover { color: var(--fg); } }
.lang-list a[aria-current="true"] { color: var(--fg); font-weight: 500; text-decoration: underline; }
.tz-indicator {
  font-size: var(--text-sm);
  color: var(--fg-muted);
  white-space: nowrap;
}

/* Popover -------------------------------------------------------------------

   One floating surface, used by every overlay this engine draws: the menubar's
   group panels (§6.8), the phone's drawer, and the header's account menu. The
   shape is shadcn's popover, in our tokens.

   **Opening is not part of this component, and each user brings its own**,
   because the two ways of opening are genuinely different interactions and both
   have to work with no script (decision 0042):

     - the menubar's panels open on `:hover` / `:focus-within`, with their own
       selector, because a menu you walk through opens by being pointed at;
     - everything else opens on `.popover-toggle:checked` — a visually hidden
       checkbox with a `<label>` for its control — because it is pressed.

   `.popover-host` is the positioning context and **nothing else**. It carried a
   hover opener for one commit, which meant the account menu opened when the
   pointer merely crossed it and then could not be closed by pressing the
   trigger again: the pointer was still on it, so the hover rule held it open
   against the checkbox. A component that offers two openers to one element
   offers a contradiction.

   The platform's `popover` attribute would give light dismiss, Escape and the
   top layer for free and needs no script either — but a popover opens against
   the *viewport*, and putting one under its own trigger needs CSS anchor
   positioning, which is a year younger than the attribute and ~91 % supported.
   A browser without it would draw the account menu in the middle of the page.
   Decision 0042 records the numbers and what would change the answer. */

.popover {
  position: absolute; z-index: 40; top: calc(100% + var(--s2)); inset-inline-start: 0;
  display: flex; flex-direction: column; gap: 1px;
  min-width: 13rem; max-width: min(20rem, calc(100vw - var(--s6)));
  margin: 0; padding: var(--s2); list-style: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  visibility: hidden; opacity: 0;
}
/* Anchored to the right where the trigger is near the viewport's right edge —
   the header's account menu, the menubar's last two groups. */
.popover-end { inset-inline-start: auto; inset-inline-end: 0; }

.popover-host { position: relative; }

/* The pressed variant. The input is never seen — the label is the control —
   but it is what focus lands on, so the ring is drawn from it onto the label
   (decision 0040 §4, and now its second user). */
.popover-toggle {
  position: absolute; width: 1px; height: 1px; opacity: 0;
  margin: 0; pointer-events: none;
}
.popover-toggle:checked ~ .popover { visibility: visible; opacity: 1; }

/* A row inside a panel: a link, or a button in its own form. Full `--fg`,
   because a panel the reader opened is the thing they are reading. */
.popover-item {
  display: flex; align-items: center; gap: var(--s2);
  width: 100%; min-height: 2.25rem;
  padding: var(--s2) var(--s3); border: 0; border-radius: var(--radius-sm);
  background: none; font: inherit; font-size: var(--text-base);
  color: var(--fg); text-align: start; text-decoration: none; cursor: pointer;
  white-space: normal; overflow-wrap: anywhere;
}
@media (hover: hover) and (pointer: fine) { .popover-item:hover { background: var(--surface-2); color: var(--fg); } }

/* What the panel says about the reader rather than offers them: not a control,
   so it takes no hover and no pointer. */
.popover-meta { padding: var(--s2) var(--s3) var(--s3); margin: 0; }
.popover-meta-name { display: block; font-size: var(--text-sm); color: var(--fg); overflow-wrap: anywhere; }
.popover-meta-sub { display: block; font-size: var(--text-sm); color: var(--fg-muted); }
.popover-sep { height: 1px; margin: var(--s1) 0; border: 0; background: var(--border); }

/* A labelled list of links inside a panel: the account menu's apps (decision
   0105). The heading names the list and is not a control. The page the reader
   is in is marked by weight, so the mark is not colour alone. */
.popover-heading { margin: 0; padding: var(--s2) var(--s3) var(--s1); font-size: var(--text-sm); color: var(--fg-muted); }
.popover-list { display: flex; flex-direction: column; gap: 1px; margin: 0; padding: 0; list-style: none; }
.popover-item[aria-current] { font-weight: 600; }

/* The settings menu (decision 0104): what the reader prefers, in one panel
   under one icon in the identity row — the language, the zone times are read
   in and the colour scheme. Each preference was a control of its own in the
   header, two of them a select and a button, and an anonymous reader, who has
   no account menu, saw all of them on every page. The panel is `.popover`
   opened the way the account menu is, so it takes no new opener and no script
   beyond the Escape and outside-press `chrome.js` already gives every
   `.popover-toggle`. Each setting names itself in the panel, because the
   panel has the room the header never had. */
.popover-toggle:focus-visible + .settings-trigger { outline: 2px solid var(--ring); outline-offset: 2px; }
.settings > .popover { min-width: 16rem; gap: var(--s2); }
.settings-group, .settings-panel .tz-switch, .settings-panel .lang-switch { padding: var(--s2) var(--s3) var(--s3); }
.settings-panel > :not(:last-child) { border-bottom: 1px solid var(--border); }
.settings-label { display: block; margin-bottom: var(--s1); font-size: var(--text-sm); color: var(--fg-muted); }
.settings-row { display: flex; align-items: center; gap: var(--s2); }
.settings-row select { flex: 1; min-width: 0; max-width: none; }
.settings-panel .tz-switch, .settings-panel .lang-switch { display: block; }
/* The links carry their own padding for a 44px target; the panel's text starts at
   the label's edge, so the list gives that padding back. */
.settings-panel .lang-list { margin-inline: calc(var(--s2) * -1); }

/* Navigation ---------------------------------------------------------------

   Two shapes of one menu, and **one DOM for both** (decision 0040):

     - a *flat bar* of text links, for an app whose whole menu fits — five
       links or fewer, which is four of the five example apps;
     - a *menubar of groups* for an app whose menu does not, whose panels open
       on `:hover` and on `:focus-within`. A pointer opens one by pointing and
       a keyboard opens one by arriving; neither asks anything of a script.

   Written mobile-first, which is what makes one DOM affordable: the drawer is
   the plain shape — headings and lists in flow — and `@media (min-width:48rem)`
   is the layer that turns it into a menubar. Nothing has to be undone for the
   small screen, so the two layouts cannot drift apart.

   nav.js adds aria-expanded, Escape, tap-outside and the arrow keys. It is
   never the condition of any of this working. */

.nav { list-style: none; display: flex; flex-wrap: wrap; margin: 0; padding: 0; gap: var(--s5); }
.nav li { min-width: 0; max-width: 100%; }
.topbar-nav { padding-bottom: var(--s2); flex-wrap: wrap; }
.mainnav { min-width: 0; }
.topbar-nav > .mainnav { margin-inline-end: auto; }

.nav a {
  display: block; padding: var(--s2) 0 calc(var(--s2) + 1px);
  margin-bottom: -1px;
  color: var(--fg-muted); text-decoration: none; white-space: normal; overflow-wrap: anywhere;
  font-size: var(--text-base);
  border-bottom: 2px solid transparent;
}
@media (hover: hover) and (pointer: fine) { .nav a:hover { color: var(--fg); } }
.nav a[aria-current="page"] {
  color: var(--fg); font-weight: 500; border-bottom-color: var(--accent);
}

/* The scope and zone selectors ride in this row rather than in the identity
   row above it (decision 0040 §4): both answer a question about the whole
   page, which is the question navigation answers, and row 1 is identity and
   session. On a phone they travel into the drawer for free, because they are
   inside it. */
.chrome-controls { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }

/* --- the drawer, which is also the plain shape of the grouped menu ------- */

/* The toggle is a checkbox because the *open* state has to be readable by CSS
   at both widths, and a <details> cannot do that: its closed state hides the
   panel with a user-agent rule, so the same element could not also be the
   desktop menubar.

   It is **`.popover-toggle`**, the same class the account menu's uses. It had a
   class of its own until the two were noticed to be one mechanism, and the
   half-done rename is what `nav.spec.js` caught: `chrome.js` walks
   `.popover-toggle` to add Escape, so a drawer wearing a different class was a
   drawer Escape no longer closed. */
.menu-toggle {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: 44px; padding: var(--s2) var(--s3);
  margin-inline-start: calc(var(--s3) * -1);
  border-radius: var(--radius); cursor: pointer;
  font-size: var(--text-base); font-weight: 500; color: var(--fg);
}
@media (hover: hover) and (pointer: fine) { .menu-toggle:hover { background: var(--surface-2); } }
.popover-toggle:focus-visible + .menu-toggle { outline: 2px solid var(--ring); outline-offset: 2px; }

/* Full screen, not a sliver over a dimmed page: a panel that covers the page
   needs no backdrop to explain itself, and a backdrop that closes the menu
   cannot be built from a checkbox without putting a click target under the
   panel it is supposed to sit behind. */
.chrome-nav-panel {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column; gap: var(--s4);
  padding: var(--s3) var(--s4) var(--s7);
  background: var(--bg); overflow-y: auto; overscroll-behavior: contain;
  visibility: hidden;
}
.popover-toggle:checked ~ .chrome-nav-panel { visibility: visible; }
/* Its own rules rather than `.icon-btn`, because the drawer's close control
   has to disappear on the desktop and `.icon-btn` is declared further down the
   sheet — a shared class that wins the cascade in one place and loses it in
   another is a bug waiting for a wider screen. */
.menu-close {
  align-self: flex-end; flex: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.75rem; height: 2.75rem; margin-inline-end: calc(var(--s2) * -1);
  border-radius: var(--radius); color: var(--fg-muted);
}
@media (hover: hover) and (pointer: fine) { .menu-close:hover { background: var(--surface-2); color: var(--fg); } }

.menubar {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: var(--s5);
}
.menugroup { position: relative; min-width: 0; }

/* A group's label is a **link**, not a button: the baseline carries no script,
   and a button that cannot act is worse than no control at all. It points at
   the first entry of the group this actor may open (frame.go's navGroup.Href),
   so it is a copy of an address the filter already admitted and never a second
   one that could 403. */
.menugroup-label {
  display: flex; align-items: center; gap: var(--s1);
  padding: 0 0 var(--s2); text-decoration: none;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm); font-weight: 600; color: var(--fg-subtle);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.menugroup-label .chevron { display: none; }

.submenu { flex-direction: column; gap: 0; padding-top: var(--s1); }
/* A group of one is the link itself — no heading, no panel, no chevron. It
   keeps the `.menugroup` box so the menubar's spacing is one rule, and in the
   drawer it reads as a link and not as a section label over nothing. */
.menugroup-plain > .submenu { padding-top: 0; }
.menugroup-plain .menugroup-label {
  border-bottom: 0; padding: var(--s2) 0; min-height: 44px;
  font-size: var(--text-base); font-weight: 400; color: var(--fg-muted);
  text-transform: none; letter-spacing: normal;
}
.submenu a {
  display: flex; align-items: center; min-height: 44px;
  padding: var(--s2) 0; margin: 0;
  border-bottom: 0; border-radius: var(--radius-sm);
}
.submenu a[aria-current="page"] {
  background: var(--surface-2); color: var(--fg); font-weight: 500;
  border-bottom-color: transparent;
}

/* A `group` inside a nav (decision 0060): a label over a list, one level below
   the nav's own pages and **never a panel of its own** — no third layer, no
   hover inside a hover. It is the same list in both layouts; only the drawing
   differs. In the drawer the list is indented behind one hairline, which is
   what says "these belong together" in a column with no other structure.

   Written with single-class selectors on purpose: the menubar block below
   replaces both rules, and a descendant selector here would outrank it there
   (AGENTS.md's mobile-first trap, four defects in decision 0040). The label is
   `--fg-muted` and not `--fg-subtle` because on the desktop it sits on the
   panel's `--surface`, and muted is the quiet text that passes there too. */
.subgroup-label {
  display: block; padding: var(--s3) 0 var(--s1);
  font-size: var(--text-sm); font-weight: 500; color: var(--fg-muted);
  overflow-wrap: anywhere;
}
.subgroup-list {
  list-style: none; margin: 0; padding: 0; padding-inline-start: var(--s3);
  border-inline-start: 1px solid var(--border);
}

/* --- the menubar, from 48rem up ----------------------------------------- */

@media (min-width: 48rem) {
  /* display:none and not opacity:0 — a checkbox that is only invisible is
     still a checkbox to a screen reader, and on this width there is nothing
     for it to toggle. */
  /* **The nav's own toggle**, not every `.popover-toggle` on the page: the
     account menu's is a popover at this width too, and `display: none` would
     take it out of the tab order and leave the menu keyboard-unreachable. */
  .chrome-nav > .popover-toggle, .menu-toggle, .menu-close { display: none; }
  .chrome-nav-panel {
    position: static; z-index: auto; visibility: visible;
    flex: 1; min-width: 0; flex-direction: row; align-items: center;
    flex-wrap: wrap; gap: var(--s4);
    padding: 0; background: none; overflow: visible;
  }
  .chrome-nav-panel > .mainnav { margin-inline-end: auto; }

  /* `center`, so every item in the bar is one height. Stretch made the group
     of one — whose link sits two lists deeper — 10px taller than its
     neighbours and dragged the row's geometry with it. */
  .menubar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: var(--s1); }
  /* The group is a flex box so its own child is placed by a rule and not by
     the baseline of a list item. The group of one reaches its link through two
     more boxes than a trigger does — `li > ul > li > a` — and left to list
     layout that link rendered 4px above the row every other item sat on. */
  .menugroup { display: flex; align-items: center; }
  .menugroup-plain > .submenu,
  .menugroup-plain > .submenu > li { display: block; min-width: 0; max-width: none; }

  /* A trigger is a quiet pill: --surface-2 on hover and while its panel is
     open, which is the only fill this design has. Never the tenant accent —
     a trigger carries text, state and an affordance, all three of which §5
     keeps off it.
     
     **The group of one is named here, not left to inherit.** The drawer's rule
     for it is `.menugroup-plain .menugroup-label`, which outranks a bare
     `.menugroup-label` by one class no matter which comes later — so without
     this selector the single link kept the drawer's weight, size and 44px box
     on a 1280px desktop, and sat 4px off the row its neighbours were on.
     `margin` is reset for the same reason: it is a `.nav a` too, and that rule
     pulls a link up by a pixel for the flat bar's underline. */
  .menugroup-label,
  .menugroup-plain .menugroup-label {
    min-height: var(--control-h); padding: 0 var(--s3); margin: 0;
    border: 0; border-radius: var(--radius);
    font-size: var(--text-base); font-weight: 500; line-height: 1.2;
    color: var(--fg-muted); white-space: nowrap;
    text-transform: none; letter-spacing: normal;
  }
  .menugroup-label:hover,
  .menugroup-plain .menugroup-label:hover,
  .menugroup:focus-within > .menugroup-label { background: var(--surface-2); color: var(--fg); }
  .menugroup-label .chevron { display: block; color: var(--fg-subtle); flex: none; }
  .menugroup:hover > .menugroup-label .chevron,
  .menugroup:focus-within > .menugroup-label .chevron { transform: rotate(180deg); }

  /* Where the reader is, said by the group and not only by the page inside it
     — the page's own link is behind a panel that is shut. --fg and weight 600
     carry it; the accent (allowed use #4) only underlines what those two
     already say, and it draws on the header's hairline exactly as the flat
     bar's underline does. */
  .menugroup-label[aria-current="true"] { color: var(--fg); font-weight: 600; }
  .menugroup-label[aria-current="true"]::after {
    content: ""; position: absolute; inset-inline-start: var(--s3); inset-inline-end: var(--s3);
    bottom: calc(var(--s1) * -1); height: 2px; border-radius: 1px;
    background: var(--accent);
  }

  /* The panel is a **layer, never flow**: it opens over the page, so nothing
     below the header moves when a menu opens. That is the whole complaint the
     old in-flow disclosure earned.

     **This is `.popover`'s surface, restated rather than shared**, and the two
     cannot be one rule: inside the drawer this list is a plain stacked list, so
     its surface has to live inside this media query, and moving `.popover`'s
     under the query would leave the account menu unstyled on a phone. Writing
     it twice and putting a test on the pair is the lesser evil — a `@media`
     block that undid a surface is the shape that produced four defects in
     decision 0040. `TestPopoverAndSubmenuShareOneSurface` fails if these four
     values ever stop matching `.popover`'s. */
  .submenu {
    position: absolute; z-index: 40; top: calc(100% + var(--s2)); inset-inline-start: 0;
    min-width: 13rem; max-width: min(20rem, calc(100vw - var(--s6)));
    padding: var(--s2); gap: 1px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    visibility: hidden; opacity: 0;
  }
  /* The `--s2` between the trigger and the panel is a gap in the *drawing*
     and must not be a gap in the **hit area**: a pointer crossing it left
     `.menugroup` and the panel it was travelling to blinked out from under it.
     The bridge is part of the panel's own box, so it cannot hold a menu open
     that is shut — `visibility` is inherited, and a hidden panel has a hidden
     bridge. */
  .submenu::before {
    content: ""; position: absolute; inset-inline-start: 0; inset-inline-end: 0;
    top: calc(var(--s2) * -1); height: var(--s2);
  }
  .menugroup:hover > .submenu,
  .menugroup:focus-within > .submenu { visibility: visible; opacity: 1; }

  /* Escape's closed state, set by nav.js and by nothing else. It has to come
     after the rule above and at the same weight, because what it overrides is
     :focus-within — the reader pressed Escape *while* the trigger has focus,
     and the trigger having focus is why the panel was open. */
  .menugroup[data-mtd-dismissed] > .submenu { visibility: hidden; opacity: 0; }
  .menugroup[data-mtd-dismissed] > .menugroup-label .chevron { transform: none; }

  /* The last two groups open leftwards, so a panel never leaves the viewport
     and no script has to measure anything to know that. */
  .menugroup:nth-last-child(-n+2) > .submenu { inset-inline-start: auto; inset-inline-end: 0; }

  /* Full --fg inside an open panel. The bar is chrome and stays quiet at
     --fg-muted, but a panel the reader opened is the thing they are reading,
     and a list of destinations at 6:1 reads like a list of disabled ones. */
  .submenu a {
    min-height: 0; padding: var(--s2) var(--s3); color: var(--fg);
    white-space: normal; overflow-wrap: anywhere;
  }

  /* The group of one never becomes a layer: its list is the menubar item. */
  .menugroup-plain > .submenu {
    position: static; visibility: visible; opacity: 1;
    min-width: 0; max-width: none; padding: 0;
    background: none; border: 0; border-radius: 0; box-shadow: none;
  }
  .menugroup-plain .submenu a[aria-current="page"] { background: none; }
  .menugroup-plain .menugroup-label[aria-current="page"] { color: var(--fg); font-weight: 600; }
  .menugroup-plain .menugroup-label[aria-current="page"]::after {
    content: ""; position: absolute; inset-inline-start: var(--s3); inset-inline-end: var(--s3);
    bottom: calc(var(--s1) * -1); height: 2px; border-radius: 1px;
    background: var(--accent);
  }
  @media (hover: hover) and (pointer: fine) { .submenu a:hover { background: var(--surface-2); color: var(--fg); } }

  /* Inside a panel a group is a section of it: a hairline above (and below,
     where a page follows), the label in the links' own inset, and no indent —
     the panel is already narrow, and the hairline does the grouping. Same
     hairline as `.popover-sep`. */
  .subgroup-label { padding: var(--s2) var(--s3) var(--s1); }
  .subgroup-list { padding: 0; border-inline-start: 0; }
  .subgroup:not(:first-child),
  .subgroup + li {
    margin-top: var(--s1); padding-top: var(--s1);
    border-top: 1px solid var(--border);
  }
}

/* Opening a panel is the one piece of motion in the chrome, and it is small:
   120ms of opacity and a quarter-rem of travel, with a 60ms delay on the way
   in so a pointer crossing the bar does not flash six panels. */
@media (min-width: 48rem) and (prefers-reduced-motion: no-preference) {
  /* `:not(.menugroup-plain)` because a group of one has no panel to open: its
     list *is* the menubar item and is drawn at all times. Without the
     exclusion it wore the closed state's -4px offset permanently — so it sat
     off the row its neighbours were on — and then animated down to zero on
     hover, which is a link moving under the pointer. */
  .menugroup:not(.menugroup-plain) > .submenu {
    transform: translateY(-0.25rem);
    transition: opacity .12s ease, transform .12s ease, visibility 0s linear .12s;
  }
  .menugroup:not(.menugroup-plain):hover > .submenu,
  .menugroup:not(.menugroup-plain):focus-within > .submenu {
    transform: none;
    transition-delay: .06s, .06s, 0s;
  }
  .menugroup-label, .submenu a { transition: background-color .12s ease, color .12s ease; }
  .chevron { transition: transform .15s ease; }
}

/* The region placeholder — slice 2 deletes this.
   Until the renderer emits regions, a page lists what it *would* render as
   machine-readable markers (engine/internal/httpd/render.go). It is styled as
   quiet metadata so a developer running the engine sees a page and not a
   broken one. */
.regions { list-style: none; margin: 0; padding: 0; color: var(--fg-muted); font-size: var(--text-sm); }
.regions li { padding: var(--s2) 0; border-bottom: 1px solid var(--border); }
.not-rendered { color: var(--fg-muted); font-size: var(--text-sm); }

/* ------------------------------------------------------------- page frame */

.container { max-width: var(--maxw); margin: 0 auto; padding: var(--s6) var(--s5) var(--s7); width: 100%; flex: 1; }
/* A page's `width:` (decision 0075, spec §7.15): one modifier on <main> and
   on nothing else. `.topbar-row` and `.footer` keep --maxw on every page, so
   the menu does not move when a reader crosses from a wide page to an
   ordinary one. Below the column's own width all four are the viewport, which
   is the one mobile rule and needs no media query. `.container-narrow` is
   the login card's column and is not one of these. */
.width-narrow { max-width: var(--maxw-narrow); }
.width-wide { max-width: var(--maxw-wide); }
.width-full { max-width: none; }
/* A page's `row { }` (decision 0075, spec §7.16): two or three regions in
   equal columns from 48rem up — the stylesheet's one breakpoint (§6.8) —
   and one stack below it, in source order, which is the reading order. It
   is a layout and not a component: the wrapper draws nothing of its own and
   the regions inside keep their own layout. Their vertical margins are
   zeroed — the grid's gap is the one distance between them, so a chart's
   own `--s5` top margin cannot set its heading lower than its neighbour's —
   and `minmax(0, 1fr)` is what stops a wide child from widening its column.
   The rows-of-one the renderer never draws, so there is no `.page-row-1`. A
   print stacks. */
.page-row { display: grid; gap: var(--s6) var(--s5); align-items: start; }
/* Named children, not `> *`: `.chart { margin: var(--s5) 0 }` is later in the
   sheet and would outrank a universal child at equal specificity. */
.page-row > .region, .page-row > .note { min-width: 0; margin-top: 0; margin-bottom: 0; }
/* The wrapper takes the step a section would have taken beside its
   neighbours, so a row sits in the flow like one. */
section + .page-row, .page-row + section { margin-top: var(--s6); }
@media (min-width: 48rem) {
  .page-row-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
/* A page's `aside "Label" { }` (decision 0075, spec §7.17): one pane beside
   the flow, `--pane-w` wide from 48rem up and one stack below it, where the
   pane is before or after the flow exactly as it was written. The side is
   the DOM order — `.page-split-start` puts the first grid column at the
   pane's width, `-end` the last — so DOM order is visual order is focus
   order (WCAG 2.4.3), and under `dir="rtl"` the grid flips on its own: no
   `order`, no `left`, no `right`. The pane is sticky at `--s5` below the
   viewport's top — the header does not stick, so there is no offset to
   clear — and `align-self: start` is what lets it stick instead of
   stretching to the flow's height. It is deliberately **not** a scroll
   container of its own: an inner `overflow` would clip a list toolbar's
   popover (decision 0042's layer) at the pane's edge and need a second
   scrollbar, so a pane taller than the viewport scrolls with the page and
   the page's end reaches its end. The heading is the pane's accessible name
   at the nav group label's register (§6.8's `.subgroup-label`): small,
   muted, weight 500 — a name for a landmark, not a heading over the
   regions, which keep their own. A print stacks. */
.page-split { display: grid; gap: var(--s6) var(--s5); align-items: start; }
.page-flow, .page-aside { min-width: 0; }
.page-aside-title {
  margin: 0 0 var(--s3);
  font-size: var(--text-sm); font-weight: 500; color: var(--fg-muted);
  overflow-wrap: anywhere;
}
@media (min-width: 48rem) {
  .page-split-start { grid-template-columns: var(--pane-w) minmax(0, 1fr); }
  .page-split-end { grid-template-columns: minmax(0, 1fr) var(--pane-w); }
  .page-aside { position: sticky; top: var(--s5); }
}
/* A row link into the page being read (a master–detail pane): weight and
   `aria-current`, never a colour alone (§10). */
.grid a[aria-current="page"] { color: var(--fg); font-weight: 600; }
.container-narrow {
  max-width: 26rem;
  display: flex; flex-direction: column; justify-content: center;
  padding-bottom: var(--s6);
}
.brand-lg { margin-bottom: var(--s4); font-size: var(--text-lg); }
.brand-lg .brand-mark { width: 1.125rem; height: 1.125rem; border-radius: 4px; }
.brand-lg .brand-name { font-size: var(--text-lg); }

.footer {
  max-width: var(--maxw); margin: 0 auto; padding: var(--s4) var(--s5) var(--s5);
  width: 100%; color: var(--fg-subtle); font-size: var(--text-sm);
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  border-top: 1px solid var(--border);
}
.footer p { margin: 0; }

.page-head {
  display: flex; flex-wrap: wrap; gap: var(--s3);
  align-items: flex-start; justify-content: space-between;
  margin-bottom: var(--s5);
}
.page-head h1 { margin: 0; }
.page-head .lead { margin: var(--s1) 0 0; font-size: var(--text-sm); }
.page-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }

section + section { margin-top: var(--s6); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }

/* Cards are containers, not decoration: hairline, no shadow, no gradient. */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--s5);
}
.card + .card { margin-top: var(--s4); }
.card-narrow { max-width: 26rem; margin-inline: auto; }
.card h2:first-child, .card h1:first-child { margin-top: 0; }
.card > h1 { font-size: var(--text-lg); margin-bottom: var(--s4); }

/* -------------------------------------------------- notes / help regions */

/* One alert, five levels, three names.
   
   `.note` is the component; `.flash` and `.form-error` are the same box with a
   different lifetime — a confirmation that survives a redirect and a validation
   summary — and they share these declarations rather than restating them, so
   there is one alert in this sheet and not three.

   The box is a hairline on a faint fill, `--radius-lg`, and nothing else. It
   used to carry a 2px left rule in the semantic colour as well; that is one
   element doing a job the fill, the icon and the title already do, and three
   signals for one fact is what makes a quiet component look loud. */
.note, .flash, .form-error {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  padding: var(--s3) var(--s4);
  margin: 0 0 var(--s4);
  font-size: var(--text-base);
}
.note > :last-child, .flash > :last-child, .form-error > :last-child { margin-bottom: 0; }

/* The icon sits in a column of its own, so a body that wraps stays aligned
   under its title instead of running back under the icon. Gated on `:has`,
   because a note without an icon must not grow an empty first column — and
   because a browser without `:has` then renders the icon inline, which is the
   old layout and not a broken one. */
.note:has(> .note-icon) {
  display: grid; align-items: start;
  grid-template-columns: 1rem 1fr;
  column-gap: var(--s3); row-gap: var(--s1);
}
.note:has(> .note-icon) > .note-icon { grid-column: 1; grid-row: 1; }
.note:has(> .note-icon) > .note-title,
.note:has(> .note-icon) > .note-body,
.note:has(> .note-icon) > .note-links,
.note:has(> .note-icon) > .note-action { grid-column: 2; }

/* The title is an `<h2>` (spec §9.5.3 — a note's heading sits at the page's
   next heading level), so the global heading size is overridden back to the
   alert's own. Weight, not size, separates it from the body: a 13px bold line
   over 15px copy reads as a label on a box, and this is a heading. */
.note-title {
  font-weight: 500; font-size: var(--text-base); line-height: 1.35;
  letter-spacing: -0.006em; color: var(--fg);
  margin: 0; display: flex; align-items: center; gap: var(--s2);
}
.note-body { margin: 0; color: var(--fg-muted); line-height: 1.55; }
/* An untitled note is one quiet paragraph, and there is no title above it to
   carry the weight, so it keeps full contrast. */
.note > .note-body:first-child { color: var(--fg); }
/* A note's `link` lines (spec §7.5, decision 0082): ordinary links, one to a
   line, under the text and above the button. The global link style is the
   only style they take. */
.note-links { margin: var(--s2) 0 0; padding: 0; list-style: none; }
.note-links > li + li { margin-top: var(--s1); }
@media (pointer: coarse) { .note-links a { display: inline-flex; align-items: center; min-height: 44px; } }

/* A note's `button` (spec §7.5): the way forward the text describes, under
   it and aligned with it, one step of space away. */
.note-action { margin: var(--s3) 0 0; }
.note:has(> .note-icon) > .note-action { margin-top: var(--s2); }

/* The warning's icon: the non-colour visual signal WCAG 1.4.1 asks for
   (spec §9.5.4). It takes the title's colour, so it is never the only signal
   and never a second one either. 1rem, nudged down to sit on the title's
   x-height rather than on its box. */
.note-icon { flex: none; width: 1rem; height: 1rem; margin-top: 0.15rem; color: var(--fg-muted); }

/* Semantic colour lands on the icon and the title only. Body copy never takes
   it: a sentence is the message, and colouring the message is how a warning
   becomes hard to read. */
.note-info { background: var(--surface-2); }
.note-info > .note-icon, .note-info .note-title { color: var(--link); }
.note-warn { background: var(--warn-bg); }
.note-warn > .note-icon, .note-warn .note-title { color: var(--warn); }
.note-danger { background: var(--danger-bg); }
.note-danger > .note-icon, .note-danger .note-title { color: var(--danger); }
.note-ok { background: var(--ok-bg); }
.note-ok > .note-icon, .note-ok .note-title { color: var(--ok); }

/* A success flash keeps the even hairline of an ordinary surface: the pale
   fill already communicates state, and a routine confirmation should not look
   like something went wrong. An error summary must interrupt the form, and its
   own text is what says so. */
.flash { background: var(--ok-bg); margin-bottom: var(--s5); }
.form-error { background: var(--danger-bg); color: var(--fg); margin-bottom: var(--s5); }

/* Empty states are guidance, not an error: heading, one sentence, one action. */
.empty-state {
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: var(--s7) var(--s5); text-align: center;
}
.empty-state .empty { font-weight: 600; margin: 0 0 var(--s1); }
.empty-state .hint { display: block; margin-bottom: var(--s4); }
.empty-state .btn { margin-top: 0; }

/* ------------------------------------------------------------------ forms */

.form { display: grid; gap: var(--s4); }
.field { display: grid; gap: var(--s1); }

/* Short fields pair up (founder feedback 2026-09-10 §1d; docs/09 §6.2).

   One column is the base. When the form itself — not the viewport — is 30rem
   wide, it becomes two equal columns. A field the engine marked `.field-short`
   (formwidth.go: a date, a number, an amount, a yes/no, an enum) takes one cell
   and everything else spans both, so a Markdown editor or a long note keeps the
   full width it had. A control is still at most `26rem` wide (the `input`
   rule), so in a wide form the second control starts a little right of where
   the first one ends; that gap is what lets the columns be equal and the wide
   items stay wide. The *form's* width decides, because the same form sits in a
   68rem page, a `width: narrow` page, half of a `row { }` and a dialog, and a
   media query knows only the window: in half a `row { }` it would squeeze two
   controls into 14rem each. A dialog's body is about 31rem and pairs; a
   phone's form is about 20rem and stacks.

   Placement is by auto-flow and so follows the DOM: a short field takes the
   next free cell, and a wide one after it starts a new row. There is no
   `order`, no `dense` and no explicit column, so the Tab order, the reading
   order and the screen-reader order are the author's `fields:` order. A short
   field that has no short neighbour stays at half width on the start side; the
   hole beside it is the price of not moving anything. `align-items: start`
   keeps a field from stretching to its neighbour's height, which would spread
   its own label, control and message apart (.field is a grid). Nothing here is
   physical, so `dir="rtl"` mirrors it by itself. A check box next to a
   labelled control sits on that control's bottom edge, level with the box it
   would be beside, and not on the label above it.

   The spanning rule names `.form > *` and the short one `.form > .field-short`:
   the second outranks the first, and neither is in the base block above, so
   the mobile-first trap (a descendant selector in the base outranking the
   wide rule) has nothing to catch. */
.region-form { container: form / inline-size; }
@container form (min-width: 30rem) {
  .form { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .form > * { grid-column: 1 / -1; }
  .form > .field-short { grid-column: auto; }
  .form > .field-check.field-short { align-self: end; }
}
.field > label { font-weight: 500; font-size: var(--text-sm); color: var(--fg); }
.req { color: var(--danger); text-decoration: none; border: 0; }

/* Field help sits between label and control (GOV.UK order: read it before you
   fill the field) and is wired up with aria-describedby. */
.field-help { color: var(--fg-muted); font-size: var(--text-sm); margin: 0 0 var(--s1); }

input, select, textarea {
  font: inherit; font-size: var(--text-base); color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 0 var(--s3); height: var(--control-h);
  width: 100%; max-width: 26rem;
}
/* iOS Safari zooms the page when a control under 16px takes focus. A touch
   screen gets 16px; a pointer keeps the 15px of --text-base. */
@media (pointer: coarse) { input, select, textarea { font-size: max(16px, 1rem); } }
textarea { min-height: 5.5rem; height: auto; padding: var(--s2) var(--s3); resize: vertical; }
select { padding-inline-end: var(--s2); }
input::placeholder, textarea::placeholder { color: var(--fg-subtle); }
@media (hover: hover) and (pointer: fine) { input:hover, select:hover, textarea:hover { border-color: var(--fg-subtle); } }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--fg-muted); }

.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }

/* Quick picks (decision 0047): values offered under a control, written into it
   when pressed. They read as links — small, blue, underlined — because they
   are an aside to the control and not a second primary action beside Save.
   They are real buttons for the same reason `.field-add` is a real link: the
   element says what pressing it does. The group arrives `hidden` and form.js
   reveals it, so a page without the module never shows a button that does
   nothing. On a coarse pointer each one gets the 44px target. */
.quick-picks { display: flex; flex-wrap: wrap; gap: 0 var(--s3); }
.quick-pick {
  font: inherit; font-size: var(--text-sm); color: var(--link);
  background: none; border: 0; padding: var(--s1) 0; cursor: pointer;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px;
}
@media (hover: hover) and (pointer: fine) { .quick-pick:hover { color: var(--link-hover); } }
@media (pointer: coarse) { .quick-pick { min-height: 44px; } }

.field-msg { font-size: var(--text-sm); color: var(--fg-muted); }
.field-msg:empty { display: none; }
.field-msg.error { color: var(--danger); }
.field-msg.ok { color: var(--ok); }

/* Checkbox and radio: a real box on the left, label and help to the right,
   the whole row clickable. accent-color is the *text* colour, not the tenant
   accent — a checked box must never depend on a colour someone else picked. */
.field-check {
  display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s3);
  align-items: start;
}
.field-check input[type="checkbox"],
.field-check input[type="radio"] {
  width: 1rem; height: 1rem; margin: 0.2rem 0 0; padding: 0;
  accent-color: var(--solid-bg);
  flex: none;
}
.field-check input[type="radio"] { border-radius: 50%; }
.field-check > label { grid-column: 2; font-weight: 500; font-size: var(--text-base); cursor: pointer; }
.field-check .field-help { grid-column: 2; margin: 0; }
.field-check .field-msg { grid-column: 2; }

fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: var(--s2); }
legend { padding: 0; font-weight: 500; font-size: var(--text-sm); margin-bottom: var(--s1); }

/* A field with **no control**: a column the author marked `readonly:`, or one
   the engine owns (a slug, an unguessable, an `img`). It is a value and not a
   disabled input, because `disabled` is a statement to a browser and a crafted
   POST is not a browser — see engine/internal/httpd/form.go.

   Its label is a `<span>`, not a `<label for>`: there is nothing to point at.
   Its help is `.field-note`, not `.field-help`, because a `.field-help` is
   help wired to a control with aria-describedby and that rule has no
   exceptions (docs/09 §6.2, TestFieldHelpIsAssociated). */
.field-readonly > .field-label { font-weight: 500; font-size: var(--text-sm); color: var(--fg); }
.field-value { margin: 0; padding: var(--s2) 0; min-height: 1.5rem; }
.field-value:empty::before { content: "—"; color: var(--fg-muted); }
.field-note { color: var(--fg-muted); font-size: var(--text-sm); margin: 0; }

/* A calendar subscription (docs/09 §6.3): a title, one sentence, a link per
   calendar app, and everything else behind one disclosure. The address is in
   the one read-only input, because its value is the thing to copy. Monospace
   so a subscriber can see what they are copying; `readonly` keeps it
   selectable where `disabled` would not. */
.feed { margin-bottom: var(--s4); display: grid; gap: var(--s2); }
.feed-title { margin: 0; font-weight: 500; }
.feed .field-note { overflow-wrap: anywhere; }
.feed-more { display: grid; gap: var(--s2); }
.feed-more summary {
  cursor: pointer; width: max-content; max-width: 100%;
  min-height: var(--control-h); display: inline-flex; align-items: center;
  color: var(--link); font-size: var(--text-sm); font-weight: 500;
}
/* `inline-flex` drops the native triangle, so the cue is drawn here. The empty
   alternative text after the slash keeps a screen reader from reading it;
   `<details>` already reports open and closed. */
.feed-more summary::before { content: "▸" / ""; margin-inline-end: var(--s1); }
.feed-more[open] summary::before { content: "▾" / ""; }
.feed-more[open] summary { margin-bottom: var(--s1); }
.feed-more label { font-weight: 500; font-size: var(--text-sm); }
.feed-copy { display: flex; gap: var(--s2); }
.feed-copy .feed-url { flex: 1 1 auto; min-width: 0; }
.feed-url { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: var(--text-sm); }
.feed .field-help { overflow-wrap: anywhere; }
.feed [role="status"]:empty { display: none; }

/* An `img` field: a native file input, the picture the row has now, and a box
   that removes it (docs/09-design-system.md §6.2).

   A *native* input, styled through ::file-selector-button, because every page
   works with JavaScript off: a drop zone is a JavaScript-only affordance with
   no keyboard path, and on a phone this control is the camera. The button
   inside it is painted like a secondary button and never with the accent —
   nothing legible ever sits on a colour a tenant picked (§5).

   The preview is capped by max-height and not by width/height attributes: the
   thumbnail's dimensions are the engine's business, and a form that hard-coded
   them would be wrong for a portrait. */
.field-upload { display: grid; gap: var(--s2); }
.field-upload .upload-current {
  max-height: 8rem; max-width: 100%; width: auto; height: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2);
}
/* The global `input` rule gives every input `height: var(--control-h)`. A file
   input is a box that *clips* its content, and its button is a child of that
   box: with 16 px of vertical padding left over from here, 18 px of the 34 were
   all the 41 px button had, and its bottom edge was cut off (founder feedback,
   2026-09-10; measured in Chromium and WebKit). So the input is as tall as its
   content, and the button is the one thing that is `--control-h` high — the
   same as a `.btn` — which makes the input no shorter than the controls beside
   it. */
.field-upload input[type="file"] {
  font: inherit; color: var(--fg);
  height: auto; min-height: var(--control-h);
  padding: 0; border: 0; background: none; width: 100%;
}
.field-upload input[type="file"]::file-selector-button {
  font: inherit; cursor: pointer;
  box-sizing: border-box; height: var(--control-h);
  margin-inline-end: var(--s3); padding: 0 var(--s3);
  color: var(--fg); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
}
@media (hover: hover) and (pointer: fine) { .field-upload input[type="file"]::file-selector-button:hover { background: var(--surface); } }
/* The focus ring belongs on the button a person actually sees: a file input's
   own box is invisible, so the default ring would land around nothing. */
.field-upload input[type="file"]:focus-visible { outline: none; }
.field-upload input[type="file"]:focus-visible::file-selector-button {
  outline: 2px solid var(--ring); outline-offset: 2px;
}

/* A picture in a report cell or a record: the `thumb` variant, at the size the
   engine derived it (320 px on the longest edge, spec §9.3.7). */
.cell-img, .figure-img {
  max-height: 4rem; max-width: 100%; width: auto; height: auto;
  border-radius: var(--radius); background: var(--surface-2);
}
.figure-img { max-height: 22rem; }
/* A picture of a library in a report (decision 0112): recognisable. The library
   is browsed to find a picture, so its thumbnail takes the picker's width
   (--picture-min-w) in the cards' shape (--card-media-ratio) instead of the
   4rem a cell otherwise gets, and the box is fixed so a late file shifts
   nothing. */
.cell-img-library {
  width: var(--picture-min-w); max-height: none; aspect-ratio: var(--card-media-ratio); object-fit: cover;
}

/* A `multi` field is a group of checkboxes under one legend (spec §6.2:
   "checkbox list"), which is why it is a fieldset and not a select. */
.field-group { gap: var(--s2); }

/* The validation summary is a note whose body is a list of links to the fields
   that need correcting (docs/09 §6.6), so it is a way to the problem and not
   only an announcement of it. */
.form-error ul { margin: var(--s2) 0 0; padding-inline-start: var(--s5); font-size: var(--text-sm); }
.form-error li + li { margin-top: var(--s1); }

/* The destructive action is its own form, so the save body and the delete body
   cannot be confused. `details.danger` below is the disclosure. */
.form-delete { margin-top: var(--s2); }

.form-actions {
  display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center;
  padding-top: var(--s2);
}
.form-actions .spacer { margin-inline-start: auto; }
.inline { display: inline; }

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  font: inherit; font-size: var(--text-base); font-weight: 500;
  height: var(--control-h); padding: 0 var(--s3);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--fg);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) { .btn:hover { background: var(--surface-2); color: var(--fg); } }

/* The one hot button. Black in light, white in dark — deliberately not the
   tenant accent, so no tenant can make the primary action ugly or illegible. */
.btn-primary {
  background: var(--solid-bg); color: var(--solid-fg); border-color: var(--solid-bg);
}
@media (hover: hover) and (pointer: fine) { .btn-primary:hover { background: var(--solid-bg-hover); border-color: var(--solid-bg-hover); color: var(--solid-fg); } }

.btn-quiet { background: transparent; border-color: transparent; color: var(--fg-muted); }
@media (hover: hover) and (pointer: fine) { .btn-quiet:hover { background: var(--surface-2); color: var(--fg); } }

.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
@media (hover: hover) and (pointer: fine) { .btn-danger:hover { background: var(--danger-bg); color: var(--danger); } }
.btn-danger-text { background: transparent; border-color: transparent; color: var(--danger); }
@media (hover: hover) and (pointer: fine) { .btn-danger-text:hover { background: var(--danger-bg); color: var(--danger); } }

/* Pressed. A touch screen has no hover, so a press is its only feedback; it
   takes the fill the same control shows under a pointer. Written after the
   variants so `.btn-primary` keeps its own. */
.btn:active, .btn-quiet:active, .icon-btn:active, .filter-chip:active,
.menu-toggle:active, .menu-close:active, .popover-item:active,
.account-trigger:active { background: var(--surface-2); color: var(--fg); }
.btn-primary:active { background: var(--solid-bg-hover); border-color: var(--solid-bg-hover); color: var(--solid-fg); }
.btn-danger:active, .btn-danger-text:active { background: var(--danger-bg); color: var(--danger); }

.btn-sm { height: 1.75rem; font-size: var(--text-sm); padding: 0 var(--s2); }

/* An icon an application names beside a label (decision 0074, docs/09 §7): the
   glyph is 1rem, follows the text colour and never takes the tenant accent. In
   a link it keeps the label at a --s2 distance; inside a flex control the
   control's own gap does that, so the margin is taken back there. */
.icon { width: 1rem; height: 1rem; flex: none; vertical-align: -.125em; margin-inline-end: var(--s2); }
.btn .icon, .popover-item .icon, .icon-btn .icon { margin-inline-end: 0; }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon .icon { vertical-align: 0; }
.nav a:has(> .icon), .submenu a:has(> .icon), .row-actions a:has(> .icon), .agenda-actions a:has(> .icon), .card-actions a:has(> .icon) { display: inline-flex; align-items: center; }
.submenu a:has(> .icon) { display: flex; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.75rem; height: 1.75rem; padding: 0;
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; color: var(--fg-muted); cursor: pointer;
}
@media (hover: hover) and (pointer: fine) { .icon-btn:hover { background: var(--surface-2); color: var(--fg); } }
.icon-btn svg { width: 1rem; height: 1rem; display: block; }

/* The delete affordance: a plain disclosure, never a coloured block. */
details.danger { margin-top: var(--s5); border-top: 1px solid var(--border); padding-top: var(--s4); }
details.danger summary {
  cursor: pointer; color: var(--danger); font-weight: 500; font-size: var(--text-sm);
  width: max-content;
}
details.danger p { font-size: var(--text-sm); margin: var(--s3) 0; }

/* --------------------------------------- filters and report (slice 2) */

/* The renderer does not emit tables yet; docs/09 §6.3 is their contract and
   this is it in CSS. `.grid` keeps the old class name deliberately: it is a
   stylesheet hook, not a region kind — the region kind is `report` (spec §7.1).
   No panel, no fill: the filter row is a toolbar sitting on the canvas. */
.filters { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin: 0; }
.field-actions { display: flex; gap: var(--s2); align-items: end; }

/* The search box: one field with its magnifier inside it. The magnifier is
   a submit button and the first one in the form, so it is the form's default
   button: Enter in the field submits through it, with the popover's filters
   in the same request, while the popover's own button is out of sight. */
.search-box { position: relative; display: flex; align-items: center; flex: 0 1 18rem; min-width: 12rem; }
.search-box input { max-width: none; padding-inline-end: calc(var(--s2) + 1.75rem); }
.search-box .icon-btn { position: absolute; inset-inline-end: var(--s1); }

/* The filters' popover (decision 0054): every filter behind one control, so
   a list whose filters say "All" draws one button and not a row of them. */
.filter-menu > .popover-toggle:focus-visible + .btn { outline: 2px solid var(--ring); outline-offset: 2px; }
.filter-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.25rem; height: 1.25rem; padding: 0 var(--s1);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: var(--text-xs); color: var(--fg);
}
.filters .filter-panel {
  gap: var(--s3); padding: var(--s4);
  width: max-content; min-width: 18rem; max-width: min(24rem, calc(100vw - var(--s6)));
  max-height: min(34rem, 75vh); overflow-y: auto;
}
.filters .filter-panel input, .filters .filter-panel select { max-width: none; }

/* An enum or a ref: any of its values, as checkboxes. A ref's options can run
   long, so the list scrolls inside the panel rather than past the screen. */
.filter-field { gap: var(--s2); }
.filter-checks { display: grid; gap: var(--s1); max-height: 12rem; overflow-y: auto; }
.filter-check { display: flex; align-items: center; gap: var(--s2); min-height: 1.75rem; }
.filter-check label { flex: 1; font-size: var(--text-base); cursor: pointer; }
.filters .filter-check input {
  flex: none; width: 1rem; height: 1rem; margin: 0; padding: 0;
  accent-color: var(--solid-bg);
}
@media (pointer: coarse) { .filter-check { min-height: 44px; } }

/* A date: from and to, side by side, each a real labelled field. */
.filter-range { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.filter-range .field > label { font-weight: 400; color: var(--fg-muted); }
.filter-panel-actions {
  display: flex; justify-content: flex-end; gap: var(--s2);
  padding-top: var(--s3); border-top: 1px solid var(--border);
}

/* A filter that is set, as a link that removes it. Neutral like every other
   piece of state (§5): the word carries the filter, the × the removal. */
.filter-chips { display: flex; flex-wrap: wrap; gap: var(--s2); margin: 0; padding: 0; list-style: none; }
.filter-chip {
  display: inline-flex; align-items: center; gap: var(--s1);
  height: var(--control-h); padding-block: 0; padding-inline: var(--s3) var(--s2);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--fg);
  font-size: var(--text-sm); text-decoration: none; white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) { .filter-chip:hover { background: var(--surface-2); color: var(--fg); } }
.filter-chip-name { color: var(--fg-muted); }
.filter-chip svg { width: 0.875rem; height: 0.875rem; color: var(--fg-subtle); }
@media (pointer: coarse) { .filter-chip { min-height: 44px; } }

/* The list toolbar (decision 0054, docs/09 §6.3): one row between a region's
   heading and its table. The controls that choose rows are on the left, the
   actions are on the right, and the primary action is last. No hairline under
   it: the table header already draws the strong one, and a second rule a
   control-height above it was structure with no job. */
.list-toolbar {
  display: flex; flex-wrap: wrap; align-items: flex-start;
  gap: var(--s3); margin: 0 0 var(--s4);
}
.list-toolbar > .filters { flex: 1 1 20rem; margin: 0; padding: 0; border: 0; }
.list-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-inline-start: auto; }

/* A split button: the primary action, and a chevron that opens the region's
   other actions (§6.8b's pressed popover). Two halves of one black shape,
   parted by the hover shade so the two targets read as two. */
.btn-split { display: inline-flex; }
.btn-split > .btn-primary:first-child { border-start-end-radius: 0; border-end-end-radius: 0; }
.btn-split-toggle {
  padding: 0 var(--s2);
  border-start-start-radius: 0; border-end-start-radius: 0;
  border-inline-start-color: var(--solid-bg-hover);
}
.btn-split .popover, .action-menu .popover { min-width: 12rem; }
.popover-toggle:focus-visible + .btn-split-toggle,
.action-menu > .popover-toggle:focus-visible + .btn { outline: 2px solid var(--ring); outline-offset: 2px; }
.popover-toggle:checked + .btn .chevron { transform: rotate(180deg); }

.grid {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  font-size: var(--text-base);
}
.grid th, .grid td {
  text-align: start; vertical-align: middle;
  padding: var(--s3); border-bottom: 1px solid var(--border);
}
/* Flush with the page, not inset from it: a table on a canvas aligns its first
   column with the `h1` above it, and an indent would read as an invisible box. */
.grid th:first-child, .grid td:first-child { padding-inline-start: 0; }
.grid th:last-child, .grid td:last-child { padding-inline-end: 0; }

/* Sentence case, `--text-sm`, weight 500 — after shadcn's `TableHead`, which
   is `font-medium` and not a micro-label. The uppercase, letter-spaced
   `--text-xs` this replaced reads as a data-grid chrome label and is the
   hardest text on the page to scan; a column heading is a heading. It stays at
   `--fg-muted` rather than shadcn's full foreground, because §1's second
   principle is that everything which labels sits one step back — otherwise the
   heading and the column below it differ only by weight. */
.grid thead th {
  background: transparent;
  font-size: var(--text-sm); font-weight: 500; color: var(--fg-muted);
  white-space: nowrap;
  border-bottom-color: var(--border-strong);
  padding-top: 0;
}
.grid thead th a { text-decoration: none; color: inherit; display: inline-block; }
@media (hover: hover) and (pointer: fine) { .grid thead th a:hover { color: var(--fg); } }

/* The last row's hairline is the table's bottom edge, and a table on a canvas
   has no bottom edge to draw — shadcn's `[&_tr:last-child]:border-0`, for the
   same reason. A pager or a section boundary follows it and draws its own. */
.grid tbody tr:last-child > td { border-bottom: 0; }

@media (hover: hover) and (pointer: fine) { .grid tbody tr:hover { background: var(--surface-2); } }
/* A grouped report's totals row (decision 0076): the one place a table says
   "and altogether". One strong hairline above it and a heavier weight say so
   without a colour, the way the header's hairline closes the head. */
.grid tfoot th, .grid tfoot td {
  font-weight: 600; border-top: 1px solid var(--border-strong); border-bottom: 0;
}
.grid td.num, .grid th.num { text-align: end; font-variant-numeric: tabular-nums; }
/* A cell that holds several short entries (the Apps page's "Named by"): one per
   line, no bullets, because the cell is already the list's frame. */
.cell-list { list-style: none; margin: 0; padding: 0; }
.cell-list > li + li { margin-top: var(--s1); }

/* Alternating rows, and **only** where `striped: true` asked for them
   (spec §7.1, docs/09 §6.3). A band is worth having on a wide table of short
   values and is noise on a short one, and nobody but the page's author knows
   which this is.
   
   Hover has to step *up* to `--surface-3` here, because `--surface-2` is
   already the band: on a striped table the ordinary hover fill would be
   invisible under the pointer exactly half the time. That is the whole reason
   the token exists. */
.grid-striped tbody tr:nth-child(even) { background: var(--surface-2); }
@media (hover: hover) and (pointer: fine) { .grid-striped tbody tr:hover { background: var(--surface-3); } }
/* The band bleeds `--s3` past the text on both sides and the table is pulled
   back by the same amount, so the first column stays flush with the `h1` while
   the fill still has somewhere to end. A band that stopped exactly at the first
   glyph would read as a clipped rectangle. `--s3` each side fits inside
   `.container`'s `--s5` gutter, so nothing overflows. */
.grid-striped {
  margin-inline-start: calc(var(--s3) * -1); margin-inline-end: calc(var(--s3) * -1);
  width: calc(100% + var(--s3) * 2);
}
.grid-striped th:first-child, .grid-striped td:first-child { padding-inline-start: var(--s3); }
.grid-striped th:last-child, .grid-striped td:last-child { padding-inline-end: var(--s3); }
.sort-arrow { font-size: 0.7em; margin-inline-start: var(--s1); color: var(--fg); }
.row-actions, .grid th.row-actions { white-space: nowrap; text-align: end; }

/* --------------------------------------- the crosstab (spec §7.9, §9.13.2)

   A `matrix` is not a `.grid` with a flag: it has headers on two sides, so the
   first column is a `<th>` and the geometry has to hold when the table is
   wider than the page. Everything else is the report's — the same hairline, no
   zebra, no header fill — because a crosstab is a table and docs/09 §6.3 is
   still what a table looks like here.

   The accent appears nowhere in this block. The tenant picks it, so it may
   only paint surfaces with no text, no state and no affordance (§5), and every
   surface in a crosstab carries a number somebody reads. */
.matrix-scroll { overflow-x: auto; }
.matrix {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  font-size: var(--text-base);
}
.matrix th, .matrix td {
  text-align: start; padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
}
.matrix th:first-child, .matrix td:first-child { padding-inline-start: 0; }
.matrix th:last-child, .matrix td:last-child { padding-inline-end: 0; }
.matrix thead th {
  background: transparent;
  font-size: var(--text-xs); font-weight: 500; color: var(--fg-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom-color: var(--border-strong);
  padding-top: 0;
}
/* The `group:` band sits above the column headers and belongs to them, so it
   carries no rule of its own between the two rows. */
.matrix-bands th { border-bottom: none; padding-bottom: 0; }
/* A row header is the row's identity: the weight of a name, not of a heading,
   and never wrapped — a crosstab scrolls sideways instead. */
.matrix tbody th {
  font-weight: 500; color: var(--fg); white-space: nowrap;
  text-transform: none; letter-spacing: normal;
}
@media (hover: hover) and (pointer: fine) { .matrix tbody tr:hover { background: var(--surface-2); } }
.matrix td.num, .matrix th.num { text-align: end; font-variant-numeric: tabular-nums; }
/* A cell with no row. Quiet, and still legible: `--fg-muted` is 6:1 on the
   background, because "no value" is information and not decoration. */
.matrix .cell-empty { color: var(--fg-muted); }

/* ------------------------------ a comparison of two versions (decision 0053)

   The history itself is a `.grid`; this is its other view. A diff is one
   monospace block with one line per `<li>`, and each changed line says what
   happened three ways: the element (`<ins>`, `<del>`), a visible sign in the
   gutter, and a word only a screen reader hears. The faint fills are the
   semantic `--ok-bg` and `--danger-bg`, and they are the fourth signal, never
   the only one (WCAG 1.4.1). The browser's underline and strike-through are
   taken off because on a whole line they are noise; the sign carries it. */
.diff-field + .diff-field { margin-top: var(--s5); }
.diff-field h4 { font-size: var(--text-sm); font-weight: 600; margin: 0 0 var(--s2); }
.diff, .diff-text {
  margin: 0; padding: var(--s2) 0; list-style: none;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: var(--mono); font-size: var(--text-sm); line-height: 1.55;
  background: var(--surface);
}
.diff li { padding: 0; padding-inline-end: var(--s3); white-space: pre-wrap; overflow-wrap: anywhere; }
.diff ins, .diff del { text-decoration: none; color: inherit; }
.diff-ins { background: var(--ok-bg); }
.diff-del { background: var(--danger-bg); }
.diff-mark { display: inline-block; width: var(--s5); text-align: center; color: var(--fg-muted); user-select: none; }
.diff-ins .diff-mark { color: var(--ok); }
.diff-del .diff-mark { color: var(--danger); }
.diff-text { padding: var(--s2) var(--s3); white-space: pre-wrap; overflow-wrap: anywhere; }
.diff-sides { display: grid; gap: var(--s3); }
@media (min-width: 48rem) {
  .diff-sides { grid-template-columns: 1fr 1fr; }
}
.version-compare > .page-actions { margin-top: var(--s5); }

/* Tags label a row's state. Semantic colour, faint fill, never the accent. */
.tag {
  display: inline-block; font-size: var(--text-xs); line-height: 1.5;
  padding: 0 var(--s2); border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--fg-muted);
  white-space: nowrap;
}
.tag-active, .tag-ok { border-color: transparent; background: var(--ok-bg); color: var(--ok); }
.tag-warn { border-color: transparent; background: var(--warn-bg); color: var(--warn); }
.tag-danger { border-color: transparent; background: var(--danger-bg); color: var(--danger); }

.pager {
  display: flex; flex-wrap: wrap; gap: var(--s3);
  justify-content: space-between; align-items: center; padding: var(--s3) 0 0;
}
.pager-info { color: var(--fg-muted); font-size: var(--text-sm); margin: 0; }
.pager-links { list-style: none; display: flex; gap: var(--s4); margin: 0; padding: 0; font-size: var(--text-sm); }
.pager-links .disabled { color: var(--fg-subtle); }

/* ------------------------------------------------------- the agenda layout
   A `list` with `layout: agenda` (decisions 0106 and 0107, docs/09 §6.3). One
   heading per day and one list of entries under it; an entry is a time cell and
   a body, so the eye reads down the left edge for *when* and across for *what*,
   which a table of labelled cards does not let it do. Hairlines and weights
   carry the structure; nothing is filled, and the tenant accent is not used.
   The tags are the ordinary `.tag`, each with its word. */
.agenda { margin: 0 0 var(--s4); }
.agenda-day {
  display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--s2);
  margin: var(--s5) 0 var(--s2); padding-bottom: var(--s2);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-base); font-weight: 600;
}
.agenda > .agenda-day:first-child { margin-top: 0; }
/* "Today" and "Tomorrow" lead, and the date steps back behind them; a day with
   no such word is its date alone, at full strength. */
.agenda-day-rel + .agenda-day-date { color: var(--fg-muted); font-weight: 400; }
.agenda-list { list-style: none; margin: 0; padding: 0; }
.agenda-item {
  display: grid; grid-template-columns: var(--agenda-time-w) minmax(0, 1fr);
  align-items: baseline; column-gap: var(--s3); row-gap: var(--s1);
  padding: var(--s3) 0; border-bottom: 1px solid var(--border);
}
.agenda-item:last-child { border-bottom: 0; }
.agenda-time { font-weight: 500; font-variant-numeric: tabular-nums; }
.agenda-time-end, .agenda-allday { display: block; font-size: var(--text-sm); font-weight: 400; color: var(--fg-muted); }
.agenda-body { min-width: 0; overflow-wrap: anywhere; }
.agenda-title { margin: 0; font-weight: 500; }
.agenda-tags { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); list-style: none; margin: var(--s1) 0 0; padding: 0; }
.agenda-tags .tag { white-space: normal; }
.agenda-meta { margin: var(--s1) 0 0; color: var(--fg-muted); font-size: var(--text-sm); }
.agenda-actions { grid-column: 2; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); font-size: var(--text-sm); }
.agenda-note { margin: var(--s4) 0 0; color: var(--fg-muted); font-size: var(--text-sm); }
@media (pointer: coarse) {
  .agenda-title a, .agenda-actions a { display: inline-flex; align-items: center; min-height: 44px; }
  /* The 44px targets are the rhythm of the list; the row's own padding gives
     way so that a phone does not read as double spaced. */
  .agenda-item { padding: var(--s1) 0; }
}
/* From 48rem the row's actions leave the body and sit at the end of the entry's
   first line, where a calendar keeps what you do with an entry. */
@media (min-width: 48rem) {
  .agenda-item { grid-template-columns: var(--agenda-time-w) minmax(0, 1fr) auto; column-gap: var(--s5); }
  .agenda-actions { grid-column: 3; grid-row: 1; }
}
/* On the narrowest phones the time stacks over the body, so the title keeps the
   whole line. The two rules name the same selectors as the wide ones above, so
   the later one wins at equal specificity. */
@media (max-width: 20rem) {
  .agenda-item { grid-template-columns: minmax(0, 1fr); }
  .agenda-actions { grid-column: 1; }
  .agenda-time-end { display: inline; margin-inline-start: var(--s1); }
  .agenda-allday { display: inline; }
}

/* --------------------------------------------------------- the cards layout
   A `list` with `layout: cards` (decision 0106, docs/09 §6.3). One `.card`, the
   design system's own surface, per row in a grid that is one column on a phone
   and as many as fit above it, never narrower than --card-min-w. The picture has
   a fixed shape, so an image that arrives late moves nothing; the title is the
   one link and its hit area is stretched over the whole card, so a card is one
   focus stop and one target. Hairlines carry the structure; the tenant accent is
   not used. The tags are the ordinary `.tag`, each with its word. */
.cards {
  list-style: none; margin: 0 0 var(--s4); padding: 0;
  display: grid; gap: var(--s4);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--card-min-w)), 1fr));
}
/* Named with `.cards >`: `.card` pads and `.card + .card` spaces, and a grid's
   items are neither. The two selectors have the same weight, and this one is
   later. */
.cards > .card-item { position: relative; display: flex; flex-direction: column; min-width: 0; margin: 0; padding: 0; }
.card-media {
  display: block; width: 100%; aspect-ratio: var(--card-media-ratio); object-fit: cover;
  background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0;
}
.card-body { flex: 1; min-width: 0; padding: var(--s4); overflow-wrap: anywhere; }
.card-title { margin: 0; font-weight: 600; }
.card-title a::after { content: ""; position: absolute; inset: 0; }
/* The ring goes around the card the link stands for, not around its words. */
.card-title a:focus-visible { outline: none; }
.card-title a:focus-visible::after { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: var(--radius); }
.card-tags { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); list-style: none; margin: var(--s2) 0 0; padding: 0; }
.card-tags .tag { white-space: normal; }
.card-meta { margin: var(--s2) 0 0; color: var(--fg-muted); font-size: var(--text-sm); }
.card-excerpt {
  margin: var(--s2) 0 0; font-size: var(--text-sm);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
}
.card-actions { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); padding: 0 var(--s4) var(--s4); font-size: var(--text-sm); }
/* A link after the title paints above the title's stretched area. */
.card-meta a, .card-actions a { position: relative; }
@media (prefers-reduced-motion: no-preference) {
  .cards > .card-item { transition: background-color .12s ease; }
}
@media (hover: hover) and (pointer: fine) { .cards > .card-item:has(.card-title a:hover) { background: var(--surface-2); } }
@media (pointer: coarse) {
  .card-title a, .card-meta a, .card-actions a { display: inline-flex; align-items: center; min-height: 44px; }
}

/* --------------------------------------------------------- the inline layout
   A `list` with `layout: inline` (decision 0117, docs/09 §6.3). The rows are a
   run of short items in one wrapping line: the tags under a post, the author
   beside a date. A `ul` with the item's link in the link blue, a second value
   in the muted text after it, and a middle dot after every item but the last.
   The dot is drawn here and not typed, with an empty alternative text, so a
   screen reader hears a list of items and not "dot". The separator is a
   character and the spacing is the same either way: it is never the only thing
   that tells two items apart. The tenant accent is not used. */
.inline-list {
  list-style: none; margin: 0 0 var(--s4); padding: 0;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s1) 0;
  font-size: var(--text-sm);
}
.inline-item { display: inline-block; margin: 0; padding: 0; overflow-wrap: anywhere; }
.inline-item:not(:last-child)::after {
  content: "\00b7"; content: "\00b7" / "";
  margin-inline: var(--s2); color: var(--fg-subtle);
}
.inline-more { color: var(--fg-muted); }
@media (pointer: coarse) {
  .inline-item a { display: inline-flex; align-items: center; min-height: 44px; }
}

/* ------------------------------------------------- dashboard (slice 2) */

.stats { list-style: none; margin: 0 0 var(--s4); padding: 0; display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); }
.stat { display: grid; gap: 0; }
.stat-num { font-size: var(--text-2xl); font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--fg-muted); font-size: var(--text-sm); }

/* ----------------------------------------------------- chart (decision 0071) */

/* The SVG carries marks and hairlines; every word around it is HTML, so the
   labels are on the type scale. The plot is a grid of the value labels, the
   drawing and the bucket labels. The tenant accent appears nowhere in it:
   a series is a grey, a texture or a dash, never a hue (docs/09 §5, §6.15). */
.chart { margin: var(--s5) 0; container-type: inline-size; }
.chart > figcaption {
  font-size: var(--text-lg); font-weight: 600; line-height: 1.25; letter-spacing: -0.01em;
  margin: 0 0 var(--s3);
}
.chart-zone { font-size: var(--text-sm); font-weight: 400; color: var(--fg-muted); margin-inline-start: var(--s2); letter-spacing: normal; }
.chart-legend {
  list-style: none; margin: 0 0 var(--s3); padding: 0;
  display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4);
  font-size: var(--text-sm); color: var(--fg-muted);
}
.chart-legend li { display: inline-flex; align-items: center; gap: var(--s2); }
.chart-swatch { flex: none; overflow: visible; }

.chart-plot {
  display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: var(--s2);
  margin-block: var(--s2) 0;
  font-size: var(--text-xs); line-height: 1.25; color: var(--fg-muted); font-variant-numeric: tabular-nums;
}
.chart-bars .chart-plot { grid-template-columns: fit-content(30%) minmax(0, 1fr) auto; }
.chart-plot ol { list-style: none; margin: 0; padding: 0; }
.chart-plot .chart-y { grid-column: 1; grid-row: 1; }
.chart-plot .chart-svg { grid-column: 2; grid-row: 1; }
.chart-plot .chart-end { grid-column: 3; grid-row: 1; }
.chart-plot .chart-x { grid-column: 2; grid-row: 2; margin-top: var(--s2); }

.chart-svg { display: block; width: 100%; overflow: visible; }
.chart-columns .chart-svg, .chart-line .chart-svg { height: auto; aspect-ratio: 5 / 2; }
/* The last bucket label is centred under a narrow column and reaches past it. */
.chart-columns .chart-plot, .chart-line .chart-plot { padding-inline-end: var(--s3); }

/* Value labels down the side: a zero-height row per tick, centred on its
   hairline, spread by the same division the drawing uses. */
.chart-y.chart-ticks { display: flex; flex-direction: column; justify-content: space-between; }
.chart-y.chart-ticks li { height: 0; display: flex; align-items: center; justify-content: flex-end; white-space: nowrap; }
/* Bucket labels along the bottom, one grid column per bucket. */
.chart-x.chart-cats { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; text-align: center; }
.chart-x.chart-cats li { min-width: 0; white-space: nowrap; }
.chart-x.chart-cats.chart-clip li { overflow: hidden; text-overflow: ellipsis; }
.chart-x.chart-cats li span { display: block; }
/* Value labels along the bottom of a bar chart, centred on their hairlines. */
.chart-x.chart-ticks { display: flex; justify-content: space-between; }
.chart-x.chart-ticks li { width: 0; display: flex; justify-content: center; white-space: nowrap; }
/* Bucket labels beside the bars, and the value at the end of each. */
.chart-y.chart-cats, .chart-end { display: grid; grid-auto-rows: 1fr; }
.chart-y.chart-cats li, .chart-end li { align-self: center; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-y.chart-cats li { text-align: end; }
.chart-end li { padding-inline-start: var(--s2); color: var(--fg); }

.chart-grid, .chart-zero { fill: none; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-grid { stroke: var(--border); }
.chart-zero { stroke: var(--border-strong); }
.chart rect, .chart-tip rect { stroke: var(--surface); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart rect.chart-s1, .chart-tip rect.chart-s1 { fill: var(--chart-1); }
.chart rect.chart-s2, .chart-tip rect.chart-s2 { fill: var(--chart-2); }
.chart rect.chart-s3, .chart-tip rect.chart-s3 { stroke: var(--chart-3); }
.chart rect.chart-s4, .chart-tip rect.chart-s4 { stroke: var(--chart-4); }
.chart-p3 path { stroke: var(--chart-3); fill: none; }
.chart-p4 ellipse, .chart-p4 circle { fill: var(--chart-4); }

.chart .chart-line, .chart .chart-dot, .chart-tip .chart-line, .chart-tip .chart-dot { fill: none; vector-effect: non-scaling-stroke; }
.chart .chart-line, .chart-tip .chart-line { stroke-width: 2; stroke-linejoin: round; }
.chart .chart-dot, .chart-tip .chart-dot { stroke-width: 6; stroke-linecap: round; }
.chart .chart-s1.chart-line, .chart .chart-s1.chart-dot, .chart-tip .chart-s1.chart-line, .chart-tip .chart-s1.chart-dot { stroke: var(--chart-1); }
.chart .chart-s2.chart-line, .chart .chart-s2.chart-dot, .chart-tip .chart-s2.chart-line, .chart-tip .chart-s2.chart-dot { stroke: var(--chart-2); }
.chart .chart-s3.chart-line, .chart .chart-s3.chart-dot, .chart-tip .chart-s3.chart-line, .chart-tip .chart-s3.chart-dot { stroke: var(--chart-3); }
.chart .chart-s4.chart-line, .chart .chart-s4.chart-dot, .chart-tip .chart-s4.chart-line, .chart-tip .chart-s4.chart-dot { stroke: var(--chart-4); }
.chart .chart-s2.chart-line, .chart-tip .chart-s2.chart-line { stroke-dasharray: 8 4; }
.chart .chart-s3.chart-line, .chart-tip .chart-s3.chart-line { stroke-dasharray: 2 4; }
.chart .chart-s4.chart-line, .chart-tip .chart-s4.chart-line { stroke-dasharray: 8 4 2 4; }

/* The tooltip (static/chart-tip.js). The popover's surface (decision 0042) at
   a pointer: fixed to the viewport so no plot clips it, and never a target, so
   it cannot steal the pointer it follows. No transition: it is immediate. */
.chart-tip {
  position: fixed; z-index: 50; margin: 0; padding: var(--s2) var(--s3);
  max-width: min(20rem, calc(100vw - var(--s6))); pointer-events: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  font-size: var(--text-sm); line-height: 1.4; color: var(--fg);
}
.chart-tip-title { display: block; font-weight: 600; }
.chart-tip-row { display: flex; align-items: center; gap: var(--s2); }
.chart-tip-row svg { flex: none; width: 20px; height: 12px; }
.chart-tip-value { margin-inline-start: auto; padding-inline-start: var(--s3); font-variant-numeric: tabular-nums; }
@media print { .chart-tip { display: none; } }

.chart > .hint { margin: var(--s2) 0 0; }
.chart-data { margin-top: var(--s3); }
.chart-data > summary { padding-block: var(--s3); color: var(--fg-muted); font-size: var(--text-sm); cursor: pointer; }

/* Below 30rem of chart every second visible bucket label is hidden; its grid
   cell stays, so the labels that remain keep their columns. */
@container (max-width: 30rem) {
  .chart-x.chart-cats .chart-alt { visibility: hidden; }
}

/* Windows high contrast: fills become system colours, and the textures and
   dashes still tell the series apart. */
@media (forced-colors: active) {
  .chart rect.chart-s1 { fill: GrayText; }
  .chart rect.chart-s2 { fill: CanvasText; }
  .chart rect { stroke: Canvas; }
  .chart rect.chart-s3, .chart rect.chart-s4 { stroke: CanvasText; }
  .chart-p3 path { stroke: CanvasText; }
  .chart-p4 ellipse, .chart-p4 circle { fill: CanvasText; }
  .chart .chart-line, .chart .chart-dot { stroke: CanvasText !important; }
  .chart-grid { stroke: GrayText; }
  .chart-zero { stroke: CanvasText; }
}

@media print {
  .chart { break-inside: avoid; width: 100%; }
  .chart rect, .chart-svg path, .chart-svg polyline { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

.event-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.event-item { padding: var(--s4) 0; border-bottom: 1px solid var(--border); }
.event-item:first-child { padding-top: 0; }
.event-when { color: var(--fg-muted); font-size: var(--text-sm); margin: 0; font-variant-numeric: tabular-nums; }
.event-title { font-weight: 600; margin: var(--s1) 0; font-size: var(--text-base); }
h2.event-title { font-size: var(--text-lg); }
.event-where, .event-meta, .event-desc { color: var(--fg-muted); font-size: var(--text-sm); margin: 0 0 var(--s1); }
.event-item > p:last-child { margin-bottom: 0; }
.event-actions { display: flex; gap: var(--s2); align-items: center; margin-top: var(--s3); }

/* ---------------------------------------- detail / record (spec §7.7) */

/* An article layout, not a read-only form: no labels down the left, no boxes.
   The metadata is one muted line under the heading and the body is prose at a
   readable measure. */
.detail { margin: 0 0 var(--s6); }

.meta {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: var(--s1) var(--s3);
  margin: 0 0 var(--s5); padding: 0;
  color: var(--fg-muted); font-size: var(--text-sm);
}
.meta-item { display: flex; align-items: baseline; gap: var(--s2); }
/* " · " between entries, drawn rather than written, so the separator is not in
   the accessible name of anything. */
.meta-item + .meta-item::before { content: "·"; color: var(--fg-subtle); }
.meta dd { margin: 0; }
.meta dd.num { font-variant-numeric: tabular-nums; }
/* A `long text` drawn as content keeps its line breaks (decision 0119): the text holds
   the newline, the class draws it. Nothing is made from the text; every character is
   escaped. A card's excerpt keeps its clamp, so three lines are three lines. */
.lines { white-space: pre-line; }

/* A picture and its caption. The <img> arrives with the blob route; until then
   the figure says a picture is there rather than drawing an empty box. */
.figure { margin: 0 0 var(--s5); }
.figure-pending {
  margin: 0; padding: var(--s6) var(--s4);
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--fg-muted);
  text-align: center; font-size: var(--text-sm);
}
.figure figcaption { margin-top: var(--s2); color: var(--fg-muted); font-size: var(--text-sm); }

/* The body: generated markup from engine/internal/richtext, or paragraphs.
   `max-width` is a measure and not a container — 34rem is ~68 German
   characters, which is the upper end of what stays readable. */
.rich { max-width: 34rem; font-size: var(--text-base); }
.rich > :first-child { margin-top: 0; }
.rich > :last-child { margin-bottom: 0; }
.rich p, .rich ul, .rich ol, .rich blockquote, .rich pre, .rich table { margin: 0 0 var(--s4); }
.rich h2, .rich h3, .rich h4, .rich h5, .rich h6 { margin: var(--s5) 0 var(--s2); }
/* The body's headings step down the scale. The renderer starts at h2 (a `#` is
   the first content heading, a `##` the next), and the global h3 is
   --text-base, which is the size of the paragraph under it: a `##` section
   heading was bold body copy. Only existing sizes: h2 24, h3 18, the rest 15
   semibold. */
.rich h2 { font-size: var(--text-xl); margin-top: var(--s6); }
.rich h3 { font-size: var(--text-lg); }
.rich h4, .rich h5, .rich h6 { font-size: var(--text-base); font-weight: 600; }.rich ul, .rich ol { padding-inline-start: var(--s5); }
.rich li + li { margin-top: var(--s1); }
.rich blockquote {
  padding-inline-start: var(--s4); border-inline-start: 2px solid var(--border-strong);
  color: var(--fg-muted);
}
.rich pre {
  padding: var(--s3) var(--s4); overflow-x: auto;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  font-size: var(--text-sm);
}
.rich code { font-size: 0.9375em; }
.rich pre code { font-size: inherit; }
.rich hr { border: 0; border-top: 1px solid var(--border); margin: var(--s5) 0; }
.rich table { border-collapse: collapse; width: 100%; font-size: var(--text-sm); }
.rich th, .rich td { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); text-align: start; }
.rich th { font-weight: 600; }
/* A picture in the body (decision 0112). The renderer writes its stored width
   and height as attributes, so the browser keeps the room before the file
   arrives: `height: auto` with `max-width: 100%` scales the box to the column
   and the attributes give its ratio. No `width` is set here on purpose, and
   `.figure-img`'s `width: auto` is not used: it would drop the attribute's
   width and the box would shift when the file loaded. A picture alone in its
   paragraph is a `.figure`, with the cover's caption style above. */
.rich img {
  max-width: 100%; height: auto;
  border-radius: var(--radius); background: var(--surface-2);
}
.rich .figure { margin: 0 0 var(--s4); }
.rich .figure img { display: block; }

/* An image reference the engine cannot resolve (spec §9.6.3): the word and the
   alt text, never a URL. */
.rich .img-unresolved {
  display: inline-block; padding: 0 var(--s2);
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
  color: var(--fg-muted); font-size: var(--text-sm);
}

/* ------------------------------------- the markdown editor (decision 0049) */

/* A `markdown` field's visual editor: one control, drawn as one — the
   textarea's boundary around a toolbar and the article as it will read. The
   content is `.rich`, so a heading in the editor is the heading the page will
   show, at the page's measure; the frame is that measure plus its padding.
   Without editor.js none of this applies and the field is its textarea. */
.md-editor {
  position: relative;
  max-width: calc(34rem + var(--s6) + 2px);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface);
}
@media (hover: hover) and (pointer: fine) { .md-editor:hover { border-color: var(--fg-subtle); } }
.has-error .md-editor { border-color: var(--danger); }

/* The toolbar stays in reach while a long article scrolls under it. */
.md-toolbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
  padding: var(--s1);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}
/* Pressed is a fill *and* a boundary, so it is not a shade of grey alone. */
.md-tool[aria-pressed="true"], .md-mode[aria-pressed="true"] {
  background: var(--surface-3); border-color: var(--border-strong); color: var(--fg);
}
.md-tool[aria-disabled="true"], .md-tool[aria-disabled="true"]:hover {
  background: transparent; border-color: transparent; color: var(--fg-subtle); cursor: default;
}
.md-sep { align-self: stretch; width: 1px; margin: var(--s1); background: var(--border); }
.md-spacer { flex: 1 1 auto; }
@media (pointer: coarse) { .md-tool { width: 44px; height: 44px; } .md-mode { min-height: 44px; } }

/* The writing surface. ProseMirror's own required rules are here rather than
   in its stylesheet: one stylesheet, and these are the few it needs. */
.md-content {
  position: relative; max-width: none; min-height: calc(var(--s7) * 4);
  padding: var(--s3) var(--s4);
  white-space: pre-wrap; white-space: break-spaces; word-wrap: break-word;
  font-variant-ligatures: none; font-feature-settings: "liga" 0;
}
.md-editor-tall .md-content, .md-editor-tall textarea { min-height: calc(var(--s7) * 8); }
.md-content pre { white-space: pre-wrap; }
.md-content li { position: relative; }
/* A tight list's items hold a paragraph in the editor's model and none in the
   article, so the paragraph's own margin goes. */
.md-content li > p { margin: 0; }
.md-content a { color: var(--link); text-decoration: underline; cursor: text; }
.md-content img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }
.md-content .ProseMirror-selectednode { outline: 2px solid var(--ring); outline-offset: 2px; }
.md-content.ProseMirror-hideselection *::selection { background: transparent; }
.md-content.ProseMirror-hideselection { caret-color: transparent; }
.md-content img.ProseMirror-separator { display: inline; border: 0; margin: 0; }

/* The Markdown view is the same textarea the page has without the editor,
   drawn inside the frame instead of beside it. */
.md-editor textarea {
  display: block; max-width: none; border: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  font-family: var(--mono); font-size: var(--text-sm);
}

/* One focus ring for the control, on its frame; the toolbar's buttons keep
   their own. */
.md-content:focus-visible, .md-editor textarea:focus-visible { outline: none; }
.md-editor:has(.md-content:focus-visible), .md-editor:has(textarea:focus-visible) {
  outline: 2px solid var(--ring); outline-offset: 2px;
}

/* A table the editor keeps as its source (a GFM table has no visual editor
   yet): labelled as such, in the article's code-block shape. */
.md-source { margin: 0 0 var(--s4); }
.md-source-label {
  display: block; margin-bottom: var(--s1);
  color: var(--fg-muted); font-size: var(--text-xs); user-select: none;
}
.md-source pre { margin: 0; }

.md-note {
  margin: 0; padding: var(--s2) var(--s4); border-top: 1px solid var(--border);
  color: var(--fg-muted); font-size: var(--text-sm);
}

/* The link panel: the popover surface (decision 0042), opened by the editor
   rather than by a checkbox, under the toolbar. */
.md-link { top: var(--s7); inset-inline-start: var(--s1); min-width: 18rem; gap: var(--s2); padding: var(--s3); }
.md-link.is-open { visibility: visible; opacity: 1; }
.md-link label { font-size: var(--text-sm); font-weight: 500; }
.md-link input { max-width: none; }
.md-link-actions { display: flex; gap: var(--s2); }

/* The picture picker of the visual editor (decision 0111): a dialog holding a
   search box, an upload link, and one button per picture of the library — its
   thumbnail, its title and its credit, so the picture is told by words and not
   by the picture alone. A picture that cannot be inserted is the same card
   with a dashed edge and no button. */
dialog.dialog-pictures { width: min(48rem, calc(100vw - 2rem)); }
.pictures-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin: 0 0 var(--s4); }
.pictures-search { display: flex; gap: var(--s2); flex: 1 1 14rem; }
.pictures-search input { flex: 1 1 auto; min-width: 0; max-width: none; }
.pictures-grid {
  list-style: none; margin: 0 0 var(--s4); padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--picture-min-w), 1fr)); gap: var(--s3);
}
.pictures-grid > li { display: flex; }
.picture-pick {
  display: flex; flex-direction: column; align-items: stretch; gap: var(--s1);
  width: 100%; padding: var(--s2); text-align: start;
  background: var(--surface); color: var(--fg); font: inherit;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
}
button.picture-pick { cursor: pointer; }
@media (hover: hover) and (pointer: fine) { button.picture-pick:hover { background: var(--surface-2); } }
button.picture-pick:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.picture-off { border-style: dashed; }
.picture-pick img {
  display: block; width: 100%; aspect-ratio: var(--card-media-ratio); object-fit: cover;
  border-radius: var(--radius-sm); background: var(--surface-3);
}
.picture-title { font-size: var(--text-sm); font-weight: 500; overflow-wrap: anywhere; }
.picture-credit { font-size: var(--text-xs); color: var(--fg-muted); overflow-wrap: anywhere; }
.pictures-pager { display: flex; justify-content: flex-end; gap: var(--s2); margin: 0 0 var(--s4); }
.field-snippet { margin-top: var(--s3); }
.field-snippet label { display: block; font-size: var(--text-sm); font-weight: 500; }
.field-snippet input { max-width: none; font-family: var(--mono); font-size: var(--text-sm); }
/* "Used in" under a library picture's file control (decision 0112): the rows
   whose text shows it, as links, and one or two quiet sentences. */
.field-usage { margin-top: var(--s3); }
.field-usage-label { margin: 0 0 var(--s1); font-size: var(--text-sm); font-weight: 500; }
.field-usage-list { margin: 0 0 var(--s1); padding-inline-start: var(--s5); font-size: var(--text-sm); }

.readonly-grid { display: grid; grid-template-columns: max-content 1fr; gap: var(--s2) var(--s5); margin: 0 0 var(--s4); font-size: var(--text-base); }
.readonly-grid dt { color: var(--fg-muted); }
.readonly-grid dd { margin: 0; }

/* Review values include file digests and other unbroken stored spellings. */
.approval { overflow-wrap: anywhere; }

.error-code { font-size: var(--text-2xl); font-weight: 600; color: var(--fg-subtle); margin: 0; font-variant-numeric: tabular-nums; }

/* The `add_via:` affordance (decision 0043): a control beside a select that
   creates the option it is missing. A row, because the two belong to one field
   and a button under a select reads as the form's next question. The select
   keeps the width; the control keeps its words. */
.field-with-add { display: flex; gap: var(--s2); align-items: center; }
.field-with-add > select { flex: 1 1 auto; min-width: 0; }
.field-add { flex: none; white-space: nowrap; }

/* A `color` column (decision 0118): the native swatch with its value as text
   beside it, because a colour is never the only signal. The swatch is the
   control and keeps the touch height; the text is the plain secondary kind. */
.color-field { display: inline-flex; align-items: center; gap: var(--s2); }
.color-field input[type="color"] {
  width: calc(var(--control-h) * 1.5); min-height: var(--control-h);
  padding: var(--s1); cursor: pointer;
}
.color-hex { font-size: var(--text-sm); color: var(--fg-muted); }

/* ---------------------------------------------------- dialog (slice 2) */

/* Native <dialog>: Esc, focus trapping and focus return are the browser's job.
   Without JavaScript the same route renders as a full page instead. */
.modal-host:empty { display: none; }

dialog.dialog {
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--fg);
  width: min(36rem, calc(100vw - 2rem));
  max-width: none;
  max-height: min(86vh, 46rem);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
dialog.dialog[open] { display: flex; flex-direction: column; }
dialog.dialog::backdrop { background: var(--backdrop); }

.dialog-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border);
  flex: none;
}
.dialog-head h2 { margin: 0; font-size: var(--text-base); font-weight: 600; }

.dialog-body {
  padding: var(--s5) var(--s5) 0;
  overflow-y: auto; flex: 1 1 auto; min-height: 0;
}
/* The action bar stays put while the fields scroll (a long form must never
   hide its Save button). */
.dialog-body .form-actions {
  position: sticky; bottom: 0;
  margin: var(--s5) calc(var(--s5) * -1) 0;
  padding: var(--s3) var(--s5);
  background: var(--surface); border-top: 1px solid var(--border);
}
.dialog-body > :last-child { margin-bottom: 0; }
.dialog-body details.danger { margin-top: 0; border-top: 0; padding: var(--s4) 0; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 48rem) {
  .topbar-row { padding: 0 var(--s4); }
  .container { padding: var(--s5) var(--s4) var(--s6); }
  .footer { padding: var(--s4); }
  /* The mark and the chevron stay; the address moves inside, where the panel
     gives it a line of its own instead of a sliver of the identity row. */
  .account-name { display: none; }
  /* The flat bar only. `.nav` also names every panel list inside the grouped
     menu, and those are a stacked drawer at this width, not a row. */
  .mainnav > .nav { gap: var(--s4); }
  /* In the drawer the scope selector gets the width it never has in a header
     row, so a season's full name is readable before it is chosen. */
  .chrome-nav-panel .chrome-controls {
    flex-direction: column; align-items: stretch; gap: var(--s3);
    padding-top: var(--s4); border-top: 1px solid var(--border);
  }
  .chrome-nav-panel .scope-switch select { max-width: none; flex: 1; }
  /* One height for the pair. `.btn-sm` exists so a control fits a 3rem header
     row, and in the drawer there is no header row to fit. */
  .chrome-nav-panel .btn-sm { height: var(--control-h); padding: 0 var(--s3); }
}

@media (max-width: 40rem) {
  /* A table row becomes one record: its identity spans both columns, and the
     remaining labelled values share lines without hiding any column. */
  .grid thead { display: none; }
  .grid, .grid tbody, .grid tfoot, .grid tr, .grid td, .grid tfoot th, .grid tfoot td { display: block; width: 100%; }
  .grid tbody tr, .grid tfoot tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: var(--s4); row-gap: var(--s2);
    border-bottom: 1px solid var(--border); padding: var(--s3) 0;
  }
  .grid td, .grid tfoot th, .grid tfoot td { width: auto; min-width: 0; border: none; padding: 0; overflow-wrap: anywhere; }
  .grid td::before {
    content: attr(data-label);
    display: block; font-size: var(--text-xs); color: var(--fg-muted);
    text-transform: uppercase; letter-spacing: 0.04em;
  }
  .grid td:first-child, .grid tfoot th { grid-column: 1 / -1; font-weight: 600; }
  /* A totals cell with no total says nothing, and on a phone nothing is not
     drawn: its label would sit over an empty line. */
  .grid tfoot td:empty { display: none; }
  .grid td:last-child:nth-child(even), .grid td.row-actions { grid-column: 1 / -1; }
  /* The desktop band's first/last-cell padding would indent individual fields.
     On a phone the band belongs to the record, so its padding belongs there. */
  .grid-striped th:first-child, .grid-striped td:first-child { padding-inline-start: 0; }
  .grid-striped th:last-child, .grid-striped td:last-child { padding-inline-end: 0; }
  .grid-striped tbody tr { padding-inline-start: var(--s3); padding-inline-end: var(--s3); }
  .grid td.num, .grid th.num { text-align: start; }
  .row-actions { text-align: start; }
  /* A crosstab below 40rem becomes what it is an efficiency layer over: one
     block per row, its header first, then one labelled line per column
     (decision 0020 §6). */
  .matrix thead { display: none; }
  .matrix, .matrix tbody, .matrix tr, .matrix td, .matrix tbody th { display: block; width: 100%; }
  .matrix tr { border-bottom: 1px solid var(--border); padding: var(--s3) 0; }
  .matrix tbody th { border: none; padding: 0 0 var(--s2); font-weight: 600; }
  .matrix td { border: none; padding: 0; }
  .matrix td::before {
    content: attr(data-label);
    display: block; font-size: var(--text-xs); color: var(--fg-muted);
    text-transform: uppercase; letter-spacing: 0.04em;
  }
  .matrix td + td { margin-top: var(--s2); }
  .matrix td.num, .matrix th.num { text-align: start; }
  .matrix-scroll { overflow-x: visible; }
  .search-box { flex: 1 1 100%; }
  dialog.dialog { width: 100vw; max-width: 100vw; max-height: 100vh; max-height: 100dvh; height: 100%; border-radius: 0; border: 0; }
}

/* ------------------------------------- the tenant's administration (0033) */

/* The one page in the product with no compiler behind it, so it uses nothing
   this stylesheet did not already have: `.card` per login, `.meta` for its
   facts, `.tag` for its status, `details.danger` for every destructive act and
   `.btn-primary` exactly once. These two rules are the whole addition, and
   neither touches the tenant accent — docs/09 §5's rule applies to this page
   like any other. */

/* The surface's own section row. It is the header's `.nav` list moved into the
   content column, with a rule under it so the cards below start somewhere. */
.admin-tabs { margin: 0 0 var(--s5); padding-bottom: var(--s3); border-bottom: 1px solid var(--border); }

/* A login's status, in the card head where a region puts its actions. */
.admin-tags { display: flex; flex-wrap: wrap; gap: var(--s2); margin: 0; }

/* Long email addresses and invitation state must fit narrow account cards. */
.admin-login .section-head { flex-wrap: wrap; }
.admin-login h2 { min-width: 0; overflow-wrap: anywhere; }

/* Two acts on one login are two sibling forms, so they need the gap a
   `.form-actions` row has and do not get it from the form itself. */
.card > .form + .form { margin-top: var(--s3); }

@media (prefers-reduced-motion: no-preference) {
  .btn, .nav a, .icon-btn, input, select, textarea {
    transition: background-color .12s ease, border-color .12s ease, color .12s ease;
  }
}

@media print {
  .topbar, .footer, .page-actions, .list-actions, .filters, .row-actions, .pager-links, .agenda-actions, .card-actions { display: none; }
  .agenda-item, .cards > .card-item { break-inside: avoid; }
  .agenda-day { break-after: avoid; }
  .page-row { display: block; }
  .page-split { display: block; }
  .page-aside { position: static; }
  body { background: #fff; color: #000; }
}
