@import "../mixins/text";

.navbar-nav {
  flex-wrap: nowrap;

  .dropdown:hover > .dropdown-menu {
    right: 0;
    left: auto;
    top: 100%;
    margin-top: var(--bs-dropdown-spacer);
  }

  .nav-item {
    > .nav-link {
      padding: .5rem;
      line-height: 1.5;
      color: $body-color;

      @include body-500;
    }

    // Mobile styles
    @include media-breakpoint-down(lg) {
      .mega-menu-wrapper {
        background: $white;
        padding: 0;

        .dropdown-menu {
          position: static;
          float: none;
          border: none;
          padding-top: .5rem;
          margin: 0;
          width: 100%;
          background: $white;
          box-shadow: none;
        }
      }

      // Mobile arrows for level 1 - only for items with dropdown
      &.menu-item--expanded {
        > .nav-link {
          position: relative;

          &::after {
            content: '';
            display: block;
            position: absolute;
            right: .5rem;
            top: 50%;
            width: 8px;
            height: 8px;
            border: solid $body-color;
            border-width: 0 2px 2px 0;
            transform: translateY(-45%) rotate(-45deg);
            transition: transform .3s ease;
          }
        }

        & > a.show {
          border-radius: $border-radius;
          font-weight: 600;
          background: $blue-50;

          &::after {
            transform: translateY(-45%) rotate(45deg);
          }
        }
      }

      // Level 2 items in mobile - only for items with dropdown
      .dropdown-item.menu-item--expanded {
        .menu-item-wrapper {
          display: flex;
          align-items: center;
          width: 100%;
          position: relative;
          background: $white;

          .menu-item-link {
            flex: 1;
            padding-right: 2.5rem;

            &::after {
              display: none; // Remove default caret
            }
          }

          .dropdown-toggle-btn {
            position: absolute;
            right: 0;
            top: 0;
            width: 40px;
            height: 100%;
            padding: 0;
            background: none;
            border: none;
            cursor: pointer;

            &::after {
              content: '';
              display: block;
              position: absolute;
              left: 50%;
              top: 50%;
              width: 8px;
              height: 8px;
              border: solid $body-color;
              border-width: 0 2px 2px 0;
              transform: translate(-50%, -50%) rotate(45deg);
              transition: transform .3s ease;
            }
          }
        }

        &.show-level3 {
          .dropdown-toggle-btn::after {
            transform: translate(-50%, -50%) rotate(-135deg);
          }
        }
      }

      &.show {
        > .nav-link {
          color: $body-secondary-color;
        }

        > .dropdown-menu {
          display: block;
        }
      }
    }

    // Desktop styles
    @include media-breakpoint-up(lg) {
      position: static;

      > .nav-link {
        border-bottom: 3px solid transparent;
        box-sizing: border-box;
        padding: .5rem .5rem;
        margin: 0 .5rem;
        text-decoration: none;

        &::after {
          display: none;
        }

        &:hover, &.active {
          border-bottom-color: $body-color;
        }
      }

      // Level 2 items in desktop
      .dropdown-item.menu-item--expanded {
        .menu-item-wrapper {
          display: flex;
          align-items: center;
          width: 100%;
          position: relative;
          background: $white;

          .menu-item-link {
            flex: 1;
            padding-right: 2.5rem;
            text-decoration: none;

            &::after {
              display: none; // Remove default caret
            }

            &:hover {
              color: $body-color;
              font-weight: 600;
              background: $blue-50;
            }
          }

          .dropdown-toggle-btn {
            position: absolute;
            right: 0;
            top: 0;
            width: 40px;
            height: 100%;
            padding: 0;
            background: none;
            border: none;
            cursor: pointer;

            &::after {
              content: '';
              display: block;
              position: absolute;
              left: 50%;
              top: 50%;
              width: 8px;
              height: 8px;
              border: solid $body-color;
              border-width: 0 2px 2px 0;
              transform: translate(-50%, -50%) rotate(45deg);
              transition: transform .3s ease;
            }

            &:hover {
              &::after {
                border-color: $body-secondary-color;
              }
            }
          }
        }

        &.show-level3 {
          .dropdown-toggle-btn::after {
            transform: translate(-50%, -50%) rotate(-135deg);
          }
        }
      }

      .mega-menu-wrapper {
        display: none;
        position: absolute;
        left: 0;
        width: 100%;
        background: $white;
        margin-top: calc(1.25rem + .3125rem);
        padding: 1.5rem;
        z-index: 1000;
        border-radius: $border-radius;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, .1), 0 2px 4px -1px rgba(0, 0, 0, .06);

        &::before {
          content: '';
          position: absolute;
          top: -25px;
          left: 0;
          width: 100%;
          height: 25px;
          background: transparent;
        }

        .mega-menu-columns {
          display: flex;
          gap: 0;
          width: 100%;
          margin: 0 auto;
          background: $white;
        }

        .mega-menu-column {
          flex: 1;
          padding: 0 2rem;
          border-right: 1px solid $dark-navy-100;

          &:last-child {
            border-right: none;
          }

          .dropdown-menu {
            display: block;
            position: static;
            border: none;
            padding-top: .5rem;
            margin: 0;
            width: 100%;
            box-shadow: none;
            background: $white;

            // Level 3 menu styles
            .level-3 {
              display: none;
              padding-left: 1rem;
            }

            // Show level 3 on click of parent in desktop
            .menu-item--expanded {
              &.show-level3 {
                > .level-3 {
                  display: block !important;
                }
              }
            }
          }
        }

        &.d-none.d-lg-block {
          display: none !important;
        }
      }

      &:hover {
        .mega-menu-wrapper.d-none.d-lg-block {
          display: block !important;
        }
      }
    }

    // Shared dropdown item styles
    .dropdown-item {
      padding: 0;
      margin-bottom: .5rem;
      background: $white;
      width: 100%;
      text-decoration: none;

      &:hover {
        background-color: unset;
      }

      &.active {
        > .menu-item-wrapper {
          .menu-item-link {
            background-color: $blue-50;
            font-weight: 600;
            border-radius: $border-radius;
          }
        }
      }

      a {
        color: $body-color;
        display: block;
        padding: .5rem;
        border-radius: $border-radius;
        background: $white;

        &:hover {
          color: $body-color;
          font-weight: 600;
          background: $blue-50;
        }
      }
    }

    // Level 3 menu base styles
    .level-3 {
      padding-left: 1rem;
    }

    // Mobile-specific level 3 behavior
    @include media-breakpoint-down(lg) {
      &.menu-item--expanded {
        &.show > .level-3 {
          display: block;
        }
      }
    }
  }
}

// Responsive adjustments
@include media-breakpoint-up(lg) {
  .navbar-nav > .nav-item > .mega-menu-wrapper {
    width: min(992px, 100vw - 40px);
  }
}

@include media-breakpoint-up(xl) {
  .navbar-nav > .nav-item > .mega-menu-wrapper {
    width: min(1200px, 100vw - 80px);
    padding: 25px 20px;
  }
}

@media screen and (min-width: 1600px) {
  .navbar-nav > .nav-item > .mega-menu-wrapper {
    width: 1440px;
    max-width: none;
    padding: 1.5rem;
  }
}
