
@btn-border: 1px solid @button-border-color;
@btn-padding: 0 @ui-size/1.25;

// Mixins -----------------------

.btn-default (@color, @hover-color, @selected-color, @text-color) {
  color: @text-color;
  text-shadow: none;
  border: @btn-border;
  background-color: @color;
  background-image: linear-gradient(lighten(@color, 2%), @color);

  &:focus {
    //.focus(); // disabled for now, since :focus styles stay even after releasing mouse.
    outline: none;
  }
  &:focus,
  &:hover {
    color: @text-color-highlight;
    background-image: linear-gradient(lighten(@hover-color, 2%), @hover-color);
  }
  &:active {
    background: darken(@color, 4%);
    box-shadow: none;
  }
  &.selected {
    background: @selected-color;
  }
  &.selected:focus,
  &.selected:hover {
    background: lighten(@selected-color, 2%);
  }
}

.btn-variant (@color) {
  @text-color: contrast(@color, hsl(0,0%,25%), white, 70% );
  @bg: @color;
  @hover: lighten(@bg, 3%);
  @selected: saturate(darken(@bg, 12%), 20%);
  .btn-default(@bg, @hover, @selected, @text-color-highlight);
  color: @text-color;
  text-shadow: 0 1px 0 hsla(0,0%,0%,.2);

  & when (@ui-lightness > 50%) {
    border-color: transparent; // hide border on light backgrounds
  }

  &:hover,
  &:focus {
    color: @text-color;
  }


  &.icon:before {
    color: @text-color;
  }
}


// Buttons -----------------------

.btn {
  height: initial;
  padding: @btn-padding;
  font-size: @ui-size;
  line-height: @ui-line-height;
}

.btn,
.btn.btn-default {
  .btn-default(@button-background-color, @button-background-color-hover, @button-background-color-selected, @text-color);
}

.btn.btn-primary {
  .btn-variant(@base-accent-color);
}
.btn.btn-info {
  .btn-variant(@background-color-info);
}
.btn.btn-success {
  .btn-variant(@background-color-success);
}
.btn.btn-warning {
  .btn-variant(@background-color-warning);
}
.btn.btn-error {
  .btn-variant(@background-color-error);
}


// Button Group -----------------------

.btn.btn-xs,
.btn-group-xs > .btn {
  font-size: @ui-size*.8;
  line-height: @ui-line-height;
  padding: @btn-padding;
}
.btn.btn-sm,
.btn-group-sm > .btn {
  font-size: @ui-size*.9;
  line-height: @ui-line-height;
  padding: @btn-padding;
}
.btn.btn-lg,
.btn-group-lg > .btn {
  font-size: @ui-size * 1.5;
  line-height: @ui-line-height;
  padding: @btn-padding;
}


// Button Group -----------------------

.btn-group > .btn {
  z-index: 0;
  &:hover {
    z-index: 0;
  }

  &:first-child {
    border-left: @btn-border;
  }
  &:last-child {
    border-right: @btn-border;
  }

  // hide border on light backgrounds
  & when (@ui-lightness > 50%) {
    &.btn-primary:first-child,
    &.btn-info:first-child,
    &.btn-success:first-child,
    &.btn-warning:first-child,
    &.btn-error:first-child {
      border-left-color: transparent;
    }

    &.btn-primary:last-child,
    &.btn-info:last-child,
    &.btn-success:last-child,
    &.btn-warning:last-child,
    &.btn-error:last-child {
      border-right-color: transparent;
    }
  }

  &.btn:focus {
    z-index: 1;
  }

  &.selected,
  &.selected:first-child,
  &.selected:last-child {
    color: @button-text-color-selected;
    border: 1px solid @button-border-color-selected;
  }
  &.selected + .btn {
    border-left-color: @button-border-color-selected;
  }
}
