/**
 * Nestiko — global Select2 dropdown polish (all pages).
 * Improves floating panel, search, options, scrollbar; works with dropdownParent: body or in-place.
 * Dark overrides: :root[data-theme='dark']
 * Scoped dark menus (e.g. contact supplier switch) stay in nestiko-users.css — they win via extra class + load order.
 */

/* Open container above headers / scroll regions (below modals that use 10500+ if any) */
.select2-container--open {
    z-index: 5005 !important;
}

.select2-dropdown {
    font-family: inherit;
    font-size: 0.8125rem;
    line-height: 1.35;
    border: 1px solid var(--nk-s2-border, #e2e8f0) !important;
    border-radius: 0.75rem !important;
    background: var(--nk-s2-surface, #ffffff) !important;
    box-shadow:
        0 20px 48px rgba(15, 23, 42, 0.12),
        0 0 0 1px rgba(15, 23, 42, 0.04);
    overflow: hidden;
    color: var(--nk-s2-text, #0f172a);
    margin-top: 0.3rem;
}

.select2-dropdown.select2-dropdown--above {
    margin-top: 0;
    margin-bottom: 0.3rem;
    box-shadow:
        0 -18px 44px rgba(15, 23, 42, 0.11),
        0 0 0 1px rgba(15, 23, 42, 0.04);
}

/* —— Search —— */
.select2-search--dropdown {
    padding: 0.55rem 0.65rem 0.5rem;
    border-bottom: 1px solid var(--nk-s2-border, #e2e8f0);
    background: var(--nk-s2-search-bg, #f8fafc);
}

.select2-search--dropdown .select2-search__field {
    width: 100% !important;
    margin: 0 !important;
    padding: 0.45rem 0.65rem 0.45rem 2.1rem !important;
    border: 1px solid var(--nk-s2-border, #dbe2ea) !important;
    border-radius: 0.5rem !important;
    background-color: var(--nk-s2-surface, #ffffff) !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.6rem 50%;
    background-size: 0.92rem 0.92rem;
    color: var(--nk-s2-text, #0f172a) !important;
    font-size: 0.8125rem !important;
    font-weight: 500;
    line-height: 1.35 !important;
    box-shadow: none !important;
}

.select2-search--dropdown .select2-search__field::placeholder {
    color: var(--nk-s2-muted, #94a3b8);
}

.select2-search--dropdown .select2-search__field:focus {
    border-color: rgba(139, 92, 246, 0.55) !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.14) !important;
}

html[dir='rtl'] .select2-search--dropdown .select2-search__field {
    padding: 0.45rem 2.1rem 0.45rem 0.65rem !important;
    background-position: calc(100% - 0.6rem) 50%;
}

/* —— Results list —— */
.select2-results > .select2-results__options {
    max-height: 16.5rem !important;
    padding: 0.35rem 0;
    /* Scrollbars: nestiko-scrollbars-global.css (same as sidebar) */
}

.select2-results__option {
    margin: 0.08rem 0.4rem;
    padding: 0.5rem 0.7rem !important;
    border-radius: 0.45rem;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.35;
    white-space: normal;
    word-break: break-word;
    color: var(--nk-s2-text, #1e293b) !important;
    border-left: none !important;
    transition: background 0.12s ease, color 0.12s ease;
}

.select2-results__option--highlighted,
.select2-results__option--highlighted.select2-results__option--selectable {
    background: rgba(139, 92, 246, 0.12) !important;
    color: var(--nk-s2-text, #0f172a) !important;
}

.select2-results__option[aria-selected='true'] {
    background: rgba(31, 44, 70, 0.06) !important;
    color: var(--nk-s2-text, #0f172a) !important;
    font-weight: 600;
}

.select2-results__option[aria-selected='true'].select2-results__option--highlighted {
    background: rgba(139, 92, 246, 0.14) !important;
}

.select2-results__message {
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    color: var(--nk-s2-muted, #64748b);
}

.select2-results__option--loading,
.select2-results__option--disabled {
    color: var(--nk-s2-muted, #94a3b8) !important;
    opacity: 0.85;
}

/* Group labels */
.select2-results__group {
    padding: 0.5rem 0.85rem 0.25rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--nk-s2-muted, #64748b);
}

/* —— Dark theme (app shell) —— */
:root[data-theme='dark'] {
    --nk-s2-border: #334155;
    --nk-s2-surface: #1e293b;
    --nk-s2-search-bg: #0f172a;
    --nk-s2-text: #f1f5f9;
    --nk-s2-muted: #94a3b8;
    /* Match Nestiko dark form fields (nestiko-users .form-control) */
    --nk-s2-selection-bg: #1a2740;
    --nk-s2-selection-border: #334866;
}

/*
 * Closed Select2 control surfaces — vendor Select2 uses background #fff on .select2-selection--single / --multiple.
 * Without this, dark mode shows bright white boxes while text is forced light (unreadable).
 */
:root[data-theme='dark'] .select2-container--default .select2-selection--single,
:root[data-theme='dark'] .select2-container--default .select2-selection--multiple {
    background-color: var(--nk-s2-selection-bg, #1a2740) !important;
    border-color: var(--nk-s2-selection-border, #334866) !important;
}

:root[data-theme='dark'] .select2-container--default.select2-container--focus .select2-selection--single,
:root[data-theme='dark'] .select2-container--default.select2-container--open .select2-selection--single,
:root[data-theme='dark'] .select2-container--default.select2-container--focus .select2-selection--multiple,
:root[data-theme='dark'] .select2-container--default.select2-container--open .select2-selection--multiple {
    border-color: rgba(167, 139, 250, 0.5) !important;
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

/* Vendor uses `border: solid black 1px` on multi focus — override fully */
:root[data-theme='dark'] .select2-container--default.select2-container--focus .select2-selection--multiple {
    border: 1px solid rgba(167, 139, 250, 0.5) !important;
    outline: 0;
}

:root[data-theme='dark'] .select2-container--default.select2-container--disabled .select2-selection--single,
:root[data-theme='dark'] .select2-container--default.select2-container--disabled .select2-selection--multiple {
    background-color: #111a2c !important;
    opacity: 0.88;
}

:root[data-theme='dark'] .select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: rgba(51, 65, 85, 0.95) !important;
    border-color: rgba(148, 163, 184, 0.38) !important;
    color: #e2e8f0 !important;
}

:root[data-theme='dark'] .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    color: #94a3b8 !important;
}

:root[data-theme='dark'] .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: #f8fafc !important;
}

:root[data-theme='dark'] .select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: #94a3b8 transparent transparent transparent !important;
}

:root[data-theme='dark'] .select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent #94a3b8 transparent !important;
}

:root[data-theme='dark'] .select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field {
    color: #e2e8f0 !important;
}

:root[data-theme='dark'] .select2-dropdown {
    box-shadow:
        0 22px 52px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(148, 163, 184, 0.12);
}

:root[data-theme='dark'] .select2-search--dropdown .select2-search__field {
    background-color: rgba(15, 23, 42, 0.65) !important;
    border-color: #475569 !important;
    color: #f1f5f9 !important;
}

:root[data-theme='dark'] .select2-results__option[aria-selected='true'] {
    background: rgba(139, 92, 246, 0.2) !important;
}

/*
 * Single-select closed state: vendor Select2 sets .select2-selection__placeholder to mid-grey.
 * On dark selection boxes that reads as “invisible”; __rendered color does not override the child span.
 */
:root[data-theme='dark'] .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--nk-s2-text, #f1f5f9) !important;
}

:root[data-theme='dark'] .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #cbd5e1 !important;
}

:root[data-theme='dark'] .select2-container--default .select2-selection--multiple .select2-selection__rendered {
    color: var(--nk-s2-text, #f1f5f9) !important;
}

:root[data-theme='dark'] .select2-container--default .select2-selection--multiple .select2-selection__placeholder {
    color: #cbd5e1 !important;
}

/* ========== Multi-select (global): single-line search on top, removable badge chips below ==========
   Select2 appends the search <li> after choices; flex + order:-1 draws search first. */
.select2-container--default .select2-selection.select2-selection--multiple {
    min-height: auto !important;
    padding: 0.38rem 0.45rem 0.48rem !important;
    border-radius: 0.5rem !important;
    background-color: var(--nk-s2-surface, #ffffff) !important;
    border: 1px solid var(--nk-s2-border, #e2e8f0) !important;
    cursor: text;
}

.select2-container--default .select2-selection--multiple .select2-selection__rendered {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    align-content: flex-start !important;
    gap: 0.35rem 0.45rem !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    white-space: normal !important;
    text-overflow: clip !important;
    box-sizing: border-box !important;
    list-style: none !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__rendered > li {
    float: none !important;
    margin: 0 !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__rendered .select2-search--inline {
    order: -1 !important;
    flex: 1 0 100% !important;
    width: 100% !important;
    padding: 0 !important;
}

.select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field {
    width: 100% !important;
    min-width: 2.75rem !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0.48rem 0.65rem 0.48rem 2.05rem !important;
    box-sizing: border-box !important;
    border: 1px solid var(--nk-s2-border, #e2e8f0) !important;
    border-radius: 0.45rem !important;
    background-color: var(--nk-s2-search-bg, #f8fafc) !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.55rem 50%;
    background-size: 0.9rem 0.9rem;
    font-size: 0.8125rem !important;
    font-weight: 500;
    line-height: 1.35 !important;
    color: var(--nk-s2-text, #0f172a) !important;
    box-shadow: none !important;
    outline: none !important;
}

.select2-container--default.select2-container--focus .select2-selection--multiple .select2-search--inline .select2-search__field,
.select2-container--default.select2-container--open .select2-selection--multiple .select2-search--inline .select2-search__field {
    border-color: rgba(139, 92, 246, 0.45) !important;
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.12) !important;
}

html[dir='rtl'] .select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field {
    padding: 0.48rem 2.05rem 0.48rem 0.65rem !important;
    background-position: calc(100% - 0.55rem) 50%;
}

/* Duplicate placeholder row — hint text is on the search input */
.select2-container--default .select2-selection--multiple .select2-selection__rendered > .select2-selection__placeholder {
    display: none !important;
}

/* Removable chips (badges) */
.select2-container--default .select2-selection--multiple .select2-selection__choice {
    float: none !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.2rem !important;
    max-width: 100%;
    margin: 0 !important;
    padding: 0.22rem 0.4rem 0.22rem 0.45rem !important;
    background: rgba(139, 92, 246, 0.11) !important;
    border: 1px solid rgba(139, 92, 246, 0.3) !important;
    border-radius: 999px !important;
    font-size: 0.78rem !important;
    font-weight: 600 !important;
    line-height: 1.25 !important;
    color: var(--nk-s2-text, #1e293b) !important;
    cursor: default !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    float: none !important;
    margin: 0 0.1rem 0 0 !important;
    padding: 0 !important;
    width: 1.1rem !important;
    height: 1.1rem !important;
    min-width: 1.1rem !important;
    border-radius: 999px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.82rem !important;
    font-weight: 700 !important;
    line-height: 1 !important;
    color: #64748b !important;
    background: rgba(255, 255, 255, 0.92) !important;
    border: none !important;
    cursor: pointer !important;
    transition: background 0.12s ease, color 0.12s ease;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: #b91c1c !important;
    background: rgba(254, 226, 226, 0.98) !important;
}

html[dir='rtl'] .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    margin: 0 0 0 0.1rem !important;
}

/* Dark: chips + inline search field */
:root[data-theme='dark'] .select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field {
    background-color: rgba(15, 23, 42, 0.55) !important;
    border-color: var(--nk-s2-selection-border, #334866) !important;
    color: var(--nk-s2-text, #f1f5f9) !important;
}

:root[data-theme='dark'] .select2-container--default .select2-selection--multiple .select2-selection__choice {
    background: rgba(99, 102, 241, 0.14) !important;
    border-color: rgba(129, 140, 248, 0.35) !important;
    color: #e2e8f0 !important;
}

:root[data-theme='dark'] .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    color: #94a3b8 !important;
    background: rgba(30, 41, 59, 0.85) !important;
}

:root[data-theme='dark'] .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: #fecaca !important;
    background: rgba(127, 29, 29, 0.45) !important;
}
