:root {
  color-scheme: light dark;
  --surface: #fcfcfb;
  --page: #f9f9f7;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --base: #c3c2b7;
  --accent: #2a78d6;
  --danger: #d03b3b;
  --star: #eda100;
  --ring: rgba(11, 11, 11, 0.1);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  /* ступени одного оттенка для тепловой карты: 0 — пусто, 6 — максимум */
  --h1: #cde2fb; --h2: #9ec5f4; --h3: #6da7ec;
  --h4: #2a78d6; --h5: #184f95; --h6: #0d366b;
  --h1-ink: #0b0b0b; --h2-ink: #0b0b0b; --h3-ink: #0b0b0b;
  --h4-ink: #fff; --h5-ink: #fff; --h6-ink: #fff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface: #1a1a19;
    --page: #0d0d0d;
    --ink: #f0efec;
    --ink2: #c3c2b7;
    --line: #2c2c2a;
    --base: #383835;
    --accent: #3987e5;
    --ring: rgba(255, 255, 255, 0.1);
    --h1: #0d366b; --h2: #104281; --h3: #184f95;
    --h4: #2a78d6; --h5: #6da7ec; --h6: #b7d3f6;
    --h1-ink: #fff; --h2-ink: #fff; --h3-ink: #fff;
    --h4-ink: #fff; --h5-ink: #0b0b0b; --h6-ink: #0b0b0b;
  }
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9); }
}

[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}
/* в свёрнутом приложении содержимое не должно попадать в превью переключателя задач */
body.cover::after { content: ""; position: fixed; inset: 0; background: var(--page); z-index: 5000; }

#map {
  position: fixed;
  inset: 0;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.leaflet-container { font: inherit; background: var(--page); }
.leaflet-control-attribution { font-size: 10px; }
.leaflet-bottom.leaflet-left { margin-bottom: env(safe-area-inset-bottom); }

/* ---------- кнопки на карте ---------- */
.tools {
  position: fixed;
  z-index: 900;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tools.bottom {
  top: auto;
  bottom: calc(28px + env(safe-area-inset-bottom));
}
.fab {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--ring);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}
.fab { position: relative; }
#btn-sync::after { content: ""; position: absolute; top: 6px; right: 6px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--surface); background: var(--muted); }
#btn-sync[data-state="ok"]::after { background: #0ca30c; }
#btn-sync[data-state="busy"]::after { background: var(--accent); animation: pulse 0.7s ease-in-out infinite alternate; }
#btn-sync[data-state="auth"]::after { background: var(--danger); }
.fab.main { width: 56px; height: 56px; background: var(--accent); color: #fff; border-color: transparent; }
.fab.on { outline: 2px solid var(--accent); }
.fab.flat { box-shadow: none; background: transparent; border-color: transparent; }
.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#toast {
  position: fixed;
  z-index: 3500;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 86vw;
  background: #0b0b0b;
  color: #fff;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}

/* ---------- пины ---------- */
.pin { background: none; border: none; }
.pin svg { width: 34px; height: 44px; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35)); }
.pin b {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: #0b0b0b;
  color: #fff;
  font: 600 11px/18px system-ui, sans-serif;
  text-align: center;
}
.pin.ghost svg { animation: pulse 0.9s ease-in-out infinite alternate; }
@keyframes pulse { from { transform: scale(0.9); opacity: 0.6; } to { transform: scale(1.05); opacity: 1; } }
.me-dot { background: #2a78d6; border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3); }

/* ---------- нижние листы ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#sheet {
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  animation: up 0.18s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
#sheet h2 { margin: 0; font-size: 20px; }
#sheet h3 { margin: 22px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.sh-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sub { color: var(--muted); font-size: 13px; margin: 2px 0 12px; }
.hint { color: var(--ink2); font-size: 14px; margin: 6px 0; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; }
.icon-btn { background: none; border: 0; color: var(--ink2); font-size: 20px; padding: 6px 10px; cursor: pointer; }

label { display: block; margin: 14px 0 0; font-size: 13px; color: var(--ink2); }
.lbl { margin: 14px 0 6px; font-size: 13px; color: var(--ink2); }
input[type="text"], input[type="password"], input[type="datetime-local"], textarea, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--base);
  border-radius: 8px;
}
textarea { resize: vertical; }
input[type="color"] { width: 40px; height: 36px; padding: 0; border: 1px solid var(--base); border-radius: 8px; background: none; }

.btn {
  font: inherit;
  font-weight: 600;
  padding: 11px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.btn.sec { background: transparent; color: var(--ink); border-color: var(--base); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: 0.5; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.row .grow { flex: 1; }
form .btn { margin-top: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 15px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--page);
  color: var(--ink);
  border: 1px solid var(--base);
  cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--page)); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; }

.stepper { display: flex; align-items: center; gap: 14px; }
.stepper button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--base); background: var(--page); color: var(--ink); font-size: 22px; cursor: pointer; }
.stepper output { min-width: 36px; text-align: center; font-size: 22px; font-weight: 600; }
.stars { display: flex; gap: 4px; }
.stars button { background: none; border: 0; font-size: 30px; line-height: 1; padding: 2px 4px; color: var(--base); cursor: pointer; }
.stars button.on { color: var(--star); }

.entries { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 12px 2px;
  cursor: pointer;
}
.entry .e-main { flex: 1; min-width: 0; }
.entry small { display: block; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .e-stars { color: var(--star); font-size: 14px; letter-spacing: 1px; }

.cat-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cat-row input[type="text"] { margin: 0; flex: 1; }

/* ---------- замок ---------- */
.lock { position: fixed; inset: 0; z-index: 3000; background: var(--page); display: grid; place-items: center; padding: 24px; overflow-y: auto; }
.lock-box { width: 100%; max-width: 360px; text-align: center; }
.lock-box h1 { margin: 12px 0 6px; font-size: 26px; }
.lock-box p { color: var(--ink2); }
.lock-box .logo { width: 72px; height: 72px; margin: 0 auto; border-radius: 18px; background: var(--accent); display: grid; place-items: center; }
.lock-box .logo svg { width: 40px; height: 40px; fill: #fff; }
.lock-box input { text-align: center; margin-top: 10px; }
.lock-box .btn { width: 100%; margin-top: 10px; }
.lock-box .link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; margin-top: 18px; cursor: pointer; text-decoration: underline; }

/* ---------- статистика ---------- */
.page { position: fixed; inset: 0; z-index: 1500; background: var(--page); overflow-y: auto; }
.page-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px;
  background: var(--page);
  border-bottom: 1px solid var(--line);
}
.page-head h1 { margin: 0; font-size: 22px; }
.page-body { max-width: 640px; margin: 0 auto; padding: 14px 16px calc(40px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 14px; padding: 14px 16px; }
.card h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; color: var(--ink2); }
.empty { text-align: center; color: var(--ink2); padding: 40px 10px; }
.note { font-size: 13px; color: var(--muted); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--ring); border-radius: 14px; padding: 12px 16px; }
.tile b { display: block; font-size: 30px; line-height: 1.15; }
.tile span { font-size: 13px; color: var(--ink2); }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 150px; }
.bars .col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.bars .v { font-size: 11px; color: var(--ink2); height: 14px; }
.bars .area { width: 100%; flex: 1; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--base); }
.bars .bar { width: min(100%, 20px); background: var(--accent); border-radius: 4px 4px 0 0; }
.bars .col[aria-pressed="true"] .bar { outline: 2px solid var(--ink); outline-offset: 1px; }
.bars .l { font-size: 10px; color: var(--muted); height: 14px; }
.readout { min-height: 22px; margin-top: 8px; font-size: 14px; color: var(--ink2); }
details summary { cursor: pointer; font-size: 13px; color: var(--muted); margin-top: 8px; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; }
table.t th, table.t td { text-align: left; padding: 4px 0; border-bottom: 1px solid var(--line); }
table.t td:last-child, table.t th:last-child { text-align: right; }

.hbar { display: grid; grid-template-columns: minmax(70px, 34%) 1fr auto; align-items: center; gap: 10px; margin: 8px 0; font-size: 14px; }
.hbar .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar .name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 12px; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .val { color: var(--ink2); font-variant-numeric: tabular-nums; white-space: nowrap; }

.heat { display: grid; grid-template-columns: 34px repeat(4, 1fr); gap: 2px; font-size: 12px; }
.heat .hh { text-align: center; color: var(--muted); padding-bottom: 2px; }
.heat .hr { color: var(--muted); display: flex; align-items: center; }
.heat .c { height: 34px; border-radius: 4px; display: grid; place-items: center; font-size: 13px; background: var(--line); color: var(--muted); }
.heat .c.h1 { background: var(--h1); color: var(--h1-ink); }
.heat .c.h2 { background: var(--h2); color: var(--h2-ink); }
.heat .c.h3 { background: var(--h3); color: var(--h3-ink); }
.heat .c.h4 { background: var(--h4); color: var(--h4-ink); }
.heat .c.h5 { background: var(--h5); color: var(--h5-ink); }
.heat .c.h6 { background: var(--h6); color: var(--h6-ink); }

dl.facts { margin: 0; }
dl.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
dl.facts div:last-child { border-bottom: 0; }
dl.facts dt { color: var(--ink2); }
dl.facts dd { margin: 0; font-weight: 600; text-align: right; }
