:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #64748b;
  --line: #d8e0ea;
  --accent: #146c78;
  --accent-dark: #0f4c5c;
  --warning: #8a5a00;
  --soft: #eaf4f6;
}

* {
  box-sizing: border-box;
}

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

.app-shell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

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

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

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

.lead {
  margin: 8px 0 0;
  color: var(--muted);
}

.status-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #23a559;
}

.workspace {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 360px;
  gap: 18px;
  padding: 18px;
}

.rail,
.summary,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.rail {
  padding: 10px;
  height: fit-content;
}

.rail-item {
  width: 100%;
  display: block;
  padding: 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.rail-item.active {
  background: var(--soft);
  color: var(--accent-dark);
  font-weight: 700;
}

.rail-placeholder {
  margin-top: 10px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: #fbfdff;
}

.rail-placeholder summary {
  padding: 10px 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.rail-placeholder div {
  min-height: 48px;
  border-top: 1px dashed var(--line);
}

.content {
  min-width: 0;
}

.panel {
  padding: 18px;
}

.hidden,
.panel.hidden {
  display: none;
}

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

.panel-header.compact {
  margin-bottom: 12px;
}

.subpanel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.grid {
  display: grid;
  gap: 14px;
}

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

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

label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  color: #334155;
  font-size: 13px;
  font-weight: 650;
}

.segmented-field {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 18px;
  padding: 0;
  border: 0;
}

.segmented-field legend {
  flex-basis: 100%;
  margin-bottom: 2px;
  color: #334155;
  font-size: 13px;
  font-weight: 650;
}

.segmented-field label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
  cursor: pointer;
}

.segmented-field input {
  width: auto;
  margin: 0;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--ink);
  font: inherit;
  resize: vertical;
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(20, 108, 120, 0.18);
  border-color: var(--accent);
}

button {
  font: inherit;
}

.primary-button,
.secondary-button,
.danger-button {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 10px 13px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: white;
}

.secondary-button {
  background: white;
  border-color: var(--line);
  color: var(--accent-dark);
}

.danger-button {
  background: #fff6f6;
  border-color: #f3c3c3;
  color: #8a1f1f;
}

.wide {
  width: 100%;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric,
.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdff;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.metric strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

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

.flagged-row {
  background: #fffaf0;
}

.check-cell {
  text-align: center;
  width: 72px;
}

.check-cell input {
  width: 18px;
  height: 18px;
}

.checkbox-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 220px;
}

.checkbox-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
  color: #334155;
  font-size: 12px;
  font-weight: 650;
}

.checkbox-chip input {
  width: 14px;
  height: 14px;
}

#medication-table td,
[data-panel="medications"] th {
  white-space: nowrap;
}

#medication-table input {
  min-width: 142px;
}

#medication-table .nowrap-input {
  min-width: 156px;
  white-space: nowrap;
  overflow-x: auto;
}

#plan-table {
  min-width: 980px;
}

#plan-table th:nth-child(1),
#plan-table td:nth-child(1) {
  width: 22%;
}

#plan-table th:nth-child(2),
#plan-table td:nth-child(2) {
  width: 56%;
}

#plan-table th:nth-child(3),
#plan-table td:nth-child(3) {
  width: 18%;
}

#plan-table textarea {
  min-height: 132px;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.row-action {
  width: 1%;
  white-space: nowrap;
}

.icon-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: #8a1f1f;
  cursor: pointer;
  font-weight: 700;
  padding: 8px 10px;
}

.summary {
  padding: 18px;
  height: calc(100vh - 126px);
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.primary-actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
}

.more-actions {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  padding: 8px;
}

.more-actions summary {
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 800;
  list-style-position: inside;
  padding: 2px 4px 8px;
}

.file-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 13px;
  margin: 0;
  background: white;
  color: var(--accent-dark);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.file-button input {
  display: none;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.template-strip {
  color: #6f4e00;
}

.template-strip summary {
  color: #6f4e00;
  font-weight: 750;
}

.template-strip .secondary-button {
  color: #6f4e00;
  border-color: #e2c875;
  background: #fffdf5;
}

.letter-preview {
  margin: 14px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--ink);
  padding: 18px;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  line-height: 1.5;
}

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

.integration-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  padding: 14px;
}

.ehr-visual {
  margin-top: 10px;
}

.ehr-document {
  border: 1px solid #cbd7e4;
  border-radius: 8px;
  background: white;
  padding: 12px;
  color: #334155;
  font-size: 13px;
  line-height: 1.45;
}

.ehr-document-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.ehr-document-header span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.ehr-document ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.review-banner {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--muted);
  padding: 12px;
  margin: 14px 0;
  font-size: 14px;
}

.review-banner strong {
  color: var(--ink);
}

.accept-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 700;
  padding: 8px 10px;
  white-space: nowrap;
}

.accept-button:disabled {
  cursor: default;
  opacity: 0.55;
}

.summary-body {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.45;
}

.patient-summary-body {
  flex: 0 0 auto;
  max-height: 230px;
  background: #fffdf7;
}

.summary-plan-condition,
.summary-allergy-alert {
  display: inline-block;
  width: 100%;
  box-sizing: border-box;
  border-radius: 6px;
  padding: 2px 6px;
}

.summary-plan-condition {
  background: #e9f3f8;
  color: #153f4c;
  font-weight: 800;
}

.summary-allergy-alert {
  border-left: 4px solid #b45309;
  background: #fff7ed;
  color: #7c2d12;
  font-weight: 800;
}

.muted {
  color: var(--muted);
}

.chart-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  padding: 14px;
  margin-bottom: 18px;
}

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

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.legend span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.legend-swatch {
  width: 22px;
  height: 3px;
  border-radius: 999px;
  display: inline-block;
}

.legend-swatch.bmi,
.line.bmi,
.dot.bmi {
  background: #146c78;
  stroke: #146c78;
}

.legend-swatch.wth,
.line.wth,
.dot.wth {
  background: #8a5a00;
  stroke: #8a5a00;
}

.legend-swatch.wthip,
.line.wthip,
.dot.wthip {
  background: #4c6fff;
  stroke: #4c6fff;
}

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

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

.axis {
  stroke: var(--line);
  stroke-width: 1.5;
}

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

.line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dot {
  fill: white;
  stroke-width: 3;
}

.code-output {
  max-height: 420px;
  overflow: auto;
  background: #0f172a;
  color: #d7e5f0;
  border-radius: 8px;
  padding: 14px;
  font-size: 12px;
}

@media print {
  body {
    background: white;
  }

  .app-shell,
  .rail,
  .content,
  .action-grid,
  #copy-note {
    display: none !important;
  }

  .workspace {
    display: block;
    padding: 0;
  }

  .summary {
    position: static;
    height: auto;
    border: 0;
    padding: 0;
  }

  .summary-body {
    border: 0;
    padding: 0;
    font-size: 12px;
    white-space: pre-wrap;
  }
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .rail {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .summary {
    position: static;
    height: auto;
  }

  .grid.two,
  .grid.four,
  .metric-grid {
    grid-template-columns: 1fr;
  }
}
