:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f9faf7;
  --ink: #20211f;
  --muted: #676b62;
  --line: #d8ddd2;
  --teal: #167a78;
  --teal-dark: #0d5f5d;
  --teal-soft: #dcefed;
  --amber: #a86f16;
  --amber-soft: #f7ead3;
  --red: #ad3b31;
  --red-soft: #f6ded9;
  --green: #487c38;
  --green-soft: #e4f0df;
  --gray-soft: #eef0eb;
  --shadow: 0 18px 44px rgba(46, 50, 43, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

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

button,
select,
input,
textarea {
  font: inherit;
}

input,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

textarea {
  min-height: 84px;
  resize: vertical;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 22px clamp(16px, 4vw, 44px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.12;
}

h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.run-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 760px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.good {
  background: var(--green-soft);
  border-color: #bdd7b2;
  color: var(--green);
}

.pill.warn {
  background: var(--amber-soft);
  border-color: #e3c387;
  color: var(--amber);
}

.pill.alert {
  background: var(--red-soft);
  border-color: #e2aaa2;
  color: var(--red);
}

.dashboard-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 20px;
  padding: 20px clamp(16px, 4vw, 44px) 36px;
}

.view-nav {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-self: start;
}

.nav-button {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
  text-align: left;
  cursor: pointer;
}

.nav-button:hover {
  border-color: #9dbdb9;
}

.nav-button.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #ffffff;
}

.workspace {
  min-width: 0;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.section-copy {
  max-width: 820px;
  color: var(--muted);
  line-height: 1.48;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin: 16px 0;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.toggle label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

select {
  min-width: min(360px, 82vw);
  min-height: 42px;
  padding: 8px 38px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.notice {
  margin: 12px 0 16px;
  padding: 12px 14px;
  border: 1px solid #e3c387;
  border-radius: 8px;
  background: var(--amber-soft);
  color: #6f4a0f;
  line-height: 1.45;
}

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

.kpi {
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi-value {
  overflow-wrap: anywhere;
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 850;
  line-height: 1;
}

.kpi-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.72fr) minmax(360px, 1.28fr);
  gap: 14px;
  align-items: start;
}

.panel,
.table-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.table-panel {
  overflow: hidden;
}

.chart-panel {
  padding: 16px;
}

.chart-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.chart-heading h3 {
  margin-bottom: 0;
}

.chart-unit {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

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

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 310px;
}

.axis-label,
.tick-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chart-line {
  fill: none;
  stroke: var(--teal);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot {
  fill: var(--surface);
  stroke: var(--teal);
  stroke-width: 2.5;
}

.range-band {
  fill: var(--green-soft);
  opacity: 0.75;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  gap: 8px;
  margin-top: 12px;
}

.section-header > .status-row {
  justify-content: flex-end;
  max-width: 520px;
  margin-top: 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--gray-soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.status-badge.good {
  background: var(--green-soft);
  border-color: #bdd7b2;
  color: var(--green);
}

.status-badge.warn {
  background: var(--amber-soft);
  border-color: #e3c387;
  color: var(--amber);
}

.status-badge.alert {
  background: var(--red-soft);
  border-color: #e2aaa2;
  color: var(--red);
}

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

.detail-item {
  min-width: 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.detail-label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-value {
  overflow-wrap: anywhere;
  font-size: 21px;
  font-weight: 850;
}

.detail-note {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.bar-list {
  display: grid;
  gap: 11px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(140px, 2fr) 40px;
  align-items: center;
  gap: 10px;
}

.bar-label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.bar-track {
  height: 12px;
  border-radius: 99px;
  background: var(--gray-soft);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--teal);
}

.bar-value {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

td {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.table-scroll {
  max-height: 420px;
  overflow: auto;
}

.compact-table .table-scroll {
  max-height: 330px;
}

.compact-table th,
.compact-table td {
  padding: 7px 10px;
}

.compact-table td {
  font-size: 12px;
  line-height: 1.25;
}

.compact-table .source-cell {
  max-width: 230px;
}

.source-cell {
  max-width: 280px;
  overflow-wrap: anywhere;
}

.qualified-section {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.notes-grid {
  margin: 14px 0;
}

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

.personal-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1.2fr) minmax(260px, 0.8fr);
  gap: 14px;
  margin: 14px 0;
  align-items: start;
}

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

.info-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.info-value {
  margin-top: 3px;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.medical-alert-card {
  border-color: #e2aaa2;
  background: #fff8f6;
}

.alert-line {
  padding: 12px 0;
  border-top: 1px solid #e2aaa2;
}

.alert-line:first-of-type {
  border-top: 0;
}

.alert-value {
  margin-top: 3px;
  color: var(--red);
  font-size: 22px;
  font-weight: 850;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.contact-card h3 {
  margin-bottom: 4px;
}

.contact-detail {
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.35;
}

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

.note-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  line-height: 1.38;
}

.note-meta,
.note-source {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.note-meta {
  margin-bottom: 4px;
  text-transform: uppercase;
}

.note-source {
  margin-top: 5px;
}

.subtle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.action-button,
.text-button {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

.action-button {
  padding: 9px 14px;
  border: 1px solid var(--teal);
  background: var(--teal);
  color: #fff;
}

.action-button:hover {
  background: var(--teal-dark);
  border-color: var(--teal-dark);
}

.text-button {
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--teal-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.notice {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  line-height: 1.4;
}

.notice.error {
  border-color: #e2aaa2;
  background: var(--red-soft);
  color: var(--red);
}

.editor-panel {
  margin-bottom: 16px;
  padding: 18px;
  border: 1px solid #9dbdb9;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.editor-heading,
.editor-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

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

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.field-wide {
  grid-column: 1 / -1;
}

.editor-actions {
  justify-content: flex-start;
  margin-top: 14px;
}

.medication-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 150px;
}

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

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

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

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

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .run-meta {
    justify-content: flex-start;
  }

  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .view-nav {
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-button {
    text-align: center;
  }

  .section-header {
    flex-direction: column;
  }

  .kpi-grid,
  .metric-detail {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: 1fr;
  }

  .bar-value {
    text-align: left;
  }

  .medication-form-grid {
    grid-template-columns: 1fr;
  }

  .field-wide {
    grid-column: auto;
  }

  .editor-heading,
  .editor-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .editor-panel {
    padding: 14px;
  }

  .action-button,
  .text-button {
    min-height: 48px;
  }
}

