:host {
  /**
   * @prop --track-background: Background of the toggle track
   * @prop --track-background-checked: Background of the toggle track when checked
   * @prop --border-radius: Border radius of the toggle track
   *
   * @prop --handle-background: Background of the toggle handle
   * @prop --handle-background-checked: Background of the toggle handle when checked
   *
   * @prop --handle-border-radius: Border radius of the toggle handle
   * @prop --handle-box-shadow: Box shadow of the toggle handle
   * @prop --handle-height: Height of the toggle handle
   * @prop --handle-max-height: Maximum height of the toggle handle
   * @prop --handle-width: Width of the toggle handle
   * @prop --handle-spacing: Horizontal spacing around the toggle handle
   * @prop --handle-transition: Transition of the toggle handle
   */
  /* stylelint-disable-next-line declaration-no-important */
  box-sizing: content-box !important;
  display: inline-block;
  position: relative;
  max-width: 100%;
  outline: none;
  cursor: pointer;
  user-select: none;
  z-index: 2;
}

:host(.in-item:not(.legacy-toggle)) {
  width: 100%;
  height: 100%;
}

/**
 * Toggle 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]:not(.legacy-toggle)),
:host([slot=end]:not(.legacy-toggle)) {
  width: auto;
}

:host(.legacy-toggle) {
  contain: content;
  touch-action: none;
}

:host(.ion-focused) input {
  border: 2px solid #5e9ed6;
}

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

:host(.legacy-toggle) label {
  top: 0;
  margin-left: 0;
  margin-right: 0;
  margin-top: 0;
  margin-bottom: 0;
  position: absolute;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;
  appearance: none;
  outline: none;
  display: flex;
  align-items: center;
  opacity: 0;
  pointer-events: none;
}
@supports (inset-inline-start: 0) {
  :host(.legacy-toggle) label {
    inset-inline-start: 0;
  }
}
@supports not (inset-inline-start: 0) {
  :host(.legacy-toggle) label {
    left: 0;
  }
  :host-context([dir=rtl]):host(.legacy-toggle) label, :host-context([dir=rtl]).legacy-toggle label {
    left: unset;
    right: unset;
    right: 0;
  }
  @supports selector(:dir(rtl)) {
    :host(.legacy-toggle) label:dir(rtl) {
      left: unset;
      right: unset;
      right: 0;
    }
  }
}
:host(.legacy-toggle) label::-moz-focus-inner {
  border: 0;
}

input {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  clip: rect(0 0 0 0);
  opacity: 0;
  overflow: hidden;
  -webkit-appearance: none;
  -moz-appearance: none;
}

.toggle-wrapper {
  display: flex;
  position: relative;
  flex-grow: 1;
  align-items: center;
  height: inherit;
  transition: background-color 15ms linear;
  cursor: inherit;
}

.label-text-wrapper {
  /**
   * This ensures that double tapping this text
   * clicks the <label> and focuses the input
   * when a screen reader is enabled.
   */
  pointer-events: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

:host(.in-item:not(.legacy-toggle)) .label-text-wrapper {
  margin-top: 10px;
  margin-bottom: 10px;
}

/**
 * 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;
  align-items: center;
}

:host(.toggle-justify-space-between) .toggle-wrapper {
  justify-content: space-between;
}

:host(.toggle-justify-start) .toggle-wrapper {
  justify-content: start;
}

:host(.toggle-justify-end) .toggle-wrapper {
  justify-content: end;
}

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

:host(.toggle-label-placement-start) .label-text-wrapper {
  /**
   * The margin between the label and
   * the input 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;
}

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

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

:host(.toggle-label-placement-fixed) .label-text-wrapper {
  /**
   * The margin between the label and
   * the input 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;
}

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

.toggle-icon-wrapper {
  display: flex;
  position: relative;
  align-items: center;
  width: 100%;
  height: 100%;
  transition: var(--handle-transition);
  will-change: transform;
}

.toggle-icon {
  border-radius: var(--border-radius);
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--track-background);
  overflow: inherit;
}

:host(.toggle-checked) .toggle-icon {
  background: var(--track-background-checked);
}

.toggle-inner {
  border-radius: var(--handle-border-radius);
  position: absolute;
  left: var(--handle-spacing);
  width: var(--handle-width);
  height: var(--handle-height);
  max-height: var(--handle-max-height);
  transition: var(--handle-transition);
  background: var(--handle-background);
  box-shadow: var(--handle-box-shadow);
  contain: strict;
}

/**
 * We do not use the @ltr and @rtl mixins
 * here because ion-toggle uses the Shadow DOM
 * and WebKit does not support :host-context.
 */
:host(.toggle-ltr) .toggle-inner {
  left: var(--handle-spacing);
}

:host(.toggle-rtl) .toggle-inner {
  right: var(--handle-spacing);
}

:host(.toggle-ltr.toggle-checked) .toggle-icon-wrapper {
  transform: translate3d(calc(100% - var(--handle-width)), 0, 0);
}

:host(.toggle-rtl.toggle-checked) .toggle-icon-wrapper {
  transform: translate3d(calc(-100% + var(--handle-width)), 0, 0);
}

:host(.toggle-checked) .toggle-inner {
  background: var(--handle-background-checked);
}

:host(.toggle-ltr.toggle-checked) .toggle-inner {
  transform: translate3d(calc(var(--handle-spacing) * -2), 0, 0);
}

:host(.toggle-rtl.toggle-checked) .toggle-inner {
  transform: translate3d(calc(var(--handle-spacing) * 2), 0, 0);
}

:host {
  --track-background: rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.39);
  --track-background-checked: rgba(var(--ion-color-primary-rgb, 56, 128, 255), 0.5);
  --border-radius: 14px;
  --handle-background: #ffffff;
  --handle-background-checked: var(--ion-color-primary, #3880ff);
  --handle-border-radius: 50%;
  --handle-box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
  --handle-width: 20px;
  --handle-height: 20px;
  --handle-max-height: calc(100% + 6px);
  --handle-spacing: 0;
  --handle-transition: transform 160ms cubic-bezier(0.4, 0, 0.2, 1), background-color 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

:host(.legacy-toggle) {
  -webkit-padding-start: 12px;
  padding-inline-start: 12px;
  -webkit-padding-end: 12px;
  padding-inline-end: 12px;
  padding-top: 12px;
  padding-bottom: 12px;
  width: 36px;
  height: 14px;
  contain: strict;
}

.native-wrapper .toggle-icon {
  width: 36px;
  height: 14px;
}

:host(.ion-color.toggle-checked) .toggle-icon {
  background: rgba(var(--ion-color-base-rgb), 0.5);
}

:host(.ion-color.toggle-checked) .toggle-inner {
  background: var(--ion-color-base);
}

:host(.toggle-checked) .toggle-inner {
  color: var(--ion-color-contrast, #fff);
}

.toggle-icon {
  transition: background-color 160ms;
}

.toggle-inner {
  will-change: background-color, transform;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
}

.toggle-inner .toggle-switch-icon {
  -webkit-padding-start: 1px;
  padding-inline-start: 1px;
  -webkit-padding-end: 1px;
  padding-inline-end: 1px;
  padding-top: 1px;
  padding-bottom: 1px;
  width: 100%;
  height: 100%;
}

:host(.toggle-disabled) {
  opacity: 0.38;
}

:host(.in-item.legacy-toggle) {
  margin-left: 0;
  margin-right: 0;
  margin-top: 0;
  margin-bottom: 0;
  -webkit-padding-start: 16px;
  padding-inline-start: 16px;
  -webkit-padding-end: 0;
  padding-inline-end: 0;
  padding-top: 12px;
  padding-bottom: 12px;
  cursor: pointer;
}

:host(.in-item.legacy-toggle[slot=start]) {
  -webkit-padding-start: 2px;
  padding-inline-start: 2px;
  -webkit-padding-end: 18px;
  padding-inline-end: 18px;
  padding-top: 12px;
  padding-bottom: 12px;
}