/* ==========================================================================
   Peptide Tracker — css/app.css   (phone first; desktop is a centered column)
   ========================================================================== */
:root {
  --paper: #F3F5F2;
  --card: #FFFFFF;
  --ink: #15252B;
  --ink-2: #4F6068;
  --ink-3: #8A9AA0;
  --line: #D8E0DC;
  --line-2: #EAEFEC;
  --accent: #1E6E66;
  --accent-deep: #15524C;
  --accent-soft: #E2F0EC;
  --amber: #8F5F0C;
  --amber-soft: #FBF0D9;
  --amber-line: #E7C77B;
  --red: #B3261E;
  --red-soft: #FBE7E5;
  --red-line: #EBA6A1;
  --green: #256B45;
  --green-soft: #E1F2E7;
  --font-ui: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-num: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --radius: 14px;
  --radius-sm: 9px;
  --tap: 44px;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }   /* author display rules must never resurrect a hidden element */
.stack { display: grid; gap: 6px; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.45 var(--font-ui); min-height: 100dvh; -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body.has-sheet { overflow: hidden; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
h3 { font-size: 19px; }
p { margin: 0 0 10px; }
a { color: inherit; }
code { font-family: var(--font-num); font-size: 0.92em; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.amber { color: var(--amber); }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 500; }
.num--lg { font-size: 26px; }
.num--xl { font-size: 40px; font-weight: 600; line-height: 1; }
.unit { font-size: 12px; color: var(--ink-2); margin-left: 4px; text-transform: uppercase; letter-spacing: 0.06em; }
.formula { font-family: var(--font-num); font-size: 12px; color: var(--ink-2); margin-top: 4px; overflow-wrap: anywhere; }

/* ---------- layout ---------- */
.app { max-width: 640px; margin: 0 auto; padding-bottom: 80px; }
.main { padding: 14px 14px 24px; }
.top { position: sticky; top: 0; z-index: 20; background: rgba(243, 245, 242, 0.94); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top__row { display: flex; align-items: center; gap: 10px; padding: 8px 14px 4px; min-height: 52px; }
.top__title { flex: 1; min-width: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand { display: inline-flex; width: 30px; height: 30px; }
.back { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; font-size: 30px; line-height: 1; text-decoration: none; border-radius: 10px; margin-left: -8px; color: var(--ink); }
.nav { display: flex; gap: 4px; padding: 0 10px 8px; }
.nav a { flex: 1; text-align: center; padding: 8px 6px; border-radius: 10px; font-weight: 500; font-size: 14px; color: var(--ink-2); text-decoration: none; }
.nav a.is-on { background: var(--ink); color: #fff; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 18px 0 10px; }
.section-head:first-child { margin-top: 4px; }
.empty { color: var(--ink-2); padding: 18px 14px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; }

/* ---------- marks ---------- */
.mark { width: 30px; height: 30px; }
.mark--big { width: 56px; height: 56px; margin-bottom: 8px; }
.mk-barrel { fill: #fff; stroke: var(--ink); stroke-width: 2; }
.mk-fill { fill: var(--accent); }
.mk-flange { fill: var(--ink); }
.mk-needle { stroke: var(--ink); stroke-width: 2; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login__card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 26px 22px; }
.login__card h1 { font-size: 24px; margin-bottom: 4px; }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 500; font-size: 15px; min-height: var(--tap); padding: 8px 14px;
  border-radius: var(--radius-sm); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:not(:disabled):hover { background: var(--accent-deep); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn--sm { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.btn--xs { min-height: 30px; padding: 2px 10px; font-size: 13px; }
.btn--block { width: 100%; }
:focus-visible { outline: 3px solid rgba(30, 110, 102, 0.45); outline-offset: 2px; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.proto { border-left-width: 5px; }
.proto--ok { border-left-color: var(--accent); }
.proto--low { border-left-color: var(--amber-line); }
.proto--empty { border-left-color: var(--red); }
.proto--no_vial { border-left-color: var(--ink-3); border-left-style: dashed; }
.proto--paused, .proto--complete { opacity: 0.8; }
.proto__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.proto__meta { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.pill { font-size: 12px; font-weight: 500; padding: 3px 9px; border-radius: 999px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.pill--active { background: var(--accent-soft); color: var(--accent-deep); }
.pill--paused { background: var(--amber-soft); color: var(--amber); }
.pill--done { background: var(--green-soft); color: var(--green); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 7px; border-radius: 6px; background: var(--line-2); color: var(--ink-2); vertical-align: middle; }
.tag--amber { background: var(--amber-soft); color: var(--amber); }
.tag--red { background: var(--red-soft); color: var(--red); }
.tag--green { background: var(--green-soft); color: var(--green); }

/* the draw: dose -> units */
.draw { display: flex; align-items: baseline; gap: 12px; margin: 8px 0 2px; flex-wrap: wrap; }
.draw__to { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.draw.is-over .num--xl { color: var(--red); }

/* syringe gauge */
.syringe { width: 100%; height: auto; display: block; margin: 4px 0 2px; }
.sy-needle { stroke: var(--ink); stroke-width: 2; }
.sy-barrel { fill: #fff; stroke: var(--ink); stroke-width: 1.6; }
.sy-fill { fill: var(--accent-soft); }
.sy-fill.is-over { fill: var(--red-soft); }
.sy-minor { stroke: var(--ink-3); stroke-width: 1; }
.sy-major { stroke: var(--ink); stroke-width: 1.4; }
.sy-label { font-family: var(--font-num); font-size: 9px; fill: var(--ink-2); text-anchor: middle; }
.sy-mark { stroke: var(--accent); stroke-width: 2.5; }
.sy-marktext { font-family: var(--font-num); font-size: 11px; font-weight: 600; fill: var(--accent-deep); text-anchor: middle; }
.sy-marktext.is-over { fill: var(--red); }
.sy-flange { fill: var(--ink); }
.syringe.is-over .sy-barrel { stroke: var(--red); }

/* facts + vial */
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 10px; }
.fact { background: var(--paper); border-radius: var(--radius-sm); padding: 8px 10px; }
.fact__k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); }
.fact__v { font-weight: 500; font-size: 14px; }
.vialrow { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--paper); }
.vialrow--low { background: var(--amber-soft); }
.vialrow--empty { background: var(--red-soft); }
.vialrow__body { min-width: 0; flex: 1; }
.vialrow__line { font-size: 15px; }
.vial { width: 30px; height: 54px; flex: none; }
.vl-cap { fill: var(--ink); }
.vl-neck { fill: #fff; stroke: var(--ink); stroke-width: 1.4; }
.vl-body { fill: #fff; stroke: var(--ink); stroke-width: 1.6; }
.vl-liquid { fill: var(--accent); }
.vial--low .vl-liquid { fill: #D9A12E; }
.vial--empty .vl-liquid { fill: var(--red); }

.sites { margin: 12px 0 6px; font-size: 15px; }
.sites .arrow { color: var(--ink-3); padding: 0 4px; }
.strip { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; margin: 6px 0 10px; }
.strip__legend { margin-left: auto; font-size: 11px; color: var(--ink-3); display: inline-flex; align-items: center; gap: 4px; }
.strip__legend .dot { width: 8px; height: 8px; margin-right: 2px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; background: var(--accent); }
.dot--skipped { background: transparent; border: 2px solid var(--ink-3); }
.dot--err { background: var(--line); border: 2px solid var(--line); position: relative; }
.dot--err::after { content: ''; position: absolute; left: 50%; top: 50%; width: 10px; height: 2px; background: var(--red); transform: translate(-50%, -50%) rotate(45deg); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.actions .btn--primary { grid-column: 1 / -1; }
.novial { padding: 12px 0 6px; }
.novial__msg { font-size: 17px; font-weight: 500; }

.recon { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 13px; }
.recon--ok .recon__mark { color: var(--green); font-weight: 700; }
.recon--bad { color: var(--red); }
.recon--bad .recon__mark { font-weight: 700; }

.alert { border-radius: var(--radius-sm); padding: 10px 12px; margin: 10px 0; font-size: 14px; line-height: 1.4; }
.alert--red { background: var(--red-soft); border: 1px solid var(--red-line); color: var(--red); }
.alert--amber { background: var(--amber-soft); border: 1px solid var(--amber-line); color: var(--amber); }
.alert--loud { font-size: 15px; font-weight: 500; border-width: 2px; }
.alert.tt { margin: 10px 14px 0; }
.recon-banner b { font-weight: 700; }

.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 0 12px; }
.chart-head__site { font-size: 22px; font-weight: 600; }
.chart-foot { text-align: center; margin-top: 18px; }

/* ---------- today / lists ---------- */
.due-list { display: flex; flex-direction: column; gap: 8px; }
.due { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: var(--radius); padding: 10px 10px 10px 12px; }
.due--low { border-left-color: var(--amber-line); }
.due--empty { border-left-color: var(--red); }
.due--no_vial { border-left-color: var(--ink-3); border-left-style: dashed; }
.due__main { flex: 1; min-width: 0; text-decoration: none; }
.due__who { font-weight: 600; font-size: 17px; }
.due__what { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.due__what .peptide { color: var(--ink); font-weight: 500; }
.due__act { flex: none; }
.search { width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); margin-bottom: 8px; }
.client-list { display: flex; flex-direction: column; gap: 6px; }
.client-row { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 12px; text-decoration: none; font-weight: 500; min-height: var(--tap); }
.client-row.is-archived { color: var(--ink-3); }
.chev { color: var(--ink-3); font-size: 20px; }

/* ---------- history ---------- */
.hist-list { display: flex; flex-direction: column; gap: 6px; }
.hist { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; display: grid; gap: 3px; }
.hist--skipped { border-style: dashed; }
.hist.is-err .hist__what, .hist.is-err .hist__when { text-decoration: line-through; color: var(--ink-3); }
.hist__what { font-size: 14px; }
.hist__what .peptide { font-weight: 500; }
.hist__err { font-size: 12px; color: var(--red); font-weight: 500; }
.hist .btn--xs { justify-self: start; margin-top: 2px; }

/* ---------- forms ---------- */
.form { display: grid; gap: 12px; }
.form h2 { font-size: 20px; text-transform: none; letter-spacing: -0.01em; color: var(--ink); }
.form label, .label-like { display: grid; gap: 5px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.form input:not([type=radio]):not([type=hidden]), .form select {
  width: 100%; font: inherit; font-size: 17px; color: var(--ink); padding: 10px 12px; min-height: var(--tap);
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card);
}
.form input.inline-num { width: 80px; display: inline-block; margin: 0 6px; }
.form input.initial { text-transform: uppercase; text-align: center; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two--wide-first { grid-template-columns: 2fr 1fr; }
.field-group { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
.field-group legend { font-size: 13px; font-weight: 500; color: var(--ink-2); padding: 0; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { appearance: none; font: inherit; font-size: 14px; min-height: 38px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip small { opacity: 0.7; font-size: 11px; margin-left: 3px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg__opt { flex: 1; position: relative; }
.seg__opt input { position: absolute; opacity: 0; inset: 0; }
.seg__opt span { display: flex; align-items: center; justify-content: center; min-height: var(--tap); font-weight: 500; color: var(--ink-2); }
.seg__opt input:checked + span { background: var(--ink); color: #fff; }
.seg__opt input:disabled + span { opacity: 0.4; }
.seg__opt input:focus-visible + span { outline: 3px solid rgba(30, 110, 102, 0.45); outline-offset: -3px; }
.summary { background: var(--paper); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 15px; }
.preview { background: var(--paper); border-radius: var(--radius-sm); padding: 10px 12px; }
.calc-result { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.sheet__actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; margin-top: 4px; }

/* ---------- bottom sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(21, 37, 43, 0.45); }
.sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--card); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
  animation: sheet-up 180ms ease-out;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet__panel { animation: none; } }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 500; max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); }
.toast--error { background: var(--red); }

/* ---------- desktop ---------- */
@media (min-width: 700px) {
  .app { padding-top: 8px; }
  .top { border: 1px solid var(--line); border-radius: 0 0 16px 16px; }
  .actions { grid-template-columns: repeat(4, 1fr); }
  .actions .btn--primary { grid-column: auto; }
}

/* ==========================================================================
   v1.1 — low-stock strip, body map, picker, components, calculator, peptides screen
   ========================================================================== */
.lowstock { background: var(--amber-soft); border: 1px solid var(--amber-line); border-radius: var(--radius); padding: 10px 12px; margin: 4px 0 14px; }
.lowstock__head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.lowstock__head h2 { color: var(--amber); }
.lowstock__row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid rgba(143, 95, 12, 0.15); font-size: 14px; }
.lowstock__row:first-of-type { border-top: 0; }
.lowstock__main { flex: 1; min-width: 0; text-decoration: none; color: var(--ink); }
.lowstock__row--empty .lowstock__main b { color: var(--red); }

.bodymap { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--paper); border-radius: var(--radius-sm); padding: 8px 6px 4px; }
.bodymap__fig { width: 100%; height: auto; display: block; }
.bm-figure > * { fill: #E6ECE9; stroke: var(--line); stroke-width: 1.2; }
.bm-caption { fill: var(--ink-3); font: 10px var(--font-ui); text-anchor: middle; stroke: none; letter-spacing: .08em; text-transform: uppercase; }
.bm-site { cursor: pointer; }
.bm-hit { fill: #fff; stroke: var(--ink-3); stroke-width: 1.2; }
.bm-site:hover .bm-hit, .bm-site:focus-visible .bm-hit { stroke: var(--accent); }
.bm-site:focus-visible { outline: none; }
.bm-label { fill: var(--ink-2); font: 600 8.5px var(--font-ui); text-anchor: middle; pointer-events: none; }
.bm-halo { fill: none; stroke: var(--amber); stroke-width: 2; opacity: .35; pointer-events: none; }
.bm-site.is-recent-0 .bm-halo { opacity: .95; stroke-width: 3; }
.bm-site.is-recent-1 .bm-halo { opacity: .7; }
.bm-site.is-recent-2 .bm-halo { opacity: .5; }
.bm-site.is-next .bm-hit { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 3 2; }
.bm-site.is-on .bm-hit { fill: var(--accent); stroke: var(--accent-deep); stroke-dasharray: none; }
.bm-site.is-on .bm-label { fill: #fff; }
.bodymap__legend { grid-column: 1 / -1; font-size: 11px; color: var(--ink-3); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 2px 4px; }
.bm-key { width: 12px; height: 12px; border-radius: 4px; display: inline-block; border: 1.5px solid var(--ink-3); background: #fff; }
.bm-key--next { border: 2px dashed var(--accent); }
.bm-key--recent { border-color: var(--amber); box-shadow: 0 0 0 2px rgba(143, 95, 12, 0.35); border-radius: 50%; }
.bm-key--on { background: var(--accent); border-color: var(--accent-deep); }
.site-picked { font-size: 15px; margin-top: 6px; }
.site-list summary { font-size: 13px; color: var(--ink-2); cursor: pointer; margin: 6px 0; }
.chips--sites .chip { font-size: 13px; }

.picker { position: relative; }
.suggest { position: absolute; left: 0; right: 0; top: 100%; z-index: 5; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); max-height: 260px; overflow-y: auto; }
.suggest__item { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left; font: inherit; font-size: 15px; padding: 10px 12px; background: none; border: 0; border-bottom: 1px solid var(--line-2); color: var(--ink); cursor: pointer; min-height: var(--tap); }
.suggest__item:last-child { border-bottom: 0; }
.suggest__item:hover, .suggest__item:focus-visible { background: var(--accent-soft); }
.suggest__item--add { color: var(--accent-deep); font-weight: 500; }
.suggest__meta { font-size: 12px; color: var(--ink-3); white-space: nowrap; }

.seg--units .seg__opt span { min-height: 40px; font-size: 14px; }
.chip--sm { min-height: 30px; padding: 2px 10px; font-size: 13px; }
.components { display: grid; gap: 6px; }
.components__row { display: grid; grid-template-columns: 1fr 84px 36px; gap: 6px; align-items: center; }
.components__row input { min-height: 40px; }
.volume { display: grid; gap: 6px; }
.volume__range { width: 100%; accent-color: var(--accent); }
.form .two--wide-first input[name=doseStr], .form .two--wide-first input[name=massStr], .form .two--wide-first input[name=dose_value] { min-width: 0; }

.hist-tools { display: flex; justify-content: flex-end; margin: 0 0 10px; }
.pastvials { margin-top: 10px; font-size: 13px; }
.pastvials summary { cursor: pointer; color: var(--ink-2); font-weight: 500; padding: 6px 0; }
.pastvials__row { padding: 6px 0; border-top: 1px dashed var(--line); color: var(--ink-2); }
.pill--empty { background: var(--red-soft); color: var(--red); }
.pill--discarded { background: var(--line-2); color: var(--ink-2); }

.name-list { display: flex; flex-direction: column; gap: 6px; }
.name-row { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
.name-row.is-archived { opacity: .7; }
.name-row__main { flex: 1; min-width: 0; font-size: 15px; }
.name-row__act { display: flex; gap: 4px; flex: none; }
.proto--unit_mismatch { border-left-color: var(--red); border-left-style: dashed; }
.due--unit_mismatch { border-left-color: var(--red); border-left-style: dashed; }
.sy-size { text-anchor: start; font-size: 8px; }
@media (min-width: 700px) { .bodymap { grid-template-columns: 1fr 1fr; max-width: 420px; } }
