/* Mega Menu Styles */
.has-mega-menu {
  position: relative !important;
  /* Changed from static to relative for pseudo-element positioning */
  /* If static is needed for full-width menu, we might need a different approach, but let's try this. */
  /* Wait, if I change this to relative, 'left: 0' on child absolute might be relative to THIS LI, not the page/header. */
  /* The previous CSS had: position: static !important; */
  /* If I keep static, the ::after will be relative to the nearest positioned ancestor (likely nav or header). */
  /* Let's try keeping static but making the bridge on the child or finding another way. */
  /* Actually, the best way for full-width is: Parent static, Menu absolute left:0 right:0 of window/header. */
  /* BUT the bridge needs to be attached to the LI. */
  /* Solution: Make LI static, but put the bridge on the anchor or make bridge relative to LI? */
  /* If LI is static, ::after with absolute position will position relative to HEADER (which is relative/fixed). */
  /* That's actually fine as long as "top: 100%" lines up or we use explicit pixels. */
  /* Let's Try: */
  position: static !important;
}

/* Invisible Bridge */
.has-mega-menu>a::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  height: 30px;
  /* Bridge height */
  background: transparent;
  z-index: 1001;
  /* Above other things */
}

.mega-menu-container {
  display: block;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 0 auto; /* Center it */
  max-width: var(--max-width, 1280px); /* Constrain width */
  background: #fff;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.08); /* Light drop shadow to separate white menu from content */
  z-index: 1000;
  border-top: 3px solid var(--primary-color);
  direction: ltr;
  /* Default LTR, overridden by HTML dir attribute handling */
  width: 100%;
  max-height: clamp(480px, 58vh, 650px);
  overflow: hidden;
  border-radius: 0; /* Sharp, flat corners per video frames */

  /* Hinged at top edge, swings downward from backward X-axis rotation */
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform-origin: top center; /* Hinge point */
  transform: perspective(1200px) rotateX(-12deg) translateY(-5px);
  transition: 
    transform 0.45s cubic-bezier(0.16, 1, 0.3, 1), 
    opacity 0.45s cubic-bezier(0.16, 1, 0.3, 1), 
    visibility 0.45s;
  transition-delay: 0.15s; /* Delay closing for hover intent */
  will-change: transform, opacity;
  backface-visibility: hidden;
}

/* Hover state - CSS Fallback */
.has-mega-menu:hover .mega-menu-container {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: perspective(1200px) rotateX(0deg) translateY(0);
  transition-delay: 0s;
}

/* JS-Controlled Active States */
.mega-menu-container.menu-visible {
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  transform: perspective(1200px) rotateX(0deg) translateY(0) !important;
  transition-delay: 0s !important;
}

.has-mega-menu.menu-active > a {
  color: var(--primary-color) !important;
}

[dir="rtl"] .mega-menu-container {
  direction: rtl;
}

.mega-menu-wrapper {
  display: flex;
  height: clamp(480px, 58vh, 650px);
  min-height: 0;
  max-width: 1400px; /* Wider container */
  width: 95%; /* Responsive width */
  margin: 0 auto;
  overflow: hidden;
}

/* Sections Sidebar */
.mega-menu-sidebar {
  width: 380px; /* Wider sidebar */
  background: #f8f9fa;
  border-right: 1px solid #eee;
  flex-shrink: 0;
  overflow-y: auto;
  height: 100%;
  max-height: none;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(200, 139, 43, 0.55) transparent;
}

.mega-menu-sidebar::-webkit-scrollbar {
  width: 5px;
}

.mega-menu-sidebar::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(200, 139, 43, 0.5);
}

[dir="rtl"] .mega-menu-sidebar {
  border-right: none;
  border-left: 1px solid #eee;
}

.sections-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.section-item {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  border-bottom: 1px solid #eee;
  font-weight: 600;
  color: #333;
  text-decoration: none;
  justify-content: space-between;
}

.section-item:hover,
.section-item.active {
  background: #fff;
  color: var(--primary-color);
  border-left: 4px solid var(--primary-color);
  padding-left: 16px;
  /* Adjust for border */
}

[dir="rtl"] .section-item:hover,
[dir="rtl"] .section-item.active {
  border-left: none;
  border-right: 4px solid var(--primary-color);
  padding-right: 16px;
  padding-left: 20px;
}

.section-item i {
  margin-right: 10px;
  width: 20px;
  text-align: center;
}

[dir="rtl"] .section-item i {
  margin-right: 0;
  margin-left: 10px;
}

/* Content Area */
.mega-menu-content {
  flex-grow: 1;
  padding: 30px 40px; /* More padding */
  background: #fff;
  overflow-y: auto;
  height: 100%;
  max-height: none;
  overscroll-behavior: contain;
}

.branches-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  /* 3 columns for branches since we expanded the width */
  gap: 20px;
}

.branch-card {
  display: flex;
  align-items: center;
  padding: 15px;
  background: #f9f9f9;
  border-radius: 8px;
  transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none;
  color: #555;
  border: 1px solid transparent;
}

.branch-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
  border-color: #eee;
  background: #fff;
  color: var(--primary-color);
}

.branch-icon {
  font-size: 1.2rem;
  margin-right: 15px;
  color: var(--secondary-color);
}

[dir="rtl"] .branch-icon {
  margin-right: 0;
  margin-left: 15px;
}

.branch-title {
  font-weight: 600;
  font-size: 0.95rem;
}

/* Animations */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Show Menu on Hover */
/* Show Menu on Hover - Handled above with transitions */
/* .has-mega-menu:hover .mega-menu-container {
  display: block;
} */

/* Responsive adjustments */
@media (max-width: 991px) {
  .mega-menu-container {
    display: none;
    position: static;
    visibility: visible;
    opacity: 1;
    animation: none;
    box-shadow: none;
    border-top: none;
    padding: 0;
    max-height: none;
    overflow: visible;
  }

  .has-mega.open .mega-menu-container,
  .has-mega-menu.open .mega-menu-container {
    display: block;
    animation: slideDown 0.3s ease-out;
  }

  .mega-menu-wrapper {
    flex-direction: column;
    height: auto;
    min-height: auto;
    overflow: visible;
  }

  .mega-menu-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #eee;
    height: auto;
    max-height: none;
  }

  .mega-menu-content {
    padding: 10px;
  }

  .branches-grid {
    grid-template-columns: 1fr;
  }
}
.branch-card:hover .branch-icon-container { transform: scale(1.1); }

/* Mega Menu Icons Color - Matches Accent Color */
.section-item i,
.mega-menu-sidebar ul li a i {
    color: var(--accent-color, #f59e0b) !important;
}
