/* stylelint-disable color-no-hex, declaration-no-important, selector-class-pattern, max-nesting-depth, selector-max-compound-selectors, selector-no-qualifying-type, no-descending-specificity */

.selectize-input {
  @include input-baseline;

  z-index: 1;
  overflow: hidden;

  > * {
    display: inline-block;
    zoom: 1;
    vertical-align: baseline;
  }

  &.disabled,
  &.disabled * {
    pointer-events: none;
  }

  &.focus {
    //box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
  }

  &::after {
    content: ' ';
    display: block;
    position: absolute;
    top: 50%;
    right: $small-spacing;
    width: 0;
    height: 0;
    transform: translateY(-50%);
    border-width: 5px 5px 0;
    border-style: solid;
    border-color: cv('gray', '700') transparent transparent;
  }

  &.dropdown-active {
    border-radius: $base-border-radius $base-border-radius 0 0;

    &::after {
      border-width: 0 5px 5px;
      border-color: transparent transparent cv('gray', '700');
    }
  }

  > input {
    display: inline-block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 2px 0 0;
    padding: 0;
    border: 0;
    background: none !important;
    box-shadow: none !important;
    font-size: inherit;
    line-height: inherit !important;
    text-indent: 0 !important;

    &::placeholder {
      color: $text-sub;
      font-size: ms(0);
    }
  }

  &.full,
  &.has-items {
    > input {
      width: 0 !important;
    }
  }
}

.selectize-input,
.selectize-control.single .selectize-input.input-active {
  display: inline-block;
  cursor: text;
}

.selectize-control {
  position: relative;

  .selectize-input {
    &.disabled {
      opacity: $med-opaque;
      background-color: #fafafa;
    }
  }

  &.multi {
    .selectize-input {
      padding-top: calc(#{$small-spacing} - (#{$tiny-spacing} / 2) - 1px);
      padding-bottom: calc(#{$small-spacing} - (#{$tiny-spacing} / 2) - #{$tiny-spacing} - 1px);

      > input {
        margin: 0 0 $tiny-spacing 0;
        padding: ($tiny-spacing / 2) 0 ($tiny-spacing / 2);
        border: 1px solid transparent;
      }

      > .item {
        margin: 0 $tiny-spacing $tiny-spacing 0;
        padding: ($tiny-spacing / 2) 0 ($tiny-spacing / 2) $small-spacing;
        border: 1px solid $base-border-color;
        border-radius: 1em;
        background-color: $white;
        cursor: default;

        &:last-child {
          margin-right: 0;
        }

        &.active {
          border-color: cv('action', 'base');
        }
      }

      &.disabled {
        > div,
        > div.active {
          border: 0 solid $white;
          background: $white;
          color: #7d7d7d;
        }
      }
    }
  }

  &.single .selectize-input.input-active,
  &.single .selectize-input.input-active input {
    cursor: text;
  }

  &.rtl {
    .selectize-input {
      > input {
        margin: 0 4px 0 -2px !important;
      }
    }

    &.single {
      .selectize-input {
        &::after {
          right: auto;
          left: 15px;
        }
      }
    }
  }

  &.plugin-drag_drop {
    .ui-sortable-placeholder {
      &::after {
        content: '!';
        visibility: hidden;
      }
    }

    .ui-sortable-helper {
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    }

    &.multi {
      > .selectize-input {
        > .ui-sortable-placeholder {
          visibility: visible !important;
          order: 0 none !important;
          background: #f2f2f2 !important;
          background: rgba(0, 0, 0, 0.06) !important;
          box-shadow: inset 0 0 12px 4px $white;
        }
      }
    }
  }

  &.plugin-remove_button {
    [data-value] {
      position: relative;

      .remove {
        display: inline-block;
        padding: 0 $small-spacing;
        color: $text-sub;
        font-weight: 600;
        text-decoration: none;
        cursor: default;

        &:hover {
          color: $text-heading;
        }
      }
    }

    .remove-single {
      position: absolute;
      top: 0;
      right: 0;
      font-size: 23px;
    }
  }
}

.selectize-dropdown-header {
  position: relative;
  padding: 5px 8px;
  border-bottom: 1px solid #d0d0d0;
  border-radius: 3px 3px 0 0;
  background: #f8f8f8;
}

.selectize-dropdown-header-close {
  position: absolute;
  top: 50%;
  right: 8px;
  margin-top: -12px;
  opacity: 0.4;
  color: #303030;
  font-size: 20px !important;
  line-height: 20px;

  &:hover {
    color: cv('gray', '900');
  }
}

.selectize-dropdown {
  position: absolute;
  z-index: 10;
  border: 1px solid cv('gray', '100');
  border-top: 0;
  border-radius: 0 0 $base-border-radius $base-border-radius;
  background: $white;

  [data-selectable] {
    overflow: hidden;

    .highlight {
      border-radius: 1px;
      background: rgba(125, 168, 208, 0.2);
    }

    &.option {
      opacity: 1;

      &:hover {
        &::before {
          content: '';
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          border: 1px solid cv('action', 'base');
        }
      }
    }
  }

  .option,
  .optgroup-header,
  .create {
    padding: $small-spacing;
  }

  .option,
  [data-disabled],
  [data-disabled] [data-selectable].option {
    opacity: $med-opaque;
    cursor: inherit;
  }

  .optgroup-header {
    padding: $small-spacing $small-spacing $tiny-spacing;
    border: 1px solid cv('gray', '100');
    border-right: 0;
    border-left: 0;
    background-color: cv('gray', '000');
    font-size: ms(-1);
    font-weight: 600;
  }

  .option {
    position: relative;
    border-bottom: 1px solid cv('gray', '100');

    &:last-child {
      border-bottom: 0;
    }

    &.selected {
      // Empty rule to maintain available selector
    }
  }

  .active {
    &.create {
      color: #495c68;
    }
  }

  .create {
    color: rgba(48, 48, 48, $med-opaque);
  }

  &.plugin-optgroup_columns {
    .optgroup {
      box-sizing: border-box;
      float: left;
      border-top: 0;
      border-right: 1px solid #f2f2f2;

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

      &::before {
        display: none;
      }
    }

    .optgroup-header {
      border-top: 0;
    }
  }
}

.selectize-dropdown-content {
  max-height: 200px;
  overflow-x: hidden;
  overflow-y: auto;
}
