.dbqdb-select-single,
.dbqdb-select-single-tree {
    width: 100%;

    .input-group {
        flex-wrap: nowrap;
        justify-content: space-between;
    }
    
    // /* Hide the add and view buttons by default */
    // .input-group-append {
    //     display: none;
    // }

    // To-do: delete if unnecessary - commented out in july 2024
    /* Unset the default Bootstrap z-index that caused sidepanel menus to fall behind the buttons */
    // .input-group-append .btn, 
    // .input-group-prepend .btn {
    //     z-index: unset;
    // }
    
    // /* Show the buttons once the data is loaded */
    // &[data-inspect-folder-document-id][data-inspect-add-rule-code] .input-group-append {
    //     display: flex;
    //     margin-left: 0;
    // }
    
    // /*
    //     Hide buttons which are missing required data.
    //     The add button may only be visible with an AddRuleCode.
    //     When there is no FolderDocumentId, all buttons must be invisible
    // */
    // &[data-inspect-add-rule-code=""] .input-group-append > .dbq-select-add-button {
    //     display: none;
    // }
    
    // &[data-inspect-folder-document-id=""] .input-group-append > .dbq-select-view-button,
    // &[data-inspect-folder-document-id=""] .input-group-append > .dbq-select-add-button {
    //     display: none !important;
    // }
    
    // &[data-has-value] .input-group-append > .dbq-select-view-button,
    // &[data-has-value="false"] .input-group-append > .dbq-select-view-button {
    //     display: none;
    // }
    
    // &[data-has-value="true"] .input-group-append > .dbq-select-view-button {
    //     display: block;
    // }
    
    // /* The border radius must change depending on which buttons are visible */
    // &[data-inspect-folder-document-id][data-has-value="true"]:not([data-inspect-folder-document-id=""]) {
    //     .dbqstd-output-content-container {
    //         border-bottom-right-radius: 0;
    //     }
    
    //     .dbq-select-view-button {
    //         border-bottom-right-radius: $border-radius-default !important;
    //     }
    // }
    // &[data-inspect-add-rule-code]:not([data-inspect-add-rule-code=""]) {
    //     .dbqstd-output-content-container {
    //         border-bottom-right-radius: 0;
    //     }
    // }
    // &[data-inspect-folder-document-id][data-inspect-add-rule-code][data-has-value="true"]:not([data-inspect-folder-document-id=""]):not([data-inspect-add-rule-code=""]) {
    //     .dbq-select-view-button {
    //         border-bottom-right-radius: 0 !important;
    //     }
    // }
    
    // /* Read only styling */
    // &[data-is-read-only="true"] {
    //     .dbqstd-output-content-container {
    //         background: $modal-disabled-color !important; /* Important is still required here, even though it gets added AFTER the default styling...? */
    //         border: $field-border-width solid $modal-disabled-color !important;
    //         cursor: not-allowed;
    //         font-weight: 700;
    //         opacity: 1;
    //         -webkit-opacity: 1; /* Override iOS opacity change affecting text & background color */
    //     }
    
    //     .input-group-append {
    //         .dbq-select-view-button,
    //         .dbq-select-add-button {
    //             background: $modal-disabled-color;
    //             border-color: $modal-disabled-color;
    //             color: $color-primary;
    //             &:hover {
    //                 background: $modal-disabled-color;
    //                 border-color: $modal-disabled-color;
    //                 color: color(text-color-default);
    //             }
    //             &:active {
    //                 background: $modal-disabled-color;
    //                 border-color: $modal-disabled-color;
    //                 color: color(text-color-default);
    //             }
    //         }
    
    //         .dbq-select-add-button {
    //             display: none;
    //         }
    //     }
    // }
}

// Note from Jeroen @ 31-03-2023:
// Unfortunately we can't get around without using !importants.
// The #classlist .dropdown-menu styling has way too many !importants.
.dbqstd-container {
    display: flex;
    flex-direction: row;
    width: 100%;
    min-width: 0;

    .dbqstd-paging-button {
        border: none;
        background: none;
        outline: 0;

        svg {
            fill: $text-color-default;
        }

        &:hover {
            svg {
                fill: $color-primary;
            }
        }

        &.disabled {
            svg {
                fill: $color-gray-base;
            }

            &:hover {
                cursor: not-allowed;
            }
        }
    }

    .dbqstd-output-button {
        outline: 0;
        background: none;
        border: none;
        padding: 0;
        margin: 0;
        width: 100%;
        overflow-x: hidden;
        overflow-y: auto;

        .dbqstd-output-content-container {
            display: flex;
            flex-direction: column;
            justify-content: center;
            border: $field-border-width solid $modal-border-color;
            outline: 0;
            width: 100%;
            height: $field-height;
            -moz-appearance: none;
            -webkit-appearance: none;
            -ms-appearance: none;
            -o-appearance: none;
            appearance: none; 
            //background: $modal-input-background;
            background-repeat: no-repeat;
            background-image: url("data:image/svg+xml;utf8,<svg fill='%23" + str-slice("#{color(text-color-default)}", 2) + "' height='20' viewBox='0 0 20 20' width='20' xmlns='http://www.w3.org/2000/svg'><g><path d='M10,16L0,6l2-2l8,8l8-8l2,2L10,16z'/></g></svg>");
            background-position-x: calc(100% - 10px);
            background-position-y: 50%;
            background-size: 10px 10px;
            //border-radius: 0 0 $border-radius-default $border-radius-default;
            padding-left: 10px;
            color: $modal-input-color;
            padding: 0 30px 0 10px;
            font-weight: $field-font-weight;
            font-size: $field-font-size;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;

            &:focus {
                border-color: $color-primary !important;
                outline: 0;
                -webkit-box-shadow: none;
                -moz-box-shadow: none;
                box-shadow: none;
            }
            &:disabled,
            .disabled {
                background: $modal-disabled-color !important;
                border: $field-border-width solid $modal-disabled-color;
                opacity: 1;
                color: $modal-input-color;
                cursor: not-allowed;
                -webkit-text-fill-color: $modal-input-color;
                -webkit-opacity: 1; /* Override iOS opacity change affecting text & background color */
            }

            &.dbqstd-invalid {
                border-color: $select-type-popup-invalid-color;
            } 

            .dbqstd-output-item {
                display: flex;
                align-items: center;
                margin-bottom: ($margin-default / 3);

                &:last-child {
                    margin-bottom: 0px;
                }

                .dbqstd-attribute {
                    display: block;
                    width: 100%;

                    .dbqstd-attribute-name {
                        float: left;
                        font-size: $font-size-small;
                        line-height: 14px;
                        color: #999;
                        margin-bottom: ($margin-default / 5);
                    }

                    .dbqstd-attribute-value {
                        float: left;
                        width: 100%;
                        text-align: left;
                        overflow-wrap: break-word;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        user-select: text;
                    }
                }
            }

            .dbqstd-error {
                color: $select-type-popup-invalid-color;
            }
        }

        &:focus,
        &:focus-visible {
            outline: none;
        }
    }

    &[data-has-paging="true"] {
        .dbqstd-output-button {
            .dbqstd-output-content-container {
                background: none !important;
                padding: 0 !important;
            }
        }
    }
}

// The popup container will be moved to the end of the <body> tag upon opening. That's also why .dbqstd-popup-container is outside of .dbqstd-container in the CSS file.
.dbqstd-popup-container {
    // width: 100%;
    padding: 0 0 ($padding-default / 3) 0;
    background: $modal-label-background;
    overflow: hidden;
    z-index: 1060;

    .dbqstd-items {
        .dbqstd-no-result {
            color: $modal-label-color;
        }
    }
    
    .dbqstd-title-container {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: ($padding-default / 3);// ($padding-default / 2);
        color: $modal-label-color;
        font-size: $font-size-small;
        font-weight: 600;
        
        .dbqstd-close {
            display: none; // To-do: remove if close button is necessary
            width: 12px;
            height: 12px;
            margin-left: 5px;
            display: inline-flex;
            cursor: pointer;
            align-items: center;
            justify-content: center;
            svg {
                fill: $modal-label-color;
            }
        }
    }

    .dbqstd-search-input {
        width: 100%; //calc(100% - 16px);
        //margin: 0px ($margin-default / 2) ($margin-default / 3) ($margin-default / 2);
        padding: 1px ($padding-default / 3);
        min-height: 30px;
        max-height: 30px;
        height: 30px;
        border-radius: 6px !important;
        font-size: $font-size-small;
        @include search-field;
        border-width: 1px;
    }

    .dbqstd-parent-items-container {
        display: flex;
        padding: 0 5px 5px 5px;
        align-items: center;

        .dbqstd-parent-items-back-button {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 24px;
            height: 24px;
            border-radius: 50%;
            padding: 0;

            svg {
                fill: #fff;
            }
        }

        .dbqstd-parent-items-dropdown {
            width: 100%;
            height: $field-height;
            margin-left: 5px;
            background: $modal-input-background;
            border: $field-border-width solid $modal-border-color;
			border-radius: $border-radius-default;
			color: $modal-input-color;
            font-size: $font-size-small;
        }
    }

    &[data-has-parent-items="false"] {
        .dbqstd-parent-items-container {
            display: none;
        }
    }

    ul {
        list-style: none;
        padding: ($padding-default / 2) 0;
        margin: 0;
        max-height: 250px;
        overflow-y: auto;
        background-color: $modal-input-background;
        border-radius: 5px;
        @include scrollbar($sidebar-background, 0, $sidebar-scrollbar-thumb-color, $sidebar-scrollbar-thumb-color-hover, $sidebar-scrollbar-width, true);

        .dbqstd-attribute-name,
        .dbqstd-attribute-checkmark {
            font-size: $font-size-small;
            font-weight: 400;

            svg {
                fill: $text-color-default;
            }
        }

        .dbqstd-no-result {
            display: block;
            margin: 0 ($margin-default / 2);
        }

        .dbqstd-error {
            color: $select-type-popup-invalid-color;
        }

        li.dbqstd-popup-dropdown-item {
            color: $text-color-default;
            cursor: pointer;
            display: block;
            outline: 0;
            position: relative;
            font-weight: 600;
            padding: 0px ($padding-default / 2) !important;
            margin: 0px;
            width: 100%;
        
            user-select: none; /* CSS3 (little to no support) */
            -ms-user-select: none; /* IE 10+ */
            -moz-user-select: none; /* Gecko (Firefox) */
            -webkit-user-select: none; /* Webkit (Safari, Chrome) */

            .dbqstd-popup-dropdown-item-content {
                flex-wrap: nowrap;
                padding: 0px;
                position: relative;
                display: flex;
                -webkit-box-pack: start;
                justify-content: flex-start;
                -webkit-box-align: center;
                align-items: center;
                border-radius: 6px;

                .dbqstd-attribute {
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    width: 100%;

                    .dbqstd-attribute-name {
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                    }

                    .dbqstd-attribute-drilldown {
                        display: none;
                        fill: $text-color-default;

                        &:hover {
                            svg {
                                fill: $color-primary !important;
                            }
                        }
                    }

                    .dbqstd-attribute-checkmark {
                        height: 16px;
                        margin-left: 5px;
                        margin-bottom: 4px;
                        display: none;
                        fill: $text-color-default;
                        flex-shrink: 0;
                    }
                }
            }

            &:hover,
            &.dbqstd-selected-dropdown-item {
                background: transparent !important;
                color: transparent !important;

                .dbqstd-popup-dropdown-item-content {
                    color: $color-primary;
                }
            }

            &.dbqstd-selected-dropdown-item {
                .dbqstd-popup-dropdown-item-content {
                    color: $color-gray-base;

                    svg {
                        fill: $text-color-default;
                    }
                }

                .dbqstd-attribute-checkmark {
                    display: none;
                }
            }

            &[data-has-child-nodes="true"] {
                .dbqstd-popup-dropdown-item-content {
                    .dbqstd-attribute {
                        .dbqstd-attribute-drilldown {
                            display: flex;
                            align-items: center;
                            justify-content: center;
                            width: 18px; // Width and height is changed to 18px in order to keep the height the same for items with and without a drilldown
                            height: 18px;
                        }
                    }
                }
            }

            &[data-is-selectable="false"] {
                .dbqstd-popup-dropdown-item-content {
                    cursor: not-allowed;
                    color: $modal-input-disabled-color !important;
                    

                    svg {
                        cursor: pointer;
                    }
                }
            }
        }
    }

    ul.dbqstd-selected-items {
        border-bottom: $field-border-width solid $modal-label-background;

        .dbqstd-popup-dropdown-item.dbqstd-selected-dropdown-item {
            .dbqstd-popup-dropdown-item-content {
                padding: ($padding-default / 3) ($padding-default / 2) !important;
                background: $background-item-color-default !important;
                color: $text-color-default !important;

                .dbqstd-attribute-drilldown {
                    display: none !important;
                }

                .dbqstd-attribute-checkmark {
                    display: block !important;
                }
            }

            .dbqstd-selected-dropdown-item {
                background: transparent !important;
                color: transparent !important;
            }
        }
    }

    .dbqstd-loading {
        margin: ($margin-default / 3) $margin-default;
    }

    .dbqstd-buttons {
        display: flex;
        margin: ($margin-default / 3) ($margin-default / 3) 0 ($margin-default / 3);

        .dbqstd-button {
            background: $color-primary;
            color: $color-white;
            border: none;
            margin-right: 5px;
            padding: 0;
            outline: 0;
            width: 24px;
            height: 24px;
            border-radius: 50%;

            svg {
                fill: $color-white;
            }
        }
    }
}

.dbqstd-loading {
    @include loading-indicator-inline;
}

.dbq-select-view-button,
.dbq-select-add-button {
    color: #000000;
    border-color: $modal-border-color;
    margin-left: 5px;
    border-left: 0;
    transition: none !important;
    outline: 0;
    &:hover {
        color: color(text-color-default);
        border-color: $modal-border-color;
        background: $modal-input-background;
        svg {
            fill: color(text-color-default);
        }
    }
    &:active {
        background: $modal-input-background;
        border-color: $modal-border-color;
        &:hover {
            background: $modal-input-background;
            border-color: $modal-border-color;
        }
    }
    svg {
        width: $field-select-button-width;
        height: $field-select-button-height;
        padding: $field-select-button-padding;
        border-radius: $border-radius-default;
        fill: $color-primary;
    }
}

/* No label styling */
.dbq-property-no-label {
    .dbqdb-select-single,
    .dbqdb-select-single-tree {
        .dbqstd-output-content-container {
            border-radius: $border-radius-default !important;
        }

        /* The border radius must change depending on which buttons are visible */
        &[data-inspect-folder-document-id][data-has-value="true"]:not([data-inspect-folder-document-id=""]) {
            .dbqstd-output-content-container {
                border-top-right-radius: 0 !important;
                border-bottom-right-radius: 0 !important;
            }

            .dbq-select-view-button {   //Commented out because it's causing trouble with the material design styling
                //border-top-right-radius: $border-radius-default !important;
                //border-bottom-right-radius: $border-radius-default !important;
            }
        }
        &[data-inspect-add-rule-code]:not([data-inspect-add-rule-code=""]) {
            .dbqstd-output-content-container {
                border-top-right-radius: 0 !important;
                border-bottom-right-radius: 0 !important;
            }
        }
        &[data-inspect-folder-document-id][data-inspect-add-rule-code][data-has-value="true"]:not([data-inspect-folder-document-id=""]):not([data-inspect-add-rule-code=""]) {
            .dbq-select-view-button {
                border-top-right-radius: 0 !important;
                border-bottom-right-radius: 0 !important;
            }
        }
    }
}