/**
 * ⚡ Performance Optimization Styles
 * 
 * - Lazy loading effects
 * - Infinite scroll indicators
 * - Loading states
 * - Smooth animations
 * 
 * @version 2.0.0
 */

/* ========================================
   LAZY LOADING STYLES
   ======================================== */

/* Lazy image placeholder */
img[data-src],
img[data-lazy] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    min-height: 200px;
    filter: blur(10px);
    transition: filter 0.3s ease-in-out;
}

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

/* Lazy loading state */
img.lazy-loading {
    opacity: 0.6;
    filter: blur(10px);
}

/* Lazy loaded (revealed) */
img.lazy-loaded {
    opacity: 1;
    filter: none !important;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Lazy load error */
img.lazy-error {
    background: #fee;
    border: 2px dashed #fcc;
    display: flex;
    align-items: center;
    justify-content: center;
}

img.lazy-error::after {
    content: "فشل التحميل";
    color: #c33;
    font-size: 14px;
}

/* ========================================
   INFINITE SCROLL STYLES
   ======================================== */

/* Scroll sentinel (invisible trigger) */
.scroll-sentinel {
    height: 1px;
    visibility: hidden;
    pointer-events: none;
}

/* Loading indicator */
.loading-more {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    animation: pulse 2s ease-in-out infinite;
}

.loading-more .spinner-border {
    width: 3rem;
    height: 3rem;
    border-width: 0.3em;
}

.loading-more p {
    margin-top: 16px;
    font-size: 16px;
    color: #666;
    font-weight: 500;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Load more button */
.btn-load-more {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 400px;
    margin: 40px auto;
    padding: 16px 32px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-load-more:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-load-more:active {
    transform: translateY(0);
}

.btn-load-more:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-load-more .btn-loader {
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* End of products message */
.no-more-products {
    padding: 60px 20px;
    text-align: center;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 16px;
    margin: 40px 0;
}

.no-more-products i {
    display: block;
    margin-bottom: 16px;
    font-size: 48px;
    color: #28a745;
    animation: bounceIn 0.6s ease;
}

.no-more-products p {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
    }
}

/* ========================================
   PRODUCTS GRID OPTIMIZATION
   ======================================== */

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    padding: 0 16px;
}

@media (max-width: 768px) {
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 16px;
        padding: 0 8px;
    }
}

/* Product card entrance animation */
.product-card-v2[data-aos] {
    opacity: 0;
    transform: translateY(30px);
}

.product-card-v2[data-aos].aos-animate {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

/* ========================================
   PERFORMANCE HINTS
   ======================================== */

/* Use GPU acceleration for transforms */
.product-card-v2,
.image-wrapper-v2,
.btn-load-more {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Reduce repaints during scroll */
.products-grid {
    contain: layout style paint;
}

.product-card-v2 {
    contain: layout style;
}

/* ========================================
   LOADING SKELETON (Alternative)
   ======================================== */

.skeleton-card {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    animation: shimmer 1.5s infinite;
}

.skeleton-image {
    width: 100%;
    height: 200px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 8px;
    margin-bottom: 12px;
}

.skeleton-title {
    height: 20px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    margin-bottom: 8px;
}

.skeleton-price {
    height: 24px;
    width: 60%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 4px;
}

/* ========================================
   SCROLL PERFORMANCE
   ======================================== */

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    img[data-src],
    img[data-lazy] {
        animation: none;
        filter: none;
    }
}

/* ========================================
   MOBILE OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) {
    /* Reduce animations on mobile for performance */
    .product-card-v2[data-aos] {
        animation-duration: 0.3s;
    }
    
    /* Smaller loading indicator */
    .loading-more {
        padding: 30px 15px;
    }
    
    .loading-more .spinner-border {
        width: 2rem;
        height: 2rem;
    }
    
    .loading-more p {
        font-size: 14px;
    }
    
    /* Compact end message */
    .no-more-products {
        padding: 40px 15px;
        margin: 30px 0;
    }
    
    .no-more-products i {
        font-size: 36px;
    }
    
    .no-more-products p {
        font-size: 16px;
    }
}

/* ========================================
   PRINT STYLES (Hide dynamic elements)
   ======================================== */

@media print {
    .scroll-sentinel,
    .loading-more,
    .btn-load-more,
    .no-more-products {
        display: none !important;
    }
}
