/* 🔧 Estilos para el Sistema de Spares - Cache busted 2026-01-26 */

/* Contenedores de Spares */
.spares-section,
#spares-section,
.product-spares {
    margin: 20px 0;
    padding: 15px;
    border-radius: 5px;
    background: #f8f9fa;
}

.spares-section h3,
#spares-section h3,
.product-spares h3 {
    margin-bottom: 15px;
    color: #333;
    font-weight: 600;
}

/* Estados de carga */
.loading-spares {
    position: relative;
    opacity: 0.6;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.loading-spares::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
    border-radius: inherit;
}

.loading-spares::after {
    content: "⟳";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: #007bff;
    animation: spin 1s linear infinite;
    z-index: 11;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ======================================
   🔄 AJAX CAROUSEL CONTROL
====================================== */

/* Evitar agrandamiento durante actualizaciones AJAX */
#spares-content .swiper-area {
    overflow: hidden;
    transition: height 0.3s ease;
}

#spares-content .swiper {
    height: auto;
    overflow: hidden;
}

#spares-content .swiper-wrapper {
    transition-duration: 300ms;
    align-items: stretch;
    display: flex;
}

#spares-content .swiper-slide {
    height: auto;
    display: flex;
    align-items: stretch;
    justify-content: center;
    /* CRITICAL: No establecer width fijo - dejar que flexbox maneje las dimensiones */
    flex-shrink: 0;
}

/* Controlar altura durante loading */
#spares-section-ajax.loading-spares #spares-content .swiper-area {
    min-height: 200px;
    max-height: 200px;
}

/* Carrusel de Spares - Estilos idénticos al carrousel general */
.spares-carousel-container,
#spares-content .swiper-area,
#spares-content .swiper-area.carrousel {
    display: block;
    width: 100%;
}

#spares-content .swiper-area.carrousel .swiper-slide .product {
    width: 100%;
    max-width: 150px; /* Forzar ancho máximo para consistencia */
    margin: 0 auto; /* Centrar el producto dentro del slide */
}

.spares-carousel-container .swiper-container,
#spares-content .swiper-area.carrousel .swiper {
    display: block;
    width: 100%;
    text-align: center;
    margin: auto;
    padding: 0px 4%;
}

.spares-carousel-container .swiper-slide,
#spares-content .swiper-area.carrousel .swiper-slide {
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 200px; /* Ancho mínimo del slide para evitar productos demasiado pequeños */
}

/* Navegación del carrusel - usando estilos del tema */
.spares-carousel-container .swiper-button-prev,
.spares-carousel-container .swiper-button-next,
#spares-content .swiper.carrousel .swiper-button-prev,
#spares-content .swiper.carrousel .swiper-button-next {
    background: var(--client);
}

.spares-carousel-container .swiper-button-prev::after,
.spares-carousel-container .swiper-button-next::after,
#spares-content .swiper-area.carrousel .swiper-button-prev::after,
#spares-content .swiper-area.carrousel .swiper-button-next::after {
    font-size: 18px;
    font-weight: bold;
}

/* Paginación - usando estilos del tema */
.spares-carousel-container .swiper-pagination-bullet,
#spares-content .swiper-area.carrousel .swiper-pagination-bullet,
#spares-content .swiper-scrollbar-drag,
#spares-content .swiper-horizontal > .swiper-pagination-bullets .swiper-pagination-bullet,
#spares-content .swiper-pagination-horizontal.swiper-pagination-bullets .swiper-pagination-bullet {
    background: var(--client);
}

.spares-carousel-container .swiper-pagination-bullet-active,
#spares-content .swiper-area.carrousel .swiper-pagination-bullet-active {
    opacity: 1;
}

.spares-carousel-container .swiper-pagination-bullet-active {
    opacity: 1;
}

/* Tarjetas de Spares */
.spare-product-card {
    background: white;
    border-radius: 8px;
    padding: 10px;
    margin: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-align: center;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* CRITICAL: Hacer que las tarjetas de spares sean idénticas a las tarjetas estándar del tema */
#spares-content .product {
    width: 20%; /* Igual que .product-accessories .product */
    margin: 0px 2%; /* Igual que .product-accessories .product */
    min-width: 0; /* Igual que otras tarjetas del tema */
}

#spares-content .thumbnail-container {
    /* Copiar estilos exactos del tema custom.css */
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 17px;
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100% !important; /* Igual que .product-miniature .thumbnail-container */
}

#spares-content .product-thumbnail {
    text-align: center;
    height: auto;
}

#spares-content .product-thumbnail img {
    height: auto;
    position: relative;
}

#spares-content .product-description {
    position: relative;
    width: auto;
    height: auto;
}

#spares-content .highlighted-informations {
    display: none; /* Igual que el resto de tarjetas */
}

#spares-content .product-actions {
    margin-top: auto; /* Igual que .products .product-actions */
}

#spares-content .product-additional-info,
#spares-content #product-availability,
#spares-content .product-minimal-quantity {
    display: none; /* Igual que otras tarjetas */
}

/* Grid Layout para pocos spares - mismo tamaño que carrousel */
.spares-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin: 15px 0;
}

/* Productos en grid de spares - mismo tamaño que en carrousel */
#spares-content .products {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 2%;
    align-items: stretch;
}

#spares-content .products .product {
    width: calc(20% - 1.6%); /* 5 productos por fila, igual que carrousel desktop */
    margin: 0 0 20px 0;
    min-width: 180px;
    max-width: 250px;
    flex: 0 0 auto;
}

/* Responsive - Mantener consistencia con el tema y carrousel */
@media (max-width: 768px) {
    .spares-section,
    #spares-section,
    .product-spares {
        padding: 10px;
        margin: 15px 0;
    }
    
    .spares-grid {
        grid-template-columns: repeat(auto-fit, minmin(150px, 1fr));
        gap: 10px;
    }
    
    /* Grid de spares - 3 productos por fila en tablet (igual que carrousel) */
    #spares-content .products .product {
        width: calc(33.333% - 2%); /* 3 columnas en tablet */
        margin: 0 1% 15px 0;
    }
    
    /* Mantener el comportamiento responsivo estándar del tema para carrousel */
    #spares-content .swiper-slide .product {
        width: calc(50% - 4%); /* 2 columnas en tablet */
        margin: 0px 2%;
    }
    
    .spares-carousel-container .swiper-button-prev,
    .spares-carousel-container .swiper-button-next {
        width: 35px;
        height: 35px;
        margin-top: -17px;
    }
    
    .spares-carousel-container .swiper-button-prev::after,
    .spares-carousel-container .swiper-button-next::after {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .spares-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Grid de spares - 2 productos por fila en móvil (igual que carrousel) */
    #spares-content .products .product {
        width: calc(50% - 1%); /* 2 columnas en móvil pequeño */
        margin: 0 0.5% 10px 0;
    }
    
    /* Comportamiento móvil estándar para carrousel */
    #spares-content .swiper-slide .product {
        width: calc(50% - 2%); /* 2 columnas en móvil pequeño */
        margin: 0px 1%;
    }
}

/* ======================================
   🔄 ESTILOS AJAX DINÁMICOS
====================================== */

#spares-section-ajax {
    transition: all 0.3s ease;
}

#spares-section-ajax.loading-spares {
    min-height: 100px;
}

.no-spares-message {
    text-align: center;
    color: #999;
    font-style: italic;
    padding: 20px;
    margin: 0;
}

#spares-content {
    transition: opacity 0.3s ease;
}

#spares-section-ajax.loading-spares #spares-content {
    opacity: 0.3;
}

/* Animación de aparición/desaparición */
#spares-section-ajax[style*="display: none"] {
    display: block !important;
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
}

#spares-section-ajax:not([style*="display: none"]) {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

@media (max-width: 480px) {
    .spares-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .spare-product-card {
        min-height: 160px;
    }
    
    .spare-product-card h4 {
        font-size: 12px;
    }
}

/* =================================================================
   FLAGS DE REFERENCIA PARA SPARES
   ================================================================= */

/* Contenedor de flags específico para spares */
.spare-flags {
    position: absolute !important;
    top: 120px !important;
    z-index: 15 !important;
    padding: 0 !important;
    margin: 0 !important;
    list-style: none !important;
}

/* Flag específico para la referencia de spare (azul) */
.spare-reference-flag {
    background-color: var(--client) !important;
    color: #fff !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    padding: 4px 8px !important;
    border-radius: 3px !important;
    margin-bottom: 3px !important;
    display: block !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2) !important;
    line-height: 1.2 !important;
    max-width: 80px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
}



/* Responsive para flags de spares */
@media (max-width: 768px) {
    .spare-reference-flag {
        font-size: 10px !important;
        padding: 3px 6px !important;
        max-width: 60px !important;
    }
    
    .spare-flags {
        top: 120px !important;
        right: 5px !important;
    }
}