/* Кольори беруться з теми Telegram (--tg-theme-*), запасні — для звичайного браузера */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f6);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111317);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2b7bd9);
  --accent: var(--tg-theme-button-color, #2b7bd9);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e0453a);
  --good: #1f9d55;
  --warn: #d98a00;
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --radius: 14px;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #17191d; --bg2: #0f1013; --section: #1d2025; --text: #eceef2; --hint: #8b919c;
    --link: #6aa9f5; --accent: #3a8ee6; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--link); text-decoration: none; }
img { display: block; }

/* ---------- каркас */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--bg2);
}
.topbar__title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.topbar__status { border: 0; background: var(--section); border-radius: 999px; padding: 8px 10px; line-height: 0; }
.view { padding: 0 12px calc(var(--tabbar-h) + var(--safe-b) + 16px); }
.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) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--bg); border-top: 1px solid var(--line);
}
.tab { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--hint); }
.tab__icon { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tab.is-active { color: var(--accent); font-weight: 600; }
.tab.is-active .tab__icon { filter: none; opacity: 1; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--hint); }
.dot--ok { background: var(--good); } .dot--warn { background: var(--warn); } .dot--down { background: var(--danger); }

/* ---------- загальні елементи */
.section { background: var(--section); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.section__title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 0 0 10px; }
.muted { color: var(--hint); } .small { font-size: 13px; } .center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; }
.row--between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: 8px; }
.empty { text-align: center; color: var(--hint); padding: 40px 16px; }
.empty__icon { font-size: 40px; margin-bottom: 8px; }

.btn { border: 0; border-radius: 12px; padding: 12px 14px; background: var(--section); font-weight: 600; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; }
.section .btn { background: var(--bg2); }
.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--danger { color: var(--danger); }
.btn--small { padding: 8px 12px; min-height: 36px; width: auto; font-size: 14px; }
.btn:disabled { opacity: .5; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips--wrap { flex-wrap: wrap; overflow: visible; padding-bottom: 0; }
.chip { flex: none; border: 1px solid var(--line); background: var(--section); border-radius: 999px; padding: 7px 12px;
  font-size: 14px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.chip.is-on { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.chip__x { border: 0; background: none; padding: 0 0 0 2px; color: inherit; opacity: .6; font-size: 16px; line-height: 1; }

.input, .textarea, .select { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px;
  background: var(--bg); outline: none; }
.input:focus, .textarea:focus { border-color: var(--accent); }
.textarea { min-height: 92px; resize: vertical; }
.search { position: sticky; top: 50px; z-index: 10; background: var(--bg2); padding: 2px 0 8px; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff;
  border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }

.badge { display: inline-flex; align-items: center; border-radius: 8px; padding: 2px 7px; font-size: 12px; font-weight: 700; }
.badge--good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.badge--bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge--neutral { background: var(--bg2); color: var(--hint); }
.badge--live { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge--test { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

/* ---------- стрічка */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card { background: var(--section); border-radius: var(--radius); overflow: hidden; border: 0; padding: 0; text-align: left;
  display: flex; flex-direction: column; }
.card__img { position: relative; aspect-ratio: 4 / 5; background: var(--bg2); }
.card__img img { width: 100%; height: 100%; object-fit: cover; }
.card__noimg { width: 100%; height: 100%; display: grid; place-items: center; font-size: 34px; color: var(--hint); }
.card__badge { position: absolute; left: 8px; top: 8px; }
.card__badge .badge, .swipe-card__info .badge { background: rgba(255,255,255,.94); }
.card__badge .badge--neutral, .swipe-card__info .badge--neutral { color: #555b66; }
.card__plat { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 11px;
  border-radius: 6px; padding: 2px 6px; }
.card__body { padding: 9px 10px 11px; }
.card__price { font-weight: 700; font-size: 16px; }
.card__title { font-size: 13px; line-height: 1.3; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; min-height: 2.6em; }
.card__meta { font-size: 12px; color: var(--hint); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- аркуші (деталі) */
.sheet { position: fixed; inset: 0; z-index: 50; background: var(--bg2); overflow-y: auto;
  padding: 0 12px calc(24px + var(--safe-b)); animation: slideIn .18s ease-out; }
@keyframes slideIn { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet__head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 10px 0;
  background: var(--bg2); }
.sheet__back { border: 0; background: var(--section); border-radius: 999px; width: 36px; height: 36px; font-size: 18px; flex: none; }
.sheet__title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery { display: flex; gap: 6px; overflow-x: auto; scroll-snap-type: x mandatory; border-radius: var(--radius);
  margin-bottom: 12px; scrollbar-width: none; }
.gallery::-webkit-scrollbar { display: none; }
.gallery img { flex: none; width: 82%; max-width: 420px; aspect-ratio: 4 / 5; object-fit: cover; scroll-snap-align: start;
  border-radius: var(--radius); background: var(--section); }
.price-big { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--hint); } .kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.range { position: relative; height: 8px; background: var(--bg2); border-radius: 999px; margin: 18px 0 6px; }
.range__band { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 999px; }
.range__mark { position: absolute; top: -6px; width: 4px; height: 20px; border-radius: 2px; background: var(--text); transform: translateX(-2px); }
.list-row { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.list-row__img { width: 52px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--bg2); flex: none; }
.list-row__body { flex: 1; min-width: 0; }
.list-row__title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: var(--bg2); border-radius: 10px; min-width: 36px; height: 36px; flex: none; font-size: 15px; }
.icon-btn.is-on { background: var(--accent); color: var(--accent-text); }

/* ---------- свайпи */
.swipe { position: relative; height: min(64vh, 560px); margin: 4px 0 14px; }
.swipe-card { position: absolute; inset: 0; background: var(--section); border-radius: 20px; overflow: hidden;
  box-shadow: 0 6px 24px rgba(0,0,0,.12); touch-action: none; user-select: none; will-change: transform; }
.swipe-card:not(:last-child) { transform: scale(.96) translateY(10px); filter: brightness(.97); }
.swipe-card img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.swipe-card__info { position: absolute; left: 0; right: 0; bottom: 0; padding: 60px 16px 16px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.78)); }
.swipe-card__price { font-size: 24px; font-weight: 800; }
.swipe-card__stamp { position: absolute; top: 24px; padding: 6px 12px; border: 3px solid; border-radius: 10px; font-size: 22px;
  font-weight: 800; opacity: 0; transform: rotate(-12deg); }
.swipe-card__stamp--like { left: 18px; color: #2ecc71; } .swipe-card__stamp--nope { right: 18px; color: #ff5a4f; transform: rotate(12deg); }
.swipe-actions { display: flex; justify-content: center; gap: 22px; }
.round { width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--section); font-size: 26px;
  box-shadow: 0 4px 14px rgba(0,0,0,.1); }
.round--small { width: 48px; height: 48px; font-size: 18px; align-self: center; }

.bottom-sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b)); box-shadow: 0 -8px 30px rgba(0,0,0,.18); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.backdrop { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.35); }
.reason { display: flex; width: 100%; text-align: left; gap: 10px; align-items: flex-start; border: 1px solid var(--line);
  background: var(--section); border-radius: 12px; padding: 11px 12px; margin-top: 8px; }
.reason.is-suggested { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.reason__emoji { font-size: 20px; line-height: 1.2; }
.reason__why { font-size: 12px; color: var(--hint); }

/* ---------- снайпер */
.rule { display: block; width: 100%; text-align: left; border: 0; }
.hit { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.hit:first-child { border-top: 0; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); transform: translate(-50%, 20px);
  background: rgba(20,22,26,.92); color: #fff; padding: 10px 14px; border-radius: 12px; font-size: 14px; max-width: 90vw;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 80; text-align: center; }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- нові лоти */
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar__grow { flex: 1 1 auto; min-width: 0; }
.card__new { position: absolute; right: 8px; top: 8px; background: var(--good); color: #fff; font-size: 11px; font-weight: 800;
  letter-spacing: .06em; border-radius: 7px; padding: 3px 7px; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.newpill { position: sticky; top: 108px; z-index: 12; display: block; margin: 0 auto 10px; border: 0; border-radius: 999px;
  padding: 9px 16px; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,.18); animation: up .2s ease-out; }
.newpill[hidden] { display: none; }
.gallery-empty { aspect-ratio: 4 / 5; max-height: 300px; display: grid; place-items: center; font-size: 48px;
  background: var(--section); border-radius: var(--radius); margin-bottom: 12px; color: var(--hint); }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-bottom: 12px; }
.cards-grid > .section { margin: 0; }

/* ---------- адаптивність: один код для вузької панелі, телефона, планшета й широкого вікна */
:root { --page: 1180px; }
.view, .sheet__body { max-width: var(--page); margin-inline: auto; }
.topbar { padding-inline: max(16px, calc((100% - var(--page)) / 2 + 12px)); }
.sheet__head { max-width: var(--page); margin-inline: auto; }
.grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); }
.tabbar { padding-inline: max(0px, calc((100% - 620px) / 2)); }
.swipe, .swipe-actions, .swipe + .muted, .narrow { max-width: 460px; margin-inline: auto; }
.btn.narrow { display: flex; }

@media (max-width: 359px) {           /* дуже вузька бічна панель Telegram Desktop */
  .view { padding-inline: 8px; }
  .grid { gap: 8px; }
  .card__body { padding: 7px 8px 9px; }
  .card__price { font-size: 15px; }
  .btn-grid { grid-template-columns: 1fr; }
  .round { width: 54px; height: 54px; font-size: 22px; }
  .swipe-actions { gap: 14px; }
}
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
  .view { padding-inline: 16px; }
  .sheet { padding-inline: 16px; }
}
@media (min-width: 820px) {
  /* картка лота: фото зліва (липке), інформація справа */
  .item-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(340px, 1fr); gap: 16px; align-items: start; }
  .item-media { position: sticky; top: 64px; }
  .item-media .gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; overflow: visible; }
  .item-media .gallery img { width: 100%; max-width: none; }
  .item-media .gallery img:first-child { grid-column: 1 / -1; aspect-ratio: 4 / 4.4; }
  .two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; align-items: start; }
  .masonry { columns: 2 360px; column-gap: 12px; }
  .masonry > .section { break-inside: avoid; display: inline-block; width: 100%; }
  .bottom-sheet { left: 50%; right: auto; width: min(480px, 100%); transform: translateX(-50%); bottom: 16px;
    border-radius: 20px; animation: none; }
  .search { top: 54px; }
}
@media (min-width: 1100px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .masonry { columns: 3 340px; }
}
@media (hover: hover) {
  .card { transition: transform .15s ease, box-shadow .15s ease; }
  .card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0,0,0,.10); }
  .chip:hover, .btn:hover { filter: brightness(.97); }
}

/* ---------- ринок і аналітика */
.card__age { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 11px;
  border-radius: 6px; padding: 2px 6px; }
.card__landed { font-size: 12px; color: var(--hint); margin-top: 1px; }
.card__price .badge { font-size: 11px; padding: 1px 5px; vertical-align: 2px; margin-left: 4px; }
.chart { width: 100%; height: 90px; display: block; margin-top: 4px; }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details.section > summary::after { content: " ▾"; }
@media (max-width: 359px) { .tab { font-size: 10px; } .tab__icon { font-size: 18px; } }
.section .btn--primary { background: var(--accent); color: var(--accent-text); }
.section .btn--danger { color: var(--danger); }

/* ---------- наживо */
.topbar__left { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--hint); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.live__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--hint); flex: none; }
.live.is-on { color: var(--good); }
.live.is-on .live__dot { background: var(--good); box-shadow: 0 0 0 0 var(--good); animation: livepulse 2s infinite; }
@keyframes livepulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.card--live { animation: livein .45s ease-out; outline: 2px solid var(--good); outline-offset: -2px; }
.card--still { animation: none; }
@keyframes livein { from { opacity: 0; transform: translateY(-8px) scale(.97); } to { opacity: 1; transform: none; } }
.tab { position: relative; }
.tab__badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; }
@media (max-width: 520px) { .live__ago { display: none; } }
@media (max-width: 359px) { .live__text { display: none; } }
@media (prefers-reduced-motion: reduce) { .card--live, .live.is-on .live__dot { animation: none; } }
