:root {
  --bg: #ffffff;
  --bg2: #f3f5f4;
  --fg: #16201d;
  --muted: #5f6b67;
  --line: #e1e6e4;
  --accent: #1f6f5c;
  --accent-fg: #ffffff;
  --accent-soft: #e3f1ec;
  --danger: #b3261e;
  --warn-bg: #fff4d6;
  --warn-fg: #6b4e00;
  --ok: #1e8e4a;
  --shadow: 0 2px 10px rgba(0,0,0,.14), 0 1px 3px rgba(0,0,0,.08);
  --r: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b2120; --bg2: #252c2a; --fg: #e9eeec; --muted: #9aa6a2; --line: #333c39;
    --accent: #5cc4a6; --accent-fg: #0b1b16; --accent-soft: #23372f;
    --danger: #ff8a80; --warn-bg: #3a3010; --warn-fg: #ffd970; --ok: #6fdc98;
    --shadow: 0 2px 12px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg);
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg:not(.leaflet-zoom-animated) { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#map { position: fixed; inset: 0; height: 100dvh; background: var(--bg2); }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 10px; opacity: .7; }
.leaflet-bottom.leaflet-left { bottom: var(--sab); }

/* ---------- пошук */
.top {
  position: fixed; z-index: 1000; left: 0; right: 0; top: 0;
  padding: calc(var(--sat) + 10px) 12px 0; pointer-events: none;
  max-width: 520px;
}
.top > * { pointer-events: auto; }
.search {
  display: flex; align-items: center; gap: 4px;
  background: var(--bg); border-radius: 28px; box-shadow: var(--shadow);
  height: 52px; padding: 0 6px 0 14px;
}
.search .ico { color: var(--muted); flex: none; width: 20px; height: 20px; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font-size: 16.5px; letter-spacing: 0; padding: 0 4px; height: 100%;
  font-variant-numeric: tabular-nums;
}
.search input::placeholder { color: var(--muted); letter-spacing: 0; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: 50%;
  display: grid; place-items: center; color: var(--muted); flex: none;
}
.icon-btn:active { background: var(--bg2); }
.search .icon-btn { width: 36px; }
.avatar {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: var(--accent-fg); font-weight: 600; font-size: 15px;
  position: relative;
}
.avatar[data-dot]::after {
  content: ""; position: absolute; top: 0; right: 0; width: 11px; height: 11px;
  border-radius: 50%; background: var(--danger); border: 2px solid var(--bg);
}
.recent {
  list-style: none; margin: 6px 0 0; padding: 6px 0; background: var(--bg);
  border-radius: var(--r); box-shadow: var(--shadow); max-height: 50vh; overflow: auto;
}
.recent li button {
  display: flex; width: 100%; align-items: center; gap: 12px; text-align: left;
  border: 0; background: none; padding: 11px 16px; font-variant-numeric: tabular-nums;
}
.recent li button:active { background: var(--bg2); }
.recent small { color: var(--muted); margin-left: auto; font-size: 13px; }
.banner {
  margin-top: 8px; background: var(--warn-bg); color: var(--warn-fg);
  border-radius: 12px; padding: 9px 14px; font-size: 14px; box-shadow: var(--shadow);
}

/* ---------- кнопки карти */
.fabs {
  position: fixed; z-index: 900; right: 12px;
  bottom: calc(var(--sab) + 24px + var(--sheet-h, 0px));
  display: flex; flex-direction: column; gap: 10px;
  transition: bottom .2s ease;
}
.fab {
  width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--bg);
  box-shadow: var(--shadow); display: grid; place-items: center; color: var(--fg);
}
.fab.on { color: var(--accent); }
.fab.busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.pop {
  position: fixed; z-index: 950; right: 70px; width: 240px;
  bottom: calc(var(--sab) + 24px + var(--sheet-h, 0px));
  background: var(--bg); border-radius: var(--r); box-shadow: var(--shadow); padding: 12px;
}
.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 8px 6px;
  color: var(--muted); font-size: 15px;
}
.seg button.on { background: var(--bg); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
.row-toggle { display: flex; align-items: center; justify-content: space-between; padding: 12px 2px 2px; gap: 12px; }
.row-toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 8px 2px 0; }

/* ---------- шторка */
.sheet {
  position: fixed; z-index: 1100; left: 0; right: 0; bottom: 0;
  background: var(--bg); border-radius: 18px 18px 0 0; box-shadow: 0 -2px 16px rgba(0,0,0,.18);
  padding: 0 16px calc(var(--sab) + 12px);
  max-height: 85dvh; overflow-y: auto; overscroll-behavior: contain;
  transform: translateY(0); transition: transform .22s ease;
  touch-action: pan-y;
}
.sheet.dragging { transition: none; }
.grab { padding: 10px 0 6px; display: grid; place-items: center; cursor: grab; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.grab span { width: 40px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet .cad {
  font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: .01em;
  border: 0; background: none; padding: 0; text-align: left; word-break: break-all;
}
.sheet .sub { color: var(--muted); margin: 4px 0 0; font-size: 15px; }
.sheet .sub b { color: var(--fg); font-weight: 600; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 6px; }
.actions button {
  border: 0; background: var(--bg2); border-radius: 12px; padding: 10px 4px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12.5px; color: var(--fg);
}
.actions button svg { color: var(--accent); }
.actions button.on svg { fill: var(--accent); }
.actions button:active { filter: brightness(.95); }
dl.kv { margin: 10px 0 0; display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: 0; font-size: 14.5px; }
dl.kv dt, dl.kv dd { padding: 9px 0; border-top: 1px solid var(--line); margin: 0; }
dl.kv dt { color: var(--muted); padding-right: 10px; }
dl.kv dd { word-break: break-word; }
details.more { margin-top: 8px; }
details.more summary { color: var(--accent); padding: 10px 0; cursor: pointer; list-style: none; font-weight: 600; font-size: 15px; }
details.more summary::-webkit-details-marker { display: none; }
.note-box { width: 100%; min-height: 64px; margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--bg2); resize: vertical; }
.loading { display: flex; gap: 12px; align-items: center; color: var(--muted); padding: 10px 0 14px; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.err { color: var(--danger); padding: 4px 0 12px; }
.warn { background: var(--warn-bg); color: var(--warn-fg); border-radius: 10px; padding: 8px 12px; font-size: 13.5px; margin-top: 10px; }
.pick { list-style: none; padding: 0; margin: 4px 0 8px; }
.pick button { width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: none; padding: 12px 0; font-variant-numeric: tabular-nums; }

/* ---------- панель */
.scrim { position: fixed; inset: 0; z-index: 1190; background: rgba(0,0,0,.35); }
.panel {
  position: fixed; z-index: 1200; inset: 0; background: var(--bg);
  display: flex; flex-direction: column; padding-top: var(--sat);
}
@media (min-width: 720px) {
  .panel { left: auto; width: 420px; box-shadow: var(--shadow); }
  .top { padding-left: 16px; }
  .sheet { left: 16px; right: auto; width: 420px; bottom: 16px; border-radius: 18px; max-height: calc(100dvh - 110px); }
  .fabs, .pop { --sheet-h: 0px !important; }
}
.panel-head { display: flex; align-items: center; gap: 4px; padding: 6px 6px; border-bottom: 1px solid var(--line); }
.panel-head h2 { flex: 1; margin: 0; font-size: 18px; }
.panel-body { flex: 1; overflow-y: auto; padding: 8px 16px calc(var(--sab) + 24px); }
.menu { list-style: none; margin: 0; padding: 0; }
.menu button, .menu a {
  display: flex; align-items: center; gap: 14px; width: 100%; border: 0; background: none;
  padding: 14px 4px; text-align: left; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--fg); font-size: 16px;
}
.menu button svg { color: var(--muted); }
.menu .badge { margin-left: auto; }
.me { display: flex; align-items: center; gap: 12px; padding: 12px 4px 16px; }
.me .avatar { width: 48px; height: 48px; font-size: 18px; }
.me small { color: var(--muted); display: block; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--bg2); color: var(--muted); font-weight: 600; }
.badge.ok { background: var(--accent-soft); color: var(--ok); }
.badge.bad { background: #fde7e6; color: var(--danger); }
@media (prefers-color-scheme: dark) { .badge.bad { background: #3b1f1d; } }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list .grow { flex: 1; min-width: 0; }
.list .grow > * { display: block; overflow: hidden; text-overflow: ellipsis; }
.list small { color: var(--muted); font-size: 13px; }
.list .mono { font-variant-numeric: tabular-nums; font-weight: 600; }
.list button.link { border: 0; background: none; padding: 0; text-align: left; width: 100%; }
.empty { color: var(--muted); text-align: center; padding: 40px 10px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }

.form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.form input, .form textarea, .form select {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 12px;
  padding: 12px 14px; font-size: 16px; color: var(--fg); outline: none;
}
.form input:focus, .form textarea:focus { border-color: var(--accent); }
.form textarea { min-height: 110px; font-family: ui-monospace, monospace; font-size: 13px; }
.btn {
  border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 600; font-size: 16px;
  background: var(--bg2); color: var(--fg);
}
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .55; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.status-card { background: var(--bg2); border-radius: var(--r); padding: 14px; margin-top: 8px; }
.status-card .big { font-size: 18px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--danger); }
.status-card p { margin: 6px 0 0; color: var(--muted); font-size: 14px; word-break: break-word; }

.toast {
  position: fixed; z-index: 2000; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sab) + 24px); background: #222; color: #fff; padding: 10px 16px;
  border-radius: 20px; font-size: 14.5px; max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}

/* ---------- вхід */
.auth-page { background: var(--bg2); min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth { width: 100%; max-width: 380px; background: var(--bg); border-radius: 20px; padding: 28px 20px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand h1 { margin: 0; font-size: 24px; }
.msg { margin: 14px 0 0; color: var(--danger); font-size: 14.5px; }
.msg.ok { color: var(--ok); }

.list li.user { flex-wrap: wrap; }
.user-acts { flex-basis: 100%; padding-top: 4px; }
.user-acts .btn { flex: 1 1 45%; }
a { color: var(--accent); }
.sub-label { display: block; font-size: 12px; color: var(--muted); line-height: 1.3; margin-top: 2px; }
