/* =========================================================================
   Elevator Studio — design system
   Layout: app header → step rail | config panel | full-bleed 3D stage
   All class/ID names consumed by script.js / the Three.js module are kept.
   ========================================================================= */

:root {
    /* ---- palette ---- */
    --ink: #0f172a;
    --text: #1e293b;
    --text-secondary: #475569;
    --muted: #64748b;
    --faint: #94a3b8;
    --border: #e6e9f0;
    --border-strong: #cfd5e1;
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --white: #ffffff;

    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: #eef0ff;
    --accent-ring: rgba(79, 70, 229, 0.28);
    --accent-glow: rgba(79, 70, 229, 0.18);

    --success: #16a34a;
    --success-soft: #e8f7ee;
    --danger: #ef4444;
    --danger-soft: #fdecec;
    --warning: #d97706;
    --overlay: rgba(15, 23, 42, 0.55);

    /* ---- spacing ---- */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;

    /* ---- type ---- */
    --font: "Lato", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
    --font-size-xs: 11px;
    --font-size-sm: 13px;
    --font-size-base: 14px;
    --font-size-md: 15px;
    --font-size-lg: 18px;
    --font-size-xl: 22px;

    /* ---- radius ---- */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --radius-full: 9999px;

    /* ---- elevation ---- */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 4px 12px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 14px 40px rgba(15, 23, 42, 0.14), 0 2px 8px rgba(15, 23, 42, 0.06);
    --shadow-accent: 0 8px 22px rgba(79, 70, 229, 0.30);

    /* ---- layout ---- */
    --header-h: 60px;
    --rail-w: 92px;
    --panel-w: 400px;

    /* ---- stacking ---- */
    --z-stage-ui: 20;
    --z-rail: 30;
    --z-overlay: 1100;
    --z-sidebar: 1201;
    --z-modal: 9999;
    --z-toast: 10000;
}

/* =========================================================================
   Base
   ========================================================================= */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: var(--font-size-base);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button { font-family: inherit; }
img { max-width: 100%; }
h1, h2, h3, h4, p { margin: 0; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Legacy drawer bits (kept in DOM for JS, never shown) */
.hamburger, .close-btn, .overlay, .preview-header[hidden] { display: none !important; }

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 38px;
    padding: 0 16px;
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    font-size: var(--font-size-base);
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease,
    transform 0.18s ease, border-color 0.18s ease;
    user-select: none;
}

.btn:active { transform: translateY(1px); }

.btn-ghost {
    background: var(--surface);
    color: var(--text-secondary);
    border-color: var(--border);
    box-shadow: var(--shadow-xs);
}

.btn-ghost:hover {
    color: var(--text);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
}

.btn-primary,
.preview-header-actions .primary {
    background: linear-gradient(135deg, #5b54f0 0%, var(--accent) 45%, var(--accent-hover) 100%);
    color: #fff;
    box-shadow: var(--shadow-accent);
}

.btn-primary:hover,
.preview-header-actions .primary:hover {
    box-shadow: 0 10px 26px rgba(79, 70, 229, 0.38);
    filter: brightness(1.04);
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

/* =========================================================================
   App header
   ========================================================================= */
.app-header {
    height: var(--header-h);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: var(--space-4);
    padding: 0 var(--space-5);
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: saturate(160%) blur(12px);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: var(--z-rail);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, #6366f1, var(--accent-hover));
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.30);
    flex: 0 0 auto;
}

.brand-name {
    font-weight: 900;
    font-size: 15px;
    letter-spacing: -0.01em;
    color: var(--ink);
    line-height: 1.1;
}

.brand-sub {
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 2px;
}

.build-tag { color: var(--faint); font-size: 10.5px; }

.header-step {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: var(--font-size-sm);
    white-space: nowrap;
}

.header-step-count {
    color: var(--muted);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 10.5px;
}

.header-step-title {
    font-weight: 700;
    color: var(--ink);
}

.header-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* =========================================================================
   App layout
   ========================================================================= */
.app {
    display: grid;
    grid-template-columns: var(--rail-w) 1fr;
    height: calc(100vh - var(--header-h));
    height: calc(100dvh - var(--header-h));
    overflow: hidden;
}

.main {
    display: grid;
    grid-template-columns: var(--panel-w) 1fr;
    min-height: 0;
    overflow: hidden;
}

/* =========================================================================
   Step rail
   ========================================================================= */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 18px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    z-index: var(--z-rail);
}

.sidebar::-webkit-scrollbar { width: 0; }

.tab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 6px 10px;
    border-radius: var(--radius-lg);
    border: 1px solid transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
    cursor: pointer;
    user-select: none;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.tab:hover { background: var(--surface-2); color: var(--text); }

.tab.active {
    background: var(--accent-soft);
    border-color: rgba(79, 70, 229, 0.25);
    color: var(--accent-hover);
    box-shadow: inset 0 0 0 1px rgba(79, 70, 229, 0.12);
}

.tab.active::before {
    content: "";
    position: absolute;
    left: -11px;
    top: 14px;
    bottom: 14px;
    width: 3px;
    border-radius: 3px;
    background: var(--accent);
}

.step-num {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 10px;
    font-weight: 800;
    color: var(--muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    transition: all 0.18s ease;
}

.tab.active .step-num {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.tab.done .step-num {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
    font-size: 0;
}

.tab.done .step-num::after {
    content: "✓";
    font-size: 11px;
    font-weight: 900;
}

.tab .ico {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background-color: var(--surface-2);
    background-position: center;
    background-repeat: no-repeat;
    background-size: 22px 22px;
    border: 1px solid var(--border);
    filter: grayscale(1) contrast(0.9);
    opacity: 0.85;
    transition: all 0.18s ease;
}

.tab:hover .ico { filter: grayscale(0.4); opacity: 1; }

.tab.active .ico {
    background-color: #fff;
    border-color: rgba(79, 70, 229, 0.35);
    filter: none;
    opacity: 1;
    box-shadow: 0 6px 14px rgba(79, 70, 229, 0.18);
}

.tab-label { display: block; max-width: 100%; }

.tab[data-icon="layout"] .ico { background-image: url("images/Frame 46.png"); }
.tab[data-icon="ceiling"] .ico { background-image: url("images/Frame 46-1.png"); }
.tab[data-icon="walls"] .ico { background-image: url("images/Frame 46-2.png"); }
.tab[data-icon="floor"] .ico { background-image: url("images/Frame 46-3.png"); }
.tab[data-icon="door"] .ico { background-image: url("images/Frame 46-4.png"); }
.tab[data-icon="ui"] .ico { background-image: url("images/Frame 46-5.png"); }
.tab[data-icon="accessories"] .ico { background-image: url("images/Frame 46-6.png"); }
.tab[data-icon="gallery"] .ico { background-image: url("images/photo.png"); }

/* =========================================================================
   Config panel
   ========================================================================= */
.config-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.left-pane {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 22px 22px 28px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.left-pane::-webkit-scrollbar { width: 8px; }
.left-pane::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

.panel-footer {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
}

.panel-footer .btn { min-width: 96px; }
.panel-footer .btn-primary { flex: 1; max-width: 240px; }

/* ---- panel typography ---- */
.pane-title {
    font-size: var(--font-size-xl);
    font-weight: 900;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin-bottom: 4px;
}

.section { margin-bottom: 18px; }
.section:last-child { margin-bottom: 0; }

.section > p,
.left-pane > .section p {
    color: var(--muted);
    font-size: var(--font-size-sm);
    line-height: 1.55;
    max-width: 44ch;
}

.section_main { margin-top: 10px; }

.section_style {
    margin-bottom: 18px;
    background: transparent;
    padding: 0;
    border-radius: 0;
}

/* group = card */
.group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-xs);
}

.group + .group { margin-top: 14px; }

.group h3,
.left-pane h3 {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 0 0 12px;
}

.left-pane h3 + .radio-row-new { margin-bottom: 16px; }

.kick-plate-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.kick-plate-header h3 { margin: 0; }

/* Floor tab: header row uses a stronger label */
.section > .kick-plate-header h3 {
    font-size: var(--font-size-md);
    letter-spacing: 0;
    text-transform: none;
    color: var(--text);
    font-weight: 700;
}

/* ---- toggle switch ---- */
.kp-toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 26px;
    flex-shrink: 0;
}

.kp-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.kp-slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background: var(--border-strong);
    border-radius: var(--radius-full);
    transition: background 0.2s ease;
}

.kp-slider::before {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease;
}

.kp-toggle input:checked + .kp-slider { background: var(--accent); }
.kp-toggle input:checked + .kp-slider::before { transform: translateX(18px); }
.kp-toggle input:focus-visible + .kp-slider { box-shadow: 0 0 0 3px var(--accent-ring); }

/* ---- pill tabs → segmented control ---- */
.pill-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    margin: 10px 0 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.pill {
    flex: 1;
    height: 34px;
    border: 0;
    background: transparent;
    border-radius: 9px;
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.18s ease;
}

.pill:hover { color: var(--text); }

.pill.active {
    background: var(--surface);
    color: var(--accent-hover);
    box-shadow: var(--shadow-sm);
}

.pane.hidden { display: none; }

/* a segmented control with a single option is just noise */
.pill-tabs:has(.pill:only-child) { display: none; }

/* ---- selects ---- */
.dd {
    display: block;
    width: 100%;
    height: 42px;
    padding: 0 40px 0 14px;
    font: inherit;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    appearance: none;
    -webkit-appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%2364748b" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>');
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px 16px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.dd:hover { border-color: var(--faint); }
.dd:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* ---- generic selectable tiles ----------------------------------------- */
/* Shared "selected" affordance: accent ring + check badge */
.option-card,
.material,
.chip,
.entrance,
.ceiling.section.group,
.door.section.group {
    position: relative;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease,
    background 0.16s ease;
}

.option-card.active::after,
.material.materialActive::after,
.chip.active::after,
.ceiling.section.group.materialActive::after,
.door.section.group.materialActive::after {
    content: "";
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="3.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>') center/12px 12px no-repeat;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.4), 0 0 0 2px #fff;
    z-index: 1;
}

/* option grid + cards */
.option-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.option-grid.full { display: block; }

.option-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    padding: 10px 8px;
    text-align: center;
}

.option-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-strong); }

.option-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm);
}

.option-card.nostyle {
    background: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    cursor: inherit;
    transform: none !important;
}

.option-card.nostyle::after { display: none; }

.option-card img.img-full { width: 100%; height: auto; border-radius: 10px; display: block; }
.option-card.text-left { text-align: left; }

.option-name {
    margin-top: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.25;
}

.sketch {
    height: 72px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    overflow: hidden;
}

.sketch img { max-height: 56px; width: auto; }
.option-card.active .sketch { background: var(--accent-soft); border-color: rgba(79, 70, 229, 0.25); }

/* Layout: car dimension chips */
.chips {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 104px;
    padding: 14px 8px 12px;
    border-radius: var(--radius-md);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    color: var(--text);
}

.chip:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-strong); }

.chip.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm);
    color: var(--accent-hover);
}

.chip img { width: 56px; height: 40px; object-fit: contain; display: block; }

/* Entrance rows (currently unused content, kept styled) */
.entrance {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

.entrance + .entrance { margin-top: 8px; }
.entrance img { width: 28px; height: 28px; object-fit: contain; }
.entrance.active { background: var(--accent-soft); border-color: var(--accent); }

/* Materials (finish swatches, floors, handrails) */
.material-group { margin-top: 4px; }

.material-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    margin: 6px 0 8px;
}

.material-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.material {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    padding: 6px 6px 8px;
    text-align: center;
}

.material:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-strong); }

.material.materialActive {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm);
}

.material > img,
.material > div:first-child {
    display: block;
    width: 100%;
    height: 78px !important;
    object-fit: cover;
    border-radius: 9px;
    border: 1px solid var(--border) !important;
    background-size: cover;
    background-position: center;
}

.material .name {
    margin-top: 7px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.tile { height: 78px; border: 1px solid var(--border); border-radius: 9px; }
.gold { background-image: url(images/gold_frame.png); }
.steel { background-image: url(images/steel_frame.png); }
#finishOptionsContainer .material { cursor: pointer; }

/* Ceiling / door / button image cards (rendered as .section.group blocks) */
.ceilingWithFanOptionsContainer,
.ceilingWithoutFanOptionsContainer,
.doorOptionsContainer,
.buttonOptionsContainer {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.buttonOptionsContainer { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 16px; }

.ceiling.section.group,
.door.section.group {
    margin: 0;
    padding: 8px;
    border-radius: var(--radius-md);
}

.ceiling.section.group:hover,
.door.section.group:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-strong); }

.ceiling.section.group.materialActive,
.door.section.group.materialActive {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm);
}

.door.section.group .option-card.nostyle { display: flex; flex-direction: column; align-items: center; }
.door.section.group img.img-full { width: auto !important; max-width: 100%; height: 96px !important; object-fit: contain; }
.ceiling.section.group .option-name,
.door.section.group .option-name { text-align: center; }

/* Radio cards */
.radio-row-new { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

.radio-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-weight: 600;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.radio-card:hover { border-color: var(--border-strong); }
.radio-card input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }

.radio-card .control,
.segmented-option .control {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    border: 2px solid var(--border-strong);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s;
    background: #fff;
}

.radio-card .control::after,
.segmented-option .control::after {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    transform: scale(0);
    transition: transform 0.15s ease-in-out;
}

.radio-card:has(input:checked),
.segmented-option:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.radio-card:has(input:checked) .control,
.segmented-option:has(input:checked) .control { border-color: var(--accent); }
.radio-card:has(input:checked) .control::after,
.segmented-option:has(input:checked) .control::after { transform: scale(1); }
.radio-card:has(input:focus-visible),
.segmented-option:has(input:focus-visible) { outline: 2px solid var(--accent-ring); outline-offset: 2px; }

.radio-row { display: flex; flex-direction: column; gap: 8px; }
.radio-column { flex-direction: row; }
.radio-option {
    display: flex; align-items: center; gap: 8px;
    border: 1px solid var(--border); background: var(--surface);
    padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer;
}
.radio-column .radio-option { width: 50%; }
.dot { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-radius: 50%; }
.radio-option.active .dot { background: var(--accent); border-color: var(--accent); }

.segmented-radio {
    display: flex; gap: 8px; padding: 6px; border-radius: var(--radius-md);
    background: var(--surface-2); border: 1px solid var(--border); width: 100%;
}
.segmented-option {
    position: relative; display: flex; width: 50%; align-items: center; gap: 8px;
    padding: 8px 12px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; cursor: pointer; font-size: var(--font-size-sm); font-weight: 600;
    transition: box-shadow 0.15s, border-color 0.15s, background 0.15s;
}
.segmented-option input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }

.dir-grid { display: flex; gap: 12px; margin-top: 8px; }
.dir { display: flex; flex-direction: column; align-items: center; gap: 6px; }

/* Accordions */
.accordion { border-radius: var(--radius-md); background: var(--surface); }
.acc-item { background: var(--surface-2); margin-bottom: 12px; padding: 12px 14px 8px; border-radius: var(--radius-md); }
.acc-head { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.acc-body { padding: 0; display: none; }
.acc-item.open .acc-body { display: block; margin-top: 12px; }
.acc-head .dd-ico {
    width: 20px; height: 20px; flex: 0 0 20px; background-repeat: no-repeat; background-position: center;
    background-size: 16px 16px; color: var(--muted); opacity: .9;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
.acc-item.open .acc-head .dd-ico {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 15l-6-6-6 6'/%3E%3C/svg%3E");
}

/* misc legacy helpers */
.floor-sticky {
    margin-top: 16px; position: sticky; bottom: 8px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: #fff; border-radius: var(--radius-md); padding: 10px 14px; text-align: center;
    cursor: pointer; font-weight: 700; box-shadow: var(--shadow-accent);
}
.select { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); padding: 10px 12px; font-size: var(--font-size-sm); cursor: pointer; }
.caret { font-size: 14px; color: var(--text-secondary); }
.text-align-center { text-align: center; }
.border { border-bottom: 1px solid var(--border); padding: 10px 0; }
.bar { width: 8px; height: 36px; background: var(--border-strong); border-radius: 4px; }
.bar.h { width: 36px; height: 8px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* =========================================================================
   3D stage
   ========================================================================= */
.right-pane {
    position: relative;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(1200px 700px at 60% 30%, #ffffff 0%, rgba(255, 255, 255, 0) 60%),
        linear-gradient(180deg, #f6f7fb 0%, #e9ecf4 100%);
    overflow: hidden;
}

.preview-surface {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
}

.canvas-wrapper {
    position: absolute;
    inset: 0;
}

canvas#three-canvas {
    display: block;
    width: 100%;
    height: 100%;
    outline: none;
    touch-action: none;
}

/* subtle floor plane under the cab */
.preview-surface::before {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 12%;
    width: min(70%, 720px);
    height: 90px;
    transform: translateX(-50%);
    background: radial-gradient(closest-side, rgba(15, 23, 42, 0.10), rgba(15, 23, 42, 0));
    pointer-events: none;
    z-index: 0;
}

/* Back to cabin */
.stage-back {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: var(--z-stage-ui);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 38px;
    padding: 0 14px 0 10px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow);
    color: var(--text);
    font-weight: 700;
    font-size: var(--font-size-sm);
    cursor: pointer;
}

.stage-back:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lg); }

/* Empty-state hint */
.stage-hint {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: var(--z-stage-ui);
    width: min(360px, calc(100% - 48px));
    text-align: center;
    padding: 26px 24px 24px;
    border-radius: var(--radius-xl);
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.9);
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.stage-hint.is-hidden { opacity: 0; transform: translate(-50%, -46%); }

.stage-hint-icon {
    width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 18px;
    display: grid; place-items: center; color: var(--accent);
    background: var(--accent-soft);
}
.stage-hint-title { font-weight: 900; font-size: 16px; color: var(--ink); letter-spacing: -0.01em; }
.stage-hint-text { margin-top: 6px; font-size: var(--font-size-sm); color: var(--muted); line-height: 1.5; }

/* Floating tool rail */
.tool-stack {
    position: absolute;
    right: 16px;
    top: 16px;
    z-index: var(--z-stage-ui);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.tool {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.tool:hover { background: var(--accent-soft); color: var(--accent-hover); }
.tool-sep { width: 22px; height: 1px; background: var(--border); margin: 2px 0; }

/* Design summary card */
.design-summary {
    position: absolute;
    left: 16px;
    bottom: 16px;
    z-index: var(--z-stage-ui);
    width: min(360px, calc(100% - 32px));
    padding: 12px 14px 12px;
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.design-summary-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.design-summary-title {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.design-summary-progress {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent-hover);
    background: var(--accent-soft);
    padding: 3px 8px;
    border-radius: var(--radius-full);
}

.design-summary-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 84px;
    overflow: hidden;
}

.ds-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 4px 9px 4px 7px;
    border-radius: var(--radius-full);
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 11.5px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ds-chip b {
    font-weight: 800;
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.chip-empty { font-size: 12px; color: var(--faint); }

/* Capture gallery drawer (inside stage) */
#gallery-container {
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: min(720px, calc(100% - 32px));
    z-index: calc(var(--z-stage-ui) + 1);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-lg);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
}

#gallery-container.open { max-height: 200px; }

/* peek the bar when closed only if there are captures (JS opens on capture) */
#gallery-bar {
    padding: 10px 14px;
    font-weight: 700;
    font-size: var(--font-size-sm);
    text-align: center;
    cursor: pointer;
    user-select: none;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

#gallery {
    display: flex;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 12px;
    height: 150px;
    gap: 10px;
    scroll-behavior: smooth;
}

.gallery-card { position: relative; flex: 0 0 auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); overflow: hidden; }
.gallery-card img { height: 122px; width: auto; display: block; }
.gallery-card button.del {
    position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border: 0; border-radius: 50%;
    background: rgba(15, 23, 42, 0.75); color: #fff; font-size: 12px; line-height: 22px; cursor: pointer;
}

/* Loading */
#glbProgress {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: var(--z-overlay);
    width: 300px;
    padding: 22px 18px;
    background: rgba(255, 255, 255, 0.96);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.glb-spinner {
    width: 32px; height: 32px; border-radius: 50%;
    border: 3px solid var(--border); border-top-color: var(--accent);
    animation: glb-spin 0.8s linear infinite;
}
@keyframes glb-spin { to { transform: rotate(360deg); } }
.glb-progress-text { font-weight: 700; font-size: var(--font-size-sm); color: var(--text); text-align: center; }

/* Error */
.glb-error-banner {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    z-index: var(--z-overlay);
    display: none; align-items: center; gap: 12px;
    max-width: min(380px, calc(100% - 32px));
    background: #fff; border: 1px solid var(--danger); border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg); padding: 14px 16px;
}
.glb-error-icon { flex: 0 0 22px; width: 22px; height: 22px; border-radius: 50%; background: var(--danger); color: #fff; font-weight: 800; font-size: 13px; display: grid; place-items: center; }
.glb-error-text { flex: 1; font-size: var(--font-size-sm); color: var(--text); line-height: 1.4; }
.glb-retry-btn { flex: 0 0 auto; border: 1px solid var(--danger); background: #fff; color: var(--danger); font-weight: 700; font-size: 12px; padding: 7px 12px; border-radius: var(--radius-sm); cursor: pointer; }
.glb-retry-btn:hover { background: var(--danger); color: #fff; }

/* Toast */
.app-toast {
    position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 12px);
    z-index: var(--z-toast);
    background: var(--ink); color: #fff; font-size: var(--font-size-sm); font-weight: 700;
    padding: 12px 20px; border-radius: var(--radius-full); box-shadow: var(--shadow-lg);
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
    max-width: min(420px, calc(100% - 32px)); text-align: center;
}
.app-toast.show { opacity: 1; transform: translate(-50%, 0); }
.app-toast.toast-success { background: var(--success); }
.app-toast.toast-error { background: var(--danger); }

/* =========================================================================
   Modal
   ========================================================================= */
.modal-overlay {
    position: fixed; inset: 0;
    background: var(--overlay);
    backdrop-filter: blur(4px);
    display: none;
    z-index: var(--z-modal);
}

.modal-box {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 480px; max-width: calc(100vw - 24px);
    background: #fff; border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column; overflow: hidden;
}

.modal-header {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
    padding: 22px 22px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; font-weight: 900; letter-spacing: -0.01em; color: var(--ink); }
.modal-sub { margin-top: 4px; font-size: var(--font-size-sm); color: var(--muted); }
.modal-close {
    flex: 0 0 34px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
    background: var(--surface-2); color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer;
    display: grid; place-items: center;
}
.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body { padding: 18px 22px; overflow-y: auto; max-height: calc(100vh - 220px); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 700; color: var(--text-secondary); margin-bottom: 6px; }
.req { color: var(--danger); }
.form-group input, .form-group textarea {
    width: 100%; padding: 11px 12px; font: inherit; font-size: var(--font-size-base);
    border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: #fff; color: var(--text);
    outline: none; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-group textarea { resize: vertical; min-height: 84px; }
.form-group input:focus, .form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.modal-footer { padding: 14px 22px 22px; }
.primary-btn { width: 100%; height: 44px; font-size: var(--font-size-md); }
.primary-btn:disabled { background: var(--border-strong); box-shadow: none; }

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 1180px) {
    :root { --panel-w: 360px; --rail-w: 84px; }
    .brand-sub { display: none; }
}

@media (max-width: 1024px) {
    .header-step { display: none; }
    .app-header { grid-template-columns: 1fr auto; }
}

/* ---- Tablet & phone: stacked (stage on top, steps, then options) ---- */
@media (max-width: 900px) {
    :root { --header-h: 54px; }

    .app-header { padding: 0 14px; }
    .brand-mark { width: 32px; height: 32px; border-radius: 10px; }
    .brand-name { font-size: 14px; }
    .btn { height: 34px; padding: 0 12px; font-size: 13px; }
    #btnReset span { display: none; }
    #btnReset { width: 34px; padding: 0; }
    #downloadBtn span { display: none; }
    #downloadBtn { width: 34px; padding: 0; }

    .app {
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: 44vh auto minmax(0, 1fr);
        grid-template-areas: "stage" "rail" "panel";
    }

    .main { display: contents; }
    .right-pane { grid-area: stage; }
    .config-panel { grid-area: panel; border-right: 0; border-top: 1px solid var(--border); }

    /* when the option panel is hidden by the app, give the stage the room */
    .app:has(.left-pane.dnone) { grid-template-rows: minmax(0, 1fr) auto 0; }
    .app:has(.left-pane.dnone) .config-panel { display: none; }
    .config-panel:has(.left-pane.dnone) .panel-footer { display: none; }
    .dnone { display: none; }

    /* rail → horizontal step strip */
    .sidebar {
        grid-area: rail;
        flex-direction: row;
        align-items: stretch;
        gap: 6px;
        padding: 8px 10px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        transform: none !important;
        left: auto !important;
        position: relative !important;
        width: 100% !important;
        height: auto !important;
    }

    .tab {
        flex: 0 0 auto;
        flex-direction: row;
        gap: 8px;
        padding: 6px 12px 6px 6px;
        border-radius: var(--radius-full);
        border-color: var(--border);
        font-size: 12px;
        white-space: nowrap;
    }

    .tab.active::before { display: none; }
    .tab .ico { display: none; }
    .step-num { position: static; width: 18px; height: 18px; order: -1; }

    .left-pane { padding: 16px 16px 20px; }
    .panel-footer { padding: 10px 14px; }

    .design-summary { display: none; }
    .stage-hint { width: min(320px, calc(100% - 32px)); padding: 18px 16px; }
    .stage-hint-icon { width: 44px; height: 44px; margin-bottom: 8px; }
    .stage-hint-title { font-size: 14px; }
    .stage-hint-text { font-size: 12px; }

    .tool-stack { right: 10px; top: 10px; padding: 4px; }
    .tool { width: 32px; height: 32px; }
    .stage-back { top: 10px; left: 10px; height: 34px; }
    #gallery-container.open { max-height: 150px; }
    #gallery { height: 104px; }
    .gallery-card img { height: 78px; }

    .material-grid, .option-grid, .chips { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
    .app { grid-template-rows: 40vh auto minmax(0, 1fr); }
    .material-grid, .option-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .buttonOptionsContainer { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .modal-box { width: 100%; max-width: 100%; height: 100%; border-radius: 0; }
    .modal-body { max-height: none; flex: 1; }
    .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .segmented-radio { flex-wrap: wrap; }
    .segmented-option { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation-duration: 0.01ms !important; }
}
