:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --shahed: #f97316;
  --jet: #dc2626;
  --missile: #7c3aed;
  --ballistic: #be123c;
  --threat: #991b1b;
  --me: #2563eb;
  --danger: #dc2626;
  --warn: #d97706;
  --topbar-h: 48px;
}
@media (prefers-color-scheme: dark) {
  :root { --panel: #111827; --text: #e5e7eb; --muted: #9ca3af; --line: #1f2937; }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 1000;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px; padding-top: env(safe-area-inset-top);
  background: var(--bg); color: #f8fafc;
}
.brand { font-weight: 700; letter-spacing: .02em; font-size: 18px; }
.status { font-size: 13px; color: #cbd5e1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.error { color: #fca5a5; }

#map { position: fixed; inset: var(--topbar-h) 0 0 0; }

.locate {
  position: fixed; right: 16px; bottom: calc(46vh + 16px); z-index: 1000;
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px; border: 0; border-radius: 999px;
  background: var(--panel); color: var(--text); font: inherit; font-weight: 600;
  box-shadow: 0 2px 10px rgba(0,0,0,.25); cursor: pointer;
}
.locate svg { width: 20px; height: 20px; fill: var(--me); stroke: var(--me); stroke-width: 2; }
.locate[aria-pressed="true"] { background: var(--me); color: #fff; }
.locate[aria-pressed="true"] svg { fill: #fff; stroke: #fff; }
body.panel-collapsed .locate { bottom: 72px; }

.panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  max-height: 46vh; display: flex; flex-direction: column;
  background: var(--panel); color: var(--text);
  border-radius: 14px 14px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.2);
  padding-bottom: env(safe-area-inset-bottom);
}
body.panel-collapsed .panel .panel-body { display: none; }
.panel-handle {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  padding: 12px 16px; border: 0; background: none; color: inherit; font: inherit; font-weight: 600; cursor: pointer;
}
.chevron { width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); }
body.panel-collapsed .chevron { transform: rotate(-135deg); }
.panel-body { overflow-y: auto; padding: 0 16px 12px; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 8px 0 6px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer;
}
.list li:first-child { border-top: 0; }
.list .icon { flex: none; width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; }
.list .main { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.list .sub { color: var(--muted); font-size: 13px; }
.list .dist { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.list .dist.danger { color: var(--danger); }
.list .dist.warn { color: var(--warn); }
.list .towards { color: var(--danger); font-weight: 600; }
.list .empty { color: var(--muted); cursor: default; }

.hint, .disclaimer { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.legend { margin-top: 10px; font-size: 14px; }
.legend summary { cursor: pointer; color: var(--muted); }
.legend ul { list-style: none; padding: 6px 0 0; margin: 0; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .lg { width: 24px; height: 24px; flex: none; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.dot.shahed { background: var(--shahed); }
.dot.jet { background: var(--jet); }
.dot.missile { background: var(--missile); }
.dot.me { background: var(--me); box-shadow: 0 0 0 3px rgba(37,99,235,.3); }
.ring { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px dashed var(--shahed); }
.square { display: inline-block; width: 11px; height: 11px; background: var(--threat); transform: rotate(45deg); }

/* маркери на мапі */
.track-icon { background: none; border: 0; }
.track-icon svg { overflow: visible; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.track-icon .badge {
  position: absolute; top: -6px; right: -8px; min-width: 18px; padding: 0 4px;
  border-radius: 9px; background: #0f172a; color: #fff; font: 700 11px/18px system-ui; text-align: center;
}
.track-icon.fresh .pulse { animation: pulse 1.6s ease-out infinite; transform-origin: center; }
@keyframes pulse { from { opacity: .6; transform: scale(.6); } to { opacity: 0; transform: scale(1.6); } }
/* темна підкладка: інвертовані тайли OSM зі збереженими відтінками води й зелені */
.tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
.arrow-head { background: none; border: 0; }
.arrow-head svg { overflow: visible; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
.heat-icon { background: none; border: 0; position: relative; }
.heat-icon svg { filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
.heat-icon .badge {
  position: absolute; top: -6px; right: -8px; min-width: 16px; padding: 0 4px;
  border-radius: 8px; background: #0f172a; color: #fff; font: 700 11px/16px system-ui; text-align: center;
}
.threat-icon { background: none; border: 0; }
.threat-icon div { width: 14px; height: 14px; background: var(--threat); transform: rotate(45deg); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
/* кнопки мапи (масштаб, вибір шарів) — під стиль сайту */
.leaflet-touch .leaflet-bar, .leaflet-bar {
  border: 0; border-radius: 12px; overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
}
.leaflet-bar a, .leaflet-touch .leaflet-bar a {
  width: 40px; height: 40px; line-height: 40px; font-size: 20px;
  background: var(--panel); color: var(--text); border-bottom: 1px solid var(--line);
}
.leaflet-bar a:hover { background: var(--panel); color: var(--me); }
.leaflet-bar a:last-child { border-bottom: 0; }
.leaflet-bar a.leaflet-disabled { opacity: .4; }
.leaflet-control-layers {
  border: 0; border-radius: 12px; background: var(--panel); color: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
}
.leaflet-control-layers-toggle {
  width: 40px; height: 40px; background-size: 20px 20px;
}
.leaflet-control-layers-expanded { padding: 8px 12px 8px 10px; }
.leaflet-control-layers label { margin: 3px 0; font-size: 14px; }
.leaflet-control-layers-selector { margin-right: 6px; }
/* у темній темі стандартна іконка шарів темна — освітлюємо */
:root:not([data-theme="light"]) .leaflet-control-layers-toggle,
:root[data-theme="dark"] .leaflet-control-layers-toggle { filter: invert(1) brightness(1.6); }
@media (prefers-color-scheme: dark) { .leaflet-control-layers-toggle { filter: invert(1) brightness(1.6); } }
.leaflet-control-attribution { background: rgba(255, 255, 255, .7); font-size: 11px; }

.leaflet-tooltip.target-label { font-weight: 600; }
.popup h3 { margin: 0 0 4px; font-size: 15px; }
.popup p { margin: 2px 0; }
.popup .msg { margin-top: 6px; padding-top: 6px; border-top: 1px solid #e2e8f0; font-size: 13px; }
.popup .msg a { color: #2563eb; }

@media (min-width: 900px) {
  .panel { left: auto; right: 16px; bottom: 16px; top: calc(var(--topbar-h) + 16px); width: 360px; max-height: none; border-radius: 14px; }
  .locate, body.panel-collapsed .locate { right: 392px; bottom: 24px; }
  body.panel-collapsed .panel { top: auto; }
}
