:root {
  --brand: #1fa463;
  --brand-dark: #178a52;
  --brand-soft: #e6f6ed;
  --ink: #16181d;
  --ink-2: #4a4f5c;
  --muted: #8a909e;
  --line: #e9ebf0;
  --bg: #f4f7f5;
  --card: #ffffff;
  --ok: #0f7a4a;
  --danger: #e5383b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 16px rgba(16, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 72px;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* --- Шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; gap: 16px; height: 64px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 20px; letter-spacing: 0.04em; }
.logo-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 18px;
}
.search { flex: 1; display: flex; gap: 8px; max-width: 680px; min-width: 0; }
.search input {
  flex: 1; min-width: 0; height: 42px; padding: 0 14px; border-radius: 10px;
  border: 2px solid var(--brand); background: #fff; outline: none;
}
.search select { height: 42px; border-radius: 10px; border: 1px solid var(--line); background: #fff; padding: 0 8px; max-width: 170px; }
.nav { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.nav .me-link { display: inline-flex; align-items: center; gap: 6px; max-width: 150px; }
.nav .me-link span { overflow: hidden; text-overflow: ellipsis; }
.nav .avatar { width: 28px; height: 28px; font-size: 12px; }
.nav a.nav-link { padding: 8px 10px; border-radius: 10px; color: var(--ink-2); font-weight: 600; position: relative; white-space: nowrap; }
.nav a.nav-link:hover { background: var(--bg); color: var(--ink); }
.badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; margin-left: 4px;
}

/* --- Кнопки и поля --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; font-weight: 650; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, transform 0.05s, border-color 0.15s;
}
.btn:hover { border-color: #cfd3dc; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 14px; border-radius: 9px; }
.btn-block { width: 100%; }

.field { display: block; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.input, .field input, .field select, .field textarea {
  width: 100%; height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.field textarea { height: auto; min-height: 140px; padding: 12px 14px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.field .err { color: var(--danger); font-size: 13px; margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }

/* --- Категории --- */
.cats { display: flex; gap: 8px; overflow-x: auto; padding: 16px 0 4px; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 18px; background: #fff; border: 1px solid var(--line); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0 16px; }
.filters input[type=number], .filters select { height: 36px; border: 1px solid var(--line); border-radius: 9px; background: #fff; padding: 0 10px; }
.filters input[type=number] { width: 110px; }

/* --- Лента --- */
.feed-head { display: flex; align-items: baseline; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
#total { white-space: nowrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.card { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); position: relative; transition: transform 0.15s, box-shadow 0.15s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(16, 24, 40, 0.1); }
.card-img { aspect-ratio: 4 / 3; background: linear-gradient(135deg, #eef0f4, #e3e6ec); position: relative; }
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.card-img .noimg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 34px; }
.card-img .count { position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 12px; padding: 2px 7px; border-radius: 8px; }
.card-body { padding: 10px 12px 14px; }
.card-price { font-size: 18px; font-weight: 800; }
.card-title { margin: 2px 0 6px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-height: 42px; }
.card-meta { font-size: 13px; color: var(--muted); }
.fav {
  position: absolute; top: 8px; right: 8px; width: 36px; height: 36px; border-radius: 50%;
  border: none; background: rgba(255, 255, 255, 0.92); cursor: pointer; font-size: 18px; display: grid; place-items: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); z-index: 2;
}
.fav.on { color: var(--danger); }
.status-pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 8px; background: var(--bg); color: var(--ink-2); }
.status-pill.active { background: #e7f7ee; color: var(--ok); }
.status-pill.blocked { background: #fdecec; color: var(--danger); }
.status-pill.sold { background: #eef1ff; color: #3b5bdb; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .big { font-size: 46px; margin-bottom: 8px; }
.loader { padding: 60px; text-align: center; color: var(--muted); }

/* --- Карточка объявления --- */
.crumbs { display: flex; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 18px 0 10px; }
.crumbs a:hover { color: var(--brand); }
.listing { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.gallery-main { aspect-ratio: 4 / 3; background: #111; border-radius: var(--radius); overflow: hidden; display: grid; place-items: center; position: relative; }
.gallery-main img { width: 100%; height: 100%; object-fit: contain; }
.gallery-main .noimg { color: #777; font-size: 60px; }
.gallery-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%; border: none; background: rgba(255,255,255,.85); cursor: pointer; font-size: 20px; }
.gallery-nav.prev { left: 12px; } .gallery-nav.next { right: 12px; }
.thumbs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; }
.thumbs img { width: 84px; height: 64px; object-fit: cover; border-radius: 8px; cursor: pointer; opacity: 0.6; border: 2px solid transparent; }
.thumbs img.on { opacity: 1; border-color: var(--brand); }
.side { position: sticky; top: 84px; }
.price-big { font-size: 30px; font-weight: 850; letter-spacing: -0.02em; }
.seller { display: flex; gap: 12px; align-items: center; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: 18px; overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 36px; height: 36px; font-size: 14px; }
.desc { white-space: pre-wrap; word-break: break-word; }
.props { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.props dt { color: var(--muted); }
.props dd { margin: 0; }

/* --- Публикация --- */
.photos-edit { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.photo-tile { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; }
.photo-tile button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: none; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; }
.photo-tile .cover { position: absolute; left: 4px; bottom: 4px; background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.photo-add { aspect-ratio: 1; border-radius: 10px; border: 2px dashed #cfd3dc; display: grid; place-items: center; text-align: center; color: var(--muted); cursor: pointer; font-size: 13px; padding: 8px; }
.photo-add:hover { border-color: var(--brand); color: var(--brand); }

/* --- Чаты --- */
.chats { display: grid; grid-template-columns: 340px 1fr; gap: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; height: calc(100vh - 140px); min-height: 480px; margin-top: 16px; }
.chat-list { border-right: 1px solid var(--line); overflow-y: auto; }
.chat-item { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.chat-item:hover, .chat-item.on { background: var(--bg); }
.chat-item .thumb { width: 52px; height: 52px; border-radius: 10px; background: var(--bg); object-fit: cover; flex: none; }
.chat-item .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .p { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .info { min-width: 0; flex: 1; }
.conv { display: flex; flex-direction: column; min-width: 0; }
.conv-head { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.conv-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; background: #fafbfc; }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 16px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.05); align-self: flex-start; white-space: pre-wrap; word-break: break-word; }
.msg.mine { align-self: flex-end; background: var(--brand); color: #fff; }
.msg .time { font-size: 11px; opacity: 0.65; margin-top: 2px; text-align: right; }
.conv-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.conv-form textarea { flex: 1; resize: none; height: 44px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 22px; outline: none; }

/* --- Профиль / админка --- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0; }
.tab { padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--ink-2); background: #fff; border: 1px solid var(--line); }
.tab.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.list-row { display: flex; gap: 14px; align-items: center; padding: 12px; background: #fff; border-radius: 12px; box-shadow: var(--shadow); }
.list-row + .list-row { margin-top: 10px; }
.list-row .thumb { width: 96px; height: 72px; border-radius: 10px; object-fit: cover; background: var(--bg); flex: none; }
.list-row .info { flex: 1; min-width: 0; }
.list-row .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.stat { background: #fff; border-radius: 12px; padding: 14px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 26px; }
.auth-box { max-width: 420px; margin: 40px auto; }

/* --- Тосты / модалки / нижняя панель --- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; transition: all 0.2s; z-index: 100; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; background: rgba(10, 12, 16, 0.5); display: grid; place-items: center; z-index: 90; padding: 16px; }
.modal-box { background: #fff; border-radius: 16px; padding: 22px; width: 100%; max-width: 440px; max-height: 90vh; overflow: auto; }
.tabbar { display: none; }

@media (max-width: 1180px) {
  .search .btn { display: none; }
  .nav a.nav-link.opt { display: none; }
}
@media (max-width: 900px) {
  .listing { grid-template-columns: 1fr; }
  .side { position: static; }
  .chats { grid-template-columns: 1fr; }
  .chats.has-conv .chat-list { display: none; }
  .chats:not(.has-conv) .conv { display: none; }
}
@media (max-width: 720px) {
  body { font-size: 15px; }
  .topbar-row { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .search { order: 3; max-width: none; width: 100%; flex-basis: 100%; }
  .search select { max-width: 120px; }
  .search .btn { display: none; }
  .nav { display: none; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card-price { font-size: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff;
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); font-weight: 600; gap: 2px; position: relative; }
  .tabbar a .i { font-size: 20px; }
  .tabbar a.on { color: var(--brand); }
  .tabbar .badge { position: absolute; top: -2px; right: 22%; }
  .chats { height: calc(100vh - 190px); }
  .props { grid-template-columns: 110px 1fr; }
}

/* Согласие при регистрации и подвал */
.consent { align-items: flex-start; font-size: 14px; line-height: 1.4; }
.consent input { margin-top: 3px; flex: none; }
.small { font-size: 13px; line-height: 1.45; }
.site-footer { text-align: center; font-size: 13px; color: #8a8f98; padding: 24px 16px 96px; }
.site-footer a { color: inherit; margin: 0 8px; }

.linklike { background: none; border: 0; padding: 8px 0 0; cursor: pointer; text-decoration: underline; align-self: flex-start; }
.linklike:hover { color: #c0392b; }
