/**
 * Image Performance CSS for MuscatHeights Booking System
 * Optimizes image loading performance and visual feedback
 * 
 * @package    MuscatHeights_Booking
 * @since      2.0.0
 */

/* ===== LAZY LOADING OPTIMIZATIONS ===== */

/* Images waiting to load */
img[data-src] {
    background: linear-gradient(135deg, #f5f5f5 0%, #eeeeee 100%);
    min-height: 200px;
    display: block;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Loaded images */
img.loaded {
    opacity: 1;
}

/* Progressive image loading */
.progressive-image {
    transition: filter 0.3s ease;
    filter: blur(2px);
}

.progressive-image.high-quality-loaded {
    filter: blur(0);
}

/* ===== WEBP SUPPORT INDICATORS ===== */

/* WebP supported browser styles */
.webp-supported .webp-fallback {
    display: none;
}

.webp-supported .webp-image {
    display: block;
}

.no-webp .webp-image {
    display: none;
}

.no-webp .webp-fallback {
    display: block;
}

/* ===== PERFORMANCE INDICATORS ===== */

.image-performance-indicator {
    position: fixed;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
    z-index: 10000;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.image-performance-indicator:hover {
    opacity: 1;
    transform: scale(1.05);
}

.image-performance-indicator.fast {
    background: rgba(40, 167, 69, 0.9);
}

.image-performance-indicator.slow {
    background: rgba(255, 193, 7, 0.9);
}

.image-performance-indicator.very-slow {
    background: rgba(220, 53, 69, 0.9);
}

/* ===== IMAGE LOADING STATES ===== */

/* Loading placeholder with shimmer effect */
.image-loading-placeholder {
    position: relative;
    background: #f6f7f8;
    overflow: hidden;
    border-radius: 8px;
}

.image-loading-placeholder::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.6),
        transparent
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Error state for failed images */
.image-load-failed {
    border: 2px dashed #dc3545;
    padding: 20px;
    text-align: center;
    color: #dc3545;
    background: #f8f9fa;
    position: relative;
}

.image-load-failed::after {
    content: '⚠️ Image failed to load';
    font-size: 14px;
    display: block;
    margin-top: 10px;
}

/* ===== RESPONSIVE IMAGE OPTIMIZATIONS ===== */

/* Responsive image container */
.responsive-image-container {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
}

/* Aspect ratio preservation */
.aspect-ratio-16-9 {
    aspect-ratio: 16/9;
}

.aspect-ratio-4-3 {
    aspect-ratio: 4/3;
}

.aspect-ratio-1-1 {
    aspect-ratio: 1/1;
}

/* Image fitting modes */
.image-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.image-contain {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
}

/* ===== CAR IMAGE SPECIFIC OPTIMIZATIONS ===== */

/* Car card image containers */
.car-image-container {
    position: relative;
    width: 100%;
    height: 200px;
    overflow: hidden;
    border-radius: 12px 12px 0 0;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.car-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.car-image-container img:hover {
    transform: scale(1.05);
}

/* Car image overlay for loading */
.car-image-container .loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #6c757d;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.car-image-container.loading .loading-overlay {
    opacity: 1;
    visibility: visible;
}

/* Car image badges */
.car-image-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 123, 255, 0.9);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    backdrop-filter: blur(4px);
}

.car-image-badge.webp {
    background: rgba(40, 167, 69, 0.9);
}

.car-image-badge.optimized {
    background: rgba(255, 193, 7, 0.9);
    color: #212529;
}

/* ===== PICTURE ELEMENT OPTIMIZATIONS ===== */

/* Picture element styling for WebP support */
picture {
    display: block;
    width: 100%;
    height: 100%;
}

picture img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ===== LAZY LOADING INTERSECTION OBSERVER STYLES ===== */

/* Images entering viewport */
.lazy-load-image {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.lazy-load-image.loaded {
    opacity: 1;
    transform: translateY(0);
}

/* ===== PERFORMANCE OPTIMIZATION CLASSES ===== */

/* Hardware acceleration for smooth animations */
.hw-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* Contain layout for better performance */
.image-contain-layout {
    contain: layout style paint;
}

/* ===== MOBILE OPTIMIZATIONS ===== */

@media (max-width: 768px) {
    .car-image-container {
        height: 180px;
    }
    
    .image-performance-indicator {
        font-size: 10px;
        padding: 3px 6px;
    }
    
    /* Reduce motion for better mobile performance */
    .progressive-image {
        transition: filter 0.2s ease;
    }
    
    .lazy-load-image {
        transition: opacity 0.4s ease, transform 0.4s ease;
    }
}

/* ===== HIGH DPI DISPLAY OPTIMIZATIONS ===== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* High DPI specific styles */
    .car-image-container img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ===== REDUCED MOTION SUPPORT ===== */

@media (prefers-reduced-motion: reduce) {
    .progressive-image,
    .lazy-load-image,
    .car-image-container img {
        transition: none !important;
        animation: none !important;
    }
    
    .image-loading-placeholder::before {
        animation: none;
    }
}

/* ===== PRINT STYLES ===== */

@media print {
    .image-performance-indicator,
    .loading-overlay,
    .car-image-badge {
        display: none !important;
    }
    
    img[data-src] {
        opacity: 1;
        background: none;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */

/* Focus indicators for keyboard navigation */
img:focus {
    outline: 3px solid #007bff;
    outline-offset: 2px;
}

/* Screen reader only content */
.sr-only-image-status {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===== DARK MODE SUPPORT ===== */

@media (prefers-color-scheme: dark) {
    .image-loading-placeholder {
        background: #2d3748;
    }
    
    .image-loading-placeholder::before {
        background: linear-gradient(
            90deg,
            transparent,
            rgba(255, 255, 255, 0.1),
            transparent
        );
    }
    
    .image-load-failed {
        background: #2d3748;
        border-color: #e53e3e;
        color: #fed7d7;
    }
}

/* ===== IMAGE GRID OPTIMIZATIONS ===== */

/* Grid layout for image galleries */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    contain: layout;
}

.image-grid-item {
    aspect-ratio: 16/10;
    overflow: hidden;
    border-radius: 8px;
    background: #f8f9fa;
    contain: layout style paint;
}

/* ===== SRCSET AND SIZES OPTIMIZATIONS ===== */

/* Responsive image sizing */
.responsive-car-image {
    width: 100%;
    height: auto;
    max-width: 100%;
}

/* ===== BLUR-UP LOADING TECHNIQUE ===== */

.blur-up {
    filter: blur(5px);
    transition: filter 0.3s ease;
}

.blur-up.loaded {
    filter: blur(0);
}

/* ===== IMAGE COMPRESSION INDICATORS ===== */

.image-quality-indicator {
    position: absolute;
    bottom: 5px;
    left: 5px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
}

.image-quality-indicator.high {
    background: rgba(40, 167, 69, 0.8);
}

.image-quality-indicator.medium {
    background: rgba(255, 193, 7, 0.8);
    color: #212529;
}

.image-quality-indicator.low {
    background: rgba(220, 53, 69, 0.8);
}

/* ===== PERFORMANCE CRITICAL ANIMATIONS ===== */

/* Use transform3d for hardware acceleration */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translate3d(0, 20px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

.fade-in-up {
    animation: fadeInUp 0.6s ease forwards;
}

/* ===== LOADING SPINNER FOR IMAGES ===== */

.image-loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}