/* ───────── Токены темы ───────── */
:root {
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-2: #f7f7fa;
  --fill: rgba(120,120,128,.12);
  --fill-2: rgba(120,120,128,.20);
  --text: #000000;
  --text-2: #6c6c70;
  --text-3: #a1a1a6;
  --sep: rgba(60,60,67,.14);
  --accent: #007aff;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --purple: #af52de;
  --teal: #30b0c7;
  --pink: #ff2d55;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
  --r-card: 18px;
  --r-tile: 14px;
  --nav-h: 52px;
  --tab-h: 54px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --fill: rgba(120,120,128,.24);
    --fill-2: rgba(120,120,128,.36);
    --text: #ffffff;
    --text-2: #98989f;
    --text-3: #6c6c70;
    --sep: rgba(84,84,88,.55);
    --accent: #0a84ff;
    --green: #30d158;
    --orange: #ff9f0a;
    --red: #ff453a;
    --purple: #bf5af2;
    --teal: #40c8e0;
    --pink: #ff375f;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --bg-elev: #1c1c1e; --card: #1c1c1e; --card-2: #2c2c2e;
  --fill: rgba(120,120,128,.24); --fill-2: rgba(120,120,128,.36);
  --text: #ffffff; --text-2: #98989f; --text-3: #6c6c70;
  --sep: rgba(84,84,88,.55); --accent: #0a84ff; --green: #30d158;
  --orange: #ff9f0a; --red: #ff453a; --purple: #bf5af2; --teal: #40c8e0; --pink: #ff375f;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
}

/* ───────── База ───────── */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior-y: none; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
h1,h2,h3,h4 { margin: 0; font-weight: 700; letter-spacing: -.02em; }

.app { min-height: 100%; display: flex; flex-direction: column; }
.screen {
  flex: 1;
  padding: calc(var(--safe-t) + 8px) 16px calc(var(--tab-h) + var(--safe-b) + 24px);
  max-width: 560px; width: 100%; margin: 0 auto;
  animation: fade .22s ease both;
}
.screen.no-tabs { padding-bottom: calc(var(--safe-b) + 24px); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ───────── Шапка ───────── */
.nav { display: flex; align-items: center; gap: 8px; min-height: var(--nav-h); margin-bottom: 4px; }
.nav .back { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-size: 17px; margin-left: -4px; }
.nav .back svg { width: 11px; height: 18px; }
.nav .spacer { flex: 1; }
.nav .act { color: var(--accent); font-size: 17px; }
.title { font-size: 32px; line-height: 1.12; letter-spacing: -.03em; margin: 2px 0 4px; }
.title-sm { font-size: 24px; letter-spacing: -.02em; margin: 2px 0 4px; }
.sub { color: var(--text-2); font-size: 15px; margin: 0 0 16px; }
.group-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 24px 4px 8px; font-weight: 600; }
.group-title:first-child { margin-top: 8px; }

/* ───────── Карточки ───────── */
.card {
  background: var(--card); border-radius: var(--r-card);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.card.tight { padding: 12px 16px; }
.card.flat { box-shadow: none; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-h h3 { font-size: 19px; }

/* Список-группа как в iOS */
.list { background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; min-height: 48px; position: relative; width: 100%; text-align: left; }
.row + .row::before { content: ""; position: absolute; left: 16px; right: 0; top: 0; height: 1px; background: var(--sep); }
.row.pressable:active { background: var(--fill); }
.row .ico { width: 29px; height: 29px; border-radius: 8px; display: grid; place-items: center; font-size: 16px; flex: none; }
.row .body { flex: 1; min-width: 0; }
.row .body .t { font-size: 17px; display: block; }
.row .body .d { font-size: 13px; color: var(--text-2); margin-top: 1px; display: block; }
.row .val { color: var(--text-2); font-size: 17px; text-align: right; white-space: nowrap; }
.row .chev { color: var(--text-3); font-size: 15px; flex: none; }

/* ───────── Кнопки ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 20px; border-radius: 14px; font-size: 17px; font-weight: 600;
  background: var(--accent); color: #fff; width: 100%;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(.975); opacity: .9; }
.btn[disabled] { opacity: .35; pointer-events: none; }
.btn.sec { background: var(--fill); color: var(--accent); }
.btn.ghost { background: none; color: var(--accent); height: 44px; }
.btn.danger { background: var(--fill); color: var(--red); }
.btn.sm { height: 38px; font-size: 15px; border-radius: 11px; width: auto; padding: 0 14px; }
.btn-row { display: flex; gap: 10px; }

/* ───────── Поля ───────── */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; color: var(--text-2); margin: 0 4px 6px; }
.input {
  width: 100%; height: 50px; padding: 0 14px; border-radius: 13px;
  background: var(--card); border: 1px solid transparent; box-shadow: var(--shadow);
  font-size: 17px; outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { height: auto; min-height: 88px; padding: 12px 14px; resize: vertical; line-height: 1.4; }
.input-money { display: flex; align-items: center; background: var(--card); border-radius: 13px; box-shadow: var(--shadow); padding-right: 14px; }
.input-money .input { box-shadow: none; background: none; }
.input-money .cur { color: var(--text-2); font-size: 17px; }

/* Сегменты */
.seg { display: flex; background: var(--fill); border-radius: 11px; padding: 2px; gap: 2px; }
.seg button { flex: 1; height: 34px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--text); transition: background .15s; }
.seg button[aria-pressed="true"] { background: var(--bg-elev); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

/* Чипы выбора */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 12px;
  background: var(--card); box-shadow: var(--shadow); font-size: 15px; transition: all .15s;
}
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: none; }

/* Чекбокс — крупный, как просили */
.check { display: flex; align-items: flex-start; gap: 14px; padding: 14px 16px; width: 100%; text-align: left; position: relative; }
.check + .check::before { content: ""; position: absolute; left: 54px; right: 0; top: 0; height: 1px; background: var(--sep); }
.check .box {
  width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--fill-2);
  flex: none; display: grid; place-items: center; transition: all .18s cubic-bezier(.2,.8,.3,1); margin-top: -1px;
}
.check[aria-checked="true"] .box { background: var(--green); border-color: var(--green); }
.check .box svg { width: 15px; height: 15px; stroke: #fff; stroke-width: 3.2; fill: none; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transform: scale(.5); transition: all .18s cubic-bezier(.2,.8,.3,1); }
.check[aria-checked="true"] .box svg { opacity: 1; transform: none; }
.check .lbl { flex: 1; font-size: 17px; padding-top: 2px; }
.check .lbl small { display: block; color: var(--text-2); font-size: 13px; margin-top: 2px; }
.check[aria-checked="true"] .lbl { color: var(--text-2); }

/* ───────── Прогресс ───────── */
.bar { height: 10px; border-radius: 6px; background: var(--fill); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 6px; background: var(--green); transition: width .5s cubic-bezier(.2,.8,.3,1); }
.bar.thin { height: 6px; }
.ring { --p: 0; width: 76px; height: 76px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--green) calc(var(--p) * 1%), var(--fill) 0);
  display: grid; place-items: center; transition: --p .6s; }
.ring > span { width: 60px; height: 60px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-size: 17px; font-weight: 700; letter-spacing: -.02em; }

/* Этапы пути */
.stages { display: flex; gap: 6px; margin: 14px 0 4px; }
.stage { flex: 1; text-align: center; }
.stage .dot { height: 5px; border-radius: 3px; background: var(--fill); margin-bottom: 7px; transition: background .3s; }
.stage.done .dot { background: var(--green); }
.stage.now .dot { background: var(--accent); }
.stage .e { font-size: 19px; filter: grayscale(1); opacity: .35; transition: all .3s; }
.stage.done .e, .stage.now .e { filter: none; opacity: 1; }
.stage .n { font-size: 10px; color: var(--text-3); margin-top: 3px; letter-spacing: -.01em; }
.stage.now .n { color: var(--accent); font-weight: 600; }

/* ───────── Значки и плашки ───────── */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 8px; font-size: 12px; font-weight: 600; background: var(--fill); color: var(--text-2); }
.pill.ok { background: rgba(52,199,89,.16); color: var(--green); }
.pill.mid { background: rgba(255,149,10,.16); color: var(--orange); }
.pill.bad { background: rgba(255,59,48,.16); color: var(--red); }
.pill.info { background: rgba(0,122,255,.14); color: var(--accent); }

.demo-note {
  display: flex; gap: 9px; align-items: flex-start; padding: 11px 13px; border-radius: 12px;
  background: rgba(255,149,10,.13); color: var(--orange); font-size: 13px; line-height: 1.35; margin-bottom: 14px;
}
.demo-note b { font-weight: 700; }
.note {
  display: flex; gap: 9px; align-items: flex-start; padding: 11px 13px; border-radius: 12px;
  background: var(--fill); color: var(--text-2); font-size: 13px; line-height: 1.38; margin-bottom: 14px;
}

/* ───────── Деньги ───────── */
.money-big { font-size: 40px; font-weight: 700; letter-spacing: -.035em; line-height: 1.05; }
.money-sub { color: var(--text-2); font-size: 14px; margin-top: 2px; }
.bars { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--fill); margin: 14px 0 10px; }
.bars > i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* ───────── Квартиры ───────── */
.flat-card { background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; display: block; width: 100%; text-align: left; }
.flat-card:active { transform: scale(.99); }
.flat-photo { aspect-ratio: 16/10; background: var(--card-2); display: grid; place-items: center; font-size: 40px; color: var(--text-3); position: relative; overflow: hidden; }
/* без фотографии карточка не должна зиять пустотой на пол-экрана */
.flat-photo:not(:has(img)) { aspect-ratio: 5/1.6; font-size: 30px; }
.flat-photo img { width: 100%; height: 100%; object-fit: cover; }
.flat-photo .badge { position: absolute; top: 10px; right: 10px; }
.flat-body { padding: 14px 16px 16px; }
.flat-price { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.flat-meta { color: var(--text-2); font-size: 14px; margin-top: 2px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.fact { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; background: var(--fill); padding: 5px 9px; border-radius: 9px; color: var(--text-2); }

.match-list { display: grid; gap: 9px; }
.match-row { display: flex; align-items: center; gap: 11px; font-size: 15px; }
.match-row .m-ico { width: 26px; text-align: center; font-size: 16px; flex: none; }
.match-row .m-name { flex: none; width: 76px; color: var(--text-2); font-size: 14px; }
.match-row .m-bar { flex: 1; height: 7px; border-radius: 4px; background: var(--fill); overflow: hidden; }
.match-row .m-bar i { display: block; height: 100%; border-radius: 4px; }
.match-row .m-val { flex: none; font-size: 13px; font-weight: 600; width: 80px; text-align: right; }

/* Сравнение */
.cmp { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px 6px; }
.cmp table { border-collapse: collapse; width: max-content; min-width: 100%; }
.cmp th, .cmp td { padding: 11px 12px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--sep); white-space: nowrap; }
.cmp th { font-weight: 600; font-size: 13px; color: var(--text-2); position: sticky; left: 0; background: var(--bg); z-index: 1; }
.cmp td.best { color: var(--green); font-weight: 700; }

/* ───────── Карта ───────── */
.map-wrap { border-radius: var(--r-card); overflow: hidden; box-shadow: var(--shadow); height: 62vh; min-height: 340px; }
#map { width: 100%; height: 100%; background: var(--card-2); }
.leaflet-container { font: inherit; background: var(--card-2); }
.pin { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; font-size: 14px; box-shadow: 0 2px 8px rgba(0,0,0,.3); border: 2px solid #fff; background: #fff; }
.pin.flat { background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; }
.pin.work { background: var(--purple); }
.map-filters { display: flex; gap: 7px; overflow-x: auto; padding: 10px 16px; margin: 0 -16px; -webkit-overflow-scrolling: touch; }
.map-filters .chip { flex: none; }

/* ───────── Фото ───────── */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(102px, 1fr)); gap: 8px; }
.photo-cell { aspect-ratio: 1; border-radius: 13px; overflow: hidden; background: var(--card-2); position: relative; display: block; box-shadow: var(--shadow); }
.photo-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-cell .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 7px 5px; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.75)); line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.photo-add { aspect-ratio: 1; border-radius: 13px; border: 2px dashed var(--fill-2); display: grid; place-items: center; font-size: 26px; color: var(--text-3); width: 100%; }

/* ───────── Шторка ───────── */
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 60; animation: fade .2s ease both; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  background: var(--bg-elev); border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(20px + var(--safe-b));
  max-height: 88vh; overflow-y: auto; max-width: 560px; margin: 0 auto;
  animation: up .3s cubic-bezier(.22,1,.3,1) both;
  box-shadow: 0 -8px 40px rgba(0,0,0,.25);
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: var(--fill-2); margin: 0 auto 14px; }
.sheet h3 { font-size: 21px; margin-bottom: 4px; }

/* ───────── Всплывашка ───────── */
.toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b) + 14px); z-index: 80; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { background: rgba(28,28,30,.94); color: #fff; padding: 11px 18px; border-radius: 14px; font-size: 15px; animation: up .25s cubic-bezier(.2,.9,.3,1) both; backdrop-filter: blur(20px); max-width: 90vw; text-align: center; }

/* ───────── Таб-бар ───────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: color-mix(in srgb, var(--bg-elev) 82%, transparent);
  backdrop-filter: saturate(180%) blur(22px); -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-top: 1px solid var(--sep);
}
.tabbar button { flex: 1; display: grid; place-items: center; gap: 1px; color: var(--text-3); font-size: 10px; padding-top: 6px; }
.tabbar button .te { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: .5; transition: all .2s; }
.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tabbar button[aria-current="page"] .te { filter: none; opacity: 1; transform: translateY(-1px); }

/* ───────── Пустые состояния ───────── */
.empty { text-align: center; padding: 44px 24px; color: var(--text-2); }
.empty .e { font-size: 46px; margin-bottom: 12px; filter: grayscale(.3); }
.empty h3 { font-size: 19px; color: var(--text); margin-bottom: 6px; }
.empty p { font-size: 15px; margin: 0 0 18px; line-height: 1.4; }

/* ───────── Мелочи ───────── */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; font-size: 15px; border-bottom: 1px solid var(--sep); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text-2); }
.kv .v { font-weight: 600; text-align: right; }
.kv.total { border-top: 1px solid var(--sep); border-bottom: 0; margin-top: 4px; padding-top: 12px; font-size: 17px; }
.kv.total .v { font-size: 19px; }
.hr { height: 1px; background: var(--sep); margin: 14px 0; }
.mt { margin-top: 16px; }
.mb0 { margin-bottom: 0; }
.center { text-align: center; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.stepdots { display: flex; gap: 6px; justify-content: center; margin: 4px 0 18px; }
.stepdots i { width: 7px; height: 7px; border-radius: 50%; background: var(--fill-2); transition: all .25s; }
.stepdots i.on { background: var(--accent); width: 20px; border-radius: 4px; }
