/**
 * Image Optimization CSS for Flat Fee Movers
 * Handles responsive images, lazy loading states, and performance optimizations
 */

/* ==========================================================================
   Responsive Image Base Styles
   ========================================================================== */

.responsive-image {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Picture element styling */
picture {
    display: block;
    width: 100%;
}

picture img {
    width: 100%;
    height: auto;
    object-fit: cover;
}

/* ==========================================================================
   Lazy Loading States
   ========================================================================== */

/* Loading state */
.lazy-loading {
    background-color: #f0f0f0;
    background-image: linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
                      linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
                      linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
                      linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    animation: loading-shimmer 1.5s linear infinite;
    min-height: 200px;
}

@keyframes loading-shimmer {
    0% { background-position: 0 0, 0 10px, 10px -10px, -10px 0px; }
    100% { background-position: 20px 0, 20px 10px, 30px -10px, 10px 0px; }
}

/* Loaded state */
.lazy-loaded {
    background: none !important;
    animation: fade-in 0.3s ease-in-out;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Error state */
.lazy-error {
    background-color: #f8f9fa;
    border: 2px dashed #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: #6c757d;
    font-size: 14px;
    position: relative;
}

.lazy-error::before {
    content: "⚠️ Image failed to load";
    text-align: center;
}

/* ==========================================================================
   Critical Image Optimization
   ========================================================================== */

/* Logo optimization */
.logo-image {
    width: auto;
    height: 60px;
    max-width: 300px;
}

@media (max-width: 768px) {
    .logo-image {
        height: 45px;
        max-width: 200px;
    }
}

/* Hero image optimization */
.hero-image {
    width: 100%;
    height: auto;
    object-fit: cover;
    aspect-ratio: 2 / 1;
}

@media (max-width: 768px) {
    .hero-image {
        aspect-ratio: 4 / 3;
    }
}

/* Service card images */
.service-image {
    width: 100%;
    height: auto;
    object-fit: cover;
    aspect-ratio: 4 / 3;
    border-radius: 8px;
}

/* Team/staff photos */
.team-image {
    width: 100%;
    height: auto;
    object-fit: cover;
    aspect-ratio: 1 / 1;
    border-radius: 50%;
}

/* ==========================================================================
   Performance Optimizations
   ========================================================================== */

/* Prevent layout shift */
.aspect-ratio-container {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.aspect-ratio-container::before {
    content: '';
    display: block;
    padding-top: var(--aspect-ratio, 75%); /* Default 4:3 ratio */
}

.aspect-ratio-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Common aspect ratios */
.aspect-16-9::before { padding-top: 56.25%; }
.aspect-4-3::before { padding-top: 75%; }
.aspect-3-2::before { padding-top: 66.67%; }
.aspect-2-1::before { padding-top: 50%; }
.aspect-1-1::before { padding-top: 100%; }

/* ==========================================================================
   Blur Effect for Lazy Loading
   ========================================================================== */

.blur-load {
    background-size: cover;
    background-position: center;
    filter: blur(5px);
    transform: scale(1.1);
    transition: filter 0.3s ease, transform 0.3s ease;
}

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

/* ==========================================================================
   Image Gallery Styles
   ========================================================================== */

.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin: 2rem 0;
}

.image-gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.image-gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   WebP Support Detection
   ========================================================================== */

/* Hide WebP images when not supported */
.no-webp .webp-only {
    display: none;
}

.webp .jpg-fallback {
    display: none;
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .lazy-loading,
    .lazy-error {
        background: none;
        border: 1px solid #ccc;
        min-height: auto;
    }
    
    .lazy-loading::after {
        content: "[Image]";
        display: block;
        text-align: center;
        padding: 10px;
        color: #666;
        font-size: 12px;
    }
}

/* ==========================================================================
   Accessibility Improvements
   ========================================================================== */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .lazy-loaded,
    .blur-load {
        animation: none;
        transition: none;
    }
    
    .loading-shimmer {
        animation: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .lazy-loading {
        background-color: #000;
        color: #fff;
    }
    
    .lazy-error {
        background-color: #fff;
        border-color: #000;
        color: #000;
    }
}

/* ==========================================================================
   Specific Image Types
   ========================================================================== */

/* Moving truck images */
.truck-image {
    width: 100%;
    height: auto;
    object-fit: cover;
    aspect-ratio: 16 / 9;
    border-radius: 12px;
}

/* Equipment/supplies images */
.equipment-image {
    width: 100%;
    height: auto;
    object-fit: cover;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    background-color: #f8f9fa;
}

/* Before/after images */
.before-after-container {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
}

.before-after-container img {
    width: 100%;
    height: auto;
    display: block;
}

/* ==========================================================================
   Mobile Optimizations
   ========================================================================== */

@media (max-width: 768px) {
    .image-gallery {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .service-image {
        aspect-ratio: 16 / 9;
    }
    
    .hero-image {
        aspect-ratio: 4 / 3;
    }
    
    /* Reduce loading animation intensity on mobile */
    .lazy-loading {
        background-size: 15px 15px;
    }
}

/* ==========================================================================
   Dark Mode Support
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .lazy-loading {
        background-color: #2d3748;
        background-image: linear-gradient(45deg, #2d3748 25%, transparent 25%), 
                          linear-gradient(-45deg, #2d3748 25%, transparent 25%), 
                          linear-gradient(45deg, transparent 75%, #2d3748 75%), 
                          linear-gradient(-45deg, transparent 75%, #2d3748 75%);
    }
    
    .lazy-error {
        background-color: #1a202c;
        border-color: #4a5568;
        color: #a0aec0;
    }
}

/* ==========================================================================
   Performance Critical Styles (Inline These)
   ========================================================================== */

/*
Critical styles that should be inlined in HTML head:

.responsive-image { max-width: 100%; height: auto; display: block; }
.hero-image { width: 100%; aspect-ratio: 2 / 1; object-fit: cover; }
.logo-image { width: auto; height: 60px; max-width: 300px; }
.lazy-loading { background-color: #f0f0f0; min-height: 200px; }
*/