/**
 * Lazy Loading Styles
 * Provides visual feedback during image loading
 */

/* Base styles for lazy images */
img[data-src],
img[data-srcset] {
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    min-height: 100px;
}

.dark img[data-src],
.dark img[data-srcset] {
    background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
}

/* Loading state */
.lazy-loading {
    position: relative;
    overflow: hidden;
}

/* Add subtle pulse animation while loading */
.lazy-loading::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.3) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    animation: shimmer 2s infinite;
    z-index: 1;
}

.dark .lazy-loading::before {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0) 100%
    );
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Loaded state */
.lazy-loaded {
    animation: fadeIn 0.5s ease-in;
}

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

/* Error state */
.lazy-error {
    position: relative;
    background: #fee2e2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dark .lazy-error {
    background: #7f1d1d;
}

.lazy-error::after {
    content: '⚠️';
    font-size: 2rem;
    position: absolute;
    color: #dc2626;
}

/* Product card specific styles */
.product-card img[data-src],
.product-card img[data-srcset] {
    aspect-ratio: 1;
    object-fit: cover;
}

/* Gallery specific styles */
.product-gallery img[data-src],
.product-gallery img[data-srcset] {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Thumbnail specific styles */
.product-thumbnail img[data-src],
.product-thumbnail img[data-srcset] {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Prevent layout shift */
img[data-src],
img[data-srcset] {
    display: block;
    width: 100%;
    height: auto;
}

/* Loading spinner option (alternative to shimmer) */
.lazy-loading.spinner-style::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #f3f4f6;
    border-top-color: #f97316;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    background: none;
}

.dark .lazy-loading.spinner-style::before {
    border-color: #374151;
    border-top-color: #fb923c;
}

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

/* Accessibility: Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .lazy-loading::before {
        animation: none;
    }

    .lazy-loaded {
        animation: none;
    }

    img[data-src],
    img[data-srcset] {
        filter: none !important;
        transform: none !important;
        transition: none !important;
    }
}

/* Low-quality placeholder (LQIP) support */
img[data-src][src],
img[data-srcset][src] {
    /* If img already has a low-quality src, show it blurred */
    filter: blur(20px);
    transform: scale(1.1);
}
