.switch {
  --track-height: 32px;
  --track-width: 52px;
  --border-width: 2px;
  --size-off: 16px;
  --size-on: 24px;
  --icon-size: 16px;
  --gap-on: calc(((var(--track-height) - var(--size-on)) / 2) - var(--border-width));
  --gap-off: calc(((var(--track-height) - var(--size-off)) / 2) - var(--border-width));
}

.switch,
.switch * {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.switch label {
  cursor: pointer;
}

.switch label input[type=checkbox] {
  opacity: 0;
  width: 0;
  height: 0;
  // @implement /Users/kzarshenas/Sites/RodeoFx/rodeo_toolkit_2/app/Front/style/scss/component_enhance.scss
  // Without this, an inherited padding can push the (invisible, 0x0)
  // checkbox out of alignment with the lever it's meant to sit under.
  box-sizing: border-box;
  padding: 0 !important;

  // CHECKED
  // Track
  &:checked + .lever{
    background-color: var(--md-sys-color-primary);
    border-color:  var(--md-sys-color-primary);
  }
  // Dot
  &:checked + .lever {
    &:before, &:after {
      top: var(--gap-on);
      inset-inline-start: calc(var(--track-width) - var(--size-on) - var(--gap-on) - 2 * var(--border-width));
      width: var(--size-on);
      height: var(--size-on);
    }
    &:after {
      background-color: var(--md-sys-color-surface);
    }
  }
}

.switch label .lever {
  content: "";
  display: inline-block;
  position: relative;
  width: var(--track-width);
  height: var(--track-height);
  border-style: solid;
  border-width: 2px;
  border-color: var(--md-sys-color-outline);

  //@extend .surface-variant;
  background-color: var(--md-sys-color-surface-variant);

  border-radius: 15px;
  margin-right: 10px;
  transition: background 0.3s ease;
  vertical-align: middle;
  touch-action: pan-y;
  margin: 0 16px;

  // DOT
  &:before, &:after {
    content: "";
    position: absolute;
    display: inline-block;
    width: var(--size-off);
    height: var(--size-off);
    border-radius: 50%;

    inset-inline-start: var(--gap-off);
    top: var(--gap-off);

    transition: inset-inline-start 0.3s ease, top .3s ease, width .3s ease, height .3s ease, background .3s ease, box-shadow 0.1s ease, transform .1s ease;
  }

  // NOT CHECKED [DOT]
  &:after {
    background-color: var(--md-sys-color-outline);
    height: var(--size-off);
    width: var(--size-off);
    //@extend .surface-variant;
    //box-shadow: 0px 3px 1px -2px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 1px 5px 0px rgba(0, 0, 0, 0.12);
  }
}

input[type=checkbox]:not(:disabled) ~ .lever:active:before,
input[type=checkbox]:not(:disabled).tabbed:focus ~ .lever::before,
input[type=checkbox]:not(:disabled) ~ .lever:hover::before {
    transform: scale(2.4);
}

input[type=checkbox]:checked:not(:disabled) ~ .lever:hover::before {
  background-color: color-mix(in srgb, transparent, var(--md-sys-color-primary) 6%);
}

// Switch active style
input[type=checkbox]:checked:not(:disabled) ~ .lever:active::before,
input[type=checkbox]:checked:not(:disabled).tabbed:focus ~ .lever::before {
  background-color: color-mix(in srgb, transparent, var(--md-sys-color-primary) 18%);
}

input[type=checkbox]:not(:disabled) ~ .lever:hover::before {
  background-color: rgba(0, 0, 0, 0.04);
}

input[type=checkbox]:not(:disabled) ~ .lever:active:before,
input[type=checkbox]:not(:disabled).tabbed:focus ~ .lever::before {
  background-color: rgba(0, 0, 0, 0.12);
}

// Disabled Styles
.switch input[type=checkbox][disabled] + .lever {
  cursor: default;
  opacity: 0.5;
}

/* Optional icon-thumb variation for Materialize switches. */
.switch.switch-with-icon {
  --size-off: 24px;
}

.switch.switch-with-icon label .lever::after {
  content: var(--switch-icon-off, "\e5cd"); /* close */
  display: grid;
  place-items: center;
  font-family: "Material Icons";
  font-feature-settings: "liga";
  text-transform: none;
  letter-spacing: normal;
  white-space: nowrap;
  font-size: var(--icon-size);
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  color: var(--md-sys-color-surface);
}

.switch.switch-with-icon label input[type="checkbox"]:checked + .lever::after {
  content: var(--switch-icon-on, "\e5ca"); /* check */
  color: var(--md-sys-color-primary);
}

.switch label input[type="checkbox"]:focus-visible + .lever {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 4px;
}

/// Preview the pointer position while the native checked state waits for release.
.switch label input[type="checkbox"] + .lever.is-dragging {
  --switch-drag-size: calc(var(--size-off) + (var(--size-on) - var(--size-off)) * var(--switch-drag-progress));
  background-color: color-mix(in srgb, var(--md-sys-color-primary) var(--switch-drag-percent), var(--md-sys-color-surface-variant));
  border-color: color-mix(in srgb, var(--md-sys-color-primary) var(--switch-drag-percent), var(--md-sys-color-outline));
  transition: none;

  &::before,
  &::after {
    width: var(--switch-drag-size);
    height: var(--switch-drag-size);
    top: calc((var(--track-height) - var(--switch-drag-size)) / 2 - var(--border-width));
    inset-inline-start: calc(var(--track-height) / 2 - var(--border-width) + (var(--track-width) - var(--track-height)) * var(--switch-drag-progress) - var(--switch-drag-size) / 2);
    transition: none;
  }

  &::after {
    background-color: color-mix(in srgb, var(--md-sys-color-surface) var(--switch-drag-percent), var(--md-sys-color-outline));
  }
}

// Keep the drag halo equally visible for plain and icon thumbs, on either side.
.switch label input[type="checkbox"]:not(:disabled) + .lever.is-dragging::before {
  width: var(--size-on);
  height: var(--size-on);
  top: var(--gap-on);
  inset-inline-start: calc(var(--track-height) / 2 - var(--border-width) + (var(--track-width) - var(--track-height)) * var(--switch-drag-progress) - var(--size-on) / 2);
  transform: scale(2.4);
  background-color: color-mix(in srgb, transparent, var(--md-sys-color-primary) 18%);
  pointer-events: none;
}

.switch.switch-with-icon label input[type="checkbox"] + .lever.is-dragging::after {
  content: var(--switch-icon-off, "\e5cd");
  color: color-mix(in srgb, var(--md-sys-color-primary) var(--switch-drag-percent), var(--md-sys-color-surface));
}

.switch.switch-with-icon label input[type="checkbox"] + .lever.is-dragging.is-drag-on::after {
  content: var(--switch-icon-on, "\e5ca");
}

@media (prefers-reduced-motion: reduce) {
  .switch label .lever,
  .switch label .lever::before,
  .switch label .lever::after { transition: none; }
}
