:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2f9ed6);
  --button-text: var(--tg-theme-button-text-color, #ffffff);

  --mint: #2fd9a8;
  --mint-dark: #1fae86;
  --teal: #1fa8d6;
  --amber: #f2a93b;
  --danger: #e5484d;

  --radius-plain: 10px;
  --radius-premium: 16px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08);
  --tap: 48px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

h1, h2, h3 { margin: 0 0 8px; font-weight: 700; }
p { margin: 0 0 12px; color: var(--hint); }

.hidden { display: none !important; }

/* ---------- Возрастной фильтр ---------- */
.age-gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.age-gate--hidden { display: none; }
.age-gate__card { max-width: 360px; text-align: center; }
.age-gate__icon { font-size: 56px; margin-bottom: 12px; }
.age-gate__actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }

/* ---------- Кнопки ---------- */
.btn {
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  min-height: var(--tap);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
}
.btn--big { width: 100%; font-size: 16px; }
.btn--primary { background: var(--mint); color: #04231a; }
.btn--primary:active { background: var(--mint-dark); }
.btn--ghost { background: var(--bg-secondary); color: var(--text); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--block { width: 100%; margin-top: 8px; }

/* ---------- Каркас приложения ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.app--hidden { display: none; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: 14px 16px;
  border-bottom: 1px solid var(--bg-secondary);
}
.topbar__title { font-size: 20px; font-weight: 700; }

.view-root {
  flex: 1;
  padding: 16px 16px 96px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.section-title {
  font-size: 13px;
  color: var(--hint);
  margin: 20px 0 10px;
  font-weight: 600;
}
.section-title:first-child { margin-top: 0; }

/* ---------- Карточка магазина (премиум) ---------- */
.shop-card {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--bg-secondary);
  border-radius: var(--radius-premium);
  padding: 12px;
  margin-bottom: 12px;
  overflow: hidden;
  cursor: pointer;
}
.shop-card::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, var(--mint), var(--teal));
}
.shop-card__logo {
  width: 56px; height: 56px; border-radius: 14px; object-fit: cover;
  background: var(--bg); flex-shrink: 0;
}
.shop-card__body { flex: 1; min-width: 0; }
.shop-card__name { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.shop-card__meta { color: var(--hint); font-size: 13px; margin-top: 2px; }

/* ---------- Сетка обычных объявлений: 3 карточки в ряд, одинаковый размер ---------- */
.listing-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.listing-card {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--bg-secondary);
  border-radius: var(--radius-plain);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
}
.listing-card__photo {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: var(--bg-secondary);
}
.listing-card__body { padding: 6px 7px 8px; display: flex; flex-direction: column; gap: 2px; }
.listing-card__model {
  font-weight: 600;
  font-size: 12.5px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  min-height: 2.5em;
}
.listing-card__price { color: var(--mint-dark); font-weight: 700; font-size: 13px; }
.listing-card__meta { color: var(--hint); font-size: 10.5px; }

/* Детальная карточка объявления в модалке */
.listing-detail__photo { width: 100%; border-radius: var(--radius-premium); margin-bottom: 12px; aspect-ratio: 1; object-fit: cover; }

.status-pill {
  display: inline-block;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 100px;
  font-weight: 600;
}
.status-pending { background: rgba(242,169,59,.15); color: var(--amber); }
.status-approved { background: rgba(47,217,168,.15); color: var(--mint-dark); }
.status-rejected, .status-expired { background: rgba(229,72,77,.12); color: var(--danger); }

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--hint);
}
.empty-state__icon { font-size: 40px; margin-bottom: 8px; }

/* ---------- Плавающая кнопка ---------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: 84px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--mint);
  color: #04231a;
  font-size: 28px;
  border: none;
  box-shadow: 0 4px 14px rgba(0,0,0,.2);
  z-index: 20;
  cursor: pointer;
}

/* ---------- Нижняя навигация ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--bg-secondary);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  z-index: 20;
}
.tabbar__item {
  flex: 1;
  background: none; border: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0;
  color: var(--hint);
  font-size: 12px;
  min-height: var(--tap);
}
.tabbar__item.is-active { color: var(--mint-dark); font-weight: 600; }
.tabbar__icon { font-size: 20px; }

/* ---------- Модальное окно ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-backdrop--hidden { display: none; }
.modal {
  position: relative;
  background: var(--bg);
  width: 100%; max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.modal__close {
  position: absolute; right: 14px; top: 14px;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-secondary); border: none; color: var(--text);
  font-size: 16px; cursor: pointer;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; font-weight: 600; }
.field input[type="text"],
.field input[type="number"],
.field textarea {
  width: 100%;
  border: 1px solid var(--bg-secondary);
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 12px;
  min-height: var(--tap);
}
.field textarea { min-height: 80px; resize: vertical; }
.radio-group { display: flex; gap: 10px; }
.radio-pill {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  background: var(--bg-secondary);
  cursor: pointer;
  font-weight: 600;
  border: 2px solid transparent;
}
.radio-pill.is-active { border-color: var(--mint); color: var(--mint-dark); }

.photo-input {
  display: flex; gap: 10px; flex-wrap: wrap;
}
.photo-input__slot {
  width: 84px; height: 84px;
  border-radius: 10px;
  background: var(--bg-secondary);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: var(--hint);
  cursor: pointer;
  overflow: hidden;
  position: relative;
}
.photo-input__slot img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Страница магазина ---------- */
.shop-header {
  display: flex; gap: 14px; align-items: center;
  margin-bottom: 16px;
}
.shop-header__logo {
  width: 72px; height: 72px; border-radius: 18px; object-fit: cover; background: var(--bg-secondary);
}
.shop-header__actions { display: flex; gap: 8px; margin-top: 10px; }
.shop-header__actions .btn { flex: 1; }

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.product-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-plain);
  overflow: hidden;
  cursor: pointer;
}
.product-card__photo { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--bg); }
.product-card__body { padding: 8px 10px; }
.product-card__price { font-weight: 700; color: var(--mint-dark); }
.product-card__desc { font-size: 12px; color: var(--hint); margin: 2px 0 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.out-of-stock { opacity: .5; }
.out-of-stock-badge { color: var(--danger); font-size: 11px; font-weight: 700; }

.carousel { display: flex; gap: 6px; overflow-x: auto; scroll-snap-type: x mandatory; border-radius: var(--radius-premium); margin-bottom: 12px; }
.carousel img { width: 100%; flex: 0 0 100%; aspect-ratio: 1; object-fit: cover; scroll-snap-align: start; }

/* ---------- Профиль ---------- */
.profile-block {
  background: var(--bg-secondary);
  border-radius: var(--radius-plain);
  padding: 14px;
  margin-bottom: 14px;
}

.progress-bar { height: 8px; border-radius: 100px; background: var(--bg); overflow: hidden; margin: 8px 0; }
.progress-bar__fill { height: 100%; background: linear-gradient(90deg, var(--mint), var(--teal)); border-radius: 100px; }
.referral-link-row { display: flex; gap: 6px; margin-top: 10px; }
.referral-link-row input {
  flex: 1; border: 1px solid var(--bg); background: var(--bg); border-radius: 10px; padding: 0 10px;
  min-height: 44px; color: var(--hint); font-size: 13px;
}
.discount-banner {
  background: linear-gradient(135deg, rgba(47,217,168,.18), rgba(31,168,214,.18));
  border-radius: var(--radius-plain);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-weight: 600;
}

.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%);
  background: #1c1c1e; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  z-index: 100; max-width: 90%; text-align: center;
}
.toast--hidden { display: none; }

/* ---------- Desktop ---------- */
@media (min-width: 720px) {
  .view-root { padding-left: 24px; padding-right: 24px; }
  .fab { right: calc(50% - 340px); }
  .product-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 900px) {
  .listing-grid { grid-template-columns: repeat(4, 1fr); }
}
