/**
 * Performance Optimization CSS
 * Styles for lazy loading, skeleton loading, and performance enhancements
 */

/* Lazy Loading Images */
.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

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

/* Image placeholder while loading */
.image-placeholder {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 14px;
}

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

/* Skeleton Loading for Product Cards */
.product-card.loading {
    pointer-events: none;
}

.product-card.loading .product-image {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    min-height: 200px;
}

.product-card.loading .product-name,
.product-card.loading .product-price,
.product-card.loading .product-spec {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    color: transparent;
    border-radius: 4px;
}

.product-card.loading .product-name {
    height: 20px;
    margin-bottom: 8px;
}

.product-card.loading .product-price {
    height: 16px;
    width: 60%;
    margin-bottom: 4px;
}

.product-card.loading .product-spec {
    height: 14px;
    width: 80%;
}

/* Performance optimizations for swipers */
.swiper-container {
    will-change: transform;
}

.swiper-slide {
    will-change: transform;
    backface-visibility: hidden;
}

/* Optimize tab switching */
.tab-content {
    will-change: opacity;
    transition: opacity 0.3s ease-in-out;
}

.tab-content:not(.active) {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    left: -9999px;
}

.tab-content.active {
    opacity: 1;
    pointer-events: auto;
    position: relative;
    left: auto;
}

/* Optimize image loading */
img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: optimize-contrast;
}

/* Critical above-the-fold optimizations */
.home-banner,
.promotional-marquee {
    contain: layout style paint;
}

/* Reduce layout shifts */
.product-card {
    min-height: 350px;
    contain: layout;
}

.series-item {
    min-height: 125px;
    contain: layout;
}

/* Optimize animations */
@media (prefers-reduced-motion: reduce) {
    .lazy-image,
    .tab-content,
    .image-placeholder {
        transition: none;
        animation: none;
    }
}

/* Loading states for sections */
.section-loading {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(90deg, #f8f8f8 25%, #e8e8e8 50%, #f8f8f8 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

.section-loading::after {
    content: "Loading...";
    color: #999;
    font-size: 16px;
}

/* Optimize font loading */
@font-face {
    font-family: 'Hisense-Font';
    font-display: swap;
}

/* Critical CSS for above-the-fold content */
.promotional-marquee {
    transform: translateZ(0);
    will-change: transform;
}

.marquee-content {
    transform: translateZ(0);
    will-change: transform;
}

/* Intersection Observer loading states */
.fade-in-on-scroll {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.fade-in-on-scroll.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Optimize hero banner */
.hero-banner-section {
    contain: layout style;
}

.hero-swiper {
    will-change: transform;
}

/* Preload critical images */
.critical-image {
    loading: eager;
    fetchpriority: high;
}

/* Non-critical images */
.lazy-load {
    loading: lazy;
    fetchpriority: low;
}

/* Optimize grid layouts */
.series-grid,
.tab-content-container {
    contain: layout;
}

/* Cache-friendly animations */
.swiper-slide-active {
    transform: translateZ(0);
}

/* Reduce paint complexity */
.product-badge {
    will-change: auto;
    transform: translateZ(0);
}

/* Optimize text rendering */
.section-title,
.product-name {
    text-rendering: optimizeSpeed;
}

/* Performance hints for browsers */
.swiper-wrapper {
    transform: translateZ(0);
}

/* Optimize newsletter section */
/* .newsletter-section {
    contain: layout style;
} */

/* Loading spinner for dynamic content */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error states */
.load-error {
    padding: 20px;
    text-align: center;
    color: #e74c3c;
    background: #fdf2f2;
    border: 1px solid #fecaca;
    border-radius: 4px;
    margin: 10px 0;
}

.load-error::before {
    content: "⚠ ";
    font-size: 18px;
}

/* Retry button */
.retry-button {
    background: #3498db;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 10px;
    transition: background 0.3s ease;
}

.retry-button:hover {
    background: #2980b9;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .product-card {
        min-height: 300px;
    }
    
    .series-item {
        min-height: 150px;
    }
    
    .image-placeholder {
        min-height: 150px;
    }
}
