/**
 * Products Lite - Memory Optimized Styles
 * Matches existing products-enhanced UI
 * Designed for iOS Safari stability with CSS containment
 */

/* ============================================
   CSS VARIABLES (Brand Colors)
   Matched with products-enhanced.html for consistent styling
   ============================================ */
:root {
    --bg-light: #f6f1e5;
    --bg-warm: #F4EAD3;
    --text-brown: #5b3d0f;
    --text-rich: #4C371C;
    --text-teal: #1b7b89;
    --accent-teal: #1b7b89;
    --accent-green: #00B56D;
    --accent-orange: #FF8C42;
    --discount-red: #FF6B6B;
    --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 12px 24px rgba(0, 0, 0, 0.15);
    --font-nunito: 'Nunito Sans', sans-serif;
    --font-inter: 'Inter', sans-serif;
    --font-quicksand: 'Quicksand', sans-serif;
    --font-delius: 'Delius Swash Caps', cursive;
    --font-Delius: 'Delius', cursive;
    --font-Delius-Swash-Caps: 'Delius Swash Caps', cursive;
    --font-Montserrat: 'Montserrat', sans-serif;
}

/* ============================================
   GLOBAL OVERFLOW FIX
   Use overflow-x: clip instead of hidden to preserve sticky positioning
   ============================================ */
html, body {
    overflow-x: clip !important;
    max-width: 100vw !important;
    width: 100% !important;
}

html {
    -webkit-overflow-scrolling: touch;
}

body {
    position: relative;
}

/* Ensure all containers stay within viewport - use clip to preserve sticky */
.products-lite-main,
.products-lite-main .container,
.products-section,
.products-grid,
.filter-bar {
    max-width: 100vw !important;
    overflow-x: clip !important;
}

/* Mobile sticky filter should NOT have overflow hidden */
.mobile-sticky-filter {
    max-width: 100vw !important;
    overflow-x: visible !important;
}

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */

/* Enable GPU acceleration for smooth scrolling */
.products-lite-main {
    transform: none;
    -webkit-transform: none;
}

/* Content visibility for off-screen elements */
.product-card.offscreen {
    content-visibility: auto;
    contain-intrinsic-size: 0 350px;
}

/* ============================================
   LAYOUT - MAIN STRUCTURE
   ============================================ */

.products-lite-main {
    background-color: var(--bg-light);
    min-height: 100vh;
    padding-bottom: 40px;
    overflow-x: clip;
    max-width: 100vw;
}

.products-lite-main .container {
    max-width: 100%;
    overflow-x: clip;
    padding-left: 12px;
    padding-right: 12px;
}

@media (min-width: 576px) {
    .products-lite-main .container {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* Breadcrumb */
.breadcrumb-nav {
    padding: 12px 0;
    background: var(--bg-light);
}

.breadcrumb-list {
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
    font-family: var(--font-inter);
    font-size: 0.875rem;
    color: var(--text-brown);
    flex-wrap: wrap;
}

.breadcrumb-list a {
    color: var(--text-teal);
    text-decoration: none;
    transition: color 0.2s ease;
}

.breadcrumb-list a:hover {
    color: var(--text-brown);
}

.breadcrumb-list .separator {
    opacity: 0.5;
}

/* ============================================
   PAGE TITLE SECTION - Elegant Header
   ============================================ */
.page-title-section {
    padding: 24px 0 16px;
    text-align: center;
    background: linear-gradient(180deg, rgba(245, 240, 232, 0.5) 0%, transparent 100%);
}

.page-title-section .container {
    max-width: 800px;
    margin: 0 auto;
}

.page-title {
    font-family: var(--font-quicksand);
    font-size: clamp(1.75rem, 6vw, 2.5rem);
    font-weight: 700;
    color: var(--text-brown);
    margin: 0 0 8px;
    line-height: 1.2;
    letter-spacing: -0.5px;
}

.page-subtitle {
    font-family: var(--font-inter);
    font-size: clamp(0.875rem, 2.5vw, 1rem);
    color: var(--text-rich);
    opacity: 0.75;
    margin: 0;
    line-height: 1.5;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-line;
}

/* Desktop: larger title section */
@media (min-width: 768px) {
    .page-title-section {
        padding: 32px 0 24px;
    }
    
    .page-title {
        margin-bottom: 10px;
    }
}

@media (min-width: 992px) {
    .page-title-section {
        padding: 40px 0 28px;
    }
}

.product-count {
    font-family: var(--font-inter);
    font-size: 0.875rem;
    color: var(--text-rich);
    opacity: 0.7;
    margin: 0;
}

/* ============================================
   MOBILE STICKY FILTER & FILTER BAR
   Styles are now inlined in products-lite.html
   (Copied from products-enhanced.html for exact UI match)
   ============================================ */

/* ============================================
   FILTER SIDEBAR - Styles are inlined in products-lite.html
   (Copied from products-enhanced.html for exact UI match)
   ============================================ */

/* ============================================
   ACTIVE FILTERS CHIPS
   ============================================ */

.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
    padding: 12px 0;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--accent-teal);
    border: none;
    color: #fff;
    font-family: var(--font-inter);
    font-size: 0.75rem;
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.filter-chip:hover {
    background: #268a7d;
}

.filter-chip .remove-icon {
    font-size: 10px;
}

/* ============================================
   PRODUCTS GRID - Clean & Spacious Layout
   Matched with products-enhanced responsive grid
   ============================================ */

.products-section {
    padding: 20px 0;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    min-height: 200px;
    margin-top: 20px;
}

@media (min-width: 576px) {
    .products-grid {
        gap: 16px;
    }
}

@media (min-width: 768px) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }

    .products-section {
        padding: 24px 0;
    }
}

@media (min-width: 992px) {
    /* Match products-enhanced responsive layout */
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
        gap: 20px;
        margin-top: 30px;
    }

    .products-section {
        padding: 30px 0;
    }
}

@media (min-width: 1200px) {
    .products-grid {
        gap: 24px;
    }
}

/* ============================================
   PRODUCT CARD - Elegant Desktop Layout
   ============================================ */

.product-card {
    position: relative;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    height: 100%;
    display: flex;
    flex-direction: column;

    /* CSS Containment - Critical for iOS memory */
    contain: content;
    will-change: auto;
}

/* Disable transforms on iOS for memory */
.ios-device .product-card {
    transition: none;
    will-change: auto;
    transform: none !important;
}

.product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.ios-device .product-card:hover {
    transform: none;
    box-shadow: var(--shadow-card);
}

/* Product Image Container */
.product-image-container {
    position: relative;
    aspect-ratio: 1 / 1;
    background: #f8f6f3;
    overflow: hidden;
    border-radius: 12px 12px 0 0;
}

.product-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease, opacity 0.3s ease;
}

.product-card:hover .product-image {
    transform: scale(1.05);
}

.ios-device .product-card:hover .product-image {
    transform: none;
}

/* Image loading states */
.product-image.loading {
    opacity: 0;
}

.product-image.loaded {
    opacity: 1;
}

/* Hide placeholder when image is loaded */
.product-image.loaded ~ .image-placeholder,
.product-image-container:has(.product-image.loaded) .image-placeholder {
    opacity: 0;
    pointer-events: none;
}

/* Hide placeholder when slider has loaded images */
.product-image-container:has(.slider-image.loaded) .image-placeholder {
    opacity: 0;
    pointer-events: none;
}

/* Image placeholder */
.image-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f8f6f3 0%, #f0ece6 100%);
    color: rgba(91, 61, 15, 0.2);
    font-size: 28px;
    transition: opacity 0.3s ease;
}

/* =============================================
   PRODUCT IMAGE SLIDER
   Memory-efficient, iOS-safe auto-sliding carousel
   ============================================= */

.product-slider {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: inherit;
}

.slider-track {
    display: flex;
    width: 100%;
    height: 100%;
    /* GPU-accelerated smooth transitions with natural easing */
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    /* iOS optimization: use 3D transforms for hardware acceleration */
    transform: translateX(0) translateZ(0);
    -webkit-transform: translateX(0) translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.slider-slide {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    position: relative;
}

.slider-slide .slider-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Smooth opacity transition for loading state */
    transition: opacity 0.3s ease;
}

.slider-slide .slider-image.loading {
    opacity: 0;
}

.slider-slide .slider-image.loaded {
    opacity: 1;
}

/* iOS-specific optimizations */
.ios-device .slider-track {
    /* Disable momentum scrolling interference */
    -webkit-overflow-scrolling: auto;
}

.ios-device .product-slider {
    /* Prevent touch interference on iOS */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .slider-track {
        transition: none;
    }
}

/* Product Labels/Badges */
.product-labels {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 2;
}

.label {
    padding: 4px 10px;
    font-family: var(--font-inter);
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-radius: 4px;
    color: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.label.new-arrivals {
    background: linear-gradient(135deg, var(--accent-teal), #3d9e8f);
}

.label.best-sellers {
    background: linear-gradient(135deg, #FC766A, #ff8a7d);
}

.label.moms-choice {
    background: linear-gradient(135deg, #d4a373, #e5be93);
}

.label.hospital-bag {
    background: linear-gradient(135deg, #7ecec8, #5fb8b0);
}

/* Mobile Cart Button - visible on mobile, hidden on desktop */
.mobile-cart-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--accent-teal);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 0.85rem;
    cursor: pointer;
    z-index: 2;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
    opacity: 1;
}

.mobile-cart-btn:hover {
    background-color: #4da39d;
    color: #fff;
    transform: scale(1.05);
}

/* Hide mobile cart button on desktop - show Quick View instead */
@media (min-width: 769px) {
    .mobile-cart-btn {
        opacity: 0;
        pointer-events: none;
    }
    
    .product-card:hover .mobile-cart-btn {
        opacity: 0;
        pointer-events: none;
    }
}

/* Show mobile cart button on mobile/tablet */
@media (max-width: 768px) {
    .mobile-cart-btn {
        opacity: 1 !important;
        pointer-events: auto !important;
    }
}

/* Quick Add Button (Desktop hover only) */
.quick-add-btn {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px;
    background: var(--accent-teal);
    border: none;
    color: #fff;
    font-family: var(--font-nunito);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    opacity: 0;
    transform: translateY(100%);
    transition: all 0.3s ease;
    z-index: 3;
    border-radius: 0 0 8px 8px;
}

.product-card:hover .quick-add-btn {
    opacity: 1;
    transform: translateY(0);
}

/* Hide Quick View button on mobile - show cart icon instead */
@media (max-width: 768px) {
    .quick-add-btn {
        display: none !important;
    }
}

@media (hover: none) {
    .quick-add-btn {
        display: none;
    }
}

/* Product Info - Clean & Minimal */
.product-info {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    background: #fff;
}

.product-brand,
.product-category {
    font-family: var(--font-inter);
    font-size: 0.6rem;
    font-weight: 500;
    color: var(--text-teal);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin: 0 0 1px 0;
}

.product-name {
    font-family: var(--font-nunito);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-brown);
    line-height: 1.2;
    margin: 0 0 3px 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    max-height: 2.4em;
}

.product-name a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

.product-name a:hover {
    color: var(--text-teal);
}

/* Product Price */
.product-price {
    display: flex;
    align-items: center;
    gap: 4px 6px;
    flex-wrap: wrap;
    margin-top: auto;
    margin-bottom: 0;
}

.current-price {
    font-family: var(--font-nunito);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-brown);
}

.original-price {
    font-family: var(--font-inter);
    font-size: 0.75rem;
    color: #888;
    text-decoration: line-through;
}

.discount-percent,
.discount-percentage {
    font-family: var(--font-inter);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--discount-red);
}

/* Desktop-specific enhancements */
@media (min-width: 992px) {
    .product-info {
        padding: 14px 16px 16px;
    }
    
    .product-name {
        font-size: 0.9rem;
    }
    
    .current-price {
        font-size: 1rem;
    }
}

/* ============================================
   LOADING SKELETONS
   ============================================ */

.products-loading {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

@media (min-width: 768px) {
    .products-loading {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 992px) {
    .products-loading {
        grid-template-columns: repeat(4, 1fr);
    }
}

.product-skeleton {
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-card);
}

.skeleton {
    background: linear-gradient(90deg, #f5f0e8 25%, #ebe6de 50%, #f5f0e8 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-image {
    aspect-ratio: 4 / 5;
    border-radius: 0;
}

.skeleton-text {
    height: 16px;
    margin: 12px;
    border-radius: 4px;
}

/* ============================================
   EMPTY & ERROR STATES
   ============================================ */

.empty-state,
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    min-height: 300px;
}

.empty-icon,
.error-icon {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-warm);
    border-radius: 50%;
    margin-bottom: 20px;
}

.empty-icon i,
.error-icon i {
    font-size: 32px;
    color: var(--text-brown);
    opacity: 0.5;
}

.empty-state h3,
.error-state h3 {
    font-family: var(--font-nunito);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-brown);
    margin: 0 0 8px;
}

.empty-state p,
.error-state p {
    font-family: var(--font-inter);
    font-size: 0.875rem;
    color: var(--text-brown);
    opacity: 0.7;
    margin: 0 0 24px;
}

.btn-reset-filters,
.btn-retry {
    padding: 12px 24px;
    background: var(--accent-teal);
    border: none;
    border-radius: 12px;
    font-family: var(--font-nunito);
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-reset-filters:hover,
.btn-retry:hover {
    background: #268a7d;
    transform: translateY(-2px);
}

/* ============================================
   LOAD MORE
   ============================================ */

.load-more-container {
    padding: 40px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.load-more-sentinel {
    height: 1px;
    width: 100%;
}

.load-more-spinner {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-inter);
    color: var(--text-brown);
    font-size: 0.875rem;
}

.end-of-products {
    text-align: center;
    padding: 40px 0;
}

.end-of-products p {
    font-family: var(--font-inter);
    font-size: 0.875rem;
    color: var(--text-brown);
    opacity: 0.6;
    margin: 0;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 575px) {
    .products-grid {
        gap: 8px;
    }

    /* Match products-enhanced card styling */
    .product-card {
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
        max-height: none;
        min-height: auto;
    }
    
    /* Match products-enhanced image sizing - aspect-ratio 4/5 */
    .product-image-container {
        aspect-ratio: 4 / 5;
        border-radius: 12px 12px 0 0;
        max-height: none;
        height: auto;
    }

    .product-info {
        padding: 6px 8px;
        gap: 2px;
    }

    .product-brand,
    .product-category {
        font-size: 0.65rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        margin-bottom: 0;
    }

    .product-name {
        font-size: 0.75rem;
        font-weight: 600;
        line-height: 1.3;
        margin-bottom: 2px;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        color: var(--text-brown);
    }

    .price-section {
        margin-top: 2px;
        gap: 4px;
    }

    .current-price {
        font-size: 0.85rem;
        font-weight: 700;
        color: var(--text-brown);
    }

    .original-price {
        font-size: 0.7rem;
        font-weight: 500;
    }
    
    .discount-badge {
        font-size: 0.65rem;
        font-weight: 600;
    }

    .mobile-cart-btn {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
        bottom: 8px;
        right: 8px;
    }

    .label {
        font-size: 7px;
        padding: 3px 8px;
        font-weight: 700;
    }
}

@media (max-width: 480px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 0 6px;
    }
}

/* iOS Safari - Position relative for sticky elements */
.ios-device .mobile-sticky-filter {
    position: sticky !important;
    top: 0 !important;
    z-index: 900 !important;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .mobile-sticky-filter,
    .filter-bar,
    .filter-sidebar,
    .filter-overlay,
    .quick-add-btn,
    .mobile-cart-btn,
    .load-more-container {
        display: none !important;
    }

    .products-grid {
        display: block;
    }

    .product-card {
        break-inside: avoid;
        page-break-inside: avoid;
        margin-bottom: 20px;
    }
}
