// В этом файле должны быть стили для БЭМ-блока main-nav, его элементов,
// модификаторов, псевдоселекторов, псевдоэлементов, @media-условий...
// Очередность: http://nicothin.github.io/idiomatic-pre-CSS/#priority

.main-nav {
  $block-name: &;

  z-index: 10;

  @media (min-width: $screen-xl) {
    position: relative;
  }

  @media (max-width: ($menu-desktop-width - 1)) {
    box-sizing: border-box;
    position: fixed;
    left: 0;
    top: 0;
    padding: 15px;
    width: 270px;
    height: 100vh;
    overflow-y: auto;
    background-color: #fff;
    opacity: 0;
    transform: translateX(-280px);
    will-change: opacity, transform;
    transition: opacity 0.5s, transform 0.5s;

    &.active {
      opacity: 1;
      transform: translateX(0);
    }
  }

  .mob-menu__close {
    @media (min-width: $screen-xl) {
      display: none;
    }

    @media (max-width: ($screen-xl - 1 )) {
      display: inline-flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 18px;
      padding: 0;
      border: 2px solid $color-cyan;
      width: 48px;
      height: 48px;
      border-radius: 4px;
      background-color: transparent;
      transition: background-color $transition-time;

      &:hover,
      &:focus {
        background-color: $color-cyan;

        svg {
          path {
            fill: #fff;
          }
        }
      }

      svg {
        path {
          transition: fill $transition-time;
        }
      }
    }
  }

  // первый уровень
  &__list {
    margin: 0;
    padding: 0;
    list-style: none;

    // мобильный вид списка
    @media (max-width: ($menu-desktop-width - 1)) {
      // открытие/закрытие меню только в случае работающего JS

      .js & {
        &--lvl-2 {
        }
      }

      .js #{$block-name}--open & {
        &--lvl-2 {
        }
      }
    }

    // настольный вид списка
    @media (min-width: $menu-desktop-width) {
      display: flex;
      // flex-wrap: wrap;
      justify-content: space-between;

      &--lvl-2 {
        display: block;
        border-radius: 4px;
        overflow: hidden;
        background-color: #fff;
      }

      &--lvl-3 {
        display: block;
      }
    }

    &--lvl-2 {
      @media (max-width: ($menu-desktop-width - 1)) {
        :first-child {
          #{$block-name}__link {
            padding-top: 0;
          }
        }
      }
    }
  }

  &__item {
    position: relative;

    @media (max-width: ($menu-desktop-width - 1)) {
      &:not(#{$block-name}__item--lvl-2) {
        & + & {
          border-top: 1px solid #d6dae5;
        }
      }
    }

    &--lvl-2 {
      @media (min-width: $menu-desktop-width) {
        & + & {
          #{$block-name}__link {
            border-top: 1px solid #eef0f7;
          }
        }
      }
    }

    &--active {
      & > #{$block-name}__link {
        color: $color-cyan;
        border-bottom-color: $color-cyan;
        cursor: default;
      }
    }

    &--has-child {
      &:hover {
        & > #{$block-name}__link {
          @media (min-width: $menu-desktop-width) {
            border-bottom-color: transparent;
          }
        }
      }

      @media (min-width: $menu-desktop-width) {
        &:focus-within {
          #{$block-name}__sublist-wrapper--lvl-2 {
            visibility: visible;
          }
        }
      }

      @media (max-width: ($menu-desktop-width - 1)) {
        padding-bottom: 23px;
      }

      & > #{$block-name}__link {
        @media (min-width: $menu-desktop-width) {
          position: relative;
          padding-right: 15px;
          padding-left: 0;

          &::before {
            content: "";
            position: absolute;
            right: 0;
            top: calc(50% + 1px);
            transform: translateY(-50%);
            width: 0;
            height: 0;
            border-left: 4px solid transparent;
            border-right: 4px solid transparent;
            border-top: 6px solid currentColor;
          }
        }
      }
    }
  }

  &__link {
    position: relative;
    display: block;
    padding: 23px 0;
    text-decoration: none;
    font: 500 15px/120% $font-family;
    transition: color $transition-time, border-color $transition-time;

    @media (min-width: $menu-desktop-width) {
      padding: 8px 0;
      border-top: 2px solid transparent;
      border-bottom: 2px solid transparent;
    }

    &:focus {
      outline: 0;
    }

    &:hover,
    &:focus {
      z-index: 1;
      text-decoration: none;
      color: $color-cyan;
      border-bottom-color: $color-cyan;
    }

    &--lvl-2 {
      padding: 8px 0;
      font-size: 13px;

      @media (min-width: $menu-desktop-width) {
        padding: 16px;
        border: none;
        min-width: 165px;
        text-align: center;
        transition: color $transition-time, background-color $transition-time;

        &:hover,
        &:focus {
          color: $color-cyan;
          background-color: #f7f8fb;
        }
      }
    }

    &--lvl-3 {
      min-width: 200px;

      @media (max-width: ($menu-desktop-width - 1)) {
        padding-left: 3em;
      }
    }
  }

  &__sublist-wrapper {
    &--lvl-2 {
      @media (min-width: $menu-desktop-width) {
        position: absolute;
        z-index: 1;
        top: 100%;
        left: 50%;
        transform: translateX(-50%);
        padding-top: 6px;
        opacity: 0;
        visibility: hidden;
        filter: drop-shadow(0 6px 30px rgba(54, 55, 85, 0.15));
        transition: opacity $transition-time;

        #{$block-name}__item--show-child > &,
        #{$block-name}__item:hover & {
          visibility: visible;
          opacity: 1;
        }

        &::before {
          content: "";
          position: absolute;
          left: 50%;
          top: 0;
          transform: translateX(-50%);
          width: 0;
          height: 0;
          border-bottom: 7px solid #fff;
          border-left: 7px solid transparent;
          border-right: 7px solid transparent;
        }
      }
    }

    &--lvl-3 {
      @media (min-width: $menu-desktop-width) {
        position: absolute;
        z-index: 1;
        top: 0;
        left: 100%;
        opacity: 0;
        height: 0;
        overflow: hidden;
        transition: opacity $transition-time;

        // stylelint-disable
        #{$block-name}__item--show-child > &,
        #{$block-name}__item--lvl-2:hover & {
          height: auto;
          overflow: visible;
          opacity: 1;
        }
        // stylelint-enable
      }
    }
  }

  // переключатель

  &__toggler {
    display: inline-block;
    border: none;
    padding: 0;
    background: none;

    @media (min-width: $menu-desktop-width) {
      display: none;
    }

    .no-js & {
      display: none;
    }
  }
}
