/* The page frame (header · search sentence · results · preview pane), the start page's grid and
   the chrome every screen shares: the compositions, plus the components only the frame places. Load order: tokens,
   components, then this file. Compositions own the BETWEEN (law C4) and style only what they placed
   (C14). */

@layer elements {
  /* at least the viewport tall, a column: the page footer sits at the bottom even on a short page */
  body {
    display: flex;
    flex-direction: column;
    min-block-size: 100dvh;
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font: var(--type-body);
  }
}

@layer components {
  /* ---- search sentence: the list's heading, "Suche [field] in … · … · …  + Filter" (a2,
     DESIGN.md "Search sentence"). It lives OUTSIDE #results, so its links are plain GET navigations;
     a q-swap refreshes its slots out-of-band. Set slots in ink, open ones quieter, centre dots
     between. The form is its size container: at S the unset slots after the first fold away. ---- */
  .search-form {
    /* on the page grid, like the header: "Suche" starts where the wordmark starts. Knob: --search-sentence-pad
       (0 where a composition already sets the page grid). */
    --_search-sentence-pad: var(
      --search-sentence-pad,
      var(--space-4) max(var(--gutter), (100% - var(--measure)) / 2 + var(--gutter)) var(--space-2)
    );
    container-type: inline-size;
    padding: var(--_search-sentence-pad);
  }
  .search-sentence {
    /* the containing block for its menus' panels (law C12) */
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-2);
    font: var(--type-query);
    color: var(--ink-2);
  }
  /* Knobs: --search-field-max (the field's widest), --search-field-pad (inside the frame),
     --search-field-basis (its width on S, where the list's field takes its own line). The start
     page sets them for its large search. */
  .search-sentence-field {
    --_field-max: var(--search-field-max, var(--measure-query));
    --_field-pad: var(--search-field-pad, var(--space-1) var(--space-2));
    /* starts at its widest, so setting a filter wraps the sentence instead of narrowing the field */
    flex: 1 1 var(--measure-query);
    max-inline-size: var(--_field-max);
    padding: var(--_field-pad);
    font: inherit;
    /* what was typed is content, in ink; the sentence around it and the placeholder stay quieter */
    color: var(--ink);
  }
  /* the native clear button draws in the browser's own blue, a second hue; Esc still clears */
  .search-sentence-field::-webkit-search-cancel-button {
    appearance: none;
  }
  /* "Suchen", beside the field where the field is the whole sentence (the start page): as tall as
     the field, wide in its label */
  .search-sentence-submit {
    align-self: stretch;
    padding-inline: var(--space-8);
    font: var(--type-body);
  }
  /* grouped in the DOM because it is the unit a q-swap refreshes, never because it is a box */
  .search-sentence > .filterset {
    /* biome-ignore lint/nursery/useBaseline: display: contents is allowed for layout (law F) */
    display: contents;
  }
  .search-sentence-slots {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
  }
  /* a slot is one unit, "in" and the dot inside it: "in" never ends a line alone and no line
     starts with a dot (it trails the slot before it) */
  .search-sentence-slots > div {
    display: inline-flex;
    align-items: baseline;
    gap: var(--space-2);
  }
  .search-sentence-slots > div:has(~ div)::after {
    content: "·";
    margin-inline: calc(var(--space-3) - var(--space-2)) var(--space-2);
    color: var(--ink-2);
  }
  /* an open slot is quieter: a context, it re-points the ink its button reads */
  .search-sentence-slots > .is-minor {
    --ink: var(--ink-2);
  }
  /* a set slot's link reads like the slot menus' buttons */
  .search-sentence .is-set > a {
    font: inherit;
    color: var(--ink);
    text-decoration: none;
  }
  .search-sentence .is-set > a:hover {
    text-decoration: underline;
  }
  /* each slot's panel hangs from its own trigger (overlay placement) */
  @supports (anchor-name: --anchor-probe) and
    (inset-block-start: anchor(end)) and
    (justify-self: anchor-center) {
    :is(.search-sentence-slots > div, .search-sentence-add, .search-sentence-more) {
      anchor-scope: --menu-button;
    }
  }
  /* "+ Filter" (and on S "Filter") read in an open slot's quieter ink */
  :is(.search-sentence-add, .search-sentence-more) {
    --ink: var(--ink-2);
    padding-inline-start: var(--space-3);
  }
  .search-sentence-more {
    display: none;
  }
  /* clear all: quiet words at the sentence's end */
  .search-sentence-clear {
    padding-inline-start: var(--space-3);
    font: var(--type-meta);
    color: var(--ink-2);
    text-decoration: none;
  }
  .search-sentence-clear:hover {
    text-decoration: underline;
  }
  @container (width < 40rem) /* S (DESIGN.md space budget); no token names a container width */ {
    .search-sentence-label,
    .search-sentence-in,
    .search-sentence-slots > .is-minor:not(:first-child),
    .search-sentence-add {
      display: none;
    }
    .search-sentence-more {
      display: block;
    }
    /* the folded slots leave no dot behind: only a slot with a set one after it keeps its dot */
    .search-sentence-slots > div:not(:has(~ .is-set))::after {
      content: none;
    }
    /* "Filter" holds the folded slots' lists: it hangs under its trigger between the gutters and
       scrolls in the room that is left, so none of the list shows beside it */
    .search-sentence-more > .toolpanel {
      inline-size: auto;
      inset-inline: var(--gutter);
      inset-block-end: var(--gutter);
      align-self: start;
      justify-self: stretch;
      max-block-size: stretch;
    }
    .search-sentence-field {
      --_field-basis: var(--search-field-basis, 100%);
      flex-basis: var(--_field-basis);
      max-inline-size: none;
    }
    .search-sentence-submit {
      padding-inline: var(--space-4);
    }
  }

  /* ---- the tool row's selection tools: "Auswählen", or in selection mode "Abbrechen", the
     count and "Feld ändern …" (owner 2026-09-30). They fill the row's start, which keeps
     "Spalten …" at the end edge. ---- */
  .bulk {
    display: flex;
    flex: 1;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
    font: var(--type-meta);
  }
  /* its panel hangs from its own tool (overlay placement) */
  @supports (anchor-name: --anchor-probe) and
    (inset-block-start: anchor(end)) and
    (justify-self: anchor-center) {
    .bulk {
      anchor-scope: --menu-button;
    }
  }
  /* its panel opens start-aligned under its tool (a2 round 2) */
  .bulk > .toolpanel {
    --toolpanel-inset-inline: anchor(start) var(--gutter);
    --toolpanel-justify-self: start;
  }
  /* the count is a state, quieter than the tools beside it */
  .bulk > [role="status"] {
    color: var(--ink-2);
  }

  /* ---- Feld chooser — the Feld → value chooser. Exactly ONE value widget shows: the one whose data-bulk-value tokens
     contain the chosen Feld, derived from the select's own :checked option — no JS, so the no-JS
     baseline behaves identically. A new bulk field needs its token here (ledger #6).
     Knobs: --chooser-control-height (its action row's height). ---- */
  .chooser {
    --_chooser-height: var(--chooser-control-height, auto);
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3);
  }
  .chooser .actions {
    --control-height: var(--_chooser-height);
    margin-left: auto;
  }
  /* in "Feld ändern …" the panel's knob is the one height source (law C8) */
  .toolpanel .chooser {
    --chooser-control-height: var(--control-height);
  }
  .chooser [data-bulk-value] {
    --field-display: none;
  }
  .chooser:has([name="field"] option:checked[value="physical_location"])
    [data-bulk-value~="physical_location"],
  .chooser:has([name="field"] option:checked[value="creator"]) [data-bulk-value~="creator"],
  .chooser:has([name="field"] option:checked[value="subject_place"])
    [data-bulk-value~="subject_place"],
  .chooser:has([name="field"] option:checked[value="Quelle"]) [data-bulk-value~="Quelle"],
  .chooser:has([name="field"] option:checked[value="Querverweis"]) [data-bulk-value~="Querverweis"],
  .chooser:has([name="field"] option:checked[value="Besitzer"]) [data-bulk-value~="Besitzer"],
  .chooser:has([name="field"] option:checked[value="media_type"]) [data-bulk-value~="media_type"],
  .chooser:has([name="field"] option:checked[value="document_type"])
    [data-bulk-value~="document_type"],
  .chooser:has([name="field"] option:checked[value="collection_id"])
    [data-bulk-value~="collection_id"] {
    --field-display: inherit; /* whatever display the context gives every other field */
  }

  /* ---- preview pane: the sheet beside the list — flat, framed by an edge. Knob: --pane-display
     (block; the frame hides it until its column exists). ---- */
  .pane {
    --_pane-display: var(--pane-display, block);
    display: var(--_pane-display);
  }
  .pane > div {
    position: sticky;
    top: var(--space-4); /* nothing sticky stands above it: the frame's own gap */
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    background: var(--ground);
    border: var(--line-width) solid var(--edge);
    padding: var(--space-4);
  }
  .pane :is(h2, p, ul) {
    margin: 0;
  }
  /* header row: Signatur tab + Titel side by side, ✕ at the end. The sheet's own column gap is the
     ONE unit through header → toolbar → meta. */
  .pane header {
    display: flex;
    align-items: baseline;
    gap: var(--space-2) var(--space-3);
  }
  .pane header h2 {
    flex: 1 1 auto;
    min-width: 0;
    font: var(--type-title);
  }
  /* the ✕ close, an icon control: an icon-only flex item has no text baseline to share with the
     header, so it aligns to the start */
  /* biome-ignore lint/style/noDescendingSpecificity: never a sentence's or a toolbar's link */
  .pane header > a {
    align-self: flex-start;
  }
  /* the meta line — a NAMED hook (law C1): positional selectors made every pane reshuffle a silent
     retarget risk */
  .pane .meta {
    font: var(--type-mono);
    font-variant-numeric: tabular-nums;
  }
  .pane .meta span + span::before {
    content: " · ";
    color: var(--ink-2);
  }
  /* media list — cover first (ADR 0015); no media shows one hollow placeholder */
  .pane ul {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }
  .pane li {
    min-width: 0;
  }
  .pane li > .media-tile {
    inline-size: 100%;
  }
  .pane .hollow {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    border: var(--line-width) solid var(--edge);
  }
  .pane li p {
    display: flex;
    flex-wrap: wrap;
    gap: 0 var(--space-3);
    margin-top: var(--space-1);
    font: var(--type-meta);
    color: var(--ink-2);
  }
}

@layer compositions {
  /* ---- header bar: wordmark + screen chrome (search / back link) ---- */
  body > header {
    /* a CONTROL ROW (law C8) — the compact height */
    --control-height: var(--touch-target-compact);
    /* the containing block for the overlay panels its controls drop (law C12) */
    position: relative;
    /* ...and it must out-stack whatever sticky element its panels drop over. The
       scale, in order: --z-* in tokens.css. */
    z-index: var(--z-header);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-4);
    /* the band spans the viewport; its content sits on the page grid (the measure, then the gutter) */
    padding: var(--space-3) max(var(--gutter), (100% - var(--measure)) / 2 + var(--gutter));
    /* the band: re-points the roles for its subtree (tokens.css) */
    --ground: var(--band-ground);
    --ink: var(--band-ink);
    --ink-2: var(--band-ink-2);
    background: var(--ground);
    color: var(--ink);
    border-bottom: var(--line-width) solid var(--band-edge);
  }
  /* ---- page-footer — the page's last line: the light/dark toggle at the end edge, on the page
     grid, on every size (owner 2026-10-06). A control row (law C8). :not([hidden]), so the display
     never overrides [hidden]. ---- */
  .page-footer:not([hidden]) {
    --control-height: var(--touch-target-compact);
    display: flex;
    margin-block-start: auto;
    justify-content: flex-end;
    padding: var(--space-8) max(var(--gutter), (100% - var(--measure)) / 2 + var(--gutter));
  }
  /* the wordmark: the ONE place a display face has character (owner 2026-08-07) */
  .wordmark {
    font: var(--type-wordmark);
    letter-spacing: var(--wordmark-tracking);
    text-decoration: none;
    white-space: nowrap;
  }
  header [role="search"] {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    flex: 1 1 20rem; /* the search field is the header's one growing track */
    min-width: 0;
  }
  header [role="search"] input {
    flex: 1 1 auto;
    min-width: 0;
  }
  /* S: the tools share the wordmark's line and the search takes the next one whole — two rows,
     not three (the band spends no third row of a phone on two words) */
  @media (width < 40rem) /* space budget S (design-system.md) */ {
    header [role="search"] {
      order: 1;
      flex-basis: 100%;
    }
    header > .wordmark + [role="search"] ~ button.link {
      margin-left: auto;
    }
  }
  /* the return-to-work link; on screens whose header holds nothing else it docks right */
  .back {
    font: var(--type-meta);
  }
  /* whichever of the two trailing items ENDS the row docks it right: the back link on the screens
     that carry one, otherwise Abmelden (archivist chrome, ADR 0018) */
  header > :is(.back, .logout):last-child {
    margin-left: auto;
  }
  /* no search (the article forms): nothing grows, so the create menu docks the tools right as one
     group, as in the a1 top bar — a wrapped line of them too */
  body > header:has(> .wordmark + button.link) {
    justify-content: flex-end;
  }
  header > .wordmark + button.link {
    margin-left: auto;
  }
  header > .wordmark + button.link ~ :last-child {
    margin-left: 0;
  }

  /* ---- a control row's TEXT occupants consume the row knob too (law C8: EVERY interactive child).
     A bare <a> or <p> is an inline box, and min-height does nothing to one — so the components-layer
     consumption rule, which names only button/a.button/summary/input/select, could not reach them and
     they stood at their own line box: a.back 19px and a breadcrumb crumb 18px beside 32px buttons,
     both under the WCAG 2.2 AA 24px target floor (law D). DIRECT-CHILD paths through the structures the
     compositions placed (law C14), so it can never reach into a dropped overlay panel, whose
     entries are sized by the panel's own re-declared knob. ---- */
  :is(body > header, body > header > nav) > :is(a, p) {
    --_row-height: var(--control-height, auto);
    display: inline-flex;
    align-items: center;
    min-height: var(--_row-height);
  }

  /* ---- page frame: main · (pane), the pane column present only at/above the 80rem switch ---- */
  .frame {
    --pane-col: minmax(20rem, 26rem); /* named frame track (law C3/C5) */
    display: grid;
    grid-template-columns: [main] minmax(0, 1fr);
    align-items: start;
    gap: var(--space-4);
    /* on the page grid, like the header (body > header): the list starts where the wordmark starts */
    padding: var(--space-4) max(var(--gutter), (100% - var(--measure)) / 2 + var(--gutter));
  }

  /* the work column: a vertical stack, whatever the screen puts in it. The workbench's bulk form
     repeats the stack of the column it sits in, so ONE rule serves both. DIRECT child only (law
     C14). */
  .frame main,
  .frame main > form {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }
  .frame main {
    grid-column: main;
    min-width: 0;
  }
  /* the list's tool row: its view tool "Spalten …" at the end edge (a2 round 11) */
  :is(.frame main, .frame main > form) > [role="toolbar"] {
    --toolbar-justify: flex-end;
  }
  /* HTMX in-flight: a static opacity dim, no motion */
  #results.htmx-request {
    opacity: 0.6;
  }

  /* ---- start — the start page's grid (start.py): areas in auto-fit columns on the page grid. It
     reads only what an area's root declares: data-span="all" takes the row, data-absent="s" leaves
     the area out of a small grid. ---- */
  .start {
    --section-head-type: var(--type-subhead);
    --search-sentence-pad: 0;
    --start-column-min: 15rem; /* the narrowest column: three still fit at M (~900px) */
    container-type: inline-size;
    display: grid;
    /* at most three columns: a track never narrower than a third, so a wide page adds no empty
       fourth track beside a row-spanning area */
    grid-template-columns: repeat(
        auto-fit,
        minmax(min(max(var(--start-column-min), (100% - 2 * var(--space-8)) / 3), 100%), 1fr)
      );
    align-items: start;
    gap: var(--space-8);
    padding: var(--space-6) max(var(--gutter), (100% - var(--measure)) / 2 + var(--gutter))
      var(--space-8);
  }
  .start > [data-span="all"] {
    grid-column: 1 / -1;
  }
  /* the large search: a wide field in an ink frame, with its button in the same row on every size */
  .start > [data-search] {
    --section-head-type: var(--type-page-title);
    --search-field-max: none;
    --search-field-pad: var(--space-4) var(--space-5);
    --search-field-basis: 0;
    --edge: var(--ink);
  }
  .start > section {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }
  @container (width < 40rem) /* S (DESIGN.md space budget); no token names a container width */ {
    .start > [data-absent~="s"] {
      display: none;
    }
  }

  /* ---- tiles — a list of links in as many columns as fit, one per tile; no width query. ---- */
  .tiles {
    /* a ~24-character Collection name in the entry face beside its count; no token measures a tile */
    --_tiles-min: var(--tiles-min, min(32ch, 100%));
    container: tiles / inline-size;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--_tiles-min), 1fr));
    column-gap: var(--space-8);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  /* a list the template marks as rows (Zuletzt hinzugefügt): one full-width row per entry */
  .tiles[data-rows] {
    --tiles-min: 100%;
  }

  /* a list of bar rows (the Zeitleiste) starts its first baseline on its neighbours': its rows are
     tighter and its face smaller */
  .tiles:has(.register-bar) {
    margin-block-start: var(--space-2);
  }

  .tiles > .register-apart {
    margin-block-start: var(--space-4);
  }

  /* ---- the Feld chooser's place: under what precedes it ---- */
  .chooser {
    margin-top: var(--space-3);
  }

  /* ---- the preview pane's place: the frame's second column ---- */
  .pane {
    /* HIDDEN BY DEFAULT: the pane switch at the bottom of this file switches the column on, and
       nothing switches it off. A negated second query is a complement kept true by hand. */
    --pane-display: none;
    grid-column: pane;
    /* stretch across the frame's ROW, against the frame's align-items: start. Without it a grid item
       is only as tall as its content, so the sheet's `position: sticky` below had no slack and never
       stuck at all — dead styling that reads exactly like live styling. */
    align-self: stretch;
  }

  /* ---- the work/reading column: ONE centered composition for every non-workbench screen. Width is
     the column's own knob (law C3): 52rem default, .narrow, .wide. ---- */
  .column {
    --column-width: 52rem;
    /* full width up to its own: a flex item centred by auto margins would shrink to its content */
    width: 100%;
    max-width: var(--column-width);
    margin: 0 auto;
    padding: var(--space-6) var(--space-4) var(--space-8);
  }
  .column.narrow {
    --column-width: 34rem;
  }
  .column.wide {
    --column-width: 72rem;
  }
  /* The door: the wordmark large and the button below it, centred on the screen (owner 2026-10-01). */
  .door {
    display: grid;
    place-content: center;
    justify-items: center;
    gap: var(--space-6);
    flex: 1 0 auto; /* the viewport's height the page footer leaves */
    padding: var(--space-4);
  }
  .door .wordmark {
    margin: 0;
    font-size: clamp(2.75rem, 9vw, 5.25rem); /* the door only: the X3 mock's 44–84px wordmark */
  }
  .column h1 {
    margin: 0 0 var(--space-5);
    font: var(--type-display);
  }
  .column > .affected {
    margin-block-end: var(--space-6);
  }
  .column > .section-head {
    margin-block: var(--space-7) var(--space-3);
  }
  /* the record's place over the question (a3 loeschen.html) */
  .column > .crumbs {
    margin-block-end: var(--space-4);
  }
  /* the screen header: h1 / context + the reserved marks, once */
  .column header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin-bottom: var(--space-6);
  }
  .column header h1 {
    margin: 0;
  }
  .column header > span {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }
  /* a confirm page names WHICH record: the quoted title next to its Signatur mark */
  .column header strong {
    font: var(--type-title);
  }
  /* the BETWEEN is the composition's, whatever the paragraph is (law C4) */
  .column > p {
    margin: 0 0 var(--space-4);
  }
  /* ...the LOOK only for the plain running paragraph. `.count` and `.hint` carry their own
     component roles, and this layer sits above theirs, so an unnarrowed rule would silently
     outrank them (law C13's second mechanism). */
  .column > p:not([class]) {
    color: var(--ink-2);
  }
  /* a value the paragraph states reads as the value, in ink */
  .column > p:not([class]) > strong {
    color: var(--ink);
  }

  /* ---- dev login page stub (dev.py) ---- */
  .stub {
    max-width: 40rem; /* dev-only reading width — one structural size, no token fits */
    margin: var(--space-6) auto;
    padding: 0 var(--space-4);
  }
  /* biome-ignore lint/style/noDescendingSpecificity: the dev stub holds no .column */
  .stub h1 {
    font: var(--type-display);
    margin: 0 0 var(--space-3);
  }
  .stub p {
    color: var(--ink-2);
  }

  /* ============================================================
     THE PANE SWITCH: at/above it an open pane adds a second frame column (the ledger re-densifies
     by itself — it is a size container). Both consequences are declared inside this one query —
     the frame grows its pane track and the pane shows. The complement is the DEFAULTS above, so the
     condition is read once instead of negated by hand.
     ============================================================ */
  /* REM, not px: the ledger's S form is a 40rem CONTAINER query (components.css) whose "never
     folds while the pane is open" guarantee (decision 1) is an inequality against this switch —
     pane ≤26rem + the 1rem gap + 6rem frame padding (two gutters) out of 80rem leaves main
     ≥ ~47rem > 40rem.
     Both sides must share the rem unit or a non-default root font size silently breaks the
     margin. */
  @media (min-width: 80rem) /* the pane switch — DERIVED per C9 from the arithmetic above; no token names a composition breakpoint */ {
    body.preview .frame {
      grid-template-columns: [main] minmax(0, 1fr) [pane] var(--pane-col);
    }
    body.preview .pane {
      --pane-display: block; /* the pane column exists here (a grid item: this only un-hides it) */
    }
  }

  /* ============================================================
     form-sheet — an article form: lead (header: crumbs + the Titel), margin (aside: record-meta)
     and body (the sections). S/M: one column, the margin under the lead. L: body | margin, the
     margin sticky so Speichern stays in reach. The page's own arrangement, so it asks the viewport,
     not a container (space budget L, design-system.md). Knob for the fields inside: the control
     type (--field-font).
     ============================================================ */
  .form-sheet {
    --field-font: var(--type-body);
    --section-head-type: var(--type-subhead);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "lead" "meta" "body";
    gap: var(--space-8);
    width: 100%;
    max-width: var(--measure);
    margin: 0 auto;
    padding: var(--space-6) var(--gutter) var(--space-8);
  }
  .form-sheet > header {
    grid-area: lead;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }
  .form-sheet > header > .title-field {
    margin: 0;
  }
  .form-sheet > aside {
    grid-area: meta;
  }
  .form-sheet > div {
    grid-area: body;
    min-width: 0;
    container-type: inline-size;
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
  }
  /* the form takes part in submission, not in layout: its sections are the body's stack items */
  .form-sheet > div > form {
    /* biome-ignore lint/nursery/useBaseline: display: contents is allowed for layout (law F) */
    display: contents;
  }
  .form-sheet > div section {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }
  @media (width >= 80rem) /* space budget L (design-system.md): the margin takes a side column */ {
    .form-sheet {
      grid-template-columns: minmax(0, 1fr) 18rem; /* the margin column: the mock's --column-min */
      grid-template-areas: "lead meta" "body meta";
    }
    .form-sheet > aside {
      position: sticky;
      top: var(--space-8);
      align-self: start;
    }
  }

  /* field-grid — fields in aligned cells, at most two per row; [data-span="all"] takes the row.
     S gets one per row: a cell is never narrower than --field-grid-min. */
  .field-grid {
    display: grid;
    --field-grid-min: 18rem; /* the narrowest cell: the mock's --column-min */
    grid-template-columns: repeat(
        auto-fill,
        minmax(max(min(100%, var(--field-grid-min)), calc((100% - var(--space-8)) / 2)), 1fr)
      );
    align-items: start;
    gap: var(--space-6) var(--space-8);
  }
  .field-grid > [data-span="all"] {
    grid-column: 1 / -1;
  }

  /* pairs — one Weitere Angaben row: Feld | Wert | remove. The fields' label and control rows are
     the row's own (subgrid), so the remove centres on the controls whatever their height. S: the
     remove moves beside Feld, Wert takes the next row. */
  .pairs {
    --field-display: grid;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto;
    gap: var(--space-4) var(--space-5);
  }
  .pairs > .field {
    --field-rows: subgrid;
    grid-row: span 2;
  }
  .pairs > .remove {
    grid-area: 2 / 3;
    align-self: center;
  }
  @container (width < 40rem) /* S (DESIGN.md space budget); no token names a container width */ {
    .pairs {
      grid-template-columns: minmax(0, 1fr) auto;
    }
    .pairs > :nth-child(2) {
      grid-column: 1 / -1;
    }
    .pairs > .remove {
      grid-area: 2 / 2;
    }
  }
}
