/* =================================================================
   MEGA MENU NAVIGATION SYSTEM - Phase 3
   ================================================================= */

/* ================================================================
   BASE NAVIGATION ENHANCEMENTS
   ================================================================ */

.site-nav {
  position: relative;
  z-index: 1000;
  transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Sticky header enhancement (optional, can be enabled via JS) */
.site-nav.sticky {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ================================================================
   MEGA MENU STRUCTURE
   ================================================================ */

.mega-menu-wrapper {
  position: relative;
}

/* Hide default Materialize dropdown for mega menu items */
.mega-menu-wrapper .dropdown-content {
  display: none !important;
}

/* Mega menu container */
.mega-menu {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  padding: 32px;
  min-width: 600px;
  max-width: 800px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
  pointer-events: none;
  margin-top: 8px;
  z-index: 999;
}

/* Show mega menu on hover */
.mega-menu-wrapper:hover .mega-menu,
.mega-menu-wrapper:focus-within .mega-menu {
  opacity: 1;
  visibility: visible;
  pointer-events: all;
  margin-top: 0;
}

/* Mega menu arrow indicator */
.mega-menu::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid var(--bg-card);
  filter: drop-shadow(0 -2px 2px rgba(0,0,0,0.05));
}

/* ================================================================
   MEGA MENU GRID LAYOUTS
   ================================================================ */

.mega-menu-grid {
  display: grid;
  gap: 20px;
}

/* 2-column layout for services */
.mega-menu-grid.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

/* 1-column layout for simple lists */
.mega-menu-grid.cols-1 {
  grid-template-columns: 1fr;
}

/* 3-column for resources */
.mega-menu-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

/* ================================================================
   MEGA MENU ITEMS
   ================================================================ */

.mega-menu-item {
  display: block;
  padding: 16px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid transparent;
  transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
  text-decoration: none;
  color: var(--text-primary);
}

.mega-menu-item:hover,
.mega-menu-item:focus {
  background: var(--bg-body);
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  text-decoration: none;
  color: var(--text-primary);
}

/* Icon + content layout */
.mega-menu-item-content {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.mega-menu-item-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--color-primary-alpha-20);
  color: var(--color-primary);
  font-size: 24px;
}

.mega-menu-item-text {
  flex: 1;
}

.mega-menu-item-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 4px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.mega-menu-item-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.4;
}

/* ================================================================
   MEGA MENU SECTIONS
   ================================================================ */

.mega-menu-section {
  margin-bottom: 24px;
}

.mega-menu-section:last-child {
  margin-bottom: 0;
}

.mega-menu-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin: 0 0 12px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

/* ================================================================
   SIMPLE DROPDOWN ITEMS (for non-mega menus)
   ================================================================ */

.mega-menu-simple {
  min-width: 220px;
  max-width: 280px;
  padding: 12px 0;
}

.mega-menu-simple .mega-menu-item {
  padding: 10px 20px;
  background: transparent;
  border-radius: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.mega-menu-simple .mega-menu-item:hover,
.mega-menu-simple .mega-menu-item:focus {
  background: var(--bg-elevated);
  transform: none;
  box-shadow: none;
  padding-left: 24px;
}

.mega-menu-simple .mega-menu-item-icon {
  width: 24px;
  height: 24px;
  font-size: 18px;
  background: transparent;
}

.mega-menu-simple .mega-menu-item-title {
  font-size: 0.95rem;
  font-weight: 500;
}

/* ================================================================
   MEGA MENU CTA SECTION
   ================================================================ */

.mega-menu-cta {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.mega-menu-cta .btn {
  margin: 0;
}

.mega-menu-cta .btn-small {
  padding: 0 16px;
  height: 36px;
  line-height: 36px;
  font-size: 0.875rem;
}

/* ================================================================
   MOBILE MEGA MENU (Sidenav enhancements)
   ================================================================ */

@media only screen and (max-width: 992px) {
  /* Hide desktop mega menu */
  .mega-menu {
    display: none;
  }

  /* Enhanced mobile menu */
  .sidenav {
    padding-top: 16px;
  }

  .sidenav-category {
    padding: 16px 32px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: var(--bg-elevated);
  }

  .sidenav-category-items {
    background: var(--bg-card);
  }

  .sidenav-category-items li a {
    padding-left: 48px;
    font-size: 0.95rem;
  }

  .sidenav-category-items li a i.material-icons {
    margin-right: 12px;
    font-size: 20px;
    color: var(--color-primary);
  }
}

/* ================================================================
   ACCESSIBILITY
   ================================================================ */

/* Focus visible for keyboard navigation */
.mega-menu-wrapper > a:focus,
.mega-menu-item:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Keyboard navigation support */
.mega-menu-wrapper > a:focus + .mega-menu,
.mega-menu:focus-within {
  opacity: 1;
  visibility: visible;
  pointer-events: all;
  margin-top: 0;
}

/* ================================================================
   REDUCED MOTION
   ================================================================ */

@media (prefers-reduced-motion: reduce) {
  .mega-menu,
  .mega-menu-item,
  .site-nav {
    transition: none;
  }

  .mega-menu-item:hover,
  .mega-menu-item:focus {
    transform: none;
  }
}

/* ================================================================
   DARK MODE ADJUSTMENTS
   ================================================================ */

[data-theme="dark"] .mega-menu {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .mega-menu::before {
  filter: drop-shadow(0 -2px 2px rgba(0,0,0,0.3));
}

[data-theme="dark"] .mega-menu-item:hover,
[data-theme="dark"] .mega-menu-item:focus {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* ================================================================
   TABLET RESPONSIVENESS
   ================================================================ */

@media only screen and (max-width: 1200px) {
  .mega-menu {
    min-width: 500px;
    max-width: 600px;
    padding: 24px;
  }

  .mega-menu-grid.cols-2 {
    gap: 16px;
  }

  .mega-menu-item {
    padding: 12px;
  }
}

@media only screen and (max-width: 992px) {
  .mega-menu-grid.cols-3 {
    grid-template-columns: 1fr;
  }
}

/* ================================================================
   LOADING STATE (for dynamic content)
   ================================================================ */

.mega-menu-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-secondary);
}

.mega-menu-loading i {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ================================================================
   BADGE/LABEL SUPPORT
   ================================================================ */

.mega-menu-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  border-radius: 12px;
  background: var(--color-accent);
  color: white;
  margin-left: 8px;
  letter-spacing: 0.3px;
}

.mega-menu-badge.new {
  background: #4CAF50;
}

.mega-menu-badge.popular {
  background: #FF9800;
}

.mega-menu-badge.beta {
  background: var(--color-primary);
}

/* ================================================================
   HOVER DELAY (prevent accidental opens)
   ================================================================ */

.mega-menu-wrapper {
  /* Small delay before showing to prevent accidental triggers */
  transition: all 0.1s ease;
}

.mega-menu {
  /* Delay the visibility to match hover intent */
  transition-delay: 0.1s;
}

.mega-menu-wrapper:not(:hover) .mega-menu {
  transition-delay: 0s;
}
