.menuItem {
  position: relative;
  margin: 0;
  border-bottom: 1px solid var(--menu-border-color);

  @include min(desktop) {
    cursor: pointer;
    
    &:hover {
      > .subMenuList {
        display: block;

        &:not(.hasChildWithSubmenu) {
          max-height: 56rem;
          overflow-y: auto;
        }
      }
    }
  }
}

.subMenuList {
  display: none;
  opacity: 0;
  border-top: 1px solid var(--menu-border-color);
  
  &.show {
    display: block;
    opacity: 1;
  }

  > li:last-of-type {
    border-color: transparent;
  }

  @include min(desktop) {
    min-width: 22rem;
    background-color: var(--levelTwo-bg-color, var(--nav-background-color));
    position: absolute;
    top: calc(100% + 1px);
    left: 0;
    width: 100%;
    perspective: 1000px;
    z-index: -1;
    transform-origin: top center;
    animation: rotateX 300ms 60ms ease-in-out forwards;
    border-top: none;

    &.show {
      display: none;
    }

    > li:last-of-type {
      border-color: var(--menu-border-color);
    }
  
    .subMenuList {
      top: 0;
      left: 100%;
      background-color: var(--levelThree-bg-color, var(--nav-background-color));

      &.hoverLeft {
        left: unset;
        right: 100%;
      }
    }
  }
}

.staticLeft {
  left: auto;
  right: 0;
}

.level1 {
  @include flex-direction(column);
  @include flex-align(stretch, center);
  background-color: var(--levelOne-btn-bg-color, var(--levelOne-bg-color));
  
  &.hasChildren {
    &:after {
      transition: 0.2s;
      @include arrow(var(--menu-text-color), 0.7rem, down, false);
      position: absolute;
      top: 2.4rem;
      right: 2.6rem;
    }
  }

  > a,
  > span {
    color: var(--levelOne-text-color, var(--menu-text-color));
    background-color: var(--levelOne-bg-color, var(--nav-background-color));
  }

  @include min(desktop) {
    border: none;
    border-top: 3px solid transparent;
    border-bottom: 3px solid transparent;
    background-color: var(--levelOne-desktop-bg-color, var(--levelOne-bg-color));

    &.hasChildren {
      &:hover {
        @include arrow-rotate(0);
      }

      &:after {
        top: calc(50% - 0.3rem);
        right: 2.2rem;
      }
    }
  
    &:hover {
      background-color: var(--levelOne-hover-bg-color, var(--nav-background-color));
  
      > a,
      > span {
        color: var(--levelOne-hover-text-color, var(--menu-text-color));
        background-color: var(--levelOne-hover-bg-color, var(--nav-background-color));
      }
    }

    > a,
    > span {
      background-color: var(--levelOne-desktop-bg-color, var(--nav-background-color));
    }
  }
}

.level2 {  
  background-color: var(--levelTwo-btn-bg-color, var(--levelTwo-bg-color));

  &.hasChildren {
    &:after {
      transition: 0.2s;
      @include arrow(var(--menu-text-color), 0.7rem, right, false);
      position: absolute;
      top: 2.4rem;
      right: 2.6rem;
    }
  }

  > a,
  > span {
    background-color: var(--levelTwo-bg-color, var(--nav-background-color));
    color: var(--levelTwo-text-color, var(--menu-text-color));
  }

  @include min(desktop) {
    background-color: var(--levelTwo-desktop-bg-color, var(--levelTwo-bg-color));

    &.hasChildren {
      &:after {
        top: calc(50% - 0.3rem);
        right: 2.4rem;
      }
    }

    > a,
    > span {
      background-color: var(--levelTwo-desktop-bg-color, var(--levelTwo-bg-color));
    }

    &:hover {  
      background-color: var(--levelTwo-hover-bg-color, var(--nav-background-color));

      > a,
      > span {
        background-color: var(--levelTwo-hover-bg-color, var(--nav-background-color));
        color: var(--levelTwo-hover-text-color, var(--menu-text-color));
      }
    }
  }
}

.level3 {
  background-color: var(--levelThree-btn-bg-color, var(--levelThree-bg-color));

  > a,
  > span {
    color: var(--levelThree-text-color, var(--menu-text-color));
    background-color: var(--levelThree-bg-color, var(--nav-background-color));
  }
  
  @include min(desktop) {
    background-color: var(--levelThree-desktop-bg-color, var(--levelThree-bg-color));

    > a,
    > span {
      background-color: var(--primary-hover-color);
      background-color: var(--levelThree-desktop-bg-color, var(--levelThree-bg-color));
    }

    &:hover {
      background-color: var(--levelThree-hover-bg-color, var(--nav-background-color));
  
      > a,
      > span {
        color: var(--levelThree-hover-text-color, var(--menu-text-color));
        background-color: var(--levelThree-hover-bg-color, var(--nav-background-color));
      }
    }
  }
}

.hasChildren {
  @include min-max(mobile-s, laptop) {  
    &.showSubMenu {
      padding-right: 0;
    }

    > a,
    > span {
      width: calc(83%);
      min-width: calc(100% - 64px);
    }
  }
}

@keyframes rotateX {
  0% {
    opacity: 0;
    transform: rotateX(-90deg);
  }
  50% {
    transform: rotateX(-20deg);
  }
  100% {
    opacity: 1;
    transform: rotateX(0deg);
  }
}