@form_padding_top_bottom: 7px;
@form_padding_sides: 20px;

@form_font_size: 12;
@form_line_height: 26px;

@form_dots_top: 25px;
@form_dots_side: 16px;

@form_icons_width: 50px;
@form_padding_icon_offset: @form_icons_width;
@form_icons_top: 0;
@form_icons_side: 0;
@form_icons_color: rgba(0,0,0,0.4);

@chosen_border_radius: 5px;
@form_border_radius: 5px;

@form_border_color: @primary_color;
@form_highlight_color: darken(@primary_color, 8%);
@form_border_dark: #fff;
@form_border_width: 1.5px;
@form_font_weight: 600;

@field_min_height: 44px;

.chosen-container {
    position: relative;
    min-width: 190px;
    display: inline-block;
    vertical-align: middle;
    zoom: 1;
    *display: inline;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    width: 100%;

    a {
        cursor: pointer;
    }

    .chosen-drop {
        position: absolute;
        top: 100%;
        left: -9999px;
        width: 100%;
        border-top: 0;
        background: #fff;
        z-index: 8999999;

        .darkBg & {
            background: transparent;
        }
    }

    .search-choice .group-name, .chosen-single .group-name {
        margin-right: 4px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        color: #fff;

        &::after {
            content: ":";
            padding-left: 2px;
            vertical-align: top;
        }
    }



    .chosen-single {
        position: relative;
        display: block;
        overflow: hidden;
        text-align: left;
        padding: (@form_padding_top_bottom + 1px) @form_padding_icon_offset (@form_padding_top_bottom - 1px) @form_padding_sides;
        height: @field_min_height;
        text-decoration: none;
        white-space: nowrap;
        .rems(@form_font_size);
        line-height: @form_line_height;
        border-radius: @chosen_border_radius;

        border: @form_border_width solid @form_border_color;
        background: #fff;
        font-family: @body_font;
        transition: border-color 200ms linear;
        color: @text_color;
        font-weight: @form_font_weight;

        .darkBg & {
            background: @dark_color;
            border-color: fade(@form_border_dark, 40%);
            color: #fff;
        }

        &:hover {
            border-color: @form_highlight_color;

            .darkBg & {
                border-color: fade(@form_border_dark, 20%)
            }
        }


        span {
            display: block;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            font-size: inherit;
            line-height: inherit;
        }

        .chosen-single-with-deselect span {
            margin-right: 32px;
        }

        abbr {
            position: absolute;
            top: 6px;
            right: 26px;
            display: block;
            width: 12px;
            height: 12px;
            font-size: 1px;
        }

        div {
            position: absolute;
            bottom: 0;
            top: @form_icons_top;
            right: @form_icons_side;
            width: @form_icons_width;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;

            b {
                display: flex;
                align-items: center;
                justify-content: center;
                width: 100%;
                height: 100%;

                &:after {
                    position: relative;
                    top: auto;
                    left: 0;
                    .fa(f107, @secondary_color);
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    opacity: 1;
                    .rems(14);
                    line-height: 14px;
                    transition: all 200ms linear;
                }
            }
        }
    }

    &.chosen-container-active {

        .chosen-single {
            border-color: @form_highlight_color;
            transition: border-color 200ms linear;

            div > b:after {
                color: @secondary_color;
                opacity: 1;
                transition: all 200ms linear;
            }

            .darkBg & {
                background: @dark_color;
                border-color: #fff;
                color: #fff;
            }
        }

        &.chosen-with-drop {
            .chosen-single {
                border-radius: @chosen_border_radius @chosen_border_radius 0 0;
                border-bottom: none;
            }
        }
    }

    .chosen-search, .search-field {
        .clearfix();
        position: relative;
        z-index: 1010;
        padding: 8px;
        margin: 0;
        white-space: nowrap;
        width: 100%;

        &:after {
            position: absolute;
            top: 50%;
            right: 24px;
            transform: translateY(-50%);
            .fa(f002);
            z-index: 1000;
            .rems(14);
            line-height: 14px;
        }

        a {
            text-decoration: none;
        }

        input[type="search"] {
            float: none;
            outline: 0;
            padding: 8px 24px 8px 12px;
            width: 100% !important;

            &:focus {
                border: @form_border_width solid @form_border_color;
                box-shadow: none;
            }
        }
    }


    .chosen-drop {
        margin-top: 0;
        background-clip: padding-box;
        text-align: left;
        border: @form_border_width solid @form_border_color;
        border-top: none;
        border-top: none;
        overflow: hidden;
        border-radius: 0 0 @chosen_border_radius @chosen_border_radius;
        box-shadow: none;
        transition: border-color 200ms linear;

        &.chosen-dropup {
            top: 100% !important;
            bottom: auto !important;
        }

        .darkBg & {
            background: @dark_color;
            border-color: fade(#fff, 40%);
        }
    }

    &.chosen-container-active {
        .chosen-drop {
            border-color: @form_highlight_color;
            transition: border-color 200ms linear;

            .darkBg & {
                border-color: fade(#fff, 100%);
            }
        }
    }
}



&.chosen-with-drop .chosen-drop {
    left: 0;
}

.chosen-container-single.chosen-container-single-nosearch .chosen-search {
    position: absolute;
    left: -9999px;
}

.chosen-container {

    width: 100%;
    min-width: 100%;

    .chosen-results {
        float: left;
        width: 100%;
        background: #fff;
        position: relative;
        overflow-x: hidden;
        overflow-y: auto;
        max-height: 216px;
        -webkit-overflow-scrolling: touch;
        margin: 0;
        padding: 0;

        .darkBg & {
            background: @dark_color;
        }

        li {
            margin: 0;
            padding: @form_padding_top_bottom @form_padding_sides;
            list-style-type: none;
            word-wrap: break-word;
            -webkit-touch-callout: none;
            color: @text_color;
            font-family: @body_font;
            .rems(@form_font_size);
            line-height: @form_line_height;
            font-weight: @form_font_weight;
            transition: background 200ms linear, color 200ms linear;

            .darkBg & {
                color: #fff;
            }

            em {
                font-style: normal;
                text-decoration: underline;
            }

            &.active-result {
                cursor: pointer;
            }

            &.disabled-result {
                display: list-item;
                cursor: default;
                opacity: 0.5;
                pointer-events: none;
            }

            &.result-selected {
                background-color: @secondary_color !important;
                color: #fff !important;
                transition: background 200ms linear, color 200ms linear;
            }

            &:hover, &.highlighted {
                background-color: fade(@secondary_color,16%);
                transition: background 200ms linear, color 200ms linear;
            }

            &:active {
                background-color: fade(@secondary_color,24%);
                transition: background 200ms linear, color 200ms linear;
            }

            .group-result {
                display: list-item;
                cursor: default;
            }

            .group-option {
                padding-left: 15px;
            }
        }
    }
}

.chosen-container-multi {



    .chosen-choices {
        position: relative;
        overflow: hidden;
        width: 100%;
        height: auto !important;
        background: #fff;
        border-radius: @chosen_border_radius;
        cursor: text;
        margin: 0;
        padding: 0 @form_padding_icon_offset 0 0;
        transition: border-color 200ms linear;
        border: @form_border_width solid @form_border_color;

        .darkBg & {
            background: transparent;
            border-color: fade(@form_border_dark, 40%);
        }

        li {
            float: left;
            list-style-type: none;

            &.search-field {
                margin: 0;
                padding: 0;
                position: initial;
                width: ~"calc(100% + @{form_padding_icon_offset})";

                input {
                    border: none;
                    background: transparent;
                    padding: @form_padding_top_bottom @form_padding_icon_offset @form_padding_top_bottom @form_padding_sides;
                    color: @text_color;
                    min-width: 100% !important;
                    width: 100% !important;

                    .darkBg & {
                        color: #fff;
                    }
                }

                &:after {

                    position: absolute;
                    top: auto;
                    bottom: @form_icons_top;
                    right: @form_icons_side;
                    width: @form_icons_width;
                    height: 56px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    .rems(14);
                    line-height: 16px;
                    color: @form_icons_color !important;
                    transition: color 200ms linear;
                    font-weight: 400 !important;
                    z-index: 1;
                    pointer-events: none;
                    transform: none !important;

                    .darkBg & {
                        color: #fff;
                    }

                }
            }

            &.search-choice-focus {
                background: red;
            }

            &.search-choice {
                position: relative;
                margin: 16px 8px 0 8px;
                padding: 0;
                max-width: 100%;
                color: @text_color;
                cursor: default;
                background-color: transparent;

                .darkBg & {
                    color: #fff;
                }

                & + .search-field {
                    margin-top: 12px;
                    background: rgba(0,0,0,0.04) !important;

                    .darkBg & {
                        background: rgba(0,0,0,0.1) !important;
                    }
                }

                span {
                    word-wrap: break-word;
                }

                .search-choice-close {
                    display: inline-block;
                    text-decoration: none;
                    margin: 0 0 0 5px;

                    &:after {
                        position: relative;
                        .fa(f057, @alert_color);
                        font-weight: 400;
                        transition: color 200ms linear;
                    }

                    &:hover {
                        &:after {
                            color: darken(@alert_color, 10%);
                            transition: color 200ms linear;
                        }
                    }

                    &:active {
                        &:after {
                            color: darken(@alert_color, 5%);
                            transition: color 200ms linear;
                        }
                    }
                }
            }
        }
    }


    &.chosen-container-active {

        .chosen-choices {

            border-color: @form_border_color;
            transition: border-color 200ms linear;

            .darkBg & {
                border-color: fade(@form_border_dark, 100%);
            }
        }


        &.chosen-with-drop {

            .chosen-choices {
                border-radius: @chosen_border_radius @chosen_border_radius 0 0;
                border-bottom: none;

                li {

                    &.search-field {

                        input {
                            border-bottom-left-radius: 0 !important;
                            border-bottom-right-radius: 0 !important;
                        }
                    }

                }
            }

        }

    }

    .chosen-results {
        margin: 0;
        padding: 0;
    }

    .chosen-drop {

        &.chosen-dropup {
            margin-bottom: 8px;
        }

        .result-selected {
            display: list-item;
            color: #ccc;
            cursor: default;
        }
    }
}

.chosen-container-active {

    &.chosen-with-drop {

        .chosen-single {

            div {
                border-left: none;
                background: transparent;

                b {

                    &:after {
                        transform: rotate(-180deg);
                    }
                }
            }
        }
    }

    .chosen-disabled {
        cursor: default;
        opacity: 0.5;

        .chosen-single {
            cursor: default;
        }

        .chosen-choices .search-choice .search-choice-close {
            cursor: default;
        }
    }


}

.mobileChosen {
    position: relative;
    min-width: 200px;

    select {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        opacity: 0;
        cursor: pointer;
        z-index: 998;
    }
}

/*
* Ensure the select box is full width within chosen
 */
.chosen-container {
    &>select {
        width: 100% !important;
    }
}

.chosen-search {
    display: none !important;
}
