/* =====================================================
   EKGLab — Cardiac Monitor Simulator
   Light grey page · dark floating ECG screen · white widget cards
   ===================================================== */

:root {
    /* Page */
    --page-bg:     #e8e8ec;

    /* ECG monitor card */
    --ecg-bg:      #060810;
    --ecg-border:  rgba(194, 231, 217, 0.10);
    --ecg-glow:    rgba(194, 231, 217, 0.06);
    --trace:       #c2e7d9;
    --grid-minor:  rgba(140, 140, 148, 0.18);
    --grid-major:  rgba(140, 140, 148, 0.36);

    /* Widget cards */
    --card-bg:     #ffffff;
    --card-border: rgba(0,0,0,0.07);
    --card-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.06);

    /* Numerics colors */
    --c-hr:      #a6cfd5;
    --c-rhythm:  #d4830a;
    --c-time:    #1a1a2e;
    --c-beat:    #c0392b;

    /* Controls */
    --ctrl-bg:    #ffffff;
    --ctrl-label: #9e9e9e;
    --ctrl-text:  #2c2c3e;
    --ctrl-border:#e0e0e0;

    /* Typography */
    --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

    /* Layout */
    --max-w:    960px;
    --r-card:   16px;
    --r-widget: 12px;
}

/* ── Reset & base ──────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
    min-height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    color: var(--ctrl-text);
    -webkit-font-smoothing: antialiased;
    overflow-y: auto;
}

/* ── App container ─────────────────────────────────── */

#app {
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* ── ECG Monitor Card (visual handled by Tailwind classes) ──────── */

#ecgCard {
    /* bg-[#1a1d23] rounded-2xl overflow-hidden shadow-xl applied via Tailwind */
    position: relative;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.10), 0 4px 24px rgba(0,0,0,0.12);
}

/* Decorative top + fading left stroke — clips to card's border-radius
   via the parent's overflow:hidden */
#ecgCard::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    background:
        /* full-width 1px top line */
        linear-gradient(90deg, rgba(255,255,255,0.13) 100%, transparent)
            top / 100% 1px no-repeat,
        /* 1px left line fading to transparent halfway down */
        linear-gradient(180deg, rgba(255,255,255,0.13) 0%, transparent 50%)
            left / 1px 100% no-repeat;
}

/* In light mode the card is white so use a dark tint instead */
#ecgCard.ecg-paper::before {
    background:
        linear-gradient(90deg, rgba(0,0,0,0.08) 100%, transparent)
            top / 100% 1px no-repeat,
        linear-gradient(180deg, rgba(0,0,0,0.08) 0%, transparent 50%)
            left / 1px 100% no-repeat;
}

/* ── ECG header bar ────────────────────────────────────────── */
#ecgHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    background: rgba(0,0,0,0.18);
    flex-shrink: 0;
}

.ecg-hdr-left {
    display: flex;
    align-items: center;
    gap: 0;
}

/* Lead selector badge */
.lead-btn {
    display: inline-flex;
    align-items: center;
    padding: 5px 14px;
    background: rgba(194, 231, 217, 0.09);
    border: 1px solid rgba(194, 231, 217, 0.28);
    border-radius: 6px;
    color: var(--trace);
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.5px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    user-select: none;
}
.lead-btn:not(:disabled):hover {
    background: rgba(194, 231, 217, 0.16);
    border-color: rgba(194, 231, 217, 0.48);
    box-shadow: 0 0 0 3px rgba(194, 231, 217, 0.07);
}
.lead-btn:disabled { opacity: 0.30; cursor: default; }

/* Divider between lead badge and meta text */
.ecg-hdr-divider {
    width: 1px;
    height: 18px;
    background: rgba(255,255,255,0.09);
    margin: 0 14px;
}

.ecg-meta {
    font-size: 11px;
    color: rgba(255,255,255,0.38);
    font-family: var(--mono);
    letter-spacing: 0.4px;
}

/* ── Right-side controls ───────────────────────────────────── */
.ecg-hdr-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── ECG display theme toggle ─────────────────────────────────── */
.ecg-theme-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    user-select: none;
}
.ecg-theme-toggle input { display: none; }

.ecg-theme-icon {
    font-size: 12px;
    color: rgba(255,255,255,0.45);
    line-height: 1;
}

.ecg-theme-track {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    background: rgba(255,255,255,0.15);
    border-radius: 9px;
    border: 1px solid rgba(255,255,255,0.18);
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
}
.ecg-theme-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #a6cfd5;
    transition: transform 0.2s, background 0.2s;
}
/* unchecked = dark mode (default, thumb left, teal) */
/* checked = paper/light mode (thumb slides right, warm white) */
#ecgThemeToggle:checked + .ecg-theme-track {
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.35);
}
#ecgThemeToggle:checked + .ecg-theme-track .ecg-theme-thumb {
    transform: translateX(14px);
    background: #ffffff;
}

/* Thin separator between button groups */
.hdr-sep {
    width: 1px;
    height: 22px;
    background: rgba(255,255,255,0.09);
    margin: 0 5px;
}

/* Base header button */
.hdr-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 33px;
    padding: 0 14px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.11);
    border-radius: 7px;
    color: rgba(255,255,255,0.52);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.1px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
    user-select: none;
    white-space: nowrap;
    flex-shrink: 0;
}
.hdr-btn:hover {
    background: rgba(255,255,255,0.11);
    border-color: rgba(255,255,255,0.22);
    color: rgba(255,255,255,0.82);
}
.hdr-btn:active { transform: scale(0.975); }
.hdr-btn:disabled { opacity: 0.27; cursor: default; pointer-events: none; }

/* Dual toggle — active state */
.dual-btn.active {
    background: rgba(194, 231, 217, 0.10);
    border-color: rgba(194, 231, 217, 0.35);
    color: var(--trace);
}
.dual-btn.active:hover {
    background: rgba(194, 231, 217, 0.16);
    border-color: rgba(194, 231, 217, 0.52);
}

/* Instructor / Present — active when window is open (legacy block, overridden by .top-action-btn.instructor-btn.active below) */
.instructor-btn.active {
    background: rgba(38,64,139,0.07);
    border-color: rgba(38,64,139,0.28);
    color: #26408b;
}
.instructor-btn.active:hover {
    background: rgba(38,64,139,0.11);
    border-color: rgba(38,64,139,0.38);
}

/* Legacy class kept for .load-btn-lg and any non-header uses */
.load-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    color: rgba(255,255,255,0.55);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    user-select: none;
}
.load-btn:hover {
    background: rgba(255,255,255,0.10);
    border-color: rgba(255,255,255,0.25);
    color: rgba(255,255,255,0.85);
}
.load-btn-lg {
    padding: 9px 20px;
    font-size: 13px;
    margin-top: 16px;
}

/* ── ECG player light / paper theme ────────────────────────────────
   Applied by JS toggling .ecg-paper on #ecgCard.
   Overrides every dark-themed color in the header, controls, and
   timeline to produce a clean light-themed player panel.
   ────────────────────────────────────────────────────────────────── */

/* Card background (overrides Tailwind bg-[#1a1d23]) */
#ecgCard.ecg-paper { background: #f7fafe !important; }

/* Header */
#ecgCard.ecg-paper #ecgHeader {
    background: #ffffff;
    border-bottom-color: #e8eaed;
}

/* Live dot */
#ecgCard.ecg-paper .ecg-live-dot {
    background: #26408b;
    box-shadow: 0 0 6px rgba(38,64,139,0.35);
}

/* Lead selector button */
#ecgCard.ecg-paper .lead-btn {
    background: rgba(38,64,139,0.07);
    border-color: rgba(38,64,139,0.28);
    color: #26408b;
}
#ecgCard.ecg-paper .lead-btn:hover {
    background: rgba(38,64,139,0.14);
    border-color: rgba(38,64,139,0.48);
    box-shadow: 0 0 0 3px rgba(38,64,139,0.07);
}

/* Header divider */
#ecgCard.ecg-paper .ecg-hdr-divider { background: #e8eaed; }

/* Meta text */
#ecgCard.ecg-paper .ecg-meta { color: #707882; }

/* Theme toggle icons */
#ecgCard.ecg-paper .ecg-theme-icon { color: rgba(0,0,0,0.45); }

/* Toggle track in light mode — needs visible border on white background */
#ecgCard.ecg-paper .ecg-theme-track {
    background: #e0e3e7;
    border-color: #c8cdd3;
}
#ecgCard.ecg-paper .ecg-theme-thumb { background: #ffffff; }
/* Checked state in light mode (light mode is active = thumb right) */
#ecgCard.ecg-paper #ecgThemeToggle:checked + .ecg-theme-track {
    background: #26408b;
    border-color: #26408b;
}
#ecgCard.ecg-paper #ecgThemeToggle:checked + .ecg-theme-track .ecg-theme-thumb {
    background: #ffffff;
}

/* Time display */
#ecgCard.ecg-paper .ecg-hdr-time-cur { color: #181c1f; }
#ecgCard.ecg-paper .ecg-hdr-time-sep { color: #b0b8c4; }
#ecgCard.ecg-paper .ecg-hdr-time-tot { color: #707882; }

/* Placeholder background (canvas pre-load) */
#ecgCard.ecg-paper #placeholder { background: #ffffff; }

/* Secondary screen divider bar */
#ecgCard.ecg-paper #ecgScreen2Bar {
    border-top-color: #e8eaed;
    background: rgba(38,64,139,0.03);
}

/* Controls card */
#ecgCard.ecg-paper #controlsCard { background: #ffffff; }

/* Timeline background */
#ecgCard.ecg-paper #timelineCard { background: transparent; }
#ecgCard.ecg-paper .tl-time-labels { color: #707882; }

/* Divider line */
#ecgCard.ecg-paper .ctrl-divider {
    background: linear-gradient(90deg, transparent 0%, #e8eaed 8%, #e8eaed 92%, transparent 100%);
}

/* Transport buttons */
#ecgCard.ecg-paper .tbtn {
    background: #ffffff;
    border-color: #e0e3e7;
    color: #404750;
}
#ecgCard.ecg-paper .tbtn:hover {
    background: rgba(38,64,139,0.07);
    border-color: rgba(38,64,139,0.28);
    color: #26408b;
}
/* Play button — keep teal gradient, lighten shadow for white bg */
#ecgCard.ecg-paper .tbtn-play {
    box-shadow: 0 0 0 3px rgba(166,207,213,0.30),
                0 4px 14px rgba(38,64,139,0.18),
                0 2px 4px rgba(0,0,0,0.06);
}

/* Sliders */
#ecgCard.ecg-paper .ctrl-slider-lbl { color: #707882; }

#ecgCard.ecg-paper .ctrl-slider {
    background: linear-gradient(
        90deg,
        #a6cfd5 0%,
        #a6cfd5 var(--sl-pct, 25%),
        #e0e3e7 var(--sl-pct, 25%),
        #e0e3e7 100%
    );
}
#ecgCard.ecg-paper .ctrl-slider::-webkit-slider-thumb {
    background: #ffffff;
    border-color: #26408b;
    box-shadow: 0 0 0 3px rgba(38,64,139,0.12), 0 1px 4px rgba(0,0,0,0.10);
}
#ecgCard.ecg-paper .ctrl-slider:hover::-webkit-slider-thumb {
    box-shadow: 0 0 0 5px rgba(38,64,139,0.16), 0 1px 4px rgba(0,0,0,0.10);
}
#ecgCard.ecg-paper .ctrl-slider::-moz-range-track { background: #e0e3e7; }
#ecgCard.ecg-paper .ctrl-slider::-moz-range-progress { background: #a6cfd5; }
#ecgCard.ecg-paper .ctrl-slider::-moz-range-thumb {
    background: #ffffff;
    border-color: #26408b;
}

/* Slider value & tick labels */
#ecgCard.ecg-paper .ctrl-slider-val { color: #26408b; }
#ecgCard.ecg-paper .ctrl-ticks span { color: #9ea6b0; }
#ecgCard.ecg-paper .ctrl-ticks span.tick-active { color: #26408b; }

/* Status area */
#ecgCard.ecg-paper .ctrl-vsep { background: #e8eaed; }
#ecgCard.ecg-paper .ctrl-status-icon { color: #9ea6b0; }
#ecgCard.ecg-paper .ctrl-status { color: #707882; }

/* Annotations (labels) toggle */
#ecgCard.ecg-paper .lbl-text { color: #404750; }
#ecgCard.ecg-paper .lbl-track {
    background: #e0e3e7;
    border-color: #c8cdd3;
}
#ecgCard.ecg-paper .lbl-toggle input:checked + .lbl-track {
    background: #26408b;
    border-color: #26408b;
}

/* ── ECG Screen (canvas stack) ─────────────────────── */

#ecgScreen {
    position: relative;
    width: 100%;
    height: 320px;
}

#ecgScreen canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* bgCanvas is furthest back — rendered first, never clears after init */
#bgCanvas    { z-index: 1; }
/* traceCanvas is transparent bg, draws trace on top of bgCanvas */
#traceCanvas { z-index: 2; }
/* isolateCanvas highlights selected beat in red; pointer-events toggled by JS */
#isolateCanvas   { z-index: 3; pointer-events: none; }
/* caliperCanvas floats above trace and isolate; pointer-events toggled by JS */
#caliperCanvas   { z-index: 4; pointer-events: none; }
/* magnifierCanvas is the topmost layer; always non-interactive */
#magnifierCanvas { z-index: 5; pointer-events: none; }

/* Placeholder (shown until record loaded) */
#placeholder {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--ecg-bg);
    color: rgba(255,255,255,0.30);
    text-align: center;
    padding: 24px;
    gap: 10px;
}


/* ── Dual-lead second screen ───────────────────────── */

#ecgScreen2Wrap {
    overflow: hidden;
    height: 0;
    transition: height 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

#ecgScreen2Bar {
    display: flex;
    align-items: center;
    padding: 7px 14px;
    border-top: 1px solid rgba(194, 231, 217, 0.07);
    background: rgba(194, 231, 217, 0.025);
}

#ecgScreen2 {
    position: relative;
    width: 100%;
    height: 300px;
}

#ecgScreen2 canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#bgCanvas2       { z-index: 1; }
#traceCanvas2    { z-index: 2; }
#caliperCanvas2  { z-index: 3; pointer-events: none; }
#magnifierCanvas2{ z-index: 4; pointer-events: none; }

/* ── Widget row (removed — replaced by .metric-grid in Step 3) ─── */
/* #widgets, .widget, .w-label, .w-icon, .w-value, .w-unit,
   .w-hr, .w-rhythm, .w-time, .w-beat — all removed */

/* ── Timeline scrubber (first row inside #controlsCard) ────────── */

#timelineCard {
    padding: 20px 20px 0;
    background: transparent;
    border-top: 1px solid rgba(255,255,255,0.07);
}
#ecgCard.ecg-paper #timelineCard {
    border-top-color: #e0e3e7;
}

#timelineCanvas {
    display: block;
    width: 100%;
    height: 58px;
    cursor: pointer;
    border-radius: 6px;
    background: transparent;
}


.tl-time-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 5px;
    padding: 0 2px;
    font-size: 10px;
    color: #9ea6b0;
    font-family: var(--mono);
    letter-spacing: 0.2px;
}

/* ── Controls card (now inside #ecgCard dark section) ───────────── */

#controlsCard {
    background: #22252e;
    overflow: hidden;
}

/* ── Top row: transport | sliders | labels ── */
.ctrl-top {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    padding: 16px 20px 12px;
    gap: 16px;
}

/* Time readout (left column) */
.ctrl-time-group {
    display: flex;
    align-items: baseline;
    gap: 4px;
}
.ctrl-time {
    font-family: var(--mono);
    font-size: 17px;
    font-weight: 700;
    color: #d8e0f4;
    min-width: 56px;
    letter-spacing: 0.4px;
}
.ctrl-time-sep { color: #404860; font-size: 14px; }
.ctrl-time-dim { color: #6878a0; font-weight: 400; font-size: 13px; min-width: auto; }

/* Transport (centre column) */
.ctrl-transport {
    display: flex;
    align-items: center;
    gap: 5px;
}
.tbtn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #2c3040;
    border: 1px solid #3a3e52;
    border-radius: 8px;
    color: #7a88b0;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.1s;
    user-select: none;
    flex-shrink: 0;
}
.tbtn:hover {
    background: #353a50;
    border-color: #4a4f6a;
    color: #c0ccec;
}
.tbtn:active { transform: scale(0.88); }

/* Play / Pause */
.tbtn-play {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, #c2e7d9, #a6cfd5);
    border: none;
    color: #0d0221;
    box-shadow:
        0 0 0 3px rgba(166,207,213,0.20),
        0 4px 14px rgba(166,207,213,0.35),
        0 2px 4px rgba(0,0,0,0.12);
    margin: 0 6px;
    transition: box-shadow 0.15s, transform 0.1s, background 0.15s;
}
.tbtn-play:hover {
    background: radial-gradient(circle at 40% 35%, #daf2eb, #c2e7d9);
    box-shadow:
        0 0 0 4px rgba(166,207,213,0.30),
        0 6px 20px rgba(166,207,213,0.45),
        0 2px 6px rgba(0,0,0,0.12);
    transform: scale(1.08);
}
.tbtn-play:active {
    transform: scale(0.94);
    box-shadow: 0 2px 8px rgba(166,207,213,0.30), 0 1px 3px rgba(0,0,0,0.1);
}

/* Right group: labels toggle + record info */
.ctrl-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
}
.ctrl-vsep {
    width: 1px;
    height: 20px;
    background: #363a50;
    flex-shrink: 0;
}
.ctrl-status-icon {
    color: #505870;
    flex-shrink: 0;
}
.ctrl-status {
    font-size: 11px;
    font-family: var(--mono);
    color: #7080a8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Labels toggle */
.lbl-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}
.lbl-toggle input { display: none; }
.lbl-track {
    width: 32px;
    height: 18px;
    border-radius: 9px;
    background: #363a50;
    border: 1px solid #4a4f6a;
    position: relative;
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
}
.lbl-track::after {
    content: '';
    position: absolute;
    left: 2px; top: 2px;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: #fff;
    transition: left 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.22);
}
.lbl-toggle input:checked + .lbl-track {
    background: #a6cfd5;
    border-color: #a6cfd5;
}
.lbl-toggle input:checked + .lbl-track::after {
    left: 16px;
}
.lbl-text {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: #7080a8;
}

/* ── Divider ── */
.ctrl-divider {
    height: 1px;
    background: linear-gradient(
        to right,
        transparent 0%,
        #363a50 8%,
        #363a50 92%,
        transparent 100%
    );
    margin: 0 18px;
}

/* ── Sliders inline (between transport and labels in ctrl-top) ── */
.ctrl-sliders-inline {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 24px;
    min-width: 0;
}

.ctrl-slider-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.ctrl-slider-lbl {
    font-size: 8.5px;
    font-weight: 800;
    letter-spacing: 1.4px;
    color: #6878a0;
    text-transform: uppercase;
    width: 38px;
    flex-shrink: 0;
    text-align: right;
}

.ctrl-slider-track-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

/* Range input — dark-theme styling */
.ctrl-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 3px;
    outline: none;
    cursor: pointer;
    border-radius: 2px;
    border: none;
    background: linear-gradient(
        to right,
        #a6cfd5 0%,
        #a6cfd5 var(--sl-pct, 25%),
        #363a50 var(--sl-pct, 25%),
        #363a50 100%
    );
}
.ctrl-slider::-webkit-slider-runnable-track {
    height: 3px;
    border-radius: 2px;
    background: transparent;
}
.ctrl-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #22252e;
    border: 2px solid #a6cfd5;
    box-shadow: 0 0 0 3px rgba(166,207,213,0.15), 0 1px 4px rgba(0,0,0,0.18);
    margin-top: -5.5px;
    cursor: pointer;
    transition: box-shadow 0.15s, transform 0.12s;
}
.ctrl-slider:hover::-webkit-slider-thumb {
    box-shadow: 0 0 0 5px rgba(166,207,213,0.22), 0 2px 6px rgba(0,0,0,0.18);
    transform: scale(1.2);
}
.ctrl-slider::-moz-range-track {
    height: 3px;
    border-radius: 2px;
    background: #363a50;
    border: none;
}
.ctrl-slider::-moz-range-progress {
    height: 3px;
    border-radius: 2px;
    background: #a6cfd5;
}
.ctrl-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #22252e;
    border: 2px solid #a6cfd5;
    box-shadow: 0 0 0 3px rgba(166,207,213,0.15);
    cursor: pointer;
}

/* Tick marks */
.ctrl-ticks {
    display: flex;
    justify-content: space-between;
    padding: 0 7px;
}
.ctrl-ticks span {
    font-size: 8.5px;
    font-family: var(--mono);
    color: #505870;
    font-weight: 600;
    letter-spacing: 0.2px;
    transition: color 0.15s;
    cursor: pointer;
    user-select: none;
}
.ctrl-ticks span.tick-active {
    color: #a6cfd5;
}

/* Slider current value readout */
.ctrl-slider-val {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    color: #a6cfd5;
    min-width: 76px;
    padding-right: 4px;
    text-align: right;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Loop button active state ── */
.tbtn.tbtn-loop.active {
    background:   rgba(166, 207, 213, 0.16);
    border-color: rgba(166, 207, 213, 0.55);
    color:        #a6cfd5;
    box-shadow: 0 0 8px rgba(166,207,213,0.18);
}
.tbtn.tbtn-loop.active:hover {
    background:   rgba(166, 207, 213, 0.26);
    border-color: rgba(166, 207, 213, 0.80);
}

#ecgCard.ecg-paper .ctrl-loop-lbl { color: #9ea6b0; }
#ecgCard.ecg-paper .tbtn.tbtn-loop.active {
    background:   rgba(38, 64, 139, 0.08);
    border-color: rgba(38, 64, 139, 0.40);
    color:        #26408b;
    box-shadow: none;
}

/* ── Scrollbar ──────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ── Responsive ─────────────────────────────────────── */

/* Responsive: old widget/body padding rules removed (handled by Tailwind) */

/* ── Firebase Record Browser ─────────────────────────────────── */

.browser-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}
.browser-overlay[hidden] { display: none; }

.browser-panel {
    background: #fff;
    border-radius: 12px;
    width: min(680px, 94vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0,0,0,0.22);
    overflow: hidden;
}

.browser-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.browser-title {
    font-weight: 600;
    font-size: 15px;
    color: #1a1a2e;
    white-space: nowrap;
}

.browser-search {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    outline: none;
}
.browser-search:focus { border-color: #a6cfd5; }

.browser-close {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: #888;
    padding: 4px 6px;
    border-radius: 4px;
}
.browser-close:hover { background: #f0f0f0; }

.browser-list {
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.browser-loading {
    padding: 24px;
    text-align: center;
    color: #888;
    font-size: 13px;
}

.browser-card {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    grid-template-rows: auto auto;
    column-gap: 10px;
    row-gap: 2px;
    padding: 10px 12px;
    border: 1px solid #e8e8ee;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    align-items: center;
}
.browser-card:hover { border-color: #a6cfd5; background: #f6fff9; }

.bc-id {
    grid-row: 1 / 3;
    font-size: 20px;
    font-weight: 700;
    color: #a6cfd5;
    text-align: center;
}

.bc-info {
    display: flex;
    gap: 10px;
    font-size: 12px;
    color: #555;
}

.bc-leads { color: #888; }

.bc-meds {
    grid-column: 2;
    font-size: 11px;
    color: #999;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 320px;
}

.bc-notes {
    grid-column: 2 / 4;
    font-size: 11px;
    color: #aaa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bc-load-btn {
    grid-row: 1 / 3;
    grid-column: 3;
    background: #a6cfd5;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.bc-load-btn:hover { background: #009148; }

/* ── POI Sidebar ─────────────────────────────────────────────── */

.poi-sidebar {
    position: fixed;
    right: 16px;
    top: 16px;
    bottom: 16px;
    width: 288px;
    background: #fff;
    border-radius: 16px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid rgba(0,168,84,0.10);
    overflow: hidden;
    animation: poiSlideIn 0.22s ease;
}
.poi-sidebar[hidden] { display: none; }

@keyframes poiSlideIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

.poi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 13px;
    background: linear-gradient(135deg, #26408b 0%, #0f084b 100%);
    flex-shrink: 0;
}

.poi-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.poi-title {
    font-weight: 700;
    font-size: 13px;
    color: #fff;
    letter-spacing: 0.2px;
}

.poi-count {
    font-size: 10px;
    font-weight: 600;
    color: rgba(255,255,255,0.75);
    background: rgba(0,0,0,0.15);
    padding: 2px 7px;
    border-radius: 10px;
    letter-spacing: 0.2px;
}

.poi-close {
    background: rgba(255,255,255,0.18);
    border: none;
    font-size: 12px;
    cursor: pointer;
    color: #fff;
    padding: 4px 9px;
    border-radius: 8px;
    transition: background 0.15s;
    line-height: 1.2;
    font-weight: 500;
}
.poi-close:hover { background: rgba(255,255,255,0.32); }

.poi-list {
    overflow-y: auto;
    flex: 1;
    padding: 6px 0 10px;
}
.poi-list::-webkit-scrollbar { width: 4px; }
.poi-list::-webkit-scrollbar-thumb { background: rgba(166,207,213,0.3); border-radius: 4px; }
.poi-list::-webkit-scrollbar-track { background: transparent; }

.poi-loading {
    padding: 20px 16px;
    text-align: center;
    color: #aaa;
    font-size: 12px;
}

.poi-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.12s;
}
.poi-item:hover { background: #f2fdf7; }
.poi-item.poi-active { background: #e6f9ee; }
.poi-item.poi-active .poi-time { background: rgba(166,207,213,0.3); }

.poi-time {
    font-size: 10px;
    font-weight: 700;
    color: #a6cfd5;
    white-space: nowrap;
    min-width: 44px;
    background: rgba(0,168,84,0.08);
    padding: 3px 7px;
    border-radius: 5px;
    text-align: center;
    flex-shrink: 0;
    letter-spacing: 0.2px;
    margin-top: 1px;
}

.poi-desc {
    font-size: 12px;
    color: #2c2c3e;
    line-height: 1.5;
}

.poi-divider {
    margin: 2px 16px 2px;
    border: none;
    border-top: 1px dashed rgba(0,168,84,0.20);
}

/* ── POI Reopen Tab ──────────────────────────────────────────── */

.poi-reopen-btn {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: #a6cfd5;
    border: none;
    border-radius: 10px 0 0 10px;
    color: #fff;
    padding: 14px 9px;
    cursor: pointer;
    z-index: 199;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    box-shadow: -3px 0 16px rgba(0,168,84,0.28);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.6px;
    transition: background 0.15s, padding-right 0.15s;
}
.poi-reopen-btn:hover { background: #009148; padding-right: 13px; }
.poi-reopen-btn[hidden] { display: none; }

/* ── Isolate Tool — QRS refinement bar ──────────────── */

.refine-bar-wrap {
    height: 0;
    overflow: hidden;
    transition: height 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.refine-bar-wrap.visible {
    height: 52px;
}

.refine-bar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--card-bg);
    border-radius: var(--r-widget);
    border: 1px solid rgba(255, 59, 48, 0.18);
    box-shadow: var(--card-shadow);
    height: 52px;
    box-sizing: border-box;
}

/* Q / J endpoint labels */
.refine-tag {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1px;
    color: rgba(255, 59, 48, 0.65);
    font-family: var(--mono);
    flex-shrink: 0;
    width: 14px;
    text-align: center;
    user-select: none;
}

/* Interactive track region */
.refine-track-area {
    flex: 1;
    position: relative;
    height: 32px;
    cursor: default;
}

/* Background rail line */
.refine-track-rail {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: #e4e4e8;
    border-radius: 1px;
    transform: translateY(-50%);
    pointer-events: none;
}

/* Highlighted region between the two handles */
.refine-fill {
    position: absolute;
    top: 50%;
    height: 2px;
    background: rgba(255, 59, 48, 0.38);
    border-radius: 1px;
    transform: translateY(-50%);
    pointer-events: none;
    transition: left 0.04s, width 0.04s;
}

/* Draggable handle (vertical bar style) */
.refine-handle {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 22px;
    height: 32px;
    cursor: ew-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    user-select: none;
    transition: left 0.04s;
}

/* The visible bar of the handle */
.rh-bar {
    width: 3px;
    height: 22px;
    background: #ff3b30;
    border-radius: 2px;
    box-shadow: 0 0 6px rgba(255, 59, 48, 0.40);
    transition: height 0.12s, box-shadow 0.12s;
    pointer-events: none;
}

.refine-handle:hover .rh-bar,
.refine-handle.dragging .rh-bar {
    height: 28px;
    box-shadow: 0 0 10px rgba(255, 59, 48, 0.65);
}

/* ── Isolate Tool — beat measurement panel ─────────────────────── */

.isolate-panel {
    position: absolute;
    /* bottom / left / right are set dynamically by JS (_positionPanel)
       so the panel always appears on the side opposite the selected beat. */
    bottom: 12px;
    left: 12px;
    background: #22252e;
    border: 1px solid rgba(255,255,255,0.09);
    border-top: 2px solid rgba(255, 59, 48, 0.65);
    border-radius: 10px;
    min-width: 242px;
    font-family: var(--mono);
    pointer-events: none;
    z-index: 6;
    box-shadow:
        0 8px 28px rgba(0,0,0,0.60),
        0 2px 6px rgba(0,0,0,0.40);
    overflow: hidden;
}

.isolate-panel[hidden] { display: none; }

.ip-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    background: #1a1d24;
}

.ip-symbol {
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 59, 48, 0.10);
    border: 1px solid rgba(255, 59, 48, 0.28);
    border-radius: 7px;
}

.ip-title {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.ip-desc {
    font-size: 12px;
    color: #ffffff;
    font-weight: 700;
    letter-spacing: 0.2px;
}

.ip-time {
    font-size: 9.5px;
    color: rgba(255,255,255,0.42);
    letter-spacing: 0.4px;
}

.ip-rows {
    padding: 4px 0 6px;
    display: flex;
    flex-direction: column;
}

.ip-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 5px 14px;
}

.ip-row:nth-child(odd) {
    background: rgba(255,255,255,0.035);
}

.ip-lbl {
    font-size: 9px;
    color: rgba(255,255,255,0.48);
    letter-spacing: 0.6px;
    text-transform: uppercase;
    white-space: nowrap;
}

.ip-val {
    font-size: 11.5px;
    color: rgba(255,255,255,0.90);
    font-weight: 600;
    text-align: right;
}

/* Highlight wide QRS (> 120 ms) in amber */
.ip-warn { color: #ff9500; }

/* ── Simulator ─────────────────────────────────────────────────────────────── */

/* Header button — "Simulator" / "Exit Sim" */
.sim-btn-mode.sim-active {
    color: #d97706;
    background: rgba(217,119,6,0.08);
    border-color: rgba(217,119,6,0.35);
}
.sim-btn-mode.sim-active:hover {
    background: rgba(217,119,6,0.13);
    border-color: rgba(217,119,6,0.50);
}

/* Simulator control panel — replaces the controlsCard when sim mode is on */
#simPanel[hidden] { display: none; }

#simPanel {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 12px 18px;
    background: rgba(10, 12, 26, 0.92);
    border: 1px solid rgba(255, 159, 10, 0.22);
    border-radius: 10px;
    margin: 0 0 8px 0;
}

.sim-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 90px;
}

.sim-mode-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1.2px;
    color: #ff9f0a;
    text-transform: uppercase;
}

.sim-status-txt {
    font-size: 10px;
    color: rgba(255,255,255,0.45);
    font-style: italic;
}

/* Rhythm button row */
.sim-rhythm-btns {
    display: flex;
    gap: 10px;
    flex: 1;
}

.sim-rhythm-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 10px 24px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.04);
    color: rgba(255,255,255,0.55);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    min-width: 100px;
}
.sim-rhythm-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.sim-rhythm-btn:not(:disabled):hover {
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.85);
}

.srb-name {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.srb-sub {
    font-size: 9px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    opacity: 0.6;
}

/* NSR button — green when active */
.sim-nsr.sim-btn-on {
    background: rgba(194, 231, 217, 0.12);
    border-color: rgba(194, 231, 217, 0.40);
    color: #c2e7d9;
}

/* PVC button — amber when active */
.sim-pvc.sim-btn-on {
    background: rgba(255, 159, 10, 0.12);
    border-color: rgba(255, 159, 10, 0.40);
    color: #ff9f0a;
}

/* AFIB button — violet when active */
.sim-afib.sim-btn-on {
    background: rgba(175, 82, 222, 0.12);
    border-color: rgba(175, 82, 222, 0.40);
    color: #af52de;
}

/* AFL button — cyan when active */
.sim-afl.sim-btn-on {
    background: rgba(0, 188, 212, 0.12);
    border-color: rgba(0, 188, 212, 0.40);
    color: #00bcd4;
}

/* ── Simulator panel light/paper theme ──────────────────────────── */

#ecgCard.ecg-paper #simPanel {
    background: #ffffff;
    border-color: transparent;
    border-top: 1px solid #e8eaed;
    border-radius: 0;
    margin: 0;
}

#ecgCard.ecg-paper .sim-mode-label {
    color: #c77800;
}

#ecgCard.ecg-paper .sim-status-txt {
    color: #707882;
}

#ecgCard.ecg-paper .sim-rhythm-btn {
    background: #ffffff;
    border-color: #e0e3e7;
    color: #404750;
}
#ecgCard.ecg-paper .sim-rhythm-btn:not(:disabled):hover {
    background: rgba(38,64,139,0.07);
    border-color: rgba(38,64,139,0.28);
    color: #26408b;
}

/* Active rhythm buttons — richer, darker tones for white background */
#ecgCard.ecg-paper .sim-nsr.sim-btn-on {
    background: rgba(26, 122, 74, 0.10);
    border-color: rgba(26, 122, 74, 0.45);
    color: #1a7a4a;
}
#ecgCard.ecg-paper .sim-pvc.sim-btn-on {
    background: rgba(199, 120, 0, 0.10);
    border-color: rgba(199, 120, 0, 0.45);
    color: #c77800;
}
#ecgCard.ecg-paper .sim-afib.sim-btn-on {
    background: rgba(122, 27, 184, 0.10);
    border-color: rgba(122, 27, 184, 0.45);
    color: #7a1bb8;
}
#ecgCard.ecg-paper .sim-afl.sim-btn-on {
    background: rgba(0, 145, 163, 0.10);
    border-color: rgba(0, 145, 163, 0.45);
    color: #0091a3;
}

/* STDEP1 button — blue when active */
.sim-stdep1.sim-btn-on {
    background:   rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.45);
    color: #3b82f6;
}
#ecgCard.ecg-paper .sim-stdep1.sim-btn-on {
    background:   rgba(26, 64, 139, 0.08);
    border-color: rgba(26, 64, 139, 0.45);
    color: #26408b;
}

/* STE1 button — red when active */
.sim-ste1.sim-btn-on {
    background:   rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.45);
    color: #ef4444;
}
#ecgCard.ecg-paper .sim-ste1.sim-btn-on {
    background:   rgba(186, 26, 26, 0.08);
    border-color: rgba(186, 26, 26, 0.45);
    color: #ba1a1a;
}

/* ABIG1 button — teal when active */
.sim-abig1.sim-btn-on {
    background:   rgba(20, 184, 166, 0.12);
    border-color: rgba(20, 184, 166, 0.45);
    color: #14b8a6;
}
#ecgCard.ecg-paper .sim-abig1.sim-btn-on {
    background:   rgba(13, 124, 112, 0.08);
    border-color: rgba(13, 124, 112, 0.45);
    color: #0d7c70;
}

/* CHB1 button — deep crimson when active (critical rhythm) */
.sim-chb1.sim-btn-on {
    background:   rgba(159, 18, 57, 0.12);
    border-color: rgba(159, 18, 57, 0.50);
    color: #9f1239;
}
#ecgCard.ecg-paper .sim-chb1.sim-btn-on {
    background:   rgba(136, 14, 48, 0.08);
    border-color: rgba(136, 14, 48, 0.45);
    color: #88100e;
}

/* ── Inline Analysis Tools (in ctrl-right, right of Labels toggle) ── */

.ctrl-tools {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ctrl-tools-lbl {
    font-size: 8.5px;
    font-weight: 800;
    letter-spacing: 1.4px;
    color: #6878a0;
    text-transform: uppercase;
    margin-right: 4px;
    flex-shrink: 0;
}

/* Active states for inline tool buttons */
.tbtn.tbtn-caliper.active {
    background:   rgba(0, 208, 220, 0.14);
    border-color: rgba(0, 208, 220, 0.50);
    color:        #00d8e0;
    box-shadow: 0 0 8px rgba(0,208,220,0.18);
}
.tbtn.tbtn-caliper.active:hover {
    background: rgba(0,208,220,0.22);
    border-color: rgba(0,208,220,0.68);
}

.tbtn.tbtn-isolate.active {
    background:   rgba(255, 59, 48, 0.13);
    border-color: rgba(255, 59, 48, 0.50);
    color:        #ff5248;
    box-shadow: 0 0 8px rgba(255,59,48,0.18);
}
.tbtn.tbtn-isolate.active:hover {
    background: rgba(255,59,48,0.22);
    border-color: rgba(255,59,48,0.68);
}

.tbtn.tbtn-magnifier.active {
    background:   rgba(0, 168, 84, 0.13);
    border-color: rgba(0, 168, 84, 0.50);
    color:        #00cc60;
    box-shadow: 0 0 8px rgba(0,168,84,0.18);
}
.tbtn.tbtn-magnifier.active:hover {
    background: rgba(0,168,84,0.22);
    border-color: rgba(0,168,84,0.68);
}

/* ── Metric Cards (bento grid) ──────────────────────────────────── */

.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

@media (min-width: 768px) {
    .metric-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.metric-card {
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #e5e8ec;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.04);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mc-accent {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.mc-accent-hr     { background: #fef2f2; color: #ba1a1a; }
.mc-accent-rhythm { background: #f0fdf4; color: #006a61; }
.mc-accent-time   { background: #f0f6ff; color: #26408b; }
.mc-accent-beat   { background: #fef9f0; color: #d4830a; }

.mc-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.mc-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: #707882;
}

.mc-value {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -1px;
    font-size: 42px;
    color: #181c1f;
}

.mc-value-sm   { font-size: 20px; letter-spacing: 0; }
.mc-value-md   { font-size: 24px; letter-spacing: 0; }
.mc-value-beat { font-size: 30px; letter-spacing: -1px; }

.mc-unit {
    font-size: 11px;
    color: #707882;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    margin-top: 2px;
}

.mc-sublabel {
    font-size: 11px;
    color: #707882;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Top Bar shadow ──────────────────────────────────────────────── */

#topBar {
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
}

/* ── Top Bar Search Field ────────────────────────────────────────── */

.topbar-search {
    position: relative;
    display: flex;
    align-items: center;
    width: 300px;
    flex-shrink: 0;
}
.topbar-search-icon {
    position: absolute;
    left: 11px;
    color: #9ea6b0;
    pointer-events: none;
    display: flex;
    align-items: center;
}
.topbar-search-input {
    width: 100%;
    height: 36px;
    padding: 0 38px 0 34px;
    background: #f8f9fa;
    border: 1px solid #e0e3e7;
    border-radius: 9px;
    color: #181c1f;
    font-size: 13px;
    font-family: 'Inter', system-ui, sans-serif;
    outline: none;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
}
.topbar-search-input::placeholder {
    color: #9ea6b0;
}
.topbar-search-input:hover {
    background: #f1f4f8;
    border-color: #c8cdd3;
}
.topbar-search-input:focus {
    background: #ffffff;
    border-color: #26408b;
    box-shadow: 0 0 0 3px rgba(38,64,139,0.08);
}
/* Hide native search clear icon */
.topbar-search-input::-webkit-search-decoration,
.topbar-search-input::-webkit-search-cancel-button,
.topbar-search-input::-webkit-search-results-button { display: none; }

.topbar-search-kbd {
    position: absolute;
    right: 10px;
    display: flex;
    align-items: center;
    pointer-events: none;
    transition: opacity 0.12s;
}
.topbar-search-input:focus ~ .topbar-search-kbd { opacity: 0; }
.topbar-search-kbd kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 20px;
    padding: 0 6px;
    background: #f1f4f8;
    border: 1px solid #e0e3e7;
    border-radius: 5px;
    color: #9ea6b0;
    font-size: 11px;
    font-family: 'Inter', system-ui, sans-serif;
    font-weight: 500;
    line-height: 1;
    letter-spacing: 0.02em;
}

/* ── Top Bar Action Buttons ──────────────────────────────────────── */

.top-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    background: #ffffff;
    border: 1px solid #e0e3e7;
    border-radius: 7px;
    color: #404750;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    user-select: none;
    white-space: nowrap;
    flex-shrink: 0;
}
.top-action-btn:hover {
    background: #f1f4f8;
    border-color: #c8cdd3;
    color: #1a1d23;
}
.top-action-btn:active { transform: scale(0.97); }
.top-action-btn:disabled { opacity: 0.38; cursor: default; pointer-events: none; }

/* Dual toggle — active state */
.top-action-btn.dual-btn.active {
    background: rgba(38,64,139,0.07);
    border-color: rgba(38,64,139,0.28);
    color: #26408b;
}

/* Instructor — active state */
.top-action-btn.instructor-btn.active {
    background: rgba(38,64,139,0.07);
    border-color: rgba(38,64,139,0.28);
    color: #26408b;
}

/* Simulator — sim-active state */
.top-action-btn.sim-btn-mode.sim-active {
    background: rgba(217,119,6,0.08);
    border-color: rgba(217,119,6,0.35);
    color: #d97706;
}

/* BPF Filter — segmented 3-way control (Off · Monitor · Diagnostic) */
.bpf-seg-group {
    display: inline-flex;
    align-items: center;
    height: 32px;
    background: #ffffff;
    border: 1px solid #e0e3e7;
    border-radius: 7px;
    padding: 3px;
    gap: 1px;
    flex-shrink: 0;
}
.bpf-seg-icon {
    color: #9aa3ae;
    margin: 0 3px 0 5px;
    flex-shrink: 0;
}
.bpf-seg-btn {
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
    height: 100%;
    border-radius: 4px;
    border: 1px solid transparent;
    background: transparent;
    color: #404750;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    user-select: none;
}
.bpf-seg-btn:hover {
    background: #f1f4f8;
    color: #1a1d23;
}
.bpf-seg-btn.bpf-seg-active {
    background: rgba(38,64,139,0.07);
    border-color: rgba(38,64,139,0.28);
    color: #26408b;
    font-weight: 600;
}

/* Points of Interest — panel open */
.top-action-btn.poi-btn.active {
    background: rgba(38,64,139,0.07);
    border-color: rgba(38,64,139,0.28);
    color: #26408b;
}

/* Poll Controls — panel open */
.top-action-btn.poll-btn.active {
    background: rgba(38,64,139,0.07);
    border-color: rgba(38,64,139,0.28);
    color: #26408b;
}

/* ── Sidebar Navigation Items ────────────────────────────────────── */

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    user-select: none;
}
.sidebar-nav-item:hover {
    background: rgba(255,255,255,0.07);
    color: #ffffff;
}
.sidebar-nav-item-active {
    background: rgba(38,64,139,0.55);
    color: #a6cfd5;
    font-weight: 600;
}
.sidebar-nav-item-active:hover {
    background: rgba(38,64,139,0.70);
}

/* ── ECG Header time display ─────────────────────────────────────── */

.ecg-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #c2e7d9;
    margin-right: 10px;
    flex-shrink: 0;
    box-shadow: 0 0 6px rgba(194, 231, 217, 0.60);
    animation: livePulse 2s ease-in-out infinite;
}

@keyframes livePulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 6px rgba(194, 231, 217, 0.60); }
    50%       { opacity: 0.55; box-shadow: 0 0 10px rgba(194, 231, 217, 0.35); }
}

.ecg-hdr-time {
    display: flex;
    align-items: baseline;
    gap: 4px;
}
.ecg-hdr-time-cur {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 14px;
    font-weight: 700;
    color: rgba(255,255,255,0.82);
    letter-spacing: 0.4px;
    min-width: 50px;
}
.ecg-hdr-time-sep {
    color: rgba(255,255,255,0.25);
    font-size: 12px;
}
.ecg-hdr-time-tot {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    font-weight: 400;
    color: rgba(255,255,255,0.38);
    letter-spacing: 0.3px;
}

/* ── BPF Filter toggle button ─────────────────────────────────── */
.bpf-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 30px;
    padding: 0 11px;
    border: 1px solid #c0c7d2;
    border-radius: 8px;
    background: #fff;
    font-size: 0.76rem;
    font-weight: 600;
    color: #404750;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.bpf-toggle:hover {
    border-color: #26408b;
    color: #26408b;
}

.bpf-toggle.active {
    background: #26408b;
    border-color: #26408b;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 98, 158, 0.28);
}

.bpf-toggle.active svg path {
    stroke: #fff;
}

/* ─────────────────────────────────────────────────────────────── */
/* Favorites — shared across all pages (library + dashboard)       */
/* ─────────────────────────────────────────────────────────────── */

/* ── Star (favorites) button — right of play ─────────────────────── */
.lib-star-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    min-width: 36px;
    height: 36px;
    border: 1.5px solid #e0e3e7;
    border-radius: 50%;
    background: transparent;
    color: #b0b8c4;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s, transform 0.1s;
}

.lib-star-btn:hover {
    border-color: #f4b400;
    color: #f4b400;
    background: rgba(244, 180, 0, 0.07);
    transform: scale(1.08);
}

.lib-star-btn.is-fav {
    border-color: #f4b400;
    color: #f4b400;
    background: rgba(244, 180, 0, 0.10);
}

.lib-star-btn .material-symbols-outlined {
    font-size: 19px;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.lib-star-btn.is-fav .material-symbols-outlined {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* ── Favorites side panel ─────────────────────────────────────────── */
.fav-panel {
    position: fixed;
    right: 16px;
    top: 16px;
    bottom: 16px;
    width: 300px;
    background: #fff;
    border-radius: 16px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid rgba(244,180,0,0.12);
    overflow: hidden;
    animation: favSlideIn 0.22s ease;
}

@keyframes favSlideIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

.fav-panel.hidden { display: none; }

.fav-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 13px;
    background: linear-gradient(135deg, #e6a800 0%, #f4b400 100%);
    flex-shrink: 0;
}

.fav-panel-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fav-panel-icon {
    font-size: 16px;
    color: rgba(255,255,255,0.9);
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    flex-shrink: 0;
}

.fav-panel-title {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.2px;
    margin: 0;
}

.fav-panel-count {
    font-size: 10px;
    font-weight: 600;
    color: rgba(255,255,255,0.75);
    background: rgba(0,0,0,0.15);
    padding: 2px 7px;
    border-radius: 10px;
    letter-spacing: 0.2px;
}

.fav-panel-close {
    background: rgba(255,255,255,0.18);
    border: none;
    font-size: 12px;
    cursor: pointer;
    color: #fff;
    padding: 4px 9px;
    border-radius: 8px;
    transition: background 0.15s;
    line-height: 1.2;
    font-weight: 500;
}
.fav-panel-close:hover { background: rgba(255,255,255,0.32); }

.fav-panel-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0 10px;
}
.fav-panel-list::-webkit-scrollbar { width: 4px; }
.fav-panel-list::-webkit-scrollbar-thumb { background: rgba(244,180,0,0.25); border-radius: 4px; }
.fav-panel-list::-webkit-scrollbar-track { background: transparent; }

.fav-empty {
    text-align: center;
    color: #9ea6b0;
    font-size: 0.82rem;
    line-height: 1.6;
    padding: 32px 20px;
}

.fav-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: #fff;
    border-bottom: 1px solid #f0f2f5;
    transition: background 0.12s;
}

.fav-item:hover { background: #f7fafe; }

.fav-item-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.fav-item-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: #26408b;
}

.fav-item-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* ── Record tag chips (shared: library + favorites panel) ─────────── */
.lib-tag {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 20px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.lt-nsr      { background: rgba(194,231,217,0.35); color: #0a4535; border: 1px solid #a6cfd5; }
.lt-critical { background: #fde8e8; color: #b91c1c; border: 1px solid #f5b8b8; }
.lt-atrial   { background: rgba(38,64,139,0.10); color: #26408b; border: 1px solid rgba(38,64,139,0.30); }
.lt-paced    { background: rgba(15,8,75,0.08); color: #0f084b; border: 1px solid rgba(15,8,75,0.20); }
.lt-other    { background: rgba(166,207,213,0.18); color: #26408b; border: 1px solid rgba(166,207,213,0.50); }

.fav-item-notes {
    font-size: 0.76rem;
    color: #404750;
    margin: 3px 0 0;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.fav-item-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    shrink: 0;
}

.fav-item-play {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1.5px solid #26408b;
    border-radius: 50%;
    background: transparent;
    color: #26408b;
    text-decoration: none;
    transition: border-color 0.12s, color 0.12s, background 0.12s, transform 0.1s;
    flex-shrink: 0;
}

.fav-item-play:hover {
    border-color: #004f80;
    color: #004f80;
    background: rgba(0, 98, 158, 0.07);
    transform: scale(1.08);
}
.fav-item-play .material-symbols-outlined {
    font-size: 17px;
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.fav-item-del {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #b0b8c4;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}

.fav-item-del:hover { background: #ffeaea; color: #ba1a1a; }
.fav-item-del .material-symbols-outlined { font-size: 17px; }

/* ── Add / edit favorite dialog ───────────────────────────────────── */
.fav-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.fav-dialog-overlay.hidden { display: none; }

.fav-dialog {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.22);
    width: 100%;
    max-width: 420px;
    overflow: hidden;
}

.fav-dialog-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid #f0f2f5;
}

.fav-dialog-icon {
    font-size: 22px;
    color: #f4b400;
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.fav-dialog-title {
    flex: 1;
    font-size: 1rem;
    font-weight: 700;
    color: #181c1f;
    margin: 0;
}

.fav-dialog-x {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 6px;
    color: #707882;
    cursor: pointer;
    transition: background 0.12s;
}

.fav-dialog-x:hover { background: #f0f2f5; }
.fav-dialog-x .material-symbols-outlined { font-size: 18px; }

.fav-dialog-body {
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.fav-notes-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #404750;
}

.fav-notes-hint {
    font-weight: 400;
    color: #9ea6b0;
}

.fav-notes-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #d0d6de;
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: 'Inter', sans-serif;
    color: #181c1f;
    resize: vertical;
    min-height: 90px;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.fav-notes-textarea:focus {
    outline: none;
    border-color: #26408b;
    box-shadow: 0 0 0 3px rgba(0, 98, 158, 0.12);
}

.fav-notes-tip {
    font-size: 0.72rem;
    color: #9ea6b0;
    margin: 0;
    text-align: right;
}

.fav-dialog-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px 18px;
    border-top: 1px solid #f0f2f5;
}

.fav-dialog-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.fav-btn-cancel, .fav-btn-save, .fav-btn-remove {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.13s, box-shadow 0.13s;
    border: none;
}

.fav-btn-cancel {
    background: #f0f2f5;
    color: #404750;
}

.fav-btn-cancel:hover { background: #e0e3e7; }

.fav-btn-save {
    background: #26408b;
    color: #fff;
    box-shadow: 0 2px 6px rgba(0,98,158,0.25);
}

.fav-btn-save:hover { background: #004f80; }
.fav-btn-save:disabled { opacity: 0.6; cursor: not-allowed; }

.fav-btn-remove {
    background: transparent;
    color: #ba1a1a;
    border: 1.5px solid #e8b4b4;
}

.fav-btn-remove:hover { background: #ffeaea; }
.fav-btn-remove.hidden { display: none; }

/* ── Global search dropdown ──────────────────────────────────────── */
.search-dropdown {
    position: fixed;
    /* left/width set by JS to match content area */
    top: 56px; /* topbar height */
    z-index: 1100;
    background: #ffffff;
    border: 1px solid #e0e3e7;
    border-radius: 0 0 16px 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
    overflow: hidden;
    max-height: calc(100vh - 72px);
    display: flex;
    flex-direction: column;
}

.search-dropdown[hidden] { display: none; }

.sr-inner {
    overflow-y: auto;
    flex: 1;
    overscroll-behavior: contain;
}

/* Scrollbar styling */
.sr-inner::-webkit-scrollbar { width: 6px; }
.sr-inner::-webkit-scrollbar-track { background: transparent; }
.sr-inner::-webkit-scrollbar-thumb { background: #d0d4da; border-radius: 3px; }
.sr-inner::-webkit-scrollbar-thumb:hover { background: #b0b5bc; }

.sr-list {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Record result row */
.sr-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.12s;
    border: 1.5px solid transparent;
}

.sr-item:hover,
.sr-item.sr-focused {
    background: rgba(38,64,139,0.05);
    border-color: rgba(38,64,139,0.12);
}

.sr-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Library badge */
.sr-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 2px 7px;
    border-radius: 20px;
    flex-shrink: 0;
    text-transform: uppercase;
}

.sr-badge-mitbih {
    background: rgba(38,64,139,0.10);
    color: #26408b;
}

.sr-badge-vfdb {
    background: rgba(167,107,250,0.12);
    color: #7c3aed;
}

/* Record ID */
.sr-id {
    font-size: 15px;
    font-weight: 600;
    color: #181c1f;
    min-width: 36px;
}

/* Tag chips row */
.sr-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

/* Secondary metadata line */
.sr-meta {
    display: flex;
    gap: 16px;
    align-items: center;
    padding-left: 2px;
}

.sr-demo,
.sr-leads,
.sr-meds {
    font-size: 12px;
    color: #707882;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sr-meds { max-width: 260px; }

/* POI sub-rows */
.sr-poi-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
    padding-left: 16px;
    border-left: 2px solid rgba(38,64,139,0.15);
}

.sr-poi {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.12s;
}

.sr-poi:hover,
.sr-poi.sr-focused {
    background: rgba(38,64,139,0.07);
}

.sr-poi-icon {
    font-size: 13px;
    color: #a6cfd5;
    flex-shrink: 0;
}

.sr-poi-time {
    font-size: 12px;
    font-weight: 600;
    color: #26408b;
    min-width: 44px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.sr-poi-desc {
    font-size: 12px;
    color: #404750;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Empty state */
.sr-empty {
    padding: 32px 16px;
    text-align: center;
    color: #9ea6b0;
    font-size: 14px;
}

.sr-empty strong {
    display: block;
    font-size: 15px;
    color: #5f6876;
    margin-bottom: 4px;
}

/* Footer hint */
.sr-footer {
    padding: 8px 16px;
    font-size: 11px;
    color: #b0b5bc;
    border-top: 1px solid #f0f2f5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.sr-footer kbd {
    background: #f0f2f5;
    border: 1px solid #d8dce2;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 11px;
    color: #5f6876;
}

/* Loading state */
.sr-loading {
    padding: 24px 16px;
    text-align: center;
    color: #9ea6b0;
    font-size: 13px;
}

/* Section divider (MIT-BIH / VFDB) */
.sr-section-header {
    font-size: 11px;
    font-weight: 600;
    color: #9ea6b0;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 10px 12px 4px;
}


/* ── 12-Lead ECG Panel ────────────────────────────────────────────── */

#ecg12Panel {
    background: #ffffff;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.10);
}

.ecg12-header {
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-bottom: none;
}

.ecg12-hdr-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px 9px 16px;
    gap: 12px;
    min-height: 44px;
}

.ecg12-hdr-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

/* ── Measurements strip ──────────────────────────────────────────── */
.ecg12-measurements {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    padding: 6px 16px 10px;
    border-top: 1px solid #f0f2f5;
}

.ecg12-meas-pill {
    display: inline-flex;
    align-items: baseline;
    gap: 3px;
    padding: 3px 9px 4px;
    background: rgba(38,64,139,0.04);
    border: 1px solid rgba(38,64,139,0.10);
    border-radius: 20px;
    white-space: nowrap;
    transition: background 0.15s;
}

.ecg12-meas-label {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #9ea6b0;
}

.ecg12-meas-value {
    font-size: 12px;
    font-weight: 700;
    color: #181c1f;
    font-family: 'Space Grotesk', monospace;
    letter-spacing: -0.01em;
}

.ecg12-meas-unit {
    font-size: 9px;
    color: #9ea6b0;
    font-weight: 500;
}

/* Flagged / out-of-range value */
.ecg12-meas-pill.warn {
    background: #fff7ed;
    border-color: rgba(194,65,12,0.22);
}
.ecg12-meas-pill.warn .ecg12-meas-value {
    color: #c2410c;
}
.ecg12-meas-pill.warn .ecg12-meas-unit,
.ecg12-meas-pill.warn .ecg12-meas-label {
    color: #e28063;
}

/* Irregular rhythm badge */
.ecg12-meas-irregular {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px 4px;
    background: #fde8e8;
    border: 1px solid #f5b8b8;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #b91c1c;
    white-space: nowrap;
}

/* ── Measurement tooltip ─────────────────────────────────────────── */
.meas-tip {
    position: fixed;
    z-index: 9999;
    width: 248px;
    background: #ffffff;
    border: 1px solid #e5e8ec;
    border-radius: 14px;
    box-shadow:
        0 4px 6px -1px rgba(0,0,0,0.07),
        0 12px 32px -4px rgba(0,0,0,0.12);
    padding: 13px 15px 14px;
    pointer-events: none;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.16s ease, transform 0.16s ease;
}
.meas-tip.tip-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Upward-pointing arrow */
.meas-tip::before {
    content: '';
    position: absolute;
    top: -5px;
    left: var(--tip-arrow, 50%);
    width: 9px;
    height: 9px;
    background: #ffffff;
    border-left: 1px solid #e5e8ec;
    border-top: 1px solid #e5e8ec;
    transform: translateX(-50%) rotate(45deg);
    border-radius: 2px 0 0 0;
}

.meas-tip-title {
    font-size: 13px;
    font-weight: 700;
    color: #26408b;
    letter-spacing: -0.01em;
    margin-bottom: 1px;
}

.meas-tip-sub {
    font-size: 9.5px;
    font-weight: 600;
    color: #9ea6b0;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 9px;
}

.meas-tip-divider {
    height: 1px;
    background: #f0f2f5;
    margin: 0 -15px 10px;
}

.meas-tip-desc {
    font-size: 11.5px;
    color: #404750;
    line-height: 1.55;
    margin-bottom: 10px;
}

.meas-tip-range {
    display: inline-block;
    font-size: 10.5px;
    font-weight: 600;
    color: #26408b;
    background: rgba(38,64,139,0.05);
    border: 1px solid rgba(38,64,139,0.14);
    border-radius: 7px;
    padding: 3px 9px 4px;
    letter-spacing: 0.01em;
}

.ecg12-hdr-icon {
    font-size: 18px !important;
    color: #26408b;
    flex-shrink: 0;
}

.ecg12-hdr-title {
    font-size: 13px;
    font-weight: 600;
    color: #181c1f;
    white-space: nowrap;
    flex-shrink: 0;
}

.ecg12-hdr-id {
    font-size: 11px;
    color: #26408b;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.ecg12-hdr-conds {
    font-size: 11px;
    color: #707882;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.ecg12-hdr-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.ecg12-hdr-meta {
    font-size: 11px;
    color: #9ea6b0;
    white-space: nowrap;
    margin-right: 4px;
}

.ecg12-gain-btn {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid #e0e3e7;
    background: #ffffff;
    color: #404750;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
    padding: 0;
}
.ecg12-gain-btn:hover {
    background: rgba(38,64,139,0.07);
    border-color: rgba(38,64,139,0.28);
    color: #26408b;
}

.ecg12-gain-val {
    font-size: 11px;
    color: #707882;
    white-space: nowrap;
    min-width: 56px;
    text-align: center;
}

.ecg12-close-btn {
    padding: 3px 10px;
    border-radius: 6px;
    border: 1px solid #e0e3e7;
    background: #ffffff;
    color: #404750;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    margin-left: 4px;
}
.ecg12-close-btn:hover {
    background: rgba(186,26,26,0.07);
    border-color: rgba(186,26,26,0.28);
    color: #ba1a1a;
}

/* 4-column lead grid */
.ecg12-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: #ffffff;
    padding: 4px;
}

.ecg12-cell {
    position: relative;
    background: #ffffff;
    cursor: pointer;
    transition: box-shadow 0.1s;
}
.ecg12-cell:hover {
    background: #f7fafe;
}
.ecg12-cell.ecg12-active {
    background: #faf7ff;
}

.ecg12-canvas {
    display: block;
    width: 100%;
    height: clamp(90px, 14vh, 160px);
}

/* ST deviation badge — bottom-right of each cell */
.ecg12-st-badge {
    position: absolute;
    bottom: 5px;
    right: 6px;
    font-size: 9.5px;
    font-weight: 700;
    font-family: 'Space Grotesk', monospace;
    letter-spacing: -0.01em;
    padding: 1px 5px 2px;
    border-radius: 5px;
    pointer-events: none;
    line-height: 1.5;
    z-index: 2;
}
.ecg12-st-badge.st-elev {
    background: #ffffff;
    color: #b91c1c;
    border: 1px solid rgba(186,26,26,0.25);
}
.ecg12-st-badge.st-dep {
    background: #ffffff;
    color: #1e3a8a;
    border: 1px solid rgba(38,64,139,0.25);
}
.ecg12-st-badge.st-normal {
    background: #ffffff;
    color: #9ea6b0;
    border: 1px solid #e5e8ec;
}

.ecg12-lead-label {
    position: absolute;
    top: 4px;
    left: 6px;
    font-size: 10px;
    font-weight: 700;
    color: rgba(0,0,0,0.30);
    letter-spacing: 0.05em;
    pointer-events: none;
    user-select: none;
}

.ecg12-rhythm-label {
    display: none;
    pointer-events: none;
    user-select: none;
}

/* ── 12-Lead Footer ───────────────────────────────────────────────── */
.ecg12-footer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 14px 12px;
    border-top: 1px solid #f0f2f5;
    background: #ffffff;
    border-radius: 0 0 1rem 1rem;
}

.ecg12-footer-disclaimer {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 0;
    padding: 5px 8px;
    background: #fffbf0;
    border: 1px solid #f5e6b8;
    border-radius: 6px;
    font-size: 11px;
    color: #7a6320;
    line-height: 1.4;
    font-family: 'Inter', sans-serif;
}

.ecg12-disclaimer-icon {
    font-size: 13px !important;
    color: #c8960a;
    flex-shrink: 0;
}

.ecg12-footer-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ecg12-footer-meta {
    font-size: 11px;
    color: #b0b8c4;
    letter-spacing: 0.04em;
    font-family: 'Space Grotesk', monospace;
}

.ecg12-footer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ecg12-footer-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 32px;
    padding: 0 13px;
    border-radius: 8px;
    border: 1px solid #e0e3e7;
    background: #ffffff;
    color: #404750;
    font-size: 12px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.ecg12-footer-btn .material-symbols-outlined {
    font-size: 15px !important;
}

.ecg12-footer-btn:hover {
    background: rgba(38,64,139,0.05);
    border-color: rgba(38,64,139,0.28);
    color: #26408b;
}

.ecg12-footer-btn-primary {
    background: #26408b;
    border-color: #26408b;
    color: #ffffff;
    box-shadow: 0 1px 4px rgba(38,64,139,0.22);
}

.ecg12-footer-btn-primary:hover {
    background: #1e3270;
    border-color: #1e3270;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(38,64,139,0.30);
}

/* ── 12-Lead Fullscreen Modal ─────────────────────────────────────── */
.ecg12-fs-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: ecg12-fs-fadein 0.2s ease;
}

.ecg12-fs-modal[hidden] { display: none !important; }

@keyframes ecg12-fs-fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.ecg12-fs-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 10, 18, 0.82);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.ecg12-fs-content {
    position: relative;
    width: calc(100vw - 32px);
    max-width: 1440px;
    max-height: calc(100vh - 32px);
    background: #ffffff;
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 4px 6px -1px rgba(0,0,0,0.10),
        0 24px 56px -8px rgba(0,0,0,0.40);
    animation: ecg12-fs-slidein 0.22s cubic-bezier(0.34, 1.30, 0.64, 1);
}

@keyframes ecg12-fs-slidein {
    from { transform: scale(0.96) translateY(8px); opacity: 0; }
    to   { transform: scale(1)    translateY(0);   opacity: 1; }
}

.ecg12-fs-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid #f0f2f5;
    background: #ffffff;
    flex-shrink: 0;
    min-height: 46px;
    gap: 12px;
}

.ecg12-fs-hdr-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
    overflow: hidden;
}

.ecg12-fs-hdr-icon {
    font-size: 18px !important;
    color: #26408b;
    flex-shrink: 0;
}

.ecg12-fs-hdr-title {
    font-size: 13px;
    font-weight: 600;
    color: #181c1f;
    white-space: nowrap;
    flex-shrink: 0;
}

.ecg12-fs-hdr-id {
    font-size: 11px;
    color: #26408b;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.ecg12-fs-hdr-conds {
    font-size: 11px;
    color: #707882;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.ecg12-fs-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid #e0e3e7;
    background: #ffffff;
    color: #404750;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    flex-shrink: 0;
    padding: 0;
}

.ecg12-fs-close .material-symbols-outlined {
    font-size: 18px !important;
}

.ecg12-fs-close:hover {
    background: rgba(186,26,26,0.07);
    border-color: rgba(186,26,26,0.28);
    color: #ba1a1a;
}

.ecg12-fs-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: #f0f2f5;
    flex: 1;
    overflow: hidden;
}

.ecg12-fs-cell {
    position: relative;
    background: #ffffff;
}

.ecg12-fs-canvas {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 80px;
}

.ecg12-fs-lead-lbl {
    position: absolute;
    top: 5px;
    left: 8px;
    font-size: 11px;
    font-weight: 700;
    color: rgba(0,0,0,0.28);
    letter-spacing: 0.05em;
    pointer-events: none;
    user-select: none;
}


/* ── 12-Lead Beat Isolation — fixed measurement panel ────────── */
/* Overrides the absolute positioning of .isolate-panel so it    */
/* floats in the viewport corner independent of any container.   */
.isolate-panel-12 {
    position: fixed;
    bottom: 20px;
    right: 20px;
    left: auto;
    top: auto;
    z-index: 10002;
}
