/* ============ Токени ============ */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;

  --sheet-bg: rgba(246, 246, 248, 0.88);
  --sheet-solid: #f2f2f7;
  --card: #ffffff;
  --fill: rgba(118, 118, 128, 0.12);
  --fill-2: rgba(118, 118, 128, 0.2);
  --sep: rgba(60, 60, 67, 0.16);
  --text: #0b0b0f;
  --text-2: rgba(60, 60, 67, 0.62);
  --text-3: rgba(60, 60, 67, 0.36);
  --accent: #0a7aff;
  --ctl-bg: rgba(255, 255, 255, 0.86);
  --shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.08), 0 4px 18px rgba(0, 0, 0, 0.14);
  --halo: rgba(251, 244, 226, 0.95);
  --map-bg: #a7c3b7;

  --r-sheet: 14px;
  --r-card: 12px;
  --ease-out: cubic-bezier(0.2, 0.9, 0.25, 1);
  --ease-spring: cubic-bezier(0.32, 1.25, 0.5, 1);

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --peek: calc(68px + var(--sab));
  --sheet-h: 96px;

  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --sheet-bg: rgba(30, 30, 32, 0.86);
    --sheet-solid: #1c1c1e;
    --card: #2c2c2e;
    --fill: rgba(118, 118, 128, 0.24);
    --fill-2: rgba(118, 118, 128, 0.34);
    --sep: rgba(84, 84, 88, 0.6);
    --text: #f5f5f7;
    --text-2: rgba(235, 235, 245, 0.62);
    --text-3: rgba(235, 235, 245, 0.32);
    --accent: #3d9bff;
    --ctl-bg: rgba(44, 44, 46, 0.86);
    --shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.08), 0 4px 18px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.3;
  color: var(--text);
  background: var(--map-bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ic { width: 20px; height: 20px; flex: none; display: block; }
#app { position: fixed; inset: 0; overflow: hidden; }

/* ============ Мапа ============ */
#map { position: absolute; inset: 0; background: var(--map-bg); }
.leaflet-container { font-family: var(--font); background: var(--map-bg); outline: none; }
.leaflet-tile, .preview-layer { image-rendering: auto; }
.preview-layer { filter: blur(0.6px); }
.night #map .leaflet-tile-pane { filter: brightness(0.55) saturate(0.75) hue-rotate(-12deg) contrast(1.08); }
.night #map, .night body { --map-bg: #3b4b52; }

/* квартали */
.ward-shape { transition: fill-opacity 0.3s, stroke-opacity 0.3s; cursor: pointer; }
.wl, .water-lbl { pointer-events: none; }
.wl span, .water-lbl span {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  white-space: nowrap; text-align: center;
}
.wl span {
  pointer-events: auto; cursor: pointer;
  font: 700 12px/1.15 var(--font-display);
  letter-spacing: 0.1em; text-transform: uppercase;
  color: #4d2f19;
  padding: 10px 18px;
  /* м'яко ховає намальовану англійську назву під собою */
  background: radial-gradient(closest-side, rgba(238, 222, 186, 0.96) 55%, rgba(238, 222, 186, 0.75) 72%, rgba(238, 222, 186, 0) 100%);
  text-shadow: 0 0 2px var(--halo), 0 0 6px var(--halo);
  opacity: 0; transition: opacity 0.25s;
}
#map.zw:not(.no-wards) .wl span { opacity: 1; }
.night .wl span { color: #f3e5c7; background: radial-gradient(closest-side, rgba(52, 58, 60, 0.95) 55%, rgba(52, 58, 60, 0) 100%); text-shadow: none; }
.water-lbl span {
  font: italic 600 13px/1.1 var(--font-display); letter-spacing: 0.18em; text-transform: uppercase;
  color: rgba(40, 84, 96, 0.75); text-shadow: 0 0 3px rgba(200, 225, 220, 0.9);
}
.night .water-lbl span { color: rgba(190, 220, 230, 0.75); text-shadow: none; }

/* вулиці */
.st { pointer-events: none; }
.st span {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  white-space: nowrap; font: 600 10.5px/1 var(--font); color: #3a2a1c;
  padding: 3px 6px 3px; border-radius: 6px;
  background: rgba(247, 238, 216, 0.92); box-shadow: 0 0 0 0.5px rgba(90, 60, 30, 0.25);
  display: none;
}
#map.zst .st span { display: block; }
.night .st span { background: rgba(40, 44, 48, 0.9); color: #eadfc8; box-shadow: none; }

/* мітки місць */
.pm { display: none; }
#map .pm.r0, #map.zr1 .pm.r1, #map.zr2 .pm.r2, #map.zr3 .pm.r3 { display: block; }
#map.filtering .pm { display: none; }
#map.filtering .pm.hit { display: block; }
.leaflet-marker-icon.pm.sel { display: block !important; }

.pm-pin {
  position: absolute; left: -13px; top: -13px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  background: var(--c);
  box-shadow: 0 0 0 2px #fff, 0 1.5px 4px rgba(0, 0, 0, 0.35);
  transition: transform 0.28s var(--ease-spring), box-shadow 0.2s;
  transform-origin: 50% 100%;
}
.pm-pin .ic { width: 15px; height: 15px; stroke-width: 2.2; }
.pm.r3 .pm-pin { left: -10px; top: -10px; width: 20px; height: 20px; }
.pm.r3 .pm-pin .ic { width: 12px; height: 12px; }
.pm:active .pm-pin { transform: scale(0.88); }

.pm-lbl {
  position: absolute; left: 0; top: 16px; transform: translateX(-50%);
  width: max-content; max-width: 132px; text-align: center;
  font: 650 11.5px/1.15 var(--font); letter-spacing: -0.01em;
  color: color-mix(in srgb, var(--c) 55%, #1a120a);
  text-shadow: 0 0 2px var(--halo), 0 0 2px var(--halo), 0 0 4px var(--halo), 0 0 6px var(--halo);
  pointer-events: none; display: none;
}
.pm.r3 .pm-lbl { top: 13px; font-size: 10.5px; }
#map.zl0:not(.no-labels) .pm.r0 .pm-lbl,
#map.zl1:not(.no-labels) .pm.r1 .pm-lbl,
#map.zl2:not(.no-labels) .pm.r2 .pm-lbl,
#map.zl3:not(.no-labels) .pm.r3 .pm-lbl,
#map.filtering.zl2:not(.no-labels) .pm.hit .pm-lbl { display: block; }
.night .pm-lbl { color: #fff; --halo: rgba(0, 0, 0, 0.75); }

/* вибрана мітка — «повітряна куля» */
.pm.sel { z-index: 100000 !important; }
.pm.sel .pm-pin {
  left: -21px; top: -50px; width: 42px; height: 42px;
  box-shadow: 0 0 0 2.5px #fff, 0 6px 16px rgba(0, 0, 0, 0.35);
  animation: pop 0.38s var(--ease-spring);
}
.pm.sel .pm-pin .ic { width: 22px; height: 22px; }
.pm.sel .pm-pin::after {
  content: ""; position: absolute; left: 50%; bottom: -9px; width: 12px; height: 12px;
  background: var(--c); transform: translateX(-50%) rotate(45deg); border-radius: 0 0 3px 0;
  box-shadow: 2px 2px 0 0.5px #fff; z-index: -1;
}
.pm.sel::before {
  content: ""; position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.35); filter: blur(1px);
}
.pm.sel .pm-lbl { display: block !important; top: 8px; font-size: 13px; max-width: 170px; }
@keyframes pop { 0% { transform: scale(0.4) translateY(20px); opacity: 0.4; } 100% { transform: none; opacity: 1; } }

/* ============ Кнопки мапи ============ */
.map-chrome {
  position: absolute; right: 10px; top: calc(var(--sat) + 10px); z-index: 500;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
  transition: opacity 0.2s, transform 0.25s var(--ease-out);
}
.map-chrome.hidden { opacity: 0; transform: translateY(-8px); pointer-events: none; }
.ctl-stack, .ctl-solo {
  background: var(--ctl-bg); border-radius: 10px; box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(20px) saturate(1.8); backdrop-filter: blur(20px) saturate(1.8);
}
.ctl-stack { display: flex; flex-direction: column; overflow: hidden; }
.ctl { width: 44px; height: 44px; display: grid; place-items: center; color: var(--accent); }
.ctl .ic { width: 21px; height: 21px; }
.ctl:active { background: var(--fill); }
.ctl-sep { height: 0.5px; background: var(--sep); margin: 0 8px; }

.scale {
  position: absolute; left: 12px; top: calc(var(--sat) + 14px); z-index: 500;
  display: flex; flex-direction: column; gap: 3px; opacity: 0; transition: opacity 0.35s;
  pointer-events: none;
}
.scale.on { opacity: 1; }
.scale-bar { height: 5px; border: 2px solid #1d1d1f; border-top: 0; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85); background: transparent; }
.scale-txt { font: 600 11px/1 var(--font); color: #1d1d1f; text-shadow: 0 0 3px #fff, 0 0 3px #fff; }

/* ============ Панель ============ */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 800;
  margin: 0 auto; max-width: 720px;
  background: var(--sheet-bg);
  -webkit-backdrop-filter: blur(28px) saturate(1.9); backdrop-filter: blur(28px) saturate(1.9);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  box-shadow: 0 -0.5px 0 rgba(0, 0, 0, 0.08), 0 -6px 30px rgba(0, 0, 0, 0.12);
  display: flex; flex-direction: column;
  will-change: transform;
  touch-action: none;
}
.sheet.animating { transition: transform 0.48s var(--ease-out); }
.sheet-grab { flex: none; height: 18px; display: grid; place-items: center; cursor: grab; }
.sheet-grab span { width: 36px; height: 5px; border-radius: 3px; background: var(--fill-2); }
.sheet-scroll {
  flex: 1; overflow: hidden; overscroll-behavior: contain;
  padding: 0 16px calc(var(--sab) + 28px);
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* пошук */
.search-wrap { display: flex; align-items: center; gap: 10px; padding: 2px 0 10px; position: sticky; top: 0; z-index: 2; }
.search {
  flex: 1; display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 8px 0 9px;
  background: var(--fill); border-radius: 10px; color: var(--text-2);
}
.search .ic { width: 18px; height: 18px; }
.search input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none;
  font: 400 17px var(--font); color: var(--text);
}
.search input::placeholder { color: var(--text-2); }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear { width: 22px; height: 22px; border-radius: 50%; background: var(--text-3); color: var(--sheet-solid); display: grid; place-items: center; }
.search-clear .ic { width: 13px; height: 13px; stroke-width: 3; }
.search-cancel { color: var(--accent); font-size: 17px; white-space: nowrap; }

/* розділи */
.sec-h { margin: 22px 4px 8px; font: 700 20px/1.2 var(--font-display); letter-spacing: -0.01em; }
.card { background: var(--card); border-radius: var(--r-card); overflow: hidden; }
.list > * + * { box-shadow: inset 0 0.5px 0 var(--sep); }
.list > .row + .row { box-shadow: none; position: relative; }
.list > .row + .row::before { content: ""; position: absolute; left: 60px; right: 0; top: 0; height: 0.5px; background: var(--sep); }

.row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 9px 12px; text-align: left; }
.row:active { background: var(--fill); }
.row-ic { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; background: var(--c); }
.row-ic .ic { width: 19px; height: 19px; stroke-width: 2.1; }
.row-ic.ward { border-radius: 9px; }
.row-ic.street { background: var(--fill-2); color: var(--text-2); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-t { font-size: 17px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-s { font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-chev { width: 16px; height: 16px; color: var(--text-3); stroke-width: 2.4; }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 4px -16px 0; padding: 4px 16px 6px; scrollbar-width: none; touch-action: pan-x pan-y; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px 0 10px;
  border-radius: 18px; background: var(--card); font-size: 15px; font-weight: 500; white-space: nowrap;
  box-shadow: 0 0 0 0.5px var(--sep);
}
.chip .ic { width: 22px; height: 22px; padding: 3.5px; border-radius: 50%; background: var(--c); color: #fff; stroke-width: 2.4; }
.chip b { font-weight: 600; color: var(--text-2); font-size: 14px; }
.chip:active { transform: scale(0.96); }

.foot { margin: 26px 6px 8px; font-size: 12.5px; color: var(--text-2); line-height: 1.45; }

/* заголовок картки */
.hdr { display: flex; align-items: flex-start; gap: 10px; padding: 0 0 10px; position: sticky; top: 0; z-index: 2; background: transparent; }
.sheet.is-full .hdr { background: var(--sheet-solid); margin: 0 -16px; padding: 0 16px 10px; }
.hdr-txt { flex: 1; min-width: 0; padding-top: 2px; }
.hdr-t { margin: 0; font: 700 26px/1.12 var(--font-display); letter-spacing: -0.02em; overflow-wrap: anywhere; }
.hdr-s { margin: 4px 0 0; font-size: 15px; color: var(--text-2); }
.hdr-act { display: flex; gap: 8px; flex: none; }
.round { width: 32px; height: 32px; border-radius: 50%; background: var(--fill); color: var(--text-2); display: grid; place-items: center; }
.round .ic { width: 17px; height: 17px; stroke-width: 2.6; }
.round:active { background: var(--fill-2); }
.link { color: var(--accent); font-size: inherit; }
.link:disabled { color: inherit; }

/* дії */
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 0; }
.act {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  height: 58px; border-radius: 12px; background: var(--card); color: var(--accent);
  font-size: 12.5px; font-weight: 600;
}
.act .ic { width: 22px; height: 22px; }
.act:active { transform: scale(0.97); background: var(--fill); }
.act.primary { background: var(--accent); color: #fff; }

/* смуга фактів */
.strip { display: grid; grid-template-columns: repeat(3, 1fr); margin: 16px 0 0; padding: 2px 0; }
.strip-c { display: flex; flex-direction: column; gap: 3px; padding: 0 10px; min-width: 0; }
.strip-c + .strip-c { border-left: 0.5px solid var(--sep); }
.strip-c:first-child { padding-left: 4px; }
.strip-k { font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-2); }
.strip-v { font-size: 20px; font-weight: 600; display: flex; align-items: center; gap: 3px; }
.strip-v.sm { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.strip-v.sm .ic { display: inline-block; vertical-align: -4px; width: 17px; height: 17px; margin-right: 2px; }

.prose { padding: 14px 16px; font-size: 16px; line-height: 1.5; }
.prose p { margin: 0; }
.prose.muted { color: var(--text-2); margin-top: 18px; }
.facts .fact { display: flex; flex-direction: column; gap: 2px; padding: 11px 16px; }
.fact-k { font-size: 13.5px; color: var(--text-2); }
.fact-v { font-size: 16px; }

.note-card { padding: 10px 14px 8px; }
.note-card textarea {
  width: 100%; border: 0; outline: 0; resize: none; background: none; min-height: 64px;
  font: 400 16px/1.45 var(--font); color: var(--text);
}
.note-card textarea::placeholder { color: var(--text-3); }
.note-hint { margin: 2px 0 0; font-size: 12px; color: var(--text-3); }

.empty { text-align: center; padding: 48px 20px; color: var(--text-2); }
.empty .ic { width: 40px; height: 40px; margin: 0 auto 10px; color: var(--text-3); }
.empty-t { margin: 0; font-size: 20px; font-weight: 700; color: var(--text); }
.empty-s { margin: 6px 0 0; font-size: 15px; }

/* ============ Модальне вікно налаштувань ============ */
.modal-backdrop { position: absolute; inset: 0; z-index: 900; background: rgba(0, 0, 0, 0.25); opacity: 0; transition: opacity 0.25s; }
.modal-backdrop.on { opacity: 1; }
.modal {
  position: absolute; left: 8px; right: 8px; bottom: calc(8px + var(--sab)); z-index: 901;
  max-width: 520px; margin: 0 auto; padding: 14px 16px 6px;
  background: var(--sheet-solid); border-radius: 22px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  transform: translateY(30px); opacity: 0; transition: transform 0.35s var(--ease-out), opacity 0.2s;
}
.modal.on { transform: none; opacity: 1; }
.modal-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-h h2 { margin: 0; font: 700 22px var(--font-display); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.seg-b { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px; border-radius: 14px; background: var(--card); font-size: 14px; font-weight: 600; box-shadow: 0 0 0 0.5px var(--sep); }
.seg-b.on { box-shadow: 0 0 0 2.5px var(--accent); color: var(--accent); }
.seg-prev { width: 100%; height: 64px; border-radius: 9px; background: url(../tiles/preview.webp) 50% 38% / 220% auto; }
.seg-prev.night { filter: brightness(0.55) saturate(0.75) hue-rotate(-12deg) contrast(1.08); }
.sw-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 56px; cursor: pointer; }
.sw-txt { flex: 1; display: flex; flex-direction: column; gap: 1px; font-size: 16px; }
.sw-txt small { font-size: 13px; color: var(--text-2); }
.sw { appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--fill-2); position: relative; transition: background 0.25s; cursor: pointer; flex: none; margin: 0; }
.sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); transition: transform 0.28s var(--ease-spring); }
.sw:checked { background: #34c759; }
.sw:checked::after { transform: translateX(20px); }

/* ============ Тост ============ */
.toast {
  position: absolute; left: 50%; top: calc(var(--sat) + 12px); z-index: 1000;
  display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 22px;
  background: var(--ctl-bg); box-shadow: var(--shadow); font-size: 15px; font-weight: 600;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  transform: translate(-50%, -80px); transition: transform 0.4s var(--ease-spring);
  pointer-events: none;
}
.toast .ic { color: #34c759; width: 18px; height: 18px; stroke-width: 2.6; }
.toast.on { transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .sheet.animating, .modal, .toast, .pm-pin { transition-duration: 0.01s !important; animation: none !important; }
}

/* ритм між блоками */
.strip + .card, .actions + .card { margin-top: 16px; }
.card + .card { margin-top: 12px; }
