/* Region switcher and desktop bottom navigation stabilization. */

.region-bottom-nav {
  overflow: visible !important;
}

.region-bottom-nav .region-nav-tabs {
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
}

.region-bottom-nav .region-nav-tab {
  position: relative !important;
}

.region-bottom-nav .region-nav-badge {
  top: 5px !important;
  right: auto !important;
  left: calc(50% + 8px) !important;
  transform: none !important;
  z-index: 8 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.region-switch-tab {
  color: rgba(232, 240, 255, 0.68) !important;
}

.region-switch-tab.is-open,
.region-switch-tab.is-active {
  color: #ffffff !important;
  background:
    radial-gradient(circle at 50% 22%, rgba(93, 231, 255, 0.2), transparent 44%),
    rgba(93, 231, 255, 0.1) !important;
}

.region-nav-flag {
  width: 30px !important;
  height: 20px !important;
  border-radius: 6px !important;
  display: inline-block !important;
  position: relative !important;
  overflow: hidden !important;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    0 6px 14px rgba(0, 0, 0, 0.18) !important;
}

.region-nav-flag::before,
.region-nav-flag::after {
  content: "";
  position: absolute;
  display: block;
}

.region-nav-flag-tr {
  background: #ec1c2f !important;
}

.region-nav-flag-tr::before {
  width: 11px;
  height: 11px;
  left: 8px;
  top: 4px;
  border-radius: 50%;
  box-shadow: -3px 0 0 1px #ffffff;
  background: transparent;
}

.region-nav-flag-tr::after {
  width: 4px;
  height: 4px;
  left: 18px;
  top: 8px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 0 1px #ffffff;
}

.region-nav-flag-cis {
  background: linear-gradient(135deg, #1e4f91, #2aa8ff) !important;
}

.region-nav-flag-cis::before {
  width: 13px;
  height: 13px;
  left: 8px;
  top: 3px;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
}

.region-nav-flag-cis::after {
  left: 9px;
  top: 9px;
  width: 12px;
  height: 1.5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow:
    0 -4px 0 rgba(255, 255, 255, 0.35),
    0 4px 0 rgba(255, 255, 255, 0.35);
}

.region-nav-flag-ua {
  background: linear-gradient(180deg, #2f8cff 0 50%, #ffd23f 50% 100%) !important;
}

.region-nav-flag-in {
  background: linear-gradient(180deg, #ff9a3a 0 33.33%, #ffffff 33.33% 66.66%, #25a55f 66.66% 100%) !important;
}

.region-nav-flag-in::before {
  width: 6px;
  height: 6px;
  left: 12px;
  top: 7px;
  border: 1.5px solid #2467d6;
  border-radius: 50%;
}

/* «Позиции» — иконка-мишень (фирменный cyan) вместо флага */
.region-nav-flag-sharing {
  background: #0f1c33 !important;
  background-image: url("/assets/services/sharing.svg") !important;
  background-size: 15px 15px !important;
  background-position: center !important;
  background-repeat: no-repeat !important;
}

.region-switch-popover {
  position: absolute !important;
  right: 0 !important;
  bottom: calc(100% + 12px) !important;
  width: min(286px, calc(100vw - 28px)) !important;
  padding: 10px !important;
  border: 1px solid rgba(93, 231, 255, 0.18) !important;
  border-radius: 24px !important;
  background:
    radial-gradient(circle at 78% 0%, rgba(93, 231, 255, 0.14), transparent 42%),
    linear-gradient(180deg, rgba(20, 25, 40, 0.98), rgba(11, 16, 29, 0.98)) !important;
  box-shadow:
    0 22px 60px rgba(0, 0, 0, 0.52),
    inset 0 1px 0 rgba(255, 255, 255, 0.06) !important;
  opacity: 0 !important;
  transform: translateY(8px) scale(0.98) !important;
  pointer-events: none !important;
  transition: opacity 0.16s ease, transform 0.16s ease !important;
  z-index: 40 !important;
}

.region-switch-popover.is-open {
  opacity: 1 !important;
  transform: translateY(0) scale(1) !important;
  pointer-events: auto !important;
}

/* Закрытый поповер невидим (opacity:0), но выложен ПОВЕРХ контента над нижним меню.
   Его кнопки-опции — <button> внутри .region-bottom-nav, поэтому получают
   pointer-events:auto из region-layout-fix.css и ловили клики даже будучи невидимыми
   (клик «между блоками», особенно в корзине, уводил в случайный регион). Пока поповер
   закрыт — полностью выключаем клики по нему и его кнопкам. */
.region-switch-popover:not(.is-open),
.region-switch-popover:not(.is-open) button {
  pointer-events: none !important;
}

.region-switch-grid {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 8px !important;
}

.region-switch-option {
  min-height: 76px !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-radius: 16px !important;
  background: rgba(255, 255, 255, 0.05) !important;
  color: rgba(237, 243, 255, 0.72) !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  font: inherit !important;
  font-weight: 900 !important;
  cursor: pointer !important;
}

.region-switch-option.is-active {
  color: #ffffff !important;
  border-color: rgba(93, 231, 255, 0.4) !important;
  background:
    radial-gradient(circle at 50% 20%, rgba(93, 231, 255, 0.18), transparent 44%),
    rgba(93, 231, 255, 0.1) !important;
}

/* «Главное меню» — вытянутый пункт (2 колонки) во втором ряду сетки, рядом с
   «Позиции». Горизонтальная раскладка (иконка + текст), лёгкая cyan-подложка. */
.region-switch-home {
  grid-column: span 2 !important;
  flex-direction: row !important;
  gap: 10px !important;
  margin-top: 0 !important;
  min-height: 76px !important;
  border: 1px solid rgba(93, 231, 255, 0.25) !important;
  background: rgba(93, 231, 255, 0.1) !important;
  color: #edf3ff !important;
  font-size: 14px !important;
}

.region-switch-home-icon {
  display: inline-flex !important;
  align-items: center !important;
  color: #5de7ff !important;
}

@media (min-width: 561px) {
  /* Keep the bar compact on desktop (was stretching to 560px, making icons look
     tiny and sparse). Mirror the mobile sizing the user is happy with. */
  .region-bottom-nav {
    width: min(calc(100% - 40px), 392px) !important;
  }

  .region-bottom-nav .region-nav-tabs {
    height: 58px !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
  }

  .region-bottom-nav .region-nav-tab {
    height: 46px !important;
    padding: 0 3px !important;
  }

  .region-bottom-nav .region-nav-label {
    font-size: 9px !important;
  }

  .region-bottom-nav .region-nav-flag {
    width: 26px !important;
    height: 17px !important;
    border-radius: 5px !important;
  }

  .region-bottom-nav .region-nav-badge {
    top: 4px !important;
    left: calc(50% + 6px) !important;
  }
}

@media (max-width: 380px) {
  .region-switch-tab .region-nav-label {
    display: inline-block !important;
    font-size: 8px !important;
  }

  .region-bottom-nav .region-nav-flag {
    width: 25px !important;
    height: 16px !important;
  }
}

/* Нижнее меню: подпись региона (ТР/СНГ/…) убрана — флаг занимает освободившееся
   место, крупнее и по центру. Высокая специфичность перебивает мобильные размеры. */
.region-bottom-nav .region-nav-tabs .region-switch-tab .region-nav-flag {
  width: 34px !important;
  height: 23px !important;
  min-width: 34px !important;
  border-radius: 6px !important;
  flex-shrink: 0 !important;
}
.region-bottom-nav .region-nav-tabs .region-switch-tab .region-nav-flag-sharing {
  width: 28px !important;
  min-width: 28px !important;
  height: 28px !important;
  border-radius: 8px !important;
  background-size: 22px 22px !important;
}
