/* ============================================================
   Konfigurator Markiz — arkusz stylów
   Estetyka Panelu Klienta Wingrow: czerń/biel + akcent klienta
   (--accent nadpisywany z katalogu / brandingu po resolve).
   Desktop: viewport + sidebar. Mobile: viewport u góry,
   panel jako bottom sheet (peek / half / full).
   ============================================================ */

:root {
    --accent: #e87722;
    --ink: #17181a;
    --ink-soft: #4b4d50;
    --ink-mute: #8b8e91;
    --paper: #f5f5f3;
    --surface: #ffffff;
    --line: #e6e6e3;
    --line-strong: #d2d2cf;
    --danger: #c0392b;

    --font-display: 'Geist', ui-sans-serif, system-ui, sans-serif;
    --font-body: 'Manrope', -apple-system, sans-serif;

    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 18px;

    --shadow-soft: 0 2px 14px rgba(20, 22, 24, 0.07);
    --shadow-pop: 0 10px 34px rgba(20, 22, 24, 0.16);

    --topbar-h: 58px;
    --panel-w: 424px;
}

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

html, body {
    height: 100%;
    overscroll-behavior: none;
}

body {
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

button {
    font-family: inherit;
    border: none;
    background: none;
    color: inherit;
    cursor: pointer;
}

.app {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============================================================
   TOPBAR
   ============================================================ */

.topbar {
    height: var(--topbar-h);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    z-index: 30;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 {
    font-family: var(--font-display);
    font-size: 21px;
    font-weight: 600;
    letter-spacing: 0.01em;
}
.brand .client-logo { max-height: 34px; max-width: 150px; object-fit: contain; }
.brand-divider { width: 1px; height: 22px; background: var(--line-strong); }
.brand-sub { font-size: 13px; color: var(--ink-mute); font-weight: 600; letter-spacing: 0.02em; }
.topbar-note { font-size: 12.5px; color: var(--ink-mute); }

/* ============================================================
   LAYOUT
   ============================================================ */

.layout {
    flex: 1;
    display: flex;
    min-height: 0;
    position: relative;
}

/* ============================================================
   VIEWPORT 3D
   ============================================================ */

.viewport {
    flex: 1;
    position: relative;
    min-width: 0;
    background: #dde2e4;
}

#canvas-container { position: absolute; inset: 0; }
#canvas-container canvas { width: 100%; height: 100%; display: block; touch-action: none; }

.viewport-vignette {
    position: absolute; inset: 0;
    pointer-events: none;
    box-shadow: inset 0 0 120px rgba(20, 24, 28, 0.14);
}

.viewport-hint {
    position: absolute;
    top: 18px; left: 50%;
    transform: translateX(-50%);
    background: rgba(23, 24, 26, 0.72);
    color: #fff;
    font-size: 12.5px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 100px;
    backdrop-filter: blur(6px);
    transition: opacity 0.5s;
    pointer-events: none;
    white-space: nowrap;
    max-width: calc(100% - 32px);
    overflow: hidden;
    text-overflow: ellipsis;
}
.viewport-hint.is-hidden { opacity: 0; }

/* dzień / noc */
.night-toggle {
    position: absolute;
    top: 16px; left: 16px;
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: var(--shadow-soft);
    display: grid;
    place-items: center;
    transition: background 0.3s, color 0.3s;
}
.night-toggle svg { width: 21px; height: 21px; position: absolute; transition: opacity 0.3s, transform 0.4s; }
.night-toggle .ico-moon { opacity: 0; transform: rotate(-40deg) scale(0.7); }
.night-toggle.is-night { background: #232830; color: #f4e8c8; }
.night-toggle.is-night .ico-sun { opacity: 0; transform: rotate(40deg) scale(0.7); }
.night-toggle.is-night .ico-moon { opacity: 1; transform: none; }

/* rozwinięcie */
.ext-controls {
    position: absolute;
    left: 50%; bottom: 20px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: min(340px, calc(100% - 40px));
}
.ext-btn {
    background: var(--surface);
    font-size: 13px;
    font-weight: 700;
    padding: 9px 20px;
    border-radius: 100px;
    box-shadow: var(--shadow-soft);
    transition: transform 0.15s;
}
.ext-btn:active { transform: scale(0.96); }
#extSlider { width: 100%; }

/* ============================================================
   PANEL KONFIGURACJI
   ============================================================ */

.panel {
    width: var(--panel-w);
    flex: 0 0 auto;
    background: var(--surface);
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    min-height: 0;
    z-index: 20;
}

.sheet-handle { display: none; }

.section-nav {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    overflow-x: auto;
    scrollbar-width: none;
    border-bottom: 1px solid var(--line);
}
.section-nav::-webkit-scrollbar { display: none; }

.nav-chip {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--ink-mute);
    padding: 7px 12px;
    border-radius: 100px;
    border: 1px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}
.nav-num { font-size: 10.5px; opacity: 0.7; }
.nav-chip:hover { color: var(--ink); }
.nav-chip.is-active {
    color: var(--ink);
    border-color: var(--line-strong);
    background: var(--paper);
}

.panel-track {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 22px 30px;
    scroll-behavior: smooth;
}

.cfg-section {
    padding: 26px 0 30px;
    border-bottom: 1px solid var(--line);
    scroll-margin-top: 8px;
}
.cfg-section:last-child { border-bottom: none; }

.section-title {
    font-family: var(--font-display);
    font-size: 21px;
    font-weight: 600;
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 6px;
}
.section-num {
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: 0.08em;
}
.section-lead {
    font-size: 13px;
    color: var(--ink-soft);
    line-height: 1.55;
    margin-bottom: 18px;
}

.field-label {
    display: block;
    font-size: 11.5px;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--ink-mute);
    margin: 20px 0 10px;
}
.field-label:first-of-type { margin-top: 0; }

.hint { font-size: 12px; color: var(--ink-mute); line-height: 1.5; margin-top: 8px; }

/* ============================================================
   KARTY OPCJI
   ============================================================ */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 10px;
}
.card-grid.cols-1 { grid-template-columns: 1fr; }

.option-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
    background: var(--paper);
    border: 1.5px solid var(--line);
    border-radius: var(--r-md);
    text-align: left;
    transition: border-color 0.2s, background 0.2s, transform 0.12s;
}
.option-card:hover { border-color: var(--line-strong); }
.option-card:active { transform: scale(0.985); }
.option-card.is-selected {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}
.option-card.is-selected::after {
    content: '';
    position: absolute;
    top: 10px; right: 10px;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent);
}
.option-card:disabled { opacity: 0.38; cursor: not-allowed; }
.option-card.is-row { flex-direction: row; align-items: center; }

.product-glyph { width: 62px; color: var(--ink-soft); }
.product-glyph svg { width: 100%; }
.option-card.is-selected .product-glyph { color: var(--accent); }
.drive-icon { width: 38px; height: 38px; flex: 0 0 auto; color: var(--ink-soft); }
.drive-icon svg { width: 100%; height: 100%; }
.option-card.is-selected .drive-icon { color: var(--accent); }

.card-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card-title { font-size: 13.5px; font-weight: 700; }
.card-sub { font-size: 11.5px; color: var(--ink-mute); line-height: 1.45; }

/* ============================================================
   CHIPY / SEGMENTED / SUWAKI
   ============================================================ */

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
    font-size: 12.5px;
    font-weight: 700;
    padding: 8px 14px;
    border-radius: 100px;
    border: 1.5px solid var(--line);
    background: var(--paper);
    transition: all 0.18s;
}
.chip:hover:not(:disabled) { border-color: var(--line-strong); }
.chip.is-selected { border-color: var(--accent); background: var(--accent); color: #fff; }
.chip:disabled { opacity: 0.32; cursor: not-allowed; text-decoration: line-through; }

.segmented {
    display: inline-flex;
    background: var(--paper);
    border: 1.5px solid var(--line);
    border-radius: 100px;
    padding: 3px;
    gap: 2px;
}
.segmented button {
    font-size: 13px;
    font-weight: 700;
    padding: 8px 18px;
    border-radius: 100px;
    color: var(--ink-soft);
    transition: all 0.18s;
}
.segmented button.is-selected { background: var(--ink); color: #fff; }
.segmented button:disabled { opacity: 0.32; cursor: not-allowed; }

.dim-control { margin-bottom: 18px; }
.dim-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}
.dim-name { font-size: 13px; font-weight: 700; }
.dim-value { font-size: 14px; font-weight: 800; color: var(--accent); }
.dim-value input {
    width: 64px;
    font: inherit;
    color: inherit;
    border: none;
    border-bottom: 1.5px solid var(--line-strong);
    background: none;
    text-align: right;
    outline: none;
}
.dim-value input:focus { border-color: var(--accent); }
.dim-range {
    display: flex;
    justify-content: space-between;
    font-size: 10.5px;
    color: var(--ink-mute);
    margin-top: 5px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 4px;
    background: var(--line-strong);
    outline: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--accent);
    box-shadow: 0 1px 6px rgba(0,0,0,0.18);
    cursor: grab;
}
input[type="range"]::-moz-range-thumb {
    width: 20px; height: 20px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--accent);
    box-shadow: 0 1px 6px rgba(0,0,0,0.18);
    cursor: grab;
}

/* ============================================================
   SWATCHE
   ============================================================ */

.swatch-row { display: flex; flex-wrap: wrap; gap: 12px; }

.swatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    width: 66px;
}
.swatch-dot {
    width: 44px; height: 44px;
    border-radius: 50%;
    border: 2px solid var(--line);
    box-shadow: inset 0 0 0 3px var(--surface);
    transition: all 0.18s;
}
.swatch:hover .swatch-dot { border-color: var(--line-strong); }
.swatch.is-selected .swatch-dot { border-color: var(--accent); }
.swatch-name { font-size: 10.5px; font-weight: 700; color: var(--ink-soft); text-align: center; }
.swatch.is-selected .swatch-name { color: var(--ink); }
.swatch.is-disabled { opacity: 0.28; pointer-events: none; }

.fabric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 10px;
    margin-top: 14px;
}
.fabric-swatch {
    display: flex;
    flex-direction: column;
    border: 1.5px solid var(--line);
    border-radius: var(--r-md);
    overflow: hidden;
    background: var(--surface);
    transition: border-color 0.18s, transform 0.12s;
}
.fabric-swatch:hover { border-color: var(--line-strong); }
.fabric-swatch:active { transform: scale(0.97); }
.fabric-swatch.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.fabric-thumb {
    height: 58px;
    background-size: 76px;
    background-position: center;
}
.fabric-meta {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 7px 9px;
    text-align: left;
}
.fabric-name { font-size: 11px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fabric-uv { font-size: 9.5px; font-weight: 700; color: var(--ink-mute); letter-spacing: 0.03em; }

/* ============================================================
   TOGGLE
   ============================================================ */

.toggle-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    margin-top: 12px;
    background: var(--paper);
    border: 1.5px solid var(--line);
    border-radius: var(--r-md);
    cursor: pointer;
    transition: opacity 0.2s;
}
.toggle-row.is-disabled { opacity: 0.42; pointer-events: none; }
.toggle-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.toggle-title { font-size: 13.5px; font-weight: 700; }
.toggle-sub { font-size: 11.5px; color: var(--ink-mute); line-height: 1.45; }
.toggle-row input { display: none; }
.toggle-pill {
    flex: 0 0 auto;
    width: 44px; height: 26px;
    border-radius: 100px;
    background: var(--line-strong);
    position: relative;
    transition: background 0.2s;
}
.toggle-pill::after {
    content: '';
    position: absolute;
    top: 3px; left: 3px;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    transition: transform 0.2s;
}
.toggle-row input:checked + .toggle-pill { background: var(--accent); }
.toggle-row input:checked + .toggle-pill::after { transform: translateX(18px); }

/* ============================================================
   PODSUMOWANIE / CENA
   ============================================================ */

.summary-block {
    background: var(--paper);
    border-radius: var(--r-md);
    padding: 6px 16px;
    margin-bottom: 14px;
}
.summary-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
    font-size: 12.5px;
}
.summary-row:last-child { border-bottom: none; }
.s-label { color: var(--ink-mute); font-weight: 600; flex: 0 0 auto; }
.s-value { font-weight: 700; text-align: right; }

.price-block { margin-bottom: 14px; }
.price-line {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 0;
    font-size: 12.5px;
    border-bottom: 1px dashed var(--line);
}
.price-line.is-total {
    border-bottom: none;
    font-size: 15px;
    font-weight: 800;
    padding-top: 12px;
}
.p-label { color: var(--ink-soft); }
.p-value { font-weight: 700; }

.quote-note {
    background: color-mix(in srgb, var(--accent) 7%, var(--surface));
    border: 1.5px solid color-mix(in srgb, var(--accent) 30%, var(--line));
    border-radius: var(--r-md);
    padding: 14px 16px;
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--ink-soft);
}
.quote-note strong { color: var(--ink); }

.next-steps {
    margin-top: 16px;
    padding: 14px 16px;
    background: var(--paper);
    border-radius: var(--r-md);
    font-size: 12px;
    line-height: 1.6;
    color: var(--ink-soft);
}

/* ============================================================
   CTA BAR
   ============================================================ */

.ctabar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 22px calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--surface);
}
.cta-price { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.cta-caption { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-mute); }
.cta-value { font-size: 17px; font-weight: 800; }
.cta-value.is-quote { font-size: 14px; }

.btn {
    font-size: 14px;
    font-weight: 800;
    padding: 13px 26px;
    border-radius: var(--r-md);
    transition: transform 0.12s, box-shadow 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: var(--ink);
    color: #fff;
    box-shadow: var(--shadow-soft);
}
.btn-primary:hover { box-shadow: var(--shadow-pop); }
.btn-primary:disabled { opacity: 0.6; }

/* ============================================================
   TOAST
   ============================================================ */

.toast {
    position: fixed;
    left: 50%; bottom: 28px;
    transform: translate(-50%, 16px);
    background: rgba(23, 24, 26, 0.92);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 11px 20px;
    border-radius: 100px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 90;
    max-width: calc(100% - 40px);
    text-align: center;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ============================================================
   MODAL
   ============================================================ */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 22, 24, 0.5);
    backdrop-filter: blur(4px);
    display: grid;
    place-items: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
    z-index: 100;
}
.modal-backdrop.is-open { opacity: 1; pointer-events: auto; }

.modal {
    width: min(560px, 100%);
    max-height: min(86dvh, 780px);
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--r-lg);
    padding: 26px;
    box-shadow: var(--shadow-pop);
    transform: translateY(14px);
    transition: transform 0.3s;
}
.modal-backdrop.is-open .modal { transform: none; }

.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { font-family: var(--font-display); font-size: 23px; font-weight: 600; }
.modal-close { font-size: 26px; color: var(--ink-mute); line-height: 1; padding: 4px 8px; }
.modal-sub { font-size: 13px; color: var(--ink-soft); margin: 6px 0 16px; }
.modal-summary {
    background: var(--paper);
    border-radius: var(--r-md);
    padding: 13px 16px;
    font-size: 12.5px;
    line-height: 1.6;
    margin-bottom: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.span-2 { grid-column: span 2; }
.form-field label { font-size: 11.5px; font-weight: 800; color: var(--ink-soft); }
.form-field input,
.form-field select {
    font: inherit;
    font-size: 14px;
    padding: 11px 13px;
    border: 1.5px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface);
    outline: none;
    transition: border-color 0.2s;
}
.form-field input:focus,
.form-field select:focus { border-color: var(--accent); }
.form-check {
    grid-column: span 2;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: 12px;
    color: var(--ink-soft);
    cursor: pointer;
}
.form-check input { margin-top: 2px; accent-color: var(--accent); }

/* ============================================================
   MOBILE — bottom sheet
   ============================================================ */

@media (max-width: 899px) {
    .topbar { padding: 0 16px; }
    .topbar-note { display: none; }

    .layout { flex-direction: column; }

    .viewport {
        flex: 1;
        min-height: 0;
    }

    /* panel = bottom sheet */
    .panel {
        position: absolute;
        left: 0; right: 0; bottom: 0;
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--line);
        border-radius: 18px 18px 0 0;
        box-shadow: 0 -8px 30px rgba(20, 22, 24, 0.14);
        transition: height 0.32s cubic-bezier(0.32, 0.72, 0.28, 1);
    }
    .panel[data-sheet="peek"] { height: 148px; }
    .panel[data-sheet="half"] { height: 48dvh; }
    .panel[data-sheet="full"] { height: calc(100dvh - var(--topbar-h) - 10px); }

    .sheet-handle {
        display: grid;
        place-items: center;
        padding: 10px 0 2px;
        touch-action: none;
        cursor: grab;
    }
    .sheet-handle span {
        width: 44px; height: 5px;
        border-radius: 100px;
        background: var(--line-strong);
    }

    .section-nav { padding: 8px 12px; }
    .panel-track { padding: 4px 16px 20px; }
    .cfg-section { padding: 20px 0 24px; }

    .ext-controls { bottom: auto; top: 60px; right: 12px; left: auto; transform: none; width: 150px; }
    .viewport-hint { top: 14px; font-size: 11px; }
    .night-toggle { top: 56px; left: 12px; width: 40px; height: 40px; }
    .ext-btn { font-size: 11.5px; padding: 8px 14px; }

    .card-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
    .ctabar { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
    .btn { padding: 12px 20px; font-size: 13px; }
}

@media (max-width: 420px) {
    .brand-sub { display: none; }
    .brand-divider { display: none; }
    .fabric-grid { grid-template-columns: repeat(3, 1fr); }
}
