/* Каталог у Telegram Mini App. Кольори — з теми Telegram (--tg-theme-*), поза Telegram — запасні світла / темна. */

:root {
  --fb-bg: #ffffff;
  --fb-bg2: #eff0f3;
  --fb-text: #0f1114;
  --fb-hint: #7d8590;
  --fb-link: #2481cc;
  --fb-btn: #2481cc;
  --fb-btn-text: #ffffff;
  --fb-sep: rgba(15, 17, 20, .09);
  --fb-ok: #1f9d55;
}
:root[data-theme="dark"] {
  --fb-bg: #17212b;
  --fb-bg2: #0e1621;
  --fb-text: #f5f5f5;
  --fb-hint: #7f91a4;
  --fb-link: #6ab3f3;
  --fb-btn: #5288c1;
  --fb-btn-text: #ffffff;
  --fb-sep: rgba(255, 255, 255, .09);
  --fb-ok: #4cc38a;
}
:root {
  --bg: var(--tg-theme-bg-color, var(--fb-bg));
  --bg2: var(--tg-theme-secondary-bg-color, var(--fb-bg2));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-bg)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --link: var(--tg-theme-link-color, var(--fb-link));
  --btn: var(--tg-theme-button-color, var(--fb-btn));
  --btn-text: var(--tg-theme-button-text-color, var(--fb-btn-text));
  --sep: var(--fb-sep);
  --ok: var(--fb-ok);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --pad: 12px;
  --radius: 14px;
}
/* Покупець кнопкою в шапці вибрав тему, протилежну темі Telegram: кольори Telegram до неї не пасують — беремо свої запасні. */
:root[data-own-colors] {
  --bg: var(--fb-bg); --bg2: var(--fb-bg2); --card: var(--fb-bg); --text: var(--fb-text); --hint: var(--fb-hint);
  --link: var(--fb-link); --btn: var(--fb-btn); --btn-text: var(--fb-btn-text);
}
/* смуги прокрутки й системні списки — у кольорах вибраної теми, а не теми телефона чи комп'ютера */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.view { max-width: 560px; margin: 0 auto; min-height: 100vh; }

/* ───────── шапка списку ───────── */

.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg2);
  padding: 8px 0 6px;
}
.search {
  position: relative; margin: 0 var(--pad);
  display: flex; align-items: center;
  background: var(--card); border-radius: 12px;
  box-shadow: 0 0 0 1px var(--sep);
}
.search:focus-within { box-shadow: 0 0 0 2px var(--btn); }
.search-ico { position: absolute; left: 11px; width: 18px; height: 18px; fill: none; stroke: var(--hint); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search input {
  flex: 1; min-width: 0; height: 42px; border: 0; outline: 0; background: transparent;
  padding: 0 40px 0 37px; font-size: 16px; /* 16px — щоб iOS не наближав сторінку */
  -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--hint); }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute; right: 5px; width: 32px; height: 32px; border: 0; border-radius: 50%;
  background: transparent; display: grid; place-items: center;
}
.search-clear svg { width: 18px; height: 18px; padding: 3px; border-radius: 50%; background: var(--hint); fill: none; stroke: var(--card); stroke-width: 2.6; stroke-linecap: round; }

/* бонус за посиланням власника: смужка в списку й підпис біля ціни товару */
.bonus {
  margin: 8px var(--pad) 0; padding: 8px 12px; border-radius: 10px;
  background: var(--btn); color: var(--btn-text); font-size: 14px; font-weight: 600; line-height: 1.25;
}
.bonus.off { background: var(--card); color: var(--hint); font-weight: 400; border: 1px solid var(--sep); }
.p-bonus { margin-top: 8px; font-size: 14px; font-weight: 600; color: var(--link); }
.p-bonus.off { font-weight: 400; color: var(--hint); }

.chips {
  display: flex; gap: 7px; overflow-x: auto; padding: 9px var(--pad) 3px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
/* другий рядок — групи вибраного розділу: дрібніший і спокійніший за перший */
.chips.sub { padding-top: 6px; }
.chips.sub .chip { padding: 5px 11px; font-size: 13px; background: transparent; }
.chips.sub .chip[aria-pressed="true"] { background: var(--card); color: var(--link); box-shadow: 0 0 0 1.5px var(--link); font-weight: 600; }
.chips.sub .chip[aria-pressed="true"] small { color: var(--link); opacity: .8; }
.chip {
  flex: none; border: 0; border-radius: 999px; padding: 7px 13px;
  background: var(--card); color: var(--text); font-size: 14px; line-height: 1.2; white-space: nowrap;
  box-shadow: 0 0 0 1px var(--sep);
}
.chip small { font-size: 12px; color: var(--hint); margin-left: 4px; }
/* рубрика-добірка («Уцінка», «На подарунок») — помітніша за звичайну категорію */
.chip.col { color: var(--link); box-shadow: 0 0 0 1.5px var(--link); font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); box-shadow: none; font-weight: 600; }
.chip[aria-pressed="true"] small { color: inherit; opacity: .8; }

.bar { display: flex; align-items: center; justify-content: space-between; padding: 7px var(--pad) 0; min-height: 32px; }
.count { font-size: 13px; color: var(--hint); white-space: nowrap; }
@media (max-width: 350px) { .count-tail { display: none; } } /* на найвужчих телефонах — просто «449 товарів» */
.sort { display: inline-flex; align-items: center; gap: 4px; color: var(--link); font-size: 14px; margin-left: auto; }
.sort svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sort select {
  border: 0; outline: 0; background: transparent; color: var(--link); padding: 4px 0; max-width: 190px;
  -webkit-appearance: none; appearance: none; text-align: right;
}
.sort select option { color: #000; background: #fff; }
/* Кнопка теми — малий значок праворуч від сортування: місяць вмикає темну тему, сонце — світлу.
   Сама кнопка не вища за рядок (шапка не росте), зона натискання ширша за значок. */
.theme-btn {
  position: relative; flex: none; width: 30px; height: 27px; margin: 0 -5px 0 8px; padding: 0; border: 0; border-radius: 8px;
  background: transparent; color: var(--hint); display: grid; place-items: center;
}
.sort[hidden] + .theme-btn { margin-left: auto; } /* нічого не знайдено: у рядку лишилась сама кнопка — тримаємо її праворуч */
.theme-btn::after { content: ""; position: absolute; inset: -7px -6px -6px -5px; }
.theme-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-btn .i-sun, :root[data-theme="dark"] .theme-btn .i-moon { display: none; }
:root[data-theme="dark"] .theme-btn .i-sun { display: block; }
.theme-btn:active { opacity: .6; }
.theme-btn:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
@media (hover: hover) { .theme-btn:hover { color: var(--text); } }

/* ───────── сітка товарів ───────── */

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 6px var(--pad) 8px; }
.card {
  display: flex; flex-direction: column; text-align: left; padding: 0; border: 0;
  background: var(--card); color: var(--text); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 0 0 1px var(--sep); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.card:active { opacity: .82; }
.card:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
.card-pic { position: relative; aspect-ratio: 1 / 1; background: #fff; width: 100%; overflow: hidden; }
.card-pic img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .2s; }
.card-pic img.ready { opacity: 1; }
.badge {
  position: absolute; left: 7px; top: 7px; padding: 3px 8px; border-radius: 999px;
  background: rgba(20, 22, 26, .78); color: #fff; font-size: 11px; font-weight: 600; letter-spacing: .1px;
}
.card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.card-title {
  font-size: 13.5px; line-height: 1.28; min-height: calc(1.28em * 3);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
  overflow-wrap: anywhere;
}
.card-foot { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; margin-top: auto; }
.price { font-size: 16.5px; font-weight: 700; white-space: nowrap; letter-spacing: -.1px; }
.price small { font-size: 12.5px; font-weight: 600; margin-left: 2px; }
.qty { font-size: 12px; color: var(--hint); white-space: nowrap; }

.skel { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 0 0 1px var(--sep); }
.skel i { display: block; aspect-ratio: 1 / 1; background: var(--bg2); }
.skel b { display: block; height: 11px; margin: 10px; border-radius: 6px; background: var(--bg2); }
.skel b + b { width: 55%; }

.empty { text-align: center; padding: 56px 28px 40px; }
.empty-title { font-size: 17px; font-weight: 600; }
.empty-text { color: var(--hint); margin: 6px 0 18px; }
.foot { text-align: center; color: var(--hint); font-size: 12px; padding: 10px 16px calc(22px + var(--safe-b)); }
#sentinel { height: 1px; }
/* «Ми на OLX · Ми на Prom» — тихий рядок у самому низу списку й сторінки товару */
.shops { display: flex; justify-content: center; flex-wrap: wrap; gap: 0 20px; margin-top: 4px; font-size: 13px; }
.shops a { color: var(--link); text-decoration: none; padding: 8px 2px; }
.shops a:active { opacity: .7; }
.shops a:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; border-radius: 4px; }
.p-shops { padding: 12px var(--pad) 0; text-align: center; color: var(--hint); font-size: 12px; }
/* години роботи менеджера — рядок над посиланнями, тим самим сірим, що й «Наявність оновлено» */
.contacts .hours { margin-top: 4px; }
/* «Відкрити чат із менеджером» у запасному вікні — посилання на вигляд як кнопка «Закрити» */
.sheet-link { display: flex; align-items: center; justify-content: center; text-decoration: none; }

/* ───────── сторінка товару ───────── */

#product-view { background: var(--bg2); padding-bottom: calc(86px + var(--safe-b)); }
.p-top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px;
  background: var(--bg2); padding: 6px 6px; min-height: 44px;
}
.p-back { display: inline-flex; align-items: center; gap: 2px; border: 0; background: transparent; color: var(--link); font-size: 16px; padding: 8px 8px 8px 4px; border-radius: 10px; }
.p-back svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.in-tg .p-top { display: none; } /* у Telegram «Назад» — рідна кнопка в шапці */

.gal { position: relative; background: #fff; }
.gal-track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.gal-track::-webkit-scrollbar { display: none; }
/* Слайд — квадрат завширшки з екран, але не вищий за 62 % висоти вікна й не більший за 560 px: у широкому вікні (Telegram на
   комп'ютері на весь екран, браузер) галерея не забирає весь екран. Фото лежить поверх слайда й на його розмір не впливає —
   інакше високе фото розтягувало всі слайди, і над квадратним фото лишались білі поля. */
.gal-slide {
  flex: none; position: relative; overflow: hidden; width: 100%; height: min(100vw, 560px, 62vh); min-height: 200px;
  scroll-snap-align: center; scroll-snap-stop: always; background: #fff;
}
.gal-slide img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.gal-count {
  position: absolute; right: 10px; bottom: 10px; padding: 3px 9px; border-radius: 999px;
  background: rgba(20, 22, 26, .62); color: #fff; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.thumbs { display: flex; gap: 6px; overflow-x: auto; padding: 8px var(--pad); background: var(--card); scrollbar-width: none; }
.thumbs::-webkit-scrollbar { display: none; }
.thumb { flex: none; width: 54px; height: 54px; padding: 0; border: 0; border-radius: 9px; overflow: hidden; background: #fff; box-shadow: 0 0 0 1px var(--sep); opacity: .62; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb[aria-current="true"] { opacity: 1; box-shadow: 0 0 0 2px var(--btn); }

.p-block { background: var(--card); padding: 14px var(--pad); margin-top: 8px; }
.p-block.first { margin-top: 0; padding-top: 12px; }
.p-title { font-size: 18px; line-height: 1.28; font-weight: 600; margin: 0 0 10px; overflow-wrap: anywhere; }
.p-price-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.p-price { font-size: 26px; font-weight: 700; letter-spacing: -.3px; }
.p-price small { font-size: 16px; font-weight: 600; margin-left: 3px; }
.p-stock { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font-size: 14px; font-weight: 600; }
.p-stock::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.p-rows { margin: 12px 0 0; padding: 0; }
.p-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 9px 0; border-top: 1px solid var(--sep); font-size: 14.5px; }
.p-row dt { color: var(--hint); flex: none; }
.p-row dd { margin: 0; text-align: right; min-width: 0; overflow-wrap: anywhere; }
.p-code { border: 0; background: transparent; color: var(--link); padding: 0; display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.p-code svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* «Поділитися товаром» — праворуч у рядку з ціною */
.p-share {
  margin-left: auto; flex: none; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 10px;
  background: var(--bg2); color: var(--link); display: inline-flex; align-items: center; justify-content: center;
}
.p-share svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.p-share:active { opacity: .8; }
/* «Доставка й оплата» — кілька рядків від власника */
.p-info { font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
.p-info p { margin: 0 0 6px; }
.p-info p:last-child { margin-bottom: 0; }
.p-h { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--hint); font-weight: 600; margin: 0 0 8px; }
.desc { font-size: 15px; line-height: 1.5; overflow-wrap: anywhere; }
.desc p { margin: 0 0 10px; }
.desc ul, .desc ol { margin: 0 0 10px; padding-left: 20px; }
.desc li { margin: 2px 0; }
.desc u { text-decoration: none; font-weight: 600; }
.desc > :last-child { margin-bottom: 0; }

.buy {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--sep);
  padding: 10px var(--pad) calc(10px + var(--safe-b));
}
.buy-in { max-width: 536px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.buy-price { font-size: 18px; font-weight: 700; white-space: nowrap; }
.buy-price small { font-size: 13px; font-weight: 600; margin-left: 2px; }
.btn-main {
  flex: 1; height: 48px; border: 0; border-radius: 12px; background: var(--btn); color: var(--btn-text);
  font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; width: 100%;
}
.btn-main:active { opacity: .85; }
.btn-main svg { width: 20px; height: 20px; fill: currentColor; }
.btn-soft { height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--link); font-size: 16px; padding: 0 18px; width: 100%; }
.empty .btn-soft { width: auto; background: var(--card); box-shadow: 0 0 0 1px var(--sep); }

/* ───────── обране ───────── */

.btn-fav {
  flex: none; width: 48px; height: 48px; border: 0; border-radius: 12px; background: var(--bg2); color: var(--hint);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-fav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.btn-fav[aria-pressed="true"] { color: #e5484d; }
.btn-fav[aria-pressed="true"] svg { fill: currentColor; }
.btn-fav:active { opacity: .8; }
/* сердечко на картці в списку: клацнув — в обране, клацнув ще раз — прибрав. Зона натискання більша за саме коло. */
.card-fav {
  position: absolute; right: 0; top: 0; width: 44px; height: 44px; padding: 0; border: 0; background: transparent;
  display: grid; place-items: center; color: #8a8f98; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.card-fav::before {
  content: ""; position: absolute; width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255, 255, 255, .94); box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}
.card-fav svg { position: relative; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.card-fav[aria-pressed="true"] { color: #e5484d; }
.card-fav[aria-pressed="true"] svg { fill: currentColor; }
.card-fav:active::before { transform: scale(.9); }
.chip.fav { color: #e5484d; box-shadow: 0 0 0 1.5px #e5484d; font-weight: 600; }
.chip.fav[aria-pressed="true"] { background: #e5484d; color: #fff; box-shadow: none; }
/* у вкладці «Обране» внизу списку — панель «замовити все одним повідомленням» */
#list-view.with-favbar { padding-bottom: calc(76px + var(--safe-b)); }
.fav-sum { flex: none; line-height: 1.25; }
.fav-sum b { display: block; font-size: 17px; white-space: nowrap; }
.fav-sum span { font-size: 12px; color: var(--hint); white-space: nowrap; }

/* «Запитати про товар» — така сама мала кнопка, як сердечко, але кольору посилання */
.btn-ask { color: var(--link); }
.btn-ask svg { stroke-linecap: round; }
/* у нижній панелі тепер дві малі кнопки: трохи щільніше, а на вузьких телефонах «Замовити» без значка */
.buy-in { gap: 8px; }
@media (max-width: 380px) { .buy .btn-main svg { display: none; } .buy .btn-main { padding: 0 10px; } }

/* «Схожі товари» — один рядок, що гортається вбік */
.sim-row {
  display: flex; gap: 8px; overflow-x: auto; margin: 0 calc(-1 * var(--pad)); padding: 0 var(--pad) 2px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.sim-row::-webkit-scrollbar { display: none; }
.sim-card {
  flex: none; width: 132px; padding: 0; border: 0; border-radius: 12px; overflow: hidden; text-align: left;
  background: var(--bg2); color: var(--text); display: flex; flex-direction: column;
}
.sim-card:active { opacity: .82; }
/* overflow: hidden — щоб високе (не квадратне) фото не розтягувало картку: без нього квадрат ставав вищим за сусідні */
.sim-pic { aspect-ratio: 1 / 1; background: #fff; width: 100%; overflow: hidden; }
.sim-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sim-title {
  font-size: 12.5px; line-height: 1.25; margin: 6px 8px 0; min-height: calc(1.25em * 2);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere;
}
.sim-price { font-size: 14.5px; font-weight: 700; padding: 4px 8px 9px; white-space: nowrap; }
.sim-price small { font-size: 12px; font-weight: 600; margin-left: 2px; }

/* «Ви дивились»: кнопка очищення під списком */
.seen-tools { text-align: center; padding: 2px var(--pad) 0; }
.seen-tools .btn-soft { width: auto; height: 40px; font-size: 14.5px; }

/* ───────── нижня шторка й підказка ───────── */

.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-back { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.sheet-body {
  position: relative; width: 100%; max-width: 560px; background: var(--card); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(12px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px;
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-body .btn-main, .sheet-body .btn-soft { flex: none; }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--sep); margin: 0 auto 4px; }
.sheet-title { font-size: 17px; font-weight: 600; }
.sheet-note { font-size: 13.5px; color: var(--hint); }
.sheet-text { margin: 0; padding: 12px; border-radius: 12px; background: var(--bg2); font: inherit; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 60;
  background: rgba(20, 22, 26, .9); color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 14px; white-space: nowrap;
}

@media (min-width: 520px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
