/* ================================
   Общий блок "Поиск + фильтры"
   Для страницы /questions
   ================================ */

/* Небольшой отступ блока от hero */
.questions-filters-block {
  margin-top: 18px;
}

/* Внешняя оболочка */
.tpl-search-shell {
  width: 100%;
}

/* Первая строка: поиск + кнопка "Фильтры" */
.tpl-search-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

/* Обёртка поля поиска */
.tpl-search-input-wrapper {
  position: relative;
  flex: 1 1 220px;
  min-width: 0;
}

/* Иконка поиска (Font Awesome) */
.tpl-search-input-wrapper .fa-search {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted, #9ca3af);
  font-size: 13px;
  pointer-events: none;
}

/* Поле поиска — размеры как в демо-макете */
.tpl-search-input {
  width: 100%;
  border-radius: var(--radius-pill, 999px);
  padding: 8px 32px 8px 30px;
  font-size: 14px; /* аккуратное тело */
  line-height: 1.4;
  color: var(--text-main, #0f172a);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow-glass, 0 8px 24px rgba(31, 38, 135, 0.15));
  outline: none;
  transition: border-color 0.16s ease-out, box-shadow 0.16s ease-out,
    background 0.16s ease-out, transform 0.16s ease-out;
}

.tpl-search-input::placeholder {
  color: var(--text-muted, #9ca3af);
}

/* Фокус, как в макете */
.tpl-search-input:focus-visible {
  border-color: var(--accent, #4c6fff);
  box-shadow: 0 0 0 1px rgba(76, 111, 255, 0.18),
    var(--shadow-ink-sm, 0 6px 18px rgba(0, 0, 0, 0.08));
  background: #ffffff;
  transform: translateY(-1px);
}

/* Кнопка "Фильтры" справа от поиска */
.tpl-filter-toggle {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-pill, 999px);
  border: 1px solid rgba(209, 213, 219, 0.9);
  background: rgba(9, 43, 78, 0.96);
  color: var(--text-main, #0f172a);
  font-size: 14px;
  cursor: pointer;
  box-shadow: var(--shadow-ink-sm, 0 6px 18px rgba(0, 0, 0, 0.08));
  white-space: nowrap;
  transition: transform 0.16s ease-out, box-shadow 0.16s ease-out,
    background 0.16s ease-out, color 0.16s ease-out, border-color 0.16s ease-out;
}

/* иконка внутри кнопки */
.tpl-filter-toggle .fa-sliders-h {
  font-size: 13px;
}

/* бейдж количества фильтров (id=questionsFiltersCount) */
.filters-cta-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent, #4c6fff);
  background: var(--accent-soft, rgba(76, 111, 255, 0.12));
}

/* когда есть активные фильтры — добавляется класс из JS */
.tpl-filter-toggle.has-active-filters,
.tpl-filter-toggle[data-filters-active="true"] {
  border-color: rgba(76, 111, 255, 0.4);
  background: rgba(239, 246, 255, 0.95);
  color: var(--accent-strong, #3340ff);
}

@media (hover: hover) {
  .tpl-filter-toggle:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glass, 0 8px 24px rgba(31, 38, 135, 0.15));
    background: #ffffff;
  }
}

.tpl-filter-toggle:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-ink-sm, 0 6px 18px rgba(0, 0, 0, 0.08));
}

/* Мобильный режим — поиск + фильтры в одну строку, компактно */
@media (max-width: 640px) {
  .tpl-search-row {
    align-items: stretch;
    flex-wrap: nowrap; /* запрещаем перенос, чтобы было в одну строку */
  }

  .tpl-search-input-wrapper {
    flex: 1 1 auto; /* поиск занимает всё доступное */
    min-width: 0;
  }

  .tpl-filter-toggle {
    width: auto; /* больше НЕ на всю ширину */
    flex: 0 0 auto;
    justify-content: center;
    padding-inline: 8px; /* чуть компактнее по горизонтали */
  }

  /* Скрываем текст "Фильтры", но оставляем иконку и бейдж */
  .tpl-filter-toggle > span:not(.filters-cta-count) {
    display: none;
  }
}

/* =================================
   Модальный интерфейс фильтров (overlay)
   Desktop: dialog по центру
   Mobile: bottom-sheet снизу (перекрывает нижнее меню + свайпом закрывается)
================================= */

.filters-modal[hidden] {
  display: none;
}

.filters-modal {
  position: fixed;
  inset: 0;
  z-index: 9999; /* выше фиксированных хедеров/меню */
  display: flex;
  align-items: center;
  justify-content: center;
}

.filters-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.filters-modal__sheet {
  position: relative;
  width: min(720px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  padding: 16px;
  -webkit-overflow-scrolling: touch;

  /* анимация bottom-sheet управляется классом .is-open на .filters-modal */
  transform: translateY(0);
}

.filters-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.filters-modal__title {
  font-weight: 700;
  font-size: 16px;
  line-height: 20px;
}

.filters-modal__closeBtn {
  background: transparent;
  border: 0;
  padding: 6px 8px;
  font: inherit;
  color: #2a66ff;
  cursor: pointer;
}

/* Mobile bottom-sheet */
@media (max-width: 640px) {
  .filters-modal {
    align-items: flex-end;
    justify-content: center;
  }

  .filters-modal__sheet {
    width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom));

    /*
      1) sheet всегда лежит поверх нижнего меню (оно перекрывается)
      2) используем 100dvh для мобильных браузеров
      3) добавляем плавное появление снизу
    */
    margin-bottom: 0;
    max-height: 100dvh;

    transform: translateY(100%);
    transition: transform 0.22s ease-out;
    will-change: transform;
    overscroll-behavior: contain;
  }

  /* открытое состояние (добавляет JS) */
  .filters-modal.is-open .filters-modal__sheet {
    transform: translateY(0);
  }
}

/* ================================
   Устранение проблем с отображением на мобильных устройствах
   ================================ */

@media (max-width: 640px) {
  /* Для мобильных устройств: поиск + фильтры в одну строку */
  .tpl-search-row {
    flex-wrap: nowrap; /* Запрещаем перенос на следующую строку */
    align-items: stretch;
  }

  .tpl-search-input-wrapper {
    flex: 1 1 auto; /* Поиск занимает всё доступное пространство */
  }

  .tpl-filter-toggle {
    width: auto; /* Не на всю ширину */
    flex: 0 0 auto;
    justify-content: center;
    padding-inline: 8px;
  }

  /* Убираем текст "Фильтры", оставляем только иконку */
  .tpl-filter-toggle > span:not(.filters-cta-count) {
    display: none;
  }
}

/* ================================
   Строка активных фильтров (summary)
   ================================ */

.filters-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  margin-bottom: 4px;
  min-height: 22px;
}

.filters-summary-empty {
  font-size: 12px;
  color: var(--text-muted, #9ca3af);
  opacity: 0.9;
}

.filters-chip {
  border-radius: var(--radius-pill, 999px);
  padding: 4px 10px;
  font-size: 12px;
  background: rgba(239, 246, 255, 0.95);
  color: var(--accent-strong, #3340ff);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.filters-chip button,
.filters-chip-close {
  border: none;
  background: transparent;
  padding: 0 0 0 4px;
  margin: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1em; /* ровно как текст чипа */
  line-height: 1;
  color: var(--accent-strong, #3340ff);
}

/* ================================
   Раскрывающаяся панель фильтров
   (tpl-filters-panel / filters-panel)
   ================================ */

.tpl-filters-panel {
  margin-top: 10px;
  padding: 12px 12px 14px;
  border-radius: var(--radius-md, 16px);
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.98));
  background: var(--glass-bg, rgba(255, 255, 255, 0.9));
  box-shadow: var(--shadow-glass, 0 8px 24px rgba(31, 38, 135, 0.15));
  display: none;
  animation: filtersSlideUp 0.2s ease-out;
}

/* класс .filters-panel у тебя уже есть — оставляем совместимость */
.tpl-filters-panel.filters-panel--open,
.tpl-filters-panel.is-open {
  display: block;
}

@keyframes filtersSlideUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Шапка панели */
.filters-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.filters-panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main, #0f172a);
}

.filters-panel-reset {
  border: none;
  background: transparent;
  color: var(--accent, #4c6fff);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
}

/* Секции внутри панели */
.filters-section {
  margin-top: 10px;
}

.filters-section-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted, #9ca3af);
  text-transform: none;
  letter-spacing: 0.12em;
  margin-bottom: 6px;
}

.chips-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ================================
   Единый стиль чипов внутри панели
   (Статус вопросов, Показать сначала)
   ================================ */

.filter-chip,
.tpl-tab,
.tpl-filter-chip {
  border-radius: var(--radius-pill, 9px);
  padding: 8px 15px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid rgba(209, 213, 219, 0.9);
  background: rgba(248, 250, 252, 0.96);
  color: var(--text-soft, #4b5563);
  cursor: pointer;
  transition: background 0.16s ease-out, color 0.16s ease-out,
    border-color 0.16s ease-out, transform 0.16s ease-out;
}

.filter-chip.tpl-tab--active,
.filter-chip.is-active,
.tpl-tab--active,
.tpl-filter-chip--active {
  background: rgba(219, 234, 254, 0.95);
  color: var(--accent-strong, #3340ff);
  border-color: rgba(76, 111, 255, 0.6);
  transform: translateY(-1px);
}

@media (hover: hover) {
  .filter-chip:hover:not(.tpl-tab--active):not(.is-active),
  .tpl-tab:hover:not(.tpl-tab--active),
  .tpl-filter-chip:hover:not(.tpl-filter-chip--active) {
    background: rgba(248, 250, 252, 1);
  }
}

/* Футер панели */
.filters-panel-footer,
.tpl-filters-footer {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Кнопка "Показать результаты" */
.tpl-filters-footer .btn-primary {
  border-radius: var(--radius-pill, 999px);
  border: none;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  background: linear-gradient(
    130deg,
    var(--accent, #4c6fff),
    var(--accent-alt, #2bc5d9)
  );
  cursor: pointer;
  box-shadow: var(--shadow-glass, 0 8px 24px rgba(31, 38, 135, 0.15));
  transition: transform 0.16s ease-out, box-shadow 0.16s ease-out,
    opacity 0.16s ease-out;
}

@media (hover: hover) {
  .tpl-filters-footer .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 26px rgba(31, 38, 135, 0.25);
  }
}

.tpl-filters-footer .btn-primary:active {
  transform: scale(0.97);
  box-shadow: var(--shadow-ink-sm, 0 6px 18px rgba(0, 0, 0, 0.08));
}

/* Кнопка "Сбросить" */
.tpl-filters-footer .btn-secondary-link {
  border: none;
  background: transparent;
  font-size: 12px;
  color: var(--text-muted, #9ca3af);
  cursor: pointer;
  padding: 4px 6px;
}
/* Заголовок над поиском в блоке вопросов */
.questions-filters-block .filters-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 15px;
}

.questions-filters-block .filters-title-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.questions-filters-block .filters-title {
  font-size: 15px; /* компактный заголовок */
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-main, #0f172a);
}

.questions-filters-block .filters-subtitle {
  font-size: 12px; /* мелкий поясняющий текст */
  color: var(--text-soft, #4b5563);
  opacity: 0.9;
}
/* Отступы блока поиска от верхнего баннера и от списка вопросов */
.questions-filters-block {
  /* раньше было margin-top: 18px; */
  margin-top: 32px; /* расстояние от hero-баннера до блока поиска */
  margin-bottom: 24px; /* расстояние от блока поиска до первой карточки вопроса */
}
/* Мобильный режим — поиск + фильтры в одну строку, компактно и без перекрытия бейджа */
@media (max-width: 640px) {
  .tpl-search-row {
    align-items: stretch;
    flex-wrap: nowrap; /* всё в одну строку */
  }

  .tpl-search-input-wrapper {
    flex: 1 1 auto; /* поиск занимает всё доступное */
    min-width: 0;
  }

  .tpl-filter-toggle {
    width: auto; /* больше не на всю ширину */
    flex: 0 0 auto;
    display: inline-flex;
    justify-content: center;
    padding-inline: 10px; /* компактнее по горизонтали */
    gap: 4px; /* небольшой зазор между иконкой и бейджем */
  }

  /* Скрываем текст "Фильтры", чтобы кнопка была компактной */
  .tpl-filter-toggle > span:not(.filters-cta-count) {
    display: none;
  }

  /* Бейдж — обычный элемент справа от иконки, НЕ поверх */
  .questions-filters-block .filters-cta-count {
    position: static; /* снимаем возможный absolute из глобальных стилей */
    margin-left: 2px; /* маленький отступ от иконки */
    transform: none;
  }
}
/* Кнопка "Фильтры" на странице вопросов: скрыть числовой бейдж */
.questions-filters-block #questionsFiltersCount {
  display: none !important;
}

/* =================================
   FIX (/templates): убрать горизонтальную прокрутку в модалке фильтров
   и включить перенос чипов
   ================================= */

/* Чипы внутри модального окна фильтров должны переноситься, без x-scroll */
.filters-modal .tpl-filter-chips,
.filters-modal .kb-filter-chips,
.filters-modal #tagChipsRow {
  flex-wrap: wrap;
  overflow-x: visible;
  white-space: normal;
  padding-bottom: 0;
}

/* На всякий случай: если контейнер рендерится как .chips-grid */
.filters-modal .chips-grid {
  flex-wrap: wrap;
  overflow-x: visible;
}

/* Скрыть возможные скроллбары в webkit (если браузер всё равно их рисует) */
.filters-modal .tpl-filter-chips::-webkit-scrollbar,
.filters-modal .kb-filter-chips::-webkit-scrollbar,
.filters-modal #tagChipsRow::-webkit-scrollbar {
  display: none;
}

/* Если где-то принудительно задан nowrap для чипов — отменяем */
.filters-modal .tpl-filter-chips .filter-chip,
.filters-modal .tpl-filter-chips .tpl-filter-chip,
.filters-modal .kb-filter-chips .kb-filter-chip,
.filters-modal #tagChipsRow button {
  white-space: normal;
}
/* =========================================
   Glass tabs/chips under search (Questions + Templates)
   Fix: make chips blend with site glass background
   ========================================= */

/* 1) Рейл (контейнер) под поиском — как стеклянная полоска */
#tagChipsRow,
.tpl-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  white-space: nowrap;

  /* вместо жирных паддингов и "пустоты" — тонкий glass-рейл */
  padding: 8px 8px;
  margin-top: 10px;

  backdrop-filter: blur(12px) saturate(150%);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
}

#tagChipsRow::-webkit-scrollbar,
.tpl-tabs::-webkit-scrollbar {
  display: none;
}

/* 2) Базовый вид чипов/табов — компактные pill в вашем стиле */
#tagChipsRow button,
#tagChipsRow .tpl-tag-chip,
#tagChipsRow .kb-chip,
.tpl-tabs .tpl-tab {
  flex: 0 0 auto;
  height: 30px;
  padding: 6px 12px; /* компактно */
  border-radius: 999px;

  font-size: 12px;
  font-weight: 600;
  line-height: 1;

  color: var(--text-soft, #4b5563);
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(209, 213, 219, 0.7);
  box-shadow: 0 2px 10px rgba(31, 38, 135, 0.08);

  cursor: pointer;
  transition: transform 0.16s ease-out, box-shadow 0.16s ease-out,
    background 0.16s ease-out, border-color 0.16s ease-out, color 0.16s ease-out;
}

/* 3) Hover — лёгкий подъём как у карточек */
@media (hover: hover) {
  #tagChipsRow button:hover,
  #tagChipsRow .tpl-tag-chip:hover,
  #tagChipsRow .kb-chip:hover,
  .tpl-tabs .tpl-tab:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--shadow-glass, 0 8px 24px rgba(31, 38, 135, 0.15));
  }
}

/* 4) Active — акцентный “soft” (без чужого яркого синего пятна) */
#tagChipsRow button.active,
#tagChipsRow .tpl-tag-chip.active,
#tagChipsRow .kb-chip.active,
.tpl-tabs .tpl-tab--active {
  color: var(--accent-strong, #3340ff);
  background: rgba(239, 246, 255, 0.92);
  border-color: rgba(76, 111, 255, 0.45);
  box-shadow: 0 6px 18px rgba(76, 111, 255, 0.18);
}

/* 5) Active: лёгкая “подсветка” внутри, как у glass-карточек */
#tagChipsRow button.active,
.tpl-tabs .tpl-tab--active {
  position: relative;
  overflow: hidden;
}
#tagChipsRow button.active::after,
.tpl-tabs .tpl-tab--active::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    circle at 18% 22%,
    rgba(76, 111, 255, 0.14),
    transparent 58%
  );
  opacity: 0.9;
}

/* 6) Mobile: чуть компактнее, чтобы не “толстело” */
@media (max-width: 640px) {
  #tagChipsRow,
  .tpl-tabs {
    padding: 7px 7px;
    gap: 7px;
  }

  #tagChipsRow button,
  #tagChipsRow .tpl-tag-chip,
  #tagChipsRow .kb-chip,
  .tpl-tabs .tpl-tab {
    height: 30px;
    padding: 6px 11px;
  }
}
