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

:root {
  /* Color palette */
  --gold:        #2c4e50;
  --gold-deep:   #1f3839;
  --gold-soft:   #c5d4d5;
  --progress-fill: #2c4e50;
  --progress-chip-bg: #f6f8f5;
  --progress-chip-border: #e6ece6;
  --progress-chip-active-border: #2c4e50;
  --progress-chip-text: #8a938f;
  --ink:         #1a1a1a;
  --ink-soft:    #4a4a4a;
  --ink-muted:   #7a7a7a;
  --brand:       #2c4e50;
  --brand-deep:  #1f3839;
  --paper:       #fafaf7;
  --paper-deep:  #f0ede4;
  --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: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body:    'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;

  /* 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: 16px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px var(--space-5) var(--space-3);
  background: var(--paper);
}
.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.brand-logo {
  display: block;
  height: 112px;
  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: 76px; }
}

/* Layout */
.form-container {
  max-width: 980px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-7);
}
.progress-panel {
  margin-bottom: var(--space-4);
  padding: 14px 18px 16px;
  border: 1px solid rgba(255, 255, 255, 0.88);
  border-radius: 34px;
  background: rgba(255, 255, 255, 0.34);
  box-shadow: 0 1px 10px rgba(26, 26, 26, 0.025);
}
.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: var(--space-7) var(--space-7) var(--space-5);
}
@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: var(--space-3);
    padding: 12px;
    border-radius: 24px;
  }
}

/* Progress bar */
.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
}
.step-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
}
.step-pct {
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
}
.progress-track {
  height: 6px;
  background: var(--paper);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: var(--space-3);
}
.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: var(--space-6);
}
.progress-step {
  appearance: none;
  width: 100%;
  min-height: 34px;
  padding: 9px 12px;
  border: 1px solid var(--progress-chip-border);
  border-radius: 999px;
  background: var(--progress-chip-bg);
  color: var(--progress-chip-text);
  cursor: pointer;
  font: 800 12px/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(--card);
  border-color: var(--progress-chip-active-border);
  color: var(--brand);
  box-shadow: none;
}
.progress-step:focus-visible {
  outline: 3px solid rgba(44, 78, 80, 0.22);
  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;
}

/* 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: 32px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0 0 2px;
  color: var(--ink);
}
.step-intro {
  color: var(--ink);
  margin: 0 0 var(--space-6);
  font-size: 17px;
  line-height: 1.45;
}
.step-intro.is-compact {
  line-height: 1.35;
  white-space: pre-line;
}

/* Field groups */
.field-group {
  margin-bottom: var(--space-5);
}
.repeater-block > .field-group {
  margin-bottom: 26px;
}
.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: 18px;
  line-height: 1.35;
  margin-bottom: var(--space-2);
  color: var(--ink);
}
.field-label-text {
  display: inline;
}

/* Hint bubble — "?" button + popover */
.hint-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
.hint-button {
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  background: var(--rule-soft);
  color: var(--ink);
  border: 1px solid var(--rule);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.hint-button:hover {
  background: var(--gold-soft);
  color: var(--ink);
  border-color: var(--gold);
}
.hint-button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.hint-button[aria-expanded="true"] {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold-deep);
}
.hint-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 50;
  width: 280px;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 13px;
  letter-spacing: 0;
  line-height: 1.5;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  text-align: left;
  white-space: normal;
  cursor: default;
}
.hint-popover::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 4px;
  border: 6px solid transparent;
  border-bottom-color: var(--ink);
}
.hint-popover[hidden] { display: none; }

.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: 17px;
  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:hover { border-color: var(--ink-muted); }
.field-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(44, 78, 80, 0.15);
}
.field-input:user-invalid {
  border-color: var(--danger);
}
textarea.field-input {
  min-height: 100px;
  resize: vertical;
  font-family: var(--font-body);
}
select.field-input {
  appearance: none;
  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 14px center;
  padding-right: 36px;
}

.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: var(--space-2);
}
.radio-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 14px 18px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 16px;
}
.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;
}
.radio-row input[type="radio"]:checked ~ * { color: var(--ink); }
.radio-row:has(input:checked) {
  border-color: var(--gold);
  background: rgba(44, 78, 80, 0.06);
}

/* Repeating sections (children, assets, bequests) */
.repeater-block {
  min-inline-size: 0;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px 28px 30px;
  margin-bottom: var(--space-5);
  background: var(--paper);
}
.repeater-block legend,
.repeater-block .repeater-label {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: var(--space-4);
  padding: 0 var(--space-3);
}

/* Navigation */
.form-nav {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-7);
  padding-top: var(--space-5);
  border-top: 1px solid var(--rule);
}
.form-nav #prev-btn {
  margin-right: auto;
}
.form-nav #save-draft-btn {
  margin-left: auto;
}
.btn {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 24px;
  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(--brand);
  color: var(--paper);
}
.btn-primary:hover:not(:disabled) {
  background: var(--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: #7e9e88;
  border-color: #7e9e88;
  color: #fff;
  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: var(--space-7) var(--space-7) var(--space-6);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 52rem;
  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: 26px;
  font-weight: 600;
  margin: 0 0 var(--space-3);
  color: var(--ink);
  letter-spacing: -0.02em;
}
.modal-card p {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
}
#error-text {
  white-space: pre-line;
}
.error-heading {
  color: var(--ink) !important;
}
.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: 1100px;
  padding-top: var(--space-6);
}

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

.review-page-header {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--rule);
}

.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-sections {
  display: grid;
  gap: var(--space-4);
  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: 10px;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.review-section h3 {
  margin: 0;
  padding: 16px 20px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font-size: 20px;
  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(320px, 0.44fr) minmax(0, 1fr);
  gap: var(--space-6);
  padding: 11px 20px;
  border-bottom: 1px solid var(--rule-soft);
}

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

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

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

.review-item dd {
  color: var(--ink);
  font-weight: 700;
  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);
  border-top: 1px solid var(--rule);
}

.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-generating {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

@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(--gold);
  box-shadow: 0 0 0 3px rgba(44, 78, 80, 0.15);
}

/* 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: transparent;
  border: 1px dashed var(--rule);
  margin-top: var(--space-3);
  margin-bottom: var(--space-3);
}
.repeater-block .repeater-block legend,
.repeater-block .repeater-block .repeater-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0;
}
