.checkbox-group,
.radio-group {
  @include list-reset;
}

input {
  &.rb-checkbox[type='checkbox'],
  &[type='radio'] {
    @extend %visuallyhidden;

    & + label {
      position: relative;
      padding-left: 1.25rem;
      font-weight: font-weight(normal);
    }

    &[disabled] + label {
      &::before {
        border: 1px solid color(gray, plus4);
        background: color(gray, plus4);
      }
    }
  }

  &[type='radio'] {
    & + label {
      align-self: flex-start;

      &::before {
        position: absolute;
        top: 0.1rem;
        left: 0;
        width: 1rem;
        height: 1rem;
        border: 1px solid color(gray, plus2);
        border-radius: 100%;
        background: color(white);
        content: '';
        transition: border 200ms ease-in, background 200ms ease-in;
      }

      &:hover::before {
        border: 6px solid rgba(color(gray), 0.2);
        background: color(white);
        transition: color 200ms ease-in, background 200ms ease-in;
      }
    }

    &:checked + label {
      &::before {
        border: 6px solid color(black);
        background: color(white);
        transition: border 200ms ease-in, background 200ms ease-in;
      }
    }

    &[disabled] {
      & + label:hover::before {
        border: none;
        background: color(gray, plus4);
      }

      &[checked] + label {
        &::before {
          border: 6px solid color(gray, plus4);
          background: color(gray, plus2);
        }
      }
    }
  }

  &.rb-checkbox[type='checkbox'] {
    $color-white: color(white);
    $color-selected: color(black);
    $color-unselected: color(gray, plus3);

    & + label {
      &::before {
        position: absolute;
        top: 0.1rem;
        left: 0;
        width: 1rem;
        height: 1rem;
        border: 1px solid color(gray, plus2);
        background: color(white);
        background-position: center center;
        content: '';
        transition: background-color 200ms ease-in;
      }

      &:hover::before {
        $color-fill: $color-white;
        border-color: transparent;
        background-color: $color-unselected;
        background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' style='fill: white%3B' viewBox='0 0 16 16'%3E%3Cpath d='M1 9.185c-.42-.342-.527-.92-.125-1.31.401-.388.922-.281 1.269.125l3.278 3.375L13.842 3c.513-.572 1-.402 1.288-.137.288.265.4.877-.13 1.308L6.133 13c-.22.251-.458.377-.71.377-.253 0-.492-.126-.717-.377L1 9.185z' fill-rule='evenodd'/%3E%3C/svg%3E");
        background-position: center center;
        background-repeat: no-repeat;
        transition: background-color 100ms ease-in, border-color 100ms ease-in;
      }
    }

    &:checked + label {
      &::before {
        $color-fill: $color-white;
        border-color: transparent;
        background-color: $color-selected;
        background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' style='fill: white%3B' viewBox='0 0 16 16'%3E%3Cpath d='M1 9.185c-.42-.342-.527-.92-.125-1.31.401-.388.922-.281 1.269.125l3.278 3.375L13.842 3c.513-.572 1-.402 1.288-.137.288.265.4.877-.13 1.308L6.133 13c-.22.251-.458.377-.71.377-.253 0-.492-.126-.717-.377L1 9.185z' fill-rule='evenodd'/%3E%3C/svg%3E");
        background-position: center center;
        background-repeat: no-repeat;
        transition: background-color 100ms ease-in, border-color 100ms ease-in;
      }
    }

    &:not(:checked) + label {
      &:hover::before {
        .touchevents & {
          border-color: color(gray, plus2);
          background-image: none;
          background-color: white;
        }
      }
    }

    &[disabled] {
      &[checked] + label {
        &::before {
          $color-fill: color(gray, plus2);
          background-color: color(gray, plus4);
          background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' style='fill: %23abadb1%3B' viewBox='0 0 16 16'%3E%3Cpath d='M1 9.185c-.42-.342-.527-.92-.125-1.31.401-.388.922-.281 1.269.125l3.278 3.375L13.842 3c.513-.572 1-.402 1.288-.137.288.265.4.877-.13 1.308L6.133 13c-.22.251-.458.377-.71.377-.253 0-.492-.126-.717-.377L1 9.185z' fill-rule='evenodd'/%3E%3C/svg%3E");
          background-position: center center;
          background-repeat: no-repeat;
        }
      }

      &:not([checked]) + label {
        &::before {
          border-color: transparent;
          background: color(gray, plus4);
        }
      }
    }
  }
}
