:root {
  color-scheme: light;
  --navy-950: #071426;
  --navy-900: #0b2039;
  --navy-800: #123657;
  --ink: #14243a;
  --muted: #657489;
  --muted-2: #8b98a8;
  --bg: #edf2f6;
  --surface: #ffffff;
  --surface-soft: #f6f9fb;
  --line: #dbe4eb;
  --line-strong: #c8d4de;
  --teal: #0b9c89;
  --teal-bright: #42e1c0;
  --teal-soft: #ddf6f0;
  --cyan: #278fbe;
  --cyan-soft: #e2f2fa;
  --amber: #d78a2f;
  --amber-soft: #fff1d9;
  --rose: #c95162;
  --shadow: 0 10px 28px rgba(11, 32, 57, .07);
  --radius: 15px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

button, input, select { font: inherit; }
button, summary, select, input[type="checkbox"] { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(39, 143, 190, .25);
  outline-offset: 2px;
}
h1, h2, h3, p { margin: 0; }
h1 { color: #fff; font-size: clamp(1.25rem, 2vw, 1.55rem); line-height: 1.1; letter-spacing: -.025em; }
h2 { font-size: clamp(1.25rem, 2vw, 1.75rem); line-height: 1.2; letter-spacing: -.025em; }
h3 { font-size: 1rem; line-height: 1.25; }
code { padding: 1px 5px; border-radius: 5px; background: rgba(7, 20, 38, .08); font-size: .85em; }

.eyebrow {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: .69rem;
  font-weight: 850;
  letter-spacing: .12em;
}

.topbar {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 76px;
  padding: 13px clamp(18px, 3vw, 44px);
  background:
    radial-gradient(circle at 78% -40%, rgba(66, 225, 192, .22), transparent 31%),
    linear-gradient(112deg, var(--navy-950), var(--navy-800));
  box-shadow: 0 3px 16px rgba(4, 17, 35, .18);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  display: grid;
  place-items: center;
  width: 72px;
  height: 50px;
  padding: 4px 7px;
  overflow: hidden;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 5px 14px rgba(0, 0, 0, .14);
}
.brand-logo img { display: block; width: 100%; height: 100%; object-fit: contain; }
.brand p { margin-bottom: 2px; color: #8fc7d9; font-size: .67rem; font-weight: 850; letter-spacing: .14em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-actions form { margin: 0; }
.privacy-state { display: inline-flex; align-items: center; gap: 8px; color: #d9e8f1; font-size: .82rem; }
.privacy-state i { width: 8px; height: 8px; border-radius: 50%; background: var(--teal-bright); box-shadow: 0 0 0 4px rgba(66, 225, 192, .13); }
.export-scope { display: grid; gap: 2px; color: #bcd3df; font-size: .64rem; font-weight: 760; letter-spacing: .035em; text-transform: uppercase; }
.export-scope select { min-width: 155px; min-height: 34px; padding-block: 4px; border-color: rgba(255, 255, 255, .24); background: rgba(255, 255, 255, .1); color: #fff; font-size: .76rem; font-weight: 720; text-transform: none; }
.export-scope option { color: var(--ink); background: #fff; }
.export-status { position: absolute; right: clamp(18px, 3vw, 44px); bottom: 2px; color: #bcd3df; font-size: .67rem; }

.button {
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: .84rem;
  font-weight: 780;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .62; transform: none; }
.button-quiet { border-color: rgba(255, 255, 255, .24); background: rgba(255, 255, 255, .08); color: #fff; }
.button-primary { background: var(--navy-900); color: #fff; }
.text-button { padding: 5px; border: 0; background: transparent; color: var(--cyan); font-size: .78rem; font-weight: 800; }

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: calc(100vh - 76px);
}
.filters-panel {
  position: sticky;
  top: 76px;
  align-self: start;
  height: calc(100vh - 76px);
  overflow-y: auto;
  padding: 22px 20px 28px;
  border-right: 1px solid var(--line);
  background: #f9fbfc;
  scrollbar-width: thin;
}
.filters-heading { display: flex; align-items: end; justify-content: space-between; gap: 15px; padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.filters-heading h2 { font-size: 1.12rem; }
.filter-section { padding: 17px 0; border-bottom: 1px solid var(--line); }
.filter-section h3 { margin-bottom: 11px; color: var(--muted); font-size: .76rem; letter-spacing: .045em; text-transform: uppercase; }
.date-grid, .age-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.date-grid label, .age-grid label, .analysis-controls label { display: grid; gap: 5px; min-width: 0; color: var(--muted); font-size: .74rem; font-weight: 760; }
input, select {
  width: 100%;
  min-height: 39px;
  padding: 7px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font-size: .83rem;
}
input:hover, select:hover { border-color: #9fb3c4; }
.field-help { margin-top: 8px; color: var(--muted-2); font-size: .68rem; line-height: 1.4; }
.dimension-filters { padding: 8px 0 14px; }
.filter-disclosure { margin-top: 7px; }
.filter-disclosure > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  list-style: none;
  font-size: .81rem;
  font-weight: 720;
}
.filter-disclosure > summary::-webkit-details-marker { display: none; }
.filter-disclosure > summary::after { content: "+"; color: var(--muted-2); font-size: 1rem; }
.filter-disclosure[open] > summary { border-color: var(--cyan); border-radius: 9px 9px 0 0; }
.filter-disclosure[open] > summary::after { content: "−"; }
.selection-count { margin-left: auto; padding: 2px 6px; border-radius: 20px; background: var(--surface-soft); color: var(--muted-2); font-size: .67rem; font-weight: 800; }
.selection-count.selected { background: var(--cyan-soft); color: #176b88; }
.multi-select { min-height: 105px; border-color: var(--cyan); border-top: 0; border-radius: 0 0 9px 9px; }
.filter-disclosure .field-help { margin: 5px 2px 10px; }
.apply-button { position: sticky; bottom: 12px; width: 100%; margin-top: 5px; box-shadow: 0 8px 22px rgba(7, 20, 38, .15); }
.dataset-note { margin-top: 11px; color: var(--muted-2); font-size: .69rem; line-height: 1.35; text-align: center; }

.workspace { min-width: 0; padding: 26px clamp(18px, 2.7vw, 44px) 42px; }
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding: 23px 27px;
  overflow: hidden;
  border-radius: 18px;
  background:
    radial-gradient(circle at 90% 15%, rgba(66, 225, 192, .22), transparent 25%),
    linear-gradient(115deg, #0b2039 0%, #123b5d 72%, #15556a 100%);
  color: #fff;
  box-shadow: 0 14px 36px rgba(7, 20, 38, .16);
}
.hero .eyebrow { color: #7bd9c8; }
.hero h2 { max-width: 760px; }
.hero p:last-child { max-width: 760px; margin-top: 8px; color: #c4d7e4; font-size: .84rem; }
.hero-count { flex: 0 0 auto; min-width: 190px; padding-left: 25px; border-left: 1px solid rgba(255, 255, 255, .22); text-align: right; }
.hero-count span { display: block; font-size: clamp(2.3rem, 4vw, 3.4rem); font-weight: 880; line-height: 1; letter-spacing: -.055em; font-variant-numeric: tabular-nums; }
.hero-count small { display: block; margin-top: 7px; color: #b9d6e1; font-size: .72rem; }

.tabs { display: flex; gap: 4px; margin-top: 21px; padding: 5px; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, .74); }
.tab { flex: 0 0 auto; min-width: 115px; padding: 9px 15px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: .82rem; font-weight: 790; }
.tab:hover { background: var(--surface-soft); color: var(--ink); }
.tab.active { background: var(--navy-900); color: #fff; box-shadow: 0 5px 14px rgba(11, 32, 57, .17); }
.status-line { min-height: 33px; padding: 10px 2px 7px; color: var(--muted-2); font-size: .72rem; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tab-customizer {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid #c9dde6;
  border-radius: 13px;
  background: linear-gradient(110deg, #f7fbfc, #eef7fa);
}
.tab-customizer h3 { font-size: .9rem; }
.tab-filter-controls { display: flex; align-items: end; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.tab-filter-controls label { display: grid; gap: 4px; min-width: 165px; color: var(--muted); font-size: .69rem; font-weight: 760; }
.tab-filter-controls select { max-width: 245px; }
.tab-filter-reset { align-self: center; margin-top: 17px; }

.kpi-grid, .quality-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 11px; margin-bottom: 16px; }
#patient-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.quality-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 0; }
.kpi-card {
  min-width: 0;
  min-height: 122px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.kpi-label { display: block; min-height: 30px; color: var(--muted); font-size: .75rem; font-weight: 760; }
.kpi-value { display: block; margin: 8px 0 6px; overflow: hidden; font-size: clamp(1.45rem, 2.3vw, 2.1rem); line-height: 1; letter-spacing: -.045em; font-variant-numeric: tabular-nums; text-overflow: ellipsis; }
.kpi-note { display: block; color: var(--muted-2); font-size: .66rem; line-height: 1.3; }
.kpi-card.primary { border-color: transparent; background: linear-gradient(145deg, var(--navy-950), var(--navy-800)); color: #fff; }
.kpi-card.primary .kpi-label, .kpi-card.primary .kpi-note { color: #c8ddea; }
.kpi-card.accent { border-top: 3px solid var(--teal); }
.kpi-card.warning { border-top: 3px solid var(--amber); }

.panel { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.panel-heading { margin-bottom: 17px; }
.panel-heading h3 { font-size: 1.02rem; }
.split-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; }
.analysis-panel { margin-bottom: 16px; }
.analysis-controls { display: grid; grid-template-columns: repeat(3, minmax(120px, 160px)); gap: 8px; }
.explorer-controls { display: grid; grid-template-columns: repeat(5, minmax(135px, 1fr)); gap: 8px; width: min(100%, 860px); }
.explorer-controls label { display: grid; gap: 5px; min-width: 0; color: var(--muted); font-size: .71rem; font-weight: 760; }
.explorer-summary { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: -2px 0 18px; padding: 12px 14px; border-radius: 10px; background: var(--surface-soft); color: var(--muted); font-size: .76rem; }
.explorer-total { color: var(--ink); font-weight: 820; }
.explorer-bars { max-width: 980px; }
.ranked-bars { display: grid; gap: 11px; }
.bar-row { display: grid; grid-template-columns: 27px minmax(0, 1fr); align-items: center; gap: 10px; }
.bar-rank { color: var(--muted-2); font-size: .67rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin-bottom: 5px; }
.bar-label { overflow: hidden; font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.bar-value { flex: 0 0 auto; font-size: .75rem; font-variant-numeric: tabular-nums; }
.bar-track { height: 9px; overflow: hidden; border-radius: 99px; background: #edf2f5; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--cyan), var(--teal)); transform-origin: left; animation: grow .32s ease-out both; }
.empty-state { padding: 27px 10px; color: var(--muted); text-align: center; font-size: .8rem; }

.trend-chart { min-height: 230px; overflow-x: auto; overflow-y: hidden; }
.trend-bars { display: flex; align-items: end; gap: 5px; min-width: 720px; height: 230px; padding: 29px 3px 24px; border-bottom: 1px solid var(--line); }
.trend-column { position: relative; display: flex; flex: 1 1 0; align-items: center; justify-content: end; flex-direction: column; min-width: 10px; height: 100%; }
.trend-value { position: absolute; top: -23px; display: none; padding: 2px 5px; border-radius: 5px; background: var(--navy-950); color: #fff; font-size: .62rem; white-space: nowrap; }
.trend-column:hover .trend-value { display: block; }
.trend-bar { width: min(18px, 76%); min-height: 3px; border-radius: 5px 5px 1px 1px; background: linear-gradient(180deg, var(--teal-bright), var(--cyan)); transform-origin: bottom; animation: rise .35s ease-out both; }
.trend-label { position: absolute; bottom: -20px; color: var(--muted-2); font-size: .54rem; transform: rotate(-48deg); transform-origin: center; white-space: nowrap; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin: 25px 2px 13px; }
.section-heading > p { color: var(--muted); font-size: .76rem; }
.breakdown-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.mini-panel { min-height: 260px; }
.mini-panel:nth-child(n+3) { margin-top: 0; }
.compact-bars { gap: 9px; }
.compact-bars .bar-row:nth-child(n+11) { display: none; }
.compact-panel { margin-top: 16px; }
.compact-panel .kpi-card { min-height: 103px; box-shadow: none; }

.dashboard-grid { display: grid; gap: 16px; }
.dashboard-grid.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dashboard-grid .panel { margin-top: 0; }
.dashboard-grid.asymmetric { grid-template-columns: minmax(310px, .7fr) minmax(500px, 1.3fr); }
.patient-detail-grid { margin-top: 16px; }
.patient-detail-grid .panel { min-height: 310px; }
.panel-footnote { margin-top: 17px; padding-top: 13px; border-top: 1px solid var(--line); color: var(--muted-2); font-size: .69rem; line-height: 1.45; }
.information-banner { display: flex; align-items: center; gap: 13px; margin-bottom: 16px; padding: 13px 16px; border: 1px solid #bcdfe8; border-radius: 11px; background: #eefafd; color: #24566c; font-size: .78rem; }
.information-banner strong { flex: 0 0 auto; color: #176b88; }

.table-panel { min-width: 0; }
.table-wrap { max-height: 560px; overflow: auto; }
.pivot-wrap { max-height: 620px; border: 1px solid var(--line); border-radius: 11px; }
.pivot-table { min-width: 860px; }
.pivot-table th { max-width: 160px; white-space: normal; }
.pivot-table th:first-child, .pivot-table td:first-child { position: sticky; z-index: 2; left: 0; min-width: 180px; background: #fff; text-align: left; }
.pivot-table thead th:first-child { z-index: 3; }
.pivot-value, .pivot-total { text-align: right; font-weight: 760; font-variant-numeric: tabular-nums; }
.pivot-total { background: var(--surface-soft); }
table { width: 100%; border-collapse: collapse; font-size: .76rem; }
th { position: sticky; z-index: 1; top: 0; padding: 9px 8px; border-bottom: 1px solid var(--line-strong); background: #fff; color: var(--muted); text-align: left; font-size: .65rem; letter-spacing: .04em; text-transform: uppercase; }
td { max-width: 260px; padding: 10px 8px; border-bottom: 1px solid #edf1f4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
th.numeric, td.numeric, th:nth-child(n+3), td:nth-child(n+3) { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-soft); }
.category-badge { display: inline-flex; max-width: 220px; padding: 4px 8px; overflow: hidden; border: 1px solid hsl(var(--badge-hue) 38% 76%); border-radius: 99px; background: hsl(var(--badge-hue) 55% 94%); color: hsl(var(--badge-hue) 45% 27%); font-size: .68rem; font-weight: 780; text-overflow: ellipsis; white-space: nowrap; }
.loading-block { display: grid; gap: 9px; padding: 15px; }
.loading-block span { height: 12px; border-radius: 5px; background: var(--line); }
.loading .panel, .loading .kpi-card { opacity: .62; }
.loading #apply-button::after { content: "…"; }

@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes rise { from { transform: scaleY(0); } to { transform: scaleY(1); } }

@media (max-width: 1380px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #patient-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .quality-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 1080px) {
  .topbar { position: relative; }
  .app-shell { grid-template-columns: 1fr; }
  .filters-panel { position: relative; top: 0; width: 100%; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .dimension-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
  .filter-disclosure { margin-top: 0; }
  .apply-button { position: static; }
  .dashboard-grid.asymmetric { grid-template-columns: 1fr; }
  .explorer-controls { grid-template-columns: repeat(3, minmax(140px, 1fr)); width: 100%; }
  .tab-customizer { align-items: stretch; flex-direction: column; }
  .tab-filter-controls { justify-content: flex-start; }
}

@media (max-width: 780px) {
  .topbar, .topbar-actions, .hero, .split-heading, .section-heading { align-items: stretch; flex-direction: column; }
  .topbar-actions { width: 100%; }
  .privacy-state { margin-bottom: 3px; }
  .export-scope { width: 100%; }
  .export-scope select { max-width: none; }
  .export-status { position: static; }
  .hero-count { min-width: 0; padding: 16px 0 0; border-top: 1px solid rgba(255, 255, 255, .22); border-left: 0; text-align: left; }
  .analysis-controls { grid-template-columns: 1fr; }
  .explorer-controls { grid-template-columns: 1fr 1fr; }
  .dimension-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid.two-columns, .breakdown-grid { grid-template-columns: 1fr; }
  .quality-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #patient-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .information-banner { align-items: flex-start; flex-direction: column; }
  .tab-filter-controls { display: grid; grid-template-columns: 1fr 1fr; }
  .tab-filter-controls label, .tab-filter-controls select { width: 100%; max-width: none; }
}

@media (max-width: 480px) {
  .date-grid, .age-grid, .dimension-filters, .kpi-grid, .quality-grid { grid-template-columns: 1fr; }
  .filters-panel, .workspace { padding-inline: 14px; }
  .hero { padding: 20px; }
  #patient-kpis { grid-template-columns: 1fr; }
  .explorer-controls { grid-template-columns: 1fr; }
  .tab-filter-controls { grid-template-columns: 1fr; }
  .tabs { border-radius: 10px; }
  .tab { min-width: 100px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
