.select2-container {
    width: 100% !important;
}

.select2-selection {
    border: 1px solid #ced4da !important;
    border-radius: 7px;
}

/* Fix multiple selection box height */
.select2-selection--multiple {
    min-height: calc(1.5em + 0.75rem + 2px) !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    position: relative !important;
}

/* Dropdown arrow indicator */
.select2-selection--multiple:before {
    content: "";
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 5px solid #888;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    pointer-events: none;
    z-index: 10;
}

/* Clear all button - position on the far left */
.select2-selection__clear {
    position: absolute !important;
    left: 8px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 20px !important;
    height: 20px !important;
    line-height: 20px !important;
    text-align: center !important;
    font-size: 1.2em !important;
    font-weight: bold !important;
    color: #999 !important;
    cursor: pointer !important;
    padding: 0 !important;
    margin: 0 !important;
    z-index: 11 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.select2-selection__clear:hover {
    color: #d9534f !important;
}

/* Add padding to selection rendered area to make room for clear button */
.select2-selection--multiple .select2-selection__rendered {
    padding-left: 32px !important;
}

.select2-dropdown {
    background-color: white;
    border-left: 1px solid #ced4da !important;
    border-right: 1px solid #ced4da !important;
    border-bottom: 1px solid #ced4da !important;

    border-bottom-right-radius: 7px;
    border-bottom-left-radius: 7px;

    /* Fix positioning gap - align dropdown directly below select box */
    margin-top: -1px !important;
    padding-top: 0 !important;
    transform: translateY(0) !important;
}

/* Search field inside the dropdown menu */
.select2-dropdown .select2-search__field {
    margin-top: 7px !important;
    margin-left: 12px !important;
    padding-top: 0px !important;
    height: 24px !important;
}

/* Inline search container - should not add extra height */
.select2-search--inline {
    display: inline-block !important;
    vertical-align: middle !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Inline search field inside the selection box - fix positioning */
.select2-search--inline .select2-search__field {
    margin: 0 !important;
    padding: 0 !important;
    height: 1.5em !important;
    max-height: 1.5em !important;
    min-height: 1.5em !important;
    line-height: 1.5em !important;
    vertical-align: middle !important;
    border: none !important;
    box-sizing: border-box !important;
    resize: none !important;
    overflow: hidden !important;
}

/* Selection rendered area should display items inline */
.select2-selection__rendered {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    padding: 0.375rem 0.75rem !important;
    margin: 0 !important;
    gap: 4px !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.select2-results__option--highlighted[aria-selected] {
    background-color: var(--secondary) !important;
    color: white !important;
}

/* Selected items (badges) styling */
.select2-selection__choice {
    margin: 0 !important;
    padding: 2px 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    max-height: 1.5em !important;
}

.select2-selection__choice__display {
    padding-left: 20px !important;
    line-height: 1.5em !important;
}

.select2-selection__choice__remove {
    margin-right: 4px !important;
}

/* Fix dropdown positioning - remove all gaps */
.select2-container--default.select2-container--open .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--multiple {
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

/* Fix for dropdown positioning when attached to body (below) */
.select2-container--default .select2-dropdown--below {
    border-top: none !important;
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
    margin-top: -1px !important;
    transform: translateY(0) !important;
}

/* Fix for dropdown positioning when attached to body (above) */
.select2-container--default .select2-dropdown--above {
    border-bottom: none !important;
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    margin-bottom: -1px !important;
    transform: translateY(0) !important;
}

/* Additional fix for body-attached dropdowns */
body > .select2-container--default.select2-container--open .select2-dropdown {
    margin-top: -1px !important;
    transform: translateY(0) !important;
}

/* Specifically target the dropdown when it appears below */
.select2-container--open .select2-dropdown--below {
    top: 100% !important;
}

/* DARK MODE SUPPORT */
[data-theme="dark"] .select2-selection {
    background-color: #2A2A2A !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #E9ECEF !important;
}

[data-theme="dark"] .select2-dropdown {
    background-color: #2A2A2A !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #E9ECEF !important;
}

[data-theme="dark"] .select2-search__field {
    background-color: #2A2A2A !important;
    color: #E9ECEF !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

[data-theme="dark"] .select2-results__option {
    background-color: #2A2A2A !important;
    color: #E9ECEF !important;
}

[data-theme="dark"] .select2-results__option--highlighted[aria-selected] {
    background-color: #00B0B9 !important;
    color: #FFFFFF !important;
}

[data-theme="dark"] .select2-selection__choice {
    background-color: rgba(255, 255, 255, 0.1) !important;
    color: #E9ECEF !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

[data-theme="dark"] .select2-selection__choice__remove {
    color: #E9ECEF !important;
}

[data-theme="dark"] .select2-selection__choice__remove:hover {
    color: #DC3545 !important;
}