/* ============================================================
   ECG·LAB — clinical chart-paper workstation
   ============================================================ */

:root {
  --paper:      #f4f1e9;
  --paper-2:    #faf8f1;
  --paper-3:    #ebe6d8;
  --paper-4:    #e1dbc9;
  --ink:        #16191b;
  --ink-2:      #3c4245;
  --muted:      #767b7a;
  --muted-2:    #9b9f9c;
  --line:       #d8d2c2;
  --line-strong:#b7ae9a;
  --accent:     #b23a2b;
  --accent-2:   #8f2c20;
  --accent-soft:#f2ded8;
  --teal:       #0e6b63;
  --teal-soft:  #dbeae6;
  --amber:      #a16510;
  --amber-soft: #f4e7ca;
  --violet:     #57489b;
  --violet-soft:#e6e0f2;
  --blue:       #2f5d8a;
  --blue-soft:  #dfe8f2;
  --slate:      #5a6472;
  --slate-soft: #e5e7ea;
  --chart-bg:   #fffdf6;
  --chart-minor:#f2dcd6;
  --chart-major:#e8c3ba;
  --chart-trace:#1b1f21;
  --shadow:     0 1px 0 rgba(22,25,27,.04), 0 12px 32px -24px rgba(22,25,27,.45);

  --font-ui: "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Roboto Mono", Consolas, "Liberation Mono", monospace;

  --r-sm: 3px;
  --r-md: 5px;
  --rail-w: 318px;
}

html[data-theme="night"] {
  --paper:      #101416;
  --paper-2:    #151a1d;
  --paper-3:    #1d2427;
  --paper-4:    #263033;
  --ink:        #edeee9;
  --ink-2:      #c3c7c1;
  --muted:      #8b918d;
  --muted-2:    #69716d;
  --line:       #2b3437;
  --line-strong:#425054;
  --accent:     #e2685a;
  --accent-2:   #f08a7d;
  --accent-soft:#3a2320;
  --teal:       #59c3b4;
  --teal-soft:  #173430;
  --amber:      #e0a34a;
  --amber-soft: #35290f;
  --violet:     #a99ce6;
  --violet-soft:#262244;
  --blue:       #7bb0e0;
  --blue-soft:  #16283a;
  --slate:      #9aa6b4;
  --slate-soft: #222a30;
  --chart-bg:   #0d1113;
  --chart-minor:#1f2a2c;
  --chart-major:#2f4043;
  --chart-trace:#dfe8e2;
  --shadow:     0 1px 0 rgba(0,0,0,.3), 0 12px 32px -24px #000;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: clip;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
code {
  font-family: var(--font-mono);
  font-size: .86em;
  background: var(--paper-3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: .08em .38em;
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.eyebrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--muted);
}
.muted { color: var(--muted); }

/* ---------------- masthead ---------------- */
.masthead {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 62px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; flex: 0 0 auto; }
.brand-mark { width: 34px; height: 24px; color: var(--accent); align-self: center; }
.brand-name {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: .12em;
  font-size: 15px;
}
.brand-sub {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .08em;
  white-space: nowrap;
}
.modes { display: flex; align-items: stretch; gap: 2px; margin-left: 12px; height: 62px; }
.modes button {
  position: relative;
  padding: 0 14px;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: .04em;
  white-space: nowrap;
}
.modes button::after {
  content: "";
  position: absolute;
  left: 14px; right: 14px; bottom: -1px;
  height: 2px;
  background: transparent;
}
.modes button:hover { color: var(--ink); }
.modes button.is-on { color: var(--ink); }
.modes button.is-on::after { background: var(--accent); }
.mast-meta { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.corpus-stat {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .04em;
  white-space: nowrap;
}
.icon-btn {
  width: 30px; height: 30px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  background: var(--paper-2);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1;
}
.icon-btn:hover { border-color: var(--line-strong); color: var(--ink); }
.icon-btn:focus-visible, .btn:focus-visible, .chips button:focus-visible,
.tabs button:focus-visible, .seg button:focus-visible, .lead-switch button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------------- shell ---------------- */
.shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: calc(100vh - 62px);
  align-items: start;
}

/* ---------------- rail ---------------- */
.rail {
  position: sticky;
  top: 62px;
  height: calc(100vh - 62px);
  display: flex;
  flex-direction: column;
  background: var(--paper-2);
  border-right: 1px solid var(--line);
  min-width: 0;
}
.rail-head { padding: 16px 16px 10px; border-bottom: 1px solid var(--line); }
.rail-title { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.rail-count { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

.search {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper);
}
.search:focus-within { border-color: var(--line-strong); box-shadow: inset 0 0 0 1px var(--line-strong); }
.search svg { width: 13px; height: 13px; color: var(--muted); flex: 0 0 auto; }
.search input {
  border: 0; background: none; outline: none;
  width: 100%; min-width: 0;
  font-size: 12.5px;
}
.search input::placeholder { color: var(--muted-2); }

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.chips button {
  display: inline-flex; align-items: center; gap: 5px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 11px;
  color: var(--ink-2);
  background: var(--paper);
  white-space: nowrap;
}
.chips button .n {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}
.chips button:hover { border-color: var(--line-strong); }
.chips button.is-on { background: var(--ink); border-color: var(--ink); color: var(--paper-2); }
.chips button.is-on .n { color: color-mix(in srgb, var(--paper) 70%, transparent); }
.chips .swatch { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.rail-list { flex: 1 1 auto; overflow-y: auto; padding: 6px 8px 16px; scrollbar-width: thin; }
.group-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 8px 6px;
  background: linear-gradient(var(--paper-2) 72%, transparent);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.group-head::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.group-head .n { color: var(--muted-2); }

.rec-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 42px;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 8px 8px 8px 6px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  text-align: left;
}
.rec-row + .rec-row { margin-top: 1px; }
.rec-row:hover { background: var(--paper-3); }
.rec-row.is-on {
  background: var(--paper);
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}
.rec-row .rno {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
  text-align: right;
  letter-spacing: -.02em;
}
.rec-row.is-on .rno { color: var(--accent); }
.rec-row .rbody { min-width: 0; }
.rec-row .rtags {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rec-row .rbar {
  margin-top: 5px;
  height: 3px;
  background: var(--paper-4);
  border-radius: 2px;
  overflow: hidden;
}
.rec-row .rbar i { display: block; height: 100%; background: var(--accent); opacity: .75; }
.rec-row .rhr {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  line-height: 1.2;
}
.rec-row .rhr b { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.rail-empty { padding: 24px 12px; color: var(--muted); font-size: 12px; text-align: center; }
.rail-foot {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--muted);
  white-space: nowrap; overflow: hidden;
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--teal); flex: 0 0 auto; }

/* ---------------- workspace / views ---------------- */
.workspace { min-width: 0; padding: 22px 26px 64px; }
.view { max-width: 1320px; margin: 0 auto; }
.view[hidden] { display: none; }

/* ---------------- record header ---------------- */
.rec-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.rec-ident { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.rec-ident .eyebrow { align-self: center; }
.rec-ident h1 {
  font-family: var(--font-mono);
  font-size: 54px;
  line-height: .95;
  font-weight: 500;
  letter-spacing: -.045em;
  font-variant-numeric: tabular-nums;
}
.badge {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 3px 8px;
  border: 1px solid currentColor;
  border-radius: 20px;
  white-space: nowrap;
}
.badge[data-cat="sinus"] { color: var(--teal); }
.badge[data-cat="svt"] { color: var(--amber); }
.badge[data-cat="vent"] { color: var(--accent); }
.badge[data-cat="paced"] { color: var(--violet); }
.badge[data-cat="conduction"] { color: var(--blue); }
.rec-head-right { text-align: right; max-width: 560px; }
.rec-desc { font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }
.rec-actions { display: flex; gap: 6px; justify-content: flex-end; }

.btn {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-size: 12px;
  letter-spacing: .03em;
  color: var(--ink-2);
  background: var(--paper-2);
  white-space: nowrap;
}
.btn:hover { background: var(--ink); border-color: var(--ink); color: var(--paper-2); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--ink); }
.btn[disabled] { opacity: .5; pointer-events: none; }

.rec-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 10px 2px 0;
  font-size: 12px;
  color: var(--muted);
}
.rec-meta b { color: var(--ink-2); font-weight: 500; }
.rec-meta .sep { color: var(--line-strong); }

/* ---------------- metrics ---------------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--paper-2);
  overflow: hidden;
}
.metric { padding: 12px 14px; border-left: 1px solid var(--line); min-width: 0; }
.metric:first-child { border-left: 0; }
.metric .k {
  display: block;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric .v {
  font-family: var(--font-mono);
  font-size: 25px;
  font-weight: 500;
  letter-spacing: -.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.metric .v small { font-size: 11px; font-weight: 400; color: var(--muted); letter-spacing: 0; margin-left: 2px; }
.metric .s { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.metric.is-alert .v { color: var(--accent); }
.metric.is-warn .v { color: var(--amber); }

/* ---------------- chart ---------------- */
.chart-card {
  margin: 0 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--paper-2);
  overflow: hidden;
}
.chart-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.lead-switch { display: flex; gap: 4px; flex-wrap: wrap; }
.lead-switch button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 27px; padding: 0 9px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.lead-switch button:hover { color: var(--ink); background: var(--paper-3); }
.lead-switch button.is-on { color: var(--ink); border-color: var(--line-strong); background: var(--paper); }
.lead-switch .swatch { width: 8px; height: 2px; background: currentColor; }
.chart-tool-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cursor-readout {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-2);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 3px 7px;
  white-space: nowrap;
}
.cursor-readout.has-range { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); }
.jump-box { display: flex; align-items: center; gap: 3px; }
.jump-box input {
  width: 92px; height: 26px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--paper); color: var(--ink);
  font-family: var(--font-mono); font-size: 11px;
}
.jump-box input:focus { outline: none; border-color: var(--line-strong); box-shadow: inset 0 0 0 1px var(--line-strong); }
.jump-box .icon-btn { width: 26px; height: 26px; font-size: 12px; }
#selectToggle.is-on { background: var(--ink); border-color: var(--ink); color: var(--paper-2); }
.seg { display: flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg button { height: 26px; padding: 0 9px; font-size: 11px; color: var(--muted); background: var(--paper); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.is-on { background: var(--ink); color: var(--paper-2); }
.zoom-group { display: flex; align-items: center; gap: 4px; }
.zoom-group .icon-btn { width: 26px; height: 26px; font-size: 13px; }
.zoom-label {
  min-width: 52px; text-align: center;
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: clamp(280px, 46vh, 430px);
  background: var(--chart-bg);
  touch-action: none;
  cursor: crosshair;
}
.chart-wrap canvas { display: block; width: 100%; height: 100%; }
.chart-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  transform: translate(-50%, -115%);
  background: var(--ink);
  color: var(--paper-2);
  padding: 6px 9px;
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1.5;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.chart-tip b { color: #fff; font-weight: 600; }
.chart-hint {
  position: absolute;
  right: 10px; bottom: 6px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .03em;
  color: var(--muted-2);
  background: color-mix(in srgb, var(--chart-bg) 76%, transparent);
  padding: 1px 5px;
  border-radius: 3px;
  pointer-events: none;
}
.overview-wrap {
  height: 58px;
  border-top: 1px solid var(--line);
  background: var(--paper-2);
  cursor: pointer;
}
.overview-wrap canvas { display: block; width: 100%; height: 100%; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}
.chart-legend .lg { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.chart-legend .lg i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chart-legend .lg[data-g="N"] { color: var(--teal); }
.chart-legend .lg[data-g="S"] { color: var(--amber); }
.chart-legend .lg[data-g="V"] { color: var(--accent); }
.chart-legend .lg[data-g="F"] { color: var(--violet); }
.chart-legend .lg[data-g="Q"] { color: var(--slate); }
.chart-legend .spacer { flex: 1; }
.chart-legend .note { color: var(--muted-2); font-family: var(--font-mono); font-size: 10px; }

/* ---------------- tabs ---------------- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative;
  padding: 9px 14px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}
.tabs button::after {
  content: "";
  position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px;
  background: transparent;
}
.tabs button:hover { color: var(--ink); }
.tabs button.is-on { color: var(--ink); }
.tabs button.is-on::after { background: var(--accent); }
.tab-count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  margin-left: 3px;
}

.tab-body { min-height: 200px; }
.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--paper-2);
  padding: 14px 16px 16px;
  min-width: 0;
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin-bottom: 10px;
}
.card-head h2 {
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  font-weight: 600;
}
.card-head .hint { font-size: 11px; color: var(--muted); }
.prose { font-size: 13px; color: var(--ink-2); }
.prose p + p { margin-top: 8px; }

.verdict { display: flex; align-items: flex-start; gap: 14px; }
.verdict .mark {
  flex: 0 0 auto;
  width: 8px; height: 46px;
  border-radius: 2px;
  background: var(--teal);
}
.verdict[data-cat="svt"] .mark { background: var(--amber); }
.verdict[data-cat="vent"] .mark { background: var(--accent); }
.verdict[data-cat="paced"] .mark { background: var(--violet); }
.verdict[data-cat="conduction"] .mark { background: var(--blue); }
.verdict h3 { font-size: 21px; font-weight: 600; letter-spacing: -.015em; line-height: 1.25; }
.verdict .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

.findings { list-style: none; padding: 0; margin: 0; }
.findings li {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
}
.findings li:first-child { border-top: 0; }
.findings .lv {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding-top: 2px;
}
.findings .lv.ok { color: var(--teal); }
.findings .lv.info { color: var(--blue); }
.findings .lv.warn { color: var(--amber); }
.findings .lv.alert { color: var(--accent); }

/* composition bar */
.comp-bar {
  display: flex;
  height: 16px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--paper-4);
  margin: 4px 0 10px;
}
.comp-bar i { display: block; height: 100%; }
.comp-bar i[data-g="N"] { background: var(--teal); }
.comp-bar i[data-g="S"] { background: var(--amber); }
.comp-bar i[data-g="V"] { background: var(--accent); }
.comp-bar i[data-g="F"] { background: var(--violet); }
.comp-bar i[data-g="Q"] { background: var(--slate); }
.comp-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 4px 10px; }
.comp-legend div { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 11.5px; padding: 3px 0; }
.comp-legend .nm { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-2); }
.comp-legend .nm i { width: 7px; height: 7px; border-radius: 2px; }
.comp-legend b { font-family: var(--font-mono); font-weight: 500; }

/* rhythm timeline */
.rhythm-line { position: relative; height: 34px; background: var(--paper-3); border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.rhythm-line i, .rhythm-line .rseg {
  position: absolute; top: 0; bottom: 0; min-width: 1px; opacity: .55;
  padding: 0; border: 0; border-radius: 0;
}
.rhythm-line .rseg { cursor: pointer; }
.rhythm-line .rseg:hover, .rhythm-line .rseg:focus-visible { opacity: .9; outline: 1px solid var(--ink); z-index: 1; }
.rhythm-line i[data-cat="sinus"], .rhythm-line .rseg[data-cat="sinus"],
.rhythm-legend i[data-cat="sinus"] { background: var(--teal); }
.rhythm-line i[data-cat="svt"], .rhythm-line .rseg[data-cat="svt"],
.rhythm-legend i[data-cat="svt"] { background: var(--amber); }
.rhythm-line i[data-cat="vent"], .rhythm-line .rseg[data-cat="vent"],
.rhythm-legend i[data-cat="vent"] { background: var(--accent); }
.rhythm-line i[data-cat="paced"], .rhythm-line .rseg[data-cat="paced"],
.rhythm-legend i[data-cat="paced"] { background: var(--violet); }
.rhythm-line i[data-cat="conduction"], .rhythm-line .rseg[data-cat="conduction"],
.rhythm-legend i[data-cat="conduction"] { background: var(--blue); }
.rhythm-line i[data-cat="unknown"], .rhythm-line .rseg[data-cat="unknown"],
.rhythm-legend i[data-cat="unknown"] { background: var(--muted-2); }
.rhythm-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 2px; font-size: 11px; color: var(--muted); }
.rhythm-legend span { display: inline-flex; align-items: center; gap: 5px; }
.rhythm-legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.rhythm-axis { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 10px; color: var(--muted); }
.rhythm-events { list-style: none; padding: 0; margin: 10px 0 0; max-height: 420px; overflow-y: auto; scrollbar-width: thin; }
.rhythm-events li {
  display: grid;
  grid-template-columns: 104px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.rhythm-events li:first-child { border-top: 0; }
.rhythm-events .t { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.rhythm-events .code { font-family: var(--font-mono); font-size: 10px; color: var(--muted-2); }
.rhythm-events button { font-size: 11px; color: var(--accent); }

/* algorithm compare */
.algo-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.algo-stat { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; background: var(--paper); }
.algo-stat .k { display: block; font-family: var(--font-mono); font-size: 9px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.algo-stat .v { font-family: var(--font-mono); font-size: 17px; font-variant-numeric: tabular-nums; }
.matrix { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 11px; }
.matrix th, .matrix td { border: 1px solid var(--line); padding: 4px 6px; text-align: center; }
.matrix th { font-weight: 500; color: var(--muted); background: var(--paper-3); font-size: 10px; }
.matrix td.hit { background: var(--teal-soft); color: var(--teal); font-weight: 600; }
.matrix td.miss { color: var(--muted-2); }
.matrix .rowh { text-align: left; background: var(--paper-3); color: var(--ink-2); }
.algo-note { font-size: 11px; color: var(--muted); margin-top: 8px; }

/* beat inspector */
.beat-inspector { display: grid; grid-template-columns: minmax(0, 1fr) 168px; gap: 12px; align-items: center; }
.beat-inspector canvas { width: 100%; height: 108px; background: var(--chart-bg); border: 1px solid var(--line); border-radius: var(--r-sm); }
.beat-facts { font-family: var(--font-mono); font-size: 11px; }
.beat-facts div { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dotted var(--line); }
.beat-facts div:last-child { border-bottom: 0; }
.beat-facts span { color: var(--muted); }
.beat-facts b { font-weight: 500; }
.beat-inspector .empty { grid-column: 1 / -1; color: var(--muted); font-size: 12px; padding: 18px 0; text-align: center; }

/* beat table */
.table-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.table-tools .seg button { height: 25px; }
.table-tools .grow { flex: 1; }
.table-tools .count { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.beat-table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r-sm); max-height: 62vh; }
table.beat-table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 11.5px; }
.beat-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--paper-3);
  text-align: left;
  font-weight: 500;
  font-size: 9.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  text-transform: none;
  letter-spacing: .06em;
}
.beat-table tbody td { padding: 5px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.beat-table tbody tr:hover { background: var(--paper-3); cursor: pointer; }
.beat-table tbody tr.is-on { background: var(--accent-soft); }
.beat-table .sym { font-weight: 600; }
.beat-table .sym[data-g="N"] { color: var(--teal); }
.beat-table .sym[data-g="S"] { color: var(--amber); }
.beat-table .sym[data-g="V"] { color: var(--accent); }
.beat-table .sym[data-g="F"] { color: var(--violet); }
.beat-table .sym[data-g="Q"] { color: var(--slate); }
.beat-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.beat-table .dash { color: var(--muted-2); }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding-top: 10px; font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.pager button { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px 9px; }
.pager button:hover { border-color: var(--line-strong); color: var(--ink); }

/* raw info */
.kv { display: grid; grid-template-columns: 132px minmax(0, 1fr); border-top: 1px solid var(--line); font-size: 12.5px; }
.kv div { padding: 7px 2px; border-bottom: 1px solid var(--line); }
.kv dt, .kv .k { color: var(--muted); font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .05em; }
.kv .v { color: var(--ink-2); word-break: break-word; }
.comment-list { list-style: none; padding: 0; margin: 0; font-size: 12.5px; }
.comment-list li { padding: 6px 0 6px 14px; border-bottom: 1px dotted var(--line); position: relative; color: var(--ink-2); }
.comment-list li::before { content: "·"; position: absolute; left: 2px; color: var(--muted-2); }
.dl-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ---------------- upload ---------------- */
.upload-head h1, .about-head h1 {
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.12;
  letter-spacing: -.035em;
  font-weight: 600;
  margin: 6px 0 10px;
}
.upload-head p, .about-head p { max-width: 70ch; color: var(--ink-2); font-size: 14px; }
.upload-head { padding-bottom: 18px; }
.dropzone {
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 40px 20px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: var(--paper-2);
  text-align: center;
  transition: background .15s ease, border-color .15s ease;
}
.dropzone svg { width: 42px; height: 42px; color: var(--muted); margin-bottom: 6px; }
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.is-over svg { color: var(--accent); }
.dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dz-main { font-size: 15px; font-weight: 500; }
.dz-main .link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.dz-sub { font-size: 11.5px; color: var(--muted); font-family: var(--font-mono); }
.upload-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; padding: 14px 2px; font-size: 12px; color: var(--ink-2); }
.upload-opts label { display: inline-flex; align-items: center; gap: 7px; }
.upload-opts input[type="number"] {
  width: 74px; height: 28px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--paper-2); font-family: var(--font-mono); font-size: 12px;
}
.upload-opts .unit { color: var(--muted); font-family: var(--font-mono); font-size: 11px; margin-left: -3px; }
.upload-opts input[type="checkbox"] { accent-color: var(--accent); }
.upload-queue { display: grid; gap: 8px; }
.up-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper-2);
}
.up-item .ico { font-family: var(--font-mono); font-size: 10px; text-align: center; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 3px 0; }
.up-item .name { font-family: var(--font-mono); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-item .stat { font-size: 11px; color: var(--muted); }
.up-item .stat.err { color: var(--accent); }
.up-item .stat.ok { color: var(--teal); }
.upload-note { margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--line); }
.upload-note h2 { font-size: 12px; font-family: var(--font-mono); letter-spacing: .1em; text-transform: uppercase; margin-bottom: 8px; }
.upload-note ol { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); }
.upload-note li + li { margin-top: 6px; }

/* ---------------- about ---------------- */
.about-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 28px; margin-top: 22px; }
.about-grid article { border-top: 1px solid var(--line-strong); padding-top: 12px; }
.about-grid h2 { font-size: 12px; font-family: var(--font-mono); letter-spacing: .1em; text-transform: uppercase; margin-bottom: 8px; }
.about-grid p { font-size: 13px; color: var(--ink-2); }
.about-grid p + p { margin-top: 8px; }
.about-foot {
  display: flex; flex-wrap: wrap; gap: 8px 24px;
  margin-top: 28px; padding-top: 12px;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 10px; color: var(--muted);
}

/* ---------------- toast ---------------- */
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: grid; gap: 8px; }
.toast {
  min-width: 220px; max-width: 360px;
  background: var(--ink); color: var(--paper-2);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  font-size: 12px;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease-out;
}
.toast.err { background: var(--accent-2); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------- loading ---------------- */
.skeleton { padding: 40px; text-align: center; font-family: var(--font-mono); font-size: 12px; color: var(--muted); letter-spacing: .1em; }

/* ---------------- responsive ---------------- */
@media (max-width: 1180px) {
  :root { --rail-w: 272px; }
  .workspace { padding: 18px 18px 56px; }
  .panel-grid { grid-template-columns: minmax(0, 1fr); }
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric:nth-child(4) { border-left: 0; border-top: 1px solid var(--line); }
  .metric:nth-child(5) { border-top: 1px solid var(--line); }
}

@media (max-width: 900px) {
  .masthead { gap: 10px; padding: 0 14px; flex-wrap: wrap; min-height: 56px; }
  .brand-sub { display: none; }
  .modes { margin-left: 0; height: 56px; }
  .mast-meta .corpus-stat { display: none; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: static;
    height: auto;
    max-height: 46vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .rail-list { max-height: 30vh; }
  .workspace { padding: 16px 14px 52px; }
  .rec-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .rec-head-right { text-align: left; }
  .rec-actions { justify-content: flex-start; }
  .rec-ident h1 { font-size: 44px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .metric:nth-child(4) { border-left: 1px solid var(--line); border-top: 1px solid var(--line); }
  .metric:nth-child(5) { border-top: 1px solid var(--line); }
  .algo-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .about-grid { grid-template-columns: minmax(0, 1fr); }
  .chart-wrap { height: clamp(250px, 50vh, 380px); }
  .beat-inspector { grid-template-columns: minmax(0, 1fr); }
  .beat-inspector canvas { height: 96px; }
}

@media (max-width: 560px) {
  .masthead { padding: 0 10px; }
  .brand-name { font-size: 13px; letter-spacing: .08em; }
  .brand-mark { width: 26px; height: 18px; }
  .modes button { padding: 0 9px; font-size: 12px; }
  .modes button::after { left: 9px; right: 9px; }
  .workspace { padding: 12px 10px 48px; }
  .rec-ident h1 { font-size: 38px; }
  .rec-head-right { max-width: 100%; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { padding: 10px 10px; }
  .metric .v { font-size: 21px; }
  .chart-tools { padding: 6px 8px; }
  .chart-hint { display: none; }
  .cursor-readout { display: none; }
  .jump-box input { width: 78px; }
  .tabs button { padding: 9px 10px; }
  .findings li { grid-template-columns: 48px minmax(0, 1fr); }
  .kv { grid-template-columns: 96px minmax(0, 1fr); }
  .card { padding: 12px 12px 14px; }
  .upload-head h1, .about-head h1 { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
  :root { --paper: #fff; --paper-2: #fff; --paper-3: #f4f4f4; --line: #ccc; }
  .masthead, .rail, .tabs, .chart-tools, .rec-actions, .overview-wrap, .chart-hint, .toast-region, .chart-legend { display: none !important; }
  .shell { display: block; }
  .workspace { padding: 0; }
  .chart-wrap { height: 300px; }
  .panel-grid { grid-template-columns: 1fr; }
  .card { break-inside: avoid; }
}

/* ---------------- loading overlay ---------------- */
.view-loading {
  position: fixed;
  left: 50%;
  top: 78px;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--ink);
  color: var(--paper-2);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .08em;
  padding: 7px 14px;
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.view-loading[hidden] { display: none; }
