/* Простые и надежные стили для dropdown - без конфликтов z-index */

/* Базовые стили для контейнера */
.custom-select {
    position: relative;
    width: 100%;
    z-index: auto; /* Не создаем stacking context по умолчанию */
}

/* Активное состояние - создаем stacking context только когда открыт */
.custom-select.active {
    z-index: 1000;
    position: relative;
}

/* Активная родительская группа получает высокий z-index */
.form-group-modern.dropdown-active {
    z-index: 1001;
    position: relative;
}

/* Триггер dropdown */
.select-trigger {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 16px 20px;
    background: #ffffff;
    border: 2px solid #e5e7eb;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 500;
    color: #1f2937;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.select-trigger:hover {
    border-color: #3b82f6;
}

.select-trigger.active {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Стрелка dropdown */
.select-arrow {
    transition: transform 0.2s ease;
    color: #6b7280;
}

.select-trigger.active .select-arrow {
    transform: rotate(180deg);
}

/* Контейнер опций */
.select-options {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #ffffff;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    margin-top: 4px;
    padding: 4px;
    z-index: 1002; /* Выше родительского контейнера */
    
    /* Скрыто по умолчанию */
    display: none;
    visibility: hidden;
    opacity: 0;
    transform: translateY(-8px) scale(0.95);
    
    /* Плавная анимация */
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Улучшенная тень */
    box-shadow: 
        0 20px 25px -5px rgba(0, 0, 0, 0.1),
        0 10px 10px -5px rgba(0, 0, 0, 0.04),
        0 0 0 1px rgba(0, 0, 0, 0.05);
    
    /* Ограничение высоты и прокрутка */
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    
    /* Улучшенная прокрутка */
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
    
    /* Предотвращаем обрезание родительскими контейнерами */
    will-change: transform, opacity;
}

/* Webkit scrollbar */
.select-options::-webkit-scrollbar {
    width: 6px;
}

.select-options::-webkit-scrollbar-track {
    background: transparent;
}

.select-options::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 3px;
}

.select-options::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8;
}

/* Показываем опции когда активны */
.custom-select.active .select-options {
    display: block;
    visibility: visible;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Открытие вверх */
.custom-select.open-up .select-options {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 4px;
    transform: translateY(8px) scale(0.95);
}

.custom-select.open-up.active .select-options {
    transform: translateY(0) scale(1);
}

/* Стили опций */
.select-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    background: transparent;
    color: #1e293b;
}

.select-option:hover {
    background: rgba(59, 130, 246, 0.08);
    transform: translateX(2px);
}

.select-option.selected {
    background: rgba(59, 130, 246, 0.12);
    color: #3b82f6;
}

.select-option.selected:hover {
    background: rgba(59, 130, 246, 0.15);
}

/* Иконки опций */
.option-icon {
    font-size: 18px;
    flex-shrink: 0;
    color: #6b7280;
    transition: color 0.15s ease;
}

.select-option.selected .option-icon {
    color: #3b82f6;
}

/* Контент опции */
.option-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.option-title {
    font-weight: 600;
    color: #1f2937;
    font-size: 15px;
    transition: color 0.15s ease;
}

.option-subtitle {
    font-size: 13px;
    color: #6b7280;
    font-weight: 400;
    transition: color 0.15s ease;
}

.select-option.selected .option-title {
    color: #3b82f6;
}

.select-option.selected .option-subtitle {
    color: #3b82f6;
    opacity: 0.8;
}

/* Фиксы для родительских контейнеров */
.calculator-card {
    /* Убираем overflow: hidden который обрезает dropdown */
    overflow: visible;
}

.config-group {
    /* Обеспечиваем видимость dropdown */
    overflow: visible;
    position: relative;
}

/* Форм-группа по умолчанию */
.form-group-modern {
    position: relative;
    z-index: auto;
}

/* Только активная форм-группа получает высокий z-index */
.form-group-modern.dropdown-active {
    z-index: 1001;
    position: relative;
}

/* Адаптивность */
@media (max-width: 768px) {
    .select-options {
        /* На мобильных устройствах ограничиваем высоту */
        max-height: 250px;
    }
    
    .select-option {
        padding: 14px 16px;
    }
    
    .option-title {
        font-size: 14px;
    }
    
    .option-subtitle {
        font-size: 12px;
    }
}

/* Анимация загрузки */
@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.95);
        visibility: visible;
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        visibility: visible;
    }
}

.custom-select.active .select-options {
    animation: dropdownFadeIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Состояние фокуса для доступности */
.select-trigger:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.select-option:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: -2px;
}

/* Предотвращение layout shift и обеспечение пространства для dropdown */
.custom-select::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 0;
    z-index: -1;
    pointer-events: none;
}

/* Высокий контраст для лучшей доступности */
@media (prefers-contrast: high) {
    .select-trigger {
        border-width: 3px;
    }
    
    .select-option:hover {
        background: rgba(59, 130, 246, 0.2);
    }
    
    .select-option.selected {
        background: rgba(59, 130, 246, 0.25);
    }
}

/* Уменьшенная анимация для пользователей с ограниченными возможностями */
@media (prefers-reduced-motion: reduce) {
    .select-options,
    .select-arrow,
    .select-option {
        transition: none !important;
        animation: none !important;
    }
    
    .custom-select.active .select-options {
        animation: none !important;
        transform: translateY(0) scale(1) !important;
    }
    
    .custom-select.open-up.active .select-options {
        transform: translateY(0) scale(1) !important;
    }
}
