/**
 * Lazy Loading Styles
 * Provides smooth loading experience for images
 */

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

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

/* Loading placeholder */
.lazy-image:not(.loaded) {
    background: linear-gradient(90deg, #f0f0f5 25%, #e8e8f0 50%, #f0f0f5 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
}

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

/* Picture element support */
picture {
    display: inline-block;
    line-height: 0;
}

picture img {
    display: block;
    width: 100%;
    height: auto;
}

/* Blur-up effect for progressive loading */
.lazy-image.blur-up {
    filter: blur(10px);
    transition: filter 0.3s ease-in-out, opacity 0.3s ease-in-out;
}

.lazy-image.blur-up.loaded {
    filter: blur(0);
}

/* Aspect ratio containers for preventing layout shift */
.image-container {
    position: relative;
    overflow: hidden;
}

.image-container::before {
    content: '';
    display: block;
    padding-top: var(--aspect-ratio, 56.25%); /* Default 16:9 */
}

.image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Specific aspect ratios */
.aspect-16-9::before {
    padding-top: 56.25%;
}

.aspect-4-3::before {
    padding-top: 75%;
}

.aspect-1-1::before {
    padding-top: 100%;
}

.aspect-21-9::before {
    padding-top: 42.86%;
}

/* Loading spinner for images */
.image-loading {
    position: relative;
}

.image-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid rgba(59, 130, 246, 0.2);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spinner 0.8s linear infinite;
}

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

/* Error state */
.image-error {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 14px;
    min-height: 200px;
}

.image-error::before {
    content: '⚠️ Image failed to load';
}

/* Responsive images */
@media (max-width: 768px) {
    .lazy-image:not(.loaded) {
        min-height: 200px;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .lazy-image,
    .lazy-image.blur-up {
        transition: none;
        animation: none;
    }
    
    .lazy-image:not(.loaded) {
        animation: none;
        background: #f0f0f5;
    }
}

/* WebP support detection fallback */
.no-webp picture source[type="image/webp"] {
    display: none;
}

/* Optimize for print */
@media print {
    .lazy-image {
        opacity: 1 !important;
        filter: none !important;
    }
}
