/**
 * Mega Menu de Categorías - Estilos
 * Menú de sábana responsive para navbar/navegación
 */

/* ========================================
   CONTENEDOR PRINCIPAL - NAVBAR MODE
   ======================================== */

.waeg-mega-menu {
  width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  position: relative;
  /* ✅ visibility: hidden evita renderizado progresivo visible */
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

/* ✅ Visible cuando JavaScript lo marque como listo O en modo navbar */
.waeg-mega-menu.waeg-ready,
.waeg-mega-menu.navbar-mode {
  visibility: visible !important;
  opacity: 1 !important;
  transition: opacity 0.2s ease, visibility 0s linear 0s;
}

/* Modo Navbar: Horizontal (botón siempre visible) */
.waeg-mega-menu.navbar-mode {
  display: inline-block;
  position: relative;
}

/* ✅ Grid del navbar: control de visibilidad solo por hover EN DESKTOP */
.waeg-mega-menu.navbar-mode .waeg-mega-menu-grid {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 800px;
  max-width: 1200px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  z-index: 9999;
  margin-top: 0;
}

/* ✅ Grid visible en hover SOLO EN DESKTOP (no en mobile) */
@media (min-width: 768px) {
  .waeg-mega-menu.navbar-mode:hover .waeg-mega-menu-grid {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
}

.waeg-mega-menu-grid {
  display: grid;
  gap: 30px;
  padding: 20px;
  background: var(--waeg-black);
  border: 1px solid var(--waeg-gray-700);
  border-radius: var(--waeg-radius-md);
  box-shadow: var(--waeg-shadow-dark);
}

/* Botón trigger del navbar */
.waeg-mega-menu-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: transparent;
  color: #ffffff;
  text-decoration: none;
  font-weight: 600;
  font-size: 0; /* Ocultar texto por defecto (mobile-first) */
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid #fff;
  width: 44px;
  height: 44px;
  position: relative;
}

/* Mostrar texto solo en desktop */
@media (min-width: 768px) {
  .waeg-mega-menu-trigger {
    font-size: 15px;
    padding: 12px 20px;
    background: #000000;
    border: none;
    width: auto;
    height: auto;
  }
}

/* Hover solo en desktop */
@media (min-width: 768px) {
  .waeg-mega-menu-trigger:hover {
    background: var(--waeg-gray-900);
    color: var(--waeg-primary-dark);
  }
}

/* Icono hamburger por defecto (mobile-first) */
.waeg-mega-menu-trigger::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 2px;
  background: #fff;
  box-shadow: 0 6px 0 #fff, 0 12px 0 #fff;
  top: 50%;
  transform: translateY(-50%);
  margin-top: -2px;
  transition: all 0.3s ease;
}

/* Ocultar icono hamburger en desktop */
@media (min-width: 768px) {
  .waeg-mega-menu-trigger::before {
    display: none;
  }
}

.waeg-mega-menu-trigger::after {
  content: " ▼";
  font-size: 10px;
  margin-left: 8px;
  transition: transform 0.3s ease;
  position: static;
  display: inline;
  color: #ffffff;
  transform: none;
}

/* Flechita en mobile - oculta */
@media (max-width: 767px) {
  .waeg-mega-menu-trigger::after {
    display: none !important;
  }
}

/* Navbar hover en desktop */
@media (min-width: 768px) {
  .waeg-mega-menu.navbar-mode:hover .waeg-mega-menu-trigger::after {
    transform: rotate(180deg);
  }
}

/* ========================================
   COLUMNAS
   ======================================== */

.waeg-mega-menu-column {
  display: flex;
  flex-direction: column;
  min-width: 0; /* Prevenir overflow */
}

.waeg-mega-menu-category {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ========================================
   IMAGEN DE CATEGORÍA
   ======================================== */

.waeg-mega-menu-image {
  width: 100%;
  margin-bottom: 15px;
  overflow: hidden;
  border-radius: 6px;
  background: #1a1a1a;
}

.waeg-mega-menu-image a {
  display: block;
  position: relative;
  padding-bottom: 75%; /* Aspect ratio 4:3 */
  overflow: hidden;
}

.waeg-mega-menu-image img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.waeg-mega-menu-image a:hover img {
  transform: scale(1.05);
}

/* ========================================
   TÍTULO DE CATEGORÍA PRINCIPAL
   ======================================== */

.waeg-mega-menu-title {
  margin: 0 0 12px 0;
  padding: 0 0 10px 0;
  border-bottom: 2px solid var(--waeg-primary-dark);
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.waeg-mega-menu-title a {
  color: #ffffff;
  text-decoration: none;
  transition: color 0.3s ease;
}

.waeg-mega-menu-title a:hover {
  color: var(--waeg-primary-dark);
}

/* ========================================
   CONTADOR DE PRODUCTOS
   ======================================== */

.waeg-category-count {
  color: #999999;
  font-weight: 400;
  font-size: 0.85em;
  margin-left: 5px;
}

/* ========================================
   SUBCATEGORÍAS
   ======================================== */

.waeg-mega-menu-subcategories {
  list-style: none;
  margin: 0;
  padding: 0;
}

.waeg-mega-menu-subcategories > li {
  margin-bottom: 4px;
}

.waeg-mega-menu-subcategories > li > a {
  display: block;
  padding: 6px 10px;
  color: #ffffff;
  text-decoration: none;
  font-size: 14px;
  border-radius: 4px;
  transition: all 0.3s ease;
}

.waeg-mega-menu-subcategories > li > a:hover {
  background: var(--waeg-gray-900);
  color: var(--waeg-primary-dark);
  padding-left: 15px;
}

/* ========================================
   SUB-SUBCATEGORÍAS (NIVEL 3)
   ======================================== */

.waeg-mega-menu-subsubcategories {
  list-style: none;
  margin: 5px 0 0 15px;
  padding: 0;
}

.waeg-mega-menu-subsubcategories li {
  margin-bottom: 5px;
}

.waeg-mega-menu-subsubcategories a {
  display: block;
  padding: 4px 8px;
  color: #cccccc;
  text-decoration: none;
  font-size: 13px;
  border-left: 2px solid #333333;
  padding-left: 12px;
  transition: all 0.3s ease;
}

.waeg-mega-menu-subsubcategories a:hover {
  color: var(--waeg-primary-dark);
  border-left-color: var(--waeg-primary-dark);
  padding-left: 16px;
}

/* ========================================
   RESPONSIVE - TABLET
   ======================================== */

@media (max-width: 1024px) {
  .waeg-mega-menu-grid {
    gap: 20px;
    padding: 15px;
  }

  /* Navbar mode: ajustar ancho en tablet */
  .waeg-mega-menu.navbar-mode .waeg-mega-menu-grid {
    min-width: 600px;
    max-width: 800px;
  }

  /* Reducir a 3 columnas en tablet */
  .waeg-mega-menu[data-columns="6"] .waeg-mega-menu-grid,
  .waeg-mega-menu[data-columns="5"] .waeg-mega-menu-grid,
  .waeg-mega-menu[data-columns="4"] .waeg-mega-menu-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  .waeg-mega-menu-title {
    font-size: 15px;
  }

  .waeg-mega-menu-subcategories > li > a {
    font-size: 13px;
  }
}

/* ========================================
   RESPONSIVE - MÓVIL
   ======================================== */

@media (max-width: 767px) {
  /* ✅ Ocultar completamente el menú hasta que esté listo en móvil */
  .waeg-mega-menu:not(.waeg-ready) {
    visibility: hidden !important;
    opacity: 0 !important;
  }
  
  /* Grid cambia a diseño vertical de acordeón */
  .waeg-mega-menu-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
    padding: 0 !important;
    height: auto;
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: hidden;
    grid-template-columns: none !important;
  }

  /* Navbar mode: ancho completo en móvil */
  .waeg-mega-menu.navbar-mode .waeg-mega-menu-grid {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    min-width: 100%;
    max-width: 100%;
    max-height: 80vh;
    border-radius: 0;
    margin-top: 0;
    /* ✅ Oculto por defecto en móvil navbar */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
  }
  
  /* ✅ Grid activo necesita position relative para el botón absoluto */
  .waeg-mega-menu.navbar-mode .waeg-mega-menu-grid.active {
    position: fixed;
  }
  
  /* ✅ Visible cuando se hace click en el botón hamburguesa */
  .waeg-mega-menu.navbar-mode .waeg-mega-menu-grid.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  /* ✅ Header bar con título y botón de cierre */
  .waeg-mega-menu-header-bar {
    position: sticky;
    top: 0;
    width: 100%;
    background: #1a1a1a;
    border-bottom: 2px solid #8B0000;
    padding: 12px 50px 12px 15px;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .waeg-mega-menu-title-text {
    margin: 0;
    padding: 0;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    text-align: center;
    flex: 1;
  }

  /* ✅ Botón de cierre del menú */
  .waeg-mega-menu-close {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    background: #8B0000;
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    z-index: 1002;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
  }

  .waeg-mega-menu-close:hover,
  .waeg-mega-menu-close:active {
    background: #a00000;
    transform: translateY(-50%) scale(1.1);
  }

  .waeg-mega-menu-close span {
    line-height: 1;
    display: block;
    font-weight: bold;
    pointer-events: none;
  }

  /* ✅ Botón activo cuando el menú está abierto */
  .waeg-mega-menu-trigger.active {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: #8B0000 !important;
  }
  
  /* ✅ Rotar flechita cuando está activo */
  .waeg-mega-menu-trigger.active::after {
    transform: translateX(-50%) rotate(180deg) !important;
    color: #8B0000 !important;
  }

  /* Cada columna = categoría con subcategorías colapsables */
  .waeg-mega-menu-column {
    display: block !important;
    flex: none !important;
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible;
    background: transparent;
    border-right: none;
    border-bottom: 1px solid #1a1a1a;
    padding: 0;
  }

  /* Ocultar imágenes en móvil */
  .waeg-mega-menu-image {
    display: none !important;
  }

  .waeg-mega-menu-category {
    height: auto;
  }

  /* Título de categoría como botón clickeable tipo acordeón */
  .waeg-mega-menu-title,
  .waeg-mega-menu-header {
    font-size: 11px; /* ✅ Reducido de 14px a 11px (-3px) */
    margin: 0;
    padding: 10px 15px; /* ✅ Reducido de 16px a 10px vertical */
    border-bottom: none;
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #0a0a0a;
    position: relative;
  }

  .waeg-mega-menu-title a,
  .waeg-mega-menu-header h3 {
    pointer-events: auto; /* ✅ Cambiar a auto para que sea clickeable */
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff; /* ✅ Asegurar que siempre sea blanco */
    font-size: 11px;
    margin: 0;
    font-weight: 600;
    cursor: pointer;
  }
  
  .waeg-mega-menu-header h3 a {
    color: #fff; /* ✅ Enlaces blancos */
    text-decoration: none;
    pointer-events: none; /* ✅ Deshabilitar click en el enlace hijo */
  }

  .waeg-mega-menu-title a::after,
  .waeg-mega-menu-header h3::after {
    content: "▼";
    font-size: 10px; /* ✅ Reducido de 12px a 10px */
    color: #fff; /* ✅ Flechita blanca por defecto */
    transition: all 0.3s ease;
    transform: rotate(-90deg);
  }

  /* Categoría expandida */
  .waeg-mega-menu-column.expanded .waeg-mega-menu-title,
  .waeg-mega-menu-column.expanded .waeg-mega-menu-header {
    background: #1a1a1a;
    border-left-color: #8B0000;
  }

  .waeg-mega-menu-column.expanded .waeg-mega-menu-title a,
  .waeg-mega-menu-column.expanded .waeg-mega-menu-header h3,
  .waeg-mega-menu-column.expanded .waeg-mega-menu-header h3 a {
    color: #fff; /* ✅ Mantener blanco incluso cuando está expandida */
  }

  .waeg-mega-menu-column.expanded .waeg-mega-menu-title a::after,
  .waeg-mega-menu-column.expanded .waeg-mega-menu-header h3::after {
    color: #8B0000;
    transform: rotate(0deg);
  }

  /* Subcategorías - ocultas por defecto, se muestran al expandir */
  .waeg-mega-menu-column .waeg-mega-menu-subcategories {
    display: none;
    list-style: none;
    margin: 0;
    padding: 0;
    background: #000;
    border-left: 3px solid #8B0000;
  }

  .waeg-mega-menu-column.expanded .waeg-mega-menu-subcategories {
    display: block !important;
    animation: mega-slideDown 0.3s ease-out;
  }

  @keyframes mega-slideDown {
    from {
      opacity: 0;
      max-height: 0;
    }
    to {
      opacity: 1;
      max-height: 500px;
    }
  }

  .waeg-mega-menu-subcategories > li {
    margin-bottom: 0;
    border-bottom: 1px solid #0a0a0a;
  }

  .waeg-mega-menu-subcategories > li > a {
    font-size: 10px; /* ✅ Reducido de 13px a 10px (-3px) */
    padding: 6px 15px 6px 25px; /* ✅ Reducido de 8px a 6px vertical */
    display: block;
    color: #fff; /* ✅ Texto blanco */
    background: #000;
    border-radius: 0;
    border-left: none;
    transition: all 0.3s ease;
  }

  .waeg-mega-menu-subcategories > li > a:hover {
    background: #1a1a1a;
    color: #8B0000;
    padding-left: 30px;
  }

  /* Sub-subcategorías */
  .waeg-mega-menu-subsubcategories {
    margin: 0;
    margin-left: 20px;
    padding: 0;
    list-style: none;
    background: #000;
  }

  .waeg-mega-menu-subsubcategories li {
    margin-bottom: 0;
    border-bottom: 1px solid #0a0a0a;
  }

  .waeg-mega-menu-subsubcategories a {
    font-size: 9px; /* ✅ Reducido de 12px a 9px (-3px) */
    padding: 4px 15px 4px 35px; /* ✅ Reducido de 6px a 4px vertical */
    color: #fff; /* ✅ Texto blanco */
    background: #000;
    border-left: none;
    border-radius: 0;
    display: block;
  }

  .waeg-mega-menu-subsubcategories a:hover {
    color: #8B0000;
    background: #0a0a0a;
    padding-left: 40px;
  }

  /* Scrollbar personalizado para móvil */
  .waeg-mega-menu-grid::-webkit-scrollbar {
    width: 4px;
  }

  .waeg-mega-menu-grid::-webkit-scrollbar-track {
    background: #0a0a0a;
  }

  .waeg-mega-menu-grid::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 2px;
  }

  .waeg-mega-menu-grid::-webkit-scrollbar-thumb:hover {
    background: #555;
  }

  /* Ocultar panel derecho si existe */
  .waeg-mobile-subcategories-panel {
    display: none !important;
  }
}

/* ========================================
   RESPONSIVE - MÓVIL PEQUEÑO
   ======================================== */

@media (max-width: 480px) {
  /* 1 columna en móviles pequeños */
  .waeg-mega-menu-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
    padding: 8px;
  }

  .waeg-mega-menu-image {
    margin-bottom: 10px;
  }

  .waeg-mega-menu-title {
    font-size: 13px;
  }

  .waeg-mega-menu-subcategories > li > a {
    font-size: 11px;
  }
}

/* ========================================
   VARIANTES DE COLOR (OPCIONALES)
   ======================================== */

/* Variante de color claro */
.waeg-mega-menu.light-theme {
  background: transparent;
}

.waeg-mega-menu.light-theme .waeg-mega-menu-grid {
  background: #ffffff;
  border-color: #ddd;
}

.waeg-mega-menu.light-theme .waeg-mega-menu-title a {
  color: #333;
}

.waeg-mega-menu.light-theme .waeg-mega-menu-subcategories > li > a {
  color: #555;
}

.waeg-mega-menu.light-theme .waeg-mega-menu-subcategories > li > a:hover {
  background: #f5f5f5;
}

/* Variante de color oscuro (ahora es por defecto) */
.waeg-mega-menu.dark-theme .waeg-mega-menu-grid {
  background: #000000;
  border-color: #333333;
}

.waeg-mega-menu.dark-theme .waeg-mega-menu-title a {
  color: #ffffff;
}

.waeg-mega-menu.dark-theme .waeg-mega-menu-subcategories > li > a {
  color: #ffffff;
}

.waeg-mega-menu.dark-theme .waeg-mega-menu-subcategories > li > a:hover {
  background: #1a1a1a;
  color: #8B0000;
}

/* ========================================
   ESTADOS DE CARGA Y VACÍO
   ======================================== */

.waeg-mega-menu-loading {
  text-align: center;
  padding: 40px;
  color: #999999;
}

.waeg-mega-menu-empty {
  text-align: center;
  padding: 40px;
  color: #cccccc;
  font-style: italic;
}

/* ========================================
   ANIMACIONES
   ======================================== */

@keyframes mega-fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.waeg-mega-menu-column {
  animation: mega-fadeIn 0.4s ease-out;
}

/* Delay progresivo para cada columna */
.waeg-mega-menu-column:nth-child(1) { animation-delay: 0s; }
.waeg-mega-menu-column:nth-child(2) { animation-delay: 0.05s; }
.waeg-mega-menu-column:nth-child(3) { animation-delay: 0.1s; }
.waeg-mega-menu-column:nth-child(4) { animation-delay: 0.15s; }
.waeg-mega-menu-column:nth-child(5) { animation-delay: 0.2s; }
.waeg-mega-menu-column:nth-child(6) { animation-delay: 0.25s; }
