:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --sec-bg: var(--tg-theme-secondary-bg-color, #f2f3f6);
  --text: var(--tg-theme-text-color, #1a1d21);
  --hint: var(--tg-theme-hint-color, #8b919a);
  --link: var(--tg-theme-link-color, #2f7bef);
  --btn: var(--tg-theme-button-color, #2f7bef);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: #f2a33a;
  --ok: #34a853;
  --line: rgba(128,128,128,.16);
  --r: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--sec-bg); color: var(--text);
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0));
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* --- шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { min-width: 0; }
.shop-title { font-weight: 800; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shop-sub { font-size: 12px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.balance-chip {
  flex: none; border: none; cursor: pointer;
  background: var(--btn); color: var(--btn-text);
  font-weight: 700; font-size: 14px; padding: 8px 14px; border-radius: 999px;
}
.balance-chip { display: inline-flex; align-items: center; gap: 6px; }

main { padding: 12px 12px 24px; max-width: 640px; margin: 0 auto; }

/* --- поиск и категории --- */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px;
}
.search input { flex: 1; border: none; background: transparent; color: var(--text); font-size: 15px; outline: none; }
.search input::placeholder { color: var(--hint); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: none; cursor: pointer;
  background: var(--bg); color: var(--text); font-weight: 600; font-size: 13px;
  padding: 8px 14px; border-radius: 999px;
}
.chip.active { background: var(--btn); color: var(--btn-text); }

/* --- сетка товаров --- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.pcard {
  background: var(--bg); border-radius: var(--r); overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; position: relative;
  transition: transform .12s ease;
}
.pcard:active { transform: scale(.98); }
.pimg {
  aspect-ratio: 1 / 1; width: 100%; object-fit: cover; display: block;
  background: linear-gradient(135deg, #ffe7b8, #ffc98a);
}
.pimg.ph { display: grid; place-items: center; color: rgba(0,0,0,.35); }
.badge {
  position: absolute; top: 8px; left: 8px;
  background: var(--accent); color: #1a1d21; font-weight: 800; font-size: 11px;
  padding: 4px 8px; border-radius: 8px; letter-spacing: .02em;
}
.badge.out { background: rgba(0,0,0,.6); color: #fff; }
.pbody { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.ptitle { font-weight: 700; font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pprice { margin-top: auto; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.pprice b { font-size: 16px; }
.pprice s { color: var(--hint); font-size: 12px; }
.pstock { font-size: 11px; color: var(--hint); }

.empty { text-align: center; color: var(--hint); padding: 48px 16px; line-height: 1.5; }
.skeleton-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.sk { aspect-ratio: 1 / 1.45; border-radius: var(--r); background: var(--bg); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* --- покупки --- */
.card { background: var(--bg); border-radius: var(--r); padding: 14px 16px; margin-bottom: 10px; }
.order-head { display: flex; gap: 12px; align-items: center; }
.order-head img, .order-head .ph { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; flex: none; background: linear-gradient(135deg, #ffe7b8, #ffc98a); display: grid; place-items: center; color: rgba(0,0,0,.35); }
.order-head .ot { flex: 1; min-width: 0; }
.order-head .ot b { display: block; font-size: 14px; }
.order-head .ot span { font-size: 12px; color: var(--hint); }
.ocontent {
  margin-top: 10px; padding: 10px 12px; background: var(--sec-bg); border-radius: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px;
  white-space: pre-wrap; word-break: break-word; max-height: 160px; overflow-y: auto;
}

/* --- профиль --- */
.profile-head { text-align: center; padding: 10px 0 16px; }
.profile-head .name { font-size: 20px; font-weight: 800; }
.profile-head .bal { font-size: 36px; font-weight: 800; margin-top: 4px; letter-spacing: -.02em; }
.profile-head .bal small { font-size: 18px; font-weight: 700; color: var(--hint); }
.profile-head .uid { color: var(--hint); font-size: 12px; margin-top: 2px; }
.section-title { font-size: 12px; text-transform: uppercase; color: var(--hint); letter-spacing: .06em; margin: 18px 4px 8px; font-weight: 700; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.kv:first-child { border-top: none; }
.kv span { color: var(--hint); }
.reflink { font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; background: var(--sec-bg); padding: 10px 12px; border-radius: 10px; margin-top: 8px; }
.legal { text-align: center; margin: 22px 0 6px; font-size: 13px; }
.legal a { color: var(--hint); }

/* --- кнопки --- */
button.primary {
  width: 100%; border: none; cursor: pointer;
  background: var(--btn); color: var(--btn-text);
  border-radius: 12px; padding: 14px; font-size: 16px; font-weight: 700;
}
button.secondary {
  width: 100%; border: none; cursor: pointer;
  background: var(--sec-bg); color: var(--link);
  border-radius: 12px; padding: 12px; font-size: 14px; font-weight: 700; margin-top: 8px;
}
button.copy {
  display: block; width: 100%; margin: 10px 0 0; border: none; cursor: pointer;
  background: var(--sec-bg); color: var(--link);
  border-radius: 10px; padding: 11px; font-size: 14px; font-weight: 600;
}
button:disabled { opacity: .5; }

/* --- нижняя навигация --- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; background: var(--bg); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab { flex: 1; background: none; border: none; color: var(--hint); padding: 8px 0 10px; font-size: 11px; font-weight: 600; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tab .ti { width: 22px; height: 22px; }
.tab.active { color: var(--link); }

/* --- шторка --- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop[hidden] { display: none; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 12px 18px calc(24px + env(safe-area-inset-bottom, 0));
  animation: up .22s ease;
}
.sheet::before { content: ""; display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 14px; }
@keyframes up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .sk { animation: none; } }
.sheet h3 { margin: 0 0 4px; font-size: 20px; line-height: 1.2; }
.sheet .sub { color: var(--hint); font-size: 14px; margin: 0 0 14px; }
.sheet .desc { font-size: 14px; line-height: 1.5; white-space: pre-wrap; margin: 0 0 14px; }
.hero { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 14px; margin-bottom: 12px; display: block; background: linear-gradient(135deg, #ffe7b8, #ffc98a); }
.hero.ph { display: grid; place-items: center; color: rgba(0,0,0,.35); }
.pricebig { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.pricebig b { font-size: 24px; }
.pricebig s { color: var(--hint); }

.qty { display: flex; align-items: center; gap: 0; background: var(--sec-bg); border-radius: 12px; overflow: hidden; }
.qty button { width: 44px; height: 44px; border: none; background: transparent; color: var(--text); font-size: 22px; cursor: pointer; }
.qty span { min-width: 40px; text-align: center; font-weight: 700; font-size: 16px; }
.line { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0; }
.line label { font-size: 14px; font-weight: 600; }
.promo { display: flex; gap: 8px; margin: 6px 0 12px; }
.promo input { flex: 1; border: 1px solid var(--line); background: var(--sec-bg); color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 15px; text-transform: uppercase; }
.promo button { border: none; background: var(--sec-bg); color: var(--link); font-weight: 700; border-radius: 12px; padding: 0 16px; cursor: pointer; }
.total { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 0; border-top: 1px solid var(--line); margin-bottom: 6px; }
.total b { font-size: 20px; }
.total .disc { color: var(--ok); font-size: 13px; font-weight: 600; }

.method {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  background: var(--sec-bg); border: none; border-radius: 12px; padding: 13px 16px; margin-bottom: 8px;
  font-size: 15px; font-weight: 700; color: var(--text);
}
.method .ic { width: 28px; display: grid; place-items: center; color: var(--link); }
.method .ic svg { width: 22px; height: 22px; }
.method .mt { flex: 1; }
.method .mh { display: block; font-weight: 400; font-size: 12px; color: var(--hint); }
.method.dis { opacity: .45; }
.amount-input {
  width: 100%; border: 1px solid var(--line); background: var(--sec-bg); color: var(--text);
  border-radius: 12px; padding: 14px 16px; font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 10px;
}
.quick { display: flex; gap: 8px; margin-bottom: 14px; }
.quick button { flex: 1; border: none; background: var(--sec-bg); color: var(--text); border-radius: 10px; padding: 10px 0; font-weight: 700; cursor: pointer; }
.reqs { background: var(--sec-bg); border-radius: 12px; padding: 12px 14px; font-size: 15px; line-height: 1.7; margin-bottom: 12px; }
.note { color: var(--hint); font-size: 13px; margin: 10px 2px 0; line-height: 1.45; }
.spinner { width: 28px; height: 28px; margin: 8px auto 18px; border: 3px solid var(--line); border-top-color: var(--btn); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.agreement { max-height: 55vh; overflow-y: auto; white-space: pre-wrap; font-size: 13px; line-height: 1.5; background: var(--sec-bg); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }

/* --- иконки --- */
svg.i { width: 1.1em; height: 1.1em; vertical-align: -0.2em; flex: none; }
.empty svg.i { color: var(--hint); margin-bottom: 8px; }
button.primary svg.i, button.secondary svg.i, button.copy svg.i { margin-right: 4px; }
.search svg.i { color: var(--hint); }
h3.ok svg.i { color: var(--ok); }
.sheet h3 svg.i { vertical-align: -0.15em; margin-right: 2px; }

/* ============================= АДМИНКА ============================= */
.adbar { display: flex; align-items: center; gap: 10px; margin: 2px 2px 14px; }
.adbar b { font-size: 18px; }
.adback, .adlogo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; border: none; background: var(--bg); color: var(--text); cursor: pointer; }
.adlogo { color: var(--link); }
.adback svg.i, .adlogo svg.i { width: 20px; height: 20px; }
.adsub { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--hint); font-weight: 700; margin: 18px 4px 8px; }
.adgrid2 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.adtile { background: var(--bg); border-radius: 12px; padding: 12px 10px; text-align: center; }
.adtile b { display: block; font-size: 16px; font-weight: 800; }
.adtile span { font-size: 11px; color: var(--hint); }
.admenu { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.adcell { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; background: var(--bg); border: none; border-radius: 14px; padding: 18px 10px; cursor: pointer; color: var(--text); font-weight: 700; font-size: 14px; }
.adcell .adci { color: var(--link); }
.adcell .adci svg.i { width: 26px; height: 26px; }
.adbadge { position: absolute; top: 8px; right: 8px; background: var(--accent); color: #1a1d21; font-size: 11px; font-weight: 800; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }
.adrow { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--bg); border: none; border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer; color: var(--text); }
.adrow.static { cursor: default; }
.adthumb { width: 44px; height: 44px; border-radius: 10px; overflow: hidden; flex: none; background: var(--sec-bg); display: grid; place-items: center; color: var(--hint); }
.adthumb img { width: 100%; height: 100%; object-fit: cover; }
.adrt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.adrt b { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adrt span { font-size: 12px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adrt span.mono { font-family: ui-monospace, Menlo, monospace; }
.adci { width: 40px; height: 40px; border-radius: 10px; background: var(--sec-bg); display: grid; place-items: center; flex: none; color: var(--link); }
.adci.st-delivered { color: var(--ok); } .adci.st-canceled, .adci.st-refunded { color: #e5354b; } .adci.st-pending { color: var(--accent); }
.adchev { color: var(--hint); flex: none; }
.off { display: inline-block; font-size: 11px; font-weight: 700; color: #e5354b; background: rgba(229,53,75,.12); padding: 1px 6px; border-radius: 6px; vertical-align: middle; }
.iconbtn { border: none; background: var(--sec-bg); color: var(--text); width: 38px; height: 38px; border-radius: 10px; cursor: pointer; flex: none; display: grid; place-items: center; }
.iconbtn.danger { color: #e5354b; }
.hintt { font-size: 12px; color: var(--hint); }
.linkbtn { border: none; background: none; color: var(--link); font-weight: 600; font-size: 13px; cursor: pointer; padding: 0; }

/* формы */
.fl { display: block; font-size: 13px; font-weight: 700; margin: 12px 2px 6px; }
.fl .fh { font-weight: 400; color: var(--hint); }
.fi { width: 100%; border: 1px solid var(--line); background: var(--sec-bg); color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 15px; font-family: inherit; }
.fi.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
textarea.fi { resize: vertical; }
select.fi { appearance: none; }
.frow { display: flex; gap: 10px; }
.frow > div { flex: 1; min-width: 0; }
.photobox { width: 100%; aspect-ratio: 16/9; border-radius: 14px; border: 2px dashed var(--line); background: var(--sec-bg); display: grid; place-items: center; cursor: pointer; overflow: hidden; position: relative; margin-bottom: 6px; }
.photobox img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photobox .phadd, .photobox .phedit { position: relative; z-index: 1; color: var(--hint); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.photobox .phedit { background: rgba(0,0,0,.55); color: #fff; padding: 6px 12px; border-radius: 999px; }
.stockbar { display: flex; align-items: center; justify-content: space-between; margin: 8px 2px 0; font-size: 13px; }
.switch { display: flex; align-items: center; gap: 10px; margin: 14px 2px; font-size: 15px; font-weight: 600; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--btn); }
button.danger { width: 100%; border: none; cursor: pointer; background: rgba(229,53,75,.12); color: #e5354b; border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 700; margin-top: 8px; }
button.ok { flex: 1; border: none; cursor: pointer; background: var(--ok); color: #fff; border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 700; }
.frow button.danger { margin-top: 0; }
