:root {
  color-scheme: dark;
  --capmap-blue: #0e5fd8;
  --capmap-blue-ink: #5b9cff;
  --capmap-aqua: #35e0bc;
  --capmap-aqua-ink: #35e0bc;
  --capmap-teal: #087a6b;
  --capmap-green: #1d9e75;
  --bg: #07101b;
  --bg-raised: #0b1522;
  --surface: #101b29;
  --surface-2: #152231;
  --surface-3: #1a2a3b;
  --viewer: #0b111b;
  --text: #f4f8fd;
  --text-soft: #cbd6e5;
  --muted: #91a1b6;
  --muted-2: #718197;
  --border: rgba(173, 198, 228, 0.14);
  --border-strong: rgba(173, 198, 228, 0.24);
  --glass: rgba(9, 20, 34, 0.74);
  --danger: #ff7b7b;
  --warning: #ffc46b;
  --success: #45d7a4;
  --focus: #76adff;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.34);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  --font-rounded: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  min-height: 100svh;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

a {
  color: var(--capmap-blue-ink);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

::selection {
  background: rgba(53, 224, 188, 0.28);
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 10px;
  left: 12px;
  transform: translateY(-150%);
  border-radius: 9px;
  padding: 10px 14px;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--capmap-aqua-ink);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.11em;
  line-height: 1.2;
  text-transform: uppercase;
}

.wordmark {
  display: inline-flex;
  align-items: baseline;
  font-family: var(--font-rounded);
  font-size: 20px;
  font-weight: 850;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.wordmark-cap {
  color: var(--capmap-blue);
  text-shadow: 0 0 20px rgba(14, 95, 216, 0.26);
}

.wordmark-map {
  color: var(--text);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-icon {
  display: block;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  object-fit: cover;
  box-shadow: 0 7px 22px rgba(14, 95, 216, 0.28);
}

.brand-context {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px 14px;
  background: var(--capmap-blue);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.button:hover:not(:disabled) {
  background: #176be3;
}

.button:active:not(:disabled) {
  transform: scale(0.985);
}

.button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.button-quiet {
  min-height: 38px;
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.055);
  color: var(--text-soft);
}

.button-quiet:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.09);
}

/* ---------------------------------------------------------------- portal */

.portal-page {
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  height: 100svh;
  min-height: 0;
  flex-direction: column;
  background:
    radial-gradient(circle at 84% -16%, rgba(14, 95, 216, 0.18), transparent 34%),
    var(--bg);
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  min-height: 68px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: var(--glass);
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.15);
  -webkit-backdrop-filter: blur(22px) saturate(145%);
  backdrop-filter: blur(22px) saturate(145%);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.read-only-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(53, 224, 188, 0.22);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(53, 224, 188, 0.075);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
}

.read-only-pill span {
  color: var(--capmap-aqua-ink);
  font-size: 9px;
}

#status {
  min-height: 30px;
  flex: 0 0 auto;
  padding: 7px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(14, 95, 216, 0.055);
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
}

#status.ok {
  color: var(--success);
}

#status.err {
  color: var(--danger);
}

#warn {
  display: none;
  flex: 0 0 auto;
  margin: 10px 18px 0;
  border: 1px solid rgba(255, 196, 107, 0.25);
  border-radius: 12px;
  padding: 10px 13px;
  background: rgba(255, 166, 32, 0.09);
  color: #ffdda8;
  font-size: 12px;
  line-height: 1.45;
}

#warn.show {
  display: block;
}

#warn ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

#warn li + li {
  margin-top: 3px;
}

.portal-page main {
  display: flex;
  min-height: 0;
  flex: 1;
}

#side {
  display: flex;
  width: 310px;
  min-height: 0;
  flex: 0 0 auto;
  flex-direction: column;
  padding: 19px 14px 14px;
  border-right: 1px solid var(--border);
  background: var(--bg-raised);
}

.side-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px 14px;
}

.side-heading h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 750;
  letter-spacing: -0.025em;
}

.case-count {
  display: inline-flex;
  min-width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 9px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.search-field {
  position: relative;
  display: block;
  margin: 0 2px 10px;
}

.search-field input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px 10px 38px;
  outline: 0;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.search-field input::placeholder {
  color: var(--muted-2);
}

.search-field input:focus {
  border-color: var(--capmap-blue-ink);
  box-shadow: 0 0 0 3px rgba(91, 156, 255, 0.14);
}

.search-icon {
  position: absolute;
  z-index: 1;
  top: 13px;
  left: 14px;
  width: 13px;
  height: 13px;
  border: 1.8px solid var(--muted-2);
  border-radius: 50%;
  pointer-events: none;
}

.search-icon::after {
  position: absolute;
  right: -5px;
  bottom: -3px;
  width: 6px;
  height: 2px;
  border-radius: 1px;
  background: var(--muted-2);
  content: "";
  transform: rotate(45deg);
}

.button-sync {
  width: calc(100% - 4px);
  margin: 0 2px;
  border-color: rgba(14, 95, 216, 0.55);
  background: rgba(14, 95, 216, 0.18);
  color: #cfe1ff;
}

.button-sync:hover:not(:disabled) {
  border-color: rgba(91, 156, 255, 0.74);
  background: rgba(14, 95, 216, 0.28);
}

.sync-icon {
  display: inline-block;
  color: var(--capmap-aqua-ink);
  font-size: 18px;
  line-height: 1;
}

.button-sync.syncing .sync-icon {
  animation: sync-spin 850ms linear infinite;
}

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

.sync-note {
  margin: 8px 5px 13px;
  color: var(--muted-2);
  font-size: 10.5px;
  line-height: 1.45;
}

#caseList,
.case-sublist {
  list-style: none;
  margin: 0;
  padding: 0;
}

#caseList {
  min-height: 0;
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--surface-3) transparent;
}

.list-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 15px 6px 7px;
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.085em;
  text-transform: uppercase;
}

.list-group-title:first-child {
  margin-top: 2px;
}

.case-card {
  position: relative;
  display: block;
  width: 100%;
  min-height: 66px;
  margin: 0 0 5px;
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 11px 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.case-card:hover {
  border-color: var(--border);
  background: var(--surface);
}

.case-card:active {
  transform: scale(0.99);
}

.case-card.active,
.case-card[aria-current="true"] {
  border-color: rgba(91, 156, 255, 0.32);
  background: linear-gradient(135deg, rgba(14, 95, 216, 0.27), rgba(14, 95, 216, 0.11));
  box-shadow: inset 3px 0 0 var(--capmap-blue-ink);
}

.case-card .nm {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 690;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-card .dt {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-card.pending .nm::after {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 7px;
  border-radius: 50%;
  background: var(--capmap-aqua);
  box-shadow: 0 0 0 3px rgba(53, 224, 188, 0.08);
  content: "";
  vertical-align: 1px;
}

.list-empty {
  margin: 8px 3px;
  border: 1px dashed var(--border);
  border-radius: 13px;
  padding: 18px 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.055em;
  line-height: 1.35;
  text-transform: uppercase;
  vertical-align: 1px;
}

.badge.app {
  background: rgba(53, 224, 188, 0.11);
  color: var(--capmap-aqua-ink);
}

.badge.man,
.badge.legacy {
  background: rgba(145, 161, 182, 0.12);
  color: var(--muted);
}

.red {
  color: var(--danger);
}

#content {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  background: var(--bg);
}

.empty-selection {
  display: flex;
  width: min(560px, calc(100% - 40px));
  min-height: 0;
  margin: auto;
  align-items: center;
  flex-direction: column;
  padding: 48px 24px;
  color: var(--muted);
  text-align: center;
}

.empty-selection h2 {
  margin: 4px 0 10px;
  color: var(--text);
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 750;
  letter-spacing: -0.04em;
}

#emptyBody {
  max-width: 490px;
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
}

.empty-facts {
  display: none;
  width: min(430px, 100%);
  margin: 24px 0 0;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--border);
  text-align: left;
}

.empty-facts.has-facts {
  display: grid;
}

.empty-facts div {
  min-width: 0;
  padding: 11px 12px;
  background: var(--surface);
}

.empty-facts dt {
  margin-bottom: 4px;
  color: var(--muted-2);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.075em;
  text-transform: uppercase;
}

.empty-facts dd {
  margin: 0;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-mark {
  position: relative;
  width: 78px;
  height: 78px;
  margin-bottom: 24px;
  border: 1px solid rgba(91, 156, 255, 0.24);
  border-radius: 24px;
  background:
    linear-gradient(145deg, rgba(14, 95, 216, 0.24), rgba(53, 224, 188, 0.06)),
    var(--surface);
  box-shadow: 0 18px 50px rgba(14, 95, 216, 0.14);
}

.empty-mark::before,
.empty-mark::after {
  position: absolute;
  background: linear-gradient(90deg, transparent, rgba(53, 224, 188, 0.72), transparent);
  content: "";
}

.empty-mark::before {
  top: 25px;
  left: 14px;
  width: 50px;
  height: 1px;
  transform: rotate(-18deg);
}

.empty-mark::after {
  top: 48px;
  left: 13px;
  width: 52px;
  height: 1px;
  transform: rotate(16deg);
}

.empty-mark span {
  position: absolute;
  width: 8px;
  height: 8px;
  border: 2px solid var(--capmap-aqua);
  border-radius: 50%;
  background: var(--surface);
}

.empty-mark span:nth-child(1) { top: 18px; left: 17px; }
.empty-mark span:nth-child(2) { top: 33px; right: 15px; }
.empty-mark span:nth-child(3) { bottom: 17px; left: 19px; }
.empty-mark span:nth-child(4) { bottom: 12px; right: 19px; }

.case-workspace {
  display: none;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

.has-case #emptySelection,
.has-patient #emptySelection {
  display: none;
}

.has-case .case-workspace {
  display: flex;
}

.patient-summary {
  display: none;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  background: var(--bg);
}

.has-patient .patient-summary {
  display: flex;
}

.has-case .patient-summary {
  display: none;
}

.patient-summary-heading {
  display: flex;
  min-height: 102px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(16, 27, 41, 0.76);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
  backdrop-filter: blur(18px) saturate(135%);
}

.patient-summary-heading h2 {
  margin: 0;
  font-size: clamp(23px, 3vw, 31px);
  font-weight: 760;
  letter-spacing: -0.04em;
  line-height: 1.1;
}

.patient-summary-body {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 24px;
  scrollbar-color: var(--surface-3) transparent;
}

.patient-loading {
  display: flex;
  min-height: 260px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.patient-loading span {
  width: 17px;
  height: 17px;
  border: 2px solid rgba(91, 156, 255, 0.2);
  border-top-color: var(--capmap-blue-ink);
  border-radius: 50%;
  animation: sync-spin 850ms linear infinite;
}

.patient-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.patient-stat {
  min-width: 0;
  min-height: 104px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: var(--surface);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.09);
}

.patient-stat span {
  display: block;
  min-height: 30px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.patient-stat strong {
  display: block;
  margin-top: 7px;
  color: var(--text);
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
  letter-spacing: -0.04em;
}

.patient-stat strong.date {
  overflow: hidden;
  color: var(--text-soft);
  font-size: 15px;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.patient-facts {
  display: grid;
  margin: 14px 0 0;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--border);
  gap: 1px;
}

.patient-facts div {
  min-width: 0;
  padding: 13px 15px;
  background: var(--surface);
}

.patient-facts dt {
  margin: 0 0 5px;
  color: var(--muted-2);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.patient-facts dd {
  margin: 0;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.journey-section {
  margin-top: 28px;
}

.journey-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.journey-title h3 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 730;
  letter-spacing: -0.025em;
}

.journey-title > span {
  display: inline-flex;
  min-width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.study-list,
.linked-case-list {
  display: grid;
  gap: 9px;
}

.study-card {
  display: grid;
  min-width: 0;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 13px 14px;
  background: var(--surface);
}

.study-index {
  display: flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(53, 224, 188, 0.2);
  border-radius: 11px;
  background: rgba(53, 224, 188, 0.08);
  color: var(--capmap-aqua-ink);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.study-content {
  min-width: 0;
}

.study-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.study-head h4,
.linked-case-card h4 {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 710;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.study-status {
  flex: 0 0 auto;
  border: 1px solid rgba(91, 156, 255, 0.22);
  border-radius: 999px;
  padding: 3px 7px;
  background: rgba(91, 156, 255, 0.07);
  color: var(--capmap-blue-ink);
  font-size: 9px;
  font-weight: 750;
}

.study-card p,
.linked-case-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
}

.module-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 9px;
}

.module-tags span {
  border-radius: 7px;
  padding: 4px 7px;
  background: var(--surface-3);
  color: var(--text-soft);
  font-size: 9.5px;
  font-weight: 650;
}

.linked-case-card {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 14px;
  background: var(--surface);
}

.linked-case-card > div {
  min-width: 0;
}

.open-case-button {
  min-width: 108px;
  flex: 0 0 auto;
}

.journey-empty {
  border: 1px dashed var(--border-strong);
  border-radius: 15px;
  padding: 20px;
  background: rgba(16, 27, 41, 0.52);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  text-align: center;
}

.case-heading {
  display: flex;
  min-height: 78px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 20px 10px;
  background: var(--bg);
}

.case-heading h2 {
  margin: 0;
  overflow: hidden;
  font-size: 22px;
  font-weight: 760;
  letter-spacing: -0.025em;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

#tabs {
  position: relative;
  z-index: 10;
  display: flex;
  min-height: 50px;
  flex: 0 0 auto;
  gap: 4px;
  overflow-x: auto;
  padding: 6px 14px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: rgba(16, 27, 41, 0.82);
  scrollbar-width: none;
  -webkit-backdrop-filter: blur(18px) saturate(135%);
  backdrop-filter: blur(18px) saturate(135%);
}

#tabs::-webkit-scrollbar {
  display: none;
}

#tabs button {
  position: relative;
  min-height: 43px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 10px 10px 0 0;
  padding: 10px 13px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 680;
  cursor: pointer;
}

#tabs button::after {
  position: absolute;
  right: 13px;
  bottom: -1px;
  left: 13px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: transparent;
  content: "";
}

#tabs button:hover {
  color: var(--text-soft);
}

#tabs button.active {
  background: rgba(91, 156, 255, 0.07);
  color: var(--text);
}

#tabs button.active::after {
  background: linear-gradient(90deg, var(--capmap-blue-ink), var(--capmap-aqua));
}

.panel {
  display: none;
  min-height: 0;
  flex: 1;
}

.panel.show {
  display: flex;
}

#panelFotos,
#panelClinica,
#panelPdf {
  display: none;
  flex-direction: column;
  overflow: auto;
  padding: 22px;
  background: var(--bg);
}

#panelFotos.show,
#panelClinica.show,
#panelPdf.show {
  display: block;
}

#panel3d {
  flex-direction: column;
}

#layers {
  display: flex;
  min-height: 48px;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
}

#layers:empty {
  display: none;
}

#layers .group {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

#layers .sep {
  width: 1px;
  height: 22px;
  background: var(--border-strong);
}

#layers .lbl {
  color: var(--muted);
  font-size: 11px;
}

#layers .seg {
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 10px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 650;
  cursor: pointer;
}

#layers .seg.active {
  border-color: rgba(91, 156, 255, 0.52);
  background: var(--capmap-blue);
  color: #fff;
}

#layers .seg.off,
#layers .chk.off {
  opacity: 0.42;
}

#layers .chk {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 5px 8px;
  color: var(--text-soft);
  cursor: pointer;
}

#layers .chk:hover:not(.off) {
  border-color: var(--border);
  background: var(--surface-2);
}

#layers .chk.off {
  cursor: default;
}

#layers .chk input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--capmap-blue);
}

#stage {
  display: flex;
  min-height: 0;
  flex: 1;
}

#viewer {
  position: relative;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 44%, rgba(36, 57, 79, 0.4), transparent 56%),
    var(--viewer);
}

#viewer canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#info {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  width: fit-content;
  max-width: calc(100% - 24px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 7px 11px;
  background: rgba(7, 12, 20, 0.72);
  color: var(--text-soft);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

#metrics {
  width: 350px;
  min-height: 0;
  flex: 0 0 auto;
  overflow: auto;
  padding: 17px 17px 28px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12.5px;
  scrollbar-color: var(--surface-3) transparent;
}

#metrics h3,
.panel > h3 {
  margin: 22px 0 9px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.095em;
  text-transform: uppercase;
}

#metrics h3:first-child,
.panel > h3:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

#metrics .row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 4px 0;
}

#metrics .row > span:first-child {
  min-width: 0;
  color: var(--text-soft);
}

#metrics .row .v {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 690;
  text-align: right;
}

#metrics .big .v {
  font-size: 15px;
  letter-spacing: -0.015em;
}

#metrics .green .v,
#metrics .green,
.green {
  color: var(--success);
}

#metrics .red .v {
  color: var(--danger);
}

#metrics .sub,
.meta,
.muted {
  color: var(--muted);
}

#metrics .sub {
  margin-top: 2px;
  font-size: 10.5px;
  line-height: 1.45;
}

#metrics .sub.right {
  text-align: right;
}

#metrics .notes {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 11px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}

#metrics .gline {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 0;
  font-size: 11.5px;
}

#metrics .gline .nm {
  min-width: 0;
  flex: 1;
}

#metrics .gline .a {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

#metrics .gline .w {
  min-width: 61px;
  color: var(--muted-2);
  font-size: 10px;
  text-align: right;
}

#metrics .sw {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

#metrics .sw.degree-0 { background: #ff3030; }
#metrics .sw.degree-1 { background: #ff9400; }
#metrics .sw.degree-2 { background: #ffd600; }
#metrics .sw.degree-3 { background: #4dd963; }
#metrics .sw.region-0 { background: #8c5cf5; }
#metrics .sw.region-1 { background: #21b8d9; }
#metrics .sw.region-2 { background: #ed4fa8; }
#metrics .sw.region-unclassified { background: #a6a6a6; }

#metrics .bar {
  height: 6px;
  margin: 7px 0;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
}

#metrics .bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
}

#metrics .bar i.green {
  background: var(--capmap-green);
}

#metrics .bar i.red {
  background: var(--danger);
}

.coverage-bar {
  display: block;
  width: 100%;
  height: 6px;
  margin: 7px 0;
  overflow: hidden;
  border: 0;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  appearance: none;
  -webkit-appearance: none;
}

.coverage-bar::-webkit-progress-bar {
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
}

.coverage-bar::-webkit-progress-value {
  border-radius: 4px;
  background: var(--capmap-green);
}

.coverage-bar.red::-webkit-progress-value {
  background: var(--danger);
}

.coverage-bar::-moz-progress-bar {
  border-radius: 4px;
  background: var(--capmap-green);
}

.coverage-bar.red::-moz-progress-bar {
  background: var(--danger);
}

.panel > h3 {
  margin-bottom: 12px;
}

.panel h3 .count {
  margin-left: 5px;
  color: var(--muted-2);
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

.grid.poses {
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
}

figure {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
  box-shadow: 0 7px 22px rgba(0, 0, 0, 0.1);
}

figure a {
  display: block;
}

figure img {
  display: block;
  width: 100%;
  height: 205px;
  object-fit: cover;
  background: var(--viewer);
  transition: transform 180ms ease, opacity 180ms ease;
}

figure a:hover img {
  opacity: 0.94;
  transform: scale(1.012);
}

figure figcaption {
  padding: 9px 11px 10px;
  color: var(--text-soft);
  font-size: 11.5px;
  line-height: 1.4;
  word-break: break-word;
}

figure.empty .ph {
  display: flex;
  height: 205px;
  align-items: center;
  justify-content: center;
  background: var(--viewer);
  color: var(--muted-2);
  font-size: 12px;
}

.meta {
  display: block;
  margin-top: 3px;
  font-size: 10px;
}

.meta.q {
  color: var(--muted-2);
}

.pdfhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 9px;
  color: var(--text-soft);
  font-size: 12px;
}

.pdfhead a {
  flex: 0 0 auto;
}

iframe.pdf {
  width: 100%;
  height: min(76vh, 930px);
  margin-bottom: 22px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: #fff;
}

/* ---------------------------------------------------------------- login */

.login-page {
  position: relative;
  display: grid;
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 18% 8%, rgba(14, 95, 216, 0.38), transparent 35%),
    radial-gradient(circle at 89% 88%, rgba(53, 224, 188, 0.16), transparent 31%),
    linear-gradient(155deg, #07111e, #08101a 50%, #06101a);
}

.login-page::before,
.login-page::after {
  position: fixed;
  width: 430px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(53, 224, 188, 0.36), transparent);
  content: "";
  pointer-events: none;
}

.login-page::before {
  top: 22%;
  left: -110px;
  transform: rotate(-17deg);
}

.login-page::after {
  right: -120px;
  bottom: 18%;
  transform: rotate(22deg);
}

.login-shell {
  position: relative;
  z-index: 1;
  width: min(430px, 100%);
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 0 20px;
}

.login-brand .brand-icon {
  width: 58px;
  height: 58px;
  border-radius: 16px;
}

.login-brand .wordmark {
  font-size: 29px;
}

.login-card {
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  padding: 31px 30px 27px;
  background: rgba(16, 27, 41, 0.96);
  box-shadow: var(--shadow);
}

.login-card .eyebrow {
  text-align: center;
}

.login-card h1 {
  margin: 7px 0 8px;
  font-size: 29px;
  font-weight: 760;
  letter-spacing: -0.04em;
  line-height: 1.1;
  text-align: center;
}

.login-intro {
  margin: 0 auto 25px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 680;
}

.password-field {
  position: relative;
}

.password-field input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 11px 13px;
  outline: 0;
  background: #0a1320;
  color: var(--text);
  font-size: 16px;
  letter-spacing: 0.02em;
}

.password-field input:focus {
  border-color: var(--capmap-blue-ink);
  box-shadow: 0 0 0 4px rgba(91, 156, 255, 0.13);
}

.login-submit {
  width: 100%;
  min-height: 48px;
  margin-top: 16px;
  border-radius: 12px;
  background: linear-gradient(100deg, var(--capmap-blue), #1674e7);
  box-shadow: 0 9px 25px rgba(14, 95, 216, 0.27);
  font-size: 14px;
}

.login-submit:hover:not(:disabled) {
  background: linear-gradient(100deg, #1269e4, #2480ed);
}

#err {
  min-height: 19px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.login-footnote {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 18px 0 0;
  color: var(--muted-2);
  font-size: 10.5px;
  text-align: center;
}

.login-footnote::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--capmap-green);
  content: "";
  box-shadow: 0 0 0 3px rgba(29, 158, 117, 0.11);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --capmap-blue-ink: #0e5fd8;
    --capmap-aqua-ink: #007868;
    --bg: #edf3f8;
    --bg-raised: #f5f8fb;
    --surface: #ffffff;
    --surface-2: #f5f8fb;
    --surface-3: #e8eff6;
    --viewer: #0b111b;
    --text: #102033;
    --text-soft: #34475c;
    --muted: #5c6e82;
    --muted-2: #6b7c8f;
    --border: rgba(25, 55, 88, 0.13);
    --border-strong: rgba(25, 55, 88, 0.23);
    --glass: rgba(248, 251, 254, 0.8);
    --danger: #b4232c;
    --warning: #895000;
    --success: #087a5d;
    --focus: #0e5fd8;
    --shadow: 0 20px 65px rgba(31, 53, 78, 0.16);
  }

  #app {
    background:
      radial-gradient(circle at 84% -16%, rgba(14, 95, 216, 0.11), transparent 35%),
      var(--bg);
  }

  .button-sync {
    border-color: rgba(14, 95, 216, 0.28);
    background: rgba(14, 95, 216, 0.08);
    color: #0b4f9f;
  }

  .button-sync:hover:not(:disabled) {
    border-color: rgba(14, 95, 216, 0.46);
    background: rgba(14, 95, 216, 0.13);
  }

  .case-card.active,
  .case-card[aria-current="true"] {
    border-color: rgba(14, 95, 216, 0.24);
    background: linear-gradient(135deg, rgba(14, 95, 216, 0.13), rgba(14, 95, 216, 0.055));
  }

  #viewer {
    color-scheme: dark;
  }

  #info {
    color: #dbe7f5;
  }

  #tabs,
  .patient-summary-heading {
    background: rgba(255, 255, 255, 0.82);
  }

  #warn {
    color: #704300;
  }

  .coverage-bar,
  .coverage-bar::-webkit-progress-bar {
    background: rgba(16, 32, 51, 0.1);
  }

  .login-page {
    background:
      radial-gradient(circle at 18% 8%, rgba(14, 95, 216, 0.17), transparent 36%),
      radial-gradient(circle at 89% 88%, rgba(53, 224, 188, 0.15), transparent 32%),
      linear-gradient(155deg, #eef5fb, #f8fbfd 50%, #edf6f4);
  }

  .login-card {
    background: rgba(255, 255, 255, 0.96);
  }

  .password-field input {
    background: #f7f9fc;
  }
}

@media (max-width: 1120px) {
  #side {
    width: 285px;
  }

  #metrics {
    width: 315px;
  }

  .patient-stat-grid,
  .patient-facts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .portal-page {
    overflow: auto;
  }

  #app {
    height: auto;
    min-height: 100vh;
    min-height: 100svh;
  }

  .portal-page main {
    min-height: 0;
    flex-direction: column;
  }

  #side {
    width: 100%;
    max-height: min(390px, 50svh);
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  #caseList {
    min-height: 110px;
  }

  #content {
    min-height: 690px;
  }

  .case-workspace {
    min-height: 690px;
  }

  .patient-summary {
    min-height: 620px;
  }

  .empty-selection {
    min-height: 500px;
  }
}

@media (max-width: 690px) {
  .topbar {
    min-height: 62px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .wordmark {
    font-size: 18px;
  }

  .brand-context {
    display: none;
  }

  .read-only-pill {
    display: none;
  }

  #status {
    padding-right: 14px;
    padding-left: 14px;
  }

  #warn {
    margin-right: 12px;
    margin-left: 12px;
  }

  #stage {
    flex-direction: column;
  }

  #viewer {
    min-height: 48svh;
  }

  #metrics {
    width: 100%;
    max-height: none;
    overflow: visible;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  #layers {
    align-items: flex-start;
    gap: 8px;
    padding: 9px 10px;
  }

  #layers .sep {
    display: none;
  }

  #layers .group {
    width: 100%;
  }

  #layers .chk,
  #layers .seg {
    min-height: 40px;
  }

  .case-heading {
    min-height: 74px;
    padding-right: 15px;
    padding-left: 15px;
  }

  .patient-summary-heading {
    min-height: 90px;
    padding: 15px;
  }

  .patient-summary-heading .read-only-pill {
    display: none;
  }

  .patient-summary-body {
    padding: 18px 12px 26px;
  }

  .patient-stat-grid,
  .patient-facts {
    grid-template-columns: 1fr 1fr;
  }

  .patient-stat {
    min-height: 94px;
    padding: 13px;
  }

  .linked-case-card {
    align-items: stretch;
    flex-direction: column;
  }

  .open-case-button {
    width: 100%;
  }

  .case-heading h2 {
    font-size: 19px;
  }

  #tabs {
    padding-left: 8px;
  }

  #tabs button {
    min-height: 46px;
  }

  #panelFotos,
  #panelClinica,
  #panelPdf {
    padding: 16px 12px 24px;
  }

  .grid,
  .grid.poses {
    grid-template-columns: 1fr;
  }

  figure img,
  figure.empty .ph {
    height: min(72vw, 330px);
  }

  .pdfhead {
    align-items: flex-start;
    flex-direction: column;
  }

  iframe.pdf {
    height: 68vh;
  }

  .login-card {
    padding: 27px 21px 23px;
  }
}

@media (max-width: 380px) {
  .topbar-actions {
    gap: 6px;
  }

  .button-quiet {
    min-width: 44px;
    padding-right: 10px;
    padding-left: 10px;
  }

  #side {
    padding-right: 10px;
    padding-left: 10px;
  }

  .side-heading h1 {
    font-size: 18px;
  }

  .patient-stat-grid,
  .patient-facts {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .topbar,
  #tabs,
  .patient-summary-heading,
  #info {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .topbar,
  #tabs,
  .patient-summary-heading {
    background: var(--surface);
  }
}

@media (prefers-contrast: more) {
  :root {
    --border: rgba(224, 236, 250, 0.32);
    --border-strong: rgba(224, 236, 250, 0.56);
    --muted: #b5c2d2;
    --muted-2: #9aabc0;
  }
}

@media (forced-colors: active) {
  .read-only-pill,
  .badge,
  .case-card.active,
  .button-sync {
    border: 1px solid CanvasText;
  }
}
