/* ==========================================================================
   Mega Menu Component
   Lower Murray Water — Self-contained, no build step required.
   Modern CSS: custom properties, native nesting, container queries.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design Tokens
   -------------------------------------------------------------------------- */

.megamenu {
  --mm-bg: #ffffff;
  --mm-bg-hover: #f5f7fa;
  --mm-text: #1a1a1a;
  --mm-text-secondary: #6c757d;
  --mm-text-hover: #0033a0;
  --mm-border: #e5e8ed;
  --mm-heading-border: #0033a0;

  --mm-panel-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  --mm-panel-max-width: 1320px;

  --mm-column-gap: 2rem;
  --mm-column-min-width: 200px;
  --mm-column-max-width: 280px;

  --mm-transition-duration: 0.2s;
  --mm-transition-easing: ease-in-out;

  --mm-z-index: 1000;
}

/* --------------------------------------------------------------------------
   1b. Header overrides — logo + container width
   -------------------------------------------------------------------------- */

@media (min-width: 1024px) {
  .navbar-brand,
  .navbar-brand img {
    flex-grow: 0;
    max-width: unset;
    margin: 0 !important;
  }

  .navbar-brand {
    padding-inline-end: 1em;
  }

  .header .container {
    max-width: 1352px !important;
  }

}

/* WordPress admin bar offset */
body.customize-support .header,
body.customize-support .header {
  top: 32px;

  @media (max-width: 782px) {
    top: 46px;
  }
}

.megamenu__nav-wrapper {
  width: 100%;
}

/* --------------------------------------------------------------------------
   2. Container — two-row layout on desktop
   -------------------------------------------------------------------------- */

.megamenu {
  display: flex;
  flex-grow: 1;
  position: static;

  /* Mobile: single column with hamburger right-aligned */
  align-items: center;

  /* Desktop: stack utility row on top, primary nav row below.
     stretch lets the nav row use the full width (space after the logo) */
  @media (min-width: 992px) {
    flex-direction: column;
    align-items: stretch;
  }

  li {
    display: flex;
    align-items: center;
  }
}

/* --------------------------------------------------------------------------
   2b. Desktop utility bar — keep right-aligned
   -------------------------------------------------------------------------- */

.megamenu > .top-nav {
  @media (min-width: 992px) {
    justify-content: flex-end;
  }
}

/* --------------------------------------------------------------------------
   3. Top-level nav list (desktop)
   -------------------------------------------------------------------------- */

.megamenu__nav {
  display: none;
  list-style: none;
  margin: 0;
  padding: 0;

  @media (min-width: 992px) {
    display: flex;
    align-items: stretch;
    justify-content: space-evenly;
    gap: 0.5em;
  }
}

.megamenu__item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;

  /* Desktop: positioned so panel aligns to this item */
  @media (min-width: 992px) {
    position: relative;
  }
}

/* --------------------------------------------------------------------------
   4. Top-level trigger link
   -------------------------------------------------------------------------- */

.megamenu__trigger {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 1rem clamp(0.375rem, 0.25vw + 0.25rem, 0.875rem);
  color: var(--mm-text);
  text-decoration: none;
  font-weight: 500;
  font-size: clamp(0.75rem, 0.5vw + 0.45rem, 0.9375rem);
  white-space: nowrap;
  transition: color var(--mm-transition-duration) var(--mm-transition-easing);
  border-bottom: 3px solid transparent;
  line-height: 1.4;

  &:hover,
  &:focus-visible {
    color: var(--mm-text-hover);
  }

  &[aria-expanded="true"] {
    color: var(--mm-text-hover);
    border-bottom-color: var(--mm-heading-border);
  }
}

/* --------------------------------------------------------------------------
   5. Chevron icon
   -------------------------------------------------------------------------- */

.megamenu__chevron {
  width: 10px;
  height: auto;
  flex-shrink: 0;
  transition: transform var(--mm-transition-duration) var(--mm-transition-easing);

  [aria-expanded="true"] > & {
    transform: rotate(180deg);
  }

  @media (max-width: 991.98px) {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   6. Desktop dropdown panel
   -------------------------------------------------------------------------- */

.megamenu__panel {
  display: none;
  position: absolute;
  top: 100%;
  background: var(--mm-bg);
  border-top: 1px solid var(--mm-border);
  box-shadow: var(--mm-panel-shadow);
  z-index: var(--mm-z-index);

  /* Auto-width, centered under trigger — JS handles viewport clamping */
  width: max-content;
  left: 50%;
  transform: translateX(-50%);

  &.is-active {
    display: block;
  }
}

.megamenu__panel-inner {
  padding: 2rem;
}

/* --------------------------------------------------------------------------
   7. Columns — flex layout for content-driven width
   -------------------------------------------------------------------------- */

.megamenu__columns {
  display: flex;
  gap: 1.5rem var(--mm-column-gap);
}

.megamenu__column {
  min-width: var(--mm-column-min-width);
  max-width: var(--mm-column-max-width);
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   8. Column heading (level 2) & links (level 3)
   -------------------------------------------------------------------------- */

.megamenu__heading {
  display: block;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
  font-weight: 700;
  font-size: 0.9375rem;
  white-space: nowrap;
  color: var(--mm-text);
  text-decoration: none;
  border-bottom: 2px solid var(--mm-heading-border);
  line-height: 1.4;

  &:hover,
  &:focus-visible {
    color: var(--mm-text-hover);
  }
}

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

.megamenu__link {
  display: block;
  padding: 0.375rem 0;
  color: var(--mm-text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.5;
  transition:
    color var(--mm-transition-duration) var(--mm-transition-easing);

  &:hover,
  &:focus-visible {
    color: var(--mm-text-hover);
  }
}

/* --------------------------------------------------------------------------
   9. Backdrop overlay (desktop)
   -------------------------------------------------------------------------- */

.megamenu__backdrop {
  position: fixed;
  top: 0; /* JS sets this to header height on desktop so it doesn't cover nav triggers */
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.3s ease-in-out,
    visibility 0.3s ease-in-out;

  &.is-active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
}

/* --------------------------------------------------------------------------
   10. Mobile: hamburger button
   -------------------------------------------------------------------------- */

.megamenu__hamburger {
  /* Inherits Bootstrap .navbar-toggler styles for the icon */
  margin: 0 0.51rem 0 auto;

  @media (min-width: 992px) {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   11. Mobile: container (the slide-in menu)
   -------------------------------------------------------------------------- */

.megamenu__container {
  @media (max-width: 991.98px) {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--mm-bg);
    z-index: var(--mm-z-index);
    padding: 1rem 1.25rem;

    &.is-open {
      display: flex;
      flex-direction: column;
    }
  }

  @media (min-width: 992px) {
    display: flex;
    align-items: center;
    width: 100%;
  }
}

/* --------------------------------------------------------------------------
   12. Mobile: nav list layout
   -------------------------------------------------------------------------- */

@media (max-width: 991.98px) {
  .megamenu__nav {
    display: block;
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .megamenu__item {
    border-bottom: 1px solid var(--mm-border);
  }

  .megamenu__trigger {
    flex: 1;
    padding: 0.875rem 0;
    border-bottom: none;
    font-size: 1rem;
  }
}

/* --------------------------------------------------------------------------
   13. Mobile: accordion toggle button
   -------------------------------------------------------------------------- */

.megamenu__toggle {
  appearance: none;
  background: none;
  border: none;
  padding: 0.875rem 0.5rem;
  cursor: pointer;
  color: var(--mm-text);
  display: flex;
  align-items: center;
  justify-content: center;

  @media (min-width: 992px) {
    display: none;
  }

  & svg {
    transition: transform var(--mm-transition-duration) var(--mm-transition-easing);
  }

  &[aria-expanded="true"] svg {
    transform: rotate(180deg);
  }
}

/* --------------------------------------------------------------------------
   14. Mobile: accordion panel behaviour
   -------------------------------------------------------------------------- */

@media (max-width: 991.98px) {
  .megamenu__panel {
    position: static;
    width: 100%;
    left: auto;
    transform: none;
    box-shadow: none;
    border-top: none;
    background: var(--mm-bg);
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease-in-out;

    /* Override: on mobile, display is controlled by max-height, not display:none */
    display: block;

    &.is-active {
      max-height: 200rem;
    }
  }

  .megamenu__panel-inner {
    padding: 0.25rem 0.25rem 0.5rem;
  }

  .megamenu__columns {
    display: block;
  }

  .megamenu__column {
    min-width: 0;
    max-width: none;
    padding: 0.1875rem 0;
  }

  .megamenu__heading {
    font-size: 0.875rem;
    border-bottom-width: 1px;
    margin-bottom: 0.125rem;
    padding: 0.125rem 0;
  }

  .megamenu__link {
    padding: 0.3125rem 0 0.3125rem 0.375rem;
  }
}

/* --------------------------------------------------------------------------
   15. Mobile: region button & utility links
   -------------------------------------------------------------------------- */

.megamenu__region-btn {
  text-decoration: none;

  @media (max-width: 991.98px) {
    display: none;
  }

  @media (min-width: 992px) {
    margin-left: auto;
    padding: 0.625rem clamp(0.75rem, 0.5vw + 0.25rem, 1.5rem) !important;
    font-size: clamp(0.75rem, 0.5vw + 0.45rem, 0.9375rem) !important;
    white-space: nowrap;
    line-height: 1 !important;
  }
}

.megamenu__mobile-footer .megamenu__region-btn {
  @media (max-width: 991.98px) {
    display: block;
    width: 100%;
    text-align: center;
    padding: 0.75rem 1.5rem;
    margin: 0;
  }
}

/* --------------------------------------------------------------------------
   15b. Mobile: scroll wrapper + nav-style utility links + pinned footer
   -------------------------------------------------------------------------- */

.megamenu__mobile-scroll {
  @media (max-width: 991.98px) {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  @media (min-width: 992px) {
    display: contents;
  }
}

.megamenu__mobile-nav-links {
  margin: 0;
  padding: 0;

  @media (min-width: 992px) {
    display: none !important;
  }

  & li {
    border-bottom: 1px solid var(--mm-border);
  }

  & a {
    display: block;
    padding: 0.875rem 0;
    color: var(--mm-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 1rem;
  }
}

.megamenu__mobile-footer {
  @media (min-width: 992px) {
    display: none !important;
  }

  @media (max-width: 991.98px) {
    flex-shrink: 0;
    padding: 1rem 0 0.5rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem 1.5rem;
  }
}

.megamenu__mobile-footer-link {
  color: var(--mm-text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  flex: 1;
  padding: 0.75rem 1.25rem;
  border: 2px solid var(--mm-heading-border);
  border-radius: 4px;
}

/* --------------------------------------------------------------------------
   16. Body scroll lock
   -------------------------------------------------------------------------- */

body.megamenu-scroll-lock {
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   17. Accessibility: focus-visible outlines
   -------------------------------------------------------------------------- */

.megamenu__trigger:focus-visible,
.megamenu__heading:focus-visible,
.megamenu__link:focus-visible,
.megamenu__toggle:focus-visible,
.megamenu__hamburger:focus-visible {
  outline: 2px solid var(--mm-text-hover);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   18. Reduced motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .megamenu__panel,
  .megamenu__backdrop,
  .megamenu__chevron,
  .megamenu__toggle svg,
  .megamenu__trigger,
  .megamenu__link {
    transition: none !important;
  }
}



/* GAP FIX */

@media (min-width: 1024px) {
    .page-holder {
        padding-top: 6.4375rem !important;
    }
}



/* Borders and search button */

.megamenu > .top-nav {
  border-bottom: 1px solid #e5e8ed;
  
}

a#search-2 {
    padding-inline: 1em;
    padding-block: .5em;
    border-width: 1px;
    border-style: solid;
    border-color: #007faf;
    transition: all .35s ease;

    &:hover {
        background-color: #007faf !important;
        color: white;
    }
}


    
/* Search bar fix */


    header .navbar-search {
      @media (min-width: 1024px) {
        height: auto !important;
    }
}