/**
 * Estilos para Componente de Tarjeta de Producto
 * Versión modular y personalizable
 */

/* ===== CONTENEDOR GRID ===== */
.products-container {
    width: 100%;
    max-width: 100%;
}

.products-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(2, 1fr);
    opacity: 1; /* visible por defecto; JS puede animar si quiere */
    transition: opacity 0.5s ease;
    max-width: 100%;
    width: 100%;
}

@media (min-width: 640px) { 
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1.25rem;
    } 
}

@media (min-width: 1024px) { 
    .products-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 1.5rem;
    } 
}

@media (min-width: 1280px) { 
    .products-grid {
        grid-template-columns: repeat(5, 1fr);
    } 
}

/* ===== TARJETA BASE ===== */
.product-card {
    background: var(--card-gradient);
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--glass-border);
    position: relative;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-glass);
    min-height: 300px;
    transform: translateY(0);
}

.product-card:hover {
    transform: translateY(-4px);
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(102, 126, 234, 0.1);
    border-color: rgba(102, 126, 234, 0.3);
}

/* ===== VARIANTES DE TARJETA ===== */
.product-card--compact {
    min-height: 250px;
}

.product-card--compact .product-info {
    padding: 0.5rem;
}

.product-card--compact .product-title {
    font-size: 0.75rem;
    -webkit-line-clamp: 1;
    line-clamp: 1;
}

.product-card--detailed {
    min-height: 350px;
}

.product-card--detailed .product-description {
    color: var(--text-secondary);
    font-size: 0.75rem;
    line-height: 1.4;
    margin: 0.5rem 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== SECCIÓN DE IMAGEN ===== */
.product-image-wrapper {
    position: relative !important;
    background: #ffffff !important; /* blanco para que imágenes pequeñas no se pierdan */
    aspect-ratio: 1 !important;
    overflow: hidden !important;
    padding: 0.75rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: var(--border-radius) var(--border-radius) 0 0 !important;
}

.product-image-link {
    display: block;
    width: 100%;
    height: 100%;
    text-decoration: none;
}

/* ===== ESTILOS DE IMAGEN SIMPLIFICADOS ===== */
.product-image {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    object-position: center !important;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
    opacity: 1 !important; /* visible por defecto para evitar grillas vacías */
    transform: none !important;
}

.product-image.loaded { 
    opacity: 1 !important;
    transform: scale(1) !important;
}

.product-card:hover .product-image.loaded { 
    transform: scale(1.05) !important;
}

/* ===== BADGE DE STOCK CON ESPECIFICIDAD ALTA ===== */
.product-card .product-image-wrapper .product-badge {
    position: absolute !important;
    top: 0.5rem !important;
    right: 0.5rem !important;
    padding: 0.4rem 0.8rem !important;
    border-radius: 16px !important;
    font-size: 0.7rem !important;
    font-weight: 900 !important;
    text-transform: uppercase !important;
    z-index: 10 !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    letter-spacing: 0.8px !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3) !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    opacity: 1 !important;
    background-clip: padding-box !important;
    backdrop-filter: none !important;
}

.product-card:hover .product-badge {
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.product-card .product-image-wrapper .badge-available { 
    background: #10b981 !important; 
    color: white !important; 
    border: 2px solid #059669 !important; 
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.8) !important;
    opacity: 1 !important;
    backdrop-filter: none !important;
}

.product-card .product-image-wrapper .badge-few { 
    background: #f59e0b !important; 
    color: white !important; 
    border: 2px solid #d97706 !important; 
    animation: pulse-warning 2s infinite !important;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.8) !important;
    opacity: 1 !important;
    backdrop-filter: none !important;
}

.product-card .product-image-wrapper .badge-out { 
    background: #ef4444 !important; 
    color: white !important; 
    border: 2px solid #dc2626 !important; 
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.8) !important;
    opacity: 1 !important;
    backdrop-filter: none !important;
}

@keyframes pulse-warning {
    0%, 100% { 
        opacity: 1; 
        transform: scale(1);
        box-shadow: 0 4px 12px rgba(245, 158, 11, 0.8);
        background: #f59e0b;
    }
    50% { 
        opacity: 1; 
        transform: scale(1.05);
        box-shadow: 0 6px 16px rgba(245, 158, 11, 1);
        background: #f59e0b;
    }
}

/* ===== INFORMACIÓN DEL PRODUCTO ===== */
.product-info { 
    padding: 0.8rem; 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    gap: 0.5rem; 
}

.product-category {
    color: transparent;
    background: var(--accent-gradient);
    -webkit-background-clip: text; 
    background-clip: text; 
    -webkit-text-fill-color: transparent;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    transition: all 0.2s ease;
}

.product-category i {
    color: var(--accent);
    font-size: 0.7rem;
}

.product-title {
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-decoration: none;
    min-height: 2.1rem;
    transition: all 0.2s ease;
}

.product-title:hover {
    color: transparent;
    background: var(--primary-gradient);
    -webkit-background-clip: text; 
    background-clip: text; 
    -webkit-text-fill-color: transparent;
    text-decoration: none;
}

/* ===== SECCIÓN DE PRECIO Y STOCK ===== */
.product-price-section {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin: 0.5rem 0;
}

.product-price {
    font-size: 1.1rem !important;
    font-weight: 800 !important;
    color: #22d3ee !important;
    background: linear-gradient(135deg, #22d3ee, #06b6d4) !important;
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    background-clip: text !important;
    text-shadow: 0 2px 4px rgba(34, 211, 238, 0.2) !important;
    letter-spacing: -0.025em !important;
}

.price-currency {
    font-size: 0.8rem !important;
    font-weight: 600 !important;
    opacity: 0.8 !important;
    color: var(--text-secondary) !important;
    background: none !important;
    -webkit-text-fill-color: var(--text-secondary) !important;
}

.product-stock {
    font-size: 0.7rem !important;
    color: var(--text-muted) !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.3rem !important;
    opacity: 0.9 !important;
}

.product-stock i {
    font-size: 0.65rem !important;
    opacity: 0.8 !important;
}

/* ===== ACCIONES ===== */
.product-actions { 
    display: flex; 
    flex-direction: column; 
    gap: 0.5rem; 
    margin-top: auto; 
}

.cart-btn {
    background: var(--accent-gradient);
    color: var(--text-primary);
    border: none;
    border-radius: 8px;
    padding: 0.6rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(79, 172, 254, 0.3);
    text-transform: uppercase;
    gap: 0.4rem;
    position: relative;
    overflow: hidden;
}

.cart-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.3s ease;
}

.cart-btn:hover:not(:disabled)::before {
    width: 200%;
    height: 200%;
}

.cart-btn:hover:not(:disabled) { 
    transform: translateY(-2px); 
    box-shadow: 0 8px 20px rgba(79, 172, 254, 0.4); 
}

.cart-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 4px 12px rgba(79, 172, 254, 0.3);
}

.cart-btn:disabled { 
    background: var(--glass-bg); 
    color: var(--text-muted); 
    cursor: not-allowed; 
    box-shadow: none; 
    transform: none;
}

.secondary-actions { 
    display: flex; 
    gap: 0.4rem; 
}

.action-btn {
    flex: 1;
    background: var(--glass-bg);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 0.5rem 0.3rem;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    backdrop-filter: blur(20px);
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
}

.action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.1), transparent);
    transition: left 0.5s ease;
}

.action-btn:hover::before {
    left: 100%;
}

.action-btn:hover { 
    background: var(--primary-gradient); 
    color: var(--text-primary); 
    transform: translateY(-1px); 
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3); 
    border-color: rgba(102, 126, 234, 0.3);
}

/* Estilos específicos para botones de acción */
.view-btn:hover {
    background: var(--accent-gradient);
}

.wishlist-btn:hover {
    background: linear-gradient(135deg, #ec4899, #be185d);
    color: white;
}

.wishlist-btn.active {
    background: linear-gradient(135deg, #be185d, #9d174d);
    color: white;
    border-color: rgba(190, 24, 93, 0.3);
}

/* ===== ESTADOS ESPECIALES ===== */
.empty-grid {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-secondary);
    font-size: 1.1rem;
    grid-column: 1 / -1;
}

/* ===== ANIMACIONES DE ENTRADA ===== */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.product-card {
    animation: slideInUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.product-card:nth-child(1) { animation-delay: 0.05s; }
.product-card:nth-child(2) { animation-delay: 0.1s; }
.product-card:nth-child(3) { animation-delay: 0.15s; }
.product-card:nth-child(4) { animation-delay: 0.2s; }
.product-card:nth-child(5) { animation-delay: 0.25s; }
.product-card:nth-child(n+6) { animation-delay: 0.3s; }

/* ===== RESPONSIVE ADJUSTMENTS ===== */
@media (max-width: 639px) {
    .product-card {
        min-height: 280px;
    }
    
    .product-info {
        padding: 0.6rem;
    }
    
    .product-title {
        font-size: 0.75rem;
    }
    
    .product-price {
        font-size: 1rem !important;
    }
    
    .product-stock {
        font-size: 0.65rem !important;
    }
    
    .cart-btn {
        padding: 0.5rem;
        font-size: 0.7rem;
    }
    
    .action-btn {
        padding: 0.4rem 0.2rem;
        font-size: 0.65rem;
    }
}

@media (min-width: 1280px) {
    .product-card {
        min-height: 320px;
    }
    
    .product-title {
        font-size: 0.85rem;
    }
    
    .product-price {
        font-size: 1.1rem;
    }
}

/* ===== DARK MODE OVERRIDES ===== */
@media (prefers-color-scheme: dark) {
    .product-image-wrapper {
        background: #ffffff !important; /* mantener blanco también en dark mode */
    }
}

/* ===== DARK MODE OPTIMIZATIONS ===== */
@media (prefers-color-scheme: dark) {
    .product-badge {
        border-width: 2px;
    }
    
    .badge-available { 
        background: #10b981 !important; 
        border-color: #059669 !important;
        color: white !important;
    }

    .badge-few { 
        background: #f59e0b !important; 
        border-color: #d97706 !important;
        color: white !important;
    }

    .badge-out { 
        background: #ef4444 !important; 
        border-color: #dc2626 !important;
        color: white !important;
    }
}

/* ===== LOADING STATES ===== */
.product-card.loading {
    pointer-events: none;
    opacity: 0.7;
}

.product-card.loading .product-image {
    filter: blur(1px);
}

.product-card.loading .cart-btn {
    background: var(--glass-bg);
    color: var(--text-muted);
}

/* ===== HIGH CONTRAST MODE ===== */
@media (prefers-contrast: high) {
    .product-card {
        border: 2px solid var(--text-primary);
    }
    
    .product-badge {
        border-width: 2px;
        font-weight: 800;
    }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    .product-card,
    .product-image,
    .cart-btn,
    .action-btn {
        transition: none;
        animation: none;
    }
    
    .product-card:hover {
        transform: none;
    }
    
    .product-image.loaded {
        transform: none;
    }
}

.summarize-btn:hover {
    background: var(--secondary-gradient);
    color: white;
    border-color: rgba(245, 158, 11, 0.3);
}

.summarize-btn.loading {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
}

/* Estados especiales para badges - solo hover effects */
.badge-available:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.8);
    background: #059669;
}

.badge-few:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.8);
    background: #d97706;
}

.badge-out:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.8);
    background: #dc2626;
}

/* ===== ESTADOS DE IMAGEN Y LOADING ===== */
.product-image-wrapper.loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    border: 3px solid rgba(34, 211, 238, 0.3);
    border-top: 3px solid #22d3ee;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    transform: translate(-50%, -50%);
    z-index: 5;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

.product-image-wrapper.loading .product-image {
    opacity: 0.3 !important;
}

/* Estados de imagen fallback */
.product-image.fallback-image {
    opacity: 0.9 !important;
    filter: sepia(0.1) contrast(1.1) !important;
}

.product-card.image-fallback {
    border-color: rgba(245, 158, 11, 0.3) !important;
}

.product-card.image-fallback::before {
    content: '⚠️';
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 12px;
    background: rgba(245, 158, 11, 0.9);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 20;
    font-weight: bold;
}

/* Estados de error de imagen */
.product-image-wrapper.image-error {
    background: linear-gradient(135deg, #374151 0%, #1f2937 100%) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.product-image-wrapper.image-error::after {
    content: '🖼️\A Sin imagen';
    white-space: pre-line;
    text-align: center;
    color: #9ca3af;
    font-size: 0.8rem;
    font-weight: 600;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
}

.product-image.error {
    display: none !important;
}

.product-card.image-error {
    border-color: rgba(239, 68, 68, 0.3) !important;
}

.product-card.image-error::before {
    content: '❌';
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 12px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 20;
}

/* Estados de éxito */
.product-card.image-loaded {
    border-color: rgba(34, 211, 238, 0.2) !important;
}

/* Mejoras visuales para wrapper de fallback */
.product-image-wrapper.fallback-used {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
}

.product-image-wrapper.fallback-used .product-image {
    border: 2px solid rgba(245, 158, 11, 0.5) !important;
}

/* ===== INDICADORES DE IMÁGENES EXTERNAS ===== */
.external-image-wrapper {
    position: relative !important;
}

.external-image-indicator {
    position: absolute !important;
    bottom: 8px !important;
    right: 8px !important;
    background: rgba(34, 211, 238, 0.9) !important;
    color: white !important;
    padding: 4px 8px !important;
    border-radius: 12px !important;
    font-size: 10px !important;
    font-weight: bold !important;
    z-index: 15 !important;
    backdrop-filter: blur(5px) !important;
    border: 1px solid rgba(34, 211, 238, 0.3) !important;
}

.product-image[data-external="true"] {
    border: 2px solid rgba(34, 211, 238, 0.3) !important;
    transition: all 0.3s ease !important;
}

.product-image[data-external="true"]:hover {
    border-color: rgba(34, 211, 238, 0.6) !important;
    box-shadow: 0 0 20px rgba(34, 211, 238, 0.3) !important;
}

/* Estados específicos para imágenes externas */
.external-image-wrapper.loading::after {
    content: '🌐 Cargando imagen externa...';
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    z-index: 20;
    white-space: nowrap;
}

.external-image-wrapper.image-error::after {
    content: '🚫 Error de imagen externa\AVerificar CORS y conectividad';
    white-space: pre-line;
    text-align: center;
    color: #ef4444;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    padding: 10px;
}
