/* ═══════════════════════════════════════════════════════════════
   IMAGE OPTIMIZATION STYLES
   ═══════════════════════════════════════════════════════════════ */

/* Lazy Loading - Placeholder blur effect */
img[loading="lazy"]:not(.loaded) {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 2s infinite;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Imagen optimizada cargada */
img.optimized-image {
    display: block;
    width: 100%;
    height: auto;
    max-width: 100%;
}

img.optimized-image.loaded {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0.8;
    }
    to {
        opacity: 1;
    }
}

/* Error en carga de imagen */
img.load-error {
    opacity: 0.7;
    filter: grayscale(1);
}

/* Picture element */
picture {
    display: contents;
}

/* Contenedor de imagen responsivo */
.image-container {
    position: relative;
    width: 100%;
    padding-bottom: 75%; /* Aspect ratio 4:3 */
    overflow: hidden;
    background: #f0f0f0;
}

.image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

/* Variaciones de aspect ratio */
.image-container.aspect-16-9 {
    padding-bottom: 56.25%;
}

.image-container.aspect-1-1 {
    padding-bottom: 100%;
}

.image-container.aspect-3-2 {
    padding-bottom: 66.67%;
}

/* Galerías de imágenes */
.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    margin: 15px 0;
}

.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background: #f5f5f5;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.gallery-item img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    object-position: center;
    display: block;
}

/* Media query para imágenes responsivas */
@media (max-width: 768px) {
    .image-gallery {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 8px;
    }

    .gallery-item img {
        height: 120px;
    }

    /* Reducir tamaño de imágenes en móvil */
    img[loading="lazy"] {
        max-width: 100%;
        height: auto;
    }
}

@media (max-width: 480px) {
    .image-gallery {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 6px;
    }

    .gallery-item img {
        height: 100px;
    }
}

/* Soporte para imágenes con diferentes densidades de pixel */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    img {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* Optimización para dark mode */
@media (prefers-color-scheme: dark) {
    img[loading="lazy"]:not(.loaded) {
        background: linear-gradient(90deg, #2a2a2a 25%, #1a1a1a 50%, #2a2a2a 75%);
        background-size: 200% 100%;
    }

    .image-container {
        background: #1a1a1a;
    }

    .gallery-item {
        background: #2a2a2a;
    }
}

/* Reducir animaciones si el usuario lo prefiere */
@media (prefers-reduced-motion: reduce) {
    img[loading="lazy"]:not(.loaded) {
        animation: none;
        background: #f0f0f0;
    }

    img.optimized-image.loaded {
        animation: none;
    }

    .gallery-item {
        transition: none;
    }
}

/* Print styles - no cargar imágenes en impresión */
@media print {
    img[loading="lazy"] {
        display: none;
    }

    img {
        max-width: 100%;
        page-break-inside: avoid;
    }
}

/* Estilos para product cards con imágenes optimizadas */
.product-card {
    position: relative;
}

.product-image {
    display: block;
    width: 100%;
    height: auto;
    background: #f5f5f5;
    border-radius: 8px 8px 0 0;
    object-fit: cover;
}

.product-image[loading="lazy"]:not(.loaded) {
    min-height: 250px;
}

/* Efecto hover en imágenes */
.product-image-link:hover .product-image {
    opacity: 0.9;
    transform: scale(1.02);
}

.product-image-link {
    display: block;
    overflow: hidden;
    border-radius: 8px;
}

/* Banner images optimization */
.banner-image {
    width: 100%;
    height: auto;
    object-fit: cover;
    object-position: center;
    display: block;
}

.banner-image[loading="lazy"]:not(.loaded) {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 2s infinite;
}

/* Logo optimization */
.brand-logo {
    max-width: 100%;
    height: auto;
    display: block;
}

.brand-logo[loading="lazy"]:not(.loaded) {
    min-width: 100px;
    min-height: 50px;
}
