/* RESET O NORMALIZACIÓN:
   Es CRUCIAL incluir esto al inicio de tu CSS o en un archivo de reset global.
   Asegura que el padding y el border no aumenten el tamaño final de los elementos. */
*, *::before, *::after {
    box-sizing: border-box; /* Incluye padding y border dentro del ancho/alto especificado. */
}

/* Estilos Generales del Módulo */
.featured-products-module {
    font-family: Arial, sans-serif;
    padding: 30px 20px;
    width: 100%;
    /*max-width: 1200px; Ancho máximo para el módulo. */
    margin: 30px auto;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
    color: #333;
    text-align: center;
    /* Aseguramos que el módulo no se desborde horizontalmente */
    overflow: hidden; /* Esto ayudará a contener cualquier elemento interno que pueda desbordarse. */
}

.featured-products-module h2 {
    text-align: center;
    color: var(--secondary-black); /* Un color negro */
    margin-bottom: 30px;
    font-size: 2em;
}

/* Flexbox para Contenedor de Productos */
.products-container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    /* Importante para que el scroll horizontal solo afecte a este contenedor y no al body */
    /* Lo principal para evitar que el scroll horizontal se propague al body
       es asegurarse de que el contenedor de los elementos desplazables horizontalmente
       tenga 'overflow-x: auto;' o 'scroll' y un ancho definido (explícitamente o implícitamente).
       Aquí, el 'max-width' y 'margin: auto' del '.featured-products-module' lo contienen.
       Los media queries ajustarán 'flex-wrap' y 'overflow-x' según la pantalla. */
}

/* Estilos de la Tarjeta de Producto */
.product-card {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
    /* Ajustes para un cálculo de ancho más seguro */
    width: 280px; /* Definimos un ancho fijo para que no dependa tanto del 100% en algunos contextos */
    flex-shrink: 0; /* Asegura que las tarjetas no se encojan en el modo carrusel */
    scroll-snap-align: start;
}

.product-card:hover {
    transform: translateY(-5px);
}

.product-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.product-info {
    padding: 15px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: left;
}

.product-info h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.2em;
    color: #555;
}

.product-info p {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 10px;
    flex-grow: 1;
}

.product-info .price {
    font-size: 1.1em;
    font-weight: bold;
    color: #333;
    text-align: right;
}

/* Estilos del Pop-up */
.featured-products-module .product-popup {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    /* Ajustes de ancho y alto para asegurar que ocupe el viewport y se centre */
    width: 100vw; /* 100% del ancho del viewport (ventana de visualización) */
    height: 100vh; /* 100% del alto del viewport */
    overflow: auto; /* Permite scroll si el contenido es demasiado grande */
    background-color: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
    /* Añadido para asegurar que el pop-up no cause scroll en el body si se desborda en el eje Y */
    overscroll-behavior: contain; /* Evita que el scroll del pop-up se propague al documento. */
}

.featured-products-module .popup-content {
    background-color: #fff;
    /* Eliminamos 'margin: auto;' aquí ya que justify/align-items hacen el centrado */
    padding: 25px;
    border-radius: 10px;
    position: relative;
    /* Aseguramos que el contenido del popup se ajuste a la pantalla */
    max-width: 90%; /* Máximo 90% del ancho del popup padre (que es 100vw) */
    width: 500px; /* Ancho deseado, pero limitado por max-width */
    max-height: 90vh; /* Para que el popup no sea más alto que la pantalla */
    overflow-y: auto; /* Permite el scroll vertical si el contenido del popup es muy alto */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    text-align: center;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.featured-products-module .close-button {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.featured-products-module .close-button:hover,
.featured-products-module .close-button:focus {
    color: #333;
    text-decoration: none;
}

.featured-products-module .popup-content img {
    max-width: 100%;
    height: auto;
    border-radius: 5px;
    margin-bottom: 15px;
}

.featured-products-module .popup-content h3 {
    margin-top: 0;
    color: #333;
    font-size: 1.8em;
}

.featured-products-module .popup-content p {
    color: #555;
    margin-bottom: 15px;
    font-size: 1.1em;
}

.featured-products-module .popup-content #popup-price {
    font-weight: bold;
    font-size: 1.3em;
    color: #222;
    margin-bottom: 20px;
}

.featured-products-module .whatsapp-button {
    display: inline-flex;
    align-items: center;
    background-color: #25D366;
    color: white;
    padding: 12px 25px;
    border-radius: 50px;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.1em;
    transition: background-color 0.3s ease;
}

.featured-products-module .whatsapp-button:hover {
    background-color: #1DA851;
}

.featured-products-module .whatsapp-button img {
    width: 24px;
    height: 24px;
    margin-right: 10px;
    vertical-align: middle;
    margin-bottom: 0;
}

/* Media Queries para Responsividad */
@media (max-width: 768px) {
    .products-container {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        justify-content: flex-start;
        padding-bottom: 15px;
        /* Aseguramos que el contenedor de scroll no se desborde si el módulo tiene padding */
        /* Eliminamos el padding lateral del contenedor y lo ponemos en las tarjetas si es necesario */
        padding-left: 20px; /* Añade padding al inicio del carrusel */
        padding-right: 20px; /* Añade padding al final del carrusel */
        margin-left: -20px; /* Compensa el padding del módulo padre para que los bordes del carrusel se alineen con el contenido del módulo */
        margin-right: -20px; /* Ídem */
    }

    /* Ocultar la barra de scroll, pero mantener la funcionalidad */
    .products-container::-webkit-scrollbar {
        display: none;
    }
    .products-container {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .product-card {
        width: 80vw; /* Utiliza el ancho del viewport para mayor predictibilidad en móviles */
        max-width: 280px; /* Mantiene el límite de ancho de la tarjeta */
        margin-right: 20px; /* Espacio entre tarjetas */
    }

    /* Aseguramos que el pop-up se ajuste perfectamente en móviles */
    .featured-products-module .product-popup {
        padding: 10px; /* Reduce el padding del pop-up general */
    }

    .featured-products-module .popup-content {
        width: calc(100% - 40px); /* Ocupa casi todo el ancho de la pantalla, restando padding */
        max-width: 400px; /* Limita el ancho máximo para evitar que sea muy grande en tablets portrait */
        padding: 15px;
    }

    .featured-products-module .popup-content h3 {
        font-size: 1.5em;
    }

    .featured-products-module .whatsapp-button {
        padding: 10px 20px;
        font-size: 1em;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .products-container {
        flex-wrap: wrap;
        overflow-x: visible;
        scroll-snap-type: none;
        justify-content: center;
        padding-bottom: 0;
        padding-left: 0; /* Asegura que no haya padding lateral para scroll */
        padding-right: 0;
        margin-left: auto; /* Restaura los márgenes automáticos */
        margin-right: auto;
    }
    .product-card {
        width: calc(50% - 20px); /* Vuelve a usar calc para 2 columnas */
        margin-right: 0;
    }
}

@media (min-width: 1025px) {
    .products-container {
        flex-wrap: wrap;
        overflow-x: visible;
        scroll-snap-type: none;
        justify-content: center;
        padding-bottom: 0;
        padding-left: 0;
        padding-right: 0;
        margin-left: auto;
        margin-right: auto;
    }
    .product-card {
        width: calc(25% - 15px); /* Vuelve a usar calc para 4 columnas */
        margin-right: 0;
    }
}

@media (max-width: 480px) {
    .featured-products-module h2 {
    font-size: 1.6em;
    }
}