:root {
  --bg: #0b1220;
  --bg-soft: #121b2e;
  --surface: rgba(18, 27, 46, 0.92);
  --surface-solid: #121b2e;
  --text: #eaf0ff;
  --text-dim: #9fb0d0;
  --border: rgba(255, 255, 255, 0.08);
  --brand: #22c55e;
  --brand-2: #16a34a;
  --accent: #38bdf8;
  --danger: #f43f5e;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="light"] {
  --bg: #eef2f9;
  --bg-soft: #ffffff;
  --surface: rgba(255, 255, 255, 0.96);
  --surface-solid: #ffffff;
  --text: #0b1220;
  --text-dim: #5a6b88;
  --border: rgba(10, 18, 32, 0.1);
  --shadow: 0 10px 40px rgba(20, 40, 80, 0.18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* Чёлка / статус-бар: матовая подложка под вырезом */
.statusbar-scrim {
  position: absolute; top: 0; left: 0; right: 0;
  height: calc(var(--safe-top) + 58px);
  background: linear-gradient(180deg, var(--surface-solid) 58%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  -webkit-mask-image: linear-gradient(180deg, #000 62%, transparent);
  mask-image: linear-gradient(180deg, #000 62%, transparent);
  z-index: 1190; pointer-events: none;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(8px + var(--safe-top)) 14px 8px;
  background: transparent;
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 1200;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: var(--shadow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { font-size: 16px; }
.brand-text small { font-size: 11px; color: var(--text-dim); }

.icon-btn {
  width: 40px; height: 40px; border: none; border-radius: 12px;
  background: var(--surface); color: var(--text);
  backdrop-filter: blur(12px);
  display: grid; place-items: center; cursor: pointer;
  box-shadow: var(--shadow); font-size: 20px;
  border: 1px solid var(--border);
}
.icon-btn:active { transform: scale(0.94); }

/* Search */
.searchbar {
  position: absolute;
  top: calc(64px + var(--safe-top)); left: 12px; right: 12px;
  z-index: 1100;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0 12px;
  box-shadow: var(--shadow);
  height: 46px;
}
.search-ic { color: var(--text-dim); flex: none; }
#search {
  flex: 1; border: none; background: transparent; outline: none;
  color: var(--text); font-size: 15px; height: 100%;
}
#search::placeholder { color: var(--text-dim); }
.clear-btn { border: none; background: transparent; color: var(--text-dim); font-size: 22px; cursor: pointer; }

/* Chips */
.chips {
  position: absolute;
  top: calc(120px + var(--safe-top)); left: 0; right: 0;
  z-index: 1100;
  display: flex; gap: 8px; padding: 0 12px;
  overflow-x: auto; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  backdrop-filter: blur(12px);
  padding: 7px 14px; border-radius: 999px; font-size: 13px;
  cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 6px;
  box-shadow: var(--shadow);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip.active { background: var(--brand); color: #04140a; border-color: transparent; font-weight: 700; }

/* Map */
#map { flex: 1; width: 100%; height: 100%; background: var(--bg-soft); z-index: 1; }

/* FAB */
.fab {
  position: absolute; right: 16px;
  width: 52px; height: 52px; border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface-solid); color: var(--accent);
  display: grid; place-items: center; cursor: pointer;
  box-shadow: var(--shadow); z-index: 1100;
  bottom: calc(28px + var(--safe-bottom));
}
.fab:active { transform: scale(0.94); }
.fab-list { bottom: calc(92px + var(--safe-bottom)); color: var(--text); }
.fab-add { bottom: calc(156px + var(--safe-bottom)); background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #04140a; }

/* Центральный пин выбора места */
.center-pin {
  position: absolute; left: 50%; top: 50%; z-index: 1300;
  transform: translate(-50%, -100%);
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.4));
  animation: pinBounce .4s ease;
}
@keyframes pinBounce { from { transform: translate(-50%, -130%);} to { transform: translate(-50%, -100%);} }
.add-bar {
  position: absolute; left: 12px; right: 12px; top: calc(120px + var(--safe-top));
  z-index: 1300; background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.add-bar span { font-size: 14px; font-weight: 600; }
.add-bar > div { display: flex; gap: 8px; }
.add-bar .btn-primary, .add-bar .btn-ghost { flex: none; padding: 10px 16px; font-size: 14px; }

/* Custom marker */
.pin {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 6px 14px rgba(0,0,0,.4);
  border: 2px solid rgba(255,255,255,.85);
}
.pin svg { transform: rotate(45deg); }
.pin-fav { box-shadow: 0 0 0 3px #facc15, 0 6px 14px rgba(0,0,0,.4); }
.pin-cluster {
  background: var(--brand); color: #04140a; font-weight: 800; font-size: 15px;
  border-radius: 50%; display: grid; place-items: center;
  border: 3px solid rgba(255,255,255,.9);
  box-shadow: 0 6px 16px rgba(0,0,0,.45);
}

/* Bottom sheet */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface-solid);
  border-radius: 22px 22px 0 0;
  z-index: 1500;
  box-shadow: 0 -10px 40px rgba(0,0,0,.4);
  transform: translateY(110%);
  transition: transform .32s cubic-bezier(.2,.8,.2,1);
  padding: 8px 18px calc(20px + var(--safe-bottom));
  max-height: 70vh; overflow-y: auto;
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 44px; height: 5px; border-radius: 3px; background: var(--border); margin: 6px auto 12px; }

.sheet-top { display: flex; align-items: center; justify-content: space-between; }
.star-btn {
  border: none; background: var(--bg); color: #facc15; font-size: 22px;
  width: 42px; height: 42px; border-radius: 12px; cursor: pointer; border: 1px solid var(--border);
}
.star-btn.on { background: #facc1522; }
.star-btn:active { transform: scale(.92); }
.sheet h2 { margin: 4px 0 2px; font-size: 20px; }
.sheet .addr { color: var(--text-dim); font-size: 14px; margin-bottom: 12px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: rgba(34,197,94,.15); color: var(--brand); font-weight: 700;
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; }
.sheet .meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.sheet .meta .tag { background: var(--bg); border: 1px solid var(--border); padding: 6px 12px; border-radius: 10px; font-size: 13px; color: var(--text-dim); }
.sheet .desc { font-size: 14px; line-height: 1.5; color: var(--text); margin: 8px 0 16px; }
.tag-pending { background: #f59e0b22 !important; color: #f59e0b !important; }

/* Голоса актуальности */
.votes { margin: 4px 0 16px; }
.votes-title { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.votes-row { display: flex; gap: 8px; }
.vote-btn {
  flex: 1; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 12px; padding: 10px 6px; font-size: 12.5px; cursor: pointer; line-height: 1.3;
}
.vote-btn b { display: block; font-size: 15px; margin-top: 2px; color: var(--accent); }
.vote-btn:active { transform: scale(.96); }
.sheet-actions { display: flex; gap: 10px; }

.btn-primary, .btn-ghost {
  flex: 1; border: none; border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #04140a; }
.btn-ghost { background: var(--bg); color: var(--text); border: 1px solid var(--border); flex: 0 0 auto; padding: 13px 18px; }
.btn-primary:active, .btn-ghost:active { transform: scale(0.97); }
.report-link {
  display: block; width: 100%; margin-top: 12px; padding: 10px;
  border: none; background: transparent; color: var(--text-dim);
  font-size: 13px; cursor: pointer; border-radius: 10px;
}
.report-link:active { background: var(--bg); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* List panel */
.list-panel {
  position: absolute; left: 0; right: 0; bottom: 0; top: auto;
  height: 75vh;
  background: var(--surface-solid);
  border-radius: 22px 22px 0 0;
  z-index: 1500; box-shadow: 0 -10px 40px rgba(0,0,0,.4);
  transform: translateY(110%); transition: transform .32s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column;
}
.list-panel.open { transform: translateY(0); }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px 10px; border-bottom: 1px solid var(--border); gap: 8px; }
.list-head strong { font-size: 16px; white-space: nowrap; }
.list-head-actions { display: flex; align-items: center; gap: 6px; }
.pill-btn {
  border: 1px solid var(--border); background: var(--bg); color: var(--text-dim);
  border-radius: 999px; padding: 7px 11px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.pill-btn.on { background: #facc1522; color: #facc15; border-color: transparent; }
.pill-btn:active { transform: scale(.95); }
.li-star { color: #facc15; margin-right: 4px; }
.empty { text-align: center; color: var(--text-dim); padding: 36px 20px; }
.list-items { overflow-y: auto; padding: 8px 12px calc(20px + var(--safe-bottom)); flex: 1; }
.vspacer { position: relative; }
.vlist-window { position: absolute; left: 0; right: 0; top: 0; }
.list-item {
  display: flex; gap: 12px; align-items: center;
  padding: 12px; border-radius: 14px; cursor: pointer;
  border: 1px solid transparent;
}
.list-item.v { position: absolute; left: 0; right: 0; height: 66px; overflow: hidden; }
.list-item:active { background: var(--bg); }
.li-ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; color: #fff; }
.li-body { flex: 1; min-width: 0; }
.li-body .t { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-body .s { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-dist { font-size: 13px; color: var(--accent); font-weight: 700; flex: none; }

/* Action sheet (выбор приложения) */
.action-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
}
.action-sheet {
  width: 100%; max-width: 460px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px;
  box-shadow: var(--shadow);
  transform: translateY(20px); opacity: 0;
  transition: transform .25s cubic-bezier(.2,.8,.2,1), opacity .2s;
  margin-bottom: calc(8px + var(--safe-bottom));
}
.action-sheet.open { transform: translateY(0); opacity: 1; }
.action-title { text-align: center; font-size: 13px; color: var(--text-dim); padding: 10px 0 8px; }
.action-btn {
  width: 100%; display: flex; align-items: center; gap: 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; margin-bottom: 8px;
  cursor: pointer; color: var(--text); text-align: left;
}
.action-btn:active { transform: scale(.98); }
.action-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.action-text { flex: 1; display: flex; flex-direction: column; }
.action-text b { font-size: 15px; }
.action-text small { font-size: 12px; color: var(--text-dim); }
.action-chev { color: var(--text-dim); font-size: 22px; }
.action-cancel {
  width: 100%; border: none; background: transparent; color: var(--accent);
  font-size: 16px; font-weight: 700; padding: 14px; cursor: pointer;
}

/* Форма добавления */
.form-sheet { padding: 12px 16px 16px; }
.fld { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.fld span { font-size: 13px; color: var(--text-dim); padding-left: 2px; }
.fld input, .fld textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; padding: 12px; font-size: 15px; font-family: inherit; outline: none; resize: none;
}
.fld input:focus, .fld textarea:focus { border-color: var(--brand); }
.fld-coords { font-size: 13px; color: var(--text-dim); margin: 0 0 14px 2px; }
.form-sheet .btn-primary { margin-top: 2px; }

/* Тост */
.toast {
  position: fixed; left: 50%; bottom: calc(40px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #111827ee; color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: 14px; z-index: 3000; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Overlay */
.overlay { position: absolute; inset: 0; background: rgba(0,0,0,.4); z-index: 1400; }

/* Install banner */
.install-banner {
  position: absolute; left: 12px; right: 12px; bottom: calc(20px + var(--safe-bottom));
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px 16px; z-index: 1600;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: var(--shadow);
}
.install-banner[hidden] { display: none; }
.install-banner span { font-size: 14px; font-weight: 600; }
.install-banner > div { display: flex; gap: 8px; }
.install-banner .btn-primary, .install-banner .btn-ghost { flex: none; padding: 10px 16px; font-size: 14px; }

/* Рекламный плейсхолдер */
.ad-banner {
  position: absolute; left: 12px; right: 84px;
  bottom: calc(28px + var(--safe-bottom));
  z-index: 1090;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 12px;
  background: color-mix(in srgb, var(--surface-solid) 78%, transparent);
  border: 1px dashed var(--border);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  color: var(--muted); text-decoration: none;
  font-size: 12px; opacity: .82;
  transition: opacity .2s ease;
  max-width: 320px;
}
.ad-banner:hover { opacity: 1; }
.ad-banner[hidden] { display: none; }
.ad-tag {
  flex: none; font-size: 9px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted);
  border: 1px solid var(--border); border-radius: 5px;
  padding: 2px 5px; opacity: .8;
}
.ad-text {
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ad-close {
  flex: none; border: none; background: transparent; color: var(--muted);
  font-size: 16px; line-height: 1; cursor: pointer; padding: 2px 4px; opacity: .7;
}
.ad-close:hover { opacity: 1; }

/* Leaflet tweaks */
.leaflet-control-zoom { display: none; }
.leaflet-control-attribution { font-size: 9px; background: rgba(0,0,0,.3) !important; color: #ccc !important; }
.leaflet-control-attribution a { color: #ddd !important; }
.user-dot {
  width: 18px; height: 18px; border-radius: 50%; background: var(--accent);
  border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(56,189,248,.25), 0 2px 6px rgba(0,0,0,.4);
}
