/*
 * Select2 Custom Styling
 * Consistent multi-select styling for Select2 v4.1.0 + Bootstrap 5 theme.
 * Uses CSS custom properties for easy theming.
 */


/* ── 1. Design Tokens ──────────────────────────────────────────── */

:root {
    --s2-primary: #0d6efd;
    --s2-primary-focus-ring: rgba(13, 110, 253, 0.25);
    --s2-danger: #dc3545;
    --s2-border: #dee2e6;
    --s2-bg: #ffffff;
    --s2-text: #212529;
    --s2-muted: #6c757d;
    --s2-light-bg: #f8f9fa;
    --s2-font-size: 0.875rem;
    --s2-min-height: 45px;
    --s2-border-radius: 0.375rem;
    --s2-pill-radius: 0.25rem;
    --s2-pill-padding: 0.25rem 0.5rem;
    --s2-search-min-width: 150px;
    --s2-transition: 0.15s ease;
}


/* ── 2. Base Container ─────────────────────────────────────────── */

.select2-container--bootstrap-5 .select2-selection {
    min-height: var(--s2-min-height);
    border: 1px solid var(--s2-border) !important;
    background-color: var(--s2-bg) !important;
    border-radius: var(--s2-border-radius);
    padding: 0.25rem 0.5rem;
}

.select2-container--bootstrap-5 .select2-selection--multiple {
    padding: 0.375rem 0.5rem !important;
}


/* ── 3. Pills (Selected Items) ─────────────────────────────────── */

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice {
    background-color: var(--s2-primary) !important;
    border: 1px solid var(--s2-primary) !important;
    color: var(--s2-bg) !important;
    padding: var(--s2-pill-padding) !important;
    margin: 0.125rem 0.25rem 0.125rem 0 !important;
    border-radius: var(--s2-pill-radius) !important;
    font-size: var(--s2-font-size) !important;
    line-height: 1.5 !important;
    display: inline-flex !important;
    align-items: center !important;
    max-width: 100% !important;
    vertical-align: middle !important;
    white-space: nowrap !important;
    float: none !important;
    flex-shrink: 0 !important;
}

/* Pill text — truncate with ellipsis */
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice__display {
    padding-left: 0 !important;
    padding-right: 0 !important;
    color: var(--s2-bg) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Pills container — flexbox wrapping */
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered {
    padding: 0 !important;
    margin: 0 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
    list-style: none !important;
}


/* ── 4. Remove Button (x) on Pills ─────────────────────────────── */

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice__remove {
    color: var(--s2-bg) !important;
    background: transparent !important;
    border: none !important;
    margin-right: 0.5rem !important;
    margin-left: 0 !important;
    padding: 0 !important;
    font-size: 1.4rem !important;
    font-weight: 700 !important;
    line-height: 1 !important;
    cursor: pointer !important;
    order: -1 !important;
    transition: all var(--s2-transition) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 0.9 !important;
    text-indent: 0 !important;
    overflow: visible !important;
    white-space: nowrap !important;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice__remove:hover {
    opacity: 1 !important;
    transform: scale(1.2) !important;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice__remove::before {
    content: '\00D7' !important;
    font-size: 1.4rem !important;
    line-height: 1 !important;
    font-weight: 700 !important;
}


/* ── 5. Search Input ───────────────────────────────────────────── */

.select2-container--bootstrap-5 .select2-search--inline {
    display: inline-block !important;
    vertical-align: middle !important;
    flex-grow: 1 !important;
    min-width: var(--s2-search-min-width) !important;
}

.select2-container--bootstrap-5 .select2-search--inline .select2-search__field {
    margin: 0 !important;
    padding: 0.375rem 0.5rem !important;
    min-width: var(--s2-search-min-width) !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    line-height: 1.5 !important;
    border: none !important;
    background: transparent !important;
    color: var(--s2-text) !important;
    font-size: var(--s2-font-size) !important;
    outline: none !important;
    box-sizing: border-box !important;
}

.select2-container--bootstrap-5 .select2-search--inline .select2-search__field::placeholder {
    color: var(--s2-muted) !important;
    opacity: 1 !important;
}

.select2-container--bootstrap-5 .select2-search--inline .select2-search__field:focus {
    outline: none !important;
    box-shadow: none !important;
    border: none !important;
}


/* ── 6. Dropdown & Options ─────────────────────────────────────── */

.select2-container--bootstrap-5 .select2-dropdown {
    border: 1px solid var(--s2-border) !important;
    border-radius: var(--s2-border-radius) !important;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
    background-color: var(--s2-bg) !important;
}

.select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field {
    border: 1px solid var(--s2-border) !important;
    border-radius: var(--s2-pill-radius) !important;
    padding: 0.5rem !important;
    margin: 0.5rem !important;
    width: calc(100% - 1rem) !important;
}

.select2-container--bootstrap-5 .select2-results__option {
    padding: 0.5rem 1rem !important;
    color: var(--s2-text) !important;
    background-color: var(--s2-bg) !important;
}

/* Highlighted option */
.select2-container--bootstrap-5 .select2-results__option--highlighted {
    background-color: var(--s2-primary) !important;
    color: var(--s2-bg) !important;
}

.select2-container--bootstrap-5 .select2-results__option--highlighted i {
    color: var(--s2-bg) !important;
}

/* Hide already-selected options from dropdown */
.select2-container--bootstrap-5 .select2-results__option--selected {
    display: none !important;
}

.select2-container--bootstrap-5 .select2-results__option--selected::after {
    display: none !important;
}


/* ── 7. States ─────────────────────────────────────────────────── */

/* Focus */
.select2-container--bootstrap-5.select2-container--focus .select2-selection {
    border-color: #86b7fe !important;
    box-shadow: 0 0 0 0.25rem var(--s2-primary-focus-ring) !important;
}

/* Validation error — applied by JS via .border-danger */
.select2-container.border-danger .select2-selection {
    border-color: var(--s2-danger) !important;
}

/* Disabled options */
.select2-container--bootstrap-5 .select2-results__option[aria-disabled=true] {
    color: var(--s2-muted) !important;
    background-color: var(--s2-light-bg) !important;
}

/* No results message */
.select2-container--bootstrap-5 .select2-results__option.select2-results__message {
    color: var(--s2-muted) !important;
    font-style: italic !important;
}

/* Placeholder */
.select2-container--bootstrap-5 .select2-selection__placeholder {
    color: var(--s2-muted) !important;
}

/* Clear button spacing */
.select2-container--bootstrap-5 .select2-selection__clear {
    margin-right: 0.5rem !important;
}


/* ── 8. Utility Classes (used by JS templates) ─────────────────── */

/* Dropdown item icon — avoids inline style in JS */
.select2-template-icon {
    font-size: var(--s2-font-size);
    line-height: 1;
    flex-shrink: 0;
}
