.button {
    height: $input-height;
    line-height: 1;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    position: relative;
    // background: transparent;
    white-space: nowrap;
    justify-content: center;

    text-decoration: none;
    font-size: 1.1rem;
    // letter-spacing: 0.3px;
    font-weight: $font-weight-semibold;

    padding: 0 $gutter-sm;
    text-align: center;
    outline: none;
    user-select: none;
    vertical-align: middle;
    color: $color-emphasisText;
    cursor: pointer;
    border-radius: $radius;
    transition: 100ms ease;

    border: 0;
    background: linear-gradient(rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.1) 100%);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);

    @if ($theme == light) {
        background: linear-gradient(rgba(205, 205, 205, 0.9) 0%, rgb(205, 205, 205) 100%);
        box-shadow: none;
    }

    &:hover,
    &:focus {
        border: 0;
        color: $color-emphasisText;
        background: linear-gradient(
            rgba(255, 255, 255, 0.25) 0%,
            rgba(255, 255, 255, 0.2) 5%,
            rgba(255, 255, 255, 0.15) 100%
        );

        @if ($theme == light) {
            background: linear-gradient(rgba(195, 195, 195, 0.9) 0%, rgb(195, 195, 195) 100%);
        }
    }

    &:active {
        background: linear-gradient(
            rgba(255, 255, 255, 0.15) 100%,
            rgba(255, 255, 255, 0.2) 5%,
            rgba(255, 255, 255, 0.25) 0%
        );
        @if ($theme == light) {
            background: linear-gradient(rgba(192, 192, 192, 0.6) 0%, rgba(192, 192, 192, 0.8) 100%);
        }
    }

    &.block {
        display: flex;
        width: 100%;
    }

    &_text {
        background: transparent;
        color: $color-emphasisText;
        border-color: transparent;

        &:hover,
        &:focus {
            background: rgba(255, 255, 255, 0.1);
            color: $color-emphasisText;
            border-color: transparent;
        }
    }

    &_small {
        height: $input-height-sm;
        line-height: 1;
        letter-spacing: 0.4px;
        font-size: 1rem;
    }

    &_large {
        height: $input-height-lg;
        line-height: 1;
        font-size: $font-size-sm;
        padding: 0 $gutter-lg;
        border-radius: $radius-lg;
    }

    &_disabled {
        opacity: 0.5;
        cursor: not-allowed;
        pointer-events: none;
    }

    &_isFetching {
        opacity: 0.5;
        cursor: wait;
    }

    .icon {
        font-size: 18px;
        vertical-align: middle;
    }

    &_small .icon {
        font-size: 15px;
    }

    &_normal {
        font-weight: normal;
    }

    &_bold {
        font-weight: $font-weight-bold;
    }

    &_hasText {
        padding: 0 $gutter;
        max-width: 100%;

        .icon_left {
            margin-right: 4px;
            margin-left: -4px;
        }

        .icon_right {
            margin-right: -4px;
            margin-left: 4px;
        }
    }

    &_dialog {
        padding: 0 $gutter-sm;
    }

    &_square {
        border-radius: 0;
    }

    &_border {
        background: transparent;
        color: white;
        border: 2px solid $color-faintText;

        &:focus,
        &:hover {
            background: white;
            color: $color-primary;
            border: 2px solid white;
        }
    }

    // Tiny button
    &_xs {
        border-width: 1px;
        height: 18px;
        letter-spacing: 0.4px;
        line-height: 14px;
        font-size: 10px;
        padding: 0 3px;

        .icon {
            font-size: 14px;
            top: 0;
        }

        &.button_hasText {
            .icon_left {
                margin-right: 1px;
                margin-left: -3px;
            }

            .icon_right {
                margin-right: -3px;
                margin-left: 1px;
            }
        }
    }
}

:global(.buttonGroup) {
    .button {
        border-radius: 0;
        margin-right: -1px;

        &:hover {
            z-index: 1;
        }

        &_small {
            height: $input-height-sm;
            line-height: 1;
            // letter-spacing: 0.4px;
        }
    }

    /* allow error container in radiogroup, for example */
    button:first-of-type,
    a:first-of-type {
        border-radius: $radius 0 0 $radius;
        border-right: 0;
    }

    button:last-of-type,
    a:last-of-type {
        border-radius: 0 $radius $radius 0;
        margin-right: 0;

        // handle case where there's only button
        &:first-of-type {
            border-radius: $radius;
        }
    }
}

@each $kind, $color_original in $color-presets {
    $color: diminish($color_original, 3%);
    @if ($kind == primary) {
        $color: $color-button or $color;
    }

    .button_#{$kind} {
        border-color: $color;
        background: linear-gradient(lighten($color, 5%) 0%, $color 100%);
        color: white;

        &:hover {
            background: linear-gradient(lighten($color, 5%) 0%, $color 100%);
            border-color: lighten($color, 5%);
            color: white;
        }

        &:focus {
            background: linear-gradient(lighten($color, 10%) 0%, $color 100%);
            border-color: lighten($color, 5%);
            color: white;
        }

        &:active {
            background: linear-gradient(lighten($color, 3%) 0%, lighten($color, 5%) 100%); // lighten($color, 5%);
        }

        &.button_border {
            background-color: transparent;
            color: $color;

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

        &.alt {
            background: #fff;
            border-color: transparent;
            color: $color;

            &:hover,
            &:focus {
                background-color: $color;
                color: #fff;
            }
        }

        &.button_text {
            background: transparent;
            color: $color;
            border-color: transparent;

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

        // &.button_light:hover {
        //     color: $color;
        // }
    }
}
