/* Цвета берутся из темы Telegram: приложение должно выглядеть продолжением
   мессенджера, а не чужой страницей внутри него. Значения после запятой — на
   случай, когда страницу открыли не из Telegram и переменных нет. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-bg-color, #fff);
  --fg: var(--tg-theme-text-color, #14171a);
  --muted: var(--tg-theme-hint-color, #8b949e);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-fg: var(--tg-theme-button-text-color, #fff);
  --line: rgba(128, 128, 128, .22);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  padding: 0 0 4.4rem;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
body.locked { overflow: hidden; }

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.screen { padding: .6rem .75rem 1rem; }
.screen[hidden] { display: none; }

.fatal {
  margin: 0;
  padding: .9rem 1rem;
  background: #b3261e;
  color: #fff;
  font-size: .9rem;
}
.fatal[hidden] { display: none; }

.status { color: var(--muted); font-size: .85rem; text-align: center; padding: .5rem 0 0; }
.hint { color: var(--muted); font-size: .82rem; }

/* ---------- Верхняя строка ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: .4rem;
  align-items: center;
  margin: -.6rem -.75rem 0;
  padding: .5rem .75rem .45rem;
  background: var(--bg);
}

.filter-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .75rem;
  font-size: .86rem;
  font-weight: 600;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.filter-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}
.filter-btn .count { color: var(--accent); }
.filter-btn .count[hidden] { display: none; }

.chips {
  display: flex;
  gap: .35rem;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 88%, transparent);
  mask-image: linear-gradient(to right, #000 88%, transparent);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: .45rem .75rem;
  font-size: .84rem;
  white-space: nowrap;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.found-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .35rem .1rem .6rem;
}
.found {
  font-size: .76rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.sort-btn {
  display: inline-flex;
  padding: .3rem;
  background: none;
  border: none;
  color: var(--fg);
}
.sort-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.title {
  margin: 0 0 .35rem;
  font-size: .97rem;
  font-weight: 600;
  line-height: 1.3;
  /* Две строки: длинные польские заголовки иначе занимают пол-карточки. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.segmented.vertical { flex-direction: column; }
.segmented.vertical .seg { text-align: left; padding: .7rem .8rem; }

/* ---------- Карточка ---------- */

.feed { display: flex; flex-direction: column; gap: .75rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.card.dropped { opacity: .42; }

.gallery { position: relative; background: #0000000d; }

/* scroll-snap-stop: always — главное здесь. Без него один жест пролистывает
   несколько снимков, и лента ощущается как перетаскивание одной картинки. */
.track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.track::-webkit-scrollbar { display: none; }
.track img {
  flex: 0 0 100%;
  width: 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  user-select: none;
}

.no-photo {
  padding: 2.4rem .8rem;
  text-align: center;
  color: var(--muted);
  font-size: .82rem;
}

.counter {
  position: absolute;
  bottom: .5rem;
  right: .6rem;
  padding: .16rem .5rem;
  font-size: .74rem;
  color: #fff;
  background: rgba(0, 0, 0, .55);
  border-radius: 999px;
  pointer-events: none;
}
.dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: .5rem;
  display: flex;
  justify-content: center;
  gap: .25rem;
  pointer-events: none;
}
.dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .5);
}
.dots span.on { background: #fff; }

.card-body {
  display: block;
  padding: .75rem .9rem .9rem;
  color: inherit;
  text-decoration: none;
}

.price-row { display: flex; align-items: baseline; gap: .45rem; flex-wrap: wrap; }
.price { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; }
.rent { font-size: .8rem; color: var(--muted); }

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem .9rem;
  margin-top: .45rem;
  font-size: .87rem;
  color: var(--muted);
}
.fact { display: inline-flex; align-items: center; gap: .3rem; }
.fact svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.place { margin-top: .45rem; font-size: .87rem; color: var(--muted); }
.meta { margin-top: .1rem; font-size: .78rem; color: var(--muted); }

/* Источник — внизу слева на снимке, как пометка на доске объявлений. */
.badge {
  position: absolute;
  bottom: .5rem;
  left: .6rem;
  padding: .18rem .55rem;
  font-size: .72rem;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, .6);
  border-radius: 6px;
  pointer-events: none;
}

/* Отметки — круглыми значками поверх снимка, как «сердце» на доске. */
.react-float { position: absolute; top: .5rem; right: .55rem; display: flex; gap: .35rem; }
.rf {
  width: 34px;
  height: 34px;
  font-size: 1rem;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, .5);
  border: none;
  border-radius: 50%;
  backdrop-filter: blur(3px);
}
.rf.on { background: var(--accent); color: var(--accent-fg); }

/* ---------- Вкладки ---------- */

.tabs {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1;
  padding: .85rem .3rem;
  font-size: .82rem;
  color: var(--muted);
  background: none;
  border: none;
}
.tabs button.active { color: var(--accent); font-weight: 600; }

/* ---------- Шторка фильтров ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, .35);
}
.backdrop[hidden] { display: none; }

.sheet {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 21;
  display: flex;
  flex-direction: column;
  max-height: 88vh;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  animation: rise .22s ease-out;
}
.sheet[hidden] { display: none; }
@keyframes rise { from { transform: translateY(100%); } to { transform: none; } }

.sheet-grip {
  width: 36px;
  height: 4px;
  margin: .5rem auto .2rem;
  background: var(--line);
  border-radius: 2px;
}
.sheet-body { overflow-y: auto; padding: .5rem 1rem 1rem; }
.sheet-actions {
  display: flex;
  gap: .5rem;
  padding: .7rem 1rem calc(.7rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.field { display: block; margin-bottom: 1rem; font-size: .82rem; color: var(--muted); }
.field select,
.field input[type=number] {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .65rem .7rem;
  background: var(--bg);
  border: none;
  border-radius: 10px;
}
.pair { display: flex; gap: .6rem; }
.pair .field { flex: 1; }

.segmented { display: flex; gap: .3rem; margin-top: .35rem; }
.seg {
  flex: 1;
  padding: .5rem .2rem;
  font-size: .84rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 9px;
}
.seg.on { background: var(--accent); color: var(--accent-fg); font-weight: 600; }

.checks { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .35rem; }
.check {
  padding: .38rem .7rem;
  font-size: .84rem;
  color: var(--fg);
  background: var(--bg);
  border-radius: 999px;
}
.check.on { background: var(--accent); color: var(--accent-fg); }
.check input { display: none; }
.check.wide {
  display: block;
  margin-top: .35rem;
  padding: .6rem .8rem;
  border-radius: 10px;
}
.check.wide:has(input:checked) { background: var(--accent); color: var(--accent-fg); }

/* Два поля диапазона рядом. */
.pair { display: flex; gap: .6rem; margin-top: .3rem; }
.pair input {
  flex: 1;
  width: 100%;
  padding: .65rem .7rem;
  background: var(--bg);
  border: none;
  border-radius: 10px;
}

.primary, .ghost {
  padding: .8rem;
  font-size: .95rem;
  font-weight: 600;
  border: none;
  border-radius: 11px;
}
.primary { flex: 1; color: var(--accent-fg); background: var(--accent); }
.ghost { flex: 1; color: var(--accent); background: var(--bg); }

/* ---------- Фото во весь экран ---------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  background: #000;
}
.viewer[hidden] { display: none; }
.viewer-track { width: 100%; }
.viewer-track img { aspect-ratio: auto; max-height: 100vh; object-fit: contain; }
.viewer-close {
  position: absolute;
  top: calc(.6rem + env(safe-area-inset-top));
  right: .7rem;
  z-index: 2;
  width: 34px;
  height: 34px;
  font-size: 1rem;
  color: #fff;
  background: rgba(0, 0, 0, .5);
  border: none;
  border-radius: 50%;
}
.viewer-counter { top: auto; bottom: calc(1rem + env(safe-area-inset-bottom)); right: 50%; transform: translateX(50%); }
