/* ─────────────────────────────────────────────────────────────────────────
   TrusteeFriend Intake Form — Design Tokens + Styles
   ───────────────────────────────────────────────────────────────────────── */

:root {
  /* Color palette */
  --section-background: #FFFFFF;
  --gold:        #7a9670;
  --gold-deep:   #647b5c;
  --gold-soft:   #eef3ec;
  --progress-fill: #7a9670;
  --progress-chip-bg: #f6f8f5;
  --progress-chip-border: #e6ece6;
  --progress-chip-active-border: #7a9670;
  --progress-chip-text: #8a938f;
  --ink:         #1a1a1a;
  --ink-soft:    #4a4a4a;
  --ink-muted:   #7a7a7a;
  --brand:       #7a9670;
  --brand-deep:  #647b5c;
  --control-brand: #7a9670;
  --control-brand-deep: #647b5c;
  --control-on-brand: #ffffff;
  --control-on-brand-deep: #ffffff;
  --brand-focus-ring: rgba(122, 150, 112, 0.15);
  --brand-outline-ring: rgba(122, 150, 112, 0.22);
  --brand-selection-bg: rgba(122, 150, 112, 0.08);
  --selected-answer-bg: #fdfcf9;
  --selected-answer-border: #ebe7de;
  --paper:       #ffffff;
  --paper-deep:  #ffffff;
  --card:        #ffffff;
  --rule:        #e8e6df;
  --rule-soft:   #f3f1ea;
  --danger:      #b91c1c;
  --danger-soft: #fef2f2;
  --shadow-sm:   0 1px 3px rgba(26, 26, 26, 0.05);
  --shadow-md:   0 4px 20px rgba(26, 26, 26, 0.06);
  --shadow-lg:   0 25px 50px -12px rgba(26, 26, 26, 0.18);

  /* Typography */
  --font-display: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-body:    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --type-page-heading: 36px;
  --type-section-heading: 28px;
  --type-subsection-heading: 24px;
  --type-nested-heading: 21px;
  --type-question: 19px;
  --type-role-question: 19px;
  --type-body: 16px;
  --type-answer: 17px;
  --type-choice-detail: 14px;
  --type-pill: 17px;
  --type-role-preview: 18px;
  --type-helper: 14px;
  --type-caption: 13px;
  --type-footer: 12px;
  --type-mobile-page-heading: 26px;
  --type-mobile-section-heading: 20px;
  --type-mobile-question: 18px;
  --type-mobile-pill: 15px;
  --type-mobile-role-heading: 20px;
  --type-mobile-role-preview: 15px;
  --type-small-page-heading: 24px;
  --type-small-pill: 14px;
  --type-small-role-heading: 19px;
  --type-small-role-preview: 14px;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
}
/* Reset */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background-color: var(--paper);
  color: var(--ink);
  font-size: var(--type-body);
  line-height: 1.65;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Native controls do not inherit the body font in every browser. */
button, input, select, textarea { font-family: var(--font-body); }

/* Header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 68px var(--space-5) var(--space-4);
  background: var(--paper);
}
.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.brand-logo {
  display: block;
  height: 220px;
  max-width: min(680px, 90vw);
  width: auto;
}
/* Co-branding: reserve the logo's space but hide it until partner theming resolves,
   so partners never flash the default brand. Removed by js/theme.js when ready. */
.theme-pending .brand-logo {
  visibility: hidden;
}
.theme-pending .brand-logo[src] { min-width: 180px; }
/* Wordmark fallback when a partner has no uploaded logo. */
.brand-wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2rem;
  letter-spacing: -0.5px;
  color: var(--brand);
}
@media (max-width: 640px) {
  .page-header { padding: var(--space-6) var(--space-4) var(--space-2); }
  .brand-logo { height: 132px; }
}

/* Layout */
.form-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-7);
  container-type: inline-size;
  container-name: questionnaire;
}
.questionnaire-language-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-height: 36px;
  margin-bottom: 4px;
}
.questionnaire-language-icon {
  display: block;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  color: var(--ink-muted);
}
.questionnaire-language-bar select {
  width: auto;
  min-width: 104px;
  min-height: 34px;
  padding: 5px 30px 5px 10px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
}
.questionnaire-language-note {
  margin: 0 0 8px;
  text-align: right;
  color: var(--ink-muted);
  font-size: var(--type-caption);
}
body.is-missing-order .form-container {
  max-width: 760px;
  padding-top: 20px;
}
body.is-missing-order .questionnaire-language-bar,
body.is-missing-order .questionnaire-language-note {
  display: none;
}
body.is-missing-order .form-card {
  padding: 28px;
}
.progress-panel {
  margin-bottom: 16px;
  padding: 12px 0 10px;
  border: 1px solid transparent;
  border-radius: 34px;
  background: transparent;
  box-shadow: none;
}
.is-reviewing .progress-panel {
  display: none;
}
.form-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--rule);
  padding: 44px 52px;
}

body.is-embedded .page-header {
  display: none;
}

body.is-embedded {
  background-color: #ffffff;
}

body.is-embedded .form-container {
  max-width: 1440px;
  padding-top: 28px;
  padding-bottom: 28px;
}

body.is-embedded .progress-panel {
  margin-bottom: 16px;
  padding-top: 0;
  padding-bottom: 10px;
}

body.is-embedded .form-card {
  box-shadow: var(--shadow-sm);
}

body.is-embedded .step-heading {
  margin-bottom: 30px;
}

body.is-embedded .page-footer {
  padding-top: 20px;
  padding-bottom: 0;
}
@media (max-width: 640px) {
  .form-card { padding: var(--space-5); }
  .form-container { padding: var(--space-4) var(--space-3) var(--space-5); }
  .progress-panel {
    margin-bottom: 10px;
    padding: 8px 0 6px;
    border-radius: 24px;
  }
}

/* Progress bar */
.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.step-label {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
}
.step-pct {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}
.progress-track {
  height: 6px;
  background: var(--paper);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-fill {
  height: 100%;
  background: var(--progress-fill);
  border-radius: 999px;
  width: 12%;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-2);
  width: 100%;
  margin-bottom: 0;
}
.progress-step {
  appearance: none;
  width: 100%;
  min-height: 40px;
  padding: 11px 14px;
  border: 1px solid var(--progress-chip-border);
  border-radius: 999px;
  background: var(--progress-chip-bg);
  color: var(--progress-chip-text);
  cursor: pointer;
  font: 800 15px/1 var(--font-body);
  text-align: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.progress-step:hover {
  border-color: var(--progress-chip-active-border);
  color: var(--brand);
}
.progress-step.is-complete {
  background: var(--progress-chip-bg);
  border-color: var(--progress-chip-border);
  color: var(--progress-chip-text);
}
.progress-step[aria-current="step"] {
  background: var(--selected-answer-bg);
  border-color: var(--progress-chip-active-border);
  color: var(--brand);
  box-shadow: none;
}
.progress-step:focus-visible {
  outline: 3px solid var(--brand-outline-ring);
  outline-offset: 2px;
}

/* Warnings */
.warning-banner {
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: var(--danger);
  padding: var(--space-4);
  border-radius: 8px;
  margin-bottom: var(--space-5);
  font-size: 14px;
  text-align: center;
}

/* Steps */
.step {
  display: none;
  animation: stepIn 0.35s ease;
}
.step.active {
  display: block;
}
@keyframes stepIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.step-heading {
  font-family: var(--font-display);
  font-size: var(--type-page-heading);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0 0 30px;
  color: var(--ink);
  text-align: left;
}
.step-intro {
  color: var(--ink);
  margin: 0 0 var(--space-6);
  font-size: var(--type-role-preview);
  line-height: 1.45;
}
.step-intro.is-compact {
  line-height: 1.35;
  white-space: pre-line;
}

/* Field groups */
.field-group {
  margin-bottom: 34.5px;
}
.repeater-block > .field-group {
  margin-bottom: 34.5px;
}
.repeater-block > .field-group:last-child {
  margin-bottom: 0;
}
.field-group:last-child { margin-bottom: 0; }
.field-group label.field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-weight: 600;
  font-size: var(--type-question);
  line-height: 1.35;
  margin-bottom: 12.65px;
  color: var(--ink);
}
.field-label-text {
  display: inline;
}
.label-optional {
  color: var(--ink-muted);
  font-weight: inherit;
}

/* Hint bubble */
.hint-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
.hint-button {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--control-brand);
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, transform 0.15s ease;
}
.hint-icon {
  display: block;
  width: 100%;
  height: 100%;
}
.hint-icon-bg {
  fill: currentColor;
}
.hint-icon-mark {
  fill: #fff;
}
.hint-icon-letter {
  fill: #fff;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 15px;
  font-style: italic;
  font-weight: 700;
}
.hint-button:hover {
  color: var(--control-brand-deep);
  transform: translateY(-1px);
}
.hint-button:focus-visible {
  outline: 2px solid var(--control-brand);
  outline-offset: 2px;
  border-radius: 50%;
}
.hint-button[aria-expanded="true"] {
  color: var(--control-brand-deep);
}
.hint-modal-card { max-width: 36rem; padding: 34px 38px 32px; }
.hint-modal-heading {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}
.hint-modal-icon {
  width: 42px;
  height: 42px;
  color: var(--control-brand);
}
.hint-modal-text { font-size: 18px; line-height: 1.55; }
.hint-modal-close { margin-top: 24px; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.field-group .field-hint {
  font-size: 14px;
  color: var(--ink);
  margin-top: var(--space-2);
  line-height: 1.5;
}

/* Inputs */
.field-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--type-answer);
  line-height: 1.25;
  min-height: 58px;
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field-input::placeholder { color: var(--ink-muted); opacity: 1; }
.field-input:hover { border-color: var(--ink-muted); }
.field-input:focus {
  outline: none;
  border-color: var(--control-brand);
  box-shadow: 0 0 0 3px var(--brand-focus-ring);
}
.field-input:user-invalid {
  border-color: var(--danger);
}
textarea.field-input {
  min-height: 100px;
  resize: vertical;
  font-family: var(--font-body);
}
.compact-ultimate-beneficiaries textarea.field-input {
  min-height: 72px;
  height: 72px;
}
select.field-input {
  appearance: none;
  height: 58px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%237a7a7a' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 18px center;
  padding-top: 0;
  padding-bottom: 0;
  padding-right: 48px;
}

.suggestion-picker {
  position: relative;
}
.suggestion-picker .field-input {
  padding-right: 52px;
}
.suggestion-toggle {
  position: absolute;
  top: 50%;
  right: 12px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transform: translateY(-50%);
}
.suggestion-toggle::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translate(-50%, -65%) rotate(45deg);
  transition: transform 0.15s ease, color 0.15s ease;
}
.suggestion-toggle:hover,
.suggestion-toggle[aria-expanded="true"] {
  color: var(--ink);
}
.suggestion-toggle[aria-expanded="true"]::before {
  transform: translate(-50%, -35%) rotate(225deg);
}
.suggestion-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 40;
  max-height: 220px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--card);
  box-shadow: var(--shadow-md);
}
.suggestion-menu[hidden] {
  display: none;
}
.suggestion-option,
.suggestion-empty {
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: 700 15px/1.35 var(--font-body);
  text-align: left;
}
.suggestion-option {
  cursor: pointer;
}
.suggestion-option:hover,
.suggestion-option:focus {
  outline: none;
  background: var(--rule-soft);
  color: var(--ink);
}
.suggestion-empty {
  color: var(--ink);
}

/* Radio / checkbox */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.horizontal-radio-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
}
.horizontal-radio-group .radio-row {
  height: 100%;
}
.distribution-section-beneficiaries > .repeater-block > .beneficiary-contingency-field {
  display: block;
  width: 100%;
  max-width: none;
  margin-right: 0;
}
.distribution-section-gifts > .repeater-block > .gift-survival-field {
  display: block;
  width: 100%;
  max-width: none;
  margin-top: 20px;
  margin-right: 0;
}
.gift-survival-field .horizontal-radio-group {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.radio-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: var(--type-answer);
}
.radio-row:hover {
  border-color: var(--gold);
  background: var(--card);
}
.radio-row input[type="radio"],
.radio-row input[type="checkbox"] {
  margin: 0;
  accent-color: var(--gold-deep);
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  transform: translateY(1px);
}
.radio-row input[type="radio"]:checked ~ * { color: var(--ink); }
.radio-row:has(input:checked) {
  border-color: var(--selected-answer-border);
  background: var(--selected-answer-bg);
  box-shadow: inset 0 0 0 1px rgba(235, 231, 222, 0.22);
}
.choice-card-group {
  gap: 12px;
}
.choice-card {
  align-items: center;
  min-height: 68px;
  padding: 16px 18px;
}
.choice-card input[type="radio"] {
  margin-top: 0;
}
.choice-card .choice-card-copy {
  align-self: center;
}
.choice-card-copy {
  display: grid;
  gap: 4px;
}
.choice-card-copy > span {
  font-weight: 760;
}
.choice-card-copy > small {
  color: var(--ink-muted);
  font-size: var(--type-choice-detail);
  font-weight: 560;
  line-height: 1.4;
}

/* Repeating sections (children, assets, bequests) */
.repeater-block {
  min-inline-size: 0;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 16px 24px 24px;
  margin-bottom: var(--space-5);
  background: var(--section-background);
}
.repeater-block legend,
.repeater-block .repeater-label {
  display: block;
  width: fit-content;
  max-width: 100%;
  font-family: var(--font-display);
  font-size: var(--type-section-heading);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: var(--space-3);
  padding: 0 var(--space-3);
  text-align: left;
}
/* Distribution of Estate keeps its denser field layout while matching section styling. */
.distribution-section {
  padding: 16px 24px 24px;
  background: var(--section-background);
  border-color: var(--rule);
  box-shadow: none;
}
.distribution-section > .repeater-label {
  display: block;
  padding: 0 var(--space-3);
  margin-bottom: var(--space-4);
}
.distribution-section > .field-group > .field-label {
  font-size: var(--type-question);
}
.plan-section {
  padding: 16px 24px 24px;
  background: var(--section-background);
  border-color: var(--rule);
  box-shadow: none;
}
.plan-section > .repeater-label {
  display: block;
  padding: 0 var(--space-3);
  margin-bottom: var(--space-4);
}
.plan-section > .field-group > .field-label {
  font-size: var(--type-question);
}
.distribution-section > .repeater-block {
  background: var(--section-background);
  border: 1px solid rgba(232, 230, 223, 0.72);
  border-radius: 12px;
  margin-top: var(--space-3);
  margin-bottom: var(--space-4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}
.distribution-section > .repeater-block > .repeater-label {
  padding: 0 var(--space-3);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: var(--type-subsection-heading);
  font-weight: 600;
}
.distribution-section-beneficiaries > .repeater-block > .field-group:first-of-type,
.distribution-section-gifts > .repeater-block > .field-group:first-of-type {
  max-width: 190px;
}
.distribution-section-beneficiaries > .repeater-block.child-alternate > .field-group:first-of-type {
  max-width: none;
}
.distribution-section-beneficiaries > .repeater-block.child-alternate > .field-group:first-of-type > .field-label {
  margin-bottom: 19.24px;
}
.distribution-section-beneficiaries > .repeater-block.child-alternate > .field-group:first-of-type > .radio-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
  gap: 14px;
}
.distribution-section-gifts > .repeater-block > .field-group:first-of-type {
  max-width: none;
}
@media (max-width: 680px) {
  .plan-section,
  .distribution-section {
    padding: 14px 16px 20px;
  }
  .gift-survival-field .horizontal-radio-group {
    grid-template-columns: 1fr;
  }
}

.field-row {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}
.field-row > * {
  flex: 1 1 0;
  min-inline-size: 0;
}
.field-row.age-milestone-row {
  gap: 16px;
}
/* Each healthcare column is a sizing container. Keep contact fields paired until
   the card is genuinely too narrow to fit two usable controls. */
.health-section { container-type: inline-size; }
@container (max-width: 360px) {
  .repeater-block.contact-agent { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .field-row { flex-direction: column; }
}

/* Decorative units stay visible without becoming part of the submitted value. */
.field-input-with-suffix {
  position: relative;
  width: 100%;
}
.field-input-with-suffix > .field-input {
  padding-right: 2.75rem;
}
.field-input-suffix {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-weight: 600;
  pointer-events: none;
  user-select: none;
}

.draft-save-status {
  min-height: 0;
  margin-top: 0;
  margin-bottom: 28px;
  padding-top: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.2;
  text-align: right;
}

.draft-save-status[data-tone="working"] {
  color: var(--brand);
}

.draft-save-status[data-tone="saved"] {
  color: var(--brand);
}

.draft-save-status[data-tone="warning"] {
  color: #9a6700;
}

.form-card:has(.step[data-step="4"].active) .draft-save-status {
  margin-top: 25px;
}

/* Navigation */
.form-nav {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-3);
  margin-top: 0;
  padding-top: 0;
}
.form-nav #prev-btn {
  margin-right: auto;
}
.form-nav #save-draft-btn {
  margin-left: auto;
}
.btn {
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 28px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: -0.005em;
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--control-brand);
  color: var(--control-on-brand);
}
.btn-primary:hover:not(:disabled) {
  background: var(--control-brand-deep);
  color: var(--control-on-brand-deep);
}
.btn-secondary {
  background: var(--card);
  color: var(--ink);
  border-color: var(--rule);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--ink);
}
.btn.is-saved,
.btn.is-saved:disabled {
  background: var(--control-brand);
  border-color: var(--control-brand);
  color: var(--control-on-brand);
  opacity: 1;
}
/* Footer */
.page-footer {
  text-align: center;
  color: var(--ink);
  font-size: 13px;
  padding: var(--space-6) var(--space-4);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.modal-card {
  background: var(--card);
  padding: 44px 48px 40px;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 44rem;
  width: calc(100% - 2rem);
  max-height: calc(100vh - 2rem);
  overflow: auto;
  transform: scale(0.95) translateY(8px);
  transition: transform 0.25s ease;
}
.modal-overlay.visible .modal-card {
  transform: scale(1) translateY(0);
}
.modal-card h2 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 16px;
  color: var(--ink);
  letter-spacing: 0;
}
.modal-card p {
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
  margin: 0 auto;
  max-width: 34rem;
}
.error-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--bg);
  color: var(--brand);
}
.error-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#error-text {
  white-space: pre-line;
}
.error-heading {
  color: var(--ink) !important;
}
#error-close {
  margin-top: 22px;
}
.modal-status {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--rule);
  font-size: 13px;
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.4s ease;
  min-height: 1.5em;
}
.modal-status.visible { opacity: 1; }

.review-page {
  animation: stepIn 0.25s ease;
}

.is-reviewing .form-container {
  max-width: 1440px;
  padding-top: var(--space-6);
}

.is-reviewing .form-card {
  padding: 44px 52px;
}

.review-page-header {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-4);
}

.review-page-header h2 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1.1;
  letter-spacing: 0;
}

.review-page-header p {
  margin: 0;
  color: var(--ink);
}

.submission-review {
  margin-top: var(--space-5);
  text-align: left;
}

.review-page .submission-review {
  margin-top: 0;
}

.review-attention,
.review-complete {
  margin-bottom: var(--space-5);
  border: 1px solid #d7c27a;
  border-radius: 10px;
  background: #fffaf0;
  color: var(--ink);
  padding: 18px;
}

.review-attention h3 {
  margin: 0 0 6px;
  font-size: 20px;
}

.review-attention p {
  margin: 0 0 14px;
  line-height: 1.5;
}

.review-attention ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.review-attention button {
  display: grid;
  width: 100%;
  gap: 2px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
}

.review-attention button:hover,
.review-attention button:focus-visible {
  border-color: var(--control-brand);
  outline: none;
  box-shadow: 0 0 0 3px var(--brand-focus-ring);
}

.review-attention button span {
  color: var(--ink-muted);
}

.review-complete {
  border-color: #b8d5b1;
  background: #f4faf2;
  font-weight: 650;
}

.review-sections {
  display: grid;
  gap: 14px;
  max-height: 42vh;
  overflow: auto;
  padding-right: 2px;
}

.review-page .review-sections {
  grid-template-columns: 1fr;
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

.review-section {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  box-shadow: none;
}

.review-section h3 {
  margin: 0;
  padding: 14px 18px;
  border-bottom: 1px solid var(--rule);
  background: #fbfaf7;
  color: var(--ink);
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: none;
}

.review-section dl {
  display: grid;
  margin: 0;
}

.review-item {
  display: grid;
  grid-template-columns: minmax(420px, 48%) minmax(0, 1fr);
  gap: 40px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--rule-soft);
}

.review-item:last-child {
  border-bottom: 0;
}

.review-item dt,
.review-item dd {
  margin: 0;
  font-size: 20.7px;
  line-height: 1.45;
}

.review-item dt {
  color: var(--ink);
  font-weight: 650;
}

.review-item dd {
  color: var(--ink);
  font-weight: 550;
  overflow-wrap: anywhere;
}

.review-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-6);
  padding-top: var(--space-5);
}

.review-generate-status {
  display: none;
  margin-top: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.review-generate-status.is-unavailable,
.review-generate-status.is-generating,
.review-generate-status.is-success {
  display: flex;
  align-items: center;
  gap: 10px;
}

.review-generate-status.is-unavailable {
  color: #92400e;
  background: #fffbeb;
  border-color: #fcd34d;
}

.review-generate-status.is-generating::before {
  content: "";
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border: 2px solid var(--rule);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}


.review-generate-status.is-success {
  color: #166534;
  background: #f0fdf4;
  border-color: #86efac;
}

.review-generate-status.is-success::before {
  content: "";
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #15803d url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m6 12 4 4 8-8' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 20px 20px no-repeat;
  box-shadow: 0 0 0 4px rgb(34 197 94 / 12%), 0 0 14px rgb(34 197 94 / 40%);
}

@media (max-width: 640px) {
  .is-reviewing .form-container {
    padding-top: var(--space-4);
  }

  .is-reviewing .form-card {
    padding: var(--space-5);
  }

  .review-page .review-sections {
    grid-template-columns: 1fr;
  }

  .modal-card {
    padding: var(--space-5);
  }

  .review-item {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .review-actions {
    display: grid;
    padding-top: var(--space-4);
  }
}


/* Stage pair — compact inline UI for "In Two/Three Stages" age distributions */
.field-group:has(.stage-pair) > .field-label { display: none; }
.stage-pair {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: var(--space-3);
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
}
.stage-pair-label { font-weight: 600; color: var(--ink); font-size: 15px; min-width: 64px; }
.stage-pair-text  { color: var(--ink); font-size: 15px; }
.stage-pair-input {
  width: 72px;
  font-family: var(--font-body);
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  text-align: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.stage-pair-input::-webkit-outer-spin-button,
.stage-pair-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stage-pair-input:focus {
  outline: none;
  border-color: var(--control-brand);
  box-shadow: 0 0 0 3px var(--brand-focus-ring);
}

/* Spinner */
.spinner {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-5);
  border: 4px solid var(--rule);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Animated dots after "Plan Loading" */
.dots {
  display: inline-block;
  width: 1.5em;
  text-align: left;
}
.dots::after {
  content: '';
  animation: dot-cycle 1.4s steps(4, end) infinite;
}
@keyframes dot-cycle {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

/* Nested repeaters: outer (section like "Children") keeps the gold box;
   inner item-blocks (Child 1, Child 2…) become more subtle. */
.repeater-block .repeater-block {
  background: #ffffff;
  border: 1px dashed var(--rule);
  padding: 14px 20px 20px;
  margin-top: var(--space-3);
  margin-bottom: var(--space-3);
}
.repeater-block .repeater-block legend,
.repeater-block .repeater-block .repeater-label {
  font-size: var(--type-subsection-heading);
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0;
}
.repeater-block .repeater-block.child-card > legend,
.repeater-block .repeater-block.child-card > .repeater-label {
  font-size: var(--type-section-heading);
}
.distribution-section-gifts > .repeater-block > .repeater-label {
  font-size: var(--type-section-heading);
  font-weight: 600;
}
/* Compact per-agent sub-card: name + relationship share a row; contact details span full. */
.repeater-block.contact-agent {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
  padding: 12px 18px 18px;
}
.role-card .repeater-block.contact-agent {
  margin-bottom: 28px;
}
.repeater-block .repeater-block.contact-agent > legend,
.repeater-block .repeater-block.contact-agent > .repeater-label {
  grid-column: 1 / -1;
  font-size: 27px;
  font-weight: 600;
  margin-bottom: var(--space-3);
}
.repeater-block.contact-agent > .field-group {
  margin-bottom: 14px;
  min-inline-size: 0;
}
.repeater-block.contact-agent > .field-group:only-of-type {
  grid-column: 1 / -1;
}
@media (max-width: 560px) {
  .repeater-block.contact-agent { grid-template-columns: 1fr; }
}

.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { position: relative; }
.pill .pill-input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.pill > span {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 10px 18px; border: 1px solid var(--rule);
  border-radius: 999px; background: var(--card); color: var(--ink);
  font: 600 15px/1 var(--font-body); cursor: pointer; transition: all .15s ease;
}
.pill:hover > span { border-color: var(--gold); }
.pill:has(.pill-input:checked) > span {
  border-color: var(--control-brand); background: var(--brand-selection-bg);
  box-shadow: inset 0 0 0 1px var(--control-brand);
}
.pill:has(.pill-input:focus-visible) > span {
  outline: 3px solid var(--brand-outline-ring); outline-offset: 2px;
}


/* Role Assignments: accordion */
.roles-layout { display: grid; grid-template-columns: 1fr; gap: 28px; align-items: start; }
.roles-main { display: flex; flex-direction: column; gap: 22px; width: 100%; min-width: 0; margin: 0 auto; }
.role-card { --role-card-inset: 28px; --role-legend-pad: var(--space-3); position: relative; min-height: 112px; min-inline-size: 0; margin-top: 18px; padding: 0 var(--role-card-inset) 28px; border: 1px solid var(--rule); border-radius: 10px; background: var(--paper); box-shadow: none; overflow: visible; }
.role-card.is-open { border-color: var(--rule); box-shadow: none; }
.role-card.is-suppressed { display: none; }
.role-card-legend { display: block; width: fit-content; max-width: calc(100% - 80px); margin-left: calc(-1 * var(--role-legend-pad)); padding: 0 var(--role-legend-pad); background: linear-gradient(to bottom, transparent calc(50% - 3px), var(--paper) calc(50% - 3px), var(--paper) calc(50% + 3px), transparent calc(50% + 3px)); font: 600 var(--type-section-heading)/1.15 var(--font-display); color: var(--ink); letter-spacing: 0; text-align: left; }
.role-card-header { display: inline; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.role-card-title { display: inline; }
.role-card-summary { display: block; margin-top: 22px; overflow: hidden; color: var(--ink-muted); font: 500 var(--type-role-preview)/1.25 var(--font-body); text-overflow: ellipsis; white-space: nowrap; }
.role-card-chevron { position: absolute; top: calc(50% + 2px); right: 28px; display: grid; width: 22px; height: 22px; place-items: center; color: var(--ink-muted); cursor: pointer; transform: translateY(-50%); transition: transform .2s ease; }
.role-card-chevron::before { content: ""; width: 10px; height: 10px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-1px) rotate(45deg); }
.role-card.is-open .role-card-chevron { top: 65px; transform: translateY(-50%) rotate(180deg); }
.role-card > .repeater-block { margin: 0; border: 0; border-radius: 0; background: transparent; padding: 46px 0 0; }
.role-card:not(.is-open) > .repeater-block { display: none; }
.role-card > .repeater-block > legend.repeater-label { display: none; }
.role-card > .repeater-block > .field-group > .field-label {
  font-size: var(--type-role-question);
  line-height: 1.35;
  margin-bottom: 12px;
}
.role-card .pill-group {
  gap: 12px;
  margin-bottom: 28px;
}
.role-card .pill > span {
  min-height: 58px;
  padding: 14px 24px;
  font-size: var(--type-pill);
  line-height: 1.15;
}
.role-card .serving-arrangement-field .pill-group {
  flex-wrap: nowrap;
  align-items: stretch;
}
.role-card .serving-arrangement-field .pill {
  display: flex;
  flex: 1 1 0;
  min-width: 0;
}
.role-card .serving-arrangement-field .pill > span {
  width: 100%;
  min-width: 0;
  text-align: center;
  white-space: normal;
}

/* Responsive refinement pass */
@media (max-width: 900px) {
  .page-header {
    padding-top: 48px;
  }

  .brand-logo {
    height: 164px;
  }

  .form-container {
    max-width: 100%;
    padding: 24px 18px 40px;
  }

  .progress-panel {
    margin-bottom: 10px;
    padding: 8px 0 6px;
  }

  .progress-steps {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 0;
  }

  .form-card {
    padding: 34px 40px 32px;
  }

  .role-card-legend {
    max-width: calc(100% - 52px);
    font-size: 27px;
  }

  .role-card-summary {
    padding-right: 34px;
    white-space: normal;
  }
}

@media (max-width: 680px) {
  .role-card .serving-arrangement-field .pill-group {
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 16px;
    line-height: 1.55;
  }

  .page-header {
    padding: 32px 16px 4px;
  }

  .brand-logo {
    height: 120px;
  }

  .form-container {
    padding: 16px 12px 32px;
  }

  .progress-meta {
    margin-bottom: 10px;
  }

  .progress-track {
    margin-bottom: 12px;
  }

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

  .progress-step {
    min-height: 42px;
    padding: 10px 8px;
    font-size: var(--type-caption);
    line-height: 1.15;
    white-space: normal;
  }

  .form-card {
    border-radius: 10px;
    padding: 20px 16px;
  }

  .step-heading {
    font-size: var(--type-mobile-page-heading);
    margin-bottom: 20px;
  }

  body.is-embedded .step-heading {
    margin-bottom: 20px;
  }

  .field-group,
  .repeater-block > .field-group {
    margin-bottom: 27.6px;
  }

  .field-group label.field-label,
  .distribution-section > .field-group > .field-label,
  .plan-section > .field-group > .field-label,
  .role-card > .repeater-block > .field-group > .field-label {
    font-size: var(--type-mobile-question);
  }

  .field-input,
  select.field-input {
    min-height: 54px;
    height: auto;
    font-size: 16px;
    padding: 14px 16px;
  }

  select.field-input {
    padding-right: 44px;
    background-position: right 16px center;
  }

  .radio-row {
    min-height: 56px;
    padding: 14px 16px;
    font-size: var(--type-answer);
  }

  .horizontal-radio-group {
    grid-template-columns: 1fr;
  }

  .repeater-block,
  .plan-section,
  .distribution-section {
    padding: 14px 16px 20px;
  }

  .repeater-block .repeater-block {
    padding: 12px 14px 18px;
  }

  .repeater-block legend,
  .repeater-block .repeater-label,
  .distribution-section > .repeater-block > .repeater-label,
  .distribution-section-gifts > .repeater-block > .repeater-label,
  .repeater-block .repeater-block legend,
  .repeater-block .repeater-block .repeater-label {
    font-size: var(--type-mobile-section-heading);
  }

  .roles-main {
    gap: 20px;
  }

  .role-card {
    --role-card-inset: 16px;
    --role-legend-pad: 8px;
    min-height: 102px;
    margin-top: 14px;
    padding: 0 var(--role-card-inset) 22px;
  }

  .role-card-legend {
    max-width: calc(100% - 36px);
    margin-left: calc(-1 * var(--role-legend-pad));
    padding: 0 var(--role-legend-pad);
    font-size: var(--type-mobile-role-heading);
    line-height: 1.18;
  }

  .role-card-summary {
    margin-top: 18px;
    padding-right: 28px;
    font-size: var(--type-mobile-role-preview);
    line-height: 1.35;
  }

  .role-card-chevron {
    top: 56px;
    right: 18px;
  }

  .role-card > .repeater-block {
    padding-top: 34px;
  }

  .role-card .pill-group {
    gap: 8px;
  }

  .role-card .pill > span {
    min-height: 48px;
    padding: 12px 16px;
    font-size: var(--type-mobile-pill);
  }

  .draft-save-status {
    margin-bottom: 22px;
    font-size: var(--type-caption);
    text-align: left;
  }

  .form-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .form-nav #prev-btn,
  .form-nav #save-draft-btn {
    margin: 0;
  }

  .btn {
    width: 100%;
    min-height: 52px;
    padding: 13px 16px;
  }

  .page-footer {
    padding: 24px 18px 32px;
    font-size: var(--type-footer);
    line-height: 1.5;
  }
}

@media (max-width: 440px) {
  .progress-steps {
    grid-template-columns: 1fr;
  }

  .form-card {
    padding: 24px 14px 20px;
  }

  .step-heading {
    font-size: var(--type-small-page-heading);
  }

  .role-card-legend {
    font-size: var(--type-small-role-heading);
  }

  .role-card-summary {
    font-size: var(--type-small-role-preview);
  }

  .role-card .pill > span {
    font-size: var(--type-small-pill);
  }

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

/* Final partner-logo sizing pass. Kept after responsive rules so iframe breakpoints
   do not shrink the organization logo after the first paint. */
.brand-logo {
  width: min(560px, 86vw);
  height: auto;
  max-width: none;
}

.partner-brand-logo {
  width: min(1080px, 88vw);
  height: auto;
  max-width: none;
}

@media (max-width: 900px) {
  .brand-logo {
    width: min(500px, 86vw);
    height: auto;
  }

  .partner-brand-logo {
    width: min(750px, 88vw);
    height: auto;
  }
}

@media (max-width: 640px) {
  .brand-logo {
    width: min(390px, 88vw);
    height: auto;
  }

  .partner-brand-logo {
    width: min(585px, 88vw);
    height: auto;
  }
}

/* Logo-free embedded questionnaire layout. */
.page-header,
.brand,
.brand-logo,
.brand-wordmark,
.partner-brand-logo {
  display: none !important;
}

.form-container {
  padding-top: clamp(18px, 3dvh, 32px);
}

.progress-panel {
  margin-bottom: 16px;
}

@media (max-width: 900px) {
  .form-container {
    padding-top: 18px;
  }
}

@media (max-width: 640px) {
  .form-container {
    padding-top: 14px;
  }
}

/* Unified questionnaire hierarchy. Scale by available form width, not embed mode. */
body .form-card {
  --questionnaire-page: var(--type-page-heading);
  --questionnaire-section: var(--type-section-heading);
  --questionnaire-subsection: var(--type-subsection-heading);
  --questionnaire-nested: var(--type-nested-heading);
  --questionnaire-question: var(--type-question);
  --questionnaire-answer: var(--type-answer);
  --questionnaire-detail: var(--type-choice-detail);
  --questionnaire-section-top: 14px;
  --questionnaire-section-inline: 26px;
  --questionnaire-section-bottom: 28px;
  --questionnaire-nested-top: 12px;
  --questionnaire-nested-inline: 22px;
  --questionnaire-nested-bottom: 22px;
  --questionnaire-question-gap: 30px;
}
@container questionnaire (max-width: 900px) {
  .progress-steps {
    display: none;
  }
  .progress-track {
    margin-bottom: 0;
  }
}
@container questionnaire (max-width: 560px) {
  body .form-card {
    --questionnaire-page: 30px;
    --questionnaire-section: 24px;
    --questionnaire-subsection: 21px;
    --questionnaire-nested: 19px;
    --questionnaire-question: 18px;
    --questionnaire-answer: 16px;
    --questionnaire-detail: 14px;
    --questionnaire-section-top: 14px;
    --questionnaire-section-inline: 16px;
    --questionnaire-section-bottom: 20px;
    --questionnaire-nested-top: 12px;
    --questionnaire-nested-inline: 16px;
    --questionnaire-nested-bottom: 18px;
    --questionnaire-question-gap: 24px;
  }
}
body .form-card .step-heading,
body .form-card .review-page-header h2 {
  font-size: var(--questionnaire-page);
  line-height: 1.2;
}
body .form-card .repeater-block > legend.repeater-label,
body .form-card .role-card > .role-card-legend,
body .form-card .review-section h3 {
  font-size: var(--questionnaire-section);
  line-height: 1.25;
  font-weight: 600;
}
body .form-card .repeater-block .repeater-block > legend.repeater-label {
  font-size: var(--questionnaire-subsection);
}
body .form-card .repeater-block .repeater-block .repeater-block > legend.repeater-label {
  font-size: var(--questionnaire-nested);
}
body .form-card .field-group > label.field-label,
body .form-card .role-card > .repeater-block > .field-group > .field-label {
  font-size: var(--questionnaire-question);
  line-height: 1.4;
  font-weight: 600;
}
body .form-card .field-input,
body .form-card .radio-row,
body .form-card .pill > span,
body .form-card .role-card-summary,
body .form-card .review-item dt,
body .form-card .review-item dd,
body .form-card .stage-pair-input,
body .form-card .stage-pair-label,
body .form-card .stage-pair-text {
  font-size: var(--questionnaire-answer);
  line-height: 1.45;
}
body .form-card .choice-card-copy > small {
  font-size: var(--questionnaire-detail);
  line-height: 1.5;
}
body .form-card .repeater-label,
body .form-card .role-card-legend {
  overflow-wrap: anywhere;
  letter-spacing: 0;
}

/* One inset rhythm for every section family, including Role Assignments. */
body .form-card .step > .repeater-block {
  padding:
    var(--questionnaire-section-top)
    var(--questionnaire-section-inline)
    var(--questionnaire-section-bottom);
}
body .form-card .step > .repeater-block > .repeater-block,
body .form-card .repeater-block.contact-agent {
  padding:
    var(--questionnaire-nested-top)
    var(--questionnaire-nested-inline)
    var(--questionnaire-nested-bottom);
}
body .form-card .role-card {
  --role-card-inset: var(--questionnaire-section-inline);
  padding: 0 var(--role-card-inset) var(--questionnaire-section-bottom);
}
body .form-card .role-card > .repeater-block {
  padding: 34px 0 0;
}
body .form-card .role-card-chevron {
  right: var(--role-card-inset);
}

/* The final visible question/control should end at the section's padding,
   without carrying an extra field margin into the bottom outline. */
body .form-card .field-row > .field-group {
  margin-bottom: 0;
}
body .form-card .child-card > .child-demographics-row {
  margin-bottom: 30px;
}
body .form-card .plan-section-assets .asset-type-row,
body .form-card .plan-section-assets .asset-account-row:has(> .field-group:not([hidden])) {
  margin-bottom: var(--questionnaire-question-gap);
}
body .form-card .repeater-block > legend.repeater-label,
body .form-card .repeater-block > .repeater-label {
  margin-left: calc(-1 * var(--space-3));
}
body .form-card .repeater-block
  > :is(.field-group, .field-row, .repeater-block):not([hidden]):not(:has(~ :is(.field-group, .field-row, .repeater-block):not([hidden]))) {
  margin-bottom: 0;
}

/* Keep the document-generation action label white in every interaction state. */
#generate-documents-btn { color: #ffffff; }

/* Distribution page: reduce visual repetition and clarify the decision hierarchy. */
body .form-card .step[data-step="3"] > .distribution-section {
  margin-bottom: 36px;
  padding-left: 30px;
  padding-right: 30px;
  border-color: #dedfd8;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(26, 26, 26, 0.025);
}
body .form-card .step[data-step="3"] > .distribution-section > .repeater-block {
  padding: 18px 24px 24px;
}
body .form-card .step[data-step="3"] > .distribution-section > legend.repeater-label {
  margin-bottom: 8px;
}
body .form-card .distribution-section-exclusions > .field-group:first-of-type .choice-card-group,
body .form-card .distribution-section-age > .field-group:first-of-type .choice-card-group,
body .form-card .distribution-section-beneficiaries > .field-group:first-of-type .choice-card-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
body .form-card .distribution-section-ultimate > .field-group:first-of-type .choice-card-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
body .form-card .step[data-step="3"] > .distribution-section > .field-group:first-of-type .choice-card {
  min-height: 64px;
}
body .form-card .step[data-step="3"] > .distribution-section :is(.choice-card-group, .horizontal-radio-group) {
  gap: 14px;
}
body .form-card .distribution-section-beneficiaries > .repeater-block:not([hidden]) {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  column-gap: 18px;
  align-items: start;
}
body .form-card .distribution-section-beneficiaries > .repeater-block:not([hidden]) > legend {
  grid-column: 1 / -1;
}
body .form-card .distribution-section-beneficiaries > .repeater-block:not([hidden]) > .field-group[data-field-id$="_pct"] {
  grid-column: 1;
}
body .form-card .distribution-section-beneficiaries > .repeater-block:not([hidden]) > .beneficiary-identity-row {
  grid-column: 2;
}
body .form-card .distribution-section-beneficiaries > .repeater-block:not([hidden]) > :is(.beneficiary-contingency-field, .field-group:not([data-field-id$="_pct"])) {
  grid-column: 1 / -1;
}
body .form-card .distribution-section-age > .age-milestone-row:has(> .field-group[hidden]) > .field-group:not([hidden]) {
  flex: 0 1 calc(50% - 8px);
}
body .form-card .distribution-section-age > .age-milestone-row + .age-milestone-row {
  margin-top: 18px;
}

/* Specific gifts use one vertical rhythm from the card heading to the final choice. */
body .form-card .step[data-step="3"] > .distribution-section-gifts > .repeater-block:not([hidden]) {
  --specific-gift-gap: 24px;
  padding: 20px 24px 24px;
}
body .form-card .step[data-step="3"] > .distribution-section-gifts > .repeater-block:not([hidden]) > legend.repeater-label {
  margin-bottom: 20px;
}
body .form-card .step[data-step="3"] > .distribution-section-gifts > .repeater-block:not([hidden])
  > :is(.field-group, .field-row):not([hidden]) {
  margin-top: 0;
  margin-bottom: var(--specific-gift-gap);
}
body .form-card .step[data-step="3"] > .distribution-section-gifts > .repeater-block:not([hidden]) > .gift-survival-field:not([hidden]) {
  margin-top: 0;
  margin-bottom: 0;
}
@media (max-width: 720px) {
  .distribution-section-beneficiaries > .repeater-block.child-alternate > .field-group:first-of-type > .radio-group {
    grid-template-columns: 1fr;
  }
  body .form-card .distribution-section-beneficiaries > .field-group:first-of-type .choice-card-group,
  body .form-card .distribution-section-ultimate > .field-group:first-of-type .choice-card-group {
    grid-template-columns: 1fr;
  }
  body .form-card .distribution-section-beneficiaries > .repeater-block:not([hidden]) {
    display: block;
  }
  body .form-card .distribution-section-age > .age-milestone-row:has(> .field-group[hidden]) > .field-group:not([hidden]) {
    flex: 1 1 auto;
    max-width: none;
  }
}
