/* 
 * intl-tel-input Custom Styles for Apollo-Next
 * Брендированные стили для выпадающего меню стран телефонного поля
 */

/* Основной контейнер */
.iti {
  width: 100%;
  position: relative;
  z-index: 1;
}

/* Когда дропдаун открыт, поднимаем весь контейнер */
.iti--show-dropdown {
  z-index: 100000 !important;
}

/* Поднимаем родительский .form-field когда дропдаун открыт */
.form-field:has(.iti--show-dropdown) {
  z-index: 100000 !important;
  position: relative;
}

/* Выбранная страна (флаг + код) */
.iti__flag-container {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  padding: 0;
}

.iti__selected-flag {
  display: flex;
  align-items: center;
  padding: 0 12px 0 16px;
  background: transparent;
  border: none;
  height: 100%;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
}

.iti__selected-flag:hover {
  background: rgba(212, 162, 75, 0.05);
}

.iti__selected-flag:focus {
  outline: none;
  background: rgba(212, 162, 75, 0.08);
}

/* Стрелка выпадающего списка */
.iti__arrow {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--gold, #d4a24b);
  margin-left: 6px;
  transition: transform 0.2s ease;
  transform: rotate(180deg); /* По умолчанию смотрит вниз */
}

.iti--show-flags .iti__arrow {
  transform: rotate(0deg); /* При открытии смотрит вверх */
}

/* Выпадающее меню (внешний контейнер может быть .iti__dropdown / .iti--container) */
.iti__dropdown,
.iti--container .iti__dropdown,
.iti__dropdown-content {
  background: #1a1a1a !important;
  border: none !important;
  border-radius: var(--radius-12, 12px) !important;
  box-shadow: none !important;
  overflow: visible !important;
}

/* Содержимое списка стран */
.iti__country-list {
  background: #1a1a1a !important;
  border: 1px solid rgba(212, 162, 75, 0.2) !important;
  border-radius: var(--radius-12, 12px);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(212, 162, 75, 0.1) inset,
    0 0 32px rgba(212, 162, 75, 0.12);
  margin-top: 4px;
  max-height: 280px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
  width: 100% !important;
  min-width: 300px;
  z-index: 99999 !important;
  color: #e0e0e0;
  position: absolute !important;
  scrollbar-width: none; /* Firefox */
}

.iti__country-list::-webkit-scrollbar {
  display: none; /* Chrome, Safari */
}

/* Когда дропдаун прикреплен к body, сбрасываем любые transform, чтобы он не "уезжал" */
body > .iti__country-list {
  position: absolute !important;
  transform: none !important;
  margin-top: 4px !important;
  z-index: 99999 !important;
}

/* Скрыть только визуальный поиск, НЕ скрывая контейнер списка */
/* В некоторых версиях плагина класс .iti__search используется как общий контейнер,
   поэтому его скрытие прятало и сам список стран. Держим видимым, скрываем лишь инпут и его обёртку. */
.iti__search-input,
.iti__search-input-container,
.iti--container .iti__search-input-container,
.iti__dropdown-content > .iti__search-input-container {
  display: none !important;
}

/* Элемент страны */
.iti__country {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  color: #e0e0e0 !important;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
  font-size: 14px;
  /* убираем внешний отступ, чтобы список не «уезжал» под контейнер */
  margin-top: 0;
  background: transparent !important;
}

.iti__country:hover {
  background: rgba(212, 162, 75, 0.1);
  color: var(--gold, #d4a24b);
}

/* На всякий случай явно гарантируем видимость текста внутри контейнера дропаунда */
.iti__dropdown-content,
.iti--container .iti__dropdown-content {
  color: #e0e0e0;
}

.iti__country.iti__highlight {
  background: rgba(212, 162, 75, 0.15);
  color: var(--gold, #d4a24b);
}

.iti__country.iti__active {
  background: rgba(212, 162, 75, 0.2);
  color: var(--gold-strong, #e5b35c);
  font-weight: 600;
}

/* Название страны */
.iti__country-name {
  margin-right: auto;
  margin-left: 8px;
  color: inherit;
}

/* Код страны */
.iti__dial-code {
  color: var(--muted, #888);
  font-size: 13px;
  transition: color 0.15s ease;
}

.iti__country:hover .iti__dial-code,
.iti__country.iti__highlight .iti__dial-code,
.iti__country.iti__active .iti__dial-code {
  color: var(--gold, #d4a24b);
}

/* Флаг */
.iti__flag {
  margin-right: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  border-radius: 2px;
}

/* Разделитель предпочитаемых стран */
.iti__divider {
  border-bottom: 1px solid rgba(212, 162, 75, 0.15);
  margin: 8px 0;
  padding: 0;
}

/* Скроллбар для выпадающего списка */
.iti__country-list::-webkit-scrollbar {
  width: 8px;
}

.iti__country-list::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  margin: 8px 0;
}

.iti__country-list::-webkit-scrollbar-thumb {
  background: rgba(212, 162, 75, 0.3);
  border-radius: 4px;
  transition: background 0.2s ease;
}

.iti__country-list::-webkit-scrollbar-thumb:hover {
  background: rgba(212, 162, 75, 0.5);
}

/* Для Firefox */
.iti__country-list {
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 162, 75, 0.3) rgba(0, 0, 0, 0.2);
}

/* Адаптивность */
@media (max-width: 640px) {
  .iti__country-list {
    width: 280px !important;
    max-height: 240px;
  }

  .iti__country {
    padding: 9px 12px;
    font-size: 13px;
  }

  .iti__dial-code {
    font-size: 12px;
  }
}

/* Инпут телефона с intl-tel-input */
.iti__tel-input {
  width: 100% !important;
  padding-left: 52px !important; /* Компактный отступ под флаг слева */
  padding-right: 0 !important;
}

/* Hover: soft gold border to match lead-form */
.iti input.iti__tel-input:hover {
  border-color: rgba(251, 191, 36, 0.45) !important;
  box-shadow: 0 2px 8px rgba(251, 191, 36, 0.10), 0 0 0 2px rgba(251, 191, 36, 0.08) !important;
}

/* Синхронизировать фокус со стилями lead-form и отключить стандартные outline */
.iti input.iti__tel-input:focus,
.iti input.iti__tel-input:focus-visible {
  outline: none !important;
  border-color: var(--gold, #d4a24b) !important;
  box-shadow: 0 4px 12px rgba(251, 191, 36, 0.15), 0 0 0 3px rgba(251, 191, 36, 0.1) !important;
  background: rgba(15, 23, 42, 0.9) !important;
}

/* Валидный номер - сохранить золотые стили после blur */
.iti input.iti__tel-input.valid-phone {
  border-color: var(--gold, #d4a24b) !important;
  box-shadow: 0 4px 12px rgba(251, 191, 36, 0.15), 0 0 0 3px rgba(251, 191, 36, 0.1) !important;
  background: rgba(15, 23, 42, 0.9) !important;
}

/* Темная тема (если используется data-theme) */
[data-theme='dark'] .iti__country-list {
  background: #0f0f0f;
  border-color: rgba(212, 162, 75, 0.25);
}

[data-theme='dark'] .iti__country {
  color: #f0f0f0;
}

[data-theme='dark'] .iti__selected-flag {
  border-left-color: #333;
}

/* Анимация появления выпадающего списка
   Важно: не оставляем список в opacity:0 по умолчанию — это делало страны «невидимыми» в некоторых сценариях отображения. */
.iti__country-list {
  opacity: 1;
  transform: none;
  animation: none;
}

@keyframes itiDropdownFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Состояние фокуса на контейнере */
.iti--container:focus-within .iti__selected-flag {
  border-left-color: var(--gold, #d4a24b);
}

/* Убрать outline при фокусе на флаге (используем свой стиль) */
.iti__selected-flag:focus-visible {
  outline: 2px solid rgba(212, 162, 75, 0.4);
  outline-offset: -2px;
  border-radius: 4px;
}

/* Поддержка reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .iti__arrow,
  .iti__country,
  .iti__selected-flag,
  .iti__country-list {
    transition: none;
    animation: none;
  }
}
