/* Every palette entry is a light/dark pair, so switching theme is just switching `color-scheme`:
   unset means follow the browser, the two overrides pin it. Colours come from here and nowhere
   else, and a new one is added as a pair. */
:root {
  --bg: light-dark(#f4f5f7, #14171c);
  --fg: light-dark(#1d2129, #e6e8ec);
  --muted: light-dark(#6b7280, #8b93a1);
  --line: light-dark(#e2e5ea, #2a3039);
  --accent: light-dark(#2f6fdb, #6f9cf0);
  --accent-soft: light-dark(#e7eefc, #1d2a45);
  /* Under a pointer: a button tinted only just, its text and border as they were. See-through, as
     a tint over whatever it lies on, the panel or the page. */
  --hover: light-dark(rgb(47 111 219 / .07), rgb(111 156 240 / .1));
  --bad-hover: light-dark(rgb(201 54 43 / .07), rgb(239 106 95 / .1));
  /* Held down: the same tint, twice as strong, and a shade inside the top edge, as if pushed in.
     Where there is no pointer to hover, it is all a tap shows. */
  --press: light-dark(rgb(47 111 219 / .15), rgb(111 156 240 / .2));
  --bad-press: light-dark(rgb(201 54 43 / .15), rgb(239 106 95 / .2));
  --press-shadow: inset 0 1px 2px light-dark(rgb(20 30 50 / .14), rgb(0 0 0 / .4));
  --ok: light-dark(#1f9d55, #4fc47f);
  --ok-soft: light-dark(#e3f5ea, #173224);
  --warn: light-dark(#c47a00, #e2a33a);
  --warn-soft: light-dark(#fdf1dc, #3a2c12);
  --bad: light-dark(#c9362b, #ef6a5f);
  --bad-soft: light-dark(#fbe7e5, #3d1f1c);
  --panel: light-dark(#ffffff, #1c2027);
  --side: light-dark(#e8eaf0, #0f1216);
  --side-fg: light-dark(#4a5160, #9aa3b2);
  --side-active: light-dark(#d7dbe5, #232a35);
  --side-strong: light-dark(#141821, #ffffff);
  --on-fill: light-dark(#ffffff, #10151d);
  --shadow:
    0 1px 2px light-dark(rgba(20, 30, 50, .06), rgba(0, 0, 0, .4)),
    0 4px 16px light-dark(rgba(20, 30, 50, .05), transparent);
  /* What floats over the page rather than lying on it. */
  --shadow-float:
    0 1px 3px light-dark(rgba(20, 30, 50, .08), rgba(0, 0, 0, .5)),
    0 12px 32px -6px light-dark(rgba(20, 30, 50, .18), rgba(0, 0, 0, .55));
  --radius: 8px;
  --control: 2rem;     /* one height for every inline control, so a row of them shares a line */
  --gutter: 1.5rem;    /* one left edge down the page: the bar, the banner and the content */
  --sidebar: 220px;
  --page-width: 100rem; /* the widest the column goes, the bar's and the notices' right edge included */
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color-scheme: light dark;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* The attribute means hidden, whatever display a rule below may give the element. */
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  display: grid; grid-template-columns: var(--sidebar) 1fr; grid-template-rows: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, textarea.mono, input.mono, select.mono, .value {
  font-family: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace; font-size: 12.5px;
  /* Code is read character by character: no ligatures, which would draw `||` as one glyph and,
     in a field being edited, leave half of it unpainted until the next repaint. */
  font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0;
}
/* Code in running text is scaled down to match the proportional glyphs around it. */
p code, td code, .note code, .hint code, li code, span code { font-size: 11.5px; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
/* What a control says is not something to copy, and a drag across a row of them would take it. */
button, a.button, .switch { user-select: none; -webkit-user-select: none; }

/* ---- sidebar ---------------------------------------------------------------------------- */

#sidebar {
  background: var(--side); color: var(--side-fg);
  display: flex; flex-direction: column; padding: 1rem .75rem; gap: 1.25rem;
  position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line);
}
.brand { color: var(--side-strong); font-weight: 600; font-size: 1.15rem; padding: .25rem .5rem; display: flex; align-items: center; gap: .5rem; }
.brand:hover { text-decoration: none; }
.logo { display: block; flex: none; }
/* Inline inside the name, so it shares its baseline. */
#version { color: var(--side-fg); font-size: .7rem; font-weight: 400; opacity: .8; }
nav { display: flex; flex-direction: column; gap: .15rem; }
nav a {
  display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; border-radius: 6px;
  color: var(--side-fg); font-weight: 500;
}
nav a:hover { background: var(--side-active); text-decoration: none; color: var(--side-strong); }
nav a.active { background: var(--side-active); color: var(--side-strong); }
nav .icon { width: 1.8rem; font-size: 1.5em; line-height: 1; text-align: center; opacity: .8; }
/* One of a few under the link above it, as a part of the same thing. */
nav a.sub { margin-left: 1.1rem; }
/* Drawn over the end of its row, so the row's own link keeps the whole width to be clicked. */
.navrow { position: relative; display: flex; }
.navrow > a:first-child { flex: 1; }
nav a.add {
  position: absolute; right: .4rem; top: 50%; transform: translateY(-50%);
  width: 1.4rem; height: 1.4rem; padding: 0; justify-content: center; border-radius: 5px;
  border: 1px solid var(--line); color: var(--side-fg); font-weight: 400; line-height: 1; opacity: .75;
}
nav a.add:hover { color: var(--accent); border-color: var(--accent); background: var(--side); opacity: 1; }
/* The panel's line is a whisker from the sidebar, so it takes the sidebar's own text, faded: more
   so in light, where dark text on the light sidebar stands out more. */
nav hr {
  border: 0; margin: .5rem .4rem; border-top: 1px solid
    light-dark(color-mix(in srgb, var(--side-fg) 20%, transparent), color-mix(in srgb, var(--side-fg) 35%, transparent));
}
#foot { margin-top: auto; display: flex; align-items: center; gap: .25rem; }
/* The server's time, which is the one that counts, over its zone. */
#clock { flex: 1; min-width: 0; padding: .5rem .6rem; font-size: .85rem; line-height: 1.4; font-variant-numeric: tabular-nums; }
#clock b { display: block; color: var(--side-strong); font-weight: 500; font-size: 1rem; white-space: nowrap; }
#refresh { color: var(--side-fg); padding: .35rem; display: flex; }
#refresh svg { display: block; }
#refresh:hover { color: var(--side-strong); }
#refresh.busy { opacity: .4; pointer-events: none; }

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

#page { min-width: 0; overflow-y: auto; height: 100vh; }
/* One sticky block, the bar and the banner: the content scrolls behind both, and it needs the
   column's own background for that. */
#top { position: sticky; top: 0; z-index: 11; background: var(--bg); }
#banner {
  padding: .6rem var(--gutter); padding-right: max(var(--gutter), calc(100% - var(--page-width) + var(--gutter)));
  background: var(--bad); color: var(--on-fill); display: flex; align-items: flex-start; gap: .8rem;
}
#banner .lines { flex: 1; min-width: 0; }
#banner .close { color: var(--on-fill); font-size: 1.2rem; line-height: 1; padding: 0 .25rem; min-height: 0; }
#banner .close:hover { color: var(--on-fill); opacity: .8; }
#banner a { color: #fff; font-weight: 600; }
/* A row whose ends are a window apart is not one row to the eye, so nothing in the column goes
   wider than `--page-width`: not the content, nor the bar's controls, nor the banner's text, whose
   colour alone runs on to the edge. */
main { padding: .25rem var(--gutter) 3rem; max-width: var(--page-width); }
/* A view that is one form rather than a list: a box as wide as a list would be is hard to read. */
.narrow { max-width: 48rem; }
h1 { font-size: 1.35rem; font-weight: 600; margin: 0 0 1rem; display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; }
h1 .muted { font-size: .9rem; font-weight: 400; }
/* The way to make a thing: a primary button at the right of the heading, in body size, as is any
   other control there. */
h1 :is(button, a.button) { font-size: 14px; font-weight: 500; }
h1 :is(label, select) { font-size: 14px; font-weight: 400; }
/* A glyph has no baseline to share with the title: by the middle instead. */
h1 > .more { align-self: center; }
h2 { margin: 1.5rem 0 .5rem; font-size: .95rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
/* A heading that is a thing's name rather than a label over rows: as it is written, and as much a
   title as the thing is, with its menu and a note beside it. */
h2.name {
  font-size: 1.15rem; color: var(--fg); text-transform: none; letter-spacing: 0; margin-top: 2rem;
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
}
h2.name > .hint { font-weight: 400; }
/* A day over the times in it, with Today and such after it: in sight while they scroll by. */
h2.day {
  position: sticky; top: var(--top-height, 3rem); z-index: 1; background: var(--bg); padding: .5rem 0;
  font-size: 1rem; color: var(--fg); text-transform: none; letter-spacing: 0;
}
h2.day .muted { font-weight: 400; margin-left: .5rem; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
.warn { color: var(--warn); }
/* A caption, and its control set back to the body text. A class of a control's own, further down,
   wins over the second of these. */
.toolbar label, .form label, .group { display: flex; flex-direction: column; gap: .3rem; color: var(--muted); font-size: .8rem; font-weight: 500; }
.toolbar label > *, .form label > *, .group > * { color: var(--fg); font-size: 14px; font-weight: 400; }
.hint { color: var(--muted); font-size: .85rem; }
.note { display: block; color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.note.error, .hint.error { color: var(--bad); }
.note.warn, .hint.warn { color: var(--warn); }
.empty { padding: 2rem; text-align: center; color: var(--muted); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: .75rem; align-items: stretch; }
/* Scrollable rather than clipped: a table too wide for the window must still be reachable. The
   radius clips it either way. */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; overflow-y: hidden; }
.card + .card { margin-top: 1rem; }
/* A read-only page, or a dialog's part of one: a label column and what it says, a line or more
   each. Only what has something to say gets a row. Inset only on a card, as a dialog has its own. */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .6rem 1.25rem; align-items: baseline; }
:is(.card.facts, .card > .facts) { padding: 1rem; }
.facts .k { color: var(--muted); font-size: .85rem; }
.facts .bad { color: var(--bad); }
.facts ul { margin: 0; padding-left: 1.1rem; }
/* Eight lines of its line height, and the rest scrolled to. */
.facts pre { max-height: calc(8 * 1.45em); overflow-y: auto; }
/* Text to be read, such as help in a dialog: paragraphs and lists a line apart. */
.prose > * { margin: 0; }
.prose > * + * { margin-top: .75rem; }
.prose ul { padding-left: 1.2rem; }
/* What `pointAt` draws the eye to blinks a few times: an outline round it, or, for a list's row,
   which has no box to draw round, the background of its cells. */
.pointed:not(tr) { outline: 3px solid transparent; outline-offset: 2px; animation: pointed .27s ease-in-out 6 alternate; }
tr.pointed > * { animation: pointed-row .27s ease-in-out 6 alternate; }
@keyframes pointed { to { outline-color: var(--accent); } }
@keyframes pointed-row { to { background-color: var(--accent-soft); } }
@media (prefers-reduced-motion: reduce) {
  .pointed:not(tr), tr.pointed > * { animation-duration: 1.5s; animation-iteration-count: 2; }
}

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

#options {
  position: relative;
  display: flex; align-items: center; justify-content: flex-end; gap: .5rem;
  padding: .7rem var(--gutter) .45rem; max-width: var(--page-width);
}
#offline {
  background: var(--bad-soft); color: var(--bad); border: 1px solid var(--bad);
  border-radius: 4px; padding: .15rem .5rem; font-size: .85rem; font-weight: 500;
  white-space: nowrap; cursor: default;
}
#who { color: var(--muted); font-size: .9rem; white-space: nowrap; }
#gear { font-size: 1.7rem; line-height: 1; padding: .1rem .35rem; }
#gear:hover, #gear[aria-expanded="true"] { color: var(--accent); }
/* Sized to its contents up to a readable measure: a hint given the whole screen turns the menu
   into a bar. */
#menu {
  position: absolute; right: 0; top: 100%; margin-top: .4rem; width: max-content;
  min-width: 12rem; max-width: min(24rem, calc(100vw - 2 * var(--gutter)));
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .8rem .9rem;
  display: flex; flex-direction: column; gap: .8rem;
}
#menu .option { display: flex; flex-direction: column; gap: .35rem; }
#menu .hint { white-space: normal; }
#menu .logged-in { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
#menu .segmented .chip { flex: 1; justify-content: center; }

/* ---- logging in ------------------------------------------------------------------------ */

/* Over everything, and opaque: what is behind it is not for whoever has yet to log in. */
#login {
  position: fixed; inset: 0; z-index: 20; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: var(--gutter);
}
#login form { width: 100%; max-width: 20rem; padding: 1.5rem; margin: 0; }
#login h1 { align-items: center; gap: .5rem; margin-bottom: .5rem; }
#login input { width: 100%; }
#login .error { margin: 0; }

/* ---- tables ----------------------------------------------------------------------------- */

/* A list is a grid that keeps its table markup for what it means: the rows and row groups step
   aside and the cells are the grid's items, laid out by `--columns`, which each kind of list sets.
   A cell cannot span a row by itself, so a row's separator is the top border of each of its cells,
   which stretch to the row's height and meet in one line. */
table.list { display: grid; }
table.list > thead, table.list > tbody, table.list > * > tr { display: contents; }
/* Middle, in every table: a row mixes cells of one to three lines and one button, and centred,
   every cell sits in the row rather than on its edge. A grid cell is a block, which centres with
   `align-content`. */
th, td { text-align: left; padding: .55rem .9rem; border-top: 1px solid var(--line); align-content: center; }
thead th { border-top: none; color: var(--muted); font-weight: 500; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; background: var(--bg); }
tbody tr:first-child td { border-top: none; }
thead + tbody tr:first-child td { border-top: 1px solid var(--line); }
tr.dim td { color: var(--muted); }
/* What a cell spans is the grid's to say: `colspan` means nothing to it. */
table.list td.empty { grid-column: 1 / -1; }
table.list, .sections { grid-template-columns: var(--columns); }
/* A view of several tables under headings is one grid: each section, its card and its table take
   their columns from it, so every table's columns line up with every other's. */
.sections { display: grid; }
.sections > section, .sections > section > .card, .sections table.list {
  grid-column: 1 / -1; display: grid; grid-template-columns: subgrid;
}
/* Besides its heading, a section may hold a hint, or a button that unfolds another card of rows. */
.sections > section > :not(.card) { grid-column: 1 / -1; }
.sections > section > .card.empty { display: block; }
.sections > section > button.unfolds { justify-self: start; margin-top: .5rem; }
.sections > section:first-child > h2 { margin-top: 0; }
td.time { white-space: nowrap; font-variant-numeric: tabular-nums; }
/* The end of a span after its start, and under both how far off it is. */
td.time .end, td.time .rel { color: var(--muted); }
td.time .rel { display: block; font-size: .8rem; }
/* Right: every row ends in the same button, the menu, and whatever a row has besides goes before
   it, so the menus line up down the edge whichever row has the most. */
td.actions { white-space: nowrap; text-align: right; }

.badge {
  display: inline-block; padding: .1rem .5rem; border-radius: 4px; font-size: .78rem;
  font-weight: 500; background: var(--line); color: var(--fg);
}
/* A state word from the data, or a short phrase: a capital to start it, not one per word. */
.badge::first-letter { text-transform: uppercase; }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.off { background: var(--line); color: var(--muted); }

/* ---- controls --------------------------------------------------------------------------- */

/* A link that looks like a button goes to a page, so it still opens in a new tab or copies like
   any link. */
button, a.button {
  font: inherit; padding: .2rem .7rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--fg); cursor: pointer; line-height: 1.3;
  min-height: var(--control);
}
a.button { display: inline-flex; align-items: center; }
/* Hover rules leave a disabled button alone, in `:where` so as to weigh no more than without it. */
button:where(:not(:disabled)):hover, a.button:hover { background-image: linear-gradient(var(--hover), var(--hover)); text-decoration: none; }
:is(button, a.button).primary { background: var(--accent); border-color: var(--accent); color: var(--on-fill); }
:is(button, a.button).primary:where(:not(:disabled)):hover { filter: brightness(1.08); color: var(--on-fill); }
button.danger { color: var(--bad); }
button.danger:where(:not(:disabled)):hover { background-image: linear-gradient(var(--bad-hover), var(--bad-hover)); }
button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
button.quiet:where(:not(:disabled)):hover { background-image: linear-gradient(var(--hover), var(--hover)); }
/* After the hover rules, which a press also matches. A busy button has been pressed already. */
:is(button, a.button):where(:not(:disabled, [aria-busy="true"])):active {
  background-image: linear-gradient(var(--press), var(--press)); box-shadow: var(--press-shadow);
}
:is(button, a.button).primary:where(:not(:disabled, [aria-busy="true"])):active { filter: brightness(.9); }
button.danger:where(:not(:disabled, [aria-busy="true"])):active { background-image: linear-gradient(var(--bad-press), var(--bad-press)); }
button.quiet:where(:not(:disabled)):active { box-shadow: none; }
.actions :is(button, a.button) { margin-left: .5rem; }
.actions :is(button, a.button), button.small { padding: .1rem .5rem; font-size: .82rem; min-height: 1.6rem; }
.actions > :first-child { margin-left: 0; }
/* A button of text and one of a glyph have no baseline in common: by their middles instead. */
.actions :is(button, a.button) { vertical-align: middle; }
/* Not `pointer-events: none`: a disabled button ignores clicks by itself, and killing hover takes
   the `title` that explains why it is disabled with it. */
button:disabled { opacity: .5; cursor: default; }
/* Waiting for the server: a spinner in place of the label, which stays, unseen, to keep the
   button's width. Full strength, as this is not a button that cannot be pressed but one that has
   been. */
:is(button, a.button)[aria-busy="true"] {
  position: relative; color: transparent !important; opacity: 1; cursor: progress;
}
:is(button, a.button)[aria-busy="true"] > * { visibility: hidden; }
:is(button, a.button)[aria-busy="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 1em; height: 1em;
  border: 2px solid var(--muted); border-right-color: transparent; border-radius: 50%;
  animation: busy .7s linear infinite;
}
:is(button, a.button).primary[aria-busy="true"]::after { border-color: var(--on-fill); border-right-color: transparent; }
:is(button, a.button).danger[aria-busy="true"]::after { border-color: var(--bad); border-right-color: transparent; }
@keyframes busy { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) {
  :is(button, a.button)[aria-busy="true"]::after { animation-duration: 2.5s; }
}
/* What folds says which way it goes: a `summary`, or a button with `.unfolds` whose `aria-expanded`
   says whether what it unfolds is open. A drawn arrow, as a font's triangles are small, and of a
   different size in each. */
summary { cursor: pointer; list-style: none; }
summary::-webkit-details-marker { display: none; }
:is(summary, button.unfolds:not([aria-busy="true"]))::after {
  content: ""; display: inline-block; width: .75em; height: .45em; margin-left: .5em; vertical-align: .1em;
  background: currentColor; clip-path: polygon(0 0, 100% 0, 50% 100%);
}
:is(details[open] > summary, button.unfolds[aria-expanded="true"])::after { clip-path: polygon(0 100%, 100% 100%, 50% 0); }
/* A section that folds stands apart from what is around it, where no gap of a container does that
   already. Unfolded, a line down its left says what is in it. */
details { margin-block: .75rem; }
:is(.form, .stack, .row, .toolbar, .group, .fields) > details { margin-block: 0; }
details[open]::details-content { margin: .5rem 0 0 .3rem; padding-left: .9rem; border-left: 2px solid var(--line); }
details > summary + * { margin-top: 0; }
details > :last-child:not(summary) { margin-bottom: 0; }
/* What an `unfoldsButton` shows, wherever it is, has the same line. */
.unfolded { margin: .75rem 0 .75rem .3rem; padding-left: .9rem; border-left: 2px solid var(--line); }
/* Right under the button, as what it opens. */
button.unfolds + .unfolded { margin-top: .25rem; }
/* A card is set apart by its own border: no line and no indent, so its columns stay in line. */
.card.unfolded { margin-left: 0; padding-left: 0; border-left: 1px solid var(--line); }
/* As is what a box of its own sets apart. */
.unfolded.unlined { margin-left: 0; padding-left: 0; border-left: none; }
:is(.form, .stack, .row, .toolbar, .group, .fields) > .unfolded { margin-block: 0; }
.unfolded > :first-child { margin-top: 0; }
.unfolded > :last-child { margin-bottom: 0; }
/* A link that opens a new tab, which is one that leaves the app, says so after its text. */
a[target="_blank"]::after {
  content: ""; display: inline-block; flex: none; width: .85em; height: .85em; margin-left: .35em; vertical-align: -.05em;
  background: currentColor; mask: url(external.svg) center / contain no-repeat;
}
/* The mark of more to read: on a caption, the rest of its meaning is in the mark's tooltip. */
.caption:has(> .tip) { display: inline-flex; align-items: center; gap: .3rem; }
.tip {
  flex: none; display: inline-block; vertical-align: -2px; margin-left: .3rem; width: 15px; height: 15px;
  background: var(--accent); mask: url(info.svg) center / contain no-repeat;
}
.caption > .tip { margin-left: 0; }
/* A button that is only that mark, opening what there is to read. Centred: with no text, it has no
   baseline to line up with a heading by. */
button.info { display: inline-grid; place-items: center; align-self: center; padding: 0 .3rem; }
button.info::before {
  content: ""; width: 18px; height: 18px; background: var(--accent); mask: url(info.svg) center / contain no-repeat;
}
/* In a column's header, as small as a caption's mark, on the header's line rather than a control's. */
th button.info { min-height: 0; padding: 3px; margin: -3px 0 -3px .15rem; border: 0; vertical-align: middle; }
th button.info::before { width: 15px; height: 15px; }
/* A button that reads as a link: it sits in a hint, where a link is what it looks like. */
button.link {
  border: 0; background: none; padding: 0; color: var(--accent); font: inherit; font-size: .8rem;
  text-decoration: underline; cursor: pointer;
}
/* The same glyph in every row, whether or not there are other buttons beside it. */
button.more { padding: .1rem .5rem; display: inline-flex; align-items: center; }
svg.icon { display: block; flex: none; }
input, select, textarea {
  font: inherit; padding: .3rem .5rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--fg); max-width: 100%;
}
/* Exactly, not at least: left to itself a date box comes out taller than a button beside it. */
input:not([type=checkbox]), select { height: var(--control); padding-block: 0; }
input.num { width: 6rem; }
input.secret { -webkit-text-security: disc; }
/* A file box's button fills the box's height, so the two read as one control. */
input[type=file] { padding: 0 .5rem 0 0; line-height: calc(var(--control) - 2px); }
input[type=file]::file-selector-button {
  font: inherit; height: 100%; margin: 0 .5rem 0 0; padding: 0 .7rem; border: 0;
  border-right: 1px solid var(--line); background: var(--bg); color: var(--fg); cursor: pointer;
}
input[type=file]:where(:not(:disabled)):hover::file-selector-button { background-image: linear-gradient(var(--hover), var(--hover)); }
input[type=file]:where(:not(:disabled)):active::file-selector-button {
  background-image: linear-gradient(var(--press), var(--press)); box-shadow: var(--press-shadow);
}
/* One ring, and one you can see: the soft accent is a whisker from the panel it sits on. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.chips { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.chip {
  border: 1px solid var(--line); border-radius: 4px; padding: 0 .55rem; cursor: pointer;
  user-select: none; background: var(--panel); font-size: .85rem; font-weight: 500;
  display: inline-flex; align-items: center; min-height: var(--control);
}
.chip.on { border-color: var(--accent); background: var(--accent); color: var(--on-fill); }
/* What a `choiceField` holds: not a button itself, only its × is. */
.chip.chosen { cursor: default; gap: .4rem; padding-right: 0; }
.chip .note { color: var(--muted); font-weight: 400; margin-top: 0; }
.chip.on .note { color: inherit; opacity: .8; }
.chip .remove {
  border: 0; background: none; min-height: 0; align-self: stretch; padding: 0 .45rem; color: var(--muted);
  font-size: 1rem; line-height: 1; border-radius: 0 3px 3px 0;
}
.chip .remove:hover { color: var(--fg); }
.chip.on:active { filter: brightness(.9); }
.chip .remove:active { background-image: linear-gradient(var(--press), var(--press)); box-shadow: none; }
.popup[role=menu] .note { display: block; color: var(--muted); font-weight: 400; font-size: .8rem; }
/* Pick one of these: the buttons are joined into a single control, rounded only at its ends.
   Chips that are independent of each other stay apart. */
.segmented { gap: 0; flex-wrap: nowrap; }
.segmented .chip { border-radius: 0; }
.segmented .chip:first-child { border-start-start-radius: 4px; border-end-start-radius: 4px; }
.segmented .chip:last-child { border-start-end-radius: 4px; border-end-end-radius: 4px; }
.segmented .chip + .chip { margin-left: -1px; }
.segmented .chip:hover, .segmented .chip.on { position: relative; z-index: 1; }
/* As tall as the boxes it sits beside, with the checkbox centred in that height. */
.switch { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; min-height: var(--control); }

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

/* A form is a column whose items take its whole width. An item is whatever the form needs; the
   plain one is a field, a caption over its control, itself a stretched column. */
.form { display: flex; flex-direction: column; gap: .75rem; align-items: stretch; }
.group > .caption, label > .caption { color: var(--muted); font-size: .8rem; font-weight: 500; }
.form label > .hint, .group > .hint { font-size: .78rem; font-weight: 400; color: var(--muted); }
.form label > .row { gap: .35rem; }
/* One that is its own label, on the control line beside the boxes of a row. */
.form label.switch { flex-direction: row; gap: .4rem; color: var(--fg); font-size: 14px; font-weight: 400; }
/* Sliders three to a row, each its caption and value over its track, which is lower than a box. */
.sliders { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem .75rem; }
label.slider > input[type=range] { width: 100%; height: 1.5rem; padding: 0; }
.slider-head { display: flex; justify-content: space-between; gap: .5rem; }
/* A box with fixed text around it, which takes what the text leaves. */
.affixed { display: flex; align-items: center; gap: .25rem; }
.affixed > input { flex: 1; min-width: 0; }
/* A small square, its icon smaller than a glyph-sized one. */
button.copy { display: inline-grid; place-items: center; padding: 0; width: 1.6rem; min-height: 1.6rem; flex: none; }
button.copy > svg.icon { width: 14px; height: 14px; }
/* A box to copy from, and beside it its copy button. */
.copybox { display: flex; align-items: center; gap: .4rem; }
.copybox > input { flex: 1; min-width: 0; }
/* A few controls that belong on one line, at their own widths, sharing that line. */
.form.across { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.card > .form, .form.card { padding: 1rem; }
.form.card { margin-bottom: 1.25rem; }
/* Captions share one row track instead of each sitting above a control of its own height, so they
   line up however tall a control grows. */
.fields { display: grid; grid-auto-flow: column; grid-auto-columns: max-content; grid-template-rows: auto auto; gap: .3rem 1.25rem; }
.fields > label, .fields > .group { display: grid; grid-row: span 2; grid-template-rows: subgrid; gap: .3rem; align-items: end; }
/* A third track for the hints, so a hint under one control never pushes that control off the line
   its neighbours sit on. Only rows that have a hint reserve it. */
.fields.hinted { grid-template-rows: auto auto auto; }
.fields.hinted > label, .fields.hinted > .group { grid-row: span 3; align-items: start; }
.fields.hinted > label > .caption, .fields.hinted > .group > .caption { align-self: end; }
/* A part of a long form. One not nested in another is a landmark: a heading in the page's own size
   with a rule under it. Those inside it keep the small label. */
.fieldset {
  border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem 1rem;
  display: flex; flex-direction: column; gap: .75rem; align-self: stretch; background: var(--panel);
}
.fieldset > .head { display: flex; align-items: center; gap: .6rem; }
.fieldset > .head .title { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.fieldset:not(.fieldset .fieldset) { padding-top: 1rem; gap: 1rem; }
.fieldset:not(.fieldset .fieldset) + .fieldset { margin-top: .75rem; }
.fieldset:not(.fieldset .fieldset) > .head { padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
.fieldset:not(.fieldset .fieldset) > .head .title { font-size: 1.05rem; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--fg); }
/* A title that is a summary of what is inside, not a section name: read as a phrase. */
.fieldset > .head .title.summary { text-transform: none; letter-spacing: 0; font-size: .85rem; color: var(--fg); }

/* The controls line up on their bottom edge. */
.toolbar {
  display: flex; gap: 1.25rem; align-items: flex-end; flex-wrap: wrap;
  padding: .85rem 1rem; margin-bottom: 1.25rem;
}
/* Pushed to the right by its own margin rather than by a spacer, which strands itself on the first
   line the moment the toolbar wraps. */
.toolbar > .hint { min-height: var(--control); display: flex; align-items: center; margin-left: auto; }
/* The foot of the card above it, kept in the window while that card is: a sibling of the card and
   not a part of it, since a card scrolls sideways and what sticks inside a scroller sticks to it. */
.card:has(+ .savebar) { border-bottom: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.savebar {
  position: sticky; bottom: 0; z-index: 2; display: flex; flex-direction: column; gap: .4rem;
  padding: .7rem 1rem; background: var(--panel); border: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius); box-shadow: var(--shadow);
}
.savebar > p { margin: 0; }
/* A field tabbed to is scrolled clear of the bar, and the notices stand above it. */
html:has(.savebar), #page:has(.savebar) { scroll-padding-bottom: 5rem; }
body:has(.savebar) #notices { bottom: 5rem; }

/* ---- popups ----------------------------------------------------------------------------- */

/* Fixed, not absolute: a card clips its overflow, and a menu opening downward from its last row
   would be cut off with it. Placed by script from the button's own box. */
.popup {
  position: fixed; z-index: 12; min-width: 12rem; padding: .3rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
}
/* Only the menu items are styled as items: a popup can also hold ordinary controls. */
.popup button[role=menuitem] {
  border: 0; background: none; text-align: left; border-radius: 4px; min-height: 0;
  padding: .4rem .7rem; font-size: .9rem; margin: 0; color: var(--fg);
}
.popup button[role=menuitem]:hover, .popup button[role=menuitem]:focus-visible { background: var(--accent-soft); color: var(--accent); outline: none; }
.popup button[role=menuitem].sub { padding-left: 1.5rem; }
.popup button[role=menuitem].danger { color: var(--bad); }
.popup button[role=menuitem].danger:hover { background: var(--bad-soft); color: var(--bad); }
.popup button[role=menuitem]:active { background-image: linear-gradient(var(--press), var(--press)); box-shadow: none; }
.popup button[role=menuitem].danger:active { background-image: linear-gradient(var(--bad-press), var(--bad-press)); }
.popup hr { border: 0; border-top: 1px solid var(--line); margin: .3rem 0; }
.popup .heading { color: var(--muted); font-size: .75rem; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; padding: .4rem .7rem .1rem; }

/* ---- notices ---------------------------------------------------------------------------- */

/* The answer to "did that work" lands in a corner of a screen that may be very wide, so it is
   sized to be seen from the other side of it rather than found, and floats clear of the page. Its
   right edge is the content's, the column's scrollbar between them and the window's. */
#notices {
  position: fixed; bottom: 1.5rem; z-index: 10;
  right: calc(max(var(--scrollbar, 0px), 100vw - var(--sidebar) - var(--page-width)) + var(--gutter));
  display: flex; flex-direction: column; gap: .6rem;
  min-width: 22rem; max-width: 40rem;
}
.notice {
  --tone: var(--ok); --tone-soft: var(--ok-soft);
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: .85rem;
  padding: .85rem .7rem .85rem 1rem; border-radius: 12px;
  background: var(--panel); color: var(--fg);
  border: 1px solid color-mix(in srgb, var(--tone) 30%, var(--line));
  box-shadow: var(--shadow-float);
  font-size: 1rem; line-height: 1.4;
}
.notice.error { --tone: var(--bad); --tone-soft: var(--bad-soft); }
.notice.leaving { pointer-events: none; animation: notice-out .2s ease-in forwards; }
/* The colour is the message, so it is a filled badge with a halo, and the glyph is drawn rather
   than typed, to sit centred in it whatever the font. Inline, not a mask: a policy that keeps
   images to the page's own would refuse a `data:` one. */
.notice .mark {
  flex: none; width: 1.75rem; height: 1.75rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--tone); color: var(--on-fill); box-shadow: 0 0 0 4px var(--tone-soft);
}
.notice .mark svg { width: 64%; height: 64%; }
.notice .text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.notice.error .text { font-weight: 500; }
.notice .close {
  flex: none; width: 1.75rem; height: 1.75rem; min-height: 0; padding: 0;
  border-radius: 50%; font-size: 1.2rem; line-height: 1; color: var(--muted);
}
/* The time it has left, draining, which the script animates. */
.notice .life {
  position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: var(--tone); opacity: .55; transform-origin: left;
}
@keyframes notice-out { to { opacity: 0; transform: translateX(1.5rem); } }
/* The bar still drains: it only shrinks in place, and the notice goes when it is empty. */
@media (prefers-reduced-motion: reduce) {
  .notice.leaving { animation: none; opacity: 0; }
}
/* The wider the screen, the further the corner is from whatever was clicked. */
@media (min-width: 1800px) {
  #notices { bottom: 2.5rem; min-width: 32rem; max-width: 52rem; }
  .notice { font-size: 1.25rem; padding: 1.1rem .9rem 1.1rem 1.3rem; gap: 1.1rem; }
  .notice .mark { width: 2.3rem; height: 2.3rem; box-shadow: 0 0 0 5px var(--tone-soft); }
  .notice .close { width: 2.3rem; height: 2.3rem; font-size: 1.5rem; }
}

/* ---- dialogs ---------------------------------------------------------------------------- */

dialog.modal {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0; max-width: 46rem;
  width: calc(100% - 2rem); max-height: 85vh; background: var(--panel); color: var(--fg);
  box-shadow: var(--shadow); overflow: hidden;
}
/* For a row of fields that is to stay one row. */
dialog.modal.wide { max-width: 54rem; }
/* Heading and foot stay, and what is between them scrolls. */
dialog.modal[open] { display: flex; flex-direction: column; }
dialog.modal::backdrop { background: rgba(15, 18, 22, .45); }
dialog.modal table { border-collapse: collapse; width: 100%; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 1.2rem; border-bottom: 1px solid var(--line); position: sticky; top: 0;
  background: var(--panel);
}
.modal-head .close { font-size: 1.4rem; line-height: 1; padding: 0 .4rem; }
.modal-head h2 { margin: 0; font-size: 1.1rem; text-transform: none; letter-spacing: 0; color: var(--fg); }
.modal-body { padding: .8rem 1.2rem 1.2rem; overflow-y: auto; flex: 1; min-height: 0; }
.modal-foot { flex: none; display: flex; flex-direction: column; gap: .4rem; padding: .8rem 1.2rem; border-top: 1px solid var(--line); }
.modal-foot > p { margin: 0; }
.modal-body pre {
  background: var(--bg); padding: .6rem .8rem; border-radius: 6px; font-size: 12.5px;
  max-height: calc(14 * 1.45em); overflow-y: auto;
}

/* ---- narrower windows ------------------------------------------------------------------- */

/* A row of fields shares its row tracks only while every field fits on one line. Below that it
   wraps, each field carrying its own caption: a form that grows downward beats one painted past
   the edge of its card. */
@media (max-width: 1500px) {
  .fields { display: flex; flex-wrap: wrap; align-items: flex-start; }
  .fields > label, .fields > .group,
  .fields.hinted > label, .fields.hinted > .group {
    grid-row: auto; grid-template-rows: none; display: flex; flex-direction: column; align-items: stretch;
  }
  .fields.hinted > label > .caption, .fields.hinted > .group > .caption { align-self: stretch; }
}

/* A long list under a heading and a filter that stay put: the list scrolls in a pane of its own,
   the height passed down to it through every box on the way. Its edge is pushed out over the
   gutter so the scrollbar, always there, sits at the side of the window, and what is left of the
   gutter beside it keeps the list as wide as the heading. Only where there is room: a phone or a
   short window gets its whole height back by letting all of it scroll. */
@media (min-width: 761px) and (min-height: 600px) {
  #page:has(.pane) { display: flex; flex-direction: column; overflow-y: hidden; }
  #page:has(.pane) > #top { flex: none; }
  #page:has(.pane) > main { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; padding-bottom: 0; }
  main > div:has(> .pane) { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  main > div:has(> .pane) > * { flex: none; }
  main > div:has(> .pane) > .pane {
    flex: 1; min-height: 0; overflow-y: scroll; align-content: start;
    margin-right: calc(-1 * var(--gutter)); padding: 0 calc(var(--gutter) - var(--scrollbar, 0px)) 3rem 0;
  }
}

/* In a form, a row of fields is an item like any other and takes the whole width: it wraps at any
   window, and the boxes on each line share that line, so one left alone on a line is as wide as a
   field outside a row. A box of a set size next to others, and a checkbox, stay as they are. */
.form .fields, dialog .fields { display: flex; flex-wrap: wrap; align-items: flex-start; }
.form .fields > label, .form .fields > .group,
.form .fields.hinted > label, .form .fields.hinted > .group,
dialog .fields > label, dialog .fields > .group,
dialog .fields.hinted > label, dialog .fields.hinted > .group {
  grid-row: auto; grid-template-rows: none; display: flex; flex-direction: column; align-items: stretch;
  max-width: 100%;   /* or a box of a set size holds it wider than a phone's dialog */
}
.form .fields.hinted > label > .caption, .form .fields.hinted > .group > .caption,
dialog .fields.hinted > label > .caption, dialog .fields.hinted > .group > .caption { align-self: stretch; }
.form .fields > label, dialog .fields > label { flex: 1 1 auto; }
.form .fields > label:has(> input.num):not(:only-child), .form .fields > label:has(> .switch):not(:only-child),
dialog .fields > label:has(> input.num):not(:only-child), dialog .fields > label:has(> .switch):not(:only-child) { flex: none; }
.form label:only-child > input.num, .form > label > input.num { width: auto; }

/* The sidebar becomes a top bar, and the page scrolls rather than a box inside it: a 100%-high
   grid row with its own scroller keeps the nav and the sticky bar on screen for ever. */
@media (max-width: 760px) {
  .sliders { grid-template-columns: minmax(0, 1fr); }
  :root { --gutter: 1rem; }
  html, body { height: auto; }
  body { grid-template-columns: 1fr; grid-template-rows: auto auto; }
  #sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: .5rem 1rem; padding: .5rem .75rem; }
  nav { flex-direction: row; }
  nav a { padding: .35rem .5rem; }
  nav { flex-wrap: wrap; }
  nav .icon, nav hr { display: none; }
  nav a.sub { margin-left: 0; }
  nav a.add { position: static; transform: none; align-self: center; }
  #foot { margin-top: 0; margin-left: auto; }
  #clock { text-align: right; }
  #clock b { display: inline; font-size: .85rem; }
  #clock .zone { margin-left: .5rem; }
  #gear { color: var(--side-fg); }
  #page { height: auto; overflow-y: visible; }
  main { padding: .25rem 1rem 1rem; }
  #notices { left: 1rem; right: 1rem; min-width: 0; }
  /* The joined look is worth less than the last option being on the screen. */
  .segmented { flex-wrap: wrap; gap: .3rem; }
  .segmented .chip { border-radius: 4px; }
  .segmented .chip + .chip { margin-left: 0; }
  /* A shared grid is as wide as its widest table and cannot scroll a card at a time, so here each
     table is a grid of its own again and each card scrolls its own. */
  .sections, .sections > section, .sections > section > .card { display: block; }
  .sections table.list { grid-template-columns: var(--columns); }
}
