/* Cart Drawer Styles */
#cartDrawerOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#cartDrawerOverlay.show {
    opacity: 1;
    visibility: visible;
}

#cartDrawer {
    position: fixed;
    z-index: 1050;
    background: #fff;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

#cartDrawer.show {
    transform: translate(0, 0) !important;
}

/* Close Button */
.btn-close-drawer {
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-close-drawer:hover {
    transform: rotate(90deg);
}

/* Header */
.drawer-header {
    flex-shrink: 0;
    /* Ensure it doesn't get squished */
    z-index: 20;
    background: #fff;
    /* Fix overlap on iOS */
    padding-top: max(1rem, env(safe-area-inset-top, 1rem)) !important;
}

/* Cart Items Container */
#cartDrawerItems {
    flex: 1;
    min-height: 0;
    /* Critical for Flex scrolling */
    overflow-y: auto;
    overflow-x: hidden;
    /* Prevent horizontal scroll */
    padding: 1.5rem;
    overscroll-behavior: contain;
    /* Prevent scroll chaining */
    touch-action: pan-y;
    /* Improve touch handling */
    outline: none;
    /* Remove blue highlight on focus */
}

/* Single Cart Item */
.drawer-item {
    display: flex;
    padding-bottom: 1.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid #f0f0f0;
    animation: fadeIn 0.3s ease;
}

.drawer-item img {
    border-radius: 4px;
    background-color: #f8f9fa;
    object-fit: cover;
    /* Fix distortion */
    aspect-ratio: 1/1.2;
    /* Maintain consistent ratio */
}

/* Specs Container */
.drawer-item-specs {
    font-size: 0.85rem;
}

.drawer-item-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.drawer-item-title {
    font-family: var(--font-main);
    /* Ensure main font */
    letter-spacing: -0.02em;
}

.drawer-item-meta {
    font-size: 0.85rem;
    color: #666;
}

.drawer-item-price {
    font-size: 1rem;
    letter-spacing: 0.02em;
}

.drawer-item-remove {
    border: none;
    background: transparent;
    color: #999;
    padding: 2px;
    cursor: pointer;
    transition: color 0.2s;
}

.drawer-item-remove:hover {
    color: #dc3545;
}

/* Footer (Total + Checkout) */
.drawer-footer {
    padding: 1.5rem;
    border-top: 1px solid #f0f0f0;
    background: #fff;
    /* Force GPU Acceleration to fix Safari ghosting bug (duplicate footer) */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
    position: relative;
    z-index: 10;
}

.drawer-total {
    display: flex;
    justify-content: space-between;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

/* DESKTOP: Slide from Right */
@media (min-width: 768px) {
    #cartDrawer {
        top: 0;
        bottom: 0;
        right: 0;
        width: 450px;
        height: auto;
        /* Replaced 100vh with top:0/bottom:0 for perfect Safari height calculation */
        transform: translateX(100%);
    }
}

/* MOBILE: Slide from Bottom (Bottom Sheet) */
@media (max-width: 767px) {
    #cartDrawer {
        bottom: 0;
        left: 0;
        width: 100vw;
        height: auto;
        min-height: 50vh;
        max-height: 85vh;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
    }

    #cartDrawerItems {
        padding: 1rem;
        -webkit-overflow-scrolling: touch; /* Essential for smooth iOS scroll without ghosting */
    }

    .drawer-footer {
        padding: 1rem;
        flex-shrink: 0; /* Ensures the footer never gets squished or duplicated visually */
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scroll Lock */
html.no-scroll,
body.no-scroll {
    overflow: hidden !important;
    height: 100vh;
    /* Prevent iOS scrollBounce */
}