:host {
  --background-color: var(--wa-form-control-background-color);
  --background-color-checked: var(--wa-form-control-activated-color);
  --border-color: var(--wa-form-control-border-color);
  --border-color-checked: var(--background-color-checked);
  --border-style: var(--wa-form-control-border-style);
  --border-width: var(--wa-form-control-border-width);
  --box-shadow: initial;
  --height: calc(1em * var(--wa-form-control-value-line-height));
  --thumb-color: var(--wa-form-control-border-color);
  --thumb-color-checked: var(--wa-form-control-background-color);
  --thumb-shadow: initial;
  --thumb-size: calc((var(--height) - var(--border-width) * 2) * 0.75);
  --width: calc(var(--height) * 1.75);

  display: inline-flex;
}

label {
  position: relative;
  display: flex;
  align-items: center;
  font: inherit;
  color: var(--wa-form-control-value-color);
  vertical-align: middle;
  cursor: pointer;
}

.switch {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--width);
  height: var(--height);
  background-color: var(--background-color);
  border-color: var(--border-color);
  border-radius: var(--height);
  border-style: var(--border-style);
  border-width: var(--border-width);
  box-shadow: var(--box-shadow);
  transition-property: translate, background, border-color, box-shadow;
  transition-duration: var(--wa-transition-normal);
  transition-timing-function: var(--wa-transition-easing);
}

.switch .thumb {
  width: var(--thumb-size);
  height: var(--thumb-size);
  background-color: var(--thumb-color);
  border-radius: 50%;
  box-shadow: var(--thumb-shadow);
  translate: calc((var(--width) - var(--height)) / -2);
  transition: inherit;
}

.input {
  position: absolute;
  opacity: 0;
  padding: 0;
  margin: 0;
  pointer-events: none;
}

/* Focus */
label:not(.disabled) .input:focus-visible ~ .switch .thumb {
  outline: var(--wa-focus-ring);
  outline-offset: var(--wa-focus-ring-offset);
}

/* Checked */
.checked .switch {
  background-color: var(--background-color-checked);
  border-color: var(--border-color-checked);
}

.checked .switch .thumb {
  background-color: var(--thumb-color-checked);
  translate: calc((var(--width) - var(--height)) / 2);
}

/* Disabled */
label:has(> :disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

[part~='label'] {
  display: inline-block;
  line-height: var(--height);
  margin-inline-start: 0.5em;
  user-select: none;
  -webkit-user-select: none;
}

:host([required]) [part~='label']::after {
  content: var(--wa-form-control-required-content);
  color: var(--wa-form-control-required-content-color);
  margin-inline-start: var(--wa-form-control-required-content-offset);
}

@media (forced-colors: active) {
  :checked:enabled + .switch:hover .thumb,
  :checked + .switch .thumb {
    background-color: ButtonText;
  }
}
