:root {
  --bg: var(--tg-theme-bg-color, #0e0f12);
  --card: var(--tg-theme-secondary-bg-color, #16181d);
  --text: var(--tg-theme-text-color, #f2f3f5);
  --hint: var(--tg-theme-hint-color, #8b919c);
  --link: var(--tg-theme-link-color, #4da3ff);
  --btn: var(--tg-theme-button-color, #2ea6ff);
  --btn-text: var(--tg-theme-button-text-color, #fff);

  --accent: #3ac569;
  --accent-soft: rgba(58, 197, 105, 0.14);
  --danger: #e6473c;
  --transit: #e6a63c;

  --line: rgba(255, 255, 255, 0.07);
  --r: 16px;
  --r-sm: 11px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Атрибут hidden має перемагати наші display:flex/grid.
   Без цього !important порожня панель фільтрів світиться смужкою. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: 28px;
  overflow-x: hidden;
}

.view { padding: 12px 12px 0; animation: fade .22s ease; }
.hidden { display: none !important; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------- шапка */
.brand-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 14px;
}
.brand-logo {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 21px;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  overflow: hidden;
  flex: 0 0 auto;
}
.brand-logo img { width: 100%; height: 100%; object-fit: cover; }
.brand-text { min-width: 0; }
.brand-name {
  font-size: 16px; font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-tagline { font-size: 12px; color: var(--hint); }

/* ------------------------------------------------------------- вкладки */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--card);
  padding: 4px;
  border-radius: 13px;
  margin-bottom: 10px;
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--hint);
  font-size: 12.5px;
  font-weight: 600;
  padding: 9px 4px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .18s, color .18s;
  position: relative;
  white-space: nowrap;
}
.tab-btn.active { background: rgba(255,255,255,.07); color: var(--text); }
.badge {
  position: absolute;
  top: 2px; right: 4px;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  min-width: 16px;
  padding: 0 4px;
  font-size: 10px;
  line-height: 16px;
}

/* ------------------------------------------------------------- пошук */
.search-bar { position: relative; margin-bottom: 10px; }
.search-bar svg {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--hint); pointer-events: none;
}
.search-bar input {
  width: 100%;
  padding: 12px 12px 12px 38px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .18s;
}
.search-bar input:focus { border-color: var(--accent); }

/* --------------------------------------------------- активні фільтри */
.filters-chip {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  margin-bottom: 10px;
  font-size: 13px;
}
.filters-chip button {
  background: none; border: none; color: var(--link);
  font-size: 13px; cursor: pointer; padding: 0; flex: 0 0 auto;
}

/* ------------------------------------------------------------- картки */
.car-list { display: flex; flex-direction: column; gap: 12px; }

.car-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease;
}
.car-card:active { transform: scale(.985); box-shadow: var(--shadow); }

/* Плейсхолдер під фото: видно, якщо картинка не завантажилась або її немає.
   Лежить під <img>, тому при помилці достатньо сховати саму картинку. */
.car-photo, .gallery-track img { background: linear-gradient(135deg, #1e2229, #14171c); }
.car-photo::before {
  content: "🚗";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 34px; opacity: .22;
}
.car-photo { position: relative; aspect-ratio: 16 / 10; }
.car-photo img { position: relative; width: 100%; height: 100%; object-fit: cover; display: block; }
.car-photo::after {
  content: "";
  position: absolute; inset: auto 0 0 0; height: 62%;
  background: linear-gradient(to top, rgba(0,0,0,.72), transparent);
  pointer-events: none;
}
.photo-count {
  position: absolute; top: 9px; right: 9px;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
  z-index: 1;
}
.price-chip {
  position: absolute; left: 10px; bottom: 10px;
  font-size: 17px; font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0,0,0,.6);
  z-index: 1;
}
.status-chip {
  position: absolute; right: 10px; bottom: 10px;
  font-size: 11px; font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid currentColor;
  backdrop-filter: blur(4px);
  z-index: 1;
}
.status-chip.transit { color: var(--transit); background: rgba(230,166,60,.15); }
.status-chip.sold    { color: var(--danger);  background: rgba(230,71,60,.15); }

.car-body { padding: 11px 13px 13px; }
.car-name { font-weight: 650; font-size: 15.5px; }
.car-specs { color: var(--hint); font-size: 13px; margin-top: 3px; }
.car-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 7px; font-size: 12px; color: var(--hint);
}
.car-vin { font-size: 10.5px; opacity: .65; letter-spacing: .3px; }

/* --------------------------------------------------------- скелетони */
.skeleton { background: var(--card); border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); }
.sk-photo { aspect-ratio: 16 / 10; }
.sk-line { height: 11px; border-radius: 6px; margin: 10px 13px; }
.sk-line.short { width: 45%; }
.shimmer {
  background: linear-gradient(90deg, rgba(255,255,255,.04) 25%, rgba(255,255,255,.10) 37%, rgba(255,255,255,.04) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ------------------------------------------------------------- порожньо */
.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--hint);
}
.empty-icon { font-size: 38px; margin-bottom: 8px; opacity: .75; }
.empty-title { color: var(--text); font-weight: 600; margin-bottom: 4px; }
.notify-row {
  display: inline-flex; align-items: center; gap: 9px;
  margin-top: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 11px 14px;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.notify-row input { width: 17px; height: 17px; accent-color: var(--accent); flex: 0 0 auto; }

/* ------------------------------------------------------------- фільтр */
.view-title { font-size: 19px; font-weight: 700; margin: 2px 0 14px; }
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 12px; color: var(--hint); margin-bottom: 5px; font-weight: 600; }
.field select, .field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  outline: none;
  appearance: none;
  transition: border-color .18s;
}
.field select:focus, .field input:focus { border-color: var(--accent); }
.field select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%238b919c' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  width: 100%;
  padding: 14px;
  border-radius: var(--r-sm);
  border: none;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  transition: opacity .16s, transform .12s;
}
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--btn); color: var(--btn-text); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-ghost {
  background: none; color: var(--link);
  padding: 11px; font-weight: 500;
}
.btn-ghost.warn { color: var(--danger); }
.sticky-actions {
  position: sticky; bottom: 0;
  background: linear-gradient(to top, var(--bg) 62%, transparent);
  padding: 14px 0 10px;
  margin-top: 4px;
}
/* Щоб останні рядки опису не ховались назавжди під липкою панеллю кнопок */
#view-detail, #view-filter { padding-bottom: 16px; }
#view-detail .desc { margin-bottom: 12px; }

/* ------------------------------------------------------------- деталі */
.gallery { position: relative; margin: -12px -12px 0; }
.gallery-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.gallery-track::-webkit-scrollbar { display: none; }
.gallery-track img {
  flex: 0 0 100%;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  scroll-snap-align: start;
  background: #1c1f25;
}
.fav-btn {
  position: absolute; top: 12px; right: 12px;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  transition: transform .16s;
}
.fav-btn:active { transform: scale(.88); }
.fav-btn.on { color: #ff5b6b; }
.dots { display: flex; justify-content: center; gap: 5px; padding: 9px 0 2px; }
.dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: rgba(255,255,255,.22);
  transition: width .2s, background .2s;
}
.dots span.on { width: 16px; border-radius: 3px; background: var(--accent); }

.detail-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; margin-top: 6px;
}
.detail-head h2 { font-size: 19px; margin: 0; font-weight: 700; }
.detail-price { font-size: 19px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.detail-sub { color: var(--hint); font-size: 13px; margin-top: 3px; }

.specs { width: 100%; border-collapse: collapse; margin: 14px 0; }
.specs td { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.specs tr:last-child td { border-bottom: none; }
.specs td:first-child { color: var(--hint); width: 46%; }
.specs td:last-child { text-align: right; font-weight: 550; }
.copy-btn {
  background: none; border: none; color: var(--link);
  font-size: 11.5px; cursor: pointer; padding: 0 0 0 7px;
}
.desc {
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-line;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 13px;
  margin-bottom: 6px;
}

.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20,22,26,.96);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  z-index: 99;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
