/* Mobile Image Display Fixes */

/* General Image Optimization for Mobile */
@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
        display: block;
        border-radius: 8px;
        transition: all 0.3s ease;
    }
    
    /* Product Images Mobile Fix */
    .product-image img,
    .product-card img {
        width: 100%;
        height: 200px;
        object-fit: cover;
        object-position: center;
        background: #f8f9fa;
        border: 1px solid #e9ecef;
    }
    
    /* Logo Mobile Fix */
    .logo img,
    .logo-img {
        height: 40px !important;
        width: auto !important;
        max-width: 150px;
        object-fit: contain;
    }
    
    /* Category Images Mobile */
    .category-image img {
        width: 100%;
        height: 150px;
        object-fit: cover;
        border-radius: 12px;
    }
    
    /* Hero Banner Mobile */
    .hero-banner img,
    .banner-image img {
        width: 100%;
        height: 250px;
        object-fit: cover;
    }
    
    /* User Avatar Mobile */
    .user-avatar img,
    .profile-image img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        object-fit: cover;
    }
    
    /* Payment Icons Mobile */
    .payment-icon img {
        width: 40px;
        height: 25px;
        object-fit: contain;
        margin: 2px;
    }
    
    /* Social Icons Mobile */
    .social-icon img {
        width: 30px;
        height: 30px;
        object-fit: contain;
    }
    
    /* Image Loading State */
    .image-loading {
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
        min-height: 200px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #6c757d;
        font-size: 14px;
    }
    
    @keyframes shimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    
    /* Image Error State */
    .image-error {
        background: #f8f9fa;
        border: 2px dashed #dee2e6;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        color: #6c757d;
        font-size: 12px;
        text-align: center;
        padding: 20px;
        min-height: 200px;
    }
    
    .image-error::before {
        content: "🖼️";
        font-size: 32px;
        margin-bottom: 10px;
        opacity: 0.5;
    }
    
    .image-error::after {
        content: "Image not available";
        font-size: 12px;
        color: #999;
    }
    
    /* Lazy Loading Enhancement */
    img[loading="lazy"] {
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    img[loading="lazy"].loaded {
        opacity: 1;
    }
    
    /* Prevent Image Flashing */
    img:not([src]) {
        opacity: 0;
    }
    
    img[src=""] {
        opacity: 0;
    }
}

/* Extra Small Devices */
@media (max-width: 480px) {
    .product-image img,
    .product-card img {
        height: 180px;
    }
    
    .hero-banner img {
        height: 200px;
    }
    
    .category-image img {
        height: 120px;
    }
}

/* Image Aspect Ratio Containers */
.image-container {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
}

.image-container::before {
    content: '';
    display: block;
    width: 100%;
    padding-top: 66.67%; /* 3:2 Aspect Ratio */
}

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

/* Product Card Image Container */
.product-card .image-container::before {
    padding-top: 75%; /* 4:3 Aspect Ratio */
}

/* Category Card Image Container */
.category-card .image-container::before {
    padding-top: 56.25%; /* 16:9 Aspect Ratio */
}

/* High DPI Display Support */
@media only screen and (-webkit-min-device-pixel-ratio: 2),
       only screen and (min-device-pixel-ratio: 2),
       only screen and (min-resolution: 192dpi),
       only screen and (min-resolution: 2dppx) {
    
    img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
    
    .logo img,
    .logo-img {
        image-rendering: auto;
    }
}

/* iOS Safari Specific Fixes */
@supports (-webkit-touch-callout: none) {
    img {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
    }
    
    .product-image img {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* Android Chrome Specific Fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .product-card img {
        will-change: transform;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }
}

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

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    img,
    .image-loading {
        animation: none !important;
        transition: none !important;
    }
}