:root {
  --ink: #16191d;
  --ink-2: #4a5058;
  --ink-3: #767d85;
  --line: #d3d7dc;
  --line-2: #e6e9ec;
  --surface: #ffffff;
  --surface-2: #f5f6f8;
  --canvas: #f7f8fa;
  --accent: #12395f;
  --accent-soft: #e7edf4;
  --ok: #177d3c;
  --ok-soft: #eef6f0;
  --run: #b56d00;
  --run-soft: #fff7e8;
  --mono: ui-monospace, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; color: var(--ink); background: var(--surface-2); font: 12px/1.4 var(--font); -webkit-font-smoothing: antialiased; }
button, input, audio { font: inherit; }
button, a, label { touch-action: manipulation; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: 600; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }

.asr-app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; min-height: 31px; padding: 0 11px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.97); }
.back-link { color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.back-link:hover { color: var(--ink); text-decoration: underline; }
.top-brand { font-weight: 600; white-space: nowrap; }
.top-context { color: var(--ink-3); white-space: nowrap; }
.top-spacer { flex: 1; }
.top-note { color: var(--ink-3); font-size: 10px; white-space: nowrap; }

.page { width: min(1420px, calc(100% - 22px)); margin: 0 auto; padding: 17px 0 30px; }
.titlebar { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding: 0 1px 12px; }
.eyebrow { color: var(--ink-3); font-size: 10px; letter-spacing: .08em; line-height: 1.25; text-transform: uppercase; }
h1 { margin-top: 2px; font-size: clamp(22px, 2.5vw, 30px); letter-spacing: -.02em; line-height: 1.1; }
h2 { margin-top: 2px; font-size: 14px; line-height: 1.2; }
h3 { font-size: 12px; line-height: 1.25; }
.title-path { padding-bottom: 2px; color: var(--ink-3); font-size: 11px; }

.control-grid { display: grid; grid-template-columns: minmax(0, .92fr) minmax(0, 1.08fr); gap: 10px; }
.control-panel, .workflow-panel, .output-panel { min-width: 0; border: 1px solid var(--line); background: var(--surface); }
.control-head, .workflow-head, .output-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.control-state { display: flex; align-items: center; gap: 5px; color: var(--ink-3); font: 10px var(--mono); text-transform: uppercase; }
.control-dot, .source-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #9aa1a9; }
.control-dot.live { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.control-dot.scanning { background: var(--run); box-shadow: 0 0 0 3px var(--run-soft); animation: qr-scan-pulse .8s ease-in-out infinite; }
@keyframes qr-scan-pulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}
.control-dot.done { background: var(--accent); }
.control-main { display: flex; align-items: baseline; gap: 9px; padding: 9px 10px 7px; }
.control-main strong { font-size: 13px; white-space: nowrap; }
.control-main span { color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.button-row { display: flex; gap: 6px; padding: 0 10px 8px; }
.qr-scanner { margin: 0 10px 8px; padding: 8px; border: 1px solid var(--line-2); background: var(--surface-2); }
.qr-scanner[hidden] { display: none; }
.qr-scanner-head, .qr-scanner-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.qr-scanner-head { font-size: 11px; }
.qr-scanner-foot { margin-top: 6px; font-size: 10px; }
.qr-video-wrap { position: relative; aspect-ratio: 4 / 3; margin-top: 7px; overflow: hidden; background: #111; }
.qr-video-wrap video { display: block; width: 100%; height: 100%; object-fit: cover; }
.qr-frame { position: absolute; inset: 15% 18%; border: 2px solid rgba(255,255,255,.9); border-radius: 10px; box-shadow: 0 0 0 999px rgba(0,0,0,.18); pointer-events: none; }
.action { min-height: 26px; padding: 3px 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); }
.action:hover, .file-button:hover { background: var(--surface-2); color: var(--ink); }
.action.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.action.primary:hover { background: #0c2d4d; }
.action:disabled { cursor: wait; opacity: .6; }
.control-foot { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; padding: 7px 10px 8px; border-top: 1px solid var(--line-2); color: var(--ink-2); font-size: 11px; }
.source-line { display: flex; align-items: center; gap: 6px; grid-column: 1 / -1; min-width: 0; }
.source-line strong { white-space: nowrap; }
.source-line .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-dot { flex: 0 0 auto; background: var(--accent); }
.timer-line, .deactivation-line { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.deactivation-line { justify-content: flex-end; }
.meta-label { color: var(--ink-3); font-size: 10px; letter-spacing: .04em; text-transform: uppercase; }
.timer-line strong { color: var(--ink); font-size: 12px; }
.text-button { border: 0; padding: 1px 3px; background: transparent; color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.text-button:hover { color: var(--ink); text-decoration: none; }

.audio-file { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 9px 10px 5px; }
.audio-file strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 11px var(--mono); }
audio { display: block; width: calc(100% - 20px); height: 31px; margin: 0 10px 7px; }
.audio-actions { display: flex; align-items: center; gap: 7px; min-height: 42px; padding: 7px 10px; border-top: 1px solid var(--line-2); background: var(--surface-2); }
.file-button { display: inline-flex; align-items: center; min-height: 26px; padding: 3px 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); cursor: pointer; }
.analysis-status { color: var(--ink-3); font-size: 11px; }
.analysis-status.running { color: var(--run); }
.analysis-status.done { color: var(--ok); }
.file-list { display: none; margin: 0 10px 8px; padding: 6px 8px; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink-2); font: 10px var(--mono); }
.file-list:not(:empty) { display: block; }
.file-list-header { margin-bottom: 4px; color: var(--ink-3); }
.file-list ul { display: grid; gap: 2px; max-height: 110px; margin: 0; padding: 0; overflow: auto; list-style: none; }
.file-list li { display: flex; justify-content: space-between; gap: 10px; min-width: 0; }
.file-list li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .file-size { flex: 0 0 auto; color: var(--ink-3); }
.recording-indicator { display: none; align-items: center; gap: 8px; margin: 0 10px 7px; padding: 7px 9px; border: 1px solid #e3aaa5; background: #fff1f0; color: #9d2018; font-size: 11px; }
.asr-app.recording .recording-indicator { display: flex; }
.recording-indicator-copy { min-width: 0; overflow: hidden; color: #b34d46; text-overflow: ellipsis; white-space: nowrap; }
.recording-pulse { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: #c92a2a; box-shadow: 0 0 0 3px rgba(201,42,42,.16); animation: recording-pulse 1s ease-in-out infinite; }
.asr-app.recording #record-button { border-color: #b42318; background: #c92a2a; color: #fff; box-shadow: 0 0 0 3px rgba(201,42,42,.16); }
.asr-app.recording #record-button:hover { background: #a61f1f; }
.asr-app.recording #record-button::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: #fff; animation: recording-pulse 1s ease-in-out infinite; }
@keyframes recording-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.workflow-panel { margin-top: 10px; }
.workflow-head { align-items: end; }
.workflow-head > .muted { padding-bottom: 1px; font-size: 10px; }
.workflow-scroll { overflow: auto; padding: 16px 18px 19px; outline: none; background-color: var(--canvas); background-image: radial-gradient(#d9dde2 .75px, transparent .75px); background-size: 16px 16px; scrollbar-color: #aeb7c0 var(--canvas); scrollbar-width: thin; }
.workflow-scroll:focus-visible { box-shadow: inset 0 0 0 2px var(--accent-soft); }
.workflow-grid { position: relative; width: 782px; height: 300px; margin: 0; }
.node { position: absolute; z-index: 1; display: flex; width: 152px; min-height: 112px; flex-direction: column; padding: 7px 8px 8px; border: 1px solid #cbd1d7; border-top: 3px solid #aeb7c0; border-radius: 4px; background: var(--surface); box-shadow: 0 2px 5px rgba(22,25,29,.09); }
.node[data-stage="capture"] { left: 0; top: 30px; }
.node[data-stage="trim"] { left: 210px; top: 30px; }
.node[data-stage="relevance"] { left: 630px; top: 30px; }
.node[data-stage="voice"] { left: 420px; top: 30px; }
.node[data-stage="context"] { left: 630px; top: 198px; }
.node[data-stage="extract"] { left: 420px; top: 198px; }
.node[data-stage="output"] { left: 210px; top: 198px; }
.node-trigger { border-top-color: var(--accent); }
.node-filter { border-top-color: #687681; }
.node-model { border-top-color: #b56d00; }
.node-join { border-top-color: #7a5a91; }
.node-llm { border-top-color: #b54b6b; }
.node-output { border-top-color: var(--accent); }
.node.active { border-color: #d3a55b; border-top-color: var(--run); background: var(--run-soft); }
.node.done { border-color: #a9cdb4; border-top-color: var(--ok); background: var(--ok-soft); }
.node-output.done { border-color: #a7bdd5; border-top-color: var(--accent); background: var(--accent-soft); }
.node-head { display: flex; align-items: center; gap: 5px; margin-bottom: 10px; }
.node-icon { display: inline-grid; flex: 0 0 auto; place-items: center; width: 18px; height: 18px; border: 1px solid var(--line); color: var(--accent); font: 11px var(--mono); }
.node-type { color: var(--ink-3); font: 9px var(--mono); letter-spacing: .04em; }
.node-status { margin-left: auto; color: var(--ink-3); font: 9px var(--mono); text-transform: uppercase; }
.node.active .node-status { color: var(--run); }
.node.done .node-status { color: var(--ok); }
.node h3 { margin-bottom: 5px; }
.node p { flex: 1; color: var(--ink-2); font-size: 11px; }
.node-meta { margin-top: 7px; color: var(--ink-3); font: 8px/1.3 var(--mono); overflow-wrap: anywhere; }
.node-port { position: absolute; width: 8px; height: 8px; margin-top: -4px; border: 2px solid #87939f; border-radius: 50%; background: var(--surface); }
.port-in { top: 50%; left: -5px; }
.port-out { top: 50%; right: -5px; }
.port-in-right { top: 50%; right: -5px; }
.port-out-left { top: 50%; left: -5px; }
.port-in-down { top: -5px; left: 50%; margin-left: -4px; }
.port-out-down { right: auto; bottom: -5px; left: 50%; margin-top: 0; margin-left: -4px; }
.connector { position: absolute; z-index: 0; height: 2px; background: #9da7b0; }
.connector-right { width: 58px; }
.connector-left { width: 58px; }
.connector-down { width: 2px; height: 56px; }
.connector-12, .connector-23, .connector-34 { top: 86px; }
.connector-12 { left: 152px; }
.connector-23 { left: 362px; }
.connector-34 { left: 572px; }
.connector-45 { top: 142px; left: 706px; }
.connector-56, .connector-67 { top: 254px; }
.connector-56 { left: 572px; }
.connector-67 { left: 362px; }
.connector-right::after { position: absolute; top: -4px; right: -1px; content: ""; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 7px solid #9da7b0; }
.connector-left::after { position: absolute; top: -4px; left: -1px; content: ""; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-right: 7px solid #9da7b0; }
.connector-down::after { position: absolute; bottom: -1px; left: -4px; content: ""; border-right: 5px solid transparent; border-left: 5px solid transparent; border-top: 7px solid #9da7b0; }

.output-panel { margin-top: 10px; }
.output-actions { display: flex; align-items: center; gap: 9px; }
.input-summary { display: flex; align-items: center; gap: 0; min-height: 26px; padding: 4px 9px; overflow-x: auto; border-bottom: 1px solid var(--line-2); background: #fbfcfd; color: var(--ink-2); font: 10px var(--mono); white-space: nowrap; scrollbar-width: thin; }
.input-summary > span:not(:last-child)::after { content: " · "; margin: 0 6px; color: #aab1b8; }
.input-summary-label { color: var(--ink-3); letter-spacing: .06em; text-transform: uppercase; }
.table-scroll { max-height: 360px; overflow: auto; scrollbar-color: #aeb7c0 var(--surface); scrollbar-width: thin; }
.output-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.output-table th { position: sticky; top: 0; z-index: 1; padding: 5px 9px; border-bottom: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); font-size: 11px; font-weight: 600; text-align: left; }
.output-table th:first-child { width: 28%; }
.output-table td { padding: 6px 9px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.output-table td:first-child { color: var(--ink-2); font-weight: 600; }
.output-table td:last-child { white-space: pre-line; }
.output-table tr:last-child td { border-bottom: 0; }
.output-table tr:hover td { background: var(--accent-soft); }
.json-panel { margin: 10px; border: 1px solid var(--line); background: var(--surface-2); }
.json-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 8px; border-bottom: 1px solid var(--line); color: var(--ink-2); font-size: 11px; }
.json-panel pre { max-height: 330px; margin: 0; padding: 9px; overflow: auto; font: 11px/1.45 var(--mono); white-space: pre-wrap; }
.output-footnote { padding: 8px 10px 9px; border-top: 1px solid var(--line-2); color: var(--ink-3); font-size: 10px; }

@media (max-width: 760px) {
  .page { width: calc(100% - 14px); padding-top: 13px; }
  .topbar { gap: 8px; }
  .top-context, .top-note { display: none; }
  .titlebar { align-items: start; flex-direction: column; gap: 4px; padding-bottom: 10px; }
  .control-grid { grid-template-columns: 1fr; }
  .workflow-grid { margin: 0; }
  .output-table { min-width: 680px; table-layout: auto; }
}

@media (max-width: 440px) {
  .control-main { align-items: start; flex-direction: column; gap: 2px; }
  .control-main span { max-width: 100%; }
  .control-foot { grid-template-columns: 1fr; }
  .deactivation-line { justify-content: flex-start; }
  .audio-actions { flex-wrap: wrap; }
}

.patient-card { margin: 0 10px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.patient-card summary { padding: 8px 10px; cursor: pointer; font-weight: 600; list-style-position: inside; }
.patient-card summary .muted { font-weight: 400; }
.patient-card textarea {
  display: block; width: calc(100% - 20px); margin: 0 10px 10px; padding: 8px 9px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
  color: var(--ink); font: 11px/1.5 var(--mono); resize: vertical; min-height: 72px;
}
