:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111114);
  --hint: var(--tg-theme-hint-color, #7d7d85);
  --link: var(--tg-theme-link-color, #2678d9);
  --accent: var(--tg-theme-button-color, #2678d9);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(128, 128, 128, .22);
  --good: #1f9d55;
  --bad: #d64545;
  --warn: #b7791f;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
#app { min-height: 100%; max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }

/* шапка */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--bg);
}
.top h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .count { color: var(--hint); font-weight: 400; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; font-size: 18px; display: grid; place-items: center; background: var(--card); }
.icon-btn:disabled { opacity: .35; }
.page { flex: 1; padding: 0 12px 24px; }
.empty { text-align: center; color: var(--hint); padding: 56px 20px; }
.hint { color: var(--hint); font-size: 13px; }

/* главное меню */
.tiles { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.tile {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border-radius: var(--radius); padding: 14px;
}
.tile .ico { font-size: 22px; width: 28px; text-align: center; }
.tile .name { flex: 1; font-weight: 550; }
.tile .sub { display: block; font-weight: 400; font-size: 13px; color: var(--hint); }
.badge { min-width: 26px; padding: 2px 8px; border-radius: 999px; text-align: center; font-size: 13px; font-weight: 600; background: var(--bg); color: var(--hint); }
.badge.hot { background: var(--accent); color: var(--accent-text); }
.section { margin: 18px 4px 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); }
.banner { background: var(--card); border-left: 3px solid var(--warn); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 14px; }

/* карточка объявления */
.card { background: var(--card); border-radius: var(--radius); overflow: hidden; touch-action: pan-y; }
.card.drag { transition: none; }
.card.snap { transition: transform .18s ease, opacity .18s ease; }
.gallery { position: relative; background: #1b1b1f; aspect-ratio: 4 / 3; }
.gallery img { width: 100%; height: 100%; object-fit: contain; display: block; }
.gallery .nophoto { height: 100%; display: grid; place-items: center; color: #8a8a93; }
.dots { position: absolute; left: 0; right: 0; bottom: 8px; display: flex; justify-content: center; gap: 5px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, .45); }
.dots i.on { background: #fff; }
.tap { position: absolute; top: 0; bottom: 0; width: 40%; }
.tap.l { left: 0; } .tap.r { right: 0; }
.stamp {
  position: absolute; top: 16px; padding: 4px 12px; border: 3px solid; border-radius: 8px;
  font-weight: 800; font-size: 20px; opacity: 0; text-transform: uppercase; background: rgba(0, 0, 0, .35);
}
.stamp.yes { left: 16px; color: #5fe39a; transform: rotate(-10deg); }
.stamp.no { right: 16px; color: #ff8a8a; transform: rotate(10deg); }
.body { padding: 12px 14px 14px; }
.title { font-size: 17px; font-weight: 650; margin: 0 0 2px; }
.price { font-size: 20px; font-weight: 700; }
.price small { font-size: 13px; font-weight: 400; color: var(--hint); margin-left: 6px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 6px 0 8px; font-size: 13px; color: var(--hint); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.chip.warn { background: rgba(183, 121, 31, .16); color: var(--warn); }
.chip.bad { background: rgba(214, 69, 69, .14); color: var(--bad); }
.chip.good { background: rgba(31, 157, 85, .14); color: var(--good); }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.text.clamp { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.more { color: var(--link); font-size: 14px; margin-top: 4px; }
.links { display: flex; gap: 8px; margin-top: 12px; }
.links button { flex: 1; padding: 9px; border-radius: 10px; background: var(--bg); color: var(--link); font-weight: 550; }

.dup { display: flex; gap: 10px; align-items: center; padding: 10px 14px; background: rgba(183, 121, 31, .13); }
.dup img { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; }
.dup .q { flex: 1; font-size: 13px; }
.dup button { padding: 6px 12px; border-radius: 8px; background: var(--card); font-weight: 600; }

/* нижняя панель */
.bar {
  position: sticky; bottom: 0; display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.btn { flex: 1; padding: 13px 10px; border-radius: 12px; font-weight: 650; background: var(--card); }
.btn.yes { background: var(--good); color: #fff; }
.btn.no { background: var(--card); color: var(--bad); }
.btn.main { background: var(--accent); color: var(--accent-text); }
.btn.small { flex: 0 0 auto; padding: 13px 16px; }
.btn:disabled { opacity: .45; }

/* списки */
.rows { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.row { display: flex; gap: 10px; width: 100%; text-align: left; background: var(--card); border-radius: 12px; padding: 8px; align-items: center; }
.row img, .row .ph { width: 60px; height: 60px; border-radius: 8px; object-fit: cover; background: var(--bg); flex: none; }
.row .info { flex: 1; min-width: 0; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .right { font-weight: 700; white-space: nowrap; }
.row.sel { outline: 2px solid var(--accent); }
.pos { color: var(--good); } .neg { color: var(--bad); }
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; }
.filters button, .reasons button { flex: none; padding: 7px 12px; border-radius: 999px; background: var(--card); font-size: 14px; }
.filters button.on, .reasons button.on { background: var(--accent); color: var(--accent-text); }
.reasons { display: flex; flex-wrap: wrap; gap: 6px; }
.form .reasons button { background: var(--bg); }
.form .reasons button.on { background: var(--accent); }

/* формы */
.form { background: var(--card); border-radius: var(--radius); padding: 4px 14px; margin-bottom: 10px; }
.field { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field label { flex: 1; }
.field input[type=number], .field input[type=text] { width: 120px; text-align: right; }
input, select, textarea { background: var(--bg); border: 0; border-radius: 8px; padding: 8px 10px; outline: none; min-width: 0; }
textarea { width: 100%; resize: vertical; min-height: 64px; }
.stack { display: grid; gap: 8px; padding: 10px 0; }
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.total { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.total b { display: block; font-size: 20px; }

/* шторка */
.sheet-back { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; background: var(--bg); border-radius: 18px 18px 0 0; padding: 16px 12px calc(16px + env(safe-area-inset-bottom)); max-height: 90vh; overflow: auto; }
.sheet h2 { margin: 0 4px 12px; font-size: 17px; }
.menu button { display: block; width: 100%; text-align: left; padding: 14px; background: var(--card); border-radius: 12px; margin-bottom: 8px; }
.menu button.danger { color: var(--bad); }

#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 30; max-width: 88%;
  background: rgba(20, 20, 24, .92); color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 14px; text-align: center;
}

/* сердечко «в избранное» в углу фото */
.heart {
  position: absolute; top: 10px; right: 10px; z-index: 2; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; font-size: 22px; line-height: 1;
  background: rgba(0, 0, 0, .45); color: #fff;
}
.heart.on { background: #fff; color: #e0245e; }

.chip.hot { background: rgba(230, 90, 20, .16); color: #d2530f; }

/* виджет «Деньги» на главном экране */
.money { background: var(--card); border-radius: var(--radius); padding: 14px; margin-top: 8px; }
.money:empty { display: none; }
.money-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.money-head b { font-size: 16px; }
.seg { display: flex; background: var(--bg); border-radius: 9px; padding: 2px; }
.seg button { padding: 4px 10px; border-radius: 7px; font-size: 13px; color: var(--hint); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.kpi { min-width: 0; }
.kpi .hint { display: block; margin-bottom: 2px; }
.kpi b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { height: 6px; border-radius: 3px; background: var(--bg); margin: 12px 0 8px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.money-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.money-foot .more { margin: 0; flex: none; }

/* свёрнутый список категорий */
.arrow { color: var(--hint); font-size: 16px; width: 26px; text-align: center; }
.sub-tile { padding: 11px 14px 11px 54px; }
[hidden] { display: none !important; }

/* сводка стока: подписи разной длины не должны сдвигать цифры */
.kpis { align-items: end; }
.row .s.pos { color: var(--good); }
.row .s.neg { color: var(--bad); }
