/*
 * TallArt - Sistema de Imágenes Responsivas
 * Optimización para diferentes dispositivos y tamaños de pantalla
 */

/* ========================================
   CONFIGURACIÓN BASE DE IMÁGENES
   ======================================== */

/* Todas las imágenes responsivas por defecto */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Lazy loading - fade in cuando se carga */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* ========================================
   IMÁGENES DE PRODUCTOS
   ======================================== */

.producto-imagen,
.product-image,
.empresa-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    background-color: var(--color-gray-100);
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Contenedores de imagen con aspect ratio */
.image-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    background-color: var(--color-gray-100);
}

/* Aspect ratios comunes */
.aspect-square {
    aspect-ratio: 1 / 1;
}

.aspect-video {
    aspect-ratio: 16 / 9;
}

.aspect-4-3 {
    aspect-ratio: 4 / 3;
}

.aspect-3-2 {
    aspect-ratio: 3 / 2;
}

.aspect-portrait {
    aspect-ratio: 3 / 4;
}

/* ========================================
   IMÁGENES RESPONSIVAS POR DISPOSITIVO
   ======================================== */

/* Móvil: imágenes más pequeñas y comprimidas */
@media (max-width: 640px) {
    .empresa-card .empresa-image,
    .product-image-wrapper img {
        height: 200px;
        min-height: 200px;
        max-height: 200px;
    }
    
    /* Hero images más pequeñas en móvil */
    .hero-image {
        max-height: 300px;
    }
}

/* Tablet: tamaño medio */
@media (min-width: 641px) and (max-width: 1024px) {
    .empresa-card .empresa-image,
    .product-image-wrapper img {
        height: 220px;
        min-height: 220px;
        max-height: 220px;
    }
    
    .hero-image {
        max-height: 400px;
    }
}

/* Desktop: tamaño completo */
@media (min-width: 1025px) {
    .empresa-card .empresa-image,
    .product-image-wrapper img {
        height: 240px;
        min-height: 240px;
        max-height: 240px;
    }
    
    .hero-image {
        max-height: 500px;
    }
}

/* ========================================
   PLACEHOLDER Y SKELETON LOADER
   ======================================== */

.image-placeholder {
    background: linear-gradient(
        90deg,
        var(--color-gray-100) 0%,
        var(--color-gray-200) 50%,
        var(--color-gray-100) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Skeleton para cards */
.skeleton-image {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ========================================
   EFECTOS DE IMAGEN INTERACTIVOS
   ======================================== */

/* Zoom suave en hover (solo en desktop con mouse) */
@media (hover: hover) and (pointer: fine) {
    .image-zoom-hover {
        overflow: hidden;
    }
    
    .image-zoom-hover img {
        transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .image-zoom-hover:hover img {
        transform: scale(1.1);
    }
}

/* Overlay oscuro en hover */
.image-overlay-hover {
    position: relative;
}

.image-overlay-hover::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

@media (hover: hover) {
    .image-overlay-hover:hover::after {
        opacity: 1;
    }
}

/* ========================================
   OPTIMIZACIÓN DE RENDIMIENTO
   ======================================== */

/* Hint al navegador para optimizar imágenes críticas */
.critical-image {
    content-visibility: auto;
}

/* Will-change para animaciones de imagen */
.animated-image {
    will-change: transform;
}

/* Prevenir layout shift con aspect ratio */
.prevent-shift {
    position: relative;
    width: 100%;
}

.prevent-shift::before {
    content: '';
    display: block;
    padding-top: 100%; /* Square por defecto, ajustar según necesidad */
}

.prevent-shift img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ========================================
   IMÁGENES EN ALTA RESOLUCIÓN (Retina)
   ======================================== */

@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
    /* Las imágenes con srcset se cargarán automáticamente en alta resolución */
    .retina-image {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* ========================================
   MODO OSCURO - AJUSTES DE IMAGEN
   ======================================== */

@media (prefers-color-scheme: dark) {
    img {
        opacity: 0.9;
    }
    
    .image-placeholder {
        background: linear-gradient(
            90deg,
            #374151 0%,
            #4B5563 50%,
            #374151 100%
        );
    }
}

/* ========================================
   ACCESIBILIDAD
   ======================================== */

/* Asegurar que las imágenes decorativas no afecten la navegación */
img[alt=""],
img:not([alt]) {
    user-select: none;
}

/* Forzar alt text visible si falta (solo en desarrollo) */
img:not([alt])::after {
    content: "⚠️ Alt text faltante";
    display: block;
    background: #ff0000;
    color: white;
    padding: 0.25rem;
    font-size: 0.75rem;
}

/* Ocultar el aviso en producción */
body:not(.dev-mode) img:not([alt])::after {
    display: none;
}

/* ========================================
   PRINT - OPTIMIZACIÓN DE IMÁGENES
   ======================================== */

@media print {
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
    
    /* Ocultar imágenes decorativas en print */
    .decorative-image,
    .background-image {
        display: none !important;
    }
}

/* ========================================
   CONEXIÓN LENTA - IMÁGENES COMPRIMIDAS
   ======================================== */

@media (prefers-reduced-data: reduce) {
    /* Ocultar imágenes grandes en conexiones lentas */
    .large-image,
    .hero-image {
        display: none;
    }
    
    /* Mostrar placeholder en su lugar */
    .large-image::before,
    .hero-image::before {
        content: '🖼️ Imagen no cargada (conexión lenta)';
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--color-gray-100);
        padding: 2rem;
        text-align: center;
    }
}
