/**
 * Image Styles with Fallback Support
 * Provides consistent styling for images with loading states and fallbacks
 */

/* Base image styles */
img {
    max-width: 100%;
    height: auto;
}

/* Loading state for images */
img[src] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

/* Stop animation when image is loaded */
img[src].loaded,
img[src][data-fallback-setup="true"] {
    animation: none;
    background: transparent;
}

/* Placeholder image styling */
.image-fallback-placeholder {
    opacity: 0.8;
    filter: grayscale(10%);
    transition: opacity 0.3s ease;
}

.image-fallback-placeholder:hover {
    opacity: 1;
}

/* Container with placeholder image */
.has-placeholder-image {
    position: relative;
}

.has-placeholder-image::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.has-placeholder-image:hover::before {
    opacity: 0.8;
}

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

.product-image-container img {
    transition: transform 0.3s ease, opacity 0.3s ease;
}

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

/* Image error state */
img[data-fallback-attempted="true"] {
    border: 1px solid #e0e0e0;
}

/* Lazy loading support */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Responsive image containers */
.aspect-square {
    aspect-ratio: 1 / 1;
}

.aspect-video {
    aspect-ratio: 16 / 9;
}

.aspect-portrait {
    aspect-ratio: 3 / 4;
}

/* Image zoom on hover for product galleries */
.image-zoom-container {
    position: relative;
    overflow: hidden;
    cursor: zoom-in;
}

.image-zoom-container img {
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* Thumbnail images */
.thumbnail-image {
    border: 2px solid transparent;
    transition: border-color 0.2s ease;
    cursor: pointer;
}

.thumbnail-image:hover {
    border-color: #007bff;
}

.thumbnail-image.active {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

/* Image gallery grid */
.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

@media (max-width: 768px) {
    .image-gallery {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.5rem;
    }
}

/* Image with overlay */
.image-overlay-container {
    position: relative;
}

.image-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-overlay-container:hover .image-overlay {
    opacity: 1;
}

/* Skeleton loader for images */
.image-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 0.5rem;
}

/* Image badge/label support */
.image-badge {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 10;
}

/* Fade in animation for loaded images */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

img.fade-in {
    animation: fadeIn 0.3s ease-in;
}

/* Print styles */
@media print {
    img {
        max-width: 100%;
        page-break-inside: avoid;
    }
    
    .image-fallback-placeholder {
        opacity: 1;
        filter: none;
    }
}
