/**
  * Custom switch control, base
  */
.sui-SwitchMark {
  /* Background and border colours are computed relatively in hover states;
     we use custom properties to make this easier */
  --background-color: var(--backdrop);
  --border-color: var(--separator-high);
  /* Switch size stored as custom properties to be used with calc
     for active switch marker's x-axis translation */
  --width: 25px;
  --height: 17px;
  background-color: var(--background-color);
  border: 1px solid var(--border-color);
  width: var(--width);
  height: var(--height);
  transition: var(--hover-transition);
}

/**
  * Custom switch marker
  */
.sui-SwitchMark:after {
  content: '';
  display: block;
  background-color: var(--foreground-high);
  width: 7px;
  height: 7px;
  border-radius: var(--radius-round);
  translate: 50%;
  transition: translate 100ms linear;
}

/**
  * Hover - uses relative border/background colours to darken/lighten in both normal & error state
  */
/** Switch border (unchecked) */
.sui-Switch:hover .sui-SwitchMark {
  border-color: light-dark(
    oklch(from var(--border-color) calc(l - var(--hover-lightness-delta)) c h),
    oklch(from var(--border-color) calc(l + var(--hover-lightness-delta)) c h)
  );
}

/* Switch background (checked) */
.sui-Switch:hover .sui-SwitchInput:is(:checked) + .sui-SwitchMark {
  background-color: light-dark(
    oklch(from var(--background-color) calc(l - var(--hover-lightness-delta)) c h),
    oklch(from var(--background-color) calc(l + var(--hover-lightness-delta)) c h)
  );
}

/**
  * Focus
  */
.sui-SwitchInput:focus-visible + .sui-SwitchMark {
  outline: var(--focus-outline);
  outline-offset: var(--focus-offset);
}

/**
  * Checked
  */
.sui-SwitchInput:checked + .sui-SwitchMark {
  --background-color: var(--active-background-emphasized);
  --border-color: transparent;
}

.sui-SwitchInput:checked + .sui-SwitchMark:after {
  background-color: var(--active-foreground-emphasized);
  translate: calc(var(--width) - 175%);
}

/**
  * Disabled
  */
.sui-SwitchInput:disabled + .sui-SwitchMark {
  --background-color: var(--inert-background);
  --border-color: var(--separator-low);
}

.sui-SwitchInput:disabled + .sui-SwitchMark:after {
  background: var(--inert-foreground);
}

/* Turn hover (and all pointer events) off for disabled switches */
.sui-Switch:has(:disabled) {
  pointer-events: none;
}

/**
  * Disabled and checked
  */
.sui-SwitchInput:disabled:checked + .sui-SwitchMark {
  --background-color: var(--inert-foreground);
  --border-color: transparent;
}

.sui-SwitchInput:disabled:checked + .sui-SwitchMark:after {
  background-color: var(--inert-background);
}

/**
  * Error
  */
.sui-SwitchMark.sui-error {
  --border-color: var(--error-separator);
}

.sui-SwitchMark.sui-error:after {
  background-color: var(--error-separator);
}

/**
  * Error and checked
  */
.sui-SwitchInput:checked + .sui-SwitchMark.sui-error {
  --background-color: var(--error-background-emphasized);
}
