:root {
  --apollo-blue: #0057a7;
  --apollo-deep: #073b72;
  --apollo-sky: #1ba7e1;
  --apollo-aqua: #27b7c9;
  --apollo-gold: #d8a92f;
  --apollo-green: #1b9c85;
  --apollo-coral: #e36f59;
  --apollo-violet: #7c6ee6;
  --ink: #12213a;
  --muted: #617089;
  --line: #dce6f2;
  --soft: #f4f8fc;
  --white: #ffffff;
  --shadow: 0 18px 45px rgba(7, 59, 114, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(0, 87, 167, 0.06), rgba(39, 183, 201, 0.06) 38%, rgba(255, 255, 255, 0) 70%),
    #f7fafd;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 22px 18px;
  background: linear-gradient(180deg, var(--white), #eef9f8 58%, #eef7ff);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-logo {
  width: 104px;
  height: 50px;
  object-fit: contain;
  border: 1px solid rgba(0, 87, 167, 0.16);
  border-radius: 8px;
  background: var(--white);
  box-shadow: 0 10px 24px rgba(0, 87, 167, 0.14);
}

.brand h1,
.topbar h2 {
  margin: 0;
  color: var(--apollo-deep);
  line-height: 1.1;
}

.brand h1 {
  font-size: 1.35rem;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--apollo-blue);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav-tabs {
  display: grid;
  gap: 7px;
  margin-bottom: 20px;
}

.nav-tab {
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-weight: 700;
}

.nav-tab:hover,
.nav-tab.active {
  color: var(--apollo-deep);
  background: var(--white);
  border-color: var(--line);
  box-shadow: 0 8px 18px rgba(7, 59, 114, 0.08);
}

.filter-panel {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.filter-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 0.82rem;
  font-weight: 900;
  color: var(--apollo-deep);
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--apollo-blue);
  background: var(--white);
  font-weight: 900;
}

.filter-grid {
  display: grid;
  gap: 12px;
}

.filter-control {
  display: grid;
  gap: 6px;
}

.filter-control label,
.compact-select span,
.role-select span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.filter-control select,
.filter-control input,
.multi-summary,
.compact-select select,
.role-select select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--white);
  outline: none;
}

.filter-control input[type="number"] {
  min-width: 0;
}

.range-row,
.date-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.sidebar .range-row,
.sidebar .date-row {
  grid-template-columns: 1fr;
}

.multi-select {
  position: relative;
}

.multi-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  cursor: pointer;
}

.multi-summary::-webkit-details-marker {
  display: none;
}

.multi-summary::after {
  content: "v";
  color: var(--apollo-blue);
  font-size: 0.72rem;
  font-weight: 900;
}

.multi-options {
  display: grid;
  gap: 7px;
  margin-top: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: 0 12px 24px rgba(7, 59, 114, 0.1);
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 750;
  line-height: 1.25;
}

.check-row input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  accent-color: var(--apollo-blue);
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
  border: 1px solid rgba(0, 87, 167, 0.12);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.97), rgba(239, 248, 255, 0.97)),
    var(--white);
  box-shadow: var(--shadow);
}

.topbar h2 {
  max-width: 780px;
  font-size: clamp(1.35rem, 2.6vw, 2.35rem);
}

.status-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--apollo-deep);
  background: var(--white);
  font-size: 0.78rem;
  font-weight: 800;
}

.pill.success {
  color: #0f765f;
  border-color: rgba(27, 156, 133, 0.26);
  background: rgba(27, 156, 133, 0.08);
}

.pill.warn {
  color: #9d6b06;
  border-color: rgba(216, 169, 47, 0.35);
  background: rgba(216, 169, 47, 0.1);
}

.topbar-actions,
.upload-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.role-select,
.compact-select {
  display: grid;
  min-width: 144px;
  gap: 4px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--white);
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--apollo-blue);
}

.action-button {
  min-width: 76px;
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid var(--apollo-blue);
  border-radius: var(--radius);
  color: var(--white);
  background: linear-gradient(135deg, var(--apollo-blue), var(--apollo-sky));
  font-weight: 900;
  box-shadow: 0 10px 20px rgba(0, 87, 167, 0.18);
}

.action-button.secondary {
  color: var(--apollo-blue);
  background: var(--white);
  box-shadow: none;
}

.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--apollo-blue);
  background: var(--white);
  font-weight: 900;
  text-decoration: none;
}

.upload-strip {
  justify-content: space-between;
  margin-top: 18px;
  padding: 16px 18px;
  border: 1px dashed rgba(0, 87, 167, 0.35);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
}

.file-drop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 190px;
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid rgba(0, 87, 167, 0.32);
  border-radius: var(--radius);
  color: var(--apollo-blue);
  background: #f8fcff;
  font-weight: 900;
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.kpi-card {
  min-height: 122px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: 0 12px 28px rgba(7, 59, 114, 0.08);
}

.kpi-card .label {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.kpi-card .value {
  margin: 10px 0 6px;
  color: var(--apollo-deep);
  font-size: clamp(1.28rem, 2vw, 1.85rem);
  font-weight: 900;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.kpi-card .delta {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.kpi-card.accent-blue {
  background: linear-gradient(135deg, #ffffff, #eef8ff);
}

.kpi-card.accent-green {
  background: linear-gradient(135deg, #ffffff, #ecfbf7);
}

.kpi-card.accent-gold {
  background: linear-gradient(135deg, #ffffff, #fff9e8);
}

.kpi-card.accent-coral {
  background: linear-gradient(135deg, #ffffff, #fff1ee);
}

.page {
  display: none;
  margin-top: 18px;
}

.page.active {
  display: block;
}

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

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 30px rgba(7, 59, 114, 0.07);
}

.panel.span-3 { grid-column: span 3; }
.panel.span-4 { grid-column: span 4; }
.panel.span-5 { grid-column: span 5; }
.panel.span-6 { grid-column: span 6; }
.panel.span-7 { grid-column: span 7; }
.panel.span-8 { grid-column: span 8; }
.panel.span-9 { grid-column: span 9; }
.panel.span-12 { grid-column: span 12; }

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel h3 {
  margin: 0;
  color: var(--apollo-deep);
  font-size: 1rem;
  line-height: 1.25;
}

.panel small {
  color: var(--muted);
  font-weight: 700;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.doctor-summary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mini-metric {
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
}

.mini-metric span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.mini-metric strong {
  display: block;
  margin-top: 8px;
  color: var(--apollo-deep);
  font-size: 1.2rem;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.chart {
  width: 100%;
  min-height: 270px;
}

.matrix-chart {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 6px;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart.compact {
  min-height: 205px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  background: var(--white);
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  font-size: 0.86rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--apollo-deep);
  background: #f2f8fe;
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #f7fbff;
}

.drill-link {
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--apollo-blue);
  background: var(--white);
  font-weight: 900;
}

.data-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.mapping-list {
  display: grid;
  gap: 8px;
}

.mapping-row {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 74px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
  font-size: 0.82rem;
}

.mapping-row strong {
  color: var(--apollo-deep);
}

.confidence {
  display: inline-grid;
  min-height: 26px;
  place-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--white);
  background: var(--apollo-green);
  font-size: 0.72rem;
  font-weight: 900;
}

.confidence.low {
  background: var(--apollo-gold);
}

.db-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.db-status {
  margin-bottom: 12px;
}

.edit-table table {
  min-width: 1180px;
}

.edit-input {
  width: 100%;
  min-width: 120px;
  min-height: 34px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #fbfdff;
}

.edit-input:focus {
  border-color: var(--apollo-blue);
  outline: 2px solid rgba(0, 87, 167, 0.12);
}

.upload-log {
  display: grid;
  gap: 8px;
  max-height: 330px;
  overflow: auto;
}

.log-entry {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--apollo-blue);
  border-radius: var(--radius);
  background: var(--white);
}

.log-entry strong {
  display: block;
  color: var(--apollo-deep);
}

.log-entry span {
  color: var(--muted);
  font-size: 0.83rem;
}

.heat-cell {
  outline: 1px solid rgba(255, 255, 255, 0.88);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(380px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--apollo-deep);
  background: var(--white);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
  font-weight: 800;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.empty-state {
  display: grid;
  min-height: 200px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: #fbfdff;
  font-weight: 800;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .nav-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .filter-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

@media (max-width: 860px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .upload-strip {
    display: grid;
    justify-content: stretch;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .nav-tabs,
  .filter-grid,
  .data-columns,
  .metric-row,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .panel.span-3,
  .panel.span-4,
  .panel.span-5,
  .panel.span-6,
  .panel.span-7,
  .panel.span-8,
  .panel.span-9,
  .panel.span-12 {
    grid-column: span 12;
  }

  .chart {
    min-height: 220px;
  }
}

@media print {
  body {
    background: var(--white);
  }

  .sidebar,
  .upload-strip,
  .topbar-actions,
  .toast {
    display: none;
  }

  .app-shell {
    display: block;
  }

  .main {
    padding: 0;
  }

  .topbar,
  .panel,
  .kpi-card {
    box-shadow: none;
    break-inside: avoid;
  }
}
