/* ===================================================================
   MOBILE FIXES - COMPREHENSIVE ONE-TIME FIX
   Ensures alignment, spacing, and usability across all mobile devices.
   =================================================================== */

/* === GLOBAL MOBILE RESETS === */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        position: relative;
    }

    /* Fix container widths and padding globally */
    .container, 
    .site-container, 
    .shop-main, 
    .checkout-main,
    .main-content,
    .page-wrap {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
    }

    /* Ensure no element exceeds viewport width */
    img, video, iframe, table {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* === MOBILE NAV TOGGLE FIX === */
    .mobile-nav-toggle {
        display: flex !important;
        z-index: 10001 !important; /* Above cart button */
        order: 1 !important;
        position: relative !important;
        pointer-events: auto !important;
        cursor: pointer !important;
        padding: 10px !important;
        background: transparent !important;
        border: none !important;
        color: white !important;
        font-size: 1.4rem !important;
    }
    
    /* Hide desktop header cart on mobile - shop pages have their own cart toggle */
    .header-cart-btn {
        display: none !important;
    }
    
    /* === SHOP PAGE CART TOGGLE - iOS/Mobile Fix === */
    .cart-toggle-btn {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* === HEADER & NAVIGATION FIXES === */
@media (max-width: 992px) {
    .main-header {
        height: 60px !important;
        min-height: 60px !important;
        padding: 0 16px !important;
        justify-content: space-between !important;
        position: relative !important;
    }

    /* CENTER THE LOGO ON MOBILE */
    .main-header .logo {
        position: absolute !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        margin: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        height: 100% !important;
        width: auto !important; /* Ensure width shrinks to content */
        max-width: 200px !important; /* Prevent overlap with nav buttons */
        z-index: 5;
    }

    /* Fix Logo Size */
    .main-header .logo .logo-icon {
        height: 32px !important;
        width: auto !important;
    }

    /* Fix Navigation Items Spacing */
    .navbar-left, .navbar-right {
        gap: 10px !important;
    }

    /* Hide text labels on mobile nav, show icons only */
    .navbar a span:not(.cart-badge) {
        display: none !important;
    }

    .navbar a i {
        font-size: 1.2rem !important;
        margin: 0 !important;
    }
    
    /* Ensure account dropdown works on mobile */
    .account-dropdown .account-menu {
        right: -10px !important;
        width: 200px !important;
    }
}

/* === SHOP PAGE FIXES === */
@media (max-width: 768px) {
    /* Fix Hero Section */
    .shop-hero {
        padding: 80px 16px 30px !important; /* Top padding accounts for fixed header */
        min-height: auto !important;
    }

    .shop-hero-content {
        padding: 0 !important;
    }

    .hero-logo-img {
        max-width: 280px !important;
    }

    /* Fix Stats Container */
    .stats-container {
        gap: 20px !important;
        margin-top: 20px !important;
    }

    .stat-item {
        flex: 1 1 30% !important; /* Allow wrapping */
        min-width: 80px !important;
    }

    .stat-number {
        font-size: 1.5rem !important;
    }

    .stat-label {
        font-size: 0.75rem !important;
    }

    /* Fix Product Grid */
    .product-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important; /* Force 2 columns on mobile */
        gap: 12px !important;
        padding-bottom: 60px !important; /* Space for bottom nav/footer */
        width: 100% !important;
        max-width: 100% !important;
        margin-left: auto !important;
        margin-right: auto !important;
        justify-content: center !important;
    }

    .shop-content {
        padding-right: 0 !important;
    }

    /* On very small screens, maybe 1 column is better, but 2 is standard for e-commerce */
    @media (max-width: 360px) {
        .product-grid {
            grid-template-columns: 1fr !important;
        }
    }

    /* Fix Product Card */
    .product-card-modern {
        height: 100% !important; /* Ensure uniform height in grid row */
        display: flex !important;
        flex-direction: column !important;
    }

    .product-image-container {
        aspect-ratio: 1 / 1 !important; /* Consistent square ratio */
        min-height: 140px !important;
        height: auto !important;
    }

    .product-info {
        padding: 10px !important;
        gap: 4px !important;
    }

    .product-title {
        font-size: 0.95rem !important;
        min-height: auto !important;
        line-height: 1.3 !important;
        margin-bottom: 4px !important;
    }

    .product-description {
        display: -webkit-box !important; /* Show description on mobile */
        -webkit-line-clamp: 2 !important;
        line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
        font-size: 1rem !important;
    }

    .product-price {
        font-size: 1rem !important;
    }

    .product-actions-container {
        padding: 10px !important;
        margin-top: 0 !important;
    }

    .add-to-cart-btn {
        height: 36px !important;
        font-size: 0.85rem !important;
        padding: 0 8px !important;
    }

    .quantity-selector {
        height: 30px !important;
        width: 80px !important;
    }
    
    /* Fix Cart Toggle Button - Top Right Corner on Mobile */
    .cart-toggle-btn {
        position: fixed !important;
        top: 70px !important; /* Below header */
        bottom: auto !important;
        right: 15px !important;
        left: auto !important;
        background: rgba(128, 0, 0, 0.9) !important; /* Semi-transparent maroon */
        border-radius: 50% !important;
        width: 48px !important;
        height: 48px !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
        padding: 0 !important;
        z-index: 9999 !important;
    }
    
    .cart-toggle-btn i {
        font-size: 22px !important;
        color: white !important;
        text-shadow: none !important;
    }
    
    .cart-badge {
        top: -5px !important;
        right: -5px !important;
        border: 2px solid #fff !important;
    }
}

/* === AUTH PAGE FIXES === */
@media (max-width: 768px) {
    .auth-container {
        width: 100% !important;
        padding: 20px !important;
        margin: 80px auto 40px !important;
    }

    .auth-card {
        padding: 24px 16px !important;
    }
    
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    /* Login/Register form alignment fixes (mobile only) */
    .auth-form .input-group,
    .auth-form input,
    .auth-form label {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .auth-form label {
        margin-top: 6px !important;
        margin-bottom: 2px !important;
    }

    .auth-form .input-group {
        margin-bottom: 4px !important;
    }

    .auth-form label[style*="margin-top:16px"] {
        margin-top: 6px !important;
    }

    /* Smaller type + tighter spacing on mobile */
    .auth-panel-header h2,
    .auth-panel-text h2 {
        font-size: 1.15rem !important;
    }

    .auth-panel-text .muted-small,
    .auth-form label {
        font-size: 0.9rem !important;
        line-height: 1.25 !important;
        font-weight: 600 !important;
    }

    .auth-form input {
        height: 44px !important;
        font-size: 14px !important;
        padding: 10px 14px 10px 44px !important;
    }

    .input-icon {
        font-size: 14px !important;
        left: 14px !important;
    }

    .toggle-password {
        right: 10px !important;
    }

    .form-actions {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
    }

    /* Remember me row alignment */
    .form-actions .form-small {
        order: 1;
        width: 100% !important;
        justify-content: flex-start !important;
        font-size: 0.85rem !important;
        gap: 2px !important;
        padding: 2px 0 !important;
    }

    .form-actions .form-small input[type="checkbox"] {
        width: 20px !important;
        height: 20px !important;
        margin-right: 2px !important;
    }

    .form-actions .form-buttons {
        order: 2;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        width: 100% !important;
    }

    .form-actions .form-buttons .btn-primary {
        order: 1;
        width: 100% !important;
        font-size: 0.95rem !important;
        padding: 12px 16px !important;
    }

    .form-actions .form-buttons .btn-secondary {
        order: 2;
        width: 100% !important;
        font-size: 0.9rem !important;
        padding: 10px 16px !important;
        border-radius: 12px !important;
        background: #f3f4f6 !important;
        border: 1px solid #e5e7eb !important;
        color: #333 !important;
    }
}

/* === DASHBOARD FIXES === */
@media (max-width: 992px) {
    .dashboard-wrapper {
        flex-direction: column !important;
        padding: 0 16px !important;
        margin-top: 20px !important;
    }

    .dashboard-sidebar {
        width: 100% !important;
        margin-bottom: 20px !important;
        position: static !important;
    }

    .dashboard-content {
        padding: 20px !important;
    }
    
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
}

/* === MODAL FIXES === */
@media (max-width: 768px) {
    .modal-content {
        width: 95% !important;
        margin: 10px auto !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }
    
    .product-modal-content {
        flex-direction: column !important;
    }
    
    .modal-image-col, .modal-info-col {
        width: 100% !important;
    }
    
    .modal-image-col {
        height: 250px !important;
    }
    
    /* Contact Modal Mobile - Stack columns vertically */
    #contact-modal .contact-modal-content {
        flex-direction: column !important;
    }
    
    #contact-modal .contact-modal-content > div {
        width: 100% !important;
    }
    
    /* About Modal Mobile Enhancements */
    #about-modal .modal-content {
        margin: 10px !important;
        max-width: calc(100% - 20px) !important;
        border-radius: 20px !important;
    }
    
    #about-modal .modal-content *,
    #about-modal .modal-content p,
    #about-modal .modal-content h2,
    #about-modal .modal-content h3 {
        color: #ffffff !important;
    }
    
    /* Smaller header padding on mobile */
    #about-modal .pt-10 {
        padding-top: 2rem !important;
    }
    
    #about-modal .px-8 {
        padding-left: 1.25rem !important;
        padding-right: 1.25rem !important;
    }
    
    /* Adjust icon boxes on mobile */
    #about-modal .w-12 {
        width: 2.5rem !important;
        height: 2.5rem !important;
    }
    
    #about-modal .w-12 i {
        font-size: 0.875rem !important;
    }
    
    /* Stats grid mobile */
    #about-modal .grid-cols-3 {
        gap: 0.5rem !important;
    }
    
    #about-modal .grid-cols-3 .text-2xl {
        font-size: 1.25rem !important;
    }
    
    #about-modal .grid-cols-3 .text-xs {
        font-size: 0.65rem !important;
    }
    
    /* Social icons smaller on mobile */
    #about-modal .w-11 {
        width: 2.5rem !important;
        height: 2.5rem !important;
    }
    
    #contact-modal .bg-gradient-to-br h2,
    #contact-modal .bg-gradient-to-br h4,
    #contact-modal .bg-gradient-to-br p {
        color: #ffffff !important;
    }
}

/* === SHOP MOBILE REPAIRS (VISIBILITY & LAYOUT FORCE) === */
@media (max-width: 992px) {
    /* 0. PARENT CONTAINER EXPANSION - CRITICAL LAYOUT FIXES */
    /* Ensure containers do not collapse or cut off content */
    html, body {
        overflow-x: hidden !important;
        position: relative !important;
    }

    .shop-main, .shop-layout, .shop-products {
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        display: block !important; /* Ensure block formatting context for wrappers */
    }

    .shop-main .container, 
    .product-section .container {
        padding-left: 0 !important;
        padding-right: 0 !important;
        max-width: 100vw !important;
        width: 100% !important; 
        margin: 0 !important;
        height: auto !important; /* Allow expansion */
    }
    
    /* Wrapper fix if exists */
    .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
        padding: 0 !important;
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important; 
    }

    /* 1. FORCE GRID VISIBILITY - DISABLE ANIMATIONS ON MOBILE */
    .product-grid .product-card-modern,
    .product-grid .product-card-modern:nth-child(n) {
        opacity: 1 !important;
        transform: none !important;
        visibility: visible !important;
        animation: none !important;
        transition: none !important;
        will-change: auto !important;
    }

    /* 2. OPTIMIZED MODERN MOBILE GRID (Maximize Width & Center) */
    .product-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important; /* Return to 1fr for cleaner gap handling */
        justify-content: start !important; /* Default flow */
        gap: 8px !important; /* TIGHT GAP (4px each side) */
        padding: 4px !important; 
        width: 100% !important;
        box-sizing: border-box !important;
        margin: 0 !important;
        height: auto !important; /* Enforce auto height to push footer */
        overflow: visible !important;
    }

    /* 3. MODERN CARD STRUCTURE - COMPACT & WIDER LOOK */
    .product-card-modern {
        background: #ffffff !important;
        border: 1px solid rgba(0,0,0,0.06) !important;
        box-shadow: 0 4px 8px rgba(0,0,0,0.04) !important;
        border-radius: 6px !important;
        height: 100% !important; /* Fill grid cell */
        min-height: 290px !important; /* Slightly reduced height to fit more info if needed */
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        position: relative !important;
        width: 100% !important;
        margin-bottom: 0 !important; /* Let grid gap handle spacing */
    }

    /* QUICK VIEW - HORIZONTAL RECTANGLE, HIDDEN UNTIL HOVER/TOUCH */
    .mobile-quick-view-btn,
    .product-card .quick-view-btn,
    .product-card-modern .quick-view-btn {
        display: flex !important;
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: auto !important;
        min-width: 100px !important;
        height: 40px !important;
        padding: 0 16px !important;
        background: rgba(255, 255, 255, 0.95) !important;
        border-radius: 8px !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.2) !important;
        z-index: 20 !important;
        border: none !important;
        color: #660000 !important;
        font-size: 0.85rem !important;
        font-weight: 600 !important;
        white-space: nowrap !important;
        opacity: 0 !important;
        transition: opacity 0.2s ease !important;
    }
    
    .mobile-quick-view-btn i,
    .product-card .quick-view-btn i,
    .product-card-modern .quick-view-btn i {
        font-size: 1rem !important;
        color: #660000 !important;
        margin: 0 !important;
        pointer-events: none !important;
        flex-shrink: 0 !important;
    }

    .product-card-modern .product-overlay,
    .product-card .product-overlay {
        position: absolute !important;
        inset: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        opacity: 0 !important;
        background: transparent !important;
        pointer-events: none !important;
        transition: opacity 0.2s ease !important;
    }
    .product-card-modern:hover .product-overlay,
    .product-card:hover .product-overlay,
    .product-card-modern.touch-active .product-overlay,
    .product-card.touch-active .product-overlay {
        opacity: 1 !important;
    }
    .product-card-modern:hover .quick-view-btn,
    .product-card:hover .quick-view-btn,
    .product-card-modern.touch-active .quick-view-btn,
    .product-card.touch-active .quick-view-btn {
        opacity: 1 !important;
    }
    .product-card-modern .product-overlay .quick-view-btn,
    .product-card .product-overlay .quick-view-btn {
        pointer-events: auto !important;
    }
    .product-card-modern .product-image-container,
    .product-card .product-image-container {
        position: relative !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* 4. IMAGE - SQUARE ASPECT RATIO */
    .product-image-container {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 1 / 1 !important;
        background: #f8f8f8 !important;
        padding: 0 !important;
        position: relative !important;
        display: block !important;
        flex-shrink: 0 !important; 
    }
    
    .product-image {
        height: 100% !important;
        width: 100% !important;
        object-fit: cover !important; /* Cover for consistent sizing */
        object-position: center !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        padding: 0 !important;
        background: transparent !important;
    }

    /* FIX: HIDE DESCRIPTION FORCEFULLY */
    .product-description, 
    .product-card-modern .product-description,
    .product-info p:not(.product-category):not(.price-container) {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        opacity: 0 !important;
    }

    /* 5. COMPACT INFO AREA - Absolute Footer Layout */
    .product-info {
        padding: 10px 6px 50px 6px !important; 
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        background: #fff !important;
        flex-grow: 1 !important;
        min-height: 100px !important; 
        position: relative !important;
        justify-content: flex-start !important;
    }

    /* Title Centered & Compact */
    .product-title {
        font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
        font-size: 0.8rem !important;
        font-weight: 600 !important;
        line-height: 1.2 !important;
        text-align: center !important;
        margin: 0 !important;
        padding: 0 !important;
        color: #111 !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
        width: 100% !important;
        height: 2.4em !important;
    }

    /* Position Price Bottom Left */
    .price-container {
        position: absolute !important;
        bottom: 8px !important;
        left: 8px !important;
        margin: 0 !important;
        width: auto !important;
        padding: 0 !important;
        z-index: 5 !important;
    }

    .product-price {
        font-size: 0.9rem !important;
        color: #111 !important;
        font-weight: 700 !important;
    }

    /* Position Add Button Bottom Right */
    .product-actions {
        display: flex !important;
        position: absolute !important;
        bottom: 6px !important;
        right: 6px !important;
        margin: 0 !important;
        padding: 0 !important;
        width: auto !important;
        visibility: visible !important;
        z-index: 10 !important;
    }

    /* Hide Quantity Input */
    .quantity-selector {
        display: none !important;
    }

    /* YELLOW SQUARE Add Button - FIXED & TEXT REMOVED */
    .add-to-cart-btn {
        width: 36px !important;   /* Square Size */
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0 !important;
        margin: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: #f59e0b !important; 
        color: transparent !important; /* HIDE TEXT COLOR */
        border-radius: 6px !important; 
        box-shadow: 0 2px 4px rgba(245, 158, 11, 0.2) !important;
        border: none !important;
        font-size: 0 !important; 
        overflow: hidden !important;
        position: relative !important;
    }
    
    /* Icon Centering */
    .add-to-cart-btn i {
        font-size: 16px !important; 
        color: #fff !important; /* Restore Icon Color */
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        margin: 0 !important;
        display: block !important;
        visibility: visible !important;
    }
    
    /* Strict Text Hiding - Super Aggressive */
    .add-to-cart-btn span {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        width: 0 !important;
        height: 0 !important;
        position: absolute !important;
        z-index: -1 !important;
    }
    
    /* Hide badges */
    .product-badge { display: none !important; }
    .product-overlay { display: none !important; }
    
    /* FIX FOOTER OVERLAP */
    .main-footer {
        position: relative !important;
        z-index: 50 !important;
        margin-top: 0 !important;
        width: 100% !important;
        clear: both !important;
    }
}

/* === FOOTER FIXES === */
@media (max-width: 768px) {
    .main-footer {
        padding: 40px 16px 20px !important;
        text-align: center !important;
    }
    
    .footer-content {
        flex-direction: column !important;
        gap: 30px !important;
    }
    
    .footer-section {
        width: 100% !important;
        align-items: center !important;
    }
    
    .footer-section h4::after {
        left: 50% !important;
        transform: translateX(-50%) !important;
    }
    
    .social-links {
        justify-content: center !important;
    }
}

/* === CART SIDEBAR FIXES === */
@media (max-width: 768px) {
    .cart-sidebar {
        width: 100% !important;
        max-width: 100% !important;
    }
}
