:root {
  color-scheme: light;
  --ink: #17233d;
  --muted: #63708a;
  --line: #d7deea;
  --line-strong: #b9c5d8;
  --soft: #f4f7fb;
  --paper: #ffffff;
  --blue: #075bd8;
  --blue-dark: #0647a6;
  --blue-soft: #eaf2ff;
  --violet: #6656d9;
  --green: #087f5b;
  --green-soft: #e6f7f0;
  --amber: #9a6700;
  --red: #b42318;
  --red-soft: #fff0ee;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--soft); color: var(--ink); }
body { min-width: 320px; }
button, input, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.app-header {
  min-height: 70px;
  padding: 10px max(20px, calc((100% - 1480px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand-block, .header-context { display: flex; align-items: center; }
.brand-block { gap: 12px; }
.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--blue);
  border-radius: 6px;
  font-size: 20px;
  font-weight: 800;
}
.brand-block h1 { margin: 0; font-size: 22px; line-height: 1.15; font-weight: 750; }
.brand-block p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.header-context { gap: 9px; color: var(--muted); font-size: 12px; }
.header-context > span { padding-right: 9px; border-right: 1px solid var(--line); }
.header-context strong { max-width: 260px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button { min-height: 36px; border: 1px solid transparent; border-radius: 5px; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #8bb8f7;
  outline-offset: 2px;
}
.icon-button { width: 38px; min-width: 38px; height: 38px; padding: 0; display: inline-grid; place-items: center; background: #fff; border-color: var(--line-strong); color: var(--blue); }
.icon-button:hover:not(:disabled) { background: var(--blue-soft); border-color: #91b3e5; }
.header-button { margin-left: 4px; color: #52627d; }
.primary-button, .secondary-button { min-height: 38px; padding: 0 16px; font-weight: 700; }
.primary-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: #fff; background: var(--blue); border-color: var(--blue); }
.primary-button:hover:not(:disabled) { background: var(--blue-dark); border-color: var(--blue-dark); }
.primary-button svg { width: 17px; height: 17px; }
.secondary-button { color: var(--ink); background: #fff; border-color: var(--line-strong); }
.secondary-button:hover { background: #f4f6fa; }

main { width: min(1480px, calc(100% - 32px)); margin: 18px auto 28px; }
.patient-band, .discovery-band, .worklist, .source-status { background: var(--paper); border: 1px solid var(--line); border-radius: 7px; }

.patient-band {
  min-height: 76px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.eyebrow { display: block; margin-bottom: 2px; color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; }
.patient-identity h2 { margin: 0; font-size: 20px; line-height: 1.25; font-weight: 750; }
.patient-facts { margin-top: 4px; display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.patient-facts span + span { position: relative; }
.patient-facts span + span::before { content: ""; position: absolute; left: -8px; top: 4px; width: 1px; height: 10px; background: var(--line-strong); }
.launch-state { min-height: 34px; padding: 0 14px; display: inline-flex; align-items: center; gap: 7px; border: 1px solid #76c4aa; border-radius: 999px; color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 750; white-space: nowrap; }
.launch-state svg { width: 17px; height: 17px; }
.launch-state.pending { color: #5d6b80; background: #f2f4f8; border-color: var(--line-strong); }
.launch-state.error { color: var(--red); background: var(--red-soft); border-color: #efafa8; }

.discovery-band { margin-top: 14px; }
.section-heading { padding: 16px 18px 10px; display: flex; align-items: end; justify-content: space-between; gap: 18px; }
.section-heading h2, .worklist-heading h2, .source-status h2 { margin: 0; font-size: 19px; line-height: 1.25; font-weight: 750; }
.section-heading p, .worklist-heading p, .source-status p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.result-metrics { display: flex; align-items: baseline; gap: 10px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.result-metrics strong { color: var(--ink); font-size: 13px; }

.filter-toolbar {
  padding: 0 18px 16px;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: end;
  gap: 9px;
}
.record-field, .modality-field, .document-class-field, .source-field, .report-field { grid-column: span 2; }
.date-field { grid-column: span 2; grid-row: 2; }
.search-field { grid-column: span 5; grid-row: 2; }
.filter-toolbar label { min-width: 0; }
.filter-toolbar label > span:first-child { display: block; margin: 0 0 4px 1px; color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; }
.filter-toolbar input, .filter-toolbar select { width: 100%; height: 38px; padding: 0 10px; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 5px; }
.search-input { position: relative; display: block; }
.search-input svg { position: absolute; left: 10px; top: 10px; width: 18px; height: 18px; color: #6d7d96; pointer-events: none; }
.search-input input { padding-left: 36px; }
.refresh-button { grid-column: 12; grid-row: 2; align-self: end; }
.refresh-button.loading svg { animation: spin .8s linear infinite; }

.worklist { margin-top: 14px; overflow: hidden; }
.worklist-heading { min-height: 68px; padding: 13px 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); }
.worklist-heading h2 { font-size: 17px; }
.worklist-tools { display: flex; align-items: center; justify-content: flex-end; gap: 14px; }
.worklist-counts { display: flex; gap: 16px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.worklist-counts strong { color: var(--ink); }
.selection-summary { color: var(--muted); font-size: 11px; white-space: nowrap; }
.copy-button { min-width: 132px; }

.table-wrap { max-height: 520px; overflow: auto; }
table { width: 100%; min-width: 940px; border-collapse: collapse; table-layout: fixed; }
thead { position: sticky; top: 0; z-index: 2; }
th { height: 42px; padding: 0 12px; color: #34415a; background: #eaf2ff; border-bottom: 1px solid #c5d7f0; font-size: 11px; text-align: left; }
th:not(:last-child), td:not(:last-child) { border-right: 1px solid #edf0f5; }
td { height: 62px; padding: 8px 12px; border-bottom: 1px solid #e5e9f0; font-size: 12px; vertical-align: middle; overflow-wrap: anywhere; }
tbody tr:hover { background: #f7faff; }
tbody tr.selected-row { background: #eef5ff; }
tbody tr:last-child td { border-bottom: 0; }
.selection-header { padding: 0; text-align: center; }
.selection-header input, .selection-control input { width: 17px; height: 17px; margin: 0; accent-color: var(--blue); cursor: pointer; }
.selection-control { min-height: 34px; display: grid; place-items: center; }
.selection-control.unavailable input { cursor: not-allowed; }
.sort-button { min-height: 30px; padding: 0; display: inline-flex; align-items: center; gap: 6px; color: inherit; background: transparent; border: 0; font-weight: 750; }
.sort-button svg { width: 14px; height: 14px; color: var(--blue); }
.description { display: block; color: #22304b; font-size: 13px; font-weight: 700; }
.record-type { display: block; margin-bottom: 3px; color: var(--blue-dark); font-size: 9px; font-weight: 800; text-transform: uppercase; }
.secondary { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.modality { display: inline-grid; min-width: 38px; min-height: 26px; padding: 0 7px; place-items: center; color: #fff; background: #53657e; border-radius: 4px; font-size: 10px; font-weight: 800; }
.document-class { display: inline-block; max-width: 100%; padding: 4px 7px; color: #245c52; background: #e8f3f0; border: 1px solid #b7d8cf; border-radius: 4px; font-size: 10px; font-weight: 750; overflow-wrap: anywhere; }
.document-class + .document-class { margin-top: 4px; }
.image-count { color: #273653; font-weight: 750; }
.thumbnail-frame { width: 72px; height: 50px; margin: 0 auto; position: relative; display: grid; place-items: center; overflow: hidden; background: #101318; border: 1px solid #bac4d3; border-radius: 4px; }
.study-thumbnail { width: 100%; height: 100%; display: block; object-fit: contain; }
.thumbnail-placeholder { display: none; color: #8995a8; }
.thumbnail-placeholder svg { width: 22px; height: 22px; }
.thumbnail-frame.unavailable { background: #f0f3f7; }
.thumbnail-frame.unavailable .thumbnail-placeholder { display: grid; place-items: center; }
.report-summary { display: grid; grid-template-columns: minmax(0, 1fr) max-content; align-items: center; gap: 7px; }
.report-summary + .report-summary { margin-top: 6px; }
.report-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-pill { padding: 3px 6px; border-radius: 4px; color: #356050; background: #e2f2eb; font-size: 9px; font-weight: 750; text-transform: capitalize; }
.no-report, .no-action { color: #7a879b; font-size: 11px; }
.report-only-row { background: #fbfbfd; }
.source-name { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.source-part { display: block; color: #26354e; line-height: 1.25; overflow-wrap: anywhere; white-space: normal; }
.row-actions { display: flex; align-items: center; justify-content: center; gap: 7px; }
.action-button { width: 36px; min-width: 36px; height: 36px; display: inline-grid; place-items: center; border: 1px solid #aab7ca; border-radius: 5px; color: var(--violet); background: #fff; text-decoration: none; }
.action-button:hover { color: #fff; background: var(--violet); border-color: var(--violet); }
.action-button.report-action { color: var(--blue); }
.action-button.report-action:hover { color: #fff; background: var(--blue); border-color: var(--blue); }
.action-button:disabled { color: #9ca7b8; background: #f2f4f7; }
.action-button svg { width: 19px; height: 19px; }

.notice { margin: 12px 18px 0; padding: 10px 12px; color: #80231b; background: var(--red-soft); border: 1px solid #f2b8b2; border-radius: 5px; font-size: 12px; }
.notice.warning { color: #6b4b00; background: #fff6d8; border-color: #e2bd55; }
.state-panel { min-height: 350px; padding: 38px 20px; display: grid; place-content: center; justify-items: center; text-align: center; }
.state-panel h3 { margin: 13px 0 5px; font-size: 18px; }
.state-panel p { max-width: 620px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.state-panel .primary-button { margin-top: 20px; min-width: 160px; }
.state-icon { width: 62px; height: 62px; display: grid; place-items: center; color: var(--blue); background: var(--blue-soft); border: 1px solid #9dc0ef; border-radius: 50%; }
.state-icon svg { width: 29px; height: 29px; }
.error-icon { color: var(--red); background: var(--red-soft); border-color: #efafa8; }
.spinner { width: 40px; height: 40px; border: 4px solid #d8e5f7; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }

.source-status { min-height: 78px; margin-top: 14px; padding: 13px 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.source-status h2 { font-size: 15px; }
.source-chip { min-height: 28px; padding: 0 12px; display: inline-flex; align-items: center; color: var(--green); background: var(--green-soft); border: 1px solid #76c4aa; border-radius: 999px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.source-chip.pending { color: #5d6b80; background: #f2f4f8; border-color: var(--line-strong); }
.source-chip.error { color: var(--red); background: var(--red-soft); border-color: #efafa8; }
.source-chip.warning { color: #6b4b00; background: #fff6d8; border-color: #e2bd55; }

dialog { width: min(680px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; color: var(--ink); background: transparent; border: 0; border-radius: 8px; overflow: visible; }
dialog::backdrop { background: rgba(14, 24, 45, .58); }
.dialog-card { position: relative; padding: 28px 30px 24px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 18px 52px rgba(20, 34, 60, .24); }
.dialog-close { position: absolute; top: 15px; right: 15px; color: #53617a; border-color: transparent; }
.dialog-heading { padding-right: 38px; }
.dialog-heading h2 { margin: 0; font-size: 22px; }
.dialog-heading p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.selected-study { margin-top: 24px; display: flex; align-items: center; gap: 15px; }
.study-icon { width: 58px; height: 58px; flex: 0 0 58px; display: grid; place-items: center; color: var(--violet); background: #f0edff; border-radius: 7px; }
.study-icon svg { width: 26px; height: 26px; }
.study-icon.has-thumbnail { overflow: hidden; background: #101318; border: 1px solid #bac4d3; }
.dialog-study-thumbnail { width: 100%; height: 100%; display: block; object-fit: cover; }
.selected-study h3 { margin: 0; font-size: 17px; }
.selected-study p { margin: 4px 0; color: var(--muted); font-size: 12px; }
.selected-study span { color: #43506a; font-size: 12px; }
.session-details { margin-top: 22px; padding: 15px 17px; color: #293955; background: var(--blue-soft); border: 1px solid #8db7ed; border-radius: 6px; }
.session-details > strong { display: block; margin-bottom: 9px; font-size: 12px; }
.session-details div { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11px; }
.session-details p { margin: 8px 0 0; color: #5c6b84; font-size: 11px; }
.dialog-error { margin-top: 14px; padding: 9px 11px; color: #80231b; background: var(--red-soft); border: 1px solid #f2b8b2; border-radius: 5px; font-size: 12px; }
.dialog-actions { margin-top: 24px; display: flex; justify-content: flex-end; gap: 10px; }
.dialog-actions button { min-width: 116px; }
.copy-selection { max-height: 260px; margin-top: 20px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.copy-study { padding: 12px 14px; display: flex; align-items: center; gap: 12px; }
.copy-study + .copy-study { border-top: 1px solid var(--line); }
.copy-study-icon { width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center; color: var(--blue); background: var(--blue-soft); border-radius: 5px; }
.copy-study-icon svg { width: 20px; height: 20px; }
.copy-study > div { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.copy-study strong { color: #22304b; font-size: 13px; }
.copy-study span { color: var(--muted); font-size: 11px; }
.copy-study .source-part { color: var(--muted); font-size: 11px; }
.copy-integration-note { margin-top: 16px; padding: 13px 14px; display: flex; align-items: flex-start; gap: 10px; color: #6b4b00; background: #fff6d8; border: 1px solid #e2bd55; border-radius: 6px; }
.copy-integration-note > svg { width: 19px; height: 19px; flex: 0 0 19px; }
.copy-integration-note strong { display: block; font-size: 12px; }
.copy-integration-note p { margin: 4px 0 0; font-size: 11px; line-height: 1.45; }
.copy-progress { margin-top: 16px; padding: 13px 14px; color: #26354e; background: #f4f8fd; border: 1px solid #a8c3e8; border-radius: 6px; }
.copy-progress.completed { color: #126447; background: var(--green-soft); border-color: #76c4aa; }
.copy-progress.partial, .copy-progress.failed { color: #80231b; background: var(--red-soft); border-color: #f2b8b2; }
.copy-progress-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.copy-progress-heading strong { font-size: 12px; }
.copy-progress-heading span { color: inherit; font-size: 11px; }
.copy-job-items { margin-top: 9px; display: grid; gap: 6px; }
.copy-job-item { padding-top: 6px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 12px; border-top: 1px solid rgba(82, 113, 153, .2); font-size: 11px; }
.copy-job-item strong { overflow-wrap: anywhere; }
.copy-job-item .copy-item-state { font-weight: 750; }
.copy-job-item p { grid-column: 1 / -1; margin: 0; color: inherit; opacity: .78; }

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

@media (max-width: 1180px) {
  .filter-toolbar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .record-field, .modality-field, .document-class-field, .source-field, .report-field, .date-field { grid-column: span 1; grid-row: auto; }
  .search-field { grid-column: span 3; grid-row: auto; }
  .refresh-button { grid-column: auto; grid-row: auto; }
}

@media (max-width: 760px) {
  .app-header { min-height: 62px; padding: 9px 14px; }
  .brand-mark { width: 34px; height: 34px; flex-basis: 34px; }
  .brand-block h1 { font-size: 17px; }
  .header-context > span, .header-context strong { display: none; }
  main { width: 100%; margin: 0; }
  .patient-band, .discovery-band, .worklist, .source-status { border-left: 0; border-right: 0; border-radius: 0; }
  .patient-band { min-height: 0; padding: 14px; align-items: flex-start; }
  .patient-identity h2 { font-size: 18px; }
  .launch-state { width: 34px; min-width: 34px; padding: 0; justify-content: center; }
  .launch-state span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .discovery-band, .worklist, .source-status { margin-top: 10px; }
  .section-heading { padding: 14px 14px 10px; align-items: flex-start; }
  .result-metrics { flex-direction: column; align-items: flex-end; gap: 2px; }
  .filter-toolbar { padding: 0 14px 14px; grid-template-columns: 1fr 1fr; }
  .source-field, .report-field, .document-class-field, .search-field { grid-column: 1 / -1; }
  .search-field { grid-column: 1 / -2; }
  .worklist-heading { min-height: 0; padding: 13px 14px; align-items: flex-start; flex-wrap: wrap; }
  .worklist-heading p { max-width: 430px; }
  .worklist-tools { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .worklist-counts { flex-direction: column; gap: 2px; text-align: right; }
  .notice { margin: 10px 14px 0; }
  .table-wrap { max-height: none; overflow: visible; }
  table { min-width: 0; table-layout: auto; }
  thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
  tbody, tr { display: block; }
  tbody tr { padding: 13px 14px; border-bottom: 1px solid var(--line); }
  td { height: auto; padding: 4px 0; border: 0 !important; }
  td::before { content: attr(data-label); display: block; margin-bottom: 3px; color: var(--muted); font-size: 9px; font-weight: 800; text-transform: uppercase; }
  .table-wrap tr { display: grid; grid-template-columns: 82px minmax(0, 1fr) 92px; column-gap: 12px; row-gap: 5px; }
  .table-wrap td:nth-child(1) { grid-column: 1; grid-row: 1; align-self: center; }
  .table-wrap td:nth-child(1)::before { display: none; }
  .table-wrap td:nth-child(2) { grid-column: 2; grid-row: 1; }
  .table-wrap td:nth-child(3) { grid-column: 1 / 3; grid-row: 2; }
  .table-wrap td:nth-child(4) { grid-column: 1 / -1; grid-row: 3; }
  .table-wrap td:nth-child(5) { grid-column: 3; grid-row: 1; text-align: right; }
  .table-wrap td:nth-child(6) { grid-column: 3; grid-row: 2; align-self: start; }
  .table-wrap td:nth-child(7) { grid-column: 3; grid-row: 4; text-align: right; }
  .table-wrap td:nth-child(8) { grid-column: 1; grid-row: 5; }
  .table-wrap td:nth-child(9) { grid-column: 1 / 3; grid-row: 4; }
  .table-wrap td:nth-child(10) { grid-column: 3; grid-row: 5; align-self: center; }
  .row-actions { justify-content: flex-end; }
  .state-panel { min-height: 330px; }
  .source-status { margin-bottom: 0; padding: 13px 14px; }
  .dialog-card { padding: 24px 20px 20px; }
}

@media (max-width: 480px) {
  .patient-band { gap: 10px; }
  .patient-facts { display: block; }
  .patient-facts span { display: block; margin-top: 3px; }
  .patient-facts span + span::before { display: none; }
  .section-heading h2 { font-size: 18px; }
  .filter-toolbar { grid-template-columns: 1fr 1fr; }
  .record-field, .modality-field, .document-class-field, .source-field, .report-field { grid-column: 1 / -1; }
  .search-field { grid-column: 1 / -2; }
  .worklist-heading { display: block; }
  .worklist-tools { margin-top: 10px; display: grid; grid-template-columns: 1fr auto; }
  .worklist-counts { margin-top: 0; flex-direction: row; text-align: left; }
  .selection-summary { grid-column: 1; }
  .copy-button { grid-column: 2; grid-row: 1 / span 2; }
  .selected-study { align-items: flex-start; }
  .session-details div { display: grid; gap: 5px; }
  .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .dialog-actions button { width: 100%; min-width: 0; }
}
