/* Qsimile – simulated electronic patient record.
   A deliberately generic hospital-system look: dense tables, a patient banner, and a left activity menu. */

:root {
  --bg: #e9edf1;
  --panel: #ffffff;
  --panel-2: #f6f8fa;
  --ink: #16222e;
  --ink-2: #3a4957;
  --muted: #637384;
  --line: #d3dbe3;
  --line-2: #e4e9ee;
  --brand: #0d4a68;
  --brand-2: #135f84;
  --brand-3: #e3eff6;
  --focus: #2b7bd6;
  --link: #145d96;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --warn: #9a5b00;
  --warn-bg: #fff4e0;
  --ok: #26722b;
  --ok-bg: #e8f4e8;
  --info-bg: #eaf2fb;
  --sim: #5b2a86;
  --hi: #b42318;
  --lo: #1d4fb8;
  --news1: #fff2b3;
  --news2: #ffd29a;
  --news3: #ffb3ad;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(16, 32, 48, 0.08), 0 2px 8px rgba(16, 32, 48, 0.06);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 13.5px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Frame --------------------------------------------------------------- */
.sim-strip {
  background: repeating-linear-gradient(135deg, var(--sim) 0 14px, #4d2273 14px 28px);
  color: #fff;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  padding: 3px 8px;
  font-weight: 600;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--brand);
  color: #fff;
  padding: 0 14px;
  height: 46px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar a, .topbar button.linklike { color: #fff; text-decoration: none; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; letter-spacing: 0.01em; white-space: nowrap; }
.brand svg { display: block; }
.brand small { font-weight: 400; opacity: 0.75; font-size: 12px; }
.topbar .sep { width: 1px; align-self: stretch; margin: 10px 0; background: rgba(255, 255, 255, 0.25); }
.topbar .crumbs { display: flex; gap: 12px; align-items: center; min-width: 0; font-size: 13px; }
.topbar .crumbs .pill { background: rgba(255, 255, 255, 0.14); padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar .who { display: flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; }
.topbar .who .role { opacity: 0.8; }
.topbar .tb-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  border-radius: 5px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12.5px;
}
.topbar .tb-btn:hover { background: rgba(255, 255, 255, 0.22); }
.topbar nav.adminnav { display: flex; gap: 2px; }
.topbar nav.adminnav a { padding: 6px 12px; border-radius: 5px; font-size: 13px; }
.topbar nav.adminnav a.active, .topbar nav.adminnav a:hover { background: rgba(255, 255, 255, 0.16); }
.page { max-width: 1280px; margin: 0 auto; padding: 18px 18px 60px; }
.page.narrow { max-width: 760px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; }
.page-head .sub { color: var(--muted); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 5px;
  padding: 5px 11px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.3;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: var(--panel-2); border-color: #b9c5d0; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.primary:hover { background: var(--brand); }
.btn.danger { color: var(--danger); border-color: #f0c2bd; }
.btn.danger:hover { background: var(--danger-bg); }
.btn.solid-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn.tiny { padding: 1px 6px; font-size: 11.5px; }
.btn svg { width: 15px; height: 15px; flex: none; }
.btn.small svg, .btn.tiny svg { width: 13px; height: 13px; }
.icon-btn { border: none; background: transparent; padding: 3px; border-radius: 4px; cursor: pointer; color: var(--muted); display: inline-flex; }
.icon-btn:hover { background: var(--panel-2); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Forms ------------------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > .label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--muted); }
.input, .select, .textarea {
  border: 1px solid #c4ced8;
  border-radius: 4px;
  background: #fff;
  padding: 5px 8px;
  width: 100%;
  min-width: 0;
}
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--focus); }
.textarea { resize: vertical; min-height: 64px; line-height: 1.45; }
.textarea.tall { min-height: 120px; }
.input.small { padding: 3px 6px; font-size: 12.5px; }
.input[readonly] { background: var(--panel-2); }
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px 14px; }
.span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; } .span-8 { grid-column: span 8; }
.span-9 { grid-column: span 9; } .span-12 { grid-column: span 12; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.check input { width: 15px; height: 15px; margin: 0; }
.radio-row { display: flex; gap: 6px; flex-wrap: wrap; }
.radio-row label {
  border: 1px solid #c4ced8;
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  background: #fff;
  font-size: 12.5px;
}
.radio-row label.on { background: var(--brand-3); border-color: var(--brand-2); color: var(--brand); font-weight: 600; }
.radio-row input { position: absolute; opacity: 0; pointer-events: none; }
.stamp-input { display: flex; gap: 6px; align-items: center; }
.stamp-input .day { width: 82px; }
.stamp-input .date { width: 150px; }
.stamp-input .time { width: 104px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--brand-3); border: 1px solid #c3d9e8; border-radius: 99px; padding: 1px 4px 1px 9px; font-size: 12px; }
.chip button { border: none; background: transparent; cursor: pointer; color: var(--muted); padding: 0 3px; font-size: 13px; line-height: 1; }
.meta-box { background: var(--info-bg); border: 1px solid #cfe0f2; border-radius: var(--radius); padding: 10px 12px; }
.meta-box .meta-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--brand); font-weight: 700; margin-bottom: 8px; }
.error-text { color: var(--danger); font-size: 12.5px; }

/* ---- Panels, cards, tables ----------------------------------------------------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel + .panel { margin-top: 14px; }
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-2);
  background: linear-gradient(#fbfcfd, #f3f6f8);
  border-radius: var(--radius) var(--radius) 0 0;
  min-height: 40px;
}
.panel-head h2, .panel-head h3 { font-size: 14px; font-weight: 700; color: var(--brand); }
.panel-head .sub { color: var(--muted); font-size: 12px; }
.panel-head .actions { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.panel-body { padding: 12px; }
.panel-body.flush { padding: 0; }
.empty { color: var(--muted); padding: 18px 12px; text-align: center; font-size: 13px; }
.empty.left { text-align: left; }
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  font-size: 12px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
table.grid th.wrap { white-space: normal; }
table.grid td { border-bottom: 1px solid var(--line-2); padding: 6px 8px; vertical-align: top; }
table.grid tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover td { background: #f7fafc; }
table.grid tr.clickable { cursor: pointer; }
table.grid tr.selected td { background: var(--brand-3) !important; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.actions { white-space: nowrap; text-align: right; width: 1%; }
table.grid .sub { color: var(--muted); font-size: 12px; }
tr.is-error td, .is-error .strike { text-decoration: line-through; color: var(--muted); }
tr.is-hidden td { background: repeating-linear-gradient(135deg, #fafbfc 0 8px, #f1f3f6 8px 16px) !important; color: var(--muted); }
.group-row td { background: #eef3f7 !important; font-weight: 700; color: var(--brand); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }

.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 4px; padding: 1px 6px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.badge.red { background: var(--danger-bg); border-color: #f3c1bb; color: var(--danger); }
.badge.amber { background: var(--warn-bg); border-color: #f0d3a3; color: var(--warn); }
.badge.green { background: var(--ok-bg); border-color: #bddcbe; color: var(--ok); }
.badge.blue { background: var(--info-bg); border-color: #c5dbf1; color: var(--link); }
.badge.purple { background: #f2eaf9; border-color: #dac6ee; color: var(--sim); }
.badge.solid-red { background: var(--danger); border-color: var(--danger); color: #fff; }
.badge svg { width: 12px; height: 12px; }
/* Medicines: "to reconcile" and where a prescription came from (pre-admission, amended, new). */
.badge.todo { background: #fff; border-style: dashed; border-color: #e0b36a; color: var(--warn); }
.badge.origin-pta { background: #e9f5f4; border-color: #b7dcd8; color: #19625b; }
.badge.origin-pta_amended { background: #eceefb; border-color: #c6cbef; color: #3a45a0; }
.badge.origin-new { background: var(--info-bg); border-color: #c5dbf1; color: var(--link); }
.origin-key { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.rec-med { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: grid; gap: 2px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
.strong { font-weight: 600; }
.mt { margin-top: 12px; } .mt-s { margin-top: 6px; } .mb { margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.cards .panel + .panel { margin-top: 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.notice { border-radius: var(--radius); padding: 9px 12px; border: 1px solid; display: flex; gap: 8px; align-items: flex-start; }
.notice svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.notice.info { background: var(--info-bg); border-color: #c5dbf1; color: #0f3f66; }
.notice.warn { background: var(--warn-bg); border-color: #f0d3a3; color: #6d4200; }
.notice.danger { background: var(--danger-bg); border-color: #f3c1bb; color: #7a1a12; }
.notice.ok { background: var(--ok-bg); border-color: #bddcbe; color: #1c5420; }
.flag-h { color: var(--hi); font-weight: 700; }
.flag-l { color: var(--lo); font-weight: 700; }
.flag-c { background: var(--hi); color: #fff; font-weight: 700; padding: 0 4px; border-radius: 3px; }

/* ---- Chart layout ----------------------------------------------------------------- */
.banner {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 8px 16px;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  position: sticky;
  top: 46px;
  z-index: 30;
  box-shadow: 0 1px 3px rgba(16, 32, 48, 0.06);
}
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: linear-gradient(135deg, #cfe0ec, #a9c6da);
  color: var(--brand);
  font-weight: 700;
  display: grid;
  place-items: center;
  font-size: 16px;
  flex: none;
}
.banner .pname { font-size: 17px; font-weight: 700; letter-spacing: 0.01em; }
.banner .pname .given { font-weight: 600; }
.banner .facts { display: flex; flex-wrap: wrap; gap: 3px 16px; font-size: 12.5px; color: var(--ink-2); margin-top: 1px; }
.banner .facts b { font-weight: 600; color: var(--ink); }
.banner .facts .lbl { color: var(--muted); margin-right: 4px; }
.banner > .ident { flex: 1 1 520px; min-width: 0; }
.banner .allergy-box { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; flex: 0 1 auto; max-width: 42%; }
.allergy-flag { display: inline-flex; align-items: center; gap: 6px; border-radius: 5px; padding: 4px 10px; font-weight: 700; font-size: 12.5px; border: 1px solid; }
.allergy-flag svg { width: 15px; height: 15px; }
.allergy-flag.has { background: var(--danger); border-color: var(--danger); color: #fff; }
.allergy-flag.nkda { background: var(--ok-bg); border-color: #9fcca2; color: var(--ok); }
.allergy-flag.unknown { background: var(--warn-bg); border-color: #efc27c; color: var(--warn); }
.alert-chip { background: #fff4e0; border: 1px solid #efc27c; color: #6d4200; border-radius: 5px; padding: 3px 8px; font-size: 12px; font-weight: 600; }

.chart {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  min-height: calc(100vh - 140px);
  background: linear-gradient(90deg, #f4f6f8 0 207px, var(--line) 207px 208px, transparent 208px);
}
.chart-nav { background: #f4f6f8; border-right: 1px solid var(--line); padding: 10px 0; position: sticky; top: calc(46px + var(--banner-h, 70px)); align-self: start; max-height: calc(100vh - 46px - var(--banner-h, 70px)); overflow-y: auto; }
.chart-nav .grp { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; padding: 10px 16px 4px; }
.chart-nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 16px;
  color: var(--ink-2);
  text-decoration: none;
  border-left: 3px solid transparent;
  font-size: 13px;
}
.chart-nav a svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.chart-nav a:hover { background: #e9eef2; }
.chart-nav a.active { background: var(--brand-3); border-left-color: var(--brand-2); color: var(--brand); font-weight: 600; }
.chart-nav a.active svg { color: var(--brand-2); }
.chart-nav .count { margin-left: auto; font-size: 11px; background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 0 6px; color: var(--muted); font-weight: 600; }
.chart-nav .count.red { background: var(--danger); border-color: var(--danger); color: #fff; }
.chart-main { padding: 14px 18px 60px; min-width: 0; }
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h1 { font-size: 18px; color: var(--ink); }
.section-head .sub { color: var(--muted); font-size: 12.5px; }
.section-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.authoring-bar {
  background: #fff8e6;
  border-bottom: 1px solid #efd9a5;
  padding: 7px 16px;
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12.5px;
}
.authoring-bar .tag { background: #9a5b00; color: #fff; border-radius: 4px; padding: 2px 8px; font-weight: 700; font-size: 11.5px; letter-spacing: 0.04em; text-transform: uppercase; }
.authoring-bar.facilitator { background: #f3ecfa; border-bottom-color: #dccaee; }
.authoring-bar.facilitator .tag { background: var(--sim); }
.authoring-bar .select { width: auto; padding: 2px 6px; }

/* Notes */
.notes-layout { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 14px; align-items: start; }
.note-list { max-height: calc(100vh - 230px); overflow-y: auto; }
.note-list .note-row { padding: 9px 12px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.note-list .note-row:hover { background: #f7fafc; }
.note-list .note-row.selected { background: var(--brand-3); box-shadow: inset 3px 0 0 var(--brand-2); }
.note-list .note-row .t { font-weight: 600; font-size: 13px; }
.note-list .note-row .m { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.note-list .note-row .x { font-size: 12px; color: var(--ink-2); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-view .nv-head { padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
.note-view .nv-head h2 { font-size: 16px; }
.note-view .nv-body { padding: 12px 14px; }
.note-sec + .note-sec { margin-top: 12px; }
.note-sec h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--brand); margin-bottom: 3px; }
.note-sec .txt { white-space: pre-wrap; }
.addendum { margin-top: 14px; border-left: 3px solid #c3d9e8; padding: 6px 10px; background: #f6fafc; }
.signature { margin-top: 14px; font-size: 12px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; }
.error-banner { background: var(--danger-bg); color: var(--danger); border: 1px solid #f3c1bb; border-radius: 5px; padding: 6px 10px; font-size: 12.5px; margin-bottom: 10px; }

/* Results */
.cum td.val { text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cum th.col { text-align: center; font-weight: 600; line-height: 1.2; }
.cum th.col .d { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }
.cum td.name { white-space: nowrap; }
.cum td.range { color: var(--muted); font-size: 12px; white-space: nowrap; }
.trend-link { color: inherit; text-decoration: none; border-bottom: 1px dotted #9fb2c3; cursor: pointer; }

/* Observations */
.obs-grid td:first-child { width: 150px; }
.obs-grid td.v { text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; }
.obs-grid .s1 { background: var(--news1) !important; }
.obs-grid .s2 { background: var(--news2) !important; }
.obs-grid .s3 { background: var(--news3) !important; }
.news-badge { display: inline-block; min-width: 28px; text-align: center; border-radius: 4px; font-weight: 700; padding: 1px 6px; }
.news-badge.low { background: #e7f3e8; color: #1f5d24; }
.news-badge.lowmed { background: var(--news2); color: #6d3a00; }
.news-badge.med { background: #ffa36b; color: #5a2300; }
.news-badge.high { background: #d9342b; color: #fff; }

/* Medication chart / administration grid */
.mar td.slot { text-align: center; min-width: 58px; }
.mar .slot-btn {
  border: 1px dashed #b8c4cf;
  background: #fff;
  border-radius: 4px;
  min-width: 52px;
  padding: 2px 4px;
  cursor: pointer;
  font-size: 11.5px;
  line-height: 1.25;
  color: var(--muted);
}
.mar .slot-btn:hover { border-color: var(--brand-2); color: var(--brand); }
.mar .slot-btn.given { border: 1px solid #9fcca2; background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.mar .slot-btn.notgiven { border: 1px solid #f3c1bb; background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.mar .slot-btn.future { opacity: 0.55; }
.mar .slot-btn[disabled] { cursor: default; }
.mar .daycol { border-left: 2px solid var(--line); }
.mar th.today { background: var(--brand-3); }
.drug-name { font-weight: 600; }
.status-held { color: var(--warn); font-weight: 600; }
.status-stopped { color: var(--muted); }
tr.stopped td { color: var(--muted); }
tr.stopped .drug-name { text-decoration: line-through; }

/* Med rec form */
.src-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 14px; }
.x-cell { text-align: center; width: 74px; }
.x-toggle {
  width: 28px; height: 24px; border: 1px solid #c4ced8; border-radius: 4px; background: #fff; cursor: pointer;
  font-weight: 800; color: var(--brand); font-size: 14px; line-height: 1;
}
.x-toggle.on { background: var(--brand-3); border-color: var(--brand-2); }
.x-toggle:disabled { cursor: default; opacity: 0.8; }
.must { background: var(--danger); color: #fff; font-weight: 700; text-align: center; padding: 4px; font-size: 12px; letter-spacing: 0.03em; }
.inline-edit td { background: #fbfdff; }
.inline-edit .input, .inline-edit .select { padding: 3px 6px; font-size: 12.5px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 14px; align-items: start; }
.drawer { position: sticky; top: calc(58px + var(--banner-h, 70px)); max-height: calc(100vh - 70px - var(--banner-h, 70px)); overflow-y: auto; }

/* Discharge letter editor */
.letter-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 18px; font-size: 13px; }
.dm-table td { padding: 3px 4px; }
.dm-table .input { padding: 3px 6px; font-size: 12.5px; }
.sticky-save { position: sticky; bottom: 0; z-index: 20; background: #fffbea; border: 1px solid #efd9a5; border-radius: var(--radius); padding: 8px 12px; display: flex; gap: 10px; align-items: center; margin-top: 14px; box-shadow: 0 -2px 10px rgba(16, 32, 48, 0.08); }

/* Ward list */
.ward td { vertical-align: middle; }
.ward .pn { font-weight: 700; }
.ward .pn small { font-weight: 400; color: var(--muted); }

/* Join & sign-in */
.center-page { min-height: calc(100vh - 22px); display: grid; place-items: center; padding: 24px 16px; }
.join-card { width: min(460px, 100%); }
.join-card .panel-body { padding: 22px; }
.join-card .logo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.join-card .logo-row h1 { font-size: 22px; color: var(--brand); }
.join-card .logo-row p { margin: 0; color: var(--muted); font-size: 13px; }
.code-input { font-family: var(--mono); font-size: 22px !important; letter-spacing: 0.25em; text-transform: uppercase; text-align: center; padding: 8px !important; }
.station-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.station-grid button { border: 1px solid #c4ced8; background: #fff; border-radius: 6px; padding: 10px 6px; cursor: pointer; text-align: center; }
.station-grid button.on { border-color: var(--brand-2); background: var(--brand-3); color: var(--brand); font-weight: 700; }
.station-grid button small { display: block; color: var(--muted); font-size: 11px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(12, 24, 36, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 8px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25); width: min(640px, 100%); display: flex; flex-direction: column; max-height: none; }
.modal.wide { width: min(920px, 100%); }
.modal.xwide { width: min(1180px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.modal-head h2 { font-size: 16px; color: var(--brand); }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 16px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line-2); background: var(--panel-2); border-radius: 0 0 8px 8px; }
.modal-foot .left { margin-right: auto; }

/* Toasts */
.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1d2a36; color: #fff; padding: 9px 14px; border-radius: 6px; box-shadow: var(--shadow); font-size: 13px; max-width: 380px; }
.toast.error { background: var(--danger); }
.toast.ok { background: #1f6a2a; }

/* Admin */
.code-big { font-family: var(--mono); font-size: 26px; font-weight: 700; letter-spacing: 0.18em; color: var(--brand); }
.stage-picker { display: flex; gap: 4px; flex-wrap: wrap; }
.stage-picker button { border: 1px solid #c4ced8; background: #fff; border-radius: 5px; padding: 5px 10px; cursor: pointer; font-size: 12.5px; }
.stage-picker button.on { background: var(--brand-2); border-color: var(--brand-2); color: #fff; font-weight: 600; }
.case-list-card { display: flex; gap: 12px; align-items: flex-start; }
.stat { display: flex; flex-direction: column; }
.stat b { font-size: 18px; }
.stat span { color: var(--muted); font-size: 12px; }

/* Trend chart */
.trend svg { width: 100%; height: auto; display: block; }
.trend .axis { stroke: #c7d0d9; stroke-width: 1; }
.trend .band { fill: #e8f4e8; }
.trend .line { fill: none; stroke: var(--brand-2); stroke-width: 2; }
.trend .pt { fill: #fff; stroke: var(--brand-2); stroke-width: 2; }
.trend .pt.out { stroke: var(--hi); fill: var(--hi); }
.trend text { font-size: 11px; fill: var(--muted); font-family: var(--font); }

/* Printable documents */
.print-doc { background: #fff; color: #000; font-family: Arial, Helvetica, sans-serif; font-size: 12.5px; line-height: 1.4; padding: 26px 30px; }
.print-doc h1 { font-size: 20px; margin: 0; }
.print-doc h2 { font-size: 14px; margin: 16px 0 6px; border-bottom: 1.5px solid #333; padding-bottom: 2px; }
.print-doc table { width: 100%; border-collapse: collapse; margin: 4px 0 8px; }
.print-doc th, .print-doc td { border: 1px solid #777; padding: 4px 6px; text-align: left; vertical-align: top; font-size: 12px; }
.print-doc th { background: #e6e6e6; }
.print-doc .doc-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; border-bottom: 3px solid var(--brand); padding-bottom: 10px; margin-bottom: 12px; }
.print-doc .sim-mark { border: 2px solid var(--sim); color: var(--sim); font-weight: 700; text-align: center; padding: 4px; margin-bottom: 12px; letter-spacing: 0.08em; font-size: 11px; }
.print-doc .box { border: 1px solid #777; padding: 6px 8px; min-height: 28px; white-space: pre-wrap; }
.print-doc .lbl { font-weight: 700; }
.rx-form { position: relative; border: 2px solid #3b5a78; border-radius: 6px; padding: 14px 16px; max-width: 560px; margin: 0 auto; overflow: hidden; background: #fbfdff; }
.rx-form .wm { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.rx-form .wm span { transform: rotate(-28deg); font-size: 34px; font-weight: 800; color: rgba(91, 42, 134, 0.13); letter-spacing: 0.08em; text-align: center; line-height: 1.1; }
.rx-form .rx-row { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; border-bottom: 1px solid #c9d6e2; padding: 5px 0; }
.rx-form .rx-items { min-height: 180px; border: 1px solid #c9d6e2; margin: 8px 0; padding: 8px; background: #fff; }

@media print {
  body { background: #fff; }
  body * { visibility: hidden; }
  .print-doc, .print-doc * { visibility: visible; }
  .print-doc { position: absolute; left: 0; top: 0; width: 100%; padding: 0; }
  .modal-backdrop { position: static; background: none; padding: 0; overflow: visible; }
  .modal { box-shadow: none; width: 100% !important; }
  .no-print { display: none !important; }
  @page { margin: 14mm; }
}

@media (max-width: 980px) {
  .chart { grid-template-columns: 1fr; background: none; }
  .chart-nav { position: static; height: auto; display: flex; flex-wrap: wrap; padding: 6px; gap: 2px; }
  .chart-nav .grp { display: none; }
  .chart-nav a { border-left: none; border-radius: 5px; padding: 6px 10px; }
  .notes-layout, .split { grid-template-columns: 1fr; }
  .banner { position: static; }
  .banner .allergy-box { margin-left: 0; max-width: none; justify-content: flex-start; }
  .topbar { height: auto; flex-wrap: wrap; padding: 6px 12px; }
  .topbar .crumbs { flex-wrap: wrap; }
}
@media (max-width: 640px) {
  .form-grid > * { grid-column: span 12 !important; }
  .src-grid { grid-template-columns: 1fr 1fr; }
}

/* Facilitator accounts */
.topbar .who a.who-link { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 5px; }
.topbar .who a.who-link:hover, .topbar .who a.who-link.active { background: rgba(255, 255, 255, 0.16); }
.join-card.wide-card { width: min(620px, 100%); }
.join-card ol.steps { padding-left: 20px; margin: 8px 0 12px; }
.join-card ol.steps li { margin-bottom: 4px; }
.qr-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin: 10px 0 14px; }
.qr-row img.qr { border: 1px solid var(--line); border-radius: 6px; background: #fff; image-rendering: pixelated; }
.qr-row .setup-key { display: block; font-family: var(--mono); font-size: 14px; letter-spacing: 0.06em; background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 6px 8px; margin-top: 4px; word-break: break-all; user-select: all; }
.recovery-grid { display: grid; grid-template-columns: repeat(2, max-content); gap: 6px 18px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 10px 14px; }
.recovery-grid code { font-family: var(--mono); font-size: 14px; letter-spacing: 0.05em; }
.role-choice { display: grid; gap: 6px; }
.role-choice label { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; cursor: pointer; }
.role-choice label.on { border-color: var(--brand-2); background: var(--brand-3); }
.role-choice label > span { display: flex; flex-direction: column; gap: 2px; }
.role-choice input { margin-top: 3px; }
table.people td { vertical-align: top; }

/* Held back / release early */
.station-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 12px; }
.radio-col { display: flex; flex-direction: column; gap: 6px; }
.held-panel .alert-setting { border-top: 1px solid var(--line-2); }
.held-panel .alert-setting .check { align-items: flex-start; }
.chart-nav .count.new, .badge.new { background: var(--ok); border-color: var(--ok); color: #fff; }

/* Also add to other stations (facilitator entries) */
.meta-box .also-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed #c9d8e4; }
.meta-box .also-row .label { margin: 0; }
table.grid.cum th.col.fresh { background: var(--ok-bg); }
table.grid.cum th.col .badge.new { display: block; width: max-content; margin: 0 auto 2px; }
