/**
 * Shared custom select — sajidhadi-style menu, BK design tokens.
 * Works in admin shell and public pages.
 */

.custom-select {
    position: relative;
    width: auto;
    min-width: 0;
    display: inline-block;
    vertical-align: middle;
    max-width: 100%;
}

.custom-select__native {
    width: 100%;
}

.custom-select.is-enhanced .custom-select__native {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    pointer-events: none;
    z-index: 0;
}

.custom-select__trigger,
.custom-select__list {
    display: none;
}

.custom-select.is-enhanced .custom-select__trigger {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    cursor: pointer;
    text-align: left;
    font: inherit;
    line-height: inherit;
    appearance: none;
    -webkit-appearance: none;
    /* Kill native select chevron from .adm-list__select / .form-field__select / .adm-dash__select */
    background-image: none !important;
    padding-right: 2.75rem !important;
}

.custom-select.is-enhanced .custom-select__trigger:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.custom-select.is-enhanced .custom-select__trigger.is-invalid {
    border-color: #b42318;
}

.custom-select.is-enhanced .custom-select__list:not(.is-ported) {
    display: block;
}

.custom-select.is-enhanced .custom-select__list:not(.is-ported)[hidden] {
    display: none;
}

.custom-select__list.is-ported {
    display: block;
}

.custom-select__list.is-ported[hidden] {
    display: none !important;
}

.custom-select__value {
    display: block;
    width: 100%;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 0;
    color: inherit;
}

.custom-select__trigger--placeholder .custom-select__value {
    color: var(--adm-muted-light, #737373);
}

body.admin-shell[data-theme='dark'] .custom-select__trigger--placeholder .custom-select__value,
html.dark .custom-select__trigger--placeholder .custom-select__value {
    color: var(--adm-muted-dark, #a1a1aa);
}

/* Chevron pinned to the right edge of the trigger (input end) */
.custom-select__chevron {
    position: absolute;
    top: 50%;
    right: 0.85rem;
    transform: translateY(-50%);
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    pointer-events: none;
    color: #525252;
    transition: transform 0.15s ease, color 0.15s ease;
}

body.admin-shell[data-theme='dark'] .custom-select__chevron,
html.dark .custom-select__chevron {
    color: #a1a1aa;
}

.custom-select.is-open .custom-select__chevron {
    transform: translateY(-50%) rotate(180deg);
    color: #0a0a0a;
}

body.admin-shell[data-theme='dark'] .custom-select.is-open .custom-select__chevron,
html.dark .custom-select.is-open .custom-select__chevron {
    color: #fafafa;
}

/* Open/focus: same black/white ring as applied filters (not green). */
.custom-select.is-open .custom-select__trigger,
.custom-select.is-enhanced .custom-select__trigger:focus,
.custom-select.is-enhanced .custom-select__trigger:focus-visible {
    border-color: #a3a3a3;
    box-shadow: 0 0 0 1px #a3a3a3;
    outline: none;
}

body.admin-shell[data-theme='dark'] .custom-select.is-open .custom-select__trigger,
body.admin-shell[data-theme='dark'] .custom-select.is-enhanced .custom-select__trigger:focus,
body.admin-shell[data-theme='dark'] .custom-select.is-enhanced .custom-select__trigger:focus-visible,
html.dark .custom-select.is-open .custom-select__trigger,
html.dark .custom-select.is-enhanced .custom-select__trigger:focus,
html.dark .custom-select.is-enhanced .custom-select__trigger:focus-visible {
    border-color: #71717a;
    box-shadow: 0 0 0 1px #71717a;
}

.custom-select__list {
    margin: 0;
    padding: 0.4rem;
    list-style: none;
    max-height: none;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--adm-border-light, #e5e5e5);
    border-radius: var(--form-control-radius, 1rem);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.12);
    transform-origin: top center;
    animation: bk-custom-select-in 0.15s ease;
    z-index: 4000;
    box-sizing: border-box;
}

.custom-select__list.is-drop-up {
    transform-origin: bottom center;
    animation-name: bk-custom-select-in-up;
}

.custom-select__list.is-scrollable {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

.custom-select__list.is-ported {
    position: fixed;
    z-index: 4000;
}

body.admin-shell[data-theme='dark'] .custom-select__list,
html.dark .custom-select__list {
    background: #18181b;
    border-color: var(--adm-border-dark, #3f3f46);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}

@keyframes bk-custom-select-in {
    from {
        opacity: 0;
        transform: translateY(-0.35rem) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes bk-custom-select-in-up {
    from {
        opacity: 0;
        transform: translateY(0.35rem) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.custom-select__list::-webkit-scrollbar {
    width: 5px;
}

.custom-select__list::-webkit-scrollbar-thumb {
    background: #9a9a9a;
    border-radius: 999px;
}

.custom-select__option {
    display: block;
    padding: 0.65rem 0.85rem;
    border-radius: calc(var(--form-control-radius, 1rem) - 0.25rem);
    font-size: 0.9375rem;
    color: #0a0a0a;
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.admin-shell[data-theme='dark'] .custom-select__option,
html.dark .custom-select__option {
    color: #fafafa;
}

.custom-select__option:hover,
.custom-select__option.is-active {
    background: #f5f5f5;
}

body.admin-shell[data-theme='dark'] .custom-select__option:hover,
body.admin-shell[data-theme='dark'] .custom-select__option.is-active,
html.dark .custom-select__option:hover,
html.dark .custom-select__option.is-active {
    background: rgba(255, 255, 255, 0.08);
}

.custom-select__option.is-selected {
    background: #0a0a0a;
    color: #fff;
    font-weight: 500;
}

body.admin-shell[data-theme='dark'] .custom-select__option.is-selected,
html.dark .custom-select__option.is-selected {
    background: #fafafa;
    color: #0a0a0a;
}

.custom-select__option--placeholder {
    color: #737373;
}

.custom-select__option.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Admin toolbar selects: width fitted by JS to longest option */
body.admin-shell .adm-list__filter-bar .custom-select,
body.admin-shell .adm-list__toolbar .custom-select {
    width: auto;
    max-width: 100%;
}

body.admin-shell .adm-list__filter-bar .custom-select.is-enhanced .custom-select__trigger.adm-list__select,
body.admin-shell .adm-list__toolbar .custom-select.is-enhanced .custom-select__trigger.adm-list__select {
    min-width: 0;
}

/* Public form selects full width */
.public-form-page .custom-select {
    display: block;
    width: 100%;
}

/* Form fields and compact pickers stay full width of their box */
body.admin-shell .adm-user-view__business-select-wrap .custom-select,
body.admin-shell .adm-user-view__sub-form-field .custom-select,
body.admin-shell .adm-referral-withdraw-modal__field .custom-select,
.form-group > .custom-select,
.mb-3 > .custom-select {
    display: block;
    width: 100%;
    max-width: 100%;
}

body.admin-shell .adm-dash__range-controls .custom-select {
    flex: 0 0 auto;
    width: auto;
    max-width: 100%;
}
