/* ============================================================
   css/layout.css
   Page-shell / structural layout rules extracted from index.html's
   inline <style> block.

   Contains: .container, .preview-section (+ its fade/canvas children),
   .form-section (base), .step-indicator, .form-content (base),
   .button-section (base), .breakdown-link-row (base), bottom-sheet
   shell/scrim, loading overlay.

   Step-specific overrides (the .container:has(.step[data-step="N"].active)
   rules that resize these same elements per step) live in
   css/configurator.css. This file loads BEFORE configurator.css, so the
   base rules here still lose to the later step-specific overrides,
   exactly as before the refactor.
   ============================================================ */

/* --- Generic utility: hide an element (replaces inline style="display:none") --- */
.hidden {
    display: none;
}

/* --- Bottom Sheet Shell + Scrim --- */

.sheet-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease;
    z-index: var(--z-sheet-scrim);
}

.sheet-scrim.open {
    opacity: 1;
    visibility: visible;
}

/* Width and centring match the .container shell exactly — both use
   --shell-width, so the sheet tracks the UI at every viewport size and
   clips evenly on both edges below --app-min-width. The horizontal
   centring is folded into the slide transform so both share one
   transition. */
.bottom-sheet {
    position: fixed;
    left: 50%;
    right: auto;
    bottom: 0;
    width: var(--shell-width);

    background: var(--color-surface);
    border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
    transform: translate(-50%, 100%);
    transition: transform 0.28s ease;

    z-index: var(--z-sheet);
    max-height: 85vh;

    /* Flex column so .sheet-body can fill remaining space and be the
       sole scroll container — keeps handle/header/footer fixed. */
    display: flex;
    flex-direction: column;

    padding: var(--sheet-pad-top) var(--padding-page-horizontal) var(--sheet-pad-bottom-base);
    padding-bottom: calc(var(--sheet-pad-bottom-base) + var(--safe-area-bottom));
}

.bottom-sheet.open {
    transform: translate(-50%, 0);
}


.sheet-handle {
    flex-shrink: 0;
    width: 40px;
    height: 4px;
    background: var(--color-card-border);
    border-radius: var(--border-radius-pill);
    margin: 0 auto var(--sheet-handle-margin-bottom);
}

.sheet-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sheet-header-margin-bottom);
}

.sheet-title {
    font-size: var(--font-size-sheet-title);
    font-weight: var(--weight-sheet-title);
    color: var(--color-text);
}

.sheet-close {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    font-size: var(--font-size-title);
    font-weight: var(--weight-title);
    color: var(--color-text);
    cursor: pointer;
    border-radius: var(--border-radius-pill);
}

.sheet-close:hover {
    background: var(--color-surface-hover);
}

.sheet-subtitle {
    flex-shrink: 0;
    font-size: var(--font-size-heading);
    font-weight: var(--weight-heading);
    color: var(--color-text);
    margin-bottom: var(--sheet-subtitle-margin-bottom);
}

.sheet-body {
    display: flex;
    flex-direction: column;
    gap: var(--sheet-card-gap);
    margin-bottom: var(--sheet-body-margin-bottom);

    /* Scroll container — fills remaining space in the flex-column
       .bottom-sheet. The .scroll-fade class applies mask-image here. */
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.sheet-update-btn {
    flex-shrink: 0;
    width: 100%;
    padding: var(--sheet-update-btn-vert-pad) 10px;
    border: none;
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: var(--font-size-button);
    font-weight: var(--weight-button);
    cursor: pointer;
    transition: background 0.2s;
    /* Near-black background + white text + #000 hover come from the shared
       .btn-primary class (CON-1) — added to the button at build time. */
}

/* .sheet-slot — per-sheet action controls (Update / ‹ Back / footer) injected
   into the shared #sheetTemplate clone. Stacked below the scrollable body. */
.sheet-slot {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.sheet-footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    margin-top: 12px;
    font-size: var(--font-size-caption);
    font-weight: var(--weight-caption);
    color: var(--color-text-secondary);
}

.sheet-footer .info-icon {
    font-size: var(--font-size-body);
    font-weight: var(--weight-body);
    color: var(--color-text-secondary);
}

/* --- App Shell Container --- */

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;      /* fallback for older browsers */
    height: 100dvh;     /* dynamic viewport — excludes mobile browser/system UI */
    min-height: min(480px, 100dvh); /* Prevents layout collapse when window is resized too short
                           on desktop (below ~480px the content can't fit). No mobile
                           device is this short, so this only affects desktop resize.
                           min(480px, 100dvh) caps the floor to the viewport height so
                           sub-480px-tall windows no longer hard-clip the nav by design. */
    width: var(--shell-width);  /* clamp() applies both the max cap and the
                                   min floor; body's flex centres it. */
    flex-shrink: 0;             /* As a flex item it would otherwise be
                                   squeezed below --app-min-width. */

    gap: 0;
    background: var(--color-surface); /* Fills any leftover space when content is
                           shorter than the viewport (e.g. Step 2 Walk-In on tall
                           screens) so nothing bleeds through behind the shell. */
}

/* --- 3D Preview Section --- */
.preview-section {
    flex: 0 1 clamp(0vh, 40vh, 45vh);
    min-height: 0; /* Allow true shrinking when nav needs space */
    background: var(--color-surface); /* White to match form section */
    overflow: hidden;
    position: relative; /* Required for absolute-positioned overlay children */
    padding: 0 var(--padding-page-horizontal); /* Match form-content horizontal padding for consistent width with inputs/buttons */
}

.preview-section.hidden {
    display: none;
}

/* Step-transition fade overlay — covers 3D preview only */
#previewFadeOverlay {
    position: absolute;
    inset: 0;
    background: var(--color-surface); /* Matches the white page background behind the now-transparent canvas */
    opacity: 0;
    pointer-events: none;
    z-index: var(--z-fade); /* Above loading spinner (--z-overlay) */
    transition: opacity 0.5s ease; /* Default; overridden by JS per-transition */
}

/* Outer frame — holds the border/radius so the outline stays visible
   during the inner wrapper's opacity fade. Never fades. */
#canvasFrame {
    width: 100%;
    height: 100%;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--border-radius);
    overflow: hidden;
    /* isolation creates a stacking context, stabilising compositing */
    isolation: isolate;
}

/* Inner wrapper — this is the element that fades in/out during
   step transitions. The canvas lives inside this. */
#canvasWrapper {
    width: 100%;
    height: 100%;
    transition: opacity 0.4s ease;
}

#canvasWrapper canvas {
    display: block;
}

/* --- Form Section --- */
.form-section {
    flex: 1 0 0%;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
    min-height: 0;
}

/* --- Step Indicator --- */
.step-indicator {
    flex: 0 0 auto; /* Fixed height — always visible, never shrinks */
    padding: var(--padding-above-step-indicator) 5px var(--padding-below-step-indicator);

    background: var(--color-surface);
    font-family: var(--font-family);
    font-size: var(--font-size-body);
    font-weight: var(--weight-body);
    letter-spacing: 0px;
    text-transform: uppercase;

    /* Fixed line-height so the "🎉" emoji on Step 6 can't inflate the
       indicator's height — keeps the indicator identical on all steps. */
    line-height: 1.2;

    text-align: center;
    color: var(--color-text);
}

/* --- Form Content (scroll container) --- */
.form-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--padding-below-step-indicator) var(--padding-page-horizontal);
    padding-bottom: var(--padding-form-bottom); /* Extra padding for sticky buttons + mobile UI overlay (Samsung/Android devices) */

    overflow-y: auto;
    min-height: 0; /* Allow flex child to shrink below content height so Step 1 cards scale to fit */

    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* --- Button Section (nav row) --- */
.button-section {
    flex-shrink: 0;
    padding: var(--padding-buttons-top) var(--padding-page-horizontal);

    display: flex;
    gap: 12px;
    align-items: center;

    background: white;
    z-index: var(--z-nav);

    /* Vertical gap between this row and the future-use button row */
    padding-bottom: var(--nav-row-gap);
}

/* Width Breakdown link row — holds the "Click here to see Width Breakdown."
   button and provides guaranteed bottom screen-edge clearance via
   --safe-area-bottom so a phone's system nav bar never covers
   this last row. No media queries or JS needed. */

.breakdown-link-row {
    flex-shrink: 0;
    display: flex;
    gap: 12px;
    padding: 0 var(--padding-page-horizontal);
    padding-bottom: var(--safe-area-bottom);
}

/* --- Loading Overlay --- */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-scene); /* Matches scene background — hides dark canvas until scene renders */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: var(--z-overlay);
    opacity: 1;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(0, 0, 0, 0.15);
    border-top-color: #007bff;
    border-radius: var(--border-radius-pill);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--color-success-dark);
    margin-top: var(--loading-text-margin-top);

    font-size: var(--font-size-subhead);
    font-weight: var(--weight-subhead);
}

/* --- Boot Overlay ---
   Full-screen overlay shown from the very first paint to hide any
   intermediate layout state (orientation class application, font/image
   load) until main.js finishes initial setup and fades it out. Distinct
   from .loading-overlay above, which is a per-preview-rebuild spinner
   scoped to .preview-section (and therefore invisible on Step 1, where
   the preview is hidden). */
.boot-overlay {
    position: fixed;
    inset: 0;
    background: var(--color-surface); /* white — matches body/shell */
    z-index: 10000; /* above --z-sheet (1001) and .loading-overlay (1000) */
    opacity: 1;
    transition: opacity 0.2s ease;
    /* Centre the spinner feedback while the app boots. */
    display: flex;
    justify-content: center;
    align-items: center;
}

.boot-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* --- Responsive (mobile) ---
   Moved from the trailing @media (max-width: 768px) block in index.html's
   inline <style> block. Only re-asserts
   horizontal padding (--padding-page-horizontal) on mobile — the vertical
   padding/gap-bar system for each step is untouched by these rules.

   The original block also had a .step-header-above-preview rule (identical
   declarations) and a .step h2 rule; those two live in css/configurator.css
   instead, appended after THAT file's base rules for those same selectors,
   so the mobile override still wins the cascade exactly as it did when
   everything was one single inline block loaded after all other CSS. */
@media (max-width: 768px) {
    .preview-section {
        padding: 0 var(--padding-page-horizontal);
    }

    .form-content {
        /* 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);
    }

    /* Keep the navigation button area's side padding in sync with
       the form content on mobile (left/right only — preserve the
       vertical padding set on each element). */
    .button-section,
    .breakdown-link-row {
        padding-left: var(--padding-page-horizontal);
        padding-right: var(--padding-page-horizontal);
    }
}


