:root {
  /* Telegram injects --tg-theme-* on <html>; the fallbacks are for a plain browser in DEV_MODE */
  --bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  /* plain colours for WebViews without color-mix(); the mixed ones replace them in @supports below */
  --separator: rgba(142,142,147,.25);
  --field: rgba(142,142,147,.12);
  --green: #31b545;
  --green-strong: #1f8f35; /* behind white text: the brand green is too light for it */
  --warn: #a86500;         /* orange text readable on light backgrounds */
  --red: #e5484d;
  --radius: 14px;
  --glass-bg: var(--card);
  --glass-edge: rgba(255,255,255,.16);
  --spring: cubic-bezier(.25,.9,.3,1.05);
  --nav-h: 64px;
}
/* A custom property accepts any value, so an unsupported color-mix() would still override a fallback line
   written before it and leave var() empty; gating it is the only way the fallback survives */
@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root {
    --separator: color-mix(in srgb, var(--hint) 25%, transparent);
    --field: color-mix(in srgb, var(--hint) 12%, var(--card));
    --glass-bg: color-mix(in srgb, var(--card) 58%, transparent);
    --glass-edge: color-mix(in srgb, #ffffff 16%, transparent);
  }
}
:root.dark { --warn: #d48806; } /* Telegram dark theme, set from tg.colorScheme in app.js */

@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #000000; --card: #1c1c1e; --text: #ffffff; --hint: #8e8e93;
    --link: #3e9be9; --accent: #3e9be9; --warn: #d48806;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* --- header & tabs --- */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  box-shadow: inset 0 0 0 .5px var(--glass-edge), inset 0 1px 0 var(--glass-edge), 0 8px 28px rgba(0,0,0,.22);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass, .top { background: var(--card) !important; }
}

.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5; height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(22px) saturate(180%); backdrop-filter: blur(22px) saturate(180%);
}
.top h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.3px; white-space: nowrap; }
.top-tools { display: flex; align-items: center; gap: 8px; }
.filter-btn { position: relative; }
.filter-dot { position: absolute; top: 7px; right: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--red); border: 2px solid var(--card); }

#pager { position: fixed; inset: 0; overflow: hidden; }
#track { display: flex; width: 400%; height: 100%; transition: transform .34s var(--spring); will-change: transform; }
.page {
  width: 25%; height: 100%; overflow-y: auto; overflow-x: hidden; overscroll-behavior-y: contain; touch-action: pan-y;
  padding: calc(64px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 84px + env(safe-area-inset-bottom));
}

.nav {
  position: fixed; left: 14px; right: 14px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 6;
  height: var(--nav-h); padding: 4px; border-radius: 32px;
  display: grid; grid-template-columns: repeat(4, 1fr); transition: transform .25s var(--spring), opacity .2s;
}
.nav button {
  position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 600; color: var(--hint); transition: color .2s, transform .15s;
}
.nav button:active { transform: scale(.92); }
.nav button.active { color: var(--accent); }
.nav-blob {
  position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc((100% - 8px) / 4); border-radius: 28px;
  background: color-mix(in srgb, var(--hint) 20%, transparent);
  box-shadow: inset 0 0 0 .5px var(--glass-edge), inset 0 1px 0 var(--glass-edge);
  transform: translateX(calc(var(--pos, 0) * 100%));
  transition: transform .36s var(--spring);
}
.nav.dragging .nav-blob { transition: none; transform: translateX(calc(var(--pos, 0) * 100%)) scale(1.05, .95); }
body.typing .nav { transform: translateY(140%); opacity: 0; pointer-events: none; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); z-index: 6;
  display: flex; align-items: center; gap: 6px; height: 46px; padding: 0 18px 0 14px; border-radius: 23px;
  font-weight: 600; color: var(--accent); transition: transform .15s;
}
.fab:active { transform: scale(.94); }
body.typing .fab { display: none; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--card); color: var(--accent);
}

.segmented {
  position: relative; display: grid; grid-template-columns: repeat(var(--segs, 2), 1fr);
  background: var(--field); border-radius: 12px; padding: 3px; margin-bottom: 12px;
}
.segmented button {
  position: relative; z-index: 1; padding: 9px 0; font-weight: 600; color: var(--hint);
  border-radius: 9px; transition: color .2s;
}
.segmented button.active { color: var(--text); }
.seg-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / var(--segs, 2));
  background: var(--card); border-radius: 9px; box-shadow: 0 1px 4px rgba(0,0,0,.12);
  transition: transform .25s cubic-bezier(.3,.7,.4,1);
}
.segmented[data-active="1"] .seg-thumb { transform: translateX(100%); }

/* --- filters --- */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  position: relative; flex: none; padding: 6px 12px; border-radius: 16px; font-weight: 600; font-size: 14px;
  background: var(--card); color: var(--text);
}
.chip::before { content: ""; position: absolute; inset: -3px 0; } /* a 37 px tall tap area; the 6 px gaps between rows stay free */
.chip.active { background: var(--accent); color: var(--accent-text); }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.method-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0; }
.filter-reset { margin-top: 8px; }
.fiat-select select {
  appearance: none; -webkit-appearance: none; border: 0; outline: 0;
  font: inherit; font-weight: 600; font-size: 14px; color: var(--accent);
  background: var(--card); padding: 6px 26px 6px 12px; border-radius: 16px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* --- feed --- */
.feed { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff;
  position: relative; overflow: hidden;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ava-wrap { position: relative; flex: none; }
.ava-dot {
  display: none; position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--card);
}
.ava-wrap.online .ava-dot { display: block; }
.prof-head .ava-dot { width: 14px; height: 14px; border-color: var(--bg); right: 1px; bottom: 1px; }
.author-col { min-width: 0; flex: 1; }
.author-seen { font-size: 12px; color: var(--hint); line-height: 1.2; min-height: 14px; }
.author-seen.online { color: var(--green); }
.author { font-weight: 600; display: flex; align-items: center; gap: 4px; min-width: 0; }
.author span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-verified { color: var(--accent); flex: none; }
.author-meta { margin-left: auto; font-size: 13px; font-weight: 600; flex: none; }
.rep-new { color: var(--hint); font-weight: 500; }
.rep-share { color: var(--green); }
.rep-bad { color: var(--red); white-space: nowrap; }
.updated { margin-top: 2px; font-size: 12px; color: var(--hint); }
.ban-kinds { margin-bottom: 10px; }
.btn.ghost.danger-text, .danger-text { color: var(--red); }
.wiz-option:disabled, .chip:disabled { opacity: .55; }
.price { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.price small { font-size: 15px; font-weight: 600; color: var(--hint); }
.row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; margin-top: 4px; }
.row .k { color: var(--hint); flex: none; }
.row .v { text-align: right; overflow: hidden; text-overflow: ellipsis; }
.card-foot { display: flex; align-items: flex-end; gap: 12px; margin-top: 10px; }
.methods { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.method { font-size: 12px; padding: 3px 8px; border-radius: 6px; background: var(--field); color: var(--text); }
.mine-tag { font-size: 12px; color: var(--hint); }
.mine-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--separator); }
.mine-actions .btn { padding: 8px 12px; font-size: 14px; }
.mine-actions .btn.danger { margin-left: auto; padding: 8px 0; }
.paused-tag { display: inline-block; margin-bottom: 8px; padding: 3px 9px; border-radius: 9px; background: var(--field); color: var(--hint); font-size: 12px; font-weight: 600; }
.price-warn { margin-top: 6px; padding: 7px 10px; border-radius: 10px; background: color-mix(in srgb, #f5a623 16%, transparent); font-size: 13px; }

/* --- ad wizard --- */
.wiz-progress { position: relative; display: flex; justify-content: space-between; margin: 12px 0 18px; }
.wiz-progress::before, .wiz-progress::after { content: ""; position: absolute; top: 12px; left: 12.5%; height: 2px; border-radius: 1px; }
.wiz-progress::before { right: 12.5%; background: var(--separator); }
.wiz-progress::after { width: calc(75% * var(--wiz, 0)); background: var(--accent); transition: width .3s var(--spring); }
.wiz-mark { position: relative; z-index: 1; width: 25%; text-align: center; font-size: 12px; color: var(--hint); }
.wiz-mark i { display: grid; place-items: center; width: 26px; height: 26px; margin: 0 auto 4px; border-radius: 50%; background: var(--field); font-style: normal; font-weight: 700; font-size: 13px; }
.wiz-mark.now { color: var(--text); font-weight: 600; }
.wiz-mark.now i, .wiz-mark.done i { background: var(--accent); color: var(--accent-text); }
.wiz-step { animation: wiz-in .24s var(--spring); }
@keyframes wiz-in { from { transform: translateX(14px); opacity: 0; } }
.wiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.wiz-option { display: flex; flex-direction: column; gap: 4px; padding: 14px; border-radius: var(--radius); background: var(--card); text-align: left; box-shadow: inset 0 0 0 1.5px transparent; transition: box-shadow .15s, transform .1s; }
.wiz-option:active { transform: scale(.98); }
.wiz-option.active { box-shadow: inset 0 0 0 1.5px var(--accent); }
.wiz-option-title { font-weight: 700; }
.wiz-option-text { color: var(--hint); font-size: 13px; }
.wiz-price { font-size: 24px; font-weight: 700; }
.wiz-market { min-height: 18px; margin: -4px 4px 12px; color: var(--hint); font-size: 13px; }
.wiz-market.warn { color: var(--warn); }
.wiz-preview { pointer-events: none; }
.wiz-nav { display: flex; gap: 8px; }
.wiz-nav .btn { flex: 1; padding: 14px; font-size: 16px; border-radius: 12px; }
.wiz-nav .btn.ghost { flex: 0 0 34%; }

.btn {
  padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 15px;
  background: var(--accent); color: var(--accent-text); transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.buy { background: var(--green-strong); color: #fff; }
.btn.sell { background: var(--red); color: #fff; }
.btn.ghost { background: var(--field); color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); padding: 8px 0; }
.btn.block { width: 100%; padding: 14px; font-size: 16px; border-radius: 12px; }
.plans { display: flex; flex-direction: column; gap: 8px; }
#homeScreenBox:not(:empty) { margin-top: 8px; }
.btn.plan { display: flex; justify-content: space-between; width: 100%; padding: 14px; font-size: 16px; border-radius: 12px; }

.empty { text-align: center; color: var(--hint); padding: 40px 16px; }
.empty .art { display: block; margin: 0 auto 12px; animation: float 4.5s ease-in-out infinite; }
.empty-title { color: var(--text); font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.empty-text { font-size: 14px; }
.empty .btn { margin-top: 14px; }
@keyframes float { 50% { transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { .empty .art, .sk { animation: none !important; } }

.sk {
  background: linear-gradient(100deg, var(--field) 30%, color-mix(in srgb, var(--hint) 26%, var(--field)) 50%, var(--field) 70%);
  background-size: 220% 100%; animation: shimmer 1.3s linear infinite; border-radius: 8px;
}
@keyframes shimmer { from { background-position: 130% 0; } to { background-position: -90% 0; } }
.sk-ava { width: 32px; height: 32px; border-radius: 50%; flex: none; }
.sk-line { height: 12px; margin-top: 8px; }
.card-head .sk-line { margin-top: 0; }
.sk-line.big { height: 22px; margin-bottom: 12px; }
.sk-foot { display: flex; align-items: center; gap: 6px; margin-top: 14px; }
.sk-chip { width: 58px; height: 26px; border-radius: 13px; }
.sk-btn { width: 84px; height: 40px; border-radius: 10px; margin-left: auto; }
.sk-row { display: flex; gap: 12px; align-items: center; padding: 10px 14px; }
.sk-row .sk-ava { width: 46px; height: 46px; }
.sk-row > div:last-child { flex: 1; }
.sk-bubble { height: 40px; border-radius: 16px; margin: 4px 0; }
.feed-more { margin-top: 0; }

/* --- bottom sheet --- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 10; animation: fade .2s;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  /* Telegram's own viewport height is right with its header and keyboard; vh is the last resort */
  max-height: 88vh;
  max-height: calc(var(--tg-viewport-height, 100vh) * .88);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .28s cubic-bezier(.3,.7,.4,1);
}
@supports (height: 100dvh) {
  .sheet { max-height: calc(var(--tg-viewport-height, 100dvh) * .88); }
}
.sheet-handle { width: 36px; height: 5px; border-radius: 3px; background: var(--separator); margin: 0 auto 12px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.sheet h2 { margin: 4px 0 6px; font-size: 20px; }
.sheet .lead { color: var(--hint); margin: 0 0 16px; }
.section { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.prof-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.prof-head .avatar { width: 52px; height: 52px; font-size: 22px; }
.prof-text { min-width: 0; }
.prof-name { display: flex; align-items: center; gap: 5px; font-size: 19px; font-weight: 700; }
.prof-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prof-sub { color: var(--hint); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--separator); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.stat { background: var(--card); padding: 12px 6px; text-align: center; min-width: 0; }
.stat b { display: block; font-size: 19px; }
.stat span { display: block; color: var(--hint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.stats-placeholder { height: 68px; margin-bottom: 12px; border-radius: var(--radius); }
.reviews { background: var(--card); border-radius: var(--radius); margin-bottom: 10px; }
.review { padding: 12px 14px; border-bottom: 1px solid var(--separator); }
.review:last-child { border-bottom: 0; }
.review-head { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.review-author { font-weight: 600; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-date { margin-left: auto; color: var(--hint); font-size: 12px; flex: none; }
.review-text { margin-top: 4px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.review .btn.danger { position: relative; font-size: 13px; padding: 6px 0 0; }
.review .btn.danger::before { content: ""; position: absolute; inset: -8px -10px; } /* about 40 px to tap, inside the review's padding */
.card-head[data-profile], .msg-sender[data-profile], #convPeer { cursor: pointer; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .3px; color: var(--hint); margin: 16px 4px 6px; }

.steps { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.step { display: flex; gap: 12px; background: var(--card); border-radius: var(--radius); padding: 14px; }
.step-num {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; background: var(--field); color: var(--hint);
}
.step.current .step-num { background: var(--accent); color: var(--accent-text); }
.step.done .step-num { background: var(--green-strong); color: #fff; }
.step-content { flex: 1; min-width: 0; }
.step-content b { display: block; margin-bottom: 2px; }
.step-content p { margin: 0 0 10px; color: var(--hint); font-size: 14px; }
.step-content p:last-child { margin-bottom: 0; }
.step-content ol { margin: 0 0 10px; padding-left: 18px; color: var(--hint); font-size: 14px; }
.step-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.status-pill { display: inline-block; font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 10px; }
.status-pill.ok { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.status-pill.wait { background: color-mix(in srgb, #f5a623 20%, transparent); color: var(--warn); }
.status-pill.no { background: var(--field); color: var(--hint); }

/* --- forms --- */
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 13px; color: var(--hint); margin: 0 4px 4px; }
.input, .field select, .field textarea {
  width: 100%; border: 0; outline: 0; border-radius: 12px; padding: 12px 14px;
  font: inherit; color: var(--text); background: var(--card);
  appearance: none; -webkit-appearance: none;
}
.field textarea { resize: none; min-height: 72px; }
.input:focus, .field select:focus, .field textarea:focus { box-shadow: inset 0 0 0 1.5px var(--accent); }
.step .input { background: var(--field); margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.side-switch { margin-bottom: 14px; }
.form-error { color: var(--danger); font-size: 14px; margin: 4px 4px 10px; min-height: 1em; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); z-index: 20;
  background: rgba(30,30,30,.92); color: #fff; padding: 12px 14px; border-radius: 12px;
  font-size: 14px; text-align: center; animation: fade .2s;
}

.kyc-list { margin: 4px 0 10px; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.fine { font-size: 12px !important; }
.notice {
  font-size: 14px; padding: 12px 14px; border-radius: 12px;
  background: color-mix(in srgb, #f5a623 16%, var(--card)); color: var(--text);
}

/* --- tabs badge --- */
.tab-badge {
  position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

/* --- chat list --- */
.chat-search { display: flex; gap: 8px; margin-bottom: 12px; }
#chatsSeg button { display: flex; align-items: center; justify-content: center; gap: 5px; }
.seg-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; line-height: 18px; }
.deal-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.deals-more { margin-top: 10px; }
.deal-state { flex: none; font-size: 14px; margin-top: 2px; color: var(--hint); }
.deal-state.action { color: var(--accent); font-weight: 600; }
/* a long ad title gives way at 375 px instead of pushing the row wider */
.deal-title { margin-left: auto; font-size: 13px; color: var(--hint); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal-state.ok { color: var(--green); }
.deal-state.wait { color: var(--warn); }
.chat-search .input { flex: 1; min-width: 0; }
.chat-list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.chat-list:has(.empty) { background: none; }
.chat-row {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--separator);
}
.chat-row:last-child { border-bottom: 0; }
.chat-row:active { background: var(--field); }
.chat-row .avatar { width: 46px; height: 46px; font-size: 18px; }
.chat-row-main { flex: 1; min-width: 0; }
.chat-row-top, .chat-row-bottom { display: flex; align-items: center; gap: 4px; }
.chat-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { margin-left: auto; color: var(--hint); font-size: 13px; display: flex; align-items: center; gap: 3px; flex: none; }
.chat-preview { color: var(--hint); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; margin-top: 2px; }
.chat-preview b { color: var(--text); font-weight: 500; }
.typing-now { color: var(--accent); }
.typing-dots i {
  display: inline-block; width: 3px; height: 3px; margin-left: 2px; border-radius: 50%; background: currentColor;
  vertical-align: 2px; animation: dots 1.1s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dots { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }
.unread {
  flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--accent); color: var(--accent-text); font-size: 13px; font-weight: 700; line-height: 22px; text-align: center;
}

/* --- conversation --- */
.conv {
  position: fixed; inset: 0; z-index: 8; overflow: hidden;
  background: var(--bg);
  animation: slide-in .24s var(--spring);
}
.conv::before {
  content: ""; position: absolute; inset: 0; background: var(--accent); opacity: .07; pointer-events: none;
  will-change: transform; contain: strict;
  --doodle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='32' cy='34' r='14'/%3E%3Cpath d='M25 28h14M32 28v13'/%3E%3Cpath d='M92 18h26a7 7 0 017 7v12a7 7 0 01-7 7h-16l-9 8v-8a7 7 0 01-8-7V25a7 7 0 017-7z'/%3E%3Cpath d='M150 62l7 14 15 2-11 11 3 15-14-7-14 7 3-15-11-11 15-2z'/%3E%3Cpath d='M18 92l14-14 14 14M32 78v30'/%3E%3Crect x='70' y='88' width='44' height='28' rx='6'/%3E%3Cpath d='M70 98h44'/%3E%3Cpath d='M142 136l-14 14-14-14M128 150v-30'/%3E%3Ccircle cx='54' cy='150' r='14'/%3E%3Cpath d='M47 144h14M54 144v13'/%3E%3C/svg%3E");
  -webkit-mask: var(--doodle) 0 0 / 180px; mask: var(--doodle) 0 0 / 180px;
}
@keyframes slide-in { from { transform: translateX(30%); opacity: 0; } }
.conv-head {
  position: absolute; top: calc(6px + env(safe-area-inset-top)); left: 8px; right: 8px; z-index: 3;
  display: flex; align-items: center; gap: 6px; padding: 5px 6px 5px 4px; border-radius: 26px; min-height: 52px;
}
body.tg #convBack { display: none; } /* Telegram's own Back button is used instead */
body.tg .conv-head { padding-left: 10px; }
.icon-btn.plain { background: none; color: var(--accent); }
.conv-peer { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.conv-peer .avatar { width: 38px; height: 38px; }
.conv-peer-text { min-width: 0; }
.conv-peer-name { font-weight: 600; display: flex; align-items: center; gap: 4px; }
.conv-peer-sub { font-size: 13px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-peer-sub.is-online, .conv-peer-sub.is-typing { color: var(--accent); }

.conv-body {
  position: absolute; inset: 0; z-index: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; touch-action: pan-y;
  padding: calc(68px + env(safe-area-inset-top)) 10px calc(var(--conv-bottom, 64px) + 8px);
  display: flex; flex-direction: column;
}
.conv-bottom { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; flex-direction: column; gap: 6px; padding: 0 8px; }
.conv-loading { text-align: center; color: var(--hint); padding: 12px; font-size: 14px; }
.conv-empty { margin: auto; text-align: center; color: var(--hint); padding: 24px; }
.conv-empty .empty { padding: 0 8px; }
.conv-empty small { display: block; margin-top: 8px; font-size: 12px; }
.sk-bubbles { display: flex; flex-direction: column; margin-top: auto; }
.day-sep { text-align: center; margin: 12px 0 6px; position: sticky; top: calc(4px + env(safe-area-inset-top)); z-index: 2; pointer-events: none; }
.day-sep span {
  font-size: 13px; color: var(--text); padding: 3px 11px; border-radius: 12px;
  background: var(--glass-bg); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.unread-sep { text-align: center; font-size: 13px; color: var(--accent); margin: 10px -10px 4px; padding: 3px 0; background: color-mix(in srgb, var(--accent) 12%, transparent); }

.conv-down {
  position: absolute; right: 12px; bottom: calc(var(--conv-bottom, 64px) + 10px); z-index: 3;
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: var(--text);
  animation: pop .2s var(--spring);
}
.conv-down-badge {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%); min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--accent); color: var(--accent-text); font-size: 12px; line-height: 20px; text-align: center;
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

.msg {
  position: relative; max-width: 80%; padding: 7px 11px 6px; border-radius: 18px; margin-top: 2px;
  word-wrap: break-word; overflow-wrap: anywhere; font-size: 15px; line-height: 1.32;
  transition: transform .2s var(--spring);
}
.msg.first { margin-top: 9px; }
.msg.theirs { align-self: flex-start; background: var(--card); box-shadow: 0 1px 1px rgba(0,0,0,.08); transform-origin: left bottom; }
.msg.mine { align-self: flex-end; background: var(--accent); color: var(--accent-text); transform-origin: right bottom; }
.msg.theirs:not(.first) { border-top-left-radius: 6px; }
.msg.theirs:not(.last) { border-bottom-left-radius: 6px; }
.msg.theirs.last { border-bottom-left-radius: 5px; }
.msg.mine:not(.first) { border-top-right-radius: 6px; }
.msg.mine:not(.last) { border-bottom-right-radius: 6px; }
.msg.mine.last { border-bottom-right-radius: 5px; }
.msg.new { animation: msg-in .24s var(--spring); }
@keyframes msg-in { from { transform: translateY(12px) scale(.94); opacity: 0; } }
.msg.in-room { margin-left: 38px; }
.msg-ava { position: absolute; left: -38px; bottom: 0; cursor: pointer; }
.msg-ava .avatar { width: 32px; height: 32px; }
.msg-reactions { clear: both; display: flex; flex-wrap: wrap; gap: 4px; padding-top: 5px; }
.reaction {
  position: relative; display: inline-flex; align-items: center; gap: 3px; height: 24px; padding: 0 8px; border-radius: 12px; font-size: 13px; font-weight: 600;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); animation: pop .2s var(--spring);
}
.reaction::before { content: ""; position: absolute; inset: -6px -2px; } /* 36 px to tap without making the chip bigger */
.reaction.mine { background: var(--accent); color: var(--accent-text); }
.msg.mine .reaction { background: rgba(255,255,255,.2); color: inherit; }
.msg.mine .reaction.mine { background: #fff; color: var(--accent); }
.swipe-arrow {
  position: absolute; top: 50%; right: -38px; width: 28px; height: 28px; margin-top: -14px; border-radius: 50%;
  display: grid; place-items: center; background: var(--glass-bg); color: var(--text); opacity: 0;
}
.swipe-arrow.ready { color: var(--accent); }
.react-row { display: flex; justify-content: space-between; background: var(--card); border-radius: 26px; padding: 6px 8px; margin-bottom: 10px; }
.react-pick { width: 44px; height: 44px; border-radius: 50%; font-size: 25px; display: grid; place-items: center; transition: transform .15s; }
.react-pick:active { transform: scale(1.3); }
.react-pick.mine { background: color-mix(in srgb, var(--accent) 22%, transparent); }

.lightbox { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(0,0,0,.92); animation: fade .18s; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; animation: pop .22s var(--spring); }
.msg-text { white-space: pre-wrap; display: inline; }
.msg-text a { color: inherit; text-decoration: underline; }
.msg-meta {
  float: right; margin: 6px 0 -2px 10px; font-size: 11px; opacity: .7;
  display: inline-flex; align-items: center; gap: 2px;
}
.msg.only-photo { padding: 3px; }
.msg.only-photo .msg-meta {
  position: absolute; right: 9px; bottom: 8px; margin: 0; padding: 1px 6px; border-radius: 8px;
  background: rgba(0,0,0,.45); color: #fff; opacity: 1;
}
.msg-photo img { display: block; max-width: 100%; max-height: 320px; min-width: 120px; min-height: 80px; border-radius: 12px; background: var(--field); object-fit: cover; }
.msg-photo + .msg-text { display: block; margin-top: 6px; }
.ticks { display: inline-flex; }
.ticks.read { opacity: 1; }
.chat-time .ticks { color: var(--accent); }

.msg-listing {
  border-left: 3px solid currentColor; padding: 2px 0 2px 8px; margin: 2px 0 6px; font-size: 13px;
}
.msg.theirs .msg-listing { border-color: var(--accent); }
.msg-reply { border-left: 3px solid currentColor; padding: 1px 0 1px 8px; margin: 2px 0 6px; font-size: 13px; line-height: 1.3; }
.msg.theirs .msg-reply { border-color: var(--accent); }
.msg-reply .mr-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.theirs .mr-name { color: var(--accent); }
.msg-reply .mr-text { opacity: .8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-reply.gone .mr-text { font-style: italic; }
.msg.flash { animation: msg-flash 1.3s ease-out; }
@keyframes msg-flash { 0%, 50% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent); } 100% { box-shadow: 0 0 0 3px transparent; } }
.mod-badge { flex: none; padding: 1px 6px; border-radius: 7px; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); font-size: 11px; font-weight: 700; }
.ban-mark { flex: none; margin-left: 4px; padding: 1px 6px; border-radius: 7px; background: color-mix(in srgb, var(--red) 18%, transparent); color: var(--red); font-size: 11px; font-weight: 700; }
.fraud-notice { background: color-mix(in srgb, var(--red) 16%, var(--card)); margin-bottom: 12px; }
.prof-facts { color: var(--hint); font-size: 13px; text-align: center; margin: -4px 0 12px; }
.prof-actions { display: flex; justify-content: center; gap: 18px; margin-top: 6px; }
.safety-bar { align-items: flex-end; }
.conv-context.safety-bar .ctx-text { border-left: 0; padding-left: 0; white-space: normal; line-height: 1.32; }
.conv-context.safety-bar .ctx-text b { display: block; color: var(--text); }
.safety-bar .btn { padding: 6px 12px; font-size: 14px; flex: none; }
.deal-bar .btn { padding: 6px 12px; font-size: 14px; flex: none; }
.conv-context.deal-bar .ctx-text { border-left: 0; padding-left: 0; white-space: normal; }
.conv-context.deal-bar .ctx-text b { color: inherit; }
.deal-bar:has(.deal-actions) { flex-wrap: wrap; padding: 8px 8px 8px 14px; }
.deal-bar:has(.deal-actions) .ctx-text { flex-basis: 100%; }
.deal-actions { display: flex; gap: 8px; flex: 1; }
.deal-actions .btn { flex: 1; }
.ml-title { font-weight: 600; }
.ml-price { font-size: 16px; font-weight: 700; }
.ml-meta { opacity: .8; }

.conv-banner { text-align: center; color: var(--hint); font-size: 14px; padding: 12px; border-radius: 18px; margin-bottom: calc(8px + env(safe-area-inset-bottom)); }
.conv-context { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; border-radius: 18px; font-size: 13px; animation: pop .18s var(--spring); }
.conv-context .ctx-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-left: 3px solid var(--accent); padding-left: 8px; }
.conv-context .ctx-text b { color: var(--accent); }
.conv-context .icon-btn { position: relative; width: 30px; height: 30px; color: var(--hint); }
.conv-context .icon-btn::before { content: ""; position: absolute; inset: -4px; } /* the ✕ is small, the finger is not: 38 px to tap */

.composer { display: flex; align-items: flex-end; gap: 6px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.round-btn { flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; }
.composer .attach { cursor: pointer; color: var(--hint); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; font: inherit; color: var(--text);
  border-radius: 21px; padding: 11px 16px; min-height: 42px; max-height: 140px; line-height: 1.3;
}
.send-btn {
  flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); transition: transform .2s var(--spring), opacity .15s;
}
.send-btn:active { transform: scale(.88); }
.send-btn:disabled { opacity: .4; transform: scale(.86); }

/* --- public room --- */
.room-avatar { background: #3a8fe8; color: #fff; display: grid; place-items: center; }
.chat-row.pinned { background: color-mix(in srgb, var(--accent) 7%, var(--card)); }
.unread.muted { background: var(--accent); }
.empty.small { padding: 24px 16px; font-size: 14px; }
.msg-sender { font-size: 13px; font-weight: 600; margin-bottom: 2px; display: flex; align-items: center; gap: 3px; cursor: pointer; }
.msg-sender .badge-verified { width: 13px; height: 13px; }
#convBody .msg { cursor: pointer; }

.action-list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; }
.action { display: block; width: 100%; padding: 14px 16px; text-align: left; font-size: 16px; color: var(--accent); border-bottom: 1px solid var(--separator); }
.action:last-child { border-bottom: 0; }
.action.danger { color: var(--danger); }
.action:active { background: var(--field); }

/* --- WebViews without color-mix() (Chrome < 111, iOS < 16.2) ---
   A color-mix() over var() is not dropped there but turns into "no background" when computed,
   so a fallback line in the same rule would not help: these rules come later and win instead */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
  .top { background: var(--bg); }
  .nav-blob { background: rgba(142,142,147,.2); }
  .sk { background: var(--field); }
  .price-warn, .notice { background: rgba(245,166,35,.16); }
  .status-pill.ok { background: rgba(49,181,69,.18); }
  .status-pill.wait { background: rgba(245,166,35,.2); }
  .unread-sep, .reaction, .react-pick.mine, .mod-badge { background: var(--field); }
  .msg.mine .reaction { background: rgba(255,255,255,.2); }
  .msg.mine .reaction.mine { background: #fff; }
  .reaction.mine { background: var(--accent); }
  .ban-mark, .fraud-notice { background: rgba(229,72,77,.16); }
}
