/**
* Base Button styles
*
* Common styles across all button types, styles, and states.
*/
.cds-button {
  border-radius: $border-radius-default;
  font-family: $base-font;
  font-weight: $font-weight-medium;
  letter-spacing: $letter-spacing-default;
  position: relative;
  border: 1px solid transparent;
  font-size: $font-size-default;
  line-height: $line-height-tight;
  padding: $unit-1 $unit-2;

  svg.cds-button__icon {
    margin-bottom: -3px;
  }

  .cds-button__loadingAnimation {
    height: $unit-3 - $unit-half;
    width: $unit-3 - $unit-half;
    animation: simpleLoader 1.6s linear infinite;
    border: 3px solid #165cab;
    border-color: rgba(255, 255, 255, 1) rgba(255, 255, 255, 0.2) rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    bottom: 0;
    box-sizing: border-box;
    display: inline-block;
    left: 0;
    margin: auto;
    position: absolute;
    right: 0;
    top: 0;
    display: none;
  }

  &:hover {
    transition: $transition-natural;
  }

  &.cds-button--sizeSmall {
    font-size: $font-size-small;
    line-height: $line-height-small-font;
    padding: $unit-half $unit-1;

    .cds-button__loadingAnimation {
      border-width: 2px;
      height: $unit-2 - $unit-half;
      width: $unit-2 - $unit-half;
    }
  }

  &.cds-button--sizeLarge {
    font-size: $font-size-large;
    line-height: $line-height-default;
    padding: $unit-1 $unit-5;

    .cds-button__loadingAnimation {
      height: $unit-3;
      width: $unit-3;
    }
  }

  &.cds-button--stateLoading {
    .cds-button__content {
      visibility: hidden;
    }

    .cds-button__loadingAnimation {
      display: inline-block;
    }
  }

  /**
  * Button Styles
  */
  &.cds-button--variantNeutral {
    background: $background-neutral;
    border: $border-gray-400;
    box-shadow: $box-shadow-neutral;
    color: $color-gray-700;

    svg.cds-button__icon {
      fill: $color-gray-700;
    }

    &:hover {
      border: $border-gray-700;
      box-shadow: $box-shadow-neutral-hover;
      color: $color-gray-1000;
    }

    &.cds-button--stateSelected {
      background: $color-primary-selection;
      border: 1px solid $color-primary-focus;
      box-shadow: $box-shadow-inset-light;
      color: $color-white;

      svg.cds-button__icon {
        fill: $color-white;
      }
    }

    &:focus {
      @include focus-default;
    }

    &:active,
    &.cds-button--stateLoading {
      background: $color-gray-200;
      border: $border-gray-700;
      box-shadow: $box-shadow-inset-light;
      color: $color-gray-1000;
    }
  }

  &.cds-button--variantPrimary {
    background: $background-primary;
    border: $border-primary-dark;
    box-shadow: $box-shadow-primary;
    color: $color-white;

    svg.cds-button__icon {
      fill: $color-white;
    }

    &:hover {
      box-shadow: $box-shadow-primary-hover;

      svg.cds-button__icon {
        fill: $color-white;
      }
    }

    &:active,
    &.cds-button--stateLoading,
    &.cds-button--stateSelected {
      box-shadow: $box-shadow-inset-dark;

      svg.cds-button__icon {
        fill: $color-white;
      }
    }

    &:focus {
      @include focus-default;
    }
  }

  &.cds-button--variantDestructive {
    background: $background-error;
    border: $border-error-800;
    box-shadow: $box-shadow-error;
    color: $color-white;

    svg.cds-button__icon {
      fill: $color-white;
    }

    &:hover {
      border: $border-error-900;
      box-shadow: none;

      svg.cds-button__icon {
        fill: $color-white;
      }
    }

    &:active,
    &.cds-button--stateLoading,
    &.cds-button--stateSelected {
      border: $border-error-900;
      box-shadow: $box-shadow-inset-light;

      svg.cds-button__icon {
        fill: $color-white;
      }
    }

    &:focus {
      @include focus-default;
    }
  }

  // Disabled styles for all variants but Naked

  &:disabled,
  &:disabled:hover,
  &:disabled:active,
  &:disabled:focus {
    background-color: $color-gray-200;
    border: $border-gray-300;
    box-shadow: none;
    color: $color-gray-400;

    svg.cds-button__icon {
      fill: $color-gray-400;
    }
  }

  &.cds-button--variantNaked {
    border: 1px solid transparent;
    background-color: transparent;
    color: $color-gray-700;

    &:hover {
      border: $border-gray-300;
      color: $color-gray-1000;
      background: $color-gray-50;

      svg.cds-button__icon {
        fill: $color-gray-1000;
      }
    }

    svg.cds-button__icon {
      fill: $color-gray-700;
    }

    &:focus {
      @include focus-default;
    }

    &.cds-button--stateSelected {
      background: $color-primary-selection;
      border: 1px solid $color-primary-focus;
      color: $color-white;

      svg.cds-button__icon {
        fill: $color-white;
      }
    }

    &:active,
    &.cds-button--stateLoading {
      background: $color-gray-100;
      border: $border-gray-400;
      box-shadow: $box-shadow-inset-light;
      color: $color-gray-1000;
    }

    &:disabled,
    &:disabled:hover,
    &:disabled:active,
    &:disabled:focus {
      background-color: $color-gray-100;
      border: $border-gray-200;
      box-shadow: none;
      color: $color-gray-400;

      svg.cds-button__icon {
        fill: $color-gray-400;
      }
    }
  }
}

@keyframes simpleLoader {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}
