// Primary navigation (mobile menu)
.usa-nav__primary .usa-current::after {
  display: none;
}

.usa-nav__primary.mobile {
  // At $theme-header-width and wider...
  @include at-media($theme-header-min-width) {
    display: none !important;

    + .block .megamenu-search-block {
      display: none !important;
    }
  }

  @include at-media-max('desktop') {
    margin-top: 0.5rem;

    .usa-nav__primary-item {
      position: relative;
      border-top: 0;
      border-bottom: 1px solid color('base-lightest');

      a {
        color: color('base');
        background-color: transparent;
        padding: 0;
        position: relative;
        z-index: 5;

        @include hover {
          background-color: transparent;
        }
      }

      span {
        display: block;
        padding: 1.5rem 4rem 1.5rem 0;
        color: color('base');
      }

      li span {
        color: color('base');
        margin-left: 2rem;
      }

      .usa-nav__submenu-item {
        border-top: 1px solid color('base-lightest');
      }

      button {
        position: absolute;
        top: 1rem;
        left: 0;
        right: 0;
        z-index: 4;
        cursor: pointer;

        @include hover {
          background-color: transparent;
        }

        &[aria-expanded="false"] {
          background-image: url("../../uswds/dist/img/angle-arrow-down-primary.svg"), linear-gradient(transparent, transparent);
          background-repeat: no-repeat;
          background-position: right 0 center;
          background-size: 1.2rem;
        }

        &[aria-expanded="true"] {
          background-image: url("../../uswds/dist/img/angle-arrow-up-primary.svg"), linear-gradient(transparent, transparent);
          background-repeat: no-repeat;
          background-position: right 0 center;
          background-size: 1.2rem;
          color: $brightblue;

          span {
            color: $brightblue;
          }
        }
      }
    }
  }
}

// Mega Menu navigation
.usa-nav__primary.main-menu-mega {
  @include u-font('sans', 3); //1.39rem
  font-size: 1.3rem;
  display: none;
  list-style: none;

  @include breakpoint($widescreen) {
    font-size: 1.4rem;
  }

  button {
    position: relative;
    padding: 1.2rem;
    background-position: center center;
    background-color: transparent;

    &[aria-expanded] {
      background-size: 1rem;
    }

    &[aria-expanded="true"] {
      @include at-media($theme-header-min-width) {
        @include add-background-svg("angle-arrow-up-primary");
      }
    }

    &.with-text {
      padding: 1.6rem 2rem 1.6rem 0;
      font-weight: 500;
      font-size: 1.5rem;
      line-height: 1.2;
      color: $darkblue;
      background: none;
      border-bottom: 1px solid transparent;
      transition: border 300ms;
      white-space: nowrap;

      @include hover {
        color: $brightblue;
        border-bottom: 1px solid $brightblue;
      }

      > span.icon {
        display: inline-block;
        position: absolute;
        margin-left: 5px;
        background-image: url("../../uswds/dist/img/angle-arrow-down.svg"), linear-gradient(transparent, transparent);
        background-repeat: no-repeat;
        background-position: right 1.6rem top 53%;
        background-size: 0.8rem;
        width: 26px;
        height: 2rem;
      }

      > span.btn-text {
        white-space: normal;
      }

      &[aria-expanded="true"] {

        > span.icon {
          background-image: url("../../uswds/dist/img/angle-arrow-up-primary.svg"), linear-gradient(transparent, transparent);
          background-repeat: no-repeat;
          background-size: 0.8rem;
          background-position: right 1.6rem top 53%;
        }

      }

    }
  }

  @include at-media($theme-header-min-width) {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    width: 100%;
    line-height: 1;
    margin-top: 0;

    > li.menu-item {
      display: flex;
      align-items: center;

      ~ li.menu-item {
        margin-left: 1.6rem;
      }

      &:last-child {
        a[href^="https://search.ftc.gov/search"],
        a[href^="https://search.usa.gov/search"],
        a[href^="/search"] {
          @include add-background-svg("search-primary");
          background-position: center;
          background-size: 1.6rem;
          text-indent: -9999px;
          width: 2.4rem;
        }

        &.dropdown {
          a[href^="https://search.ftc.gov/search"],
          a[href^="https://search.usa.gov/search"],
          a[href^="/search"] {
            display: none;

            + button {
              @include add-background-svg("search-primary");
              background-size: 1.6rem;
            }
          }
        }
      }

      > a {
        color: $darkblue;
        @include u-text('no-underline');
        line-height: 1.3;
        font-weight: 500;

        @include hover {
          color: $brightblue;
        }
      }
    }
  }
}

// legacy support - ms edge
@supports (-ms-ime-align: auto) {
  .usa-nav__primary.main-menu-mega {
    button {
      top: 1rem;
    }
  }
}

// legacy support - ie11
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  .usa-nav__primary.main-menu-mega {
    button {
      top: 1rem;
    }
  }
}
