/**
 * Divi primary header / desktop flyout menu fixes (site-wide).
 *
 * @package Divi_Child_Theme
 */

/* Do not clip nested flyouts inside the fixed header stack. */
#main-header,
#main-header .container,
#main-header .et_menu_container,
#et-top-navigation,
#top-menu-nav,
#top-header {
  overflow: visible !important;
}

#top-header .wdi-secondary-login-link {
  color: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-right: 14px;
  text-decoration: none;
}

#top-header .wdi-secondary-login-link:hover,
#top-header .wdi-secondary-login-link:focus-visible {
  text-decoration: underline;
}

@media screen and (min-width: 981px) {
  /* Flex layout replaces Divi's full-width absolute logo overlay crowding the nav. */
  #main-header .container.et_menu_container {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 24px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .et_header_style_left #main-header .logo_container {
    position: relative !important;
    width: auto !important;
    height: auto;
    flex: 0 0 auto;
    max-width: min(200px, 22vw);
  }

  .et_header_style_left #main-header .logo_container .logo_helper {
    display: none;
  }

  .logo_container #logo {
    max-height: 54px;
    width: auto;
    height: auto;
  }

  /*
   * Divi custom.js sets inline padding-left = logo width + 30px for left header.
   * That duplicates space once the logo sits in normal flex flow — reset it.
   */
  .et_header_style_left #et-top-navigation {
    flex: 1 1 auto;
    min-width: 0;
    float: none !important;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Divi default is 33px top; we zeroed this earlier and crushed the menu upward. */
    padding-top: 32px !important;
    padding-left: 0 !important;
    padding-right: 32px !important;
    margin: 0;
  }

  .et_header_style_left #main-header.et-fixed-header #et-top-navigation {
    padding-top: 22px !important;
  }

  #top-menu-nav,
  #top-menu {
    float: none !important;
  }

  #top-menu {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    row-gap: 4px;
    line-height: 1.2;
  }

  #top-menu > li {
    display: block;
    float: none;
    padding-right: 14px;
  }

  #top-menu > li:last-child {
    padding-right: 0;
  }

  .et_header_style_left #top-menu > li > a {
    white-space: nowrap;
    padding-bottom: 32px;
  }

  .et_header_style_left #main-header.et-fixed-header #top-menu > li > a {
    padding-bottom: 22px;
  }

  /*
   * Divi sets visibility on .et-hover panels but opacity:1 only on :hover.
   * Nested flyouts (Technology > Email > Google Workspace, etc.) stay invisible without this.
   */
  #top-menu li.et-hover > ul,
  #top-menu li.et-touch-hover > ul {
    opacity: 1 !important;
    visibility: visible !important;
  }

  /* 3rd+ level flyouts: stay above page content and header siblings. */
  #top-menu li ul.sub-menu,
  #top-menu .nav li li ul {
    z-index: 100001;
  }

  /*
   * Shared dropdown chrome — same cream panels / soft item fills on homepage
   * and partner (navy) headers so flyouts match across the site.
   */
  #top-menu li ul.sub-menu {
    background-color: #f2eadf !important;
    border: 1px solid rgba(10, 35, 66, 0.1);
    box-shadow: 0 8px 24px rgba(6, 22, 40, 0.16);
    padding: 8px 0;
  }

  #top-menu li li a {
    background: #faf6ef !important;
    color: #0a2342 !important;
    margin: 0 8px;
    padding: 10px 16px !important;
    border-radius: 4px;
    line-height: 1.35;
  }

  #top-menu li li a:hover,
  #top-menu li li a:focus-visible,
  #top-menu li li.current-menu-item > a,
  #top-menu li li.current_page_item > a {
    background: #f2eadf !important;
    color: #1d7d81 !important;
  }

  /* Per-item flip (set by wdi-header-nav.js) when a nested panel would overflow right. */
  #top-menu ul .menu-item-has-children.wdi-submenu-flip-left > ul.sub-menu,
  #top-menu ul .menu-item-has-children.wdi-submenu-flip-left > ul {
    left: auto !important;
    right: 100% !important;
  }

  /* Divi's top-level reverse class (resize handler) — keep behavior explicit. */
  #top-menu li.et-reverse-direction-nav li ul {
    left: auto !important;
    right: 240px !important;
  }

  /*
   * Tall leaf panels (Business, etc.) may scroll.
   * Panels that still open nested flyouts (Technology → Hosting) must stay
   * overflow:visible so 3rd-level items are not clipped.
   */
  #top-menu ul.sub-menu:not(:has(> .menu-item-has-children)),
  #top-menu #menu-item-1359 > ul.sub-menu {
    max-height: min(70svh, calc(100svh - 112px));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  #top-menu ul.sub-menu:has(> .menu-item-has-children) {
    max-height: none !important;
    overflow: visible !important;
  }

  /* Keep tertiary+ panels visible when Divi uses et-hover without :hover opacity. */
  #top-menu li li.et-hover > ul,
  #top-menu li li.et-touch-hover > ul,
  #top-menu li li li.et-hover > ul,
  #top-menu li li li.et-touch-hover > ul {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  /* Stack deeper flyouts above their parent panels. */
  #top-menu li li > ul.sub-menu {
    z-index: 100002;
  }

  #top-menu li li li > ul.sub-menu {
    z-index: 100003;
  }
}

@media screen and (min-width: 981px) and (max-width: 1400px) {
  #main-header .container.et_menu_container {
    padding-left: 20px;
    padding-right: 20px;
  }

  #top-menu > li {
    padding-right: 10px;
  }

  #top-menu > li > a {
    font-size: 13px;
    padding-left: 6px;
    padding-right: 6px;
  }
}

@media screen and (min-width: 981px) and (max-width: 1200px) {
  #top-menu > li {
    padding-right: 6px;
  }

  #top-menu > li > a {
    font-size: 12px;
  }
}

/* ============================================================================
   MOBILE PRIMARY MENU — full-width panel + accordion submenus
   Divi defaults expand every .sub-menu (display:block !important) and size
   the panel to the 80% .container — override both for usable mobile nav.
   ============================================================================ */
@media screen and (max-width: 980px) {
  #et_mobile_nav_menu {
    float: none !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /*
   * Lock page scroll while the hamburger panel is open so wheel/touch
   * scrolling stays inside #mobile_menu (avoids “cut off” / stuck scroll).
   */
  html.wdi-mobile-nav-open,
  html.wdi-mobile-nav-open body {
    overflow: hidden !important;
    overscroll-behavior: none;
  }

  /*
   * Full-bleed sheet from under the fixed header to the viewport bottom.
   * Top offset: --wdi-mobile-menu-top (set by wdi-header-nav.js).
   * Prefer bottom:0 over max-height alone so iOS toolbars cannot clip items.
   */
  #mobile_menu.et_mobile_menu {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    top: var(--wdi-mobile-menu-top, 140px) !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0.35rem 0 calc(5.5rem + env(safe-area-inset-bottom, 0px)) !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    background: #f2eadf !important;
    border-top: 3px solid #1d7d81 !important;
    box-shadow: 0 12px 32px rgba(6, 22, 40, 0.18) !important;
    /* Above HubSpot (99990 mobile; never under a mega chat z-index). */
    z-index: 1000500 !important;
    pointer-events: auto !important;
  }

  html.wdi-mobile-nav-open #main-header,
  html.wdi-mobile-nav-open #top-header,
  html body:has(.mobile_nav.opened) #main-header,
  html body:has(.mobile_nav.opened) #top-header {
    z-index: 1000400 !important;
  }

  /* Collapse all levels until a parent is opened (beats Divi !important). */
  #main-header .et_mobile_menu li ul,
  #mobile_menu.et_mobile_menu li ul,
  .et_pb_menu .et_mobile_menu li ul,
  .et_pb_fullwidth_menu .et_mobile_menu li ul {
    display: none !important;
    visibility: hidden !important;
    height: auto !important;
    max-height: none !important;
    position: static !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    width: 100% !important;
    float: none !important;
    opacity: 1 !important;
    box-shadow: none !important;
    border: 0 !important;
    background: transparent !important;
    padding: 0 0 0.25rem 0.65rem !important;
    margin: 0 !important;
  }

  #main-header .et_mobile_menu li.wdi-mobile-accordion-open > ul,
  #mobile_menu.et_mobile_menu li.wdi-mobile-accordion-open > ul,
  .et_pb_menu .et_mobile_menu li.wdi-mobile-accordion-open > ul,
  .et_pb_fullwidth_menu .et_mobile_menu li.wdi-mobile-accordion-open > ul {
    display: block !important;
    visibility: visible !important;
  }

  #mobile_menu.et_mobile_menu > li {
    border-bottom: 1px solid rgba(10, 35, 66, 0.08);
  }

  #mobile_menu.et_mobile_menu li a {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 0.9rem 1rem !important;
    color: #0a2342 !important;
    font-size: 1rem;
    line-height: 1.35;
    border-bottom: 0 !important;
    background: transparent !important;
  }

  /*
   * Parent row = label + disclosure control (grid keeps chevron from
   * overlapping long titles and keeps submenu full-width below).
   */
  #mobile_menu.et_mobile_menu .menu-item-has-children {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 2.75rem;
    grid-template-rows: auto auto;
    align-items: stretch;
  }

  #mobile_menu.et_mobile_menu .menu-item-has-children > a {
    grid-column: 1;
    grid-row: 1;
    font-weight: 700;
    padding-right: 0.5rem !important;
    background: rgba(10, 35, 66, 0.04) !important;
  }

  #mobile_menu.et_mobile_menu .menu-item-has-children > .wdi-mobile-accordion-toggle {
    grid-column: 2;
    grid-row: 1;
  }

  #mobile_menu.et_mobile_menu .menu-item-has-children > ul {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  #mobile_menu.et_mobile_menu li li a {
    font-weight: 500;
    font-size: 0.9375rem;
    padding: 0.8rem 1rem !important;
    color: #0a2342 !important;
  }

  #mobile_menu.et_mobile_menu li li li a {
    font-size: 0.875rem;
    color: #1d3a5c !important;
  }

  #mobile_menu.et_mobile_menu .wdi-mobile-accordion-toggle {
    position: static;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    min-width: 2.75rem;
    height: 100%;
    min-height: 2.75rem;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(10, 35, 66, 0.04);
    color: #0a2342;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  #mobile_menu.et_mobile_menu .wdi-mobile-accordion-toggle::before {
    content: '';
    width: 0.55rem;
    height: 0.55rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
  }

  #mobile_menu.et_mobile_menu
    li.wdi-mobile-accordion-open
    > .wdi-mobile-accordion-toggle::before {
    transform: rotate(-135deg);
    margin-top: 0.2rem;
  }

  #mobile_menu.et_mobile_menu li.wdi-mobile-accordion-open > a,
  #mobile_menu.et_mobile_menu
    li.wdi-mobile-accordion-open
    > .wdi-mobile-accordion-toggle {
    background: rgba(29, 125, 129, 0.12) !important;
  }

  #mobile_menu.et_mobile_menu .wdi-mobile-accordion-toggle:focus-visible {
    outline: 2px solid #1d7d81;
    outline-offset: -2px;
  }

  @media (prefers-reduced-motion: reduce) {
    #mobile_menu.et_mobile_menu .wdi-mobile-accordion-toggle::before {
      transition: none;
    }
  }
}
