/* stylelint-disable max-nesting-depth */
.b-select {
    $choices-selector: 'choices';
    $choices-font-size-lg: 16px;
    $choices-font-size-md: 14px;
    $choices-font-size-sm: 12px;
    $choices-guttering: 24px;
    $choices-border-radius: 4px;
    $choices-border-radius-item: 4px;
    $choices-bg-color: $white;
    $choices-bg-color-disabled: $light-gray;
    $choices-bg-color-dropdown: $white;
    $choices-text-color: $dark-gray;
    $choices-keyline-color: $light-gray;
    $choices-primary-color: $primary-color;
    $choices-disabled-color: $medium-gray;
    $choices-highlight-color: $choices-primary-color;
    $choices-button-dimension: 8px;
    $choices-button-offset: 8px;
    $choices-icon-cross: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjEiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMSAyMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSIjRkZGIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yLjU5Mi4wNDRsMTguMzY0IDE4LjM2NC0yLjU0OCAyLjU0OEwuMDQ0IDIuNTkyeiIvPjxwYXRoIGQ9Ik0wIDE4LjM2NEwxOC4zNjQgMGwyLjU0OCAyLjU0OEwyLjU0OCAyMC45MTJ6Ii8+PC9nPjwvc3ZnPg==) !default;
    $choices-icon-cross-inverse: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjEiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMSAyMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSIjMDAwIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yLjU5Mi4wNDRsMTguMzY0IDE4LjM2NC0yLjU0OCAyLjU0OEwuMDQ0IDIuNTkyeiIvPjxwYXRoIGQ9Ik0wIDE4LjM2NEwxOC4zNjQgMGwyLjU0OCAyLjU0OEwyLjU0OCAyMC45MTJ6Ii8+PC9nPjwvc3ZnPg==) !default;

    .#{$choices-selector} {
        position: relative;
        margin-bottom: $choices-guttering;
        font-size: $choices-font-size-lg;

        &:focus {
            outline: none;
        }

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

        &.is-disabled {
            .#{$choices-selector}__inner,
            .#{$choices-selector}__input {
                user-select: none;
                background-color: $choices-bg-color-disabled;
                cursor: auto;
            }

            .#{$choices-selector}__item {
                cursor: auto;
            }

            .#{$choices-selector}__list .#{$choices-selector}__button {
                display: none;
            }
        }

        &:not(.is-disabled) {
            &:hover {
                .#{$choices-selector}__inner {
                    border-color: $medium-gray;
                }
            }

            &.is-focused,
            &.is-open {
                .#{$choices-selector}__inner {
                    border-color: $choices-primary-color;
                }
            }
        }

        &.is-flipped .#{$choices-selector}__list--dropdown {
            top: auto;
            bottom: 100%;
        }
    }

    .#{$choices-selector}[data-type*='select-one'] {
        cursor: pointer;

        .#{$choices-selector}__input {
            display: block;
            width: 100%;
            margin: 0;
            border-bottom: 1px solid $choices-keyline-color;
            padding: 10px;
            background-color: #fff;
        }

        .#{$choices-selector}__button {
            opacity: .5;
            position: absolute;
            top: 50%;
            right: 0;
            width: 20px;
            height: 20px;
            margin-top: -10px;
            margin-right: 30px;
            border-radius: 10em;
            padding: 0;
            background-image: $choices-icon-cross-inverse;
            background-size: 8px;

            &:hover,
            &:focus {
                opacity: 1;
            }

            &:focus {
                box-shadow: 0 0 0 1px $choices-highlight-color;
            }
        }

        &[dir='rtl'] {
            .#{$choices-selector}__button {
                right: auto;
                left: 0;
                margin-right: 0;
                margin-left: 25px;
            }
        }
    }

    .#{$choices-selector}[data-type*='select-one'],
    .#{$choices-selector}[data-type*='select-multiple'] {
        &::after {
            content: '';
            position: absolute;
            top: 50%;
            right: 11.5px;
            width: 0;
            height: 0;
            margin-top: -2.5px;
            border-width: 5px;
            border-style: solid;
            border-color: $choices-text-color transparent transparent transparent;
            pointer-events: none;
        }

        &.is-open::after {
            margin-top: -7.5px;
            border-color: transparent transparent $choices-text-color transparent;
        }

        &[dir='rtl'] {
            &::after {
                right: auto;
                left: 11.5px;
            }
        }
    }

    .#{$choices-selector}[data-type*="select-multiple"],
    .#{$choices-selector}[data-type*='text'] {
        .#{$choices-selector}-inner {
            cursor: text;
        }

        .#{$choices-selector}__button {
            opacity: .75;
            position: relative;
            display: inline-block;
            width: $choices-button-dimension;
            margin-left: 5px;
            border-radius: 0;
            padding-left: $choices-button-offset * 2;
            line-height: 1;
            background-image: $choices-icon-cross;
            background-size: $choices-button-dimension;

            &:hover,
            &:focus {
                opacity: 1;
            }
        }
    }

    .#{$choices-selector}__inner {
        overflow: hidden;
        display: inline-block;
        width: 100%;
        min-height: 38px;
        border: 1px solid $choices-keyline-color;
        border-radius: $choices-border-radius;
        padding: 3px 7.5px;
        font-size: $choices-font-size-md;
        vertical-align: top;
        background-color: $choices-bg-color;
        transition: border-color .2s;
    }

    .#{$choices-selector}__list {
        margin: 0;
        padding-left: 0;
        list-style: none;
    }

    .#{$choices-selector}__list--single {
        display: inline-block;
        width: 100%;
        padding: 4px 16px 4px 4px;

        [dir='rtl'] & {
            padding-right: 4px;
            padding-left: 16px;
        }

        .#{$choices-selector}__item {
            width: 100%;
        }
    }

    .#{$choices-selector}__list--multiple {
        display: inline;

        .#{$choices-selector}__item {
            display: inline-block;
            margin-right: 3.75px;
            margin-bottom: 3.75px;
            border: 1px solid darken($choices-primary-color, 5%);
            border-radius: $choices-border-radius-item;
            padding: 2px 8px;
            font-size: $choices-font-size-sm;
            font-weight: 500;
            word-break: break-all;
            vertical-align: middle;
            color: #fff;
            background-color: $choices-primary-color;

            &[data-deletable] {
                padding-right: 5px;
            }

            [dir='rtl'] & {
                margin-right: 0;
                margin-left: 3.75px;
            }

            .is-disabled & {
                border: 1px solid darken($choices-disabled-color, 35%);
                background-color: darken($choices-disabled-color, 25%);
            }
        }
    }

    .#{$choices-selector}__list--dropdown {
        overflow: hidden;
        position: absolute;
        top: 100%;
        z-index: 1;
        visibility: hidden;
        width: 100%;
        margin: 8px 0;
        box-shadow: 0 0 0 1px hsla(0, 0%, 0%, .1), 0 4px 11px hsla(0, 0%, 0%, .1);
        border-radius: $choices-border-radius;
        word-break: break-all;
        background-color: $choices-bg-color-dropdown;
        will-change: visibility;

        &.is-active {
            visibility: visible;
        }

        .is-open & {
            border-color: darken($choices-keyline-color, 15%);
        }

        .#{$choices-selector}__list {
            overflow: auto;
            position: relative;
            max-height: 300px;
            -webkit-overflow-scrolling: touch;
            will-change: scroll-position;
        }

        .#{$choices-selector}__item {
            position: relative;
            padding: 10px;
            font-size: $choices-font-size-md;

            [dir='rtl'] & {
                text-align: right;
            }
        }

        .#{$choices-selector}__item--selectable {
            @media (min-width: 640px) {
                padding-right: 100px;

                &::after {
                    content: attr(data-select-text);
                    opacity: 0;
                    position: absolute;
                    top: 50%;
                    right: 10px;
                    font-size: $choices-font-size-sm;
                    transform: translateY(-50%);
                }

                [dir='rtl'] & {
                    padding-right: 10px;
                    padding-left: 100px;
                    text-align: right;

                    &::after {
                        right: auto;
                        left: 10px;
                    }
                }
            }

            &.is-highlighted {
                background-color: mix(#000, #fff, 5%);

                &::after {
                    opacity: .5;
                }
            }
        }
    }

    .#{$choices-selector}__item {
        cursor: default;
    }

    .#{$choices-selector}__item--selectable {
        cursor: pointer;
    }

    .#{$choices-selector}__item--disabled {
        opacity: .5;
        user-select: none;
        cursor: not-allowed;
    }

    .#{$choices-selector}__heading {
        border-bottom: 1px solid lighten($choices-keyline-color, 10%);
        padding: 10px;
        font-size: $choices-font-size-sm;
        font-weight: 600;
        color: lighten(#333, 30%);
    }

    .#{$choices-selector}__button {
        appearance: none;
        border: 0;
        text-indent: -9999px;
        background-color: transparent;
        background-position: center;
        background-repeat: no-repeat;
        cursor: pointer;

        &:focus {
            outline: none;
        }
    }

    .#{$choices-selector}__input {
        display: inline-block;
        max-width: 100%;
        margin-bottom: 5px;
        border: 0;
        border-radius: 0;
        padding: 4px 0 4px 2px;
        font-size: $choices-font-size-md;
        vertical-align: baseline;
        background-color: $choices-bg-color;

        &:focus {
            outline: 0;
        }

        [dir='rtl'] & {
            padding-right: 2px;
            padding-left: 0;
        }
    }

    .#{$choices-selector}__placeholder {
        opacity: .7;
    }
}
