/**
 * Image Optimization CSS
 * Provides loading animations, placeholder styles, and performance optimizations
 */

/* Lazy Image Base Styles */
.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    will-change: opacity;
    contain: layout style paint;
    content-visibility: auto;
}

.lazy-image.loaded {
    opacity: 1;
    background: none !important;
    animation: none !important;
}

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

.lazy-image.error {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    font-size: 0.875rem;
}

/* Loading Animation */
@keyframes loading-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Skeleton Loading States */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
    border-radius: 4px;
}

.skeleton-image {
    width: 100%;
    height: 200px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
    border-radius: 8px;
}

/* Performance Optimizations */
.hero-section {
    min-height: 75vh;
    will-change: transform;
    contain: layout style paint;
}

.product-grid {
    contain: layout style;
    content-visibility: auto;
}

/* Image Container Optimizations */
.image-container {
    position: relative;
    overflow: hidden;
    contain: layout style paint;
}

.image-container img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
}

.image-container:hover img {
    transform: scale(1.05);
}

/* Responsive Image Optimizations */
.responsive-image {
    max-width: 100%;
    height: auto;
    display: block;
}

/* WebP Support Fallback */
.webp-image {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Avatar image fixes - ensure proper dimensions */
.avatar-xs {
    width: 2rem !important;
    height: 2rem !important;
    max-width: 2rem !important;
    max-height: 2rem !important;
}

.avatar-sm {
    width: 3rem !important;
    height: 3rem !important;
    max-width: 3rem !important;
    max-height: 3rem !important;
}

.avatar-md {
    width: 4.5rem !important;
    height: 4.5rem !important;
    max-width: 4.5rem !important;
    max-height: 4.5rem !important;
}

.avatar-lg {
    width: 6rem !important;
    height: 6rem !important;
    max-width: 6rem !important;
    max-height: 6rem !important;
}

.avatar-xl {
    width: 7.5rem !important;
    height: 7.5rem !important;
    max-width: 7.5rem !important;
    max-height: 7.5rem !important;
}

.avatar-xxs {
    width: 1.5rem !important;
    height: 1.5rem !important;
    max-width: 1.5rem !important;
    max-height: 1.5rem !important;
}

/* Loading States for Different Image Types */
.product-image {
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
}

.banner-image {
    width: 100%;
    height: auto;
    max-height: 400px;
    object-fit: cover;
}

.avatar-image {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

/* Error State Styling */
.image-error {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    color: #6c757d;
    font-size: 0.875rem;
    min-height: 100px;
}

.image-error::before {
    content: "⚠️";
    margin-right: 8px;
    font-size: 1.2rem;
}

/* Performance Monitoring Styles */
.performance-indicator {
    position: fixed;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    z-index: 9999;
    display: none;
}

.performance-indicator.show {
    display: block;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .lazy-image.loading {
        background: linear-gradient(90deg, #2d3748 25%, #4a5568 50%, #2d3748 75%);
    }
    
    .skeleton {
        background: linear-gradient(90deg, #2d3748 25%, #4a5568 50%, #2d3748 75%);
    }
    
    .image-error {
        background: #2d3748;
        border-color: #4a5568;
        color: #a0aec0;
    }
}

/* Print Styles */
@media print {
    .lazy-image {
        opacity: 1 !important;
        transition: none !important;
    }
    
    .loading-shimmer {
        animation: none !important;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .lazy-image.loading {
        background: #000;
        border: 2px solid #fff;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .lazy-image {
        transition: none;
    }
    
    .loading-shimmer {
        animation: none;
    }
    
    .image-container:hover img {
        transform: none;
    }
}

/* Focus Styles for Accessibility */
.lazy-image:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Container Query Support (Future) */
@supports (container-type: inline-size) {
    .image-container {
        container-type: inline-size;
    }
    
    @container (max-width: 300px) {
        .product-image {
            aspect-ratio: 4/3;
        }
    }
}

/* Critical Images - No Skeleton Loading */
.logo img,
.navbar-brand img,
.header img,
.brand img,
img[src*="logo"],
img[src*="brand"],
img[src*="header"],
img[src*="nav"],
img[alt*="logo"],
img[alt*="brand"],
img[alt*="header"],
.avatar-xs,
.avatar-sm,
.avatar-md,
.avatar-lg,
.avatar-xl,
.avatar-xxs {
    /* Exclude from skeleton loading */
    background: none !important;
    animation: none !important;
}

/* Ensure critical images don't get loading states */
.logo img.loading,
.navbar-brand img.loading,
.header img.loading,
.brand img.loading,
img[src*="logo"].loading,
img[src*="brand"].loading,
img[src*="header"].loading,
img[src*="nav"].loading,
img[alt*="logo"].loading,
img[alt*="brand"].loading,
img[alt*="header"].loading,
.avatar-xs.loading,
.avatar-sm.loading,
.avatar-md.loading,
.avatar-lg.loading,
.avatar-xl.loading,
.avatar-xxs.loading {
    background: none !important;
    animation: none !important;
    opacity: 1 !important;
}

/* Force immediate display for critical images */
.logo img,
.navbar-brand img,
.header img,
.brand img,
img[src*="logo"],
img[src*="brand"],
img[src*="header"],
img[src*="nav"],
img[alt*="logo"],
img[alt*="brand"],
img[alt*="header"] {
    opacity: 1 !important;
    transition: none !important;
} 