@mixin btn-default {
  border-radius: 3px;
  font-size: $gl-font-size;
  font-weight: 400;
  padding: $gl-vert-padding $gl-btn-padding;

  &:focus,
  &:active {
    background-color: $btn-active-gray;
    box-shadow: $gl-btn-active-background;
  }
}

@mixin btn-middle {
  @include btn-default;
}

@mixin btn-outline($background, $text, $border, $hover-background, $hover-text, $hover-border, $active-background, $active-border) {
  background-color: $background;
  color: $text;
  border-color: $border;

  &:hover,
  &:focus {
    background-color: $hover-background;
    border-color: $hover-border;
    color: $hover-text;
  }

  &:active {
    background-color: $active-background;
    border-color: $active-border;
    color: $hover-text;
  }
}

@mixin btn-color($light, $border-light, $normal, $border-normal, $dark, $border-dark, $color) {
  background-color: $light;
  border-color: $border-light;
  color: $color;

  &:hover,
  &:focus {
    background-color: $normal;
    border-color: $border-normal;
    color: $color;
  }

  &:active,
  &.active {
    box-shadow: $gl-btn-active-background;

    background-color: $dark;
    border-color: $border-dark;
    color: $color;
  }

  svg {

    path {
      fill: $color;
    }

    use {
      stroke: $color;
    }
  }
}

@mixin btn-green {
  @include btn-color($green-light, $border-green-light, $green-normal, $border-green-normal, $green-dark, $border-green-dark, $white-light);
}

@mixin btn-blue {
  @include btn-color($blue-light, $border-blue-light, $blue-normal, $border-blue-normal, $blue-dark, $border-blue-dark, $white-light);
}

@mixin btn-blue-medium {
  @include btn-color($blue-medium-light, $border-blue-light, $blue-medium, $border-blue-normal, $blue-medium-dark, $border-blue-dark, $white-light);
}

@mixin btn-orange {
  @include btn-color($orange-light, $border-orange-light, $orange-normal, $border-orange-normal, $orange-dark, $border-orange-dark, $white-light);
}

@mixin btn-red {
  @include btn-color($red-light, $border-red-light, $red-normal, $border-red-normal, $red-dark, $border-red-dark, $white-light);
}

@mixin btn-gray {
  @include btn-color($gray-light, $border-gray-normal, $gray-normal, $border-gray-normal, $gray-dark, $border-gray-dark, $gl-text-color);
}

@mixin btn-white {
  @include btn-color($white-light, $border-color, $white-normal, $border-white-normal, $white-dark, $border-gray-dark, $gl-text-color);
}

@mixin btn-with-margin {
  margin-left: $btn-side-margin;
  float: left;

  &.inline {
    float: none;
  }

  &.btn-sm {
    margin-left: $btn-sm-side-margin;
  }

  &.btn-xs {
    margin-left: $btn-xs-side-margin;
  }
}

.btn {
  @include btn-default;
  @include btn-white;

  color: $gl-text-color;

  &:focus:active {
    outline: 0;
  }

  &.btn-small,
  &.btn-sm {
    padding: 4px 10px;
    font-size: 13px;
    line-height: 18px;
  }

  &.btn-xs {
    padding: 2px 5px;
  }

  &.btn-success,
  &.btn-new,
  &.btn-create,
  &.btn-save {
    @include btn-green;
  }

  &.btn-inverted {
    &.btn-success,
    &.btn-new,
    &.btn-create,
    &.btn-save {
      @include btn-outline($white-light, $border-green-light, $border-green-light, $green-light, $white-light, $border-green-light, $green-normal, $border-green-normal);
    }

    &.btn-remove {
      @include btn-outline($white-light, $border-red-light, $border-red-light, $red-light, $white-light, $border-red-light, $red-normal, $border-red-normal);
    }
  }

  &.btn-gray {
    @include btn-gray;
  }

  &.btn-primary {
    @include btn-blue-medium;
  }

  &.btn-info,
  &.btn-register {
    @include btn-blue;
  }

  &.btn-warning {
    @include btn-orange;
  }

  &.btn-close {
    @include btn-outline($white-light, $border-orange-light, $border-orange-light, $orange-light, $white-light, $border-orange-light, $orange-normal, $border-orange-normal);
  }

  &.btn-spam {
    @include btn-outline($white-light, $border-red-light, $border-red-light, $red-light, $white-light, $border-red-light, $red-normal, $border-red-normal);
  }

  &.btn-danger,
  &.btn-remove,
  &.btn-red {
    @include btn-red;
  }

  &.btn-cancel {
    float: right;
  }

  &.btn-reopen {
    /* should be same as parent class for now */
  }

  &.btn-grouped {
    @include btn-with-margin;
  }

  &.disabled {
    pointer-events: auto !important;
  }

  &[disabled] {
    pointer-events: none !important;
  }

  .fa-caret-down,
  .fa-chevron-down {
    margin-left: 5px;
  }

  &.dropdown-toggle {
    .fa-caret-down {
      margin-left: 3px;
    }
  }

  svg {
    height: 15px;
    width: 15px;
    position: relative;
    top: 2px;
  }

  svg,
  .fa {
    &:not(:last-child) {
      margin-right: 5px;
    }
  }
}

.btn-terminal {
  svg {
    height: 14px;
    width: 18px;
  }
}

.btn-lg {
  padding: 12px 20px;
}

.btn-transparent {
  color: $gl-text-color-secondary;
  background-color: transparent;
  border: 0;

  &:hover,
  &:active,
  &:focus {
    background-color: transparent;
    box-shadow: none;
  }
}

.btn-block {
  width: 100%;
  margin: 0;
  margin-bottom: 15px;

  &.btn {
    padding: 6px 0;
  }
}

.btn-group {
  &.btn-grouped {
    @include btn-with-margin;
  }
}

.btn-clipboard {
  border: none;
  padding: 0 5px;
}

.input-group-btn {
  .btn {
    @include btn-middle;

    &:hover {
      outline: none;
    }

    &:active {
      outline: none;
    }

    &.btn-clipboard {
      padding-left: 15px;
      padding-right: 15px;
    }
  }

  .active {
    box-shadow: $gl-btn-active-background;

    border: 1px solid $border-gray-dark !important;
    background-color: $btn-active-gray-light !important;
  }
}

.btn-loading {
  &:not(.disabled) .fa {
    display: none;
  }

  .fa {
    margin-right: 5px;
  }
}

.btn-text-field {
  width: 100%;
  text-align: left;
  padding: 6px 16px;
  border-color: $border-color;
  color: $gray-darkest;
  background-color: $gray-light;

  &:hover,
  &:active,
  &:focus {
    cursor: text;
    box-shadow: none;
    border-color: lighten($dropdown-input-focus-border, 20%);
    color: $gray-darkest;
    background-color: $gray-light;
  }
}

.btn-build {
  margin-left: 10px;

  i {
    color: $gl-text-color-secondary;
  }
}

.clone-dropdown-btn a {
  color: $dropdown-link-color;

  &:hover {
    text-decoration: none;
  }
}

.btn-static {
  background-color: $gray-light !important;
  border: 1px solid $border-gray-normal;
  cursor: default;

  &:active {
    -moz-box-shadow: inset 0 0 0 $white-light;
    -webkit-box-shadow: inset 0 0 0 $white-light;
    box-shadow: inset 0 0 0 $white-light;
  }
}

.btn-inverted {
  &-secondary {
    @include btn-outline($white-light, $border-blue-light, $border-blue-light, $blue-light, $white-light, $border-blue-light, $blue-normal, $border-blue-normal);
  }
}

@media (max-width: $screen-xs-max) {
  .btn-wide-on-xs {
    width: 100%;
  }
}
