/* AutoBazar Mini App — цвета берём из темы Telegram, чтобы приложение
   выглядело родным и в светлой, и в тёмной теме. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --accent: #38bdf8;
  --radius: 14px;
  --gap: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg2); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-tap-highlight-color: transparent; }
body { padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--link); }
button { font: inherit; }

#app { max-width: 720px; margin: 0 auto; min-height: 100vh; }
.screen { padding: var(--gap); animation: fade .15s ease-out; }
@keyframes fade { from { opacity: .4 } to { opacity: 1 } }
.loading, .empty, .error { padding: 48px 16px; text-align: center; color: var(--hint); font-size: 16px; }
.error { color: #e5484d; }

/* Шапка */
.header { display: flex; align-items: baseline; justify-content: space-between; margin: 4px 2px 14px; }
.header h1 { font-size: 24px; margin: 0; letter-spacing: -0.01em; }
.header h1 span { color: var(--accent); }
.header .sub { color: var(--hint); font-size: 13px; }

/* Поиск */
.search { display: flex; gap: 8px; margin-bottom: 12px; }
.search input { flex: 1; border: 0; border-radius: 12px; padding: 12px 14px; font-size: 16px;
  background: var(--card); color: var(--text); outline: none; }
.search input::placeholder { color: var(--hint); }

/* Чипы городов */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 0; border-radius: 999px; padding: 8px 14px; font-size: 14px;
  background: var(--card); color: var(--text); cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--btn); color: var(--btn-text); }

/* Сетка категорий */
.cats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 480px) { .cats { grid-template-columns: repeat(3, 1fr); } }
.cat { border: 0; border-radius: var(--radius); background: var(--card); color: var(--text);
  padding: 14px 12px; text-align: left; display: flex; gap: 10px; align-items: center; cursor: pointer;
  min-height: 64px; }
.cat:active { transform: scale(.98); }
.cat .ico { font-size: 26px; line-height: 1; }
.cat .name { font-size: 14px; font-weight: 600; line-height: 1.2; }
.cat .cnt { font-size: 12px; color: var(--hint); margin-top: 2px; }
.cat.zero { opacity: .55; }

/* Список объявлений */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin: 2px 2px 12px; gap: 8px; }
.toolbar h2 { font-size: 20px; margin: 0; }
.toolbar .cnt { color: var(--hint); font-size: 13px; white-space: nowrap; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.card { background: var(--card); border-radius: var(--radius); overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; }
.card:active { transform: scale(.985); }
.card .ph { position: relative; aspect-ratio: 4 / 3; background: var(--bg2); }
.card .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .ph .noph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--hint); font-size: 28px; }
.card .ph .n { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.55); color: #fff;
  font-size: 11px; padding: 2px 7px; border-radius: 999px; }
.card .ph .test { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.55); color: #fff;
  font-size: 11px; padding: 2px 7px; border-radius: 999px; }
.card .body { padding: 9px 10px 11px; }
.card .price { font-weight: 700; font-size: 16px; }
.card .price.free { color: #2a9d5c; }
.card .title { font-size: 13px; line-height: 1.25; margin-top: 3px; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { font-size: 11px; color: var(--hint); margin-top: 5px; }

.more { display: block; width: 100%; margin: 14px 0 4px; border: 0; border-radius: 12px; padding: 13px;
  background: var(--card); color: var(--link); font-weight: 600; cursor: pointer; }
.more:disabled { opacity: .5; }

/* Карточка объявления */
.detail .gallery { position: relative; margin: calc(-1 * var(--gap)); margin-bottom: 0; background: #000; }
.gallery .track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.gallery .track::-webkit-scrollbar { display: none; }
.gallery .track img { flex: 0 0 100%; width: 100%; aspect-ratio: 4 / 3; object-fit: contain;
  scroll-snap-align: center; background: #000; }
.gallery .dots { position: absolute; bottom: 10px; left: 0; right: 0; display: flex; justify-content: center; gap: 5px; }
.gallery .dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.45); }
.gallery .dots i.on { background: #fff; }
.gallery .cnt { position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,.55); color: #fff;
  font-size: 12px; padding: 3px 8px; border-radius: 999px; }
.detail .noph { aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center;
  background: var(--card); color: var(--hint); margin: calc(-1 * var(--gap)); margin-bottom: 0; }
.detail .price { font-size: 26px; font-weight: 800; margin: 16px 0 4px; }
.detail .price.free { color: #2a9d5c; }
.detail h2 { font-size: 19px; margin: 0 0 10px; line-height: 1.25; }
.detail .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.detail .tag { background: var(--card); border-radius: 999px; padding: 5px 10px; font-size: 13px; }
.detail .tag.test { background: #fde68a; color: #4a3d00; }
.detail .desc { background: var(--card); border-radius: var(--radius); padding: 14px; white-space: pre-wrap;
  line-height: 1.45; font-size: 15px; word-break: break-word; }
.detail .author { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-top: 10px; }
.detail .author .who { font-size: 14px; }
.detail .author .who b { display: block; }
.detail .author .who span { color: var(--hint); font-size: 12px; }
.detail .foot { color: var(--hint); font-size: 12px; margin: 12px 2px 90px; }

/* Нижняя кнопка «Написать автору» */
.cta { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px var(--gap) calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg2) 70%, transparent); }
.cta button { width: 100%; max-width: 720px; display: block; margin: 0 auto; border: 0; border-radius: 12px;
  padding: 15px; font-size: 16px; font-weight: 700; background: var(--btn); color: var(--btn-text); cursor: pointer; }
.cta button.muted { background: var(--card); color: var(--hint); }
