/* Ultra-small / phone portrait optimizations */
@media (max-width: 600px) {
    body { overflow-y: auto; overflow-x: hidden; }
    #step1, .step { flex-direction: column; }
    .step { padding: 0 0.5rem 6.5rem; min-height: unset; }
    /* Center the 'Product selection' title on small devices irrespective of sidebar offsets */
    #step1 .h2-banner h2 { position: relative; left: 50%; transform: translateX(-50%); }
    /* Reserve horizontal space for collapsed sidebars so products are not overlapped */
    #main-content { margin-left: 56px; margin-right: 56px; }
    /* When an overlay sidebar is open, let content span full width behind (interaction disabled anyway) */
    body.sidebar-overlay-active #main-content { margin-left: 0; margin-right: 0; }
    /* MOBILE SIDEBAR MODEL: both collapsed as thin edge bars; expanded => full-screen overlay */
    #price-overview, #system-config {
        top: 0; bottom: 0; height: 100vh; position: fixed; z-index: 2000; overflow-y: auto;
        width: 100vw; border-radius: 0; padding: 0.9rem 1rem 8rem; box-shadow: none;
        transition: transform 0.35s ease, width 0.35s ease; max-width: 100%;
    }
    /* Anchor sides separately so system-config originates from the right */
    #price-overview { left: 0; right: auto; }
    #system-config { right: 0; left: auto; }
    #price-overview.collapsed, #system-config.collapsed {
        width: 46px; padding: 0.4rem 0.25rem; overflow: hidden; cursor: pointer;
    }
    #price-overview.collapsed .sidebar-toggle, #system-config.collapsed .sidebar-toggle {
        width: 100%; height: 44px; display: flex; align-items: center; justify-content: center; padding: 0; margin: 0;
        touch-action: manipulation; -webkit-tap-highlight-color: transparent;
    }
    #price-overview .sidebar-toggle, #system-config .sidebar-toggle { touch-action: manipulation; }
    /* Center arrow above gear icon in collapsed state */
    #price-overview.collapsed .toggle-wrapper,
    #system-config.collapsed .toggle-wrapper { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 0.35rem; height: 100%; width: 100%; }
    #price-overview.collapsed .sidebar-toggle,
    #system-config.collapsed .sidebar-toggle { position: static !important; font-size: 1.45rem; line-height: 1; }
    #price-overview.collapsed .icon-container,
    #system-config.collapsed .icon-container { display: block !important; position: static; margin: 0; width: 28px; height: 28px; }
    #price-overview.collapsed .icon-container svg,
    #system-config.collapsed .icon-container svg { width: 100%; height: 100%; }
    /* Remove previous absolute offsets that misalign arrow */
    #price-overview.collapsed .sidebar-toggle { right: auto !important; left: auto !important; top: auto !important; }
    #system-config.collapsed .sidebar-toggle { left: auto !important; right: auto !important; top: auto !important; }
    /* Expanded overlay: arrows on opposite sides, hide icons */
    #price-overview:not(.collapsed) .toggle-wrapper { position: absolute; top: 0.6rem; right: 0.6rem; left: auto; display: flex; flex-direction: row-reverse; align-items: center; gap: 0.4rem; width: auto; }
    #system-config:not(.collapsed) .toggle-wrapper { position: absolute; top: 0.6rem; left: 0.6rem; right: auto; display: flex; flex-direction: row; align-items: center; gap: 0.4rem; width: auto; }
    #price-overview:not(.collapsed) .sidebar-toggle,
    #system-config:not(.collapsed) .sidebar-toggle { position: static; font-size: 1.55rem; line-height: 1; }
    #price-overview:not(.collapsed) .icon-container,
    #system-config:not(.collapsed) .icon-container { display: none !important; }
    #price-overview.collapsed { left: 0; right: auto; }
    #system-config.collapsed { right: 0; left: auto; }
    /* Slide-in animations */
    #price-overview:not(.collapsed) { animation: slideFromLeft 0.35s ease; }
    #system-config:not(.collapsed) { animation: slideFromRight 0.35s ease; }
    @keyframes slideFromLeft { from { transform: translateX(-30px); opacity: 0.8; } to { transform: translateX(0); opacity: 1; } }
    @keyframes slideFromRight { from { transform: translateX(30px); opacity: 0.8; } to { transform: translateX(0); opacity: 1; } }
    /* Hide internal content when collapsed except toggle + icon */
    #price-overview.collapsed .toggle-wrapper > :not(.sidebar-toggle):not(.icon-container),
    #system-config.collapsed .toggle-wrapper > :not(.sidebar-toggle):not(.icon-container),
    #price-overview.collapsed .config-item,
    #system-config.collapsed .config-item,
    #price-overview.collapsed section,
    #system-config.collapsed .sidebar-header { display: none !important; }
    #price-overview .sidebar-toggle, #system-config .sidebar-toggle { font-size: 1.4rem; }
    #price-overview:not(.collapsed), #system-config:not(.collapsed) { box-shadow: 0 0 0 9999px rgba(12,12,19,0.82); }
    /* Only disable interaction with main content & floating actions, NOT sidebars themselves */
    body.sidebar-overlay-active #main-content,
    body.sidebar-overlay-active #quote-container,
    body.sidebar-overlay-active .total-price { pointer-events: none; }
    body.sidebar-overlay-active #quote-container, body.sidebar-overlay-active .total-price { opacity: 0; }
    /* Keep sidebars interactive */
    #price-overview, #system-config { pointer-events: auto; }
    /* Ensure toggle buttons always clickable above overlay */
    #price-overview .sidebar-toggle, #system-config .sidebar-toggle { position: relative; z-index: 2100; }
    /* Force interactive elements inside expanded sidebars to accept touch/click */
    #price-overview:not(.collapsed) input,
    #price-overview:not(.collapsed) select,
    #price-overview:not(.collapsed) button,
    #system-config:not(.collapsed) input,
    #system-config:not(.collapsed) select,
    #system-config:not(.collapsed) button { pointer-events: auto; touch-action: manipulation; }
    /* Prevent accidental text selection while sliding */
    #price-overview.collapsed, #system-config.collapsed { -webkit-user-select: none; user-select: none; }
    #produkteList { padding: 0.5rem 0.5rem 1.25rem; gap: 1.35rem; max-height: none; -webkit-mask-image: none; mask-image: none; }
    .produkt-block { padding: 1rem 0.85rem 1.1rem; margin: 0; box-shadow: 0 2px 8px rgba(0,0,0,0.25); }
    .produkt-block.cat-mainproduct, .produkt-block.cat-feature { min-height: unset; }
    .product-description { width: 100%; font-size: 13px; }
    .product-price { position: relative; bottom: auto; left: 0; right: 0; width: 100%; margin-top: 0.65rem; }
    .product-subheading { font-size: clamp(0.95rem, 3vw, 1.05rem); }
    .features-controls .product-subheading { font-size: clamp(0.9rem, 2.8vw, 1rem); }
    .control-group, .checkbox-control-group { gap: 0.5rem; padding: 0.55rem; max-width: 100%; }
    .control-group input[type="range"] { max-width: 100%; }
    .features-controls .control-group input[type="range"] { max-width: 140px; }
    .control-group input[type="range"],
    .features-controls .control-group input[type="range"],
    .user-controls input[type="range"],
    .custom-controls input[type="range"] { height: 12px; }
    .control-group input[type="range"]::-webkit-slider-thumb,
    .features-controls .control-group input[type="range"]::-webkit-slider-thumb,
    .user-controls input[type="range"]::-webkit-slider-thumb,
    .custom-controls input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; }
    .control-group input[type="range"]::-moz-range-thumb,
    .features-controls .control-group input[type="range"]::-moz-range-thumb,
    .user-controls input[type="range"]::-moz-range-thumb,
    .custom-controls input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; }
    .transaction-control:not(.hidden) { flex-direction: column; }
    .Icon-block { display: none !important; }
    /* Floating price & quote reposition center bottom */
    .total-price, .quote { left: 50%; transform: translateX(-50%); width: calc(100% - 1.5rem); max-width: 420px; }
    .total-price { bottom: 4.25rem; }
    .quote { bottom: 0.85rem; }
    .step.left-collapsed, .step.right-collapsed { padding-left: 0.5rem; padding-right: 0.5rem; }
}

@media (max-width: 768px) {
    #step1 {
        flex-direction: column;
    }

    #price-overview,
    #system-config {
        width: 80%;
        max-width: 300px;
        top: 0.5rem;
        bottom: var(--sidebar-bottom-gap, 0.5rem);
        height: auto;
        overflow-y: auto;
    }

    #main-content {
        padding-right: 0;
        width: 100%;
    }

    #system-config h2 {
        font-size: clamp(1.1rem, 1.8vw, 1.2rem);
    }

    .step {
        padding-left: 40px;
        padding-right: 40px;
    }

    #toggle-price-overview,
    #toggle-system-config {
        display: block;
    }

    #price-overview.collapsed {
        transform: translateX(calc(-100% + 40px));
    }

    #system-config.collapsed {
        transform: translateX(calc(100% - 40px));
    }

    .config-item select {
        font-size: clamp(0.8rem, 1.2vw, 0.9rem);
    }

    .produkt-block {
        width: 100%;
        max-width: 400px;
        margin: 0.5rem 0;
        padding: 1.2rem 0.8rem 2.5rem;
    }

    #produkteList {
        max-height: calc(100vh - 150px);
        padding: 1.5rem;
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .features-controls {
        grid-template-columns: 1fr;
        gap: 0.2rem;
        width: 100%;
        max-width: 100%;
        padding: 0;
    }

    .features-controls .product-subheading {
        text-align: center;
    }

    .features-controls .product-subheading::after {
        width: 100%;
        left: 0;
    }

    .control-group {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        max-width: 400px;
    }

    .features-controls .control-group {
        max-width: 100%;
        padding: 0.5rem;
    }

    .control-group.transaction-control:not(.hidden) {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
    }

    .control-group .control-description {
        width: 100%;
        text-align: center;
        margin-top: 5px;
        font-size: 12px;
    }

    .user-controls label,
    .custom-controls label {
        text-align: center;
        width: 100%;
    }

    .control-group input[type="range"] {
        width: 80%;
        max-width: 350px;
        height: 8px;
        appearance: none;
    }

    .features-controls .control-group input[type="range"] {
        max-width: 120px;
        background: linear-gradient(to right, var(--colorLeft, #7f85e4) 0%, var(--colorLeft, #7f85e4) var(--value, 0%), #2c2c46 var(--value, 0%), #2c2c46 100%);
    }

    .control-group input[type="range"]::-webkit-slider-thumb {
        -webkit-appearance: none;
        width: 16px;
        height: 16px;
        border-radius: 50%;
        background: #ffffff;
        border: 2px solid var(--colorLeft, #7f85e4);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        cursor: pointer;
    }

    .features-controls .control-group input[type="range"]::-webkit-slider-thumb {
        -webkit-appearance: none;
        width: 16px;
        height: 16px;
        border-radius: 50%;
        background: #ffffff;
        border: 2px solid var(--colorLeft, #7f85e4);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        cursor: pointer;
    }

    .control-group input[type="number"] {
        width: 100%;
        max-width: 120px;
    }

    .features-controls .control-group input[type="number"] {
        width: 50px;
    }

    .control-group span {
        text-align: center;
        width: 100%;
    }

    .user-controls input[type="range"]::-webkit-slider-thumb,
    .custom-controls input[type="range"]::-webkit-slider-thumb {
        width: 16px;
        height: 16px;
    }

    .user-controls input[type="range"].dynamic-slider,
    .custom-controls input[type="range"].dynamic-slider {
        width: 80px;
    }

    .user-controls input[type="range"].dynamic-slider::-webkit-slider-thumb,
    .custom-controls input[type="range"].dynamic-slider::-webkit-slider-thumb {
        width: 8px;
        height: 8px;
    }

    .user-controls input[type="range"].dynamic-slider+input[type="number"],
    .custom-controls input[type="range"].dynamic-slider+input[type="number"] {
        width: 45px;
    }

    .user-controls label:has(+ .control-group input[type="range"].dynamic-slider),
    .custom-controls label:has(+ .control-group input[type="range"].dynamic-slider) {
        font-size: clamp(0.6rem, 1vw, 0.7rem);
    }

    .features-controls .feature-description {
        width: 100%;
        font-size: clamp(0.7rem, 1.1vw, 0.8rem);
    }

    .product-subheading {
        margin: 0.4rem 0 0.2rem;
        padding-bottom: 0.4rem;
        font-size: clamp(1rem, 1.5vw, 1.1rem);
        text-align: center;
    }

    .product-subheading::after {
        width: 100%;
        left: 0;
    }

    .checkbox-control-group {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        max-width: 400px;
    }

    .checkbox-control-group label,
    .checkbox-control-group span {
        text-align: center;
        width: 100%;
    }

    .checkbox-control-group .control-description {
        width: 100%;
        text-align: center;
        margin-top: 5px;
        font-size: 12px;
    }

    .Icon-block {
        display: none !important;
    }

    .produkt-block label {
        margin-top: 0;
        margin-bottom: 1rem;
    }

    .product-description {
        margin-top: 0;
        margin-bottom: 1.5rem;
        width: 90%;
    }
}

@media (min-width: 769px) and (max-width: 1440px) {
    .custom-controls {
        margin-top: 2rem;
    }

    .Icon-block {
        width: 4rem;
        height: 4rem;
    }

    #produkteList {
        grid-template-columns: 1fr;
    }

    #system-config {
        width: 250px;
    }

    .features-controls {
        grid-template-columns: 1fr !important;
        width: 100%;
        max-width: 100%;
        padding: 0;
    }

    .control-group {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 0.75rem;
        max-width: 600px;
    }

    .checkbox-control-group {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        max-width: 100%;
    }

    .features-controls .product-subheading::after {
        width: 100%;
        left: 0;
    }

    .features-controls>div {
        padding: 0.6rem;
        min-height: 180px;
    }

    .features-controls .feature-description {
        font-size: clamp(0.8rem, 1.2vw, 0.9rem);
    }

    .product-subheading {
        margin: 0.5rem 0 0.3rem;
        padding-bottom: 0.45rem;
        font-size: clamp(1.05rem, 1.55vw, 1.15rem);
        text-align: center;
    }

    .product-subheading::after {
        width: 100%;
        left: 0;
    }

    #system-config .sidebar-toggle {
        left: 0.1rem;
    }
    /* Distribute horizontal space evenly between left (price overview) and right (system config) sidebars */
    .step { padding-left: 370px; padding-right: 370px; }
    /* Re-center the step title after symmetric padding */
    #step1 .h2-banner h2 { position: relative; left: 50%; transform: translateX(-50%); }
}

/* Tablet portrait: keep symmetric space for collapsed sidebars as requested */
@media (min-width: 601px) and (max-width: 768px) {
    #main-content { margin-left: 56px; margin-right: 56px; }
}