:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --border: #dfe3dd;
  --text: #17201c;
  --muted: #5f6b65;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d8efe9;
  --warn: #9a5b00;
  --warn-soft: #fff1d6;
  --danger: #b42318;
  --danger-soft: #fde4e1;
  --ok: #157a3d;
  --ok-soft: #ddf3e4;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --violet: #6d28d9;
  --violet-soft: #ede9fe;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .04);
  --radius: 14px;
  --spk-0: #0f766e; --spk-1: #7c3aed; --spk-2: #c2410c; --spk-3: #2563eb; --spk-4: #be185d; --spk-5: #4d7c0f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --surface: #161d1a; --surface-2: #1d2622; --border: #2a3530;
    --text: #e6ece8; --muted: #95a39b; --accent: #2bb3a3; --accent-ink: #04201c; --accent-soft: #123a35;
    --warn: #f0b456; --warn-soft: #3a2a0f; --danger: #f87171; --danger-soft: #3b1715;
    --ok: #4ade80; --ok-soft: #12321f;
    --info: #93c5fd; --info-soft: #172554; --violet: #c4b5fd; --violet-soft: #2e1065;
    --shadow: none;
    --spk-0: #2bb3a3; --spk-1: #a78bfa; --spk-2: #fb923c; --spk-3: #60a5fa; --spk-4: #f472b6; --spk-5: #a3e635;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #161d1a; --surface-2: #1d2622; --border: #2a3530;
  --text: #e6ece8; --muted: #95a39b; --accent: #2bb3a3; --accent-ink: #04201c; --accent-soft: #123a35;
  --warn: #f0b456; --warn-soft: #3a2a0f; --danger: #f87171; --danger-soft: #3b1715;
  --ok: #4ade80; --ok-soft: #12321f; --shadow: none;
  --info: #93c5fd; --info-soft: #172554; --violet: #c4b5fd; --violet-soft: #2e1065;
  --spk-0: #2bb3a3; --spk-1: #a78bfa; --spk-2: #fb923c; --spk-3: #60a5fa; --spk-4: #f472b6; --spk-5: #a3e635;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "Geeza Pro", "Noto Sans Arabic", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 18px; }
h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; flex: none; }
.logo svg { width: 22px; height: 22px; stroke: var(--accent-ink); stroke-width: 2.4; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.sub { margin: 0; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; }

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px;
  max-width: 1280px; margin: 0 auto; padding: 20px 24px 60px;
}
.col-main, .col-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }

.banner { padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.error { background: var(--danger-soft); color: var(--danger); }

.tabs { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface-2); border-radius: 10px; margin-bottom: 16px; }
.tab { border: 0; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 30px 16px; border: 1.5px dashed var(--border); border-radius: 12px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { width: 30px; height: 30px; stroke: var(--accent); stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.dz-title { font-weight: 600; }
.dz-hint { color: var(--muted); font-size: 13px; }

.recorder { display: flex; align-items: center; gap: 18px; padding: 14px 4px; }
.rec-btn {
  width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface);
  display: grid; place-items: center; flex: none; transition: transform .1s;
}
.rec-btn:active { transform: scale(.96); }
.rec-dot { width: 26px; height: 26px; border-radius: 50%; background: var(--danger); transition: border-radius .15s, width .15s, height .15s; }
.rec-btn.recording .rec-dot { border-radius: 6px; width: 22px; height: 22px; }
.rec-btn.recording { border-color: var(--danger); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(180,35,24,.25); } 50% { box-shadow: 0 0 0 10px rgba(180,35,24,0); } }
.rec-info { flex: 1; min-width: 0; }
.rec-time { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.meter { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 6px 0; }
.meter-fill { height: 100%; width: 0; background: var(--accent); transition: width .08s; }
.rec-hint { color: var(--muted); font-size: 13px; }

.selected { margin-top: 14px; padding: 12px; background: var(--surface-2); border-radius: 10px; }
.selected-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.selected-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected audio { width: 100%; }

.components { margin-top: 16px; padding: 14px; background: var(--surface-2); border-radius: 12px; }
.comp-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; margin-bottom: 10px; }
.comp-head h2 { margin: 0; }
.final-order { font-size: 12px; color: var(--muted); font-weight: 600; }
.thinking-note { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }
.comp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px 12px; }
.comp { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; min-width: 0; }
.comp-name small { font-weight: 500; opacity: .8; }
.comp-pair { display: flex; gap: 6px; min-width: 0; }
.comp-pair select:first-child { flex: 1 1 auto; }
.comp-pair select.thinking, .comp-pair #window-s { flex: 0 0 auto; }
.comp select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0; width: 100%;
}
.comp-pair select { width: auto; }
.comp select:disabled { opacity: .55; }
.comp.off .comp-name { opacity: .6; }
.options { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-top: 16px; }
.opt { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.opt select, .opt input {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
.opt input { width: 78px; }
.primary {
  margin-left: auto; border: 0; background: var(--accent); color: var(--accent-ink);
  padding: 10px 18px; border-radius: 10px; font-weight: 700;
}
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 13px; padding: 2px 4px; }
.ghost { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; text-decoration: none; }

.progress-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.progress-stage { font-weight: 600; }
.progress-meta { color: var(--muted); font-size: 13px; }
.spinner { width: 20px; height: 20px; border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
.spinner.stopped { animation: none; border-color: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.bar-fill.indeterminate { width: 30%; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }

.results-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.stat b { font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.session { margin-top: 14px; }
.session summary { cursor: pointer; font-weight: 600; color: var(--muted); font-size: 14px; }
.session-lines { margin-top: 10px; max-height: 360px; overflow: auto; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.session-line { display: grid; grid-template-columns: 120px 1fr; gap: 10px; }
.session-line .ts { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; padding-top: 2px; }

.turns { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.extraction-h { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.term-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.term-chip {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.term-chip:hover { border-color: var(--accent); }
.term-count { font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 0 6px; }
.term-chip.static { cursor: default; }
.term-cat { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; border-radius: 999px; padding: 0 6px; background: var(--surface); color: var(--muted); }
.term-cat.cat-drug { background: var(--accent-soft); color: var(--accent); }
.term-cat.cat-diagnosis { background: var(--warn-soft); color: var(--warn); }
.term-cat.cat-dose_or_number { background: var(--ok-soft); color: var(--ok); }
.evidence-cell { min-width: 110px; }
.evidence-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.term-chip.small { font-size: 12px; padding: 1px 7px; }
.num-row { cursor: pointer; }
.num-row:hover td { background: var(--surface-2); }
.num-value { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.badge.route-verifier { background: var(--accent-soft); color: var(--accent); }
.row-gated td { color: var(--muted); }
.route-filter { display: flex; flex-wrap: wrap; gap: 6px; }
.route-filter .active { border-color: var(--accent); color: var(--accent); }
/* fact statuses (Jev): one colour per status */
.fact-filter { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.fact-filter .active { border-color: var(--accent); color: var(--accent); }
.fact-badges { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.fact { font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 8px; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.fact-present { background: var(--ok-soft); color: var(--ok); }
.fact-negated { background: var(--danger-soft); color: var(--danger); }
.fact-uncertain { background: var(--warn-soft); color: var(--warn); }
.fact-hypothetical { background: var(--info-soft); color: var(--info); }
.fact-ended { background: var(--surface-2); color: var(--muted); }
.fact-past { background: var(--surface-2); color: var(--text); }
.fact-future { background: var(--accent-soft); color: var(--accent); }
.fact-someone_else { background: var(--violet-soft); color: var(--violet); }
.fact-unknown { background: transparent; color: var(--muted); border: 1px dashed var(--border); }
td.said { min-width: 220px; }
#results[data-route="verifier"] .turn:not([data-route="verifier"]),
#results[data-route="gated"] .turn:not([data-route="gated"]) { display: none; }
.turn.flash { outline: 2px solid var(--accent); outline-offset: 2px; transition: outline-color 1.2s; }
.turn {
  display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px;
  border-left: 4px solid var(--spk-color, var(--accent));
}
.turn-meta { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.chip { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; color: var(--spk-color); background: color-mix(in srgb, var(--spk-color) 14%, transparent); }
.time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; text-transform: uppercase; letter-spacing: .03em; }
.badge.verified { background: var(--ok-soft); color: var(--ok); }
/* ElevenLabs word confidence: high >= 90%, mid >= 75%, low below */
.badge.conf { text-transform: none; }
.conf-high { background: var(--ok-soft); color: var(--ok); }
.conf-mid { background: var(--warn-soft); color: var(--warn); }
.conf-low { background: var(--danger-soft); color: var(--danger); }
.conf-none { background: transparent; color: var(--muted); border: 1px dashed var(--border); }
.term-conf { font-size: 10px; font-weight: 700; border-radius: 999px; padding: 0 6px; white-space: nowrap; }
.badge.unresolved, .badge.overlap { background: var(--warn-soft); color: var(--warn); }
.badge.failed { background: var(--danger-soft); color: var(--danger); }
.badge.too_short, .badge.asr_only, .badge.gated { background: var(--surface-2); color: var(--muted); }
.final { margin: 0 0 8px; font-size: 17px; line-height: 1.75; white-space: pre-wrap; unicode-bidi: plaintext; }
.final.empty { color: var(--muted); font-style: italic; font-size: 14px; }
.clip { width: 100%; max-width: 420px; height: 34px; }
.details { margin-top: 6px; }
.details summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.detail { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.detail.wide { grid-column: 1 / -1; }
.detail h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.detail p { margin: 0; white-space: pre-wrap; unicode-bidi: plaintext; font-size: 14px; }
.detail .err { color: var(--danger); font-size: 13px; }
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; margin-top: 8px; }
th, td { text-align: start; padding: 5px 6px; border-top: 1px solid var(--border); vertical-align: top; unicode-bidi: plaintext; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.sig-high { color: var(--danger); font-weight: 700; }
.usage { color: var(--muted); font-size: 12px; margin-top: 6px; }

.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.runs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 420px; overflow: auto; }
.runs li button {
  width: 100%; text-align: start; border: 0; background: transparent; color: var(--text);
  padding: 8px; border-radius: 8px; display: flex; flex-direction: column; gap: 2px;
}
.runs li button:hover, .runs li button.current { background: var(--surface-2); }
.run-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-meta { font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); font-size: 13px; }
.legend h2 { margin-bottom: 8px; }
.legend ol { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.legend b { color: var(--text); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .topbar { padding: 12px 16px; }
  .turn { grid-template-columns: 1fr; }
  .turn-meta { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .detail-grid { grid-template-columns: 1fr; }
  .primary { margin-left: 0; width: 100%; }
  .session-line { grid-template-columns: 1fr; gap: 0; }
}

/* ---------- debug view ---------- */
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); margin: 0; }
.debug-card { border-style: dashed; }
.debug-card table { margin-top: 12px; }
.ghost.small { padding: 4px 8px; font-size: 12px; }
.fold { margin-top: 10px; }
.fold summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
.debug-box { border: 1px dashed var(--border); }
pre.raw {
  margin: 6px 0 0; padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word;
  max-height: 360px; overflow: auto; unicode-bidi: plaintext;
}

.row-flag td { background: var(--warn-soft); }
.muted-stat { color: var(--muted); }
.user-box { display: flex; align-items: center; gap: 8px; }
/* fact types (Jev): one neutral chip per type; other and unknown stand out */
.ftype { font-size: 11px; font-weight: 600; border-radius: 6px; padding: 1px 7px; white-space: nowrap; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.ftype-medication, .ftype-dose { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.ftype-clinical_finding { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.ftype-allergy_intolerance { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.ftype-measurement, .ftype-weight, .ftype-height, .ftype-bmi, .ftype-age { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.ftype-family_history { background: var(--violet-soft); color: var(--violet); border-color: transparent; }
.ftype-procedure, .ftype-ongoing_therapy, .ftype-device, .ftype-immunisation, .ftype-follow_up { background: var(--info-soft); color: var(--info); border-color: transparent; }
.ftype-other { background: transparent; color: var(--muted); }
.ftype-unknown { background: transparent; color: var(--muted); border-style: dashed; }

/* Draft note (app/note.py): one colour only, amber, for what the doctor must check (N13) */
.note .review-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 12px 0 4px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.note-body { display: grid; gap: 4px; }
.note-sec { padding: 10px 0; border-top: 1px solid var(--border); }
.note-sec-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.note-sec-head h3 { font-size: 13px; font-weight: 600; margin: 0; }
.note-header { font-size: 14px; }
.note-line { padding: 2px 6px; margin: 0 -6px; border-radius: 6px; line-height: 1.5; }
.note-line.inline { display: inline; margin: 0; padding: 0; }
.note-line.plan { padding-left: 22px; }
.note-line.linked { cursor: pointer; }
.note-line.linked:hover { background: var(--surface-2); }
.note-cell { margin: 0; padding: 0; }
.note-empty { color: var(--muted); }
.note-problem { margin: 4px 0 8px; }
.note-problem-head { font-weight: 600; }
.note-mentioned-row { padding: 2px 0; }
.note mark.amber { background: var(--warn-soft); color: var(--warn); border-radius: 4px; padding: 0 3px; cursor: help; }
.note mark.amber:focus { outline: 2px solid var(--warn); outline-offset: 1px; }
.muted.small { font-size: 12px; }
.turn.source { outline: 2px solid var(--accent); outline-offset: 2px; }
