/*
 * Strategic Capital — Mobile Fixed Navigation V3R2
 *
 * Mobile <=980px:
 * - do not depend on position: sticky
 * - SEC/IAPD band remains ordinary entry content
 * - nav-shell becomes fixed only after it reaches viewport top
 * - measured nav height preserves document geometry
 *
 * Desktop >980px remains unchanged.
 */

@media (max-width: 980px) {

  /*
   * Override the V1 sticky mechanism.
   */
  .site-header[data-site-header] {
    position: relative !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
  }

  /*
   * V2R2's scroll class remains useful on desktop.
   *
   * On mobile V3R2 prevents that class from collapsing the topbar.
   * The bar instead leaves the viewport naturally with document
   * scroll, exactly as requested.
   */
  html.sc-topbar-scrolled
  .site-header[data-site-header]
  [data-topbar] {
    max-height: 40px !important;
    min-height: 0 !important;
    opacity: 1 !important;
    transform: none !important;
    overflow: hidden !important;
    pointer-events: auto !important;
  }

  /*
   * When nav-shell leaves normal flow to become fixed, preserve the
   * exact measured height inside the header.
   */
  html.sc-mobile-nav-fixed
  .site-header[data-site-header] {
    padding-bottom:
      var(--sc-mobile-nav-height, 72px) !important;
  }

  html.sc-mobile-nav-fixed
  .site-header[data-site-header]
  .nav-shell {
    position: fixed !important;

    top: 0 !important;
    left: 0 !important;
    right: 0 !important;

    width: 100% !important;
    max-width: 100% !important;

    margin: 0 !important;

    padding-left:
      max(16px, env(safe-area-inset-left)) !important;

    padding-right:
      max(16px, env(safe-area-inset-right)) !important;

    min-height:
      var(--sc-mobile-nav-height, 72px) !important;

    box-sizing: border-box;

    background: #ffffff !important;

    border-bottom:
      1px solid rgba(52, 80, 115, 0.24);

    z-index: 3200 !important;
  }

  html.sc-mobile-nav-fixed
  .site-header
  .nav-toggle[data-nav-toggle] {
    margin-inline-start: auto;

    margin-inline-end:
      max(.5rem, env(safe-area-inset-right));
  }
}

/*
 * Existing <=767px code already makes the open menu fixed.
 *
 * Replace its historical hard-coded 98px top coordinate with the
 * measured current nav height.
 */
@media (max-width: 767px) {

  html.sc-mobile-nav-fixed
  .site-header
  .primary-nav[data-nav-menu],

  html.sc-mobile-nav-fixed
  .site-header
  .primary-nav[data-nav-menu][data-open],

  html.sc-mobile-nav-fixed.sc-nav-open
  .site-header
  .primary-nav[data-nav-menu] {

    top:
      calc(
        var(--sc-mobile-nav-height, 72px)
        + max(8px, env(safe-area-inset-top))
      ) !important;
  }

  html.sc-mobile-nav-fixed.sc-nav-open
  .site-header
  .primary-nav[data-nav-menu] {

    max-height:
      calc(
        100vh
        - var(--sc-mobile-nav-height, 72px)
        - 16px
      ) !important;
  }

  @supports (height: 100dvh) {

    html.sc-mobile-nav-fixed.sc-nav-open
    .site-header
    .primary-nav[data-nav-menu] {

      max-height:
        calc(
          100dvh
          - var(--sc-mobile-nav-height, 72px)
          - 16px
        ) !important;
    }
  }
}
