$input-color-focus: $color-blue !default;
$input-color-border: $color-grey !default;
$input-color-error: $color-red !default;
$input-radius: 2px !default;
$select-arrow: url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiPgo8cGF0aCBmaWxsPSIjNjY2NjY1IiBkPSJNNS4yOTMgOS43MDdsNiA2YzAuMzkxIDAuMzkxIDEuMDI0IDAuMzkxIDEuNDE0IDBsNi02YzAuMzkxLTAuMzkxIDAuMzkxLTEuMDI0IDAtMS40MTRzLTEuMDI0LTAuMzkxLTEuNDE0IDBsLTUuMjkzIDUuMjkzLTUuMjkzLTUuMjkzYy0wLjM5MS0wLjM5MS0xLjAyNC0wLjM5MS0xLjQxNCAwcy0wLjM5MSAxLjAyNCAwIDEuNDE0eiI+PC9wYXRoPgo8L3N2Zz4K') !default;
$select-color-bg: $color-white !default;

@mixin inputStyleFocus($clr: $input-color-focus) {
    box-shadow: 0 0 0 2px rgba(lighten($clr, 5%), 0.25);
    border: 1px solid $clr;
    transition: box-shadow 0.125s;
}

@mixin inputStyle(
    $clr: $input-color-focus,
    $clr-border: $input-color-border,
    $radius: $input-radius
) {
    flex-grow: 1;
    font-family: inherit;
    font-size: inherit;
    font-weight: 200;
    outline: none;
    border: 1px solid $clr-border;
    border-radius: $radius;
    line-height: 1;
    margin-top: 6px;
    padding: 10px;

    &:focus,
    &.focus {
        @include inputStyleFocus($clr);
    }

    &:disabled {
        opacity: 0.8;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    line-height: 1.5;
    margin: px2rem(20) 0;

    &:first-of-type {
        margin-top: 0;
    }

    &:last-of-type {
        margin-bottom: 0;
    }

    label {
        user-select: none;
        cursor: pointer;
        display: flex;
        flex-direction: column;
        font-weight: 500;

        * {
            font-weight: normal;
        }
    }

    &,
    label {
        input,
        textarea,
        select {
            @include inputStyle();

            &:first-child {
                &:last-child {
                    margin-top: 0;
                    margin-bottom: 0;
                }
            }
        }

        textarea {
            line-height: 1.25;
        }
    }

    .inline,
    &.inline {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-direction: row !important;
    }

    .small,
    small {
        &:last-child {
            @extend .em;
            margin-top: 8px;
            font-weight: normal;
        }
    }

    &.row {
        label {
            flex-direction: row;
            align-items: center;
        }

        input,
        textarea,
        select {
            margin: 0;
        }
    }

    &.error {
        input,
        textarea,
        select {
            @include inputStyleFocus($input-color-error);

            &:focus,
            &.focus {
                border: 1px solid $input-color-error;
                box-shadow: none !important;
            }
        }

        .small,
        small {
            color: $input-color-error;
        }
    }
}

.input-group {
    display: flex;
    align-items: stretch;
    flex-direction: row;

    input,
    textarea,
    select {
        flex-grow: 1;
        font-family: inherit;
        font-size: inherit;
        font-weight: 200;
        outline: none;
        border: none;
        line-height: 1;
        padding: 10px;

        &:disabled {
            opacity: 0.8;
        }

        &:first-child {
            &:last-child {
                margin-top: 0;
                margin-bottom: 0;
            }
        }
    }

    input,
    textarea {
        z-index: 1;
        background-color: none;
        border-top: 1px solid $input-color-border;
        border-bottom: 1px solid $input-color-border;
        border-left: 1px solid $input-color-border;

        &:last-child {
            border-right: 1px solid $input-color-border;
        }

        &:hover {
            cursor: pointer;
        }
    }

    textarea {
        line-height: 1.25;
    }

    > * {
        z-index: 1;

        &:last-child {
            border-radius: 0 $input-radius $input-radius 0;
        }

        &:first-child {
            border-radius: $input-radius 0 0 $input-radius;

            &:last-child {
                border-radius: $input-radius;
            }
        }
    }

    button,
    label {
        flex-grow: 0;
        border-radius: 0;
        margin-right: -1px;
        z-index: 10;
    }
}

select:not([multiple]) {
    display: block;
    line-height: 1.3;
    width: auto;
    max-width: 100%;
    margin: 0;
    -moz-appearance: none;
    -webkit-appearance: none;
    appearance: none;
    background-color: $select-color-bg;
    background-image: $select-arrow;
    background-repeat: no-repeat, repeat;
    background-position: right 10px top 50%, 0 0;
    background-size: 24px 24px, 100%;
    padding-right: 40px;

    option {
        font-weight: normal;

        &:hover {
            cursor: pointer;
        }
    }
}

select::-ms-expand {
    display: none;
}

select {
    &:hover,
    option:hover {
        cursor: pointer;
    }
}
