$border-color: #dedede;
$placeholder-color: #999;
$hovered-bg: #f5f5f5;
$active-color: #11d8fb;
$disabled-bg: #f5f5f5;
$errored: #ff1f44;
$focused: #11d8fb;

.select {
  position: relative;
  display: inline-block;
  width: 100%;
  user-select: none;
  font-size: 12px;

  .placeholder {
    color: $placeholder-color;
  }

  &.disabled .control {
    opacity: 0.5;
    background-color: $disabled-bg;
    pointer-events: none;
  }

  &.error .control {
    box-shadow: 0 0 0 1px $errored;
  }

  &.active .control {
    box-shadow: 0 0 0 1px $focused;
  }

  .wrap {
    position: relative;
  }

  .control {
    padding: 4px 30px 4px 4px;
    box-shadow: 0 0 0 1px $border-color;
    min-height: 35px;

    &__input {
      display: inline-block;
      vertical-align: middle;
      padding: 6px 0 4px 6px;

      input {
        text-overflow: ellipsis;
        width: 80px;
        background-color: transparent;
      }

      &_multiple_no {
        width: 100%;

        input {
          width: 100%;

          &::placeholder {
            opacity: 0.5;
          }
        }
      }
    }

    &__placeholder {
      padding: 6px 0 4px 6px;
      opacity: 0.5;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }

    &__selected {
      position: relative;
      display: inline;
      text-overflow: ellipsis;
      line-height: 15px;
      font-size: 14px;
      cursor: pointer;

      &_multiple {
        li {
          display: inline-block;
          padding: 0 16px 0 10px;
          background-color: #f5f7f9;
          font-size: 10px;
          line-height: 24px;
          vertical-align: middle;
          margin: 2px 2px 0 0;
          position: relative;
        }
      }

      &_multiple_no {
        display: block;
        width: 100%;
        white-space: nowrap;
        text-overflow: ellipsis;
        padding-top: 6px;
        padding-left: 6px;

        li {
          width: 100%;
        }
      }
    }
  }

  .label {
    margin-bottom: 11px;
  }

  .list {
    position: absolute;
    left: -9999px;
    top: -9999px;
    margin-top: 1px;
    box-shadow: 0 0 0 1px $border-color;
    background-color: #fff;
    list-style: none;
    z-index: -1;

    li {
      position: relative;
      padding: 10px 50px 10px 10px;
      line-height: 16px;
      word-break: break-all;
      cursor: pointer;

      &:hover {
        background-color: $hovered-bg;
      }

      &.active {
        color: $active-color;
      }

      &.disabled {
        opacity: 0.5;
        pointer-events: none;

        &:hover {
          background: none;
        }
      }

      .icon {
        position: absolute;
        right: 10px;
        top: 50%;
        transform: translateY(-50%);
        font-size: 12px;
        color: #44e240;
      }

      &:first-child {
        &::before,
        &::after {
          content: '';
          display: block;
          width: 0;
          height: 0;
          position: absolute;
          top: -5px;
          right: 10px;
          border-left: 5px solid transparent;
          border-right: 5px solid transparent;
          border-bottom: 5px solid #fff;
          z-index: 2;
        }

        &::after {
          top: -6px;
          border-bottom-color: $border-color;
          z-index: 1;
        }

        &:hover::before {
          border-bottom-color: $hovered-bg;
        }
      }
    }
  }

  &.top {
    .list {
      bottom: 37px;

      li:first-child {
        &::before,
        &::after {
          display: none;
        }
      }

      li:last-child {
        &::before,
        &::after {
          content: '';
          display: block;
          width: 0;
          height: 0;
          position: absolute;
          bottom: -5px;
          right: 10px;
          border-left: 5px solid transparent;
          border-right: 5px solid transparent;
          border-top: 5px solid #fff;
          z-index: 2;
        }

        &::after {
          bottom: -6px;
          border-top-color: $border-color;
          z-index: 1;
        }

        &:hover::before {
          border-top-color: $hovered-bg;
        }
      }
    }
  }

  &.open {
    .list {
      top: auto;
      left: 0;
      right: 0;
      z-index: 3;
      max-height: 252px;
      overflow-x: auto;
    }

    .arrow {
      transform: translateY(-50%) rotate(180deg);
    }
  }
}

.arrow {
  display: block;
  width: 0;
  height: 0;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 10px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #282828;
  z-index: 2;
  transition: transform 0.2s ease;
  will-change: transform;
}

.error-label {
  position: absolute;
  top: 100%;
  right: 0;
  padding: 8px 15px 7px 13px;
  color: #fff;
  background-color: $errored;
  font-size: 10px;
  line-height: 1.4;
  z-index: 0;
}

.close {
  position: absolute;
  cursor: pointer;
  right: 0;
  top: 0;
  width: 9px;
  height: 12px;
  opacity: 0.3;
  z-index: 3;
  transition: opacity 0.5s;
  margin-top: 6px;

  &:hover {
    opacity: 1;
  }

  &::before,
  &::after {
    position: absolute;
    left: 1px;
    content: ' ';
    height: 10px;
    width: 1px;
    background-color: #333;
  }

  &::before {
    transform: rotate(45deg);
  }

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

.hiddenInput {
  display: block;
  height: 0;
  width: 0;
  text-indent: -9999px;
}
