/* ===== Базовые переменные и сброс ===== */
/* Атрибут hidden должен скрывать элемент, даже если у класса задан display:flex/grid */
[hidden] { display: none !important; }

:root {
  --accent: #1F4E78;
  --accent-hover: #173f63;
  --accent-soft: #eaf1f8;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-warm: #f6f7f9;      /* тёпло-серый фон панели фильтров */
  --border: #e2e6ec;
  --border-strong: #c5cdd7;   /* более контрастная рамка полей ввода */
  --input-bg: #f7f9fc;        /* лёгкий тонированный фон полей ввода */
  --text: #1c2733;
  --text-muted: #6b7686;
  --danger: #c0392b;
  --ok: #1e8e4e;
  --warn: #b7791f;
  --warm: #F08A3E;            /* мягкий оранжевый */
  --warm-soft: #FFF3E8;
  --warm-border: #F6C9A3;
  --warm-dark: #C2621A;       /* затемнённый оранжевый (мелкие акценты/иконки) */
  --focus-ring: rgba(240, 138, 62, .26);
  --radius: 12px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(20, 40, 60, .08), 0 4px 16px rgba(20, 40, 60, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
a { color: var(--accent); }

/* ===== Шапка ===== */
.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: relative;   /* шапка уезжает при прокрутке — больше места под список */
  z-index: 1000;
  box-shadow: var(--shadow);
}
/* Тонкая оранжевая линия-акцент по верху шапки */
.app-header::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--warm) 0%, #f5ae70 60%, #f8cba0 100%);
}
.app-title { font-size: 18px; margin: 0; font-weight: 700; }
.header-main { flex: 1; min-width: 0; }
.status-line { color: var(--text-muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filters-toggle {
  display: none;
  width: 40px; height: 40px;
  font-size: 20px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
}

/* ===== Кнопки ===== */
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: #f0f3f7; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-accent { background: var(--accent-soft); border-color: #c9d8e8; color: var(--accent); }
.btn-accent:hover { background: #dde9f4; }
.btn-small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Плашки ===== */
.banner { margin: 12px 18px 0; padding: 14px 16px; border-radius: var(--radius); font-size: 14px; }
.banner-empty { background: #fff7e0; border: 1px solid #f0d48a; color: #7a5a10; }
.banner-error { background: #fdecea; border: 1px solid #f0b4ad; color: #7c1f17; }

/* ===== Раскладка ===== */
/* Обычная прокрутка всей страницы (полоса прокрутки браузера), без
   фиксированной высоты и вложенных прокруток. */
.app-main { display: flex; align-items: flex-start; }
/* Колонка «карта + список» прокручивается целиком, как обычная страница:
   список получает всю высоту экрана, а не узкую полоску под картой. */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ===== Панель фильтров ===== */
.filters-panel {
  width: 340px;
  min-width: 340px;
  background: var(--panel-warm);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 900;
  /* фильтры «прилипают» слева и всегда под рукой, пока листается список */
  position: sticky;
  top: 0;
  height: 100vh;
}
.filters-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 14px 8px; }
.filters-actions {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel-warm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.filters-actions .btn { width: 100%; }
.filters-overlay { display: none; }

/* Каждая секция фильтров — отдельный белый «блок-карточка» на тёпло-сером фоне */
.filter-group {
  margin-bottom: 12px;
  padding: 14px 14px 15px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 2px rgba(20, 40, 60, .05);
}
.filter-group:last-child { margin-bottom: 0; }
.filter-group-title {
  position: relative;
  padding-left: 11px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text); margin: 0 0 10px;
}
/* оранжевая полоска-маркер слева от заголовка секции */
.filter-group-title::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 14px;
  border-radius: 2px;
  background: var(--warm);
}
.range-row { display: flex; gap: 10px; }
.num-field { flex: 1; display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-muted); }
.num-field input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 9px; font-size: 14px;
  background: var(--input-bg); color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.num-field input::placeholder { color: var(--text-muted); opacity: .6; }
.num-field input:hover:not(:focus) { border-color: #b4bdc9; }
.num-field input:focus { outline: none; border-color: var(--warm); background: #fff; box-shadow: 0 0 0 3px var(--focus-ring); }
.keyword-field input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 9px; font-size: 14px;
  background: var(--input-bg); color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.keyword-field input::placeholder { color: var(--text-muted); opacity: .7; }
.keyword-field input:hover:not(:focus) { border-color: #b4bdc9; }
.keyword-field input:focus { outline: none; border-color: var(--warm); background: #fff; box-shadow: 0 0 0 3px var(--focus-ring); }

.check-group { display: flex; flex-direction: column; gap: 5px; }
.check-item {
  display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 13.5px; padding: 3px 6px 3px 2px;
  border-radius: 6px;
}
.check-item:hover { background: var(--warm-soft); }
.check-item input { margin-top: 2px; accent-color: var(--warm); }
.check-item.inline { display: inline-flex; }
.check-unknown { color: var(--text-muted); margin-top: 6px; }
.check-group-sub {
  font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em;
  margin: 8px 0 2px;
}
.check-group-sub.ok { color: var(--ok); }
.check-group-sub.q { color: var(--warn); }
.check-group-sub.bad { color: var(--danger); }
.check-label-note { color: var(--text-muted); font-size: 12px; }

/* ===== Карта ===== */
.map-section { position: relative; height: 50vh; min-height: 300px; max-height: 640px; flex: none; }
.map-section.collapsed { display: none; }
.map { position: absolute; inset: 0; background: #dfe6ec; }
.map-tools {
  position: absolute; top: 12px; left: 12px; z-index: 800;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px; width: 296px; max-width: calc(100% - 24px);
}
.map-tools-title { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); margin-bottom: 7px; }
.map-tools-row { display: flex; gap: 7px; margin-bottom: 7px; flex-wrap: wrap; }
.map-tools-row-tight { margin-bottom: 0; }
.map-tool {
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 9px; border: 1px solid var(--border); border-radius: 8px; background: #f8fafc;
  font-size: 12.5px; font-weight: 600; color: var(--text);
}
.map-tool:hover { background: var(--accent-soft); border-color: #c9d8e8; }
.map-tool.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.map-tool-icon { font-size: 15px; }
/* пресет «Южнее Жибек-Жолу» — согласован с тёплой оранжевой палитрой */
.map-tool-preset { background: var(--warm-soft); border-color: var(--warm-border); }
.map-tool-preset:hover { background: #ffe6d1; border-color: #f2b97e; }
.map-tool-preset .map-tool-icon { color: var(--warm-dark); }
.map-tool-clear { flex: none; background: #fdecea; border-color: #f0b4ad; color: #7c1f17; }
.street-search { flex: 1; display: flex; gap: 6px; min-width: 0; }
.street-search input {
  flex: 1; min-width: 0; height: 38px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 8px; font-size: 13px;
  background: var(--input-bg); color: var(--text);
}
.street-search input::placeholder { color: var(--text-muted); opacity: .7; }
.street-search input:focus { outline: none; border-color: var(--warm); background: #fff; box-shadow: 0 0 0 3px var(--focus-ring); }

.draw-bar {
  margin-top: 8px; padding: 8px; background: var(--accent-soft); border-radius: 8px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.draw-hint { flex: 1; font-size: 12.5px; color: var(--accent); min-width: 120px; }

.ppsm-legend { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.ppsm-legend-label { font-weight: 600; color: var(--text); }
.ppsm-legend-bar { width: 80px; height: 8px; border-radius: 4px; background: linear-gradient(to right, #1e8e4e, #e0c341, #c0392b); flex: none; }
.ppsm-legend-scale { white-space: nowrap; }
.district-list { font-size: 13px; }
.district-empty { color: var(--text-muted); font-size: 12.5px; line-height: 1.5; }
.district-item { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.district-item-name { cursor: pointer; color: var(--accent); flex: 1; min-width: 0; overflow-wrap: anywhere; }
.district-item-name:hover { text-decoration: underline; }
.district-item-x { cursor: pointer; color: var(--text-muted); font-weight: 700; padding: 0 4px; border: none; background: none; }
.district-item-x:hover { color: var(--danger); }
.district-side-select { font-size: 12px; padding: 1px 2px; border: 1px solid var(--border); border-radius: 5px; }
.map-hint { margin-top: 8px; font-size: 12.5px; color: var(--text-muted); }
.map-hint summary { cursor: pointer; font-weight: 600; color: var(--text); }
.map-hint p { margin: 6px 0 0; }

/* ===== Результаты ===== */
.results-section { flex: none; display: flex; flex-direction: column; background: var(--bg); padding: 0 16px 24px; }
/* шапка списка прилипает к верху при прокрутке */
.results-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 700; background: var(--bg);
  padding: 10px 0; margin-bottom: 6px; border-bottom: 1px solid var(--border);
}
.results-title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0; }
.results-title { font-size: 16px; font-weight: 700; }
.results-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.control-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.control-label select {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: var(--panel);
}

.excluded-summary {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px;
}
.excluded-summary summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--text-muted); }
.excluded-list { margin-top: 6px; font-size: 13px; }
.excluded-row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--border); }
.excluded-row:last-child { border-bottom: none; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; padding: 6px 0; }
.pagination button {
  min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid var(--border); background: var(--panel);
  border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--text);
}
.pagination button:hover:not(:disabled) { background: var(--accent-soft); border-color: #c9d8e8; }
.pagination button.current { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination .ellipsis { padding: 0 4px; color: var(--text-muted); }

.results-list { display: flex; flex-direction: column; gap: 10px; }

/* ===== Фото карточки ===== */
.card-photo-box { width: 150px; height: 110px; flex: none; border-radius: 9px; background: #e9edf2; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.card-photo-ph { font-size: 30px; color: #aeb8c4; position: absolute; }
.card-photo { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }

/* ===== Кнопка отмены в диалоге стороны ===== */
.side-cancel {
  margin-top: 12px; background: transparent; border: none; color: var(--text-muted); font-size: 13px;
  text-decoration: underline; padding: 4px 8px;
}
.side-cancel:hover { color: var(--text); }

/* ===== Карточка объявления ===== */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; display: flex; gap: 14px; cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
}
/* мягкое тёплое выделение карточки при наведении */
.card:hover { box-shadow: 0 6px 22px rgba(20,40,60,.12), 0 0 0 1px rgba(240,138,62,.28); border-color: var(--warm-border); }
.card.highlight { outline: 3px solid var(--accent); outline-offset: 1px; }
.card-body { flex: 1; min-width: 0; }
.card-title { font-weight: 700; font-size: 14.5px; margin: 0 0 6px; }
.card-price-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.card-price { font-size: 20px; font-weight: 800; color: var(--accent); }
.card-ppsm { font-size: 13px; color: var(--text-muted); }
.card-facts { display: flex; flex-wrap: wrap; gap: 5px 12px; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.card-facts b { color: var(--text); font-weight: 600; }
.card-district { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.card-notes { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
.badge {
  font-size: 11.5px; padding: 2px 8px; border-radius: 20px; font-weight: 600; white-space: nowrap;
}
.badge-note { background: #eef2f7; color: #44546a; }
.badge-approx { background: #fff3cd; color: #7a5a10; }
.badge-text { background: #e8f0fe; color: #174ea6; }
.card-links { display: flex; gap: 12px; align-items: center; }
.card-open { font-size: 13px; font-weight: 600; }
.series-by-text { color: var(--warn); font-size: 12px; }

/* ===== Пустое состояние ===== */
.empty-state { background: var(--panel); border: 1px dashed var(--border); border-radius: var(--radius); padding: 26px 20px; }
.empty-state h3 { margin: 0 0 8px; }
.empty-state ul { margin: 8px 0 0; padding-left: 20px; }
.empty-state li { margin: 3px 0; }

/* ===== Спиннер / скелетон ===== */
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
.loading-bar { text-align: center; padding: 30px; color: var(--text-muted); }
.skeleton-card { background: var(--panel); border-radius: var(--radius); padding: 12px; display: flex; gap: 14px; }
.skeleton { background: linear-gradient(90deg, #eef1f5 25%, #e2e7ed 37%, #eef1f5 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ===== Тост ===== */
.toast-container { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #1c2733; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 13.5px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: 90vw; animation: toast-in .2s ease;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }
.toast.info { background: var(--accent); }

/* Кнопки обновления убраны с сайта — обновление идёт по расписанию на бэкенде. */
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Диалог выбора стороны ===== */
.side-dialog {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2100;
  background: var(--panel); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.3);
  padding: 18px; width: 320px; max-width: 92vw; text-align: center;
}
.side-dialog-title { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.side-dialog-subtitle { color: var(--text-muted); font-size: 12.5px; margin-bottom: 12px; }
.side-dialog-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.side-btn {
  padding: 12px 8px; border: 1px solid var(--border); border-radius: 10px; background: #f8fafc; font-size: 13.5px; font-weight: 600;
}
.side-btn:hover { background: var(--accent-soft); border-color: #c9d8e8; }
.side-btn.default { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Leaflet переопределения попапа */
.leaflet-popup-content { font-size: 13px; }
.leaflet-popup-content .pp-title { font-weight: 700; margin-bottom: 4px; }
.leaflet-popup-content .pp-row { margin: 2px 0; }
.leaflet-popup-content a.pp-btn { display: inline-block; margin-top: 6px; margin-right: 6px; padding: 5px 10px; background: var(--accent); color: #fff; border-radius: 7px; text-decoration: none; font-size: 12.5px; font-weight: 600; }
.leaflet-popup-content a.pp-btn.secondary { background: #eef2f7; color: var(--accent); }

/* ===== Адаптивность ===== */
@media (max-width: 1279px) {
  .filters-toggle { display: block; }
  .filters-panel {
    position: fixed; top: 0; left: 0; bottom: 0; width: 320px; min-width: 320px;
    transform: translateX(-100%); transition: transform .25s ease; box-shadow: 0 0 40px rgba(0,0,0,.2);
  }
  .filters-panel.open { transform: translateX(0); }
  .filters-overlay { display: block; position: fixed; inset: 0; background: rgba(20,40,60,.35); z-index: 850; }
  .map-section { height: 46vh; min-height: 300px; }
  .map-tools { width: 260px; }
  .card-photo-box { width: 120px; height: 96px; }
}
@media (max-width: 640px) {
  .app-title { font-size: 15px; }
  .map-section { height: 44vh; }
  .map-tools { width: 100%; max-width: 100%; top: 0; left: 0; border-radius: 0; }
  .card-photo-box { width: 96px; height: 84px; }
  .card-price { font-size: 17px; }
}
