/* ============================================================
   Выбор страны доставки в шапке сайта — оформление v3.

   Палитра (--bg, --surface, --line, --text, --accent…), класс .ic и поле
   .countries-search приходят из bestherb-v2.css плагина — он объявлен
   зависимостью этого файла.

   Блок встаёт в правую секцию шапки Astra (хук astra_render_header_column,
   приоритет 20 — после меню и переключателя темы).
   ============================================================ */

/* ---------- Кнопка в шапке ---------- */

.hdr-country{position:relative;display:flex;align-items:center;flex:none}
.bh-country--in-header{margin-left:10px}
.country-name{white-space:nowrap}

/* «button.» в селекторе — чтобы перебить button:hover / button:focus
   из стилей Astra: они красят любую кнопку в цвет ссылок с белым текстом. */
button.country-btn{display:inline-flex;align-items:center;gap:8px;height:38px;padding:0 14px;border:1px solid var(--line);border-radius:10px;background:transparent;box-shadow:none;font:inherit;font-family:var(--font);font-size:14px;font-weight:500;line-height:1.2;color:var(--text);cursor:pointer;white-space:nowrap}
button.country-btn:hover,
button.country-btn:focus,
button.country-btn[aria-expanded="true"]{background:transparent;color:var(--text);border-color:var(--line-2)}
.country-btn .ic{color:var(--muted);transition:transform .2s}
.country-btn[aria-expanded="true"] .ic{transform:rotate(180deg)}
.country-btn .flag{width:16px;height:16px;border-radius:50%;object-fit:cover;flex:none;box-shadow:inset 0 0 0 1px rgba(128,128,128,.3)}
/* Пока страна не выбрана, флага нет — на его месте глобус. На телефоне
   название скрыто, и без глобуса от кнопки оставалась одна стрелка:
   понять, что это выбор страны, было нельзя. */
.country-btn .country-globe{width:16px;height:16px;color:var(--text2);transition:none}
/* «~», а не «+»: плагин отложенной загрузки картинок вставляет после флага
   <noscript>, и с «+» глобус оставался рядом с флагом — на странице страны
   кнопка выходила на 22px шире и на экране 320px давала прокрутку вбок. */
.country-btn .flag:not([hidden]) ~ .country-globe{display:none}
.country-btn[aria-expanded="true"] .country-globe{transform:none}

/* ---------- Запасная полоса под шапкой (классический режим Astra) ---------- */

.bh-country-bar{background:var(--bg);border-bottom:1px solid var(--line);color:var(--text)}
.bh-country-bar__inner{max-width:1224px;margin:0 auto;padding:0 24px;height:48px;display:flex;align-items:center;justify-content:flex-end}

button.country-auto{display:block;width:100%;margin-top:8px;padding:8px 10px;border:1px solid var(--line);border-radius:8px;background:transparent;box-shadow:none;font:inherit;font-size:13.5px;color:var(--text2);cursor:pointer}
button.country-auto:hover,
button.country-auto:focus{background:var(--hover);color:var(--text)}
.country-auto[hidden]{display:none}

/* ---------- Выпадающее меню ---------- */

.country-menu{display:none;position:absolute;right:0;top:calc(100% + 10px);width:320px;max-height:70vh;overflow-y:auto;background:var(--surface);color:var(--text);border:1px solid var(--line);border-radius:16px;box-shadow:0 18px 48px -12px rgba(0,0,0,.35);z-index:30;font-family:var(--font)}
.country-menu.is-open{display:block}
.country-menu .countries-top{padding:12px 14px;position:sticky;top:0;z-index:1;background:var(--surface);border-bottom:1px solid var(--line)}
.country-menu .countries-search{width:100%;height:40px}
.country-menu .countries-search input[type="search"]{width:100%}
.country-menu .region{display:block;padding:10px 14px;border-top:1px solid var(--line)}
.country-menu .region:first-of-type{border-top:none}
.country-menu h4{margin:4px 6px 8px;font-size:13px;font-weight:400;letter-spacing:0;text-transform:none;color:var(--muted)}
.country-menu ul{display:block;list-style:none;margin:0;padding:0}
.country-menu li{display:block;margin:0;padding:0;border-radius:8px;background:none;font-size:14.5px;line-height:1.2;color:var(--text)}
/* Пункт — ссылка на страницу страны. Ссылка занимает всю строку: щелчок
   по пустому месту справа тоже срабатывает.
   Цвет и подчёркивание сбрасываем явно — Astra красит любые ссылки. */
.country-menu li .country-opt,
.country-menu li .country-opt:hover,
.country-menu li .country-opt:focus{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:9px 8px;border-radius:8px;color:inherit;text-decoration:none;cursor:pointer;outline-offset:-2px}
.country-menu li:hover{background:var(--hover)}
.country-menu li.me{background:var(--accent-soft);color:var(--text);font-weight:500}
.country-menu li.me .country-opt::after{content:'✓';color:var(--accent-text);font-weight:600}
/* Плагин подписывает «· ваша» страну посетителя в панели стран у карточки
   (.region li.me::after) — правило задевает и это меню. Здесь своя галочка. */
.country-menu li.me::after{content:none}
.country-menu li small{margin-left:auto;font-size:12.5px;font-weight:400;color:var(--muted)}
.country-menu li.na small{color:var(--warn)}
.country-menu li.hide,
.country-menu .region.hide{display:none}
.country-menu .countries-empty{display:none;margin:0;padding:14px;font-size:14px;color:var(--muted)}
.country-menu.no-match .countries-empty{display:block}
.country-menu-foot{padding:12px 14px;border-top:1px solid var(--line);font-size:12.5px;line-height:1.5;color:var(--muted);background:var(--surface)}

.country-menu-foot .country-all,
.country-menu-foot .country-all:hover,
.country-menu-foot .country-all:focus{display:block;width:fit-content;margin-top:6px;font-weight:500;color:var(--accent-text);text-decoration:none}
.country-menu-foot .country-all:hover{text-decoration:underline}

/* ---------- Узкие экраны ---------- */

@media (max-width:921px){
  .bh-country--in-header{margin-left:0}
  button.country-btn{height:40px;padding:0 12px;font-size:13.5px;gap:6px}
}

/* Кнопка в шапке ужимается: длинное название («Босния и Герцеговина»,
   «Сент-Винсент и Гренадины») обрезается многоточием, а не выталкивает шапку
   за край экрана. На 421–440px (iPhone Pro Max/Plus — 430) шапка была шире
   экрана на 12–70px, и страница прокручивалась вбок. Сетку шапки, которой
   есть куда ужиматься, задаёт site.css (#ast-mobile-header). */
.bh-country--in-header{flex:0 1 auto;min-width:0}
.bh-country--in-header button.country-btn{min-width:0;max-width:100%}
.bh-country--in-header .country-name{min-width:0;overflow:hidden;text-overflow:ellipsis}

/* На совсем узких оставляем флаг и шеврон: название видно в открытом меню
   и в гео-полосе под шапкой. */
@media (max-width:420px){
  .bh-country--in-header .country-name{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
}

@media (max-width:760px){
  .bh-country-bar__inner{padding:0 16px;height:44px}
  /* Меню — шторкой снизу, как панель стран у кода. */
  .country-menu.is-open{position:fixed;left:0;right:0;bottom:0;top:auto;width:auto;max-height:82vh;border-radius:20px 20px 0 0;box-shadow:0 -12px 40px rgba(0,0,0,.35);z-index:200;-webkit-overflow-scrolling:touch}
  .country-menu li{font-size:15.5px}
  .country-menu li .country-opt,
  .country-menu li .country-opt:hover,
  .country-menu li .country-opt:focus{padding:12px 8px}
}
