@import '../../styles/common';

.Checkbox {
  position: relative;
}

.error {
  // The basic checked styles have more specificity than this, so need to
  // basically duplicate that selector here, too.
  // stylelint-disable-next-line selector-max-specificity
  .Input:checked + .Backdrop,
  .Input.Input-indeterminate + .Backdrop,
  .Backdrop {
    @include control-backdrop(error);
  }

  // We need to know if the input is focusing to change the border color.
  // stylelint-disable-next-line selector-max-specificity
  .Input:focus + .Backdrop,
  .Input:active + .Backdrop {
    @include control-backdrop(focused-error);
  }

  .Icon {
    @include recolor-icon(color('red', 'dark'));
  }
}

.Input {
  @include visually-hidden;

  &:focus,
  &:active,
  &:checked,
  &.Input-indeterminate {
    // stylelint-disable-next-line selector-max-class
    + .Backdrop {
      background: color('indigo');
    }
  }

  &:checked,
  &.Input-indeterminate {
    // stylelint-disable-next-line selector-max-class
    ~ .Icon {
      transform: translate(-50%, -50%) scale(1);
    }
  }

  &:focus,
  &:active {
    + .Backdrop {
      @include control-backdrop(focused);
    }
  }

  &:disabled {
    + .Backdrop {
      @include control-backdrop(disabled);
    }

    ~ .Icon {
      @include recolor-icon(color('ink', 'lightest'));
    }
  }
}

.Backdrop {
  @include control-backdrop;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  pointer-events: none;
}

.Icon {
  @include recolor-icon(color('indigo'));
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  transform-origin: 50% 50%;
  transition: control-icon-transition();
  pointer-events: none;

  @media (-ms-high-contrast: active) {
    fill: ms-high-contrast-color('text');
  }
}
