/**
 * TB Megamenu Custom Styles
 * MSU Engineering Dark Green Theme
 * Based on screenshot design
 */

/* Main Megamenu Container */
.tb-megamenu {
  background-color: #2d5249;
  color: #ffffff;
}

/* Top Navigation Bar */
.tb-megamenu .nav-level-0 {
  background-color: #2d5249;
}

/* Top Level Menu Items */
.tb-megamenu .nav-level-0 > li > a,
.tb-megamenu .nav-level-0 > li > span {
  color: #ffffff !important;
  font-size: 1rem;
  font-weight: 400;
  padding: 1rem 1.25rem;
  text-decoration: none;
  transition: all 0.2s ease;
}

.tb-megamenu .nav-level-0 > li > a:hover,
.tb-megamenu .nav-level-0 > li > span:hover {
  color: #ffffff !important;
  opacity: 0.9;
}

/* Active Menu Item - Green underline */
.tb-megamenu .nav-level-0 > li.active > a,
.tb-megamenu .nav-level-0 > li.active-trail > a {
  position: relative;
}

.tb-megamenu .nav-level-0 > li.active > a::after,
.tb-megamenu .nav-level-0 > li.active-trail > a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 1.25rem;
  right: 1.25rem;
  height: 3px;
  background-color: #5db09d;
}

/* Menu Item Separators (pipes) */
.tb-megamenu .nav-level-0 > li:not(:last-child)::after {
  content: '|';
  color: rgba(255, 255, 255, 0.5);
  padding: 0 0.5rem;
  font-weight: 300;
}

/* Dropdown/Submenu Container */
.tb-megamenu .mega-dropdown-inner,
.tb-megamenu .dropdown-menu {
  background-color: #2d5249;
  border: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
  padding: 2rem 0;
  z-index: 1000;
  position: relative;
}

/* Remove top padding from submenu */
.tbm-submenu {
  padding-top: 0 !important;
  z-index: 1000;
}

/* Column Container */
.tbm-column {
  position: relative;
  padding: 0 2rem;
}

/* Column Inner */
.tbm-column-inner {
  position: relative;
}

/* Column Separators - vertical lines between columns */
.tbm-row .tbm-column:not(:last-child) {
  border-right: 1px solid rgba(255, 255, 255, 0.2);
}

/* Alternative: Using pseudo-element for more control with fade effect */
.tbm-row .tbm-column:not(:last-child)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 1rem;
  bottom: 1rem;
  width: 1px;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(255, 255, 255, 0.2) 10%,
    rgba(255, 255, 255, 0.2) 90%,
    transparent 100%
  );
}

/* Column spacing adjustments */
.tbm-row {
  gap: 0;
  display: flex;
}

/* Ensure columns have equal spacing */
.tbm-column {
  min-width: 250px;
  flex: 1;
}

/* Special sizing for column with featured card */
.tbm-column:has(.storybite-card) {
  min-width: 280px;
  max-width: 350px;
  flex: 0 1 auto;
}

/* Column hover effect - subtle */
.tbm-column:hover {
  background-color: transparent;
}

/* Column title styling if present */
.tbm-column .block-title,
.tbm-column h2,
.tbm-column h3 {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: #ffffff;
  padding-bottom: 0;
  border-bottom: none;
}

/* Submenu Links */
.tbm-column .nav-link,
.tbm-column a,
.tb-megamenu .mega-nav > li > a,
.tb-megamenu .dropdown-menu a {
  padding: 0.625rem 0;
  color: #ffffff !important;
  text-decoration: none;
  display: block;
  transition: all 0.2s ease;
  font-size: 0.9375rem;
  font-weight: 400;
  line-height: 1.5;
}

.tbm-column .nav-link:hover,
.tbm-column a:hover,
.tb-megamenu .mega-nav > li > a:hover,
.tb-megamenu .dropdown-menu a:hover {
  color: #5db09d !important;
  text-decoration: none;
  padding-left: 0.5rem;
}

/* Block content in columns */
.tbm-column .block {
  margin-bottom: 0;
}

/* TB Megamenu Block Container */
.tb-megamenu .tbm-block,
.tb-megamenu .block-inner,
.tb-megamenu .views-element-container {
  width: 100%;
}

/* Remove extra padding/margins from block wrappers */
.tb-megamenu .tbm-block .block-inner {
  padding: 0;
  margin: 0;
}

.tb-megamenu .views-element-container {
  margin: 0;
  padding: 0;
}

.tb-megamenu .storybite-block-view {
  width: 100%;
}

.tb-megamenu .storybite-block-view .view-content {
  width: 100%;
  padding: 0;
  margin: 0;
}

.tb-megamenu .storybite-block-view .views-row {
  width: 100%;
  margin: 0;
  padding: 0;
}

/* Featured Card/StoryBite in Megamenu - Matching Screenshot Design */
.tb-megamenu .storybite-card {
  background-color: transparent !important;
  border: none;
  box-shadow: none;
  border-radius: 0;
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
}

.tb-megamenu .storybite-card:hover {
  background-color: transparent !important;
  box-shadow: none;
  transform: none;
}

/* Image styling in megamenu - handles 500x190 dimensions */
.tb-megamenu .storybite-image {
  background: transparent;
  border-radius: 0;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
  line-height: 0;
}

.tb-megamenu .storybite-image img {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 0;
  object-fit: cover;
}

.tb-megamenu .storybite-card:hover .storybite-image img {
  transform: scale(1.03);
  transition: transform 0.3s ease;
}

/* Content area in megamenu */
.tb-megamenu .storybite-content {
  padding: 1.25rem 0 0 0;
  gap: 0.875rem;
  display: flex;
  flex-direction: column;
  background-color: transparent !important;
}

/* Title styling - light green/teal color with WCAG AA compliance */
.tb-megamenu .storybite-card-title {
  color: #b8e0d7 !important;
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.45;
  margin: 0;
  padding: 0;
}

.tb-megamenu .storybite-card-title a {
  color: #b8e0d7 !important;
  text-decoration: none;
  transition: color 0.2s ease;
}

.tb-megamenu .storybite-card-title a:hover {
  color: #d5f0ea !important;
  text-decoration: none;
}

.tb-megamenu .storybite-card-title a:focus {
  outline: 2px solid #5db09d;
  outline-offset: 2px;
  border-radius: 0;
}

/* Learn More link styling - matching screenshot */
.tb-megamenu .storybite-link {
  margin-top: 0.625rem;
}

.tb-megamenu .storybite-link a {
  color: #5db09d !important;
  font-weight: 600;
  font-size: 0.9375rem;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0;
  text-decoration: none;
  transition: all 0.2s ease;
  position: relative;
}

.tb-megamenu .storybite-link a:hover {
  color: #7cc4b3 !important;
  padding-left: 0;
  text-decoration: none;
}

.tb-megamenu .storybite-link a .visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Hide the external link icon in megamenu */
.tb-megamenu .storybite-link a.external-link::after {
  display: none;
}

/* Add arrow after Learn More text */
.tb-megamenu .storybite-link a::before {
  content: '\2192';
  font-size: 1.125rem;
  margin-left: 0.25rem;
  transition: transform 0.2s ease;
  display: inline-block;
}

.tb-megamenu .storybite-link a:hover::before {
  transform: translateX(4px);
}

/* Remove any accessibility outline that's not from focus */
.tb-megamenu .storybite-link a[style*="outline"] {
  outline: none !important;
}

.tb-megamenu .storybite-link a:focus {
  outline: 2px solid #5db09d !important;
  outline-offset: 2px;
  border-radius: 0;
}

/* Responsive adjustments */
@media (max-width: 991px) {
  .tbm-column {
    padding: 0 1.5rem;
  }

  .tb-megamenu .nav-level-0 > li > a,
  .tb-megamenu .nav-level-0 > li > span {
    padding: 0.875rem 1rem;
    font-size: 0.9375rem;
  }

  .tb-megamenu .nav-level-0 > li:not(:last-child)::after {
    padding: 0 0.25rem;
  }
}

/* ==========================================================================
   Mobile Submenu Toggle Buttons
   ========================================================================== */

/* Mobile menu wrapper - ensure proper display */
.tbm.tbm--mobile {
  position: relative;
  width: 100%;
  overflow: visible;
}

.tbm.tbm--mobile .tbm-submenu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem;
  background-color: #265c50;
  color: #ffffff;
  border: 2px solid #265c50;
  border-radius: 0;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-left: 0.5rem;
  font-size: 1.25rem;
  line-height: 1;
  text-align: center;
}

.tbm.tbm--mobile .tbm-submenu-toggle:hover {
  background-color: #2d7063;
  border-color: #2d7063;
  color: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(38, 92, 80, 0.3);
}

.tbm.tbm--mobile .tbm-submenu-toggle:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(38, 92, 80, 0.2);
}

.tbm.tbm--mobile .tbm-submenu-toggle:focus {
  outline: 3px solid #18453b;
  outline-offset: 2px;
  background-color: #265c50;
  border-color: #265c50;
}

/* Toggle icon styling */
.tbm.tbm--mobile .tbm-submenu-toggle .fa,
.tbm.tbm--mobile .tbm-submenu-toggle .icon {
  color: #ffffff;
  font-size: 1rem;
  line-height: 1;
}

/* Active/Open state */
.tbm.tbm--mobile .tbm-item.open > .tbm-submenu-toggle,
.tbm.tbm--mobile .tbm-submenu-toggle[aria-expanded="true"] {
  background-color: #18453b;
  border-color: #18453b;
  color: #ffffff;
}

.tbm.tbm--mobile .tbm-item.open > .tbm-submenu-toggle:hover,
.tbm.tbm--mobile .tbm-submenu-toggle[aria-expanded="true"]:hover {
  background-color: #0f2b23;
  border-color: #0f2b23;
}

/* Ensure proper spacing for toggle buttons in mobile menu */
.tbm.tbm--mobile .tbm-item {
  display: block;
  width: 100%;
  position: relative;
}

/* Parent menu item with toggle button layout */
.tbm.tbm--mobile .tbm-item.level-1 {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  width: 100%;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
}

.tbm.tbm--mobile .tbm-link-container {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
  position: relative;
  z-index: 2;
}

/* Ensure parent link wrapper is visible */
.tbm.tbm--mobile .tbm-item.level-1 > .tbm-link-container,
.tbm.tbm--mobile .tbm-item.level-1 > a {
  order: 1;
  flex: 1 1 auto;
}

/* Position toggle button inline with parent link */
.tbm.tbm--mobile .tbm-item.level-1 > .tbm-submenu-toggle {
  position: relative;
  margin: 0;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 50px;
  order: 2;
  flex: 0 0 auto;
}

/* Submenu appears below in full width */
.tbm.tbm--mobile .tbm-item.level-1 > .tbm-submenu {
  flex-basis: 100%;
  width: 100%;
  order: 3;
}

/* Mobile menu item styling to accommodate toggle button */
.tbm.tbm--mobile .tbm-nav > li {
  position: relative;
  width: 100%;
}

/* Mobile menu container */
.tbm.tbm--mobile .tbm-nav {
  display: flex;
  flex-direction: column;
  width: 100%;
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

/* Mobile menu parent links - always visible at top */
.tbm.tbm--mobile .tbm-link.level-1 {
  display: block !important;
  visibility: visible !important;
  padding: 1rem 1.5rem !important;
  color: #ffffff !important;
  background-color: transparent !important;
  border: none !important;
  font-size: 1rem;
  font-weight: 500;
  text-decoration: none;
  width: 100%;
  text-align: left;
  transition: background-color 0.2s ease;
  position: relative;
  z-index: 2;
}

.tbm.tbm--mobile .tbm-link.level-1:hover,
.tbm.tbm--mobile .tbm-link.level-1:focus {
  background-color: rgba(93, 176, 157, 0.15) !important;
}

/* Active parent item */
.tbm.tbm--mobile .tbm-item.open > .tbm-link-container > .tbm-link.level-1,
.tbm.tbm--mobile .tbm-item.open > .tbm-link.level-1 {
  background-color: rgba(93, 176, 157, 0.2) !important;
}

/* Mobile submenu positioning - appear below parent with smooth animation */
.tbm.tbm--mobile .tbm-submenu {
  position: relative !important;
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  background-color: #173830 !important;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2) !important;
  z-index: 1 !important;
  padding: 0 !important;
  margin: 0 !important;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.3s ease,
              padding 0.3s ease;
}

/* Show submenu when parent is open - smooth expand down */
.tbm.tbm--mobile .tbm-item.open > .tbm-submenu,
.tbm.tbm--mobile li.open > .tbm-submenu {
  max-height: 2000px;
  opacity: 1;
  padding: 0.5rem 0 !important;
  transition: max-height 0.5s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.4s ease 0.1s,
              padding 0.3s ease;
}

/* Submenu links styling in mobile */
.tbm.tbm--mobile .tbm-submenu .tbm-item {
  width: 100%;
  display: block;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.tbm.tbm--mobile .tbm-submenu .tbm-item:last-child {
  border-bottom: none;
}

.tbm.tbm--mobile .tbm-submenu .tbm-link {
  padding: 0.875rem 1.5rem 0.875rem 3rem !important;
  color: rgba(255, 255, 255, 0.95) !important;
  display: block !important;
  text-decoration: none;
  transition: all 0.2s ease;
  font-size: 0.9375rem;
  font-weight: 400;
  border-left: 3px solid transparent;
  position: relative;
}

/* Submenu link indicator */
.tbm.tbm--mobile .tbm-submenu .tbm-link::before {
  content: '\203A';
  position: absolute;
  left: 1.5rem;
  color: #5db09d;
  font-size: 1.25rem;
  line-height: 1;
  font-weight: 700;
}

.tbm.tbm--mobile .tbm-submenu .tbm-link:hover {
  background-color: rgba(93, 176, 157, 0.15);
  border-left-color: #5db09d;
  color: #ffffff !important;
  padding-left: 3.25rem !important;
}

.tbm.tbm--mobile .tbm-submenu .tbm-link:focus {
  outline: 2px solid #5db09d;
  outline-offset: -2px;
  background-color: rgba(93, 176, 157, 0.1);
}

/* Nested submenu positioning - also below with animation */
.tbm.tbm--mobile .tbm-submenu .tbm-submenu {
  background-color: #0f2b23 !important;
  padding-left: 0;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.3s ease,
              padding 0.3s ease;
}

.tbm.tbm--mobile .tbm-submenu .tbm-item.open > .tbm-submenu {
  max-height: 1500px;
  opacity: 1;
  padding-left: 1rem;
  transition: max-height 0.5s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.4s ease 0.1s,
              padding 0.3s ease;
}

.tbm.tbm--mobile .tbm-submenu .tbm-submenu .tbm-link {
  padding-left: 3.5rem !important;
  font-size: 0.875rem;
}

.tbm.tbm--mobile .tbm-submenu .tbm-submenu .tbm-link:hover {
  padding-left: 3.75rem !important;
}

/* Responsive adjustment for very small screens */
@media (max-width: 375px) {
  .tbm.tbm--mobile .tbm-submenu-toggle {
    min-width: 40px;
    min-height: 40px;
    padding: 0.375rem;
    font-size: 1.125rem;
  }
}

@media (max-width: 767px) {
  /* Stack columns on mobile */
  .tbm-row {
    flex-direction: column;
  }

  /* Mobile menu styling */
  .tb-megamenu .nav-level-0 > li:not(:last-child)::after {
    display: none;
  }

  .tbm-column {
    min-width: 100%;
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  .tbm-column:last-child {
    border-bottom: none;
  }

  .tb-megamenu .mega-dropdown-inner,
  .tb-megamenu .dropdown-menu {
    padding: 1rem 0;
  }

  /* Fix for audience-menu region - ensure full width on mobile */
  .region-audience-menu .tb-megamenu,
  .region-audience-menu .tbm-submenu,
  .region-audience-menu .tbm-submenu .container,
  .region-audience-menu .tbm-row,
  .region-audience-menu .tbm-nav .container {
    width: 100% !important;
    max-width: 100% !important;
    left: 0 !important;
    right: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .region-audience-menu .tbm-submenu .container,
  .region-audience-menu .tbm-nav .container {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .region-audience-menu .tbm-column {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
}

/* Focus states for accessibility */
.tb-megamenu a:focus,
.tbm-column .nav-link:focus {
  outline: 2px solid #5db09d;
  outline-offset: 2px;
  border-radius: 0;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .tb-megamenu *,
  .tbm-column *,
  .tbm-column .nav-link {
    transition: none !important;
  }

  /* Instant expand/collapse for reduced motion */
  .tbm.tbm--mobile .tbm-submenu {
    transition: none !important;
  }

  .tbm.tbm--mobile .tbm-item.open > .tbm-submenu,
  .tbm.tbm--mobile li.open > .tbm-submenu {
    transition: none !important;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .tb-megamenu .nav-level-0 > li > a,
  .tbm-column a {
    text-decoration: underline;
  }

  .tb-megamenu .nav-level-0 > li.active > a::after,
  .tb-megamenu .nav-level-0 > li.active-trail > a::after {
    height: 4px;
  }
}

/* Additional spacing for clean look */
.tb-megamenu .mega-dropdown-inner .container,
.tb-megamenu .dropdown-menu .container {
  max-width: 1400px;
  padding: 0 2rem;
}

/* Ensure proper alignment */
.tb-megamenu .nav-level-0 {
  display: flex;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
}

.tb-megamenu .nav-level-0 > li {
  display: inline-flex;
  align-items: center;
}

/* Menu item list styling */
.tbm-column ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tbm-column li {
  margin: 0;
  padding: 0;
}

/* Prevent unwanted Bootstrap overrides */
.tb-megamenu .dropdown-menu {
  border-radius: 0;
  margin-top: 0;
}

/* Smooth transitions */
.tb-megamenu .mega-dropdown-inner,
.tb-megamenu .dropdown-menu {
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* ============================================
   Intranet Link Styling
   ============================================ */

/* Intranet link - white background with black text */
li.intranet-link .tbm-link,
li.intranet-link > .tbm-link-container > .tbm-link {
  background-color: white !important;
  color: black !important;
  padding: 5px 10px !important;
  border-bottom: 3px solid #00c24e !important;
  border-radius: 0 !important;
}

li.intranet-link .tbm-link:hover,
li.intranet-link .tbm-link:focus,
li.intranet-link > .tbm-link-container > .tbm-link:hover,
li.intranet-link > .tbm-link-container > .tbm-link:focus {
  background-color: white !important;
  color: black !important;
  opacity: 0.8;
  text-decoration: none;
  border-bottom: 3px solid #00c24e !important;
  border-radius: 0 !important;
}

/* ============================================
   MSU Top Menu Specific Styles
   ============================================ */

/* Top menu megamenu container */
.egr-top-msu-menu .tb-megamenu {
  background-color: #2d5249;
}

/* Top menu submenu - remove padding */
.egr-top-msu-menu .tbm-submenu {
  padding: 0 !important;
  z-index: 1000;
}

/* Top menu dropdown */
.egr-top-msu-menu .mega-dropdown-inner,
.egr-top-msu-menu .dropdown-menu {
  background-color: #2d5249;
  padding: 2rem 0;
  z-index: 1000;
}

/* ==========================================================================
   Bootstrap Dropdown Menu Z-Index Fix
   Ensure dropdowns appear above header sections
   ========================================================================== */

/* Dropdown menu containers - CRITICAL Z-INDEX */
.dropdown-menu,
.dropdown-menu.show {
  z-index: 9999 !important;
  position: absolute !important;
}

/* Dropdown parent items - must be high enough */
.nav-item.dropdown,
.dropdown {
  position: relative;
  z-index: auto;
}

/* Specific fix for Engineering dropdown and similar blocks */
#block-egrbs5-engineering-2 .dropdown-menu,
#block-egrbs5-engineering-2 .dropdown-menu.show,
.block-menu .dropdown-menu,
.block-menu .dropdown-menu.show,
.navigation .dropdown-menu,
.navigation .dropdown-menu.show {
  z-index: 9999 !important;
  position: absolute !important;
}

/* Ensure dropdown toggle buttons are clickable */
.dropdown-toggle {
  position: relative;
  z-index: auto;
}

/* Override any conflicting z-index from headers */
#msu-header-top .dropdown-menu,
#msu-header .dropdown-menu,
#dept-header .dropdown-menu,
#top-menu .dropdown-menu,
#msu-header-top .dropdown-menu.show,
#msu-header .dropdown-menu.show,
#dept-header .dropdown-menu.show,
#top-menu .dropdown-menu.show {
  z-index: 9999 !important;
  position: absolute !important;
}

/* Ensure navbar doesn't create stacking context issues */
.navbar,
.navbar-nav,
.nav {
  position: relative;
  z-index: auto;
}
