/* The app's stylesheet: the Sky theme, light and dark, written by hand. No
   build step — the file is embedded and served as it is (static/static.go).
   It styles every signed-in page (dashboard/) and the signed-out auth pages
   (auth/); the public landing page has its own landing.css.

   Every colour is a token below; the dark set redefines the same tokens and
   nothing else, so a rule never names a colour of its own. Light or dark
   follows the device unless the reader chose one in the sidebar
   (theme.js writes the choice as data-theme on <html>).

   Sky: a pale blue-grey ground, white panels, navy text, and ONE blue for
   what the reader acts on. The navy "chrome" carries the sidebar and the
   signed-out panel. Green, amber and red are kept for status, and a status
   chip always pairs its tint with a border and a dot — never colour alone. */

@font-face {
  font-family: "Geist";
  src: url("fonts/geist.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Geist Mono";
  src: url("fonts/geist-mono.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ground: #edf2f7;
  --surface: #ffffff;
  --ink: #1a2537;
  --muted: #4a586d;
  --placeholder: #66748a;
  --line: #d8e0ea;
  --control-line: #75869c;
  --wash: #f2f6fb;
  --accent: #2160c4;
  --accent-hover: #1a4ea3;
  --accent-wash: #e7effb;
  --on-accent: #ffffff;
  --chrome: #1d3557;
  --chrome-raised: #284670;
  --chrome-edge: #1d3557;
  --on-chrome: #ffffff;
  --on-chrome-muted: #b9c8dc;
  --danger: #b42318;
  --danger-wash: #fbeceb;
  --ok: #17663a;
  --ok-wash: #e9f5ee;
  --ok-line: #8cc4a3;
  --wait: #7a4d00;
  --wait-wash: #fdf3e0;
  --wait-line: #dbb469;
  --info: #1d5fbf;
  --info-wash: #e5eefa;
  --backdrop: rgb(10 22 40 / 0.5);
  --font: "Geist", system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, monospace;
  --shadow-card: 0 1px 3px rgb(29 53 87 / 0.06);
  --shadow-button: 0 1px 2px rgb(29 53 87 / 0.24), 0 4px 12px rgb(29 53 87 / 0.16);
  --shadow-panel: 0 4px 16px rgb(29 53 87 / 0.14);
}

/* Sky at night: charcoal with a blue cast, not black, and off-white text.
   Written twice — for a device set to dark (unless the reader chose light)
   and for the reader's own choice. KEEP THE TWO BLOCKS EQUAL. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground: #121721;
    --surface: #1b2230;
    --ink: #e3e8f0;
    --muted: #a3aec0;
    --placeholder: #8692a7;
    --line: #2c3546;
    --control-line: #6a7790;
    --wash: #232b3b;
    --accent: #8ab3ff;
    --accent-hover: #a8c7ff;
    --accent-wash: #1f2f4d;
    --on-accent: #0c1630;
    --chrome: #0b1019;
    --chrome-raised: #1f2838;
    --chrome-edge: #2c3546;
    --on-chrome: #e3e8f0;
    --on-chrome-muted: #98a3b6;
    --danger: #ff8a80;
    --danger-wash: #3b1f22;
    --ok: #5fcf8a;
    --ok-wash: #16302a;
    --ok-line: #2f6b4a;
    --wait: #f0b44c;
    --wait-wash: #3a2f1a;
    --wait-line: #7a5a1e;
    --info: #8ab3ff;
    --info-wash: #1f2f4d;
    --backdrop: rgb(0 0 0 / 0.6);
    --shadow-card: none;
    --shadow-button: none;
    --shadow-panel: 0 4px 16px rgb(0 0 0 / 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #121721;
  --surface: #1b2230;
  --ink: #e3e8f0;
  --muted: #a3aec0;
  --placeholder: #8692a7;
  --line: #2c3546;
  --control-line: #6a7790;
  --wash: #232b3b;
  --accent: #8ab3ff;
  --accent-hover: #a8c7ff;
  --accent-wash: #1f2f4d;
  --on-accent: #0c1630;
  --chrome: #0b1019;
  --chrome-raised: #1f2838;
  --chrome-edge: #2c3546;
  --on-chrome: #e3e8f0;
  --on-chrome-muted: #98a3b6;
  --danger: #ff8a80;
  --danger-wash: #3b1f22;
  --ok: #5fcf8a;
  --ok-wash: #16302a;
  --ok-line: #2f6b4a;
  --wait: #f0b44c;
  --wait-wash: #3a2f1a;
  --wait-line: #7a5a1e;
  --info: #8ab3ff;
  --info-wash: #1f2f4d;
  --backdrop: rgb(0 0 0 / 0.6);
  --shadow-card: none;
  --shadow-button: none;
  --shadow-panel: 0 4px 16px rgb(0 0 0 / 0.4);
}

/* ==== base ==== */

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4, p, ul, ol, dl, dd, figure, fieldset, legend {
  margin: 0;
  padding: 0;
}

ul, ol { list-style: none; }
fieldset { min-width: 0; border: 0; }
img, video, svg { max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* read out, not drawn */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ==== small helpers ==== */

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; }
.strong { font-weight: 600; }
.capitalize { text-transform: capitalize; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.break { overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.right { margin-left: auto; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }

/* siblings one under another / side by side */
.stack { display: grid; gap: 16px; min-width: 0; }
.stack-sm { display: grid; gap: 8px; min-width: 0; }
.stack-lg { display: grid; gap: 24px; min-width: 0; }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.spread { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.grow { flex: 1 1 0; min-width: 0; }
/* position: relative so an absolutely placed child (.sr-only in a far column)
   is clipped by the box instead of widening the page */
.scroll-x { position: relative; overflow-x: auto; }
.narrow { max-width: 480px; }

/* a text link; also a button that reads as one */
.link {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: var(--control-line);
  cursor: pointer;
}

.link:hover { text-decoration-color: currentColor; }
.link-quiet { color: var(--muted); font-weight: 500; }
.link-quiet:hover { color: var(--ink); }
.link-danger:hover { color: var(--danger); }

/* ==== brand ==== */

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--on-chrome);
  color: var(--chrome);
  font-size: 12px;
  font-weight: 700;
}

/* on the ground instead of the chrome */
.brand-mark-dark {
  background: var(--chrome);
  color: var(--on-chrome);
  box-shadow: inset 0 0 0 1px var(--chrome-edge);
}

.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* ==== the frame: the floating navy sidebar and the page beside it ==== */

.portal {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 8px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 8px;
}

.side {
  position: sticky;
  top: 8px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: calc(100vh - 16px);
  height: calc(100dvh - 16px);
  padding: 20px 12px 12px;
  border: 1px solid var(--chrome-edge);
  border-radius: 16px;
  background: var(--chrome);
  color: var(--on-chrome);
  box-shadow: var(--shadow-panel);
  overflow-y: auto;
}

.side :focus-visible { outline-color: var(--on-chrome); }
.side-brand { padding: 0 8px; }
.side-sections { display: grid; gap: 16px; }
.side-nav { display: grid; gap: 2px; }

.side-label {
  padding: 0 12px 6px;
  color: var(--on-chrome-muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--on-chrome-muted);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.side-link:hover {
  background: var(--chrome-raised);
  color: var(--on-chrome);
}

.side-link[aria-current="page"] {
  background: var(--on-chrome);
  color: var(--chrome);
}

.side-small { min-height: 36px; }

/* the lab switcher: the active lab and the role held in it; opened, every
   lab the reader belongs to */
.lab-switch { position: relative; }

.lab-switch > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 6px 10px;
  border: 1px solid var(--chrome-raised);
  border-radius: 12px;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.lab-switch > summary::-webkit-details-marker { display: none; }

.lab-switch > summary:hover,
.lab-switch[open] > summary {
  background: var(--chrome-raised);
}

.lab-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  z-index: 20;
  display: grid;
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--chrome-edge);
  border-radius: 12px;
  background: var(--chrome-raised);
  box-shadow: var(--shadow-panel);
}

.lab-menu .side-link:hover { background: var(--chrome); }
.lab-menu .side-link[aria-current="true"] { color: var(--on-chrome); font-weight: 600; }
.lab-menu-rule { height: 1px; margin: 4px 0; background: var(--chrome); }

.side-who { display: grid; flex: 1; min-width: 0; }
.side-name { overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.side-role { overflow: hidden; color: var(--on-chrome-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.side-chevron { flex: none; color: var(--on-chrome-muted); }

.side-user {
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding: 12px 4px 0;
  border-top: 1px solid var(--chrome-raised);
}

.side-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 4px;
}

/* light, dark, or whatever the device says (theme.js) */
.theme-pick {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 0 0 4px;
}

.theme-opt {
  min-height: 36px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--on-chrome-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.theme-opt:hover { color: var(--on-chrome); }

.theme-opt[aria-pressed="true"] {
  background: var(--chrome-raised);
  color: var(--on-chrome);
  font-weight: 600;
}

.avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--wash);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

.avatar-light {
  background: var(--on-chrome);
  color: var(--chrome);
}

/* the page: its children keep a readable width; a region that holds a data
   grid says .wide and takes the whole page */
.page {
  display: grid;
  align-content: start;
  gap: 20px;
  min-width: 0;
  padding: 24px 24px 48px;
}

.page { grid-template-columns: minmax(0, 1fr); }
.page > * { max-width: 1064px; min-width: 0; }
.page > .wide { max-width: none; }

/* a page with a full-width region: its header and tabs line up with it */
.page:has(> .wide) > * { max-width: none; }

/* a signed-in page outside any lab: one centred column, no sidebar */
.solo {
  display: grid;
  gap: 20px;
  width: 100%;
  max-width: 480px;
  margin-inline: auto;
  padding: 64px 16px;
}

.solo-wide { max-width: 1064px; padding-top: 32px; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 24px;
}

.page-title {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.crumb { color: var(--muted); font-size: 14px; }
.lede { color: var(--muted); }

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.section-title { font-size: 17px; font-weight: 600; }

/* the out-of-band notice region at the top of every page */
.toast-region {
  position: sticky;
  top: 8px;
  z-index: 30;
}

.toast-region:empty { display: none; }
.toast-region .notice { box-shadow: var(--shadow-panel); }

/* ==== buttons ==== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-lg {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  font-size: 16px;
  box-shadow: var(--shadow-button);
}

.btn-outline {
  border-color: var(--control-line);
  background: var(--surface);
  color: var(--ink);
}

.btn-outline:hover { background: var(--wash); }

.btn-quiet {
  border-color: var(--wash);
  background: var(--wash);
  color: var(--ink);
}

.btn-quiet:hover { border-color: var(--line); background: var(--line); }

.btn-danger {
  border-color: var(--danger);
  background: var(--surface);
  color: var(--danger);
}

.btn-danger:hover { background: var(--danger-wash); }

/* an amber "are you sure": replacing a file, overwriting */
.btn-warn {
  border-color: var(--wait-line);
  background: var(--wait-wash);
  color: var(--wait);
}

.btn-warn:hover { background: var(--wait-wash); border-color: var(--wait); }

.btn-tiny {
  min-width: 32px;
  min-height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 13px;
}

/* a toggle that is on (NOT in the filter builder) */
.btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-wash);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* a bare glyph button: remove a row, close */
.icon-btn {
  display: inline-grid;
  flex: none;
  place-items: center;
  min-width: 32px;
  min-height: 32px;
  padding: 0 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.icon-btn:hover { background: var(--wash); color: var(--ink); }
.icon-btn-danger:hover { background: var(--danger-wash); color: var(--danger); }

/* ==== panels, tiles ==== */

.panel {
  display: grid;
  gap: 16px;
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

/* a wide table inside scrolls in its box instead of stretching the panel */
.panel > * { min-width: 0; }

/* a panel that is only a table: the rows run to its edges */
.panel-flush { padding: 8px 8px; }

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

.panel-title { font-size: 17px; font-weight: 600; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.tile {
  position: relative;
  display: grid;
  align-content: start;
  gap: 6px;
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.tile:hover { border-color: var(--control-line); }
.tile-title { font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.tile-count { color: var(--muted); font-size: 14px; }
.tile-link { color: inherit; text-decoration: none; }

/* the whole tile is the link's target */
.tile-link::after {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  content: "";
}

/* a tinted box inside a panel: a note, a sub-form */
.well {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--wash);
}

.empty {
  padding: 24px 12px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

/* ==== chips: a tinted fill, a border and a dot, never colour alone ==== */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  padding: 2px 10px;
  border: 1px solid var(--control-line);
  border-radius: 999px;
  background: var(--wash);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.chip::before {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  content: "";
}

.chip-plain::before { content: none; }
.chip-ok { border-color: var(--ok-line); background: var(--ok-wash); color: var(--ok); }
.chip-wait { border-color: var(--wait-line); background: var(--wait-wash); color: var(--wait); }
.chip-info { border-color: var(--info); background: var(--info-wash); color: var(--info); }
.chip-bad { border-color: var(--danger); background: var(--danger-wash); color: var(--danger); }
.chip-off { border-style: dashed; background: var(--surface); color: var(--muted); }

/* a variable's type, beside its name */
.type-tag {
  flex: none;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--wash);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
}

/* ==== notices ==== */

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--danger);
  border-radius: 12px;
  background: var(--danger-wash);
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.notice-done { border-color: var(--ok-line); background: var(--ok-wash); color: var(--ok); }
.notice-warn { border-color: var(--wait-line); background: var(--wait-wash); color: var(--wait); }
.notice-info { border-color: var(--line); background: var(--wash); color: var(--muted); }
.notice .link { color: inherit; text-decoration-color: currentColor; }

/* ==== tables ==== */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th,
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.table th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table .num { font-family: var(--mono); white-space: nowrap; }
.table .end { text-align: right; }
.table-main { font-weight: 500; overflow-wrap: anywhere; }

.cell-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.cell-actions form { display: contents; }

/* ==== the data grid: an SPSS-style sheet ==== */

.grid-box {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow-x: auto;
}

.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.grid th,
.grid td {
  height: 40px;
  padding: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.grid th:last-child,
.grid td:last-child { border-right: 0; }
.grid tbody tr:last-child td { border-bottom: 0; }

.grid thead th {
  background: var(--wash);
  font-size: 13px;
  font-weight: 600;
}

/* a read-only cell, or a header that is plain text */
.grid .cell { padding: 0 12px; }

.grid .rownum {
  width: 56px;
  padding: 0 10px;
  background: var(--wash);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
  text-align: right;
}

.grid .num { font-family: var(--mono); text-align: right; }
.grid .missing { color: var(--placeholder); }

/* an editable cell: the input IS the cell */
.cell-input {
  display: block;
  width: 100%;
  min-width: 96px;
  height: 39px;
  padding: 0 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.cell-input::placeholder { color: var(--placeholder); opacity: 1; }
.cell-input:hover { background: var(--wash); }

.cell-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-wash);
}

.cell-input.num { font-family: var(--mono); text-align: right; }

/* a header that opens its variable's popover */
.col-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 39px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

button.col-head:hover { background: var(--line); }

/* the row under the last case: add a case, load more */
.grid-foot {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.grid-foot:hover { background: var(--wash); color: var(--ink); }

/* ==== forms ==== */

.form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; min-width: 0; }

.field > label,
.label,
.legend {
  font-size: 14px;
  font-weight: 500;
}

.optional { color: var(--muted); font-weight: 400; }

.input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--control-line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}

.input::placeholder { color: var(--placeholder); opacity: 1; }
.input:disabled { background: var(--wash); color: var(--muted); cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input-lg { min-height: 48px; padding: 0 14px; font-size: 16px; }
.input-sm { min-height: 32px; padding: 0 8px; border-radius: 8px; font-size: 14px; }
.input-auto { width: auto; }
.input-mono { font-family: var(--mono); font-size: 14px; }

textarea.input {
  min-height: 72px;
  padding: 10px 12px;
  line-height: 1.5;
  resize: vertical;
}

input[type="file"].input { padding: 7px 12px; }

.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.row-end {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.row-end .field { flex: 1 1 180px; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  font-size: 15px;
}

.check input,
.checkbox {
  flex: none;
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

/* ==== section tabs: the views of one section, under the page's header ==== */

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  box-shadow: inset 0 -1px 0 var(--line);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.tab:hover { color: var(--ink); }
.tab:focus-visible { outline-offset: -2px; }

/* the view on the page: the line under it and its weight, not colour alone */
.tab[aria-current] {
  border-bottom-color: var(--accent);
  color: var(--ink);
  font-weight: 600;
}

.tab-count {
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--line);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
}

.tab[aria-current] .tab-count { background: var(--accent); color: var(--on-accent); }

/* ==== facts: a record read, label over value ==== */

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px 24px;
}

.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { font-weight: 500; overflow-wrap: anywhere; }

/* text as it was written or sent: a rendered prompt, raw output */
.source {
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--wash);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* a <details> that folds a secondary block away */
.fold > summary {
  width: fit-content;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.fold > summary:hover { color: var(--ink); }
.fold[open] > summary { margin-bottom: 10px; }

/* ==== popovers and dialogs (native popover / <dialog>, top layer) ==== */

.pop {
  position: fixed;
  inset: 0;
  width: 22rem;
  max-width: calc(100vw - 32px);
  height: fit-content;
  max-height: calc(100vh - 32px);
  margin: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-panel);
  text-align: left;
  overflow-y: auto;
}

.pop::backdrop { background: var(--backdrop); }
.pop-wide { width: 34rem; }
.pop-title { margin-bottom: 14px; font-size: 17px; font-weight: 600; }

/* ==== the signed-out pages ==== */

.auth {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: 8px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 12px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  padding: 32px 40px 40px;
  border: 1px solid var(--chrome-edge);
  border-radius: 20px;
  background: var(--chrome);
  color: var(--on-chrome);
  box-shadow: var(--shadow-panel);
}

.auth-pitch {
  display: grid;
  gap: 32px;
  max-width: 400px;
  margin-block: auto;
  padding-block: 48px;
}

.auth-pitch-title {
  font-size: 32px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.auth-features { display: grid; gap: 20px; }
.auth-features li { display: flex; gap: 14px; }

.auth-feature-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--chrome-raised);
}

.auth-feature-title { display: block; font-weight: 600; }
.auth-feature-body { display: block; color: var(--on-chrome-muted); font-size: 14px; }

.auth-main {
  display: flex;
  flex-direction: column;
  padding: 32px clamp(16px, 4vw, 48px) 40px;
}

.auth-phone-brand { display: none; }

.auth-col {
  width: 100%;
  max-width: 400px;
  margin: auto;
  padding-block: 32px;
}

.auth-heading {
  font-size: 32px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.auth-lede {
  margin-top: 8px;
  margin-bottom: 32px;
  color: var(--muted);
  font-size: 16px;
}

.auth-foot {
  display: grid;
  gap: 8px;
  margin-top: 28px;
  color: var(--muted);
  font-size: 14px;
}

/* a bot trap: off the page, still in the form */
.honeypot {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ==== a phone ==== */

@media (max-width: 860px) {
  .portal {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 0;
  }

  .side {
    position: static;
    gap: 12px;
    height: auto;
    padding: 12px;
    border-radius: 0 0 16px 16px;
    overflow-y: visible;
  }

  .side-sections { display: flex; flex-wrap: wrap; gap: 4px 12px; }
  .side-label { display: none; }
  .side-nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .side-link { width: auto; min-height: 44px; }
  .side-user { margin-top: 0; padding-top: 8px; }
  .page { padding: 20px 16px 40px; }
  .page-title { font-size: 22px; }
  .panel { padding: 16px; }

  .auth {
    grid-template-columns: minmax(0, 1fr);
    padding: 0;
  }

  .auth-brand { display: none; }
  .auth-phone-brand { display: flex; }
  .auth-main { padding: 20px 16px 32px; }
  .auth-col { margin-top: 48px; }
}

/* ==== datasets, media (dashboard/datasets.templ, media.templ) ==== */

/* a dataset's description under its name in the list */
.dataset-blurb { display: block; }

/* an out-of-band target that takes no room until something lands in it */
.slot:empty { display: none; }

/* a popover opened from inside the grid must not inherit the sheet's type */
.grid .pop {
  font-size: 15px;
  font-weight: 400;
  white-space: normal;
}

/* a further block inside a popover, ruled off from the one above */
.pop-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* a case row: its number gives way to the delete button under the pointer */
.case-del { display: none; min-height: 28px; }
.case-row:hover .case-num { display: none; }
.case-row:hover .case-del { display: inline-grid; }

/* a media cell: the filename, then replace / clear */
.media-cell {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 11rem;
  max-width: 22rem;
  height: 39px;
  padding: 0 6px 0 12px;
  font-size: 14px;
}

.media-cell .link { font-weight: 500; }

/* "or upload" between the library picker and the upload form */
.or-rule {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 13px;
}

.or-rule::before,
.or-rule::after {
  flex: 1;
  border-top: 1px solid var(--line);
  content: "";
}

/* the import popover widens once the preview has landed inside it */
.import-pop { transition: width 0.15s; }
.import-pop:has([data-preview]) { width: 34rem; }

.import-preview {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.import-cols { max-height: 45vh; overflow-y: auto; }

.import-col {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.import-col + .import-col { border-top: 1px solid var(--line); }
.import-col .input { flex: none; width: 11rem; }

.import-issues {
  display: grid;
  gap: 4px;
  max-height: 10rem;
  padding-left: 18px;
  font-size: 13px;
  font-weight: 400;
  list-style: disc;
  overflow-y: auto;
}

/* export: the other datasets whose variables may be appended */
.export-joins {
  display: grid;
  gap: 6px;
  max-height: 14rem;
  overflow-y: auto;
}

.export-joins .legend { margin-bottom: 6px; }
.export-joins .check { align-items: flex-start; }
.export-joins .check input { margin: 2px 0 0; }
.export-joins .hint { display: block; }

/* value labels: one value → label pair per row */
.label-row { display: flex; align-items: center; gap: 8px; }
.label-row .input { flex: 1 1 0; min-width: 0; }
.label-row .label-value { flex: 0 0 6rem; }

/* the media library */
.media-kind { width: 1%; }
.table td.media-kind { padding-right: 0; }
.media-more { padding: 0 12px 4px; }
.media-cloud-text { display: grid; flex: 1 1 320px; gap: 4px; min-width: 0; }
.copy-all { user-select: all; }

.dropzone {
  display: grid;
  gap: 6px;
  padding: 28px 24px;
  border: 2px dashed var(--control-line);
  border-radius: 16px;
  background: var(--surface);
  text-align: center;
  transition: border-color 0.15s, background-color 0.15s;
}

.dropzone[data-dragging] {
  border-color: var(--accent);
  background: var(--accent-wash);
}

.upload-queue {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  text-align: left;
}

.upload-queue:empty { display: none; }

.upload-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.upload-name { max-width: 40%; font-size: 13px; }

.upload-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.upload-bar {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.15s;
}

.upload-bar.is-bad { background: var(--danger); }

.upload-status {
  flex: none;
  width: 6rem;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.upload-status.is-bad { color: var(--danger); }

/* ==== batch inference, studies, scatter (dashboard/research.templ, studies.templ, scatter.templ) ==== */

/* a second line under a table cell's main text: a description, a time */
.cell-sub {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

/* a read-only grid header: the variable's type beside its name */
.col-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* an empty-state row inside the read-only grid */
.grid td.empty {
  height: auto;
  padding: 40px 12px;
  white-space: normal;
}

/* the filter builder: a group is a box, a nested group a box inside it;
   a condition (and a group's own header) is one row of controls */
.group {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--wash);
}

.group .group { background: var(--surface); }
.group .group .group { background: var(--wash); }

/* a negated group: the amber edge says "everything in here is turned round" */
.group-not { border-color: var(--wait-line); box-shadow: inset 3px 0 0 var(--wait-line); }

.cond {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.cond .cond-val { width: 10rem; }
.cond .cond-val-num { width: 7rem; font-family: var(--mono); }

.not-toggle {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
}

/* the filter as logic notation, above the builder */
.formula {
  display: block;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--wash);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  overflow-wrap: anywhere;
}

/* the sentence under a popover's title */
.pop-lede { margin: -8px 0 14px; }

/* two controls side by side inside a narrow form: dataset + variable */
.pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

/* a study tile: name and view type, then the foot with its own controls,
   which sit above the tile-wide link */
.tile-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.tile-foot {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

.clamp-2 {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

/* the scatter: geometry is computed in Go, every colour is a token here */
.plot {
  display: block;
  width: 100%;
  max-width: 600px;
  height: auto;
  justify-self: center;
}

.plot-rule { stroke: var(--line); stroke-width: 1; }
.plot-axis { stroke: var(--control-line); stroke-width: 1; }
.plot-tick { fill: var(--muted); font-family: var(--mono); font-size: 11px; }
.plot-label { fill: var(--ink); font-family: var(--font); font-size: 12px; font-weight: 500; }

.plot-dot {
  fill: var(--accent);
  fill-opacity: 0.85;
  stroke: var(--surface);
  stroke-width: 2;
  pointer-events: none;
}

/* the oversized target that carries a dot's <title> tooltip */
.plot-hit { fill: none; pointer-events: all; }

.plot-caption {
  display: grid;
  gap: 2px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* ==== prompts, playground, admin (dashboard/prompts.templ, playground.templ, admin.templ) ==== */

/* a prompt's description under its name in the library table */
.prompt-blurb {
  display: block;
  max-width: 56ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* the output-schema builder: a table whose cells are controls */
.schema-table td { padding: 6px; vertical-align: top; }
.schema-table th { padding: 8px 6px; }
.schema-table .input { min-width: 104px; }
.schema-table .schema-name .input { min-width: 150px; }
.schema-table .schema-wide .input { min-width: 180px; }

/* the playground's dataset pickers: the wrapper is a swap target only, its
   fields sit in the setup form's row */
.slots { display: contents; }

/* the run form, under the setup form in the same panel */
.bindings {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* where a run's result lands; nothing until a run is made or recalled */
.result-slot:empty { display: none; }

/* a chip that holds a value of any length: a bound cell */
.chip-wrap {
  border-radius: 10px;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* the platform-admin page: its second part, and stacked load errors */
.admin-part {
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.solo .toast-region > * + * { margin-top: 8px; }
