/* ===== DESKTOP (default) ===== */
#megaMenu{
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  height: 0;
  overflow: hidden;

  background: #fff;
  z-index: 999;

  opacity: 0;
  visibility: hidden;
  transition: height .3s ease, opacity .2s ease;
  border-top: 1px solid #e0e0e0;
  box-shadow: 0 10px 20px rgba(0,0,0,.1);
  display: flex;
}

#megaMenu.open{
  height: 400px;          /* desktop fijo */
  opacity: 1;
  visibility: visible;
}

/* ===== MegaMenu FIX Mobile ===== */
@media (max-width: 768px) {

  /* importante: el nav debe tener contexto */
  .main-nav {
    position: relative;
  }

  /* en mobile el mega menu debe ser un panel fijo */
  #megaMenu {
    position: fixed;
    left: 0;
    right: 0;
    top: 64px;     /* ajusta */
    height: auto !important;    /* ✅ evita hueco */
    max-height: 70vh; 
    width: 100vw;

    display: none;
    background: #fff;

    overflow-y: auto;   /* ✅ único scroll */
    overflow-x: hidden;

    z-index: 9999;
    box-shadow: 0 10px 30px rgba(0,0,0,.15);
  }
  
  #megaMenu .mega-menu-container{
    width: 100% !important;
    max-width: 100% !important;
  }

  #megaMenu.open { display: block; }

  /* layout en columna */
  .mega-menu-container {
    flex-direction: column;
    max-width: 100%;
    height: auto !important; /* ✅ */
  }

  #megaCategoriesList {
    width: 100%;
    height: auto !important;     /* ✅ */
    overflow: visible !important;/* ✅ */
    border-right: 0;
  }
  
  #megaMenu #megaCategoriesList{
    width: 100% !important;
    max-width: 100% !important;
  }

  .mega-content-area { display: none !important; }

  #megaSubcategoriesGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  
  #megaMenu #megaCategoriesList li,
  #megaMenu .category-header{
    width: 100% !important;
    box-sizing: border-box;
  }

}

/* Layout Grid */
.mega-menu-container {
    display: flex;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
}

/* Categories List (Left Side) */
#megaCategoriesList {
    width: 250px;
    list-style: none;
    padding: 0;
    margin: 0;
    background-color: #f9f9f9;
    border-right: 1px solid #eee;
    overflow-y: auto;
    height: 100%;
}

#megaCategoriesList li {
    padding: 0; /* Reset padding for li */
    cursor: default;
    color: #555;
    transition: background-color 0.2s, color 0.2s;
    font-size: 0.95rem;
    border-bottom: 1px solid #eee;
    display: block; /* Change from flex to block to hold sub-ul */
}

.category-header {
    padding: 15px 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

#megaCategoriesList li:hover .category-header,
#megaCategoriesList li.active .category-header {
    background-color: #fff0f0;
    color: #e7452e;
    border-left: 3px solid #e7452e;
}

/* Hide mobile elements on desktop */
.mobile-subcategories {
    display: none;
}

.mobile-arrow {
    display: none;
}

/* Desktop Chevron using pseudo-element */
#megaCategoriesList li.active .category-header::after {
    content: '\f054'; /* FontAwesome right chevron */
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    font-size: 0.8rem;
}

/* Subcategories Grid (Right Side) */
.mega-content-area {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #fff;
}

#megaSubcategoriesGrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 20px;
}

/* Subcategory Items */
.subcat {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    text-decoration: none;
    color: #555;
    padding: 10px;
    border-radius: 8px;
    transition: background-color 0.2s, transform 0.2s;
}

.subcat:hover {
    background-color: #f5f5f5;
    transform: translateY(-5px);
    color: #e7452e;
}

.subcat img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 10px;
    background-color: #fff;
    padding: 5px;
    border-radius: 50%;
    border: 1px solid #eee;
}

.subcat span {
    font-size: 0.9rem;
    line-height: 1.2;
}

/* Loading & Empty States */
#megaSubcategoryEmpty {
    color: #888;
    text-align: center;
    padding: 40px;
    font-style: italic;
    display: none;
}

.loading {
    padding: 20px;
    text-align: center;
    color: #888;
}

/* Search Panel (if used) */
#searchCategoriesPanel {
    display: none; /* Implementar si es necesario */
}

/* Scrollbar Styling */
#megaCategoriesList::-webkit-scrollbar,
.mega-content-area::-webkit-scrollbar {
    width: 6px;
}

#megaCategoriesList::-webkit-scrollbar-track,
.mega-content-area::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#megaCategoriesList::-webkit-scrollbar-thumb,
.mega-content-area::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

#megaCategoriesList::-webkit-scrollbar-thumb:hover,
.mega-content-area::-webkit-scrollbar-thumb:hover {
    background: #bbb;
}
