: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);
  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;
}

textarea {
  min-height: 108px;
}

[data-panel="history"] textarea {
  min-height: 158px;
  line-height: 1.45;
}

[data-panel="history"] #first-increase,
[data-panel="history"] #initial-factors {
  min-height: 118px;
}

.history-main-grid {
  align-items: stretch;
}

.history-context-panel {
  margin: 10px 0 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

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;
}

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

.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;
}

.compact-metric-grid .metric {
  padding: 10px 12px;
}

.compact-metric-grid .metric strong {
  font-size: 18px;
}

.anthro-entry-panel {
  margin-top: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdff;
}

.anthro-entry-panel + .anthro-entry-panel {
  margin-top: 16px;
}

.current-measurement-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.current-measurement-grid label {
  min-width: 0;
}

.current-measurement-grid input,
#vital-signs-table input,
#measurement-table input {
  min-width: 126px;
}

#measurement-history-details > summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 800;
  padding: 10px 0;
}

.measurement-history-wrap table {
  min-width: 920px;
}

.vital-signs-table {
  min-width: 840px;
}

.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 {
  grid-column: 1 / -1;
  padding: 18px;
  height: auto;
  position: static;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.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;
  min-height: 280px;
  max-height: none;
}

.patient-summary-body {
  flex: 1;
  min-height: 240px;
  max-height: none;
  background: #fffdf7;
}

.allergy-review-panel {
  margin-top: 0;
  padding: 14px;
  border: 1px solid #f1c27d;
  border-radius: 10px;
  background: #fff9ed;
}

.allergy-card-list {
  display: grid;
  gap: 12px;
}

.allergy-card-list:empty::before {
  content: "No allergies entered yet. Use Add Allergy to document medication, food, or other intolerance details.";
  display: block;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.allergy-card {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  padding: 12px;
  border: 1px solid #eccb9a;
  border-radius: 8px;
  background: #fffdf8;
}

.ros-card {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdff;
}

.ros-table-wrap {
  overflow: visible;
}

.exam-table-wrap {
  overflow: visible;
}

.ros-table,
.exam-table,
.ros-table tbody,
.exam-table tbody,
.ros-table tr,
.exam-table tr,
.ros-table td {
  display: block;
  width: 100%;
}

.exam-table td {
  display: block;
  width: 100%;
}

.ros-table thead,
.exam-table thead {
  display: none;
}

.ros-table td,
.exam-table td {
  padding: 0;
  border: 0;
}

.ros-table tr + tr,
.exam-table tr + tr {
  margin-top: 14px;
}

.ros-card-header,
.exam-card-header {
  display: grid;
  grid-template-columns: auto minmax(280px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  white-space: nowrap;
}

.ros-system-field {
  margin: 0;
}

.ros-system-field textarea,
.exam-system-field textarea {
  min-height: 54px;
}

.exam-card {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdff;
}

.exam-system-field {
  margin: 0;
}

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

.ros-option-block {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.ros-option-block h4 {
  margin: 0 0 10px;
  color: #334155;
  font-size: 13px;
}

.checkbox-stack-wide {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.checkbox-chip:has(input:checked) {
  border-color: #146c78;
  background: #eaf4f6;
  color: #0f4c5c;
}

.checkbox-chip:has(input:checked) span::before {
  content: "✓ ";
  font-weight: 900;
}

.ros-included-strip {
  padding: 10px 12px;
  border: 1px solid #cfe0e8;
  border-radius: 8px;
  background: #f4fafb;
  color: #334155;
  font-size: 13px;
  line-height: 1.45;
}

.ros-included-strip strong {
  color: var(--accent-dark);
}

.ros-details-field {
  margin: 0;
}

.ros-details-field textarea {
  min-height: 92px;
}

.ros-card-footnote {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.text-delete-button {
  align-self: center;
  border: 0;
  background: transparent;
  color: #8a1f1f;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  padding: 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.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,
  .current-measurement-grid,
  .allergy-card,
  .ros-card-header,
  .exam-card-header,
  .ros-card-grid {
    grid-template-columns: 1fr;
  }
}
