/* rf-select2.css — THE ONE SELECT2 STYLESHEET (RF-UI-FOUNDATION-20261110).

   Owner of every Select2 rule in a generated application. Behaviour lives in js/Services/select2-global.js.
   It sits on top of the vendor files (vendor/select2: select2.min.css 4.1.0-rc.0 and the bootstrap-5 theme 1.3.0) and loads
   after rf-baseline.css, so equal specificity wins without !important. Before this file the same component was styled in
   Site.css, Validation.css, Ar.css, rf-baseline.css, rf-components.css and attachments.css; those rules were moved here.
   Theme tokens only (fallback = the vendor value, so a legacy profile renders as before). Never copy Select2 rules into
   app-overrides.css or a page: change them here. */

/* ---- 1. Container -------------------------------------------------------------------------------------------------- */
/* The enhanced control always tracks its grid cell (form fields, filters, the attachment upload row). */
.select2-container {
    width: 100% !important; /* Select2 writes an inline width; the cell owns the width */
    font-size: 14px;
}

.select2-container .select2-selection__placeholder {
    color: var(--input-placeholder, #6c757d);
}

.select2-container .select2-selection__arrow {
    height: 100%;
}

/* RF-UI-REVIEW-20261110: the selection takes the shared control geometry (base/variables.css) — height, 14 px text,
   radius, border and surface — so a Select2 field is the twin of the text input and native select beside it (it was
   38 px with 16 px text and a 4 px corner next to 35 px / 14 px / 10 px inputs). */
.select2-container--bootstrap-5 .select2-selection {
    min-height: var(--rf-control-height, calc(1.5em + .75rem + 2px));
    font-size: var(--rf-control-font, 1rem);
    border-color: var(--input-border, #ced4da);
    border-radius: var(--rf-control-radius, .375rem);
    background-color: var(--input-bg, #fff);
    color: var(--input-fg, inherit);
}

.select2-container--bootstrap-5 .select2-selection--single {
    display: flex;
    align-items: center;
    padding-block: 0;
    padding-inline-start: var(--rf-control-pad-x, .75rem);
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    flex: 1 1 auto;
    min-inline-size: 0;
}

.select2-container--bootstrap-5 .select2-dropdown {
    font-size: var(--rf-control-font, 1rem);
}

.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
    border-color: var(--primary-base1, #86b7fe);
    box-shadow: var(--btn-focus-ring, 0 0 0 .25rem rgba(13, 110, 253, .25));
}

.select2-container .select2-dropdown {
    border: 1px solid var(--input-border, #ced4da);
    border-radius: var(--rf-radius-input, 4px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, .1);
    z-index: 9999; /* above the page chrome; a dialog's Select2 is parented inside the dialog */
}

/* Matching / selected option: the theme's primary colour instead of the vendor blue. */
.select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option.select2-results__option--highlighted {
    background-color: color-mix(in srgb, var(--rf-color-primary, #0d6efd) 12%, transparent);
    color: inherit;
}

.select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option.select2-results__option--selected,
.select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option[aria-selected=true]:not(.select2-results__option--highlighted) {
    background-color: var(--rf-color-primary, #0d6efd);
    color: #fff;
}

/* ---- 2. Direction (the bootstrap-5 theme has no RTL rules) ---------------------------------------------------------- */
/* The chevron is a background image on the right and the clear button sits 2.25rem from the right; in Arabic both move to
   the end (left) side, like a native select, and the text gets the matching padding. */
.select2-container--bootstrap-5[dir="rtl"] .select2-selection--single {
    padding-right: .75rem;
    padding-left: 2.25rem;
    background-position: left .75rem center;
}

.select2-container--bootstrap-5[dir="rtl"] .select2-selection--single .select2-selection__rendered {
    padding-right: 0;
    padding-left: 1rem;
    text-align: right;
}

.select2-container--bootstrap-5[dir="rtl"] .select2-selection--single .select2-selection__clear {
    right: auto;
    left: 2.25rem;
}

.select2-container--bootstrap-5[dir="rtl"] .select2-selection--multiple .select2-selection__clear {
    right: auto;
    left: .75rem;
}

.select2-container--bootstrap-5[dir="rtl"] .select2-selection--multiple .select2-selection__rendered .select2-selection__choice {
    margin-right: 0;
    margin-left: .375rem;
}

.select2-container--bootstrap-5[dir="rtl"] .select2-selection--multiple .select2-selection__rendered .select2-selection__choice .select2-selection__choice__remove {
    margin-right: 0;
    margin-left: .25rem;
}

.select2-container--bootstrap-5[dir="rtl"] .select2--small.select2-selection--single {
    padding-right: .5rem;
    padding-left: 2.25rem;
}

/* ---- 3. Focus (DEF22-COMPLIANCE G8b: an opaque ring instead of the vendor's 25% blue, about 1.4:1) ------------------- */
.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection,
.select2-container--bootstrap-5 .select2-dropdown .select2-search .select2-search__field:focus {
    box-shadow: var(--rf-focus-ring, 0 0 0 .25rem rgba(13, 110, 253, .25));
}

/* ---- 4. Validation ---------------------------------------------------------------------------------------------------
   The select keeps the state class (jQuery Validate input-validation-error, Bootstrap is-invalid, Parsley parsley-error);
   the Select2 container is its next sibling. The container classes are the older API (validation scripts that mark it). */
select.parsley-error + .select2-container .select2-selection,
select.is-invalid + .select2-container .select2-selection,
select.input-validation-error + .select2-container .select2-selection,
.select2-container.is-invalid .select2-selection {
    border-color: var(--rf-color-danger, #dc3545);
}

select.is-valid + .select2-container .select2-selection,
.select2-container.is-valid .select2-selection {
    border-color: var(--rf-color-success, #28a745);
}

select.parsley-error + .select2-container.select2-container--focus .select2-selection,
select.is-invalid + .select2-container.select2-container--focus .select2-selection,
select.input-validation-error + .select2-container.select2-container--focus .select2-selection {
    box-shadow: 0 0 0 .25rem color-mix(in srgb, var(--rf-color-danger, #dc3545) 25%, transparent);
}

/* Disabled / read-only (a dependent lookup waits for its parent). */
.select2-container--bootstrap-5.select2-container--disabled .select2-selection {
    cursor: not-allowed;
    opacity: .75;
}

/* ---- 5. Generic Add/Edit dialog ------------------------------------------------------------------------------------- */
/* Lookup (relationship) selects carry long human-readable names: a full row while the dialog is not wide, and a long chosen
   value wraps onto a second line instead of being cut with an ellipsis. */
@container (max-width: 759px) {
    #genericModalBody .row > [class*="col-"]:has(> select.select2),
    #genericModalBody .row > [class*="col-"]:has(> .select2-container) {
        width: 100%;
        max-width: 100%;
    }
}

#genericModalBody .select2-container .select2-selection--single {
    height: auto;
    min-height: 38px;
    display: flex;
    align-items: center;
}

    #genericModalBody .select2-container .select2-selection--single .select2-selection__rendered {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        line-height: 1.4;
    }

/* ---- 6. Phone touch targets (DEF22-G19 P2; fallback = the vendor height) ------------------------------------------- */
@media (max-width: 575.98px) {
    .select2-container--bootstrap-5 .select2-selection {
        min-height: var(--rf-touch-target, calc(1.5em + .75rem + 2px));
        align-content: var(--rf-touch-align, normal);
    }

    .select2-container--bootstrap-5 .select2--small.select2-selection,
    .form-select-sm ~ .select2-container--bootstrap-5 .select2-selection {
        min-height: var(--rf-touch-target, calc(1.5em + .5rem + 2px));
    }

    #genericModalBody .select2-container .select2-selection--single {
        min-height: var(--rf-touch-target, 38px);
    }
}

/* ---- 7. Dark mode (theme-modes.css tokens) -------------------------------------------------------------------------- */
html[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection--single,
html[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection--multiple {
    background-color: var(--input-bg);
    color: var(--input-fg);
    border-color: var(--input-border);
}

/* The vendor chevron is drawn dark (#343a40); in dark mode it is drawn light. */
html[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection--single {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23cbd5e1' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
}

html[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection__rendered {
    color: var(--input-fg);
}

html[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection__placeholder {
    color: var(--input-placeholder);
}

html[data-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown {
    background-color: var(--dropdown-bg);
    color: var(--dropdown-fg);
    border-color: var(--dropdown-border);
}

html[data-theme="dark"] .select2-container--bootstrap-5 .select2-search__field {
    background-color: var(--input-bg);
    color: var(--input-fg);
    border-color: var(--input-border);
}

html[data-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option.select2-results__option--highlighted {
    background-color: var(--menu-hover-bg);
    color: var(--menu-fg);
}

html[data-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option[aria-selected=true]:not(.select2-results__option--highlighted) {
    background-color: var(--menu-active-bg);
    color: var(--menu-active-fg);
}

html[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered .select2-selection__choice {
    background-color: var(--dropdown-bg);
    color: var(--input-fg);
    border-color: var(--input-border);
}

html[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection__clear {
    filter: invert(1) grayscale(1);
}

/* ---- 8. Kidora additions (feature 24) ---------------------------------------------------------------------------------- */
/* Arabic has no italic: the placeholder was drawn in a synthetic slant. */
.select2-container .select2-selection__placeholder { font-style: normal; }
