/* Smart Fallback Image Loader Styles */

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

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Image loaded state */
.image-loaded {
    opacity: 0;
    animation: fadeInImage 0.5s ease-in-out forwards;
}

@keyframes fadeInImage {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Fallback image styling */
.fallback-image {
    background-color: #f8f9fa;
    border: 2px dashed #dee2e6;
    padding: 20px;
    opacity: 0.8;
    filter: grayscale(20%);
    transition: all 0.3s ease;
}

.fallback-image:hover {
    opacity: 1;
    filter: grayscale(0%);
    border-color: #B8860B;
}

/* Category-specific fallback styles */
.fallback-soap {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-color: #2196f3;
}

.fallback-cleaner {
    background: linear-gradient(135deg, #e8f5e8 0%, #c8e6c9 100%);
    border-color: #4caf50;
}

.fallback-fabric {
    background: linear-gradient(135deg, #fce4ec 0%, #f8bbd9 100%);
    border-color: #e91e63;
}

.fallback-disinfectant {
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border-color: #ff9800;
}

/* Product image containers */
.product-image-wrapper {
    position: relative;
    overflow: hidden;
    background: #f8f9fa;
}

.product-image-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255,255,255,0.1) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
    z-index: 1;
    pointer-events: none;
}

.product-image-wrapper:hover::before {
    transform: translateX(100%);
}

/* Loading indicator */
.image-loading {
    position: relative;
}

.image-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #B8860B;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 2;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error state */
.image-error {
    background: #ffebee;
    border: 1px solid #ffcdd2;
    color: #c62828;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 150px;
    font-size: 14px;
    text-align: center;
}

.image-error::before {
    content: '⚠️';
    display: block;
    font-size: 24px;
    margin-bottom: 8px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .image-skeleton {
        min-height: 150px;
    }
    
    .fallback-image {
        padding: 15px;
    }
}

@media (max-width: 576px) {
    .image-skeleton {
        min-height: 120px;
    }
    
    .fallback-image {
        padding: 10px;
    }
}

/* Integration with existing product cards */
.related-product-card .product-image,
.product-card .product-image,
.featured-product .product-image {
    transition: all 0.3s ease;
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 8px 8px 0 0;
}

.related-product-card .fallback-image,
.product-card .fallback-image,
.featured-product .fallback-image {
    border-radius: 8px 8px 0 0;
    width: 100%;
    height: 200px;
    object-fit: contain;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Fix for product cards in homepage */
.product-card .product-image {
    position: relative;
    overflow: hidden;
    height: 200px;
}

.product-card .product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

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

/* Related products specific styling */
.related-product-card {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.related-product-card .product-image {
    flex-shrink: 0;
    height: 150px;
}

.related-product-card .product-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 15px;
}

/* Fix image display in product cards */
.product-image-wrapper {
    position: relative;
    height: 150px;
    overflow: hidden;
    border-radius: 8px 8px 0 0;
}

.product-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

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

/* Homepage product cards fix */
.featured-products-section .product-image,
.best-sellers-section .product-image {
    height: 200px;
    overflow: hidden;
    border-radius: 8px 8px 0 0;
}

.featured-products-section .product-image img,
.best-sellers-section .product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px 8px 0 0;
}

/* Fix for category images */
.category-image {
    height: 150px;
    overflow: hidden;
    position: relative;
}

.category-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.category-card:hover .category-image img {
    transform: scale(1.1);
}

/* Critical fix for product image display in all cards */
.product-card img,
.related-product-card img,
.featured-product img {
    width: 100% !important;
    height: 200px !important;
    object-fit: cover !important;
    border-radius: 8px 8px 0 0 !important;
    display: block !important;
    background-color: transparent !important;
    padding: 0 !important;
    border: none !important;
}

/* Homepage product cards specific styling */
.featured-products-section .product-card img,
.best-sellers-section .product-card img {
    height: 200px !important;
}

/* Force image container sizing */
.product-image {
    height: auto !important;
    min-height: 150px !important;
    overflow: hidden !important;
    display: block !important;
}

.featured-products-section .product-image,
.best-sellers-section .product-image {
    min-height: 200px !important;
}

/* Fallback image specific styling */
.fallback-image {
    width: 100% !important;
    height: 150px !important;
    object-fit: contain !important;
    background: #f8f9fa !important;
    border: 2px dashed #dee2e6 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Remove any conflicting styles */
.product-card .product-image,
.related-product-card .product-image {
    position: relative !important;
    height: 200px !important;
    overflow: hidden !important;
    background: transparent !important;
    border-radius: 8px 8px 0 0 !important;
    padding: 0 !important;
}

/* Fix for broken/missing images */
img[src=""], img:not([src]), img[src*="default-product.svg"] {
    background: #f8f9fa !important;
    border: 2px dashed #dee2e6 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Hide broken image icons */
img::before,
img::after {
    display: none !important;
}

/* Ensure images have proper background */
img {
    background-color: #f8f9fa !important;
    min-height: 40px !important;
}

/* Fix black image issue and ensure full image display */
.product-image img,
.related-product-card img,
.product-card img {
    background: transparent !important;
    border: none !important;
    object-fit: cover !important;
    object-position: center !important;
    width: 100% !important;
    height: 200px !important;
}

/* Ensure proper image loading states */
img:not([src]), 
img[src=""], 
img[src$="null"],
img[src$="undefined"] {
    content: url('/assets/images/default-product.svg') !important;
    background: #f8f9fa !important;
}

/* Accessibility improvements */
.fallback-image[alt*="not available"]::after {
    content: attr(alt);
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .fallback-image {
        border-width: 3px;
        border-style: solid;
    }
    
    .image-skeleton {
        background: #000;
        color: #fff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .image-loaded,
    .image-skeleton,
    .product-image-wrapper::before {
        animation: none;
        transition: none;
    }
}