/* ================================================================
   library.css — MIT-BIH Library view styles
   ================================================================ */

/* ── View container ─────────────────────────────────────────────── */
#libraryView {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: #f7fafe;
}

/* ── Page header ─────────────────────────────────────────────────── */
.lib-page-header {
    padding: 24px 28px 0;
}

.lib-page-header h1 {
    font-family: 'Inter', sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: #181c1f;
    margin: 0 0 2px;
}

.lib-page-header p {
    font-size: 0.8rem;
    color: #707882;
    margin: 0;
}

/* ── Controls bar (search + chips) ───────────────────────────────── */
.lib-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px 28px 12px;
}

.lib-search-wrap {
    position: relative;
    flex: 1;
    min-width: 220px;
    max-width: 420px;
}

.lib-search-wrap .material-symbols-outlined {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: #707882;
    pointer-events: none;
}

#libSearch {
    width: 100%;
    height: 38px;
    padding: 0 12px 0 36px;
    border: 1px solid #c0c7d2;
    border-radius: 8px;
    background: #fff;
    font-size: 0.82rem;
    color: #181c1f;
    outline: none;
    transition: border-color 0.15s;
}

#libSearch:focus {
    border-color: #26408b;
    box-shadow: 0 0 0 3px rgba(0, 98, 158, 0.12);
}

#libSearch::placeholder { color: #9aa3af; }

/* Filter chips */
#libFilters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.lib-chip {
    height: 30px;
    padding: 0 12px;
    border: 1px solid #c0c7d2;
    border-radius: 20px;
    background: #fff;
    font-size: 0.76rem;
    font-weight: 500;
    color: #404750;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.lib-chip:hover {
    border-color: #26408b;
    color: #26408b;
}

.lib-chip.active {
    background: #26408b;
    border-color: #26408b;
    color: #fff;
}

/* Record count */
.lib-count-bar {
    padding: 0 28px 8px;
    font-size: 0.76rem;
    color: #707882;
}

/* ── Record list grid ─────────────────────────────────────────────── */
#libGrid {
    flex: 1;
    padding: 0 20px 32px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ── Loading / error state ───────────────────────────────────────── */
.lib-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 60px 20px;
    font-size: 0.88rem;
    color: #707882;
    text-align: center;
}

.lib-error { color: #ba1a1a; }

.lib-spinner-wrap { margin-bottom: 4px; }

.lib-spin {
    display: inline-block;
    animation: lib-spin 1s linear infinite;
    font-size: 28px !important;
    color: #26408b;
}

@keyframes lib-spin {
    to { transform: rotate(360deg); }
}

/* ── Individual record row ───────────────────────────────────────── */
.lib-row {
    display: flex;
    align-items: center;
    gap: 16px;
    background: linear-gradient(to top, #eef3f8 0%, #ffffff 55%);
    border: 1px solid #e5e8ec;
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.07), 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.15s, border-color 0.15s, background 0.15s;
    min-height: 110px;
}

.lib-row:hover {
    background: linear-gradient(to top, #dde9f4 0%, #ffffff 55%);
    border-color: #a0b8cc;
    box-shadow: 0 6px 18px rgba(0, 98, 158, 0.13), 0 2px 4px rgba(0, 0, 0, 0.06);
}

/* ── Record badge (left) ─────────────────────────────────────────── */
.lib-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 56px;
    min-width: 56px;
    height: 56px;
    border-radius: 10px;
    background: #e8f3fb;
    text-align: center;
}

.lib-rec-num {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.05rem;
    font-weight: 700;
    color: #26408b;
    line-height: 1.1;
}

.lib-rec-db {
    font-size: 0.55rem;
    font-weight: 600;
    color: #707882;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-top: 1px;
}

/* ── Demographics info (centre-left) ─────────────────────────────── */
.lib-info {
    flex: 0 0 210px;
    min-width: 0;
}

.lib-info-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: #181c1f;
    margin-bottom: 2px;
}

.lib-info-demo {
    font-size: 0.78rem;
    color: #404750;
    margin-bottom: 3px;
}

.lib-info-meds {
    font-size: 0.73rem;
    color: #707882;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.lib-meds-label {
    font-weight: 600;
    color: #404750;
}

/* ── Rhythm tags ─────────────────────────────────────────────────── */
.lib-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.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: #e6f4ea;
    color: #1e6e35;
    border: 1px solid #b8dfc2;
}

.lt-critical {
    background: #fde8e8;
    color: #b91c1c;
    border: 1px solid #f5b8b8;
}

.lt-atrial {
    background: #fff3e0;
    color: #92400e;
    border: 1px solid #fcd7a0;
}

.lt-paced {
    background: #ede9fe;
    color: #5b21b6;
    border: 1px solid #c4b5fd;
}

.lt-other {
    background: #e0eefb;
    color: #26408b;
    border: 1px solid #a8ccec;
}

.lib-none {
    font-size: 0.73rem;
    color: #9aa3af;
    font-style: italic;
}

/* ── Waveform snapshot (centre-right) ────────────────────────────── */
.lib-wave-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
    height: 80px;
    border-radius: 10px;
    overflow: hidden;
    background: #13161c;
    border: 1px solid #2a2f3a;
}

.lib-wave-canvas {
    display: block;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.lib-wave-wrap.wave-ready .lib-wave-canvas {
    opacity: 1;
}

.lib-wave-wrap.wave-ready .lib-wave-loading {
    display: none;
}

.lib-wave-wrap.wave-failed .lib-wave-loading {
    opacity: 0.35;
}

/* Overlay labels (record id + duration) */
.lib-wave-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 4px 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.lib-row:hover .lib-wave-overlay { opacity: 1; }

.lib-wave-id,
.lib-wave-dur {
    font-size: 0.65rem;
    font-weight: 600;
    color: rgba(255,255,255,0.55);
    letter-spacing: 0.04em;
    font-family: 'Space Grotesk', monospace;
}

/* Loading spinner inside waveform card */
.lib-wave-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.lib-wave-loading .lib-spin {
    font-size: 18px !important;
    color: rgba(255,255,255,0.3);
}

/* .lib-play-btn removed — whole card is now a link */



/* ── ECG12 Library — card grid layout ───────────────────────────── */

#libGrid:has(.lib-card) {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    padding: 16px 20px 32px;
}

.lib-card {
    background: linear-gradient(
        to top,
        #f0f2f5 0%,
        #ffffff 12.5%
    );
    border: 1px solid #e5e8ec;
    border-radius: 14px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}
.lib-card:hover {
    border-color: #a6cfd5;
    box-shadow: 0 4px 16px rgba(38,64,139,0.10);
    transform: translateY(-1px);
}
.lib-card:active {
    transform: translateY(0);
}

/* ECG preview area */
.lib-card-preview {
    width: 100%;
    aspect-ratio: 16 / 7;
    background: #f0f2f5;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}


/* Shimmer animation while loading */
.lib-card-preview::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg,
        transparent 0%, rgba(255,255,255,0.55) 50%, transparent 100%);
    background-size: 200% 100%;
    animation: lib-shimmer 1.4s infinite;
    border-radius: 8px;
}
.lib-card-preview:has(.lib-ecg-loaded)::after {
    display: none;
}
@keyframes lib-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position:  200% 0; }
}

.lib-ecg-canvas {
    width: 100%;
    height: 100%;
    display: block;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.lib-ecg-canvas.lib-ecg-loaded {
    opacity: 1;
}

/* Card info row */
.lib-card-info {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
}

.lib-record-id {
    font-size: 13px;
    font-weight: 700;
    color: #181c1f;
    font-family: 'Space Grotesk', monospace;
    letter-spacing: 0.02em;
}

.lib-demo {
    font-size: 11px;
    color: #9ea6b0;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Card measurement stats row ─────────────────────────────────── */
.lib-card-stats {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: -2px;
}

.lib-stat {
    font-size: 11px;
    font-weight: 600;
    color: #404750;
    font-family: 'Space Grotesk', monospace;
    letter-spacing: -0.01em;
}

.lib-stat-lbl {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #9ea6b0;
    margin-right: 3px;
    font-family: 'Inter', sans-serif;
}

.lib-stat-sep {
    font-size: 10px;
    color: #c8cdd3;
    line-height: 1;
}

/* QTc elevated */
.lib-stat.lib-stat-warn {
    color: #c2410c;
}
.lib-stat.lib-stat-warn .lib-stat-lbl {
    color: #e28063;
}

/* Irregular rhythm */
.lib-stat.lib-stat-irreg {
    font-size: 10px;
    color: #b91c1c;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.lib-empty {
    padding: 48px 20px;
    text-align: center;
    color: #9ea6b0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.lib-empty strong {
    font-size: 15px;
    color: #5f6876;
}
.lib-empty p {
    font-size: 13px;
    margin: 0;
}

/* Infinite scroll sentinel — invisible, full grid width so observer fires reliably */
.lib-sentinel {
    grid-column: 1 / -1;
    height: 1px;
    visibility: hidden;
}

/* Make filter bar wrap with group separators */
.lib-filters-wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 4px 20px 8px;
}
