/* ==========================================================================
   MEGA MENU DE CATEGORÍAS (Estilo Alibaba / Grid)
   ========================================================================== */

/* Contenedor en el nav — ancla el dropdown */
.hybinet-mega-menu-wrapper {
    position: static; /* En escritorio lo anclamos al header-bottom-inner (relativo más arriba) */
}

/* ==========================================================================
   DESKTOP Y ESTRUCTURA BASE
   ========================================================================== */
.hybinet-megamenu {
    position: absolute;
    left: 1.5rem; /* Alineado al padding del contenedor inner */
    top: 100%;
    width: 900px;
    max-width: calc(100vw - 3rem);
    height: 600px; /* Altura fija para tener un scroll consistente como Alibaba */
    max-height: 70vh;
    background: var(--hybinet-palette-white);
    border-radius: 0 0 12px 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-top: none;
    display: flex;
    z-index: 9999;
    
    /* Animación de entrada: Despliegue desde arriba */
    visibility: hidden;
    opacity: 0;
    pointer-events: none; /* Asegura que el menú oculto nunca intercepte el ratón */
    transform-origin: top center;
    transform: translateY(-5px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}

/* Puente invisible */
.hybinet-megamenu::before {
    content: '';
    position: absolute;
    top: -15px;
    left: 0;
    width: 100%;
    height: 15px;
    z-index: 1;
}

/* Ocultar elementos exclusivos de móvil en escritorio */
.hybinet-megamenu__mobile-main-header {
    display: none;
}

/* Mostrar al hacer hover */
@media (min-width: 768px) {
    /* El overlay oscuro */
    .hybinet-mega-menu-wrapper::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1; /* Dentro del contexto del header, esto lo coloca detrás del fondo del header pero encima del body */
        visibility: hidden;
        opacity: 0;
        transition: opacity 0.1s ease, visibility 0s linear 0.1s;
        pointer-events: none;
    }

    .hybinet-mega-menu-wrapper.is-open::after {
        visibility: visible;
        opacity: 1;
        transition: opacity 0.2s ease 0.05s, visibility 0s linear 0.05s;
        pointer-events: none;
    }

    .hybinet-mega-menu-wrapper.is-open > .hybinet-megamenu {
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0);
        transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0s;
    }
}

/* Envuelve sidebar + contenido en escritorio y móvil */
.hybinet-megamenu__body-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* --- SIDEBAR (Nivel 1) --- */
.hybinet-megamenu__sidebar {
    width: 250px;
    flex-shrink: 0;
    background-color: var(--hybinet-color-bg-secondary);
    border-right: 1px solid rgba(0, 0, 0, 0.05);
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-y: auto;
    border-radius: 0 0 0 12px;
    
    /* Scrollbar sutil */
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.15) transparent;
}

.hybinet-megamenu__sidebar::-webkit-scrollbar {
    width: 6px;
}
.hybinet-megamenu__sidebar::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.15);
    border-radius: 10px;
}

.hybinet-megamenu__sidebar-item {
    margin: 0;
    padding: 0;
}

.hybinet-megamenu__sidebar-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    padding: 12px 20px;
    color: var(--hybinet-color-text-primary);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    border-left: 3px solid transparent; /* Indicador de selección */
    border-radius: 0 !important;
    outline: none !important;
    box-shadow: none !important;
    transition: background-color 0.15s, color 0.15s;
    cursor: pointer;
}

.hybinet-megamenu__sidebar-link svg {
    color: var(--hybinet-color-text-meta, #9ca3af);
    transition: color 0.15s;
}

.hybinet-megamenu__sidebar-link:hover svg,
.hybinet-megamenu__sidebar-link:focus svg,
.hybinet-megamenu__sidebar-link.is-active svg {
    color: var(--hybinet-color-brand-primary);
}

.hybinet-megamenu__sidebar-link:hover,
.hybinet-megamenu__sidebar-link:focus {
    background-color: var(--hybinet-palette-white);
    color: var(--hybinet-color-brand-primary);
}

.hybinet-megamenu__sidebar-link.is-active {
    background-color: var(--hybinet-palette-white);
    color: var(--hybinet-color-brand-primary);
    font-weight: 600;
    border-left-color: var(--hybinet-color-text-primary); /* Línea negra para el activo */
}

/* --- PANEL DE CONTENIDO (Niveles 2 y 3) --- */
.hybinet-megamenu__content {
    flex-grow: 1;
    background-color: var(--hybinet-palette-white);
    position: relative;
    border-radius: 0 0 12px 0;
}

.hybinet-megamenu__panel {
    position: absolute;
    inset: 0;
    padding: 24px;
    overflow-y: auto;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease;
    
    /* Scrollbar sutil */
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.15) transparent;
}

.hybinet-megamenu__panel::-webkit-scrollbar {
    width: 6px;
}
.hybinet-megamenu__panel::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.15);
    border-radius: 10px;
}

.hybinet-megamenu__panel.is-active {
    visibility: visible;
    opacity: 1;
    z-index: 2;
}

/* Encabezado visible en móvil (oculto en desktop para ahorrar espacio) */
.hybinet-megamenu__mobile-header {
    display: none;
}

/* Secciones (Nivel 2) */
.hybinet-megamenu__section {
    margin-bottom: 32px;
}

.hybinet-megamenu__section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--hybinet-color-title);
    margin-top: 0;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.hybinet-megamenu__section-title a {
    color: inherit;
    text-decoration: none;
}
.hybinet-megamenu__section-title a:hover {
    color: var(--hybinet-color-brand-primary);
}

/* Grid de Tarjetas (Nivel 3) */
.hybinet-megamenu__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 16px;
}

/* Tarjeta individual (Imagen circular + texto) */
.hybinet-megamenu__card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--hybinet-color-text-secondary);
    text-align: center;
    transition: transform 0.2s ease;
}

.hybinet-megamenu__card:hover {
    transform: translateY(-2px);
    color: var(--hybinet-color-brand-primary);
}

.hybinet-megamenu__card-img {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: var(--hybinet-color-bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.03);
    border: 1px solid rgba(0,0,0,0.03);
}

.hybinet-megamenu__card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.hybinet-megamenu__card-fallback {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--hybinet-color-text-meta);
    text-transform: uppercase;
}

.hybinet-megamenu__card-text {
    font-size: 0.8rem;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Estado vacío */
.hybinet-megamenu__empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--hybinet-color-text-meta);
}

/* ==========================================================================
   MÓVIL (Comportamiento Touch Pestañas)
   ========================================================================== */
@media (max-width: 767px) {
    .hybinet-megamenu {
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-width: none;
        max-height: none;
        border-radius: 0;
        box-shadow: none;
        border: none;
        z-index: 100000; /* Por encima de TODO */
        flex-direction: column;
        pointer-events: none; /* Nunca intercepta el ratón cuando está oculto */
        
        /* Animación: solo opacidad, sin transform para no romper position:fixed */
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease, visibility 0s linear 0.25s;
    }
    
    .hybinet-megamenu.is-open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transition: opacity 0.25s ease, visibility 0s linear 0s;
    }
    
    .hybinet-mega-menu-wrapper:hover > .hybinet-megamenu:not(.is-open) {
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
    }

    /* Cabecera Móvil (El botón < Categorías) */
    .hybinet-megamenu__mobile-main-header {
        display: grid;
        grid-template-columns: 40px 1fr 40px;
        align-items: center;
        padding: 12px 16px;
        background-color: var(--hybinet-palette-white);
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }

    .hybinet-megamenu__mobile-main-header span {
        grid-column: 2;
        text-align: center;
        font-weight: 700;
        font-size: 1.1rem;
    }

    .hybinet-megamenu__close {
        grid-column: 1;
        background: none;
        border: none;
        padding: 8px;
        margin-left: -8px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--hybinet-color-text-primary);
        border-radius: 50%;
        width: 40px;
        height: 40px;
        transition: background-color 0.15s ease;
    }

    .hybinet-megamenu__close:hover,
    .hybinet-megamenu__close:active {
        background-color: var(--hybinet-color-bg-tertiary);
        color: var(--hybinet-color-text-primary); /* Sin cambio de color en ícono */
    }

    /* Contenedor Flex para Sidebar y Contenido */
    .hybinet-megamenu__body-wrapper {
        display: flex;
        flex: 1;
        overflow: hidden; /* Evita que crezca más del 100vh */
        background-color: var(--hybinet-color-bg-secondary);
    }

    /* Sidebar ocupa 35% */
    .hybinet-megamenu__sidebar {
        width: 35%;
        border-radius: 0;
        height: 100%;
        overflow-y: auto;
    }
    
    .hybinet-megamenu__sidebar-link {
        padding: 16px 12px;
        font-size: 0.85rem;
    }

    /* Contenido ocupa 65% */
    .hybinet-megamenu__content {
        width: 65%;
        border-radius: 0;
        height: 100%;
        overflow-y: auto;
        background-color: var(--hybinet-palette-white);
    }
    
    .hybinet-megamenu__panel {
        padding: 16px;
    }
    
    /* Mostrar cabecera en móvil */
    .hybinet-megamenu__mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20px;
    }
    
    .hybinet-megamenu__mobile-header h2 {
        font-size: 1.1rem;
        font-weight: 800;
        margin: 0;
    }
    
    .hybinet-megamenu__view-all {
        font-size: 0.8rem;
        color: var(--hybinet-color-brand-primary);
        font-weight: 600;
        text-decoration: none;
    }
    
    /* Ajustar cuadrícula en móvil */
    .hybinet-megamenu__grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
        gap: 12px;
    }
    
    .hybinet-megamenu__card-img {
        width: 60px;
        height: 60px;
    }
    
    .hybinet-megamenu__section-title {
        font-size: 0.95rem;
    }
}
