/* ============================================
   SELECT2 — the app's skin
   Every select2 on the site runs select2's `default` theme: django-select2
   widgets via SELECT2_THEME, manual inits via `data-select2-init`. The only
   vendor CSS under it is vendor/select2.min.css, so this file is the skin.


   Watch the cascade here. django-select2 can inject its own copy of select2's
   CSS through `{{ form.media }}`, which lands in <body> — after every <head>
   stylesheet, including this one — and silently outranks it. SELECT2_CSS = []
   in settings keeps that from happening.
   ============================================ */

/* --- container plumbing --- */
.content .select2-container,
.modal .select2-container,
.swal2-html-container .select2-container {
    width: 100% !important;
}

/* sidebar.css slide-outs sit at 1000001 to clear this */
.select2-container.select2-container--open {
    z-index: 1000000 !important;
}

/* --- before init ---
   A select2 field is authored as a plain <select> and becomes a widget in JS, so
   there is a window in which the browser has the native control and nothing else -
   on first paint of a page, and on any swap whose init this file does not reach in
   the same task. Painting it costs a flash and a reflow, and a multiple is the worst
   of them: the UA renders a listbox several rows tall where a one-line box belongs.

   So the native control is held at the widget's height and kept invisible until
   `.select2-hidden-accessible` - the class select2 adds to a <select> it has taken
   over - says the widget exists. The box never changes size, and nothing paints in
   it that is not the finished control. */
select.django-select2:not(.select2-hidden-accessible),
select[data-select2-init]:not(.select2-hidden-accessible) {
    height: 38px;
    min-height: 38px;
    visibility: hidden;
}

select.django-select2.form-control-sm:not(.select2-hidden-accessible),
select[data-select2-init].form-control-sm:not(.select2-hidden-accessible) {
    height: 32px;
    min-height: 32px;
}

/* collapse the original <select> select2 hides but leaves in flow */
.form-control.select2-hidden-accessible {
    padding: 0 !important;
    height: 1px !important;
    overflow: hidden !important;
}

/* --- selection box (single + multiple, both themes) --- */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
    background: var(--input-bg) !important;
    border: 1px solid var(--input-border) !important;
    color: var(--text-primary) !important;
    border-radius: 6px;
    font-size: 14px;
    box-shadow: var(--input-inset);
    transition-property: border-color, background, box-shadow;
    transition-duration: 0.15s;
    transition-timing-function: ease-out;
}

.select2-container--default .select2-selection--single:hover,
.select2-container--default .select2-selection--multiple:hover {
    border-color: var(--input-border-hover) !important;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--multiple {
    background: var(--input-bg-focus) !important;
    border-color: var(--input-border-focus) !important;
    box-shadow: var(--input-focus-ring) !important;
}

/* --- single --- */
.select2-container--default .select2-selection--single {
    display: flex !important;
    align-items: center;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--text-primary);
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* same gray as .form-control::placeholder */
.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--text-muted);
}

/* thin chevron that rotates open, instead of select2's CSS triangle */
.select2-container--default .select2-selection--single .select2-selection__arrow {
    position: absolute;
    top: 0;
    right: 6px;
    width: 20px;
    height: 100% !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border: solid var(--select-arrow-color) !important;
    border-width: 0 1.5px 1.5px 0 !important;
    width: 7px;
    height: 7px;
    position: static;
    margin: -3px 0 0;
    transform: rotate(45deg);
    transition: transform 0.15s ease-out;
}

.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    transform: rotate(-135deg);
    margin: 3px 0 0;
}

/* --- multiple --- */
.select2-container--default .select2-selection--multiple {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 3px;
    cursor: text;
}

.select2-container--default .select2-selection--multiple .select2-selection__rendered {
    display: inline-flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 3px;
    float: none;
    width: auto !important;
    margin: 0;
    padding: 0;
    list-style: none;
}

.select2-container--default .select2-selection--multiple .select2-selection__placeholder {
    color: var(--text-muted);
    float: none;
    margin: 0;
}

.select2-container--default .select2-selection--multiple .select2-search--inline {
    float: none !important;
    flex: 1 1 60px;
    margin: 0 !important;
}

.select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: inherit;
    font-family: inherit;
    height: 24px;
    margin: 0 !important;
    padding: 0 4px;
}

.select2-container--default .select2-search--inline .select2-search__field::placeholder {
    color: var(--text-muted);
}

/* --- chips (one style for both themes; select2 4.1 markup puts
   the × <button> before the text — flex `order` moves it after) --- */
.select2-container--default .select2-selection--multiple .select2-selection__choice {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    float: none !important;
    margin: 0 !important;
    padding: 1px 6px;
    max-width: 100%;
    background: rgba(var(--bs-primary-rgb), 0.2);
    border: 1px solid rgba(var(--bs-primary-rgb), 0.3);
    border-radius: 4px;
    color: var(--color-blue);
    font-size: 13px;
    white-space: nowrap;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__display {
    padding: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    order: 2;
    position: static !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 17px;
    height: 17px;
    border: none !important;
    border-radius: 3px;
    background: transparent !important;
    margin: 0 -2px 0 0;
    padding: 0 !important;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    color: rgba(var(--bs-primary-rgb), 0.75);
    cursor: pointer;
    transition-property: color, background-color;
    transition-duration: 0.15s;
    transition-timing-function: ease-out;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: var(--color-red);
    background: rgba(var(--bs-danger-rgb), 0.18) !important;
}

/* --- clear button --- */
.select2-container--default .select2-selection__clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* sized and coloured to match .upoly-clear in polymorphic/widget.css */
    width: 22px;
    height: 22px;
    color: var(--text-tertiary);
    font-size: 0;
    float: none;
    margin: 0 0.25rem 0 0;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
}

/* select2 prepends the × to the selection; on singles `order` moves it
   past the label, and the right margin keeps it clear of the chevron
   sitting at right: 6px in a 20px box. */
.select2-container--default .select2-selection--single .select2-selection__clear {
    order: 2;
    flex: 0 0 auto;
    margin: 0 22px 0 0.25rem;
    line-height: 1;
}

.select2-container--default .select2-selection__clear:hover {
    color: var(--color-red);
    background: rgba(var(--bs-danger-rgb), 0.18);
}

/* On multiples the chips wrap, so the × is pinned to the bottom-right
   corner of the box; the rendered list reserves that width so no chip
   ends up underneath it. */
.select2-container--default .select2-selection--multiple {
    position: relative;
}

.select2-container--default .select2-selection--multiple.select2-selection--clearable .select2-selection__rendered {
    padding-right: 24px;
}

.select2-container--default .select2-selection--multiple .select2-selection__clear {
    position: absolute;
    right: 4px;
    bottom: 2px;
    margin: 0;
    line-height: 1;
}

/* --- disabled state --- */
.select2-container--default.select2-container--disabled .select2-selection--single,
.select2-container--default.select2-container--disabled .select2-selection--multiple {
    background: var(--input-bg-disabled) !important;
    color: var(--text-tertiary) !important;
    /* Matches the inert-field rule at the end of this file: no blanket
       opacity. It would fade the border that locates the field, and
       composite the translucent fill down until it vanishes. */
    cursor: not-allowed;
}

/* --- dropdown --- */
@keyframes select2-drop-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* same surface as .dropdown-menu (opaque — options scroll under it,
   so any translucency reads as ghosting) */
.select2-dropdown {
    background: var(--select-dropdown-bg) !important;
    /* same border as the focused selection box above it, so the open
       control and its dropdown read as one connected unit */
    border: 1px solid var(--input-border-focus) !important;
    border-radius: 8px !important;
    /* Focus halo on the panel too: flush against the equally-wide
       control, the two rings merge into one around the open unit. */
    box-shadow: var(--input-focus-ring), var(--menu-shadow) !important;
    box-sizing: border-box;
    min-width: 100% !important;
    overflow: hidden;
    animation: select2-drop-in 0.12s ease-out;
}

/* dropdown rendered above the select — rise instead of drop */
.select2-dropdown--above {
    animation-name: select2-drop-in-above;
}

/* the dropdown sits flush against the selection box — square the
   corners at the seam so the two read as one connected surface */
.select2-dropdown--below {
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
}

.select2-dropdown--above {
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

.select2-container--open.select2-container--below .select2-selection--single,
.select2-container--open.select2-container--below .select2-selection--multiple {
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

.select2-container--open.select2-container--above .select2-selection--single,
.select2-container--open.select2-container--above .select2-selection--multiple {
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
}

@keyframes select2-drop-in-above {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Search field in dropdown: an integrated borderless row with a
   leading magnifier (like the upoly search), not a nested input —
   the dropdown border already frames it, so the field itself gets
   no border, background, or focus ring. */
.select2-container--default .select2-search--dropdown {
    position: relative;
    padding: 0.35rem 0.75rem 0.35rem 2rem !important;
    background: transparent !important;
    /* Emphasis, not subtle: this line is the only thing separating the
       search field from the results, and it carries that on a panel whose
       fill matches the card behind it. Same weight as --input-border, so
       the panel's internal divider and its edge read as one family. */
    border-bottom: 1px solid var(--border-emphasis) !important;
}

.select2-container--default .select2-search--dropdown::before {
    content: "\f002";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 12px;
    color: var(--select-arrow-color);
    position: absolute;
    left: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    background: transparent !important;
    opacity: 100% !important;
    border: none !important;
    color: var(--text-primary) !important;
    border-radius: 0 !important;
    padding: 0.4rem 0 !important;
    outline: none !important;
    box-shadow: none !important;
    width: 100% !important;
    box-sizing: border-box;
}

.select2-container--default .select2-search--dropdown .select2-search__field::placeholder {
    color: var(--text-muted) !important;
}

/* --- results --- */
.select2-container--default .select2-results {
    background: transparent !important;
}

.select2-container--default .select2-results > .select2-results__options,
.modal .select2-results > .select2-results__options,
.swal2-html-container .select2-results > .select2-results__options {
    max-height: 450px !important;
}

.select2-results > .select2-results__options {
    font-style: normal;
}

/* rows inset 4px from the dropdown edge and rounded (8px shell − 4px
   padding = 4px row radius), hover reads as a pill, not a stripe */
.select2-container--default .select2-results__option {
    color: var(--text-secondary) !important;
    padding: 0.45rem 0.6rem !important;
    background-color: transparent !important;
    border-radius: 4px;
    transition-property: background-color, color;
    transition-duration: 0.15s;
    transition-timing-function: ease-out;
}

/* scrollbar mirrors .dropdown-menu's */
.select2-dropdown .select2-results__options {
    padding: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
    background: transparent;
}

.select2-dropdown .select2-results__options::-webkit-scrollbar {
    width: 8px;
}

.select2-dropdown .select2-results__options::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: 4px;
}

.select2-dropdown .select2-results__options::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 4px;
}

.select2-dropdown .select2-results__options::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
}

.select2-dropdown .select2-results__options::-webkit-scrollbar-corner {
    background: transparent;
}

/* hover/selected use the .dropdown-item primary tints */
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: rgba(var(--bs-primary-rgb), 0.1) !important;
    color: var(--text-primary) !important;
}

.select2-container--default .select2-results__option[aria-selected=true] {
    background-color: rgba(var(--bs-primary-rgb), 0.15) !important;
    color: var(--text-primary) !important;
}

/* Visual indication for selected items in multiple select */
.select2-container--default .select2-results__option.select2-results__option--selected {
    background-color: rgba(var(--bs-primary-rgb), 0.15) !important;
    color: var(--text-primary) !important;
    font-weight: 600;
    position: relative;
    /* keep long labels clear of the ✓ */
    padding-right: 1.75rem !important;
}

.select2-container--default .select2-results__option.select2-results__option--selected::after {
    content: "✓";
    position: absolute;
    right: 0.6rem;
    color: var(--color-blue);
    font-weight: bold;
    font-size: 1rem;
}

.select2-container--default .select2-results__option[aria-disabled=true] {
    color: var(--text-muted) !important;
    opacity: 0.6;
}

.select2-container--default .select2-results__option--highlighted[aria-selected]:hover {
    background-color: rgba(var(--bs-primary-rgb), 0.15) !important;
}

/* Results groups */
.select2-container--default .select2-results__group {
    color: var(--text-tertiary) !important;
    font-size: 0.75rem !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    /* left-aligned with the 0.6rem option rows */
    padding: 0.5rem 0.6rem 0.25rem !important;
    margin: 0
}

/* Loading */
.select2-container--default .select2-results__message {
    color: var(--text-tertiary) !important;
    padding: 1rem !important;
}

/* Custom styles for the Voxtix chrome extension. */
.select2-results__option.select2-results__option--selectable .voxtix-phone-cls-0251 {
    color: black;
}
/** END SELECT 2 STYLES **/

/* --- box metrics ---------------------------------------------------------
   Sizing that keeps select2 in step with the other form controls; the
   matching .form-control rules live in theme-override.css under
   STANDARDIZED FORM-CONTROL HEIGHTS. Change these together. --- */

/* Select2's inner rendered span carries its own line-height — match. */
.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 36px !important;
    padding-left: 0 !important;
    padding-right: 1.5rem !important;
    font-size: 14px !important;
}

/* Multi-select grows vertically with chips — keep min-height at 38. */
.select2-container .select2-selection--multiple {
    min-height: 38px !important;
    height: auto !important;
    padding: 2px 6px !important;
}

.form-control-sm + .select2-container .select2-selection--single .select2-selection__rendered,
.input-group-sm > .select2-container .select2-selection--single .select2-selection__rendered {
    line-height: 30px !important;
    padding-left: 0 !important;
    padding-right: 1.25rem !important;
    font-size: 0.8125rem !important;
}

.form-control-lg + .select2-container .select2-selection--single .select2-selection__rendered,
.input-group-lg > .select2-container .select2-selection--single .select2-selection__rendered {
    line-height: 46px !important;
    padding-left: 0 !important;
    padding-right: 1.75rem !important;
    font-size: 1.25rem !important;
}

/* Large multi-select: 48px floor to match the single, chips scaled up with
   the type so they do not read as small controls in a tall box. */
.form-control-lg + .select2-container .select2-selection--multiple,
.input-group-lg > .select2-container .select2-selection--multiple {
    min-height: 48px !important;
    padding: 4px 10px !important;
    font-size: 1.25rem !important;
}
.form-control-lg + .select2-container .select2-selection--multiple .select2-selection__choice,
.input-group-lg > .select2-container .select2-selection--multiple .select2-selection__choice {
    font-size: 15px;
    padding: 2px 8px;
}
.form-control-lg + .select2-container .select2-selection--multiple .select2-search--inline .select2-search__field,
.input-group-lg > .select2-container .select2-selection--multiple .select2-search--inline .select2-search__field {
    height: 30px;
}

/* Small multi-select: same 32px floor as the other -sm controls,
   chips and inline search scaled down to fit. */
.form-control-sm + .select2-container .select2-selection--multiple,
.input-group-sm > .select2-container .select2-selection--multiple {
    min-height: 32px !important;
    padding: 1px 5px !important;
    font-size: 0.8125rem !important;
}
.form-control-sm + .select2-container .select2-selection--multiple .select2-selection__choice,
.input-group-sm > .select2-container .select2-selection--multiple .select2-selection__choice {
    font-size: 12px;
    padding: 0 5px;
}
.form-control-sm + .select2-container .select2-selection--multiple .select2-search--inline .select2-search__field,
.input-group-sm > .select2-container .select2-selection--multiple .select2-search--inline .select2-search__field {
    height: 20px;
}

/* --- inside an input group ------------------------------------------------
 *
 * select2 leaves the original <select> in place and renders its own wrapper
 * next to it, so the group's flex row ends up holding a box that matches none
 * of Bootstrap's `.input-group > .form-control` rules. Untreated it takes the
 * 100% width the container rule at the top of this file gives it and wraps
 * onto its own line, pushing the addons out of the group. The hidden <select>
 * itself needs nothing — select2 takes it out of flow. */
.input-group > .select2-container {
    flex: 1 1 auto;
    /* 1%, as Bootstrap does for a grouped .form-control: a nonzero basis that
       still shrinks, so a long value cannot push the addons out of the row.
       !important beats the 100% at the top of this file. */
    width: 1% !important;
    min-width: 0;
}

/* Bootstrap squares the seam corners of a grouped .form-control; the wrapper
   is not one, so its selection box is squared here on whichever side has a
   neighbour. */
.input-group > .input-group-prepend ~ .select2-container .select2-selection--single,
.input-group > .input-group-prepend ~ .select2-container .select2-selection--multiple {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

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

/* The group draws one ring around itself and every member inside it draws
   none (see Input groups in components/forms.css) — otherwise a second ring
   is trapped in the seam between the control and its addon. */
.input-group .select2-container--default.select2-container--focus .select2-selection--single,
.input-group .select2-container--default.select2-container--focus .select2-selection--multiple,
.input-group .select2-container--default.select2-container--open .select2-selection--single,
.input-group .select2-container--default.select2-container--open .select2-selection--multiple {
    box-shadow: none !important;
}

/* An open select2 puts focus in its search field, which lives in the menu in
   the top layer and not in the group, so `:focus-within` cannot hold the ring
   on for the one state that most needs it. Match the open widget instead. */
.input-group:has(.select2-container--open) {
    border-radius: 6px;
    box-shadow: var(--input-focus-ring);
}

.input-group:has(.select2-container--open) .input-group-text,
.input-group:has(.select2-container--open) .input-group-prepend > .btn,
.input-group:has(.select2-container--open) .input-group-append > .btn {
    border-color: var(--input-border-focus) !important;
}

/* --- the menu in the top layer -------------------------------------------- *
 *
 * A select2 inside an overlay has to reach the top layer or it paints behind it,
 * so its menu is promoted to a popover on open (js/components/select2.js). The
 * promoted element is select2's own body-level wrapper: a bare positioning box
 * with no surface of its own, the visible card being .select2-dropdown inside it.
 * So every part of the UA's popover chrome has to be cleared, or the wrapper
 * paints as a small white bordered card around nothing.
 *
 * Position, top, left and width are written from JS. Width in particular, because
 * the widget's own _positionDropdown is replaced there — placement is Floating UI's
 * job — and setting the wrapper's width was the other thing it did. */
.select2-container[popover] {
    margin: 0;
    inset: auto;
    padding: 0;
    border: 0;
    background: none;
    overflow: visible;
}

/* select2 hides the menu off-canvas at `left: -100000px` and drops it back to 0
   once open, which only works while the wrapper is a positioned ancestor with a
   height of zero. In the top layer that leaves Floating UI measuring an empty box,
   so it can never know the menu does not fit and flip it above the input. In flow,
   the wrapper takes the menu's real size and placement works on true numbers. */
.select2-container[popover] > .select2-dropdown {
    position: static;
}
