/*!
 * Lazy Loading Styles
 * Provides smooth loading transitions and layout stability for images
 * Optimizes user experience while images load progressively
 */

/* Base image styling for lazy loading */
img[loading='lazy'] {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

/* Images that have loaded */
img[loading='lazy'].loaded,
img[loading='lazy']:not([src*='data:']) {
    opacity: 1;
}

/* Fallback for browsers without native lazy loading support */
.no-native-lazy-loading img[data-src] {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.no-native-lazy-loading img[data-src].loaded {
    opacity: 1;
}

/* Loading shimmer effect for better UX */
@keyframes shimmer {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

.lazy-loading-placeholder {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200px 100%;
    animation: shimmer 1.5s infinite;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 14px;
}

/* Aspect ratio containers to prevent layout shifts */
.aspect-ratio-container {
    position: relative;
    width: 100%;
    height: 0;
    overflow: hidden;
}

.aspect-ratio-container.ratio-16-9 {
    padding-bottom: 56.25%; /* 16:9 */
}

.aspect-ratio-container.ratio-4-3 {
    padding-bottom: 75%; /* 4:3 */
}

.aspect-ratio-container.ratio-1-1 {
    padding-bottom: 100%; /* 1:1 */
}

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

/* Performance optimizations */
img[loading='lazy'] {
    content-visibility: auto;
    contain-intrinsic-size: 300px 200px;
}

/* Ensure hero images load immediately with high priority */
img[loading='eager'] {
    opacity: 1;
}

img[fetchpriority='high'] {
    opacity: 1;
}

/* Smooth transitions for JavaScript fallback */
.lazy-image {
    transition: opacity 0.3s ease-in-out;
}

.lazy-image.loading {
    opacity: 0.5;
}

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

.lazy-image.error {
    opacity: 0.3;
    filter: grayscale(100%);
}

/* Mobile optimizations */
@media (max-width: 768px) {
    img[loading='lazy'] {
        contain-intrinsic-size: 300px 150px;
    }

    .lazy-loading-placeholder {
        min-height: 150px;
        font-size: 12px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .lazy-loading-placeholder {
        background: #000;
        color: #fff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    img[loading='lazy'],
    .lazy-image {
        transition: none;
    }

    .lazy-loading-placeholder {
        animation: none;
        background: #f0f0f0;
    }
}

/* Print styles - ensure all images are visible */
@media print {
    img[loading='lazy'],
    .lazy-image {
        opacity: 1 !important;
    }

    .lazy-loading-placeholder {
        display: none !important;
    }
}

/* Focus management for accessibility */
img[loading='lazy']:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Loading states for different image types */
.blog-post img[loading='lazy'] {
    border-radius: 8px;
}

.product-image img[loading='lazy'] {
    background-color: #f8f9fa;
}

.thumbnail img[loading='lazy'] {
    contain-intrinsic-size: 150px 150px;
}

/* Error handling styles */
img[loading='lazy'].error::after {
    content: 'Image failed to load';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
}
