:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-muted: #f7f8fa;
  --surface-soft: #f2f5f8;
  --border: #d6dce3;
  --border-strong: #9ca8b6;
  --text: #1c2733;
  --text-soft: #536171;
  --text-faint: #708093;
  --accent: #114b5f;
  --accent-soft: #e2eef2;
  --success-bg: #edf7f0;
  --success-border: #9ec9aa;
  --success-text: #1f5a33;
  --warning-bg: #fff7e8;
  --warning-border: #e0bd74;
  --warning-text: #7a5618;
  --error-bg: #fff1f0;
  --error-border: #df9b95;
  --error-text: #8a2d24;
  --shadow: 0 18px 45px rgba(28, 39, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(122, 148, 173, 0.16), transparent 24%),
    linear-gradient(180deg, #f8fafc 0%, var(--bg) 100%);
  color: var(--text);
}

code {
  font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
  font-size: 0.95em;
}

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

.app-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0 64px;
}

.page-header {
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--text-soft);
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-header h1 {
  margin: 0;
  font-family: "IBM Plex Serif", Georgia, serif;
  font-size: clamp(2rem, 4vw, 2.8rem);
  line-height: 1.1;
}

.subtitle {
  max-width: 58ch;
  margin: 14px 0 0;
  color: var(--text-soft);
  font-size: 1rem;
  line-height: 1.6;
}

.panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.upload-panel,
.content-panel {
  padding: 24px;
}

.content-panel {
  margin-top: 20px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

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

.panel-header p {
  margin: 6px 0 0;
  color: var(--text-soft);
  line-height: 1.5;
}

.panel-actions {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.panel-action-hint {
  max-width: 34ch;
  text-align: right;
  font-size: 0.92rem;
}

.action-status-region {
  width: min(100%, 34ch);
}

.primary-action {
  padding: 12px 18px;
  border: 1px solid rgba(17, 75, 95, 0.24);
  border-radius: 14px;
  background: linear-gradient(180deg, #194f62 0%, #114b5f 100%);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    opacity 140ms ease,
    background-color 140ms ease;
  box-shadow: 0 12px 22px rgba(17, 75, 95, 0.18);
}

.secondary-action {
  padding: 12px 18px;
  border: 1px solid rgba(17, 75, 95, 0.18);
  border-radius: 14px;
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    opacity 140ms ease,
    border-color 140ms ease;
  box-shadow: 0 10px 20px rgba(17, 75, 95, 0.08);
}

.primary-action:hover,
.primary-action:focus-visible,
.secondary-action:hover,
.secondary-action:focus-visible {
  outline: none;
  transform: translateY(-1px);
}

.primary-action:hover,
.primary-action:focus-visible {
  box-shadow: 0 16px 28px rgba(17, 75, 95, 0.2);
}

.secondary-action:hover,
.secondary-action:focus-visible {
  border-color: rgba(17, 75, 95, 0.34);
  box-shadow: 0 14px 24px rgba(17, 75, 95, 0.12);
}

.primary-action:disabled,
.secondary-action:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

.upload-dropzone {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  padding: 28px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 18px;
  background: var(--surface-muted);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    transform 160ms ease;
}

.upload-dropzone:hover,
.upload-dropzone:focus-within {
  border-color: var(--text);
  background: #f0f4f8;
  transform: translateY(-1px);
}

.upload-dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.upload-title {
  font-weight: 600;
  font-size: 1.05rem;
}

.upload-hint {
  color: var(--text-soft);
  line-height: 1.5;
}

.status-region {
  margin-top: 16px;
}

.status-message {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid;
  line-height: 1.5;
}

.status-message strong {
  display: block;
  margin-bottom: 4px;
}

.status-message.success {
  color: var(--success-text);
  background: var(--success-bg);
  border-color: var(--success-border);
}

.status-message.error {
  color: var(--error-text);
  background: var(--error-bg);
  border-color: var(--error-border);
}

.status-message.warning {
  color: var(--warning-text);
  background: var(--warning-bg);
  border-color: var(--warning-border);
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--border);
  border-radius: 16px;
  color: var(--text-soft);
  background: rgba(247, 248, 250, 0.9);
}

.empty-state strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
}

.patient-context-card {
  margin-bottom: 20px;
  padding: 18px 20px;
  border: 1px solid rgba(17, 75, 95, 0.16);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(226, 238, 242, 0.7) 0%, rgba(255, 255, 255, 0.96) 100%);
}

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

.patient-context-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.patient-context-header p,
.patient-context-note {
  margin: 6px 0 0;
  color: var(--text-soft);
  line-height: 1.5;
}

.patient-context-note {
  max-width: 28ch;
  font-size: 0.92rem;
  text-align: right;
}

.patient-context-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.patient-field {
  display: grid;
  gap: 8px;
  align-content: start;
  color: var(--text);
  font-weight: 600;
}

.patient-field input,
.patient-field select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-weight: 400;
}

.patient-field input:focus,
.patient-field select:focus {
  border-color: rgba(17, 75, 95, 0.55);
  outline: 3px solid rgba(17, 75, 95, 0.12);
}

.patient-field-help {
  color: var(--text-soft);
  font-size: 0.84rem;
  font-weight: 400;
  line-height: 1.4;
}

.patient-field-help.is-error {
  color: var(--error-text);
}

.schema-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.meta-card,
.part-card,
.question-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}

.meta-card {
  padding: 16px;
}

.meta-label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-soft);
  font-size: 0.9rem;
}

.meta-value {
  font-weight: 600;
}

.workspace-layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.navigator-panel,
.section-panel {
  min-width: 0;
}

.navigator-header,
.section-detail-header {
  margin-bottom: 18px;
}

.navigator-header h3,
.section-detail-header h3 {
  margin: 0;
  font-size: 1.25rem;
}

.navigator-header p,
.section-meta,
.section-eyebrow {
  margin: 6px 0 0;
  color: var(--text-soft);
}

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

.part-card {
  overflow: hidden;
  background: linear-gradient(180deg, #fcfdfe 0%, #f7f9fb 100%);
}

.part-card.is-active {
  border-color: rgba(17, 75, 95, 0.38);
  box-shadow: 0 10px 24px rgba(17, 75, 95, 0.08);
}

.part-trigger,
.section-trigger {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.part-trigger {
  display: grid;
  gap: 6px;
  padding: 18px 20px;
}

.part-trigger:hover,
.part-trigger:focus-visible {
  background: rgba(17, 75, 95, 0.05);
  outline: none;
}

.part-trigger-title {
  font-size: 1.05rem;
  font-weight: 600;
}

.part-key {
  color: var(--text-soft);
  font-size: 0.95rem;
}

.section-list {
  list-style: none;
  margin: 0;
  padding: 0 0 10px;
}

.section-item {
  padding: 0 10px;
}

.section-item.empty {
  padding: 14px 20px 10px;
  color: var(--text-soft);
  font-style: italic;
}

.section-trigger {
  display: grid;
  gap: 6px;
  padding: 14px 12px;
  margin-bottom: 8px;
  border-radius: 12px;
  transition:
    background-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

.section-trigger:hover,
.section-trigger:focus-visible {
  background: rgba(17, 75, 95, 0.08);
  outline: none;
  transform: translateY(-1px);
}

.section-trigger.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.section-title {
  font-weight: 600;
}

.section-key {
  color: var(--text-faint);
  font-size: 0.92rem;
}

.section-panel {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(248, 251, 252, 0.92) 0%, rgba(255, 255, 255, 0.96) 100%),
    var(--surface);
}

.section-eyebrow {
  margin-bottom: 8px;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.section-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  line-height: 1.5;
}

.question-stack {
  display: grid;
  gap: 16px;
}

.question-card {
  padding: 18px;
  background: rgba(255, 255, 255, 0.88);
}

.repeat-question-card {
  background:
    linear-gradient(180deg, rgba(244, 249, 251, 0.95) 0%, rgba(255, 255, 255, 0.98) 100%),
    var(--surface);
}

.table-question-card {
  background:
    linear-gradient(180deg, rgba(248, 250, 252, 0.96) 0%, rgba(255, 255, 255, 0.98) 100%),
    var(--surface);
}

.question-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.question-label {
  font-weight: 600;
  line-height: 1.5;
}

.required-indicator {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef3f6;
  color: var(--text-soft);
  font-size: 0.82rem;
  white-space: nowrap;
}

.question-hint {
  margin: 8px 0 0;
  color: var(--text-soft);
  line-height: 1.5;
}

.combined-question-card {
  border-color: rgba(17, 75, 95, 0.18);
  background:
    linear-gradient(180deg, rgba(242, 247, 249, 0.92) 0%, rgba(255, 255, 255, 0.98) 100%),
    var(--surface);
}

.combined-question-card.is-invalid {
  border-color: var(--error-border);
  box-shadow: inset 0 0 0 1px rgba(138, 45, 36, 0.08);
}

.inline-field-group-card {
  border-color: rgba(17, 75, 95, 0.14);
  background: rgba(250, 252, 253, 0.98);
}

.inline-field-group-card.is-invalid {
  border-color: var(--error-border);
  box-shadow: inset 0 0 0 1px rgba(138, 45, 36, 0.08);
}

.repeat-sync-hint {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #eef5f8;
  color: var(--text-soft);
}

.repeat-entry-list,
.repeat-field-stack {
  display: grid;
  gap: 14px;
}

.repeat-entry-list {
  margin-top: 16px;
}

.repeat-entry-card,
.repeat-field-card,
.repeat-note {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
}

.repeat-entry-card {
  padding: 16px;
}

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

.repeat-entry-header h4 {
  margin: 0;
  font-size: 1rem;
}

.repeat-field-card,
.repeat-note {
  padding: 14px;
}

.repeat-note {
  color: var(--text-soft);
  line-height: 1.5;
}

.repeat-note strong {
  display: block;
  color: var(--text);
}

.repeat-note p {
  margin: 6px 0 0;
}

.repeat-empty-state {
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--text-soft);
  background: rgba(247, 248, 250, 0.85);
}

.repeat-empty-state p,
.repeat-empty-state strong {
  margin: 0;
}

.repeat-empty-state strong {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
}

.combined-input-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  margin-top: 16px;
}

.combined-input-panel {
  min-width: 0;
}

.combined-input-label {
  margin-bottom: 8px;
  color: var(--text-soft);
  font-size: 0.92rem;
  font-weight: 600;
}

.inline-field-help {
  margin: 0 0 10px;
  color: var(--text-soft);
  font-size: 0.9rem;
  line-height: 1.45;
}

.inline-field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.inline-field-item {
  min-width: 0;
}

.inline-field-item--number {
  flex: 0 0 110px;
}

.inline-field-item--single {
  flex: 0 0 170px;
}

.inline-field-item .form-input,
.inline-field-item .form-select,
.inline-field-item .form-textarea,
.inline-field-item .choice-list,
.inline-field-item .segmented-options {
  margin-top: 0;
}

.inline-field-separator {
  color: var(--text-soft);
  font-weight: 600;
}

.inline-field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-soft);
  font-size: 0.88rem;
  font-weight: 600;
}

.combined-input-separator {
  align-self: center;
  justify-self: center;
  padding: 8px 0;
  color: var(--text-faint);
  font-size: 0.95rem;
  font-weight: 600;
}

.repeat-actions {
  margin-top: 16px;
}

.table-shell {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.98);
  overflow: hidden;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

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

.data-table thead th {
  background: #f4f7fa;
  color: var(--text-soft);
  font-size: 0.92rem;
  font-weight: 600;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.table-actions-header,
.table-action-cell {
  width: 104px;
}

.table-input,
.table-select {
  width: 100%;
  min-width: 120px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}

.table-input:focus,
.table-select:focus {
  border-color: rgba(17, 75, 95, 0.55);
  outline: 3px solid rgba(17, 75, 95, 0.12);
}

.table-readonly-cell {
  color: var(--text);
  font-weight: 500;
  background: rgba(242, 245, 248, 0.82);
}

.table-empty-cell {
  color: var(--text-soft);
  text-align: center;
  font-style: italic;
}

.table-unsupported-cell {
  padding: 10px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: #fafbfc;
  color: var(--text-soft);
  line-height: 1.4;
}

.table-actions {
  margin-top: 16px;
}

.table-add-button,
.table-remove-button {
  border: 1px solid rgba(17, 75, 95, 0.22);
  border-radius: 12px;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background-color 140ms ease;
}

.table-add-button:hover,
.table-add-button:focus-visible,
.table-remove-button:hover,
.table-remove-button:focus-visible {
  border-color: rgba(17, 75, 95, 0.5);
  background: var(--accent-soft);
  outline: none;
  transform: translateY(-1px);
}

.table-add-button {
  padding: 12px 16px;
  font-weight: 600;
}

.table-remove-button {
  padding: 9px 12px;
}

.table-static-note {
  color: var(--text-faint);
  font-size: 0.9rem;
}

.repeat-add-button,
.repeat-remove-button {
  border: 1px solid rgba(17, 75, 95, 0.22);
  border-radius: 12px;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background-color 140ms ease;
}

.repeat-add-button:hover,
.repeat-add-button:focus-visible,
.repeat-remove-button:hover,
.repeat-remove-button:focus-visible {
  border-color: rgba(17, 75, 95, 0.5);
  background: var(--accent-soft);
  outline: none;
  transform: translateY(-1px);
}

.repeat-add-button {
  padding: 12px 16px;
  font-weight: 600;
}

.repeat-remove-button {
  padding: 9px 12px;
}

.segmented-options,
.choice-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.segmented-options {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.chip-option,
.choice-option {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
  cursor: pointer;
}

.chip-option:has(input:checked),
.choice-option:has(input:checked) {
  border-color: rgba(17, 75, 95, 0.45);
  background: var(--accent-soft);
}

.chip-option input,
.choice-option input {
  margin: 0;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: rgba(17, 75, 95, 0.55);
  outline: 3px solid rgba(17, 75, 95, 0.12);
}

.form-textarea {
  resize: vertical;
  min-height: 132px;
}

.date-field-grid {
  display: grid;
  gap: 12px;
}

.date-field-grid--1 {
  grid-template-columns: minmax(0, 1fr);
}

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

.date-field-grid--3 {
  grid-template-columns: minmax(100px, 0.8fr) minmax(0, 1.1fr) minmax(120px, 1fr);
}

.date-part-field {
  display: grid;
  gap: 8px;
  color: var(--text-soft);
  font-size: 0.92rem;
  font-weight: 600;
}

.date-part-field .form-input,
.date-part-field .form-select {
  margin-top: 0;
}

.date-field-help {
  margin: 10px 0 0;
  color: var(--text-soft);
  font-size: 0.9rem;
  line-height: 1.5;
}

.validation-message {
  margin: 12px 0 0;
  color: var(--error-text);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.unsupported-question {
  margin-top: 16px;
  padding: 16px;
  border: 1px dashed var(--border-strong);
  border-radius: 14px;
  background: #fafbfc;
  color: var(--text-soft);
  line-height: 1.5;
}

.unsupported-question strong {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
}

.developer-warning {
  padding: 14px 16px;
  border: 1px dashed #d6a84d;
  border-radius: 14px;
  background: #fff8e8;
  color: #6f561a;
  line-height: 1.5;
}

.developer-warning strong {
  display: block;
  margin-bottom: 4px;
  color: #5d4510;
}

.developer-warning p {
  margin: 0;
}

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

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

  .panel-actions {
    justify-items: start;
  }

  .panel-action-hint {
    text-align: left;
  }

  .action-status-region {
    width: 100%;
  }

  .patient-context-header {
    flex-direction: column;
  }

  .patient-context-note {
    max-width: none;
    text-align: left;
  }

  .section-panel {
    order: -1;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1220px);
    padding: 24px 0 40px;
  }

  .upload-panel,
  .content-panel,
  .section-panel {
    padding: 18px;
  }

  .question-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .repeat-entry-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .segmented-options {
    grid-template-columns: 1fr;
  }

  .combined-input-layout,
  .date-field-grid--2,
  .date-field-grid--3 {
    grid-template-columns: 1fr;
  }

  .inline-field-row {
    align-items: stretch;
  }

  .inline-field-item--number,
  .inline-field-item--single {
    flex-basis: 100%;
  }

  .combined-input-separator {
    justify-self: start;
    padding: 0;
  }

  .data-table {
    min-width: 0;
  }
}
