/* ── MEDICATIONS TAB ────────────────────────────────────────────────────────── */
.med-subtitle { font-size: 13px; color: var(--text-muted); margin: 2px 0 16px; }

.med-layout {
  display: flex;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  overflow: hidden;
  height: calc(100vh - var(--nav-height, 48px) - 130px);
  height: calc(100dvh - var(--nav-height, 48px) - 130px);
  min-height: 400px;
  background: var(--glass-bg);
  box-shadow: var(--shadow-md);
}

.med-sidebar {
  width: 220px; min-width: 180px; flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg);
  display: flex; flex-direction: column;
}

.med-detail {
  flex: 1; overflow-y: auto;
  padding: 18px 22px 28px;
  background: var(--surface);
}

.med-search-wrap {
  padding: 10px 10px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.med-search-input {
  width: 100%; padding: 7px 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); outline: none; color: var(--text);
}
.med-search-input:focus { border-color: var(--primary); box-shadow: var(--glow-primary); }
/* v2.36/v2.37 — hide medications search bars on mobile across all meds views
   (MSK Drugs: .med-search-wrap; Patient Background: .mb-search-wrap).
   Elements kept in DOM so desktop search + their JS listeners are unaffected. */
@media (max-width: 767px) {
  .med-search-wrap,
  .mb-search-wrap { display: none; }
}

.med-group-header {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 10px 14px 4px; flex-shrink: 0;
}
.med-cat-item {
  display: block; width: 100%; text-align: left;
  padding: 9px 14px; font-size: 13px; font-weight: 500;
  color: var(--text-secondary); background: none; border: none;
  border-left: 3px solid transparent; cursor: pointer;
  transition: background 0.12s, border-color 0.12s; line-height: 1.3;
}
.med-cat-item:hover { background: var(--primary-bg); }
.med-cat-item.active {
  background: #ddeeff;
  border-left-color: var(--primary);
  border-left-width: 4px;
  color: var(--primary); font-weight: 700;
}
.med-cat-item[data-group="caution"].active {
  border-left-color: #e65100; color: #e65100; background: #fff3e0;
}

.med-card { max-width: 100%; }
.med-card-header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.med-card-title { font-size: 18px; font-weight: 700; color: var(--text); margin: 0; }

.med-badge {
  display: inline-block; padding: 3px 9px; border-radius: 12px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
}
.med-badge-treatment { background: #e8f5e9; color: #2e7d32; border: 1px solid #2e7d32; }
.med-badge-caution   { background: var(--draft-bg); color: var(--draft-color); border: 1px solid var(--draft-border); }

.med-examples-wrap {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 6px; margin-bottom: 14px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.med-field-label {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em; flex-shrink: 0;
}
.med-example {
  display: inline-block; padding: 3px 9px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; font-size: 12px; color: var(--text-secondary);
}
/* Drug name / note within chips: don't shrink the note (already 12px) — use colour only */
.med-example .mb-med-name { color: var(--text); }
.med-example .mb-med-note { font-size: inherit; color: var(--text-muted); }

.med-section {
  margin: 10px 0; padding: 12px 16px;
  border-radius: 8px; background: var(--bg);
  border: 1px solid var(--border); border-left-width: 3px;
}
.med-section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px;
}
.med-text { font-size: 13px; line-height: 1.65; color: var(--text-secondary); margin: 0; }
.med-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 5px; }
.med-list li { font-size: 13px; line-height: 1.6; color: var(--text-secondary); padding-left: 16px; position: relative; }
.med-list li::before { content: '–'; position: absolute; left: 0; color: var(--border); }

.med-relevance  { border-left-color: #2e7d32; background: #f1f8f1; }
.med-relevance .med-section-title { color: #2e7d32; }
.med-adverse    { border-left-color: #7b1fa2; }
.med-adverse .med-section-title { color: #6a1b9a; }
.med-redflags   { border-left-color: var(--tier1-color); background: #fff8f8; }
.med-redflags .med-section-title { color: var(--tier1-color); }
.med-redflags .med-list li { color: #7f0000; }
.med-assess     { border-left-color: #e65100; }
.med-assess .med-section-title { color: #e65100; }
.med-questions  { border-left-color: var(--primary); background: var(--primary-bg); }
.med-questions .med-section-title { color: var(--primary); }
.med-questions .med-list li { color: #1a237e; }
.med-questions .med-list li::before { content: '?'; color: var(--primary); }

.med-no-results { padding: 12px 14px; font-size: 13px; color: var(--text-muted); }

/* ── MEDS TAB BAR (shared by MSK Drugs + Patient Background) ─────────────────── */
.meds-tab-bar {
  display: flex; gap: 3px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  margin: 0 0 16px;
}
.meds-tab {
  flex: 1; padding: 9px 10px;
  font-size: 13px; font-weight: 600;
  border: none; background: transparent; cursor: pointer;
  color: var(--text-muted);
  border-radius: calc(var(--radius) - 2px);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  font-family: inherit; line-height: 1.2;
}
.meds-tab:hover:not(.meds-tab--active) {
  background: var(--bg); color: var(--text);
}
.meds-tab--active {
  background: var(--primary); color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.14);
}

/* ── PATIENT BACKGROUND — search ─────────────────────────────────────────────── */
.mb-search-wrap  { margin-bottom: 4px; }
.mb-search-row   { display: flex; align-items: center; gap: 6px; }
.mb-search-input {
  flex: 1; min-width: 0; padding: 9px 12px;
  font-size: 14px; font-family: inherit;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  outline: none; box-sizing: border-box;
}
.mb-search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }

/* clear (✕) button — shown only when query is non-empty */
.mb-search-clear {
  flex-shrink: 0; width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-muted);
  font-size: 13px; cursor: pointer; font-family: inherit;
  transition: background 0.13s, color 0.13s, border-color 0.13s;
}
.mb-search-clear:hover { background: var(--bg); color: var(--text); border-color: var(--text-muted); }
.mb-search-clear:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* meta row: count (left) + hint (right) */
.mb-search-meta {
  display: flex; align-items: baseline; gap: 8px;
  padding: 5px 1px 14px;
}
.mb-count { font-size: 11.5px; color: var(--text-muted); line-height: 1; }
.mb-search-hint {
  font-size: 11px; color: var(--text-muted); opacity: 0.7;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* empty state */
.mb-no-results {
  font-size: 13px; color: var(--text-muted);
  padding: 2px 0 16px; margin: 0;
}

/* ── PATIENT BACKGROUND — groups ─────────────────────────────────────────────── */
.mb-group { margin-bottom: 32px; }
.mb-group-header {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  padding: 0 0 10px; margin-bottom: 10px;
  border-bottom: 1.5px solid var(--border);
}

/* ── PATIENT BACKGROUND — scan cards ─────────────────────────────────────────── */
.mb-card {
  display: block; padding: 18px 16px 16px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-left-width: 4px; border-radius: var(--radius);
  text-decoration: none; color: var(--text);
  margin-bottom: 12px;
  transition: box-shadow 0.18s, border-color 0.18s, transform 0.12s;
  /* full card is the single tap target — no inner interactive elements */
}
.mb-card:hover {
  box-shadow: 0 3px 14px rgba(0,0,0,0.10);
  border-color: var(--primary);
  transform: translateX(3px);
}
.mb-card:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--focus-ring);
  border-color: var(--primary);
}
.mb-card:active {
  transform: translateX(1px);
  box-shadow: 0 1px 5px rgba(0,0,0,0.07);
}

/* ── Card content hierarchy ─────────────────────────────────────────────────── */

/* 1. Title — dominant: largest, heaviest, darkest, most space below */
.mb-card-top {
  display: flex; align-items: center; gap: 9px; margin-bottom: 13px;
}
.mb-card-icon  { font-size: 20px; line-height: 1; flex-shrink: 0; }
.mb-card-title {
  font-size: 16px; font-weight: 700; color: var(--text);
  line-height: 1.15; letter-spacing: -0.02em;
}

/* 2. Impact — second level: medium-dark, semibold, clearly below title */
/* Color: var(--text-secondary) #44546A — darker than muted, lighter than title */
.mb-card-impact {
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  line-height: 1.55; margin: 0 0 6px;
}

/* 3. Cue — third level: muted, italic, smallest — readable but clearly subordinate */
/* Not too faint: var(--text-muted) #6B7A90 meets 4.5:1 on white */
.mb-card-cue {
  font-size: 11.5px; font-weight: 400; color: var(--text-muted);
  font-style: italic; line-height: 1.55; margin: 0 0 12px;
}

/* 4. Tags */
.mb-card-tags { display: flex; flex-wrap: wrap; gap: 5px; }

@media (max-width: 480px) {
  .mb-card { padding: 15px 13px 14px; margin-bottom: 10px; }
  .mb-card-top { gap: 8px; margin-bottom: 11px; }
  .mb-card-icon { font-size: 18px; }
  .mb-card-title { font-size: 15px; letter-spacing: -0.015em; }
  .mb-card-impact { font-size: 12.5px; margin-bottom: 5px; }
  .mb-card-cue { font-size: 11px; margin-bottom: 10px; }
  .mb-card-tags { gap: 4px; }
  .mb-tag { font-size: 10px; padding: 2px 6px; }
  .mb-group-header { font-size: 9.5px; letter-spacing: 0.06em; }
  .mb-group { margin-bottom: 26px; }
  /* prevent iOS zoom on focus — must be ≥16px */
  .mb-search-input { font-size: 16px; }
  /* clear button: comfortable tap target */
  .mb-search-clear { width: 38px; height: 38px; font-size: 14px; }
  /* meta row: hint may truncate on very narrow widths — that's fine */
  .mb-search-meta { gap: 6px; }
}

/* accent left-border per category */
.mb-card--analgesics      { border-left-color: #6d28d9; }
.mb-card--nsaid-context   { border-left-color: #dc2626; }
.mb-card--anticoagulants  { border-left-color: #be123c; }
.mb-card--steroids        { border-left-color: #d97706; }
.mb-card--antidepressants { border-left-color: #7c3aed; }
.mb-card--antihypertensives { border-left-color: #0369a1; }
.mb-card--bone-health     { border-left-color: #15803d; }
.mb-card--diabetes        { border-left-color: #0891b2; }
.mb-card--cardiac         { border-left-color: #e11d48; }
.mb-card--statins         { border-left-color: #b45309; }
.mb-card--renal-risk      { border-left-color: #0e7490; }
.mb-card--polypharmacy    { border-left-color: #374151; }

/* risk tag pills — 6 semantic families */
.mb-tag {
  display: inline-block; font-size: 10.5px; font-weight: 600;
  padding: 2px 7px; border-radius: 10px;
  border: 1px solid; line-height: 1.5; white-space: nowrap;
}
.mb-tag--danger   { color: #9f1239; background: #fff1f2; border-color: #fda4af; }
.mb-tag--caution  { color: #92400e; background: #fffbeb; border-color: #fcd34d; }
.mb-tag--cns      { color: #5b21b6; background: #f5f3ff; border-color: #c4b5fd; }
.mb-tag--physio   { color: #1e40af; background: #eff6ff; border-color: #93c5fd; }
.mb-tag--metabolic{ color: #0e7490; background: #f0fdff; border-color: #67e8f9; }
.mb-tag--neutral  { color: #374151; background: #f9fafb; border-color: #d1d5db; }

/* ── PATIENT BACKGROUND — detail page ────────────────────────────────────────── */
.mb-detail-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; margin: 0 0 20px;
  border-radius: var(--radius);
  background: var(--surface); border: 1.5px solid var(--border);
  border-left-width: 5px;
}
.mb-detail-header--analgesics      { border-left-color: #6d28d9; }
.mb-detail-header--nsaid-context   { border-left-color: #dc2626; }
.mb-detail-header--anticoagulants  { border-left-color: #be123c; }
.mb-detail-header--steroids        { border-left-color: #d97706; }
.mb-detail-header--antidepressants { border-left-color: #7c3aed; }
.mb-detail-header--antihypertensives { border-left-color: #0369a1; }
.mb-detail-header--bone-health     { border-left-color: #15803d; }
.mb-detail-header--diabetes        { border-left-color: #0891b2; }
.mb-detail-header--cardiac         { border-left-color: #e11d48; }
.mb-detail-header--statins         { border-left-color: #b45309; }
.mb-detail-header--renal-risk      { border-left-color: #0e7490; }
.mb-detail-header--polypharmacy    { border-left-color: #374151; }

.mb-detail-icon  { font-size: 28px; flex-shrink: 0; }
.mb-detail-title { font-size: 18px; font-weight: 700; margin: 0; color: var(--text); }

.mb-section {
  margin-bottom: 16px; padding: 14px 16px;
  background: var(--surface); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.mb-section-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  margin-bottom: 8px;
}
.mb-section--ask   .mb-section-title { color: var(--primary); }
.mb-section--concern { border-left: 3px solid #b91c1c; background: #fff5f5; }
.mb-section--concern .mb-section-title { color: #b91c1c; }
.mb-section--ask   { border-left: 3px solid var(--primary); background: #f0f6ff; }

.mb-section-text { font-size: 13.5px; line-height: 1.6; margin: 0; color: var(--text); }
.mb-list {
  margin: 0; padding-left: 18px;
  display: flex; flex-direction: column; gap: 6px;
}
.mb-list li { font-size: 13px; line-height: 1.6; color: var(--text); }

/* Medication name highlighting — common examples section only */
.mb-med-name {
  font-weight: 700;
  color: var(--text);           /* weight alone signals importance; no colour reliance */
}
.mb-med-note {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.9em;
}
.mb-list--examples .mb-example-item { line-height: 1.6; }

/* ── MEDICATION CAUTION BADGE ─────────────────────────────────────────────── */
.med-caution-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #594300;
  background: #fff8e7;
  border: 1px solid #e8a000;
  border-radius: 4px;
  padding: 2px 8px;
  margin-top: 6px;
}

/* ── MEDICATION CARD CLASS TINTING ───────────────────────────────────────── */
.med-card--analgesic   { border-top: 3px solid #4a7c59; }
.med-card--nsaid       { border-top: 3px solid #7c6a4a; }
.med-card--opioid      { border-top: 3px solid #7c4a4a; }
.med-card--dmard       { border-top: 3px solid #4a5c7c; }
.med-card--neuropathic { border-top: 3px solid #6a4a7c; }

/* ── v1.1 — drug class label ─────────────────────────────────────────────── */
.med-class-row { margin-bottom: 12px; }
.med-class-badge {
  display: inline-block;
  font-size: 11px; font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  letter-spacing: 0.01em;
}

/* ── v1.1 — important interactions block ────────────────────────────────── */
.med-interactions { border-left: 3px solid #B45309; background: #FFFDF5; }
.med-ix-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.med-ix-list li {
  display: flex; align-items: baseline; gap: 6px;
  font-size: var(--fs-sm, 13px); color: var(--text);
  line-height: 1.5;
}
.med-ix-icon {
  flex-shrink: 0;
  font-size: 12px; font-weight: 700;
  min-width: 16px;
}
.med-ix-icon--high { color: var(--risk, #C0392B); }
.med-ix-icon--mod  { color: #B45309; }
.med-ix-with { font-weight: 600; color: var(--text); }

/* ── v1.1 — when this changes your reasoning ────────────────────────────── */
.med-reasoning { border-left: 3px solid var(--primary, #3B6EA5); background: var(--primary-bg, #EBF0F8); }
.med-reasoning__text {
  font-style: italic;
  color: var(--text);
  line-height: 1.65;
}



/* ════════════════════════════════════════════════════════════════════════════
   v2.62 : meds triage shelf (background rows) + MSK drugs accordion
   ════════════════════════════════════════════════════════════════════════════ */
.mbr-group { margin-top: 18px; }
.mbr-group-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 8px; padding-left: 10px;
  border-left: 4px solid var(--border);
}
.mbr-group--act  .mbr-group-head { border-left-color: var(--tier1-color); color: var(--tier1-color); }
.mbr-group--ltc  .mbr-group-head { border-left-color: var(--primary); }
.mbr-group--pain .mbr-group-head { border-left-color: #d97706; color: #92600a; }
.mbr-group-count {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  background: var(--surface-sunken); border-radius: 99px; padding: 1px 8px;
  font-variant-numeric: tabular-nums; letter-spacing: 0;
}
.mbr-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.mbr-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px 7px 12px;
  min-height: 50px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  transition: background var(--transition);
}
.mbr-row:last-child { border-bottom: none; }
.mbr-row:hover { background: var(--primary-bg); }
.mbr-row:hover .mbr-label { color: var(--primary); }
.mbr-icon { font-size: 17px; flex-shrink: 0; line-height: 1; }
.mbr-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.mbr-label { font-size: 14px; font-weight: 600; color: var(--text); line-height: 1.35; }
.mbr-cue {
  font-size: 11.5px; color: var(--text-muted); font-style: italic;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mbr-dots { display: flex; gap: 3px; flex-shrink: 0; }
.mbr-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.mbr-dot--danger    { background: var(--tier1-color); }
.mbr-dot--caution   { background: #d97706; }
.mbr-dot--cns       { background: #6B21A8; }
.mbr-dot--physio    { background: #0E7490; }
.mbr-dot--metabolic { background: #166534; }
.mbr-chev { color: var(--text-muted); font-size: 15px; flex-shrink: 0; }

/* ── MSK drugs accordion ── */
.med-acc-group { margin-top: 18px; }
.med-acc-group-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--primary);
  margin-bottom: 8px; padding-left: 10px;
  border-left: 4px solid var(--primary);
}
.med-acc-group-head--caution { color: #92600a; border-left-color: #d97706; }
.med-acc {
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: -1px;
}
.med-acc:first-of-type { border-radius: var(--radius) var(--radius) 0 0; }
.med-acc:last-of-type  { border-radius: 0 0 var(--radius) var(--radius); margin-bottom: 0; }
.med-acc-sum {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; min-height: 46px;
  cursor: pointer; list-style: none; -webkit-appearance: none; user-select: none;
}
.med-acc-sum::-webkit-details-marker { display: none; }
.med-acc-name { font-size: 14px; font-weight: 600; color: var(--text); flex: 1; }
.med-acc-warn {
  font-size: 10px; font-weight: 700; flex-shrink: 0;
  color: var(--caution); background: var(--caution-bg);
  border: 1px solid var(--draft-border); border-radius: 6px; padding: 2px 7px;
}
.med-acc-chev { color: var(--text-muted); transition: transform var(--transition); }
.med-acc[open] > .med-acc-sum { background: var(--primary-bg); border-bottom: 1px solid var(--border); }
.med-acc[open] > .med-acc-sum .med-acc-name { color: var(--primary); }
.med-acc[open] > .med-acc-sum .med-acc-chev { transform: rotate(90deg); }
.med-acc-body .med-card {
  border: none; box-shadow: none; border-radius: 0; margin: 0;
}
