/* ═══════════════════════════════════════════════════════════════════
   wizard.css — the step surface: step container, conditional reveal,
   optional-collapsed disclosure, repeaters, summary preview.

   The density rules from the plan are the brief for this file:
     max 4 visible questions per screen · max 1 textarea per screen
     1 repeater per screen · optional-collapsed does not count
     conditionals expand in place beneath their trigger
   The audit block at the bottom makes a violation look wrong.
   ═══════════════════════════════════════════════════════════════════ */

.step-container { position: relative; }

.wizard-step { display: none; }
.wizard-step.active {
  display: block;
  animation: fadeIn var(--transition-slow);
}

.step-title {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
}

/* Step accent comes from --step-accent (set by JS from the manifest),
   never from an inline hex on the element. */
.step-icon {
  --step-accent: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  color: var(--step-accent);
  background: color-mix(in srgb, var(--step-accent) 12%, transparent);
  border-radius: var(--r-sm);
}
.step-icon svg { width: 18px; height: 18px; }

.step-subtitle {
  margin: var(--sp-2) 0 var(--sp-5);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--text-muted);
}
@media (min-width: 600px) {
  .step-subtitle { margin-left: calc(34px + var(--sp-3)); }
}

/* Questions sit in a card so a screen reads as one unit of work. */
.step-body {
  padding: var(--sp-5);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
/* One textarea per screen, so it can afford to be generous. */
.step-body textarea { min-height: 140px; }

/* ── Conditional reveal — expands in place beneath its trigger ───────
   Contract: .conditional lives as the next sibling of the field that
   triggers it; JS toggles .show.                                     */
.conditional { display: none; }
.conditional.show {
  display: block;
  position: relative;
  margin: var(--sp-3) 0 var(--sp-4) var(--sp-4);
  padding-left: var(--sp-4);
  border-left: 2px solid var(--accent-light);
  animation: fadeIn var(--transition-slow);
}
.conditional.show::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 0;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
}
.conditional.show > .field:last-child { margin-bottom: 0; }

/* ── Optional-collapsed disclosure — "Add detail" ────────────────────
   Uses <details>/<summary> so it works before JS loads and is
   keyboard-accessible for free. Does not count toward the 4.          */
.optional-group {
  margin-top: var(--sp-4);
  border-top: 1px solid var(--border-light);
  padding-top: var(--sp-3);
}
.optional-group > summary {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--tap-min);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--accent);
  cursor: pointer;
  list-style: none;
}
.optional-group > summary::-webkit-details-marker { display: none; }
.optional-group > summary::before {
  content: '>';
  font-family: var(--font-mono);
  transition: transform var(--transition);
}
.optional-group[open] > summary::before { transform: rotate(90deg); }
.optional-group > summary:hover { text-decoration: underline; }
.optional-group .optional-note {
  font-weight: var(--fw-normal);
  color: var(--text-muted);
}
.optional-group > .optional-body {
  padding-top: var(--sp-4);
  animation: fadeIn var(--transition-slow);
}

/* ── Repeater — one per screen ───────────────────────────────────────
   Contract for T7:
     .repeater > .repeater-rows > .repeater-row > .repeater-fields
                                                + .repeater-remove
     .repeater-add        add-a-row button
     .repeater-empty      the "I don't have any yet" button
     .repeater-consequence  copy shown once .repeater is [data-empty]:
       "That section won't appear on your site. We won't invent one."
     .repeater-count      "3 of 6"
   ──────────────────────────────────────────────────────────────────── */
.repeater { margin-bottom: var(--sp-5); }

.repeater-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
}
.repeater-count {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  white-space: nowrap;
}

.repeater-rows {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.repeater-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-4);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  animation: fadeIn var(--transition);
}
.repeater-row > .repeater-fields {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: var(--sp-3);
}
/* Multi-part rows (what changed / by how much / where) go side by side
   only when there is room for them. */
@media (min-width: 600px) {
  /* minmax(0, …) or a long placeholder pushes the track wider than its share
     and the row overflows its card. */
  .repeater-row > .repeater-fields.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .repeater-row > .repeater-fields.cols-3 {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr);
  }
}
/* A chip row or a prose box takes the whole width whatever the column count:
   four chips in a 1fr column is four stacked lines, and the escape-hatch
   sentence beside a figure needs room to be a sentence. */
.repeater-row > .repeater-fields > [data-field-kind='single'],
.repeater-row > .repeater-fields > [data-field-kind='multi'],
.repeater-row > .repeater-fields > [data-field-kind='textarea'],
.repeater-row > .repeater-fields > [data-field-kind='toggle'],
.repeater-row > .repeater-fields > .row-unconfirmed { grid-column: 1 / -1; }

/* A CV-proposed row is visibly provisional until a human clears the flag.
   The repeater row in its own step is the only place that can happen. */
.repeater-row[data-unconfirmed] {
  background: var(--amber-light);
  border-color: var(--amber-border);
}
.row-unconfirmed {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px dashed var(--amber-border);
}
.row-unconfirmed .hint { flex: 1 1 200px; margin: 0; color: var(--amber-text); }
.row-unconfirmed[data-confirmed] { border-top-color: var(--border); }
.row-unconfirmed[data-confirmed] .hint { color: var(--text-muted); }
.row-confirm.selected {
  color: var(--green-text);
  background: var(--green-light);
  border-color: var(--green);
}
.repeater-row .repeater-index {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--text-muted);
}
.repeater-remove { align-self: flex-start; }

.repeater-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}
.repeater-add {
  border-style: dashed;
  color: var(--accent);
}
.repeater-add:hover { background: var(--accent-soft); }

/* "I don't have any yet" — a first-class answer, not a hidden escape. */
.repeater-empty { color: var(--text-secondary); }

.repeater-consequence {
  display: none;
  margin-top: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--amber-text);
  background: var(--amber-light);
  border: 1px solid var(--amber-border);
  border-radius: var(--r-sm);
}
.repeater[data-empty] .repeater-consequence { display: block; }
.repeater[data-empty] .repeater-rows { display: none; }
.repeater[data-empty] .repeater-empty {
  background: var(--amber-light);
  border-color: var(--amber);
  color: var(--amber-text);
}

/* Permission-to-publish sits inside a testimonial row and must be seen. */
.repeater-row .permission {
  padding-top: var(--sp-2);
  border-top: 1px dashed var(--border-strong);
  font-size: var(--fs-sm);
}

/* ── Summary preview ─────────────────────────────────────────────── */
.summary-grid {
  display: grid;
  gap: var(--sp-3);
  padding: var(--sp-5);
  background: var(--accent-soft);
  border: 1px solid var(--accent-light);
  border-radius: var(--radius);
}
@media (min-width: 600px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
}
.summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--fs-sm);
  min-width: 0;
}
.summary-item .label {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.summary-item .value { color: var(--text); word-break: break-word; }
.summary-item .value:empty::after {
  content: 'Not answered';
  color: var(--text-muted);
  font-style: italic;
}

/* Jump back to the step that owns a summary line. */
.summary-item a { font-size: var(--fs-xs); }

/* ── Density audit — opt in with <html data-density-audit> ───────────
   Never fires in production. Flags the three ceilings the plan sets, so
   a screen that breaks them looks broken.

   Counted by sibling chain, not :nth-of-type. :nth-of-type counts by
   element *type*, so the .confirm-card and every .conditional wrapper —
   all divs — took an ordinal and the rule flagged the third real field
   as if it were the fifth. `.field ~ .field ~ ...` skips them, which is
   also the rule the JS audit applies (render/step.js:densityCounts) and
   the one Step.visible_questions applies server-side: a conditional
   expands in place beneath its trigger and counts against no ceiling.

   Everything here is scoped with `>` for the same reason — a reveal
   nests inside .conditional and a collapsed extra inside .optional-body,
   so neither is a direct child and neither is counted.               */
html[data-density-audit] .wizard-step.active .step-body > .field ~ .field ~ .field ~ .field ~ .field,
html[data-density-audit] .wizard-step.active .step-body > .field:has(textarea) ~ .field:has(textarea),
html[data-density-audit] .wizard-step.active .step-body > .field:has(.repeater) ~ .field:has(.repeater) {
  outline: 3px dashed var(--red);
  outline-offset: 4px;
}
html[data-density-audit] .wizard-step.active .step-body > .field ~ .field ~ .field ~ .field ~ .field::after,
html[data-density-audit] .wizard-step.active .step-body > .field:has(.repeater) ~ .field:has(.repeater)::after {
  content: 'DENSITY: over the per-screen ceiling — split this step';
  display: block;
  margin-top: var(--sp-2);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  color: var(--red);
}

/* ── The output gate — asked before the first question ─────────────
   It replaces the wizard chrome rather than sitting above it: the
   progress bar and Next button describe a step list the user has not
   scoped yet, so views/outputs.js hides them while this is up. */
.outputs-gate {
  padding: var(--sp-6) 0 var(--sp-4);
}
.outputs-gate h3 {
  font-size: var(--fs-2xl);
  letter-spacing: var(--tracking-tight);
}
.outputs-gate .outputs-sub {
  margin-top: var(--sp-2);
  font-size: var(--fs-md);
  color: var(--text-secondary);
}
.outputs-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-4);
  margin-top: var(--sp-5);
}
.output-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-5);
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.output-card:hover { border-color: var(--accent); }
.output-card:focus-visible { outline: none; box-shadow: var(--ring); }
.output-card .output-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
}
.output-card .output-body {
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--text-secondary);
}
.output-card .output-meta {
  margin-top: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--text-muted);
}

.wizard-header #btnChangeOutputs { margin-top: var(--sp-3); }
