/* ============================================
   BI.KG — Доска объявлений
   Мобильное приложение
   ============================================ */

:root {
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-header: #000000;
  --color-header-text: #ffffff;
  --color-accent: #1e90ff;
  --color-accent-hover: #1a7ae6;
  --color-accent-light: #e8f4ff;
  --color-text: #000000;
  --color-text-muted: #555555;
  --color-border: #e2e8f0;
  --color-shadow: rgba(15, 23, 42, 0.08);
  --color-shadow-strong: rgba(15, 23, 42, 0.15);
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 10px;
  --radius-full: 9999px;
  --font: 'Trebuchet MS', Trebuchet, Tahoma, Arial, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --header-h: 56px;
  --header-total: calc(var(--header-h) + max(12px, env(safe-area-inset-top)));
  --nav-h: 70px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100%;
  overflow: hidden;
}

.app {
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 0 1px var(--color-border);
  overflow: hidden;
}

/* ========== Верхний топ-бар (зафиксирован) ========== */
.top-bar {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  z-index: 100;
  flex-shrink: 0;
  min-height: var(--header-h);
  padding: 0 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: 8px;
  background: #000000;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.top-bar__side {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

.top-bar__side--left {
  justify-content: flex-start;
}

.top-bar__side--right {
  justify-content: flex-end;
}

.top-bar__btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--color-accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff;
  -webkit-text-fill-color: #ffffff;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 400;
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  flex-shrink: 0;
}

.top-bar__btn:hover {
  background: var(--color-accent-hover);
}

.top-bar__btn:active {
  transform: scale(0.97);
}

.top-bar__btn svg {
  width: 18px;
  height: 18px;
}

.top-bar__logo {
  font-size: 20px;
  font-weight: 400;
  letter-spacing: -0.5px;
  color: #ffffff;
  -webkit-text-fill-color: #ffffff;
  text-decoration: none;
  cursor: pointer;
  flex-shrink: 0;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.top-bar__auth {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
  min-width: 0;
}

.top-bar__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  text-decoration: none;
  font-size: 12px;
  font-weight: 400;
  padding: 8px 12px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  opacity: 0.9;
  transition: opacity 0.2s, background 0.2s;
  white-space: nowrap;
}

.top-bar__link:hover {
  opacity: 1;
}

.top-bar__link--accent {
  background: var(--color-accent);
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff;
}

.top-bar__link--accent:hover {
  background: var(--color-accent-hover);
}

/* ========== Контент (скролл только в центре) ========== */
.content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 12px;
  padding-top: var(--header-total);
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  overflow: hidden;
  gap: 10px;
}

.content__scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 16px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.content__scroll::-webkit-scrollbar {
  display: none;
}

.content__scroll[hidden] {
  display: none !important;
}

.home-top-bar {
  flex-shrink: 0;
  margin-bottom: 12px;
}

.home-header {
  flex-shrink: 0;
  margin-bottom: 12px;
}

.category-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--color-text);
  margin-bottom: 10px;
  text-align: center;
  letter-spacing: -0.3px;
}

/* ========== Переключатель вида ========== */
.view-switcher {
  display: flex;
  gap: 8px;
  margin: 0;
  flex-shrink: 0;
  background: var(--color-surface);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
}

.view-switcher__btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.view-switcher__btn svg {
  width: 18px;
  height: 18px;
}

.view-switcher__btn:hover {
  color: var(--color-text);
}

.view-switcher__btn--active {
  background: var(--color-accent);
  color: white;
}

.view-switcher__btn--active:hover {
  color: white;
  background: var(--color-accent-hover);
}

/* ========== Страницы ========== */
.page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
}

.page[hidden] {
  display: none !important;
}

.page__scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.page__scroll::-webkit-scrollbar {
  display: none;
}

.page__title {
  font-size: 24px;
  font-weight: 800;
  color: var(--color-text);
  margin-bottom: 20px;
  text-align: center;
}

/* Формы */
.add-form,
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row-with-btn {
  display: flex;
  gap: 8px;
  align-items: center;
}

.form-row-with-btn .form-input {
  flex: 1;
  min-width: 0;
}

.add-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.add-photo-preview {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-border);
}

.add-photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.add-photo-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.form-input {
  font-family: var(--font);
  font-size: 15px;
  padding: 12px 14px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.btn--full {
  width: 100%;
  margin-top: 8px;
}

/* Профиль */
.profile-block {
  text-align: center;
  padding: 24px 0;
}

.profile-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.profile-email {
  font-size: 14px;
  color: var(--color-text-muted);
  margin-bottom: 20px;
}

.profile-nav {
  margin-bottom: 16px;
  width: 100%;
}

.profile-tier {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  width: 100%;
}

.profile-tier__label {
  font-size: 14px;
  color: var(--color-text);
  font-weight: 500;
}

.profile-tier__badge {
  font-size: 12px;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.profile-tier__badge--basic {
  background: var(--color-bg);
  color: var(--color-text-muted);
}

.profile-tier__badge--premium {
  background: #e0e7ff;
  color: #4338ca;
}

.profile-tier__badge--vip {
  background: #fef3c7;
  color: #b45309;
}

.profile-upgrade {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
  width: 100%;
}

.profile-upgrade__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 4px;
}

.profile-upgrade__item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 12px 14px;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  width: 100%;
}

.profile-upgrade__info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.profile-upgrade__desc {
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.3;
}

.profile-upgrade__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-start;
  margin-top: 4px;
}

.profile-upgrade__btn {
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 600;
}

.btn--sm {
  padding: 8px 16px;
  font-size: 13px;
  flex-shrink: 0;
}

.profile-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.profile-link {
  color: var(--color-accent);
  font-weight: 600;
  text-decoration: none;
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
}

.auth-tab--active {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.add-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.add-tab {
  flex: 1;
  padding: 8px 6px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.add-tab--active {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-light);
}

.add-tab-desc {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 12px;
}

.add-file-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  cursor: pointer;
  margin-bottom: 12px;
}

.add-file-zone:hover {
  border-color: var(--color-accent);
}

.add-file-input {
  display: none;
}

.add-file-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

.add-file-hint {
  font-size: 12px;
  color: var(--color-text-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form[hidden] {
  display: none !important;
}

.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: 40px 20px;
}

.empty-state .btn {
  margin-top: 16px;
  display: inline-block;
}

.empty-state__hint {
  font-size: 13px;
  margin-top: 8px;
  opacity: 0.8;
}

.favorites-tabs {
  margin-bottom: 12px;
}

.favorites-tab-panel {
  animation: fadeIn 0.2s ease;
}

.favorites-queries {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.favorite-query-card {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.favorite-query-card:hover {
  border-color: var(--color-accent);
  box-shadow: 0 4px 12px var(--color-shadow);
}

.favorite-query-card__body {
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.favorite-query-card__title {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.favorite-query-card__actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* Материалы пользователя */
.materials-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 0;
}

.material-item {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
}

.material-item__body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.material-item__title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.material-item__desc {
  font-size: 13px;
  color: var(--color-text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.material-item__actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.material-item__btn {
  padding: 6px 12px;
  font-size: 12px;
}

.material-item__btn--edit {
  background: #000000;
  color: white;
  border: none;
}

.material-item__btn--edit:hover {
  background: #333333;
}

.material-item__btn--danger {
  background: #ffffff;
  color: #000000;
  border: 2px solid #000000;
}

.material-item__btn--danger:hover {
  background: #f5f5f5;
}

.materials-main-tabs {
  margin-bottom: 12px;
}

.materials-export-tabs {
  margin-bottom: 12px;
}

.materials-tabs {
  margin-bottom: 12px;
}

.materials-tab-panel {
  animation: fadeIn 0.2s ease;
}

.materials-export-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.materials-export-btns .btn {
  flex: 1;
  min-width: 80px;
}

/* ========== Карта ========== */
.map-container {
  flex: 1;
  min-height: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  position: relative;
  isolation: isolate;
  z-index: 1;
  border: 2px solid var(--color-border);
  margin-bottom: 12px;
  background: var(--color-surface);
  box-shadow: 0 2px 12px var(--color-shadow);
}

.map-container[hidden] {
  display: none !important;
}

#listingsMap {
  width: 100%;
  height: 100%;
  min-height: 300px;
}

.map-close-btn {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius-md);
  background: #1e90ff;
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(30, 144, 255, 0.4);
  cursor: pointer;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  transition: background 0.2s, transform 0.15s;
}

.map-close-btn:hover {
  background: #1a7ae6;
}

.map-close-btn:active {
  transform: translateX(-50%) scale(0.98);
}

.map-fullscreen-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 2px 12px var(--color-shadow-strong);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.map-fullscreen-btn:hover {
  background: var(--color-accent);
  color: #ffffff;
}

.map-fullscreen-btn svg {
  width: 20px;
  height: 20px;
}

/* Корректировка нижней части карты — бордер и attribution */
.leaflet-bottom.leaflet-right {
  bottom: 8px !important;
  right: 8px !important;
}

.leaflet-control-attribution {
  font-size: 10px !important;
  padding: 2px 6px !important;
  max-width: 200px;
}

/* Ограничение z-index Leaflet */
.leaflet-pane,
.leaflet-top,
.leaflet-bottom {
  z-index: 2 !important;
}

.leaflet-control {
  z-index: 3 !important;
}

.leaflet-popup-pane {
  z-index: 4 !important;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px var(--color-shadow-strong);
  padding: 0;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0;
  min-width: 200px;
  font-family: var(--font);
}

.map-popup {
  padding: 12px;
}

.map-popup__price {
  font-weight: 700;
  font-size: 15px;
  color: var(--color-accent);
  margin-bottom: 4px;
}

.map-popup__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.35;
  margin-bottom: 6px;
}

.map-popup__link {
  font-size: 12px;
  color: var(--color-accent);
  font-weight: 600;
  text-decoration: none;
}

.leaflet-container {
  font-family: var(--font);
}

/* Кластеры маркеров — в стиле приложения */
.marker-cluster-small {
  background-color: rgba(249, 115, 22, 0.4);
}
.marker-cluster-small div {
  background-color: rgba(249, 115, 22, 0.7);
  color: white;
}

.marker-cluster-medium {
  background-color: rgba(234, 88, 12, 0.4);
}
.marker-cluster-medium div {
  background-color: rgba(234, 88, 12, 0.7);
  color: white;
}

.marker-cluster-large {
  background-color: rgba(194, 65, 12, 0.4);
}
.marker-cluster-large div {
  background-color: rgba(194, 65, 12, 0.8);
  color: white;
}

.marker-cluster {
  font-family: var(--font);
  font-weight: 600;
}

/* ========== Поиск и фильтр ========== */
.search-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  width: 100%;
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0 12px;
  min-height: 40px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  text-align: left;
  color: var(--color-text-muted);
  transition: border-color 0.2s, box-shadow 0.2s, color 0.2s;
}

.search-trigger--full {
  width: 100%;
}

.filters-row {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
}

.region-select {
  flex: 1;
  min-width: 0;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 0 10px;
  min-height: 40px;
  cursor: pointer;
}

.region-select--full {
  width: 100%;
  flex: none;
}

.region-select:hover,
.region-select:focus {
  border-color: var(--color-accent);
  outline: none;
}

.search-trigger:hover,
.search-trigger:focus {
  border-color: var(--color-accent);
  color: var(--color-text);
  outline: none;
}

.search-trigger__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.search-trigger__text,
.filter-category-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box--in-dialog {
  margin: 0;
}

.search-box:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-light);
}

.search-box__icon {
  width: 20px;
  height: 20px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.search-box__input {
  flex: 1;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 15px;
  padding: 12px 0;
  color: var(--color-text);
}

.search-box__input::placeholder {
  color: var(--color-text-muted);
}

.search-box__input:focus {
  outline: none;
}

.sort-select {
  flex: 0 1 auto;
  min-width: 0;
  width: auto;
  max-width: min(220px, 100%);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 0 10px;
  min-height: 40px;
  cursor: pointer;
  transition: all 0.2s;
}

.sort-select:hover,
.sort-select:focus {
  border-color: var(--color-accent);
  outline: none;
}

.filter-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 0 12px;
  min-height: 40px;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn:hover,
.filter-btn:focus {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.filter-btn:active {
  transform: scale(0.98);
}

.filter-btn svg {
  width: 20px;
  height: 20px;
}

/* ========== Карточки объявлений ========== */
.listings {
  padding: 12px;
}

.listings:has(.listings-grid) {
  display: flex;
  flex-direction: column;
}

.listings:not(:has(.listings-grid)) {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.listings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.listings-pagination {
  margin-top: 16px;
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.listings-load-more {
  margin-top: 20px;
  padding: 12px 20px;
  background: var(--color-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.listings-load-more:hover {
  background: var(--color-accent-hover);
}

.listings-pagination__pages {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.listings-pagination__btn {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.listings-pagination__btn:hover {
  border-color: var(--color-accent);
}

.listings-pagination__btn--active {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: white;
}


.listing-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 2px 12px var(--color-shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}

.listing-card:hover,
.listing-card:active {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--color-shadow-strong);
}

.listing-card__img-wrap {
  position: relative;
  aspect-ratio: 1;
  background: var(--color-border);
  overflow: hidden;
}

.listing-card__img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.listing-card__price {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  color: white;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

.listing-card__body {
  padding: 8px 10px;
}

.listing-card__title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.listing-card__meta {
  font-size: 11px;
  color: var(--color-text-muted);
}

/* ========== Модальное окно (диалог) ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  pointer-events: none;
  visibility: hidden;
  transition: visibility 0.3s;
}

.modal[hidden] {
  display: flex !important;
}

.modal.is-open {
  pointer-events: auto;
  visibility: visible;
}

.modal.is-open .modal__backdrop {
  opacity: 1;
}

.modal.is-open .modal__panel {
  transform: translateY(0);
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.3s;
}

.modal__panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 40px var(--color-shadow-strong);
  overflow: hidden;
}

.modal__panel--full {
  max-height: 90vh;
}

/* Модалка по центру (категории) */
.modal--center {
  align-items: center;
  justify-content: center;
}

.modal--center .modal__panel {
  transform: scale(0.9);
  opacity: 0;
  border-radius: var(--radius-xl);
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.modal--center.is-open .modal__panel {
  transform: scale(1);
  opacity: 1;
}

.modal__panel--fullscreen {
  width: 100%;
  max-width: 480px;
  height: 90vh;
  max-height: 700px;
  border-radius: var(--radius-xl);
}

.modal__panel--universal {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  border-radius: var(--radius-xl);
}

.modal__body--scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: calc(90vh - 70px);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.modal__body--scroll::-webkit-scrollbar {
  display: none;
}

/* Страница объявления в диалоге */
.listing-detail {
  padding-bottom: 16px;
}

.listing-detail__img-wrap {
  position: relative;
  aspect-ratio: 16/10;
  background: var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 16px;
}

.listing-slider {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.listing-slider__track {
  display: flex;
  height: 100%;
  transition: transform 0.3s ease;
}

.listing-slider__slide {
  flex: 0 0 100%;
  height: 100%;
}

.listing-slider__slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.listing-slider__dots {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 2;
}

.listing-slider__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: background 0.2s;
}

.listing-slider__dot:hover,
.listing-slider__dot--active {
  background: rgba(255, 255, 255, 1);
}

.listing-slider__arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(0, 0, 0, 0.4);
  color: white;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.listing-slider__arrow:hover {
  background: rgba(0, 0, 0, 0.6);
}

.listing-slider__arrow--prev {
  left: 8px;
}

.listing-slider__arrow--next {
  right: 8px;
}

.listing-detail__img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.listing-detail__price {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  font-size: 18px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
}

.listing-detail__title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.3;
}

.listing-detail__meta {
  color: var(--color-text-muted);
  font-size: 14px;
  margin-bottom: 16px;
}

.listing-detail__desc {
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 20px;
  color: var(--color-text);
}

.listing-detail__contact {
  text-decoration: none;
  text-align: center;
  display: block;
}

.modal__header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  min-height: 56px;
}

.modal__header .modal__title {
  text-align: center;
}

.modal__title {
  font-size: 20px;
  font-weight: 700;
  padding: 0 48px;
}

.modal__close {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  border: none;
  border-radius: var(--radius-full);
  font-size: 24px;
  line-height: 1;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.modal__close:hover {
  background: var(--color-border);
  color: var(--color-text);
}

.modal__body {
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.modal__body::-webkit-scrollbar {
  display: none;
}

.modal__footer {
  padding: 16px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

/* Фильтры */
.filter-group {
  margin-bottom: 20px;
}

.filter-group:last-child {
  margin-bottom: 0;
}

.filter-footer {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}

.filter-footer .btn {
  flex: 1;
}

.filter-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-input,
.filter-select {
  flex: 1;
  font-family: var(--font);
  font-size: 15px;
  padding: 12px 14px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.2s;
}

.filter-input:focus,
.filter-select:focus {
  outline: none;
  border-color: var(--color-accent);
}

.filter-sep {
  color: var(--color-text-muted);
  font-weight: 500;
}

/* Кнопки */
.btn {
  flex: 1;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn--ghost {
  background: var(--color-bg);
  color: var(--color-text-muted);
}

.btn--ghost:hover {
  background: var(--color-border);
}

.btn--primary {
  background: var(--color-accent);
  color: white;
}

.btn--primary:hover {
  background: var(--color-accent-hover);
}

.btn:active {
  transform: scale(0.98);
}

/* Иерархический stack menu категорий */
.stack-menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stack-menu__item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s;
}

.stack-menu__item:hover,
.stack-menu__item:active {
  background: var(--color-bg);
}

.stack-menu__icon {
  font-size: 20px;
  line-height: 1;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.stack-menu__label {
  flex: 1;
}

.stack-menu__arrow {
  color: var(--color-text-muted);
  font-size: 18px;
}

.modal__header {
  position: relative;
}

.stack-menu__back {
  position: absolute;
  left: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  border: none;
  border-radius: var(--radius-full);
  font-size: 20px;
  color: var(--color-text);
  cursor: pointer;
  transition: background 0.2s;
}

.stack-menu__back:hover {
  background: var(--color-border);
}

.stack-menu__back[hidden] {
  display: flex !important;
  visibility: hidden;
  pointer-events: none;
}

.top-bar__user {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-header-text);
}

/* ========== Баннер установки PWA ========== */
.pwa-install-banner {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 480px;
  z-index: 150;
  background: #000000;
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  animation: pwaBannerIn 0.3s ease;
}

.pwa-install-banner[hidden] {
  display: none !important;
}

@keyframes pwaBannerIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.pwa-install-banner__content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pwa-install-banner__text {
  font-size: 14px;
  flex: 1;
}

.pwa-install-banner__actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ========== Нижний нав-бар ========== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #000000;
  border-top: 1px solid rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  padding: 8px 0 0;
  z-index: 90;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
}

.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  padding: 8px 4px;
  text-decoration: none;
  color: #ffffff;
  font-size: 10px;
  font-weight: 400;
  transition: color 0.2s;
  position: relative;
}

.bottom-nav__item svg {
  width: 24px;
  height: 24px;
  stroke-width: 2;
  stroke: currentColor;
}

.bottom-nav__item:hover {
  color: #1e90ff;
}

.bottom-nav__item--active {
  color: #ffffff;
}

.bottom-nav__item--active:hover {
  color: #1e90ff;
}

.bottom-nav__item--active svg {
  stroke-width: 2.5;
}

.bottom-nav__item--add {
  color: #1390ff;
}

.bottom-nav__item--add:hover,
.bottom-nav__item--add:active {
  color: #1e90ff;
}

/* ========== Адаптив ========== */
@media (min-width: 481px) {
  .app {
    border-radius: 0;
    overflow: hidden;
    margin: 20px auto;
    min-height: calc(100dvh - 40px);
  }

  .top-bar,
  .bottom-nav {
    border-radius: 0;
  }
}

/* Desktop: топ-бар, центральный блок и нижний бар на всю ширину */
@media (min-width: 769px) {
  .app {
    max-width: none;
    width: 100%;
    margin: 0;
    border-radius: 0;
  }

  .top-bar {
    left: 0;
    transform: none;
    max-width: none;
    width: 100%;
  }

  .bottom-nav {
    left: 0;
    transform: none;
    max-width: none;
    width: 100%;
  }

  .top-bar__btn {
    font-size: 14px;
    padding: 10px 14px;
  }

  .top-bar__btn svg {
    width: 20px;
    height: 20px;
  }

  .top-bar__logo {
    font-size: 24px;
  }

  .top-bar__link {
    font-size: 14px;
    padding: 10px 14px;
    min-height: 40px;
  }

  .bottom-nav__item {
    font-size: 13px;
    gap: 6px;
    padding: 10px 6px;
  }

  .bottom-nav__item svg {
    width: 28px;
    height: 28px;
  }

  .home-top-bar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
  }

  .home-top-bar .view-switcher {
    flex: 1 1 0;
    min-width: 0;
  }

  .home-top-bar .home-header {
    flex: 3 3 0;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 0;
    min-width: 0;
  }

  .home-top-bar .home-header .category-title {
    flex: 2 2 0;
    margin-bottom: 0;
    text-align: center;
    min-width: 0;
  }

  .home-top-bar .home-header .filters-row {
    flex: 1 1 0;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
  }

  .home-top-bar .category-title {
    font-size: 22px;
  }

  .home-top-bar .sort-select {
    font-size: 14px;
    min-height: 42px;
  }

  .home-top-bar .filter-btn {
    font-size: 14px;
    min-height: 42px;
    padding: 0 14px;
  }

  .listings:not(:has(.listings-grid)) {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
  }

  .listings-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
  }
}

/* Улучшение для очень маленьких экранов */
@media (max-width: 340px) {
  .top-bar__btn span {
    display: none;
  }

  .listings {
    grid-template-columns: 1fr;
  }
}
