*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #edeef0;
  --card: #fff;
  --text: #1a1a2e;
  --text2: #818c99;
  --accent: #2688eb;
  --border: #e1e3e6;
  --green: #4bb34b;
  --r: 12px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

html {
  font-family: -apple-system, system-ui, 'Helvetica Neue', Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: contain;
}

img { max-width: 100%; display: block; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; -webkit-appearance: none; }
input { font: inherit; color: inherit; -webkit-appearance: none; }

/* ─── Toolbar ─── */
.toolbar {
  background: var(--card);
  padding: calc(10px + var(--sat)) 12px 8px;
  position: sticky;
  top: 0;
  z-index: 49;
  border-bottom: 1px solid var(--border);
}

.search {
  display: flex;
  align-items: center;
  background: var(--bg);
  border-radius: 10px;
  padding: 0 12px;
  gap: 8px;
}
.search__icon { width: 18px; height: 18px; color: var(--text2); flex-shrink: 0; }
.search__input {
  flex: 1; border: none; outline: none; background: none;
  padding: 10px 0; font-size: 15px;
}
.search__input::placeholder { color: #b0b5bd; }
.search__clear {
  width: 24px; height: 24px; padding: 0; color: var(--text2);
  display: flex; align-items: center; justify-content: center;
}
.search__clear svg { width: 18px; height: 18px; }

.chips { display: flex; gap: 8px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 14px; border-radius: 20px; font-size: 13px;
  font-weight: 500; background: var(--bg); white-space: nowrap;
}
.chip--sort { color: var(--accent); }
.chip--filter { color: var(--text); }
.chip--active { background: var(--accent); color: #fff !important; }
.chip__count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; border-radius: 9px;
  background: #fff; color: var(--accent);
  font-size: 11px; font-weight: 700;
  padding: 0 4px;
}
.chip--active .chip__count { background: rgba(255,255,255,0.3); color: #fff; }

/* ─── Active filter tags ─── */
.active-tags {
  display: flex; gap: 6px; margin-top: 8px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; padding-bottom: 2px;
}
.active-tags::-webkit-scrollbar { display: none; }
.active-tag {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 14px;
  font-size: 12px; font-weight: 500;
  background: #e3f0fd; color: var(--accent);
}
.active-tag svg { opacity: 0.6; }

/* ─── Car List (tile grid) ─── */
.car-list {
  padding: 6px 6px 80px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

/* ─── Car Card (tile) ─── */
.car-card {
  background: var(--card);
  border-radius: var(--r);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.car-card:active { opacity: 0.88; }

.car-card__img-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--bg);
  overflow: hidden;
}
.car-card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.car-card__overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 8px 7px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  color: #fff;
}
.car-card__overlay-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.car-card__overlay-specs {
  font-size: 10px;
  opacity: 0.85;
  margin-top: 2px;
  line-height: 1.3;
}

.car-card__tag {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
}
.car-card__tag--new {
  background: var(--green);
  right: auto;
  left: 6px;
}
.car-card__photos {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 10px;
  color: #fff;
  background: rgba(0,0,0,0.5);
}

.car-card__body {
  padding: 8px 8px 10px;
}
.car-card__price {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.car-card__country {
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
  margin-top: 2px;
}

/* ─── Loader ─── */
.loader { display: flex; justify-content: center; padding: 24px 0; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Empty ─── */
.empty { text-align: center; padding: 60px 20px; }
.empty__title { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.empty__sub { font-size: 14px; color: var(--text2); margin-bottom: 20px; }
.empty__btn {
  padding: 12px 32px; border-radius: 22px;
  background: var(--accent); color: #fff;
  font-size: 15px; font-weight: 600;
}

/* ─── Sheet (bottom sheet) ─── */
.sheet { position: fixed; inset: 0; z-index: 200; }
.sheet__overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.4); animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } }
.sheet__body {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--card); border-radius: 16px 16px 0 0;
  padding: 20px 16px calc(20px + var(--sab));
  animation: slideUp 0.25s ease-out;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
@keyframes slideUp { from { transform: translateY(100%); } }
.sheet__header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.sheet__title { font-size: 17px; font-weight: 700; }
.sheet__reset {
  font-size: 14px; color: var(--accent); font-weight: 500;
}
.sheet__option {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0; font-size: 15px;
  border-bottom: 1px solid var(--bg); cursor: pointer;
}
.sheet__option input[type=radio] { width: 20px; height: 20px; accent-color: var(--accent); }

/* ─── Filter sheet ─── */
.sheet__body--filters {
  padding-bottom: calc(80px + var(--sab));
}
.sheet__apply {
  position: sticky; bottom: 0;
  width: 100%; padding: 14px; border-radius: var(--r);
  background: var(--accent); color: #fff;
  font-size: 16px; font-weight: 600;
  margin-top: 16px;
}

/* Filter group */
.fgroup {
  margin-bottom: 18px;
}
.fgroup__label {
  font-size: 13px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.3px;
  margin-bottom: 8px;
}
.fgroup__row {
  display: flex; align-items: center; gap: 8px;
}
.fgroup__dash {
  color: var(--text2); font-size: 14px;
}
.finput {
  flex: 1; border: 1.5px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; background: var(--card);
  outline: none; min-width: 0;
}
.finput:focus { border-color: var(--accent); }

.fgroup__presets {
  display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap;
}
.fpreset {
  padding: 5px 12px; border-radius: 14px;
  font-size: 12px; font-weight: 500;
  background: var(--bg); color: var(--text);
  transition: all 0.15s;
}
.fpreset.on { background: var(--accent); color: #fff; }

.fgroup__chips {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.fchip {
  padding: 7px 14px; border-radius: 16px;
  font-size: 13px; font-weight: 500;
  background: var(--bg); color: var(--text);
  transition: all 0.15s;
}
.fchip.on { background: var(--accent); color: #fff; }

.fgroup__select {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: 15px; cursor: pointer;
}
.fgroup__select-text { color: var(--text2); }
.fgroup__select.has-value .fgroup__select-text { color: var(--text); font-weight: 500; }

/* ─── Select sheet ─── */
.sheet__body--select {
  max-height: 80vh;
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(16px + var(--sab));
}
.select-search {
  margin-bottom: 8px;
}
.select-search__input {
  width: 100%; border: 1.5px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; background: var(--bg);
  outline: none;
}
.select-search__input:focus { border-color: var(--accent); }
.select-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  margin: 0 -16px; padding: 0 16px;
}
.select-item {
  display: block; width: 100%; text-align: left;
  padding: 14px 0; font-size: 15px;
  border-bottom: 1px solid var(--bg);
}
.select-item.on { color: var(--accent); font-weight: 600; }

/* ─── Detail Page ─── */
.detail-page {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  animation: slideIn 0.2s ease-out;
}
@keyframes slideIn { from { transform: translateX(100%); } }

.detail-back {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  padding: calc(12px + var(--sat)) 14px 12px;
  background: rgba(26,26,46,0.9);
  backdrop-filter: blur(12px);
  color: #fff; font-size: 15px; font-weight: 500; width: 100%;
}
.detail-back svg { width: 20px; height: 20px; }

.detail-gallery {
  position: relative; aspect-ratio: 4 / 3;
  background: #111; overflow: hidden; touch-action: pan-y;
}
.detail-gallery__track {
  display: flex; height: 100%; transition: transform 0.3s ease;
}
.detail-gallery__slide { min-width: 100%; height: 100%; }
.detail-gallery__slide img {
  width: 100%; height: 100%; object-fit: contain; background: #111;
}
.detail-gallery__counter {
  position: absolute; top: 10px; right: 10px;
  padding: 3px 10px; border-radius: 10px;
  font-size: 12px; color: #fff; background: rgba(0,0,0,0.5);
}

.detail-card {
  background: var(--card); margin: 8px;
  border-radius: var(--r); padding: 16px;
}
.detail-card + .detail-card { margin-top: 0; }

.detail-title { font-size: 20px; font-weight: 700; line-height: 1.25; }
.detail-trim { font-size: 14px; color: var(--text2); margin-top: 2px; }
.detail-price { font-size: 26px; font-weight: 800; margin-top: 12px; }
.detail-price-note { font-size: 12px; color: var(--text2); margin-top: 2px; }

.detail-specs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.detail-spec-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.3px; }
.detail-spec-val { font-size: 14px; font-weight: 600; margin-top: 1px; }

.detail-cost-title { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.detail-cost-row {
  display: flex; justify-content: space-between;
  padding: 5px 0; font-size: 13px; color: var(--text2);
}
.detail-cost-total {
  display: flex; justify-content: space-between;
  padding-top: 10px; margin-top: 6px;
  border-top: 1.5px solid var(--border);
  font-size: 16px; font-weight: 700; color: var(--text);
}

.detail-delivery {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}
.detail-delivery__icon { font-size: 18px; }

.detail-actions {
  display: flex; gap: 8px;
  margin: 8px 8px calc(16px + var(--sab));
}
.detail-btn {
  flex: 1; padding: 14px; border-radius: var(--r);
  font-size: 15px; font-weight: 600;
  text-align: center; text-decoration: none; display: block;
}
.detail-btn--primary { background: var(--accent); color: #fff; }
.detail-btn--vk { background: #0077FF; color: #fff; }
.detail-btn--max { background: #F54142; color: #fff; }

/* ─── Responsive ─── */
@media (min-width: 480px) {
  .car-list { grid-template-columns: repeat(3, 1fr); gap: 8px; }
}
@media (min-width: 768px) {
  .car-list { grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 10px; }
}
