/**
 * @file
 * Checkbox and radio input elements.
 */

/**
 * Form item modifiers.
 */
.form-type--boolean {
  margin-inline-start: var(--input--label-spacing);
  line-height: var(--space-l);
}

/**
 * Radio and checkbox items that are the child of a form item.
 */
.form-type--boolean .form-boolean {
  position: relative;
  inset-block-start: calc(var(--space-l) / 2);
  float: left; /* LTR */
  margin-inline-start: calc(var(--input--label-spacing) * -1);
  transform: translateY(-50%);

  @nest [dir="rtl"] & {
    float: right;
  }
}

.form-type--boolean.form-item--no-label {
  margin-inline-start: 0;
}

.form-type--boolean.form-item--no-label .form-boolean {
  position: static;
  float: none;
  margin-inline: 0;
  transform: none;
}

/**
 * When form items are nested in radios or checkboxes group, reduce the default
 * space between them.
 */
.form-boolean-group .form-type--boolean {
  margin-block: 0.4em;
}

/**
 * Input appearance.
 */
.form-boolean {
  display: inline-block;
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  vertical-align: text-bottom;
  border: 1px solid var(--input-border-color);
  border-radius: 2px;
  background: var(--input-bg-color) no-repeat 50% 50%;
  background-size: 100% 100%;
  box-shadow: 0 0 0 4px transparent;
  appearance: none;

  &:active,
  &:hover {
    border-color: var(--input-fg-color);
    box-shadow: inset 0 0 0 1px var(--input-fg-color);
  }

  &:focus:active,
  &:focus:hover {
    box-shadow:
      0 0 0 2px var(--color-white),
      0 0 0 5px var(--color-focus),
      inset 0 0 0 1px var(--input-fg-color);
  }
}

@media (forced-colors: active) {
  .form-boolean {
    appearance: auto;
  }
}

.form-boolean--type-radio {
  width: 19px;
  height: 19px;
  border-radius: 19px;

  &:checked {
    border-color: var(--input--focus-border-color);
    background-image: url(../../images/icons/003ecc/circle.svg);
    box-shadow: inset 0 0 0 1px var(--input--focus-border-color);

    &:focus {
      box-shadow:
        0 0 0 2px var(--color-white),
        0 0 0 5px var(--color-focus),
        inset 0 0 0 1px var(--input--focus-border-color);

      &:active,
      &:hover {
        box-shadow:
          0 0 0 2px var(--color-white),
          0 0 0 5px var(--color-focus),
          inset 0 0 0 1px var(--input-fg-color);
      }
    }
    &:active,
    &:hover {
      border-color: var(--input-fg-color);
      background-image: url(../../images/icons/000f33/circle.svg);
      box-shadow: inset 0 0 0 1px var(--input-fg-color);
    }
  }
}
.form-boolean--type-checkbox:checked {
  border-color: var(--input--focus-border-color);
  background-color: var(--input--focus-border-color);
  background-image: url(../../images/icons/ffffff/checkmark-sm.svg);

  &:active,
  &:hover {
    border-color: var(--input-fg-color);
    background-color: var(--input-fg-color);
  }
}

/**
 * Error states.
 */
.form-boolean.error {
  border-color: var(--input--error-border-color);
  background-color: var(--input-bg-color);
  box-shadow: inset 0 0 0 1px var(--input--error-border-color);
  &:active,
  &:hover {
    box-shadow: inset 0 0 0 1px var(--input--error-border-color);
  }
  &:focus,
  &:focus:active,
  &:focus:hover {
    box-shadow:
      0 0 0 2px var(--color-white),
      0 0 0 5px var(--color-focus),
      inset 0 0 0 1px var(--input--error-border-color);
  }
  &:checked:active,
  &:checked:hover {
    border-color: var(--input--error-border-color);
    background-color: var(--input-bg-color);
  }
}
.form-boolean--type-checkbox.error:checked,
.form-boolean--type-checkbox.error:checked:active,
.form-boolean--type-checkbox.error:checked:hover {
  background-color: var(--input--error-border-color);
}
.form-boolean--type-radio.error:checked,
.form-boolean--type-radio.error:checked:active,
.form-boolean--type-radio.error:checked:hover {
  background-image: url(../../images/icons/d72222/circle.svg);
}
.form-boolean--type-radio.error:checked:focus {
  box-shadow:
    0 0 0 2px var(--color-white),
    0 0 0 5px var(--color-focus),
    inset 0 0 0 1px var(--input--error-border-color);
}

/**
 * Disabled states.
 */
.form-boolean[disabled],
.form-boolean[disabled]:hover,
.form-boolean[disabled].error,
.form-boolean[disabled].error:hover,
.form-boolean--type-radio[disabled]:focus:active,
.form-boolean--type-radio[disabled]:active:hover,
.form-boolean--type-radio[disabled].error:active:hover {
  border-color: var(--input--disabled-border-color);
  background-color: var(--input--disabled-bg-color);
  background-image: none;
  box-shadow: none;
}
.form-boolean--type-checkbox[disabled]:checked {
  background-image: url(../../images/icons/82828c/checkmark.svg);
}
.form-boolean--type-radio[disabled]:checked,
.form-boolean--type-radio[disabled].error:checked {
  background-image: url(../../images/icons/82828c/circle.svg);
}
