/* ============================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   Improves loading speed and smooth experience
   ============================================ */

/* Reduce animations on slow connections */
body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

/* Optimize images for mobile */
@media (max-width: 768px) {
    img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
        transform: translateZ(0);
        backface-visibility: hidden;
    }

    /* Lazy load placeholder */
    img[data-src] {
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
    }

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

    /* Contain layout shifts */
    .product-img {
        content-visibility: auto;
        contain-intrinsic-size: 300px;
    }

    /* GPU acceleration for smooth scrolling */
    .product,
    .product-card-compact {
        will-change: transform;
        transform: translateZ(0);
        backface-visibility: hidden;
    }

    /* Optimize fonts */
    body {
        text-rendering: optimizeSpeed;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /* Reduce repaints */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* Optimize scrolling */
    html {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }

    /* Critical CSS loading */
    .loading-skeleton {
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
        border-radius: 8px;
    }

    /* Defer offscreen content */
    .below-fold {
        content-visibility: auto;
        contain-intrinsic-size: 500px;
    }

    /* Optimize animations */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
}

/* Loading state */
.page-loading {
    pointer-events: none;
}

.page-loading * {
    cursor: wait !important;
}

/* Intersection observer optimization */
[data-lazy] {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

[data-lazy].loaded {
    opacity: 1;
    transform: translateY(0);
}

/* Critical rendering path optimization */
.above-fold {
    contain: layout style paint;
}

/* Network-aware loading */
@media (prefers-reduced-data: reduce) {
    /* Reduce image quality on slow connections */
    img {
        image-rendering: pixelated;
    }

    /* Disable background images */
    *::before,
    *::after {
        background-image: none !important;
    }

    /* Simplify gradients */
    [style*="gradient"] {
        background: var(--purple-primary) !important;
    }
}

/* Optimize touch interactions */
@media (max-width: 768px) {
    button,
    a,
    input,
    textarea,
    select {
        touch-action: manipulation;
    }

    /* Larger touch targets */
    .btn-add-cart,
    .btn-whatsapp,
    .view-btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Preload critical fonts */
@font-face {
    font-family: 'system-ui';
    font-display: swap;
}

/* Optimize z-index layers */
@media (max-width: 768px) {
    /* Reduce layer complexity */
    .product-detail-panel,
    .panel-overlay {
        isolation: isolate;
    }

    /* Force hardware acceleration */
    .mobile-category-card,
    .subcategory-section {
        transform: translate3d(0, 0, 0);
    }
}

/* Service Worker support notification */
.sw-update-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #7c3aed;
    color: white;
    padding: 12px 24px;
    border-radius: 999px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 99999;
    display: none;
    animation: slideUp 0.3s ease;
}

.sw-update-notification.show {
    display: block;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Progressive Web App optimizations */
@media (display-mode: standalone) {
    body {
        user-select: none;
        -webkit-user-select: none;
    }

    /* Add safe area padding for notched devices */
    .navbar,
    .panel-header {
        padding-top: env(safe-area-inset-top);
    }

    .product-detail-panel {
        padding-bottom: env(safe-area-inset-bottom);
    }
}
