:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef3f4;
  --text: #1f2933;
  --muted: #667085;
  --line: #d9e2e7;
  --primary: #006d77;
  --primary-dark: #07545d;
  --accent: #bc6c25;
  --danger: #9d174d;
  --warning: #b54708;
  --success: #2d6a4f;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: var(--primary);
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0 20px;
  border-bottom: 1px solid var(--line);
}

.app-kicker {
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 2vw, 2rem);
  font-weight: 750;
}

h2 {
  font-size: 1rem;
  font-weight: 730;
}

h3 {
  font-size: 0.94rem;
  font-weight: 730;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 0.82rem;
  font-weight: 650;
}

.search-band,
.content-band,
.orders-strip,
.charts-section,
.table-section {
  margin-top: 20px;
}

.search-band,
.content-band,
.table-section,
.charts-section,
.orders-strip {
  border-bottom: 1px solid var(--line);
  padding: 18px 0;
}

.search-form {
  max-width: 760px;
}

.search-form.is-code-only {
  max-width: 560px;
}

.quick-searches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.quick-searches a,
.quick-searches span,
.chart-filter {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 10px;
  background: var(--surface);
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 650;
  text-decoration: none;
}

.btn-primary {
  --bs-btn-bg: var(--primary);
  --bs-btn-border-color: var(--primary);
  --bs-btn-hover-bg: var(--primary-dark);
  --bs-btn-hover-border-color: var(--primary-dark);
}

.btn-outline-primary {
  --bs-btn-color: var(--primary);
  --bs-btn-border-color: var(--primary);
  --bs-btn-hover-bg: var(--primary);
  --bs-btn-hover-border-color: var(--primary);
}

.empty-state {
  padding: 28px 8px;
  color: var(--muted);
}

.empty-state h2 {
  color: var(--text);
  margin-bottom: 6px;
}

.section-heading,
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.section-heading span,
.table-toolbar span {
  color: var(--muted);
  font-size: 0.86rem;
}

.patient-list {
  display: grid;
  gap: 10px;
}

.patient-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.patient-row div {
  display: grid;
  gap: 4px;
}

.patient-row div:last-child {
  justify-items: end;
  align-content: center;
}

.patient-row span {
  color: var(--muted);
  font-size: 0.88rem;
}

.patient-row small {
  color: var(--muted);
  font-size: 0.78rem;
}

.content-band.is-loading {
  opacity: 0.72;
}

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

.patient-summary div,
.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.patient-summary span,
.metric-card span,
.metric-card em {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-style: normal;
}

.patient-summary strong {
  display: block;
  margin-top: 3px;
  font-size: 0.94rem;
}

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

.overview-strip article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfd;
}

.overview-strip span,
.overview-strip strong {
  display: block;
}

.overview-strip span {
  color: var(--muted);
  font-size: 0.78rem;
}

.overview-strip strong {
  margin-top: 4px;
  font-size: 1.05rem;
}

.overview-strip .has-alert {
  border-color: rgba(180, 35, 24, 0.4);
  background: #fff8f6;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(105px, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.metric-card strong {
  display: block;
  margin: 4px 0;
  font-size: 1.1rem;
}

.metric-card small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.metric-card-high,
.metric-card-low {
  border-color: rgba(180, 35, 24, 0.34);
  background: #fff8f6;
}

.metric-card-normal {
  border-color: rgba(45, 106, 79, 0.25);
}

.insight-panel {
  margin-top: 20px;
  border-bottom: 1px solid var(--line);
  padding: 18px 0;
}

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

.insight-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfd;
}

.insight-item div {
  display: grid;
  gap: 3px;
}

.insight-item div:last-child {
  text-align: right;
}

.insight-item span {
  color: var(--muted);
  font-size: 0.8rem;
}

.insight-high,
.insight-low {
  border-color: rgba(180, 35, 24, 0.4);
  background: #fff8f6;
}

.orders-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.order-chip {
  display: block;
  min-width: 170px;
  border: 1px solid var(--line);
  background: #fbfcfd;
  border-radius: var(--radius);
  padding: 10px;
  color: var(--text);
  text-align: left;
  text-decoration: none;
}

.order-chip strong,
.order-chip span,
.order-chip small {
  display: block;
}

.order-chip span,
.order-chip small {
  color: var(--muted);
  font-size: 0.78rem;
}

.order-chip.is-active {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.order-chip:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.order-chip.is-unloaded {
  background: #f2f4f7;
}

.order-chip.is-muted {
  min-width: 90px;
  text-align: center;
}

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

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chart-filter {
  color: var(--text);
  cursor: pointer;
}

.chart-filter.is-active {
  border-color: var(--primary);
  background: #e6f4f1;
  color: var(--primary-dark);
}

.chart-card {
  min-height: 300px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfd;
}

.chart-card-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.chart-card-header span {
  color: var(--muted);
  font-size: 0.78rem;
}

.chart-trend {
  min-width: 116px;
  text-align: right;
}

.chart-trend strong,
.chart-trend span {
  display: block;
}

.chart-trend strong {
  font-size: 0.98rem;
}

.chart-trend.status-high strong,
.chart-trend.status-low strong {
  color: #b42318;
}

.chart-canvas {
  height: 240px;
}

.chart-card canvas {
  width: 100%;
  min-height: 100%;
}

.toolbar-controls {
  display: flex;
  gap: 8px;
  min-width: min(460px, 100%);
}

.result-table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.result-table {
  margin-bottom: 0;
}

.result-table thead th {
  background: var(--surface-soft);
  color: #344054;
  font-size: 0.78rem;
  text-transform: uppercase;
  white-space: nowrap;
}

.result-table td {
  font-size: 0.88rem;
}

.result-table td span {
  color: var(--muted);
}

.loading-line {
  color: var(--muted);
  padding: 16px;
}

@media (max-width: 980px) {
  .patient-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .overview-strip,
  .insight-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 12px;
  }

  .app-topbar,
  .patient-row,
  .section-heading,
  .table-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .patient-row div:last-child {
    justify-items: start;
  }

  .patient-summary,
  .metric-grid,
  .overview-strip,
  .insight-list {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar-controls {
    flex-direction: column;
    min-width: 100%;
  }
}
