/* Select2 dark theme — override vendor defaults */

/* ---- Container ---- */

.select2-container {
    width: 100%;
    max-width: var(--control-width);
}

.division-editor-form .select2-container {
    min-width: 16rem;
}

/* ---- Selection box (single) ---- */

.select2-container--default .select2-selection--single {
    box-sizing: border-box;
    position: relative;
    height: 2.25em;
    background-color: var(--bg-panel);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    transition: background-color var(--transition),
                border-color var(--transition),
                box-shadow var(--transition);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    box-sizing: border-box;
    height: 100%;
    line-height: calc(2.25em - 2px);
    padding-left: 0.6em;
    padding-right: 2.8em;
    color: var(--text-main);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Arrow */

.select2-container--default .select2-selection--single .select2-selection__arrow {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 1.8em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: var(--text-muted) transparent transparent transparent;
    border-width: 5px 4px 0 4px;
    border-style: solid;
}

.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent var(--text-muted) transparent;
    border-width: 0 4px 5px 4px;
}

/* Clear button — positioned at far right */

.select2-container--default .select2-selection--single .select2-selection__clear {
    position: absolute;
    right: 1.6em;
    top: 50%;
    transform: translateY(-40%);
    color: var(--text-muted);
    font-size: 0.85em;
    line-height: 1;
    padding: 0;
    margin-top: 0;
    background: none;
    border: none;
    cursor: pointer;
    width: auto;
    height: auto;
    max-width: none;
}

.select2-container--default .select2-selection--single .select2-selection__clear:hover {
    color: var(--text-main);
}

/* When clear is visible, shift arrow right and increase rendered padding */

.select2-container--default .select2-selection--single .select2-selection__clear ~ .select2-selection__arrow {
    right: 0;
}

/* ---- Selection box (multiple) ---- */

.select2-container--default .select2-selection--multiple {
    box-sizing: border-box;
    min-height: 2.25em;
    background-color: var(--bg-panel);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.15em 0.4em;
    outline: none;
    transition: background-color var(--transition),
                border-color var(--transition),
                box-shadow var(--transition);
}

/* The global button width (forms.css) would stretch the clear button across
   the whole selection box; pin it to a small fixed square at the right. */

.select2-container--default .select2-selection--multiple .select2-selection__clear {
    width: var(--space-5);
    max-width: none;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: var(--bg-accent);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.05em 1.25em 0.05em 0.35em;
    line-height: 1.5;
    margin: 0.15em 0.2em;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    left: auto;
    right: 0;
    border-right: none;
    border-left: 1px solid var(--border-color);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-top-right-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
    color: var(--text-muted);
    width: auto;
    max-width: none;
    height: 100%;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: var(--danger);
}

/* "not" (exclude) toggle — left segment of the shelf chip, mirroring the
   __choice__remove segment but pinned to the leading edge */

.select2-container--default .select2-selection--multiple .select2-selection__choice:has(.select2-selection__choice__not) {
    padding-left: 1.5em;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__not {
    position: absolute;
    left: 0;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.25em;
    height: 100%;
    border: none;
    border-right: 1px solid var(--border-color);
    border-top-left-radius: var(--radius-sm);
    border-bottom-left-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    font-size: 0.9em;
    font-weight: 700;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__not:hover {
    color: var(--text-main);
    background-color: var(--bg-hover);
}

.select2-container--default .select2-selection--multiple .select2-selection__choice--not {
    border-color: var(--danger-border);
    background-color: var(--danger-bg);
}

.select2-container--default .select2-selection--multiple .select2-selection__choice--not .select2-selection__choice__not {
    color: var(--danger-light);
    border-right-color: var(--danger-border);
    background-color: var(--danger-bg);
}

/* ---- Focus ---- */

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--multiple {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-ring);
}

/* ---- Disabled ---- */

.select2-container--default.select2-container--disabled .select2-selection--single,
.select2-container--default.select2-container--disabled .select2-selection--multiple {
    background-color: var(--bg-main);
    border-style: dashed;
    opacity: 0.45;
    cursor: not-allowed;
}

.select2-container--default.select2-container--disabled .select2-selection__arrow {
    display: none;
}

/* ---- Dropdown panel ---- */

.select2-dropdown {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    z-index: 1200;
}

.select2-search--dropdown .select2-search__field {
    box-sizing: border-box;
    width: 100%;
    background-color: var(--bg-main);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.4em 0.6em;
    font-family: inherit;
}

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

/* The inline search field inside multi-selects is a textarea, which the
   generic forms.css color rule (input/select/button) does not cover —
   without this it renders with the browser-default black text and caret. */

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

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

.select2-search--dropdown .select2-search__field:focus {
    border-color: var(--primary);
    outline: none;
}

/* ---- Results list ---- */

.select2-container--default .select2-results__options {
    max-height: 14em;
}

.select2-container--default .select2-results__option {
    color: var(--text-main);
    padding: 0.45em 0.65em;
}

.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background-color: var(--bg-hover);
    color: var(--text-main);
}

.select2-container--default .select2-results__option[aria-selected="true"] {
    background-color: var(--bg-accent);
    color: var(--text-main);
}

.select2-container--default .select2-results__option--highlighted[aria-selected="true"] {
    background-color: var(--bg-hover);
    color: var(--text-main);
}

/* ---- No results ---- */

.select2-container--default .select2-results__message {
    color: var(--text-muted);
    padding: 0.45em 0.65em;
}

/* ---- Inline-create suggestion ---- */

.select2-create-option {
    color: var(--primary);
    font-style: italic;
}
