/* Mega Menu Styles */
.mega-menu-container {
  position: relative;
}

.mega-menu-container ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
}

.mega-menu-container > ul > li {
  position: relative;
  margin: 0 1rem;
}

.mega-menu-container > ul > li > a {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  color: white;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s ease;
  border-radius: 0.5rem;
}

.mega-menu-container > ul > li > a:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.mega-menu-container > ul > li > a::after {
  content: "˅";
  margin-left: 0.5rem;
  font-size: 0.8rem;
  transition: transform 0.3s ease;
}

.mega-menu-container > ul > li:hover > a::after {
  transform: rotate(180deg);
}

/* Mega Menu Dropdown - Enhanced with adaptive sizing */
.mega-menu-dropdown {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 90vw;
  max-width: 1200px;
  min-width: 800px; /* Minimum width for proper layout */
  border-radius: 1rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px) translateX(-50%);
  transition: all 0.3s ease;
  z-index: 1000;
  margin-top: 0.5rem;
  min-height: 400px;
  max-height: 80vh; /* Limit height to viewport */
}

/* Show dropdown only for the hovered parent */
.mega-menu-container > ul > li:hover > .mega-menu-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) translateX(-50%);
}

.mega-menu-columns {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  padding: 1rem;
}

.mega-menu-column-groups {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
  min-width: 200px;
}

.mega-menu-column-header:hover a,
.mega-menu-column-header.active {
  color: #3b82f6;
  border-color: #3b82f6;
  transform: translateX(3px);
}

.mega-menu-column-header {
  border-radius: 0.5rem;
  padding: 9px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Updated to justify toggle-dropdown to the right */
.mega-menu-column-header .toggle-dropdown {
  margin-left: 1rem; /* Optional: Add spacing between text and icon */
  transition: transform 0.3s ease;
}

.mega-menu-column-header:hover .toggle-dropdown {
  transform: rotate(180deg);
}

/* Updated hover rule to target only the specific column group's items */
.mega-menu-column-group:hover > .mega-menu-column-items {
    display: block;
    opacity: 1;
    max-height: auto; /* Adjust as needed */
}

.mega-menu-column-group {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.5rem;
}
.menu-item[data-mega-menu="true"] .toggle-dropdown {
    margin-left: 8px;
    transition: transform 0.3s ease;
}
.menu-item[data-mega-menu="true"]:hover .toggle-dropdown {
    transform: rotate(180deg);
}

.mega-menu-column-items {
  display: none; /* Initial state */
  flex-direction: column;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity 0.3s ease, max-height 0.3s ease;
}

/* Content layout - Enhanced with scrolling */
.mega-menu-content {
  display: flex;
  padding: 0;
  gap: 0;
  min-height: 400px;
  max-height: 80vh; /* Limit total height */
  border-radius: 1rem;
  overflow: hidden;
  width: 90%;
}

/* Sidebar - Left column */
.mega-menu-sidebar {
  flex: 0 0 280px;
  background: rgba(0, 0, 0, 0.8);
  padding: 1.5rem;
  padding-top: 45px;
  backdrop-filter: blur(10px);
  overflow-y: auto; /* Add vertical scrolling for sidebar */
  max-height: 80vh;
}

/* Custom scrollbar for sidebar */
.mega-menu-sidebar::-webkit-scrollbar {
  width: 6px;
}

.mega-menu-sidebar::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.mega-menu-sidebar::-webkit-scrollbar-thumb {
  background: rgba(96, 165, 250, 0.5);
  border-radius: 3px;
}

.mega-menu-sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(96, 165, 250, 0.7);
}

.mega-menu-category {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  cursor: pointer;
  border-top: 1px solid white;
}

.mega-menu-category a {
  display: block;
  padding: 0.5rem !important;
  color: white;
  text-decoration: none;
  transition: all 0.3s ease;
  font-weight: 500;
  font: 18px 'Helvetica ', sans-serif;
  position: relative;
}

.mega-menu-category .bi-chevron-right {
  margin-left: 1rem; /* Optional: Add spacing between text and icon */
  transition: transform 0.3s ease;
}

/* .mega-menu-category:hover .bi-chevron-right {
  transform: rotate(90deg); 
} */

.mega-menu-category:hover a,
.mega-menu-category.active a {
  color: #2563eb;
  border-color: #3b82f6;
  transform: translateX(3px);
}

.mega-menu-category a::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: #60a5fa;
  border-radius: 2px;
  transition: height 0.3s ease;
}

.mega-menu-category:hover a::before,
.mega-menu-category.active a::before {
  height: 60%;
}

/* Main Content Area - Enhanced with scrolling */
.mega-menu-main {
  flex: 1;
  background: rgb(31 39 67 / 92%);
  backdrop-filter: blur(10px);
  padding: 0; /* Remove padding to allow full scrolling area */
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden; /* Hide overflow on main container */
  display: flex;
  flex-direction: column;
}

/* Scrollable content wrapper */
.mega-menu-sections {
  flex: 1;
  overflow-y: auto; /* Enable vertical scrolling */
  overflow-x: hidden;
  padding: 2rem; /* Move padding here */
  position: relative;
}

/* Custom scrollbar for main content */
.mega-menu-sections::-webkit-scrollbar {
  width: 8px;
}

.mega-menu-sections::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.mega-menu-sections::-webkit-scrollbar-thumb {
  background: rgba(96, 165, 250, 0.5);
  border-radius: 4px;
}

.mega-menu-sections::-webkit-scrollbar-thumb:hover {
  background: rgba(96, 165, 250, 0.7);
}

/* Hide all sections by default */
.mega-menu-section {
  display: none;
  min-height: fit-content; /* Allow content to determine height */
}

/* Show first section by default */
.mega-menu-section:first-child {
  display: block;
}

.mega-menu-column {
  min-height: 200px;
}

.mega-menu-section-title {
  color: #60a5fa;
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding: 9px;
  border-bottom: 2px solid rgba(96, 165, 250, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: sticky; /* Make title sticky when scrolling */
  top: 0;
  background: rgba(33, 31, 31, 0.64);
  backdrop-filter: blur(10px);
  z-index: 10;
}

/* Enhanced items layout with better spacing */
.mega-menu-items {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
  padding-bottom: 2rem; /* Add bottom padding for scroll area */
}

/* Alternative: If you prefer columns, use this instead */
.mega-menu-items.column-layout {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.mega-menu-item {
  margin-left: 34px;
  transition: all 0.3s ease;
  border-top: 1px solid rgba(255, 255, 255, 0.89);
  break-inside: avoid; /* Prevent breaking across columns */
}

.mega-menu-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  color: rgba(96, 165, 250, 0.782);
}

.mega-menu-item > a {
  color: white;
  text-decoration: none;
  font-weight: 500;
  display: block;
  font-size: 0.95rem;
}

.mega-menu-item > a:hover {
  color: #60a5fa;
}

.mega-menu-item .item-description {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.85rem;
  margin-top: 0.5rem;
  margin-bottom: 0;
  line-height: 1.4;
}

/* Subitems Container - Enhanced for scrolling */
.mega-menu-subitems {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  max-height: 200px; /* Limit subitem height */
  overflow-y: auto; /* Add scrolling for long sublists */
}

/* Custom scrollbar for subitems */
.mega-menu-subitems::-webkit-scrollbar {
  width: 4px;
}

.mega-menu-subitems::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 2px;
}

.mega-menu-subitems::-webkit-scrollbar-thumb {
  background: rgba(96, 165, 250, 0.3);
  border-radius: 2px;
}

/* Level 3 Subitems */
.mega-menu-subitem {
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0.25rem;
  transition: all 0.3s ease;
  border-left: 2px solid transparent;
}

.mega-menu-subitem:hover {
  background: rgba(255, 255, 255, 0.1);
  border-left-color: #60a5fa;
  transform: translateX(3px);
}

.mega-menu-subitem > a {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 400;
  display: block;
}

.mega-menu-subitem > a:hover {
  color: #93c5fd;
}

.mega-menu-subitem .subitem-description {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.8rem;
  margin-top: 0.25rem;
  margin-bottom: 0;
  line-height: 1.3;
}

/* Level 4+ Deep Subitems */
.mega-menu-deep-subitems {
  margin-top: 0.5rem;
  margin-left: 1rem;
  padding-left: 0.75rem;
  border-left: 2px solid rgba(147, 197, 253, 0.3);
  max-height: 150px; /* Limit deep subitem height */
  overflow-y: auto; /* Add scrolling for deep items */
}

.mega-menu-subitem-level-4 {
  background: rgba(255, 255, 255, 0.03);
  border-left-color: rgba(147, 197, 253, 0.4);
  margin-left: 0.5rem;
}

.mega-menu-subitem-level-4 > a {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.8);
}

.mega-menu-subitem-level-5 {
  background: rgba(255, 255, 255, 0.02);
  border-left-color: rgba(147, 197, 253, 0.3);
  margin-left: 0.25rem;
}

.mega-menu-subitem-level-5 > a {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
}

.mega-menu-subitem-level-6 {
  background: rgba(255, 255, 255, 0.01);
  border-left-color: rgba(147, 197, 253, 0.2);
}

.mega-menu-subitem-level-6 > a {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
}

.mega-menu-subitem-level-7 {
  border-left-color: rgba(147, 197, 253, 0.1);
}

.mega-menu-subitem-level-7 > a {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.5);
}

/* Deep subitems nesting */
.mega-menu-deep-subitems.level-5 {
  margin-left: 0.75rem;
  border-left-color: rgba(147, 197, 253, 0.25);
}

.mega-menu-deep-subitems.level-6 {
  margin-left: 0.5rem;
  border-left-color: rgba(147, 197, 253, 0.2);
}

.mega-menu-deep-subitems.level-7 {
  margin-left: 0.25rem;
  border-left-color: rgba(147, 197, 253, 0.15);
}

/* Scroll indicators */
.mega-menu-sections::before {
  content: "";
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  height: 10px;
  background: linear-gradient(to bottom, rgba(50, 46, 46, 0.8), transparent);
  pointer-events: none;
  z-index: 5;
}

.mega-menu-sections::after {
  content: "";
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  height: 10px;
  background: linear-gradient(to top, rgba(50, 46, 46, 0.8), transparent);
  pointer-events: none;
  z-index: 5;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
  .mega-menu-dropdown {
    width: 95vw;
    min-width: 600px;
  }

  .mega-menu-items {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
}

@media (max-width: 1024px) {
  .mega-menu-content {
    flex-direction: column;
    max-height: 70vh;
  }

  .mega-menu-sidebar {
    flex: none;
    padding: 1rem;
    max-height: 200px; /* Limit sidebar height on tablets */
    overflow-x: auto; /* Allow horizontal scrolling for categories */
    overflow-y: hidden;
    display: flex;
    flex-direction: row;
    gap: 1rem;
    padding-top: 45px !important;
  }

  .mega-menu-category {
    flex-shrink: 0;
    margin-bottom: 0;
  }

  .mega-menu-main {
    padding: 0;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .mega-menu-sections {
    padding: 1rem;
  }

  .mega-menu-items {
    grid-template-columns: 1fr;
  }

  .mega-menu-deep-subitems {
    margin-left: 0.5rem;
  }
}

@media (max-width: 768px) {
  .mega-menu-dropdown {
    width: 98vw;
    min-width: 320px;
    max-height: 60vh;
  }

  .mega-menu-sidebar {
    display: none; /* Hide sidebar on mobile */
  }

  .mega-menu-main {
    padding: 0;
  }

  .mega-menu-sections {
    padding: 1rem;
  }

  .mega-menu-items {
    gap: 0.5rem;
  }

  .mega-menu-deep-subitems {
    margin-left: 0.25rem;
  }

  .mega-menu-subitem-level-4,
  .mega-menu-subitem-level-5,
  .mega-menu-subitem-level-6,
  .mega-menu-subitem-level-7 {
    margin-left: 0;
  }
}

/* Theme Integration Fixes */
.header .mega-menu-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  width: auto;
  transform: translateX(0);
  margin-left: auto;
  margin-right: auto;
}

/* Fix for Bootstrap nav-pills */
.nav-pills .mega-menu-container > ul > li > a {
  background: transparent;
  border: none;
}

.nav-pills .mega-menu-container > ul > li > a:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* Animation improvements */
.mega-menu-dropdown.show .mega-menu-category {
  animation: slideInFromLeft 0.4s ease forwards;
}

.mega-menu-dropdown.show .mega-menu-section.active .mega-menu-column {
  animation: fadeInUp 0.5s ease forwards;
}

.mega-menu-subitem {
  animation: fadeInUp 0.3s ease forwards;
}

.mega-menu-deep-subitems {
  animation: slideInFromLeft 0.2s ease forwards;
}

@keyframes slideInFromLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Smooth scrolling behavior */
.mega-menu-sections,
.mega-menu-sidebar,
.mega-menu-subitems,
.mega-menu-deep-subitems {
  scroll-behavior: smooth;
}

/* Focus styles for accessibility */
.mega-menu-sections:focus,
.mega-menu-sidebar:focus {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}