// Sliders
//================================================== //

// Avoid the FoUC
// Ranges are styled similarly to their pseudo-markup in size.
input[type='range'] {
  height: 4px;
  margin: 25px 5px 50px;
  position: relative;
  visibility: hidden;
  width: 92%;

  &.vertical {
    writing-mode: bt-lr;
  }
}

.slider-box {
  display: inline-block;
  width: 60px;
  margin-left: 24px;
  vertical-align: middle;
}

.slider-wrapper {
  background-color: $slider-bg-color;
  position: relative;
  touch-action: none;

  @include css3(touch-callout, none);
  @include css3(user-select, none);

  &:not(.vertical) {
    height: 4px;
    margin: 25px 4% 50px;
    width: 92%;

    &.has-slider-box {
      display: inline-block;
      margin: unset;
      width: 400px;
    }

    .slider-hit-area {
      bottom: -10px;
      left: 0;
      right: 0;
      top: -10px;
    }

    > .tick {
      margin-top: -2px;

      &::after {
        margin-left: -4px;
      }

      > .label {
        left: 3px;
        top: 17px;
      }
    }

    .slider-handle {
      margin-top: -7px;

      &.is-animated {
        @include css3(transition, left 200ms, right 200ms);
      }
    }

    .slider-range {
      height: inherit;

      &.is-animated {
        @include css3(transition, left 200ms, right 200ms);
      }
    }
  }

  &.vertical {
    height: 94%;
    margin: calc(25px + 4%) 50px calc(50px + 4%);
    min-height: 150px;
    width: 4px;
    margin-left: 72px;

    .slider-hit-area {
      bottom: 0;
      left: -10px;
      right: -10px;
      top: 0;
    }

    > .tick {
      margin-left: -2px;

      &::after {
        margin-left: -4px;
      }

      > .label {
        right: 24px;
        text-align: right;
        top: -7px;
      }
    }

    .slider-handle {
      margin-left: -6px;

      &.is-animated {
        @include css3(transition, top 200ms, bottom 200ms);
      }
    }

    .slider-range {
      width: inherit;

      &.is-animated {
        @include css3(transition, top 200ms, bottom 200ms);
      }
    }
  }

  .slider-hit-area {
    cursor: pointer;
    position: absolute;
  }

  > .tick {
    background-color: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: inline-block;
    height: 8px;
    line-height: 8px;
    outline: 0;
    position: absolute;
    text-align: center;
    text-decoration: none;
    -webkit-touch-callout: none;
    -ms-user-select: none;
    -webkit-user-select: none;
    user-select: none;
    width: 8px;

    &.complete::after {
      background-color: $slider-active-bg-color;
    }

    &::after {
      background-color: $slider-bg-color;
      border-radius: 50%;
      content: '';
      height: 8px;
      position: absolute;
      width: 8px;
    }

    &.inherit::after {
      background-color: inherit !important;
    }

    > .label {
      color: $slider-labels-color;
      position: absolute;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  &.is-disabled {
    background-color: $slider-disabled-color !important;
    opacity: 0.7;

    > * {
      cursor: default;
    }

    > .tick {
      background-color: $slider-disabled-color !important;

      > .label {
        color: $slider-disabled-labels-color;
      }

      &::after {
        background-color: $slider-disabled-color;
      }

      &.complete {
        background-color: $slider-disabled-active-bg-color !important;
      }
    }

    > .slider-range {
      background-color: $slider-disabled-range-color !important;
      border-color: $slider-disabled-range-color !important;
    }

    > .slider-handle {
      background-color: $slider-disabled-handle-color !important;
      border-color: $slider-disabled-handle-color !important;
    }
  }

  &.is-readonly {
    background-color: $slider-readonly-color !important;

    > * {
      cursor: default;
    }

    > .tick {
      background-color: $slider-readonly-color !important;

      > .label {
        color: $slider-readonly-labels-color;
      }

      &::after {
        background-color: $slider-readonly-color;
      }

      &.complete {
        background-color: $slider-readonly-active-bg-color !important;
      }
    }

    > .slider-range {
      background-color: $slider-readonly-range-color !important;
      border-color: $slider-readonly-range-color !important;
    }

    > .slider-handle {
      background-color: $slider-readonly-handle-color !important;
      border-color: $slider-readonly-handle-color !important;
    }
  }
}

// Tick Margins are screwy in old versions of IE
.ie:not(.ie-edge) {
  .slider-wrapper > .tick::after {
    margin-left: 0;
  }
}

.slider-handle {
  background-color: $slider-active-bg-color;
  border: 6px solid $slider-active-bg-color;
  border-radius: 16px;
  box-shadow: 0 0 0 20px transparent; //Increase touch point
  color: transparent;
  cursor: pointer;
  display: inline-block;
  height: 16px;
  line-height: 16px;
  position: absolute;
  width: 16px;
  z-index: 20;

  @include css3(touch-callout, none);

  &::after,
  &::before {
    border-color: inherit;
    border-radius: 50%;
    content: '';
    left: -14px;
    position: absolute;
    top: -14px;
    z-index: 19;

    @include transition(transform 200ms ease 0s);
    @include scale(0);
  }

  // Focus Border
  &:not(.hide-focus)::after {
    border: 1px solid;
    border-color: inherit;
    border-radius: 50%;
    content: '';
    height: 30px;
    position: absolute;
    width: 30px;
    z-index: 19;

    @include scale(0);
    @include transition(transform 200ms ease 0s);
  }

  // Transparent BGs
  &:not(.is-dragging)::before {
    border: 16px solid;
    border-color: inherit;
    border-radius: 50%;
    content: '';
    opacity: 0.1;
    position: absolute;
    z-index: 19;

    @include transition(transform 200ms ease 0s);
    @include scale(0);
  }

  &:focus,
  &:active {
    outline: 0;

    &:not(.hide-focus) {
      border-color: $slider-active-bg-color;
    }
  }

  &:focus {
    &::before,
    &::after {
      @include scale(0.96);
    }
  }

  &:hover,
  &.is-dragging {
    @include css3(transition, none);

    box-shadow: $slider-hover-shadow;
  }
}

.slider-range {
  background-color: $ids-color-brand-primary-base;
  cursor: pointer;
  display: block;
  position: absolute;

  &.is-dragging {
    @include css3(transition, none);
  }
}

// Compact Mode
.field-short,
.form-layout-compact .field {
  input[type='range'] {
    margin: 15px 4% 25px;
  }

  .slider-wrapper {
    &:not(.vertical) {
      height: 4px;
      margin: 15px 4% 25px;
      width: 92%;
    }
  }
}

@include respond-to(large) {
  .slider-wrapper {
    &:not(.vertical) {
      margin: 25px 3% 50px;
      width: 94%;
    }

    &.vertical {
      height: 94%;
    }
  }
}

@include respond-to(extralarge) {
  .slider-wrapper {
    &:not(.vertical) {
      margin: 25px 2.5% 50px;
      width: 95%;
    }

    &.vertical {
      height: 95%;
    }
  }
}

// RTL Styles
html[dir='rtl'] {
  .slider-wrapper {
    &.vertical {
      > .tick {
        margin-left: inherit;
        margin-right: -2px;

        &::after {
          margin-left: inherit;
          margin-right: -4px;
        }

        > .label {
          left: 24px;
          right: auto;
          text-align: left;
        }
      }

      .slider-handle {
        margin-left: inherit;
        margin-right: -7px;
      }
    }

    > .tick {
      &.inherit::after {
        background-color: transparent !important;
      }
    }

    &.is-disabled {
      > .tick {
        &::after {
          background-color: transparent;
        }
      }
    }

    &:not(.vertical) {
      > .tick {
        > .label {
          left: auto !important;
        }
      }
    }
  }
}
