/* Patient context first; the trash stays outside the scrolling content. */
.recording-library {
  padding: 14px 12px 0;
  gap: 12px;
  background: var(--surface);
}
.recording-library > .library-heading { flex: none; }
.library-heading .library-patient-label { color: var(--ink); font-size: 14px; font-weight: 600; }
.library-heading #libraryClose { border-color: transparent; color: var(--muted); font-size: 22px; }
.library-heading #libraryClose:hover { background: var(--surface-soft); color: var(--ink); }
.library-content { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; padding: 2px 3px 12px; margin: -2px -3px 0; }
.recording-library .patient-combobox input { min-height: 38px; padding-right: 64px; background: var(--surface); }
.recording-library .patient-combobox-clear { right: 34px; }
.patient-combobox-toggle { position: absolute; top: 1px; right: 1px; bottom: 1px; width: 31px; display: grid; place-items: center; padding: 0; border: 0; border-left: 1px solid var(--line); border-radius: 0 6px 6px 0; background: var(--surface-soft); color: var(--muted); cursor: pointer; }
.patient-combobox-toggle:is(:hover,[aria-expanded="true"]) { background: var(--accent-soft); color: var(--accent); }
.patient-combobox-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.patient-combobox-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.patient-combobox input::-webkit-search-cancel-button { display: none; }
.library-content > .patient-combobox-status:not(:empty) { margin-top: 8px; }
.library-patient-details { margin-top: 16px; }
.library-patient-details h2 { margin: 0 0 12px; color: var(--ink); font-size: 17px; line-height: 1.35; font-weight: 600; letter-spacing: -.025em; overflow-wrap: anywhere; }
.library-patient-facts { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px 10px; }
.library-patient-facts:empty { display: none; }
.library-patient-facts > div { min-width: 0; }
.library-patient-facts .patient-fact-wide { grid-column: 1 / -1; }
.library-patient-facts dt { margin-bottom: 3px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.library-patient-facts dd { margin: 0; color: var(--ink); font-size: 12px; font-weight: 500; line-height: 1.4; overflow-wrap: anywhere; }
.library-content > .library-patient-card { display: inline-block; margin-top: 12px; font-size: 11px; }
.recording-library > .library-import { flex: none; width: 100%; min-height: 38px; border-radius: 7px; }
.recording-picker #importDestination { max-width: 100%; margin: 4px 0 0 6px; }
.library-items { flex: none; overflow: visible; margin: 0; padding: 0; }
.recording-library .library-record { position: relative; display: block; margin: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); transition: border-color .15s, background .15s; }
.recording-library .library-record + .library-record { margin-top: 5px; }
.library-record:hover { border-color: var(--accent); background: var(--surface-soft); }
.recording-library .library-record.active { background: var(--accent-soft); border-color: var(--accent); box-shadow: inset 3px 0 var(--accent); }
.library-record > button:first-child { display: grid; gap: 5px; min-height: 44px; width: 100%; padding: 8px 9px; border-radius: 9px; line-height: 1.35; cursor: pointer; }
.library-record > button:first-child:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.library-record .record-heading { min-width: 0; }
body:not([data-patient]):not([data-restricted-library]) .library-record .record-heading { padding-right: 39px; }
.record-date { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 6px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.record-heading strong { font-size: 14px; font-weight: 700; line-height: 1.15; white-space: nowrap; color: var(--ink); }
.record-details { display: flex; align-items: baseline; gap: 3px 7px; flex-wrap: wrap; color: var(--muted); font-size: 10px; }
.record-duration { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; }
.library-record .record-age { color: var(--muted); }
.library-record .record-age:empty { display: none; }
.record-badges { display: flex; flex-wrap: wrap; gap: 3px; min-width: 0; }
.record-badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: 5px; padding: 2px 5px; font-weight: 600; font-size: 10px; color: var(--record-tone, var(--muted)); background: color-mix(in srgb, var(--record-tone, var(--muted)) 12%, transparent); }
.record-badge[data-tone="tag"] { --record-tone: var(--tag-color, var(--accent)); color: var(--ink); }
.record-badge[data-tone="tag"]::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; background: var(--record-tone); border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent); }
.record-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(53px, 1fr)); border-radius: 5px; background: color-mix(in srgb, var(--line) 30%, transparent); }
.record-metric { display: grid; gap: 1px; padding: 3px 4px; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.record-metric b { color: var(--record-tone, var(--ink)); font-size: 11px; white-space: nowrap; }
.record-notes { display: grid; gap: 1px; border-left: 2px solid var(--line); padding-left: 5px; min-width: 0; color: var(--muted); font-size: 11px; }
.record-notes b { font-size: 10px; }
.record-note-preview { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; white-space: pre-line; }
.library-record [data-tone="blue"] { --record-tone: var(--accent); }
.library-record [data-tone="teal"] { --record-tone: #0a706d; }
.library-record [data-tone="green"] { --record-tone: #24703e; }
.library-record [data-tone="orange"] { --record-tone: #925415; }
.library-record [data-tone="purple"] { --record-tone: #7048a8; }
.library-record [data-tone="red"] { --record-tone: #a8364c; }
:root[data-theme="dark"] .library-record [data-tone="teal"] { --record-tone: #6cd1c8; }
:root[data-theme="dark"] .library-record [data-tone="green"] { --record-tone: #94ce9e; }
:root[data-theme="dark"] .library-record [data-tone="orange"] { --record-tone: #efbb7c; }
:root[data-theme="dark"] .library-record [data-tone="purple"] { --record-tone: #c3a8f1; }
:root[data-theme="dark"] .library-record [data-tone="red"] { --record-tone: #f39aaa; }
.library-record-actions { position: absolute; top: 4px; right: 4px; display: flex; gap: 1px; }
.library-record .library-record-actions button { display: grid; place-items: center; width: 21px; height: 24px; padding: 3px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); opacity: 0; cursor: pointer; }
.library-record .library-record-actions svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.library-record:is(:hover,:focus-within) .library-record-actions button { opacity: 1; }
.library-record .assign-patient:hover { color: var(--accent); background: var(--surface); }
.library-record .delete-recording:hover { color: var(--red, #bd4650); background: var(--surface); }
.library-empty { padding: 16px 8px; border: 1px dashed var(--line); border-radius: 8px; font-size: 11px; text-align: center; }
.recording-library > .library-bottom { flex: none; margin: 0; padding: 10px 0 12px; border-top: 1px solid var(--line); }
.library-bottom .patients-trash-button { min-height: 36px; background: transparent; border-color: transparent; color: var(--muted); }
.library-bottom .patients-trash-button:hover { background: var(--surface-soft); border-color: var(--line); color: var(--ink); }
@media (pointer: coarse) { .library-record .library-record-actions button { opacity: 1; } }


/* A phone shows the selected recording or its library at full width. */
.desktop-shell { min-height: calc(100dvh - 56px); }
.desktop-shell #libraryClose[hidden] { display: none; }
.desktop-shell .recording-library { top: 56px; height: calc(100dvh - 56px); }
.desktop-shell > .app { height: calc(100dvh - 56px); }
@media (min-width: 701px) {
  .library-patient-details { margin-top: 10px; }
  .library-patient-details h2 { margin-bottom: 6px; }
}
@media (max-width: 1200px) {
  .desktop-shell > .app { height: auto; min-height: calc(100dvh - 56px); }
}
@media (max-width: 700px) {
  .desktop-shell:not(.library-hidden) > .app, .desktop-shell > .patient-scope-notice { display: none; }
  .desktop-shell .recording-library { position: relative; inset: auto; width: 100%; border: 0; box-shadow: none; }
  .desktop-shell .library-resize { display: none; }
  .desktop-shell .recording-library .library-heading h2 { font-size: 19px; }
  .desktop-shell .recording-library #libraryClose { width: 44px; height: 40px; }
  .desktop-shell .library-content { padding-bottom: 8px; }
  .desktop-shell .library-record .record-age { font-size: 11px; }
  .desktop-shell .library-bottom { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .desktop-shell .library-bottom:empty { display: none; }
  .desktop-shell > .app { padding: 6px; }
}
#libraryClose svg, .library-import-label svg {
  width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round;
}
.library-import-label { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.library-import-trace { display: none; }
body[data-patient] .recording-library {
  container: patient-library / inline-size;
  gap: 15px;
  padding: 16px 10px 0;
  background: linear-gradient(142deg, #f7f9fd, #eff4fc);
}
body[data-patient] .recording-library .library-bottom { display: none; }
body[data-patient] .recording-library .library-heading { padding-inline: 3px; }
body[data-patient] .recording-library .library-patient-label { color: #101828; font-size: 20px; font-weight: 700; }
body[data-patient] .recording-library #libraryClose { width: 28px; height: 22px; color: #556273; }
body[data-patient] .recording-library #libraryClose svg { width: 18px; height: 18px; }
body[data-patient] .recording-library > .library-import {
  position: relative; display: grid; place-items: center; min-height: 42px;
  padding: 0 10px; border: 0; border-radius: 7px; color: #f7fbff;
  background: linear-gradient(164deg, #1775d5 0%, #0757bf 56%, #0347a5 100%);
  font-size: 16px; font-weight: 700;
}
body[data-patient] .library-import-trace {
  position: absolute; inset-inline-end: 12px; display: block;
  width: clamp(38px, 15%, 64px); height: 24px; pointer-events: none;
  fill: none; stroke: url(#libraryTraceGradient); stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round;
}
.recording-library .patient-library-record {
  --card-border: #c3cddd;
  --card-bg: linear-gradient(155deg, #fcfdff, #f7f9fd);
  --selected-border: #0872f9;
  --selected-bg: linear-gradient(135deg, #eaf3fd, #e1edfb);
  --card-ink: #101828;
  --card-icon: #465466;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: 26px 26px;
  row-gap: 2px;
  padding-block: 5px 6px;
  border-color: var(--card-border);
  border-radius: 7px;
  background: var(--card-bg);
}
.recording-library .patient-library-record + .patient-library-record { margin-top: 8px; }
.recording-library .patient-library-record.active {
  border-color: var(--selected-border);
  background: var(--selected-bg);
  box-shadow: none;
}
:root[data-theme="dark"] body[data-patient] .recording-library { background: var(--surface); }
:root[data-theme="dark"] body[data-patient] .recording-library .library-patient-label { color: var(--ink); }
:root[data-theme="dark"] body[data-patient] .recording-library #libraryClose { color: var(--muted); }
:root[data-theme="dark"] .patient-library-record {
  --card-border: var(--line);
  --card-bg: var(--surface);
  --selected-border: var(--accent);
  --selected-bg: var(--accent-soft);
  --card-ink: var(--ink);
  --card-icon: var(--muted);
}
.patient-library-record > button:first-child {
  grid-area: 1 / 1 / 3 / 3;
  grid-template-columns: subgrid;
  grid-template-rows: subgrid;
  row-gap: inherit;
  min-height: 0;
  padding: 0;
  border-radius: 6px;
  font-family: inherit;
}
.patient-library-record .record-heading { grid-area: 1 / 1 / 2 / 3; align-self: center; padding: 0 37px 0 13px; }
.patient-library-record .record-start { display: flex; align-items: center; min-width: 0; gap: 10px; }
.patient-library-record .record-heading strong,
.patient-library-record .record-date {
  color: var(--card-ink); font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.patient-library-record .record-date {
  flex: none; flex-wrap: nowrap; align-items: center; column-gap: 4px; white-space: nowrap;
}
.patient-library-record .record-date svg { margin-inline-end: 6px; color: var(--card-icon); }
.patient-library-record .record-start .record-badge {
  min-width: 0; padding: 2px 6px; border-radius: 5px; font-size: 11px; font-weight: 650;
}
.patient-library-record .record-details {
  grid-area: 2 / 1; align-self: start; min-width: 0; padding-inline: 13px 5px;
  flex-wrap: nowrap; align-items: center; gap: 6px; white-space: nowrap;
}
.patient-library-record .record-metrics {
  --metric-spacing: 8px;
  display: flex; align-items: center; min-width: 0;
  overflow-x: auto; scrollbar-width: thin; background: none; border-radius: 0;
}
@supports selector(::-webkit-scrollbar) {
  .patient-library-record .record-metrics { scrollbar-width: auto; }
  .patient-library-record .record-metrics::-webkit-scrollbar { height: 5px; }
  .patient-library-record .record-metrics::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
}
.patient-library-record .record-metrics:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.patient-library-record .record-metrics:empty { display: none; }
.patient-library-record .record-unavailable { overflow: hidden; text-overflow: ellipsis; }
.patient-library-record .metric {
  display: inline-flex; flex: none; align-items: center; gap: 4px;
  height: 23px; font-size: 14px; font-weight: 600; line-height: 1;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  color: var(--metric-color);
}
.patient-library-record .metric + .metric {
  position: relative; margin-inline-start: var(--metric-spacing);
  padding-inline-start: calc(1px + var(--metric-spacing));
}
.patient-library-record .metric + .metric::before {
  content: ""; position: absolute; inset-inline-start: 0;
  width: 1px; height: 12px; background: var(--card-border);
}
.metric-duration { --metric-color: #34435e; }
.metric-hrv { --metric-color: #0c5c38; }
.metric-min { --metric-color: #0753c8; }
.metric-avg { --metric-color: #bb1421; }
.metric-max { --metric-color: #c94e08; }
:root[data-theme="dark"] .patient-library-record .metric {
  color: color-mix(in srgb, var(--metric-color) 42%, white);
}
.patient-library-record :is(.metric, .record-date, .record-note-indicator) svg {
  width: 16px; height: 16px; flex: none; fill: none;
  stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.patient-library-record .metric svg { color: var(--card-icon); }
.patient-library-record .record-more {
  grid-area: 1 / 1 / 2 / 3;
  align-self: center; justify-self: end;
  display: grid; place-items: center; width: 28px; height: 26px; padding: 0; margin-inline-end: 7px;
  border: 0; border-radius: 6px; background: transparent; color: var(--card-icon); cursor: pointer;
}
.patient-library-record .record-more svg { width: 18px; height: 18px; fill: currentColor; }
.patient-library-record .record-more:is(:hover,:focus-visible,[aria-expanded="true"]),
.patient-library-record:has(.record-menu:popover-open) .record-more { background: var(--accent-soft); color: var(--accent); }
.patient-library-record .record-indicators {
  grid-area: 2 / 2; align-self: start; z-index: 1;
  display: flex; align-items: center; gap: 2px; height: 23px; margin-inline-end: 7px;
}
.patient-library-record .record-note-indicator {
  display: grid; place-items: center; width: 18px; height: 18px; border-radius: 4px;
  color: var(--card-icon);
}
.patient-library-record .ecg-review-badges { flex-wrap: nowrap; gap: 2px; }
.patient-library-record .ecg-unreviewed {
  --badge-bg: transparent; --badge-color: var(--card-icon);
}
.patient-library-record .ecg-badge-icon { min-width: 28px; }
.patient-library-record .ecg-badge-icon svg { width: 17px; height: 17px; stroke-width: 1.75; }
.patient-library-record .ecg-checked { --badge-bg: #dcefe2; --badge-color: #184b2c; }
.patient-library-record .ecg-gray { --badge-bg: #eae4f6; --badge-color: #50377f; }
.patient-library-record .ecg-waiting { --badge-bg: #eaf1fb; --badge-color: #244878; }
.patient-library-record .patient-record-messages {
  display: grid; place-items: center; width: auto; height: auto; min-height: 22px; padding: 0 2px;
  border-color: transparent; background: transparent;
}
.patient-library-record .patient-record-messages:hover { border-color: var(--line); }
.patient-library-record .patient-record-messages.has-unread { border-color: var(--accent); background: var(--accent-soft); }
@container patient-library (width <= 410px) {
  .patient-library-record .record-details { padding-inline-end: 4px; }
  .patient-library-record .record-metrics { --metric-spacing: 5px; }
  .patient-library-record .metric { gap: 3px; font-size: 12px; }
  .patient-library-record .metric svg { width: 13px; height: 13px; }
  .patient-library-record .record-indicators { margin-inline-end: 5px; }
  .patient-library-record .ecg-badge-icon { min-width: 22px; }
}
@container patient-library (width <= 335px) {
  .recording-library .patient-library-record { grid-template-rows: 23px 23px; }
  .patient-library-record .record-heading { padding: 0 30px 0 8px; }
  .patient-library-record .record-start { gap: 5px; }
  .patient-library-record :is(.record-date, .record-heading strong) { font-size: 13px; }
  .patient-library-record .record-date svg { width: 13px; height: 13px; margin-inline-end: 2px; }
  .patient-library-record .record-details { padding-inline: 8px 3px; }
  .patient-library-record .record-metrics { --metric-spacing: 4px; }
  .patient-library-record .metric { gap: 2px; height: 20px; font-size: 11px; }
  .patient-library-record .metric svg { width: 10px; height: 10px; }
  .patient-library-record .record-more { margin-inline-end: 3px; }
  .patient-library-record .record-indicators { gap: 1px; height: 20px; margin-inline-end: 4px; }
  .patient-library-record .record-note-indicator { width: 13px; }
  .patient-library-record .ecg-badge-icon { min-width: 17px; }
  .patient-library-record :is(.ecg-badge-icon, .record-note-indicator) svg { width: 13px; height: 13px; }
  .patient-library-record .patient-record-messages { padding-inline: 0; }
}
body[data-patient] #recordReviewStatus { display: none; }
.record-menu {
  position: fixed; inset: auto; box-sizing: border-box; margin: 0; min-width: 178px; padding: 4px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink);
  box-shadow: 0 8px 24px #0b193626;
}
.record-menu button.tool, .record-menu .delete-recording {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 34px; padding: 5px 8px;
  border: 0; border-radius: 5px; background: transparent; color: var(--ink); font: inherit; font-size: 12px;
  text-align: left; cursor: pointer;
}
.record-menu .delete-recording, .record-tag-dialog .record-tag-remove { color: var(--red, #bd4650); }
.record-menu button:is(:hover,:focus-visible), .library-record .record-menu .delete-recording:hover { background: var(--surface-soft); }
.record-menu svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.record-menu .record-tag-filled path { fill: currentColor; }
.record-menu .record-tag-filled circle { stroke: var(--surface); }
.record-tag-dialog { max-width: 390px; }
.record-tag-dialog #recordTagTitle { font-size: 18px; }
.record-tag-dialog .record-tag-color { display: flex; align-items: center; justify-content: space-between; }
.record-tag-dialog #recordTagColor { width: 50px; height: 32px; padding: 2px 4px; cursor: pointer; }
.record-tag-dialog #recordTagNotice:empty { display: none; }
.record-tag-dialog .record-tag-remove { margin-inline-end: auto; }
.record-tag-dialog .record-tag-remove[hidden] { display: none; }
.record-tag-dialog .record-tag-save { background: var(--accent); color: var(--surface); }
.library-record > button:first-child .ecg-review-badges { grid-column: 1/-1; justify-self: start; white-space: normal; }
