/**
 * Image Optimization Styles
 * Provides smooth loading transitions and placeholders
 */

/* Base image styles */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Loading state */
img.img-loading {
    background: linear-gradient(
        90deg,
        var(--bg-secondary, #1C1C1E) 0%,
        var(--bg-tertiary, #2C2C2E) 50%,
        var(--bg-secondary, #1C1C1E) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    opacity: 0.6;
    filter: blur(5px);
    transition: all 0.3s ease;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Loaded state */
img.img-loaded {
    opacity: 1;
    filter: blur(0);
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Error state */
img.img-error {
    opacity: 0.5;
    border: 2px dashed var(--border-color, rgba(255,255,255,0.1));
    padding: var(--spacing-md, 16px);
}

/* Progressive loading for specific image types */
.avatar-preview,
.member-avatar-image,
.method-logo-small,
.method-logo-tiny,
.gateway-logo,
.popup-thumbnail {
    object-fit: cover;
    background: var(--bg-secondary, #1C1C1E);
}

/* Aspect ratio containers to prevent layout shift */
.img-container {
    position: relative;
    overflow: hidden;
}

.img-container::before {
    content: '';
    display: block;
    padding-bottom: 75%; /* Default 4:3 aspect ratio */
}

.img-container.ratio-1-1::before {
    padding-bottom: 100%; /* Square */
}

.img-container.ratio-16-9::before {
    padding-bottom: 56.25%; /* Widescreen */
}

.img-container.ratio-4-3::before {
    padding-bottom: 75%; /* Standard */
}

.img-container.ratio-3-2::before {
    padding-bottom: 66.67%; /* Photo */
}

.img-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Optimized logos and icons */
.logo-image,
.admin-logo-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Avatar optimizations */
.member-avatar-image,
.avatar-preview {
    border-radius: 50%;
    will-change: transform;
}

/* Method logos optimization */
.method-logo-small,
.method-logo-tiny,
.gateway-logo {
    object-fit: contain;
    image-rendering: auto;
}

/* Background images optimization */
.user-profile-background {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    will-change: transform;
}

/* Prevent CLS (Cumulative Layout Shift) */
img[width][height] {
    aspect-ratio: attr(width) / attr(height);
    height: auto;
}

/* Blur-up technique for images */
.img-blur-up {
    filter: blur(10px);
    transition: filter 0.3s ease;
}

.img-blur-up.img-loaded {
    filter: blur(0);
}

/* Responsive images optimization */
@media (max-width: 768px) {
    img.img-loading {
        filter: blur(3px); /* Less blur on mobile for faster perceived load */
    }
}

/* Print optimization */
@media print {
    img.img-loading {
        display: none !important;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    img.img-loading {
        animation: none;
        background: var(--bg-secondary, #1C1C1E);
    }
    
    img.img-loaded {
        animation: none;
    }
}

/* Dark mode optimization */
@media (prefers-color-scheme: dark) {
    img.img-loading {
        background: linear-gradient(
            90deg,
            #1C1C1E 0%,
            #2C2C2E 50%,
            #1C1C1E 100%
        );
    }
}

/* Light mode optimization */
@media (prefers-color-scheme: light) {
    img.img-loading {
        background: linear-gradient(
            90deg,
            #F5F5F5 0%,
            #E8E8E8 50%,
            #F5F5F5 100%
        );
    }
}
