/* Image Handling Utilities - CLS Prevention & Performance */

/* Responsive Image Container - Prevents CLS */
.responsive-image-container {
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* Aspect Ratio Boxes - Prevents Layout Shift */
.aspect-16-9 {
    aspect-ratio: 16 / 9;
}

.aspect-4-3 {
    aspect-ratio: 4 / 3;
}

.aspect-3-4 {
    aspect-ratio: 3 / 4;
}

.aspect-1-1 {
    aspect-ratio: 1 / 1;
}

.aspect-21-9 {
    aspect-ratio: 21 / 9;
}

/* Fallback for browsers without aspect-ratio support */
@supports not (aspect-ratio: 1 / 1) {
    .aspect-16-9::before {
        content: '';
        display: block;
        padding-top: 56.25%; /* 9/16 = 0.5625 */
    }

    .aspect-4-3::before {
        content: '';
        display: block;
        padding-top: 75%; /* 3/4 = 0.75 */
    }

    .aspect-3-4::before {
        content: '';
        display: block;
        padding-top: 133.33%; /* 4/3 = 1.3333 */
    }

    .aspect-1-1::before {
        content: '';
        display: block;
        padding-top: 100%;
    }

    .aspect-21-9::before {
        content: '';
        display: block;
        padding-top: 42.86%; /* 9/21 = 0.4286 */
    }

    .aspect-16-9 img,
    .aspect-4-3 img,
    .aspect-3-4 img,
    .aspect-1-1 img,
    .aspect-21-9 img {
        position: absolute;
        top: 0;
        left: 0;
    }
}

/* Responsive Image Base Styles */
.responsive-image {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

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

/* Loading State - Prevents blank space */
.responsive-image[loading="lazy"] {
    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 Wrapper */
.picture-wrapper {
    position: relative;
    width: 100%;
    display: block;
}

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

/* Hero Image - CLS < 0.02 */
.hero-image-wrapper {
    position: relative;
    width: 100%;
    min-height: 100vh;
    overflow: hidden;
}

.hero-image-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #1a2a2a 0%, #0f1a1a 100%);
    z-index: 1;
}

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

/* Blur-up Placeholder Technique */
.image-blur-placeholder {
    filter: blur(20px);
    transform: scale(1.1);
    transition: filter 0.3s ease, transform 0.3s ease;
}

.image-blur-placeholder.loaded {
    filter: blur(0);
    transform: scale(1);
}

/* Image with Caption */
.image-with-caption {
    margin: 2rem 0;
}

.image-with-caption figure {
    margin: 0;
}

.image-with-caption figcaption {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #666666;
    font-style: italic;
    background: #f8f8f8;
    border-left: 3px solid #0892D0;
}

/* Performance Optimization Classes */
/* 
 * Note: Use these HTML attributes on <img> tags:
 * 
 * For above-the-fold images:
 *   loading="eager" fetchpriority="high"
 * 
 * For below-the-fold images:
 *   loading="lazy"
 * 
 * For decorative images:
 *   alt=""
 */

/* WebP/AVIF Support Detection */
@supports (background-image: -webkit-image-set(url("test.webp") 1x)) {
    .webp-supported {
        display: block;
    }
    .webp-fallback {
        display: none;
    }
}

/* Print Styles */
@media print {
    .responsive-image,
    .responsive-image-contain {
        max-width: 100%;
        page-break-inside: avoid;
    }

    .hero-image-wrapper {
        min-height: auto;
        height: 400px;
    }
}

/* Accessibility - Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .image-blur-placeholder {
        transition: none;
    }

    .responsive-image[loading="lazy"] {
        animation: none;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .responsive-image[loading="lazy"] {
        background: linear-gradient(
            90deg,
            #2a2a2a 25%,
            #1a1a1a 50%,
            #2a2a2a 75%
        );
    }

    .image-with-caption figcaption {
        background: #2a2a2a;
        color: #d0d0d0;
    }
}
