:root {
  --bg: #070B14;
  --panel: rgba(11, 17, 32, 0.85);
  --panel-active: rgba(18, 28, 52, 0.92);
  --line: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9;
  --dim: #94a3b8;
  --cyan: #22d3ee;
  --emerald: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --yellow: #eab308;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font: 14px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#map { position: absolute; inset: 0; }

/* --------------------------------- Верхній тактичний HUD */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(6px + var(--safe-t)) 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: linear-gradient(180deg, rgba(7, 11, 20, 0.96) 0%, rgba(7, 11, 20, 0.65) 75%, transparent 100%);
  pointer-events: none;
  z-index: 10;
  box-sizing: border-box;
}

.top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.brand {
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  flex-shrink: 0;
}
.brand-title {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .08em;
  color: #fff;
}
.brand-title .accent { color: var(--cyan); }
.brand-sub {
  font-size: 9px;
  font-weight: 600;
  color: var(--dim);
  display: flex;
  align-items: center;
  gap: 5px;
  letter-spacing: .04em;
}

.conn {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
  display: inline-block;
  transition: all .3s;
}
.conn.off {
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
}

/* --------------------------------- Тактичний статус загроз */
.threat-banner {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  transition: all .25s ease;
  min-width: 0;
  max-width: 65%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#threat-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.threat-banner .pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.threat-banner.none {
  color: #94a3b8;
  border-color: rgba(148, 163, 184, 0.25);
}
.threat-banner.none .pulse-dot {
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
}

.threat-banner.early {
  color: #fde047;
  background: rgba(234, 179, 8, 0.15);
  border-color: rgba(234, 179, 8, 0.45);
  box-shadow: 0 0 14px rgba(234, 179, 8, 0.2);
}
.threat-banner.early .pulse-dot {
  background: var(--yellow);
  box-shadow: 0 0 10px var(--yellow);
  animation: pulse 1.6s infinite;
}

.threat-banner.alert {
  color: #fdba74;
  background: rgba(249, 115, 22, 0.18);
  border-color: rgba(249, 115, 22, 0.5);
  box-shadow: 0 0 16px rgba(249, 115, 22, 0.25);
}
.threat-banner.alert .pulse-dot {
  background: var(--amber);
  box-shadow: 0 0 12px var(--amber);
  animation: pulse 1.2s infinite;
}

.threat-banner.critical {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.22);
  border-color: var(--red);
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
  animation: danger-glow 1s infinite alternate;
}
.threat-banner.critical .pulse-dot {
  background: var(--red);
  box-shadow: 0 0 14px var(--red);
  animation: pulse .7s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}
@keyframes danger-glow {
  from { border-color: rgba(239, 68, 68, 0.5); box-shadow: 0 0 10px rgba(239, 68, 68, 0.25); }
  to { border-color: #ef4444; box-shadow: 0 0 22px rgba(239, 68, 68, 0.5); }
}

/* --------------------------------- Панель кнопок (Швидкі перемикачі) */
#layers-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3px;
  pointer-events: auto;
  width: 100%;
  max-width: 100%;
  padding: 2px 4px;
  border-radius: 9px;
  box-sizing: border-box;
}

.glass-bar {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
}

.segmented-switch {
  display: flex;
  background: rgba(0, 0, 0, 0.45);
  padding: 1.5px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  gap: 1px;
}
.seg-btn {
  font: inherit;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--dim);
  background: transparent;
  border: none;
  padding: 3px 5px;
  border-radius: 5px;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.seg-btn.active {
  background: rgba(34, 211, 238, 0.22);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.25);
}

.toggle-group {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.tool-btn {
  font: inherit;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--dim);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 3px 5px;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.tool-btn.active {
  background: rgba(34, 211, 238, 0.18);
  border-color: rgba(34, 211, 238, 0.45);
  color: #fff;
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.2);
}

/* --------------------------------- Нижня навігація по секторах */
#fly {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(14px + var(--safe-b));
  display: flex;
  gap: 5px;
  padding: 3px;
  border-radius: 12px;
  z-index: 10;
  width: fit-content;
  white-space: nowrap;
}
.fly-btn {
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--dim);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px 11px;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.fly-btn.active, .fly-btn:active {
  background: rgba(34, 211, 238, 0.22);
  border-color: var(--cyan);
  color: #fff;
}

/* --------------------------------- Детальна панель телеметрії цілі */
#panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(64px + var(--safe-b));
  z-index: 20;
  max-width: 480px;
  margin: 0 auto;
  background: rgba(11, 17, 32, 0.94);
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 16px;
  padding: 16px 18px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.65), 0 0 20px rgba(34, 211, 238, 0.15);
  animation: slide-up .25s ease-out;
}
@keyframes slide-up {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
#panel[hidden], #notice[hidden] { display: none !important; }

#panel-close {
  position: absolute;
  top: 10px; right: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .2s;
}
#panel-close:active { background: rgba(255, 255, 255, 0.2); }

.target-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-right: 32px;
}
.target-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.target-eta {
  font-size: 13px;
  font-weight: 700;
  color: var(--cyan);
}

.telemetry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.telemetry-cell {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 8px 10px;
}
.telemetry-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 2px;
}
.telemetry-value {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.report-box {
  background: rgba(0, 0, 0, 0.45);
  border-left: 3px solid var(--cyan);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  color: #e2e8f0;
  margin-bottom: 12px;
  line-height: 1.4;
}

.panel-actions {
  display: flex;
  gap: 8px;
}
.btn-focus-target {
  flex: 1;
  background: rgba(34, 211, 238, 0.2);
  border: 1px solid var(--cyan);
  border-radius: 9px;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  padding: 8px 12px;
  cursor: pointer;
  transition: all .2s;
}
.btn-focus-target:active { background: rgba(34, 211, 238, 0.35); }

/* --------------------------------- Сповіщення / Notice */
#notice {
  position: absolute;
  top: calc(76px + var(--safe-t));
  left: 12px; right: 12px;
  z-index: 30;
  padding: 9px 14px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--red);
  border-radius: 10px;
  color: #fecaca;
  font-size: 12px;
  font-weight: 600;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* --------------------------------- Маркери секторів «Хата» / «Хата ДИ» */
.pylon { position: relative; width: 0; height: 0; }
.pylon i {
  position: absolute; left: -1px; bottom: 0; width: 2px; height: 32px;
  background: var(--c); box-shadow: 0 0 10px var(--c);
}
.pylon b {
  position: absolute; left: -8px; bottom: 28px; width: 16px; height: 16px; transform: rotate(45deg);
  border: 2px solid var(--c); background: color-mix(in srgb, var(--c) 30%, transparent); box-shadow: 0 0 14px var(--c);
}
.pylon u {
  position: absolute; left: -4px; bottom: -4px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--c); border: 2px solid #fff;
}
.pylon em {
  position: absolute; left: 14px; bottom: 30px; font-style: normal; font-weight: 800; font-size: 12px;
  color: var(--c); text-shadow: 0 0 8px #000, 0 0 3px #000; white-space: nowrap; letter-spacing: .02em;
}

/* --------------------------------- Маркери цілей (Touch hitbox 48x48) */
.drone {
  position: relative;
  width: 48px;
  height: 48px;
  margin-left: -24px;
  margin-top: -24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.drone .halo {
  position: absolute;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 2px solid var(--c);
  animation: ping 1.8s ease-out infinite;
  pointer-events: none;
}
.drone .tag {
  position: absolute;
  left: 36px; top: -14px;
  padding: 3px 8px;
  border-radius: 7px;
  white-space: nowrap;
  font-weight: 700;
  font-size: 11px;
  color: #fff;
  background: rgba(11, 17, 32, 0.88);
  border: 1px solid var(--c);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
@keyframes ping {
  from { transform: scale(.55); opacity: .95; }
  to { transform: scale(1.35); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .drone .halo, .pulse-dot, .threat-banner.critical { animation: none !important; }
}

.maplibregl-ctrl-attrib {
  background: rgba(7, 11, 20, 0.75) !important;
  color: var(--dim) !important;
  font-size: 10px !important;
}
.maplibregl-ctrl-attrib a { color: var(--dim) !important; }

/* --------------------------------- Кнопка та маркер геолокації */
.gps-btn {
  position: absolute;
  right: 12px;
  bottom: calc(14px + var(--safe-b));
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dim);
  cursor: pointer;
  z-index: 10;
  transition: all .2s;
  padding: 0;
  border: 1px solid var(--line);
}
.gps-btn:active, .gps-btn.active {
  color: #fff;
  border-color: var(--cyan);
  background: rgba(34, 211, 238, 0.22);
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.35);
}

.user-marker {
  position: relative;
  width: 24px;
  height: 24px;
  margin-left: -12px;
  margin-top: -12px;
  pointer-events: none;
}
.user-marker .dot {
  position: absolute;
  left: 6px; top: 6px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #38bdf8;
  border: 2px solid #fff;
  box-shadow: 0 0 10px #38bdf8;
}
.user-marker .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid #38bdf8;
  animation: ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

/* --------------------------------- Кнопка Зведення та Індикатор */
.intel-btn {
  position: relative;
  border-color: rgba(34, 211, 238, 0.4);
  color: #e2e8f0;
}
.badge-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--red);
  margin-left: 4px;
  box-shadow: 0 0 6px var(--red);
  animation: pulse 1s infinite;
  vertical-align: middle;
}
.badge-dot[hidden] { display: none !important; }

/* --------------------------------- Тактична Шторка / Модальне Вікно Зведення */
.intel-drawer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  background: rgba(11, 15, 25, 0.96);
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 -8px 36px rgba(0, 0, 0, 0.8), 0 0 24px rgba(34, 211, 238, 0.12);
  z-index: 50;
  animation: drawer-slide-up 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes drawer-slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.intel-drawer[hidden] { display: none !important; }

.intel-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
.intel-drawer-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.intel-title-icon {
  font-size: 20px;
}
.intel-main-title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #fff;
}
.intel-sub-title {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--cyan);
  letter-spacing: 0.8px;
}
.intel-close-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #94a3b8;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .2s;
}
.intel-close-btn:active {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.intel-drawer-body {
  padding: 14px 16px calc(24px + var(--safe-b)) 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Секція статусу та районів */
.intel-section-title {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.districts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 6px;
}
.district-card {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: all .2s;
}
.district-card.active {
  border-color: rgba(239, 68, 68, 0.55);
  background: rgba(239, 68, 68, 0.14);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.2);
}
.district-card.quiet {
  border-color: rgba(16, 185, 129, 0.25);
  background: rgba(16, 185, 129, 0.06);
}
.district-name {
  font-size: 11px;
  font-weight: 700;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.district-status {
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
}
.district-card.active .district-status {
  color: #fca5a5;
}
.district-card.quiet .district-status {
  color: #6ee7b7;
}

/* Стрічка хроніки / таймлайн */
.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.timeline-card {
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.timeline-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.timeline-source {
  font-size: 10.5px;
  font-weight: 800;
  color: var(--cyan);
}
.timeline-time {
  font-size: 10px;
  font-weight: 700;
  color: var(--dim);
}
.timeline-text {
  font-size: 11.5px;
  line-height: 1.35;
  color: #e2e8f0;
}

/* Статистика за добу */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.stat-pill {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 9px;
  padding: 8px 6px;
  text-align: center;
}
.stat-num {
  font-size: 15px;
  font-weight: 900;
  color: #fff;
}
.stat-lbl {
  font-size: 8.5px;
  font-weight: 700;
  color: var(--dim);
  text-transform: uppercase;
  margin-top: 2px;
}
