:root {
  --bg: #ffffff;
  --bg-soft: #f4f4f6;
  --surface: #ffffff;
  --text: #142846;
  --text-2: #6b6e76;
  --line: #e6e7ea;
  --accent: #ff745c;
  --accent-ink: #142846;
  --accent-soft: #fff1ec;
  --brand-navy: #142846;
  --brand-mint: #4ce0b4;
  --ok: #14a35a;
  --fav: #ff3b5c;
  --shadow: 0 6px 24px rgba(20, 22, 30, .08);
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121316; --bg-soft: #1c1d22; --surface: #1a1b20; --text: #f2f2f4; --text-2: #9a9ca4;
    --line: #2a2c33; --accent-soft: #3a2117; --shadow: 0 6px 24px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121316; --bg-soft: #1c1d22; --surface: #1a1b20; --text: #f2f2f4; --text-2: #9a9ca4;
  --line: #2a2c33; --accent-soft: #3a2117; --shadow: 0 6px 24px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* страница никогда не шире экрана — иначе на телефоне её «водит» вбок при прокрутке */
html, body { overflow-x: clip; max-width: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; color: var(--text); }
/* iPhone увеличивает страницу при фокусе на поле со шрифтом меньше 16px и не возвращает масштаб */
@media (max-width: 899px) { input, textarea, select { font-size: 16px; } }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
img { display: block; }
main { max-width: 1200px; margin: 0 auto; padding: 0 16px 24px; outline: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; max-width: 1200px; margin: 0 auto;
}
.topbar.hidden-mobile { display: none; }
.logo { display: flex; align-items: center; gap: 8px; font-size: 21px; letter-spacing: -.01em; flex-shrink: 0; }
.logo-mark { width: 34px; height: 34px; flex-shrink: 0; }
.logo-text { font-weight: 500; }
.logo-text b { font-weight: 800; }
.logo-text { color: var(--accent); }
.logo-text b { color: var(--text); }
.logo-text { display: none; }
.search { flex: 1; min-width: 0; position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-2); }
.search input {
  width: 100%; height: 42px; border-radius: 12px; border: 1.5px solid transparent; background: var(--bg-soft);
  padding: 0 12px 0 38px; outline: none; transition: border-color .15s;
}
.search input:focus { border-color: var(--accent); background: var(--surface); }
.city-btn { display: none; color: var(--text-2); white-space: nowrap; }
.desk-nav { display: none; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--text-2); }
.tabbar a.active { color: var(--text); }
.tabbar a.active svg { stroke-width: 2.2; }
.tabbar a[data-tab="fav"].active svg { fill: var(--fav); stroke: var(--fav); }
.tab-new svg { background: var(--accent); color: var(--accent-ink); border-radius: 10px; width: 34px; height: 28px; padding: 4px 9px; stroke-width: 2.4; }
.badge { position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--fav); color: #fff; font: 600 11px/18px sans-serif; font-style: normal; text-align: center; }

/* ---------- buttons, chips ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 18px; border-radius: 12px; font-weight: 600; background: var(--bg-soft); transition: transform .1s, opacity .15s; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; margin: 0 -16px; padding: 4px 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; height: 36px; padding: 0 14px; border-radius: 18px; background: var(--bg-soft); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 14px; }
.chip.on { background: var(--text); color: var(--bg); }
.chip svg { width: 16px; height: 16px; }

/* ---------- home ---------- */
.cats { display: grid; grid-auto-flow: column; grid-auto-columns: 92px; gap: 8px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; margin: 4px -16px 18px; padding: 0 16px; }
.cats::-webkit-scrollbar { display: none; }
.cat { height: 92px; border-radius: var(--radius); background: var(--bg-soft); padding: 10px; display: flex; flex-direction: column; justify-content: space-between; font-size: 12.5px; font-weight: 600; line-height: 1.15; position: relative; overflow: hidden; }
.cat .ico { font-size: 30px; align-self: flex-end; line-height: 1; }
.cat.on { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.promo { border-radius: 18px; padding: 18px; margin: 0 0 18px; background: var(--brand-navy); color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.promo h2 { font-size: 19px; margin-bottom: 4px; }
.promo p { margin: 0; opacity: .9; font-size: 13.5px; }
.promo .btn { background: var(--accent); color: var(--brand-navy); flex-shrink: 0; height: 40px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 6px 0 12px; }
.section-head h1, .section-head h2 { font-size: 20px; letter-spacing: -.01em; }
.section-head .muted { white-space: nowrap; }
.section-head .muted { font-size: 13px; }
.muted { color: var(--text-2); }
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 10px; }
.card { position: relative; min-width: 0; }
.card .ph { aspect-ratio: 1 / 1; border-radius: 12px; overflow: hidden; background: var(--bg-soft); position: relative; }
.card .ph img { width: 100%; height: 100%; object-fit: cover; }
.card .t { margin-top: 8px; font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .p { font-weight: 700; font-size: 16px; margin-top: 3px; }
.card .m { font-size: 12.5px; color: var(--text-2); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .tagline { position: absolute; left: 8px; bottom: 8px; display: flex; gap: 4px; }
.pill { font-size: 11px; font-weight: 600; padding: 3px 7px; border-radius: 6px; background: rgba(255, 255, 255, .92); color: #16171a; }
.pill.new { background: var(--ok); color: #fff; }
.fav-btn { position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; filter: drop-shadow(0 1px 3px rgba(0,0,0,.45)); }
.fav-btn.on svg { fill: var(--fav); stroke: var(--fav); }
.fallback { width: 100%; height: 100%; display: grid; place-items: center; font-size: 56px; background: linear-gradient(135deg, var(--bg-soft), var(--line)); }

.empty { text-align: center; padding: 56px 20px; color: var(--text-2); }
.empty .big { font-size: 52px; margin-bottom: 12px; }
.empty h2 { color: var(--text); font-size: 19px; margin-bottom: 6px; }
.empty .btn { margin-top: 18px; }

/* ---------- item page ---------- */
.item { display: grid; gap: 18px; }
.gallery { position: relative; margin: 0 -16px; }
.gallery-track { display: flex; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scrollbar-width: none; }
.gallery-track::-webkit-scrollbar { display: none; }
.gallery-track > * { flex: 0 0 100%; aspect-ratio: 4 / 3; scroll-snap-align: start; background: var(--bg-soft); }
.gallery-track img { width: 100%; height: 100%; object-fit: cover; }
.dots { position: absolute; bottom: 10px; left: 0; right: 0; display: flex; justify-content: center; gap: 5px; }
.dots i { width: 6px; height: 6px; border-radius: 3px; background: rgba(255,255,255,.55); transition: width .2s; }
.dots i.on { width: 16px; background: #fff; }
.g-btn { position: absolute; top: calc(10px + env(safe-area-inset-top)); width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.92); color: #16171a; display: grid; place-items: center; box-shadow: var(--shadow); }
.g-back { left: 14px; } .g-share { right: 60px; } .g-fav { right: 14px; }
.g-fav.on svg { fill: var(--fav); stroke: var(--fav); }
.item-price { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.item-title { font-size: 19px; font-weight: 500; margin-top: 4px; }
.item-meta { font-size: 13px; color: var(--text-2); margin-top: 8px; display: flex; gap: 12px; flex-wrap: wrap; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel h3 { font-size: 17px; margin-bottom: 10px; }
.params { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14.5px; }
.params dt { color: var(--text-2); }
.params dd { margin: 0; }
.desc { white-space: pre-wrap; margin: 0; }
.seller { display: flex; align-items: center; gap: 12px; }
.avatar { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 19px; color: #fff; flex-shrink: 0; }
.seller .name { font-weight: 600; }
.stars { color: #f5a623; letter-spacing: 1px; }
.contact-bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.sticky-contact { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); z-index: 25; }
.sticky-contact .btn { box-shadow: var(--shadow); }
.item-page { padding-bottom: 64px; }
.side { display: grid; gap: 12px; align-content: start; }
.safe-note { font-size: 13px; color: var(--text-2); display: flex; gap: 10px; }

/* ---------- form ---------- */
.form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; max-width: 640px; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: 14px; }
.field input:not([type=radio]):not([type=checkbox]):not([type=file]), .field textarea, .field select {
  width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; outline: none;
}
.field input:not([type=radio]):not([type=checkbox]):focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field textarea { min-height: 120px; resize: vertical; }
.field .hint { font-size: 12.5px; color: var(--text-2); }
.field.err input:not([type=radio]), .field.err textarea, .field.err select { border-color: var(--fav); }
.price-wrap { position: relative; }
.price-wrap::after { content: '₽'; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--text-2); }
.photos { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.photos > * { aspect-ratio: 1; border-radius: 12px; overflow: hidden; position: relative; background: var(--bg-soft); }
.photos img { width: 100%; height: 100%; object-fit: cover; }
.photos .add { display: grid; place-items: center; border: 1.5px dashed var(--line); color: var(--text-2); font-size: 12px; text-align: center; }
.photos .add svg { width: 26px; height: 26px; margin: 0 auto 2px; display: block; }
.photos .rm { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; }
.photos .rm svg { width: 14px; height: 14px; }
.cat-pick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.cat-pick label { position: relative; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 12px 10px; border-radius: 12px; background: var(--bg-soft); cursor: pointer; font-size: 14px; border: 1.5px solid transparent; overflow-wrap: anywhere; }
.cat-pick input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.cat-pick label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.cat-pick .e { font-size: 22px; }

/* ---------- chats ---------- */
.chat-list { display: grid; }
.chat-row { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: center; }
.chat-row img, .chat-row .fallback { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; flex-shrink: 0; font-size: 26px; }
.chat-row .body { min-width: 0; flex: 1; }
.chat-row .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--text-2); }
.chat-row .who { font-weight: 600; color: var(--text); }
.chat-row .ttl { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row .last { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-row .unread { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }

.chat { display: flex; flex-direction: column; height: calc(100dvh - var(--tabbar-h) - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 8px); padding-top: env(safe-area-inset-top); max-width: 760px; margin: 0 auto; }
.chat-top { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); }
.chat-top .chat-head { flex: 1; min-width: 0; border-bottom: 0; }
.chat-back { width: 36px; height: 44px; display: grid; place-items: center; margin-left: -8px; flex-shrink: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 0 12px; border-bottom: 1px solid var(--line); }
.chat-head img, .chat-head .fallback { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; font-size: 22px; }
.chat-head .body { min-width: 0; flex: 1; }
.chat-head .ttl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-head .pr { font-weight: 700; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 0; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 78%; padding: 9px 12px; border-radius: 16px; background: var(--bg-soft); align-self: flex-start; white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; }
.msg:not(.me) { border-bottom-left-radius: 5px; }
.msg time { display: block; font-size: 11px; opacity: .65; margin-top: 2px; text-align: right; }
.day-sep { align-self: center; font-size: 12px; color: var(--text-2); margin: 6px 0; }
.typing { align-self: flex-start; color: var(--text-2); font-size: 13px; padding: 4px 2px; }
.quick { display: flex; gap: 6px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; padding-bottom: 8px; }
.quick::-webkit-scrollbar { display: none; }
.quick button { flex-shrink: 0; padding: 7px 12px; border-radius: 16px; border: 1px solid var(--line); font-size: 13.5px; }
.composer { display: flex; gap: 8px; padding: 8px 0 4px; }
.composer input { flex: 1; min-width: 0; height: 44px; border-radius: 22px; border: 1.5px solid var(--line); background: var(--surface); padding: 0 16px; outline: none; }
.composer input:focus { border-color: var(--accent); }
.composer button { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex-shrink: 0; }

/* ---------- profile ---------- */
.profile-head { display: flex; align-items: center; gap: 14px; margin: 8px 0 18px; }
.profile-head .avatar { width: 64px; height: 64px; font-size: 26px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 18px; }
.stat { background: var(--bg-soft); border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12.5px; color: var(--text-2); }
.my-ad { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: center; }
.my-ad .thumb { width: 72px; height: 72px; border-radius: 12px; overflow: hidden; flex-shrink: 0; background: var(--bg-soft); }
.my-ad .thumb img { width: 100%; height: 100%; object-fit: cover; }
.my-ad .body { flex: 1; min-width: 0; }
.my-ad .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.my-ad .actions { display: flex; gap: 6px; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; background: var(--bg-soft); display: grid; place-items: center; }
.icon-btn svg { width: 18px; height: 18px; }
.menu-list { display: grid; margin-top: 18px; border-top: 1px solid var(--line); }
.menu-list button, .menu-list a { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); text-align: left; }

/* ---------- sheet & toast ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 86dvh; overflow-y: auto; animation: up .25s ease-out;
}
.sheet::before { content: ''; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { font-size: 20px; margin-bottom: 14px; }
.sheet .opts { display: grid; gap: 2px; margin-bottom: 16px; }
.sheet .opt { display: flex; justify-content: space-between; align-items: center; padding: 13px 0; border-bottom: 1px solid var(--line); text-align: left; width: 100%; }
.sheet .opt.on::after { content: '✓'; color: var(--accent); font-weight: 700; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 72px); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); margin: 4px 0 10px; }
.back-link svg { width: 18px; height: 18px; }

/* ---------- wider screens ---------- */
@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cat-pick { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .photos { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tabbar { display: none; }
  .logo-text, .city-btn { display: inline; }
  .desk-nav { display: flex; align-items: center; gap: 18px; font-size: 14px; flex-shrink: 0; }
  .desk-nav a:not(.btn):hover { color: var(--accent); }
  .desk-nav .btn { height: 42px; }
  .topbar { padding: 14px 24px; gap: 18px; }
  .topbar.hidden-mobile { display: flex; }
  main { padding: 0 24px 48px; }
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px 16px; }
  .cats { grid-auto-flow: row; grid-template-columns: repeat(10, 1fr); grid-auto-columns: auto; margin: 4px 0 22px; padding: 0; overflow: visible; }
  .chips { margin: 0; padding: 4px 0; }
  .item { grid-template-columns: minmax(0, 1fr) 360px; gap: 28px; align-items: start; }
  .gallery { margin: 0; border-radius: 18px; overflow: hidden; }
  .g-btn.g-back { display: none; }
  .side { position: sticky; top: 84px; }
  .sticky-contact { position: static; }
  .sticky-contact .btn { box-shadow: none; }
  .item-page { padding-bottom: 0; }
  .section-head h1, .section-head h2 { font-size: 24px; }
  .chat-back { display: none; }
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: 440px; border-radius: 20px; animation: fade .2s; }
  .sheet::before { display: none; }
  .chat { height: calc(100dvh - 120px); }
  .toast { bottom: 24px; }
}
@media (min-width: 1200px) {
  .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
