/* Themes: five palettes, each with a dark and a light mode, selected with
   data-theme / data-mode on <html> (see src/theme.ts). Midnight dark is the
   default. "Film" tokens colour the always-dark lightbox-style panels. */
:root {
  --radius-s: 4px;
  --radius-m: 8px;
  --font: 'Atkinson Hyperlegible Next', 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
:root, :root[data-theme="midnight"][data-mode="dark"] {
  --bg: #0d1726;
  --panel: #13213a;
  --panel-2: #1a2b48;
  --rule: #253a5c;
  --text: #dbe5f3;
  --muted: #8ea2c0;
  --accent: #5aa2ff;
  --accent-ink: #05111f;
  --accent-soft: rgba(90, 162, 255, 0.16);
  --ok: #4fbf8f;
  --bad: #ef6b5e;
  --film: #08101c;
  --film-panel: #14223a;
  --film-rule: #22344f;
  --film-text: #d6e1f0;
  --film-muted: #8496b3;
  --focus: #9cc8ff;
  color-scheme: dark;
}
:root[data-theme="midnight"][data-mode="light"] {
  --bg: #edf2f9;
  --panel: #ffffff;
  --panel-2: #f4f7fc;
  --rule: #d3dceb;
  --text: #15233a;
  --muted: #566a88;
  --accent: #1d64c9;
  --accent-ink: #ffffff;
  --accent-soft: rgba(29, 100, 201, 0.12);
  --ok: #237a52;
  --bad: #c0392f;
  --film: #0f1a2b;
  --film-panel: #182640;
  --film-rule: #2a3c5a;
  --film-text: #dbe5f3;
  --film-muted: #8ea2c0;
  --focus: #1d64c9;
  color-scheme: light;
}
:root[data-theme="slate"][data-mode="dark"] {
  --bg: #18212b;
  --panel: #212d3a;
  --panel-2: #283646;
  --rule: #2f3e4f;
  --text: #dce4ec;
  --muted: #8b9bae;
  --accent: #e9b44c;
  --accent-ink: #1d1606;
  --accent-soft: rgba(233, 180, 76, 0.14);
  --ok: #5db88c;
  --bad: #e0675a;
  --film: #0f161e;
  --film-panel: #283646;
  --film-rule: #2f3e4f;
  --film-text: #dce4ec;
  --film-muted: #8b9bae;
  --focus: #7cc4ff;
  color-scheme: dark;
}
:root[data-theme="slate"][data-mode="light"] {
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel-2: #f5f7f9;
  --rule: #d5dce3;
  --text: #1c2733;
  --muted: #5b6b7d;
  --accent: #b97a0c;
  --accent-ink: #ffffff;
  --accent-soft: rgba(185, 122, 12, 0.12);
  --ok: #2d8a5e;
  --bad: #c2463a;
  --film: #1a232d;
  --film-panel: #283646;
  --film-rule: #33445a;
  --film-text: #dce4ec;
  --film-muted: #8b9bae;
  --focus: #1f6fb5;
  color-scheme: light;
}
:root[data-theme="graphite"][data-mode="dark"] {
  --bg: #161718;
  --panel: #1f2022;
  --panel-2: #27292c;
  --rule: #34373b;
  --text: #e3e4e6;
  --muted: #979ba1;
  --accent: #3cc4d6;
  --accent-ink: #04191c;
  --accent-soft: rgba(60, 196, 214, 0.15);
  --ok: #5dbb84;
  --bad: #e8695d;
  --film: #0c0d0e;
  --film-panel: #222326;
  --film-rule: #323438;
  --film-text: #dedfe1;
  --film-muted: #8d9196;
  --focus: #7fe3f0;
  color-scheme: dark;
}
:root[data-theme="graphite"][data-mode="light"] {
  --bg: #f2f2f3;
  --panel: #ffffff;
  --panel-2: #f7f7f8;
  --rule: #dadbdd;
  --text: #1c1d1f;
  --muted: #62666b;
  --accent: #0e8797;
  --accent-ink: #ffffff;
  --accent-soft: rgba(14, 135, 151, 0.12);
  --ok: #2b7d51;
  --bad: #c2412f;
  --film: #18191b;
  --film-panel: #26282b;
  --film-rule: #36393d;
  --film-text: #e3e4e6;
  --film-muted: #979ba1;
  --focus: #0e8797;
  color-scheme: light;
}
:root[data-theme="evergreen"][data-mode="dark"] {
  --bg: #0f1a17;
  --panel: #152420;
  --panel-2: #1c2f29;
  --rule: #284239;
  --text: #dbe9e3;
  --muted: #8eab9f;
  --accent: #4fd1a1;
  --accent-ink: #04170f;
  --accent-soft: rgba(79, 209, 161, 0.15);
  --ok: #7ccf72;
  --bad: #ef6f60;
  --film: #08110e;
  --film-panel: #152621;
  --film-rule: #243a33;
  --film-text: #d6e6df;
  --film-muted: #87a397;
  --focus: #93ead0;
  color-scheme: dark;
}
:root[data-theme="evergreen"][data-mode="light"] {
  --bg: #eef5f2;
  --panel: #ffffff;
  --panel-2: #f5faf8;
  --rule: #d0e1d9;
  --text: #13261f;
  --muted: #557063;
  --accent: #137a56;
  --accent-ink: #ffffff;
  --accent-soft: rgba(19, 122, 86, 0.12);
  --ok: #2f7d3c;
  --bad: #c03a2f;
  --film: #10201b;
  --film-panel: #1a2e28;
  --film-rule: #2a453c;
  --film-text: #dbe9e3;
  --film-muted: #8eab9f;
  --focus: #137a56;
  color-scheme: light;
}
:root[data-theme="plum"][data-mode="dark"] {
  --bg: #1a1424;
  --panel: #231b31;
  --panel-2: #2c223d;
  --rule: #3b2e52;
  --text: #e8e0f2;
  --muted: #a596ba;
  --accent: #c08cff;
  --accent-ink: #1a0d2b;
  --accent-soft: rgba(192, 140, 255, 0.16);
  --ok: #5fc49a;
  --bad: #f0707a;
  --film: #0f0b16;
  --film-panel: #241c33;
  --film-rule: #382c4e;
  --film-text: #e3dbee;
  --film-muted: #9c8eb2;
  --focus: #d9b8ff;
  color-scheme: dark;
}
:root[data-theme="plum"][data-mode="light"] {
  --bg: #f5f1fa;
  --panel: #ffffff;
  --panel-2: #faf7fd;
  --rule: #e0d6ec;
  --text: #24183a;
  --muted: #6c5d84;
  --accent: #7b3fc4;
  --accent-ink: #ffffff;
  --accent-soft: rgba(123, 63, 196, 0.12);
  --ok: #2a7d57;
  --bad: #c13b4a;
  --film: #1a1326;
  --film-panel: #2a2140;
  --film-rule: #3d3058;
  --film-text: #e8e0f2;
  --film-muted: #a596ba;
  --focus: #7b3fc4;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 0.5rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 700; }
p { margin: 0 0 0.75rem; }
a { color: var(--accent); }
.tab { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.strong { font-weight: 700; }

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

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-s);
  padding: 0.45rem 0.6rem;
  min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input[type='checkbox'] { accent-color: var(--accent); width: 1rem; height: 1rem; padding: 0; }

button { font: inherit; cursor: pointer; color: inherit; }
button:disabled { cursor: default; opacity: 0.55; }
.btn, .btn-primary, .btn-ghost, .btn-link {
  border-radius: var(--radius-s);
  padding: 0.45rem 0.9rem;
  border: 1px solid transparent;
  background: none;
  white-space: nowrap;
}
.btn { border-color: var(--rule); background: var(--panel-2); }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn-primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--panel-2); }
.btn-ghost.danger:hover:not(:disabled) { color: var(--bad); }
.btn-link { padding: 0.1rem 0.3rem; color: var(--accent); }
.btn-link:hover { text-decoration: underline; }
.block { width: 100%; }

/* ------------------------------------------------------------------ shell */
.boot { min-height: 100vh; }
.shell { display: grid; grid-template-columns: 15rem 1fr; min-height: 100vh; }
.rail {
  background: var(--panel);
  border-right: 1px solid var(--rule);
  padding: 1.1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.rail ul { list-style: none; margin: 0; padding: 0; }
.rail a {
  display: block;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-s);
  color: var(--text);
  text-decoration: none;
}
.rail a:hover { background: var(--panel-2); }
.rail a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.rail-group { color: var(--muted); font-size: 0.82rem; margin: 1.1rem 0.65rem 0.25rem; }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.15rem; border-top: 1px solid var(--rule); padding-top: 0.75rem; }
.rail-foot .btn-ghost { text-align: left; padding-left: 0.65rem; }
.rail-viewer { border: 1px solid var(--rule); text-align: center; margin-bottom: 0.4rem; }

.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; font-size: 1.05rem; padding: 0 0.65rem 1rem; }
.brand-lg { font-size: 1.35rem; padding: 0 0 1rem; }
/* A tiny lightbox: four panes, one lit. */
.brand-mark {
  width: 1.15rem; height: 1.15rem; flex: none;
  display: inline-block;
  background:
    linear-gradient(var(--accent), var(--accent)) 0 0 / 46% 46% no-repeat,
    linear-gradient(var(--rule), var(--rule)) 100% 0 / 46% 46% no-repeat,
    linear-gradient(var(--rule), var(--rule)) 0 100% / 46% 46% no-repeat,
    linear-gradient(var(--rule), var(--rule)) 100% 100% / 46% 46% no-repeat;
  border-radius: 2px;
}

.main { padding: 1.75rem 2rem 4rem; min-width: 0; }
.page { max-width: 82rem; }
.page-narrow { max-width: 34rem; }
.page-head { display: flex; align-items: center; gap: 1rem; justify-content: space-between; flex-wrap: wrap; margin-bottom: 0.5rem; }
.page-head h1 { margin: 0; }
.lede { color: var(--muted); max-width: 70ch; }
.notice { color: var(--muted); }
.count { color: var(--muted); margin: 1.25rem 0 0.5rem; }

/* ------------------------------------------------------------------ login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(24rem, 100%); display: flex; flex-direction: column; gap: 0.9rem; }
.login-lede { color: var(--muted); }

/* ------------------------------------------------------------------ forms */
.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; border: 0; padding: 0; margin: 0; }
.field-label { font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.field-hint { font-size: 0.8rem; color: var(--muted); }
.form { display: flex; flex-direction: column; gap: 0.9rem; }
.form h2 { margin-top: 0.5rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0.9rem 1rem; align-items: start; }
.form-grid .field-wide, .form-grid > .field-wide { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.spacer { flex: 1; }
.form-error { color: var(--bad); margin: 0.5rem 0; }
.check { display: inline-flex; align-items: center; gap: 0.45rem; cursor: pointer; }
.checks { display: flex; gap: 1.25rem; flex-wrap: wrap; margin: 0.25rem 0 0.5rem; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-grid > .check { align-self: end; padding-bottom: 0.5rem; }

.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--radius-s); overflow: hidden; flex-wrap: wrap; }
.seg button { background: var(--panel-2); border: 0; border-right: 1px solid var(--rule); padding: 0.42rem 0.75rem; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* ------------------------------------------------------------------ search */
.node-picker { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.75rem 0 1rem; }
.node-chip {
  display: inline-flex; align-items: center; gap: 0.5rem;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-m);
  padding: 0.5rem 0.8rem;
}
.node-chip:hover { border-color: var(--muted); }
.node-chip.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.node-chip-name { font-weight: 700; }
.node-chip-kind { color: var(--muted); font-size: 0.82rem; }

.query {
  display: grid;
  grid-template-columns: repeat(4, minmax(8rem, 1fr)) minmax(10rem, max-content);
  gap: 0.6rem;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  padding: 0.9rem;
}
.query-row { grid-column: 1 / -1; border: 0; padding: 0; margin: 0.25rem 0 0; min-width: 0; }
.query-row > legend { padding: 0; margin-bottom: 0.35rem; }
.query .dates { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; color: var(--muted); }
.date-range { display: inline-flex; align-items: center; gap: 0.5rem; }
.date-summary { font-size: 0.9rem; }
.mod-checks { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.mod-check {
  display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer; user-select: none;
  border: 1px solid var(--rule); background: var(--panel-2); border-radius: var(--radius-s);
  padding: 0.3rem 0.6rem; font-weight: 700; font-size: 0.88rem;
}
.mod-check:hover { border-color: var(--muted); }
.mod-check.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.mod-check input { width: 0.9rem; height: 0.9rem; }
.query > .btn-primary { grid-column: 5; max-width: 20rem; overflow: hidden; text-overflow: ellipsis; }
.query-compact { grid-template-columns: 1fr auto; max-width: 40rem; margin: 1rem 0; }

.dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; opacity: 0.6; }
.dot-ok { background: var(--ok); opacity: 1; }
.dot-bad { background: var(--bad); opacity: 1; }

.mods { display: inline-flex; gap: 0.25rem; flex-wrap: wrap; }
.mod {
  display: inline-block; font-size: 0.78rem; font-weight: 700; padding: 0.05rem 0.4rem;
  border-radius: 3px; background: var(--panel-2); border: 1px solid var(--rule); color: var(--text);
}
.badge { font-size: 0.75rem; padding: 0.05rem 0.4rem; border-radius: 3px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--rule); }

table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-m); overflow: hidden; }
.grid th { text-align: left; font-weight: 500; font-size: 0.85rem; color: var(--muted); padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--rule); background: var(--panel-2); }
.grid td { padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid .num { text-align: right; }
.grid .actions { text-align: right; white-space: nowrap; }
.grid .actions > * + * { margin-left: 0.25rem; }
.grid .sub { display: block; color: var(--muted); font-size: 0.85rem; max-width: 40ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { cursor: pointer; }
.row:hover td { background: var(--panel-2); }
.row-open td { background: var(--accent-soft); }
.row-open td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tr.detail > td { background: var(--film); padding: 0; }

.study-detail { display: grid; grid-template-columns: minmax(0, 1fr) 19rem; gap: 1.25rem; padding: 1rem 1.25rem 1.25rem; color: var(--film-text); }
.series-list { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.series { display: grid; grid-template-columns: auto 2.5rem auto 1fr auto; align-items: center; gap: 0.65rem; padding: 0.35rem 0.5rem; border-radius: var(--radius-s); cursor: pointer; }
.series:hover { background: rgba(255, 255, 255, 0.06); }
.series .mod { background: transparent; border-color: var(--film-rule); color: var(--film-text); }
.series-no { color: var(--film-muted); text-align: right; }
.series-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.series-count { color: var(--film-muted); font-size: 0.85rem; }
.study-actions { display: flex; flex-direction: column; gap: 0.6rem; align-items: stretch; }
.study-actions .field-label { color: var(--film-muted); display: block; margin-bottom: 0.3rem; }
.study-actions .seg button { background: var(--film-panel); color: var(--film-text); border-color: var(--film-rule); }
.study-actions .seg button.on { background: var(--accent); color: var(--accent-ink); }
.study-actions .btn { background: var(--film-panel); color: var(--film-text); border-color: var(--film-rule); }
.study-detail .muted { color: var(--film-muted); }

.progress { display: flex; flex-direction: column; gap: 0.3rem; min-width: 11rem; }
.progress-bar { height: 0.4rem; background: var(--rule); border-radius: 99px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--accent); transition: width 0.4s ease; }
.progress-completed .progress-bar span { background: var(--ok); }
.progress-failed .progress-bar span, .progress-partial .progress-bar span { background: var(--bad); }
.progress-cancelled .progress-bar span { background: var(--muted); }
.progress-label { font-size: 0.85rem; }
.progress-msg { font-size: 0.8rem; color: var(--bad); max-width: 46ch; overflow-wrap: anywhere; }
.progress-cell { width: 30%; }

.empty { border: 1px dashed var(--rule); border-radius: var(--radius-m); padding: 2rem; margin-top: 1.25rem; max-width: 46rem; }
.empty-title { font-weight: 700; font-size: 1.1rem; margin-bottom: 0.35rem; }
.empty-body { color: var(--muted); }
.empty-body p { margin: 0; }

/* ------------------------------------------------------------------ nodes */
.node-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr)); gap: 1rem; margin-top: 1rem; }
.node-card { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: 0.45rem; }
.node-card.disabled { opacity: 0.65; }
.node-card header { display: flex; align-items: center; gap: 0.55rem; }
.node-kind { color: var(--muted); font-size: 0.82rem; margin-left: auto; }
.node-addr { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.node-meta { margin: 0; color: var(--muted); font-size: 0.88rem; }
.node-card footer { display: flex; gap: 0.35rem; margin-top: auto; padding-top: 0.5rem; }
.steps { list-style: none; margin: 0.25rem 0; padding: 0.55rem 0.7rem; background: var(--panel-2); border-radius: var(--radius-s); display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.88rem; }
.steps li { display: grid; grid-template-columns: 1rem 9.5rem 1fr; gap: 0.4rem; }
.steps .ok .step-mark { color: var(--ok); }
.steps .bad .step-mark, .steps .bad .step-detail { color: var(--bad); }
.step-detail { color: var(--muted); overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ modal / toasts */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8, 12, 17, 0.6); display: grid; place-items: start center; padding: 6vh 1rem; overflow-y: auto; z-index: 20; }
.modal { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-m); width: min(32rem, 100%); padding: 1.25rem 1.4rem 1.4rem; }
.modal-wide { width: min(58rem, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.toasts { position: fixed; right: 1.25rem; bottom: 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 30; }
.toast { background: var(--panel); border: 1px solid var(--rule); border-left: 3px solid var(--ok); padding: 0.65rem 0.9rem; border-radius: var(--radius-s); max-width: 26rem; }
.toast-error { border-left-color: var(--bad); }
.code { background: var(--film); color: var(--film-text); padding: 1rem; border-radius: var(--radius-s); overflow: auto; max-height: 65vh; font-size: 0.8rem; }

/* ------------------------------------------------------------------ hanging protocols */
.page-split { display: grid; grid-template-columns: 18rem minmax(0, 1fr); gap: 2rem; max-width: 96rem; }
.hp-list .lede { font-size: 0.92rem; }
.hp-group { margin-top: 1.25rem; }
.hp-group-mod { font-weight: 700; color: var(--accent); margin: 0 0 0.35rem; }
.hp-group ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.hp-item { width: 100%; display: flex; align-items: center; gap: 0.6rem; text-align: left; background: none; border: 1px solid transparent; border-radius: var(--radius-s); padding: 0.4rem 0.5rem; }
.hp-item:hover { background: var(--panel); }
.hp-item.on { background: var(--panel); border-color: var(--accent); }
.hp-item.off .hp-item-name { color: var(--muted); }
.hp-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hp-prio { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.mini { display: inline-grid; gap: 2px; width: 1.6rem; height: 1.2rem; flex: none; }
.mini span { background: var(--muted); opacity: 0.55; border-radius: 1px; }
.mini-big { width: 4.5rem; height: 3.3rem; gap: 3px; }
.mini-big span { background: var(--film); opacity: 1; box-shadow: inset 0 0 0 1px var(--rule); }

.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr)); gap: 0.75rem; }
.template { display: flex; flex-direction: column; align-items: flex-start; gap: 0.45rem; background: var(--panel-2); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 0.9rem; text-align: left; }
.template:hover { border-color: var(--accent); }
.template-name { font-weight: 700; }
.template-mod { color: var(--muted); font-size: 0.85rem; }

.hp-editor { display: flex; flex-direction: column; gap: 1.25rem; }
.hp-meta { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 1rem; align-items: start; }
.hp-meta > .check { padding-top: 1.7rem; }

/* The lightbox: the protocol as it will hang, panes lit like a film viewer. */
.hp-stage { background: var(--film); border-radius: var(--radius-m); padding: 0.9rem; }
.hp-stage-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.8rem; color: var(--film-text); }
.hp-stage .field-label { color: var(--film-muted); }
.sync { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.layout-picker { display: flex; align-items: center; gap: 0.75rem; }
.layout-cells { display: grid; grid-template-columns: repeat(4, 0.95rem); gap: 3px; }
.layout-cells button { width: 0.95rem; height: 0.95rem; padding: 0; border: 1px solid var(--film-rule); background: var(--film-panel); border-radius: 2px; }
.layout-cells button.in { background: var(--accent); border-color: var(--accent); }
.layout-label { color: var(--film-text); font-weight: 700; min-width: 3rem; }
.lightbox { display: grid; gap: 6px; min-height: 19rem; }
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; gap: 0.1rem;
  text-align: left;
  border: 1px solid var(--film-rule);
  border-radius: 3px;
  padding: 0.7rem 0.8rem;
  color: var(--film-text);
  background: radial-gradient(120% 90% at 50% 40%, color-mix(in srgb, var(--film-panel) 70%, #ffffff 12%) 0%, var(--film-panel) 70%);
  overflow: hidden;
  min-height: 7.5rem;
}
.tile:hover { border-color: var(--film-muted); }
.tile.on {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  /* A lit lightbox pane, tinted with the theme accent. */
  background: radial-gradient(120% 90% at 50% 40%, color-mix(in srgb, var(--accent) 35%, #ffffff) 0%, color-mix(in srgb, var(--accent) 80%, #ffffff) 55%, color-mix(in srgb, var(--accent) 75%, #000000) 100%);
  color: #10141a;
}
.tile.inverted:not(.on) { background: radial-gradient(120% 90% at 50% 40%, #cfd6dd 0%, #8d99a5 70%); color: #10171e; }
.tile-title { font-weight: 700; font-size: 1rem; }
.tile-line { font-size: 0.82rem; opacity: 0.85; }
.tile-plane { position: absolute; top: 0.7rem; right: 0.8rem; width: 2rem; height: 2rem; border: 1.5px solid currentColor; border-radius: 50%; opacity: 0.55; }
.plane-axial { border-radius: 50%; transform: scaleY(0.35); }
.plane-sagittal { transform: scaleX(0.35); }
.plane-coronal { border-radius: 4px; transform: scaleY(0.8); }

.hp-inspector { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 1.1rem 1.2rem; }
.hp-inspector h2 { margin-bottom: 0.9rem; }
.hp-advanced { margin-top: 1.2rem; border-top: 1px solid var(--rule); padding-top: 0.9rem; }
.hp-advanced summary { cursor: pointer; color: var(--muted); margin-bottom: 0.75rem; }

/* ------------------------------------------------------------------ small screens */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 0.6rem; }
  .rail ul { display: flex; flex-wrap: wrap; }
  .rail-group { display: none; }
  .rail-foot { margin: 0; border: 0; padding: 0; flex-direction: row; flex-wrap: wrap; }
  .brand { padding: 0 0.5rem; }
  .main { padding: 1.25rem 1rem 3rem; }
  .query { grid-template-columns: 1fr 1fr; }
  .query > .btn-primary { grid-column: 1 / -1; }
  .study-detail { grid-template-columns: 1fr; }
  .page-split { grid-template-columns: 1fr; }
  .hp-meta { grid-template-columns: 1fr 1fr; }
  table.grid { display: block; overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* layout fixes */
.field > .seg { align-self: flex-start; }
.seg-grid { display: grid; grid-template-columns: repeat(2, 1fr); align-self: stretch !important; }
.seg-grid button { border-bottom: 1px solid var(--rule); }
.seg-grid button:nth-child(2n) { border-right: 0; }
.seg-grid button:nth-last-child(-n + 2) { border-bottom: 0; }
.hp-list .btn-primary.block { margin: 0.25rem 0 1rem; }
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .page-split > *, .main { min-width: 0; }
  .rail { width: 100%; }
}

/* ------------------------------------------------------------------ 1.1 additions */
.small { font-size: 0.85rem; }
.small-print { font-size: 0.88rem; margin-top: 1rem; }
.warn-text { color: var(--bad); font-size: 0.9rem; }
code { font-size: 0.9em; background: var(--panel-2); border: 1px solid var(--rule); border-radius: 3px; padding: 0.05rem 0.3rem; }

.chips, .found { display: inline-flex; gap: 0.3rem; flex-wrap: wrap; align-items: center; }
.chip { display: inline-block; font-size: 0.78rem; padding: 0.08rem 0.45rem; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--rule); color: var(--text); white-space: nowrap; }
.chip-local { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }

/* Multi-select node chips get a checkbox mark. */
.node-check { width: 0.95rem; height: 0.95rem; border: 1.5px solid var(--muted); border-radius: 3px; flex: none; position: relative; }
.node-check.on { background: var(--accent); border-color: var(--accent); }
.node-check.on::after { content: ''; position: absolute; left: 0.27rem; top: 0.06rem; width: 0.25rem; height: 0.5rem; border: solid var(--accent-ink); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.node-company { margin: 0; font-weight: 700; font-size: 0.9rem; }

.detail-nodes { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.6rem; }
.detail-nodes .field-label { color: var(--film-muted); }
.detail-nodes .seg button { background: var(--film-panel); color: var(--film-text); border-color: var(--film-rule); }
.detail-nodes .seg button.on { background: var(--accent); color: var(--accent-ink); }
.row td.actions .btn { padding: 0.25rem 0.75rem; }

/* Rail: badge, mode toggle */
.rail a { display: flex; align-items: center; gap: 0.5rem; }
.nav-badge { margin-left: auto; background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: 0.75rem; font-weight: 700; min-width: 1.3rem; text-align: center; padding: 0 0.35rem; line-height: 1.3rem; }
.rail-user { display: flex; align-items: center; gap: 0.25rem; }
.rail-user > a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mode-toggle { padding: 0.35rem 0.5rem; }
.mode-icon { display: block; width: 1rem; height: 1rem; border-radius: 50%; }
/* moon: a crescent; sun: a filled disc with a ring */
.mode-icon-dark { box-shadow: inset -0.3rem -0.15rem 0 0 currentColor; transform: rotate(-20deg); }
.mode-icon-light { background: currentColor; box-shadow: 0 0 0 2px var(--panel), 0 0 0 3.5px currentColor; transform: scale(0.65); }

/* Update notification */
.update-banner { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius-m); padding: 0.6rem 0.9rem; margin: -0.5rem 0 1.25rem; max-width: 82rem; }
.update-banner > span:nth-child(2) { flex: 1; min-width: 12rem; }
.update-banner .btn-primary, .update-banner .btn { text-decoration: none; }
.update-dot { width: 0.65rem; height: 0.65rem; border-radius: 50%; background: var(--accent); flex: none; display: inline-block; }
.update-dot-busy { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
a.btn-primary, a.btn, a.btn-ghost { display: inline-block; text-decoration: none; }
a.btn-primary { color: var(--accent-ink); }
a.btn { color: var(--text); }

.notice-box { border: 1px solid var(--rule); background: var(--panel); border-radius: var(--radius-m); padding: 0.8rem 1rem; margin: 1rem 0; max-width: 60rem; }
.notice-box.warn { border-color: var(--bad); }
.update-status { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 0.9rem 1.1rem; margin: 1rem 0; max-width: 60rem; }
.update-status.update-failed, .update-status.update-rolled_back { border-color: var(--bad); }
.update-status.update-succeeded { border-color: var(--ok); }
.update-status-head { display: flex; align-items: center; gap: 0.55rem; }
.update-step { margin: 0.4rem 0; }
.update-log { margin-top: 0.5rem; max-height: 22rem; white-space: pre-wrap; }
.update-list { display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; max-width: 60rem; }
.update-card { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: 0.6rem; }
.update-card header { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.update-notes { white-space: pre-wrap; line-height: 1.5; }
.update-card footer { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

/* Account: appearance */
.account-block { margin-top: 1.75rem; }
.account-block h2 { margin-bottom: 0.35rem; }
.mode-seg { margin: 0.5rem 0 1rem; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr)); gap: 0.75rem; max-width: 64rem; }
.theme-card { display: flex; flex-direction: column; gap: 0.35rem; text-align: left; background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 0.7rem; }
.theme-card:hover { border-color: var(--muted); }
.theme-card.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.theme-swatch { display: grid; grid-template-columns: 1fr 3fr; gap: 4px; height: 4.2rem; border-radius: var(--radius-s); padding: 5px; border: 1px solid rgba(127, 127, 127, 0.25); }
.theme-swatch-rail { border-radius: 2px; }
.theme-swatch-panel { border-radius: 2px; display: flex; align-items: flex-end; padding: 6px; }
.theme-swatch-panel > span { width: 45%; height: 0.55rem; border-radius: 2px; }
.theme-name { font-weight: 700; }
.theme-blurb { color: var(--muted); font-size: 0.85rem; }

/* Opening a study (its own tab) */
.opening { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.opening-card { width: min(30rem, 100%); background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 1.4rem 1.5rem; display: flex; flex-direction: column; gap: 0.75rem; }
.opening-card .brand { padding: 0; }
.opening-study { margin: 0; }
.opening-step { margin: 0; }

/* ------------------------------------------------------------------ 1.2.0: monitors */
.monitor-map { position: relative; width: 100%; max-width: 46rem; max-height: 22rem; min-height: 9rem; margin: 0.9rem 0; background: var(--panel-2); border: 1px solid var(--rule); border-radius: var(--radius-m); box-sizing: border-box; }
.monitor { position: absolute; box-sizing: border-box; border: 3px solid var(--panel); background: var(--film-panel); color: var(--film-text); border-radius: 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem; padding: 0.2rem; overflow: hidden; }
.monitor:hover { background: var(--film-rule); }
.monitor.on { outline: 3px solid var(--accent); outline-offset: -3px; }
.monitor-num { font-size: 1.7rem; font-weight: 700; line-height: 1; }
.monitor-role { font-size: 0.78rem; color: var(--film-muted); text-align: center; }
.monitor-worklist .monitor-role, .monitor-viewer .monitor-role { color: var(--film-text); font-weight: 700; }
.monitor-viewer { background: #05080d; }
.monitor-none { opacity: 0.55; }
.monitor-inspector { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem 1.4rem; margin-bottom: 0.6rem; }
.monitor-inspector h3 { margin: 0; font-size: 1rem; }
.monitor-inspector p { margin: 0.15rem 0 0; }
.monitor-inspector .field { min-width: 14rem; }
.monitor-blank { min-height: 100vh; background: #000; color: #7d838c; display: grid; place-items: center; text-align: center; font-size: 0.95rem; }
.monitor-blank .strong { color: #b9bec6; }
.opening-card .brand .badge { margin-left: auto; }

.hp-monitors { display: flex; flex-wrap: wrap; align-items: stretch; gap: 0.5rem; }
.hp-mon { display: flex; align-items: center; gap: 0.55rem; padding: 0.45rem 0.75rem; border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--panel-2); text-align: left; }
.hp-mon.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.hp-mon > span { display: flex; flex-direction: column; font-weight: 700; }
.hp-mon-study { font-weight: 400; font-size: 0.8rem; color: var(--muted); }
.hp-mon-add { align-self: center; }
.hp-mon-field { min-width: 15rem; }
.hp-mon-field select { background: var(--film-panel); color: var(--film-text); border-color: var(--film-rule); }
.hp-mon-note { margin: 0 0 0.6rem; font-size: 0.85rem; color: var(--film-muted); }
.hp-mon-actions { margin: 0 0 0.6rem; }
.lightbox[style*="aspect-ratio"] { min-height: 0; }
.lightbox-empty { display: grid; place-items: center; border: 1px dashed var(--film-rule); border-radius: 3px; min-height: 12rem; }
.template-mons { display: flex; gap: 0.35rem; }
.check-list { display: flex; flex-direction: column; gap: 0.45rem; align-items: flex-start; }
.hp-mon .mini span { background: var(--accent); opacity: 0.6; }
.th-sort { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 0.3rem; text-transform: inherit; letter-spacing: inherit; }
.th-sort:hover { color: var(--text); }
.th-sort.on { color: var(--accent); }
.th-arrow { font-size: 0.7em; opacity: 0.45; }
.th-sort.on .th-arrow { opacity: 1; }
th.num .th-sort { flex-direction: row-reverse; }

/* 1.3.0: passkeys and HTTPS */
.note { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 0.55rem 0.8rem; border-radius: 3px; max-width: 70ch; }
.note.bad { border-left-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.note.ok { border-left-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.75rem; }
.inline-form input { flex: 1 1 14rem; max-width: 22rem; }
.login-or { display: flex; align-items: center; gap: 0.6rem; color: var(--muted); font-size: 0.85rem; }
.login-or::before, .login-or::after { content: ''; flex: 1; border-top: 1px solid var(--rule); }
.login-hint { color: var(--muted); font-size: 0.85rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1.25rem; margin: 0.75rem 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.tls-log { background: var(--panel-2); border: 1px solid var(--rule); border-radius: 4px; padding: 0.6rem 0.8rem; max-height: 16rem; overflow: auto; font-size: 0.8rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.host-list { display: flex; flex-direction: column; gap: 0.4rem; max-width: 26rem; }
.host-list .host-row { display: flex; gap: 0.4rem; }
.host-list .host-row input { flex: 1; min-width: 0; }

/* 1.4.0: security, audit, idle sign-out */
.nav-badge-alert { background: var(--bad); color: #fff; }
.inline-badge { display: inline-block; margin-left: 0.6rem; vertical-align: middle; font-size: 0.75rem; }
.rail-note { font-size: 0.78rem; line-height: 1.35; }
.idle-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; z-index: 1000; padding: 1rem; }
.idle-card { background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 1.25rem 1.5rem; max-width: 26rem; display: flex; flex-direction: column; gap: 0.8rem; }
.idle-card h2 { margin: 0; }
.enroll-card { width: min(34rem, 100%); }
.enroll-title { font-size: 1.3rem; margin: 0; }
.plain-list { list-style: none; padding: 0; margin: 0.25rem 0; display: flex; flex-direction: column; gap: 0.35rem; }
.audit-filters { margin: 1rem 0; align-items: end; }
.audit-table td { vertical-align: top; }
.audit-table .uid { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.small { font-size: 0.8rem; }
.nowrap { white-space: nowrap; }
.bad-row td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.outcome-badge { margin-left: 0.4rem; font-size: 0.72rem; padding: 0 0.35rem; border-radius: 3px; background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.muted-row td { color: var(--muted); }
.strong-row td { font-weight: 600; }
textarea { font: inherit; }
.users-table .actions { white-space: normal; width: 1%; min-width: 16rem; }
.users-table .actions > * { margin: 0.1rem 0 0.1rem 0.25rem; }
