$button-color-base-fg: color(ui, button-base-fg);
$button-color-base-bg: transparent;
$button-color-border: color(ui, button-base-fg);
$button-box-shadow: z-depth(0);

button:not(.button):not(.button-text),
a[role='button']:not(.button):not(.button-text),
.button {
  padding: 0 2em;
  height: 2.9rem;
  border: 1px solid $button-color-border;
  background: $button-color-base-bg;
  box-shadow: $button-box-shadow;
  color: $button-color-base-fg;
  cursor: pointer;
  fill: $button-color-base-fg;

  &:not(:last-of-type) {
    margin-right: 0.5em;
  }

  &:hover {
    background: transparentize(
      $color: scale-color($button-color-base-fg, $lightness: 85%),
      $amount: 0.85
    );
    box-shadow: z-depth(2);
    color: scale-color($button-color-base-fg, $lightness: 12.5%);
  }

  &:active {
    background: $button-color-base-bg;
    box-shadow: z-depth(1);
    color: $button-color-base-fg;
  }

  &[disabled] {
    box-shadow: none;
    opacity: 0.6;
    filter: grayscale(0.6);
    cursor: default;
    pointer-events: none;
  }
}

a[role='button'] {
  @include no-anchor-underline();

  display: inline-flex;
  align-items: center;
  justify-content: center;
}

[role='button'].button-primary,
.button-primary {
  $button-primary-color-fg: color(white);
  $button-primary-color-bg: color(primary);

  border-color: $button-primary-color-bg;
  background: $button-primary-color-bg;
  color: $button-primary-color-fg;

  &:hover {
    background: scale-color($button-primary-color-bg, $lightness: 10%);
    color: $button-primary-color-fg;
  }

  &:active {
    background: scale-color($button-primary-color-bg, $lightness: -12.5%);
    color: $button-primary-color-fg;
  }
}

.button-minimal,
.button-text {
  $button-text-color-fg: color(ui, link);
  $button-text-color-bg: transparent;

  display: inline-block;
  padding: 0;
  height: auto;
  border: 0;
  box-shadow: none;
  color: $button-text-color-fg;

  &:active,
  &:hover {
    background: $button-text-color-bg;
    box-shadow: none;
  }

  &:hover {
    color: scale-color($color: $button-text-color-fg, $lightness: 25%);
  }

  &:active {
    color: $button-text-color-fg;
  }
}

.button-minimal {
  &:active,
  &:hover {
    background: inherit;
  }
}

.button-sm,
.button-small {
  height: 2.4rem;
  font-size: font-size(-1);
}

.button-mini {
  height: 2rem;
  font-size: font-size(-1);
}

.button-dynamic {
  @include button-style(dynamic);
}

.button-busy {
  @include button-style(busy);
}

.button-success {
  @include button-style(success);
}

.touchevents {
  // Enlarges the click area without enlarging the UI element
  .button-sm,
  .button-mini {
    position: relative;
    &:after {
      content: '';
      position: absolute;
      top: -10px;
      bottom: -10px;
      left: -10px;
      right: -10px;
      min-height: 44px;
    }
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.button-dropdown {
  position: relative;
  display: inline-flex;
  min-width: 0;

  &.button {
    padding: 0;
    border: 0;
  }

  .button {
    min-width: 0;
    box-shadow: none;
  }

  .button:first-child {
    flex: 1;
    padding-right: padding(0.25);
    padding-left: padding(1);
    text-align: left;
  }

  .button-text {
    border: 0;
    color: inherit;

    & ~ .button-dropdown_icon {
      color: inherit;
    }
  }

  input:focus {
    & + .button-dropdown_icon {
      outline: 1px dotted;
    }
  }

  .button-dropdown_icon {
    display: flex;
    padding-right: padding(0.25);
    padding-left: padding(0.25);
    border: 1px transparent solid;
    font-size: initial;
    align-items: center;

    .icon {
      display: inline-block;
      margin: auto margin(0.125);
      vertical-align: middle;
    }
  }

  .button-secondary,
  .button-text {
    & ~ .button-dropdown_icon {
      background-color: transparent;
      transition: background-color 200ms;

      &:hover {
        background-color: rgba(color(gray, plus4), 0.5);
        transition: background-color 200ms;
      }
    }
  }

  .button-dropdown_trigger {
    & ~ .button-dropdown_content {
      display: none;
      visibility: hidden;
    }

    &:checked {
      & ~ .button-dropdown_content {
        @include z-depth(2);

        position: absolute;
        top: 100%;
        right: 0;
        z-index: 1;
        display: block;
        visibility: visible;
        padding: padding(1);
        background: color(white);
        color: initial;
        font-weight: initial;
        font-size: initial;
        opacity: 1;
        animation: appear 0.5s;
      }
    }
  }
}

@keyframes appear {
  0% {
    display: none;
    visibility: hidden;
    opacity: 0;
  }

  1% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}
