/* Цвета — из темы Telegram (светлая и тёмная приходят сами). Запасные значения — для обычного
   браузера; тёмная тема браузера — ниже, в prefers-color-scheme. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #7d8590);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --ok: #1f9d55;
  --warn: #d98a00;
  --bad: #d64545;
  --radius: 14px;
  --gap: 12px;
  --nav: calc(60px + env(safe-area-inset-bottom)); /* высота нижней панели */
  --tap: 48px; /* меньше палец промахивается */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17191c);
    --bg2: var(--tg-theme-secondary-bg-color, #22262b);
    --text: var(--tg-theme-text-color, #eef0f2);
    --hint: var(--tg-theme-hint-color, #8b949e);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding-bottom: calc(var(--nav) + 76px); /* нижняя панель и закреплённая кнопка над ней */
  overflow-wrap: break-word; /* длинное слово или ссылка не растягивает страницу вбок */
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg2);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%; /* iPhone не укрупняет текст сам при повороте экрана */
}

h2, h3, p { margin: 0 0 8px; }
small { font-size: 13px; }

/* --- нижняя панель и «Управление» --- */

.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; height: var(--nav); padding-bottom: env(safe-area-inset-bottom); background: var(--bg); border-top: 1px solid var(--line); }
.tab { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 6px 2px; border-radius: 0; background: none; color: var(--hint); font-size: 11px; font-weight: 600; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.active { color: var(--accent); }
.menu { display: grid; gap: 8px; }
.menu-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 14px 16px; background: var(--bg); color: var(--text); border-radius: var(--radius); text-align: left; font-size: 17px; }
.menu-item small { font-size: 13px; }

.page { padding: var(--gap) 0; }
.pad { padding: 0 16px; }

/* --- кнопки и поля --- */

button { font: inherit; cursor: pointer; border-radius: 10px; padding: 10px 16px; border: 0; min-height: var(--tap); }
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.secondary { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 600; }
.ghost { background: none; color: var(--link); padding: 6px 8px; }
.link { background: none; color: var(--link); padding: 8px 4px; }
.danger { color: var(--bad); }
.wide { width: 100%; padding: 14px; font-size: 17px; }
/* «Оплатить» в корзине — заметнее всего на экране: крупно, зелёным, с тенью. */
.pay:disabled { opacity: .6; }
.pay { display: block; width: 100%; min-height: 68px; padding: 18px; border-radius: var(--radius); background: var(--ok); color: #fff; font-size: 22px; font-weight: 700; box-shadow: 0 6px 16px color-mix(in srgb, var(--ok) 35%, transparent); }
/* «Оплатить» закреплена над нижней панелью — и в Telegram тоже (не как .actionbar). */
.paybar { position: fixed; left: 0; right: 0; bottom: var(--nav); z-index: 5; padding: 10px 16px; background: var(--bg); border-top: 1px solid var(--line); }
.back { background: none; color: var(--link); padding: 8px 16px; }
button:active { opacity: .7; }

/* font-size 16px — не меньше: iPhone (Safari и Telegram) увеличивает страницу при нажатии на поле
   с шрифтом мельче и обратно не уменьшает. Подписи форм — 14px, поэтому inherit не годится. */
input, select, textarea { width: 100%; min-height: var(--tap); margin-top: 6px; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.form { display: grid; gap: 14px; }
.form label { font-weight: 600; font-size: 14px; }
.form small { font-weight: 400; }

/* --- каталог --- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--gap); padding: 0 16px; }
.card { background: var(--bg); border-radius: var(--radius); overflow: hidden; cursor: pointer; box-shadow: 0 1px 2px rgb(0 0 0 / 6%); transition: transform .12s; }
.card:active { transform: scale(.98); }
.thumb { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--bg2); }
.noimg { display: grid; place-items: center; color: var(--hint); background: var(--bg2); }
.card-body { padding: 10px 12px 12px; }
.title { font-size: 15px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
h2.title { font-size: 20px; -webkit-line-clamp: 3; }
.price { font-weight: 700; margin: 4px 0 0; }
.price.big { font-size: 24px; margin: 4px 0 12px; }

/* --- карточка товара --- */

.gallery { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 4px; margin-bottom: 12px; scrollbar-width: none; }
.gallery .photo { flex: 0 0 100%; width: 100%; aspect-ratio: 1; object-fit: cover; scroll-snap-align: center; }
#page > .noimg { aspect-ratio: 2; margin: 0 16px 12px; border-radius: var(--radius); }
.panel { background: var(--bg); border-radius: var(--radius); padding: 14px 16px; margin-bottom: var(--gap); }
.text { white-space: pre-line; }
.delivery-photo { display: block; width: 100%; margin-top: 8px; border-radius: 10px; }
.actionbar { position: fixed; left: 0; right: 0; bottom: var(--nav); z-index: 5; padding: 10px 16px; background: var(--bg); border-top: 1px solid var(--line); }
/* В Telegram вместо своих «← назад» и закреплённой кнопки — его родные (app.js). */
.tg .back, .tg .actionbar { display: none; }
.tg body { padding-bottom: calc(var(--nav) + 16px); }
body:has(.paybar) { padding-bottom: calc(var(--nav) + 96px); } /* чтобы конец корзины не прятался под кнопкой */

/* --- оформление и оплата --- */

.label { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--hint); margin: 16px 0 8px; }
.panel > .label:first-child { margin-top: 0; }
.coins { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.coin { display: flex; align-items: center; gap: 10px; padding: 12px; background: var(--bg); border: 2px solid transparent; border-radius: var(--radius); cursor: pointer; }
.coin input { position: absolute; opacity: 0; width: 0; height: 0; min-height: 0; }
.coin:has(input:checked) { border-color: var(--accent); }
.coin:has(input:focus-visible) { outline: 2px solid var(--accent); }
.coin-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: #fff; font-weight: 700; flex: none; }
.c-btc { background: #f7931a; }
.c-ltc { background: #345d9d; }
.c-eth { background: #627eea; }
.c-trx { background: #ec0928; }
.amount { font-size: 26px; font-weight: 700; margin: 0; }
.address { padding: 12px; margin: 4px 0 10px; background: var(--bg2); border-radius: 10px; font-size: 14px; }
.qr { display: block; width: min(240px, 100%); margin: 8px auto 10px; border-radius: 8px; }
.notes { margin: 12px 0 0; padding-left: 18px; font-size: 14px; }
.notes li { margin-bottom: 4px; }
.pickup { border-left: 4px solid var(--ok); }
.pick { margin-bottom: 12px; }
.pick p { margin: 0 0 6px; }

/* --- списки --- */

.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 8px; background: var(--bg); border-radius: var(--radius); cursor: pointer; }
.item > div:first-child, .grow { flex: 1; min-width: 0; }
.item p { margin: 2px 0 0; }
.mini { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; flex: none; }
.badge { display: inline-block; flex: none; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--bg2); color: var(--hint); }
.s-available, .s-paid, .s-ready, .s-free { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.s-awaiting_payment, .s-reserved, .s-check { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.s-needs_review, .s-refunded { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.empty { text-align: center; padding: 40px 16px; color: var(--hint); }
.empty .noimg { width: 72px; height: 72px; margin: 0 auto 12px; border-radius: 50%; }

/* --- главная --- */

.hero { text-align: center; }
.hero .logo { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; margin: 4px auto 10px; display: block; }
.hero .text { margin-bottom: 14px; }
.block-img { display: block; width: calc(100% + 32px); margin: -14px -16px 12px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius) var(--radius) 0 0; }
.block .text { margin-bottom: 10px; }
a.button { display: inline-block; padding: 10px 16px; border-radius: 10px; text-decoration: none; text-align: center; }

/* --- корзина и варианты --- */

.qty-input { width: 90px; }
.qty-input { margin: 6px 0 0; flex: none; }

/* --- обращения --- */

.message { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 8px; max-width: 90%; }
.message .hint { margin: 0 0 4px; font-size: 12px; }
.message .text { margin: 0; }
.from-buyer { background: var(--bg); }
.from-shop { background: color-mix(in srgb, var(--accent) 12%, var(--bg)); margin-left: auto; }

/* --- админка --- */

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filters label { font-weight: 600; font-size: 14px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 400; }
.check input { width: 22px; height: 22px; min-height: 0; margin: 0; flex: none; }
.variant { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; align-items: center; }
.variant input { margin: 0; }
.variant .check { grid-column: 1 / -1; }

/* Плитки фото (_tiles.html): 2 в ряд, квадратные. Нажатие на фото — отметить на удаление
   (полупрозрачное, значок ↺ — передумать), «＋ Фото» — выбрать; превью рисует app.js. */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.tiles img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; }
/* Фото места на весь экран (app.js): целиком, на чёрном, поверх нижней панели; дальше — пальцами. */
.tiles img.zoom { cursor: zoom-in; }
.tiles img.zoomed { position: fixed; inset: 0; z-index: 20; width: 100%; height: 100%; aspect-ratio: auto; object-fit: contain; border-radius: 0; background: #000; cursor: zoom-out; touch-action: none; }
.tile { position: relative; display: grid; place-items: center; aspect-ratio: 1; overflow: hidden; border: 1px dashed var(--line); border-radius: 10px; background: var(--bg2) center / cover no-repeat; color: var(--link); font-weight: 600; cursor: pointer; }
.tile[hidden] { display: none; }
.tile input { position: absolute; width: 0; height: 0; min-height: 0; margin: 0; opacity: 0; }
.tile img { position: absolute; inset: 0; height: 100%; border-radius: 0; }
.tile.picked { border-style: solid; } /* фото выбрано, превью может прийти позже */
.tile.chosen span { visibility: hidden; }
.tile-mark { position: absolute; top: 6px; right: 6px; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: rgb(0 0 0 / .55); color: #fff; font-size: 18px; }
.tile-mark::before { content: "×"; }
.tile:has(input:checked) img { opacity: .3; }
.tile:has(input:checked) .tile-mark::before { content: "↺"; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* --- общее --- */

.row { display: flex; align-items: center; gap: 8px; }
.row > * { min-width: 0; } /* поле в строке сжимается, а не выталкивает кнопки за экран */
.row input { margin: 0; }
.row > input { flex: 1; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.hint { color: var(--hint); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.break { word-break: break-all; }
.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; }
.alert.error { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.alert.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.env-badge { position: fixed; top: 0; right: 0; z-index: 10; padding: 2px 8px; font-size: 11px; font-weight: 700; background: #f5a623; color: #000; border-bottom-left-radius: 8px; }

/* Загрузка: полоска сверху, пока идёт запрос; скелетоны — пока грузится первая страница. */
.progress { position: fixed; top: 0; left: 0; height: 2px; width: 0; z-index: 20; background: var(--accent); }
body.loading .progress { width: 80%; transition: width 2s ease-out; }
.skeleton { height: 120px; margin: 12px 16px; border-radius: var(--radius); background: linear-gradient(90deg, var(--bg) 25%, var(--bg2) 50%, var(--bg) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.districts { border: 0; padding: 0; margin: 8px 0 0; }
.districts legend { padding: 0; font-size: 14px; color: var(--hint); }
.place-filter { margin-bottom: var(--gap); }
.c-usdt { background: #26a17b; }
.c-doge { background: #c2a633; }
