/* Mobile Performance Optimization Styles */

/* Critical CSS for Above the Fold Content */
:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --text-color: #333;
    --bg-color: #fff;
    --border-color: #e5e7eb;
}

/* Performance optimizations */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

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

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Reduce repaints during scroll */
.fixed-header,
.sticky-element {
    will-change: transform;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* Optimize image rendering */
img {
    content-visibility: auto;
    contain-intrinsic-size: 400px 300px;
}

/* Lazy loading styles */
.lazy-image {
    background: #f0f0f0;
    background-image: linear-gradient(
        90deg,
        #f0f0f0 0%,
        #f8f8f8 50%,
        #f0f0f0 100%
    );
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

.lazy-loaded {
    animation: fadeIn 0.3s;
    background: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Mobile-specific optimizations */
@media (max-width: 768px) {
    /* Reduce animations on mobile */
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
    
    /* Optimize touch targets */
    button,
    a,
    input,
    select,
    textarea {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Prevent horizontal scroll */
    html,
    body {
        overflow-x: hidden;
        max-width: 100%;
    }
    
    /* Optimize font sizes for mobile */
    body {
        font-size: 16px; /* Prevent zoom on input focus */
    }
    
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
    
    /* Reduce shadow complexity on mobile */
    .card,
    .shadow {
        box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    }
    
    /* Optimize product cards for mobile */
    .product-card {
        contain: layout style;
    }
    
    .product-card img {
        width: 100%;
        height: auto;
        aspect-ratio: 1/1;
        object-fit: cover;
    }
    
    /* Reduce complex gradients */
    .gradient-bg {
        background: var(--primary-color) !important;
    }
    
    /* Optimize swiper for mobile */
    .swiper-container {
        touch-action: pan-y;
    }
    
    .swiper-slide {
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }
    
    /* Optimize modals for mobile */
    .modal {
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-backdrop {
        backdrop-filter: none;
        background-color: rgba(0, 0, 0, 0.5);
    }
    
    /* Reduce blur effects on mobile */
    .blur-effect {
        backdrop-filter: none !important;
        background-color: rgba(255, 255, 255, 0.95) !important;
    }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Network-aware optimizations */
@media (prefers-reduced-data: reduce) {
    /* Hide decorative images */
    .decorative-image,
    .background-image {
        display: none !important;
    }
    
    /* Use system fonts */
    body {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    }
    
    /* Reduce image quality */
    img {
        filter: contrast(0.95);
    }
}

/* Dark mode optimizations */
@media (prefers-color-scheme: dark) {
    :root {
        --text-color: #e5e7eb;
        --bg-color: #1f2937;
        --border-color: #374151;
    }
    
    body {
        background-color: var(--bg-color);
        color: var(--text-color);
    }
    
    img {
        opacity: 0.9;
    }
}

/* Container queries for responsive components */
@container (max-width: 400px) {
    .product-card {
        grid-template-columns: 1fr;
    }
    
    .product-info {
        padding: 0.5rem;
    }
}

/* Optimize print styles */
@media print {
    * {
        background: transparent !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    a,
    a:visited {
        text-decoration: underline;
    }
    
    img {
        max-width: 100% !important;
    }
    
    @page {
        margin: 0.5cm;
    }
}

/* Critical fonts */
@font-face {
    font-family: 'System';
    font-style: normal;
    font-weight: 400;
    src: local('Segoe UI'), local('Roboto'), local('Helvetica Neue'), local('Arial');
    font-display: swap;
}

/* Optimize form inputs */
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

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

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

/* Optimize buttons */
.btn {
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

/* Optimize navigation */
.navbar {
    contain: layout style;
    position: sticky;
    top: 0;
    z-index: 1000;
}

/* Progressive enhancement */
.no-js .lazy-image {
    display: none;
}

.no-js .lazy-image + noscript img {
    display: block;
}

/* High performance GPU animations */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* Optimize cart animations */
.cart-add-animation {
    animation: cartAdd 0.3s ease-out;
}

@keyframes cartAdd {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

/* Mobile-first grid system */
.mobile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

@media (min-width: 768px) {
    .mobile-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

@media (min-width: 1024px) {
    .mobile-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }
}