/* Homoeo Health Care — v1.2 styles
 * Palette: aqua / green / blue / white. No dark colors.
 */

:root {
  --bg: #f0fafa;
  --bg-card: #ffffff;
  --bg-soft: #e8f5f5;
  --border: #cfe6e4;
  --border-strong: #a9d4d0;

  --text: #1a3a52;
  --text-muted: #4a6b80;
  --text-soft: #7a95a8;

  --green: #2e7d6b;
  --green-soft: #4caf97;
  --aqua: #4dd0c9;
  --aqua-soft: #a3e4e0;
  --blue: #4a90e2;
  --blue-soft: #bcd7f5;

  --warn: #d88a3a;
  --warn-soft: #fbe8cf;
  --danger: #c45c5c;
  --danger-soft: #f5d7d7;

  --ff: #b77fd1;       /* family & friends accent (soft purple fits palette) */
  --ff-soft: #ecd9f5;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(30, 80, 90, 0.06);
  --shadow-md: 0 4px 14px rgba(30, 80, 90, 0.10);
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  /* Use --bg-soft so the page bg matches the iOS PWA safe-area tint.
     iOS applies a subtle blur/darken behind the status-bar zone; with
     --bg (#f0fafa) the tinted result was visibly darker than the rest
     of the page (the boundary was sharp). --bg-soft (#e8f5f5) IS what
     iOS produces from --bg, so safe-area and page now match. The drawer
     header (also --bg-soft) was the proof — it matched the safe area
     perfectly while open. */
  background: var(--bg-soft);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  /* viewport-fit=cover extends the page under the iOS PWA safe area; add the
     safe-area insets to padding so content isn't hidden under the status bar
     or home indicator. Body bg paints into the safe area zones too — exactly
     what we want, since iOS ignores theme-color on this device. */
  padding: calc(18px + env(safe-area-inset-top, 0px))
           calc(18px + env(safe-area-inset-right, 0px))
           calc(18px + env(safe-area-inset-bottom, 0px))
           calc(18px + env(safe-area-inset-left, 0px));
}

/* ─── Headings ─── */

h2, h3, h4 {
  color: var(--text);
  font-weight: 600;
  margin: 0 0 10px;
}

h2 { font-size: 22px; letter-spacing: 0.2px; }
h3 { font-size: 18px; }
h4 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); margin-top: 18px; }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

p { margin: 8px 0; }
em { font-style: normal; color: var(--text-muted); }
strong { font-weight: 600; }
small { color: var(--text-soft); }

/* ─── App header ─── */

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.app-header img.logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: var(--shadow-sm);
  background: #fff;
}

.app-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.app-header .version {
  font-size: 11px;
  color: var(--text-soft);
  font-weight: normal;
  margin-left: 4px;
}

.app-version-line {
  font-size: 11px;
  color: var(--text-soft);
  margin-bottom: 4px;
}

/* Wrapper that pairs the user name with the Logout button so they stay on
   the same line — on desktop it sits to the right of the spacer; on phone
   the mobile rule forces it to wrap onto its own row. */
.app-header-user {
  display: flex;
  align-items: center;
  gap: 12px;
}
.app-header-user #user-info { margin: 0; }

/* Always-visible "Update" button — a small round refresh (↻) icon in the
   header. Matches the round back-to-top buttons: green disc, white glyph, soft
   shadow. On click the glyph spins (.spinning) to signal work in progress. */
.sw-update-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(46, 125, 107, 0.3);
  flex: 0 0 auto;
}
.sw-update-btn:hover:not(:disabled) { background: var(--green-soft); }
.sw-update-btn:active:not(:disabled) { transform: scale(0.94); }
.sw-update-btn:disabled { cursor: default; }
.sw-update-glyph {
  display: block;
  font-size: 19px;
  line-height: 1;
  /* nudge the glyph optically centred */
  transform: translateY(-0.5px);
}
/* Spin while checking / applying an update. */
.sw-update-btn.spinning .sw-update-glyph {
  animation: sw-update-spin 0.8s linear infinite;
}
@keyframes sw-update-spin { to { transform: rotate(360deg); } }

/* Connection status dot in the header. Green = connected, amber = writes
 * parking, red = offline. Click for details (handled in connection.js). */
.conn-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-left: 8px;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.15);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.6);
  transition: background-color 0.2s;
}
.conn-dot.conn-green { background-color: #2ecc71; }
.conn-dot.conn-amber { background-color: #f39c12; }
.conn-dot.conn-red   { background-color: #e74c3c; }

/* Reconnect banner — two states.
   Default (orange):  writes draining or realtime catching up.
   .offline (red):    network truly down. */
.reconnect-banner {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: 6px;
  padding: 10px 14px;
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}
.reconnect-banner::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--warn);
  border-top-color: transparent;
  border-radius: 50%;
  animation: reconnect-spin 1s linear infinite;
  flex-shrink: 0;
}
.reconnect-banner.offline {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
}
.reconnect-banner.offline::before {
  /* Static dot, no spinner — we're not actively syncing. */
  border-color: var(--danger);
  border-top-color: var(--danger);
  animation: none;
  background: var(--danger);
  border-radius: 50%;
}
@keyframes reconnect-spin {
  to { transform: rotate(360deg); }
}

/* Small pill rendered inside the reconnecting message for the pending-write
   count. Reads as a separated chip without breaking the sentence flow. */
.reconnect-chip {
  display: inline-block;
  padding: 1px 8px;
  margin: 0 2px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  font-size: 12px;
  font-weight: 600;
  vertical-align: baseline;
}

/* Disabled state for queue action buttons during reconnect — distinct from
   normal :disabled so the user sees this is intentional, not a UI bug. */
button.reconnect-locked {
  opacity: 0.55;
  cursor: not-allowed;
  background: #f0fafa;
  color: var(--text-muted);
}

/* Dead-letter failure banner — persistent until acknowledged.
   Shown when a write was dropped after max online failures (genuine data-loss risk).
   Distinct from .reconnect-banner: red not orange, static not spinning, has an
   "OK" button the user must tap to dismiss. */
.dead-letter-banner {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 6px;
  padding: 10px 14px;
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.dead-letter-banner .dl-msg {
  flex: 1;
}
.dead-letter-banner .dl-ack-btn {
  flex-shrink: 0;
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  min-height: unset;
}
.dead-letter-banner .dl-ack-btn:active {
  background: var(--danger-soft);
}

/* Floating app-wide toast (used for offline / queued-write feedback). */
#app-toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #f39c12;
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 10000;
  max-width: 90%;
  text-align: center;
}

/* ─── Forms & inputs ─── */

input[type="text"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="email"],
input[type="search"],
textarea,
select {
  font: inherit;
  font-size: 16px; /* iOS auto-zooms inputs <16px on focus */
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-height: var(--tap);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="search"]:focus,
textarea:focus,
select:focus {
  border-color: var(--green-soft);
  box-shadow: 0 0 0 3px rgba(76, 175, 151, 0.18);
}

input[type="text"]::placeholder,
input[type="password"]::placeholder {
  color: var(--text-soft);
}

/* ─── Title field (select-only dropdown) + inline M/F gender ─── */
/* One row: a tap-to-open Title dropdown (left, wide) and the M | F gender
   segment (right, snug). Mirrors the .age-row "input + narrow segment" layout. */
.title-gender-row {
  display: flex;
  gap: 8px;
  margin: 6px 0;
  align-items: stretch;
}

.title-field {
  position: relative;
  flex: 1;
  min-width: 0;
}

/* ▾ affordance so the trigger reads as a dropdown. pointer-events:none so it
   never steals a tap from the trigger button beneath it. */
.title-field::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

/* The trigger: styled to match the form's text inputs exactly, but it's a
   button (select-only, no typing). Left-aligned text like a filled input. */
.title-trigger {
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  font-size: 16px; /* match inputs; avoids iOS zoom parity issues */
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 30px 10px 12px; /* room for the ▾ */
  min-height: var(--tap);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.title-trigger.placeholder {
  color: var(--text-soft); /* show the "Title" placeholder muted, like input::placeholder */
}

.title-trigger.open,
.title-trigger:focus {
  outline: none;
  border-color: var(--green-soft);
  box-shadow: 0 0 0 3px rgba(76, 175, 151, 0.18);
}

/* M | F gender segment — narrow, snug on the right. */
.title-gender-row .gender-mf {
  flex: 0 0 auto;
  width: 96px;
  margin: 0;
}

.title-gender-row .gender-mf button {
  padding: 10px 6px;
  font-weight: 600;
}

.title-options {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  margin-top: 2px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.title-option {
  padding: 10px 12px;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.title-option:last-child {
  border-bottom: none;
}

.title-option:hover {
  background: var(--bg-soft);
}

/* ─── Segmented controls (radio-like buttons) ─── */
/* Used in patient forms for gender, age unit, and category. */
.segmented {
  display: flex;
  gap: 0;
  margin: 6px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: #fff;
}

.segmented button {
  flex: 1;
  background: #fff;
  color: var(--text-muted);
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  padding: 10px 12px;
  min-height: var(--tap);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.segmented button:last-child {
  border-right: none;
}

.segmented button:hover:not(.selected) {
  background: var(--bg-soft);
}

.segmented button.selected,
.segmented button.selected:hover {
  background: var(--green);
  color: #fff;
  font-weight: 600;
}

/* Age row: number input + Y/M/D segmented unit picker side-by-side */
.age-row {
  display: flex;
  gap: 8px;
  margin: 6px 0;
  align-items: stretch;
}

.age-row input {
  flex: 1;
  margin: 0 !important;
  min-width: 0;
}

.age-row .segmented {
  flex: 0 0 auto;
  margin: 0;
  width: 140px;
}

.age-row .segmented button {
  padding: 10px 6px;
  font-weight: 600;
}

/* ─── Buttons ─── */

button {
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  min-height: 36px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}

button:hover:not(:disabled) {
  background: var(--bg-soft);
  border-color: var(--green-soft);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

button.primary:hover:not(:disabled) {
  background: var(--green-soft);
  border-color: var(--green-soft);
}

button.big {
  min-height: var(--tap);
  padding: 12px 20px;
  font-size: 16px;
}

/* ─── Login + clinic picker ─── */

#login-section,
#clinic-picker {
  max-width: 380px;
  margin: 40px auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

#login-section .login-logo,
#clinic-picker .login-logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

#login-section input,
#clinic-picker input {
  display: block;
  width: 100%;
  margin: 8px 0;
}

#login-section #login-btn,
#clinic-picker button {
  display: inline-block;
  margin: 6px 4px 0;
  min-width: 100px;
}

/* Picker selection highlight (chosen clinic / doctor). Mirrors the segmented
   .selected look. Explicit :hover override so a sticky touch :hover on a tablet
   can't beat the selected state (see feedback_touch_sticky_hover_selected_state). */
#clinic-picker .picker-selected,
#clinic-picker .picker-selected:hover {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  font-weight: 600;
}

/* Doctor step sits below the clinic buttons; a little breathing room. */
#doctor-picker {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Continue commits the compounder's clinic+doctor pick. Green like login,
   full-width, and visibly disabled until both are chosen. */
#clinic-picker #btn-enter-clinic {
  width: 100%;
  margin-top: 16px;
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

#clinic-picker #btn-enter-clinic:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Header "With: Dr. X · Switch Doctor" line, compounder only. */
#with-doctor-line { margin-left: 6px; }
#with-doctor-line #btn-switch-doctor { margin-left: 6px; }

#login-section #login-btn {
  width: 100%;
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  margin-top: 14px;
}

#login-msg, #clinic-msg {
  color: var(--danger);
  min-height: 1.2em;
}

/* Neutral (non-error) status text in the same slot — e.g. "Connecting…" while
   a clinic selection is in flight. Without this the progress message renders in
   the same red as the genuine failure message. */
#clinic-msg.msg-info {
  color: var(--text-soft);
}

/* ─── Logged-in top bar ─── */

#logged-in-section > p#user-info {
  display: inline-block;
  margin-right: 10px;
  color: var(--text-muted);
}

#logout-btn,
#btn-switch-clinic {
  font-size: 13px;
  padding: 6px 10px;
  min-height: 32px;
}

#clinic-name {
  display: inline-block;
  background: var(--aqua-soft);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
}

#peer-warning:not(:empty) {
  background: var(--warn-soft);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--warn);
  margin: 8px 0;
}

/* ─── Compounder view — sidebar layout ─── */

#view-compounder {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 18px;
  align-items: start;
}

#compounder-main,
#compounder-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

#compounder-sidebar hr {
  margin: 14px -18px;
}

#search-input,
#doctor-search-input {
  width: 100%;
  display: block;
}

/* Inline clear (×) button — overlaid on the right edge of the search input.
   Hidden via [hidden] when input is empty; JS toggles. */
.search-input-wrap {
  position: relative;
  width: 100%;
}
.search-input-wrap input {
  /* Make room for the × so typed text doesn't slide underneath it */
  padding-right: 36px;
}
.search-clear {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}
.search-clear:hover { color: var(--text); background: var(--bg-soft); }
.search-clear:active { background: var(--border); }

#search-results {
  margin-top: 8px;
}

/* Doctor search results float beneath the input as a dropdown overlay so the
   queue / current-patient card don't get pushed down while typing. Anchored
   to #doctor-search-section (position:relative). Empty state stays invisible
   via :not(:empty). */
#doctor-search-results:not(:empty) {
  position: absolute;
  left: 14px;
  right: 14px;
  top: calc(100% - 14px);
  margin-top: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-height: min(60vh, 480px);
  overflow-y: auto;
  z-index: 50;
}

#search-results > div,
#doctor-search-results > div {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

/* Two-zone result row: info line above, action buttons below in a single row */
.search-row-info { margin-bottom: 6px; }
.search-row-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}
.search-row-actions button {
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
}
/* Match the app's own button hierarchy: ONE primary action (Add to Queue =
   solid green, like button.primary), the other two stay subtle white buttons
   differentiated only by a colored text + border accent. Quiet, not loud. */
.search-row-actions button[data-add-queue] {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  font-weight: 600;
}
.search-row-actions button[data-add-queue]:hover:not(:disabled) {
  background: var(--green-soft);
  border-color: var(--green-soft);
}
/* Text colors are darkened (vs --blue/--warn) to pass WCAG AA on white
   (blue 5.2:1, amber 4.7:1); the soft border carries the lighter color cue. */
.search-row-actions button[data-view-patient] {
  color: #2f6fb0;
  border-color: var(--blue-soft);
}
.search-row-actions button[data-view-patient]:hover:not(:disabled) {
  border-color: var(--blue);
}
.search-row-actions button[data-edit-patient] {
  color: #a8631f;
  border-color: var(--warn-soft);
}
.search-row-actions button[data-edit-patient]:hover:not(:disabled) {
  border-color: var(--warn);
}

/* Clinic group header (shown in "All clinics" results). */
.search-group-header {
  padding: 6px 10px;
  margin: 4px 0 0;
  background: var(--bg-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-group-count {
  background: var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 11px;
}

/* Highlight matched substrings inside the result info line */
.search-row-info mark {
  background: #fff3a8;
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}

#doctor-search-results > h4 {
  padding: 6px 10px;
  margin: 0;
  background: var(--bg-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

#search-results > div:last-child,
#doctor-search-results > div:last-child {
  border-bottom: none;
}

.search-address {
  display: inline-block;
  color: var(--text-soft);
  font-size: 12px;
  font-style: italic;
}

/* ── Search scope/category toggles ── */
.search-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 4px;
}
.seg-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-card);
}
.seg-toggle button {
  border: none;
  background: transparent;
  padding: 5px 12px;
  font-size: 12.5px;
  color: var(--text-muted);
  min-height: 32px;
  border-radius: 0;
}
.seg-toggle button.active {
  background: var(--green);
  color: #fff;
  font-weight: 600;
}

/* ── Restructured result rows ── */
.search-row-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  margin-bottom: 2px;
}
.search-row-ids {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-bottom: 3px;
}
.search-id {
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 12.5px;
  color: var(--blue);
  font-weight: 600;
}
/* "old: <id>" — the patient's legacy/paper id, clearly labelled so it's not
   confused with the current id. */
.legacy-wrap {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.legacy-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  font-weight: 600;
}
.legacy-chip {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--warn-soft);
  border: 1px dashed var(--warn);
  color: var(--warn);
  font-weight: 600;
}
.clinic-tag {
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--aqua-soft);
  color: var(--blue);
  font-weight: 600;
  letter-spacing: 0.3px;
}
.search-row-details {
  font-size: 12.5px;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.search-row-lastseen {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.search-row mark, .search-row-ids mark {
  background: #fff3a8;
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}
/* Inside a legacy chip the pale-yellow <mark> is lost against the amber chip
   background — use a dark, high-contrast highlight instead so it stands out. */
.legacy-chip mark {
  background: var(--warn);
  color: #fff;
  border-radius: 2px;
  padding: 0 2px;
}
.search-empty { color: var(--text-muted); padding: 8px 10px; }

#register-section input,
#register-section select {
  display: block;
  width: 100%;
  margin: 6px 0;
}

/* Register action row. "Register" is the quiet secondary (outlined, neutral so
   it doesn't compete); "Register & Queue" is the bold primary in bright aqua —
   lighter and more striking than the dark-green "Regular" segmented pill above
   it, so the two no longer blur together. */
.reg-btn-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.reg-btn-row button { flex: 1; }
.reg-btn-row .reg-only {
  background: var(--aqua-soft);
  color: var(--text);
  border: 1px solid var(--aqua);
  font-weight: 600;
}
.reg-btn-row .reg-only:hover:not(:disabled) { background: var(--aqua); border-color: var(--aqua); }
.reg-btn-row .reg-queue {
  background: var(--aqua);
  color: var(--text);
  border-color: var(--aqua);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.reg-btn-row .reg-queue:hover:not(:disabled) { background: var(--aqua-soft); border-color: var(--aqua-soft); }

#reg-msg { color: var(--text-muted); font-size: 13px; }

/* Queue rows (compounder) */

#queue-list h4 {
  margin-top: 14px;
  padding: 6px 10px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--aqua);
}

#queue-list > div {
  padding: 10px 12px;
  margin: 6px 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--aqua);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

#queue-list > div button {
  padding: 6px 10px;
  min-height: 32px;
  font-size: 13px;
}

/* Status-colored left borders — applied via class in ui.js */
.qrow-queued       { border-left-color: var(--blue) !important; }
.qrow-with_doctor  { border-left-color: var(--green) !important; }
.qrow-rx_ready     { border-left-color: var(--warn) !important; background: var(--warn-soft) !important; }
.qrow-dispensed    { border-left-color: var(--green-soft) !important; opacity: 0.7; }
.qrow-walked_away  { border-left-color: var(--danger) !important; opacity: 0.6; }

.ff-tag {
  background: var(--ff-soft);
  color: var(--ff);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  margin-left: 6px;
}

/* "NEW" badge — a brand-new patient (auto-ID) who hasn't completed their first
   consult, or completed it today. Green reads as fresh; clears the next day. */
.new-tag {
  background: var(--green);
  color: #ffffff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-left: 6px;
}

/* Rx info-bar tags — address (left), name+age (center), ID (right) share the
   same pill shape/weight but get distinct soft colors so the eye can tell the
   three zones apart at a glance without the colors fighting for attention. */
.rx-info-address-tag,
.rx-info-name-tag,
.rx-info-id-tag {
  padding: 2px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rx-info-address-tag {
  background: var(--blue-soft, #bcd7f5);
  color: var(--blue, #4a90e2);
}
.rx-info-name-tag {
  background: var(--aqua-soft, #d8f0f0);
  color: var(--text, #1a2b33);
}
.rx-info-id-tag {
  background: var(--warn-soft, #fbe8cf);
  color: var(--warn, #d88a3a);
}

/* Repeat (formerly Top-up) badge in the completed-today list. */
.repeat-tag {
  background: var(--aqua-soft);
  color: var(--blue);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  margin-left: 6px;
}

/* Repeat duration stepper in the patient-detail panel. */
.repeat-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0;
  padding: 8px 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.repeat-stepper-label { font-weight: 600; color: var(--text); }
.repeat-step-btn {
  width: 38px;
  height: 38px;
  font-size: 20px;
  line-height: 1;
  border-radius: 8px;
}
.repeat-step-btn:disabled { opacity: 0.4; }
.repeat-weeks-val {
  min-width: 28px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.repeat-weeks-unit { color: var(--text-muted); }

/* ─── Doctor view — tablet-first ─── */

#view-doctor {
  max-width: 900px;
  margin: 0 auto;
}

#doctor-search-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
  position: relative;
}

#doctor-reg-toggle {
  margin-top: 10px;
  font-size: 13px;
  padding: 6px 12px;
  min-height: 32px;
  color: var(--text-muted);
}

#doctor-register-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

#doctor-register-section input,
#doctor-register-section select {
  display: block;
  width: 100%;
  margin: 6px 0;
}

#doc-reg-msg { color: var(--text-muted); font-size: 13px; min-height: 1.2em; }

.current-patient-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 6px solid var(--green);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-md);
  margin-bottom: 14px;
}

.current-patient-card.empty {
  border-left-color: var(--border-strong);
  text-align: center;
  color: var(--text-muted);
}

.current-patient-card h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 600;
}

.current-patient-id {
  font-size: 14px;
  color: var(--text-muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.current-patient-name {
  font-size: 28px;
  font-weight: 600;
  margin: 4px 0 16px;
  color: var(--text);
}

.current-patient-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.current-patient-actions button {
  min-height: var(--tap);
}

#doctor-queued {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}

#doctor-queued:empty { display: none; }

#doctor-queued h4 {
  margin-top: 0;
}

.queued-row {
  padding: 12px;
  margin: 6px 0;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: var(--radius-sm);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
}

.queued-row button {
  min-height: 38px;
  padding: 8px 14px;
}

#doctor-rx-ready:not(:empty) {
  background: var(--warn-soft);
  border-left: 3px solid var(--warn);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}

#doctor-rx-ready h4 { margin-top: 0; color: var(--text); }

/* Rx-ready row: thumbnail | patient info | actions (shared by both views) */
.rx-ready-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  margin: 6px 0;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--warn);
  border-radius: var(--radius-sm);
}

.rx-ready-row .rx-thumb {
  max-width: 80px;
  max-height: 80px;
  margin-top: 0;
  flex-shrink: 0;
}

/* When the queue-row thumb has been populated with a rendered image, contain
   the img to the 80x80 slot and make the slot itself behave like the thumb
   (clickable, hover affordance). Applies to both rx-ready and completed-today rows. */
.rx-ready-row .rx-thumb:not(.rx-thumb-empty),
.completed-row .rx-thumb:not(.rx-thumb-empty) {
  width: 80px;
  height: 80px;
  overflow: hidden;
  padding: 2px;
  background: #fff;
}
.rx-ready-row .rx-thumb:not(.rx-thumb-empty) img,
.completed-row .rx-thumb:not(.rx-thumb-empty) img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.rx-thumb-empty {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-size: 12px;
  flex-shrink: 0;
}

.rx-ready-info {
  flex: 1;
  font-size: 14px;
  color: var(--text);
}

.rx-ready-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ─── Completed Today drawer (doctor view) ─── */
/* Closed by default. Sticky toggle pill at bottom-right opens a slide-in
 * drawer from the right. Same UI at all sizes for now (Akshay: "same as
 * mobile for the time being"). Backdrop click / × / Esc all close.
 * Inside, oldest at top, most recent at BOTTOM — list auto-scrolls on open. */

#completed-drawer-toggle {
  position: fixed;
  bottom: 14px;
  right: 14px;
  z-index: 2500;
}

#completed-drawer-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--green-soft, #6aa37a);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  box-shadow: var(--shadow-md, 0 4px 12px rgba(0, 0, 0, 0.18));
  cursor: pointer;
}

#completed-drawer-toggle-btn:hover {
  filter: brightness(1.05);
}

#completed-drawer-toggle-count {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 13px;
  min-width: 22px;
  text-align: center;
}

#completed-drawer-backdrop {
  /* Invisible tap-catcher: lets the user dismiss the drawer by tapping
     outside it, without dimming or tinting the rest of the page. The user
     specifically didn't want a background-color change when the drawer
     opens. Stays transparent in both states. */
  position: fixed;
  inset: 0;
  background: transparent;
  z-index: 2600;
  pointer-events: none;
}

body.completed-drawer-open #completed-drawer-backdrop {
  pointer-events: auto;
}

#completed-drawer {
  position: fixed;
  top: 0;
  right: 0;
  /* Use dynamic viewport height on iOS so the drawer ends at the visible
     bottom of the page — not below the Safari address bar. Without dvh, the
     bottom of the inner scroll list is unreachable on iPhone. */
  height: 100vh;
  height: 100dvh;
  width: 420px;
  max-width: 100vw;
  background: var(--bg, #fff);
  border-left: 1px solid var(--border, #d6dee5);
  z-index: 2700;
  transform: translateX(100%);
  transition: transform 220ms ease;
  display: flex;
  flex-direction: column;
}

body.completed-drawer-open #completed-drawer {
  transform: translateX(0);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
}

.completed-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border, #d6dee5);
  background: var(--bg-soft, #f3f7f4);
}

.completed-drawer-header h4 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
}

#completed-drawer-close {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}

#completed-drawer-close:hover {
  background: rgba(0, 0, 0, 0.06);
}

#doctor-completed-today {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Drawer-scoped search — filters all sections live. */
.completed-drawer-search {
  position: relative;
  flex-shrink: 0;
}

.completed-drawer-search input {
  width: 100%;
  /* Don't set font-size — global input rule (line ~238) keeps it at 16px so
     iOS Safari doesn't auto-zoom on focus. Padding-right makes room for ×. */
  padding-right: 32px;
  box-sizing: border-box;
}

.completed-drawer-search input:focus {
  outline: none;
  border-color: var(--green-soft, #6aa37a);
}

#completed-drawer-search-clear {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted, #6b7a85);
  cursor: pointer;
  padding: 2px 6px;
}

/* Collapsible compounder queue section (Dispensed). Mirrors completed-section. */
.queue-collapse {
  border: 1px solid var(--border, #d6dee5);
  border-radius: var(--radius-sm, 4px);
  background: var(--bg-soft, #f3f7f4);
  overflow: hidden;
  margin-top: 10px;
}

.queue-collapse-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.queue-collapse-caret {
  display: inline-block;
  transition: transform 160ms ease;
  font-size: 12px;
  color: var(--text-muted, #6b7a85);
}

.queue-collapse.open .queue-collapse-caret { transform: rotate(0deg); }
.queue-collapse:not(.open) .queue-collapse-caret { transform: rotate(-90deg); }

.queue-collapse-label { flex: 1; }

.queue-collapse-count {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  min-width: 22px;
  text-align: center;
}

.queue-collapse-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 220ms ease, padding 220ms ease;
  padding: 0 8px;
}

.queue-collapse.open .queue-collapse-body {
  max-height: none;
  padding: 4px 8px 8px 8px;
  overflow-y: visible;
}

/* Each clinic gets a labeled section. Header is the toggle (accordion). */
.completed-section {
  border: 1px solid var(--border, #d6dee5);
  border-radius: var(--radius-sm, 4px);
  background: var(--bg-soft, #f3f7f4);
  overflow: hidden;
  flex-shrink: 0;
}

.completed-section-current {
  border-color: var(--green-soft, #6aa37a);
}

.completed-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.completed-section-current .completed-section-header {
  background: rgba(106, 163, 122, 0.08);
}

.completed-section-caret {
  display: inline-block;
  transition: transform 160ms ease;
  font-size: 12px;
  color: var(--text-muted, #6b7a85);
}

.completed-section.open .completed-section-caret {
  transform: rotate(0deg);
}

.completed-section:not(.open) .completed-section-caret {
  transform: rotate(-90deg);
}

.completed-section-label {
  flex: 1;
}

.completed-section-count {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  min-width: 22px;
  text-align: center;
}

.completed-section-current .completed-section-count {
  background: var(--green-soft, #6aa37a);
  color: #fff;
}

/* The row list. Collapsed when section is closed (max-height 0). */
.completed-section .completed-today-list {
  max-height: 0;
  overflow: hidden;
  transition: max-height 220ms ease, padding 220ms ease;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0 8px;
}

.completed-section.open .completed-today-list {
  /* Generous cap so 80+ patients all show; outer #doctor-completed-today scrolls. */
  max-height: none;
  padding: 4px 8px 8px 8px;
  overflow-y: visible;
}

.completed-drawer-empty {
  color: var(--text-muted, #6b7a85);
  text-align: center;
  padding: 24px 12px;
  margin: 0;
}

.completed-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  margin: 6px 0;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--green-soft);
  border-radius: var(--radius-sm);
}

.completed-row .rx-thumb {
  max-width: 80px;
  max-height: 80px;
  margin-top: 0;
  flex-shrink: 0;
}

/* ─── Edit form (shared) ─── */

#edit-section {
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-md);
  margin: 14px 0;
}

#edit-section input,
#edit-section select {
  display: block;
  width: 100%;
  margin: 6px 0;
}

#edit-section button {
  margin-top: 8px;
  margin-right: 6px;
}

#edit-msg { color: var(--text-muted); font-size: 13px; }

/* ─── Patient detail (shared) ─── */

#detail-section {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin: 14px 0;
}

/* Top-right ↑ — anchored to the panel's corner so it's always reachable when
   the panel header itself is in view. (FAB below covers the scrolled-down case.) */
#detail-back-to-top-top {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  z-index: 2;
  box-shadow: 0 1px 4px rgba(46, 125, 107, 0.3);
}
#detail-back-to-top-top:hover { background: var(--green-dark, #246b58); }
#detail-back-to-top-top:active { background: var(--green-dark, #1f5d4d); }

/* Floating "back to top" — fixed to viewport, visible only when the user
   has scrolled away from the top of the detail panel. JS toggles [hidden]. */
#detail-back-to-top-fab {
  position: fixed;
  right: 16px;
  bottom: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  z-index: 100;
  padding: 0;
}
#detail-back-to-top-fab:hover { background: var(--green-dark, #246b58); }
#detail-back-to-top-fab:active { background: var(--green-dark, #1f5d4d); }

#detail-patient-info {
  color: var(--text-muted);
  font-size: 14px;
}

#detail-visits > div,
#detail-notes > div,
#detail-attachments > div {
  padding: 10px 12px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  margin: 6px 0;
  font-size: 14px;
}

/* Section header row: the <h4> title beside its "+ Add" button. */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 0 4px;
}
.section-head h4 { margin: 0; }

/* Standard filled "add" button (＋ Add note / ＋ Add file). */
.add-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  min-height: 36px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.add-btn:hover:not(:disabled) { background: var(--green-soft); }
.add-btn:active { transform: translateY(1px); }
.add-btn:disabled { opacity: 0.5; cursor: default; }

/* Note / attachment list rows: tappable body + trailing actions. */
.note-row,
.attach-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.note-row .row-main,
.attach-row .row-main {
  flex: 1 1 auto;
  min-width: 0;
  cursor: pointer;
}
.note-row .row-title,
.attach-row .row-title {
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}
.note-row .row-meta,
.attach-row .row-meta {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}
.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.row-actions button {
  min-height: 34px;
  padding: 5px 10px;
  font-size: 13px;
}
.row-del {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: transparent;
}

.empty-hint {
  color: var(--text-soft);
  font-size: 14px;
  margin: 6px 0;
}

/* Rx thumbnail — click-to-enlarge */
.rx-thumb {
  max-width: 180px;
  max-height: 180px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 6px;
  cursor: zoom-in;
  transition: transform 0.1s, box-shadow 0.1s;
  display: block;
}

.rx-thumb:hover {
  box-shadow: var(--shadow-md);
  transform: scale(1.02);
}

/* Rx lightbox overlay */
#rx-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26, 58, 82, 0.85);
  z-index: 3000;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}

#rx-lightbox.open { display: flex; }

#rx-lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  background: #fff;
}

/* ─── Prescription canvas overlay ─── */

#rx-overlay {
  background: var(--bg) !important;
}

#rx-toolbar {
  background: var(--bg-card) !important;
  border-bottom: 1px solid var(--border);
  /* Fixed height + no-wrap is authoritative here (beats the inline style and any
     media query) so the bar can never grow a second row and shove the canvas. */
  flex-wrap: nowrap !important;
  height: 56px;
  padding: 0 12px !important;
  gap: 8px !important;
}

#rx-toolbar button {
  min-height: 38px;
  padding: 8px 14px;
}

/* Scrolling tools group must be allowed to shrink below its content so the
   pinned Done/Close cluster always stays on-screen; its overflow scrolls. */
#rx-tools { min-width: 0; }

#rx-toolbar #rx-save {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

/* ─── Continuous paper view ─── */

#rx-paper-host {
  /* Canvas is sized via JS; this just gives a soft grey margin around it. */
  padding: 0;
}

/* Visit rows in patient-detail are tap targets for opening the paper. */
.rx-row { transition: background 0.1s; }
.rx-row:hover { background: var(--bg-soft, #f7f9fb); }
.rx-row:active { background: var(--bg, #eef1f4); }

/* Per-visit thumbnail slots (Rx + Balance). One row, one slot per mode.
   Each .rx-thumb-mini is filled async after the row renders. */
.rx-row-thumbs {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.rx-thumb-mini {
  width: 160px;
  height: 100px;
  object-fit: contain;
  border: 1px solid var(--border, #d4dee5);
  border-radius: var(--radius-sm, 4px);
  background: #fff;
}
.rx-thumb-mini-comp {
  border-color: var(--green, #6ab187);
}

#rx-patient-label {
  font-size: 15px;
  color: var(--text);
}

#rx-save-msg {
  font-size: 13px;
  color: var(--text-muted);
  /* Lives in the scrolling #rx-tools group now. nowrap so the status text
     itself never wraps; no reserved min-width (the old 120px reservation just
     consumed row budget and pushed the toolbar toward wrapping). The toolbar's
     fixed height + nowrap means a status-text width change can no longer move
     the canvas — so the old "stray vertical line on tap" cause is gone too. */
  flex: 0 0 auto;
  margin-left: 10px;
  white-space: nowrap;
}

/* ─── Toast ─── */

#toast-container { gap: 8px !important; }

.toast {
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--green);
  max-width: 320px;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  transform: translateY(-4px);
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.doctor { border-left-color: var(--blue); }
.toast.compounder { border-left-color: var(--green); }

/* ─── Responsive — compounder collapses below 1024px ─── */

@media (max-width: 1023px) {
  #view-compounder {
    grid-template-columns: 1fr;
  }
  /* Single-column: search/register on top (like the doctor view), queue below.
     DOM order is main-then-sidebar, so reorder the grid items. */
  #compounder-sidebar { order: 1; }
  #compounder-main { order: 2; }
}

/* ─── Tablet portrait tweaks ─── */

@media (max-width: 820px) {
  body { padding: calc(12px + env(safe-area-inset-top, 0px))
                  calc(12px + env(safe-area-inset-right, 0px))
                  calc(12px + env(safe-area-inset-bottom, 0px))
                  calc(12px + env(safe-area-inset-left, 0px)); }
  h2 { font-size: 20px; }
  .current-patient-name { font-size: 26px; }
  .current-patient-actions button { flex: 1 1 auto; }
}

/* ─── Phone tweaks (compounder on Android Chrome) ─── */

@media (max-width: 480px) {
  body { padding: calc(8px + env(safe-area-inset-top, 0px))
                  calc(8px + env(safe-area-inset-right, 0px))
                  calc(8px + env(safe-area-inset-bottom, 0px))
                  calc(8px + env(safe-area-inset-left, 0px)); }

  .app-header { flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
  /* No flex-grow on h2 so the green dot sits right next to the title
     instead of being pushed to the right edge. */
  .app-header h2 { font-size: 16px; flex: 0 1 auto; }
  .app-header .version { font-size: 10px; }
  .app-header img.logo { width: 36px; height: 36px; }

  /* Row 1: logo · title · green dot. Row 2 (forced full-width): user · Logout. */
  .app-header > span[style*="flex:1"] { display: none; }  /* drop the row-1 spacer */
  .app-header-user {
    flex: 1 1 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .app-header-user #user-info { margin: 0; }

  #compounder-main, #compounder-sidebar { padding: 12px; }

  /* 44px tap target + 2-up button grid when wrapped */
  #queue-list > div { padding: 10px; gap: 8px; }
  #queue-list > div button {
    min-height: 44px;
    font-size: 14px;
    padding: 8px 12px;
    flex: 1 1 calc(50% - 4px);
  }

  #search-results > div, #doctor-search-results > div { font-size: 13px; }
  .search-row-actions button { font-size: 13px; padding: 8px 6px; min-height: 40px; }

  /* Awaiting Dispense / Completed row: thumb + info on row 1, actions wrap
     onto row 2 spanning full width so buttons don't overflow on phone. */
  .rx-ready-row,
  .completed-row { flex-wrap: wrap; }
  .rx-ready-actions { flex-basis: 100%; }
  .rx-ready-actions button { flex: 1 1 0; min-height: 40px; font-size: 13px; padding: 8px 6px; white-space: nowrap; }

  .age-row .segmented { width: 120px; }
  .age-row .segmented button { padding: 10px 4px; font-size: 13px; }

  /* Phone: keep the single no-wrap bar (Done/Close pinned, tools scroll) — the
     same structure as tablet. Wrapping here used to grow the bar and shove the
     canvas; nowrap + horizontal scroll keeps every control reachable instead. */
  #rx-toolbar { gap: 6px !important; padding: 0 8px !important; }
  #rx-toolbar button { flex-shrink: 0; min-height: 36px; padding: 6px 10px; font-size: 13px; }
  #rx-patient-label { font-size: 13px; }
}

/* ─── Hydrate overlay (Step 3 read-cache directory pull) ─── */
/* Subtle non-blocking directory-sync chip (bottom-left). App stays usable. */
#hydrate-chip {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 9000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(74, 144, 226, 0.12);
  font-size: 12.5px;
  color: var(--text-muted);
  max-width: 70vw;
  pointer-events: none;
}
.hydrate-chip-spinner {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border: 2px solid var(--aqua-soft);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: hydrate-spin 0.9s linear infinite;
}
@keyframes hydrate-spin {
  to { transform: rotate(360deg); }
}

/* Doctor overflow menu — surfaces compounder fallback actions (Edit / Balance
   / Walked Away / Remove) on doctor queue rows so doctor can keep the clinic
   running when compounder is absent. */
.overflow-wrap {
  position: relative;
  display: inline-block;
}
.overflow-btn {
  font-size: 18px;
  line-height: 1;
  padding: 4px 10px;
  min-width: 36px;
}
.overflow-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  min-width: 160px;
}
.overflow-menu[hidden] { display: none; }
.overflow-menu button {
  width: 100%;
  text-align: left;
  white-space: nowrap;
}
