/*!
 * FLUENT SELECT2 - Microsoft Fluent Design System
 * Modern, accessible, and responsive dropdown/select component
 * Version 2.0
 */

:root {
    /* Fluent Design Tokens */
    --fluent-select-bg: #ffffff;
    --fluent-select-bg-hover: #faf9f8;
    --fluent-select-bg-pressed: #f3f2f1;
    --fluent-select-bg-disabled: #f3f2f1;
    --fluent-select-border: #8a8886;
    --fluent-select-border-hover: #323130;
    --fluent-select-border-focus: #0078d4;
    --fluent-select-border-disabled: #c8c6c4;
    --fluent-select-text: #323130;
    --fluent-select-text-secondary: #605e5c;
    --fluent-select-text-disabled: #a19f9d;
    --fluent-select-placeholder: #a19f9d;
    --fluent-select-accent: #0078d4;
    --fluent-select-accent-light: #e6f2fa;
    --fluent-select-shadow-focus: 0 0 0 3px rgba(0, 120, 212, 0.1);
    --fluent-select-choice-bg: #f3f2f1;
    --fluent-select-choice-text: #323130;
    --fluent-select-dropdown-bg: #ffffff;
    --fluent-select-dropdown-border: #edebe9;
    --fluent-select-option-hover: #f3f2f1;
    --fluent-select-option-selected: #e6f2fa;
    --fluent-select-option-highlight: #0078d4;
    --fluent-select-option-highlight-text: #ffffff;
    
    /* Spacing */
    --fluent-select-spacing-xs: 4px;
    --fluent-select-spacing-sm: 8px;
    --fluent-select-spacing-md: 12px;
    --fluent-select-spacing-lg: 16px;
    --fluent-select-spacing-xl: 20px;
    
    /* Typography */
    --fluent-select-font: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --fluent-select-font-size: 14px;
    --fluent-select-font-size-sm: 12px;
    --fluent-select-line-height: 20px;
    
    /* Borders & Shadows */
    --fluent-select-radius: 4px;
    --fluent-select-radius-lg: 6px;
    --fluent-select-shadow-sm: 0 1.6px 3.6px rgba(0,0,0,0.13), 0 0.3px 0.9px rgba(0,0,0,0.1);
    --fluent-select-shadow-md: 0 3.2px 7.2px rgba(0,0,0,0.16), 0 0.6px 1.8px rgba(0,0,0,0.1);
    
    /* Transitions */
    --fluent-select-transition: 0.1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== BASE CONTAINER ===== */
.select2-container {
    box-sizing: border-box;
    display: inline-block;
    margin: 0;
    position: relative;
    vertical-align: middle;
    font-family: var(--fluent-select-font);
    font-size: var(--fluent-select-font-size);
    line-height: var(--fluent-select-line-height);
}

/* ===== SINGLE SELECT ===== */
.select2-container .select2-selection--single {
    box-sizing: border-box;
    cursor: pointer;
    display: block;
    height: 36px;
    user-select: none;
    -webkit-user-select: none;
    background-color: var(--fluent-select-bg);
    border: 1px solid var(--fluent-select-border);
    border-radius: var(--fluent-select-radius);
    transition: all var(--fluent-select-transition);
}

.select2-container .select2-selection--single:hover {
    border-color: var(--fluent-select-border-hover);
    background-color: var(--fluent-select-bg-hover);
}

.select2-container .select2-selection--single:active {
    background-color: var(--fluent-select-bg-pressed);
}

.select2-container .select2-selection--single .select2-selection__rendered {
    display: block;
    padding: 7px var(--fluent-select-spacing-xl) 7px var(--fluent-select-spacing-md);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--fluent-select-text);
    line-height: 20px;
}

.select2-container .select2-selection--single .select2-selection__clear {
    position: relative;
    color: var(--fluent-select-text-secondary);
    margin-right: var(--fluent-select-spacing-sm);
    font-size: 18px;
    font-weight: 400;
    transition: color var(--fluent-select-transition);
}

.select2-container .select2-selection--single .select2-selection__clear:hover {
    color: var(--fluent-select-text);
}

/* ===== SINGLE SELECT ARROW ===== */
.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 34px;
    position: absolute;
    top: 1px;
    right: 1px;
    width: 28px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: var(--fluent-select-text-secondary) transparent transparent transparent;
    border-style: solid;
    border-width: 5px 4px 0 4px;
    height: 0;
    left: 50%;
    margin-left: -4px;
    margin-top: -2px;
    position: absolute;
    top: 50%;
    width: 0;
    transition: transform var(--fluent-select-transition);
}

.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent var(--fluent-select-text-secondary) transparent;
    border-width: 0 4px 5px 4px;
    transform: rotate(180deg);
}

/* ===== MULTIPLE SELECT ===== */
.select2-container .select2-selection--multiple {
    box-sizing: border-box;
    cursor: text;
    display: block;
    min-height: 36px;
    user-select: none;
    -webkit-user-select: none;
    background-color: var(--fluent-select-bg);
    border: 1px solid var(--fluent-select-border);
    border-radius: var(--fluent-select-radius);
    padding: 2px;
    transition: all var(--fluent-select-transition);
}

.select2-container .select2-selection--multiple:hover {
    border-color: var(--fluent-select-border-hover);
    background-color: var(--fluent-select-bg-hover);
}

.select2-container .select2-selection--multiple:focus-within {
    border-color: var(--fluent-select-border-focus);
    box-shadow: var(--fluent-select-shadow-focus);
}

.select2-container .select2-selection--multiple .select2-selection__rendered {
    display: inline;
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
}

.select2-container .select2-selection--multiple .select2-selection__rendered li {
    list-style: none;
    display: inline-block;
    margin: 2px;
}

/* ===== SELECTED CHOICES ===== */
.select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: var(--fluent-select-choice-bg);
    border: 1px solid transparent;
    border-radius: calc(var(--fluent-select-radius) - 1px);
    cursor: default;
    float: left;
    margin: 2px;
    padding: 2px var(--fluent-select-spacing-sm);
    color: var(--fluent-select-choice-text);
    font-size: var(--fluent-select-font-size);
    line-height: 22px;
    display: flex;
    align-items: center;
    transition: background-color var(--fluent-select-transition);
}

.select2-container--default .select2-selection--multiple .select2-selection__choice:hover {
    background-color: var(--fluent-select-bg-pressed);
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    color: var(--fluent-select-text-secondary);
    cursor: pointer;
    display: inline-block;
    font-weight: 500;
    margin-right: var(--fluent-select-spacing-xs);
    font-size: 16px;
    line-height: 1;
    transition: all var(--fluent-select-transition);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    text-align: center;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: var(--fluent-select-text);
    background-color: rgba(0,0,0,0.08);
}

/* ===== SEARCH FIELD ===== */
.select2-container .select2-search--inline {
    float: left;
    margin: 2px;
}

.select2-container .select2-search--inline .select2-search__field {
    box-sizing: border-box;
    border: none;
    font-size: var(--fluent-select-font-size);
    margin: 4px 0 4px var(--fluent-select-spacing-xs);
    padding: 0;
    background: transparent;
    color: var(--fluent-select-text);
    min-width: 120px;
}

.select2-container .select2-search--inline .select2-search__field:focus {
    outline: none;
}

.select2-container .select2-search--inline .select2-search__field::placeholder {
    color: var(--fluent-select-placeholder);
}

/* ===== DROPDOWN ===== */
.select2-dropdown {
    background-color: var(--fluent-select-dropdown-bg);
    border: 1px solid var(--fluent-select-dropdown-border);
    border-radius: var(--fluent-select-radius-lg);
    box-sizing: border-box;
    display: block;
    position: absolute;
    left: -100000px;
    width: 100%;
    z-index: 1051;
    box-shadow: var(--fluent-select-shadow-md);
    margin-top: 4px;
    overflow: hidden;
}

.select2-container--open .select2-dropdown {
    left: 0;
    animation: fluentSelectFadeIn 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.select2-container--open .select2-dropdown--above {
    border-bottom: none;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-top: 0;
    margin-bottom: 4px;
}

.select2-container--open .select2-dropdown--below {
    border-top: none;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

@keyframes fluentSelectFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== SEARCH IN DROPDOWN ===== */
.select2-search--dropdown {
    display: block;
    padding: var(--fluent-select-spacing-sm);
    border-bottom: 1px solid var(--fluent-select-dropdown-border);
}

.select2-search--dropdown .select2-search__field {
    padding: var(--fluent-select-spacing-sm) var(--fluent-select-spacing-md);
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--fluent-select-border);
    border-radius: var(--fluent-select-radius);
    font-family: var(--fluent-select-font);
    font-size: var(--fluent-select-font-size);
    line-height: var(--fluent-select-line-height);
    color: var(--fluent-select-text);
    transition: all var(--fluent-select-transition);
}

.select2-search--dropdown .select2-search__field:focus {
    border-color: var(--fluent-select-border-focus);
    outline: none;
    box-shadow: var(--fluent-select-shadow-focus);
}

.select2-search--dropdown.select2-search--hide {
    display: none;
}

/* ===== RESULTS ===== */
.select2-results {
    display: block;
}

.select2-results__options {
    list-style: none;
    margin: 0;
    padding: var(--fluent-select-spacing-xs) 0;
    max-height: 280px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #c8c6c4 #f3f2f1;
}

.select2-results__options::-webkit-scrollbar {
    width: 6px;
}

.select2-results__options::-webkit-scrollbar-track {
    background: #f3f2f1;
}

.select2-results__options::-webkit-scrollbar-thumb {
    background: #c8c6c4;
    border-radius: 3px;
}

.select2-results__options::-webkit-scrollbar-thumb:hover {
    background: #a19f9d;
}

.select2-results__option {
    padding: var(--fluent-select-spacing-sm) var(--fluent-select-spacing-md);
    user-select: none;
    -webkit-user-select: none;
    color: var(--fluent-select-text);
    font-size: var(--fluent-select-font-size);
    line-height: var(--fluent-select-line-height);
    cursor: pointer;
    transition: background-color var(--fluent-select-transition);
}

.select2-results__option[aria-selected="true"] {
    background-color: var(--fluent-select-option-selected);
    color: var(--fluent-select-text);
    position: relative;
}

.select2-results__option[aria-selected="true"]::before {
    content: "✓";
    position: absolute;
    right: var(--fluent-select-spacing-md);
    color: var(--fluent-select-accent);
    font-weight: 600;
}

.select2-results__option--highlighted[aria-selected] {
    background-color: var(--fluent-select-option-hover);
    color: var(--fluent-select-text);
}

.select2-results__option[aria-disabled="true"] {
    color: var(--fluent-select-text-disabled);
    cursor: not-allowed;
}

/* ===== GROUP OPTIONS ===== */
.select2-results__option[role="group"] {
    padding: 0;
}

.select2-results__group {
    cursor: default;
    display: block;
    padding: var(--fluent-select-spacing-sm) var(--fluent-select-spacing-md);
    font-weight: 600;
    color: var(--fluent-select-text-secondary);
    background-color: var(--fluent-select-bg-hover);
    font-size: var(--fluent-select-font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== NESTED OPTIONS ===== */
.select2-container--default .select2-results__option .select2-results__option {
    padding-left: calc(var(--fluent-select-spacing-md) * 2);
}

.select2-container--default .select2-results__option .select2-results__option .select2-results__option {
    padding-left: calc(var(--fluent-select-spacing-md) * 3);
}

.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option {
    padding-left: calc(var(--fluent-select-spacing-md) * 4);
}

/* ===== STATES ===== */
.select2-container--default.select2-container--disabled .select2-selection--single,
.select2-container--default.select2-container--disabled .select2-selection--multiple {
    background-color: var(--fluent-select-bg-disabled);
    border-color: var(--fluent-select-border-disabled);
    cursor: not-allowed;
    opacity: 0.8;
}

.select2-container--default.select2-container--disabled .select2-selection--single .select2-selection__clear,
.select2-container--default.select2-container--disabled .select2-selection--multiple .select2-selection__clear,
.select2-container--default.select2-container--disabled .select2-selection__choice__remove {
    display: none;
}

.select2-container--default.select2-container--disabled .select2-selection--single .select2-selection__rendered {
    color: var(--fluent-select-text-disabled);
}

.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: var(--fluent-select-border-focus);
    outline: none;
    box-shadow: var(--fluent-select-shadow-focus);
}

/* ===== PLACEHOLDER ===== */
.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--fluent-select-placeholder);
}

/* ===== RTL SUPPORT ===== */
.select2-container[dir="rtl"] .select2-selection--single .select2-selection__rendered {
    padding-right: var(--fluent-select-spacing-md);
    padding-left: var(--fluent-select-spacing-xl);
}

.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__arrow {
    left: 1px;
    right: auto;
}

.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
    float: right;
    margin-left: 5px;
    margin-right: auto;
}

.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove {
    margin-left: 2px;
    margin-right: auto;
}

/* ===== ACCESSIBILITY ===== */
.select2-close-mask {
    border: 0;
    margin: 0;
    padding: 0;
    display: block;
    position: fixed;
    left: 0;
    top: 0;
    min-height: 100%;
    min-width: 100%;
    height: auto;
    width: auto;
    opacity: 0;
    z-index: 99;
    background-color: #fff;
}

.select2-hidden-accessible {
    border: 0 !important;
    clip: rect(0 0 0 0) !important;
    -webkit-clip-path: inset(50%) !important;
    clip-path: inset(50%) !important;
    height: 1px !important;
    overflow: hidden !important;
    padding: 0 !important;
    position: absolute !important;
    width: 1px !important;
    white-space: nowrap !important;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .select2-container {
        width: 100% !important;
    }
    
    .select2-container .select2-selection--single,
    .select2-container .select2-selection--multiple {
        height: 40px;
        font-size: 16px; /* Better touch target */
    }
    
    .select2-container .select2-selection--single .select2-selection__rendered {
        padding-top: 9px;
        padding-bottom: 9px;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 38px;
    }
    
    .select2-dropdown {
        max-height: 300px;
    }
    
    .select2-results__option {
        padding: var(--fluent-select-spacing-md);
    }
}

/* ===== DARK MODE ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --fluent-select-bg: #2b2b2b;
        --fluent-select-bg-hover: #3b3b3b;
        --fluent-select-bg-pressed: #404040;
        --fluent-select-bg-disabled: #333333;
        --fluent-select-border: #666666;
        --fluent-select-border-hover: #888888;
        --fluent-select-border-focus: #4a9eff;
        --fluent-select-border-disabled: #4d4d4d;
        --fluent-select-text: #ffffff;
        --fluent-select-text-secondary: #c8c6c4;
        --fluent-select-text-disabled: #8a8886;
        --fluent-select-placeholder: #8a8886;
        --fluent-select-choice-bg: #404040;
        --fluent-select-choice-text: #ffffff;
        --fluent-select-dropdown-bg: #2b2b2b;
        --fluent-select-dropdown-border: #404040;
        --fluent-select-option-hover: #404040;
        --fluent-select-option-selected: #1e3b4a;
        --fluent-select-option-highlight: #4a9eff;
    }
}

/* ===== HIGH CONTRAST ===== */
@media (forced-colors: active) {
    .select2-container .select2-selection--single,
    .select2-container .select2-selection--multiple,
    .select2-dropdown {
        border: 1px solid WindowText;
    }
    
    .select2-container--default .select2-results__option--highlighted[aria-selected] {
        forced-color-adjust: none;
        background: Highlight;
        color: HighlightText;
    }
}

/* ===== LOADING STATE ===== */
.select2-container--default .select2-results__options.select2-results__options--loading {
    min-height: 80px;
    background-image: linear-gradient(90deg, transparent 40%, rgba(0,120,212,0.1) 50%, transparent 60%);
    background-size: 200% 100%;
    animation: fluentSelectLoading 1.5s infinite;
}

@keyframes fluentSelectLoading {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}