/* ══════════════════════════════════════════════════════════════════
   LOCATION FILTER — мультиселект с popover / bottom sheet
   Триггер = поле ввода (чипы + input внутри)
   ══════════════════════════════════════════════════════════════════ */

.location-filter {
  position: relative;
}

/* ─── Триггер (выглядит как input, внутри чипы + настоящий input) ─── */
.location-filter__trigger {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 42px;
  padding: 6px 40px 6px 10px;
  background: var(--color-bg, #fff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 10px;
  font-size: 14px;
  text-align: left;
  cursor: text;
  transition: border-color .15s, box-shadow .15s;
  position: relative;
}
.location-filter__trigger:hover {
  border-color: color-mix(in srgb, var(--color-accent, #e45a5a) 50%, transparent);
}
.location-filter__trigger:focus-within,
.location-filter__trigger[aria-expanded="true"] {
  border-color: var(--color-accent, #e45a5a);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent, #e45a5a) 15%, transparent);
}

/* ─── Встроенный input (поиск + плейсхолдер) ─── */
.location-filter__input {
  flex: 1 1 120px;
  min-width: 120px;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 4px 0;
  font-size: 14px;
  color: var(--color-text, #111827);
  font-family: inherit;
}
.location-filter__input::placeholder {
  color: var(--color-muted, #9ca3af);
  opacity: 1;
}

/* Legacy (если где-то остался старый span-плейсхолдер) */
.location-filter__placeholder {
  color: var(--color-muted, #9ca3af);
  pointer-events: none;
}

/* ─── Шеврон (кликабельный) ─── */
.location-filter__chevron {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--color-muted, #9ca3af);
  transition: transform .2s, color .15s;
  pointer-events: auto;
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 0;
}
.location-filter__chevron:hover {
  color: var(--color-accent, #e45a5a);
}
.location-filter__trigger[aria-expanded="true"] .location-filter__chevron {
  transform: translateY(-50%) rotate(180deg);
}

/* ─── Чипы внутри триггера ─── */
.location-filter__chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 10px;
  background: color-mix(in srgb, var(--color-accent, #e45a5a) 12%, transparent);
  color: var(--color-accent, #e45a5a);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  max-width: 180px;
  animation: lf-chip-in .18s ease-out;
}
.location-filter__chip > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
}
.location-filter__chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: pointer;
  opacity: .6;
  transition: opacity .15s, background .15s;
  flex-shrink: 0;
}
.location-filter__chip-remove:hover {
  opacity: 1;
  background: color-mix(in srgb, var(--color-accent, #e45a5a) 20%, transparent);
}

@keyframes lf-chip-in {
  from { opacity: 0; transform: scale(.85); }
  to   { opacity: 1; transform: scale(1); }
}

/* ─── Popover (десктоп) ─── */
.location-filter__popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 60;
  background: var(--color-card, #fff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 12px;
  box-shadow: 0 12px 32px -8px rgba(0,0,0,.15), 0 4px 10px -2px rgba(0,0,0,.06);
  max-height: 420px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.location-filter__popover[data-open="true"] {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ─── Список ─── */
.location-filter__list {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0 8px;
  -webkit-overflow-scrolling: touch;
}
.location-filter__group-label {
  padding: 10px 14px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-muted, #9ca3af);
}
.location-filter__option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
  transition: background .1s;
  user-select: none;
}
.location-filter__option:hover,
.location-filter__option[data-focus="true"] {
  background: color-mix(in srgb, var(--color-accent, #e45a5a) 8%, transparent);
}
.location-filter__option[data-selected="true"] {
  color: var(--color-accent, #e45a5a);
  font-weight: 500;
}
.location-filter__option--child {
  padding-left: 28px;
  font-size: 13px;
}
.location-filter__option mark {
  background: color-mix(in srgb, var(--color-accent, #e45a5a) 25%, transparent);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}
.location-filter__check {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0;
  color: var(--color-accent, #e45a5a);
}
.location-filter__option[data-selected="true"] .location-filter__check {
  opacity: 1;
}

.location-filter__empty {
  padding: 24px 14px;
  text-align: center;
  color: var(--color-muted, #9ca3af);
  font-size: 13px;
}

/* ─── Mobile bottom sheet ─── */
@media (max-width: 767px) {
  .location-filter__popover {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 85vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform .25s ease-out;
    border-bottom: none;
  }
  .location-filter__popover[data-open="true"] {
    transform: translateY(0);
  }
  .location-filter__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 59;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
  }
  .location-filter__backdrop[data-open="true"] {
    opacity: 1;
    pointer-events: auto;
  }
  .location-filter__handle {
    display: flex;
    justify-content: center;
    padding: 10px 0 6px;
    flex-shrink: 0;
  }
  .location-filter__handle::before {
    content: '';
    width: 40px;
    height: 4px;
    background: var(--color-border, #d1d5db);
    border-radius: 2px;
  }
  .location-filter__sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 16px 12px;
    flex-shrink: 0;
  }
  .location-filter__sheet-title {
    font-weight: 600;
    font-size: 15px;
  }
  .location-filter__sheet-close {
    padding: 6px;
    color: var(--color-muted, #9ca3af);
    cursor: pointer;
    background: transparent;
    border: 0;
  }
  .location-filter__apply {
    display: block;
    margin: 10px 16px 16px;
    padding: 12px;
    background: var(--color-accent, #e45a5a);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
    text-align: center;
    min-width: 160px;
  }
  .location-filter__apply:hover {
    background: color-mix(in srgb, var(--color-accent, #e45a5a) 85%, #000);
  }
  .location-filter__apply:active {
    transform: scale(0.98);
  }
}

/* На десктопе скрываем мобильные элементы */
@media (min-width: 768px) {
  .location-filter__handle,
  .location-filter__sheet-header,
  .location-filter__apply,
  .location-filter__backdrop {
    display: none;
  }
}

body.lf-scroll-lock {
  overflow: hidden;
}

body.filter-sidebar-open {
  overflow: hidden;
}

/* Гарантируем полноэкранный оверлей: CSS-правило надёжнее Tailwind-классов через JS */
@media (max-width: 1023px) {
  #filter-sidebar:not(.hidden) {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    overflow: hidden !important;
    z-index: 9999 !important;
    background: var(--bg, #FDF8F3) !important;
    display: flex !important;
    flex-direction: column !important;
  }
}

/* ─── TomSelect внутри мобильного сайдбара ─── */
@media (max-width: 1023px) {
  #filter-sidebar .ts-wrapper {
    max-width: 100%;
  }
  #filter-sidebar .ts-dropdown {
    max-width: 100%;
    left: 0;
    right: 0;
  }
}

/* ─── Когда location-filter находится внутри мобильного drawer'а ─── */
/* Drawer фильтров сам является fullscreen-overlay, поэтому popover
   не должен превращаться в bottom-sheet — иначе fixed-в-fixed ломается. */
@media (max-width: 767px) {
  #filter-sidebar .location-filter__popover {
    position: absolute;
    top: calc(100% + 6px);
    bottom: auto;
    left: 0;
    right: 0;
    max-height: 320px;
    border-radius: 12px;
    transform: translateY(-4px);
    border: 1px solid var(--color-border, #e5e7eb);
  }
  #filter-sidebar .location-filter__popover[data-open="true"] {
    transform: translateY(0);
  }
  #filter-sidebar .location-filter__backdrop,
  #filter-sidebar .location-filter__handle,
  #filter-sidebar .location-filter__sheet-header,
  #filter-sidebar .location-filter__apply {
    display: none;
  }
}

/* ══════════════════════════════════════════════════════════════════
   Metro select (Tom Select) — двухуровневое дерево «Линия → станции»
   ══════════════════════════════════════════════════════════════════ */
/* !important — Tom Select по умолчанию ставит display:block на .option, нужно перебить */
.ts-metro-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.ts-metro-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  min-width: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  /* Лёгкий контур, чтобы светлые цвета линий не «терялись» на белом фоне */
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.ts-metro-title {
  flex: 0 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ts-metro-row--chip {
  gap: 6px;
}

/* Шапка группы (название линии) внутри Tom Select dropdown */
.ts-metro-group-header {
  font-weight: 600;
  font-size: 11px;
  color: var(--color-muted, #8B7E74);
  padding: 6px 10px 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: rgba(0, 0, 0, .025);
  border-top: 1px solid var(--color-border, #E8E0D8);
}
/* Первая шапка без верхней разделительной линии */
.ts-dropdown .optgroup:first-child .ts-metro-group-header {
  border-top: 0;
}

/* ─── Скрываем плейсхолдер «Все типы» / «Все типы лагерей» при выбранных тегах (десктоп) ─── */
/* TomSelect добавляет .has-items на .ts-wrapper, когда выбран ≥1 элемент.
   Без плагина input_autogrow у input остаётся min-width:7rem (дефолтный tom-select.css) →
   он переносится на новую строку и показывает плейсхолдер (~24px лишней высоты).
   Убираем min-width и скрываем плейсхолдер; при фокусе (dropdown открыт) —
   восстанавливаем нормальный размер для поиска по опциям. */
@media (min-width: 1024px) {
  .ts-wrapper.has-items .ts-control > input {
    min-width: 0 !important;
    flex: 0 0 0 !important;
  }
  .ts-wrapper.has-items.focus .ts-control > input {
    flex: 1 1 auto !important;
    min-width: 4px !important;
  }
  .ts-wrapper.has-items .ts-control > input::placeholder {
    color: transparent !important;
  }
}

/* ─── Мягкое сжатие вертикальных отступов формы фильтров (десктоп) ─── */
/* Форма (#catalog-filter-form) использует space-y-6 (24px) между секциями
   и mb-3 (12px) на подписях. На десктопе уменьшаем до 16px и 8px
   соответственно, чтобы выиграть ~40px высоты под рекламный блок.
   Высота полей и кнопки не меняется. */
@media (min-width: 1024px) {
  /* Промежутки между секциями фильтров: space-y-6 (24px) → 16px */
  #catalog-filter-form > * + * {
    margin-top: 1rem;
  }
  /* Отступ от подписи / заголовка до поля: mb-3 (12px) → 8px */
  #catalog-filter-form label.mb-3,
  #catalog-filter-form h3.mb-3 {
    margin-bottom: 0.5rem;
  }
  /* Верхний отступ секции кнопки «Показать»: pt-4 (16px) → 12px */
  #catalog-filter-form > .border-t {
    padding-top: 0.75rem;
  }
}