/*
 * Select2 Bootstrap 5 Theme for KTUI/Metronic
 * Matches the KTUI design system variables (--input, --background, --foreground, etc.)
 * Used with select2.init.js which sets theme: "bootstrap5"
 */

/* ============================================
   Selection (trigger element)
   ============================================ */
.select2-container--bootstrap5 .select2-selection {
    box-shadow: none;
    height: auto;
    outline: none !important;
    border: 1px solid var(--input);
    background-color: var(--background);
    border-radius: var(--radius, 0.5rem);
    transition: color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Focus & open states */
.select2-container--bootstrap5.select2-container--focus:not(.select2-container--disabled) .select2-selection,
.select2-container--bootstrap5.select2-container--open:not(.select2-container--disabled) .select2-selection {
    border-color: var(--ring);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 30%, transparent);
}

/* Disabled state */
.select2-container--bootstrap5.select2-container--disabled .select2-selection {
    background-color: var(--muted, #f4f4f5);
    border-color: var(--input);
    cursor: not-allowed;
    opacity: 0.6;
}

/* ============================================
   Single select mode
   ============================================ */
.select2-container--bootstrap5 .select2-selection--single {
    display: flex;
    align-items: center;
    padding: 0.5rem 2.25rem 0.5rem 0.75rem;
    min-height: 2.5rem;
}

.select2-container--bootstrap5 .select2-selection--single .select2-selection__rendered {
    display: block;
    padding-left: 0;
    padding-right: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--foreground);
    line-height: 1.5;
    font-size: 0.875rem;
}

.select2-container--bootstrap5 .select2-selection--single .select2-selection__placeholder {
    color: var(--muted-foreground);
}

/* ============================================
   Multiple select mode
   ============================================ */
.select2-container--bootstrap5 .select2-selection--multiple {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.25rem 0.5rem;
    min-height: 2.5rem;
    gap: 0.25rem;
}

.select2-container--bootstrap5 .select2-selection--multiple .select2-selection__rendered {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Tags (selected choices) */
.select2-container--bootstrap5 .select2-selection--multiple .select2-selection__choice {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.5rem;
    border-radius: calc(var(--radius, 0.5rem) - 2px);
    background-color: var(--muted, #f4f4f5);
    color: var(--foreground);
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
    border: none;
}

/* Tag remove button */
.select2-container--bootstrap5 .select2-selection--multiple .select2-selection__choice__remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    order: 2;
    cursor: pointer;
    border: 0;
    padding: 0;
    background: none;
    color: var(--muted-foreground);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.15s ease;
}

.select2-container--bootstrap5 .select2-selection--multiple .select2-selection__choice__remove:hover {
    opacity: 1;
    color: var(--destructive, #ef4444);
}

/* Search input inside multi-select */
.select2-container--bootstrap5 .select2-search--inline .select2-search__field {
    color: var(--foreground);
    font-family: inherit !important;
    font-size: 0.875rem;
    background-color: transparent;
    border: 0;
    box-shadow: none;
    outline: none;
    line-height: 1.5;
    margin: 0;
    padding: 0.15rem 0;
    min-width: 5em;
}

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

/* ============================================
   Dropdown
   ============================================ */
.select2-container--bootstrap5 .select2-dropdown {
    border: 1px solid var(--border);
    border-radius: var(--radius, 0.5rem);
    padding: 0.25rem 0;
    background-color: var(--background);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    overflow: hidden;
}

/* Dropdown below */
.select2-container--bootstrap5.select2-container--open.select2-container--below .select2-selection {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.select2-container--bootstrap5.select2-container--open.select2-container--below .select2-dropdown {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-top: none;
}

/* Dropdown above */
.select2-container--bootstrap5.select2-container--open.select2-container--above .select2-selection {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.select2-container--bootstrap5.select2-container--open.select2-container--above .select2-dropdown {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: none;
}

/* Search inside dropdown */
.select2-container--bootstrap5 .select2-search--dropdown {
    padding: 0.5rem 0.75rem;
}

.select2-container--bootstrap5 .select2-search--dropdown .select2-search__field {
    width: 100%;
    padding: 0.375rem 0.625rem;
    font-size: 0.8125rem;
    color: var(--foreground);
    background-color: var(--background);
    border: 1px solid var(--input);
    border-radius: calc(var(--radius, 0.5rem) - 2px);
    outline: none;
    transition: border-color 0.15s ease;
}

.select2-container--bootstrap5 .select2-search--dropdown .select2-search__field:focus {
    border-color: var(--ring);
}

/* ============================================
   Options
   ============================================ */
.select2-container--bootstrap5 .select2-results > .select2-results__options {
    max-height: 250px;
    overflow-y: auto;
}

.select2-container--bootstrap5 .select2-results__option {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: var(--foreground);
    transition: background-color 0.1s ease, color 0.1s ease;
    cursor: pointer;
}

/* Highlighted (hovered) option */
.select2-container--bootstrap5 .select2-results__option--highlighted {
    background-color: var(--muted, #f4f4f5);
    color: var(--foreground);
}

/* Selected option */
.select2-container--bootstrap5 .select2-results__option--selected,
.select2-container--bootstrap5 .select2-results__option[aria-selected="true"] {
    background-color: color-mix(in oklab, var(--primary) 10%, transparent);
    color: var(--primary);
    font-weight: 500;
}

/* Disabled option */
.select2-container--bootstrap5 .select2-results__option--disabled,
.select2-container--bootstrap5 .select2-results__option[aria-disabled="true"] {
    color: var(--muted-foreground);
    cursor: not-allowed;
    opacity: 0.5;
}

/* "No results" message */
.select2-container--bootstrap5 .select2-results__message {
    color: var(--muted-foreground);
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
}

/* Option group */
.select2-container--bootstrap5 .select2-results__option--group .select2-results__group {
    display: block;
    color: var(--foreground);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.5rem 0.75rem 0.25rem;
}

/* ============================================
   Clear button
   ============================================ */
.select2-container--bootstrap5 .select2-selection__clear {
    position: absolute;
    right: 2.25rem;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--muted-foreground);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
    opacity: 0.5;
    transition: opacity 0.15s ease;
    background: none;
    border: 0;
    padding: 0;
}

.select2-container--bootstrap5 .select2-selection__clear:hover {
    opacity: 1;
    color: var(--destructive, #ef4444);
}

/* ============================================
   In modals - ensure proper z-index
   ============================================ */
.modal-open .select2-container--bootstrap5 .select2-dropdown {
    z-index: 10060;
}

/* Select2 container that is appended to body */
body > .select2-container--bootstrap5 {
    z-index: 9999;
}
