/* ============================================
   Custom Select Plugin
   ============================================ */

.custom-select {
    position: relative;
    display: inline-block;
    min-width: 200px;
    font-size: 0.9rem;
}

.custom-select__trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    transition: all var(--transition);
    text-align: left;
    min-height: 42px;
    font-family: inherit;
}

.custom-select__trigger:hover {
    border-color: var(--primary);
    background: var(--bg-light);
}

.custom-select__trigger:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(38, 69, 147, 0.15);
}

.custom-select__value {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.custom-select__arrow {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.3s ease;
}

.custom-select.open .custom-select__arrow {
    transform: rotate(180deg);
}

.custom-select__dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    list-style: none;
    margin: 0;
    padding: 4px;
    overflow-y: auto;
    z-index: 100;
    
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

/* Выпадающий список, перемещенный в body (чтобы не обрезаться overflow) */
.custom-select__dropdown.dropdown-appended {
  position: fixed !important;
  z-index: 9999 !important;
  margin: 0 !important;
  /* Анимация остается, но top/left будут задаваться через JS */
}

.custom-select__dropdown::-webkit-scrollbar {
    width: 4px;
}

.custom-select__dropdown::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

/* Показываем dropdown, когда открыт родитель ИЛИ когда открыт сам dropdown (для версии в <body>) */
.custom-select.open .custom-select__dropdown,
.custom-select__dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.custom-select__dropdown li[role="option"] {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
    color: var(--text-secondary);
    font-weight: 450;
    user-select: none;
}

.custom-select__dropdown li[role="option"]:hover {
    background: var(--bg-light);
    color: var(--text-primary);
}

.custom-select__dropdown li[role="option"].active {
    background: var(--primary-bg);
    color: var(--primary);
    font-weight: 500;
}

.custom-select__dropdown li[role="option"].focused {
    background: var(--bg-light);
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

.custom-select__dropdown li[role="option"].disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.custom-select__option-text {
    flex: 1;
}

.custom-select__check {
    flex-shrink: 0;
    color: var(--primary);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.custom-select__dropdown li[role="option"].active .custom-select__check {
    opacity: 1;
}

/* Чекбокс для множественного выбора */
.custom-select__checkbox {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-white);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.custom-select__checkbox svg {
    color: #fff;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.custom-select__dropdown li[role="option"].active .custom-select__checkbox {
    background: var(--primary);
    border-color: var(--primary);
}

.custom-select__dropdown li[role="option"].active .custom-select__checkbox svg {
    opacity: 1;
}

/* Поиск внутри селекта */
.custom-select__search-wrapper {
    padding: 4px !important;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
    cursor: default !important;
}

.custom-select__search-wrapper:hover {
    background: transparent !important;
}

.custom-select__search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s ease;
    font-family: inherit;
}

.custom-select__search:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(38, 69, 147, 0.15);
}

/* Стиль для пункта "Выбрать все" */
.custom-select__dropdown li[data-action="toggle-all"],
.custom-select__dropdown li[data-value="-1"] {
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  background: var(--bg-light);
  margin-bottom: 4px;
}

.custom-select__dropdown li[data-action="toggle-all"]:hover,
.custom-select__dropdown li[data-value="-1"]:hover {
  background: var(--primary-bg);
}

/* Делаем чекбокс "Выбрать все" чуть более заметным */
.custom-select__dropdown li[data-action="toggle-all"] .custom-select__checkbox,
.custom-select__dropdown li[data-value="-1"] .custom-select__checkbox {
  border-color: var(--primary);
}

.custom-select__dropdown li[data-action="toggle-all"].active .custom-select__checkbox,
.custom-select__dropdown li[data-value="-1"].active .custom-select__checkbox {
  background: var(--primary);
  border-color: var(--primary);
}

@media (max-width: 768px) {
    .custom-select {
        min-width: 160px;
    }
    .custom-select__trigger {
        padding: 8px 12px;
        font-size: 0.85rem;
        min-height: 38px;
    }
}
