/**
 * Lazy Loading Styles for Better UX
 * Prevents layout shift (CLS) and provides smooth transitions
 */

/* Default state for lazy-loading images */
img[data-src],
img[data-srcset] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    min-height: 200px;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

/* Shimmer animation for loading state */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* When image is loading */
img.lazy-loading {
    opacity: 0;
}

/* When image is loaded */
img.lazy-loaded {
    opacity: 1;
    animation: none;
    background: none;
}

/* Smooth fade-in for loaded images */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

img.lazy-loaded {
    animation: fadeIn 0.3s ease-in-out;
}

/* Error state */
img.img-error {
    background: #f5f5f5;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
}

img.img-error::after {
    content: '📷';
    font-size: 3rem;
    opacity: 0.3;
}

 

/* Aspect ratio boxes to prevent CLS */
.img-container {
    position: relative;
    overflow: hidden;
    background: #f5f5f5;
}

.img-container::before {
    content: '';
    display: block;
    padding-top: calc(var(--aspect-ratio, 56.25%) * 1%); /* Default 16:9 ratio */
}

.img-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Product images - 1:1 ratio */
.img-container-square::before {
    padding-top: 100%;
}

/* Wide images - 16:9 ratio */
.img-container-wide::before {
    padding-top: 56.25%;
}

/* Portrait images - 4:3 ratio */
.img-container-portrait::before {
    padding-top: 133.33%;
}

/* Background image lazy loading */
[data-bg],
[data-bg-set] {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-color: #f0f0f0;
    position: relative;
}

[data-bg]::before,
[data-bg-set]::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

[data-bg].bg-loaded::before,
[data-bg-set].bg-loaded::before {
    display: none;
}

/* Priority/LCP images - no placeholder needed */
img[data-lcp="true"],
img.lcp-image {
    background: none;
    animation: none;
    min-height: auto;
    opacity: 1;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    img[data-src],
    img[data-srcset] {
        min-height: 150px;
    }
}

/* Print styles */
@media print {
    img[data-src] {
        opacity: 1;
        background: none;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    img[data-src],
    img[data-srcset],
    img.lazy-loaded {
        animation: none;
        transition: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    img[data-src],
    img[data-srcset] {
        background: linear-gradient(90deg, #2a2a2a 25%, #1a1a1a 50%, #2a2a2a 75%);
    }
    
    [data-bg],
    [data-bg-set] {
        background-color: #2a2a2a;
    }
    
    [data-bg]::before,
    [data-bg-set]::before {
        background: linear-gradient(90deg, #2a2a2a 25%, #1a1a1a 50%, #2a2a2a 75%);
    }
}
