/**
 * Image Optimization CSS - PWA Phase 5
 *
 * Styles for responsive images, blur-up progressive loading,
 * aspect ratio containers, and placeholders.
 */

/* =============================================================================
   RESPONSIVE IMAGE CONTAINER
   ============================================================================= */

.responsive-image-container {
    position: relative;
    overflow: hidden;
    background-color: #f0f0f0;
    background-size: cover;
    background-position: center;
}

/* Aspect ratio containers */
.responsive-image-container.aspect-square {
    aspect-ratio: 1 / 1;
}

.responsive-image-container.aspect-4-3 {
    aspect-ratio: 4 / 3;
}

.responsive-image-container.aspect-16-9 {
    aspect-ratio: 16 / 9;
}

.responsive-image-container.aspect-3-2 {
    aspect-ratio: 3 / 2;
}

/* =============================================================================
   RESPONSIVE IMAGE
   ============================================================================= */

.responsive-image {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

/* Blur-up progressive loading effect */
.responsive-image.blur-up {
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.responsive-image.blur-up.loaded {
    opacity: 1;
}

/* Smooth fade-in when image loads */
.responsive-image:not(.blur-up) {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* =============================================================================
   PLACEHOLDER FOR MISSING IMAGES
   ============================================================================= */

.responsive-image-container.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e0e0e0 0%, #f5f5f5 100%);
    min-height: 200px;
}

.placeholder-icon {
    color: #bbb;
    text-align: center;
}

.placeholder-icon i {
    opacity: 0.5;
}

/* =============================================================================
   LOADING SKELETON
   ============================================================================= */

.image-skeleton {
    position: relative;
    overflow: hidden;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

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

/* =============================================================================
   PICTURE ELEMENT OPTIMIZATION
   ============================================================================= */

picture {
    display: block;
    width: 100%;
}

picture img {
    max-width: 100%;
    height: auto;
}

/* =============================================================================
   LAZY LOADING STATES
   ============================================================================= */

img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Prevent layout shift during image load */
img[width][height] {
    height: auto;
}

/* =============================================================================
   IMAGE GALLERY OPTIMIZATION
   ============================================================================= */

.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.image-gallery-item {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.image-gallery-item:hover {
    transform: scale(1.05);
}

.image-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* =============================================================================
   WEBP DETECTION & FALLBACK
   ============================================================================= */

/* These classes are added by JavaScript to indicate WebP support */
.webp .webp-unsupported,
.no-webp .webp-only {
    display: none;
}

/* =============================================================================
   PRINT OPTIMIZATION
   ============================================================================= */

@media print {
    .responsive-image-container {
        break-inside: avoid;
    }

    /* Load all images for print */
    img[loading="lazy"] {
        opacity: 1;
    }
}

/* =============================================================================
   MOBILE OPTIMIZATIONS
   ============================================================================= */

@media (max-width: 640px) {
    .image-gallery {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
    }

    .responsive-image-container.placeholder {
        min-height: 150px;
    }
}

/* =============================================================================
   DARK MODE SUPPORT
   ============================================================================= */

@media (prefers-color-scheme: dark) {
    .responsive-image-container {
        background-color: #2a2a2a;
    }

    .responsive-image-container.placeholder {
        background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
    }

    .placeholder-icon {
        color: #666;
    }

    .image-skeleton {
        background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
    }
}

/* =============================================================================
   REDUCED MOTION SUPPORT
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {
    .responsive-image.blur-up,
    .responsive-image:not(.blur-up),
    .image-gallery-item,
    img[loading="lazy"] {
        animation: none;
        transition: none;
    }
}

/* =============================================================================
   HIGH DPI DISPLAYS
   ============================================================================= */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Images on retina displays use higher resolution variants automatically via srcset */
}

/* =============================================================================
   UTILITY CLASSES
   ============================================================================= */

.img-cover {
    object-fit: cover;
}

.img-contain {
    object-fit: contain;
}

.img-fill {
    object-fit: fill;
}

.img-rounded {
    border-radius: var(--border-radius, 8px);
}

.img-circle {
    border-radius: 50%;
    aspect-ratio: 1 / 1;
}

.img-shadow {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
