:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111114);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --accent: var(--tg-theme-button-color, #0a84ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #0a84ff);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--hint) 12%, transparent);
  --good: #24a148;
  --warn: #d18b00;
  --radius: 16px;
  --tabbar-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #000; --card: #1c1c1e; --text: #f2f2f7; --hint: #8d8d93;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: var(--text); }
.hidden { display: none !important; }

/* header */
.top { padding: 14px 16px 6px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--text); color: var(--bg); font-weight: 800; font-size: 14px; letter-spacing: -.3px;
}
.brand h1 { margin: 0; font-size: 19px; letter-spacing: -.3px; }
.brand p { margin: 1px 0 0; color: var(--hint); font-size: 13px; }

/* controls */
.controls { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 16px 6px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--soft); border-radius: 10px; padding: 2px; }
.segmented button { padding: 7px 0; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--hint); }
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.search {
  margin-top: 8px; display: flex; align-items: center; gap: 8px; background: var(--card);
  border-radius: 10px; padding: 0 10px;
}
.search svg { width: 16px; height: 16px; stroke: var(--hint); fill: none; stroke-width: 2; flex: none; }
.search input { flex: 1; border: 0; outline: 0; background: transparent; padding: 9px 0; min-width: 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 16px 4px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 12px; border-radius: 999px; background: var(--card); font-size: 14px; white-space: nowrap;
  border: 1px solid transparent;
}
.chip.active { background: var(--accent); color: var(--accent-text); }
.chip small { opacity: .6; margin-left: 4px; }

/* sections & grid */
.section-title { margin: 18px 16px 8px; font-size: 20px; font-weight: 700; letter-spacing: -.3px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 10px; padding: 0 16px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 10px; text-align: left; display: flex;
  flex-direction: column; gap: 4px; min-width: 0; position: relative; transition: transform .12s;
}
.card:active { transform: scale(.97); }
.card .pic { aspect-ratio: 1; border-radius: 12px; background: var(--soft); display: grid; place-items: center; overflow: hidden; }
.card .pic svg { width: 78%; height: 78%; }
.card .pic img, .sheet .pic img { width: 100%; height: 100%; object-fit: cover; }
.card h3 { margin: 6px 0 0; font-size: 15px; font-weight: 600; line-height: 1.25; }
.card .meta { color: var(--hint); font-size: 12.5px; }
.card .price { font-weight: 700; font-size: 16px; margin-top: auto; padding-top: 4px; }
.card .price s, .sheet s { color: var(--hint); font-weight: 400; font-size: 13px; margin-left: 4px; }
.dots { display: flex; gap: 4px; margin-top: 2px; }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); flex: none; }
.tag {
  position: absolute; top: 14px; left: 14px; font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 6px;
  background: #ff3b30; color: #fff;
}
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.pill { font-size: 11.5px; padding: 2px 7px; border-radius: 6px; background: var(--soft); color: var(--text); }
.pill.good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.empty { text-align: center; color: var(--hint); padding: 48px 24px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--sep);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--hint); font-size: 11px; position: relative; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent); }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: #ff3b30; color: #fff; font-size: 11px; line-height: 18px; font-weight: 700;
}

/* sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); animation: fade .2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .25s ease-out;
}
.sheet .grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 10px; }
.sheet .close { position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; border-radius: 50%; background: var(--soft); font-size: 18px; line-height: 30px; color: var(--hint); }
.sheet .pic { width: 100%; max-width: 280px; aspect-ratio: 1; margin: 4px auto 8px; display: grid; place-items: center; border-radius: 20px; overflow: hidden; }
.sheet .pic svg { width: 82%; height: 82%; }
.sheet h2 { margin: 4px 0 2px; font-size: 22px; letter-spacing: -.4px; }
.sheet .sub { color: var(--hint); margin-bottom: 12px; font-size: 14px; }
.opt-label { font-size: 13px; color: var(--hint); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .3px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  padding: 9px 13px; border-radius: 12px; background: var(--card); border: 2px solid transparent; font-size: 14px;
  display: inline-flex; align-items: center; gap: 7px;
}
.opt.active { border-color: var(--accent); }
.opt.na { opacity: .45; }
.opt .dot { width: 16px; height: 16px; }
.buybar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; }
.buybar .total { font-size: 24px; font-weight: 700; letter-spacing: -.4px; }
.buybar .stock { font-size: 12.5px; color: var(--good); }
.btn {
  background: var(--accent); color: var(--accent-text); border-radius: 12px; padding: 14px 18px; font-weight: 600; font-size: 16px;
  text-align: center; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--card); color: var(--accent); }
.btn:disabled { opacity: .5; }
.specs { background: var(--card); border-radius: 14px; margin-top: 14px; }
.specs div { display: flex; justify-content: space-between; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--sep); font-size: 14.5px; }
.specs div:last-child { border-bottom: 0; }
.specs span:first-child { color: var(--hint); }
.specs span:last-child { text-align: right; }
.note { color: var(--hint); font-size: 13px; margin-top: 10px; }

/* forms, lists */
.page { padding: 4px 16px 24px; }
.page h2 { font-size: 24px; letter-spacing: -.4px; margin: 10px 0 4px; }
.page .lead { color: var(--hint); margin: 0 0 14px; }
.group { background: var(--card); border-radius: 14px; overflow: hidden; margin-bottom: 14px; }
.field { display: block; padding: 10px 14px; border-bottom: 1px solid var(--sep); }
.field:last-child { border-bottom: 0; }
.field span { display: block; font-size: 12.5px; color: var(--hint); margin-bottom: 2px; }
.field input, .field select, .field textarea { width: 100%; border: 0; outline: 0; background: transparent; padding: 2px 0; font-size: 16px; }
.field textarea { resize: vertical; min-height: 44px; }
.radio-row { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--sep); }
.cart-item { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--sep); }
.cart-item:last-child { border-bottom: 0; }
.cart-item .pic { width: 54px; height: 54px; border-radius: 10px; background: var(--soft); flex: none; display: grid; place-items: center; overflow: hidden; }
.cart-item .pic svg { width: 80%; height: 80%; }
.cart-item .pic img { width: 100%; height: 100%; object-fit: cover; }
.cart-item .info { flex: 1; min-width: 0; }
.cart-item .info b { display: block; font-size: 14.5px; font-weight: 600; }
.cart-item .info small { color: var(--hint); }
.qty { display: flex; align-items: center; gap: 8px; }
.qty button { width: 28px; height: 28px; border-radius: 50%; background: var(--soft); font-size: 17px; line-height: 28px; }
.summary { display: flex; justify-content: space-between; font-size: 18px; font-weight: 700; padding: 6px 2px 14px; }
.success { text-align: center; padding: 48px 20px; }
.success .big { font-size: 56px; }
.success h2 { margin: 8px 0; }
.list-link { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--sep); text-decoration: none; color: var(--text); width: 100%; text-align: left; }
.list-link:last-child { border-bottom: 0; }
.list-link .ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-size: 16px; background: var(--soft); flex: none; }
.list-link .tx { flex: 1; }
.list-link .tx small { display: block; color: var(--hint); }
.list-link .chev { color: var(--hint); }
.perks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.perk { background: var(--card); border-radius: 14px; padding: 12px; font-size: 13.5px; }
.perk b { display: block; font-size: 20px; margin-bottom: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(30,30,32,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50;
  max-width: calc(100% - 32px); animation: fade .2s;
}
.skeleton { height: 220px; border-radius: var(--radius); background: linear-gradient(90deg, var(--card), var(--soft), var(--card)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }

@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* checkout */
.form-title { font-size: 18px; margin: 6px 0 10px; letter-spacing: -.2px; }
.segmented.big { margin-bottom: 12px; padding: 3px; border-radius: 12px; }
.segmented.big button { padding: 10px 0; font-size: 15px; border-radius: 10px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; }
.field-row .field + .field { border-left: 1px solid var(--sep); }
.field-row .field { border-bottom: 0; }
.field input[type="date"], .field input[type="time"] { min-height: 26px; -webkit-appearance: none; appearance: none; }
.field.invalid span { color: #ff3b30; }
.field.invalid { background: color-mix(in srgb, #ff3b30 8%, transparent); }
.hint-line { color: var(--hint); font-size: 13.5px; margin: 0 2px 8px; }
.notice {
  background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--text); border-radius: 12px;
  padding: 11px 14px; font-size: 14px; margin: -4px 0 14px; line-height: 1.35;
}
.success .specs { margin-top: 18px; }
.success .notice { margin-top: 12px; text-align: left; }

/* Галочка «Сдам устройство в trade-in» (только самовывоз) */
.check-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; cursor: pointer; }
.check-row input { width: 20px; height: 20px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }
.check-row b { display: block; font-weight: 600; }
.check-row small { display: block; color: var(--hint); font-size: 13px; margin-top: 2px; line-height: 1.35; }
#tiBox { border-top: 1px solid var(--sep); }
#tiBox .field-row { border-bottom: 1px solid var(--sep); }
