/* Flicker-Free Mega Menu Styles */

/* Animation Keyframes */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes slideInFromRight {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

/* Navbar container - needs to be relative for absolute positioning of shelf */
.navbar {
  position: relative !important;
  z-index: 1000; /* Navbar stays above shelf */
}

/* Ensure navbar maintains full width for absolute positioning */
.navbar .mega-menu-shelf {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  width: 100vw; /* Full viewport width */
  margin-left: calc(-50vw + 50%); /* Center and extend to edges */
  margin-right: calc(-50vw + 50%);
}

/* Single Mega Menu Shelf - Attached to Navbar */
.mega-menu-shelf {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%; /* Attached directly below navbar */
  width: 100vw; /* Full viewport width */
  margin-left: calc(-50vw + 50%); /* Center and extend to viewport edges */
  margin-right: calc(-50vw + 50%);
  background-color: var(--navy-bg, #0a1628);
  color: #ffffff;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  z-index: 9999; /* Above navbar and all content including hero/header */
  max-height: 0;
  overflow: hidden;
  will-change: max-height, opacity;
  
  /* Initial hidden state - prevents flicker */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: max-height 400ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 400ms cubic-bezier(0.4, 0, 0.2, 1),
              visibility 400ms;
}

/* Visible state - shelf expands below navbar */
.mega-menu-shelf:not([hidden]) {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  max-height: 85vh; /* Increased height to prevent cut-off */
  min-height: 500px; /* Minimum height to ensure panels are not cut off */
  height: auto; /* Allow natural height */
  overflow-y: auto; /* Allow scrolling if content exceeds max-height */
}

.mega-menu-shelf-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.5rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  border-radius: 0.25rem;
  transition: background-color 150ms ease;
}

.mega-menu-shelf-close:hover,
.mega-menu-shelf-close:focus {
  background-color: rgba(255, 255, 255, 0.1);
  outline: none;
}

.mega-menu-shelf-close[hidden] {
  display: none;
}

.mega-menu-shelf-content {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0;
}

/* Individual menu panels - only one visible at a time */
.mega-menu-panel {
  display: none;
}

.mega-menu-panel:not([hidden]) {
  display: block;
  animation: fadeInUp 400ms cubic-bezier(0.4, 0, 0.2, 1) 100ms both;
}

/* Legacy .mega-menu class for backward compatibility with template */
.mega-menu {
  position: static;
  background: transparent;
  box-shadow: none;
  max-height: none;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  overflow: visible;
}

/* Menu Content */
.mega-menu-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem 1.5rem; /* Extra bottom padding for watermark and margin */
  animation: fadeInUp 400ms cubic-bezier(0.4, 0, 0.2, 1) 100ms both;
  position: relative;
  min-height: 450px; /* Minimum height to ensure content is visible */
}

/* Menu Title - H1 in TBF Pink */
.mega-menu-title {
  font-size: 2rem;
  font-weight: 600;
  color: var(--tbf-accent, #EF5E91);
  margin-bottom: 2rem;
  line-height: 1.2;
  margin-top: 0;
}

.mega-menu-title-link {
  color: #e91e63;
  text-decoration: none;
  transition: color 0.2s ease;
}

.mega-menu-title-link:hover {
  color: var(--tbf-accent-blue, #00b0ff);
  text-decoration: none;
}

.mega-menu-intro {
  display: none; /* Hidden - replaced by title */
}

/* Category Grid - 3 columns minimum width ~1200px */
.mega-menu-columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2rem;
  position: relative;
  min-width: 1200px; /* Minimum width for 3 columns */
}

/* Category Card */
.mega-menu-category {
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 0.5rem;
  padding: 1.5rem;
  transition: all 200ms ease;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.mega-menu-category:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  background-color: rgba(255, 255, 255, 0.08);
}

/* Category Header - Icon and title on same row */
.category-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-direction: row; /* Icon and title on same row */
}

.category-icon {
  font-size: 1.5rem; /* Slightly smaller to fit on same row */
  line-height: 1;
  transition: transform 200ms ease;
  flex-shrink: 0;
}

.mega-menu-category:hover .category-icon {
  transform: scale(1.1);
}

.category-header.accent-primary .category-icon {
  color: var(--tbf-accent-blue, #00b0ff);
}

.category-header.accent-secondary .category-icon {
  color: var(--tbf-accent-pink, #e91e63);
}

.category-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
  color: #ffffff;
  line-height: 1.3;
  flex: 1; /* Take remaining space */
}

.category-description {
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.7);
  margin: 0.5rem 0 0 0;
  line-height: 1.4;
}

/* Category Links */
.category-links {
  list-style: none;
  padding: 0;
  margin: 0;
}

.category-links li {
  margin-bottom: 0.5rem;
}

.category-link {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 0.25rem;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.9);
  transition: all 150ms ease;
  cursor: pointer;
}

.category-link:hover,
.category-link:focus {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--tbf-accent-blue, #00b0ff);
  outline: none;
}

.category-link:focus-visible {
  outline: 2px solid var(--tbf-accent-blue, #00b0ff);
  outline-offset: 2px;
}

.link-title {
  display: block;
  font-weight: 500;
  font-size: 0.9375rem;
}

.link-description {
  display: block;
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 0.25rem;
  line-height: 1.4;
}

/* Watermark - Single instance at bottom right of menu shelf container */
.mega-menu-shelf {
  position: relative; /* Ensure watermark is positioned relative to shelf */
}

.mega-menu-watermark {
  position: absolute;
  bottom: calc(1rem + 120px - 400px); /* Moved up 400px */
  right: 1rem;
  width: 36rem; /* Expanded by 200%: 12rem * 3 = 36rem */
  height: 36rem; /* Expanded by 200%: 12rem * 3 = 36rem */
  opacity: 0.1;
  pointer-events: none;
  animation: fadeInUp 300ms ease-out 300ms both;
  z-index: 0;
}

/* Watermark positioning for mobile - anchored to shelf base */
@media (max-width: 1199px) {
  .mega-menu-watermark {
    position: absolute;
    bottom: calc(1rem + 120px - 400px); /* Moved up 400px */
    right: 1rem;
    width: 30rem; /* Expanded by 200%: 10rem * 3 = 30rem */
    height: 30rem; /* Expanded by 200%: 10rem * 3 = 30rem */
  }
}

.mega-menu-watermark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: 0.1;
}

/* Overlay - Only for mobile drawer, not desktop */
.mega-menu-overlay {
  display: none; /* Hidden on desktop - nav remains active */
}

@media (max-width: 768px) {
  .mega-menu-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1049; /* Below drawer but above content */
    opacity: 0;
    visibility: hidden;
    transition: opacity 300ms ease-out, visibility 300ms ease-out;
  }

  .mega-menu-overlay:not([hidden]) {
    opacity: 1;
    visibility: visible;
  }
}

/* Hamburger Button */
.nav-hamburger {
  display: none;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.82);
  font-size: 1.5rem;
  padding: 0.5rem;
  cursor: pointer;
  transition: color 0.2s ease;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
}

.nav-hamburger:hover,
.nav-hamburger:focus {
  color: var(--tbf-accent-pink, #e91e63);
  outline: none;
}

.nav-hamburger:focus-visible {
  outline: 2px solid var(--tbf-accent-blue, #00b0ff);
  outline-offset: 2px;
}

/* Nav Trigger with Toggle Arrow */
.nav-trigger {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: color 0.2s ease;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-trigger-text {
  display: inline-block;
  transition: color 0.2s ease;
}

/* Nav Trigger Chevron - rotates on expand */
.nav-chevron {
  font-size: 0.75rem;
  transition: transform 300ms ease, color 0.2s ease;
  display: inline-block;
  line-height: 1;
  transform: rotate(0deg); /* Default: pointing right (>) */
  color: inherit;
}

/* When menu is open, rotate chevron to point down (↓) */
.nav-trigger[aria-expanded="true"] .nav-chevron {
  transform: rotate(90deg); /* Rotate right arrow 90° to point down */
}

/* Pulsing TBF Pink Arrow for Mega Menu Titles */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(1.15);
  }
}

.mega-menu-arrow-pulse {
  display: inline-block;
  margin-left: 0.75rem;
  vertical-align: middle;
  font-size: 1.875rem; /* 30px - same height as previous arrow animation */
  font-weight: 700;
  line-height: 1;
  color: var(--tbf-accent-pink, #EF5E91);
  animation: pulse 1.5s ease-in-out infinite;
}

.nav-trigger-icon {
  font-size: 0.875rem;
  transition: transform 300ms ease;
  display: inline-block;
  line-height: 1;
}

.nav-trigger[aria-expanded="true"] .nav-trigger-icon {
  transform: rotate(180deg);
}

.nav-trigger:hover,
.nav-trigger:focus {
  color: var(--tbf-accent-pink, #e91e63);
  outline: none;
  text-decoration: none;
}

.nav-trigger:hover .nav-trigger-text,
.nav-trigger:hover .nav-chevron,
.nav-trigger:focus .nav-trigger-text,
.nav-trigger:focus .nav-chevron {
  color: var(--tbf-accent-pink, #e91e63);
}

/* Active nav trigger - highlighted in pink */
.nav-trigger[aria-expanded="true"] {
  color: var(--tbf-accent-pink, #EF5E91);
}

.nav-trigger[aria-expanded="true"] .nav-trigger-text,
.nav-trigger[aria-expanded="true"] .nav-chevron {
  color: var(--tbf-accent-pink, #EF5E91) !important;
}

.nav-trigger:focus-visible {
  outline: 2px solid var(--tbf-accent-blue, #00b0ff);
  outline-offset: 2px;
}

/* Prevent nav items from wrapping - switch to mobile if they would */
.primary-nav {
  display: flex;
  flex-wrap: nowrap; /* Prevent wrapping */
  white-space: nowrap;
}

.primary-nav > .nav-item {
  flex-shrink: 0; /* Prevent items from shrinking */
  white-space: nowrap;
}

/* Desktop menu only - hide on mobile */
@media (max-width: 1199px) {
  /* Switch to mobile burger menu when 3 columns won't fit */
  .nav-hamburger {
    display: flex;
  }
  
  .primary-nav > .nav-item.has-megamenu {
    display: none;
  }
  
  /* Hide CTA in navbar on mobile - it's in mobile menu header */
  .nav-item.nav-cta {
    display: none !important;
  }
  
  /* Hide desktop menu on mobile - mobile accordion menu handles this */
  .mega-menu-shelf {
    display: none !important;
  }
}

/* Desktop menu styles - only for >=1200px */
@media (min-width: 1200px) {
  .mega-menu-shelf {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    width: 100%;
    max-width: 100%;
    transform: none;
    transition: max-height 400ms cubic-bezier(0.4, 0, 0.2, 1),
                opacity 400ms cubic-bezier(0.4, 0, 0.2, 1),
                visibility 400ms;
  }
  
  .mega-menu-shelf:not([hidden]) {
    transform: none;
  }
  
  /* Hide mobile menu on desktop */
  .mobile-accordion-menu {
    display: none !important;
  }
}

/* Tablet Styles (768px - 1024px) - removed, using content-based breakpoint */
  
  .mega-menu-watermark {
    width: 12rem;
    height: 12rem;
    bottom: calc(1rem + 120px - 400px); /* Moved up 400px to match desktop */
  }
}

/* Mobile Menu Container */

/* Mobile/Tablet Styles (<1200px) - Accordion layout */
@media (max-width: 1199px) {
  .mega-menu-shelf-content {
    height: 100%;
    overflow-y: auto;
    padding: 0;
    padding-top: 5.5rem; /* Space for extended header */
  }
  
  /* Mobile header with close button */
  .mega-menu-shelf-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 5.5rem; /* Extended height so accordion titles sit below close button */
    background-color: var(--navy-bg, #0a1628);
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 1rem 1.5rem;
    padding-top: 1rem;
    z-index: 10;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .mega-menu-shelf-header-title {
    display: none; /* Removed "Menu" text */
  }
  
  .mega-menu-content {
    padding: 1.5rem;
    padding-top: 0.5rem; /* Reduced top padding */
  }
  
  /* Hide menu title on mobile - use accordion headers instead */
  .mega-menu-title {
    display: none;
  }
  
  /* Primary nav item as accordion header on mobile */
  .mega-menu-panel {
    margin-bottom: 0;
    position: relative;
  }
  
  .mobile-panel-header {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--tbf-accent, #EF5E91);
    padding: 1rem 1.5rem;
    padding-top: 0.5rem; /* Reduced top padding to sit closer to header */
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 0;
    margin-top: 0;
    cursor: pointer;
    position: relative;
    padding-right: 3rem; /* Space for chevron */
  }
  
  .mobile-panel-chevron {
    position: absolute;
    right: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    transition: transform 300ms ease;
    pointer-events: none;
  }
  
  .mega-menu-panel.is-expanded .mobile-panel-chevron {
    transform: translateY(-50%) rotate(180deg);
  }
  
  /* Hide panel content when collapsed - ensure initial state */
  .mega-menu-panel .mega-menu-content {
    transition: max-height 300ms ease;
  }
  
  .mega-menu-panel:not(.is-expanded) .mega-menu-content {
    max-height: 0 !important;
    overflow: hidden !important;
    display: block; /* Keep in flow but collapsed */
  }
  
  .mega-menu-panel.is-expanded .mega-menu-content {
    max-height: 5000px; /* Large enough for content */
    overflow: visible;
  }
  
  /* Accordion categories */
  .mega-menu-category {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0;
    padding: 1rem;
    margin: 0;
  }
  
  .category-header {
    cursor: pointer;
    padding: 0;
    margin-bottom: 0;
    border-bottom: none;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  
  /* Hide category icons on mobile for cleaner look */
  .mega-menu-category .category-header .category-icon,
  .mega-menu-category .category-icon {
    display: none !important;
    visibility: hidden !important;
  }
  
  /* Hide link descriptions on mobile - only show link titles */
  .mega-menu-category .category-link .link-description,
  .category-link .link-description,
  .link-description {
    display: none !important;
    visibility: hidden !important;
  }
  
  /* Hide category descriptions on mobile */
  .mega-menu-category .category-description,
  .category-description {
    display: none !important;
    visibility: hidden !important;
  }
  
  .category-header::after {
    content: '▼';
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    transition: transform 300ms ease;
  }
  
  .mega-menu-category.is-expanded .category-header::after {
    transform: rotate(180deg);
  }
  
  /* Category links - ensure initial collapsed state */
  .mega-menu-category .category-links {
    transition: max-height 300ms ease, padding-top 300ms ease;
  }
  
  .mega-menu-category:not(.is-expanded) .category-links {
    max-height: 0 !important;
    overflow: hidden !important;
    padding: 0 !important;
  }
  
  .mega-menu-category.is-expanded .category-links {
    max-height: 2000px;
    padding-top: 1rem;
  }
  
  .category-link {
    padding: 0.75rem 0;
    min-height: 44px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  
  /* Show watermark on mobile - fixed to base of menu container */
  .mega-menu-watermark {
    display: block;
    position: absolute;
    bottom: calc(1rem - 280px); /* Moved up 400px from original 1rem position */
    right: 1rem;
    width: 10rem;
    height: 10rem;
    opacity: 0.1;
    pointer-events: none;
    z-index: 0;
  }
  
  .mega-menu-intro {
    font-size: 1rem;
    margin-bottom: 1.5rem;
  }
  
  .category-icon {
    font-size: 1.75rem;
  }
  
  .category-header h3 {
    font-size: 1rem;
  }
}

/* Desktop click states - shelf expands (≥1200px) */
@media (min-width: 1200px) {
  .mega-menu-shelf:not([hidden]) {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    max-height: 85vh;
  }
}

