/**
 * Sidecart Mobile Fix
 * Stellt sicher, dass Buttons im Sidecart auf Mobile sichtbar sind
 */

/* === DESKTOP: 4 saubere Sektionen === */
@media (min-width: 769px) {
    html body #wcc-sidecart-container {
        display: flex !important;
        flex-direction: column !important;
    }

    /* SEKTION 1: Header */
    html body #wcc-sidecart-container .wcc-sidecart-header {
        flex-shrink: 0 !important;
    }

    /* SEKTION 2: Produkte (scrollbar) */
    html body #wcc-sidecart-container .wcc-sidecart-section-products {
        flex: 1 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    /* SEKTION 3: Summen (separate Section) */
    html body #wcc-sidecart-container .wcc-sidecart-section-totals {
        flex-shrink: 0 !important;
        background: #f8f9fa !important;
        border-top: 1px solid #e0e0e0 !important;
        border-bottom: 1px solid #e0e0e0 !important;
    }

    /* SEKTION 4: Aktionen */
    html body #wcc-sidecart-container .wcc-sidecart-footer {
        flex-shrink: 0 !important;
        background: #fff !important;
    }
}

/* === MOBILE: Produkte + Summen verschmelzen === */
@media (max-width: 768px) {
    /* Container scrollt selbst - KEINE Child-Scrolls! */
    html body #wcc-sidecart-container {
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        overflow-y: auto !important; /* Container scrollt! */
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* SEKTION 1: Header sticky oben */
    html body #wcc-sidecart-container .wcc-sidecart-header {
        position: sticky !important;
        top: 0 !important;
        z-index: 30 !important;
        background: #fff !important;
        flex-shrink: 0 !important;
    }

    /* SEKTION 1.5: Free Shipping Section sticky unter Header */
    html body #wcc-sidecart-container .wcc-sidecart-section-freeshipping {
        position: sticky !important;
        top: 60px !important; /* Header-Höhe */
        z-index: 25 !important;
        background: #fff !important;
        flex-shrink: 0 !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
    }

    /* Free Shipping Widget Padding */
    html body #wcc-sidecart-container .wcc-sidecart-free-shipping {
        padding: 0px 15px 0px 15px !important;
    }

    /* SEKTION 2+3: Produkte + Summen - NATÜRLICHE Größe, fließen zusammen */
    html body #wcc-sidecart-container .wcc-sidecart-section-products,
    html body #wcc-sidecart-container .wcc-sidecart-section-totals {
        flex: 0 0 auto !important; /* Natürliche Höhe, kein flex-grow! */
        overflow-y: visible !important; /* KEIN eigener Scroll! */
        overflow-x: hidden !important;
        border: none !important;
        background: transparent !important;
        position: relative !important;
        max-height: none !important; /* Keine Höhenbeschränkung */
    }

    /* Products-Content auch auf natürliche Höhe */
    html body #wcc-sidecart-container .wcc-sidecart-content {
        overflow-y: visible !important;
        max-height: none !important;
    }

    /* SEKTION 4: Footer sticky unten */
    html body #wcc-sidecart-container .wcc-sidecart-footer {
        position: sticky !important;
        bottom: 0 !important;
        flex-shrink: 0 !important;
        background: #fff !important;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.15) !important;
        z-index: 30 !important;
    }
    
    /* Totals kompakter auf Mobile */
    html body #wcc-sidecart-container .wcc-sidecart-totals {
        padding: 8px 15px !important;
    }

    html body #wcc-sidecart-container .wcc-sidecart-total-row {
        padding: 4px 0 !important; /* Reduziert von 8px auf 4px */
        margin-bottom: 2px !important; /* Minimaler zusätzlicher Abstand */
    }

    /* Letzter Total-Row (Gesamt) etwas mehr Abstand */
    html body #wcc-sidecart-container .wcc-sidecart-total-row:last-child {
        padding-top: 8px !important;
        margin-top: 6px !important;
        border-top: 1px solid #e0e0e0 !important;
    }
    
    /* Footer Bottom mit Buttons */
    html body #wcc-sidecart-container .wcc-sidecart-footer-bottom {
        padding: 10px 15px 15px !important;
        position: relative !important;
        background: #fff !important;
    }
    
    /* Button Container immer sichtbar */
    html body #wcc-sidecart-container .wcc-sidecart-buttons {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        width: 100% !important;
    }
    
    /* Buttons volle Breite auf Mobile */
    html body #wcc-sidecart-container .wcc-sidecart-btn,
    html body #wcc-sidecart-container .wcc-btn-secondary,
    html body #wcc-sidecart-container .wcc-btn-primary {
        width: 100% !important;
        padding: 14px 20px !important;
        font-size: 15px !important;
        min-height: 48px !important; /* Touch-friendly */
    }
    
    /* Coupon Section kompakter */
    html body #wcc-sidecart-container .wcc-sidecart-coupon-section {
        margin-bottom: 10px !important;
    }
    
    /* Coupon Form responsiv */
    html body #wcc-sidecart-container .wcc-sidecart-coupon-form {
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    html body #wcc-sidecart-container .wcc-sidecart-coupon-input {
        width: 100% !important;
    }
    
    html body #wcc-sidecart-container .wcc-sidecart-coupon-btn {
        width: 100% !important;
    }
    
    /* Merged Coupon auf Mobile trotzdem untereinander */
    html body #wcc-sidecart-container .wcc-sidecart-coupon-merged {
        flex-direction: row !important; /* Behalte nebeneinander wenn gewünscht */
    }
    
    /* Free Shipping Info kompakter */
    html body #wcc-sidecart-container .wcc-free-shipping-info {
        padding: 10px !important;
        margin-bottom: 10px !important;
        font-size: 13px !important;
    }
    
    /* Progress Bar kleiner */
    html body #wcc-sidecart-container .wcc-shipping-progress {
        height: 6px !important;
    }
}

/* Extra kleine Screens (< 375px) */
@media (max-width: 375px) {
    /* Noch kompaktere Abstände */
    html body #wcc-sidecart-container .wcc-sidecart-header {
        padding: 15px !important;
    }
    
    html body #wcc-sidecart-container .wcc-sidecart-title {
        font-size: 16px !important;
    }
    
    html body #wcc-sidecart-container .wcc-sidecart-footer-bottom {
        padding: 10px !important;
    }
    
    html body #wcc-sidecart-container .wcc-sidecart-btn {
        padding: 12px 16px !important;
        font-size: 14px !important;
        min-height: 44px !important;
    }
    
    /* Sidecart width auf kleinen Screens */
    html body #wcc-sidecart-container {
        width: 100% !important;
        right: -100% !important;
    }
    
    html body #wcc-sidecart-container.active {
        right: 0 !important;
    }
}

/* iOS Safari Fix für Footer Position */
@supports (-webkit-touch-callout: none) {
    html body #wcc-sidecart-container {
        height: -webkit-fill-available !important;
        min-height: -webkit-fill-available !important;
    }
    
    html body #wcc-sidecart-container .wcc-sidecart-footer {
        padding-bottom: env(safe-area-inset-bottom) !important;
    }
}

/* Fallback für Browser die dvh nicht unterstützen */
@supports not (height: 100dvh) {
    html body #wcc-sidecart-container {
        height: calc(var(--vh, 1vh) * 100) !important;
    }
}

/* Landscape Mode auf Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    /* Footer bleibt fixiert, kein max-height mehr */
    html body #wcc-sidecart-container .wcc-sidecart-footer {
        /* Kein max-height - Footer soll sich nicht verkleinern */
    }

    /* Body nutzt verfügbaren Platz */
    html body #wcc-sidecart-container .wcc-sidecart-body {
        flex: 1 !important;
        /* Kein max-height - flex regelt die Höhe automatisch */
    }
}

/* Debug: Zeige Scrollbar NUR für Body auf Mobile für bessere UX */
@media (max-width: 768px) {
    /* NUR Body hat Scrollbar - Footer scrollt nicht */
    html body #wcc-sidecart-container .wcc-sidecart-body::-webkit-scrollbar {
        width: 4px !important;
    }

    html body #wcc-sidecart-container .wcc-sidecart-body::-webkit-scrollbar-track {
        background: #f1f1f1 !important;
    }

    html body #wcc-sidecart-container .wcc-sidecart-body::-webkit-scrollbar-thumb {
        background: #888 !important;
        border-radius: 2px !important;
    }

    /* Footer hat KEINE Scrollbar */
    html body #wcc-sidecart-container .wcc-sidecart-footer {
        scrollbar-width: none !important; /* Firefox */
    }

    html body #wcc-sidecart-container .wcc-sidecart-footer::-webkit-scrollbar {
        display: none !important; /* Chrome/Safari */
    }
}