/* ============================================================
   css/configurator.css
   Step-specific visibility/override rules and the Gap Bar System
   blocks, extracted from index.html's inline <style> block.

   Contains: global resets (*, body, .sr-only), Step 2 vertical-shrink
   priority rules, .step-header-above-preview base/overrides, Best
   Match card growth (Steps 2 & 3), .form-content step overrides,
   @keyframes bounce, .step/.step-heading/.step-subtitle shell rules,
   .form-group, .pinned-config-section,
   breakdown-link visibility rules, generic button/.btn-back/.btn-next,
   .error-message, input-suffix rules, Width Formula rules,
   and all five Step 1–5 Gap Bar
   System blocks (zero-out + restore + bars), including the interleaved
   Step 4/5 preview-growth rules and Step 6 indicator/summary-title
   overrides.

   Also contains the .step-header-above-preview and .step h2 rules from
   the trailing @media (max-width: 768px) block —
   kept in this file (appended at the very end) rather than moved to
   css/layout.css, because their base rules also live in THIS file; since
   configurator.css loads LAST, appending the mobile override after those
   base rules preserves the exact cascade order the original single
   stylesheet had (the @media block was the last thing in the file).
   The rest of that @media block (.preview-section/.form-content/
   .button-section/.breakdown-link-row) moved to css/layout.css instead,
   for the same reason — their base rules live there.
   ============================================================ */


* {

    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--color-surface); /* Flat white — gutters beside the centred shell */

    height: 100vh;      /* fallback for older browsers */
    height: 100dvh;     /* dynamic viewport — excludes mobile browser/system UI */
    overflow: hidden;

    /* Centres .container horizontally. Flex is used instead of the
       shell's own `margin-inline: auto` because auto margins collapse to 0
       when the child is wider than its parent — that would pin the shell to
       the left and clip only the right edge. justify-content: center keeps
       it centred and overflows evenly on BOTH edges below --app-min-width,
       which `overflow: hidden` above then clips (no scrollbar). */
    display: flex;
    justify-content: center;
}


        
/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
    font-weight: var(--weight-heading);  /* avoid UA-bold <h1> pulling in Stolzl 700 */
}

/* --- Step 2 vertical-shrink priority ---------------------------------
   On Step 2 the heading/input/Best-Match cards live in
   .step-header-above-preview and .form-content only holds hidden
   fields, so the form-section only needs enough height for the nav.

   Three growth phases as the window gets taller (basis + lopsided
   grow factors give the phases their ordering):
     1. Preview grows from --preview-min-height up to
        --preview-square-size (its flex-basis) — a square. The header
        sits at its basis (auto = cards at their min height).
     2. Header grows next (--flex-priority-high), which expands the
        Best Match cards inside it, until the header itself hits
        --step-header-max-height.
     3. Flexbox freezes the header at that cap and redistributes the
        rest to the uncapped preview — no dead band under the preview.

   Shrinking runs in reverse priority: the preview releases space first,
   down to --preview-min-height. After that nothing can yield — both the
   header and form-section are flex-shrink: 0 — so the layout overflows the
   container's bottom and the nav row clips. That is deliberate: a clipped
   nav row is preferable to a Best Match card being sliced in half. See the
   flex-shrink note beside the Step 3 header rule for the full reasoning.

   ------------------------------------------------------------------ */

.container:has(.step[data-step="2"].active) .preview-section {
    flex-grow: var(--flex-priority-low);      /* grows LAST  → phase 3 */
    flex-shrink: var(--flex-priority-high);   /* shrinks FIRST */
    flex-basis: var(--preview-square-size);   /* square = resting size */
    min-height: var(--preview-min-height);
    max-height: none;
}



/* ── Step 2 (portrait): orientation controls in flow, inside the card ──
   The Left/Right-Hinged control and its caption used to be absolutely
   positioned ON TOP of the 3D canvas. On a phone-width shell that puts
   small text and two tap targets over a busy rendered scene: the copy
   competes with the drawn walls behind it, and the controls read as part
   of the drawing rather than as things you press.

   They now sit in normal flow in a reserved strip at the TOP OF THE CARD —
   still inside #canvasFrame's border, so the preview still reads as one
   panel, but with their own space instead of floating over the render.
   index.html was changed to match: .orientation-overlay is now a CHILD of
   #canvasFrame rather than its sibling. The frame becomes a flex column,
   the overlay takes its natural height and #canvasWrapper takes the rest,
   so the canvas is slightly shorter and nothing is cropped.

   Three constraints this has to respect:

   1. The Step 2 zero-out (`* { margin/padding-top/bottom: 0 !important }`
      further down this file) silently eats any vertical margin or padding
      added here. The strip's separation from the canvas is therefore
      `row-gap`, and its inset from the top border is a transparent
      `border-top` — neither is touched by the zero-out. This is the same
      approved workaround the gap-bar system uses.

   2. #canvasWrapper is `height: 100%` by default, which would overflow a
      flex column. It is switched to `flex: 1` + `min-height: 0` so it
      shrinks to what is left. The ResizeObserver on #canvasWrapper in
      src/main.js re-syncs the Three.js camera and renderer to the new box
      on its own, so no JS change is needed.

   3. Horizontal inset comes from .orientation-overlay's own existing
      `padding` (horizontal padding survives the zero-out), so the canvas
      below still spans the full width of the card.

   Portrait only — landscape keeps the overlay absolutely positioned over
   the canvas, and css/landscape.css loads after this file. The DOM move is
   safe there: the overlay's containing block is still .preview-section,
   which is an ANCESTOR of #canvasFrame, so #canvasFrame's `overflow:
   hidden` does not clip it. */
html:not(.is-landscape) .container:has(.step[data-step="2"].active) #canvasFrame {
    display: flex;
    flex-direction: column;
    row-gap: var(--space-2);
}

html:not(.is-landscape) .container:has(.step[data-step="2"].active) .orientation-overlay {
    position: static;
    flex: 0 0 auto;
    max-width: 100%;
    /* Inset from the card's top border. A border, not padding — see (1). */
    border-top: var(--space-2) solid transparent;
    /* No longer floating over the canvas, so it need not pass gestures
       through — and the caption becomes selectable. */
    pointer-events: auto;
}

html:not(.is-landscape) .container:has(.step[data-step="2"].active) #canvasWrapper {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
}


.container:has(.step[data-step="2"].active) .form-section {
    flex: 0 0 auto;   /* content-sized: never absorbs leftover space (cards do) */
    display: flex;
    flex-direction: column;
    min-height: 0;
}




/* Step-header above preview — sits between indicator and 3D preview.
   Hidden by default; only visible for Step 2 (and future steps that
   adopt this pattern). */
.step-header-above-preview {
    display: none;
    padding: var(--step-header-above-preview-pad-top) var(--padding-page-horizontal) var(--step-header-above-preview-pad-bottom);
    background: var(--color-surface);
}

/* Show for Step 2 — grows first to enlarge the Best Match cards, stopping
   at --step-header-max-height so the surplus passes to the preview.
   flex-shrink: 0 is what stops the lower Best Match card being sliced in
   half on short viewports — see the note below the Step 3 rule.
   overflow: visible — the header is NO LONGER the scroll container; the
   card list inside scrolls on its own (see the Best Match card growth rule
   below), so the heading/input/tip stay fixed while only the cards scroll. */
.container:has(.step[data-step="2"].active) .step-header-above-preview {
    display: flex;
    flex-direction: column;
    flex-grow: var(--flex-priority-high);   /* grows FIRST  → phase 2 */
    flex-shrink: 0;                         /* never compressed below its content */
    flex-basis: auto;                       /* = cards at their min height */
    max-height: var(--step-header-max-height);   /* phase-2 ceiling → releases to preview */
    min-height: min-content;                /* …but never below content (wrapped text on narrow phones) */
    overflow: visible;                      /* chrome fixed; card list scrolls itself */
}






/* Remove bottom margin from form-group inside above-preview header
   so the bottom padding is the sole spacing — keeps it visually balanced. */
.step-header-above-preview .form-group {
    margin-bottom: 0;
}

/* Gap above the width input (between subtitle and input), Step 2 only.
   Scoped to .step-header-above-preview so Step 1's subtitle is unaffected. */
.step-header-above-preview .step-subtitle {
    margin-bottom: var(--input-field-gap-above);
}

/* --- Best Match card growth (Steps 2 & 3) ---------------------------
   The header section grows first (see its per-step rules), and that
   growth is passed down through the step wrapper to .best-match-list,
   which stretches to fill whatever height the header has. The ceiling
   is --step-header-max-height on the header itself, so the cards can
   never leave blank space behind them.

   Scoped to .step-header-above-preview — the only place these cards
   render — so no per-step duplication is needed. */

.step-header-above-preview .best-match-list {
    flex: 1 1 auto;   /* absorb whatever height the header block has */
    min-height: 0;
    overflow-y: auto;               /* the card list is its own scroll region */
    overscroll-behavior: contain;    /* don't chain scroll to the page */
    -webkit-overflow-scrolling: touch;
}


.step-header-above-preview .best-match-card {
    flex: 1 1 var(--best-match-card-min-height);      /* 1 or 2 cards split evenly, 65px resting floor */
    min-height: min-content;                          /* never shorter than its text — on narrow phones
                                                         the subtitle/value wrap and a fixed 65px floor
                                                         clipped "BEST MATCH" and the mm value */
}

/* The list and header must also respect the cards' content height, or the
   header's vh-based max-height cap clips the (now taller) cards. min-height
   beats max-height, so the cap still applies whenever content fits. */
.step-header-above-preview .best-match-list {
    min-height: min-content;
}

/* Chrome (heading / subtitle / input) is FIXED — never compressed
   when the header is capped at short viewports. Without this, flexbox
   would shave a few px off the chrome instead of scrolling the cards. */
.step-header-above-preview .step-heading,
.step-header-above-preview .step-subtitle,
.step-header-above-preview .form-group {
    flex-shrink: 0;
}

/* Solo card inside the header — reaches the SAME max height as one card
   in a 2-card layout. The global :only-child rules (larger padding,
   bigger checkmark, bigger fonts) are designed for the bottom-sheet
   context, so they are undone here.

   ⚠️ The card's ceiling is NOT set here — it comes from the header's
   reduced max-height (see the two solo rules below). Two tempting
   alternatives are both wrong:
     • flex: 0 1 auto      → card never grows at all (phase 2 lost).
     • max-height on the card (or on .best-match-list) → the header still
       grows to its cap, so the space the card refuses pools as a blank
       white band above the preview and phase 3 never fires. Flexbox only
       hands space back when the FLEX ITEM ITSELF is clamped, and that
       item is the header, not the card. */
.step-header-above-preview .best-match-card:only-child {
    flex: 1 1 var(--best-match-card-min-height);             /* fills the (smaller) solo header */
    padding: 16px;                                           /* equal spacing to match top-left tick alignment */
    gap: 16px;                                               /* regular gap, not solo */
}

/* ── Solo-card header ceiling (Steps 2 & 3) ──
   With one card the header only needs room for ONE card, not two, so its
   phase-2 cap drops to --step-header-max-height-solo. The card then tops
   out at exactly --best-match-card-max-height — the same height it would
   reach as one of two — and the space saved passes to the preview in
   phase 3 instead of sitting blank.

   ⚠️ MUST be scoped per step by list ID. #header-step-2 and
   #header-step-3 are BOTH always in the DOM (only one is display: flex)
   and JS populates both lists, so a bare
   `.step-header-above-preview:has(.best-match-card:only-child)` would key
   off the hidden step's card count and shrink the wrong header. */
.container:has(.step[data-step="2"].active):has(#bestMatchList .best-match-card:only-child)
        .step-header-above-preview {
    max-height: var(--step-header-max-height-solo);
}

.container:has(.step[data-step="3"].active):has(#depthBestMatchList .best-match-card:only-child)
        .step-header-above-preview {
    max-height: var(--step-header-max-height-solo);
}

/* M-03 range warning — it sits inside the capped header, so raise the cap
   by its height while it shows; otherwise the card is clipped instead. */
.container:has(.step[data-step="2"].active):has(#widthRangeWarning:not(:empty))
        .step-header-above-preview {
    max-height: calc(var(--step-header-max-height) + var(--range-warning-height));
}

.container:has(.step[data-step="2"].active):has(#widthRangeWarning:not(:empty)):has(#bestMatchList .best-match-card:only-child)
        .step-header-above-preview {
    max-height: calc(var(--step-header-max-height-solo) + var(--range-warning-height));
}

.container:has(.step[data-step="3"].active):has(#depthRangeWarning:not(:empty))
        .step-header-above-preview {
    max-height: calc(var(--step-header-max-height) + var(--range-warning-height));
}

.container:has(.step[data-step="3"].active):has(#depthRangeWarning:not(:empty)):has(#depthBestMatchList .best-match-card:only-child)
        .step-header-above-preview {
    max-height: calc(var(--step-header-max-height-solo) + var(--range-warning-height));
}

/* ── Step 2/3 pre-entry empty-state reservation (post-audit finding) ──
   When the active step's Best Match list is empty, stop the header from
   growing and reserve the two-card height in the list itself. Otherwise the
   empty list (flex: 1 1 auto) balloons into every leftover pixel inside the
   `flex-grow: 200` header, stretching into a blank band that pushes the 2D
   preview's top edge down (measured 38.9px on Step 2). Reserving the space
   keeps the header the same height before and after a value is entered.

   The header rule is scoped per step with :has(...) — #header-step-2 and
   #header-step-3 are BOTH always in the DOM (only one is display: flex), so
   it must key off the active step's list (same idiom as the :only-child
   solo rules above). */
.container:has(.step[data-step="2"].active):has(#bestMatchList:empty) .step-header-above-preview,
.container:has(.step[data-step="3"].active):has(#depthBestMatchList:empty) .step-header-above-preview {
    flex-grow: 0;
}

/* The empty list keeps a two-card min-height so the header is not merely
   content-sized (chrome only) — it reserves the exact space the cards will
   occupy. Exact for a 2-card Best Match result; a solo (1-card) result
   leaves ~65px of residual. Accepted — do NOT render placeholder cards to
   match it. */
#bestMatchList:empty,
#depthBestMatchList:empty {
    min-height: calc(2 * var(--best-match-card-min-height) + var(--gap-s2-04a) + var(--gap-s2-04));
}



.step-header-above-preview .best-match-card:only-child .best-match-check {
    width: var(--checkmark-size);
    height: var(--checkmark-size);
}

.step-header-above-preview .best-match-card:only-child .best-match-label,
.step-header-above-preview .best-match-card:only-child .best-match-sub {
    font-size: inherit;  /* fall back to the non-solo font sizes */
}

.step-header-above-preview .best-match-card:only-child .best-match-value {
    font-size: var(--font-size-heading);  /* regular size */
}

/* Step 1 must fit entirely on screen — disable scrolling and hide the
   scroll-indicator gradient while Step 1 is the active step.
   Also disable mask-image scroll fades on .form-content because Step 1's
   heading/subtitle live INSIDE .form-content (unlike Steps 2–6 where
   headings are in .step-header-above-preview). The layout-buttons inside
   get their own .scroll-fade. See ARCHITECTURE.md issue #51. */
.form-content:has(.step[data-step="1"].active) {
    overflow: hidden;
}
.form-content.scroll-fade:has(.step[data-step="1"].active) {
    mask-image: none;
    -webkit-mask-image: none;
}

/* Step 2 — allow scrolling when preview has collapsed to its minimum.
   Best Match cards scroll so the pinned nav section never gets cut off. */
.form-content:has(.step[data-step="2"].active) {
    flex: 1 1 auto;
    overflow: auto;
    min-height: 0;
}

.step[data-step="2"].active {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}


.step {
    display: none;
}

.step.active {
    display: block;
    flex: 0 0 auto;
}

/* Step 1 stretches to fill available height so layout buttons expand */
.step[data-step="1"].active {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

/* Step Heading — row with number circle + title */
.step-heading {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: var(--step-heading-margin-bottom);
}




.step-number-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: var(--color-panel-black);
    color: #fff;
    border-radius: var(--border-radius-pill);
    font-weight: var(--weight-heading);
    font-size: var(--font-size-heading);
    flex-shrink: 0;
}

.step-heading .step-title {
    margin: 0;
    font-size: var(--font-size-heading);    font-weight: var(--weight-heading);
    line-height: 1;
    color: var(--color-text);
}



.step-subtitle {
    margin: 0;

    font-size: var(--font-size-body);    font-weight: var(--weight-caption);
    line-height: 1.4;
    color: var(--color-text-secondary);

}





/* Form Groups */
.form-group {
    margin-bottom: clamp(4px, 1vh, 20px);
}

.form-group label {
    display: block;
    font-size: var(--font-size-body);    font-weight: var(--weight-heading);
    margin-bottom: clamp(2px, 0.5vh, 8px);
    color: var(--color-text-secondary);
}

.form-group select,
.form-group input {
    width: 100%;
    height: var(--control-height);
    padding: var(--control-padding-y) 7px;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--border-radius);
    font-size: var(--font-size-body);
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input::placeholder {
    color: var(--color-placeholder);
    opacity: 1; /* Firefox applies reduced opacity by default */
}

.form-group select:hover,
.form-group input:hover {
    border-color: var(--color-border-strong);
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: var(--shadow-focus);
}

/* Shared keyboard focus cue for selector-style controls (INT-5). */
.best-match-card:focus-visible,
.config-card:focus-visible,
.config-sheet-option:focus-visible,
.layout-btn:focus-visible,
.fixing-btn:focus-visible,
.swatch:focus-visible,
.view-other-options:focus-visible,
.step6-breakdown-btn:focus-visible,
.width-breakdown-link:focus-visible,
.btn-checkout:focus-visible,
.step6-download-btn:focus-visible,
.sheet-close:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

/* Pinned Config Section — sits above nav buttons, visible only on Step 2 */
.pinned-config-section {
    display: none;
    flex-shrink: 0;
    padding: 1px var(--padding-page-horizontal) 0px;
    background: white;
}

.pinned-config-section label {
    display: block;
    font-size: var(--font-size-body);    font-weight: var(--weight-heading);
    margin-bottom: clamp(2px, 0.5vh, 8px);
    color: var(--color-text-secondary);
}

.pinned-config-section .config-card {
    margin-bottom: 4px;
    /* Undo the global `button { flex: 1; height: --control-height }` so the
       card grows to two lines when the config text wraps on narrow phones
       (min-height on .config-card keeps the 40px single-line height). */
    flex: none;
    height: auto;
}

/* Step 2's zero-out rule strips all vertical padding (!important); give the
   wrapped two-line config text a little breathing room inside the border.
   8px top/bottom → the two-line phone layout is ~56px tall. Single-line
   desktop text (21px + 16px) is still governed by the 40px min-height. */
.container:has(.step[data-step="2"].active) .pinned-config-section .config-card {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
}

.pinned-config-section .error-message {
    margin-bottom: 0;
}

/* Show pinned config section on Steps 2 & 3. On Step 3 its content is
   visibility: hidden (see the Step 3 gap-bar block) so it still occupies
   the same space as Step 2's real section — keeping the form-section
   heights identical and the cards/preview split in sync between steps. */
.form-section:has(.step[data-step="2"].active) .pinned-config-section,
.form-section:has(.step[data-step="3"].active) .pinned-config-section {
    display: block;
}

/* Hide the Width Breakdown link button on Step 1 only — keep its space reserved */
.form-section:has(.step[data-step="1"].active) .breakdown-link-row > button {
    visibility: hidden;
}
/* Hide the breakdown link button on Steps 4, 5 & 6 — keep its space reserved */
.container:has(.step[data-step="4"].active) .breakdown-link-row > button,
.container:has(.step[data-step="5"].active) .breakdown-link-row > button,
.container:has(.step[data-step="6"].active) .breakdown-link-row > button {
    visibility: hidden;
}

/* BREAKDOWN_ROW_RESERVE_MODE === 'collapse' (dev toggle) — remove only the
   button's own 40px reserved height on steps without a real breakdown button
   (Steps 1/4/5/6/7). The row's border-top/border-bottom gap tokens are NOT
   touched, so the nav row keeps the same 10px-above / 12px-below spacing and
   simply sits 40px closer to the bottom edge. Steps 2/3 keep their real,
   visible button (their rules above/below are unaffected).

   The class is added to <html> by formManager.init() when
   CONSTANTS.BREAKDOWN_ROW_RESERVE_MODE === 'collapse'.

   Debug-only note: the gap bars are transparent in production
   (--gap-debug-opacity: 0.0), so these collapsed rows render as empty space.
   If the debug opacity is raised, Steps 1/4/5/6 will show the blue gap strip
   while Step 7 landscape will not — its row-level visibility:hidden
   (landscape.css rule 5b) hides the borders too. That is a debug-only
   cosmetic difference, not a nav-position difference. */
html.breakdown-row-collapse .form-section:has(.step[data-step="1"].active) .breakdown-link-row > button,
html.breakdown-row-collapse .container:has(.step[data-step="4"].active) .breakdown-link-row > button,
html.breakdown-row-collapse .container:has(.step[data-step="5"].active) .breakdown-link-row > button,
html.breakdown-row-collapse .container:has(.step[data-step="6"].active) .breakdown-link-row > button,
html.breakdown-row-collapse .container:has(.step[data-step="7"].active) .breakdown-link-row > button {
    display: none;
}





button {
    flex: 1;
    height: var(--control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border: var(--border-width) solid transparent;

    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: var(--font-size-button);    font-weight: var(--weight-button);
    cursor: pointer;
    transition: opacity 0.2s, background 0.2s, transform 0.1s;
}



/* Primary black button role (CON-1). Shared by the Back/Next nav, the sheet
   "Update" button and the nav row — one place for background/colour/hover.
   Per-slot sizing (flex/padding) stays in each slot's own rule. */
.btn-primary {
    background: var(--color-panel-black);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #000;
}

.btn-back {
    flex: 1;
}

.btn-next {
    flex: 3;
}

button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Error Message */
.error-message {
    color: #d32f2f;
    font-size: var(--font-size-caption);
    margin-top: 4px;
}

/* M-03 — entered width/depth exceeds the largest system. The ID
   selectors are needed to beat the per-step `* { padding: 0 !important }`
   spacing resets on Steps 2/3. */
.range-warning {
    color: var(--color-danger);
    font-size: var(--font-size-caption);
}

#widthRangeWarning,
#depthRangeWarning {
    padding-top: 4px !important;
}

.range-warning:empty {
    display: none;
}

/* Runtime error banner — the single always-visible sink displayStepErrors() targets
   for steps without a dedicated per-step slot (Steps 4–7). Sits at the top of
   .form-section in index.html with role="alert". Empty text → zero height, so it
   has no layout impact until an error is written. */
.error-banner {
    color: #d32f2f;
    font-size: var(--font-size-caption);
    padding: 0 var(--padding-page-horizontal);
}

/* Remove browser spinner arrows from number inputs */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Input suffix wrapper — places a unit label (e.g. "mm") inside the right edge of an input */
.input-suffix-wrapper {
    position: relative;
    display: block;
}

.input-suffix-wrapper input {
    padding-right: 36px; /* space for the suffix so text doesn't overlap */
}

.input-suffix {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: var(--font-size-body);
    color: var(--color-text-secondary);
    pointer-events: none;
    font-family: var(--font-family);
}

/* Width Formula */
.formula-header {
    cursor: pointer;
    font-weight: var(--weight-button);
    margin-bottom: 8px;
    padding: 8px;
    background: var(--color-warning-light);
    border-radius: var(--border-radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.formula-header:hover {
    background: var(--color-warning);
}

.formula-toggle {
    font-size: var(--font-size-heading);
    transition: transform 0.2s;
}

.formula-toggle.collapsed {
    transform: rotate(-90deg);
}

.formula-content {
    transition: max-height 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
}

.formula-content.collapsed {
    max-height: 0;
    opacity: 0;
}

.formula-line {
    margin: 4px 0;
}

.formula-total {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--color-border);
    font-weight: var(--weight-button);
    color: var(--color-success-dark);
}

/* ============================================================
   STEP 1 GAP BAR SYSTEM
   Same mechanism as Steps 2 & 3 below: a zero-out rule strips all
   vertical padding/margin inside the active step, then one bar per
   gap adds the spacing back as a border in --gap-bar-color. The
   complete list of gaps lives in :root as --gap-s1-NN.
   Set --gap-debug-opacity: 0 to hide the bars.
   See docs/STYLING.md for the full map.
   ============================================================ */

/* ══════════════════════════════════════════════════════════════════
   ⚠️ ZERO-OUT (Step 1) — FRAGILE CONSTRAINT, READ BEFORE EDITING.
   This universal `*` rule strips ALL vertical padding and margin from
   every element inside the active step, using !important.
   (a) WHAT IT DOES: resets padding-top/bottom + margin-top/bottom to 0
       so the step's vertical rhythm is driven entirely by the --gap-s1-NN
       border bars (one bar per gap, painted in --gap-bar-color).
   (b) FORBIDDEN: vertical padding and vertical margin CANNOT be used
       anywhere inside this step — the !important zero-out overrides them,
       so any padding/margin you add will silently disappear.
   (c) APPROVED WORKAROUNDS: use borders for vertical spacing (the gap-bar
       pattern) and row-gap for flex/grid children. Internal padding that
       must survive needs its own !important restore rule directly below.
   See docs/STYLING.md for the full gap map.
   ══════════════════════════════════════════════════════════════════ */
.container:has(.step[data-step="1"].active) * {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}
/* Restore internal padding for elements that need it. The zero-out uses
   !important, so each restore must too. */
.container:has(.step[data-step="1"].active) .layout-btn {
    padding-top: var(--layout-btn-vert-pad) !important;
    padding-bottom: var(--layout-btn-vert-pad) !important;
}
.container:has(.step[data-step="1"].active) .button-section button { align-items: center !important; justify-content: center !important; }
/* NOTE: .loading-text needs no restore here — the loading overlay lives
   inside .preview-section, which is hidden on Step 1. */


/* ── Step 1 gap bars ──
   Same border-vs-margin caveat as Steps 2/3: the zero-out rule wins on
   padding and margin, so every bar here is a border (borders are never
   zeroed). Any NEW bar must also be a border. */

/* ≡ s2-00 (shared) */
.container:has(.step[data-step="1"].active) .step-indicator { border-top: var(--gap-s1-00) solid var(--gap-shared-bar-color); }
/* ≡ s2-01 (shared) — ONE bar for the whole indicator → heading gap. There is no
   bar on .preview-section: formManager hides it on Step 1 (display: none),
   so a border there would be painted on a removed box and contribute 0.
   This bar now uses the shared 4px value from --gap-all-01. */
.container:has(.step[data-step="1"].active) .step-indicator { border-bottom: var(--gap-s1-01) solid var(--gap-shared-bar-color); }
/* ≡ s2-02 (shared) */
.container:has(.step[data-step="1"].active) .step[data-step="1"] .step-heading { border-bottom: var(--gap-s1-02) solid var(--gap-shared-bar-color); }
/* ≡ s2-04 (Step 1 has no size input, so s2-03 has no counterpart).
   s1-03a, the gap BETWEEN cards, is the row-gap on .layout-buttons —
   see the comment on that rule for why it is not a border here. */
.container:has(.step[data-step="1"].active) .layout-buttons { border-top: var(--gap-s1-03) solid var(--gap-bar-color); }
/* s1-04 has no Step 2 counterpart — keeps the inline layout error
   message clear of the cards when it is shown. */
.container:has(.step[data-step="1"].active) .step[data-step="1"] .error-message { border-top: var(--gap-s1-04) solid var(--gap-bar-color); }
/* Client feedback (25-08-2026): the Step 1 heading/subtitle get left breathing
   room. The unbolded weight and one-line width now come from the shared
   .step-subtitle rule (which uses --weight-caption and no max-width for every
   step), so only the padding override is scoped here. */
.step[data-step="1"] .step-heading,
.step[data-step="1"] .step-subtitle {
    padding-left: 8px;
}


/* ≡ s2-09 (shared) — last element above the nav → nav buttons. Merges what were
   three separate paddings (form-content bottom + button-section top). */
.container:has(.step[data-step="1"].active) .button-section { border-top: var(--gap-s1-05) solid var(--gap-shared-bar-color); }
/* s1-06 (shared, ≡ s2-10) above the row = nav buttons → breakdown link row.
   s1-07 (shared, ≡ s2-11) below the row = breakdown link row → bottom edge.
   The link's button is hidden on Step 1 but its space is reserved, so
   both bars still apply. */
.container:has(.step[data-step="1"].active) .breakdown-link-row {
    border-top: var(--gap-s1-06) solid var(--gap-shared-bar-color);
    border-bottom: var(--gap-s1-07) solid var(--gap-shared-bar-color);
}


/* ============================================================
   STEP 2 GAP BAR DEBUG SYSTEM

   Each --gap-s2-NN controls a red bar between two elements.
   Elements have NO vertical padding — only margin-bottom for
   spacing + a red bottom-border as the visual debug marker.
   Set --gap-debug-opacity: 0 to hide the red bars.
   See docs/STYLING.md for the gap map.
   ============================================================ */

/* ══════════════════════════════════════════════════════════════════
   ⚠️ ZERO-OUT (Step 2) — FRAGILE CONSTRAINT, READ BEFORE EDITING.
   This universal `*` rule strips ALL vertical padding and margin from
   every element inside the active step, using !important.
   (a) WHAT IT DOES: resets padding-top/bottom + margin-top/bottom to 0
       so the step's vertical rhythm is driven entirely by the --gap-s2-NN
       border bars (one bar per gap, painted in --gap-bar-color).
   (b) FORBIDDEN: vertical padding and vertical margin CANNOT be used
       anywhere inside this step — the !important zero-out overrides them,
       so any padding/margin you add will silently disappear.
   (c) APPROVED WORKAROUNDS: use borders for vertical spacing (the gap-bar
       pattern) and row-gap for flex/grid children. Internal padding that
       must survive needs its own !important restore rule directly below.
   See docs/STYLING.md for the full gap map.
   ══════════════════════════════════════════════════════════════════ */
.container:has(.step[data-step="2"].active) * {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}
/* Restore internal padding for elements that need it */
.container:has(.step[data-step="2"].active) .button-section button { align-items: center !important; justify-content: center !important; }
.container:has(.step[data-step="2"].active) .view-other-options { padding-top: 0 !important; padding-bottom: 0 !important; }
.container:has(.step[data-step="2"].active) .form-group input { margin-bottom: 0 !important; }
.container:has(.step[data-step="2"].active) .best-match-card { padding-top: 16px !important; padding-bottom: 16px !important; }
/* Portrait phones: 12px pays for the extra air around the "View Other
   Options / View Diagram" row (--gap-s2-08 0→8px, --gap-s2-09 8→16px) without
   pushing the nav / breakdown link off short screens (iPhone SE). */
html:not(.is-landscape) .container:has(.step[data-step="2"].active) .best-match-card,
html:not(.is-landscape) .container:has(.step[data-step="3"].active) .best-match-card { padding-top: 12px !important; padding-bottom: 12px !important; }
.container:has(.step[data-step="2"].active) .best-match-check { margin-top: calc((var(--checkmark-size) - (12px + var(--font-offset))) / -2) !important; }

/* ── Step 2 gap bars ──
   Each --gap-s2-NN controls spacing between two elements.
   All bars use --gap-bar-color. Set --gap-debug-opacity: 0 to hide.

   NOTE: the zero-out rule above uses !important on padding/margin, so the
   margin-* declarations below are inert — the visible gap comes from the
   border-* (borders are never zeroed). Any NEW gap bar must therefore be
   applied as a border, plus matching padding where real inner space is
   needed. The margins are kept for documentation of intent. */

/* ≡ s2-00 (shared) */
.container:has(.step[data-step="2"].active) .step-indicator { border-top: var(--gap-s2-00) solid var(--gap-shared-bar-color); }
/* ≡ s2-01 (shared) */
.container:has(.step[data-step="2"].active) .step-indicator { margin-bottom: var(--gap-s2-01); border-bottom: var(--gap-s2-01) solid var(--gap-shared-bar-color); }
.container:has(.step[data-step="2"].active) .step-header-above-preview { padding-top: 0; padding-bottom: 0; }
/* ≡ s2-02 (shared) */
.container:has(.step[data-step="2"].active) .step-header-above-preview .step-heading { margin-bottom: var(--gap-s2-02); border-bottom: var(--gap-s2-02) solid var(--gap-shared-bar-color); }
/* ≡ s2-03 */
.container:has(.step[data-step="2"].active) .step-header-above-preview .step-subtitle { margin-bottom: var(--gap-s2-03); border-bottom: var(--gap-s2-03) solid var(--gap-bar-color); }
.container:has(.step[data-step="2"].active) .step-header-above-preview .form-group { margin-bottom: 0; }
/* ≡ s3-04 */
.container:has(.step[data-step="2"].active) .step-header-above-preview .best-match-list { gap: var(--gap-s2-04a); margin-top: var(--gap-s2-04); border-top: var(--gap-s2-04) solid var(--gap-bar-color); }
/* s2-04a — between cards: row-gap (not a border) so each card keeps its own
   2px outline. row-gap is untouched by the zero-out rule, so the gap is still
   driven by the single variable — it just has no debug bar. */
/* ≡ s3-05 */
.container:has(.step[data-step="2"].active) .step-header-above-preview { margin-bottom: var(--gap-s2-05); border-bottom: var(--gap-s2-05) solid var(--gap-bar-color); }
/* s2-06 … s2-09 — the pinned-config section's internal gaps. These apply
   to BOTH Step 2 and Step 3: Step 3 renders the same real section (its
   content is visibility: hidden) so the form-section heights match exactly
   and the cards/preview split stays in sync between steps. */
.container:has(.step[data-step="2"].active) .preview-section,
.container:has(.step[data-step="3"].active) .preview-section { padding-top: 0; padding-bottom: 0; margin-bottom: var(--gap-s2-06); border-bottom: var(--gap-s2-06) solid var(--gap-bar-color); }
.container:has(.step[data-step="2"].active) .pinned-config-section,
.container:has(.step[data-step="3"].active) .pinned-config-section { padding-top: 0; padding-bottom: 0; }
.container:has(.step[data-step="2"].active) .pinned-config-section label,
.container:has(.step[data-step="3"].active) .pinned-config-section label { margin-bottom: var(--gap-s2-07); border-bottom: var(--gap-s2-07) solid var(--gap-bar-color); }
/* s2-08 — config card → "View Other Options".
   ⚠️ This bar MUST be a border-TOP on .view-other-options, NOT a
   border-bottom on .config-card. The card has a min-height
   (--control-height) and box-sizing: border-box, so a bottom border is
   painted INSIDE its box: it squeezes the card text upward (looks clipped),
   overrides the card's own 2px grey outline, and adds ZERO actual gap.
   Same trap as s7-08 on the Step 7 red button — see docs/STYLING.md. */
.container:has(.step[data-step="2"].active) .view-other-options,
.container:has(.step[data-step="3"].active) .view-other-options { padding-top: 0; padding-bottom: 0; margin-bottom: var(--gap-s2-09); border-top: var(--gap-s2-08) solid var(--gap-bar-color); border-bottom: var(--gap-s2-09) solid var(--gap-shared-bar-color); }
.container:has(.step[data-step="2"].active) .button-section { padding-top: 0; padding-bottom: 0; margin-top: auto !important; }
/* s2-10 (shared, ≡ s3-07) above the row = nav buttons → breakdown link.
   s2-11 (shared, ≡ s3-08) below the row = breakdown link → bottom edge. */
.container:has(.step[data-step="2"].active) .breakdown-link-row {
    padding-top: var(--gap-s2-10);    border-top: var(--gap-s2-10) solid var(--gap-shared-bar-color);
    padding-bottom: var(--gap-s2-11); border-bottom: var(--gap-s2-11) solid var(--gap-shared-bar-color);
}


/* ── Step 3: Show header section ──
   Same three phases as Step 2: preview grows to square, then the header
   grows (enlarging the cards) until --step-header-max-height, then the
   preview absorbs the rest. form-section stays content-sized. */

.container:has(.step[data-step="3"].active) .step-header-above-preview {
    display: flex;
    flex-direction: column;
    flex-grow: var(--flex-priority-high);   /* grows FIRST  → phase 2 */
    flex-shrink: 0;                         /* never compressed below its content */
    flex-basis: auto;                       /* = cards at their min height */
    max-height: var(--step-header-max-height);   /* phase-2 ceiling → releases to preview */
    min-height: min-content;                /* …but never below content (wrapped text on narrow phones) */
    overflow: visible;                      /* chrome fixed; card list scrolls itself */
}

/* ── Why the header needs flex-shrink: 0 (both steps) ──
   .form-section is `flex: 0 0 auto` and never yields a pixel, and the
   preview stops at --preview-min-height. On a short viewport that left
   the header as the ONLY item still able to absorb the deficit, so it got
   compressed past its own content height — and because it's a scroll
   container the lower Best Match card was sliced at the header's bottom
   edge. The preview starts immediately below that edge, so it looked like
   the preview was overlapping the card.

   ⚠️ `min-height: min-content` does NOT fix this. A scroll container's
   min-content size is ZERO in its scrolling axis (its content is
   scrollable, so it contributes nothing to intrinsic height) — and this
   header is a scroll container via `overflow: hidden auto`. So the
   declaration silently resolved to 0, i.e. no floor at all. `flex-shrink: 0`
   is used instead: it forbids shrinking below flex-basis (= content
   height) outright, with no dependence on intrinsic-sizing rules. Same
   idiom as `.form-section`'s `flex: 0 0 auto`.

   The bug was identical on both steps; only Step 2 showed it. Step 2
   carries the pinned-config section (~92px: label + config card + "View
   Other Options" + gaps), so it stops fitting at ~540px of viewport
   height. Step 3's threshold is ~448px, which is BELOW
   .container's `min-height: 480px` — the shell stops shrinking before the
   header can ever be squeezed, so Step 3 was only correct by accident.

   Any deficit beyond the preview's floor now overflows the container's
   bottom edge (clipped by `body { overflow: hidden }`), so the nav row
   clips instead of a card being cut in half. */



.container:has(.step[data-step="3"].active) .preview-section {
    flex-grow: var(--flex-priority-low);      /* grows LAST  → phase 3 */
    flex-shrink: var(--flex-priority-high);   /* shrinks FIRST */
    flex-basis: var(--preview-square-size);   /* square = resting size */
    min-height: var(--preview-min-height);
    max-height: none;
}

.container:has(.step[data-step="3"].active) .form-section { flex: 0 0 auto; display: flex; flex-direction: column; min-height: 0; }

/* Mode A (empty input → preview hidden): grow the form-section so the nav row
   (margin-top: auto on .button-section) re-pins to the viewport bottom. The
   :has(.preview-section.hidden) scope means the FILLED state keeps flex: 0 0 auto
   and the phase-2/phase-3 growth system is untouched. */
.container:has(.step[data-step="2"].active):has(.preview-section.hidden) .form-section,
.container:has(.step[data-step="3"].active):has(.preview-section.hidden) .form-section {
    flex: 1 0 auto;
}

/* Step 2/3 portrait: the inline preview is ALWAYS replaced by the "View
   Diagram" link + popup on phones (html.step23-preview-hidden, toggled by
   formManager.applyStep23PreviewHide() in portrait on Steps 2/3 — every
   layout, every height). Landscape never gets the class. The preview is
   hidden with display:none; the 3D scene keeps rendering and is shown
   full-screen by the popup.
   Vacated height: the header (Best Match cards) grows into it first, up to
   its usual --step-header-max-height cap (flex-grow 200 vs the form-section's
   1). The empty .form-content must NOT absorb it (it did — a ~330px blank
   band above "Recommended Configurations" on tall phones), so whatever the
   capped header leaves goes to the button-section's margin-top: auto, i.e.
   above Next / Back, which stay pinned to the bottom. */
html.step23-preview-hidden .container:has(.step[data-step="2"].active) .preview-section,
html.step23-preview-hidden .container:has(.step[data-step="3"].active) .preview-section {
    display: none;
}

html.step23-preview-hidden .container:has(.step[data-step="2"].active) .form-section,
html.step23-preview-hidden .container:has(.step[data-step="3"].active) .form-section {
    flex: 1 0 auto;
}

html.step23-preview-hidden .container:has(.step[data-step="2"].active) .form-section .form-content,
html.step23-preview-hidden .container:has(.step[data-step="3"].active) .form-section .form-content {
    flex: 0 0 auto;
}

/* Spare height goes ABOVE "Recommended Configurations" (not between the
   links row and Next), so the recommended card + View Other Options /
   View Diagram row sit on the Next / Back stack at the bottom. On Step 3
   and an empty Step 2 that leaves "View Diagram" just above Back instead
   of floating mid-screen. !important + extra specificity beat the Step 2/3
   `*` margin zero-out and the button-section's margin-top: auto. */
html.step23-preview-hidden .container:has(.step[data-step="2"].active) .pinned-config-section,
html.step23-preview-hidden .container:has(.step[data-step="3"].active) .pinned-config-section {
    margin-top: auto !important;
}
html.step23-preview-hidden .container:has(.step[data-step="2"].active) .button-section,
html.step23-preview-hidden .container:has(.step[data-step="3"].active) .button-section {
    margin-top: 0 !important;
}

/* Empty width/depth: Next is normally visibility:hidden (space kept so the
   inline preview doesn't jump when it appears). With no inline preview here
   that reserved slot is just a blank band between "View Diagram" and Back,
   so collapse it; the spare space above the pinned group absorbs the change. */
html.step23-preview-hidden .container:has(.step[data-step="2"].active) .btn-next.is-pending,
html.step23-preview-hidden .container:has(.step[data-step="3"].active) .btn-next.is-pending {
    display: none !important;
}

/* ── "View Diagram" button + popup (Steps 2/3, short portrait phones) ──
   When applyStep23PreviewHide() hides the inline preview (e.g. iPhone SE,
   ~375x470 iframe), this button takes its place above "Recommended
   Configurations". Tapping it adds html.preview-popup-open, which lifts the
   SAME live .preview-section into a full-screen fixed layer — the 3D scene,
   Left/Right-Hinged toggle and callouts all keep working, and main.js's
   ResizeObserver resizes the renderer to the popup. */
.view-diagram-btn {
    display: none;
}

/* "View Other Options" + "View Diagram" share one row (no extra height).
   On very narrow phones (~320px) the two don't fit side by side, so the row
   wraps and "View Diagram" drops to its own line instead of overlapping.
   The s2-08 / s2-09 gap bars move from .view-other-options onto the row, so
   the space before Next stays below BOTH links when they wrap. */
.pinned-links-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    row-gap: var(--space-2);
}
.pinned-links-row .view-other-options {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
}
.container:has(.step[data-step="2"].active) .pinned-links-row,
.container:has(.step[data-step="3"].active) .pinned-links-row {
    border-top: var(--gap-s2-08) solid var(--gap-bar-color);
    border-bottom: var(--gap-s2-09) solid var(--gap-shared-bar-color);
}
.container:has(.step[data-step="2"].active) .pinned-links-row .view-other-options,
.container:has(.step[data-step="3"].active) .pinned-links-row .view-other-options {
    border-top: 0;
    border-bottom: 0;
}

html.step23-preview-hidden .container:has(.step[data-step="2"].active) .view-diagram-btn,
html.step23-preview-hidden .container:has(.step[data-step="3"].active) .view-diagram-btn {
    display: inline-flex;
    flex: none;                 /* undo the global button { flex: 1 } */
    align-items: center;
    gap: 8px;
    width: auto;
    height: auto;
    /* Both edges = config card text inset: the right edge lines up with
       the card text, and when wrapped it starts where "View Other Options"
       starts. */
    padding: 0 calc(10px + var(--border-width)) !important;
    background: transparent;
    border: none;
    font-family: var(--font-family);
    font-size: var(--font-size-body);
    font-weight: var(--weight-body);
    color: var(--color-text);
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.2s;
}
html.step23-preview-hidden .container:has(.step[data-step="2"].active) .view-diagram-btn:hover,
html.step23-preview-hidden .container:has(.step[data-step="3"].active) .view-diagram-btn:hover {
    opacity: 0.7;
}
html.step23-preview-hidden .container:has(.step[data-step="2"].active) .view-diagram-btn svg,
html.step23-preview-hidden .container:has(.step[data-step="3"].active) .view-diagram-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Walk-in (singlepanel): no recommended configuration, so the pinned group
   is "links-only" (formManager.syncEmptyState). Hidden entirely — as before —
   except on portrait Steps 2/3, where it shows just the "View Diagram" link. */
#recommendedConfigGroup.pinned-config--links-only {
    display: none;
}
html.step23-preview-hidden .container:has(.step[data-step="2"].active) #recommendedConfigGroup.pinned-config--links-only,
html.step23-preview-hidden .container:has(.step[data-step="3"].active) #recommendedConfigGroup.pinned-config--links-only {
    display: block;
}
#recommendedConfigGroup.pinned-config--links-only > label,
#recommendedConfigGroup.pinned-config--links-only > .config-card,
#recommendedConfigGroup.pinned-config--links-only > .error-message,
#recommendedConfigGroup.pinned-config--links-only .view-other-options {
    display: none;
}

.preview-popup-close {
    display: none;
}

/* The popup: same element, lifted out of the flow. !important + the
   :has(.step.active) specificity beat the step23-preview-hidden display:none,
   the per-step flex sizing and Step 2/3's `*` padding/margin zero-out. */
html.preview-popup-open .container:has(.step.active) .preview-section {
    display: flex !important;
    flex-direction: column;
    position: fixed;
    inset: 0;
    z-index: 1000;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    padding: 56px var(--padding-page-horizontal) var(--padding-page-horizontal) !important;
    margin: 0 !important;
    border: 0 !important;
    background: var(--color-surface);
}
html.preview-popup-open #canvasFrame {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
}
html.preview-popup-open body {
    overflow: hidden;
}

html.preview-popup-open .preview-popup-close {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 6px;
    position: absolute;
    top: 12px;
    right: var(--padding-page-horizontal);
    height: 32px;
    padding: 0 10px !important;
    background: var(--color-surface);
    color: var(--color-text);
    border: var(--border-width) solid var(--color-card-border);
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: var(--font-size-body);
    font-weight: var(--weight-heading);
    cursor: pointer;
    z-index: 2;
}
html.preview-popup-open .preview-popup-close svg {
    width: 16px;
    height: 16px;
}

.container:has(.step[data-step="3"].active) .form-content { flex: 1 1 auto; overflow: auto; min-height: 0; }
.container:has(.step[data-step="3"].active) .form-content::after { display: block; }
.step[data-step="3"].active { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }

/* ── Step 3: Show/hide header content by step ──
   flex: 1 1 auto passes the header section's growth down to the
   .best-match-list inside (see "Best Match card growth" above). */
#header-step-2, #header-step-3,
#header-step-4, #header-step-5, #header-step-6 { display: none; }
.container:has(.step[data-step="2"].active) #header-step-2 { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.container:has(.step[data-step="3"].active) #header-step-3 { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
/* Steps 4, 5 & 6 — simple fixed-height header (no Best Match cards,
   so no flex-grow/max-height/overflow needed). */
.container:has(.step[data-step="4"].active) #header-step-4,
.container:has(.step[data-step="5"].active) #header-step-5,
.container:has(.step[data-step="6"].active) #header-step-6 {
    display: flex;
    flex-direction: column;
}

/* Show the .step-header-above-preview container for Steps 4, 5 & 6.
   Unlike Steps 2/3 these headers are content-sized (no growth phases). */
.container:has(.step[data-step="4"].active) .step-header-above-preview,
.container:has(.step[data-step="5"].active) .step-header-above-preview,
.container:has(.step[data-step="6"].active) .step-header-above-preview {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

/* ── Step 4 preview sizing ──
   Preview is a FIXED square (flex: 0 1) so it is the same size on Steps
   4, 5 & 6 regardless of the different form-section content heights. It
   can still shrink on short viewports (flex-shrink: 1) down to
   --preview-min-height. The form-section grows (flex: 1 1 auto) to fill
   the leftover space — content at top, nav at bottom via margin-top: auto. */
.container:has(.step[data-step="4"].active) .preview-section {
    flex: 0 1000 var(--preview-square-size-456);  /* shrink priority 1000 — absorbs ALL deficit first */
    min-height: var(--preview-min-height-456);
    max-height: none;
}

.container:has(.step[data-step="4"].active) .form-section {
    flex: 1 1 auto;  /* can shrink on short viewports so the fixing tiles compress instead of clipping the nav row */
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ── Step 5 preview sizing ──
   Same as Step 4: preview is a FIXED square (flex: 0 1) so it matches
   Steps 4 & 6; form-section grows to fill leftover space. The gap between
   the swatches and the nav buttons is the --gap-s5-04 bar. */
.container:has(.step[data-step="5"].active) .preview-section {
    flex: 0 1000 var(--preview-square-size-456);  /* shrink priority 1000 — absorbs ALL deficit first */
    min-height: var(--preview-min-height-456);
    max-height: none;
}

.container:has(.step[data-step="5"].active) .form-section {
    /* flex-shrink 1 vs the preview's 1000: the preview still absorbs the
       deficit first, but once it is at its min-height the form-section can
       shrink too, so an opened "Optional Add-On" scrolls inside .form-content
       (overflow-y: auto) instead of pushing Next / Back below the viewport
       (iPhone SE: nav at 616-704px in a 553px frame, body overflow hidden =
       stuck on Step 5). Was flex-shrink 0. */
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Step 6 — the step indicator shows "🎉 Nice Work!" instead of
   "STEP X OF Y", so override the .step-indicator's text-transform:
   uppercase to preserve the celebratory message's natural casing. */
.container:has(.step[data-step="6"].active) .step-indicator {
    text-transform: none;
}

/* D4 — hide the "🎉 Nice Work!" indicator text on Step 6 only (space
   reserved). The new logo + ready badge replace it visually. */
.container:has(.step[data-step="6"].active) #stepCounter {
    visibility: hidden;
}

/* Step 6 header — same .step-heading structure as Steps 4/5 so the
   header height matches exactly. The "6" circle is display: none (removed
   from the flex flow entirely) so the title centers across the full
   header width. line-height: 26px preserves the row height the circle
   used to provide, matching Steps 4/5's 26px circle. The title wraps
   (white-space: normal) at the standard heading size. */
/* Step 6 header — green "ready" badge replaces the .step-heading
   structure of Steps 4/5. The badge is vertically centered between the
   logo and the summary content: row-gap (s6-09a) equals the gap below
   the badge (s6-02 + s6-03). */
.container:has(.step[data-step="6"].active) #header-step-6 {
    align-items: flex-start;
    row-gap: var(--gap-s6-09a);
}

/* ── Steps 4/5/6 content box ──
   Wraps each step's form-content in a shared fluid height so the
   form-section is constant across Steps 4/5/6 → the preview is identical.
   The vh term makes the box shrink on short viewports (before the
   preview's flex-shrink kicks in); the clamp floor is the box's minimum.
   The box is a flex column so its content can stretch to fill it. */
.container:has(.step[data-step="4"].active) .step-content-box,
.container:has(.step[data-step="5"].active) .step-content-box,
.container:has(.step[data-step="6"].active) .step-content-box {
    height: var(--step-content-box-height-456);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ── Step 4 shrinkable content box + step ──
   Overrides the shared rule above (and the base .step.active flex: 0 0 auto)
   so the fixing tiles can compress on short viewports instead of clipping
   the nav row. The resting size is unchanged (flex-basis = the same clamp
   value); only the ability to shrink is added. Scoped to Step 4 only so
   Steps 5/6 keep their fixed content box. */
.container:has(.step[data-step="4"].active) .step-content-box {
    flex: 1 1 var(--step-content-box-height-456);
    height: auto;
    min-height: 0;
}

.step[data-step="4"].active {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

/* ── Step 4 fixing tiles: square + fixed center gap ──
   The tiles are height-driven (not width-driven): as the content box
   shrinks (via vh), the tiles get shorter → narrower (square). A fixed
   10px gap separates the two tiles; the wrappers split the remaining
   width evenly (flex: 1 1 auto). The caption (inside each wrapper, below
   the button) moves with its tile. */
.container:has(.step[data-step="4"].active) .fixing-buttons {
    flex: 1;
    display: flex;
    align-items: stretch;
    gap: 10px; /* guaranteed gap between the two fixing tiles */
    min-height: 0; /* allow the row (and its buttons) to shrink */
}

.container:has(.step[data-step="4"].active) .fixing-btn-wrapper {
    flex: 1 1 auto;  /* split the row width evenly, minus the 10px gap */
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;   /* allow the wrapper (and its button) to shrink */
}

.container:has(.step[data-step="4"].active) .fixing-btn {
    flex: 0 1 auto;        /* never grows (never taller than wide); can shrink */
    width: 100%;           /* fill wrapper width — stays wide when shrinking */
    aspect-ratio: 1 / 1;   /* preferred square: height = width (the max) */
    min-height: 0;         /* allow the button to shrink below its square → wider-than-tall */
}


/* ══════════════════════════════════════════════════════════════════
   ⚠️ ZERO-OUT (Step 3) — FRAGILE CONSTRAINT, READ BEFORE EDITING.
   This universal `*` rule strips ALL vertical padding and margin from
   every element inside the active step, using !important.
   (a) WHAT IT DOES: resets padding-top/bottom + margin-top/bottom to 0
       so the step's vertical rhythm is driven entirely by the --gap-s3-NN
       border bars (one bar per gap, painted in --gap-bar-color).
   (b) FORBIDDEN: vertical padding and vertical margin CANNOT be used
       anywhere inside this step — the !important zero-out overrides them,
       so any padding/margin you add will silently disappear.
   (c) APPROVED WORKAROUNDS: use borders for vertical spacing (the gap-bar
       pattern) and row-gap for flex/grid children. Internal padding that
       must survive needs its own !important restore rule directly below.
   See docs/STYLING.md for the full gap map.
   ══════════════════════════════════════════════════════════════════ */
.container:has(.step[data-step="3"].active) * {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}
/* Restore internal padding for elements that need it */
.container:has(.step[data-step="3"].active) .button-section button { align-items: center !important; justify-content: center !important; }
.container:has(.step[data-step="3"].active) .view-other-options { padding-top: 0 !important; padding-bottom: 0 !important; }
.container:has(.step[data-step="3"].active) .form-group input { margin-bottom: 0 !important; }
.container:has(.step[data-step="3"].active) .best-match-card { padding-top: 16px !important; padding-bottom: 16px !important; }
.container:has(.step[data-step="3"].active) .best-match-check { margin-top: calc((var(--checkmark-size) - (12px + var(--font-offset))) / -2) !important; }

/* ── Step 3 gap bars (using --gap-s3-NN variables) ──
   Each rule is annotated with its Step 2 counterpart. Step 3 has no
   pinned-config section, so s2-06…s2-09 collapse into the single s3-06
   bar and the trailing numbers shift down by three (s2-10 → s3-07,
   s2-11 → s3-08). Same border-vs-margin caveat as Step 2 applies. */
/* ≡ s2-00 (shared) */
.container:has(.step[data-step="3"].active) .step-indicator { border-top: var(--gap-s3-00) solid var(--gap-shared-bar-color); }
/* ≡ s2-01 (shared) */
.container:has(.step[data-step="3"].active) .step-indicator { margin-bottom: var(--gap-s3-01); border-bottom: var(--gap-s3-01) solid var(--gap-shared-bar-color); }
.container:has(.step[data-step="3"].active) .step-header-above-preview { padding-top: 0; padding-bottom: 0; }
/* ≡ s2-02 (shared) */
.container:has(.step[data-step="3"].active) .step-header-above-preview .step-heading { margin-bottom: var(--gap-s3-02); border-bottom: var(--gap-s3-02) solid var(--gap-shared-bar-color); }
/* ≡ s2-03 */
.container:has(.step[data-step="3"].active) .step-header-above-preview .step-subtitle { margin-bottom: var(--gap-s3-03); border-bottom: var(--gap-s3-03) solid var(--gap-bar-color); }
.container:has(.step[data-step="3"].active) .step-header-above-preview .form-group { margin-bottom: 0; }
/* ≡ s2-04 */
.container:has(.step[data-step="3"].active) .step-header-above-preview .best-match-list { gap: var(--gap-s3-04a); margin-top: var(--gap-s3-04); border-top: var(--gap-s3-04) solid var(--gap-bar-color); }
/* s3-04a — between cards: row-gap (not a border) so each card keeps its own
   2px outline. row-gap is untouched by the zero-out rule, so the gap is still
   driven by the single variable — it just has no debug bar. */
/* ≡ s2-05 */
.container:has(.step[data-step="3"].active) .step-header-above-preview { margin-bottom: var(--gap-s3-05); border-bottom: var(--gap-s3-05) solid var(--gap-bar-color); }
/* Step 3 — the pinned-config section is rendered but its content is
   visibility: hidden (space reserved, not clickable). This keeps the
   form-section height identical to Step 2's real section, so the cards
   and preview split the leftover space identically on both steps. */
.container:has(.step[data-step="3"].active) .pinned-config-section label,
.container:has(.step[data-step="3"].active) .pinned-config-section .config-card,
.container:has(.step[data-step="3"].active) .pinned-config-section .view-other-options,
.container:has(.step[data-step="3"].active) .pinned-config-section .error-message {
    visibility: hidden;
}
/* Step 2 empty — reserve the pinned-config space exactly like Step 3 (label,
   config card, "View Other Options" and error all visibility:hidden) so the
   form-section doesn't collapse to 0 on an empty width and the nav/preview
   don't jump. When a width is entered the list is no longer :empty and the
   real, clickable config shows. */
.container:has(.step[data-step="2"].active):has(#bestMatchList:empty) .pinned-config-section label,
.container:has(.step[data-step="2"].active):has(#bestMatchList:empty) .pinned-config-section .config-card,
.container:has(.step[data-step="2"].active):has(#bestMatchList:empty) .pinned-config-section .view-other-options,
.container:has(.step[data-step="2"].active):has(#bestMatchList:empty) .pinned-config-section .error-message {
    visibility: hidden;
}
.container:has(.step[data-step="3"].active) .button-section { padding-top: 0; padding-bottom: 0; margin-top: auto !important; }
/* s3-07 (shared, ≡ s2-10) above the row = nav buttons → breakdown link.
   s3-08 (shared, ≡ s2-11) below the row = breakdown link → bottom edge. */
.container:has(.step[data-step="3"].active) .breakdown-link-row {
    padding-top: var(--gap-s3-07);    border-top: var(--gap-s3-07) solid var(--gap-shared-bar-color);
    padding-bottom: var(--gap-s3-08); border-bottom: var(--gap-s3-08) solid var(--gap-shared-bar-color);
}


/* ============================================================
   STEP 4 GAP BAR SYSTEM
   ============================================================ */

/* ── Zero-out: strip ALL vertical padding/margin on Step 4 ── */
.container:has(.step[data-step="4"].active) * {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}
/* Restore internal padding for elements that need it */
.container:has(.step[data-step="4"].active) .button-section button { align-items: center !important; justify-content: center !important; }

/* ── Step 4 gap bars (using --gap-s4-NN variables) ──
   Each rule is annotated with its Step 2 counterpart. Step 4 has no
   pinned-config section and no subtitle/input, so s2-02+s2-03 collapse
   into s4-02, and the preview→nav-buttons gap is a single s4-05 bar.
   The fixing-btn→caption gap (s4-04) has no Step 2 counterpart — it is
   specific to the fixing-buttons layout. */

/* ≡ s2-00 (shared) */
.container:has(.step[data-step="4"].active) .step-indicator { border-top: var(--gap-s4-00) solid var(--gap-shared-bar-color); }
/* ≡ s2-01 (shared) */
.container:has(.step[data-step="4"].active) .step-indicator { margin-bottom: var(--gap-s4-01); border-bottom: var(--gap-s4-01) solid var(--gap-shared-bar-color); }
.container:has(.step[data-step="4"].active) .step-header-above-preview { padding-top: 0; padding-bottom: 0; }
/* s4-02 ≡ s2-02 + s2-03 collapsed — heading→preview (no subtitle/input) */
.container:has(.step[data-step="4"].active) .step-header-above-preview { margin-bottom: var(--gap-s4-02); border-bottom: var(--gap-s4-02) solid var(--gap-bar-color); }
/* ≡ s2-05 (preview → form-content) */
.container:has(.step[data-step="4"].active) .preview-section { padding-top: 0; padding-bottom: 0; }
.container:has(.step[data-step="4"].active) .form-content { border-top: var(--gap-s4-03) solid var(--gap-bar-color); overflow: hidden; }
/* s4-04 — fixing button image → caption label (no Step 2 counterpart) */
.container:has(.step[data-step="4"].active) .fixing-btn-caption { border-top: var(--gap-s4-04) solid var(--gap-bar-color); }
/* ≡ s2-09 (shared) — last content → nav buttons.
   Merges form-content pb + button-section pt into one bar. */
.container:has(.step[data-step="4"].active) .button-section { padding-top: 0; padding-bottom: 0; margin-top: auto !important; border-top: var(--gap-s4-05) solid var(--gap-shared-bar-color); }
/* s4-06 (shared, ≡ s2-10) above the row = nav buttons → breakdown link.
   s4-07 (shared, ≡ s2-11) below the row = breakdown link → bottom edge. */
.container:has(.step[data-step="4"].active) .breakdown-link-row {
    padding-top: var(--gap-s4-06);    border-top: var(--gap-s4-06) solid var(--gap-shared-bar-color);
    padding-bottom: var(--gap-s4-07); border-bottom: var(--gap-s4-07) solid var(--gap-shared-bar-color);
}


/* ============================================================
   STEP 5 GAP BAR SYSTEM
   ============================================================ */

/* ── Zero-out: strip ALL vertical padding/margin on Step 5 ── */
.container:has(.step[data-step="5"].active) * {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}
/* Restore internal padding for elements that need it */
.container:has(.step[data-step="5"].active) .button-section button { align-items: center !important; justify-content: center !important; }
/* The Optional Add-On box is a self-contained card with its own border, so it
   keeps its own internal vertical padding (the zero-out above strips it with
   !important). Without this the title sits 2px under the top border and the
   last option row 2px above the bottom border. */
.container:has(.step[data-step="5"].active) .support-addon-box {
    padding-top: var(--card-pad) !important;
    padding-bottom: var(--card-pad) !important;
}

/* ── Step 5 gap bars (using --gap-s5-NN variables) ──
   Each rule is annotated with its Step 2 counterpart. Structurally
   similar to Step 4 — swatches instead of fixing buttons.
   s5-03a covers the gap between the swatch color circle and its label. */

/* ≡ s2-00 (shared) */
.container:has(.step[data-step="5"].active) .step-indicator { border-top: var(--gap-s5-00) solid var(--gap-shared-bar-color); }
/* ≡ s2-01 (shared) */
.container:has(.step[data-step="5"].active) .step-indicator { margin-bottom: var(--gap-s5-01); border-bottom: var(--gap-s5-01) solid var(--gap-shared-bar-color); }
.container:has(.step[data-step="5"].active) .step-header-above-preview { padding-top: 0; padding-bottom: 0; }
/* s5-02 ≡ s2-02 + s2-03 collapsed — heading→preview (no subtitle/input) */
.container:has(.step[data-step="5"].active) .step-header-above-preview { margin-bottom: var(--gap-s5-02); border-bottom: var(--gap-s5-02) solid var(--gap-bar-color); }
/* ≡ s2-05 (preview → form-content) */
.container:has(.step[data-step="5"].active) .preview-section { padding-top: 0; padding-bottom: 0; }
.container:has(.step[data-step="5"].active) .form-content { border-top: var(--gap-s5-03) solid var(--gap-bar-color); }
/* s5-03a — swatch color circle → label text (no Step 2 counterpart) */
.container:has(.step[data-step="5"].active) .swatch-label { border-top: var(--gap-s5-03a) solid var(--gap-bar-color); }
/* s5-03b — swatch group → optional add-on box. The box carries its own
   border, so this gap is a row-gap on the content box (NOT a border-top,
   which would clobber the box's top border). Mirrors Step 6's height:auto +
   scroll: the opted-in box is taller than the 456 content box, so the box
   is content-sized and .form-content scrolls. */
.container:has(.step[data-step="5"].active) .step-content-box {
    height: auto;
    row-gap: var(--gap-s5-03b);
}
/* ≡ s2-09 (shared) — last content → nav buttons */
.container:has(.step[data-step="5"].active) .button-section { padding-top: 0; padding-bottom: 0; margin-top: auto !important; border-top: var(--gap-s5-04) solid var(--gap-shared-bar-color); }
/* s5-05 (shared, ≡ s2-10) above the row = nav buttons → breakdown link.
   s5-06 (shared, ≡ s2-11) below the row = breakdown link → bottom edge. */
.container:has(.step[data-step="5"].active) .breakdown-link-row {
    padding-top: var(--gap-s5-05);    border-top: var(--gap-s5-05) solid var(--gap-shared-bar-color);
    padding-bottom: var(--gap-s5-06); border-bottom: var(--gap-s5-06) solid var(--gap-shared-bar-color);
}

/* ============================================================
   STEP 6 GAP BAR SYSTEM
   ============================================================ */

/* ── Zero-out: strip ALL vertical padding/margin on Step 6 ── */
.container:has(.step[data-step="6"].active) * {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}
/* Restore horizontal padding for summary elements that need it */
.container:has(.step[data-step="6"].active) .button-section button { align-items: center !important; justify-content: center !important; }

/* ── Step 6 gap bars (using --gap-s6-NN variables) ── */
/* ≡ s2-00 (shared) */
.container:has(.step[data-step="6"].active) .step-indicator { border-top: var(--gap-s6-00) solid var(--gap-shared-bar-color); }
/* ≡ s2-01 (shared) */
.container:has(.step[data-step="6"].active) .step-indicator { margin-bottom: var(--gap-s6-01); border-bottom: var(--gap-s6-01) solid var(--gap-shared-bar-color); }
.container:has(.step[data-step="6"].active) .step-header-above-preview { padding-top: 0; padding-bottom: 0; }
/* s6-02 — heading → preview (merged s2-02+s2-03, no subtitle/input) */
.container:has(.step[data-step="6"].active) .step-header-above-preview { margin-bottom: var(--gap-s6-02); border-bottom: var(--gap-s6-02) solid var(--gap-bar-color); }
/* s6-03 — preview → form-content ("Your Summary" heading) */
.container:has(.step[data-step="6"].active) .preview-section { padding-top: 0; padding-bottom: 0; }
.container:has(.step[data-step="6"].active) .form-content { border-top: var(--gap-s6-03) solid var(--gap-bar-color); }
/* Step 6 portrait (preview hidden) - the preview is gone, so s6-02
   (heading -> preview) is retired. s6-03 (24px) becomes the single
   header -> "Your Summary" gap, matching Step 7's s7-01 collapse.
   Keyed off .preview-section.hidden, which on Step 6 only occurs in
   portrait (landscape keeps the preview), so landscape is untouched. */
.container:has(.step[data-step="6"].active):has(.preview-section.hidden) .step-header-above-preview {
    border-bottom-width: 0;
}
/* s6-04 — retired: the heading → table gap is now the step-content-box
   row-gap (s6-09), since the summary is a single block of elements. */
/* s6-05 — retired: the old "Layout row → dims block" gap. The summary is
   now a single .summary-table, so the table → nav gap is s6-06. */

/* Step 6 download card — restore vertical padding (zeroed by the `*` rule
   above). The card is a self-contained component and needs its own padding. */
.container:has(.step[data-step="6"].active) .step6-download-card {
    padding-top: 16px !important;
    padding-bottom: 16px !important;
}

/* Step 6 — table header → first row gap (the `*` rule zeroes margins). */
.container:has(.step[data-step="6"].active) .summary-table-header {
    margin-bottom: var(--gap-s6-09) !important;
}

/* Step 6 — the new summary content (badge + table + buttons + logo + card)
   is taller than the shared 456 content box, so the box is content-sized
   (height: auto) and the form-content scrolls. row-gap spaces the children
   (the `*` rule zeroes padding/margin, not gap). */
.container:has(.step[data-step="6"].active) .step-content-box {
    height: auto;
    row-gap: var(--gap-s6-09);
}
/* s6-06 (shared) — dims block → nav buttons (≡ s2-09) */
.container:has(.step[data-step="6"].active) .button-section { padding-top: 0; padding-bottom: 0; margin-top: auto !important; border-top: var(--gap-s6-06) solid var(--gap-shared-bar-color); }
/* s6-07 (shared, ≡ s2-10) nav buttons → breakdown link.
   s6-08 (shared, ≡ s2-11) breakdown link → bottom edge. */
.container:has(.step[data-step="6"].active) .breakdown-link-row {
    padding-top: var(--gap-s6-07);    border-top: var(--gap-s6-07) solid var(--gap-shared-bar-color);
    padding-bottom: var(--gap-s6-08); border-bottom: var(--gap-s6-08) solid var(--gap-shared-bar-color);
}

/* Step 6 — preview sizing (same as Steps 4/5: fixed square, form-section grows) */
.container:has(.step[data-step="6"].active) .preview-section {
    flex: 0 1000 var(--preview-square-size-456);  /* shrink priority 1000 — absorbs ALL deficit first */
    min-height: var(--preview-min-height-456);
    max-height: none;
}

.container:has(.step[data-step="6"].active) .form-section {
    flex: 1 1 auto;  /* flex-shrink: 0 — never shrinks, so the nav row stays intact while the preview shrinks */
    display: flex;
    flex-direction: column;
    min-height: 0;
}


/* ============================================================
   STEP 7 GAP BAR SYSTEM
   ============================================================ */

/* ── Step 7 visibility rules ──
   No 3D preview on Step 7; step-indicator text is hidden but space
   reserved. Header and pinned-config section are hidden entirely. */
.container:has(.step[data-step="7"].active) .preview-section { display: none; }
.container:has(.step[data-step="7"].active) .step-indicator { color: transparent; }
.container:has(.step[data-step="7"].active) .step-header-above-preview { display: none; }
.container:has(.step[data-step="7"].active) .pinned-config-section { display: none; }
/* Hide breakdown link button on Step 7 (space reserved) */
.container:has(.step[data-step="7"].active) .breakdown-link-row > button { visibility: hidden; }

/* ── Step 7 flex layout ──
   The shopping list grows to fill any leftover vertical space, pushing
   the subheading + body-text + checkout buttons down to sit just above
   the nav row. Same pattern as Step 1's layout buttons. */
.step[data-step="7"].active {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}
/* overflow: auto (NOT hidden) — graceful degradation: when the list
   collapses to 0 at short heights, .form-content becomes the scroll region
   for everything except the nav row (button-section + breakdown-link-row
   stay pinned below). `hidden` here (commit b09c64ac) clipped the disclaimers
   with no scrollbar while scroll-fade still painted a bottom fade — the
   "dead zone". */
.form-content:has(.step[data-step="7"].active) {
    flex: 1 1 auto;
    overflow: auto;
    min-height: 0;
}

.container:has(.step[data-step="7"].active) .shopping-list {
    flex: 1 1 auto;
    min-height: var(--shopping-list-min-height); /* 2 BOM rows — adjustable */
    overflow-y: auto;
    touch-action: auto;
    -webkit-overflow-scrolling: touch;
}

/* Step 7 — when the list can't show its minimum height, it fully expands
   (flex: none; overflow: visible) and .form-content scrolls the whole step
   (everything except nav). Toggled by
   formManager.applyShoppingListScrollFallback(). */
html.step7-list-expanded .container:has(.step[data-step="7"].active) .step[data-step="7"] {
    flex: none;
}
html.step7-list-expanded .container:has(.step[data-step="7"].active) .shopping-list {
    flex: none;
    min-height: 0;
    overflow: visible;
}

/* Step 7 — more than 4 rows: the list shows 4 and scrolls the rest, in
   both layouts above. --shopping-list-max-height is the measured bottom
   of the 4th row, set by formManager.applyShoppingListRowCap(). The
   `html` prefix makes this outrank the step7-list-expanded rule above. */
html .container:has(.step[data-step="7"].active) .shopping-list.is-row-capped {
    max-height: var(--shopping-list-max-height, none);
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* ── Zero-out: strip ALL vertical padding/margin on Step 7 ── */
.container:has(.step[data-step="7"].active) * {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}
/* Restore internal padding for elements that need it */
.container:has(.step[data-step="7"].active) .button-section button { align-items: center !important; justify-content: center !important; }
/* Restore step-indicator vertical padding so the box has visible height
   between --gap-all-00 (top bar) and --gap-all-01 (bottom bar). */
.container:has(.step[data-step="7"].active) .step-indicator {
    padding-top: var(--padding-above-step-indicator) !important;
    padding-bottom: var(--padding-below-step-indicator) !important;
}
/* Restore the shopping-list-item vertical padding (20px above/below each
   item's text) that the zero-out rule strips — it separates the text from
   the divider lines above and below. */
.container:has(.step[data-step="7"].active) .shopping-list-item {
    flex-shrink: 0 !important;
    padding-top: 20px !important;
    padding-bottom: 20px !important;
}
/* The .shopping-list-divider (JS-injected before BOM warnings, inside the
   list) needs NO padding restore: it is a bare 1px line and the warning
   items below it carry their own padding. */

/* ── Step 7 gap bars (using --gap-s7-NN variables) ── */
/* s7-00 (shared, ≡ s2-00) */
.container:has(.step[data-step="7"].active) .step-indicator { border-top: var(--gap-s7-00) solid var(--gap-shared-bar-color); }
/* s7-01b (shared, ≡ s2-01) — bottom of hidden indicator */
.container:has(.step[data-step="7"].active) .step-indicator { margin-bottom: var(--gap-all-01); border-bottom: var(--gap-all-01) solid var(--gap-shared-bar-color); }
/* s7-01 (≡ s2-02 through s2-05 collapsed — no header, no preview) */
.container:has(.step[data-step="7"].active) .form-content { border-top: var(--gap-s7-01) solid var(--gap-bar-color); }
/* s7-01a — logo → title AND title → list (symmetric). The
   .shopping-list-heading wrapper carries the gap as equal border-top and
   border-bottom, so the title is vertically centered between the logo and
   the list regardless of its font size. */
.container:has(.step[data-step="7"].active) .shopping-list-heading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-top: var(--gap-s7-01a) solid var(--gap-bar-color);
    border-bottom: var(--gap-s7-01a) solid var(--gap-bar-color);
}
/* s7-03 — heading → first shopping list item. No bar: the gap is the first
   item's own 20px top padding, so a border here would add a stray second
   line in the middle of that space. */
/* s7-04 — between shopping list items (carried by the item's own border-bottom).
   Uses the real dark divider colour (var(--color-panel-black)) so the between-item lines are
   always visible, not the debug gap-bar colour. */
.container:has(.step[data-step="7"].active) .shopping-list-item { border-bottom: 1px solid var(--color-panel-black); }
/* The last item has no divider under it — borders only between items.
   (0,6,0) beats the (0,5,0) rule above, which would otherwise re-add the
   border that components.css's :last-child rule removes. */
.container:has(.step[data-step="7"].active) .shopping-list-item:last-child { border-bottom: none; }
/* s7-05 — last list item → subheading. No border: the line above "Order
   these products" is not wanted, so the list has no bottom border. */
.container:has(.step[data-step="7"].active) .shopping-list { margin-bottom: var(--gap-s7-05); }
/* s7-06 — subheading → body text */
.container:has(.step[data-step="7"].active) .shopping-subheading { border-bottom: var(--gap-s7-06) solid var(--gap-bar-color); }
/* s7-07 — body text → red button */
.container:has(.step[data-step="7"].active) .shopping-body-text { border-bottom: var(--gap-s7-07) solid var(--gap-bar-color); }
/* s7-08 — red button → small print. Painted as a border-top on the small
   print (NOT a border-bottom on the red button): the button has a fixed
   height (--control-height), so a bottom border would be painted INSIDE
   its box, squeezing the text up while the button box stays the same
   height. A border-top on the following auto-height text element creates
   the gap above it without touching the button. */
.container:has(.step[data-step="7"].active) .shopping-small-print { border-top: var(--gap-s7-08) solid var(--gap-bar-color); }
/* s7-09 — small print → orange button */
.container:has(.step[data-step="7"].active) .shopping-small-print { border-bottom: var(--gap-s7-09) solid var(--gap-bar-color); }
.container:has(.step[data-step="7"].active) .shopping-disclaimers { border-top: var(--gap-s7-11) solid var(--gap-bar-color); }
.container:has(.step[data-step="7"].active) .shopping-disclaimer + .shopping-disclaimer { border-top: var(--gap-s7-12) solid var(--gap-bar-color); }
/* s7-10 — orange button → nav buttons (per-step, ≡ s2-09 position).
   Painted on .button-section's border-top so it never overlaps the
   orange button's own box. */
.container:has(.step[data-step="7"].active) .button-section { padding-top: 0; padding-bottom: 0; margin-top: auto !important; border-top: var(--gap-s7-10) solid var(--gap-bar-color); }
.container:has(.step[data-step="7"].active) .breakdown-link-row {
    padding-top: var(--gap-all-06);    border-top: var(--gap-all-06) solid var(--gap-shared-bar-color);
    padding-bottom: var(--gap-all-07); border-bottom: var(--gap-all-07) solid var(--gap-shared-bar-color);
}


/* --- Responsive (mobile): step-header-above-preview + step h2 ---
   Moved from the trailing @media (max-width: 768px) block in index.html's
   inline <style> block. Kept in THIS file, appended after the base
   .step-header-above-preview and .step h2 rules above, so the mobile
   override still wins the cascade — exactly as when this was the last
   block in one single stylesheet. See css/layout.css for the other half
   of the original @media block
   (.preview-section/.form-content/.button-section/.breakdown-link-row). */
@media (max-width: 768px) {
    .step-header-above-preview {
        /* Only adjust horizontal padding on mobile — using the shorthand
           here would override the vertical spacing variables above. */
        padding-left: var(--padding-page-horizontal);
        padding-right: var(--padding-page-horizontal);
    }

    .step h2 {
        font-size: var(--font-size-heading);
    }
}


