/* ============================================================
   Sampaloc RHU EMR — Clinical Operations Console
   Design tokens + base + components
   ============================================================ */

:root {
  /* Surfaces & neutrals (cool slate) */
  --bg:           #EEF2F2;
  --surface:      #FFFFFF;
  --surface-2:    #F4F7F7;
  --surface-3:    #EAEFEF;
  --border:       #E0E7E7;
  --border-2:     #D2DCDC;
  --border-strong:#BFCBCB;

  /* Text */
  --text:   #142220;
  --text-2: #51625F;
  --text-3: #809390;
  --text-inv: #FFFFFF;

  /* Brand — clinical teal-green */
  --primary:        #0E8C72;
  --primary-700:    #0B6F5B;
  --primary-800:    #095746;
  --primary-soft:   #E0F1EB;
  --primary-softer: #EFF8F4;
  --primary-line:   #BCE0D5;

  /* Semantic */
  --danger:       #C5453A;
  --danger-soft:  #FBE9E6;
  --danger-line:  #F0C8C2;
  --warn:         #B97309;
  --warn-soft:    #FBF0DC;
  --warn-line:    #EDD6A6;
  --info:         #2C6CB0;
  --info-soft:    #E6EFF8;
  --info-line:    #C3D8EE;
  --violet:       #6E59C0;
  --violet-soft:  #ECE9F9;
  --violet-line:  #D3CBF0;
  --violet-800:   #4B3A99;
  --cyan:         #0E8FAE;
  --cyan-soft:    #E1F1F5;
  --cyan-line:    #B5DDE8;
  --cyan-800:     #0A6076;
  --rose:         #C04A77;
  --rose-soft:    #FBE7EE;
  --rose-line:    #F0C6D8;
  --rose-800:     #93305A;
  --ok:           #0E8C72;
  --ok-soft:      #E0F1EB;
  --lab:          #3E63C7;   /* laboratory requests (Sprint Review 2.1) — indigo, distinct from info/violet */
  --lab-soft:     #E8EDFB;
  --lab-line:     #C6D3F3;
  --lab-800:      #2B47A0;

  /* Radii */
  --r-xs: 5px;
  --r-sm: 7px;
  --r:    10px;
  --r-lg: 14px;
  --r-xl: 20px;

  /* Shadows */
  --sh-1: 0 1px 2px rgba(18,40,37,.06), 0 1px 1px rgba(18,40,37,.04);
  --sh-2: 0 2px 4px rgba(18,40,37,.05), 0 4px 12px rgba(18,40,37,.06);
  --sh-3: 0 8px 28px rgba(18,40,37,.12), 0 2px 8px rgba(18,40,37,.08);
  --sh-pop: 0 12px 40px rgba(10,40,34,.18);

  /* Type */
  --font: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Layout */
  --rail-w: 248px;
  --rail-w-compact: 68px;
  --topbar-h: 60px;
  --ctx-h: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#root { height: 100%; }

/* density */
[data-density="compact"] { --row-pad: 8px; --card-pad: 14px; --gap: 12px; }
[data-density="balanced"] { --row-pad: 11px; --card-pad: 18px; --gap: 16px; }
[data-density="comfy"] { --row-pad: 15px; --card-pad: 24px; --gap: 22px; }
:root { --row-pad: 11px; --card-pad: 18px; --gap: 16px; }

h1,h2,h3,h4,p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
.mono { font-family: var(--mono); font-feature-settings: "zero" 1; }
.tnum { font-variant-numeric: tabular-nums; }

::selection { background: var(--primary-soft); }

/* scrollbars */
.scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.scroll::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 20px; border: 3px solid var(--surface); }
.scroll::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  display: grid;
  height: 100%;
  background: var(--bg);
}
/* sidebar layout */
.app.lay-sidebar { grid-template-columns: var(--rail-w) 1fr; grid-template-rows: 100%; }
.app.lay-rail    { grid-template-columns: var(--rail-w-compact) 1fr; grid-template-rows: 100%; }
.app.lay-topbar  { grid-template-rows: var(--topbar-h) 1fr; grid-template-columns: 100%; }

/* ---- Side navigation ---- */
.nav {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  z-index: 5;
}
.nav-brand {
  display: flex; align-items: center; gap: 11px;
  padding: 0 10px 0 18px;
  border-bottom: 1px solid var(--border);
  height: var(--topbar-h); min-height: var(--topbar-h);
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(150deg, var(--primary) 0%, var(--primary-700) 100%);
  display: grid; place-items: center; flex: none;
  box-shadow: 0 2px 6px rgba(11,111,91,.35), inset 0 1px 0 rgba(255,255,255,.25);
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-text b { font-size: 14.5px; font-weight: 600; letter-spacing: -.01em; }
.brand-text span { font-size: 11px; color: var(--text-3); font-weight: 500; letter-spacing: .02em; }

.nav-scroll { flex: 1; overflow-y: auto; padding: 12px 12px; min-height: 0; }
.nav-group-label {
  font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-3); padding: 14px 10px 6px;
}
.lay-rail .nav-group-label { text-align: center; padding: 12px 0 5px; font-size: 9px; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--r-sm);
  color: var(--text-2); font-weight: 500; font-size: 13.5px;
  border: none; background: none; width: 100%; text-align: left;
  position: relative; transition: background .12s, color .12s;
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item .badge-dot { margin-left: auto; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-800); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--primary);
}
.lay-rail .nav-item { justify-content: center; padding: 11px 0; }
.lay-rail .nav-item span.label { display: none; }
.lay-rail .nav-item .badge-dot { position: absolute; top: 6px; right: 12px; margin: 0; }
.lay-rail .nav-item.active::before { left: 0; }

.nav-foot { border-top: 1px solid var(--border); padding: 12px; }
.staff-chip {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 9px; border-radius: var(--r-sm); border: none; background: none;
  text-align: left; transition: background .12s;
}
.staff-chip:hover { background: var(--surface-2); }
.staff-meta { min-width: 0; line-height: 1.2; }
.staff-meta b { font-size: 12.5px; font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.staff-meta span { font-size: 11px; color: var(--text-3); }
.lay-rail .staff-meta, .lay-rail .nav-brand .brand-text { display: none; }
.lay-rail .nav-brand { justify-content: center; padding: 16px 0; }

/* ---- App-wide notice + collapsible sidebar ----
   The test banner spans the full width above the app grid (a flex-column .shell), so the sidebar
   header and the top bar share the same baseline. The chevron in the sidebar header (#navToggle)
   collapses the full sidebar to the icon-only rail and back, reusing the .lay-rail rules above —
   keyed on html.nav-collapsed, which base.html sets in <head> from localStorage (applied before
   paint, so there's no width flash on a full page load). */
.shell { height: 100%; display: flex; flex-direction: column; }
.shell > .app { flex: 1 1 auto; min-height: 0; height: auto; }
.test-banner {
  background: #fef3c7; color: #92400e; border-bottom: 1px solid #fcd34d;
  padding: 7px 16px; font-size: 12.5px; font-weight: 500;
  display: flex; align-items: center; gap: 8px; justify-content: center; text-align: center;
}

.nav-collapse-btn {
  margin-left: auto; flex: none; width: 28px; height: 28px; border-radius: 7px;
  display: grid; place-items: center; border: none; background: none; cursor: pointer;
  color: var(--text-3); transition: background .12s, color .12s;
}
.nav-collapse-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-collapse-btn svg { width: 18px; height: 18px; }
.nav-collapse-btn span { display: grid; place-items: center; }
.nav-collapse-btn .i-expand { display: none; }

.app.lay-sidebar { transition: grid-template-columns .16s ease; }
html.nav-collapsed .app.lay-sidebar { grid-template-columns: var(--rail-w-compact) 1fr; }
html.nav-collapsed .lay-sidebar .nav-group-label { text-align: center; padding: 12px 0 5px; font-size: 9px; }
html.nav-collapsed .lay-sidebar .nav-item { justify-content: center; padding: 11px 0; }
html.nav-collapsed .lay-sidebar .nav-item span.label { display: none; }
html.nav-collapsed .lay-sidebar .nav-item .badge-dot { position: absolute; top: 6px; right: 12px; margin: 0; }
html.nav-collapsed .lay-sidebar .nav-item.active::before { left: 0; }
html.nav-collapsed .lay-sidebar .staff-meta,
html.nav-collapsed .lay-sidebar .nav-brand .brand-text,
html.nav-collapsed .lay-sidebar .nav-brand .brand-mark { display: none; }
html.nav-collapsed .lay-sidebar .nav-brand { justify-content: center; padding: 0; }
html.nav-collapsed .lay-sidebar .nav-collapse-btn { margin: 0; }
html.nav-collapsed .lay-sidebar .nav-collapse-btn .i-collapse { display: none; }
html.nav-collapsed .lay-sidebar .nav-collapse-btn .i-expand { display: grid; }
html.nav-collapsed .lay-sidebar .staff-chip { justify-content: center; }

/* ---- Top-bar layout ---- */
.topbar {
  grid-column: 1 / -1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  padding: 0 18px; height: var(--topbar-h);
  position: relative; z-index: 5;
}
.topbar .nav-brand { border: none; min-height: 0; padding: 0 22px 0 0; margin-right: 8px; border-right: 1px solid var(--border); height: 34px; }
.topnav { display: flex; gap: 2px; align-items: center; }
.topnav .nav-item { width: auto; padding: 8px 13px; }
.topnav .nav-item.active::before { display: none; }
.topnav .nav-item.active { background: var(--primary-soft); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* ---- Main column ---- */
.main {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  overflow: hidden;
}
/* context bar (search + facility + date), shown in side layouts */
.ctxbar {
  display: flex; align-items: center; gap: 14px;
  height: var(--ctx-h); flex: none;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.lay-topbar .ctxbar { display: none; }

.facility-pill {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 12px 6px 8px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.facility-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.facility-pill b { font-size: 12.5px; font-weight: 600; }
.facility-pill span { font-size: 11.5px; color: var(--text-3); }

.date-block { line-height: 1.15; }
.date-block b { font-size: 13px; font-weight: 600; display: block; }
.date-block span { font-size: 11.5px; color: var(--text-3); }

/* global search */
.gsearch {
  flex: 1; max-width: 460px; position: relative;
}
.gsearch input {
  width: 100%; height: 38px; border-radius: var(--r-sm);
  border: 1px solid var(--border-2); background: var(--surface-2);
  padding: 0 14px 0 38px; font-family: inherit; font-size: 13.5px; color: var(--text);
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.gsearch input:focus { outline: none; background: var(--surface); border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-softer); }
.gsearch input::placeholder { color: var(--text-3); }
.gsearch .si { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.gsearch .kbd { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); }

.kbd {
  font-family: var(--mono); font-size: 11px; color: var(--text-3);
  background: var(--surface); border: 1px solid var(--border-2); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; line-height: 1.5;
}

.iconbtn {
  width: 38px; height: 38px; border-radius: var(--r-sm); flex: none;
  border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; color: var(--text-2);
  position: relative; transition: background .12s, color .12s, border-color .12s;
}
.iconbtn:hover { background: var(--surface-2); color: var(--text); }
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn .ndot { position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); border: 1.5px solid var(--surface); }

/* page scroll region */
.page {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 24px 28px 40px;
}
.page-wide { max-width: 1320px; margin: 0 auto; }

/* ============================================================
   PRIMITIVES
   ============================================================ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-1);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 14px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.card-head .count {
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 99px; padding: 1px 9px;
}
.card-head .ho-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  height: 38px; padding: 0 15px; border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 600; border: 1px solid transparent;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
/* A button the double-submit guard has disabled (D27): dimmed so the clerk sees the click was taken.
   `default`, not `progress`: a button left disabled after the browser's Stop must not look busy. */
.btn:disabled { opacity: .6; cursor: default; }
.btn-pri { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(8,87,70,.3); }
.btn-pri:hover { background: var(--primary-700); }
.btn-ghost { background: var(--surface); border-color: var(--border-2); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-soft { background: var(--primary-soft); color: var(--primary-800); }
.btn-soft:hover { background: var(--primary-line); }
.btn-sm { height: 31px; padding: 0 11px; font-size: 12.5px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 14.5px; }

/* chips / pills / badges */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px;
  border: 1px solid transparent; white-space: nowrap; line-height: 1.4;
}
.chip svg { width: 12px; height: 12px; }
.chip .cdot { width: 6px; height: 6px; border-radius: 50%; }
.chip-neutral { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.chip-teal    { background: var(--primary-soft); color: var(--primary-800); border-color: var(--primary-line); }
.chip-blue    { background: var(--info-soft); color: var(--info); border-color: var(--info-line); }
.chip-amber   { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.chip-red     { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-line); }
.chip-rose    { background: var(--rose-soft); color: var(--rose-800); border-color: var(--rose-line); }
.chip-violet  { background: var(--violet-soft); color: var(--violet-800); border-color: var(--violet-line); }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: var(--r-xs);
  text-transform: uppercase; letter-spacing: .03em;
}

/* avatars */
.avatar {
  width: 36px; height: 36px; border-radius: 9px; flex: none;
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
  color: var(--primary-800); background: var(--primary-soft);
  border: 1px solid var(--primary-line); letter-spacing: -.02em;
}
.avatar.a-blue { color: var(--info); background: var(--info-soft); border-color: var(--info-line); }
.avatar.a-amber { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-line); }
.avatar.a-slate { color: var(--text-2); background: var(--surface-2); border-color: var(--border-2); }
.avatar.sm { width: 28px; height: 28px; border-radius: 7px; font-size: 11px; }
.avatar.lg { width: 52px; height: 52px; border-radius: 13px; font-size: 18px; }

/* ============================================================
   DASHBOARD
   ============================================================ */
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-size: 23px; font-weight: 600; letter-spacing: -.02em; }
.page-head .sub { color: var(--text-2); font-size: 13.5px; margin-top: 3px; }
.page-head .ph-right { margin-left: auto; display: flex; gap: 9px; align-items: center; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--gap); margin-bottom: var(--gap); }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 15px 16px; box-shadow: var(--sh-1); position: relative; overflow: hidden;
}
.tile .tl-top { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.tile .tl-top svg { width: 15px; height: 15px; }
.tile .tl-label { font-size: 12px; font-weight: 600; white-space: nowrap; }
.tile .tl-val { font-size: 30px; font-weight: 600; letter-spacing: -.03em; margin-top: 8px; line-height: 1; font-variant-numeric: tabular-nums; }
.tile .tl-val small { font-size: 14px; color: var(--text-3); font-weight: 500; margin-left: 3px; }
.tile .tl-foot { font-size: 11.5px; color: var(--text-3); margin-top: 7px; display: flex; align-items: center; gap: 5px; }
.tile .tl-accent { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
.trend-up { color: var(--ok); font-weight: 600; }
.trend-dn { color: var(--danger); font-weight: 600; }

/* main grid */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr); gap: var(--gap); align-items: start; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } .tiles { grid-template-columns: repeat(3, 1fr); } }

/* queue */
.qfilter { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: var(--r-sm); border: 1px solid var(--border); }
.qfilter button {
  border: none; background: none; font-size: 12.5px; font-weight: 600; color: var(--text-2);
  padding: 5px 11px; border-radius: 5px; display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.qfilter button .n { font-family: var(--mono); font-size: 11px; opacity: .7; }
.qfilter button.on { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }

.qrow {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center;
  padding: var(--row-pad) 18px; border-bottom: 1px solid var(--border);
  transition: background .1s; cursor: pointer; position: relative;
}
.qrow:last-child { border-bottom: none; }
.qrow:hover { background: var(--surface-2); }
.qrow .q-stat { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
.q-person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.q-name { font-weight: 600; font-size: 14px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.q-meta { font-size: 12px; color: var(--text-3); margin-top: 1px; display: flex; gap: 8px; align-items: center; }
.q-meta .mono { color: var(--text-2); }
.q-svc { display: flex; flex-direction: column; gap: 5px; align-items: flex-start; }
.q-svc .svc-sub { font-size: 11.5px; color: var(--text-3); }
.q-right { display: flex; align-items: center; gap: 14px; }
.q-wait { text-align: right; line-height: 1.2; }
.q-wait b { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; display: block; }
.q-wait span { font-size: 11px; color: var(--text-3); }
.q-go {
  width: 32px; height: 32px; border-radius: var(--r-sm); border: 1px solid var(--border-2);
  background: var(--surface); display: grid; place-items: center; color: var(--text-2);
  transition: all .12s;
}
.qrow:hover .q-go { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Derived clinic-flow rail, station label & summary (dashboard "Clinic flow" card). The station is
   inferred from recorded activity (worklists.clinic_day_board) — display only, never gates. Each
   element carries a flow-<station> class that sets --fc to the (next) station colour. */
.flow-waiting  { --fc: var(--warn); }
.flow-triage   { --fc: var(--info); }
.flow-consult  { --fc: var(--primary); }
.flow-pharmacy { --fc: #6E59C7; }
.flow-checkout { --fc: var(--primary-700); }
.flow-done     { --fc: var(--text-3); }

/* rail over the next-step label — a compact vertical stack, matching the q-wait rhythm */
.q-flow { display: flex; flex-direction: column; align-items: center; gap: 5px; }

/* fixed-length per-type rail: the line always spans Waiting→Checkout; a dot appears only at the
   stations the encounter type uses; cleared dots + line are tinted, the hollow ring is the NEXT
   step (built in chips.html flow_rail). Slots sit at 0/25/50/75/100% so spacing is constant. */
.flow-rail { position: relative; display: inline-block; width: 132px; height: 14px; vertical-align: middle; }
.flow-rail .rail-base { position: absolute; top: 50%; left: 0; right: 0; height: 2.5px; transform: translateY(-50%); background: var(--surface-3); border-radius: 2px; }
.flow-rail .rail-fill { position: absolute; top: 50%; left: 0; height: 2.5px; transform: translateY(-50%); background: var(--fc); border-radius: 2px; }
.flow-rail .rdot { position: absolute; top: 50%; transform: translate(-50%, -50%); border-radius: 99px; }
.flow-rail .rdot.done  { width: 8px; height: 8px; background: var(--fc); }
.flow-rail .rdot.next  { width: 12px; height: 12px; background: #fff; border: 2.5px solid var(--fc);
  box-shadow: 0 0 0 3px var(--surface-2); /* fallback for engines without color-mix (offline LGU, §2) */
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--fc) 18%, transparent); }
.flow-rail .rdot.later { width: 7px; height: 7px; background: #fff; border: 1.5px solid var(--border-2); }
.flow-step {
  font-size: 10px; font-weight: 700; padding: 1px 10px; border-radius: 99px; white-space: nowrap;
  color: var(--fc, var(--text-2)); border: 1px solid var(--fc, var(--border-2));
  background: #fff; /* fallback for engines without color-mix (offline LGU, §2) */
  background: color-mix(in srgb, var(--fc) 8%, #fff);
}
.flow-seen { font-size: 10px; font-weight: 700; padding: 1px 9px; border-radius: 99px; white-space: nowrap; color: var(--text-2); border: 1px solid var(--border-2); }

.flow-summary { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 11px 18px 3px; border-bottom: 1px solid var(--border); }
.fs-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.fs-item b { font-weight: 700; font-variant-numeric: tabular-nums; }
.fs-dot { width: 8px; height: 8px; border-radius: 99px; flex: none; background: var(--fc, var(--text-3)); }
.fs-cap { font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); align-self: center; margin-right: 2px; }

.qrow.qrow-done { opacity: .6; }

/* Dashboard Clinic-flow card: header + rows share one grid so the rail sits under "Next step" and
   the time under "Checked in". Scoped to .clinic-flow so the shared .qrow (visits, etc.) is left
   alone. Columns: person | service | rail(138) | time(72) | go(32). */
.clinic-flow .qrow  { grid-template-columns: auto minmax(0, 1fr) 138px 72px 32px; }
.clinic-flow .q-flow { width: 138px; }
.clinic-flow .q-wait { width: 72px; }
.clinic-flow .qhead {
  display: grid; grid-template-columns: auto minmax(0, 1fr) 138px 72px 32px; gap: 14px;
  align-items: center; padding: 7px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.clinic-flow .qh-l { font-size: 9.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); }
.clinic-flow .qh-flow { text-align: center; color: var(--primary-800); }
.clinic-flow .qh-wait { text-align: right; }

/* worklist cards */
.wl-stack { display: flex; flex-direction: column; gap: var(--gap); }
.wl-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 18px;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s;
}
.wl-item:last-child { border-bottom: none; }
.wl-item:hover { background: var(--surface-2); }
.wl-body { min-width: 0; flex: 1; }
.wl-body b { font-size: 13.5px; font-weight: 600; }
.wl-body .wl-sub { font-size: 11.5px; color: var(--text-3); margin-top: 1px; }
.wl-right { text-align: right; flex: none; }
.wl-more { padding: 10px 18px; text-align: center; font-size: 12.5px; font-weight: 600; color: var(--primary); cursor: pointer; }
.wl-more:hover { background: var(--surface-2); }

.attempt-dots { display: inline-flex; gap: 3px; }
.attempt-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--border-2); display: block; }
.attempt-dots i.miss { background: var(--warn); }
.attempt-dots i.hit { background: var(--ok); }

/* mini accomplishment bar */
.accbar { display: flex; flex-direction: column; gap: 11px; padding: 4px 2px; }
.accrow { display: grid; grid-template-columns: 130px 1fr 38px; gap: 12px; align-items: center; font-size: 12.5px; }
.accrow .lab { color: var(--text-2); font-weight: 500; }
.accrow .track { height: 7px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.accrow .fill { height: 100%; border-radius: 99px; }
.accrow .val { text-align: right; font-weight: 600; font-family: var(--mono); font-size: 12px; }

/* ============================================================
   SEARCH & REGISTRATION
   ============================================================ */
.search-wrap { max-width: 880px; margin: 0 auto; }
.bigsearch { position: relative; margin-bottom: 8px; }
.bigsearch input {
  width: 100%; height: 58px; border-radius: var(--r-lg);
  border: 1.5px solid var(--border-2); background: var(--surface);
  padding: 0 18px 0 52px; font-family: inherit; font-size: 17px; color: var(--text);
  box-shadow: var(--sh-1); transition: border-color .12s, box-shadow .12s;
}
.bigsearch input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-softer), var(--sh-2); }
.bigsearch input::placeholder { color: var(--text-3); }
.bigsearch .bsi { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); color: var(--primary); }
.bigsearch .bs-clear { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); }
.search-hint { font-size: 12.5px; color: var(--text-3); display: flex; align-items: center; gap: 14px; padding: 0 4px; }

/* htmx request indicator — hidden until a request is in flight (live-search "searching…"). */
.htmx-indicator { opacity: 0; transition: opacity 120ms ease; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.search-hint .sh-seg { display: flex; align-items: center; gap: 6px; }

.scope-banner {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-radius: var(--r); font-size: 12.5px; margin: 14px 0;
  border: 1px solid var(--border);
}
.scope-banner.local { background: var(--surface-2); color: var(--text-2); }
.scope-banner.mpi { background: var(--info-soft); border-color: var(--info-line); color: var(--info); }

.res-list { display: flex; flex-direction: column; gap: 10px; }
.res-card {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--sh-1); cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .08s;
}
.res-card:hover { border-color: var(--primary-line); box-shadow: var(--sh-2); }
.res-main { min-width: 0; flex: 1; }
.res-name { font-size: 15.5px; font-weight: 600; letter-spacing: -.01em; display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.res-sub { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-3); margin-top: 3px; flex-wrap: wrap; }
.res-sub .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--border-strong); }
.res-id { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); }
.res-right { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; min-width: 132px; }
.res-right .muted, .res-right > span { white-space: nowrap; }

/* MPI match score */
.matchbar { display: flex; align-items: center; gap: 8px; }
.matchbar .mb-track { width: 54px; height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.matchbar .mb-fill { height: 100%; border-radius: 99px; }
.matchbar b { font-family: var(--mono); font-size: 12px; font-weight: 600; }

.empty-state { text-align: center; padding: 46px 20px; }
.empty-state .es-ic { width: 56px; height: 56px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; margin: 0 auto 16px; color: var(--text-3); }
.empty-state h3 { font-size: 16px; font-weight: 600; margin-bottom: 5px; }
.empty-state p { color: var(--text-2); font-size: 13.5px; max-width: 380px; margin: 0 auto 18px; }

/* recents */
.recents-head { display: flex; align-items: center; gap: 8px; font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); margin: 22px 4px 12px; }

/* registration form / patient detail (slide-over) */
.overlay { position: fixed; inset: 0; background: rgba(16,32,29,.42); z-index: 40; backdrop-filter: blur(2px); animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; width: 560px; max-width: 94vw;
  background: var(--surface); z-index: 41; box-shadow: var(--sh-pop);
  display: flex; flex-direction: column; animation: slidein .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes slidein { from { transform: translateX(30px); opacity: .4; } }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); flex: none; }
.sheet-head h2 { font-size: 16.5px; font-weight: 600; }
.sheet-head .sh-sub { font-size: 12px; color: var(--text-3); }
.sheet-body { flex: 1; overflow-y: auto; padding: 20px 22px; }
.sheet-foot { flex: none; padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; background: var(--surface-2); }

/* form */
/* Baseline theme for text-like form controls. A bare <input>/<select>/<textarea> that ISN'T
   wrapped in .field (or given .hx-in / .vro-cell) used to render as a raw native control that
   clashed with the theme (e.g. the FPE immunization date boxes and the visual-acuity grid). This
   themes their appearance for ALL of them so no bare control is ever left unstyled again. It is
   pinned to ZERO specificity via :where() (the `input:where(...)` part contributes nothing, so it
   scores (0,0,1)); every .field/.hx-in/.vro-cell rule below has a class and therefore wins on
   ties, so nothing already-themed shifts. Sizing (height/width) still comes from context.
   Radios/checkboxes/buttons/etc. are excluded so they keep their own affordances. */
input:where(:not([type="radio"], [type="checkbox"], [type="range"], [type="file"], [type="color"],
            [type="hidden"], [type="submit"], [type="button"], [type="reset"], [type="image"])),
select, textarea {
  border: 1px solid var(--border-2); border-radius: var(--r-sm); background: var(--surface);
  padding: 7px 10px; font-family: inherit; font-size: 14px; color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
input:where(:not([type="radio"], [type="checkbox"], [type="range"], [type="file"], [type="color"],
            [type="hidden"], [type="submit"], [type="button"], [type="reset"], [type="image"])):focus,
select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-softer); }

.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field label .req { color: var(--danger); }
/* Text inputs and selects only. A checkbox or radio must not be stretched to a 40px full-width
   box — the base reset above and the touch layer below both carve them out already; this rule did
   not, so any tick box placed inside a .field rendered several times its proper size.
   :where() keeps the carve-out at ZERO specificity, so .field input:focus still outranks this. */
.field input:where(:not([type="radio"], [type="checkbox"])), .field select {
  width: 100%; height: 40px; border-radius: var(--r-sm); border: 1px solid var(--border-2);
  background: var(--surface); padding: 0 12px; font-family: inherit; font-size: 14px; color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-softer); }
/* Themed inline input for compact form rows (FPE history detail, PE Others, referral feedback) —
   appearance only; layout (flex/min-width) comes from a local rule. Matches .field input so bare
   inputs in a row aren't left as raw native controls. */
.hx-in { height: 40px; border: 1px solid var(--border-2); border-radius: var(--r-sm); background: var(--surface); padding: 0 12px; font-family: inherit; font-size: 14px; color: var(--text); transition: border-color .12s, box-shadow .12s; }
.hx-in:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-softer); }
/* Shared checkbox + label affordance (was hand-rolled inline / used an undefined token). */
.chk { display: inline-flex; gap: 7px; align-items: center; font-size: 13px; color: var(--text); cursor: pointer; }
/* An option label INSIDE a .field is an option, not the field's caption. `.field label` (0,1,1)
   outranks `.chk` (0,1,0), so without this an option renders block, bold and muted with a 6px
   gap — the options stack instead of sitting in a row. Covers the FPE screens' option rows too. */
.field .chk, .field .yn label, .field .chkgrid label {
  display: inline-flex; gap: 7px; align-items: center; font-size: 13px; font-weight: 400;
  color: var(--text); margin-bottom: 0; cursor: pointer;
}
/* Option-row layouts referenced by the FPE assessment screen but never defined (the undefined-class
   bug this repo has shipped before): a yes/no pair, and a wrapping grid of checkboxes. */
.yn { display: inline-flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.chkgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 16px; }
/* Inline value/unit edit cell on the vitals card (edit-during-visit) — compact themed inputs. */
.vro-cell input { height: 34px; border: 1px solid var(--border-2); border-radius: var(--r-xs); background: var(--surface); padding: 0 8px; font-size: 14px; color: var(--text); transition: border-color .12s, box-shadow .12s; }
.vro-cell input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-softer); }
/* Typeahead suggestion dropdown (prescription formulary search) — replaces the unreliable native
   <datalist>; absolutely positioned under the .field search input (which is position:relative). */
.ta-menu { position: absolute; top: calc(100% + 3px); left: 0; right: 0; z-index: 30; max-height: 240px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r-sm); box-shadow: 0 8px 24px rgba(20, 34, 32, .12); padding: 4px; }
/* The dropdown extends BELOW its form. Inside a group card (.actgroup — the "add another" footer
   and the edit-in-place rows) the card's overflow:hidden (rounded-corner clipping) hid the results
   entirely (2026-07-03 bug: worked on the FIRST add — the empty-state chips sit outside any card —
   then never again). The search input's focus/blur handlers toggle .ta-open on the closest group,
   lifting the clipping only while the menu is open (transient ~2px corner-rounding loss). */
.actgroup.ta-open { overflow: visible; }
.ta-opt { display: block; width: 100%; text-align: left; padding: 7px 10px; border: none; background: none; border-radius: var(--r-xs); font-family: inherit; font-size: 13px; color: var(--text); cursor: pointer; }
.ta-opt:hover { background: var(--surface-2); }
.ta-empty { padding: 8px 10px; font-size: 12px; color: var(--text-3); }
/* SR4 E7: the prescription's WORKFLOW marker — where this script gets written, not a coverage
   verdict. Both read as quiet information, never as a warning: a GAMOT-App drug is perfectly
   prescribable, it is just written in the other app, so neither uses the danger hue (principle 3
   — this never gates). The typeahead row lays name and marker out on one line. */
.ta-opt { display: flex; align-items: center; gap: 8px; }
.ta-opt .ta-name { flex: 1 1 auto; min-width: 0; }
.rxch { flex: 0 0 auto; font-size: 10.5px; font-weight: 600; letter-spacing: .02em; padding: 1px 6px;
  border-radius: 999px; white-space: nowrap; margin-left: 6px; }
.rxch-konsulta { background: var(--primary-softer); color: var(--primary-800); }
.rxch-gamot_app { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border-2); }
.field-row { display: grid; gap: 12px; }
.field-row.c2 { grid-template-columns: 1fr 1fr; }
.field-row.c3 { grid-template-columns: 1.4fr 1fr 1fr; }
.form-section { font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); margin: 22px 0 12px; padding-bottom: 7px; border-bottom: 1px solid var(--border); }
.form-section:first-child { margin-top: 0; }

.callout { display: flex; gap: 11px; padding: 13px 15px; border-radius: var(--r); font-size: 12.5px; line-height: 1.5; }
.callout svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.callout.amber { background: var(--warn-soft); border: 1px solid var(--warn-line); color: #7a5006; }
.callout.blue { background: var(--info-soft); border: 1px solid var(--info-line); color: #1d4a7a; }
.callout b { font-weight: 600; }

.toggle-row { display: flex; align-items: center; gap: 12px; padding: 13px 15px; border: 1px solid var(--border-2); border-radius: var(--r); background: var(--surface-2); }
.toggle-row .tr-body { flex: 1; }
.toggle-row .tr-body b { font-size: 13px; font-weight: 600; display: block; }
.toggle-row .tr-body span { font-size: 11.5px; color: var(--text-3); }
.switch { width: 40px; height: 23px; border-radius: 99px; background: var(--border-strong); position: relative; flex: none; transition: background .15s; border: none; }
.switch.on { background: var(--primary); }
.switch i { position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch.on i { left: 19px; }

/* patient detail composition panels */
.pd-hero { display: flex; align-items: center; gap: 14px; padding-bottom: 18px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.pd-hero .pd-name { font-size: 19px; font-weight: 600; letter-spacing: -.02em; }
.pd-hero .pd-meta { font-size: 12.5px; color: var(--text-2); margin-top: 3px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.compose-panel { border: 1px solid var(--border); border-radius: var(--r); margin-bottom: 13px; overflow: hidden; }
.compose-head { display: flex; align-items: center; gap: 8px; padding: 9px 13px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.compose-head .src { margin-left: auto; font-size: 10px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); display: flex; align-items: center; gap: 5px; }
.compose-head h4 { font-size: 12.5px; font-weight: 600; }
.compose-head svg { width: 15px; height: 15px; color: var(--text-2); }
.compose-body { padding: 13px; }
/* Pencil edit affordance, upper-right of a panel header (uniform with the CRM): reveals that
   panel's form (read-only ⟷ form swap), toggled by .editing on the panel. */
.compose-head .edit-link {
  margin-left: 10px; color: var(--primary); cursor: pointer;
  display: inline-flex; align-items: center; opacity: .7; transition: opacity .12s;
}
.compose-head .edit-link:hover { opacity: 1; }
.compose-head .edit-link svg { width: 15px; height: 15px; color: var(--primary); }
.compose-panel .cp-form { display: none; }
.compose-panel.editing .cp-readonly { display: none; }
.compose-panel.editing .cp-form { display: block; }
[hidden] { display: none !important; }   /* reliable hide for JS-toggled conditional fields */

/* In-EMR record: brighten the profile boards (white) so an engaged patient doesn't read as a
   stale/registry-only record. The registry preview (no .emr-record) keeps the duller look. */
.emr-record .compose-panel { background: var(--surface); }
.emr-record .compose-head { background: var(--surface); }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 11px 16px; }
.kv .k { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.kv .v { font-size: 13px; font-weight: 500; margin-top: 1px; }
.ctx-flags { display: flex; flex-wrap: wrap; gap: 7px; }
.problem-row { display: flex; align-items: center; gap: 9px; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 12.5px; }
.problem-row:last-child { border: none; }
.problem-row .mono { color: var(--text-2); }
.problem-row .pr-name { font-weight: 500; flex: 1; }

/* divider / misc */
.hr { height: 1px; background: var(--border); margin: 18px 0; border: none; }
.muted { color: var(--text-3); }
.center-col { display: flex; flex-direction: column; }

/* small fade-up entrance */
@keyframes up { from { transform: translateY(8px); } to { transform: none; } }
.up { animation: up .3s cubic-bezier(.2,.8,.2,1) both; }
@media (prefers-reduced-motion: reduce) { .up { animation: none; } }

/* ============================================================
   WORK SURFACE (intake + encounter shared top bar)
   ============================================================ */
.work-top {
  display: flex; align-items: center; gap: 14px; flex: none;
  padding: 13px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.work-top .wt-id { min-width: 0; }
.work-top .wt-name { font-size: 16px; font-weight: 600; letter-spacing: -.01em; display: flex; align-items: center; gap: 9px; white-space: nowrap; }
/* SR4 essential 3 put age/birthday/PhilHealth on this strip. Dropping the encounter-id fragment
   keeps it to one line in the normal case, but a long barangay name on a tablet can still push it
   over — wrap rather than clip. */
.work-top .wt-meta { font-size: 12px; color: var(--text-3); margin-top: 1px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; row-gap: 2px; }
.work-top .wt-meta .mono { color: var(--text-2); }
.work-top .wt-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
/* B1/A2 added a fourth item (the chief complaint) to this strip. It is nowrap + overflow:hidden and
   only the LAST item may shrink, so the new item absorbed the entire shortfall and rendered at zero
   width at tablet portrait — the one form factor CLAUDE.md names for clinicians. Allow the row to
   WRAP instead of clipping: the complaint drops to a second line rather than disappearing. */
.enc-metabar { display: flex; align-items: center; gap: 8px 16px; padding: 9px 28px; background: var(--surface-2); border-bottom: 1px solid var(--border); flex: none; font-size: 12.5px; flex-wrap: wrap; }
.enc-metabar .emb-item { display: flex; align-items: center; gap: 6px; color: var(--text-2); white-space: nowrap; }
.enc-metabar .emb-item:last-child { min-width: 0; overflow: hidden; }
.enc-metabar .emb-item:last-child b { overflow: hidden; text-overflow: ellipsis; }
.enc-metabar .emb-item b { color: var(--text); font-weight: 600; }
.enc-metabar .emb-item svg { color: var(--text-3); }

/* ============================================================
   INTAKE
   ============================================================ */
.intake-wrap { max-width: 940px; margin: 0 auto; }
.patient-banner {
  display: flex; align-items: center; gap: 14px; padding: 13px 16px; margin-bottom: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-1);
}
.patient-banner .pb-name { font-size: 15px; font-weight: 600; }
.patient-banner .pb-meta { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.patient-banner .pb-flags { margin-left: auto; display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }

.sect { margin-bottom: 18px; }
.sect-head { display: flex; align-items: center; gap: 9px; margin-bottom: 13px; }
.sect-head .sh-n { width: 22px; height: 22px; border-radius: 6px; background: var(--primary-soft); color: var(--primary-800); display: grid; place-items: center; font-size: 12px; font-weight: 700; font-family: var(--mono); flex: none; }
.sect-head h3 { font-size: 14.5px; font-weight: 600; white-space: nowrap; }
.sect-head .sh-opt { margin-left: auto; font-size: 11.5px; color: var(--text-3); text-align: right; }

.type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 11px; }
@media (max-width: 720px) { .type-grid { grid-template-columns: repeat(2, 1fr); } }
.type-card {
  display: flex; gap: 11px; align-items: flex-start; padding: 13px 14px; cursor: pointer;
  border: 1.5px solid var(--border-2); border-radius: var(--r); background: var(--surface);
  transition: border-color .12s, background .12s, box-shadow .12s; position: relative;
}
.type-card:hover { border-color: var(--primary-line); background: var(--primary-softer); }
.type-card.sel { border-color: var(--primary); background: var(--primary-softer); box-shadow: 0 0 0 3px var(--primary-softer); }
.type-card .tc-ic { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; flex: none; color: #fff; }
.type-card .tc-body b { font-size: 13.5px; font-weight: 600; display: block; }
.type-card .tc-body span { font-size: 11.5px; color: var(--text-3); }
.type-card .tc-check { position: absolute; top: 10px; right: 10px; color: var(--primary); opacity: 0; transition: opacity .12s; }
.type-card.sel .tc-check { opacity: 1; }

textarea.cc {
  width: 100%; min-height: 76px; border-radius: var(--r-sm); border: 1px solid var(--border-2);
  padding: 11px 13px; font-family: inherit; font-size: 14px; color: var(--text); resize: vertical; line-height: 1.5;
}
textarea.cc:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-softer); }
textarea.cc::placeholder { color: var(--text-3); }

.vitals-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 720px) { .vitals-grid { grid-template-columns: repeat(2, 1fr); } }
.vital-cell label { font-size: 11.5px; font-weight: 600; color: var(--text-2); display: flex; justify-content: space-between; margin-bottom: 6px; }
.vital-cell label .unit { color: var(--text-3); font-weight: 500; }
.vital-cell input {
  width: 100%; height: 42px; border: 1px solid var(--border-2); border-radius: var(--r-sm);
  padding: 0 12px; font-family: var(--mono); font-size: 15px; color: var(--text); background: var(--surface);
  transition: border-color .12s, box-shadow .12s;
}
.vital-cell input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-softer); }
.vital-cell.flag input { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.vital-cell .flag-note { font-size: 11px; color: var(--danger); font-weight: 600; margin-top: 4px; display: flex; align-items: center; gap: 4px; }

.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--r-sm); border: 1px solid var(--border); }
.seg button { flex: 1; border: none; background: none; padding: 8px 10px; border-radius: 6px; font-weight: 600; font-size: 13px; color: var(--text-2); transition: all .1s; }
.seg button.on { background: var(--surface); box-shadow: var(--sh-1); color: var(--text); }
.seg button.on.urgent { color: var(--warn); }
.seg button.on.emergency { color: var(--danger); }

.action-bar {
  position: sticky; bottom: 0; margin: 22px -28px -40px; padding: 15px 28px;
  background: rgba(255,255,255,.92); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); display: flex; align-items: center; gap: 12px; z-index: 3;
}
.action-bar .ab-summary { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 7px; }
.action-bar .ab-right { margin-left: auto; display: flex; gap: 10px; }

/* ============================================================
   ENCOUNTER CANVAS
   ============================================================ */
.enc-body { flex: 1; overflow-y: auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 344px; gap: var(--gap); padding: 22px 28px 60px; align-items: start; }
@media (max-width: 1080px) { .enc-body { grid-template-columns: 1fr; } }
.enc-main { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.enc-rail { display: flex; flex-direction: column; gap: var(--gap); }

.vitals-readout { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); border-radius: var(--r); overflow: hidden; border: 1px solid var(--border); }
.vro-cell { background: var(--surface); padding: 11px 13px; }
.vro-cell .vk { font-size: 10.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-3); font-weight: 600; }
.vro-cell .vv { font-family: var(--mono); font-size: 17px; font-weight: 600; margin-top: 3px; }
.vro-cell .vv small { font-size: 11px; color: var(--text-3); font-weight: 500; margin-left: 2px; }
.vro-cell.flag { background: var(--danger-soft); }
/* SR4 add-on 4: the derived BMI cell. Tinted to read as computed rather than measured — nobody
   typed it, and there is no pencil on it. The class colours are informative only (principle 3):
   amber for the ends of the range, primary for normal, never red, because a BMI is not an alarm. */
.vro-cell.vro-derived { background: var(--surface-2); }
.vro-cell .vro-note { font-size: 11px; margin-top: 3px; color: var(--text-3); font-weight: 500; }
.vro-cell .vro-note.bmi-normal { color: var(--primary-800); }
.vro-cell .vro-note.bmi-underweight,
.vro-cell .vro-note.bmi-overweight { color: var(--warn); }
.vro-cell .vro-note.bmi-obese1,
.vro-cell .vro-note.bmi-obese2 { color: var(--warn); font-weight: 600; }
/* WHO growth-chart bands (SR4 A4). These keys are the PAEDIATRIC set and only 'normal' and
   'overweight' overlap the adult one above — without these rules a "Severely wasted" child
   rendered in default grey, visually quieter than an adult's "Obese I". The two severe bands are
   the strongest treatment on the card, because they are the ones that need acting on today. */
.vro-cell .vro-note.bmi-risk_of_overweight,
.vro-cell .vro-note.bmi-thinness,
.vro-cell .vro-note.bmi-wasted { color: var(--warn); }
.vro-cell .vro-note.bmi-obese { color: var(--warn); font-weight: 600; }
.vro-cell .vro-note.bmi-severely_wasted,
.vro-cell .vro-note.bmi-severe_thinness { color: var(--danger); font-weight: 600; }
.vro-cell.flag .vv { color: var(--danger); }

.addbar { display: flex; flex-wrap: wrap; gap: 8px; }
.addbar button {
  display: flex; align-items: center; gap: 7px; padding: 9px 13px; border-radius: var(--r-sm);
  border: 1px dashed var(--border-strong); background: var(--surface); font-weight: 600; font-size: 12.5px; color: var(--text-2);
  transition: all .12s;
}
.addbar button:hover { border-style: solid; border-color: var(--primary); color: var(--primary-800); background: var(--primary-softer); }
.addbar button svg { width: 15px; height: 15px; }

/* Visit activities grouped by type: one card per type, header+count once, compact rows inside. */
.actgroups { display: flex; flex-direction: column; gap: 11px; }
.actgroup { border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); overflow: hidden; position: relative; box-shadow: var(--sh-1); }
.actgroup .a-accent { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
.actgroup-head { display: flex; align-items: center; gap: 11px; padding: 9px 14px 9px 17px; border-bottom: 1px solid var(--border); }
.actgroup-head .a-ic { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; flex: none; }
.actgroup-head .a-title b { font-size: 13px; font-weight: 600; }
.actgroup-head .ag-count { margin-left: auto; min-width: 22px; height: 20px; padding: 0 7px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 11.5px; font-weight: 600; display: grid; place-items: center; }
.ag-rows { display: flex; flex-direction: column; }
.ag-row { display: flex; align-items: center; gap: 10px; padding: 8px 16px 8px 17px; min-height: 40px; border-top: 1px solid var(--border); }
.ag-row:first-child { border-top: none; }
.ag-row-block { align-items: stretch; }
.ag-main { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; font-size: 13.5px; flex: 1 1 auto; min-width: 0; }
.ag-main.ag-col { flex-direction: column; align-items: stretch; gap: 6px; }
.ag-sub { font-size: 12px; color: var(--text-2); }
/* SR4 add-on 3: free-text sub-lines a clinician typed with line breaks (lab special
   instructions) keep them; the bare .ag-sub stays collapsing for one-line labels. */
.ag-sub-pre { white-space: pre-line; }
.ag-who { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-3); white-space: nowrap; flex: none; }
.ag-row > .ag-who { margin-left: auto; }
.ag-who-block { margin-top: 2px; }
/* SR4 add-on 3: staff type lab results LINE PER LINE and they came back as one paragraph. The
   newlines were never lost — they are in the database — HTML was collapsing them on display.
   `pre-line` (not `pre-wrap`) restores exactly what was typed while still wrapping long lines to
   the column, so figures entered in a column stay in a column. */
/* SR4 essential 4: Visit history rows that expand in place. Closed, a row is one line and reads
   exactly like the problem-row it replaced; open, it reveals that visit's recap without ever
   navigating away from the visit the clinician is in the middle of. */
.vh-item > summary { list-style: none; cursor: pointer; }
.vh-item > summary::-webkit-details-marker { display: none; }
.vh-summary { position: relative; padding-right: 22px; }
.vh-summary::after { content: ""; position: absolute; right: 7px; top: 50%; width: 6px; height: 6px;
  border-right: 1.5px solid var(--text-3); border-bottom: 1.5px solid var(--text-3);
  transform: translateY(-70%) rotate(45deg); transition: transform .15s; }
.vh-item[open] > .vh-summary::after { transform: translateY(-30%) rotate(-135deg); }
.vh-item[open] > .vh-summary { background: var(--surface-2); }
.vh-body { padding: 2px 0 12px 74px; }
@media (max-width: 900px) { .vh-body { padding-left: 8px; } }
.vh-recap { display: grid; gap: 7px; }
.vh-line { display: grid; grid-template-columns: 96px 1fr; gap: 10px; font-size: 12.5px; align-items: start; }
.vh-line .vh-k { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3); padding-top: 2px; }
/* Past notes keep the line breaks the clinician typed, same as the live note (add-on 3). */
.vh-line .vh-v { white-space: pre-line; line-height: 1.5; min-width: 0; }
.vh-open { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--primary-800);
  text-decoration: none; margin-top: 4px; }
.soap-grid { display: grid; gap: 15px; }
.soap-grid > div + div { border-top: 1px solid var(--border); padding-top: 13px; }
.soap-grid .sg-k { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
.soap-grid .sg-v { font-size: 13px; margin-top: 3px; white-space: pre-line; line-height: 1.55; }
/* In-board "add another" footer: the add action lives inside the board, where the new row lands. */
.ag-add { border-top: 1px solid var(--border); }
.ag-add > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 7px; padding: 9px 16px 9px 17px; font-size: 12.5px; font-weight: 600; color: var(--primary-800); background: var(--primary-softer); }
.ag-add > summary::-webkit-details-marker { display: none; }
.ag-add > summary:hover { background: var(--primary-soft); }
.ag-add[open] > summary { border-bottom: 1px solid var(--border); }
.ag-add svg, .ag-newchip svg { flex: none; }
.ag-form { padding: 12px 16px 14px 17px; }
/* Closing row to start a type not yet on the visit; an open chip expands full-width to show its form. */
.ag-newrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 13px; padding: 11px 13px; border: 1px dashed var(--border-2); border-radius: var(--r); background: var(--surface); }
.ag-newrow .ag-newlabel { font-size: 12px; font-weight: 600; color: var(--text-3); margin-right: 2px; }
.ag-newchip > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; padding: 6px 11px; font-size: 12.5px; font-weight: 600; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; white-space: nowrap; }
.ag-newchip > summary::-webkit-details-marker { display: none; }
.ag-newchip > summary:hover { background: var(--surface-3); }
.ag-newchip[open] { flex: 1 0 100%; }
.ag-newchip[open] > summary { background: var(--primary-soft); color: var(--primary-800); border-color: var(--primary-line); margin-bottom: 11px; }
.ag-newchip .ag-form { padding: 0; }

.summary-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.summary-row:last-child { border: none; }
.summary-row .sr-l { display: flex; align-items: center; gap: 9px; color: var(--text-2); }
.summary-row .sr-l svg { color: var(--text-3); }
.summary-row .sr-c { font-family: var(--mono); font-weight: 600; font-size: 13px; }
.summary-row .sr-c.zero { color: var(--text-3); font-weight: 500; }

.glance-list { display: flex; flex-direction: column; gap: 9px; }
.glance-list .gl-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.glance-list .gl-row .mono { color: var(--text-2); margin-left: auto; }

.add-pop { position: relative; }
.add-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 6; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r); box-shadow: var(--sh-pop); padding: 6px;
  animation: up .16s ease both;
}
.add-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: none; background: none; border-radius: var(--r-xs); font-size: 13px; font-weight: 500; color: var(--text); text-align: left; }
.add-menu button:hover { background: var(--surface-2); }
.add-menu button .am-ic { width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; flex: none; }

/* ============================================================
   Patients split-screen (master/detail): left = search results, right = profile/preview
   ============================================================ */
.patients-split { flex: 1; display: flex; min-height: 0; overflow: hidden; }
.ps-left {
  width: 416px; flex: none; min-width: 0;
  border-right: 1px solid var(--border); background: var(--surface);
  overflow-y: auto; padding: 22px 22px 40px;
}
.ps-right { flex: 1; min-width: 0; overflow-y: auto; padding: 24px 30px 48px; }
.ps-right .pd-hero, .ps-right .compose-panel, .ps-right .card { max-width: 760px; }
.ps-left .res-right { display: none; }              /* the whole card is clickable in split mode */
.ps-left .res-card { padding: 11px 13px; }
.ps-left .scope-banner { margin-bottom: 12px; }
.res-card { cursor: pointer; }
.res-card.sel {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-softer);
  background: var(--primary-softer);
}
.ps-placeholder { text-align: center; padding: 56px 24px; color: var(--text-3); max-width: 430px; margin: 36px auto 0; }
.ps-placeholder .es-ic { width: 60px; height: 60px; border-radius: 17px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; margin: 0 auto 16px; color: var(--text-3); }
.ps-placeholder h3 { font-size: 16px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.ps-placeholder p { font-size: 13px; line-height: 1.5; }
@media (max-width: 1000px) {
  .patients-split { flex-direction: column; overflow-y: auto; }
  .ps-left { width: auto; flex: none; border-right: none; border-bottom: 1px solid var(--border); overflow: visible; }
  .ps-right { overflow: visible; }
}

/* social-context / sectoral chip strip (Senior Citizen / PWD / Solo Parent / 4Ps / Indigent / OFW) */
.social-strip { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 14px; }
.social-strip:empty { display: none; }

/* active state for the touch-mode toggle (ctxbar) */
.iconbtn.on { background: var(--primary-soft); color: var(--primary-800); border-color: var(--primary-line); }

/* ============================================================
   PORTRAIT TABLETS / NARROW WINDOWS  (CLAUDE.md §6(f))
   Force the icon-only rail so clinical content gets the width. Mirrors the
   html.nav-collapsed rules but keyed on viewport, so it overrides a saved
   "expanded" preference below this width. The chevron is hidden here — width
   owns the layout, not the toggle.
   ============================================================ */
@media (max-width: 900px) {
  .app.lay-sidebar { grid-template-columns: var(--rail-w-compact) 1fr; }
  .lay-sidebar .nav-group-label { text-align: center; padding: 12px 0 5px; font-size: 9px; }
  .lay-sidebar .nav-item { justify-content: center; padding: 11px 0; }
  .lay-sidebar .nav-item span.label { display: none; }
  .lay-sidebar .nav-item .badge-dot { position: absolute; top: 6px; right: 12px; margin: 0; }
  .lay-sidebar .nav-item.active::before { left: 0; }
  .lay-sidebar .staff-meta,
  .lay-sidebar .nav-brand .brand-text,
  .lay-sidebar .nav-brand .brand-mark { display: none; }
  .lay-sidebar .nav-brand { justify-content: center; padding: 0; }
  .lay-sidebar .nav-collapse-btn { display: none; }
  .lay-sidebar .staff-chip { justify-content: center; }
  /* the date's second line (full date) is redundant once space is tight; keep the day + clock */
  .ctxbar .date-block span { display: none; }
}

/* ============================================================
   TABLET / TOUCH LAYER  (CLAUDE.md §6(f) — clinicians work on tablets)
   Enabled by html.touch: auto-set from pointer:coarse in base.html, forced
   on/off by the ctxbar toggle. Bigger tap targets (≥44px), 16px inputs (so
   iOS Safari does not zoom on focus), visible-not-hover affordances, and
   :active feedback (hover does not fire on touch) — without disturbing the
   dense desktop build reception/encoders use. Width-independent: a tablet in
   landscape still gets the touch treatment.
   ============================================================ */
html.touch, html.touch * { -webkit-tap-highlight-color: transparent; }
html.touch { --row-pad: 14px; }

/* primary controls → ≥44px */
html.touch .btn { height: 44px; padding: 0 18px; }
html.touch .btn-sm { height: 40px; padding: 0 14px; font-size: 13px; }
/* !important: the per-entry edit/delete pencils carry inline width/height (24-28px) that otherwise
   win over this rule, leaving the headline edit-during-visit affordance below the 44px tap target. */
html.touch .iconbtn { width: 44px !important; height: 44px !important; }
html.touch .ta-opt { min-height: 44px; padding: 11px 12px; }
html.touch .nav-collapse-btn { width: 40px; height: 40px; }
html.touch .q-go { width: 40px; height: 40px; }
html.touch .clinic-flow .qrow,
html.touch .clinic-flow .qhead { grid-template-columns: auto minmax(0, 1fr) 138px 72px 40px; }

/* nav items roomier */
html.touch .nav-item { padding: 12px 12px; font-size: 14px; }
html.touch .topnav .nav-item { padding: 11px 14px; }

/* Register-form name inputs LOOK uppercase as the encoder types (Sprint Review 3).
   Display-only: text-transform never changes the submitted value; stored case is as typed
   (MPI identity stays consistent with the CRM — Nikko 2026-07-09). */
.caps-input { text-transform: uppercase; }

/* FPE editable immunization history (Sprint Review 3 item 1A) */
.imm-grid { display: flex; flex-direction: column; gap: 4px; }
.imm-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 3px 0; font-size: 12.5px; }
.imm-name { min-width: 260px; }
.imm-doses { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
/* appearance comes from the baseline theme above; here just keep the date box compact + bounded */
.imm-doses input[type=date] { max-width: 150px; padding: 5px 8px; font-size: 13px; }
html.touch .imm-doses input[type=date] { font-size: 15px; }

/* FPE visual-acuity grid (Sprint Review 3 item 4) */
.va-grid { border-collapse: collapse; font-size: 12.5px; min-width: 480px; }
.va-grid th, .va-grid td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.va-grid thead th { background: var(--surface-2); font-weight: 600; font-size: 11.5px; }
.va-grid tbody th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.va-grid td input { width: 110px; }
.va-grid .muted { font-weight: 400; font-size: 10px; }

/* RHU lab-request checkbox panel (Sprint Review 3 item 6) */
.lab-panel { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px 18px; }
.lab-cat-h { font-size: 10.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: 5px; }
.lab-cat .chk { display: flex; gap: 7px; align-items: center; font-size: 12.5px; padding: 2.5px 0; cursor: pointer; }
/* SR4 E2b: the YAKAP coverage marker. A quiet asterisk with a legend, not a badge — coverage is
   guidance at the point of ordering and must never read as a gate (principle 3).
   NORMAL weight on purpose: at 700 the arms merge into a filled blob at this size instead of
   reading as an asterisk. Mono keeps the arms distinct and evenly spaced. */
.yk { color: var(--primary); font-family: var(--mono); font-weight: 400; margin-left: 2px; }
/* SR4: a grouped panel entry — one test that reveals its variants when ticked (OGTT loads, chest
   X-ray views, ultrasound regions). The parent is a disclosure; the variants are the real choices,
   indented under it with a rule so the nesting reads at a glance. */
.lab-group { display: block; }
.lab-sub { display: none; margin: 2px 0 4px 9px; padding-left: 10px; border-left: 2px solid var(--border-2); }
.lab-group.open .lab-sub { display: block; }
.lab-sub .chk { display: flex; gap: 7px; align-items: center; font-size: 12.5px; padding: 2.5px 0; cursor: pointer; }
/* SR4 E2a: ONE destination control for the whole request, sat below the panel with the legend. */
.lab-foot { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: flex-start;
  justify-content: space-between; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.lab-legend { font-size: 11.5px; color: var(--text-3); }
.lab-where { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-top: 2px; }

/* Show/Hide password toggle (Sprint Review 3) */
.pwd-wrap { position: relative; }
.pwd-wrap input { padding-right: 58px; }
.pwd-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--primary-800); font: inherit; font-size: 12px;
  font-weight: 600; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.pwd-eye:hover { background: var(--surface-2); }

/* form controls: tall + font ≥16px to stop iOS focus-zoom. Radios/checkboxes are EXEMPT —
   the 48px height blew them up into giant circles/boxes on tablets (Sprint Review 3: "reduce
   the size of the checkboxes"); they get a moderate bump below, and the ≥44px tap target
   comes from the label row around them, not the control itself. */
html.touch .field input:not([type=radio]):not([type=checkbox]), html.touch .field select { height: 48px; font-size: 16px; }
html.touch input[type=radio], html.touch input[type=checkbox] { width: 20px; height: 20px; flex-shrink: 0; }
html.touch textarea.cc { font-size: 16px; }
html.touch .vital-cell input { height: 50px; font-size: 17px; }
html.touch .gsearch input { height: 46px; font-size: 16px; }

/* the "go" chevron has no hover on touch — show it in its actionable state by default */
html.touch .q-go { background: var(--primary-soft); color: var(--primary-800); border-color: var(--primary-line); }
html.touch .qfilter button { padding: 9px 14px; }

/* edit pencil: always visible (no hover reveal) with a real hit area */
html.touch .compose-head .edit-link { opacity: 1; padding: 6px; margin: -6px -6px -6px 4px; }
html.touch .compose-head .edit-link svg { width: 18px; height: 18px; }

/* add / menu / segmented / switch affordances */
html.touch .addbar button { padding: 12px 15px; font-size: 13px; }
html.touch .ag-row { min-height: 46px; }
html.touch .ag-add > summary { padding-top: 13px; padding-bottom: 13px; }
html.touch .ag-newchip > summary { padding: 10px 14px; }
html.touch .ag-newrow { gap: 10px; }
html.touch .add-menu button { padding: 12px 12px; }
html.touch .seg button { padding: 11px 12px; }
html.touch .switch { width: 48px; height: 28px; }
html.touch .switch i { width: 24px; height: 24px; }
html.touch .switch.on i { left: 22px; }

/* keyboard shortcut hint is noise without a physical keyboard */
html.touch .gsearch .kbd { display: none; }

/* tap feedback, since :hover is unreliable/sticky on touch */
html.touch .btn-pri:active { background: var(--primary-700); }
html.touch .qrow:active,
html.touch .wl-item:active,
html.touch .nav-item:active,
html.touch .res-card:active,
html.touch .type-card:active,
html.touch .add-menu button:active,
html.touch .addbar button:active { background: var(--surface-2); }

/* ============================================================
   FPE LIVING-BASELINE PANEL (patient view / encounter rail / intake)
   Plain, readable read-back of the latest FPE — no alert chips, no suggested actions.
   ============================================================ */
.baseline { font-size: 13px; }
.baseline .bl-when { display: flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.baseline .bl-when svg { width: 13px; height: 13px; color: var(--text-3); }
.baseline .kv { margin-top: 10px; }
.baseline .bl-row { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.baseline .bl-row:last-child { border-bottom: none; }
.baseline .bl-k { font-size: 10.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; flex: none; width: 90px; padding-top: 1px; }
.baseline .bl-v { font-size: 12.5px; flex: 1; min-width: 0; line-height: 1.5; }
.baseline .bl-v b { font-weight: 600; }

/* SR4 A6: the FPE recovery-draft stamp. Wording and tone both matter — it must read as "held, not
   saved", because only the Save FPE profile button writes the patient's record. Muted, never the
   success colour, so it is not mistaken for a confirmation. */
.draft-state { font-size: 11.5px; color: var(--text-3); opacity: 0; transition: opacity .15s; }
.draft-state.is-on { opacity: 1; }

/* ---- SR4 E6: logbook report generator ------------------------------------------------------
   A report is a dense table people read across, so it gets real table styling rather than the
   .qrow card idiom used elsewhere — a logbook column has to line up with the one above it. */
.rpt-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; padding: 0 2px 12px; }
.rpt-wrap { overflow-x: auto; }                 /* wide logbooks scroll rather than squeezing */
.rpt { width: 100%; border-collapse: collapse; font-size: 13px; }
.rpt th, .rpt td { padding: 8px 10px; text-align: left; vertical-align: top;
                   border-bottom: 1px solid var(--border); }
.rpt th { font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
          color: var(--text-2); background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
.rpt tbody tr:hover { background: var(--surface-2); }
.rpt td:first-child { white-space: nowrap; }    /* the date column never wraps mid-date */
.rpt-held { display: flex; flex-direction: column; gap: 2px; padding: 9px 2px;
            border-bottom: 1px solid var(--border); font-size: 12.5px; }
.rpt-held:last-child { border-bottom: none; }

/* Print. The app chrome (sidebar, top bar, buttons) is screen furniture; a printed logbook page
   should be the table and a header saying which report, which unit and which dates it covers.
   `.print-only` is hidden on screen and shown here, `.no-print` the reverse. */
.print-only { display: none; }
.rpt-printhead { font-size: 12px; padding: 0 2px 10px; }
@media print {
  .sidebar, .topbar, .no-print, .test-banner { display: none !important; }
  .print-only { display: block; }
  .page, .page-wide, .app, .main { margin: 0 !important; padding: 0 !important;
                                   overflow: visible !important; height: auto !important; }
  .card { border: none !important; box-shadow: none !important; padding: 0 !important; }
  .rpt-wrap { overflow: visible !important; }
  .rpt { font-size: 10.5px; }
  .rpt th { background: none; border-bottom: 1.5px solid #000; position: static; }
  .rpt th, .rpt td { padding: 4px 6px; }
  .rpt tr { break-inside: avoid; }              /* never split a logbook row across pages */
  .rpt thead { display: table-header-group; }   /* repeat the headings on every printed page */
  body { background: #fff !important; }
  @page { margin: 12mm; }
}

/* Facility checklist on the report generator (SR4 E6). 15 sites, so it needs to be a compact grid
   rather than a column — the whole control should cost one glance, not a scroll. */
.rpt-facs { border-top: 1px solid var(--border); padding: 10px 2px 2px; }
.rpt-facs-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.rpt-facs-head label { font-size: 11.5px; font-weight: 600; text-transform: uppercase;
                       letter-spacing: .03em; color: var(--text-2); }
.rpt-facs-acts { margin-left: auto; display: flex; gap: 4px; }
.rpt-facs-grid { display: grid; gap: 2px 14px;
                 grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.rpt-fac { font-size: 12.5px; }
.rpt-open { width: 1%; white-space: nowrap; text-align: right; }


/* ---- Send feedback (docs/feedback-spec.md) ---------------------------------------------------- */
.fb-pop { position: fixed; left: 14px; bottom: 14px; z-index: 45; width: 440px; max-width: calc(100vw - 28px); }
.fb-card { background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r-lg);
  box-shadow: var(--sh-pop); animation: fbup .18s ease-out; }
@keyframes fbup { from { transform: translateY(6px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .fb-card { animation: none; } }
.fb-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.fb-head h3 { font-size: 14px; font-weight: 600; flex: 1; }
.fb-x { border: none; background: none; color: var(--text-3); padding: 4px; border-radius: 6px; display: grid; place-items: center; }
.fb-x:hover { background: var(--surface-2); color: var(--text); }
.fb-body { padding: 14px 16px; display: grid; gap: 12px; max-height: calc(100vh - 180px); overflow-y: auto; }
.fb-body .field { margin: 0; }
.fb-body .hx-in { width: 100%; }
.fb-body textarea.hx-in { height: auto; padding: 9px 11px; resize: vertical; line-height: 1.4; }
.fb-stamp { background: var(--primary-softer); border: 1px solid var(--primary-line); border-radius: var(--r-sm); padding: 9px 11px; display: grid; gap: 2px; }
.fb-stamp-k { font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--primary-800); }
.fb-stamp-v { font-size: 13px; }
.fb-stamp-m { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); word-break: break-all; }
.fb-seg { display: grid; grid-template-columns: 1fr 1fr; }   /* 2×2: the full wording fits a tablet */
.fb-seg label { display: block; position: relative; }
.fb-seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.fb-seg span { display: block; text-align: center; padding: 8px 6px; border-radius: 6px; font-weight: 600; font-size: 12.5px; color: var(--text-2); cursor: pointer; }
.fb-seg input:checked + span { background: var(--surface); box-shadow: var(--sh-1); color: var(--primary-800); }
.fb-seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 1px; }
.fb-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.fb-foot small { font-size: 11.5px; }
.fb-acts { display: flex; gap: 8px; flex: none; }
.fb-sent-ok { width: 26px; height: 26px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-800); display: grid; place-items: center; flex: none; }
.nav-foot button.nav-item { cursor: pointer; font-family: inherit; }
html.touch .fb-seg span { padding: 11px 6px; }

/* inbox */
.fb-filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.fb-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-right: 8px; }
.fb-chip { height: 30px; padding: 0 11px; border-radius: 15px; border: 1px solid var(--border-2); background: var(--surface); font-size: 12.5px; font-weight: 500; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; font-family: inherit; }
.fb-chip .n { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
.fb-chip.on { background: var(--primary-soft); border-color: var(--primary-line); color: var(--primary-800); font-weight: 600; }
.fb-chip.on .n { color: var(--primary-800); }
.fb-tbl td { vertical-align: top; }
.fb-title a { color: inherit; text-decoration: none; }
.fb-title a:hover b { text-decoration: underline; text-underline-offset: 2px; }
.fb-title b { font-weight: 600; display: block; }
.fb-title span { color: var(--text-3); font-size: 12px; display: block; max-width: 46ch; }
.fb-m { font-size: 11.5px; color: var(--text-2); white-space: nowrap; }
.fb-who b { font-weight: 500; display: block; } .fb-who span { color: var(--text-3); font-size: 12px; }
.fb-unread .fb-title b::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--info); margin-right: 7px; vertical-align: middle; }
.fb-st { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.fb-st::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.fb-st-new { color: var(--info); } .fb-st-triaged { color: var(--warn); } .fb-st-planned { color: var(--violet); }
.fb-st-done { color: var(--ok); } .fb-st-wont_fix { color: var(--text-3); }
.fb-cat-wrong { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-line); }
.fb-cat-missing { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.fb-cat-suggestion { background: var(--info-soft); color: var(--info); border-color: var(--info-line); }
.fb-cat-other { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }

/* item */
.fb-detail { display: grid; grid-template-columns: 1fr 320px; gap: 14px; align-items: start; }
@media (max-width: 900px) { .fb-detail { grid-template-columns: 1fr; } }
.fb-detail .field textarea, .fb-detail .field select { width: 100%; }
.fb-kv { display: grid; grid-template-columns: 110px 1fr; gap: 7px 12px; font-size: 13px; margin: 0; }
.fb-kv dt { color: var(--text-3); font-weight: 500; } .fb-kv dd { margin: 0; }
.fb-kv a { color: var(--primary-800); text-decoration: underline; text-underline-offset: 2px; }
.fb-lbl { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); margin-bottom: 4px; }
.fb-prose { white-space: pre-wrap; font-size: 13.5px; line-height: 1.5; overflow-wrap: anywhere; }
.fb-audit { font-size: 12px; color: var(--text-3); border-top: 1px dashed var(--border-2); padding-top: 10px; display: grid; gap: 3px; }
