
/* MEGAMENU STYLES */
header nav ul {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    list-style: none;
    margin: 0;
    padding: 0;
}
header nav > ul > li > a {
    text-transform: uppercase;
    font-weight: 800;
    font-size: 0.85rem;
    text-decoration: none;
    color: white;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
header nav ul li a:hover {
    color: #2563eb;
}
.has-megamenu {
    position: relative;
}
.megamenu {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(15px);
    background: white;
    border-radius: 8px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
    padding: 1.5rem;
    min-width: 450px;
    border: 1px solid #eaeaea;
    cursor: default;
}
.has-megamenu:hover .megamenu {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}
.solutions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.mm-item {
    display: flex;
    align-items: flex-start;
    gap: 0.8rem;
    padding: 0.8rem;
    border-radius: 6px;
    text-decoration: none !important;
    color: #333 !important;
    transition: background 0.2s;
    text-transform: none !important;
}
.mm-item:hover {
    background: #f8fafc;
}
.mm-item i {
    font-size: 1.2rem;
    color: #2563eb;
    margin-top: 0.2rem;
    width: 20px;
    text-align: center;
}
.mm-item h4 {
    margin: 0 0 0.2rem 0;
    font-size: 0.95rem;
    font-weight: 800;
    color: #111;
    text-transform: none;
}
.mm-item p {
    margin: 0;
    font-size: 0.75rem;
    color: #666;
    font-weight: 400;
    text-transform: none;
}

.megamenu-2col {
    display: grid;
    grid-template-columns: 2.5fr 1fr;
    gap: 3rem;
    min-width: 900px;
}
.mm-col h3 {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid #eaeaea;
    padding-bottom: 0.5rem;
}
.mm-link {
    display: block;
    padding: 0.5rem 0;
    color: #333 !important;
    text-decoration: none !important;
    font-size: 0.85rem !important;
    font-weight: 600 !important;
    transition: color 0.2s;
    text-transform: none !important;
}
.mm-link:hover {
    color: #2563eb !important;
}

/* MOBILE ACCORDION STYLES */
@media (max-width: 1024px) {
    header nav ul {
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
        width: 100%;
    }
    header nav ul li {
        width: 100%;
        border-bottom: 1px solid rgba(0,0,0,0.05);
    }
    header nav ul li a {
        padding: 1rem 0;
        width: 100%;
        justify-content: space-between;
    }
    .has-megamenu {
        position: relative;
    }
    .megamenu {
        position: static;
        transform: none;
        opacity: 1;
        visibility: visible;
        box-shadow: none;
        background: #f8fafc;
        border: none;
        padding: 0;
        display: none;
        min-width: 100%;
        border-radius: 0;
        margin-bottom: 1rem;
    }
    .has-megamenu.active .megamenu {
        display: block;
        padding: 1rem;
    }
    .megamenu-2col, .solutions-grid {
        grid-template-columns: 1fr;
        min-width: 100%;
        gap: 1rem;
    }
    .has-megamenu.active > a i {
        transform: rotate(180deg);
    }
    .has-megamenu > a i {
        transition: transform 0.3s;
    }
}

/* CONVENCIONALES SUBMENU */
.convencionales-list {
    display: none;
    margin-top: 0.8rem;
    padding-left: 0.5rem;
    border-left: 2px solid #eaeaea;
    margin-bottom: 1rem;
    padding-right: 10px;
    max-height: 55vh;
    overflow-y: auto;
}
.convencionales-list.open {
    display: block;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}
.density-group {
    margin-bottom: 0.5rem;
}
.density-title {
    font-size: 0.8rem;
    font-weight: 900;
    color: #2563eb;
    margin-bottom: 0.8rem;
    letter-spacing: 0.5px;
}
.foam-list-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem 2rem;
}
.foam-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    text-decoration: none !important;
    transition: transform 0.2s;
}
.foam-item:hover {
    transform: translateX(5px);
}
.foam-img {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid #eaeaea;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.foam-info {
    display: flex;
    flex-direction: column;
}
.foam-firmness {
    font-size: 0.85rem;
    font-weight: 800;
    color: #111;
    line-height: 1.2;
}
.foam-color {
    font-size: 0.75rem;
    color: #666;
    margin-top: 0.2rem;
}

/* CUSTOM SCROLLBAR FOR MEGAMENU LISTS */
.convencionales-list::-webkit-scrollbar, .hr-list::-webkit-scrollbar, .aglomerado-list::-webkit-scrollbar {
    width: 6px;
}
.convencionales-list::-webkit-scrollbar-track, .hr-list::-webkit-scrollbar-track, .aglomerado-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}
.convencionales-list::-webkit-scrollbar-thumb, .hr-list::-webkit-scrollbar-thumb, .aglomerado-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
.convencionales-list::-webkit-scrollbar-thumb:hover, .hr-list::-webkit-scrollbar-thumb:hover, .aglomerado-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.hr-list, .convencionales-list, .aglomerado-list { padding-right: 10px; }

/* ========================================================= */
/* OMNIFOAM GLOBAL RESPONSIVE & VISUAL FIXES (INJECTED)      */
/* ========================================================= */

/* GLOBAL: Fix horizontal scrolling and images */
html, body {
    overflow-x: hidden;
    width: 100%;
}
img {
    max-width: 100%;
    height: auto;
    object-fit: cover;
}

/* HEADER: Ensure highest z-index so dropdowns never hide */
header {
    z-index: 99999 !important;
}

/* FIXING MEGAMENU OVERRIDE ON MOBILE */
@media (max-width: 1024px) {
    /* Hamburger nav fixes */
    nav {
        position: fixed !important;
        top: 65px;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        max-height: calc(100vh - 65px) !important;
        max-height: calc(100dvh - 65px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        background: #111;
        display: none !important;
        padding: 1rem 5% 7rem !important;
        box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    }
    nav.open {
        display: block !important;
    }
    header nav ul {
        display: flex !important;
        flex-direction: column !important;
        gap: 0 !important;
        align-items: stretch !important;
    }
    header nav > ul > li {
        width: 100%;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    header nav > ul > li > a {
        padding: 1rem 0 !important;
        color: white !important; /* Fix contrast on dark bg */
        width: 100%;
        justify-content: space-between;
    }

    /* MEGAMENU -> ACCORDION ON MOBILE */
    .has-megamenu .megamenu {
        position: static !important;
        transform: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        box-shadow: none !important;
        background: rgba(255,255,255,0.03) !important;
        padding: 0 1rem 1rem 1rem !important;
        min-width: unset !important;
        display: none !important;
    }
    
    .has-megamenu.active .megamenu {
        display: block !important;
    }

    /* Inner links in megamenu mobile */

    .mm-link { color: #f8fafc !important; }
    .foam-firmness { color: #ffffff !important; }
    .foam-color { color: #bbbbbb !important; }
    .foam-short-desc { color: #aaaaaa !important; }
    .mm-item { color: #f8fafc !important; }

    .megamenu-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    .mm-item {
        background: rgba(255,255,255,0.05) !important;
        border: 1px solid rgba(255,255,255,0.1) !important;
        border-radius: 8px;
    }
    .mm-item:hover {
        background: rgba(255,255,255,0.1) !important;
    }
    .mm-item h4 {
        color: white !important;
    }
    .mm-item p {
        color: #bbb !important;
    }
    .mm-col h3 {
        color: #888 !important;
        border-bottom: 1px solid rgba(255,255,255,0.1) !important;
    }
    
    /* Grid for Materials on Mobile */
    .material-category {
        border-left: 2px solid #2563eb !important;
        padding-left: 1rem;
    }
    .foam-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Ensure icon flips on accordion */
    .has-megamenu.active > a > i {
        transform: rotate(180deg);
    }
}

/* ========================================================= */
/* TEXT CONTRAST & READABILITY FIXES (ALL SCREENS)           */
/* ========================================================= */
.btn-primary, .btn-primary-camper {
    color: white !important;
}
.btn-primary:hover, .btn-primary-camper:hover {
    color: white !important;
}

/* Ensure inputs are readable */
input, select, textarea {
    color: #111 !important;
    background-color: #fff !important;
}

/* Flex items fixes */
.half-half {
    align-items: center;
}

@media (max-width: 1024px) {
    .megamenu-2col {
        grid-template-columns: 1fr;
        min-width: 100%;
        gap: 1.5rem;
    }
    .foam-list-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

.foam-img {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    transform-origin: left center;
    position: relative;
    z-index: 1;
}
.foam-img:hover {
    transform: scale(1.1);
    z-index: 1000;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
    cursor: pointer;
}

    /* Prevent megamenu from overflowing the screen on desktop */
    @media (min-width: 1025px) {
        .megamenu {
            width: max-content;
            max-width: 90vw;
        }
        .has-megamenu:last-child .megamenu {
            left: auto;
            right: 0;
            transform: translateY(15px);
        }
        .has-megamenu:last-child:hover .megamenu {
            transform: translateY(0);
        }
    }

/* Fix for mobile: Disable max-height so it scrolls natively */
@media (max-width: 1024px) {
    .convencionales-list, .hr-list, .ignifugas-list, .tecnicas-list {
        max-height: none !important;
        overflow-y: visible !important;
    }
}

/* Custom scrollbars for the new lists */
.ignifugas-list::-webkit-scrollbar, .tecnicas-list::-webkit-scrollbar {
    width: 6px;
}
.ignifugas-list::-webkit-scrollbar-track, .tecnicas-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}
.ignifugas-list::-webkit-scrollbar-thumb, .tecnicas-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
.ignifugas-list::-webkit-scrollbar-thumb:hover, .tecnicas-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ===================================================
   MOBILE MENU - SCROLL FIX & UX IMPROVEMENTS
   =================================================== */
@media (max-width: 1024px) {
    /* El nav completo es el único contenedor con scroll suave en móvil */
    nav.open {
        max-height: calc(100vh - 65px) !important;
        max-height: calc(100dvh - 65px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: thin;
        scrollbar-color: rgba(255,255,255,0.2) transparent;
        padding-bottom: 7rem !important; /* Margen inferior para llegar a ver todos los materiales */
    }
    nav.open::-webkit-scrollbar {
        width: 5px;
    }
    nav.open::-webkit-scrollbar-thumb {
        background: rgba(255,255,255,0.25);
        border-radius: 4px;
    }

    /* El megamenú activo se expande dentro de nav sin atrapar el scroll */
    .has-megamenu.active .megamenu {
        max-height: none !important;
        overflow: visible !important;
    }

    /* Las listas de espumas se expanden completamente dentro del menú móvil */
    .convencionales-list,
    .hr-list,
    .ignifugas-list,
    .tecnicas-list,
    .aglomerado-list {
        max-height: none !important;
        overflow: visible !important;
    }

    /* Touch target mínimo para botones de muestra */
    .foam-item button,
    .foam-item .btn {
        min-height: 38px !important;
        padding: 0.45rem 0.65rem !important;
        font-size: 0.72rem !important;
        touch-action: manipulation;
    }

    /* Separadores visuales entre categorías */
    .mm-col + .mm-col {
        border-top: 1px solid rgba(255,255,255,0.08);
        padding-top: 0.8rem;
        margin-top: 0.5rem;
    }

    /* Imagen de espuma en el menú móvil: tamaño equilibrado */
    .foam-img {
        width: 44px !important;
        height: 44px !important;
    }

    /* Botón de muestra en el menú móvil más compacto */
    .foam-item {
        align-items: center !important;
    }

    /* Category section headers más compactos */
    .density-title {
        font-size: 0.72rem !important;
        margin-bottom: 0.5rem !important;
        padding: 0.2rem 0 !important;
    }
    .density-group {
        margin-bottom: 0.75rem !important;
    }
}

/* En móviles muy pequeños */
@media (max-width: 480px) {
    nav.open {
        max-height: calc(100vh - 60px) !important;
        max-height: calc(100dvh - 60px) !important;
        padding-bottom: 7rem !important;
    }
    .has-megamenu.active .megamenu {
        max-height: none !important;
        overflow: visible !important;
    }
    .foam-img {
        width: 38px !important;
        height: 38px !important;
    }
    .foam-firmness {
        font-size: 0.78rem !important;
    }
    .foam-color {
        font-size: 0.68rem !important;
    }
    .foam-short-desc {
        font-size: 0.65rem !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 1 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
    }
}
