/* ============================================================================
   APP STYLES — Peptide Tracker
   Dense, keyboard-friendly, instrument-panel UI. Numerals are monospaced and
   tabular everywhere a value is read, so columns line up and digits don't jump.
   ========================================================================== */

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}

h1, h2, h3, h4, p, figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

::selection { background: var(--accent-wash); color: var(--ink); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: var(--bg-sunken); }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; border: 2px solid var(--bg-sunken); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-xs); }

/* ---------------------------------------------------------------- typography */

.micro {
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: var(--track-micro);
  text-transform: uppercase;
  color: var(--muted);
}

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.num-lg { font-family: var(--mono); font-size: var(--fs-xl); font-weight: 500; letter-spacing: -0.03em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.dim { color: var(--ink-2); }
.tiny { font-size: var(--fs-xs); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.mono-prose { font-family: var(--mono); font-size: var(--fs-sm); line-height: 1.7; }

/* ------------------------------------------------------------------- layout */

.app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.rail {
  background: var(--bg-sunken);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.brand-mark { flex: none; display: block; }
.brand-text { min-width: 0; }
.brand-name { font-size: var(--fs-sm); font-weight: 600; letter-spacing: var(--track-tight); }
.brand-sub { font-size: var(--fs-micro); letter-spacing: var(--track-micro); text-transform: uppercase; color: var(--faint); }

.nav { padding: var(--sp-3) var(--sp-2); display: flex; flex-direction: column; gap: 1px; overflow-y: auto; flex: 1; min-height: 0; }
.nav-group-label {
  font-size: var(--fs-micro); letter-spacing: var(--track-micro); text-transform: uppercase;
  color: var(--faint); padding: var(--sp-4) var(--sp-2) var(--sp-1);
}
.nav-group-label:first-child { padding-top: var(--sp-1); }

.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 7px var(--sp-2);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: var(--fs-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--t-fast), color var(--t-fast);
  text-align: left;
  background: none;
  width: 100%;
}
.nav-item:hover { background: var(--surface); color: var(--ink); text-decoration: none; }
.nav-item[aria-current="page"] {
  background: var(--accent-wash);
  color: var(--ink);
  border-color: var(--accent-dim);
  font-weight: 500;
}
.nav-item svg { flex: none; opacity: 0.85; }
.nav-count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: var(--fs-xs);
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--ink-2);
}
.nav-item[aria-current="page"] .nav-count { background: var(--accent-dim); color: var(--ink); }

.rail-foot { border-top: 1px solid var(--border); padding: var(--sp-3); }
.user-chip { display: flex; align-items: center; gap: var(--sp-3); }
.avatar {
  width: 30px; height: 30px; flex: none;
  border-radius: var(--r-sm);
  background: var(--accent-wash);
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  display: grid; place-items: center;
  font-family: var(--mono); font-size: var(--fs-sm); font-weight: 500;
}

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-6);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.topbar h1 { font-size: var(--fs-lg); font-weight: 600; letter-spacing: var(--track-tight); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }

.view { overflow-y: auto; padding: var(--sp-6); flex: 1; min-height: 0; }
.view-inner { max-width: 1480px; }

/* Status strip under the title: the at-a-glance state of the day. */
.status-strip { display: flex; align-items: center; gap: var(--sp-5); flex-wrap: wrap; }
.status-cell { display: flex; flex-direction: column; gap: 2px; min-width: 54px; }
.status-cell .v { font-family: var(--mono); font-size: var(--fs-md); font-weight: 500; line-height: 1.15; }
.status-cell .k { font-size: var(--fs-micro); letter-spacing: var(--track-micro); text-transform: uppercase; color: var(--faint); }
.status-cell.is-due .v { color: var(--accent); }
.status-cell.is-overdue .v { color: var(--danger); }
.status-cell.is-taken .v { color: var(--ok); }

.strip-divider { width: 1px; height: 26px; background: var(--border); }

/* ------------------------------------------------------------------- panels */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
  min-height: 42px;
}
.panel-head h2, .panel-head h3 { font-size: var(--fs-sm); font-weight: 600; letter-spacing: var(--track-tight); }
.panel-head .spacer { margin-left: auto; }
.panel-body { padding: var(--sp-4); }
.panel-body.flush { padding: 0; }
.panel-foot { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); background: var(--bg-sunken); }

.grid { display: grid; gap: var(--sp-5); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-monitor { grid-template-columns: minmax(0, 1.62fr) minmax(0, 1fr); align-items: start; }
.grid-calc { grid-template-columns: minmax(320px, 0.9fr) minmax(0, 1.1fr); align-items: start; }
.grid-explore { grid-template-columns: minmax(0, 300px) minmax(0, 1fr); align-items: start; }
.stack { display: grid; gap: var(--sp-5); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); }
.spacer { margin-left: auto; }
/* Flex children default to min-width:auto, so one long label can push a whole
   row past its panel and clip its siblings. Everything in a flex row may shrink. */
.row > *, .row-wrap > * { min-width: 0; }
/* A ring must never be the reason a panel overflows. */
.ring-center { display: flex; justify-content: center; }

/* --------------------------------------------------------------- key/value */

.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-4); align-items: baseline; }
.kv dt { font-size: var(--fs-micro); letter-spacing: var(--track-micro); text-transform: uppercase; color: var(--faint); }
.kv dd { margin: 0; font-family: var(--mono); font-size: var(--fs-sm); }

.spec-list { display: flex; flex-direction: column; }
.spec-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
}
.spec-row:last-child { border-bottom: 0; }
.spec-row .k { font-size: var(--fs-xs); color: var(--muted); }
.spec-row .v { font-family: var(--mono); font-size: var(--fs-sm); }

/* Researched prose contains long unbreakable tokens (URLs, formula expressions,
   CIDR-ish identifiers). Without this a single token widens its panel and clips
   everything beside it. */
.prose, .mono-prose, .sub-block, .sub-point, .panel-body, .disclaimer, .source-title, .readout-caption {
  overflow-wrap: anywhere;
}

/* -------------------------------------------------------------------- readout */

.readout {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}
.readout-primary { display: flex; align-items: baseline; gap: var(--sp-3); flex-wrap: wrap; }
.readout-value {
  font-family: var(--mono);
  font-size: var(--fs-3xl);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1;
  color: var(--accent);
}
.readout-unit { font-family: var(--mono); font-size: var(--fs-md); color: var(--muted); }
.readout-caption { font-size: var(--fs-xs); color: var(--muted); margin-top: var(--sp-2); }

.readout-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
.readout-cell { background: var(--surface); padding: var(--sp-3); }
.readout-cell .k { font-size: var(--fs-micro); letter-spacing: var(--track-micro); text-transform: uppercase; color: var(--faint); display: block; margin-bottom: 3px; }
.readout-cell .v { font-family: var(--mono); font-size: var(--fs-md); font-weight: 500; }
.readout-cell .u { font-family: var(--mono); font-size: var(--fs-xs); color: var(--muted); margin-left: 3px; }

/* ------------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 34px; padding: 0 var(--sp-4);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(0.5px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }

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

.btn-sm { min-height: 27px; padding: 0 var(--sp-3); font-size: var(--fs-xs); }
.btn-lg { min-height: 42px; padding: 0 var(--sp-6); font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn-icon { min-height: 30px; width: 30px; padding: 0; }

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

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label {
  font-size: var(--fs-micro); font-weight: 600;
  letter-spacing: var(--track-micro); text-transform: uppercase;
  color: var(--muted);
}
.field .hint { font-size: var(--fs-xs); color: var(--faint); }
.field .err { font-size: var(--fs-xs); color: var(--danger); }

.input, .select, .textarea {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--ink);
  font-size: var(--fs-sm);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input.num, .input[type="number"], .input[type="date"], .input[type="time"], .input[type="datetime-local"] {
  font-family: var(--mono);
  letter-spacing: -0.01em;
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.6; font-family: var(--sans); }
.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
  cursor: pointer;
}
.input-group { display: flex; gap: var(--sp-2); align-items: stretch; }
.input-group .input { flex: 1; }
.input-suffix {
  display: flex; align-items: center; padding: 0 10px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  font-family: var(--mono); font-size: var(--fs-xs); color: var(--muted); white-space: nowrap;
}

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: var(--sp-4); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }

.check { display: flex; align-items: flex-start; gap: var(--sp-2); font-size: var(--fs-sm); cursor: pointer; }
.check input { margin: 3px 0 0; accent-color: var(--accent); width: 15px; height: 15px; flex: none; }

/* Segmented control: mode switches (forward / reverse, unit pickers). */
.segmented { display: inline-flex; background: var(--bg-sunken); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted);
  padding: 5px var(--sp-3); border-radius: var(--r-xs); cursor: pointer;
  font-size: var(--fs-xs); font-weight: 500; letter-spacing: 0.01em;
  transition: background var(--t-fast), color var(--t-fast);
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent); font-weight: 600; }

/* Chip toggles for multi-select (sites, side effects, weekdays). */
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  padding: 4px 9px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: var(--fs-xs);
  color: var(--ink-2);
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  white-space: nowrap;
}
.chip:hover { border-color: var(--faint); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--accent-wash); border-color: var(--accent-dim); color: var(--accent); font-weight: 500; }
.chip.is-static { cursor: default; }
.chip.is-static:hover { border-color: var(--border-strong); }

/* --------------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 7px;
  border-radius: var(--r-xs);
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--ink-2);
  /* Not nowrap. A long badge ("Retatrutide + GHK-Cu (metabolic + cosmetic
     co-protocol)") shrank inside its flex row while its text could not, so the
     panel's rounded-corner overflow:hidden cut the label off — invisibly, which
     is why a scroll-based overflow check missed it. Wrap and break instead:
     a taller badge beats missing words. */
  white-space: normal;
  max-width: 100%;
  overflow-wrap: anywhere;
  flex-wrap: wrap;
  text-align: left;
}
.badge-ok      { border-color: var(--ok);     color: var(--ok);     background: var(--ok-wash); }
.badge-warn    { border-color: var(--warn);   color: var(--warn);   background: var(--warn-wash); }
.badge-danger  { border-color: var(--danger); color: var(--danger); background: var(--danger-wash); }
.badge-accent  { border-color: var(--accent-dim); color: var(--accent); background: var(--accent-wash); }
.badge-info    { border-color: var(--info);   color: var(--info);   background: var(--info-wash); }

.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--faint); }
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-danger { background: var(--danger); }
.dot-accent { background: var(--accent); }

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

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.data th {
  text-align: left;
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: var(--track-micro);
  text-transform: uppercase;
  color: var(--faint);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border-strong);
  background: var(--bg-sunken);
  position: sticky; top: 0; z-index: 1;
  white-space: nowrap;
}
table.data td { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { font-family: var(--mono); text-align: right; }
table.data td.tight { width: 1%; white-space: nowrap; }
table.data caption { text-align: left; padding: var(--sp-2) var(--sp-3); font-size: var(--fs-xs); color: var(--muted); }

/* ---------------------------------------------------------------- progress */

.meter { height: 5px; background: var(--bg-sunken); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.meter > i { display: block; height: 100%; background: var(--accent); transition: width var(--t-base); }
.meter.is-ok > i { background: var(--ok); }
.meter.is-warn > i { background: var(--warn); }
.meter.is-danger > i { background: var(--danger); }
.meter-label { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--muted); margin-bottom: 5px; }

/* -------------------------------------------------------------------- syringe */

.syringe { width: 100%; height: auto; display: block; }
.syringe .sg-barrel { fill: var(--bg-sunken); stroke: var(--border-strong); }
.syringe .sg-liquid { fill: var(--accent-wash); }
.syringe .sg-plunger { fill: var(--surface-3); stroke: var(--border-strong); }
.syringe .sg-grad { stroke: var(--border-strong); }
.syringe .sg-grad-major { stroke: var(--faint); }
.syringe .sg-tick-label { fill: var(--faint); font-family: var(--mono); font-size: 7.5px; }
.syringe .sg-target { stroke: var(--accent); stroke-width: 1.6; }
.syringe .sg-target-label { fill: var(--accent); font-family: var(--mono); font-size: 10px; font-weight: 500; }
.syringe .sg-needle { stroke: var(--border-strong); stroke-width: 2.5; }
.syringe .sg-hub { fill: var(--surface-2); stroke: var(--border-strong); }

/* --------------------------------------------------------------------- charts */

.chart { width: 100%; display: block; overflow: visible; }
.chart .axis-line { stroke: var(--border); stroke-width: 1; }
.chart .grid-line { stroke: var(--border); stroke-width: 0.5; stroke-dasharray: 2 4; opacity: 0.6; }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-2 { fill: none; stroke: var(--faint); stroke-width: 1.25; stroke-dasharray: 3 3; }
.chart .area { fill: var(--accent-wash); opacity: 0.35; }
.chart .point { fill: var(--bg); stroke: var(--accent); stroke-width: 1.5; }
.chart .axis-label { fill: var(--faint); font-family: var(--mono); font-size: 9.5px; }
.chart .bar { fill: var(--accent-dim); }
.chart .bar.is-peak { fill: var(--accent); }
.chart .bar-label { fill: var(--faint); font-family: var(--mono); font-size: 9px; }
.chart-empty { padding: var(--sp-8); text-align: center; color: var(--faint); font-size: var(--fs-sm); }

.legend { display: flex; gap: var(--sp-4); flex-wrap: wrap; font-size: var(--fs-xs); color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 2px; vertical-align: middle; margin-right: 5px; background: var(--accent); }
.legend .alt i { background: var(--faint); }

/* --------------------------------------------------------------------- empty */

.empty { padding: var(--sp-8) var(--sp-5); text-align: center; }
.empty h3 { font-size: var(--fs-md); font-weight: 600; margin-bottom: var(--sp-2); }
.empty p { color: var(--muted); font-size: var(--fs-sm); max-width: 46ch; margin: 0 auto var(--sp-4); }

/* --------------------------------------------------------------------- modal */

.modal-scrim {
  position: fixed; inset: 0;
  background: oklch(8% 0 0 / 0.66);
  display: grid; place-items: center;
  padding: var(--sp-5);
  z-index: 100;
  animation: fade var(--t-base) ease-out;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-modal);
  width: min(680px, 100%);
  max-height: 90vh;
  display: flex; flex-direction: column;
  animation: rise var(--t-base) cubic-bezier(0.32, 0.72, 0, 1);
}
.modal.modal-wide { width: min(900px, 100%); }
.modal-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: var(--fs-md); font-weight: 600; }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-foot { display: flex; gap: var(--sp-3); justify-content: flex-end; padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); background: var(--bg-sunken); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(0.995); } }

/* -------------------------------------------------------------------- toasts */

.toasts { position: fixed; bottom: var(--sp-5); right: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); z-index: 200; max-width: 380px; }
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-left-width: 3px;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-sm);
  animation: rise var(--t-base) cubic-bezier(0.32, 0.72, 0, 1);
}
.toast.is-ok { border-left-color: var(--ok); }
.toast.is-err { border-left-color: var(--danger); }
.toast.is-info { border-left-color: var(--accent); }
.toast .t-title { font-weight: 600; }

/* --------------------------------------------------------------- login screen */

.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-5); background: var(--bg); }
.gate-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-8);
}
.gate-brand { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-6); }
.gate h1 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: var(--track-tight); margin-bottom: var(--sp-2); }
.gate .sub { color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--sp-6); }
.gate form { display: grid; gap: var(--sp-4); }
.gate-foot { margin-top: var(--sp-6); padding-top: var(--sp-4); border-top: 1px solid var(--border); font-size: var(--fs-xs); color: var(--faint); }
.qr-box { background: #fff; padding: var(--sp-3); border-radius: var(--r-sm); display: grid; place-items: center; }
.qr-box img { display: block; width: 200px; height: 200px; }
.code-input {
  font-family: var(--mono); font-size: var(--fs-xl); letter-spacing: 0.32em;
  text-align: center; padding: var(--sp-3);
}
.recovery-codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-2); font-family: var(--mono); font-size: var(--fs-sm); }

/* ------------------------------------------------------------------- callouts */

.callout {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: var(--fs-sm);
  line-height: 1.6;
}
.callout .micro { display: block; margin-bottom: 3px; }
.callout.is-warn { border-color: var(--warn); background: var(--warn-wash); }
.callout.is-danger { border-color: var(--danger); background: var(--danger-wash); }
.callout.is-info { border-color: var(--info); background: var(--info-wash); }
.callout.is-ok { border-color: var(--ok); background: var(--ok-wash); }

/* Ordered procedure steps (the handbook and recon walkthrough). */
.steps { counter-reset: step; display: grid; gap: var(--sp-1); }
.steps li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3) var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
  list-style: none;
  font-size: var(--fs-sm);
  line-height: 1.65;
}
.steps li:last-child { border-bottom: 0; }
.steps li::before {
  content: counter(step, decimal-leading-zero);
  font-family: var(--mono);
  font-size: var(--fs-xs);
  color: var(--accent);
  padding-top: 3px;
  text-align: right;
}
.steps li strong { font-weight: 600; }

/* ------------------------------------------------------------------- citation */

.cite { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--info); }
.cite:hover { text-decoration: underline; }
.sources { display: grid; gap: 5px; margin-top: var(--sp-3); }
.source-item { font-size: var(--fs-xs); color: var(--muted); line-height: 1.5; }
.source-item .yr { font-family: var(--mono); color: var(--faint); margin-right: 5px; }

/* ---------------------------------------------------------------- misc utils */

.divider { height: 1px; background: var(--border); border: 0; margin: var(--sp-5) 0; }
.pad { padding: var(--sp-4); }
.pad-lg { padding: var(--sp-6); }
.mt-1 { margin-top: var(--sp-2); } .mt-2 { margin-top: var(--sp-3); } .mt-3 { margin-top: var(--sp-4); } .mt-4 { margin-top: var(--sp-5); }
.mb-1 { margin-bottom: var(--sp-2); } .mb-2 { margin-bottom: var(--sp-3); } .mb-3 { margin-bottom: var(--sp-4); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.disclaimer {
  font-size: var(--fs-xs);
  color: var(--muted);
  line-height: 1.6;
  border-top: 1px solid var(--border);
  padding-top: var(--sp-3);
}

.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sweep 1.4s linear infinite; border-radius: var(--r-sm); }
@keyframes sweep { to { background-position: -200% 0; } }

.spinner { width: 13px; height: 13px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.list-plain { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--sp-2); }
.list-plain li { font-size: var(--fs-sm); line-height: 1.6; }

/* Dose row: the unit of work on the Today surface. */
.dose-row {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.dose-row:last-child { border-bottom: 0; }
.dose-row:hover { background: var(--surface-2); }
.dose-time { font-family: var(--mono); font-size: var(--fs-sm); color: var(--ink-2); }
.dose-name { font-weight: 500; font-size: var(--fs-sm); }
.dose-meta { font-size: var(--fs-xs); color: var(--muted); font-family: var(--mono); }
.dose-row.is-taken { opacity: 0.62; }
.dose-row.is-overdue { background: var(--danger-wash); }

/* ------------------------------------------------------------------ responsive */

@media (max-width: 1180px) {
  .grid-monitor, .grid-calc, .grid-explore { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: var(--rail-w-compact); }
  .brand-text, .nav-item span.label, .nav-group-label, .user-chip .who { display: none; }
  .nav-item { justify-content: center; padding: 9px 0; }
  .nav-count { position: absolute; top: 3px; right: 3px; font-size: 9px; padding: 0 4px; }
  .nav-item { position: relative; }
  .rail-foot { display: flex; justify-content: center; }
  .view { padding: var(--sp-4); }
  .topbar { padding: 0 var(--sp-4); }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .dose-row { grid-template-columns: 54px minmax(0, 1fr); row-gap: var(--sp-2); }
  .dose-row .dose-actions { grid-column: 2; }
  .toasts { left: var(--sp-4); right: var(--sp-4); bottom: var(--sp-4); max-width: none; }
  .form-grid .span-2 { grid-column: span 1; }
  .recovery-codes { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .hide-sm { display: none !important; }
  .gate-card { padding: var(--sp-5); }
  .readout-value { font-size: var(--fs-2xl); }
}

@media print {
  .rail, .topbar-actions, .toasts, .btn { display: none !important; }
  body { overflow: visible; background: #fff; color: #000; }
  .view { overflow: visible; }
  .panel { break-inside: avoid; border-color: #ccc; }
}

/* ============================================================================
   COLLAPSIBLE SECTIONS
   The main density tool: anything that is reference rather than action folds
   into one of these. Native <details>, so it needs no JS and stays searchable.
   ========================================================================== */
.disc {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}
.disc-summary {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  min-height: 44px;
  cursor: pointer;
  list-style: none;
  transition: background var(--t-fast);
}
.disc-summary::-webkit-details-marker { display: none; }
.disc-summary::before {
  content: '';
  flex: none;
  width: 0; height: 0;
  border-left: 5px solid var(--faint);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform var(--t-fast);
}
.disc[open] > .disc-summary::before { transform: rotate(90deg); }
.disc-summary:hover { background: var(--surface-2); }
.disc-summary:focus-visible { outline: none; box-shadow: var(--focus); }
.disc-title { font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); }
.disc-meta, .disc-summary .nav-count { margin-left: auto; }
.disc-body { padding: 0 var(--sp-4) var(--sp-4); }
.disc[open] { background: var(--surface); }

/* ============================================================================
   STEPPER — the guided reconstitution flow
   ========================================================================== */
.stepper {
  display: flex;
  gap: var(--sp-1);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.stepper::-webkit-scrollbar { display: none; }
.step {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex: none;
  white-space: nowrap;
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3);
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.step:hover:not(:disabled) { background: var(--surface-2); color: var(--ink-2); }
.step:disabled { opacity: 0.45; cursor: default; }
.step-dot {
  flex: none;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  font-family: var(--mono);
  font-size: var(--fs-xs);
}
.step.is-current { background: var(--surface-2); color: var(--ink); }
.step.is-current .step-dot { border-color: var(--accent); color: var(--accent); }
.step.is-done { color: var(--ink-2); }
.step.is-done .step-dot { border-color: var(--ok); color: var(--ok); }

/* ============================================================================
   PICK CARDS — compound and protocol choices
   ========================================================================== */
.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: var(--sp-3);
}
.pick {
  display: block;
  width: 100%;
  min-height: 44px;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.pick:hover { border-color: var(--border-strong); background: var(--surface-2); }
.pick:focus-visible { outline: none; box-shadow: var(--focus); }
.pick.is-featured { border-color: var(--accent-dim); }
.pick-name { font-size: var(--fs-md); font-weight: 500; }
.pick-wide { cursor: default; padding: var(--sp-4); }
.pick-wide:hover { background: var(--surface); border-color: var(--border); }

/* ============================================================================
   STAT LINE + VIAL LINES — the numbers on Today, without charts
   ========================================================================== */
.stat-line { display: flex; flex-wrap: wrap; gap: var(--sp-6); }
.stat { min-width: 0; }
.stat-v {
  font-family: var(--mono);
  font-size: var(--fs-xl);
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.03em;
  line-height: var(--lh-tight);
}
.stat-k {
  margin-top: 2px;
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  color: var(--muted);
}
.stat-sub { font-size: var(--fs-xs); color: var(--faint); }

.vial-lines { display: grid; gap: var(--sp-3); }
.vial-line {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-4);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}
.vial-line:first-child { border-top: 0; padding-top: 0; }
.vial-line-main { flex: 1; min-width: 0; }
.vial-line-name {
  font-size: var(--fs-sm);
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vial-line-actions { flex: none; }

/* Steps inside the guided flow: same counter list as the handbook, tighter. */
.step-title { font-size: var(--fs-sm); font-weight: 500; color: var(--ink); margin-bottom: 2px; }
.steps .prose { font-size: var(--fs-sm); color: var(--ink-2); margin: 0; }

/* ============================================================================
   RESPONSIVE
   ----------------------------------------------------------------------------
   Below 900px the rail becomes an off-canvas drawer rather than a 62px strip of
   unlabelled icons: on a phone there is width to spare as an overlay, and
   icon-only navigation costs comprehension for no real gain. Above it, the rail
   is a static column and the toggle is hidden.
   ========================================================================== */
.rail-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px; height: 40px;
  margin-left: calc(-1 * var(--sp-2));
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  cursor: pointer;
}
.rail-toggle:hover { background: var(--surface-2); color: var(--ink); }
.rail-backdrop { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  .rail {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: min(84vw, 300px);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform var(--t-base);
    box-shadow: var(--shadow-modal);
    overscroll-behavior: contain;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .rail.is-open { transform: none; }

  .rail-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: oklch(0% 0 0 / 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-base);
  }
  .rail-backdrop.is-open { opacity: 1; pointer-events: auto; }

  /* Undo the icon-only strip: the drawer has room for labels again. */
  .brand-text,
  .nav-group-label,
  .nav-item span.label,
  .user-chip .who { display: revert; }
  .nav-item { justify-content: flex-start; padding: 11px var(--sp-3); min-height: 44px; }
  .nav-count { position: static; margin-left: auto; }
  .rail-foot { display: flex; justify-content: flex-start; }

  .rail-toggle { display: inline-flex; }
  body.rail-open .view { overflow: hidden; }

  /* Layout: one column, and let the content breathe into the edges. */
  .grid-monitor, .grid-calc, .grid-explore, .grid-2, .grid-3,
  .form-grid, .recovery-codes { grid-template-columns: minmax(0, 1fr); }
  .view { padding: var(--sp-4) var(--sp-4) calc(var(--sp-6) + env(safe-area-inset-bottom)); }
  .topbar { padding: 0 var(--sp-3); gap: var(--sp-2); }
  .panel-head { padding: var(--sp-3) var(--sp-4); }
  .panel-body { padding: var(--sp-4); }
  .panel-body.flush { padding: 0; }
  .modal-scrim { padding: var(--sp-3); }
  .modal { max-height: 88dvh; }
  .toasts { left: var(--sp-3); right: var(--sp-3); bottom: calc(var(--sp-3) + env(safe-area-inset-bottom)); max-width: none; }
  .table-wrap { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  .stepper { margin: 0 calc(-1 * var(--sp-4)); padding: 0 var(--sp-4); }
  .stack { gap: var(--sp-4); }
  .pick-grid { grid-template-columns: minmax(0, 1fr); }
  .stat-line { gap: var(--sp-5) var(--sp-6); }
  .vial-line { flex-direction: column; gap: var(--sp-2); }
  .vial-line-actions { width: 100%; }
  .vial-line-actions .btn { width: 100%; }
  .steps li { grid-template-columns: 22px minmax(0, 1fr); gap: var(--sp-2); }
}

@media (max-width: 640px) {
  .hide-sm { display: none !important; }
  .disc-meta { display: none; }
  .stat-v { font-size: var(--fs-lg); }
  .panel-head h2 { font-size: var(--fs-md); }
  .topbar h1 { font-size: var(--fs-md); }
  .readout-value { font-size: var(--fs-2xl); }
  .dose-row { grid-template-columns: 48px minmax(0, 1fr); padding: var(--sp-3); }
  .gate-card { padding: var(--sp-5); }
}

/* Touch devices: 44px minimum targets, and 16px inputs so iOS does not zoom
   the whole page when a field takes focus. */
@media (pointer: coarse) {
  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }
  .chip { min-height: 32px; display: inline-flex; align-items: center; }
  input, select, textarea { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .rail, .rail-backdrop { transition: none; }
}

/* ============================================================================
   TEMPLATE ROWS — a list with one action each, not a grid of panels
   ========================================================================== */
.tmpl-list { display: grid; gap: var(--sp-2); }
.tmpl {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}
.tmpl-main { flex: 1; min-width: 0; }
.tmpl-name { font-size: var(--fs-md); font-weight: 500; min-width: 0; }
.tmpl-caution {
  margin-top: var(--sp-2);
  padding-left: var(--sp-3);
  border-left: 2px solid var(--warn);
  font-size: var(--fs-xs);
  color: var(--muted);
}
.tmpl-actions { flex: none; display: flex; gap: var(--sp-2); }

@media (max-width: 900px) {
  .tmpl { flex-direction: column; align-items: stretch; gap: var(--sp-2); }
  .tmpl-actions { width: 100%; }
  .tmpl-actions .btn { flex: 1; }
}
