/* Landlord — стили. Подход «mobile first»: базовые правила для телефона,
   @media (min-width: …) добавляют раскладку для широких экранов.
   Цвета заданы переменными (custom properties) — тёмная тема меняет только их. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --ink: #17202c;
  --muted: #5f6b7a;
  --line: #e1e5ea;
  --accent: #1f5fd6;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #13803c;
  --sale: #0b6e63;
  --sale-soft: #e1f3ef;
  --rent: #9a3f0c;
  --rent-soft: #fcefe4;
  --new: #c2410c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --gutter: 16px;
  /* Отступ от края с учётом «чёлки» и закруглений экрана в горизонтальной ориентации. */
  --edge-left: max(var(--gutter), env(safe-area-inset-left));
  --edge-right: max(var(--gutter), env(safe-area-inset-right));
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b;
    --surface: #171e27;
    --surface-2: #1e2732;
    --ink: #e6ebf1;
    --muted: #96a3b3;
    --line: #2a3441;
    --accent: #6c9dff;
    --accent-ink: #0b1220;
    --accent-soft: #1b2a45;
    --danger: #ff8a80;
    --danger-soft: #3a1d1b;
    --ok: #5fd08a;
    --sale: #5ccdb9;
    --sale-soft: #173a35;
    --rent: #f3a36f;
    --rent-soft: #3b2618;
    --new: #fb923c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
/* Атрибут hidden должен побеждать любые display из классов (.btn { display: inline-flex }
   иначе «воскрешает» скрытую скриптом кнопку). */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- каркас */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px var(--edge-right) 10px var(--edge-left);
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--ink); font-size: 17px; }
.topnav { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 14px; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page { max-width: 1280px; margin: 0 auto; padding: 18px var(--edge-right) 40px var(--edge-left); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.inline { display: inline; margin: 0; }
.stack { display: grid; gap: 14px; }
.empty {
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 32px var(--gutter); text-align: center;
}

/* ---------- кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { color: var(--accent-ink); filter: brightness(1.06); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; }

/* ---------- формы */
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 550; }
input, select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 16px; /* 16px — iOS не будет приближать страницу при фокусе */
}
.alert { padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); }

/* ---------- вход */
body.auth { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; }
body.auth .page { width: 100%; max-width: 400px; padding: 24px var(--gutter); }
.auth-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 22px; box-shadow: var(--shadow); display: grid; gap: 14px;
}
.auth-title { font-size: 26px; }
.auth-card p { margin: 0; }

/* ---------- уведомления, карточки */
.notice { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); margin-bottom: 14px; }
.alert { margin-bottom: 14px; }
.footnote { margin-top: 24px; }
.back { display: inline-block; font-size: 14px; margin-bottom: 4px; }
.cards { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .cards { grid-template-columns: repeat(3, 1fr); } }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: grid; gap: 10px; align-content: start;
}
.card-title { font-size: 17px; margin: 0; line-height: 1.3; overflow-wrap: anywhere; }
.card-title a { color: var(--ink); }
.card-stat strong { font-size: 22px; }

/* ---------- форма запроса */
.qform { display: grid; gap: 16px; padding-bottom: 84px; /* место под закреплённую панель */ }
.fgrid { display: grid; gap: 12px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 900px) { .fgrid { grid-template-columns: repeat(2, 1fr); } }
.fsec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.fsec > summary {
  list-style: none; cursor: pointer; padding: 14px 16px; display: flex; gap: 10px;
  align-items: baseline; justify-content: space-between; min-height: 48px;
}
.fsec > summary::-webkit-details-marker { display: none; }
.fsec > summary::after { content: "▾"; color: var(--muted); margin-left: 4px; }
.fsec[open] > summary::after { content: "▴"; }
.fsec-title { font-weight: 650; }
.fsec-summary { color: var(--muted); font-size: 13px; margin-left: auto; text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
.fsec-body { padding: 0 16px 16px; display: grid; gap: 12px; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--surface);
}
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 550; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

.checklist { display: grid; gap: 8px; }
.checklist-items { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; min-height: 40px; }
.check:hover { background: var(--surface-2); }
.check input { flex: none; width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--accent); }
.check-title { flex: 1; }
.check-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.check.is-empty .check-title { color: var(--muted); }
.check[hidden] { display: none; }

.range { display: flex; align-items: center; gap: 8px; }
.range input { flex: 1; min-width: 0; }
.range-sep { color: var(--muted); }
.range-unit { color: var(--muted); font-size: 13px; min-width: 28px; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px var(--edge-right) 10px var(--edge-left); padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.savebar-count strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.savebar-count strong.is-loading { opacity: .45; }
.danger-zone { margin-top: 8px; padding-bottom: 80px; }

/* ---------- бейджи и статусы */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-sale { background: var(--sale-soft); color: var(--sale); }
.badge-rent { background: var(--rent-soft); color: var(--rent); }
.badge-new { background: color-mix(in srgb, var(--new) 14%, transparent); color: var(--new); }
/* «С постройкой» — нейтральная пометка: не ошибка, а другой тип объекта. */
.badge-building { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); cursor: help; }
.st { font-size: 13px; color: var(--muted); white-space: nowrap; }
.st-open { color: var(--ok); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--new); margin-right: 6px; vertical-align: 1px; }
.new-text { color: var(--new); font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 14px; }

/* ---------- карточка запроса на дашборде */
.qcard { position: relative; }
.qcard-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.qcard:hover { border-color: var(--accent); }
.qcard-link:focus-visible { outline: none; }
.qcard:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.qcard-main { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.qcard-total { font-size: 28px; font-variant-numeric: tabular-nums; }
.qcard-stats { display: grid; gap: 6px; margin: 0; }
.qcard-stats div { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.qcard-stats dt { color: var(--muted); font-size: 13px; }
.qcard-stats dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.qcard-actions { position: relative; z-index: 1; /* кнопка поверх растянутой ссылки */ display: flex; justify-content: flex-end; }

/* ---------- страница результатов */
.page-head-title { min-width: 0; }
.page-head-title h1 { overflow-wrap: anywhere; }
.page-head-actions { display: flex; gap: 8px; }
.rbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.rbar-search { flex: 1 1 260px; }
/* Выпадающие мультивыборы (Лот, ВРИ) над таблицей: <details> как кнопка-раскрытие,
   меню с галочками позиционируется поверх содержимого (position: absolute), чтобы не
   раздвигало страницу. Работает без JS — галочки уходят в форму независимо от открытия. */
.rbar-multi { position: relative; }
.rbar-multi > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink);
  font-size: 14px; white-space: nowrap;
}
.rbar-multi > summary::-webkit-details-marker { display: none; } /* убрать стрелку WebKit */
.rbar-multi > summary::after { content: "▾"; color: var(--muted); font-size: 11px; }
.rbar-multi[open] > summary { border-color: var(--accent); color: var(--accent); }
.rbar-menu {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 240px;
  max-height: 60vh; overflow-y: auto; padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
}
/* Широкое меню (ВРИ — длинные подписи) прижимаем к правому краю кнопки, иначе на основной
   странице оно вылезает за правый край окна и вся страница получает горизонтальную прокрутку. */
.rbar-menu-wide {
  left: auto; right: 0; min-width: 320px; max-width: min(460px, calc(100vw - 2 * var(--gutter)));
}
.rbar-opt {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 7px;
  font-size: 14px; line-height: 1.3; cursor: pointer;
}
.rbar-opt:hover { background: var(--accent-soft); }
/* Чекбоксы: без этого их растягивает глобальное правило input { width:100%; min-height:42px },
   подписи уезжают и список прокручивается вбок. Фиксируем размер — как у .check input. */
.rbar-opt input { flex: none; width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--accent); }
/* Переключатели над результатами — компактнее, чтобы «Только новые»
   помещалось в одну строку даже на экране 360px. */
.rbar .chips { gap: 6px; }
.rbar .chip span { min-height: 36px; padding: 0 11px; font-size: 14px; }
.rsummary { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; margin: 4px 0 12px; }
/* Сортировка на телефоне — отдельной строкой; ссылки с внутренним отступом, чтобы в них
   было легко попасть пальцем (рекомендация — зона нажатия не меньше ~40px). */
.msort {
  flex-basis: 100%; display: flex; align-items: center; gap: 0 2px; font-size: 14px; color: var(--muted);
  /* Одна строка, лишнее прокручивается пальцем вбок (сама страница при этом не шире экрана). */
  white-space: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.msort::-webkit-scrollbar { display: none; }
.msort a { color: var(--muted); padding: 9px 7px; flex: none; }
.msort a.is-sorted { color: var(--accent); font-weight: 600; }

.tablewrap { display: none; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ltable { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; }
.ltable th, .ltable td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.ltable tbody tr:last-child td { border-bottom: 0; }
.ltable th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; font-weight: 600; white-space: nowrap; z-index: 1; }
.ltable th a { color: var(--muted); }
.ltable th.is-sorted a { color: var(--ink); }
.ltable th .arrow { display: inline-block; width: 12px; margin-left: 2px; }
.ltable .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ltable .nowrap { white-space: nowrap; }
.ltable .addr { min-width: 220px; max-width: 360px; }
.ltable .w-vri { min-width: 160px; max-width: 260px; }
.ltable .lot-cell { min-width: 150px; }
.ltable .lot-cell > div + div { margin-top: 3px; }
.ltable tr.is-new td { background: color-mix(in srgb, var(--new) 5%, transparent); }

.lcards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.lcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 6px; }
.lcard.is-new { border-left: 3px solid var(--new); }
.lcard-top { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.lcard-price strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.lcard-meta { color: var(--muted); font-size: 14px; }
.lcard-addr { overflow-wrap: anywhere; }
.lcard-links a { display: inline-block; padding: 6px 0; /* крупнее зона нажатия на телефоне */ }

/* Переключение: до 860px — карточки, шире — таблица. */
@media (min-width: 860px) {
  .tablewrap { display: block; }
  .lcards { display: none; }
  .msort { display: none; }
}

.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 18px 0; flex-wrap: wrap; }

/* ---------- карта */
.map-bar { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.map-toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; }
.map-toggle input { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--accent); }
/* Высота карты: экран минус шапка и фильтры; на телефоне — не меньше 420px. */
.map {
  height: calc(100vh - 260px); height: calc(100dvh - 260px); min-height: 420px;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface-2);
}
.map-legend { margin-top: 10px; }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 4px 0 8px; vertical-align: 0; }
.legend-dot:first-child { margin-left: 0; }
.legend-sale { background: #1b7f3b; }
.legend-rent { background: #e6761b; }
.legend-cadastral { background: #8e54e9; }
.legend-approx { background: #9aa3ad; }
.legend-archived { background: #6b7280; }
/* Всплывающее окно Яндекса рисуется в нашем документе — наши стили к нему применяются.
   Оно всегда светлое, поэтому цвета заданы явно, а не переменными тёмной темы. */
.mballoon { display: grid; gap: 4px; font-size: 14px; line-height: 1.4; color: #17202c; max-width: 280px; }
.mb { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f0f2f5; color: #17202c; }
.mb-sale { background: #e1f3ef; color: #0b6e63; }
.mb-rent { background: #fcefe4; color: #9a3f0c; }
.mb-new { background: #fdeee6; color: #c2410c; }
.mballoon .mb-warn { color: #b42318; font-style: normal; }

/* Архив: дашборды исходов и итогов, итоговая цена в таблице. */
.astats { display: flex; flex-wrap: wrap; gap: 12px; margin: 4px 0 18px; }
.astat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 16px; min-width: 130px; }
.astat-val { font-size: 20px; font-weight: 700; color: var(--ink); }
.astat-lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.afin { color: var(--ok); font-weight: 600; }

/* Страница лота и блок «Соседние торги». */
.lot-detail { margin: 8px 0 24px; }
.lot-badges { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.lot-result { background: var(--sale-soft); color: var(--sale); border-radius: var(--radius); padding: 8px 14px; margin-bottom: 14px; }
.lot-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 28px; }
.lot-facts > div { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.lot-facts dt { color: var(--muted); min-width: 118px; }
.lot-facts dd { margin: 0; }
.nearby { margin-top: 8px; }
.nearby-lead { font-size: 15px; margin: 4px 0 12px; }
