/* 
 * WooCommerce Specific Mobile Overrides
 * Targets only specific WooCommerce structure to prevent breaking global theme layouts.
 */

@media (max-width: 1024px) {
    /* My Account Layout */
    .account-layout { 
        display: flex !important;
        flex-direction: column !important; 
        gap: 30px !important;
    }
    /* Dashboard Header */
    .account-header-flex {
        flex-direction: column !important;
        gap: var(--spacing-xl) !important;
    }
    .account-header-flex .account-header-right.dashboard-hero {
        width: 100% !important;
        min-height: 220px;
        border-radius: 12px;
        margin-top: 10px;
    }

    /* Pill Navigation Overhaul */
    .account-sidebar { 
        width: 100% !important; 
        flex: none !important;
        border: none !important;
        background: transparent !important;
        padding: 5px 0 10px 0 !important;
        margin-bottom: 30px !important;
        overflow-x: auto !important; 
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        scrollbar-width: none; /* Hide scrollbar Firefox */
    }
    .account-sidebar::-webkit-scrollbar {
        display: none; /* Hide scrollbar WebKit */
    }
    .account-sidebar ul {
        display: flex !important;
        gap: 12px !important;
        margin: 0 !important;
        padding: 0 5px !important;
    }
    .account-sidebar li {
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
    }
    .account-sidebar li a {
        display: inline-flex !important;
        align-items: center !important;
        gap: 8px !important;
        background: var(--color-white) !important;
        color: var(--color-text-dark) !important;
        padding: 10px 20px !important;
        border-radius: 50px !important; /* Pill shape */
        font-size: 14px !important;
        font-weight: 500 !important;
        border: 1px solid var(--color-champagne) !important;
        transition: all 0.3s ease !important;
        box-shadow: 0 2px 5px rgba(0,0,0,0.02) !important;
    }
    .account-sidebar li.is-active a {
        background: var(--color-taupe) !important;
        color: #fff !important;
        border-color: var(--color-taupe) !important;
    }
    .account-sidebar li.is-active a .account-sidebar-icon svg,
    .account-sidebar li.is-active a .account-sidebar-icon svg *,
    .account-sidebar li.is-active a svg {
        stroke: #fff !important;
    }
    
    .account-content {
        width: 100% !important; 
        flex: none !important;
    }
    
    .dashboard-stats { 
        grid-template-columns: repeat(2, 1fr) !important; 
    }
    
    /* Cart Layout */
    .cart-layout { 
        display: flex !important;
        flex-direction: column !important; 
        gap: 30px !important;
    }
    .cart-main, .cart-sidebar { 
        width: 100% !important; 
    }
    
    /* Checkout Layout */
    .checkout-layout { 
        display: flex !important;
        flex-direction: column-reverse !important; /* Move summary to top on mobile sometimes? No, normal stack is fine. */
        flex-direction: column !important;
        gap: 30px !important;
    }
    .checkout-form, .checkout-sidebar { 
        width: 100% !important; 
    }

    /* Shop Grid Layout */
    .shop-container {
        display: flex !important;
        flex-direction: column !important;
    }
    .shop-sidebar {
        width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid var(--color-champagne);
        padding-bottom: 20px !important;
        margin-bottom: 20px !important;
    }

    /* Sticky Add To Cart (Mobile/Tablet) */
    .mobile-sticky-atc {
        position: fixed !important;
        bottom: calc(68px + env(safe-area-inset-bottom)) !important; /* Above bottom nav */
        left: 0;
        width: 100%;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        padding: 10px 15px !important;
        box-shadow: 0 -4px 10px rgba(0,0,0,0.05);
        z-index: 999999 !important;
        display: flex !important;
        gap: 10px;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transform: translateY(20px);
        transition: all 0.3s ease;
    }
    .mobile-sticky-atc.visible {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        transform: translateY(0) !important;
    }
    .mobile-sticky-atc .btn-buy-now {
        flex: 1;
        padding: 12px 0;
        margin-top: 0;
    }

    .mobile-only-wishlist {
        display: flex !important;
    }

    .desktop-only-buy-now-row {
        display: none !important;
    }
}

@media (max-width: 768px) {
    /* Dash Grids */
    .dashboard-stats { 
        grid-template-columns: 1fr !important; 
    }
    
    .address-grid, .orders-grid, .downloads-grid, .rewards-history, .wishlist-grid, .points-grid { 
        grid-template-columns: 1fr !important; 
    }
    
    /* PDP Layout */
    .pdp-layout, .product-main, .pdp-main-layout, .pdp-lower-split {
        display: flex !important;
        flex-direction: column !important;
        gap: 30px !important;
    }
    
    .product-gallery, .product-info, .pdp-summary {
        width: 100% !important;
        padding: 0 !important;
    }

    /* Swipeable Product Gallery (Custom) */
    .maison-gallery {
        flex-direction: column !important;
        gap: 10px !important;
    }
    .maison-gallery__thumbs {
        display: none !important; /* Hide thumbs on mobile, rely on swipe */
    }
    .maison-gallery__main {
        display: flex !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        aspect-ratio: auto !important;
        margin: 0 -15px !important;
        padding: 0 15px !important;
    }
    .maison-gallery__main::-webkit-scrollbar {
        display: none;
    }
    .maison-gallery__slide {
        display: block !important;
        position: relative !important;
        opacity: 1 !important;
        width: 85vw !important;
        flex: 0 0 auto !important;
        scroll-snap-align: center;
        margin-right: 10px !important;
        aspect-ratio: 3/4;
    }

    /* Dot indicators */
    .maison-gallery__dots {
        display: flex !important;
        justify-content: center;
        gap: 8px;
        margin-top: 16px;
        width: 100%;
    }
    .maison-gallery__dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background-color: var(--color-stone);
        border: none;
        padding: 0;
        opacity: 0.5;
        transition: opacity 0.2s, background-color 0.2s;
    }
    .maison-gallery__dot.is-active {
        opacity: 1;
        background-color: var(--color-text-dark);
    }


    /* Touch-friendly Variation Selectors */
    .size-pill {
        min-height: 44px; /* Apple Human Interface Guidelines */
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
    }
    .color-swatch {
        width: 44px;
        height: 44px;
    }

    /* Horizontal Carousels for Recommendations */
    .ctl-grid {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        gap: 15px !important;
        padding-bottom: 20px;
        margin: 0 -15px !important;
        padding: 0 15px 20px !important;
        scrollbar-width: none;
    }
    .ctl-grid::-webkit-scrollbar {
        display: none;
    }
    .ctl-grid > * {
        flex: 0 0 65% !important; /* Peak next item */
        scroll-snap-align: start;
    }

    /* Hide Desktop Tabs on Mobile */
    .pdp-tabs-section {
        display: none !important;
    }
    .product-accordions {
        display: block !important;
    }

    /* Elegant 2-Column Product Grid */
    ul.products {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important; /* Slightly tighter gap on mobile */
    }
    ul.products li.product {
        width: 100% !important;
        margin: 0 !important;
        clear: none !important;
    }
    ul.products li.product .woocommerce-loop-product__title {
        font-size: 0.75rem !important; /* Smaller on mobile */
        margin-bottom: 4px !important;
    }
    ul.products li.product .price {
        font-size: 0.75rem !important;
    }

    /* Mobile Shop Filter Bar */
    .shop-filter-bar {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 15px 0;
        border-top: 1px solid var(--color-champagne);
        border-bottom: 1px solid var(--color-champagne);
    }
    .filters-left, .sort-right {
        width: auto !important;
        padding: 0 !important;
        border: none !important;
        display: flex;
        align-items: center;
    }

    /* Full-screen Mobile Filter Drawer */
    .filters-sidebar {
        position: fixed !important;
        top: 0;
        left: -100vw;
        width: 100vw !important;
        height: 100vh !important;
        background: var(--color-white);
        z-index: 10000;
        transition: left 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        padding: 0 !important;
        display: flex;
        flex-direction: column;
        border: none !important;
    }
    .filters-sidebar.active {
        left: 0;
    }
    .filters-sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: calc(20px + env(safe-area-inset-top)) 20px 20px;
        border-bottom: 1px solid var(--color-champagne);
        font-family: var(--font-body);
        font-weight: 600;
        font-size: 1rem;
        text-transform: uppercase;
    }
    .filters-sidebar-content {
        flex: 1;
        overflow-y: auto;
        padding: 20px;
    }
    .filters-sidebar-footer {
        padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--color-champagne);
        display: flex;
        justify-content: center;
    }
    .filters-sidebar-footer .btn-primary {
        width: 100%;
        text-align: center;
    }
    
    /* WooCommerce Native Overrides */
    .col2-set {
        display: flex !important;
        flex-direction: column !important;
        gap: 20px !important;
    }
    .col-1, .col-2 {
        width: 100% !important;
        float: none !important;
    }
    
    table.shop_table_responsive thead {
        display: none !important;
    }
    table.shop_table_responsive tbody tr {
        display: block !important;
        padding: 15px 0 !important;
        border-bottom: 1px solid #eee;
    }
    table.shop_table_responsive tbody td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 10px 0 !important;
        border: none !important;
    }
    table.shop_table_responsive tbody td::before {
        content: attr(data-title);
        font-weight: 600;
        margin-right: 15px;
    }
}

@media (max-width: 360px) {
    /* Fold Phone spacing */
    .account-page-wrapper, .cart-page-wrapper, .checkout-page-wrapper {
        padding: 20px 0 !important;
    }
    
    /* Ensure no container overflow */
    .account-sidebar, .account-content, .cart-main, .checkout-form {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
}

/* =========================================
   Utility & State Components (Mobile)
   ========================================= */
@media (max-width: 768px) {
    /* WooCommerce Notices (Errors, Success, Info) */
    .woocommerce-error,
    .woocommerce-info,
    .woocommerce-message {
        padding: 15px 20px !important;
        margin-bottom: 20px !important;
        background-color: var(--color-lavender-whisper) !important;
        color: var(--color-text-dark) !important;
        border: 1px solid var(--color-lavender-accent) !important;
        border-radius: 4px !important;
        font-size: 0.875rem !important;
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        box-shadow: 0 4px 15px rgba(0,0,0,0.03) !important;
    }
    .woocommerce-error::before,
    .woocommerce-info::before,
    .woocommerce-message::before {
        display: none !important; /* Hide default icons if any */
    }

    /* Empty States */
    .cart-empty, .wishlist-empty {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        padding: 60px 20px !important;
        background-color: transparent !important;
        border: 1px dashed var(--color-champagne) !important;
        border-radius: 8px !important;
        margin: 20px 0 !important;
    }
    .cart-empty::before, .wishlist-empty::before {
        content: '' !important;
        display: block !important;
        width: 64px !important;
        height: 64px !important;
        background-image: url('data:image/svg+xml;utf8,<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="%239d8db3" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z"></path><line x1="3" y1="6" x2="21" y2="6"></line><path d="M16 10a4 4 0 0 1-8 0"></path></svg>') !important;
        background-repeat: no-repeat !important;
        background-position: center !important;
        margin-bottom: 15px !important;
    }

    /* Loading States (BlockUI Overrides) */
    .blockUI.blockOverlay {
        background: rgba(255,255,255,0.7) !important;
        backdrop-filter: blur(2px) !important;
        -webkit-backdrop-filter: blur(2px) !important;
    }
}

/* =========================================
   Mobile Touch & Accessibility Adaptations
   ========================================= */

/* Safe Area Insets (The Notch Problem) */
body {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.mobile-drawer-footer,
.site-footer {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

/* Touch Target Densities */
@media (pointer: coarse) {
    /* Ensure all links inside accordion/drawer have 44px min tap area */
    .mobile-accordion-menu li a {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    /* Action icons need larger hit areas */
    .action-icon, .mobile-menu-trigger, .wishlist-link {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Expand buttons inside mobile drawer */
    .mobile-accordion-menu .expand-btn {
        min-width: 44px;
        min-height: 44px;
    }
}
