:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #7d828c);
  --link: var(--tg-theme-link-color, #2a7ae2);
  --accent: var(--tg-theme-button-color, #2a7ae2);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --kr: #1f5bb5;
  --jp: #c8322f;
  --r-lg: 14px;
  --r-sm: 8px;
  --top: var(--tg-content-safe-area-inset-top, 0px);
  --bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
  color-scheme: light dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--bottom) + 16px);
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- список ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 8px; padding: calc(var(--top) + 10px) 12px 8px;
  background: var(--bg2);
}
.bar input {
  flex: 1; min-width: 0; height: 40px; padding: 0 14px;
  border: 0; border-radius: 20px; background: var(--bg);
}
.bar-btn {
  position: relative; width: 40px; height: 40px; flex: none;
  display: grid; place-items: center; border: 0; border-radius: 20px; background: var(--bg);
}
.badge {
  position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-text);
  font-size: 11px; line-height: 18px; font-weight: 600;
}
.tabs { display: flex; gap: 6px; padding: 0 12px 6px; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  flex: none; height: 32px; padding: 0 14px; border: 0; border-radius: 16px;
  background: transparent; color: var(--hint); font-weight: 500;
}
.tabs button.on { background: var(--bg); color: var(--text); }
.meta {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 16px 10px; color: var(--hint); font-size: 13px;
}
.meta select { border: 0; background: transparent; color: var(--link); font-size: 13px; text-align: right; }

.grid {
  display: grid; gap: 8px; padding: 0 8px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.card {
  position: relative; display: flex; flex-direction: column;
  background: var(--bg); border-radius: var(--r-lg); overflow: hidden;
  border: 0; padding: 0; text-align: left;
}
.card .ph { position: relative; aspect-ratio: 4 / 3; background: var(--line); }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .cnt {
  position: absolute; left: 6px; bottom: 6px; padding: 1px 6px; border-radius: 6px;
  background: rgba(0,0,0,.55); color: #fff; font-size: 11px;
}
.card .body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.price { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.card .title { font-size: 13px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .specs { font-size: 12px; color: var(--hint); }
.fav {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px;
  border: 0; border-radius: 16px; background: rgba(0,0,0,.35); color: #fff;
  display: grid; place-items: center;
}
.fav.on { color: #ff4d5e; background: rgba(255,255,255,.9); }
.origin {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--hint);
}
.origin::before { content: ""; width: 3px; height: 12px; border-radius: 2px; background: var(--hint); }
.origin.kr::before { background: var(--kr); }
.origin.jp::before { background: var(--jp); }
.origin.cn::before { background: #d9a400; }

.skel { background: var(--bg); border-radius: var(--r-lg); aspect-ratio: 3 / 4; opacity: .6; }
.empty { text-align: center; color: var(--hint); padding: 40px 24px; }
.more { height: 60px; }

/* ---------- карточка авто ---------- */
#detail-view { background: var(--bg); min-height: 100vh; padding-bottom: 90px; }
.gallery {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  aspect-ratio: 4 / 3; background: #000; margin-top: var(--top);
}
.gallery img { flex: none; width: 100%; height: 100%; object-fit: contain; scroll-snap-align: center; }
.gal-wrap { position: relative; }
.gal-count {
  position: absolute; right: 10px; bottom: 10px; padding: 2px 8px; border-radius: 10px;
  background: rgba(0,0,0,.6); color: #fff; font-size: 12px;
}
.d-body { padding: 14px 16px; }
.d-body h1 { font-size: 20px; line-height: 1.25; margin: 6px 0 10px; font-weight: 600; }
.d-price { font-size: 30px; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.d-note { color: var(--hint); font-size: 13px; margin-top: 2px; }
.specs-table { width: 100%; border-collapse: collapse; margin: 18px 0; }
.specs-table td { padding: 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.specs-table td:first-child { color: var(--hint); width: 45%; }
.d-body h2 { font-size: 16px; margin: 20px 0 10px; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opts span { padding: 5px 10px; border-radius: var(--r-sm); background: var(--bg2); font-size: 13px; }
.d-actions { display: flex; gap: 8px; margin-top: 22px; }
.d-actions a, .d-actions button {
  flex: 1; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: transparent; color: var(--link); display: grid; place-items: center;
  text-decoration: none; font-weight: 500;
}
.raw { white-space: pre-wrap; color: var(--hint); font-size: 13px; }
.back-fallback {
  position: fixed; left: 12px; top: calc(var(--top) + 12px); z-index: 6;
  height: 34px; padding: 0 12px; border-radius: 17px; border: 0;
  background: rgba(0,0,0,.55); color: #fff;
}
.fixed-cta {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(var(--bottom) + 10px);
  background: var(--bg); border-top: 1px solid var(--line);
}

/* ---------- шторки ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 88vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding-bottom: calc(var(--bottom) + 12px);
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 6px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 4px 16px 12px; }
.link { border: 0; background: none; color: var(--link); }
.fld { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; color: var(--hint); font-size: 13px; }
.fld input, .fld textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 0;
  background: var(--bg2); color: var(--text); font-size: 15px; resize: vertical;
}
.range { display: flex; gap: 8px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills button {
  height: 32px; padding: 0 12px; border-radius: 16px; border: 0;
  background: var(--bg2); color: var(--text); font-size: 13px;
}
.pills button small { color: var(--hint); margin-left: 4px; }
.pills button.on { background: var(--accent); color: var(--accent-text); }
.pills button.on small { color: inherit; opacity: .75; }
.btn-main {
  margin: 4px 16px 0; height: 48px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 16px;
}
.btn-main:disabled { opacity: .6; }
.lead-car { margin: 0 0 4px; font-weight: 500; }
.error { color: #e0413b; font-size: 13px; margin: 4px 0; }
