/* Łowca PWA — вариант 2 «как OLX, только для перепродажи» (Ваня 22.10; макет — холст «Łowca — приложение», страница
   «Вариант 2»): светлая лента с крупными фото и ценой, тёмная шапка, 5 вкладок (Главная · Находки · Сообщения · Мои ·
   Ещё), сделка — как объявление, исходное объявление продавца — отдельным экраном. Тёмная тема — по системе.
   Шрифты свои (static/fonts, OFL): Onest — текст, JetBrains Mono — номера наборов; без внешних CDN (CSP). Кнопки ≥ 44 px,
   отступы safe-area для iPhone. */

@font-face {
  font-family: "Onest"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("/fonts/onest-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Onest"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("/fonts/onest-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Onest"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("/fonts/onest-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "JetBrains Mono"; font-style: normal; font-weight: 100 800; font-display: swap;
  src: url("/fonts/jbmono-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono"; font-style: normal; font-weight: 100 800; font-display: swap;
  src: url("/fonts/jbmono-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: light;
  --bg: #f3f1ec;          /* тёплый светлый фон ленты */
  --surface: #ffffff;     /* карточки */
  --surface-2: #f3f1ec;   /* чипы, поля, плашки внутри карточек */
  --photo: #e9e5dc;       /* место под фото */
  --line: #e3dfd6;
  --text: #1c1b18;
  --text-2: #4a463f;      /* второстепенный текст (контраст ≥ 7:1) */
  --muted: #6b665d;       /* подписи (≥ 4.5:1 на белом) */
  --ink: #1c1b18;         /* шапка и тёмные кнопки */
  --ink-2: #2e2c27;
  --on-ink: #f3f1ec;
  --on-ink-muted: #cfc9bd;
  --accent: #f2a93b;      /* янтарь: главная кнопка, активная вкладка */
  --accent-ink: #1c1b18;
  --accent-text: #a35f00; /* ссылки и акцент текстом (≥ 4.5:1 на белом) */
  --ok: #1f7a4d;  --ok-bg: #e3f4ea;
  --bad: #b42318; --bad-bg: #fbe9e5;
  --warn: #7a4700; --warn-bg: #fff1d6;
  --info: #1d4e89; --info-bg: #e4eefb;
  --need-bg: #fff8ec;     /* строка «нужен ты» в списках */
  --shadow: 0 8px 30px rgba(0, 0, 0, .15);
  --radius: 14px;
  --tabs-h: 62px;
  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #11100e;
    --surface: #1b1a17;
    --surface-2: #24221f;
    --photo: #2a2620;
    --line: #33302b;
    --text: #f1ede6;
    --text-2: #d9d4cb;
    --muted: #a39e94;
    --ink: #0b0a09;
    --ink-2: #24221f;
    --accent-text: #f2a93b;
    --ok: #5bd6a0;  --ok-bg: #17291f;
    --bad: #ff8a73; --bad-bg: #2c1814;
    --warn: #f2c14e; --warn-bg: #2b2414;
    --info: #8ab8ff; --info-bg: #16233a;
    --need-bg: #231f15;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 var(--font); min-height: 100vh; overflow-x: hidden; -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent-text); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
h3 { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
pre, code { font-family: var(--mono); font-size: 12.5px; }
pre {
  margin: 8px 0 0; padding: 10px; border-radius: 10px; background: var(--surface-2);
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 60vh; overflow: auto;
}
[hidden] { display: none !important; }
svg.i { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 16px; height: 16px; stroke-width: 2.1; }
.mono { font-family: var(--mono); font-weight: 500; }
.num { font-family: var(--mono); color: var(--muted); font-weight: 500; }

/* --- шапка (тёмная) --- */
#top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px; min-height: 56px;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 12px) 8px calc(env(safe-area-inset-left) + 12px);
  background: var(--ink); color: var(--on-ink);
}
#top h1 { flex: 1; font-size: 20px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top h1.brand { font-size: 24px; font-weight: 800; letter-spacing: -.03em; color: var(--accent); }
#back {
  min-width: 44px; min-height: 44px; margin-left: -8px; border: 0; border-radius: 22px; background: none; color: var(--on-ink);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
#link {
  display: inline-flex; align-items: center; gap: 7px; min-height: 32px; padding: 0 10px; border-radius: 16px;
  font-size: 13px; color: var(--on-ink-muted); background: var(--ink-2); white-space: nowrap; max-width: 60%;
  overflow: hidden; text-overflow: ellipsis; flex: none;
}
#top h1:not(.brand) + #link { max-width: 42%; }
#link::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--on-ink-muted); }
#link.on::before { background: #5bd6a0; }
#link.off::before { background: #ff8a73; }
#link.warn::before { background: #f2c14e; }
#link.bad::before { background: #ff8a73; }
a#link { cursor: pointer; }

/* продолжение шапки на экране: поиск, чипы, цифры */
.hero {
  background: var(--ink); color: var(--on-ink);
  margin: 0 calc(-1 * (env(safe-area-inset-right) + 16px)) 0 calc(-1 * (env(safe-area-inset-left) + 16px));
  padding: 2px calc(env(safe-area-inset-right) + 16px) 14px calc(env(safe-area-inset-left) + 16px);
  display: flex; flex-direction: column; gap: 12px;
}
.hero .muted { color: var(--on-ink-muted); }
.search {
  display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 0 14px; border-radius: 12px;
  background: #ffffff; color: #6b665d;
}
.search input { flex: 1; min-width: 0; min-height: 44px; border: 0; padding: 0; background: transparent; color: #1c1b18; font-size: 16px; }
.search input:focus { outline: none; }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.hero-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.hero-stats div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.hero-stats span { font-size: 12px; color: var(--on-ink-muted); }
.hero-stats b { font-size: 18px; font-weight: 800; color: #ffffff; white-space: nowrap; }
.hero-stats b.ok { color: #7fe0ae; }
.under-tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin-bottom: -14px; }
.under-tabs::-webkit-scrollbar { display: none; }
.under-tabs button, .under-tabs a {
  flex: none; min-height: 44px; padding: 0 12px; border: 0; background: transparent; color: var(--on-ink-muted);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
.under-tabs .on { color: #ffffff; font-weight: 700; box-shadow: inset 0 -3px 0 var(--accent); }

/* --- контент --- */
#view {
  max-width: 760px; margin: 0 auto;
  padding: 0 calc(env(safe-area-inset-right) + 16px) calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 16px);
}
body.unpaired #view { padding-bottom: 32px; }
body.has-bar #view { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 96px); }
.stack { display: flex; flex-direction: column; gap: 12px; padding-top: 14px; }
.stack .stack { padding-top: 0; }
.stack.flush { padding-top: 0; gap: 8px; }
.sec { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.sec-head a { font-size: 14px; font-weight: 600; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 8px; min-width: 0;
}
a.card { color: inherit; }
.card.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-head h3 { flex: 1; min-width: 0; }
.card h3 a { color: inherit; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.html { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text-2); font-size: 14px; }
.html a { word-break: break-all; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.error-box { border-color: var(--bad); background: var(--bad-bg); }
.spinner { display: flex; justify-content: center; padding: 40px; color: var(--muted); }
.spinner::before {
  content: ""; width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.nowrap { white-space: nowrap; }
.oneline { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.clamp3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.grow { flex: 1; min-width: 0; }
.status:empty { display: none; }

/* --- чипы, метки, точки --- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chips-row::-webkit-scrollbar { display: none; }
.pill {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px; border-radius: 19px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.pill b { font-weight: 700; }
.pill.on { background: var(--ink); border-color: var(--ink); color: #ffffff; font-weight: 600; }
.pill.hot { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.hero .pill { border-color: #45423b; background: transparent; color: var(--on-ink); }
.hero .pill.hot { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 8px;
  font-size: 13px; background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.info { background: var(--info-bg); color: var(--info); }
.tag { font-size: 11.5px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; color: var(--accent-text); }
.tag.bad { color: var(--bad); }
.tag.ok { color: var(--ok); }
.tag.info { color: var(--info); }
.badge-box { align-self: flex-start; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; text-transform: uppercase; letter-spacing: .02em; }
.badge-box.ok { background: var(--ok-bg); color: var(--ok); }
.badge-box.warn { background: var(--warn-bg); color: var(--warn); }
.badge-box.bad { background: var(--bad-bg); color: var(--bad); }
.badge-box.quiet { background: var(--surface-2); color: var(--text-2); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.warn { background: #e0a21f; }

/* --- деньги --- */
.price { font-size: 20px; font-weight: 800; letter-spacing: -.01em; white-space: nowrap; font-variant-numeric: tabular-nums; line-height: 1.15; }
.price.big { font-size: 28px; letter-spacing: -.02em; }
.price.sm { font-size: 18px; }
.old { color: var(--muted); text-decoration: line-through; font-size: 15px; white-space: nowrap; }
.gain { font-weight: 700; white-space: nowrap; color: var(--ok); }
.gain.bad { color: var(--bad); }
.amt { font-size: 21px; font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* --- фото-заглушка и миниатюры --- */
.ph {
  position: relative; background: var(--photo); color: var(--muted); display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex: none; font-size: 12px;
}
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .corner { position: absolute; font-size: 11.5px; font-weight: 700; padding: 3px 7px; border-radius: 7px; }
.ph .tl { top: 8px; left: 8px; }
.ph .bl { bottom: 8px; left: 8px; }
.ph .br { bottom: 8px; right: 8px; }
.on-photo { background: rgba(28, 27, 24, .82); color: #ffffff; font-weight: 600; }
.on-photo.gain { background: #d8f1e2; color: #14532d; }

/* --- «Нужен ты» лентой --- */
.need-strip {
  display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  margin: 0 calc(-1 * (env(safe-area-inset-right) + 16px)) 0 calc(-1 * (env(safe-area-inset-left) + 16px));
  padding: 2px calc(env(safe-area-inset-right) + 16px) 4px calc(env(safe-area-inset-left) + 16px);
}
.need-strip::-webkit-scrollbar { display: none; }
.need-strip > .card { flex: none; width: min(86%, 340px); scroll-snap-align: start; }
.need-strip > .card:only-child { width: 100%; }
.need-top { display: flex; gap: 10px; align-items: flex-start; }
.need-top .ph { width: 56px; height: 56px; border-radius: 10px; }
.need-top .grow { display: flex; flex-direction: column; gap: 2px; }
.need-top h3 a { color: var(--text); }
.card.need .html { font-size: 13.5px; }
.card.need .btns { flex-wrap: nowrap; }
.card.need .btns .btn { padding-left: 12px; padding-right: 12px; }
.card.need .btns .grow1 { min-width: 0; }
.card.need { justify-content: space-between; }

/* --- сетка находок (главная) --- */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile { background: var(--surface); border-radius: var(--radius); overflow: hidden; color: var(--text); display: flex; flex-direction: column; }
.tile .ph { aspect-ratio: 1 / 1; width: 100%; }
.tile-body { padding: 10px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tile-body .name { font-size: 13px; line-height: 1.3; min-height: 34px; }

/* --- карточка-строка (как выдача OLX) --- */
.item { background: var(--surface); border-radius: var(--radius); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.item.need { background: var(--need-bg); }
.item-main { display: flex; gap: 12px; padding: 10px; color: var(--text); min-width: 0; }
.item-main .ph { width: 112px; height: 112px; border-radius: 10px; }
.item-main .ph.md { width: 92px; height: 92px; }
.item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.item-body .name { font-size: 14px; line-height: 1.3; }
.item-body .where { margin-top: auto; font-size: 12px; color: var(--muted); }
.item-foot { display: flex; align-items: center; gap: 8px; padding: 0 10px 10px; }
.item-foot .note { flex: 1; min-width: 0; font-size: 12.5px; line-height: 1.35; color: var(--text-2); }
.item-foot .note.bad { color: var(--bad); }
.item-stats { display: flex; align-items: center; gap: 12px; margin: 0 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--text-2); }
.item-stats span { display: inline-flex; align-items: center; gap: 4px; }
.item .btns { padding: 0 10px 10px; }

/* строка-ссылка «Исходное объявление» и подобные */
.link-row {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 10px; border-radius: 10px;
  background: var(--surface-2); color: var(--text); font-size: 14px;
}
.link-row b { font-weight: 600; }
.link-row .side { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item > .link-row { margin: 0 10px 10px; }
.link-row.outline { background: transparent; border: 1px solid var(--line); border-radius: 12px; }

/* --- сделка и исходное объявление --- */
.full-bleed { margin: 0 calc(-1 * (env(safe-area-inset-right) + 16px)) 0 calc(-1 * (env(safe-area-inset-left) + 16px)); }
.gallery {
  position: relative; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; background: var(--photo);
  height: 300px;
}
.gallery::-webkit-scrollbar { display: none; }
.gallery img { flex: none; width: 100%; height: 300px; object-fit: cover; scroll-snap-align: start; cursor: zoom-in; display: block; }
.gallery .empty-ph { flex: none; width: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }
.gallery-wrap { position: relative; }
.gallery-wrap .corner { position: absolute; z-index: 1; font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 8px; }
.gallery-wrap .tl { top: 12px; left: 16px; }
.gallery-wrap .br { bottom: 12px; right: 16px; }
.thumbs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.thumbs img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 8px; background: var(--photo); cursor: pointer; }
.panel { background: var(--surface); padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.panel h2 { font-size: 17px; }
.panels { display: flex; flex-direction: column; gap: 8px; }
.panels.full-bleed .panel { padding-left: calc(env(safe-area-inset-left) + 16px); padding-right: calc(env(safe-area-inset-right) + 16px); }
.ad-title { font-size: 20px; line-height: 1.3; font-weight: 600; }
.sum-rows { display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.sum-rows > div { display: flex; justify-content: space-between; gap: 12px; }
.sum-rows > div > span:first-child { color: var(--text-2); }
.sum-rows > .total { padding-top: 8px; border-top: 1px solid var(--line); font-size: 17px; font-weight: 600; }
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.35; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.quiet { background: var(--surface-2); color: var(--text-2); }
.changes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 14px; line-height: 1.4; }
.changes li { display: flex; gap: 10px; }
.changes .when { width: 48px; flex: none; font-family: var(--mono); font-size: 12px; color: var(--muted); padding-top: 2px; }
.seller { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 48px; height: 48px; flex: none; border-radius: 24px; background: var(--photo); color: var(--text-2);
  display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700;
}
.avatar.sm { width: 40px; height: 40px; font-size: 16px; }
.avatar.buyer { background: var(--info-bg); color: var(--info); }

/* нижняя панель действий (сделка, исходное) — над вкладками */
.actionbar {
  position: fixed; left: 0; right: 0; z-index: 19; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  display: flex; gap: 8px; padding: 10px calc(env(safe-area-inset-right) + 16px) 10px calc(env(safe-area-inset-left) + 16px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.actionbar .btn { min-height: 50px; font-size: 16px; }
.actionbar .btn.primary { flex: 1; }
.actionbar .composer-bar { flex: 1; }
.actionbar .composer-bar .btn { min-height: 46px; }
.stack > .hero:first-child { margin-top: -14px; }

/* --- сообщения --- */
.chat-list { display: flex; flex-direction: column; background: var(--surface); }
.chat-row { display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--text); min-width: 0; }
.chat-row.need { background: var(--need-bg); }
.chat-row .ph { width: 56px; height: 56px; border-radius: 10px; }
.chat-row .grow { display: flex; flex-direction: column; gap: 2px; }
.chat-row .top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.chat-row .who { font-size: 15px; font-weight: 700; }
.chat-row .at { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.chat-row .last { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.chat-row .last span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row .last.unread span { font-weight: 600; }
.chat-row .state { font-size: 12px; font-weight: 600; color: var(--text-2); }
.chat-row .state.warn { color: var(--accent-text); }
.chat-row .state.bad { color: var(--bad); }
.chat-row .state.ok { color: var(--ok); }
.role { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.role.buyer { background: var(--info-bg); color: var(--info); }
.unread-n {
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--accent); color: var(--accent-ink);
  font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.chat-head { background: var(--surface); display: flex; flex-direction: column; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-head .person { display: flex; align-items: center; gap: 10px; }
.item-strip { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 12px; background: var(--surface-2); color: var(--text); }
.item-strip .ph { width: 44px; height: 44px; border-radius: 8px; }
.thread { display: flex; flex-direction: column; gap: 8px; padding: 16px 0; }
.msg { display: flex; flex-direction: column; gap: 3px; max-width: 84%; }
.msg .b { padding: 10px 12px; font-size: 15px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.them { align-self: flex-start; }
.msg.them .b { background: var(--surface); border-radius: 16px 16px 16px 4px; }
.msg.me { align-self: flex-end; }
.msg.me .b { background: var(--ink); color: #ffffff; border-radius: 16px 16px 4px 16px; }
.msg.me .m { text-align: right; }
.msg .m { font-size: 11.5px; color: var(--muted); }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); }
.decision { border-radius: 16px; background: var(--surface); border: 1px solid #f2d29a; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.decision .opt {
  min-height: 48px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; text-align: left; display: flex; flex-direction: column; gap: 1px; cursor: pointer;
}
.decision .opt.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.decision .opt b { font-size: 15px; }
.decision .opt span { font-size: 13px; opacity: .85; }

/* --- процессы, цифры, списки --- */
.procs, .stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.proc { padding: 12px; gap: 4px; }
.proc-name { display: flex; align-items: center; gap: 8px; font-weight: 600; min-height: 28px; }
.proc .icon-btn { margin: -8px -8px -8px 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat b { display: block; font-size: 20px; font-weight: 800; overflow-wrap: anywhere; }
.stat span { font-size: 12.5px; color: var(--muted); }
.kv { display: grid; grid-template-columns: minmax(100px, auto) 1fr; gap: 4px 12px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.rows { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-top: 1px solid var(--line);
  color: inherit; min-height: 44px;
}
.row:first-child { border-top: 0; }
.row .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.big { font-size: 17px; min-height: 56px; }
.chev { color: var(--muted); display: inline-flex; }
ul.plain { margin: 0; padding-left: 18px; }
ul.plain li { margin: 2px 0; overflow-wrap: anywhere; }
.sub { display: flex; flex-direction: column; gap: 4px; }
.sub h2 { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* --- кнопки и поля --- */
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: 15px; font-weight: 600;
  cursor: pointer; user-select: none; -webkit-user-select: none; text-align: center;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.dark { background: var(--ink); color: #ffffff; border-color: var(--ink); }
.btn.outline { border-color: var(--text); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.grow1 { flex: 1; }
.btn.sm { min-height: 40px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.icon { width: 44px; padding: 0; flex: none; }
.btn.icon.sm { width: 40px; }
.btn.busy { opacity: .6; pointer-events: none; }
.icon-btn {
  min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--muted);
  border-radius: 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .pill:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > input, .inline > select { flex: 1; min-width: 0; }
.inline > .btn { flex: none; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.seg a, .seg button {
  min-height: 40px; padding: 6px 10px; border-radius: 9px; border: 0; background: transparent;
  color: var(--muted); font: inherit; font-size: 14px; text-align: center; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
}
.seg .on { background: var(--surface); color: var(--text); font-weight: 700; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.composer-bar { display: flex; gap: 8px; align-items: center; }
.composer-bar input { border-radius: 23px; background: var(--surface-2); }
.composer-bar .btn { border-radius: 23px; }

/* --- журналы --- */
.log { padding: 10px 12px; gap: 4px; }
.log .msg-text { font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; cursor: pointer; }
.log.clip .msg-text { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.lvl-ERROR, .lvl-CRITICAL { color: var(--bad); }
.lvl-WARNING { color: var(--warn); }
.lvl-INFO { color: var(--info); }
.scroll-x { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { display: none; }
.scroll-x .btn { flex: none; min-height: 38px; padding: 6px 12px; font-size: 14px; }
.scroll-x .btn.on { background: var(--ink); color: #ffffff; border-color: var(--ink); }

/* --- агент --- */
.feed { display: flex; flex-direction: column; gap: 8px; }
.bubble {
  padding: 10px 12px; border-radius: 14px 14px 14px 4px; background: var(--surface); border: 1px solid var(--line);
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px;
}
.bubble.me { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: var(--info-bg); border-color: transparent; max-width: 88%; }
.bubble.result { border-color: var(--accent); }
.bubble.fail { border-color: var(--bad); }
details.tool { border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: var(--surface-2); font-size: 13px; }
details.tool summary {
  min-height: 36px; padding: 8px 0; cursor: pointer; list-style: none;
  font-family: var(--mono); font-size: 12.5px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
details.tool summary::-webkit-details-marker { display: none; }
details.tool[open] summary { color: var(--text); white-space: normal; }
details.tool pre { margin: 0 0 10px; }
.sys { font-size: 12px; color: var(--muted); text-align: center; }
.composer { display: flex; flex-direction: column; gap: 8px; }

/* --- нижние вкладки --- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 2px calc(env(safe-area-inset-right) + 4px) calc(env(safe-area-inset-bottom) + 4px) calc(env(safe-area-inset-left) + 4px);
  background: var(--surface); border-top: 1px solid var(--line);
}
body.unpaired #tabs { display: none; }
#tabs a {
  position: relative; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--muted); font-size: 11px; font-weight: 500;
}
#tabs a::before { content: ""; width: 22px; height: 3px; border-radius: 2px; background: transparent; }
#tabs a.on { color: var(--text); font-weight: 700; }
#tabs a.on::before { background: var(--accent); }
#tabs .ico { position: relative; display: inline-flex; }
#tabs .badge {
  position: absolute; top: -4px; left: 15px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

/* --- тосты --- */
#toasts {
  position: fixed; left: 0; right: 0; z-index: 60; pointer-events: none;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0 16px;
}
body.has-bar #toasts { bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 84px); }
body.unpaired #toasts { bottom: calc(env(safe-area-inset-bottom) + 16px); }
.toast {
  max-width: 560px; padding: 10px 14px; border-radius: 12px; background: var(--ink); color: #ffffff;
  box-shadow: var(--shadow); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere;
  pointer-events: auto; animation: rise .2s ease-out; border-left: 4px solid var(--accent);
}
.toast.ok { border-left-color: #5bd6a0; }
.toast.err { border-left-color: #ff8a73; }
.toast.info { border-left-color: #8ab8ff; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* --- нижний лист и PIN --- */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; margin: 0;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 18px); display: flex; flex-direction: column; gap: 12px;
  animation: slide .2s ease-out; color: var(--text);
}
.sheet::before { content: ""; align-self: center; width: 40px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet h3 { font-size: 18px; font-weight: 700; }
.sheet .err { color: var(--bad); font-size: 14px; }
.sheet .err:empty { display: none; }
@keyframes slide { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.pin-input { font-size: 26px; letter-spacing: .4em; text-align: center; font-family: var(--mono); }
.sheet.menu { gap: 8px; }
.sheet.menu .btn { justify-content: flex-start; text-align: left; font-weight: 500; }
.sheet.menu .btn.cancel { justify-content: center; margin-top: 4px; }

/* --- сопряжение --- */
.pair { max-width: 420px; margin: 6vh auto 0; text-align: center; }
.pair .logo { width: 88px; height: 88px; border-radius: 22px; margin: 0 auto 4px; display: block; }
.pair p { margin: 0; }

/* --- «Ничего не требуется» --- */
.calm { text-align: center; padding: 28px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.calm-big { font-size: 22px; font-weight: 700; }
.calm-big::before { content: "✓"; display: block; font-size: 40px; line-height: 1.1; margin-bottom: 4px; color: var(--ok); }
.calm-day { color: var(--muted); font-size: 14px; }
.calm-day:empty { display: none; }

/* --- свёртки --- */
details.fold { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
details.fold > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  min-height: 52px; padding: 12px 14px; user-select: none; -webkit-user-select: none; font-weight: 600;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary .chev { transition: transform .15s; }
details.fold[open] > summary .chev { transform: rotate(90deg); }
details.fold > .fold-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 10px; }
details.fold.quiet > summary { font-weight: 500; color: var(--muted); }
.count { font-family: var(--mono); font-size: 15px; font-weight: 600; color: var(--muted); }

/* тревоги строкой */
.card.alerts { padding: 2px 14px; border-color: #f0c2b8; background: var(--bad-bg); }
.row.alert { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 6px 8px; color: var(--text); }
.row.alert > .alert-icon { grid-column: 1; grid-row: 1; color: var(--bad); display: inline-flex; }
.row.alert > .alert-text { grid-column: 2; grid-row: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; font-weight: 600; }
.row.alert > .alert-age { grid-column: 3; grid-row: 1; }
.row.alert > .btn { grid-column: 4; grid-row: 1; }
.row.alert > .alert-text.open { grid-column: 1 / -1; grid-row: 2; white-space: pre-wrap; overflow-wrap: anywhere; font-weight: 400; }

/* загрузка фото */
.strip { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.add-photo {
  flex: none; position: relative; overflow: hidden; width: 100%; min-height: 52px; border: 1px dashed var(--muted); border-radius: 12px;
  display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--text-2); font-size: 15px; font-weight: 600; cursor: pointer;
}
.add-photo input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; }

@media (min-width: 700px) {
  .grid2 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .gallery, .gallery img { height: 420px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
