/* Цвета берутся из темы Telegram (переменные --tg-theme-*), запасные — для светлой/тёмной системы. */
:root {
  --fb-bg: #ffffff; --fb-text: #0f0f10; --fb-hint: #8e8e93; --fb-link: #2481cc;
  --fb-btn: #2481cc; --fb-btn-text: #ffffff; --fb-secondary: #f0f1f5; --fb-destructive: #e5393b;
  --bg: var(--tg-theme-secondary-bg-color, var(--fb-secondary));
  --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));
  --sub: var(--tg-theme-subtitle-text-color, var(--hint));
  --link: var(--tg-theme-link-color, var(--fb-link));
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --btn: var(--tg-theme-button-color, var(--fb-btn));
  --btn-text: var(--tg-theme-button-text-color, var(--fb-btn-text));
  --head: var(--tg-theme-section-header-text-color, var(--hint));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-destructive));
  --sep: var(--tg-theme-section-separator-color, color-mix(in srgb, var(--hint) 25%, transparent));
  --soft: color-mix(in srgb, var(--btn) 12%, transparent);
  --ok: #31b545; --warn: #f0a020;
  --r: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --fb-bg: #1c1c1e; --fb-text: #f2f2f7; --fb-hint: #8d8e93; --fb-link: #5eb5f7;
          --fb-btn: #3e88f7; --fb-secondary: #000000; color-scheme: dark; }
}
:root[data-scheme="dark"] { color-scheme: dark; }
:root[data-scheme="light"] { color-scheme: light; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(72px + var(--safe-b));
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.view { padding: 12px 16px 24px; max-width: 760px; margin: 0 auto; animation: in .18s ease-out; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h1 { font-size: 22px; margin: 6px 2px 12px; font-weight: 700; letter-spacing: -.2px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--head); margin: 20px 4px 8px; font-weight: 600; }
.hint { color: var(--hint); font-size: 13px; }
.muted { color: var(--sub); }

/* --- поиск и вкладки --- */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0 8px; margin: -12px -16px 4px; padding-inline: 16px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 12px; padding: 0 12px; height: 40px; }
.search input { flex: 1; border: 0; outline: 0; background: transparent; height: 100%; min-width: 0; }
.search input::placeholder { color: var(--hint); }
.search .clear { border: 0; background: none; color: var(--hint); font-size: 18px; padding: 0 2px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 10px 0 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 999px; font-weight: 500; white-space: nowrap; transition: background .15s; }
.chip.active { background: var(--btn); color: var(--btn-text); }

/* --- сетка категорий --- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 520px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tile { border: 0; padding: 0; text-align: left; background: var(--card); border-radius: var(--r); overflow: hidden; display: flex; flex-direction: column; transition: transform .1s; }
.tile:active { transform: scale(.97); }
.tile .pic { aspect-ratio: 16 / 10; background: var(--soft); display: grid; place-items: center; font-size: 30px; overflow: hidden; }
.tile .pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .name { padding: 8px 10px 10px; font-size: 14px; font-weight: 500; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: calc(2 * 1.25em + 18px); }
.tile .tag { display: block; font-size: 11px; color: var(--hint); font-weight: 400; margin-top: 2px; }

/* --- секции-карточки в стиле настроек Telegram --- */
.card { background: var(--card); border-radius: var(--r); overflow: hidden; }
.card + .card { margin-top: 10px; }
.pad { padding: 14px 16px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 48px; position: relative; width: 100%; border: 0; background: none; text-align: left; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 1px; background: var(--sep); }
.row .grow { flex: 1; min-width: 0; }
.row .price { font-weight: 600; white-space: nowrap; }
.row .stars { color: var(--hint); font-size: 12px; white-space: nowrap; text-align: right; }
.row .radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--hint); flex: none; display: grid; place-items: center; transition: border-color .15s; }
.row.selected .radio { border-color: var(--btn); }
.row.selected .radio::after { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--btn); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 16px; }
.kv + .kv { border-top: 1px solid var(--sep); }
.kv .k { color: var(--hint); }
.kv .v { text-align: right; word-break: break-all; font-weight: 500; }

.hero { border-radius: var(--r); overflow: hidden; background: var(--soft); aspect-ratio: 16 / 8; display: grid; place-items: center; font-size: 46px; margin-bottom: 12px; }
.hero img { width: 100%; height: 100%; object-fit: cover; }
.note { white-space: pre-line; color: var(--sub); font-size: 14px; }
.note.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.more { border: 0; background: none; color: var(--link); padding: 4px 0 0; font-size: 14px; }

/* --- поля ввода --- */
.field { padding: 10px 16px 12px; }
.field + .field { border-top: 1px solid var(--sep); }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 4px; }
.field input, .field select { width: 100%; border: 0; outline: 0; background: transparent; font-size: 16px; padding: 4px 0; }
.field select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--hint) 50%), linear-gradient(135deg, var(--hint) 50%, transparent 50%); background-position: calc(100% - 12px) 55%, calc(100% - 7px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
.field .status { font-size: 13px; margin-top: 4px; }
.ok { color: var(--ok); } .bad { color: var(--danger); }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 0; border-radius: 8px; font-weight: 500; }
.seg button.active { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.pgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.ptile { border: 2px solid transparent; background: var(--card); border-radius: 12px; padding: 12px 6px; text-align: center; transition: border-color .15s; }
.ptile b { display: block; font-size: 17px; }
.ptile span { font-size: 13px; color: var(--hint); }
.ptile.selected { border-color: var(--btn); }

.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--text); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-top: 10px; }
.total { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px; font-size: 17px; }
.total b { font-size: 22px; }

/* --- заказы --- */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--soft); color: var(--accent); white-space: nowrap; }
.badge.completed { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge.refunded, .badge.needs_refund { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.expired, .badge.awaiting_payment { background: color-mix(in srgb, var(--hint) 16%, transparent); color: var(--hint); }
.code { display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
.code + .code { border-top: 1px solid var(--sep); }
.code .val { flex: 1; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 15px; word-break: break-all; user-select: all; }
.code .lbl { font-size: 12px; color: var(--hint); }
.copy { border: 0; background: var(--soft); color: var(--accent); border-radius: 8px; padding: 6px 10px; font-weight: 600; font-size: 13px; flex: none; }
.big-status { text-align: center; padding: 22px 16px; }
.big-status .e { font-size: 46px; }
.big-status .t { font-size: 18px; font-weight: 600; margin-top: 6px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--soft); border-top-color: var(--btn); border-radius: 50%; animation: spin .8s linear infinite; margin: 8px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 48px 16px; color: var(--hint); }
.empty .e { font-size: 44px; margin-bottom: 8px; }
.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px; background: var(--btn); color: var(--btn-text); font-weight: 600; margin-top: 12px; }
.btn.ghost { background: var(--soft); color: var(--accent); }

.skel { background: linear-gradient(90deg, var(--card) 0%, color-mix(in srgb, var(--hint) 12%, var(--card)) 50%, var(--card) 100%); background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: var(--r); }
@keyframes sh { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* --- нижнее меню и уведомления --- */
#tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--sep); padding-bottom: var(--safe-b); }
#tabbar button { flex: 1; border: 0; background: none; padding: 8px 0 7px; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; color: var(--hint); font-weight: 500; }
#tabbar button .ico { font-size: 21px; filter: grayscale(1); opacity: .7; }
#tabbar button.active { color: var(--btn); }
#tabbar button.active .ico { filter: none; opacity: 1; }
#toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%); z-index: 20; background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--card); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); text-align: center; }
@media (prefers-reduced-motion: reduce) { .view, .tile, .skel, .spinner { animation: none; transition: none; } }
