/* --- ESTILOS GENERALES Y DE ESCRITORIO --- */
.cwmegamenu {
    font-family: 'Barlow', sans-serif;
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    width: 100%;
    /* background-color: #222222; Fondo oscuro (descomentar si es necesario en desktop) */
}

.cwmegamenu ul.navbar-nav {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    justify-content: center;
    margin: 0;
    padding: 0;
}

/* Elementos de primer nivel (Las secciones) */
.cwmegamenu ul.navbar-nav > li {
    position: relative;
    padding: 15px 20px;
}

.cwmegamenu ul.navbar-nav > li > a {
    color: #ffffff; /* Asegúrate de que esto contraste con el fondo de tu cabecera en escritorio */
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.cwmegamenu ul.navbar-nav > li > a:hover {
    color: #cccccc;
}

/* El cuadro desplegable (Megamenú en escritorio) */
.cwmegamenu .megamenu-content {
    display: none; /* Oculto por defecto */
    position: absolute;
    top: 100%;
    left: 0;
    background-color: #333333;
    min-width: 450px;
    padding: 20px;
    z-index: 9999;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
}

/* Mostrar el desplegable al hacer hover (solo actúa visiblemente en escritorio) */
.cwmegamenu ul.navbar-nav > li:hover .megamenu-content {
    display: flex;
    gap: 30px;
}

/* Estilos de los elementos internos (Títulos y enlaces) */
.cwmegamenu .megamenu-content > li {
    list-style: none;
    flex: 1;
}

.cwmegamenu .megamenu-item-title {
    display: block;
    color: #ffffff;
    border-bottom: 1px solid #555555;
    padding-bottom: 8px;
    margin-bottom: 12px;
    text-decoration: none;
    font-weight: 600;
}

/* Subcategorías */
.cwmegamenu .megamenu-subcategories {
    list-style: none;
    padding: 0;
    margin: 0;
}

.cwmegamenu .megamenu-subcategories li {
    padding: 4px 0;
}

.cwmegamenu .megamenu-subcategories a {
    color: #eeeeee;
    text-decoration: none;
    font-size: 0.95em;
}

.cwmegamenu .megamenu-subcategories a:hover {
    color: #ffffff;
    text-decoration: underline;
}

/* --- ESTILOS ESPECÍFICOS PARA MÓVIL (OFF-CANVAS DEFINITIVO) --- */
@media (max-width: 991px) {
    .cwmegamenu ul.navbar-nav { display: block; }
    
    /* Botón de apertura y overlay */
    .cwmegamenu-mobile-btn {
        display: inline-block; background: transparent; color: #fff; border: none; font-size: 25px;
        padding: 0px 10px; font-family: 'Barlow', sans-serif; cursor: pointer;
    }
    
    .cwmegamenu-overlay {
        position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
        background: rgba(0,0,0,0.6); z-index: 9998;
        opacity: 0; visibility: hidden; transition: opacity 0.3s ease;
    }
    .cwmegamenu-overlay.is-active { opacity: 1; visibility: visible; }

    /* --- CANVAS PRINCIPAL --- */
    .cwmegamenu {
        position: fixed; top: 0; left: 0;
        transform: translateX(-100%);
        width: 85%; max-width: 350px; height: 100vh;
        background: #ffffff; z-index: 9999; 
        transition: transform 0.3s ease-in-out;
        overflow-y: auto; overflow-x: hidden; color: #333333;
    }
    .cwmegamenu.is-open { 
        transform: translateX(0);
    }

    /* Cabecera principal */
    .cwmegamenu-mobile-header {
        display: flex; justify-content: space-between; align-items: center;
        padding: 20px; background: #f5f5f5; color: #333;
        border-bottom: 1px solid #e0e0e0; font-weight: bold; font-size: 1.1em;
    }
    .cwmegamenu-close-btn { background: none; border: none; color: #333; font-size: 20px; cursor: pointer; padding: 0; }

    /* ¡CLAVE 1! Quitar el position:relative del escritorio */
    .cwmegamenu ul.navbar-nav > li { position: static; border-bottom: 1px solid #eee; padding: 0; }
    
    .cwmegamenu ul.navbar-nav > li > a.section-link {
        display: flex; justify-content: space-between; align-items: center;
        padding: 15px 20px; color: #333; font-weight: 600; text-decoration: none;
    }
    .cwmegamenu-arrow { font-size: 20px; color: #888; }

    /* --- CANVAS SECUNDARIO (El Submenú interior) --- */
    .cwmegamenu .megamenu-content {
        display: none; /* Por defecto oculto para que no interfiera */
        position: absolute;
        top: 0; left: 0; 
        transform: translateX(100%);
        width: 100%; min-height: 100%; 
        background: #ffffff; padding: 0; margin: 0;
        transition: transform 0.3s ease-in-out; z-index: 10000;
        overflow-y: auto; overflow-x: hidden; box-shadow: none;
    }
    
    /* Cuando el JS le añade la clase .is-active, lo mostramos y deslizamos */
    .cwmegamenu .megamenu-content.is-active {
        display: block;
        transform: translateX(0);
    }

    /* ¡CLAVE 2! Neutralizar el comportamiento flex del hover/focus de escritorio */
    .cwmegamenu ul.navbar-nav > li:hover .megamenu-content,
    .cwmegamenu ul.navbar-nav > li:focus-within .megamenu-content {
        display: block; /* Mantiene el bloque en lugar de convertirlo en flex */
    }

    /* Asegurarnos de que el header y la lista ocupan el 100% del ancho */
    .cwmegamenu .megamenu-content > div,
    .cwmegamenu .megamenu-content > ul {
        width: 100%;
        display: block;
    }

    /* Cabecera del submenú (Estilo PcComponentes) */
    .cwmegamenu-submenu-header {
        display: flex; flex-direction: column; align-items: flex-start;
        padding: 20px; background: #ffffff; border-bottom: 1px solid #eee;
    }
    
    .cwmegamenu-back-btn {
        background: none; border: none; color: #555;
        font-size: 14px; cursor: pointer; padding: 0 0 15px 0;
        display: flex; align-items: center; gap: 5px; font-weight: 500;
    }
    
    .cwmegamenu-submenu-title { font-size: 24px; font-weight: 700; color: #333; margin: 0; line-height: 1.2; text-transform: uppercase; }

    /* Listado interno */
    .cwmegamenu .megamenu-items-list { padding: 0; margin: 0; list-style: none; }
    .cwmegamenu .megamenu-items-list li { border-bottom: 1px solid #f9f9f9; }
    
    /* Sobrescribimos el color blanco del desktop por oscuro en móvil */
    .cwmegamenu .megamenu-items-list a, 
    .cwmegamenu .megamenu-subcategories a {
        display: block; padding: 15px 20px; color: #444 !important; 
        text-decoration: none; font-size: 16px; font-weight: 500;
        border-bottom: none; /* Quitamos bordes internos del desktop */
    }
    
    .cwmegamenu .megamenu-items-list a:hover { background-color: #f5f5f5; }
    
    .cwmegamenu .megamenu-subcategories { padding: 0; margin: 0; }
    .cwmegamenu .megamenu-subcategories li { border: none; }
    .cwmegamenu .megamenu-subcategories a { padding-left: 30px; font-weight: 400; color: #666 !important; }
}

/* Ocultar elementos móviles en escritorio */
@media (min-width: 992px) {
    .cwmegamenu-mobile-btn, .cwmegamenu-overlay, 
    .cwmegamenu-mobile-header, .cwmegamenu-submenu-header, .cwmegamenu-arrow {
        display: none !important;
    }
}