:root {
  --bg: #f5f0e8;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #fffdf9;
  --surface-muted: rgba(244, 239, 231, 0.9);
  --text: #1d2a35;
  --muted: #5d6b79;
  --accent: #0d6f73;
  --accent-soft: #dff0ee;
  --accent-strong: #084c5b;
  --warm: #be5c2b;
  --warm-soft: #fde8da;
  --danger: #b13c32;
  --danger-soft: #f9e2de;
  --ring: rgba(13, 111, 115, 0.18);
  --shadow: 0 24px 60px rgba(29, 42, 53, 0.12);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(13, 111, 115, 0.12), transparent 30%),
    radial-gradient(circle at top right, rgba(190, 92, 43, 0.12), transparent 30%),
    linear-gradient(180deg, #f9f4ec 0%, #f3eee5 100%);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

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

.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px;
}

.hero {
  display: block;
  margin-bottom: 24px;
}

.hero h1,
.panel h2,
.section h3 {
  margin: 0;
  font-family: "Iowan Old Style", "Georgia", serif;
  letter-spacing: -0.02em;
}

.hero h1 {
  font-size: clamp(2.2rem, 3vw, 3.6rem);
  line-height: 1;
  margin-top: 8px;
}

.eyebrow,
.panel-eyebrow,
.hero-card-label,
.subheading {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.73rem;
  color: var(--accent);
  font-weight: 700;
}

.hero-copy {
  max-width: 56rem;
  margin: 14px 0 0;
  font-size: 1.04rem;
  line-height: 1.55;
  color: var(--muted);
}

.hero-notes {
  display: grid;
  gap: 16px;
}

.hero-card,
.panel,
.preview-surface,
.compliance-panel {
  background: var(--surface);
  border: 1px solid rgba(8, 76, 91, 0.08);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.hero-card {
  padding: 18px 20px;
}

.hero-card p:last-child {
  margin: 10px 0 0;
  line-height: 1.5;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 24px;
  align-items: start;
}

.panel {
  padding: 24px;
}

.controls-panel {
  min-width: 0;
}

.preview-panel {
  position: sticky;
  top: 24px;
  display: grid;
  gap: 18px;
}

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

.shortcut-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  font-size: 0.84rem;
  color: var(--muted);
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.7em;
  height: 1.8em;
  padding: 0 0.44em;
  border-radius: 8px;
  border: 1px solid rgba(8, 76, 91, 0.12);
  background: var(--surface-strong);
  box-shadow: inset 0 -2px 0 rgba(8, 76, 91, 0.08);
  font-size: 0.82em;
}

#builder-form {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.section {
  --section-accent: var(--accent);
  --section-accent-soft: var(--accent-soft);
  --section-accent-strong: var(--accent-strong);
  --section-border: rgba(8, 76, 91, 0.08);
  --section-border-strong: rgba(13, 111, 115, 0.34);
  --section-ring: var(--ring);
  --section-shadow: rgba(13, 111, 115, 0.16);
  --section-copy: var(--muted);
  --section-surface: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(244, 239, 231, 0.94));
  padding: 18px;
  background: var(--section-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--section-border);
  border-top: 5px solid var(--section-accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.section-heading {
  margin-bottom: 14px;
}

.section h3,
.section .subheading,
.section .field span,
.section .checkbox-row span {
  color: var(--section-accent);
}

.section-heading p,
.subsection,
.compliance-panel p {
  margin: 8px 0 0;
  color: var(--section-copy, var(--muted));
  line-height: 1.5;
}

.preset-row,
.segmented-control,
.action-row,
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.preset-button,
.segment,
.chip,
.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid rgba(8, 76, 91, 0.16);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--text);
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.preset-button,
.segment,
.chip {
  padding: 10px 14px;
}

.preset-button:hover,
.segment:hover,
.chip:hover,
.action-button:hover {
  transform: translateY(-1px);
  border-color: rgba(8, 76, 91, 0.28);
}

.segment.is-active,
.chip.is-active {
  background: var(--section-accent-soft, var(--accent-soft));
  border-color: var(--section-border-strong, rgba(13, 111, 115, 0.28));
  color: var(--section-accent, var(--accent-strong));
  box-shadow: 0 12px 26px var(--section-shadow, rgba(13, 111, 115, 0.2));
}

.preset-button:disabled,
.segment:disabled,
.chip:disabled,
.action-button:disabled {
  opacity: 0.46;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.button-shortcut-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.15em;
  height: 1.9em;
  padding: 0 0.56em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(8, 76, 91, 0.14);
  box-shadow: inset 0 -1px 0 rgba(8, 76, 91, 0.08);
  color: var(--section-accent, var(--accent-strong));
  font-size: 0.72em;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  flex: 0 0 auto;
}

.button-label {
  display: inline-block;
}

.shortcut-mark {
  color: var(--section-accent, var(--accent-strong));
  font-weight: 800;
  text-decoration: underline;
  text-decoration-color: currentColor;
  text-decoration-thickness: 0.14em;
  text-underline-offset: 0.18em;
}

.segment.is-active .button-shortcut-badge,
.chip.is-active .button-shortcut-badge {
  background: rgba(255, 255, 255, 0.88);
}

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

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

.field span,
.checkbox-row span {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--accent-strong);
}

.field input,
.field select,
.field textarea,
.distance-row {
  width: 100%;
  border: 1px solid rgba(8, 76, 91, 0.12);
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--surface-strong);
  color: var(--text);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.distance-row:focus-within {
  border-color: var(--section-border-strong, rgba(13, 111, 115, 0.34));
  box-shadow: 0 0 0 4px var(--section-ring, var(--ring));
}

.field.is-disabled {
  opacity: 0.52;
}

.distance-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.distance-row input {
  border: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.distance-row span {
  white-space: nowrap;
  color: var(--muted);
}

.theme-type {
  --section-accent: #1667b7;
  --section-accent-soft: #d8ebff;
  --section-accent-strong: #0f4b88;
  --section-border: rgba(45, 95, 139, 0.18);
  --section-border-strong: rgba(22, 103, 183, 0.34);
  --section-ring: rgba(22, 103, 183, 0.2);
  --section-shadow: rgba(22, 103, 183, 0.2);
  --section-copy: #637588;
  --section-surface: linear-gradient(180deg, rgba(244, 249, 255, 0.98), rgba(216, 235, 255, 0.95));
}

.theme-presets {
  --section-accent: #d38317;
  --section-accent-soft: #ffeed1;
  --section-accent-strong: #9b5600;
  --section-border: rgba(211, 131, 23, 0.2);
  --section-border-strong: rgba(211, 131, 23, 0.34);
  --section-ring: rgba(211, 131, 23, 0.18);
  --section-shadow: rgba(211, 131, 23, 0.18);
  --section-copy: #7a6647;
  --section-surface: linear-gradient(180deg, rgba(255, 250, 242, 0.98), rgba(255, 238, 209, 0.95));
}

.theme-determination {
  --section-accent: #d25842;
  --section-accent-soft: #ffe1db;
  --section-accent-strong: #992d1d;
  --section-border: rgba(210, 88, 66, 0.2);
  --section-border-strong: rgba(210, 88, 66, 0.34);
  --section-ring: rgba(210, 88, 66, 0.18);
  --section-shadow: rgba(210, 88, 66, 0.18);
  --section-copy: #7d635d;
  --section-surface: linear-gradient(180deg, rgba(255, 247, 245, 0.98), rgba(255, 225, 219, 0.95));
}

.theme-facts {
  --section-accent: #5d7390;
  --section-accent-soft: #e4edf8;
  --section-accent-strong: #35506f;
  --section-border: rgba(93, 115, 144, 0.2);
  --section-border-strong: rgba(93, 115, 144, 0.34);
  --section-ring: rgba(93, 115, 144, 0.18);
  --section-shadow: rgba(93, 115, 144, 0.18);
  --section-copy: #6a7684;
  --section-surface: linear-gradient(180deg, rgba(248, 250, 253, 0.98), rgba(228, 237, 248, 0.95));
}

.theme-snf-current {
  --section-accent: #008e94;
  --section-accent-soft: #d2f6f3;
  --section-accent-strong: #006268;
  --section-border: rgba(0, 142, 148, 0.2);
  --section-border-strong: rgba(0, 142, 148, 0.34);
  --section-ring: rgba(0, 142, 148, 0.2);
  --section-shadow: rgba(0, 142, 148, 0.2);
  --section-copy: #5f7278;
  --section-surface: linear-gradient(180deg, rgba(245, 252, 252, 0.98), rgba(210, 246, 243, 0.95));
}

.theme-hospital-current {
  --section-accent: #4e88c7;
  --section-accent-soft: #dcebff;
  --section-accent-strong: #285b94;
  --section-border: rgba(78, 136, 199, 0.2);
  --section-border-strong: rgba(78, 136, 199, 0.34);
  --section-ring: rgba(78, 136, 199, 0.18);
  --section-shadow: rgba(78, 136, 199, 0.18);
  --section-copy: #65778d;
  --section-surface: linear-gradient(180deg, rgba(246, 250, 255, 0.98), rgba(220, 235, 255, 0.95));
}

.theme-needs {
  --section-accent: #c87415;
  --section-accent-soft: #ffe8cb;
  --section-accent-strong: #8f4e00;
  --section-border: rgba(200, 116, 21, 0.2);
  --section-border-strong: rgba(200, 116, 21, 0.34);
  --section-ring: rgba(200, 116, 21, 0.18);
  --section-shadow: rgba(200, 116, 21, 0.18);
  --section-copy: #7b694f;
  --section-surface: linear-gradient(180deg, rgba(255, 249, 242, 0.98), rgba(255, 232, 203, 0.95));
}

.theme-discharge {
  --section-accent: #7aa51c;
  --section-accent-soft: #eef8cf;
  --section-accent-strong: #53710c;
  --section-border: rgba(122, 165, 28, 0.2);
  --section-border-strong: rgba(122, 165, 28, 0.34);
  --section-ring: rgba(122, 165, 28, 0.18);
  --section-shadow: rgba(122, 165, 28, 0.18);
  --section-copy: #6f7d58;
  --section-surface: linear-gradient(180deg, rgba(250, 253, 242, 0.98), rgba(238, 248, 207, 0.95));
}

.theme-agree {
  --section-accent: #1f9a4f;
  --section-accent-soft: #d9f8df;
  --section-accent-strong: #0d6c31;
  --section-border: rgba(31, 154, 79, 0.2);
  --section-border-strong: rgba(31, 154, 79, 0.34);
  --section-ring: rgba(31, 154, 79, 0.18);
  --section-shadow: rgba(31, 154, 79, 0.18);
  --section-copy: #617766;
  --section-surface: linear-gradient(180deg, rgba(246, 253, 247, 0.98), rgba(217, 248, 223, 0.95));
}

.theme-disagree {
  --section-accent: #d63d33;
  --section-accent-soft: #ffdeda;
  --section-accent-strong: #9c1f18;
  --section-border: rgba(214, 61, 51, 0.2);
  --section-border-strong: rgba(214, 61, 51, 0.34);
  --section-ring: rgba(214, 61, 51, 0.18);
  --section-shadow: rgba(214, 61, 51, 0.18);
  --section-copy: #7b635f;
  --section-surface: linear-gradient(180deg, rgba(255, 247, 246, 0.98), rgba(255, 222, 218, 0.95));
}

.theme-extra {
  --section-accent: #0f8a80;
  --section-accent-soft: #d9f3ef;
  --section-accent-strong: #00625a;
  --section-border: rgba(15, 138, 128, 0.2);
  --section-border-strong: rgba(15, 138, 128, 0.34);
  --section-ring: rgba(15, 138, 128, 0.18);
  --section-shadow: rgba(15, 138, 128, 0.18);
  --section-copy: #66777a;
  --section-surface: linear-gradient(180deg, rgba(247, 252, 251, 0.98), rgba(217, 243, 239, 0.95));
}

.theme-custom {
  --section-accent: #9a6842;
  --section-accent-soft: #f7e6d7;
  --section-accent-strong: #724521;
  --section-border: rgba(154, 104, 66, 0.2);
  --section-border-strong: rgba(154, 104, 66, 0.34);
  --section-ring: rgba(154, 104, 66, 0.18);
  --section-shadow: rgba(154, 104, 66, 0.18);
  --section-copy: #786b61;
  --section-surface: linear-gradient(180deg, rgba(252, 248, 244, 0.98), rgba(247, 230, 215, 0.95));
}

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

.checkbox-row input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.inline-checkbox {
  align-self: end;
  min-height: 46px;
}

.subsection {
  margin-top: 16px;
}

.is-hidden {
  display: none;
}

.action-row {
  justify-content: flex-end;
}

.action-button {
  padding: 11px 16px;
  font-weight: 700;
  background: var(--surface-strong);
}

.action-button-primary {
  background: linear-gradient(135deg, #0d6f73 0%, #0b5d69 100%);
  color: white;
  border-color: transparent;
}

.action-button-danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: rgba(177, 60, 50, 0.2);
}

.compliance-panel {
  display: grid;
  gap: 12px;
  padding: 16px 18px;
}

.compliance-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: grid;
  gap: 8px;
}

.compliance-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-muted);
  font-size: 0.94rem;
}

.compliance-item.good {
  border: 1px solid rgba(13, 111, 115, 0.16);
}

.compliance-item.warn {
  border: 1px solid rgba(190, 92, 43, 0.18);
  background: var(--warm-soft);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent);
  flex: 0 0 auto;
}

.compliance-item.warn .status-dot {
  background: var(--warm);
}

.copy-status {
  min-height: 1.4rem;
  margin: 0;
  font-weight: 700;
  color: var(--accent-strong);
}

.preview-surface {
  padding: 24px;
  min-height: 360px;
}

.preview-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.preview-help {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.95rem;
}

.icon-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid rgba(8, 76, 91, 0.16);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(228, 241, 243, 0.94));
  color: #0d6f73;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.icon-button:hover {
  transform: translateY(-1px);
  border-color: rgba(13, 111, 115, 0.3);
  box-shadow: 0 12px 24px rgba(13, 111, 115, 0.14);
}

.icon-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(13, 111, 115, 0.14);
}

.icon-button[data-shortcut-display]::after {
  content: attr(data-shortcut-display);
  position: absolute;
  right: -7px;
  bottom: -7px;
  min-width: 1.9em;
  height: 1.9em;
  padding: 0 0.45em;
  border-radius: 999px;
  border: 1px solid rgba(8, 76, 91, 0.14);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 18px rgba(13, 111, 115, 0.16);
  color: #0d6f73;
  font-size: 0.63rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.9em;
  text-transform: uppercase;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.preview-editor {
  min-height: 300px;
  padding: 18px 20px;
  border-radius: 18px;
  border: 1px solid rgba(8, 76, 91, 0.14);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(245, 249, 250, 0.96));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.78);
  line-height: 1.65;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: text;
}

.preview-editor:focus {
  border-color: rgba(13, 111, 115, 0.32);
  box-shadow: 0 0 0 4px rgba(13, 111, 115, 0.12);
}

.preview-inline {
  color: var(--section-accent);
  font-weight: 600;
}

.preview-inline.theme-facts,
.preview-inline.theme-custom {
  color: var(--section-accent-strong);
  font-weight: 600;
}

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

  .preview-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 16px;
  }

  .panel {
    padding: 18px;
  }

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

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

  .action-row,
  .shortcut-strip {
    justify-content: flex-start;
  }

  .preview-toolbar {
    align-items: stretch;
  }
}
