/* Layout: panel = tylko nawigacja (marker); render = od marker w prawo, pełna szerokość */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

.app-layout {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

.panel {
    width: 90px;
    flex-shrink: 0;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    color: #0f172a;
}

.render {
    flex: 1;
    min-width: 0;
    position: relative;
    background: #111;
}

.render #app {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.render #app canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.config-panel {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 24%;
    min-width: 224px;
    max-width: 320px;
    pointer-events: auto;
    z-index: 10;
}

.configurator {
    height: 100%;
    display: flex;
    overflow: hidden;
}

.config-nav {
    width: 90px;
    background: #0e1118;
    padding: 12px 0 10px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    box-shadow: 0 20px 60px rgba(15, 17, 25, 0.45);
    justify-content: flex-start;
}

.config-nav__item {
    border: none;
    background: transparent;
    color: #c7cbd7;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 0;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
    font-size: 12px;
    flex: 0 0 auto;
    min-height: 60px;
    box-sizing: border-box;
}

.config-nav__item:hover {
    color: #fff;
}

.config-nav__item.active {
    background: linear-gradient(135deg, #16a34a, #15803d);
    color: #fff;
    border-radius: 0 24px 24px 0;
    min-height: 60px;
}

.config-nav__icon {
    width: 26px;
    height: 26px;
    min-width: 26px;
    min-height: 26px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.config-nav__item.active .config-nav__icon {
    background: rgba(255, 255, 255, 0.2);
}

.config-nav__icon svg {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.config-nav__text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 0;
    width: 100%;
    padding: 0 3px;
    box-sizing: border-box;
}

.config-nav__label {
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    line-height: 1.1;
}

.config-nav__hint {
    font-size: 8px;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
    color: #8b92a8;
    max-width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
    hyphens: auto;
}

.config-nav__item.active .config-nav__hint {
    color: rgba(255, 255, 255, 0.9);
}

.config-panel {
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    overflow-y: auto;
    padding: 24px 20px 32px;
    box-shadow: 4px 0 20px rgba(15, 17, 25, 0.08);
}

.config-panel__content {
    position: relative;
}

.config-step {
    margin-bottom: 32px;
}

.config-step__label {
    font-weight: 600;
    font-size: 1rem;
    margin: 0 0 8px 0;
}

.config-step__progress {
    height: 6px;
    background: #e5e7eb;
    border-radius: 100px;
    overflow: hidden;
}

.config-step__progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #16a34a, #15803d);
    border-radius: 100px;
    transition: width 0.25s ease;
}

.config-section {
    padding: 0;
}

.config-section.is-hidden {
    display: none;
}

.config-section h3 {
    font-size: 1.25rem;
    margin: 0 0 8px 0;
}

.config-section p {
    font-size: 0.875rem;
    color: #6b7280;
    margin: 0;
}

/* Form & dimension fields */
.config-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.dimension-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dimension-field .field-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

.dimension-field .unit {
    font-size: 0.75rem;
    color: #9ca3af;
}

.dimension-field .field-hint {
    font-size: 0.85rem;
    line-height: 1.35;
    color: #6b7280;
    margin: 0 0 8px;
}

.dimension-field input[type="range"] {
    width: 100%;
    height: 6px;
    accent-color: #16a34a;
}

.value-input {
    display: flex;
    align-items: center;
    gap: 6px;
}

.value-input input[type="number"] {
    width: 72px;
    padding: 6px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 0.875rem;
}

.value-input .suffix {
    font-size: 0.75rem;
    color: #6b7280;
}

/* Config cards */
.config-card {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 16px;
}

.config-card__header h3 {
    font-size: 1rem;
    margin: 0 0 4px 0;
}

.config-card__header p {
    font-size: 0.8125rem;
    color: #6b7280;
    margin: 0;
}

/* Option grids */
.option-grid {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.option-grid--three {
    grid-template-columns: repeat(3, 1fr);
}

.option-grid--cover {
    grid-template-columns: repeat(2, 1fr);
}

.option-grid--profiles {
    grid-template-columns: 1fr;
}

.option-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 8px;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #374151;
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.option-tile:hover {
    border-color: #d1d5db;
    background: #f9fafb;
}

.option-tile.active,
.option-tile[aria-pressed="true"] {
    border-color: #16a34a;
    background: rgba(22, 163, 74, 0.1);
    color: #15803d;
}

.option-tile__title,
.option-tile__label {
    text-align: center;
    line-height: 1.2;
}

/* Color grid (swatches) */
.color-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

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

.ral-tile {
    border: 2px solid #e5e7eb;
    border-radius: 14px;
    padding: 10px;
    background: #fff;
    text-align: left;
    cursor: pointer;
    display: grid;
    gap: 6px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ral-tile:hover {
    border-color: #cbd5f5;
}

.ral-tile.active,
.ral-tile[aria-pressed="true"] {
    border-color: #16a34a;
    box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.22);
}

.ral-swatch {
    width: 100%;
    height: 48px;
    border-radius: 10px;
    background: #e5e7eb;
}

.ral-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #111827;
}

.ral-code {
    font-size: 0.75rem;
    color: #6b7280;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 2px solid #e5e7eb;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.15s ease;
}

.color-swatch:hover {
    border-color: #9ca3af;
}

.color-swatch.active,
.color-swatch[aria-pressed="true"] {
    border-color: #16a34a;
    box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.22);
}

/* Summary & actions */
.config-summary {
    padding: 12px 0;
    border-top: 1px solid #e5e7eb;
}

.config-summary--inline {
    padding: 10px 0;
}

.config-summary__title {
    font-weight: 600;
    font-size: 0.9375rem;
    margin: 0 0 4px 0;
    color: #0f172a;
}

.config-summary__meta {
    font-size: 0.8125rem;
    color: #6b7280;
    margin: 0;
}

.config-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}

.btn {
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.2s ease, color 0.2s ease;
}

.btn.ghost {
    background: transparent;
    color: #6b7280;
    border: 1px solid #d1d5db;
}

.btn.ghost:hover {
    background: #f3f4f6;
    color: #374151;
}

.btn.primary {
    background: linear-gradient(135deg, #16a34a, #15803d);
    color: #fff;
}

.btn.primary:hover {
    background: linear-gradient(135deg, #22c55e, #15803d);
}

/* Accordion */
.config-accordion {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 16px;
}

.config-accordion__header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #f9fafb;
    border: none;
    font-size: 0.9375rem;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    text-align: left;
}

.config-accordion__header:hover {
    background: #f3f4f6;
}

.config-accordion__caret {
    transition: transform 0.2s ease;
}

.config-accordion[data-open="true"] .config-accordion__caret {
    transform: rotate(90deg);
}

.config-accordion > .config-accordion__body {
    display: none;
    padding: 14px 16px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.config-accordion[data-open="true"] > .config-accordion__body {
    display: block;
}

/* Rozwijane listy (ściana, rozmiar…) są position:absolute — overflow:hidden na akordeonie
   obcinał menu. Te same komponenty co brama (door-add-panel / door-dropdown-*). */
:is(
    .config-section[data-section-panel="brama"],
    .config-section[data-section-panel="drzwi"],
    .config-section[data-section-panel="okna"],
    .config-section[data-section-panel="wiata"]
),
:is(
    .config-section[data-section-panel="brama"],
    .config-section[data-section-panel="drzwi"],
    .config-section[data-section-panel="okna"],
    .config-section[data-section-panel="wiata"]
) .config-accordion,
:is(
    .config-section[data-section-panel="brama"],
    .config-section[data-section-panel="drzwi"],
    .config-section[data-section-panel="okna"],
    .config-section[data-section-panel="wiata"]
) .config-accordion > .config-accordion__body,
.config-section[data-section-panel="brama"] [data-gate-system-gui],
.config-section[data-section-panel="drzwi"] [data-door-system-gui],
.config-section[data-section-panel="okna"] [data-window-system-gui],
.config-section[data-section-panel="wiata"] [data-canopy-list],
:is(
    .config-section[data-section-panel="brama"],
    .config-section[data-section-panel="drzwi"],
    .config-section[data-section-panel="okna"],
    .config-section[data-section-panel="wiata"]
) .door-add-panel,
:is(
    .config-section[data-section-panel="brama"],
    .config-section[data-section-panel="drzwi"],
    .config-section[data-section-panel="okna"],
    .config-section[data-section-panel="wiata"]
) .door-selector-container,
:is(
    .config-section[data-section-panel="brama"],
    .config-section[data-section-panel="drzwi"],
    .config-section[data-section-panel="okna"],
    .config-section[data-section-panel="wiata"]
) .door-dropdown-wrapper {
    overflow: visible !important;
}

/* Menu nad sąsiednimi kontrolkami; panel ma overflow-y:auto — wyższy z-index pomaga warstwowaniu */
:is(
    .config-section[data-section-panel="brama"],
    .config-section[data-section-panel="drzwi"],
    .config-section[data-section-panel="okna"],
    .config-section[data-section-panel="wiata"]
) .door-dropdown-menu.is-open {
    z-index: 80;
}

/* Checkbox & select */
.checkbox-field {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: #374151;
    cursor: pointer;
}

.checkbox-field input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #16a34a;
}

.door-wall-select,
select.door-wall-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 0.875rem;
    margin: 10px 0;
}

.placeholder-card {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}

/* Shared add-element UI (brama/drzwi/okna) */
.door-add-panel {
    width: 100%;
}

.door-selector-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.door-dropdown-wrapper {
    position: relative;
    width: 100%;
    z-index: 2;
}

/* Otwarty dropdown nad kolejnymi wrapperami (inaczej przycisk „rozmiar” zasłania listę „ściana”). */
.door-dropdown-wrapper:has(> .door-dropdown-menu.is-open) {
    z-index: 70;
}

.door-dropdown-button {
    width: 100%;
    min-height: 56px;
    border: 1.5px solid #16a34a;
    border-radius: 16px;
    background: #f8fafc;
    color: #111827;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.door-dropdown-button:hover {
    background: #ffffff;
}

.door-dropdown-button.is-open {
    background: #ffffff;
}

.door-dropdown-button-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.door-dropdown-icon {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #16a34a;
}

.door-dropdown-text {
    font-size: 1.05rem;
    font-weight: 700;
    color: #111827;
}

.door-dropdown-arrow {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #16a34a;
    transition: transform 0.2s ease;
}

.door-dropdown-button.is-open .door-dropdown-arrow {
    transform: rotate(180deg);
}

.door-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    background: #f8fafc;
    border: 1px solid #dbe3ef;
    border-radius: 16px;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.12);
    overflow: hidden;
    z-index: 40;
}

.door-dropdown-menu.is-open {
    display: block;
}

.door-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    cursor: pointer;
    color: #111827;
    background: #f8fafc;
    transition: background 0.2s ease;
}

.door-dropdown-item:hover {
    background: #ffffff;
}

.door-dropdown-item + .door-dropdown-item {
    border-top: 1px solid #e5e7eb;
}

.door-dropdown-item-icon {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
}

.door-dropdown-item-text {
    font-size: 1rem;
    font-weight: 600;
}

.door-add-button {
    width: fit-content;
    min-width: 138px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
    color: #0f172a;
    font-weight: 700;
    font-size: 1.75rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 14px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.door-add-button:hover {
    background: #ffffff;
    border-color: #94a3b8;
}

.door-add-button-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.door-add-button .door-add-button-icon + span {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.15;
}

.placeholder-card h3 {
    margin: 0 0 8px 0;
    font-size: 1.125rem;
}

.placeholder-card p {
    margin: 0;
    font-size: 0.875rem;
    color: #6b7280;
}

/**
 * Mobile: u góry scena 3D, pod nią przewijany formularz, na samym dole pasek kroków (nav).
 * Desktop: panel absolutny po lewej na canvas — bez zmian powyżej 768px.
 */
@media (max-width: 768px) {
    /* Czystszy tap (bez szarej poświaty Safari/Chrome) */
    .config-nav__item,
    .btn,
    .option-tile,
    .ral-tile {
        -webkit-tap-highlight-color: transparent;
    }

    .app-layout {
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
        min-height: 0;
    }

    /* Środek ekranu: scena + formularz — zajmuje przestrzeń nad dolnym paskiem */
    .render {
        width: 100%;
        flex: 1 1 0;
        min-height: 0;
        display: flex;
        flex-direction: column;
        order: 1;
        /* Obcięcie w flex — bez tego iOS często nie liczy wysokości scrolla w dziecku */
        overflow: hidden;
    }

    /* Pasek ikon kroków przy dolnej krawędzi (nie zasłania sceny u góry) */
    .panel {
        width: 100%;
        flex-shrink: 0;
        max-height: none;
        order: 2;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
    }

    .configurator {
        flex-direction: row;
    }

    .config-nav {
        width: 100%;
        min-height: 0;
        flex-direction: row;
        padding: 8px 6px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        justify-content: flex-start;
        gap: 6px;
        box-shadow: 0 -6px 20px rgba(15, 17, 25, 0.4);
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .config-nav__item {
        flex: 0 0 auto;
        min-width: 64px;
        max-width: 76px;
        padding: 8px 4px;
        min-height: 64px;
        border-radius: 12px;
    }

    .config-nav__item.active {
        border-radius: 12px;
        box-shadow: inset 0 3px 0 0 #16a34a;
    }

    @media (prefers-reduced-motion: no-preference) {
        .config-nav__item {
            transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
        }

        .config-nav__item:active {
            transform: scale(0.96);
        }
    }

    .config-nav__text {
        font-size: 10px;
    }

    .config-nav__icon {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
    }

    .config-nav__icon svg {
        width: 18px;
        height: 18px;
        min-width: 18px;
        min-height: 18px;
    }

    /* Scena: większy udział wysokości niż panel formularza (flex reszta → .config-panel) */
    .render #app {
        position: relative;
        flex: 0 0 auto;
        width: 100%;
        height: 48vh;
        min-height: 200px;
        max-height: min(56vh, 480px);
        touch-action: none;
    }

    .render #app canvas {
        touch-action: none;
    }

    /* Formularz między sceną a dolnym nav — przewijany */
    .config-panel {
        position: relative;
        left: auto;
        top: auto;
        right: auto;
        bottom: auto;
        width: 100%;
        min-width: 0;
        max-width: none;
        max-height: none;
        flex: 1 1 0;
        min-height: 0;
        box-sizing: border-box;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        overscroll-behavior-y: contain;
        padding-top: 12px;
        /* Odstęp od krawędzi ekranu (wszystkie zakładki + podsumowanie) */
        padding-left: max(20px, env(safe-area-inset-left, 0px));
        padding-right: max(20px, env(safe-area-inset-right, 0px));
        /* Dolny padding: pasek kroków (~64px+) + safe area + zapas pod „Zapisz” w podsumowaniu */
        padding-bottom: max(88px, calc(env(safe-area-inset-bottom, 0px) + 72px));
        scroll-padding-bottom: max(88px, calc(env(safe-area-inset-bottom, 0px) + 72px));
        box-shadow: none;
        border-top: 1px solid rgba(15, 17, 25, 0.08);
        /* backdrop-filter na scrollowanym bloku psuje przewijanie na Safari/iOS — stałe tło */
        background: rgba(248, 250, 252, 0.97);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .config-panel__content {
        min-height: min-content;
        max-width: 100%;
        box-sizing: border-box;
    }

    #summary-content {
        overflow: visible;
    }

    /* Jedno przewijanie w .config-panel — bez zagnieżdżonego scrolla z soplicaSummaryRender (psuje iOS) */
    #summary-content .planete-summary-body {
        max-height: none !important;
        overflow: visible !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .config-step {
        margin-bottom: 12px;
    }

    .option-grid--three {
        grid-template-columns: repeat(2, 1fr);
    }

    .ral-palette {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .config-actions {
        flex-wrap: wrap;
        justify-content: stretch;
        gap: 8px;
        padding-bottom: 4px;
    }

    .config-actions .btn {
        flex: 1 1 auto;
        min-width: 120px;
    }

    #customer-data-modal .modal-content {
        width: min(100%, 26rem);
        max-height: min(90dvh, 640px);
        padding: 1.1rem;
        margin: 0.5rem;
    }

    #customer-data-modal .modal-footer {
        flex-direction: column-reverse;
        align-items: stretch;
    }

    #customer-data-modal .modal-footer .btn {
        width: 100%;
    }

    .customer-form-postal-row {
        grid-template-columns: 1fr;
    }
}

/* Modal: kod + miasto obok na desktopie */
.customer-form-postal-row {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1rem;
}

/* Bardzo wąskie ekrany: jedna kolumna dla gęstych kafelków */
@media (max-width: 380px) {
    .option-grid--three {
        grid-template-columns: 1fr;
    }
}
