/* Image Optimization CSS - Luxury Watch Service Theme */

/* Critical LCP and CLS optimizations */
img {
    opacity: 1 !important;
    filter: none !important;
    transition: none !important;
    /* Prevent layout shift with explicit dimensions */
    width: auto;
    height: auto;
    max-width: 100%;
}

/* Priority loading for above-the-fold content */
img[loading="eager"],
img:not([loading="lazy"]),
.hero-image,
.featured-image,
img.wp-post-image {
    opacity: 1 !important;
    filter: none !important;
    /* Immediate visibility for LCP candidates */
    display: block !important;
}

img.loaded,
img[loading="eager"],
img:not([loading="lazy"]) {
    opacity: 1 !important;
    filter: none !important;
}

/* Error handling for failed image loads */
img.error {
    opacity: 0.5;
    filter: grayscale(100%);
}

/* Background image lazy loading */
[data-bg] {
    background-image: none !important;
    background-color: #f5f5f5;
    transition: background-image 0.4s ease-in-out;
}

.bg-loaded {
    background-color: transparent;
}

.bg-error {
    background-color: #e0e0e0;
}

/* Modern picture element styling */
picture {
    display: inline-block;
    line-height: 0;
}

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

/* Enhanced aspect ratio preservation for zero CLS */
.image-wrapper {
    position: relative;
    overflow: hidden;
    /* Prevent layout shift during image load */
    contain: layout style;
}

.image-wrapper::before {
    content: '';
    display: block;
    padding-bottom: var(--aspect-ratio, 56.25%); /* Default 16:9 */
    /* Ensure no layout shift */
    width: 100%;
    height: 0;
}

.image-wrapper img,
.image-wrapper picture {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Immediate loading for critical images */
    opacity: 1 !important;
    transform: translateZ(0); /* GPU acceleration */
}

/* Critical LCP image optimization */
.hero-image-container,
.featured-image-container,
.wp-post-image {
    --aspect-ratio: 42.857%; /* 21:9 for hero images */
    contain: layout style paint;
}

.gallery-image-container {
    --aspect-ratio: 100%; /* 1:1 for gallery images */
    contain: layout style;
}

.thumbnail-container {
    --aspect-ratio: 75%; /* 4:3 for thumbnails */
    contain: layout style;
}

/* WebP/AVIF progressive enhancement */
.no-webp .webp-only,
.no-avif .avif-only {
    display: none;
}

/* Image loading states */
.image-loading {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .retina-optimized {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Print optimizations */
@media print {
    img[loading="lazy"] {
        opacity: 1 !important;
    }
    
    .bg-loading,
    [data-bg] {
        background-image: inherit !important;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    img,
    picture,
    [data-bg] {
        transition: none !important;
        animation: none !important;
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Reduce transition duration on mobile for better performance */
    img[loading="lazy"],
    [data-bg] {
        transition-duration: 0.2s;
    }
}

/* Dark mode support for image placeholders */
@media (prefers-color-scheme: dark) {
    [data-bg] {
        background-color: #2a2a2a;
    }
    
    .bg-error {
        background-color: #404040;
    }
    
    .image-loading {
        background: linear-gradient(90deg, #2a2a2a 25%, #404040 50%, #2a2a2a 75%);
        background-size: 200% 100%;
    }
}
