/* ============================================================
   База недвижимости Грозного — две темы:
   тёмная «стекло» (Pane) и светлая пастельная (Dashboard V13).
   Тема ставится в app.js: <body data-theme="dark|light">
   ============================================================ */

:root {
  --bg: #0d1016;
  --fg: #edf1f7;
  --hint: #8e97a6;
  --accent: #4f8cff;
  --accent-fg: #ffffff;
  --card: rgba(255, 255, 255, 0.05);
  --card-solid: #171c25;
  --line: rgba(255, 255, 255, 0.08);
  --free: #2ec27e;
  --booked: #e8a93c;
  --sold: #6f7987;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  /* плитки статистики — тихие стеклянные заливки */
  --tile-1: rgba(124, 108, 255, 0.14);
  --tile-2: rgba(46, 194, 126, 0.12);
  --tile-3: rgba(232, 169, 60, 0.12);
  --tile-4: rgba(79, 140, 255, 0.13);
  --blur: blur(18px) saturate(160%);
}

body[data-theme="light"] {
  /* тёплый крем в стиле rapport */
  --bg: #f3eee3;
  --fg: #211e18;
  --hint: #8d8371;
  --accent: #23262a;
  --accent-fg: #f6f1e6;
  --card: #fffdf7;
  --card-solid: #fffdf7;
  --line: rgba(70, 58, 35, 0.09);
  --free: #1e7f54;
  --booked: #c9861f;
  --sold: #a79e8c;
  --shadow: 0 6px 22px rgba(90, 74, 40, 0.10);
  /* плитки: песок, шалфей, горчица, терракота */
  --tile-1: #ece4d2;
  --tile-2: #e0ebdf;
  --tile-3: #f3e2b4;
  --tile-4: #f1dccb;
  --blur: none;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding: 14px 14px 96px;
  min-height: 100vh;
}

/* мягкое свечение сверху — только в тёмной теме */
.glow {
  position: fixed; inset: -30% -20% auto; height: 55vh; z-index: -1;
  background: radial-gradient(ellipse at 50% 0%,
              rgba(79, 140, 255, 0.16), transparent 65%);
}
body[data-theme="light"] .glow { display: none; }

.hidden { display: none !important; }

/* ---------- заголовки ---------- */
.pagehead { margin: 4px 2px 12px; }
.pagehead h1, .page-title {
  font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1;
}
.pagesub, .page-sub { color: var(--hint); font-size: 13.5px; margin-top: 3px; }
.section-title {
  font-size: 17px; font-weight: 800; letter-spacing: -0.01em; margin: 20px 2px 10px;
}

/* ---------- карточки-основа ---------- */
.card-base {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
}

/* ---------- поиск ---------- */
.search-box input {
  width: 100%; padding: 12px 15px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  color: var(--fg); font-size: 15px; outline: none;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
}
.search-box input::placeholder { color: var(--hint); }
.search-box input:focus-visible { border-color: var(--accent); }

/* ---------- список объектов ---------- */
.complex-item {
  display: flex; gap: 12px; margin-top: 12px; padding: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow); cursor: pointer;
  transition: transform 120ms ease-out;
}
.complex-item:active { transform: scale(0.98); }
.complex-item img, .complex-item .noimg {
  width: 92px; height: 92px; border-radius: 12px; object-fit: cover;
  background: var(--tile-4); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 32px;
}
.complex-item .info { min-width: 0; padding: 2px 0; }
.complex-item .name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.complex-item .sub { color: var(--hint); font-size: 13px; margin-top: 2px; }
.complex-item .price { margin-top: 7px; font-weight: 700; font-size: 14.5px; }
.complex-item .free { color: var(--free); font-size: 13px; margin-top: 2px; font-weight: 600; }
.empty { text-align: center; color: var(--hint); padding: 44px 0; }

/* ---------- страница проекта ---------- */
.back {
  color: var(--accent); background: none; border: 0;
  font-size: 15px; font-weight: 600; padding: 2px 0 12px; cursor: pointer;
}
.gallery {
  display: flex; gap: 10px; overflow-x: auto; margin-bottom: 14px;
  scroll-snap-type: x mandatory; border-radius: 18px;
  -webkit-overflow-scrolling: touch;
}
.gallery::-webkit-scrollbar { display: none; }
.gallery img, .gallery video {
  height: 210px; width: 86%; flex-shrink: 0; object-fit: cover;
  border-radius: 18px; scroll-snap-align: start; background: var(--card-solid);
}
.card-title { font-size: 23px; font-weight: 800; letter-spacing: -0.02em; }
.card-sub { color: var(--hint); margin: 4px 0 12px; font-size: 13.5px; }

/* плитки статистики (2 колонки) */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 4px; }
.stat {
  border-radius: 16px; padding: 14px 14px 12px;
  border: 1px solid var(--line);
}
.stat:nth-child(4n+1) { background: var(--tile-1); }
.stat:nth-child(4n+2) { background: var(--tile-2); }
.stat:nth-child(4n+3) { background: var(--tile-3); }
.stat:nth-child(4n+4) { background: var(--tile-4); }
.stat .num { font-size: 23px; font-weight: 800; letter-spacing: -0.02em; }
.stat .lbl { color: var(--hint); font-size: 12.5px; margin-top: 3px; }
.stat.wide { grid-column: 1 / -1; }
body[data-theme="light"] .stat { border: 0; }

.kv { display: flex; justify-content: space-between; gap: 14px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.kv .k { color: var(--hint); flex-shrink: 0; }
.kv .v { text-align: right; font-weight: 600; }
.desc { margin: 14px 2px; color: var(--fg); }

.building-btn {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; margin-top: 10px; padding: 15px 16px;
  border: 0; border-radius: 16px; background: var(--accent); color: var(--accent-fg);
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform 120ms ease-out;
}
.building-btn:active { transform: scale(0.98); }
.building-btn small { font-weight: 500; opacity: 0.85; }

/* ---------- шахматка ---------- */
.grid-title { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 4px; }
.legend { display: flex; gap: 16px; color: var(--hint); font-size: 13px; margin: 10px 0 14px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.grid-scroll {
  overflow-x: auto; padding: 14px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
}
.floor-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.floor-num { width: 24px; flex-shrink: 0; color: var(--hint); font-size: 11.5px; text-align: right; }
.unit {
  min-width: 54px; padding: 7px 4px; border-radius: 9px; text-align: center;
  color: #fff; font-size: 12px; font-weight: 700; cursor: pointer; flex-shrink: 0;
  transition: transform 100ms ease-out;
}
.unit:active { transform: scale(0.94); }
.unit small { display: block; font-weight: 500; font-size: 10px; opacity: 0.9; }
.unit.free { background: var(--free); }
.unit.booked { background: var(--booked); }
.unit.sold { background: var(--sold); }

/* ---------- графики-бары ---------- */
.bars-card { padding: 16px 16px 12px; }
.bars { display: flex; align-items: flex-end; gap: 7px; height: 110px; margin-top: 18px; }
.bar {
  flex: 1; border-radius: 7px 7px 3px 3px; min-height: 6px; position: relative;
  background: linear-gradient(180deg, var(--accent), rgba(79,140,255,0.55));
}
body[data-theme="light"] .bar { background: var(--accent); opacity: 0.85; }
.bar b {
  position: absolute; top: -17px; left: 50%; transform: translateX(-50%);
  font-size: 9.5px; color: var(--hint); font-weight: 600; white-space: nowrap;
}
.bars-labels { display: flex; gap: 7px; margin-top: 6px; }
.bars-labels span { flex: 1; text-align: center; font-size: 10px; color: var(--hint); }

/* ---------- строки-списки ---------- */
.row-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 2px; border-bottom: 1px solid var(--line);
}
.row-item .l { font-weight: 600; min-width: 0; }
.row-item .r { color: var(--hint); flex-shrink: 0; font-size: 13.5px; }
.row-item.tap { cursor: pointer; }

/* ---------- бейджи и пилюли ---------- */
.pill {
  display: inline-block; padding: 4px 11px; border-radius: 20px;
  font-size: 12.5px; font-weight: 700;
}
.pill-ok { background: rgba(46, 194, 126, 0.16); color: var(--free); }
.pill-warn { background: rgba(232, 169, 60, 0.16); color: var(--booked); }
.pill-off { background: rgba(130, 138, 150, 0.16); color: var(--hint); }
.pill-role { background: var(--tile-1); color: var(--fg); }

/* ---------- команда (как V13) ---------- */
.member {
  display: flex; gap: 12px; align-items: flex-start;
  margin-top: 12px; padding: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
}
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; color: var(--accent-fg);
  background: linear-gradient(135deg, var(--accent), #7c6cff);
}
.member .body { min-width: 0; flex: 1; }
.member .name { font-weight: 700; font-size: 15.5px; }
.member .meta { color: var(--hint); font-size: 12.5px; margin: 2px 0 8px; }
.member .stats { display: flex; gap: 14px; color: var(--hint); font-size: 12.5px; }
.member .stats b { color: var(--fg); font-size: 14px; font-weight: 700; display: block; }

/* ---------- попап квартиры ---------- */
.popup {
  position: fixed; inset: 0; background: rgba(8, 10, 14, 0.55);
  display: flex; align-items: flex-end; z-index: 10;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.popup-content {
  width: 100%; background: var(--card-solid);
  border: 1px solid var(--line); border-bottom: 0;
  border-radius: 22px 22px 0 0; padding: 20px 18px 30px;
}
.popup-content h3 { font-size: 19px; letter-spacing: -0.01em; margin-bottom: 10px; }
.status-badge {
  display: inline-block; padding: 4px 12px; border-radius: 20px;
  color: #fff; font-size: 13px; font-weight: 700; margin-bottom: 10px;
}
.popup-actions { display: flex; gap: 8px; margin-top: 16px; }
.popup-actions button {
  flex: 1; padding: 13px; border: 0; border-radius: 14px;
  font-size: 14.5px; font-weight: 700; cursor: pointer;
  transition: transform 120ms ease-out;
}
.popup-actions button:active { transform: scale(0.97); }
.btn-fav { background: var(--card); border: 1px solid var(--line) !important; color: var(--fg); }
.btn-fav.on { background: rgba(232, 169, 60, 0.16); color: var(--booked); border-color: transparent !important; }
.btn-share { background: var(--accent); color: var(--accent-fg); }

/* ---------- нижняя навигация (плавающее стекло) ---------- */
.bottombar {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 5;
  display: flex; padding: 7px 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  backdrop-filter: blur(22px) saturate(170%);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  box-shadow: var(--shadow);
}
body[data-theme="light"] .bottombar { background: rgba(255, 255, 255, 0.82); }
.nav {
  flex: 1; border: 0; background: none; color: var(--hint);
  font-size: 19px; padding: 5px 0 3px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; cursor: pointer; border-radius: 14px;
}
.nav span { font-size: 10px; font-weight: 700; }
.nav.active { color: var(--accent); }

.error {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 24px; font-size: 16px; z-index: 20;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .card-base, .complex-item, .grid-scroll, .member, .bottombar, .search-box input
  { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--card-solid); }
}

/* ===== Аналитика ЖК ===== */
.donut-wrap { display: flex; align-items: center; gap: 20px; padding: 18px 16px; }
.donut {
  width: 128px; height: 128px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; position: relative;
}
.donut::after {
  content: ""; position: absolute; inset: 15px; border-radius: 50%;
  background: var(--card-solid);
}
.donut .center { position: relative; z-index: 1; text-align: center; }
.donut .center b { font-size: 24px; font-weight: 800; display: block; letter-spacing: -0.02em; }
.donut .center small { color: var(--hint); font-size: 11px; }
.donut-legend { display: flex; flex-direction: column; gap: 9px; font-size: 13.5px; min-width: 0; }
.donut-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; }
.donut-legend b { font-variant-numeric: tabular-nums; }

.money-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }

.rooms-row { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 2px; border-bottom: 1px solid var(--line); }
.rooms-row .t { font-weight: 700; }
.rooms-row .d { color: var(--hint); font-size: 13px; }
.rooms-row .p { font-weight: 700; flex-shrink: 0; font-variant-numeric: tabular-nums; }

.floors-heat { display: flex; gap: 5px; flex-wrap: wrap; padding: 16px 14px; }
.heat-cell { width: 44px; border-radius: 9px; padding: 7px 0 6px; text-align: center; color: #fff; }
.heat-cell b { display: block; font-size: 13px; font-weight: 800; }
.heat-cell small { font-size: 9.5px; opacity: 0.92; }


/* ===== CRM: чипы, формы, сделки ===== */
.kind-chips, .stage-chips { display: flex; gap: 8px; margin: 2px 0 4px; overflow-x: auto; padding-bottom: 4px; }
.kind-chips::-webkit-scrollbar, .stage-chips::-webkit-scrollbar { display: none; }
.chip {
  padding: 8px 15px; border: 1px solid var(--line); border-radius: 20px;
  background: var(--card); color: var(--fg); font-size: 13.5px; font-weight: 700;
  cursor: pointer; flex-shrink: 0;
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
}
.chip.active { background: var(--accent); color: var(--accent-fg); border-color: transparent; }

.add-btn {
  width: 100%; margin: 10px 0 2px; padding: 14px; border: 0; border-radius: 16px;
  background: var(--accent); color: var(--accent-fg); font-size: 15px; font-weight: 700;
  cursor: pointer; transition: transform 120ms ease-out;
}
.add-btn:active { transform: scale(0.98); }

/* карточка сделки — цвет по стадии, как карточки в rapport */
.deal {
  margin-top: 12px; padding: 14px 15px; border-radius: 18px;
  border: 1px solid var(--line); box-shadow: var(--shadow); cursor: default;
}
.deal .top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.deal .client { font-weight: 800; font-size: 15.5px; letter-spacing: -0.01em; }
.deal .sum { font-weight: 800; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.deal .obj { color: var(--hint); font-size: 13px; margin-top: 3px; }
.deal .foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 11px; }
.deal .agent { color: var(--hint); font-size: 12px; }
.deal-actions { display: flex; gap: 7px; }
.deal-actions button {
  border: 0; border-radius: 11px; padding: 8px 13px; font-size: 13px; font-weight: 700;
  cursor: pointer; background: var(--card-solid); color: var(--fg);
  border: 1px solid var(--line);
}
.deal-actions .next { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.deal.s-lead    { background: var(--tile-3); }
.deal.s-showing { background: var(--tile-2); }
.deal.s-booked  { background: var(--tile-4); }
.deal.s-won     { background: rgba(46,194,126,0.16); }
.deal.s-lost    { background: var(--card); opacity: 0.7; }
body[data-theme="light"] .deal { border: 0; }

/* формы в попапе */
.form-field { margin-top: 12px; }
.form-field label { display: block; color: var(--hint); font-size: 12.5px; margin-bottom: 5px; }
.form-field input, .form-field textarea, .form-field select {
  width: 100%; padding: 12px 13px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--fg); font-size: 15px; outline: none;
}
.form-field input:focus-visible, .form-field textarea:focus-visible { border-color: var(--accent); }
.form-submit {
  width: 100%; margin-top: 16px; padding: 14px; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-fg); font-size: 15px; font-weight: 700; cursor: pointer;
}
.status-switch { display: flex; gap: 7px; margin-top: 6px; }
.status-switch button {
  flex: 1; padding: 10px 4px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); font-size: 13px; font-weight: 700; cursor: pointer;
}
.status-switch button.on-free   { background: var(--free);   color: #fff; border-color: transparent; }
.status-switch button.on-booked { background: var(--booked); color: #fff; border-color: transparent; }
.status-switch button.on-sold   { background: var(--sold);   color: #fff; border-color: transparent; }
.edit-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
  border-radius: 12px; padding: 7px 13px; font-size: 13.5px; font-weight: 700; cursor: pointer;
}
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: var(--card-solid); border: 1px solid var(--line); color: var(--fg);
  padding: 11px 17px; border-radius: 14px; font-size: 13.5px; z-index: 30;
  max-width: 86%; text-align: center; box-shadow: var(--shadow);
}

/* ===== Движение интерфейса (без внешних сервисов) ===== */

/* экраны мягко появляются */
.screen { animation: screen-in 240ms cubic-bezier(.2,.8,.3,1); }
@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* попапы выезжают снизу как шторка */
.popup-content { animation: sheet-up 300ms cubic-bezier(.2,.9,.25,1); }
@keyframes sheet-up {
  from { transform: translateY(60px); opacity: .4; }
  to   { transform: none; opacity: 1; }
}

/* бары графиков вырастают */
.bar { animation: bar-grow 500ms cubic-bezier(.2,.8,.3,1) backwards; transform-origin: bottom; }
.bar:nth-child(2) { animation-delay: 40ms; } .bar:nth-child(3) { animation-delay: 80ms; }
.bar:nth-child(4) { animation-delay: 120ms; } .bar:nth-child(5) { animation-delay: 160ms; }
.bar:nth-child(6) { animation-delay: 200ms; } .bar:nth-child(7) { animation-delay: 240ms; }
@keyframes bar-grow { from { transform: scaleY(0); } to { transform: none; } }

/* кольцо аналитики плавно проявляется */
.donut { animation: donut-in 420ms cubic-bezier(.2,.8,.3,1); }
@keyframes donut-in { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }

/* карточки списка слегка приподнимаются при появлении */
.complex-item, .deal, .member { animation: card-in 260ms cubic-bezier(.2,.8,.3,1) backwards; }
.complex-item:nth-child(2), .deal:nth-child(3), .member:nth-child(2) { animation-delay: 50ms; }
.complex-item:nth-child(3), .deal:nth-child(4), .member:nth-child(3) { animation-delay: 100ms; }
.complex-item:nth-child(4), .deal:nth-child(5), .member:nth-child(4) { animation-delay: 150ms; }
@keyframes card-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.toast { animation: sheet-up 240ms cubic-bezier(.2,.9,.25,1); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
}

/* ===== фикс клавиатуры iOS: формы — шторкой сверху, со скроллом ===== */
.popup-content { max-height: 86vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.popup.form-top { align-items: flex-start; }
.popup.form-top .popup-content {
  border-radius: 0 0 22px 22px; border-top: 0; border-bottom: 1px solid var(--line);
  max-height: 75vh;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
}
