/* MOBILE APP OPTIMIZATION - CRITICAL FIX */

/* Prevent horizontal scroll on all pages */
html,
body {
    max-width: 100vw;
    width: 100%;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100vh;
    position: static !important;
    /* Fix potential relative locking */
    touch-action: auto !important;
}

/* All containers must respect viewport */
*,
*::before,
*::after {
    max-width: 100%;
}

/* Image optimization */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Smooth scrolling for mobile */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Touch-friendly tap targets */
button,
a,
input,
select,
textarea {
    min-height: 44px;
    min-width: 44px;
}

/* Product Grid Mobile Optimization */
@media (max-width: 768px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
        padding: 10px !important;
    }

    .product-card {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }

    .product-card img {
        width: 100% !important;
        height: auto !important;
        max-height: 180px !important;
        object-fit: cover !important;
    }
}

/* Header Mobile Fix */
@media (max-width: 768px) {
    .main-header {
        padding: 0 8px !important;
    }

    .nav-container {
        padding: 0 !important;
    }

    .desktop-nav,
    .desktop-search {
        display: none !important;
    }

    /* REMOVED RESTRICTIVE LOGO SIZES */
}

/* Hero Section Mobile */
@media (max-width: 768px) {
    .hero {
        height: auto !important;
        min-height: 520px !important;
        padding: 0 !important;
        margin-top: 0 !important;
        position: relative !important;
        z-index: 1 !important;
    }

    .hero h1 {
        font-size: 1.8rem !important;
    }

    .hero p {
        font-size: 0.95rem !important;
    }

    .hero-slide {
        padding: 30px 20px !important;
        padding-top: 50px !important;
        padding-bottom: 60px !important;
    }

    .hero-slide .btn {
        margin-bottom: 10px;
    }
}

/* Product Detail Mobile - COMPREHENSIVE FIX */
@media (max-width: 768px) {
    .product-detail-layout {
        padding: 10px !important;
        display: block !important;
        width: 100% !important;
    }

    /* Image Container Wrapper Fix */
    .img-container-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Image Container Fix */
    .img-container {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 12px !important;
        overflow: hidden !important;
        position: relative !important;
    }

    .img-container img {
        width: 100% !important;
        height: auto !important;
        max-height: 350px !important;
        object-fit: cover !important;
        border-radius: 12px !important;
        display: block !important;
    }

    /* Gallery Thumbnails Wrapper */
    .product-gallery-thumbnails-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        margin: 10px 0 0 0 !important;
        padding: 0 !important;
    }

    /* Gallery Thumbnails */
    .product-gallery-thumbnails {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        display: flex !important;
        gap: 8px !important;
        padding: 4px 0 !important;
        width: 100% !important;
    }

    .product-gallery-thumbnails::-webkit-scrollbar {
        display: none !important;
    }

    .thumb-item {
        width: 60px !important;
        height: 60px !important;
        min-width: 60px !important;
        flex-shrink: 0 !important;
        border-radius: 8px !important;
        border: 1px solid #e2e8f0 !important;
    }

    .thumb-item img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        padding: 3px !important;
    }

    /* Badges on Image */
    .badges-stack {
        top: 10px !important;
        left: 10px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
        width: auto !important;
    }

    .badge-narin-pink,
    .badge-narin-discount {
        font-size: 0.7rem !important;
        padding: 4px 8px !important;
        margin: 0 !important;
        width: fit-content !important;
    }
}

/* Bottom Navigation Safe Area */
@media (max-width: 768px) {
    .mobile-bottom-nav {
        padding-bottom: max(env(safe-area-inset-bottom), 10px) !important;
    }

    body {
        padding-bottom: calc(70px + env(safe-area-inset-bottom)) !important;
    }
}

/* GLOBAL BADGE SYSTEM (Desktop & Mobile) */
.badges-stack {
    position: absolute !important;
    top: 8px !important;
    left: 8px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 4px !important;
    z-index: 2 !important;
    width: auto !important;
    pointer-events: none;
}

.badges-stack>* {
    display: block !important;
    margin: 0 !important;
    width: fit-content !important;
}

.badge-narin-pink {
    background: linear-gradient(135deg, #C9A96E, #8B6F47) !important;
    color: white !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 0.65rem !important;
    font-weight: 700 !important;
    padding: 3px 10px !important;
    border-radius: 20px !important;
    box-shadow: 0 4px 10px rgba(139, 111, 71, 0.25) !important;
    letter-spacing: 0.5px !important;
    text-transform: uppercase !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    line-height: normal !important;
}

.badge-narin-discount {
    background: rgba(255, 255, 255, 0.95) !important;
    color: #8B6F47 !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 0.65rem !important;
    font-weight: 800 !important;
    padding: 3px 10px !important;
    border-radius: 20px !important;
    border: 1px solid #E8DCCC !important;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05) !important;
    letter-spacing: 0.3px !important;
    backdrop-filter: blur(4px);
    line-height: normal !important;
}

.badge-mdf-brown {
    background: rgba(139, 111, 71, 0.9) !important;
    backdrop-filter: blur(4px);
    color: white !important;
    font-size: 0.6rem !important;
    font-weight: 700 !important;
    padding: 3px 8px !important;
    border-radius: 20px !important;
    box-shadow: 0 4px 8px rgba(139, 111, 71, 0.2) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    line-height: normal !important;
}

/* COMPREHENSIVE MOBILE FIXES WRAPPER */
@media (max-width: 768px) {

    /* Prevent zoom on input focus (iOS) */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Remove default iOS styling */
    input,
    textarea,
    button,
    select {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        border-radius: 0;
    }

    /* Fix for Top Bar in Mobile */
    .top-bar {
        display: block !important;
        background: #8B6F47 !important;
        padding: 0 !important;
        height: auto !important;
        width: 100% !important;
    }

    .top-bar .nav-container {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        width: 100% !important;
        padding: 8px 10px !important;
        box-sizing: border-box !important;
    }

    .top-bar .nav-container>* {
        flex: 1 !important;
        width: 50% !important;
        max-width: 50% !important;
        color: white !important;
        font-size: 0.6rem !important;
        line-height: 1.1 !important;
        white-space: normal !important;
        display: flex !important;
        align-items: center !important;
    }

    /* Left side (Shipping) */
    .top-bar .nav-container>a:first-child {
        justify-content: flex-start !important;
        text-align: left !important;
        padding-right: 4px !important;
    }

    /* Right side (Store) */
    .top-bar .nav-container>div:last-child {
        justify-content: flex-end !important;
        text-align: right !important;
        padding-left: 4px !important;
    }

    .top-bar span {
        font-weight: 700 !important;
        display: inline-block !important;
        /* Helps with wrapping */
    }
}

/* End of Top Bar Styles */

/* COMPREHENSIVE MOBILE FIXES */
@media (max-width: 768px) {

    /* Main Product Page Fixes */
    #productsPageContainer {
        margin-top: 1rem !important;
        /* Adjusted to balance with header */
        padding-top: 10px !important;
    }

    /* Breadcrumb Fix */
    .breadcrumb-fix {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        flex-wrap: nowrap !important;
        white-space: nowrap !important;
        overflow-x: auto !important;
        padding-bottom: 5px !important;
        margin-bottom: 1rem !important;
        border-bottom: 1px solid #f1f5f9;
        font-family: 'Inter', sans-serif !important;
        font-size: 0.8rem !important;
        color: #64748b !important;
    }

    .breadcrumb-fix a {
        display: flex !important;
        align-items: center !important;
        gap: 5px !important;
        color: #64748b !important;
        text-decoration: none !important;
    }

    .breadcrumb-fix i {
        font-size: 0.7rem !important;
        opacity: 0.6 !important;
    }

    .breadcrumb-fix::-webkit-scrollbar {
        display: none;
    }

    #productsPageContainer>div:first-child {
        display: none !important;
        /* Hide old selector if present to avoid conflicts */
    }

    /* Ensure the new breadcrumb is visible */
    #productsPageContainer>.breadcrumb-fix {
        display: flex !important;
    }

    /* Mobile-specific badge size adjustments */
    .badge-narin-pink {
        font-size: 0.55rem !important;
        /* Smaller text */
        padding: 2px 7px !important;
        /* Reduced padding */
        box-shadow: 0 2px 5px rgba(139, 111, 71, 0.2) !important;
        letter-spacing: 0.3px !important;
        width: fit-content !important;
        margin: 0 !important;
        line-height: 1.1 !important;
    }

    .badge-narin-discount {
        font-size: 0.55rem !important;
        /* Smaller text */
        padding: 2px 7px !important;
        /* Reduced padding */
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05) !important;
        letter-spacing: 0.2px !important;
        width: fit-content !important;
        margin: 0 !important;
        line-height: 1.1 !important;
    }

    .badge-mdf-brown {
        position: static !important;
        font-size: 0.5rem !important;
        /* Smaller text */
        padding: 2px 6px !important;
        /* Reduced padding */
        box-shadow: 0 2px 5px rgba(139, 111, 71, 0.2) !important;
        width: fit-content !important;
        margin: 0 !important;
        margin-top: 1px !important;
        line-height: 1.1 !important;
    }

    .category-tag {
        font-size: 0.65rem !important;
        margin-bottom: 4px !important;
        color: #94a3b8 !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
        font-weight: 700 !important;
    }
}