:root {
  --bg: #f4f5f7;
  --panel: rgba(255, 255, 255, 0.96);
  --text: #12161b;
  --muted: #5b6573;
  --line: rgba(18, 22, 27, 0.12);
  --accent: #d62f32;
  --accent-text: #ffffff;
  --ok: #1f9d55;
  --btn: #e9ecf0;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --panel: rgba(24, 29, 35, 0.96);
    --text: #eef1f4;
    --muted: #9aa5b1;
    --line: rgba(255, 255, 255, 0.12);
    --btn: #2a313a;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); overflow: hidden;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
#map { position: fixed; inset: 0; }

/* ---------- верхняя панель ---------- */
.topbar {
  position: fixed; top: calc(10px + var(--safe-t)); left: 12px; right: 12px; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); padding: 6px 6px 6px 14px;
}
.brand { font-weight: 700; white-space: nowrap; }
.brand span { font-weight: 400; color: var(--muted); margin-left: 6px; }
.pill {
  margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: transparent; color: var(--muted); font-size: 13px; padding: 8px 6px;
}
.pill::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: 1px; }
.pill.offline { color: #c77700; }
.pill.offline::before { background: #f08c00; }
.icon-btn { width: 44px; height: 44px; border-radius: 10px; background: transparent; display: grid; place-items: center; flex: none; }
.demo {
  position: fixed; top: calc(68px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 4;
  background: #f08c00; color: #fff; font-size: 12px; padding: 2px 10px; border-radius: 10px;
}

/* ---------- кнопки на карте ---------- */
.fab {
  position: fixed; right: 12px; bottom: calc(86px + var(--safe-b)); z-index: 5;
  width: 52px; height: 52px; border-radius: 50%; background: var(--panel); box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.bottom {
  position: fixed; left: 0; right: 0; bottom: calc(18px + var(--safe-b)); z-index: 5;
  display: flex; justify-content: center; pointer-events: none;
}
.report-btn {
  pointer-events: auto; display: inline-flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 26px; border-radius: 26px;
  background: var(--panel); color: var(--text); box-shadow: var(--shadow);
  font-size: 17px; font-weight: 600;
}
.report-btn:active, .kind:active, .ok:active, .secondary:active { transform: scale(0.97); }

/* ---------- булавка: кончик точно в центре карты ---------- */
.pin { display: none; }
body.reporting .pin { display: block; position: fixed; left: 50%; top: 50%; z-index: 3; pointer-events: none; }
.pin-icon {
  position: absolute; left: -20px; top: -51px; transition: transform 0.15s ease-out;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.3));
}
.pin-shadow {
  position: absolute; left: -6px; top: -2px; width: 12px; height: 4px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.35); transition: transform 0.15s ease-out;
}
body.moving .pin-icon { transform: translateY(-12px); }
body.moving .pin-shadow { transform: scale(1.6); opacity: 0.6; }
body.reporting .fab { bottom: calc(360px + var(--safe-b)); }

/* ---------- нижние карточки ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: var(--panel); border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  padding: 18px 16px calc(14px + var(--safe-b)); max-height: 75vh; overflow-y: auto;
}
.sheet[hidden], .bottom[hidden] { display: none; }
.sheet h2 { margin: 0 0 4px; font-size: 22px; }
.lead { margin: 0 0 12px; font-weight: 600; }
.meta { margin: 0 0 14px; color: var(--muted); }
.address { margin: -2px 0 12px; font-weight: 600; min-height: 1.4em; }
.address:empty { display: none; }
.note { margin: 6px 0 4px; color: var(--muted); font-size: 14px; }
.small { margin: 10px 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.small:empty { display: none; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.kind {
  min-height: 72px; border-radius: 14px; background: var(--accent); color: #fff; padding: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.kind b { font-size: 19px; }
.kind small { font-size: 12px; opacity: 0.85; }
.kind[data-kind="raid"] { background: #8f1d20; }
.ok, .secondary { min-height: 60px; border-radius: 14px; font-size: 18px; font-weight: 700; }
.ok { background: var(--ok); color: #fff; }
.secondary { background: var(--btn); }
.secondary:disabled { opacity: 0.6; }
.ghost { display: block; width: 100%; background: transparent; color: var(--muted); padding: 14px; margin-top: 4px; }

.search { position: relative; margin-bottom: 12px; }
.search input {
  width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line); padding: 0 14px;
  background: var(--bg); color: var(--text); font-size: 16px;
}
.search ul { list-style: none; margin: 6px 0 0; padding: 0; }
.search li button { width: 100%; text-align: left; background: transparent; padding: 12px 6px; border-bottom: 1px solid var(--line); }

.links { display: flex; flex-direction: column; margin: 14px 0 8px; }
.links a { color: var(--text); padding: 12px 0; border-bottom: 1px solid var(--line); text-decoration: none; }
.legend { display: flex; gap: 16px; color: var(--muted); font-size: 13px; margin-top: 10px; flex-wrap: wrap; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; border: 2px solid #fff; }
.dot.fresh { background: #e5383b; } .dot.mid { background: #f08c00; } .dot.old { background: #7b8794; }

.user-dot {
  width: 18px; height: 18px; border-radius: 50%; background: #2f80ed; border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(47, 128, 237, 0.25);
}

.toast {
  position: fixed; left: 16px; right: 16px; top: calc(70px + var(--safe-t)); z-index: 10;
  background: #12161b; color: #fff; border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-8px); transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { bottom: calc(80px + var(--safe-b)); }
body.reporting .maplibregl-ctrl-bottom-right { display: none; }

/* ---------- текстовые страницы ---------- */
.page { max-width: 680px; margin: 0 auto; padding: 24px 16px 48px; overflow: auto; height: 100%; }
body.text { overflow: auto; }
.page a { color: var(--accent); }
.page h1 { font-size: 26px; }
.page h2 { font-size: 19px; margin-top: 28px; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; }

@media (max-width: 400px) {
  .brand span { display: none; }
}
