/*
 * Switch — an on/off toggle that is a real checkbox underneath, so it submits
 * like one and works with the keyboard (Space toggles it).
 * <label class="switch">
 *   <input type="checkbox" class="switch__input" role="switch">
 *   <span class="switch__track" aria-hidden="true"></span>
 *   <span class="switch__label">Update stock</span>
 * </label>
 */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
}

/* The checkbox stays in the page (for forms and screen readers) but invisible */
.switch__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch__track {
  position: relative;
  flex-shrink: 0;
  width: 2.25rem;
  height: 1.25rem;
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
  transition: background-color var(--duration-fast) var(--ease-out);

  /* The knob */
  &::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc(1.25rem - 4px);
    height: calc(1.25rem - 4px);
    border-radius: var(--radius-full);
    background: var(--white);
    box-shadow: var(--shadow-xs);
    transition: transform var(--duration-fast) var(--ease-out);
  }
}

.switch__input:checked + .switch__track {
  background: var(--color-primary);

  &::after {
    transform: translateX(1rem);
  }
}

.switch__input:focus-visible + .switch__track {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.switch__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
}
