// (C) 2025-2026 GoodData Corporation

@use "../../../styles/scss/variables";
@use "../../../styles/scss/mixins";

.gd-ui-kit-listbox {
    $root: &;
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    width: 100%;
    min-width: 200px;
    padding: 6px 0;

    &--padding-none {
        padding: 0;
    }

    &--mobile {
        // !important to override inline style from maxWidth prop
        /* stylelint-disable-next-line declaration-no-important */
        max-width: 100vw !important;
        max-height: 100vh;
        width: 100vw;
    }

    &__items {
        list-style: none;
        margin: 0;
        padding: 0;
        outline: none;

        &:focus-visible #{$root}__item--isFocused {
            background-color: variables.$is-focused-background;
            @include mixins.focus-ring;
        }

        // the list is never focused itself, so the highlight shows without :focus-visible
        // (a selected highlighted item is styled by --isSelected--isFocused below)
        &--virtualFocus #{$root}__item--isFocused:not(#{$root}__item--isSelected) {
            background-color: variables.$is-focused-background;
        }
    }

    &__item {
        box-sizing: border-box;
        min-height: 32px;
        padding: var(--gd-spacing-5px) var(--gd-spacing-10px);
        cursor: pointer;
        display: flex;
        align-items: center;
        font-size: 14px;
        line-height: 20px;
        color: variables.$gd-color-text;
        gap: 10px;

        // With virtual focus, hovering moves the highlight itself (onFocusedItemIdChange), so painting :hover
        // too would show a second highlight on the item under a resting mouse
        #{$root}__items:not(#{$root}__items--virtualFocus) &:hover:not(&--isDisabled):not(&--isSelected) {
            background-color: variables.$is-focused-background;
            color: variables.$is-focused-color;
        }

        // Only show focus highlight when navigating by keyboard
        // The --isFocused class is applied programmatically, but background only shows on keyboard focus
        &--isFocused {
            color: variables.$is-focused-color;
        }

        &--isSelected {
            font-weight: bold;
            background-color: variables.$is-selected-background;
            color: variables.$is-selected-color;
        }

        &--isSelected#{&}--isFocused,
        #{$root}__items:not(#{$root}__items--virtualFocus) &:hover#{&}--isSelected {
            font-weight: bold;
            background-color: variables.$is-selected-focused-background;
            color: variables.$is-selected-focused-color;
        }

        &--isDisabled {
            color: variables.$gd-color-disabled;
            cursor: not-allowed;
        }

        &--isCompact {
            min-height: 28px;
            font-size: 12px;
            line-height: 18px;
        }
    }

    &__item-title {
        display: block;
        width: 100%;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    &__item-secondary {
        font-weight: normal;
        color: var(--gd-palette-complementary-6);
    }

    &__item--isSelected &__item-secondary,
    &__item--isFocused &__item-secondary {
        color: inherit;
        opacity: 0.7;
    }

    // wrapper around the question mark icon to center it vertically
    &__item-explanation {
        display: flex;
        align-items: center;
    }
}
