/**
 * Lazy Loading Styles
 * Provides smooth transitions and placeholder effects
 */

/* Base lazy image styles */
img[data-src],
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
}

/* Loading state */
img.lazy-loading {
    opacity: 0.3;
    filter: blur(5px);
}

/* Loaded state */
img.lazy-loaded {
    opacity: 1;
    filter: none;
}

/* Error state */
img.lazy-error {
    opacity: 0.5;
    background: #f0f0f0;
}

/* Placeholder effect - Low quality blur-up */
img[data-src]::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #f0f0f0 0%, #e0e0e0 100%);
    z-index: -1;
}

/* Background lazy loading */
[data-bg] {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

[data-bg]:not(.bg-loaded) {
    background-color: #f0f0f0;
}

.bg-loaded {
    animation: fadeInBg 0.6s ease-in-out;
}

/* Video lazy loading */
video[data-src] {
    background: #000;
}

video.video-loaded {
    animation: fadeIn 0.6s ease-in-out;
}

/* Skeleton loader for images */
.skeleton-image {
    position: relative;
    overflow: hidden;
    background: linear-gradient(90deg, #f0f0f0 0%, #e0e0e0 50%, #f0f0f0 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* Aspect ratio preservation */
.lazy-wrapper {
    position: relative;
    overflow: hidden;
}

.lazy-wrapper::before {
    content: '';
    display: block;
    padding-top: 56.25%;
    /* 16:9 aspect ratio */
}

.lazy-wrapper img,
.lazy-wrapper video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Specific aspect ratios */
.lazy-wrapper.aspect-1-1::before {
    padding-top: 100%;
    /* Square */
}

.lazy-wrapper.aspect-4-3::before {
    padding-top: 75%;
    /* 4:3 */
}

.lazy-wrapper.aspect-16-9::before {
    padding-top: 56.25%;

    to {
        opacity: 1;
    }
}

@keyframes fadeInBg {
    from {
        opacity: 0;
        transform: scale(1.05);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

/* Progressive enhancement */
.no-js img[data-src] {
    /* If JS is disabled, ensure image shows */
    opacity: 1;
}

/* Print styles - load all images */
@media print {

    img[data-src],
    img.lazy-loading {
        opacity: 1;
        filter: none;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {

    img[data-src],
    img.lazy-loading,
    img.lazy-loaded {
        transition: none;
        animation: none;
    }
}

/* Loading spinner overlay */
.lazy-loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 10;
}

@keyframes spin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Image gallery lazy loading */
.gallery-item {
    position: relative;
}

.gallery-item img[data-src] {
    cursor: pointer;
}

.gallery-item.lazy-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #fff;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Responsive images with lazy loading */
picture {
    display: block;
    position: relative;
}

picture img {
    width: 100%;
    height: auto;
    display: block;
}

/* Noscript fallback */
noscript img {
    opacity: 1 !important;
    filter: none !important;
}