/* ECG viewer looks (2026-10-23). Light theme only, ECG-paper colours: white paper, pale red grid, dark trace. System fonts only
   (no web fonts: the page runs offline inside a hospital network). Dynamic values (band colours, tooltip position) are set from
   viewer.js through the CSSOM, never as style= attributes, because the page's CSP has style-src 'self'. */

:root {
  --paper: #ffffff;
  --grid-fine: #f7d2d2;
  --grid-coarse: #eaa0a0;
  --trace: #16213a;
  --ink: #1c1c1c;
  --muted: #5e6470;
  --line: #d9dde3;
  --card: #fafbfc;
  --accent: #1f5fbf;
  --error: #b3261e;
  --error-bg: #fdecea;
  --warn-bg: #fff4d6;
  --warn: #8a5a00;
  --ok: #2e7d32;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: #f3f4f6;
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }

.top, main, .foot { max-width: 1480px; margin: 0 auto; padding: 0 16px; }
.top { padding-top: 18px; }
.top h1 { margin: 0 0 4px; font-size: 22px; font-weight: 650; letter-spacing: 0.2px; }
.top .sub { margin: 0; color: var(--muted); max-width: 900px; }
.top .server { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }
.top .server.bad { color: var(--error); }
.foot { padding: 14px 16px 28px; color: var(--muted); font-size: 12.5px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); border: 0; white-space: nowrap;
}

/* the drop zone: the file input stays focusable (visually hidden, not display:none) and its label is the button */
.drop {
  margin: 14px 0 12px; padding: 18px 20px; text-align: center;
  background: var(--paper); border: 2px dashed #b9bfc8; border-radius: var(--radius);
  transition: border-color 120ms, background-color 120ms;
}
.drop.over { border-color: var(--accent); background: #eef4ff; }
.drop .button {
  display: inline-block; padding: 8px 16px; cursor: pointer; font-weight: 600;
  color: #fff; background: var(--accent); border-radius: 6px;
}
.drop .button:hover { background: #184e9e; }
.drop input:focus-visible ~ .button { outline: 3px solid #9cc0ff; outline-offset: 2px; }
.drop .hint { margin: 10px 0 0; color: var(--muted); }
.drop .fileinfo { margin: 8px 0 0; font-weight: 600; min-height: 1.2em; }
.drop .status { margin: 4px 0 0; color: var(--muted); min-height: 1.2em; }
.drop .status.busy { color: var(--accent); }
.drop .status.bad { color: var(--error); }

/* the result: summary cards above, the plot below, the raw response last */
.result { display: block; }
.ecg-error {
  margin: 0 0 12px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--error-bg); color: var(--error); border: 1px solid #f1b3ad; font-weight: 600;
}
.ecg-banner {
  margin: 0 0 12px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn); border: 1px solid #f0d08a; font-weight: 600;
}
.ecg-banner small { font-weight: 400; display: block; margin-top: 2px; }

/* 2026-10-23: plot first, then its legend, then the model's insight cards */
.ecg-legend-wrap { margin: 12px 0; }
.ecg-insights-title { font-size: 16px; margin: 18px 0 10px; }
.ecg-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-bottom: 12px;
}
.ecg-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0;
}
.ecg-card.wide { grid-column: 1 / -1; }
.ecg-card h2 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); font-weight: 650; }
.ecg-card h3 { margin: 10px 0 4px; font-size: 13px; font-weight: 650; }
.ecg-card p { margin: 4px 0; }
.ecg-card .muted { color: var(--muted); }
.ecg-card .small { font-size: 12.5px; }

.ecg-calls { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 8px; }
.ecg-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  font-weight: 650; font-size: 13px; color: #fff; background: #777;
}
.ecg-chip .dur { font-weight: 400; opacity: 0.9; }
.ecg-chip.light { color: var(--ink); }

.ecg-kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; margin: 0; }
.ecg-kv dt { color: var(--muted); }
.ecg-kv dd { margin: 0; font-variant-numeric: tabular-nums; }

.ecg-badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; vertical-align: 1px;
  background: #e5e7eb; color: #333;
}
.ecg-badge.ok { background: #dff3e1; color: var(--ok); }
.ecg-badge.bad { background: var(--error-bg); color: var(--error); }
.ecg-badge.warn { background: var(--warn-bg); color: var(--warn); }

/* probability bars (ECGFounder second opinion, model class probabilities) */
.ecg-bars { display: grid; grid-template-columns: max-content 1fr max-content; gap: 3px 8px; align-items: center; margin: 6px 0 0; }
.ecg-bars .bar { height: 9px; background: #e9ecf0; border-radius: 4px; overflow: hidden; }
.ecg-bars .bar i { display: block; height: 100%; background: var(--accent); }
.ecg-bars .num { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--muted); }

.ecg-windows { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 6px; }
.ecg-windows span { padding: 1px 6px; border-radius: 4px; font-size: 11.5px; color: #fff; background: #888; }
.ecg-windows span.light { color: var(--ink); }

/* long recordings (2026-10-23 review): the ECGFounder chips past the first WINDOW_CHIPS hide while their list is folded (viewer.js
   foldButton toggles the class), and the per-minute sinus-arrhythmia measures sit in a closed <details>; both kept the plot of a
   10 min file two screens down */
.folded .folded { display: none; }
.ecg-more {
  font: inherit; font-size: 12.5px; margin-top: 6px; padding: 2px 10px; border-radius: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--accent); cursor: pointer;
}
.ecg-more:hover { background: #eef4ff; }
.ecg-fold { margin-top: 6px; }
.ecg-fold summary { cursor: pointer; font-size: 12.5px; color: var(--accent); }

.ecg-scroll { overflow-x: auto; max-width: 100%; }
table.ecg-table { border-collapse: collapse; width: 100%; font-size: 12.5px; margin-top: 6px; }
table.ecg-table th, table.ecg-table td { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.ecg-table th { color: var(--muted); font-weight: 600; }
table.ecg-table td.num { font-variant-numeric: tabular-nums; text-align: right; }
/* chips inside a table row are the compact size: the full chip made a per-minute row 40 px, ten minutes 487 px (2026-10-23 review) */
table.ecg-table .ecg-chip { padding: 1px 8px; font-size: 12px; }

ul.ecg-list { margin: 4px 0 0; padding-left: 18px; }
ul.ecg-list li { margin: 2px 0; }

/* the legend: colour swatches for rhythm classes and the beat markers */
.ecg-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; }
.ecg-legend .sw { display: inline-block; width: 14px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-right: 5px; background: #888; }
.ecg-legend .sw.hatch { background-image: repeating-linear-gradient(135deg, transparent 0 3px, rgba(255,255,255,0.75) 3px 5px); }
.ecg-legend .mk { display: inline-block; width: 14px; text-align: center; font-weight: 700; margin-right: 4px; }

/* plot controls */
.ecg-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; margin: 0 0 8px; padding: 8px 12px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
}
.ecg-controls label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.ecg-controls .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.ecg-controls .seg button {
  border: 0; background: #fff; padding: 4px 10px; cursor: pointer; font: inherit; color: var(--ink);
}
.ecg-controls .seg button + button { border-left: 1px solid var(--line); }
.ecg-controls .seg button.on { background: var(--accent); color: #fff; }
/* 2026-10-23: the second-opinion button (ECGFounder + scanner); pressed = their bands shown under every row */
.ecg-controls .second-btn {
  font: inherit; font-weight: 600; padding: 4px 10px; border: 1px solid var(--accent); border-radius: 6px; background: #fff;
  color: var(--accent); cursor: pointer;
}
.ecg-controls .second-btn.on { background: var(--accent); color: #fff; }
.ecg-controls .second-btn:disabled { opacity: 0.6; cursor: progress; }
.ecg-controls .note { color: var(--muted); font-size: 12.5px; margin-left: auto; }

/* the plot: one canvas per 10 s row, drawn by viewer.js; the paper is the canvas itself */
.ecg-plot { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 8px 4px; }
.ecg-row { display: block; margin: 0 0 8px; }
.ecg-row canvas { display: block; width: 100%; cursor: crosshair; }

/* the hover tooltip (position set through the CSSOM) */
.ecg-tip {
  position: fixed; z-index: 10; pointer-events: none; max-width: 340px;
  padding: 6px 9px; border-radius: 6px; background: rgba(28, 28, 28, 0.92); color: #fff; font-size: 12px; line-height: 1.4;
  white-space: pre-line; box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}
.ecg-tip.hidden { display: none; }

/* the raw response */
.ecg-raw { margin-top: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px; }
.ecg-raw summary { cursor: pointer; font-weight: 650; }
.ecg-raw .meta { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.ecg-raw button {
  font: inherit; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line); background: #fff; cursor: pointer; margin-left: 8px;
}
.ecg-raw pre {
  max-height: 520px; overflow: auto; margin: 6px 0 4px; padding: 8px; background: #f6f7f9; border-radius: 6px;
  font-size: 12px; line-height: 1.35;
}

@media (max-width: 720px) {
  .ecg-summary { grid-template-columns: 1fr; }
  .ecg-controls .note { margin-left: 0; }
}
