:root {
  --bg: var(--tg-theme-bg-color, #f3f4f8);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-alt: #eef0f6;
  --text: var(--tg-theme-text-color, #111827);
  --muted: var(--tg-theme-hint-color, #6b7280);
  --accent: var(--tg-theme-button-color, #e11d48);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(15, 23, 42, 0.09);
  --success: #059669;
  --success-bg: rgba(5, 150, 105, 0.13);
  --warning: #d97706;
  --warning-bg: rgba(217, 119, 6, 0.14);
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.13);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
  --radius: 16px;
  --nav-h: 62px;
}

[data-theme="dark"] {
  --bg: #0b0f19;
  --surface: #141b2d;
  --surface-alt: #1d273f;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #f43f5e;
  --border: rgba(148, 163, 184, 0.16);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

.hidden { display: none !important; }

.app-shell {
  min-height: 100vh;
  max-width: 820px;
  margin: 0 auto;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 14px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)) 14px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-badge {
  width: 36px; height: 36px; border-radius: 11px;
  background: var(--accent); color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center;
}
.brand-title { font-weight: 800; font-size: 15px; letter-spacing: -0.2px; }
.brand-sub { font-size: 11px; color: var(--muted); }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-alt);
  color: var(--text); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}

.view-root { padding: 12px; animation: fadeIn 0.16s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 0 10px;
}
.section-head:first-child { margin-top: 0; }
.section-title { font-size: 16px; font-weight: 800; margin: 0; }

/* Карточки лотов в стиле маркетплейса */
.lots-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 600px) {
  .lots-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.lot-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.lot-card:active { transform: scale(0.99); }

.lot-photo-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--surface-alt);
  overflow: hidden;
}
.lot-photo-wrap img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.lot-photo-placeholder {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px;
}

.fav-fab {
  position: absolute; top: 8px; right: 8px;
  width: 34px; height: 34px; border-radius: 999px;
  border: none; background: rgba(15, 23, 42, 0.62); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.fav-fab.active { background: var(--accent); color: #fff; }

.lot-badges {
  position: absolute; left: 8px; bottom: 8px;
  display: flex; flex-wrap: wrap; gap: 5px;
}

.lot-body { padding: 12px; }
.lot-title { font-weight: 800; font-size: 15px; margin: 0 0 4px; }
.lot-price { font-weight: 800; font-size: 17px; color: var(--accent); margin: 4px 0; }
.lot-specs { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Общие карточки */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap;
}
.pill-dark { background: rgba(15, 23, 42, 0.75); color: #fff; }
.pill-warn { background: var(--warning); color: #fff; }
.pill-warn-soft { background: var(--warning-bg); color: var(--warning); }
.pill-ok { background: var(--success-bg); color: var(--success); }
.pill-danger { background: var(--danger-bg); color: var(--danger); }
.pill-neutral { background: var(--surface-alt); color: var(--muted); }

/* Галерея в карточке */
.gallery-strip {
  display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory;
  padding-bottom: 6px; margin-bottom: 10px;
}
.gallery-strip img {
  width: 86%; max-width: 440px; aspect-ratio: 16 / 10; object-fit: cover;
  border-radius: 12px; flex-shrink: 0; scroll-snap-align: start; cursor: zoom-in;
}

/* Блок сравнения 2 площадок и Было/Стало */
.compare-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 8px;
}
.compare-box {
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: 12px; padding: 10px;
}
.compare-box.winner { border-color: var(--success); background: var(--success-bg); }
.compare-box img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; margin-bottom: 6px; cursor: zoom-in; }

/* Кнопки, поля, чипы */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 11px; border: 1px solid transparent;
  font-size: 13px; font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-success { background: var(--success-bg); color: var(--success); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 9px; }

.input, .select {
  width: 100%; padding: 10px 12px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface-alt);
  color: var(--text); font-size: 14px; outline: none;
}
.form-group { margin-bottom: 10px; }
.form-label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.controls-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.controls-row {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 8px;
}

.select {
  appearance: auto;
  text-overflow: ellipsis;
}

details.acc {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px;
}
details.acc summary { font-weight: 700; cursor: pointer; list-style: none; }

.spec-row {
  display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.spec-row:last-child { border-bottom: none; }
.muted { color: var(--muted); }

/* Нижняя навигация */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: center;
}
.nav-btn {
  flex: 1; height: var(--nav-h); border: none; background: transparent;
  color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 10px; font-weight: 700; cursor: pointer;
}
.nav-btn.active { color: var(--accent); }

/* Модалка и полноэкранная галерея */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.58);
  display: flex; align-items: flex-end; justify-content: center; padding: 10px;
}
@media (min-width: 600px) { .modal-backdrop { align-items: center; } }
.modal-card {
  width: 100%; max-width: 500px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 16px; padding: 16px;
}

.lightbox {
  position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, 0.94);
  display: flex; flex-direction: column; justify-content: space-between; padding: 12px;
}
.lightbox-img-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto;
}
.lightbox-img-wrap img { max-width: 100%; max-height: 78vh; transition: transform 0.15s ease; border-radius: 8px; }

.loader, .empty { text-align: center; padding: 34px 14px; color: var(--muted); }
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; margin: 0 auto 10px; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%);
  z-index: 100; background: #111827; color: #fff; padding: 9px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 700; max-width: 90vw; text-align: center;
}
