:host {
  /**
   * @prop --bar-background: Background of the range bar
   * @prop --bar-background-active: Background of the active range bar
   * @prop --bar-height: Height of the range bar
   * @prop --bar-border-radius: Border radius of the range bar
   * @prop --height: Height of the range
   * @prop --knob-background: Background of the range knob
   * @prop --knob-border-radius: Border radius of the range knob
   * @prop --knob-box-shadow: Box shadow of the range knob
   * @prop --knob-size: Size of the range knob
   * @prop --pin-background: Background of the range pin (only available in MD mode)
   * @prop --pin-color: Color of the range pin (only available in MD mode)
   */
  --knob-handle-size: calc(var(--knob-size) * 2);
  display: flex;
  position: relative;
  flex: 3;
  align-items: center;
  font-family: var(--ion-font-family, inherit);
  user-select: none;
  z-index: 2;
}

:host(.range-disabled) {
  pointer-events: none;
}

::slotted(ion-label) {
  flex: initial;
}

::slotted(ion-icon[slot]) {
  font-size: 24px;
}

.range-slider {
  position: relative;
  flex: 1;
  width: 100%;
  height: var(--height);
  contain: size layout style;
  cursor: grab;
  touch-action: pan-y;
}

:host(.range-pressed) .range-slider {
  cursor: grabbing;
}

.range-pin {
  position: absolute;
  background: var(--ion-color-base);
  color: var(--ion-color-contrast);
  text-align: center;
  box-sizing: border-box;
}

.range-knob-handle {
  top: calc((var(--height) - var(--knob-handle-size)) / 2);
  -webkit-margin-start: calc(0px - var(--knob-handle-size) / 2);
  margin-inline-start: calc(0px - var(--knob-handle-size) / 2);
  position: absolute;
  width: var(--knob-handle-size);
  height: var(--knob-handle-size);
  text-align: center;
}
@supports (inset-inline-start: 0) {
  .range-knob-handle {
    inset-inline-start: 0;
  }
}
@supports not (inset-inline-start: 0) {
  .range-knob-handle {
    left: 0;
  }
  :host-context([dir=rtl]) .range-knob-handle {
    left: unset;
    right: unset;
    right: 0;
  }
  [dir=rtl] .range-knob-handle {
    left: unset;
    right: unset;
    right: 0;
  }
  @supports selector(:dir(rtl)) {
    .range-knob-handle:dir(rtl) {
      left: unset;
      right: unset;
      right: 0;
    }
  }
}
:host-context([dir=rtl]) .range-knob-handle {
  /* stylelint-disable-next-line property-disallowed-list */
  left: unset;
}

[dir=rtl] .range-knob-handle {
  /* stylelint-disable-next-line property-disallowed-list */
  left: unset;
}

@supports selector(:dir(rtl)) {
  .range-knob-handle:dir(rtl) {
    /* stylelint-disable-next-line property-disallowed-list */
    left: unset;
  }
}
.range-knob-handle:active, .range-knob-handle:focus {
  outline: none;
}

.range-bar-container {
  border-radius: var(--bar-border-radius);
  top: calc((var(--height) - var(--bar-height)) / 2);
  position: absolute;
  width: 100%;
  height: var(--bar-height);
}
@supports (inset-inline-start: 0) {
  .range-bar-container {
    inset-inline-start: 0;
  }
}
@supports not (inset-inline-start: 0) {
  .range-bar-container {
    left: 0;
  }
  :host-context([dir=rtl]) .range-bar-container {
    left: unset;
    right: unset;
    right: 0;
  }
  [dir=rtl] .range-bar-container {
    left: unset;
    right: unset;
    right: 0;
  }
  @supports selector(:dir(rtl)) {
    .range-bar-container:dir(rtl) {
      left: unset;
      right: unset;
      right: 0;
    }
  }
}
:host-context([dir=rtl]) .range-bar-container {
  /* stylelint-disable-next-line property-disallowed-list */
  left: unset;
}

[dir=rtl] .range-bar-container {
  /* stylelint-disable-next-line property-disallowed-list */
  left: unset;
}

@supports selector(:dir(rtl)) {
  .range-bar-container:dir(rtl) {
    /* stylelint-disable-next-line property-disallowed-list */
    left: unset;
  }
}

.range-bar {
  border-radius: var(--bar-border-radius);
  position: absolute;
  width: 100%;
  height: var(--bar-height);
  background: var(--bar-background);
  pointer-events: none;
}

.range-knob {
  border-radius: var(--knob-border-radius);
  top: calc(50% - var(--knob-size) / 2);
  position: absolute;
  width: var(--knob-size);
  height: var(--knob-size);
  background: var(--knob-background);
  box-shadow: var(--knob-box-shadow);
  z-index: 2;
  pointer-events: none;
}
@supports (inset-inline-start: 0) {
  .range-knob {
    inset-inline-start: calc(50% - var(--knob-size) / 2);
  }
}
@supports not (inset-inline-start: 0) {
  .range-knob {
    left: calc(50% - var(--knob-size) / 2);
  }
  :host-context([dir=rtl]) .range-knob {
    left: unset;
    right: unset;
    right: calc(50% - var(--knob-size) / 2);
  }
  [dir=rtl] .range-knob {
    left: unset;
    right: unset;
    right: calc(50% - var(--knob-size) / 2);
  }
  @supports selector(:dir(rtl)) {
    .range-knob:dir(rtl) {
      left: unset;
      right: unset;
      right: calc(50% - var(--knob-size) / 2);
    }
  }
}
:host-context([dir=rtl]) .range-knob {
  /* stylelint-disable-next-line property-disallowed-list */
  left: unset;
}

[dir=rtl] .range-knob {
  /* stylelint-disable-next-line property-disallowed-list */
  left: unset;
}

@supports selector(:dir(rtl)) {
  .range-knob:dir(rtl) {
    /* stylelint-disable-next-line property-disallowed-list */
    left: unset;
  }
}

:host(.range-pressed) .range-bar-active {
  will-change: left, right;
}

:host(.in-item) {
  width: 100%;
}

/**
 * Range can be slotted
 * in components such as item and
 * toolbar which is why we do not
 * limit the below behavior to just ion-item.
 */
:host([slot=start]),
:host([slot=end]) {
  width: auto;
}

:host(.in-item) ::slotted(ion-label) {
  align-self: center;
}

.range-wrapper {
  display: flex;
  position: relative;
  flex-grow: 1;
  align-items: center;
  height: inherit;
}

::slotted([slot=label]) {
  /**
   * Label text should not extend
   * beyond the bounds of the range.
   * However, we do not set the max
   * width to 100% because then
   * only the label would show and users
   * would not be able to see the range.
   */
  max-width: 200px;
  /**
   * This ensures that double tapping this text
   * clicks the <label> and focuses the range
   * when a screen reader is enabled.
   */
  pointer-events: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

/**
 * If no label text is placed into the slot
 * then the element should be hidden otherwise
 * there will be additional margins added.
 */
.label-text-wrapper-hidden {
  display: none;
}

.native-wrapper {
  display: flex;
  flex-grow: 1;
  align-items: center;
}

/**
 * Label is on the left of the range in LTR and
 * on the right in RTL.
 */
:host(.range-label-placement-start) .range-wrapper {
  flex-direction: row;
}

:host(.range-label-placement-start) .label-text-wrapper {
  /**
   * The margin between the label and
   * the range should be on the end
   * when the label sits at the start.
   */
  -webkit-margin-start: 0;
  margin-inline-start: 0;
  -webkit-margin-end: 16px;
  margin-inline-end: 16px;
  margin-top: 0;
  margin-bottom: 0;
}

/**
 * Label is on the right of the range in LTR and
 * on the left in RTL.
 */
:host(.range-label-placement-end) .range-wrapper {
  flex-direction: row-reverse;
}

/**
 * The margin between the label and
 * the range should be on the start
 * when the label sits at the end.
 */
:host(.range-label-placement-end) .label-text-wrapper {
  -webkit-margin-start: 16px;
  margin-inline-start: 16px;
  -webkit-margin-end: 0;
  margin-inline-end: 0;
  margin-top: 0;
  margin-bottom: 0;
}

:host(.range-label-placement-fixed) .label-text-wrapper {
  /**
   * The margin between the label and
   * the range should be on the end
   * when the label sits at the start.
   */
  -webkit-margin-start: 0;
  margin-inline-start: 0;
  -webkit-margin-end: 16px;
  margin-inline-end: 16px;
  margin-top: 0;
  margin-bottom: 0;
}

/**
 * Label is on the left of the range in LTR and
 * on the right in RTL. Label also has a fixed width.
 */
:host(.range-label-placement-fixed) .label-text-wrapper {
  flex: 0 0 100px;
  width: 100px;
  min-width: 100px;
  max-width: 200px;
}

:host {
  --knob-border-radius: 50%;
  --knob-background: #ffffff;
  --knob-box-shadow: 0px 0.5px 4px rgba(0, 0, 0, 0.12), 0px 6px 13px rgba(0, 0, 0, 0.12);
  --knob-size: 26px;
  --bar-height: 4px;
  --bar-background: var(--ion-color-step-900, #e6e6e6);
  --bar-background-active: var(--ion-color-primary, #3880ff);
  --bar-border-radius: 2px;
  --height: 42px;
}

:host(.legacy-range) {
  -webkit-padding-start: 16px;
  padding-inline-start: 16px;
  -webkit-padding-end: 16px;
  padding-inline-end: 16px;
  padding-top: 8px;
  padding-bottom: 8px;
}

:host(.ion-color) .range-bar-active,
:host(.ion-color) .range-tick-active {
  background: var(--ion-color-base);
}

::slotted([slot=start]) {
  -webkit-margin-start: 0;
  margin-inline-start: 0;
  -webkit-margin-end: 16px;
  margin-inline-end: 16px;
  margin-top: 0;
  margin-bottom: 0;
}

::slotted([slot=end]) {
  -webkit-margin-start: 16px;
  margin-inline-start: 16px;
  -webkit-margin-end: 0;
  margin-inline-end: 0;
  margin-top: 0;
  margin-bottom: 0;
}

:host(.range-has-pin) {
  padding-top: 20px;
}

.range-bar-active {
  bottom: 0;
  width: auto;
  background: var(--bar-background-active);
}
.range-bar-active.has-ticks {
  border-radius: 0;
  -webkit-margin-start: -2px;
  margin-inline-start: -2px;
  -webkit-margin-end: -2px;
  margin-inline-end: -2px;
}

.range-tick {
  -webkit-margin-start: -2px;
  margin-inline-start: -2px;
  border-radius: 0;
  position: absolute;
  top: 17px;
  width: 4px;
  height: 8px;
  background: var(--ion-color-step-900, #e6e6e6);
  pointer-events: none;
}

.range-tick-active {
  background: var(--bar-background-active);
}

.range-pin {
  transform: translate3d(0,  28px,  0) scale(0.01);
  -webkit-padding-start: 8px;
  padding-inline-start: 8px;
  -webkit-padding-end: 8px;
  padding-inline-end: 8px;
  padding-top: 8px;
  padding-bottom: 8px;
  display: inline-block;
  position: relative;
  top: -20px;
  min-width: 28px;
  transition: transform 120ms ease;
  background: transparent;
  color: var(--ion-text-color, #000);
  font-size: 12px;
  text-align: center;
}

.range-knob-pressed .range-pin,
.range-knob-handle.ion-focused .range-pin {
  transform: translate3d(0,  0,  0) scale(1);
}

:host(.range-disabled) {
  opacity: 0.3;
}