/* ============================================================
   ReconMed — app.css
   ------------------------------------------------------------
   ADDITIVE ONLY. Loaded after style.css and never edits it, so
   design work and engine work never collide in the same file.

   Contains: the state classes the base sheet was missing
   (progress, loading, disabled, focus, empty), the utilities
   that were being inlined repeatedly, the new components the
   engine needs (rule trace, confidence, counterfactual), a
   mobile navbar, and a print stylesheet.
   ============================================================ */

/* ---------- tokens the base sheet lacked ---------- */
:root {
  --danger: #c0392b;
  --danger-dark: #a93226;
  --ai: #6366f1;
  --ai-light: #eef0ff;
  --tint-red: #fde8e2;
  --tint-amber: #fef3cd;
  --tint-green: #e2f5eb;
  --tint-grey: #eaecf0;
  --pill-radius: 20px;
  --shadow-lg: 0 4px 16px rgba(0,0,0,.10);
}

/* ---------- utilities that were being inlined ---------- */
.hidden { display: none !important; }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }
.m-0 { margin: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-l { margin-bottom: 24px; }
.mb-xl { margin-bottom: 32px; }
.mt-xl { margin-top: 32px; }
.gap-xs { gap: 4px; }
.gap-xl { gap: 40px; }
.flex-wrap { flex-wrap: wrap; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.align-start { align-items: flex-start; }
.align-end { align-items: flex-end; }
.w-auto { width: auto !important; }
.text-xs { font-size: 11px; }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }
.text-ok { color: var(--ok); }
.text-brand { color: var(--brand); }
.text-accent { color: var(--accent); }
.text-ai { color: var(--ai); }
.list-disc { list-style: disc; padding-left: 18px; }
.col-span-full { grid-column: 1 / -1; }
.mono { font-family: 'Cascadia Mono', Consolas, 'Courier New', monospace; }
.nowrap { white-space: nowrap; }
.strike { text-decoration: line-through; opacity: .65; }

/* repeated 5x in the base pages as an inline style */
.form-actions {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 24px; padding-top: 16px;
  border-top: 1px solid var(--border); flex-wrap: wrap;
}

/* clickable card that does not inherit link blue (6x inline in index) */
.card-link {
  display: flex; flex-direction: column; gap: 8px;
  padding: 20px; color: var(--text); text-decoration: none;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.card-link:hover {
  text-decoration: none; border-color: var(--brand);
  box-shadow: var(--shadow-lg); transform: translateY(-1px);
}

/* dark card header (3x inline in discharge) */
.card-header-dark {
  background: var(--brand-dark); color: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
}
.card-header-dark h2, .card-header-dark h3 { color: #fff; }
.card-header-dark .sub { color: rgba(255,255,255,.72); font-size: 13px; }

/* ---------- fix: base sheet renders the literal word "checkmark" ---------- */
.checklist li::before { content: '\2713' !important; }

/* ---------- select needs its chevron back (base sets appearance:none) --- */
select.form-control {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
}

/* ---------- accessibility: the base sheet has no focus ring ---------- */
a:focus-visible, button:focus-visible, .btn:focus-visible,
.form-control:focus-visible, .tab-btn:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 3px;
}
.navbar a:focus-visible { outline-color: #fff; }

/* ---------- disabled states (absent from the base sheet) ---------- */
.btn:disabled, .btn.is-disabled, button:disabled {
  opacity: .5; cursor: not-allowed; pointer-events: none;
}
.form-control:disabled, .form-control[readonly] {
  background: var(--bg); color: var(--muted); cursor: not-allowed;
}

/* ---------- progress (hand-rolled inline in reconciliation.html) ---------- */
.progress { background: var(--border); border-radius: 4px; height: 8px; overflow: hidden; }
.progress-bar {
  background: var(--brand); height: 100%; width: 0;
  border-radius: 4px; transition: width .35s ease;
}
.progress-bar.is-complete { background: var(--ok); }

/* ---------- loading (no @keyframes existed at all) ---------- */
@keyframes rm-spin { to { transform: rotate(360deg); } }
@keyframes rm-pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes rm-flash { 0% { background: var(--tint-amber); } 100% { background: transparent; } }
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border); border-top-color: var(--brand);
  border-radius: 50%; animation: rm-spin .7s linear infinite;
}
.skeleton {
  background: var(--border); border-radius: 4px;
  animation: rm-pulse 1.2s ease-in-out infinite; min-height: 12px;
}
.just-changed { animation: rm-flash 1.1s ease-out 1; }

/* ---------- empty state ---------- */
.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty-state .icon { font-size: 28px; margin-bottom: 10px; opacity: .5; }
.empty-state h3 { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 13px; max-width: 420px; margin: 0 auto 14px; }

/* ---------- AI / confidence provenance markers ---------- */
.badge-ai { background: var(--ai-light); color: var(--ai); }
.badge-purple { background: var(--ai-light); color: var(--ai); }
.conf {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 1px 7px;
  border-radius: var(--pill-radius); white-space: nowrap;
}
.conf-high { background: var(--tint-green); color: var(--ok); }
.conf-med  { background: var(--tint-amber); color: #8a6200; }
.conf-low  { background: var(--tint-red);   color: var(--danger); }
.conf-bar { display: inline-block; width: 34px; height: 4px; border-radius: 2px; background: var(--border); position: relative; overflow: hidden; }
.conf-bar > i { position: absolute; inset: 0 auto 0 0; background: currentColor; }

.provenance {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .3px;
}
.provenance .tag {
  background: var(--tint-grey); color: #4b5563;
  padding: 1px 6px; border-radius: 3px; letter-spacing: 0;
  text-transform: none; font-weight: 600;
}
.provenance .tag.is-brand { background: var(--brand-light); color: var(--brand); }
.provenance .tag.is-fuzzy { background: var(--ai-light); color: var(--ai); }

/* ---------- rule trace: how a finding was reached ---------- */
.trace {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-top: 12px;
}
.trace > .trace-head {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 700;
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; list-style: none; user-select: none;
}
.trace > .trace-head::-webkit-details-marker { display: none; }
/* the marker has to say which way it will go, not only that it is a control */
.trace > .trace-head::after {
  content: 'show'; margin-left: auto; font-weight: 700;
  color: var(--brand); letter-spacing: .4px;
}
.trace[open] > .trace-head::after { content: 'hide'; }
.trace[open] > .trace-head { margin-bottom: 8px; }
.trace > .trace-head:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 3px; border-radius: 4px;
}
.trace ol { list-style: none; counter-reset: tr; }
.trace ol li {
  counter-increment: tr; position: relative;
  padding: 4px 0 4px 26px; font-size: 13px; line-height: 1.5;
}
.trace ol li::before {
  content: counter(tr); position: absolute; left: 0; top: 5px;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--brand); color: #fff;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.trace .cite {
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border);
  font-size: 11px; color: var(--muted);
}

/* ---------- the one sentence telling you what to do next ---------- */
.next-step {
  display: flex; align-items: baseline; gap: 10px;
  background: var(--brand-light);
  border-left: 3px solid var(--brand);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 10px 14px; font-size: 13px; line-height: 1.55;
}
.next-step-label {
  font-size: 10px; font-weight: 800; letter-spacing: .6px;
  text-transform: uppercase; color: var(--brand); flex: none;
}

/* a caveat the tool volunteers about its own limits */
.caveat {
  margin-top: 10px; padding: 9px 12px; font-size: 13px;
  background: #fef9ec; border-left: 3px solid var(--warn);
  border-radius: 0 var(--radius) var(--radius) 0; color: #713f12;
}

/* ---------- flag card severity accents (base sheet has none) ---------- */
.disc-row.sev-high   { border-left: 4px solid var(--danger); }
.disc-row.sev-confirm{ border-left: 4px solid var(--warn); }
.disc-row.sev-medium { border-left: 4px solid var(--accent); }
.disc-row.sev-low    { border-left: 4px solid var(--brand); }
.disc-row.sev-info   { border-left: 4px solid var(--border); }
.disc-row.is-resolved { opacity: .72; }
.disc-row.is-resolved .disc-header { background: var(--tint-green); }
.disc-row.is-headline { box-shadow: 0 0 0 2px rgba(192,57,43,.18), var(--shadow); }

/* ---------- collapsible findings ---------- */
.disc-header[data-role="toggle-flag"] { cursor: pointer; user-select: none; }
.disc-header[data-role="toggle-flag"]:hover { background: var(--tint-grey); }
.disc-chevron {
  display: inline-block; color: var(--muted); font-size: 12px;
  transition: transform .18s ease; flex-shrink: 0;
}
.disc-row.is-collapsed .disc-chevron { transform: rotate(-90deg); }
.disc-row.is-collapsed .disc-body { display: none; }
.disc-collapsed-line { display: none; }
.disc-row.is-collapsed .disc-collapsed-line {
  display: block; padding: 10px 18px 13px;
  font-size: 13px; color: var(--muted); line-height: 1.5;
  border-top: 1px solid var(--border);
}
.disc-row.is-collapsed .disc-collapsed-line .text-brand { cursor: pointer; }

.headline-ribbon {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; padding: 3px 9px;
  border-radius: var(--pill-radius);
}
.posture-tag {
  font-size: 10px; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase; padding: 2px 7px; border-radius: 3px;
  background: var(--tint-grey); color: #4b5563;
}
.posture-tag.is-confirm { background: var(--tint-amber); color: #8a6200; }

/* ---------- diff / counterfactual presentation ---------- */
.cf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 820px) { .cf-grid { grid-template-columns: 1fr; } }
.cf-panel { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cf-panel > header { padding: 11px 15px; font-size: 13px; font-weight: 700; }
.cf-bad > header  { background: var(--tint-red); color: #7b1d1d; border-bottom: 1px solid #f3c8bd; }
.cf-good > header { background: var(--tint-green); color: #14532d; border-bottom: 1px solid #bfe6d0; }
.cf-panel ul { list-style: none; }
.cf-panel li {
  padding: 8px 15px; font-size: 13px; border-bottom: 1px solid var(--border);
  display: flex; gap: 8px; align-items: flex-start;
}
.cf-panel li:last-child { border-bottom: none; }
.cf-panel li .mark { flex-shrink: 0; font-weight: 700; width: 14px; }
.cf-panel li.is-danger { background: #fef6f4; color: #7b1d1d; }
.cf-panel li.is-danger .mark { color: var(--danger); }
.cf-panel li.is-fixed .mark { color: var(--ok); }
.cf-note { font-size: 12px; color: var(--muted); padding: 10px 15px; background: var(--bg); }

/* ---------- timeline dots the base sheet lacked ---------- */
.tl-dot-ai { background: var(--ai) !important; }
.tl-dot-danger { background: var(--danger) !important; }
.tl-actor {
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; padding: 1px 6px; border-radius: 3px;
  background: var(--tint-grey); color: #4b5563; margin-right: 6px;
}
.tl-actor.is-system { background: var(--brand-light); color: var(--brand); }
.tl-actor.is-engine { background: var(--tint-amber); color: #8a6200; }
.tl-actor.is-pharmacist { background: var(--ai-light); color: var(--ai); }
.tl-actor.is-physician { background: var(--tint-green); color: var(--ok); }
.tl-detail {
  font-size: 13px; color: var(--muted); margin-top: 3px;
  background: var(--bg); border-radius: var(--radius);
  padding: 8px 11px; border: 1px solid var(--border);
}

/* ---------- tabs need a panel + hidden partner ---------- */
.tab-panel[hidden] { display: none; }

/* ---------- plain-language patient copy ----------
   Larger type and looser spacing, because the people who most need the
   simplified wording are also the most likely to be reading it without
   their glasses, in a corridor, on the day they go home. */
.card.is-plain { font-size: 16px; }
.card.is-plain table { font-size: 15px; }
.card.is-plain td { padding: 14px 12px; line-height: 1.6; }
.card.is-plain th { font-size: 13px; }
.card.is-plain .text-sm { font-size: 15px; }
.card.is-plain h3 { font-size: 20px; }
.card.is-plain .alert { font-size: 16px; }
.card.is-plain li { margin-bottom: 6px; }

/* ---------- code / JSON display ---------- */
.code-dump {
  background: #0f1b2a; color: #cfe3f7; border-radius: var(--radius);
  padding: 14px 16px; font-family: 'Cascadia Mono', Consolas, monospace;
  font-size: 12px; line-height: 1.55; overflow-x: auto; max-height: 460px;
  overflow-y: auto; white-space: pre;
}
.code-dump.is-light {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
}
.code-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 700; margin-bottom: 6px;
}

/* ---------- test runner ---------- */
.test-tick  { color: var(--ok); font-weight: 700; }
.test-cross { color: var(--danger); font-weight: 700; }

/* ---------- stop wide children forcing the page wider than the phone ----------
   Grid and flex items default to min-width:auto, so one unshrinkable child --
   a code block, a wide table, a long unbroken string -- holds its whole column
   open and pushes the entire page sideways. The patient page was 537px wide in
   a 375px viewport because of exactly this. */
.two-col > *,
.three-col > *,
.cf-grid > *,
.form-actions > *,
.patient-bar > * { min-width: 0; }

.code-dump { max-width: 100%; }
.table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.trace ol li, .disc-collapsed-line, .source-val { overflow-wrap: anywhere; }

/* ---------- patient portal: whose record is this ----------
   A real portal shows you your own record and offers no choice. This is a
   demo control and is styled to read as one, not as a product feature. */
.pp-whose {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 14px; padding: 10px 14px;
  background: #fff; border: 1px dashed var(--border);
  border-radius: var(--radius); font-size: 12px;
}
.pp-whose-label { font-weight: 700; color: var(--muted); }
.pp-whose-note {
  flex-basis: 100%; color: var(--muted); font-size: 11.5px; line-height: 1.5;
}

/* ---------- session lock ---------- */
.lock-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(12, 23, 16, .72);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.lock-overlay.hidden { display: none; }
.lock-card {
  background: #fff; border-radius: var(--radius); padding: 34px 32px;
  max-width: 460px; text-align: center; box-shadow: var(--shadow-lg);
}
.lock-card .lock-icon { font-size: 34px; margin-bottom: 10px; }
.lock-card h2 { font-size: 21px; margin-bottom: 10px; }
.lock-card p { font-size: 14px; line-height: 1.6; margin-bottom: 12px; }

/* ============================================================
   COLOUR IS NEVER THE ONLY SIGNAL
   ------------------------------------------------------------
   Severity here runs red / amber / green, which is the single
   most common accessibility failure: around one man in twelve
   has a red-green deficiency, and to them "danger" and "resolved"
   can look alike. Every status therefore also carries a shape,
   so the meaning survives with the colour removed.
   ============================================================ */
.badge::before {
  font-weight: 700; margin-right: 5px; font-size: 11px;
}
.badge-red::before    { content: '\26A0'; }   /* warning triangle */
.badge-amber::before  { content: '\25C6'; }   /* diamond */
.badge-green::before  { content: '\2713'; }   /* tick */
.badge-blue::before   { content: '\25CF'; }   /* dot */
.badge-grey::before   { content: '\25CB'; }   /* hollow dot */
.badge-ai::before     { content: '\25C7'; }   /* hollow diamond */

.status-pill::before { font-weight: 700; margin-right: 4px; }
.pill-pending::before  { content: '\25D4'; }  /* part-filled circle */
.pill-approved::before { content: '\2713'; }
.pill-review::before   { content: '\21BB'; }  /* cycle arrow */

.score-ring { position: relative; }
.score-ring.score-high::after,
.score-ring.score-medium::after,
.score-ring.score-low::after {
  position: absolute; top: -3px; right: -3px;
  font-size: 11px; font-weight: 700; line-height: 1;
  background: #fff; border-radius: 50%; padding: 1px 2px;
}
.score-ring.score-high::after   { content: '\26A0'; color: var(--danger); }
.score-ring.score-medium::after { content: '\25C6'; color: var(--warn); }
.score-ring.score-low::after    { content: '\2713'; color: var(--ok); }

.source-cell.conflict > .source-label::before { content: '\26A0 '; font-weight: 700; }
.source-cell.match    > .source-label::before { content: '\2713 '; font-weight: 700; }
.source-cell.missing  > .source-label::before { content: '\2717 '; font-weight: 700; }

/* ---------- colour-blind-safe palette ----------
   Swaps the red/green axis for blue/orange, which stays separable
   under deuteranopia, protanopia and tritanopia. Only the tokens
   change: no component needs to know this mode exists. */
body.cb-safe {
  --danger: #b3450e;
  --danger-dark: #8f3609;
  --warn: #7a5c00;
  --ok: #1c5fa8;
  --accent: #1c5fa8;
  --tint-red: #fbe7da;
  --tint-amber: #f6efd2;
  --tint-green: #dce9f7;
}
body.cb-safe .badge-red    { background: #fbe7da; color: #8f3609; }
body.cb-safe .badge-amber  { background: #f6efd2; color: #6b5000; }
body.cb-safe .badge-green  { background: #dce9f7; color: #14477e; }
body.cb-safe .pill-pending { background: #f6efd2; color: #6b5000; }
body.cb-safe .pill-approved{ background: #dce9f7; color: #14477e; }
body.cb-safe .score-high   { border-color: #b3450e; color: #8f3609; }
body.cb-safe .score-medium { border-color: #7a5c00; color: #6b5000; }
body.cb-safe .score-low    { border-color: #1c5fa8; color: #14477e; }
body.cb-safe .cf-bad > header  { background: #fbe7da; color: #8f3609; }
body.cb-safe .cf-good > header { background: #dce9f7; color: #14477e; }
body.cb-safe .legend-dot.is-high { background: #b3450e; }
body.cb-safe .legend-dot.is-med  { background: #7a5c00; }
body.cb-safe .legend-dot.is-low  { background: #1c5fa8; }

.a11y-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted);
}
.a11y-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: #fff;
  border-radius: var(--pill-radius); padding: 4px 11px;
  font-size: 12px; font-weight: 600; cursor: pointer; color: var(--text);
}
.a11y-toggle:hover { border-color: var(--brand); }
.a11y-toggle[aria-pressed="true"] {
  background: var(--brand); border-color: var(--brand); color: #fff;
}

/* ---------- worklist legend ----------
   A number in a column headed "Score" tells a reader nothing. This says what
   it is and what to do about it, before the table rather than after it. */
.worklist-legend {
  padding: 11px 18px; background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 13px; line-height: 1.6; color: var(--muted);
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
}
.worklist-legend > strong:first-child { color: var(--text); }
.worklist-legend .legend-key {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 600; color: var(--text); white-space: nowrap;
}
.worklist-legend .legend-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.legend-dot.is-high { background: var(--danger); }
.legend-dot.is-med  { background: var(--warn); }
.legend-dot.is-low  { background: var(--ok); }
.worklist-legend a { font-weight: 600; white-space: nowrap; }
th .th-sub {
  display: block; font-weight: 500; font-size: 10px;
  color: var(--muted); text-transform: none; letter-spacing: 0;
}

/* ---------- score factor breakdown ---------- */
.factor-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.factor-row:last-child { border-bottom: none; }
.factor-row .f-label { font-size: 13px; font-weight: 600; min-width: 175px; }
.factor-row .f-detail { font-size: 12px; color: var(--muted); flex: 1; }
.factor-row .f-track { width: 90px; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; flex-shrink: 0; }
.factor-row .f-fill { height: 100%; background: var(--brand); border-radius: 3px; }
.factor-row .f-pts { font-size: 13px; font-weight: 700; min-width: 56px; text-align: right; }
.factor-total { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; padding-top: 10px; border-top: 2px solid var(--border); font-weight: 700; }

/* ---------- context strip ----------
   Quiet by design. It sits above the clinical content telling you which
   record you are in, the way a ward system would, rather than announcing
   itself as demo scaffolding. */
.context-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 14px; background: #fff;
  border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 16px; font-size: 13px;
}
.context-bar .ctx-back {
  font-weight: 600; color: var(--brand); text-decoration: none; white-space: nowrap;
}
.context-bar .ctx-back:hover { text-decoration: underline; }
.context-bar .ctx-patient { font-weight: 700; }
.context-bar .ctx-meta { color: var(--muted); }
.context-bar .ctx-sep { width: 1px; height: 15px; background: var(--border); }
.context-bar .ctx-actions { display: flex; align-items: center; gap: 8px; }
@media (max-width: 720px) {
  .context-bar { flex-wrap: wrap; }
  .context-bar .ctx-sep { display: none; }
  /* The controls grew when they gained their Arabic labels and this row
     would not wrap, so the last button hung past the edge of a phone. */
  .context-bar .ctx-actions {
    width: 100%; display: flex; flex-wrap: wrap; gap: 8px;
  }
  .context-bar .ctx-actions > * { min-width: 0; }
  .context-bar .btn, .context-bar .a11y-toggle { white-space: normal; }
}

/* kept so any older markup still renders sensibly */
.demo-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--brand-light);
  border: 1px solid var(--brand); border-radius: var(--radius);
  margin-bottom: 18px; font-size: 13px;
}
.demo-bar .label { font-weight: 700; color: var(--brand); }

/* ---------- mobile: the base navbar had no treatment at all ---------- */
@media (max-width: 860px) {
  .navbar { height: auto; flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  .navbar nav { order: 3; flex-basis: 100%; overflow-x: auto; padding-bottom: 2px; }
  .navbar nav a { white-space: nowrap; font-size: 13px; padding: 5px 10px; }
  .navbar .role-badge { margin-left: auto; }
  .page-wrap { padding: 20px 14px 48px; }
  .hero { padding: 44px 18px; }
  .hero h1 { font-size: 27px; }
  .tabs { overflow-x: auto; }
  .factor-row { flex-wrap: wrap; }
  .factor-row .f-label { min-width: 100%; }

  /* The two page-foot buttons sat in a flex row that would not wrap, so
     "Submit for physician approval" hung a few pixels past the edge of a
     phone and gave the whole page a horizontal scrollbar. */
  .form-actions { flex-wrap: wrap; gap: 10px; }
  .form-actions > * { min-width: 0; }
  .form-actions .flex { flex-wrap: wrap; gap: 10px; }
  .form-actions .btn-lg { width: 100%; justify-content: center; }
}

/* ---------- print: the discharge summary is meant to be handed over ---- */
/* The masthead and running footer exist only on paper. */
.print-only { display: none; }

@media print {
  @page { size: A4; margin: 14mm 13mm 16mm; }

  /* ---- everything that belongs to the screen, not the document ---- */
  .navbar, .sidebar, .footer, .breadcrumb, .tabs, .demo-bar, .page-header,
  .btn, .form-actions, .no-print, .next-step, .pp-whose,
  #rm-demo-bar, #rm-counterfactual, #rm-status,
  .cb-toggle, .lock-btn, .session-lock, .integrity-banner { display: none !important; }

  /* The four language panels are alternatives, not sections. Printing the
     hidden ones produced the same summary four times over, which is how a
     two page document became fourteen pages. Only what is on screen prints. */
  .tab-panel[hidden] { display: none !important; }

  html, body {
    background: #fff; color: #000;
    font-size: 10.5pt; line-height: 1.42;
  }
  /* main carries the page's rounded card look, which printed as a stray
     rounded rectangle wrapped around the whole document, and a left margin
     sized for the sidebar, which indented every sheet. worker.css loads after
     this file, so these need to be marked important to win. */
  .page-wrap, main {
    max-width: none !important; padding: 0 !important; margin: 0 !important;
    border-radius: 0 !important; box-shadow: none !important;
    background: #fff !important; min-height: 0 !important;
  }
  .print-only { display: block; }

  /* ---- masthead ---- */
  .print-head { margin: 0 0 10pt; }
  .print-head-top {
    display: flex; justify-content: space-between; align-items: flex-end;
    border-bottom: 2pt solid #000; padding-bottom: 5pt;
  }
  .print-org { font-size: 11pt; font-weight: 700; }
  .print-org span { display: block; font-size: 8.5pt; font-weight: 400; }
  .print-mark { font-size: 8.5pt; letter-spacing: 1.4pt; text-transform: uppercase; }
  .print-title { font-size: 17pt; margin: 9pt 0 0; letter-spacing: -.2pt; }
  .print-status {
    margin-top: 7pt; padding: 5pt 7pt; font-size: 9pt;
    border-left: 2.5pt solid #000; background: #f2f2f2;
  }
  .print-status.is-draft { border-left-color: #000; font-weight: 700; }

  /* ---- running footer, repeated on every sheet ---- */
  .print-foot {
    position: fixed; bottom: 0; left: 0; right: 0;
    display: flex; justify-content: space-between;
    font-size: 7.5pt; color: #444;
    border-top: .5pt solid #bbb; padding-top: 3pt;
  }

  /* ---- the document body ---- */
  /* Cards stop being cards. A patient handout should not look like a UI. */
  .card {
    border: 0 !important; box-shadow: none !important; border-radius: 0 !important;
    background: #fff !important; margin: 0 0 10pt; padding: 0;
    break-inside: auto;
  }
  .card-body, .card-footer { padding: 0 !important; }
  /* The masthead already gives the title and the hospital, so the card's own
     dark header would repeat both immediately underneath it. */
  .card-header-dark { display: none !important; }
  .card-header {
    background: #fff !important; color: #000 !important;
    border-bottom: 1pt solid #000; padding: 0 0 4pt; margin-bottom: 8pt;
    break-after: avoid;
  }
  .card-header h2 { color: #000 !important; font-size: 12pt; }
  .card-body { padding: 0; }
  h2, h3 { break-after: avoid; }
  hr { border: 0; border-top: .6pt solid #bbb; margin: 9pt 0; }

  /* ---- medication table: the part that must survive a page break ---- */
  table { font-size: 9pt; width: 100%; border-collapse: collapse; }
  thead { display: table-header-group; }   /* header repeats on every page */
  tfoot { display: table-footer-group; }
  tr, .alert, .two-col > * { break-inside: avoid; }
  th, td {
    border: 0; border-bottom: .5pt solid #ccc;
    padding: 4pt 6pt 4pt 0; vertical-align: top;
  }
  th {
    background: #fff !important; color: #000 !important;
    border-bottom: 1pt solid #000;
    font-size: 7.5pt; text-transform: uppercase; letter-spacing: .5pt;
  }
  .table-wrap { overflow: visible !important; border: 0; }

  /* Left to itself the browser gave the line number column as much room as the
     drug name and wrapped "Twice daily" onto three lines. */
  .tab-panel table { table-layout: fixed; }
  .tab-panel th:nth-child(1), .tab-panel td:nth-child(1) { width: 4%; }
  .tab-panel th:nth-child(2), .tab-panel td:nth-child(2) { width: 19%; }
  .tab-panel th:nth-child(3), .tab-panel td:nth-child(3) { width: 11%; }
  .tab-panel th:nth-child(4), .tab-panel td:nth-child(4) { width: 14%; }
  .tab-panel th:nth-child(5), .tab-panel td:nth-child(5) { width: 24%; }
  .tab-panel th:nth-child(6), .tab-panel td:nth-child(6) { width: 27%; }
  /* "When to take" was setting three lines of header over a one line cell. */
  .tab-panel thead th { letter-spacing: .2pt; font-size: 7pt; }
  .tab-panel td { overflow-wrap: break-word; }
  /* A hyphenated drug name on a patient handout is a misreading waiting to
     happen. Spironolactone was printing as "Spironolac tone". */
  .tab-panel td:nth-child(2), .tab-panel td:nth-child(3) {
    overflow-wrap: normal; word-break: keep-all; hyphens: none;
  }
  /* A dose split across two lines invites reading the number without its
     unit, so the dose cell never wraps. */
  .tab-panel td:nth-child(3), .tab-panel td:nth-child(4) { white-space: nowrap; }

  /* ---- callouts print as ruled blocks, not coloured chips ---- */
  .alert {
    border: 0; border-left: 2.5pt solid #000; background: #f2f2f2 !important;
    color: #000 !important; padding: 6pt 8pt; margin: 8pt 0; font-size: 9pt;
  }
  .badge, .status-pill {
    border: .5pt solid #666 !important; background: #fff !important;
    color: #000 !important; font-size: 7.5pt; padding: 1pt 4pt;
  }
  .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10pt 18pt; }

  /* Arabic keeps its own direction and a readable size on paper. */
  [dir="rtl"], .ar { font-size: 10pt; line-height: 1.7; }

  a { color: #000; text-decoration: none; }
  a[href]::after { content: ''; }
}

/* ---------- logo lockup ----------
   The container is a flex row with a gap, and "Recon" was a bare text node,
   so the browser made it its own flex item and the gap pushed it away from
   <span>Med</span>. Wrapping the wordmark makes it a single item, which
   closes that space. The accent colour has to be re-pointed at the inner
   span, because ".logo span" now also matches the wrapper. */
.logo-mark {
  width: 28px; height: 28px;
  object-fit: contain; flex: none; display: block;
}
.logo .logo-word,
.sidebar-logo .logo-word {
  display: inline; white-space: nowrap; color: inherit;
}

/* The mark is green and blue, and the sidebar is green, so on that one
   surface it nearly disappears. A white disc gives it something to sit on. */
.sidebar-logo .logo-mark {
  background: #fff;
  border-radius: 50%;
  padding: 4px;
  box-sizing: border-box;
  width: 34px; height: 34px;
}


