/* Simple Phone Input Styles with PNG Flags */
.simple-phone-wrapper,
.phone-input-group {
    display: flex !important;
    flex-direction: row !important;
    width: 100%;
    position: relative;
}

/* Custom Country Dropdown */
.country-dropdown {
    position: relative;
    flex: 0 0 auto;
    min-width: auto;
}

.selected-country {
    display: flex;
    align-items: center;
    padding: var(--space-4, 15px) 12px;
    background: var(--bg-white, white);
    border: 2px solid var(--border-light, #e2e8f0);
    border-right: none;
    border-radius: var(--radius-lg, 0.75rem) 0 0 var(--radius-lg, 0.75rem);
    cursor: pointer;
    transition: var(--transition, all 0.3s ease);
    box-sizing: border-box;
    height: 56px;
    color: var(--text-primary, #2d3748);
    position: relative;
    white-space: nowrap;
}

.selected-country:hover {
    border-color: #cbd5e0;
    background: #f7fafc;
}

.flag-img {
    width: 20px;
    height: 15px;
    object-fit: cover;
    border-radius: 2px;
    margin-right: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid rgba(0,0,0,0.1);
}

.dial-code {
    font-size: 1rem;
    font-weight: 500;
    color: #2d3748;
    margin-left: 6px;
}

.dropdown-arrow {
    margin-left: 8px;
    font-size: 0.9rem;
    color: #718096;
    transition: transform 0.3s ease;
}

.selected-country:hover .dropdown-arrow {
    color: #4a5568;
}

.country-list {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 300px;
    background: var(--bg-white, white);
    border: 2px solid var(--border-light, #e2e8f0);
    border-top: none;
    border-radius: 0 0 var(--radius-lg, 0.75rem) var(--radius-lg, 0.75rem);
    max-height: 400px;
    overflow-y: auto;
    z-index: 10000;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    margin-top: -1px;
}

/* Уменьшенная высота dropdown для формы входа */
#login-form .country-list {
    max-height: 180px;
}

/* Custom scrollbar */
.country-list::-webkit-scrollbar {
    width: 6px;
}

.country-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 0 0 12px 0;
}

.country-list::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.country-list::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

.country-option {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid #f7fafc;
    transition: background-color 0.2s ease;
}

.country-option:hover {
    background: #f7fafc;
}

.country-option:last-child {
    border-bottom: none;
}

.country-option .country-name {
    flex: 1;
    margin-left: 10px;
    font-size: 0.9rem;
    color: #2d3748;
    font-weight: 400;
}

.country-option .dial-code {
    font-size: 0.85rem;
    color: #718096;
    font-weight: 500;
}

/* Dropdown adjustments for viewport constraints */
.country-dropdown {
    position: relative;
}

/* Ensure dropdown doesn't go off-screen */
@media (max-height: 600px) {
    .country-list {
        max-height: 250px;
    }
}

@media (max-height: 400px) {
    .country-list {
        max-height: 180px;
    }
}

/* Old select styles for fallback compatibility */
.country-select {
    flex: 0 0 auto;
    padding: 12px;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    color: #495057;
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-right: none;
    border-radius: 8px 0 0 8px;
    transition: all 0.3s ease;
    cursor: pointer;
    min-width: 120px;
    box-sizing: border-box;
}

.country-select:focus {
    outline: none;
    border-color: #007bff;
    background: #fff;
}

.phone-number-input {
    flex: 1 1 auto;
    padding: var(--space-4, 15px) 16px var(--space-4, 15px) 8px;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary, #2d3748);
    background: var(--bg-white, white);
    border: 2px solid var(--border-light, #e2e8f0);
    border-left: none;
    border-radius: 0 var(--radius-lg, 0.75rem) var(--radius-lg, 0.75rem) 0;
    transition: var(--transition, all 0.3s ease);
    box-sizing: border-box;
    height: 56px;
    font-weight: 400;
    text-align: left;
}

.phone-number-input:focus {
    outline: none;
    border-color: var(--brand-primary, #2563EB);
    box-shadow: var(--shadow-focus, 0 0 0 3px rgba(37, 99, 235, 0.1));
}

/* Синхронизация focus состояний - когда поле в фокусе, dropdown тоже подсвечивается */
.simple-phone-wrapper:focus-within .selected-country {
    border-color: var(--brand-primary, #2563EB);
}

/* Убираем дублирование shadow между полями при focus */
.simple-phone-wrapper:focus-within .phone-number-input {
    box-shadow: var(--shadow-focus, 0 0 0 3px rgba(37, 99, 235, 0.1));
}

/* Success состояние для валидации */
.phone-number-input.success,
.simple-phone-wrapper.success .selected-country {
    border-color: var(--brand-success, #10B981);
}

.phone-number-input.success {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* Error состояние для валидации */
.phone-number-input.error,
.simple-phone-wrapper.error .selected-country {
    border-color: var(--brand-danger, #EF4444);
}

.phone-number-input.error {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.phone-number-input::placeholder {
    color: #a0aec0;
    font-weight: 400;
}

.phone-number-input:focus + .country-select,
.country-select:focus + .phone-number-input,
.simple-phone-wrapper:focus-within .country-select {
    border-color: var(--brand-primary);
}

/* Error states */
.phone-number-input.error {
    border-color: var(--brand-danger);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.phone-number-input.error + .country-select,
.simple-phone-wrapper:has(.phone-number-input.error) .country-select {
    border-color: var(--brand-danger);
}

/* Success states */
.phone-number-input.success {
    border-color: var(--brand-success);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.phone-number-input.success + .country-select,
.simple-phone-wrapper:has(.phone-number-input.success) .country-select {
    border-color: var(--brand-success);
}

/* Mobile responsive */
@media (max-width: 768px) {
    .country-select {
        min-width: 100px;
        padding: var(--space-3) var(--space-2);
        font-size: 0.875rem;
    }
    
    .phone-number-input {
        padding: var(--space-3) var(--space-3) var(--space-3) 6px;
        font-size: 0.875rem;
        text-align: left !important;
    }
}

@media (max-width: 480px) {
    /* ИСПРАВЛЕНО: НЕ разделяем на 2 поля, оставляем в одну строку */
    .simple-phone-wrapper,
    .phone-input-group {
        flex-direction: row !important; /* Принудительно в одну строку */
        display: flex !important;
    }
    
    /* Компактный селектор стран для мобильных */
    .country-dropdown,
    .phone-input-group .country-dropdown {
        flex: 0 0 80px !important; /* Фиксированная ширина 80px */
        min-width: 80px !important;
    }
    
    .selected-country,
    .phone-input-group .selected-country {
        padding: 12px 6px !important; /* Уменьшенные отступы */
        height: 50px !important; /* Меньшая высота */
        min-width: 80px !important;
    }
    
    .flag-img {
        width: 16px; /* Меньший флаг */
        height: 12px;
        margin-right: 4px;
    }
    
    .dial-code {
        font-size: 0.85rem; /* Меньший шрифт */
        margin-left: 2px;
    }
    
    .dropdown-arrow {
        display: none; /* Убираем стрелку на мобильных */
    }
    
    /* Поле ввода занимает остальное место */
    .phone-number-input,
    .phone-input-group input[type="tel"],
    .phone-input-group .phone-input {
        flex: 1 !important;
        height: 50px !important; /* Соответствует высоте селектора */
        padding: 12px 8px !important;
        text-align: left !important;
        border-left: none !important; /* Убираем левую границу */
    }
    
    /* Dropdown список уже */
    .country-list {
        min-width: 280px; /* Уменьшенная ширина списка */
        max-height: 250px; /* Меньшая высота */
    }
}

/* Переопределение Bootstrap стилей для мобильных */
@media (max-width: 767px) {
    .phone-input.form-control,
    .phone-number-input.form-control,
    input[type="tel"].form-control,
    .phone-input-group input[type="tel"] {
        text-align: left !important;
        padding-left: 8px !important;
    }
    
    /* Обеспечиваем что phone-input-group тоже остается в одну строку */
    .phone-input-group {
        display: flex !important;
        flex-direction: row !important;
        width: 100%;
        align-items: stretch !important; /* Выравниваем по высоте */
    }
    
    /* Принудительно переопределяем любые инлайн-стили */
    .phone-input-group[style*="flex-direction"] {
        flex-direction: row !important;
    }
}

/* Дополнительные правила для очень маленьких экранов */
@media (max-width: 400px) {
    .phone-input.form-control,
    .phone-number-input.form-control,
    input[type="tel"].form-control,
    .phone-input-group input[type="tel"] {
        padding-left: 4px !important;
        text-align: left !important;
    }
    
    /* Еще более компактный селектор на очень маленьких экранах */
    .country-dropdown,
    .phone-input-group .country-dropdown {
        flex: 0 0 70px !important;
        min-width: 70px !important;
    }
    
    .selected-country,
    .phone-input-group .selected-country {
        padding: 10px 4px !important;
        min-width: 70px !important;
    }
    
    .dial-code {
        font-size: 0.8rem !important;
    }
    
    /* КРИТИЧЕСКИ ВАЖНО: принудительно убираем любой flex-direction: column */
    .phone-input-group,
    .simple-phone-wrapper {
        flex-direction: row !important;
        display: flex !important;
    }
}

/* КРИТИЧЕСКОЕ ИСПРАВЛЕНИЕ МОБИЛЬНОЙ АДАПТАЦИИ */
/* Максимальный приоритет - переопределяет все остальные стили */
@media screen and (max-width: 768px) {
    .phone-input-group,
    .phone-input-group[style],
    .simple-phone-wrapper,
    .simple-phone-wrapper[style] {
        display: flex !important;
        flex-direction: row !important;
        align-items: stretch !important;
        width: 100% !important;
    }
    
    /* Селектор стран компактный */
    .phone-input-group .country-dropdown,
    .phone-input-group .selected-country {
        flex: 0 0 80px !important;
        width: 80px !important;
        height: 50px !important;
    }
    
    /* Поле ввода занимает остальное место */
    .phone-input-group input[type="tel"] {
        flex: 1 !important;
        height: 50px !important;
        border-left: none !important;
    }
} 