/**
 * Main Menu element
 *
 * Desktop: mega menu (opens on hover/focus)
 * Mobile (<= 991px): drill-down panels
 *
 * Typography (color, size, weight, etc.) for top level links, mega headings
 * and menu items is controlled via the element's typography controls in the
 * builder. The values below are structural defaults only.
 */

.main-menu {
  --mm-accent: #97c23c; /* Hover/current color */
  --mm-text: #ffffff;
  --mm-gap: 2.5rem; /* Space between top level items */
  --mm-column-gap: 4rem; /* Space between mega columns */

  position: relative;
}

.main-menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.main-menu__toggle,
.main-menu__drill-toggle,
.main-menu__back {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--mm-text);
}

/* ----------------------------------------
 * Top level
 * ---------------------------------------- */
.main-menu__list {
  display: flex;
  align-items: center;
  gap: var(--mm-gap);
}

.main-menu__top-link {
  display: inline-flex;
  align-items: center;
  padding: 1rem 0;
  color: var(--mm-text);
  text-decoration: none;
  transition: color 0.2s ease;
}

.main-menu__top-link:hover,
.main-menu__top-link:focus-visible,
.main-menu__item.is-current > .main-menu__top-link {
  color: var(--mm-accent);
}

/* ----------------------------------------
 * Mega panel (desktop)
 * ---------------------------------------- */
.main-menu__item {
  position: static; /* Mega panel positions against .main-menu */
}

/*
 * Full-bleed panel: on desktop the JS positions the panel Bricks-style
 * via inline left/top/min-width, measured against a horizontal target
 * node (data-mega-menu selector, default: document.body = full width)
 * and a vertical target node (data-mega-menu-vertical selector,
 * default: closest header). It also sets --mm-offset-left (panel left
 * edge -> menu left edge, aligns the columns with the menu) and
 * --mm-pin-gap (menu bottom -> vertical target bottom, sizes the
 * hover bridge).
 */
.main-menu__mega {
  position: absolute;
  background: var(--secondary);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease,
    visibility 0.2s;
  z-index: 100;
}

.main-menu__item--has-mega:hover > .main-menu__mega,
.main-menu__item--has-mega:focus-within > .main-menu__mega {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.main-menu__columns {
  display: flex;
  gap: var(--mm-column-gap);
}

.main-menu__col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 160px;
}

.main-menu__mega-heading {
  display: block;
  color: var(--mm-text);
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 0.5rem;
}

a.main-menu__mega-heading:hover,
a.main-menu__mega-heading:focus-visible {
  color: var(--mm-accent);
}

.main-menu__sub-list {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.main-menu__sub-link {
  color: var(--mm-text);
  text-decoration: none;
  transition: color 0.2s ease;
}

.main-menu__sub-link:hover,
.main-menu__sub-link:focus-visible,
.main-menu__sub-item .is-current > .main-menu__sub-link,
.main-menu__sub-link[aria-current="page"] {
  color: var(--mm-accent);
}

/* Chevron (shared) */
.main-menu__chevron {
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.main-menu__chevron--back {
  transform: rotate(135deg);
  margin-right: 0.5em;
}

/* ----------------------------------------
 * Desktop only
 * ---------------------------------------- */
@media (min-width: 992px) {
  .main-menu__toggle,
  .main-menu__drill-toggle,
  .main-menu__back {
    display: none;
  }

  /* left/top/min-width are set inline by the JS (Bricks-style mega
	 * menu positioning); the values here are no-JS fallbacks only.
	 * Inline padding aligns the columns with the menu's left edge;
	 * content is free to keep flowing right. */
  .main-menu__mega {
    top: calc(100% + var(--mm-pin-gap, 0px));
    left: calc(-1 * var(--mm-offset-left, 0px));
    min-width: 100%;
    padding-block: var(--brxw-space-4xl, 2rem);
    padding-inline: var(--mm-offset-left, 2.5rem);
  }

  /* Invisible hover bridge so the pointer can cross the gap between
	 * the top level link and the panel without closing it */
  .main-menu__mega::before {
    content: "";
    position: absolute;
    bottom: 100%;
    left: 0;
    width: 100%;
    height: calc(var(--mm-pin-gap, 0px) + 8px);
  }

  /* While a mega panel is open, the JS adds .mm-mega-open to the
	 * closest header wrapper so the navy background extends to the
	 * top of the page (matches the design). */
  .mm-has-mega-menu {
    transition: background-color 0.2s ease;
  }

  .mm-mega-open {
    background-color: var(--secondary, #16425b);
  }
}

/* ----------------------------------------
 * Mobile drill-down (<= 991px)
 * ---------------------------------------- */
@media (max-width: 991px) {
  /* Hamburger */
  .main-menu__toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 10px;
  }

  .main-menu__toggle span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--mm-text);
    transition:
      transform 0.2s ease,
      opacity 0.2s ease;
  }

  .main-menu.is-open .main-menu__toggle span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }

  .main-menu.is-open .main-menu__toggle span:nth-child(2) {
    opacity: 0;
  }

  .main-menu.is-open .main-menu__toggle span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  /* Dropdown panel */
  .main-menu__panel {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    min-width: 280px;
    background: var(--secondary);
    overflow: hidden;
    display: none;
    z-index: 100;
  }

  .main-menu.is-open .main-menu__panel {
    display: block;
  }

  .main-menu__list {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0.5rem 0;
    min-height: 50vh;
  }

  .main-menu__item {
    position: static;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }

  .main-menu__top-link {
    flex: 1;
    padding: 0.875rem 1.25rem;
  }

  .main-menu__drill-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
  }

  .main-menu__drill-toggle .main-menu__chevron {
    transform: rotate(-45deg); /* Point right */
  }

  /* Drill panel (reuses the mega panel) */
  .main-menu__mega {
    position: absolute;
    inset: 0;
    width: 100%;
    min-width: 0;
    padding: 0.5rem 0 1.5rem;
    overflow-y: auto;
    opacity: 1;
    visibility: hidden;
    transform: translateX(100%);
    transition:
      transform 0.25s ease,
      visibility 0.25s;
  }

  .main-menu__item.is-drilled > .main-menu__mega {
    visibility: visible;
    transform: translateX(0);
  }

  /* Hover must not open panels on mobile */
  .main-menu__item--has-mega:hover > .main-menu__mega,
  .main-menu__item--has-mega:focus-within > .main-menu__mega {
    opacity: 1;
    visibility: hidden;
    transform: translateX(100%);
  }

  .main-menu__item--has-mega.is-drilled:hover > .main-menu__mega,
  .main-menu__item--has-mega.is-drilled > .main-menu__mega {
    visibility: visible;
    transform: translateX(0);
  }

  .main-menu__back {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.875rem 1.25rem;
    font-weight: 600;
  }

  .main-menu__columns {
    flex-direction: column;
    gap: 1.25rem;
  }

  .main-menu__col {
    gap: 0.75rem;
    padding: 0 1.25rem;
  }

  .main-menu__mega-heading {
    margin-bottom: 0;
    opacity: 0.7;
    font-size: 0.875em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .main-menu__sub-list {
    gap: 0.75rem;
  }
}
