﻿/* =========================================================
   Searchable dropdowns (pioSearchSelect_directive.js)
   1) Select2 boxes that replace the native <select> on V2 pages,
      styled like the site's .form-select (12px corners, same height).
   2) The search field pio-menu-search adds to custom dropdown menus.
   ========================================================= */

/* ---------- 1) Select2 box ---------- */

.select2-container.pio-select {
    max-width: 100%;
}

    /* inside an input-group the box stretches to the height of the field next to it */
    .input-group > .select2-container.pio-select {
        display: flex;
    }

        .input-group > .select2-container.pio-select > .selection,
        .input-group > .select2-container.pio-select .select2-selection--single {
            flex: 1 1 auto;
            height: 100%;
        }

    /* a col-* class carried over from the <select> sizes the box; its gutter padding must not
       push the box away from the field next to it (the select itself had none) */
    .select2-container.pio-select[class*="col-"] {
        padding-left: 0;
        padding-right: 0;
    }

    .select2-container.pio-select .select2-selection--single {
        display: flex;
        align-items: center;
        height: auto;
        min-height: calc(1.5em + .75rem + 2px);
        padding: .375rem 2.25rem .375rem .75rem;
        border: 1px solid var(--pio-auth-line, var(--bs-border-color, #dee2e6));
        border-radius: 12px;
        background-color: var(--pio-auth-field, var(--bs-body-bg, #fff));
        transition: border-color .2s ease, box-shadow .2s ease;
    }

    .select2-container.pio-select[dir="rtl"] .select2-selection--single {
        padding: .375rem .75rem .375rem 2.25rem;
    }

    .select2-container.pio-select .select2-selection__rendered {
        padding: 0 !important;
        line-height: 1.5;
        color: var(--bs-body-color, #212529);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .select2-container.pio-select .select2-selection__placeholder {
        color: var(--bs-secondary-color, #6c757d);
    }

    /* caret, same as the form-select one */
    .select2-container.pio-select .select2-selection__arrow {
        top: 50%;
        right: .9rem;
        left: auto;
        width: 15px;
        height: 15px;
        transform: translateY(-50%);
        background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%238b93a1' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E") no-repeat center / 15px 15px;
        transition: transform .2s ease;
    }

        .select2-container.pio-select .select2-selection__arrow b {
            display: none;
        }

    .select2-container.pio-select[dir="rtl"] .select2-selection__arrow {
        right: auto;
        left: .9rem;
    }

    .select2-container.pio-select.select2-container--open .select2-selection__arrow {
        transform: translateY(-50%) rotate(180deg);
    }

    /* focus / open: the same blue as Bootstrap's form fields and the filter menus */
    .select2-container.pio-select.select2-container--focus .select2-selection--single,
    .select2-container.pio-select.select2-container--open .select2-selection--single {
        border-color: #86b7fe;
        box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color, rgba(13, 110, 253, .25));
        outline: 0;
    }

    .select2-container.pio-select.select2-container--disabled .select2-selection--single {
        background-color: var(--bs-secondary-bg, #e9ecef);
        cursor: not-allowed;
        opacity: .75;
    }

/* the opened list */
.select2-container--default .select2-dropdown {
    border: 1px solid var(--pio-auth-line, var(--bs-border-color, #dee2e6));
    border-radius: 12px;
    background-color: var(--bs-body-bg, #fff);
    box-shadow: 0 18px 40px -16px rgba(10, 21, 37, .28);
    overflow: hidden;
    z-index: 2000; /* above Bootstrap modals (1055) */
}

.select2-container--default .select2-search--dropdown {
    padding: .5rem;
}

    .select2-container--default .select2-search--dropdown .select2-search__field {
        padding: .45rem .75rem;
        border: 1px solid var(--pio-auth-line, var(--bs-border-color, #dee2e6));
        border-radius: 10px;
        background: var(--bs-body-bg, #fff);
        color: var(--bs-body-color, #212529);
        outline: 0;
    }

        .select2-container--default .select2-search--dropdown .select2-search__field:focus {
            border-color: #86b7fe;
            box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color, rgba(13, 110, 253, .25));
        }

.select2-container--default .select2-results > .select2-results__options {
    max-height: 260px;
}

.select2-container--default .select2-results__option {
    padding: .5rem .85rem;
    font-size: .9rem;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: rgba(5, 83, 134, .08);
    color: var(--bs-body-color, #212529);
}

.select2-container--default .select2-results__option[aria-selected="true"] {
    background-color: var(--pio-blue-color, #055386);
    color: #fff;
}

.select2-container--default .select2-results__message {
    color: var(--bs-secondary-color, #6c757d);
}

/* dark theme */
body[data-bs-theme="dark"] .select2-container--default .select2-dropdown,
body[data-bs-theme="dark"] .select2-container--default .select2-search--dropdown .select2-search__field {
    background-color: #15181d;
    border-color: rgba(255, 255, 255, .12);
    color: #f3f4f6;
}

body[data-bs-theme="dark"] .select2-container.pio-select .select2-selection__rendered {
    color: #f3f4f6;
}

body[data-bs-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: rgba(255, 255, 255, .08);
    color: #f3f4f6;
}

/* required + empty after submit: the real <select> is hidden, so mark the visible box */
form.ng-submitted select.ng-invalid + .select2-container.pio-select .select2-selection--single,
.was-validated select:invalid + .select2-container.pio-select .select2-selection--single {
    border-color: var(--bs-form-invalid-border-color, #dc3545);
}

/* phone = country box + number, read as one field: square corners where the two meet */
.input-group > .select2-container.pio-select {
    flex: 0 0 auto;
}

    .input-group > .select2-container.pio-select:not(:last-child) .select2-selection--single {
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
    }

body[dir="rtl"] .input-group > .select2-container.pio-select:not(:last-child) .select2-selection--single {
    border-radius: 0 12px 12px 0;
}

/* a lone country box in a full-width input-group (login form) */
.input-group > .select2-container.pio-select:last-child {
    flex: 1 1 auto;
}

/* ---------- 2) search field in custom dropdown menus ---------- */

/* the search field stays on top while the list scrolls under it. The menu's own top
   padding (py-3...) would leave a gap above the sticky field where the items show
   through, so the menu loses its top padding and the field carries it instead. */
.dropdown-menu[pio-menu-search] {
    padding-top: 0 !important;
}

.dropdown-menu > .pio-menu-search {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: .75rem .5rem .5rem;
    background: var(--bs-dropdown-bg, var(--bs-body-bg, #fff));
    border-top-left-radius: inherit;
    border-top-right-radius: inherit;
}

    .dropdown-menu > .pio-menu-search .form-control {
        border-radius: 10px;
    }

.dropdown-menu > .pio-menu-hidden {
    display: none !important;
}

.dropdown-menu > .pio-menu-search-empty {
    padding: .5rem .85rem;
    font-size: .85rem;
    color: var(--bs-secondary-color, #6c757d);
    text-align: center;
}

/* long category lists (offers / schedules): scroll inside the menu, search field stays on top */
.dropdown-menu.pio-categories-menu {
    max-height: min(60vh, 420px);
    overflow-y: auto;
}

    .dropdown-menu.pio-categories-menu .pio-category-subject {
        font-size: .75em;
        line-height: 1.3;
    }
