/* harpseal layout (issues #5, #21). One file for back office + Mini App.
   --brand is overridden per Deployment from [branding] primary_color. */
:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #17212b;
  --muted: #5b6b7a;
  --line: #dde3e9;
  /* The brand and what is derived from it (#129, `ui::brand`): text on
     it, links, and the focus ring, each checked against every light
     surface. These defaults are the Harbour Teal ones. */
  --brand: #0f5c7a;
  --brand-ink: #ffffff;
  --brand-text: #0f5c7a;
  --focus: #0f5c7a;
  /* Field Edge: 3.5:1 on Paper, 3.3:1 on Counter Mist (WCAG 1.4.11). */
  --field-edge: #7d8a97;
  --ok-bg: #e5f5ec;
  --ok-ink: #145c36;
  --err-bg: #fdecec;
  --err-ink: #8a1c1c;
  /* Status pairs beyond approved and refused, their 1px edges (at least
     3:1 on Paper and on their wash), and the fills of meters (#129). Named
     once here so no rule carries a one-off colour (#131). */
  --on-fill: #ffffff;
  --brand-press: #0d4e68;
  --chip-bg: #e8eef3; --chip-ink: #2c4456;
  --caution-bg: #fff3d6; --caution-ink: #6b4a00; --caution-edge: #a37200;
  --caution-text: #8a5a00; --caution-meter: #9a6a00; --attention-bg: #fff8e6;
  --ok-edge: #3d8a5f; --err-edge: #c24141; --err-press: #6f1515; --over: #c62828;
  /* Radii: cards 12, controls 10, bubbles 14, meters and logo tiles 6. */
  --radius: 12px; --radius-control: 10px; --radius-bubble: 14px; --radius-meter: 6px;
  /* Spacing: 4, 8, 12, 16 (the gutter); 24 sets a section off above its heading. */
  --space-xs: 4px; --space-sm: 8px; --space-md: 12px; --space-lg: 24px;
  --gutter: 16px;
  --tap: 48px;
  /* Type scale (#129): a 1.25 ratio between heading levels, from a
     1.125rem title. Body stays 1rem. */
  --step-title: 1.125rem;
  --step-section: calc(var(--step-title) * 1.25);
  --step-page: calc(var(--step-section) * 1.25);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 100%/1.6 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Sukhumvit Set", sans-serif;
  overflow-wrap: anywhere;
}
/* `main` is the container the content's breakpoints query (#123): the
   back office's side navigation takes 15rem, so the viewport says
   little about the room the content has. */
main {
  container-type: inline-size;
  /* A size container has no content width: without this, the shell's
     grid (auto margins, no stretch) would shrink it to nothing. */
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: var(--gutter);
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}
.mini main { max-width: 560px; }
/* Headings: the Mini App keeps its compact sizes; the back office (and its
   sign-in pages, `.office`) takes the 1.25 scale (#129). 1.4 leaves Thai
   upper vowels and tone marks room on a second line (1.3 nearly touched
   at 28 px); `balance` keeps short last lines off. */
h1 { font-size: 1.375rem; line-height: 1.3; margin: 8px 0 16px; }
h2 { font-size: 1.125rem; margin: 0 0 12px; }
.office h1, .office h2, .office h3 { line-height: 1.4; text-wrap: balance; }
.office h1 { font-size: var(--step-page); }
.office h2 { font-size: var(--step-section); }
p { margin: 0 0 12px; }
a { color: var(--brand-text); text-underline-offset: .2em; }
.muted { color: var(--muted); font-size: .875rem; }

/* Bar */
.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 8px var(--gutter); background: var(--brand); color: var(--brand-ink);
}
.bar a { color: var(--brand-ink); text-decoration: none; }
.brand { font-weight: 700; margin-right: auto; min-height: var(--tap); display: flex; align-items: center; }
.brand { gap: 10px; }
.brand .logo { height: 32px; width: auto; border-radius: var(--radius-meter); background: var(--card); }
.who { display: flex; align-items: center; gap: 8px; margin: 0; font-size: .875rem; opacity: .9; }
.who .link { color: var(--brand-ink); }

/* Cards and forms */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--gutter); margin-bottom: var(--gutter);
}
label { display: block; font-weight: 600; margin: 0 0 6px; }
.field { margin-bottom: 14px; }
input, select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  font: inherit; color: inherit; background: var(--card);
  border: 1px solid var(--field-edge); border-radius: var(--radius-control);
}
textarea { min-height: 120px; resize: vertical; }
/* One focus ring (#129): solid, 3px, from the brand (`--focus` is at least
   3:1 on every light surface), on links, buttons, summaries and fields. */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--focus); }
[hidden] { display: none !important; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); min-width: var(--tap); padding: 0 20px;
  font: inherit; font-weight: 600; border-radius: var(--radius-control); cursor: pointer;
  border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  text-decoration: none; touch-action: manipulation;
}
button.secondary { background: var(--card); color: var(--brand-text); border-color: var(--brand-text); }
button.done { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok-edge); }
/* Danger (#120): an action in proportion to its reach (sends to everyone,
   makes many Students left). Refused Ink, never the brand: white on it is
   9.3:1. Its own solid focus ring, so a red brand cannot hide it. */
button.danger, .btn.danger { background: var(--err-ink); border-color: var(--err-ink); color: var(--on-fill); }
button.danger:hover, .btn.danger:hover { background: var(--err-press); border-color: var(--err-press); }
button.danger:focus-visible, .btn.danger:focus-visible { outline: 3px solid var(--err-ink); outline-offset: 2px; }
button.link { background: none; border: 0; padding: 0 4px; min-width: 0; text-decoration: underline; font-weight: 400; }
.wide { width: 100%; }
.row2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@container (min-width: 600px) { .row2 { grid-template-columns: 1fr 1fr; } }

.cols { display: grid; gap: 0 var(--gutter); grid-template-columns: minmax(0, 1fr); align-items: start; }
@container (min-width: 860px) { .cols { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); } }

.narrow { max-width: 440px; margin-left: auto; margin-right: auto; }

/* table.rows: stacked cards while main's content is under 860 px (a
   900 px window without the side navigation), a real table from there.
   Each td carries data-label, shown as its caption on phones. */
table.rows { width: 100%; border-collapse: collapse; }
table.rows thead { display: none; }
table.rows tr { display: block; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px var(--gutter); margin-bottom: 12px; }
table.rows td { display: flex; gap: 12px; padding: 6px 0; min-width: 0; }
table.rows td::before { content: attr(data-label); flex: 0 0 8rem; color: var(--muted); font-size: .875rem; }
@container (min-width: 860px) {
  table.rows { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
  table.rows thead { display: table-header-group; }
  table.rows tr { display: table-row; border: 0; border-top: 1px solid var(--line); }
  table.rows th { text-align: left; padding: 10px 12px; color: var(--muted); font-size: .875rem; overflow-wrap: normal; }
  table.rows td { display: table-cell; padding: 10px 12px; }
  table.rows td::before { content: none; }
}

/* Usage banner slot (#26) */
#usage-banner:empty { display: none; }
#usage-banner { padding: 10px var(--gutter); font-weight: 600; }

/* Flash */
.flash { padding: 12px 14px; border-radius: var(--radius-control); margin-bottom: var(--gutter); font-weight: 600; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.err { background: var(--err-bg); color: var(--err-ink); }

/* Lists (no tables: nothing scrolls sideways on a phone) */
.list { list-style: none; margin: 0; padding: 0; }
.list > li {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.list > li:first-child { border-top: 0; }
.list .name { font-weight: 600; flex: 1 1 12rem; min-width: 0; }
.code { font-variant-numeric: tabular-nums; color: var(--muted); }
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--chip-bg); color: var(--chip-ink); font-size: .8125rem; white-space: nowrap;
}
.chip.ok { background: var(--ok-bg); color: var(--ok-ink); }
.search { position: sticky; top: 0; background: var(--card); padding-bottom: 8px; z-index: 1; }
.count { margin: 8px 0 0; }
.htmx-request .spinner { opacity: 1; }
.spinner { opacity: 0; transition: opacity .2s; }

/* Mini App */
.status { display: flex; gap: 12px; align-items: center; }
.avatar {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700;
}
.news > li { display: block; }
.news .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
.foot { text-align: center; color: var(--muted); font-size: .8125rem; padding: 8px var(--gutter) 24px; }
.notice h2 { margin-top: 20px; }
.notice ul { padding-left: 1.25rem; }

/* Students (#22) */
.li { display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; font-size: .875rem; }
.li-active { color: var(--ok-ink); }
.li-unreachable { color: var(--caution-text); }
.li-none { color: var(--muted); }
td.icons { flex-wrap: wrap; }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 12px 0; }
.facts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px 16px; margin: 0 0 16px; }
.facts dt { color: var(--muted); font-size: .875rem; }
.facts dd { margin: 0 0 8px; }
@container (min-width: 600px) { .facts { grid-template-columns: 10rem minmax(0, 1fr); } .facts dd { margin: 0; } }
.chip.override { background: var(--caution-bg); color: var(--caution-ink); }
.field-warning { color: var(--caution-text); font-weight: 600; margin: 6px 0 0; }
.field-error { color: var(--err-ink); font-weight: 600; margin: 6px 0 0; }
/* An error line an inline check fills (#135): no room while empty. */
.field-error:empty { margin: 0; }
[aria-invalid="true"] { border-color: var(--err-ink); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.sr-default { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.list form { margin: 0; }
.links .name { flex: 0 0 auto; }
.manual-link { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
h3 { font-size: 1rem; margin: 12px 0 8px; }
.office h3 { font-size: var(--step-title); margin: 16px 0 8px; }
details summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; }

/* Roster import (#24) */
.chip.err { background: var(--err-bg); color: var(--err-ink); }
.warn { padding: 12px 14px; border-radius: var(--radius-control); margin-bottom: var(--gutter);
  background: var(--err-bg); color: var(--err-ink); font-weight: 600; }
label.choice { display: flex; align-items: flex-start; gap: 10px; min-height: var(--tap);
  padding: 8px 0; font-weight: 400; cursor: pointer; }
label.choice input { width: auto; min-height: 0; margin-top: 4px; flex: none; }
input[type="file"] { padding: 8px; }
progress { width: 100%; height: 16px; accent-color: var(--focus); }
.names { columns: 14rem auto; margin: 0; padding-left: 1.25rem; }
/* The typed confirmation of a broad full replace (#120), above the buttons. */
.confirm-reach { max-width: 36rem; }
/* A send that cannot go yet (#135): the reason on its own line of the
   action row, above the disabled button it describes. */
.blocked-reason { flex-basis: 100%; margin: 0; padding: 12px 14px; border-radius: var(--radius-control);
  background: var(--caution-bg); color: var(--caution-ink); font-weight: 600; }

/* Admin pages (#27) */
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 8px; margin: 0; font-size: .875rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.checks { border: 0; margin: 0 0 12px; padding: 0; }
.checks legend { font-weight: 600; margin-bottom: 4px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; min-height: var(--tap); margin: 0; }
label.check input { width: auto; min-height: 0; }
tr.changed td { background: var(--attention-bg); }
.secret { font-size: var(--step-section); letter-spacing: .05em; user-select: all; }
.default-text { white-space: pre-wrap; color: var(--muted); }

/* Announcements (#25) */
.head-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.announcement-form fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 0 0 16px; min-width: 0; }
.announcement-form legend { font-weight: 600; padding: 0 4px; }
/* The Audience choice (#120): a group inside the Audience fieldset. */
.announcement-form fieldset.scope, .announcement-form fieldset.checks { border: 0; padding: 0; margin: 0 0 8px; }
.announcement-form fieldset.scope legend, .announcement-form fieldset.checks legend { padding: 0; margin-bottom: 4px; }
/* An informational note (#120): neutral, neither approved nor refused. */
.note { padding: 12px 14px; border-radius: var(--radius-control); margin-bottom: var(--gutter);
  background: var(--chip-bg); color: var(--chip-ink); font-weight: 600; }
.warn-note { background: var(--caution-bg); color: var(--caution-ink); }
.count .estimate { font-weight: 600; margin-bottom: 0; }
.preview .bubble { border: 1px solid var(--line); border-radius: var(--radius-bubble); padding: 12px; max-width: 22rem; background: var(--card); }
.preview .bubble p { white-space: pre-wrap; overflow-wrap: anywhere; }
.preview .btn { pointer-events: none; margin-top: 8px; }
a.btn.secondary { background: var(--card); color: var(--brand-text); border-color: var(--brand-text); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.chips a.chip { text-decoration: none; min-height: var(--tap); display: inline-flex; align-items: center; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
form.inline { display: inline-flex; margin: 0; }

/* Usage and Quotas (#26) */
#usage-banner:not(:empty) { padding: 0; }
.usage-line { margin: 0; padding: 10px var(--gutter); font-weight: 600; }
.usage-line.warn { background: var(--caution-bg); color: var(--caution-ink); }
.usage-line.over { background: var(--err-bg); color: var(--err-ink); }
.usage-line a { color: inherit; }
.chip.warn { background: var(--caution-bg); color: var(--caution-ink); }
.chip.over { background: var(--err-bg); color: var(--err-ink); }
.usage h3 { margin: 16px 0 8px; }
.usage .used { font-weight: 600; }
.meter { height: 12px; border-radius: var(--radius-meter); background: var(--line); overflow: hidden; margin: 0 0 12px; }
.meter span { display: block; height: 100%; background: var(--ok-ink); }
.meter.warn span { background: var(--caution-meter); }
.meter.over span { background: var(--over); }
.usage-kv { margin-bottom: 12px; }
.chart { margin: 0; }
.chart svg { display: block; width: 100%; height: 120px; background: var(--bg); border-radius: var(--radius-control); }
.chart .bar-m { fill: var(--focus); }
.chart .bar-f { fill: var(--over); }
.chart .key::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 4px; }
.chart .key.m::before { background: var(--focus); }
.chart .key.f::before { background: var(--over); }

/* Mini App pages (#28): one column, 16 px gutters, 48 px tap targets,
   nothing wider than the viewport at 360 px. */
.app-who { display: flex; gap: 12px; align-items: center; }
.app-who h1 { margin: 0; font-size: 1.125rem; }
.app-who p { margin: 0; }
.app-consent { margin: 12px 0 0; }
.app-news { list-style: none; margin: 0; padding: 0; }
.app-news > li { margin-bottom: 12px; }
.app-news details { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.app-news summary { display: block; list-style: none; cursor: pointer; padding: var(--gutter); min-height: var(--tap); }
.app-news summary::-webkit-details-marker { display: none; }
.app-news h3 { font-size: 1rem; margin: 0 0 4px; }
.app-news .clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  line-clamp: 2; overflow: hidden; margin: 0; color: var(--muted); }
.app-news details[open] .clamp { display: none; }
.app-news .more { color: var(--brand-text); font-size: .875rem; }
.app-news details[open] .more { display: none; }
.app-news .full { padding: 0 var(--gutter) var(--gutter); }
.app-meta { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 8px; margin-top: 8px; font-size: .875rem; color: var(--muted); }
.app-body { white-space: pre-line; overflow-wrap: anywhere; }
/* The body format (#108): lists, links. */
.app-body ul, .app-body ol { margin: 4px 0; padding-left: 1.5em; white-space: normal; }
.app-body li { white-space: pre-line; }
.app-body a { color: var(--brand-text); text-decoration: underline; }
/* Headings and the text colours (#113): a fixed palette, each at least
   4.5:1 on #ffffff and on #f4f6f8 (DESIGN.md "Text palette"). */
.app-body .app-h { white-space: normal; margin: 12px 0 4px; line-height: 1.4; }
.app-body h2.app-h { font-size: 1.125rem; }
.app-body h3.app-h { font-size: 1rem; }
.tc-red { color: #b42318; }
.tc-orange { color: #b54708; }
.tc-green { color: #067647; }
.tc-blue { color: #175cd3; }
.tc-grey { color: #475467; }
/* Colour adds emphasis, never meaning alone: coloured text is also
   semi-bold, so it stands out without colour; links keep their underline,
   so blue text is not taken for a link. */
.tc-red, .tc-orange, .tc-green, .tc-blue, .tc-grey { font-weight: 600; }
/* PDF attachments (#113): name and size, one per line. */
.app-files { list-style: none; margin: 8px 0 0; padding: 0; }
.app-files li { margin: 4px 0; }
.app-files a { display: inline-flex; align-items: center; min-height: var(--tap); color: var(--brand-text); text-decoration: underline; }
.app-files .size { color: var(--muted); font-size: .875rem; }
.md-toolbar .swatch { font-weight: 700; }
.md-toolbar { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.md-toolbar button { min-width: var(--tap); padding: 4px 10px; }
.app-img { display: block; max-width: 100%; height: auto; margin: 8px 0; border-radius: var(--radius); }
.app-images { margin-top: 8px; }
.image-slot .app-img { max-width: 240px; }
.announcement-images .hint { font-weight: 600; }
.mini-preview { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-top: 8px; background: var(--card); }
.app-ack { margin: 12px 0 0; }
.app-ack button { width: 100%; }
.app-acked { display: flex; align-items: center; justify-content: center; min-height: var(--tap);
  margin: 12px 0 0; border-radius: var(--radius-control); background: var(--ok-bg); color: var(--ok-ink); font-weight: 600; }
.app-wait { color: var(--caution-text); font-weight: 600; }
.app-center { text-align: center; }
.app-center .btn { margin-top: 8px; }

/* Branding (#114): the Mini App's slim header, and the previews of
   /admin/branding. */
.mini-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px var(--gutter);
  background: var(--brand); color: var(--brand-ink); font-weight: 700;
}
.mini-bar .logo { height: 28px; width: auto; border-radius: var(--radius-meter); background: var(--card); }
.brand-preview { border: 1px dashed var(--line); border-radius: var(--radius-control); padding: 8px 12px 12px; }
.brand-preview .bar { border-radius: var(--radius-control); }
.brand-preview .mini-frame { max-width: 380px; border-radius: var(--radius-control); overflow: hidden; }
.menu-preview { margin: 8px 0 16px; }
.menu-preview svg { width: 100%; max-width: 720px; height: auto; display: block; border-radius: var(--radius-control); }
.menu-preview rect { fill: rgba(255,255,255,.18); stroke: #ff1744; stroke-width: 8; }
.menu-preview text { fill: #fff; stroke: #000; stroke-width: 6; paint-order: stroke; font-size: 72px; font-weight: 700; }

/* Manual Link picker (#143): a control that loads the recent unlinked
   chat accounts as radio rows (the whole row is the 48 px label), then
   the typed id behind a disclosure. The loaded list takes the focus
   without a ring unless the keyboard put it there. */
.manual-link .pick { margin-bottom: var(--space-sm); }
.manual-link .pick-area { margin-bottom: var(--space-md); }
.manual-link .pick-load { margin-top: var(--space-xs); }
.manual-link .pick .field-warning { margin: 0; }
.manual-link .pick:focus { outline: none; }
.manual-link .pick:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.manual-link .pick .list > li { padding: 0; }
.manual-link .pick label.choice { flex: 1 1 auto; margin: 0; padding: var(--space-sm) 0; }
.manual-link .pick .name { font-weight: 600; }
.manual-link .pick-typed { margin: 0 0 var(--space-md); }
.manual-link .pick-typed > summary { gap: var(--space-sm); font-weight: 600; color: var(--brand-text); }
.manual-link .pick-typed > summary::before { content: ""; width: 8px; height: 8px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(-45deg); }
.manual-link .pick-typed[open] > summary::before { transform: rotate(45deg); }
.manual-link .pick-typed .row2 { margin-top: var(--space-sm); }

/* Back-office shell (#123): skip link, grouped navigation, term status
   home, technical details. Appended to ui.css (see `ui::CSS`). */

/* Skip link: off screen until focused, then a Paper tab over the bar. */
.skip {
  position: absolute; left: 8px; top: -120px; z-index: 10;
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 16px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--radius-control); font-weight: 600;
}
.skip:focus { top: 8px; outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }

/* The bar holds the letterhead and who is signed in; the email hides on
   phones so the bar stays one row. */
.bar { flex-wrap: nowrap; }
.brand { min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who { flex: none; }
.who .link { min-height: var(--tap); }
@media (max-width: 639px) { .who-email { display: none; } }

/* The current page is the brand with its ink, the bar's own pair, whose
   contrast the branding page checks on save, so a light brand stays legible.
   Navigation: one <details>. Phones: a "เมนู" row naming the current page
   that opens the groups. From 640 px: a side column. */
.menu { background: var(--card); border-bottom: 1px solid var(--line); }
.menu > summary {
  display: flex; align-items: center; gap: 10px; min-height: var(--tap);
  padding: 0 var(--gutter); font-weight: 600; cursor: pointer; list-style: none;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary .icon { flex: none; width: 20px; height: 20px; }
.menu-here { color: var(--muted); font-weight: 400; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-here::before { content: "·"; margin-right: 10px; }
.menu[open] > summary { border-bottom: 1px solid var(--line); }
.menu > summary:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.nav { padding: 4px 8px 12px; }
.nav ul { list-style: none; margin: 0; padding: 0; }
.nav a {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 0 12px;
  border-radius: var(--radius-control); color: var(--ink); text-decoration: none;
}
/* Icons (#nav icons): 20 px line drawings in Slate Note beside Ledger Ink
   names, so the words still lead; the current page's icon takes its ink. */
.nav .icon { flex: none; width: 20px; height: 20px; color: var(--muted); }
.nav a:hover .icon { color: var(--ink); }
.nav a[aria-current="page"] .icon { color: inherit; }
.nav-label { min-width: 0; }
.nav a:hover { background: var(--bg); }
.nav a:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.nav a[aria-current="page"] { background: var(--brand); color: var(--brand-ink); font-weight: 700; }
.nav a[aria-current="page"]:hover { background: var(--brand); }
/* A group is a <details>: its name is a 48 px row with a chevron that
   turns to point at the closed group. */
.nav-sec { margin-top: var(--space-sm); }
.nav-group {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: var(--tap); padding: 0 12px; border-radius: var(--radius-control);
  color: var(--muted); font-size: .875rem; font-weight: 600; cursor: pointer; list-style: none;
}
.nav-group::-webkit-details-marker { display: none; }
.nav-group:hover { background: var(--bg); color: var(--ink); }
.nav-group:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.nav .nav-group .icon { width: 16px; height: 16px; color: inherit; transition: rotate .15s ease-out; }
.nav-sec:not([open]) > .nav-group .icon { rotate: -90deg; }
/* "ย่อเมนู": a quiet row at the top of the side column, from 640 px and
   only with JS (the script shows it). */
.nav .nav-rail-toggle { display: none; }

@media (min-width: 640px) {
  .office-shell { display: grid; grid-template-columns: 15rem minmax(0, 1fr); align-items: start; }
  .office-shell.no-nav { display: block; }
  .menu {
    position: sticky; top: 0; max-height: 100vh; overflow-y: auto;
    border-bottom: 0; border-right: 1px solid var(--line); min-height: calc(100vh - 64px);
  }
  .nav { padding: 8px 8px 24px; }
  .nav .nav-rail-toggle:not([hidden]) {
    display: flex; justify-content: flex-start; gap: 12px; width: 100%; min-height: var(--tap);
    margin: 0 0 4px; padding: 0 12px; border-radius: var(--radius-control);
    color: var(--muted); font-size: .875rem; font-weight: 600; text-decoration: none;
  }
  .nav .nav-rail-toggle:hover { background: var(--bg); color: var(--ink); }
  .nav .nav-rail-toggle:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
  .nav .nav-rail-toggle .icon { color: inherit; transition: rotate .15s ease-out; }

  /* The icon rail: a 72 px column of icons. Each name stays in its link
     (transparent, never `visibility: hidden`, so it still names the link)
     and shows as a Ledger Ink label beside the icon on hover and focus.
     The column scrolls with the page (no inner scroll box to clip the
     labels), every group is open (no headings to open them), and a Rule
     Line parts the groups. */
  .nav-rail .office-shell:not(.no-nav) { grid-template-columns: 4.5rem minmax(0, 1fr); }
  .nav-rail .menu { position: static; max-height: none; overflow: visible; }
  .nav-rail .nav { padding: 8px 12px 24px; }
  .nav-rail .nav a, .nav-rail .nav .nav-rail-toggle { position: relative; justify-content: center; padding: 0; }
  .nav-rail .nav .nav-rail-toggle .icon { rotate: 180deg; }
  .nav-rail .nav-label {
    position: absolute; left: calc(100% + 8px); top: 50%; translate: 0 -50%; z-index: 5;
    width: max-content; max-width: 16rem; padding: 6px 10px; border-radius: 6px;
    background: var(--ink); color: var(--card); font-size: .875rem; font-weight: 600;
    pointer-events: none; opacity: 0;
  }
  .nav-rail .nav :is(a, .nav-rail-toggle):is(:hover, :focus-visible) .nav-label { opacity: 1; }
  .nav-rail .nav-group { display: none; }
  .nav-rail .nav-sec { margin-top: var(--space-sm); padding-top: var(--space-sm); border-top: 1px solid var(--line); }
  .nav-rail .nav-sec::details-content { content-visibility: visible; }
}
@media (prefers-reduced-motion: reduce) {
  .nav .icon { transition: none !important; }
}
/* Where the browser lets CSS show a closed <details>, the side column is
   always open from 640 px and the button goes; elsewhere it stays. */
@supports selector(::details-content) {
  @media (min-width: 640px) {
    .menu > summary { display: none; }
    .menu::details-content { content-visibility: visible; }
  }
}

/* Term status home (Attention Wash #fff8e6 on warn rows): one ledger of status cards, each a state, one fact
   and one next action. Attention is a wash, never a shadow. */
.term { padding: 0; overflow: hidden; }
.status-list { list-style: none; margin: 0; padding: 0; }
.status-card {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px 16px;
  padding: var(--gutter); border-top: 1px solid var(--line);
}
.status-card:first-child { border-top: 0; }
.status-card[data-state="warn"] { background: var(--attention-bg); }
/* Not `.chip.warn`: the roster's `.warn` block would pad it. Its border
   (var(--caution-edge)) is 4.0:1 on the Attention Wash, so the chip reads on a warn row. */
.chip.caution { background: var(--caution-bg); color: var(--caution-ink); border: 1px solid var(--caution-edge); padding: 1px 9px; }
.status-card h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0; font-size: var(--step-title); }
.status-card .fact { margin: 0; }
.status-card .btn { justify-self: start; margin-top: 4px; }
/* Three columns once main's content has room (about 1000 px with the
   side navigation, 750 px without), not at a viewport width. */
@container (min-width: 720px) {
  .status-card { grid-template-columns: 14rem minmax(0, 1fr) auto; align-items: center; }
  .status-card .btn { justify-self: end; margin-top: 0; }
}

/* "ข้อมูลทางเทคนิค": raw details behind a closed disclosure. */
.tech { margin: 0 0 var(--gutter); border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.tech > summary { padding: 0 var(--gutter); font-weight: 600; color: var(--muted); }
.tech > summary:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; border-radius: var(--radius); }
.tech-body { padding: 0 var(--gutter) var(--gutter); border-top: 1px solid var(--line); }
.tech-body > :first-child { margin-top: 12px; }
.tech-body .card { border: 0; padding: 0; margin: 12px 0 0; }
/* Help where the work is (#127): the upload help beside the file input,
   empty states, the next step after an import, the first-run checklist
   and the empty announcement preview. Flat: tone and 1px rules only. */
.upload-help h2 { margin-top: 0; }
.upload-help h3 { margin-top: 16px; }
.upload-help .rules { margin: 0; padding-left: 1.25rem; }
.upload-help .rules li { margin: 2px 0; }
.upload-columns > li { align-items: baseline; gap: 2px 10px; }
.upload-columns .code-head { flex: 1 1 auto; overflow-wrap: anywhere; }
.upload-columns .holds { flex: 1 1 100%; }
.upload-columns .example { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.upload-help p:last-child { margin: 12px 0 0; }
/* "เว้นว่างได้" reads quieter than "ต้องมีค่า": Paper with a rule, Slate Note text (5.4:1). */
.chip.quiet { background: var(--card); color: var(--muted); border: 1px solid var(--line); }

.card.empty p { margin: 0; max-width: 60ch; }
.card.empty .btn { margin-top: 12px; }

.next-step h2 { margin-top: 0; }
.next-step p { margin: 0 0 4px; max-width: 60ch; }

.setup h2 { margin-top: 0; }
.setup > p { margin: 0 0 4px; }
.checklist > li { gap: 4px 12px; }
.checklist .name { min-height: var(--tap); display: inline-flex; align-items: center; }
/* The tick: a drawn ring, filled Approved Ink with a white check when done. */
.tick {
  position: relative; flex: none; width: 22px; height: 22px;
  border: 2px solid var(--field-edge); border-radius: 50%;
}
.tick.done { background: var(--ok-ink); border-color: var(--ok-ink); }
.tick.done::after {
  content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px;
  border: solid var(--on-fill); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.checklist li[data-done] .name { color: var(--muted); }

.preview-placeholder {
  margin: 0; padding: 12px 14px; color: var(--muted);
  border: 1px dashed var(--field-edge); border-radius: var(--radius-bubble);
}

table.rows + .card.empty { margin-top: var(--gutter); }

/* Type, contrast and access (#129). Appended after the shell and the
   onboarding help (see `ui::CSS`). Measured, not eyeballed: every ratio
   below is WCAG 2 relative luminance. */

/* On the letterhead the ring is the bar's own ink: white, else Ledger
   Ink, else black (a light TOML colour), at least 4.5:1 on the brand. */
.bar :focus-visible, .mini-bar :focus-visible { outline-color: var(--brand-ink); }
/* The current page's ring sits inside its brand fill, in the bar's ink. */
.nav a[aria-current="page"]:focus-visible { outline: 3px solid var(--brand-ink); outline-offset: -5px; }

/* Numbers line up in tables, facts, counts, meters and status cards. */
table.rows td, .facts dd, .kv dd, .count, .pager, .usage, .status-card .fact,
[data-count], .code { font-variant-numeric: tabular-nums; }

/* Targets (WCAG 2.5.8): links in tables, lists and facts, and the "back"
   link (`a.back`), are at least 24 px tall. A link inside a sentence is
   exempt and keeps the sentence's 1.6 line. Buttons and fields stay 48 px. */
:where(.office main) :where(td, dd, li, .pager, .name) > a:not(.btn, .chip),
:where(.office main) a.back {
  display: inline-block; min-height: 24px; line-height: 1.6;
}

/* A table whose columns follow the Deployment's config (the Students
   list) scrolls inside its own focusable region, never the page. */
.table-scroll { overflow-x: auto; }

/* Checkboxes and radios: 20 px boxes in the brand, inside 48 px labels. */
input[type="checkbox"], input[type="radio"] {
  width: 20px; height: 20px; min-height: 0; flex: none; accent-color: var(--focus);
}
label.check input, label.choice input { width: 20px; height: 20px; }

/* Status chips carry a 1px edge of at least 3:1 on Paper and on their
   own wash: Approved var(--ok-edge) (4.2:1 / 3.7:1), Refused var(--err-edge) (5.1:1 /
   4.5:1), Caution var(--caution-edge) (4.2:1 / 3.8:1). Neutral chips are labels whose
   words carry them; they stay borderless. */
.chip.ok { border: 1px solid var(--ok-edge); padding: 1px 9px; }
.chip.err, .chip.over { border: 1px solid var(--err-edge); padding: 1px 9px; }
.chip.warn, .chip.override { border: 1px solid var(--caution-edge); padding: 1px 9px; }
/* A long chip wraps instead of pushing the page sideways at 360 px. */
.chip { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }

/* A Link's state is a word as well as a glyph (#129). */
.li-word { color: var(--ink); }
.li-unreachable .li-word { color: var(--caution-text); }
.li-none .li-word { color: var(--muted); }

/* Field errors sit under the field they describe (`aria-describedby`). */
.field-error { overflow-wrap: anywhere; }

/* Motion: the only thing that moves is the HTMX spinner's fade; with
   reduced motion it appears and goes at once, so the state still shows. */
@media (prefers-reduced-motion: reduce) {
  .spinner { transition: none; }
}
/* Read by screen readers, not drawn (#134); any page may use it. */
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
/* Polish (#131): one set of states, one rhythm, and wrapping that keeps
   ids, codes and dates whole. Appended last (see `ui::CSS`); every value
   is a token from `:root` in ui.css. */

/* States. Hover and active move a fill one step (the brand to
   `--brand-press`, Paper to Counter Mist, then Chip Fog); focus is the one
   ring; disabled is Chip Fog with Slate Note (4.6:1); busy keeps the label
   and adds a drawn ring. No shadow, no lift. */
:is(button, .btn):not(.secondary, .danger, .done, .link, :disabled, [aria-disabled="true"]):is(:hover, :active) {
  background: var(--brand-press); border-color: var(--brand-press);
}
:is(button, a.btn).secondary:not(:disabled, [aria-disabled="true"]):hover { background: var(--bg); }
:is(button, a.btn).secondary:not(:disabled, [aria-disabled="true"]):active { background: var(--chip-bg); }
button.danger:active, .btn.danger:active { background: var(--err-press); border-color: var(--err-press); }
button.done:hover, button.done:active { border-color: var(--ok-ink); }
button.link:hover, a:hover { text-decoration-thickness: 2px; }
:is(button, .btn):not(.link):active { translate: 0 1px; }
.chips a.chip:hover { background: var(--line); }
.chips a.chip:active { background: var(--chip-ink); color: var(--on-fill); }
.menu > summary:hover, .tech > summary:hover { background: var(--bg); }
.tech > summary:hover { color: var(--ink); border-radius: var(--radius); }
:is(input, select, textarea):not(:disabled, [aria-invalid="true"]):hover { border-color: var(--muted); }

:is(button, .btn):disabled, :is(button, .btn)[aria-disabled="true"] {
  background: var(--chip-bg); border-color: var(--line); color: var(--muted);
  cursor: not-allowed; translate: none;
}
:is(input, select, textarea):disabled {
  background: var(--bg); color: var(--muted); border-color: var(--line); cursor: not-allowed;
}
/* Busy: a form that is posting (`aria-busy`, set by `ui::busy`) marks
   its submit buttons `aria-disabled` (drawn as disabled; a repeat is
   cancelled, nothing is `disabled`) and rings the one pressed
   (`data-busy`); an HTMX form also rings through `htmx-request`. */
form[aria-busy="true"], form[aria-busy="true"] :is(button, .btn)[aria-disabled="true"] { cursor: progress; }
:is(button, .btn)[data-busy]::after,
form.htmx-request button[type="submit"]::after,
button.htmx-request::after {
  content: ""; flex: none; width: 1em; height: 1em; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: busy-turn .8s linear infinite;
}
@keyframes busy-turn { to { rotate: 1turn; } }
/* Under reduced motion the ring stands still: the state still shows. */
@media (prefers-reduced-motion: reduce) {
  :is(button, .btn)[data-busy]::after, form.htmx-request button[type="submit"]::after,
  button.htmx-request::after { animation: none; border-right-color: currentColor; border-style: dotted; }
}

/* Rhythm. Fields and labels on the 4-8-12-16 scale; a section heading
   gets more room above it (24) than below (12); buttons in a row never
   touch: an action row is `.actions` (12 apart), and two buttons side by
   side anywhere else keep the same 12. */
.office .field { margin-bottom: var(--gutter); }
.office label { margin-bottom: var(--space-sm); }
.office :is(label.check, label.choice) { margin-bottom: 0; }
:where(.office main) :where(table, .table-scroll, .card, .list, ul, ol, form, p, dl, div, details, section) + h2 {
  margin-top: var(--space-lg);
}
:where(.office main) :not(.actions, .md-toolbar, .head-row, .pager, .chips, .inline) > :is(button, .btn) + :is(button, .btn) {
  margin-left: var(--space-md);
}
.actions { gap: var(--space-md); margin-top: var(--space-sm); align-items: center; }
.actions form { margin: 0; }
/* Whatever follows an action row (a table, a list, a card) keeps a
   gutter (16) from its buttons; a heading keeps its own 24 above. */
:where(.office main) .actions + :not(h1, h2, h3, [hidden]) { margin-top: var(--gutter); }
/* A row holding a stacked form (a rename form beside its delete button)
   lines its buttons up along the bottom, not the middle of the form. */
.actions:has(> form > :is(input:not([type="hidden"]), select, textarea)) { align-items: flex-end; }
/* A stacked form (ชื่อ, the field, then its button) keeps 12 between the
   field and the button; a row (`form.inline`, `.actions`) spaces with
   its gap instead. */
:where(.office main) :not(.actions, .inline, .md-toolbar, .head-row, .pager, .chips, .saved-row, .list > li)
  > :is(input:not([type="hidden"], [type="checkbox"], [type="radio"]), select, textarea)
  + :is(button, .btn) { margin-top: var(--space-md); }
.head-row { margin-bottom: var(--space-md); }
.head-row h1 { margin-bottom: 0; }

/* Wrapping. A chip breaks only between words; buttons and short labels
   stay one line (a long Thai button label may still wrap between words).
   A number (`.num`) stays whole. An id or a date breaks only when its
   column has no room for it, and the stacked rows below give every value
   the whole width beside its caption; a long technical token (a UUID, a
   key) may still break rather than push the page sideways. */
.num, .nowrap { white-space: nowrap; overflow-wrap: normal; }
.chip { overflow-wrap: break-word; }
button, .btn { overflow-wrap: break-word; max-width: 100%; text-align: center; }
form.inline { flex-wrap: wrap; align-items: center; gap: var(--space-sm) var(--space-md); }
form.inline label { margin: 0; white-space: nowrap; }
form.inline input:not([type="checkbox"], [type="radio"]) { flex: 1 1 10rem; width: auto; min-width: 0; }
form.inline :is(button, .btn) { white-space: nowrap; }
/* An inline form with a field in an action row (a rename beside its
   delete) takes the room the row has, up to a readable 40rem. */
.actions > form.inline:has(> input:not([type="hidden"], [type="checkbox"], [type="radio"])) { flex: 1 1 20rem; max-width: 40rem; }
.list .name, a.name { overflow-wrap: break-word; }
/* A stacked row (phones): the caption floats in its own 8rem column,
   beside every part of the value however many there are, and the value
   flows as text in the rest, so a name, its chip and a note wrap
   instead of squeezing each other into single letters; the Link icons
   stay one row that wraps. */
@container (max-width: 859.98px) {
  table.rows td { display: flow-root; padding-left: calc(8rem + var(--space-md)); }
  table.rows td::before { float: left; width: 8rem; margin-left: calc(-8rem - var(--space-md)); }
  table.rows td .li { margin-right: var(--space-md); }
}
/* A table (wider): numbers right-aligned in tabular figures. */
@container (min-width: 860px) {
  table.rows :is(th, td).num { text-align: right; }
  table.rows { margin-bottom: var(--space-md); }
}

/* The Mini App keeps its own scale (#129 left these to the back office's
   rules): meta lines at its .875rem step, 20 px boxes inside 48 px labels,
   status chips with their 1px edges. Named here so a back-office change
   cannot move them. */
.mini .muted { font-size: .875rem; }
.mini input[type="checkbox"], .mini input[type="radio"] { width: 20px; height: 20px; }
/* #142 Texts page: each page's texts behind a disclosure, closed on load
   and opened by a search, a page filter or an edit to fix. The summary is
   the group's 48 px row: a chevron that turns when open, the group's name
   drawn at the title step (not a heading: a summary is a button, and a
   heading inside it is flattened into the button's name), the to-fix chip. */
.text-group { margin: 0 0 var(--space-sm); border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.text-group > summary { list-style: none; gap: var(--space-sm); flex-wrap: wrap; padding: var(--space-xs) var(--gutter); }
.text-group > summary::-webkit-details-marker { display: none; }
.text-group > summary:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; border-radius: var(--radius); }
.text-group > summary .group-name { font-size: var(--step-title); font-weight: 700; line-height: 1.4; min-width: 0; overflow-wrap: anywhere; }
.text-group > summary .fold { flex: none; width: 20px; height: 20px; color: var(--muted); transition: rotate .15s ease-out; }
.text-group[open] > summary .fold { rotate: 90deg; }
.text-group-body { padding: 0 var(--gutter) var(--gutter); border-top: 1px solid var(--line); }
.text-group-body table.rows { margin: var(--space-md) 0 0; }
@media (prefers-reduced-motion: reduce) { .text-group > summary .fold { transition: none; } }

/* Bulk actions on the Students list (#145): the bar above the table, the
   checkbox column and the review's list of codes. */
.bulk-bar > h2 { margin-top: 0; }
.bulk-count { margin: 0 0 var(--gutter); font-variant-numeric: tabular-nums; }
table.rows :is(th, td).pick { width: 3.5rem; }
.bulk-review .codes { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.bulk-review .codes-title { font-size: var(--step-title); }

/* #155 Students list: the dock, the checkbox target, phone rows.
   The dock (count and buttons) follows the last row, so it never covers
   it; once a row is ticked, or a whole page or search is chosen, it sticks
   to the bottom of the window. Flat: Paper with a brand top rule, no lift.
   No JS: `:has()` reads the form's own boxes. */
.bulk-dock { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm) var(--gutter);
  margin-top: var(--space-md); padding: var(--space-md) var(--gutter);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.bulk-dock-count { flex: 1 1 14rem; min-width: 0; }
.bulk-dock .bulk-count { margin: 0; }
.bulk-dock .actions { margin: 0; gap: var(--space-sm); }
form.bulk:has(input[name="student"]:checked, input[name="which"]:not([value="picked"]):checked) .bulk-dock {
  position: sticky; bottom: 0; z-index: 2; border-color: var(--field-edge); border-top: 2px solid var(--brand);
  border-bottom-left-radius: 0; border-bottom-right-radius: 0;
  padding-bottom: max(var(--space-md), env(safe-area-inset-bottom)); }
/* A field focused under the stuck dock scrolls clear of it. */
:root:has(form.bulk :is(input[name="student"], input[name="which"]:not([value="picked"])):checked) {
  scroll-padding-bottom: 11rem; }
/* The whole cell is the checkbox's label: at least 48 x 48 px. */
table.rows td.pick { padding: 0; }
table.rows td.pick label.check { justify-content: center; min-width: var(--tap); min-height: var(--tap); width: 100%; cursor: pointer; }
/* Stacked rows: the checkbox moves to the card's top corner instead of
   taking a captioned line; the name keeps clear of it. */
@container (max-width: 859.98px) {
  table.rows tr { position: relative; }
  table.rows td.pick { position: absolute; top: 0; right: 0; padding: 0; width: auto; }
  table.rows td.pick::before { content: none; }
  table.rows td.pick + td { padding-right: var(--tap); }
}
/* Phones (#155): the search card scrolls with the page instead of
   covering rows, and stacked rows are tighter: a 6.5rem caption column,
   less padding per line, 8 px between cards. The bar's buttons share the
   width two by two. */
@container (max-width: 599.98px) {
  .search { position: static; }
  table.rows tr { padding: var(--space-xs) var(--space-md); margin-bottom: var(--space-sm); }
  table.rows td { padding-top: 2px; padding-bottom: 2px; padding-left: calc(6.5rem + var(--space-sm)); }
  table.rows td::before { width: 6.5rem; margin-left: calc(-6.5rem - var(--space-sm)); }
  .bulk-dock { padding: var(--space-sm) var(--space-md); }
  .bulk-dock .actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .bulk-dock .actions button { padding: 0 var(--space-sm); }
  /* The stuck dock is taller here (two rows of buttons, the hint). */
  :root:has(form.bulk :is(input[name="student"], input[name="which"]:not([value="picked"])):checked) {
    scroll-padding-bottom: calc(15rem + env(safe-area-inset-bottom)); }
}
/* A short window (a phone held sideways): the search scrolls too. */
@media (max-height: 30rem) { .search { position: static; } }
/* The bar's skip link to the dock: hidden until focused, so the buttons
   are one Tab away instead of past every row. */
.bulk-skip:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.bulk-skip:focus { display: inline-flex; align-items: center; min-height: var(--tap); margin-bottom: var(--space-sm); }

/* Row actions (`ui::row_actions`): one right-aligned row of tools, 8
   apart, never wrapping where the table is a table. A tool is a 48 px
   Paper button with a Field Edge border (3.5:1) and a 20 px icon; a
   labelled tool adds its name. Move up / down are one joined pair; the
   delete is icon-only in Refused Ink, set apart by a Rule Line; an
   icon-only tool's name shows as a Ledger Ink label above it on hover
   and focus (and is its aria-label). */
.row-actions { display: flex; flex-wrap: nowrap; align-items: center; justify-content: flex-end; gap: var(--space-sm); }
.row-actions .tool-form { display: inline-flex; margin: 0; }
.tool {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); min-width: var(--tap); padding: 0 14px 0 12px; margin: 0;
  background: var(--card); color: var(--ink); border: 1px solid var(--field-edge);
  border-radius: var(--radius-control); font: inherit; font-weight: 600; white-space: nowrap;
  text-decoration: none; cursor: pointer;
}
.tool .icon { flex: none; width: 20px; height: 20px; }
.tool.icon-only { width: var(--tap); padding: 0; }
.row-actions .tool:not(:disabled):is(:hover, :active) { background: var(--bg); border-color: var(--ink); color: var(--ink); }
.row-actions .tool:not(:disabled):active { background: var(--chip-bg); }
.row-actions .tool.tool-danger { color: var(--err-ink); border-color: var(--err-edge); }
.row-actions .tool.tool-danger:not(:disabled):is(:hover, :active) { background: var(--err-bg); border-color: var(--err-ink); color: var(--err-ink); }
.row-actions .tool:disabled { background: var(--card); border-color: var(--line); color: var(--line); cursor: default; }
.row-actions .tool:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; z-index: 2; }
.row-danger { margin-left: var(--space-xs); padding-left: var(--space-md); border-left: 1px solid var(--line); }
/* The pair: two tools sharing one border, the inner corners square. */
.tool-pair { display: inline-flex; }
.tool-pair > * + * { margin-left: -1px; }
.tool-pair > :first-child, .tool-pair > :first-child .tool { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.tool-pair > :last-child, .tool-pair > :last-child .tool { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.tool-pair .tool:is(:hover, :focus-visible) { z-index: 1; }
/* The name of an icon-only tool (`data-tip`), above it on hover and
   keyboard focus. `::before`: the busy ring owns `::after`. */
.tool[data-tip]::before {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; translate: -50% 0;
  z-index: 3; padding: 4px 8px; border-radius: 6px; background: var(--ink); color: var(--card);
  font-size: .8125rem; font-weight: 600; white-space: nowrap; pointer-events: none; opacity: 0;
}
.tool[data-tip]:is(:hover, :focus-visible)::before { opacity: 1; }
/* The column of row actions takes only the room its tools need. */
table.rows th.row-actions-head { text-align: right; }
@container (min-width: 860px) {
  table.rows td:has(> .row-actions) { width: 1%; white-space: nowrap; }
}
/* Stacked rows (phones): the tools take the card's whole width, under the
   row's other facts, and wrap if they must. */
@container (max-width: 859.98px) {
  table.rows td:has(> .row-actions) { padding-left: 0; padding-top: var(--space-sm); }
  table.rows td:has(> .row-actions)::before { display: none; }
  .row-actions { flex-wrap: wrap; justify-content: flex-start; row-gap: var(--space-sm); }
  /* The delete keeps to the far end, on the row or the line below. */
  .row-actions .row-danger { margin-left: auto; padding-left: 0; border-left: 0; }
  table.rows th.row-actions-head { text-align: left; }
}
.head-row .row-actions { margin: 0; }
/* Roster preview (#134): what changes first, then for whom. */
/* Three figures: new, updated, leaving. Stacked rows on a phone (label,
   then the number on the same line), three columns from 30rem. Leaving
   takes the refused pair when anyone leaves (8.6:1); the brand never. */
.figures { display: grid; gap: var(--space-sm); margin: 0 0 var(--space-md); }
.figure { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--space-sm);
  border: 1px solid var(--line); border-radius: var(--radius-control); padding: var(--space-sm) var(--space-md); min-width: 0; }
.figure dt { flex: 1 1 auto; color: var(--muted); font-weight: 600; }
.figure dd { margin: 0; font-size: var(--step-page); font-weight: 700; line-height: 1.4; font-variant-numeric: tabular-nums; }
.figure dd.figure-note { flex: 1 1 100%; font-size: .875rem; font-weight: 600; line-height: 1.6; }
.figure.leaving { background: var(--err-bg); border-color: var(--err-edge); }
.figure.leaving dt, .figure.leaving dd { color: var(--err-ink); }
@container (min-width: 30rem) {
  .figures { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-md); }
  .figure { display: block; padding: var(--space-md); }
}
/* Unchanged and the other counts: one quieter line under the figures. */
.counts-line { list-style: none; margin: 0 0 var(--space-md); padding: 0; display: flex; flex-wrap: wrap;
  gap: var(--space-xs) var(--space-md); color: var(--muted); font-size: .875rem; }
.counts-line strong { color: var(--ink); }
/* Who changes: collapsed; each field old → new on its own line. */
details.changes > summary { font-weight: 600; color: var(--brand-text); }
.deltas { list-style: none; margin: var(--space-xs) 0 0; padding: 0; }
.deltas li { overflow-wrap: anywhere; }
.delta-field, .delta-before { color: var(--muted); }
.delta-after { font-weight: 600; }
.leaving-count { color: var(--err-ink); font-variant-numeric: tabular-nums; }
/* The header error: found beside expected. */
.header-list .chip { flex: none; }
/* #154: the header an unknown one is close to, under it; the value a
   row's problem echoes, under its column, cut by the server and wrapped
   anywhere so a long token never scrolls sideways at 360 px; a slashed
   zero tells 0 from O (`6801OO05`). */
.header-list .hint { flex: 1 1 100%; color: var(--muted); font-size: .875rem; }
.header-list .hint .code-head { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.bad-value { display: block; margin-top: var(--space-xs); color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }
.bad-value code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--ink); font-weight: 600; font-variant-numeric: slashed-zero; }
/* #154: a full import's left-out columns, set in caution. */
.card.absent-full { border-color: var(--caution-edge); }
/* ===== #140 Distill: shorter announcement editor, ids that do not wrap,
   help lines at a readable width. Appended to ui.css (see `ui::CSS`). ===== */

/* The editor's optional parts (English, images, PDFs, expiry and the
   acknowledgement): one disclosure each, a Paper panel with a Rule Line like
   the technical details, open when it holds a value or an error. A fieldset
   inside loses its own border (nothing nests) and its legend is read, not
   drawn: the summary already names it. */
.announcement-form details.optional { margin: 0 0 var(--gutter); border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--card); }
.announcement-form details.optional > summary { padding: 0 var(--gutter); font-weight: 600; }
.announcement-form details.optional > summary:focus-visible { outline-offset: -3px; border-radius: var(--radius); }
.announcement-form details.optional > summary:hover { background: var(--bg); border-radius: var(--radius); }
.optional-body { padding: var(--space-md) var(--gutter) var(--gutter); border-top: 1px solid var(--line); }
.optional-body > fieldset { border: 0; padding: 0; margin: 0; }
.optional-body > fieldset > legend { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.optional-body > :last-child { margin-bottom: 0; }

/* The syntax help under a body: a quiet link-like summary, folded. */
.syntax-help > summary { color: var(--brand-text); font-weight: 600; font-size: .875rem; width: fit-content; }
.syntax-help > p { margin-top: 0; }

/* Both draw their own chevron: a flex summary has no marker. It turns when
   open; nothing moves under reduced motion because nothing animates. */
.announcement-form details.optional > summary::before, .syntax-help > summary::before {
  content: ""; flex: none; width: .45em; height: .45em; margin: 0 12px 0 2px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); }
.announcement-form details.optional[open] > summary::before, .syntax-help[open] > summary::before {
  transform: rotate(45deg); }
.announcement-form details.optional > summary::-webkit-details-marker,
.syntax-help > summary::-webkit-details-marker { display: none; }

/* Ids and codes (student ids, Tags, import codes): never broken inside the
   token. A list of them still wraps between ids. */
.id { white-space: nowrap; overflow-wrap: normal; word-break: keep-all; }
/* A chip breaks between words, and inside one only when the word alone is
   wider than the line (was `anywhere`, which let a table squeeze a chip
   into a broken id). */
.chip { overflow-wrap: break-word; }

/* Help and meta lines read at a comfortable measure on a wide page: 60ch,
   as the empty state's sentence (#127). */
p.muted, .muted p { max-width: 60ch; }

/* An upload problem's fix, on its own line under the problem (#140). */
.fix { display: block; margin-top: var(--space-xs); color: var(--muted); font-size: .875rem; }
.fix strong { color: var(--ink); font-weight: 600; }

/* Saved Audiences (#144): a select or a name box with its button on one
   row that wraps on a phone; the list page stacks each one.
   The picker sits above the choice, the save box below the count. */
.saved-row { display: flex; flex-wrap: wrap; gap: var(--space-sm) var(--space-md); align-items: center; }
.saved-row > input, .saved-row > select { flex: 1 1 14rem; width: auto; min-width: 0; }
.saved-save { margin-top: var(--gutter); }
.saved-save .flash, .saved-save .field-error { margin: var(--space-sm) 0 0; }
.saved-list > li { display: block; padding-left: var(--gutter); padding-right: var(--gutter); }
.saved-list > li > p { margin: 0 0 var(--space-xs); }
.saved-edit { margin-top: var(--space-sm); }
.saved-edit > summary { font-weight: 600; color: var(--brand-text); }
.saved-edit form { margin-top: var(--space-md); }

/* Audience fieldset (#156): a choice's part is hidden until it is chosen
   (by script; without it every part shows); a small whole-number list
   (a year) is one wrapping row of checkboxes; a range's "ตั้งแต่" and
   "ถึง" boxes sit side by side even at 360 px, its help under them. */
.scope-part[hidden] { display: none; }
.check-row { display: flex; flex-wrap: wrap; column-gap: var(--space-lg); }
.announcement-form fieldset.range { border: 0; padding: 0; margin: 0 0 var(--space-sm); }
.announcement-form fieldset.range legend { padding: 0; margin-bottom: var(--space-xs); font-weight: 600; }
.announcement-form fieldset.range .row2 { grid-template-columns: 1fr 1fr; max-width: 28rem; }
.announcement-form fieldset.range .row2 .field { margin-bottom: 0; }
.announcement-form fieldset.range .row2 label { font-weight: 400; }
.announcement-form fieldset.range .muted { margin: var(--space-xs) 0 var(--gutter); }
/* Student picker (#146, `ui::StudentPicker`): the picked Students as
   chips, each with its own 48 px "ลบ"; unknown codes on the Refused pair
   and left Students on the Caution pair, each with a 1px edge (#129) and a
   word, never colour alone. Chips wrap, so nothing scrolls sideways at
   360 px. The search hits are a `.list`; the paste box is a disclosure. */
.picker-count { margin: 0 0 var(--space-xs); font-variant-numeric: tabular-nums; }
.picker-chips { list-style: none; margin: var(--space-sm) 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: var(--space-sm); }
.picker-chips > li { display: inline-flex; flex-wrap: wrap; align-items: center; column-gap: var(--space-xs);
  min-height: var(--tap); max-width: 100%; padding: 0 0 0 var(--space-md); border-radius: 999px;
  background: var(--chip-bg); color: var(--chip-ink); border: 1px solid transparent; overflow-wrap: anywhere; }
.picker-chips > li.err { background: var(--err-bg); color: var(--err-ink); border-color: var(--err-edge); }
.picker-chips > li.warn { background: var(--caution-bg); color: var(--caution-ink); border-color: var(--caution-edge); }
.picker-code { font-weight: 600; font-variant-numeric: tabular-nums; }
.picker-flag { font-size: .875rem; font-weight: 600; }
.picker-chips button.link { min-height: var(--tap); min-width: var(--tap); padding: 0 var(--space-md); color: inherit; border-radius: 999px; }
.picker-chips button.link:hover { background: var(--line); }
.picker-chips > li.err button.link:hover { background: var(--card); }
.picker-chips > li.warn button.link:hover { background: var(--card); }
.picker-status:empty { display: none; }
.picker-status { margin: 0 0 var(--space-sm); color: var(--muted); }
.picker-results:not(:empty) { margin: var(--space-sm) 0 var(--space-md); }
.picker-found .picker-name { flex: 1 1 10rem; min-width: 0; }
.picker-found .picker-code { color: var(--ink); }
.picker-found button, .picker-found .picker-picked { margin-left: auto; }
.picker-found .picker-picked { font-weight: 600; color: var(--muted); }
details.picker-paste { margin-top: var(--space-md); }
details.picker-paste > summary { min-height: var(--tap); display: flex; align-items: center;
  font-weight: 600; color: var(--brand-text); cursor: pointer; }
.picker > .actions, .picker-js .actions { margin-top: var(--space-sm); }
/* "ล้างรายชื่อทั้งหมด" is a link: the brand's text colour, 48 px tall. */
.picker-js .actions button.link { color: var(--brand-text); min-height: var(--tap); }
/* A Module's starting point above the picker ("เริ่มจากรายการค้างชำระ")
   keeps a gutter below it. */
.picker-start { margin-bottom: var(--gutter); }
