@import '@lightspeed/cirrus-tokens/index.scss';

$cr-checkbox-focus-shadow: 0 0 0 1px $cr-snow, 0 0 0 3px $cr-blue;
$cr-checkbox-checkmark-class: 'cr-checkbox__checkmark';

.cr-checkbox {
  position: relative;
  line-height: 1rem;
}

.cr-checkbox__label {
  position: relative;
  display: inline-flex;
}

.cr-checkbox__input {
  position: absolute;
  width: 1rem;
  height: 1rem;
  top: 0;
  left: 0;
  opacity: 0;
  padding: 0;
  margin: 0;
  z-index: 1;

  &:indeterminate + .#{$cr-checkbox-checkmark-class} {
    border-color: $cr-blue;
  }

  &:checked + .#{$cr-checkbox-checkmark-class} {
    background-color: $cr-blue;
    border-color: $cr-blue-300;
    background-image: none;
  }

  &:focus + .#{$cr-checkbox-checkmark-class} {
    box-shadow: $cr-checkbox-focus-shadow;
  }

  &[disabled] + .#{$cr-checkbox-checkmark-class} {
    opacity: 0.5;
  }
}

.#{$cr-checkbox-checkmark-class} {
  position: relative;
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
  border-radius: $cr-radius-1;
  background-color: transparent;
  border: solid 1px $cr-gray-200;
  box-sizing: border-box;
  overflow: hidden;
  cursor: default;
  background-image: linear-gradient(180deg, $cr-snow, $cr-snow-200);

  .cr-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    fill: $cr-snow;
  }
}

.cr-checkbox__indeterminate {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 0.5rem;
  height: 0.125rem;
  border-radius: $cr-radius-1;
  background: $cr-blue-300;
}

.cr-checkbox__text {
  margin-left: $cr-spacing-2;
}

.cr-checkbox__description {
  margin-left: calc(1rem + #{$cr-spacing-2});
}
