:root {
  --bg: #0a0e13;
  --panel: rgba(13, 19, 27, .88);
  --panel-border: #1f2b3a;
  --text: #dbe4ee;
  --muted: #7b8a9c;
  --alert: #e11d2e;
  --alert-soft: #ff5c5c;
  --calm: #1c2733;
  --accent: #3aa0ff;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

#map {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 0;
}

.panel {
  position: fixed;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(6px);
}

/* ── верхня панель ─────────────────────────────── */
.top-panel {
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: calc(100vw - 24px);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand h1 { font-size: 16px; font-weight: 700; letter-spacing: .2px; }
.brand-dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: #2ecc71; flex: 0 0 auto;
}
.brand-dot.on {
  background: var(--alert);
  animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(225, 29, 46, .55); }
  50%      { box-shadow: 0 0 0 7px rgba(225, 29, 46, 0); }
}
.meta { color: var(--muted); font-size: 12px; }
.meta .sep { margin: 0 6px; }
#alertCount b { color: var(--alert-soft); }

/* ── бічна панель зі списком тривог ────────────── */
.side-panel {
  top: 86px;
  left: 12px;
  width: 250px;
  max-height: calc(100vh - 170px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sheet-toggle { display: none; } /* лише мобільна шторка */
.side-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--panel-border);
  font-weight: 600; font-size: 13px;
}
.sound-btn {
  background: none; border: 1px solid var(--panel-border);
  border-radius: 8px; color: var(--text);
  font-size: 14px; padding: 2px 8px; cursor: pointer;
}
.sound-btn.on { border-color: var(--accent); }
#alertList {
  list-style: none;
  overflow-y: auto;
  padding: 6px 0;
}
#alertList li {
  padding: 5px 12px;
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 13px;
}
#alertList li .dur { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
#alertList li.muted { color: var(--muted); }
#alertList li::before { content: "🔴 "; font-size: 9px; }
#alertList li.muted::before { content: ""; }

/* ── легенда ───────────────────────────────────── */
.legend-panel {
  bottom: 12px;
  left: 12px;
  right: auto;
  max-width: calc(100vw - 24px);
  padding: 8px 12px;
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  font-size: 12px; color: var(--muted);
  align-items: center;
}
.lg { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw-alert  { background: rgba(225, 29, 46, .65); border: 1px solid var(--alert-soft); }
.sw-calm   { background: var(--calm); border: 1px solid #2a3a4a; }
.sw-occupied { background: #571722; border: 1px dashed #b04552; }
.sw-gray { background: rgba(107, 114, 128, .35); border: 1px dashed #8a8f98; }

.city-badge {
  background: var(--alert);
  color: #fff;
  font-size: 11px; font-weight: 700;
  line-height: 16px;
  min-width: 18px;
  text-align: center;
  border-radius: 9px;
  padding: 0 4px;
  box-shadow: 0 0 6px rgba(225, 29, 46, .7);
  cursor: pointer;
}

.leaflet-control-attribution {
  background: rgba(13, 19, 27, .6) !important;
  color: #55677c !important;
  font-size: 9px !important;
}
.leaflet-control-attribution a { color: #55677c !important; }
.ticon { font-style: normal; margin: 0 2px 0 8px; }
.t-shahed    { color: #ff5c5c; }
.t-missile   { color: #ff9f43; }
.t-ballistic { color: #ff3b6b; }
.t-kab       { color: #ffd32a; }
.t-recon     { color: #3aa0ff; }
.credit { margin-left: auto; }
.credit a { color: var(--muted); }

/* ── тост нової тривоги ────────────────────────── */
.toast {
  position: fixed;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  background: var(--alert);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(225, 29, 46, .45);
  animation: toast-in .25s ease-out;
}
@keyframes toast-in {
  from { transform: translate(-50%, -18px); opacity: 0; }
  to   { transform: translate(-50%, 0);     opacity: 1; }
}

/* ── карта: полігони областей ──────────────────── */
.leaflet-container { background: var(--bg); font: inherit; }
path.region { transition: fill .4s; cursor: pointer; }
/* тривога: заливка спокійна, «дихає» жирна червона обводка */
path.region-alert { animation: pulse-stroke 1.6s ease-in-out infinite; }
@keyframes pulse-stroke {
  0%, 100% { stroke-width: 1.5; stroke-opacity: .55; }
  50%      { stroke-width: 4.5; stroke-opacity: 1; }
}
.leaflet-tooltip.region-tip {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 8px;
  box-shadow: none;
}
.leaflet-tooltip.region-tip::before { display: none; }

/* ── другий блок бічної панелі + список загроз ── */
.side-head-2 { border-top: 1px solid var(--panel-border); }
.threat-count { color: var(--alert-soft); }
#threatList { list-style: none; overflow-y: auto; padding: 6px 0; }
#threatList li {
  padding: 5px 12px;
  display: flex; align-items: baseline; gap: 6px;
  font-size: 13px; cursor: pointer;
}
#threatList li:hover { background: rgba(58, 160, 255, .08); }
#threatList li .tl-txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#threatList li .dur { color: var(--muted); font-size: 11px; white-space: nowrap; }
#threatList li.muted { color: var(--muted); cursor: default; }

/* ── міста ─────────────────────────────────────── */
.leaflet-tooltip.city-label {
  background: none; border: none; box-shadow: none;
  color: #aebdcd; font-size: 11px; font-weight: 600;
  text-shadow: 0 1px 3px #000, 0 0 6px #000;
  pointer-events: none; padding: 0 2px;
}
.leaflet-tooltip.city-label::before { display: none; }
.leaflet-tooltip.city-label-small { font-size: 10px; font-weight: 400; color: #7d8fa1; }
#map.hide-big-labels .city-label { display: none; }
#map.hide-big-labels .city-label-top { display: block; } /* топ-8 підписані завжди */
#map.hide-small-cities .city-label-small { display: none; }
#map.hide-small-cities path.city-small { display: none; }

/* ── стрічка моніторів ─────────────────────────── */
.feed-list {
  list-style: none;
  overflow-y: auto;
  max-height: 190px;
  padding: 4px 0;
}
.feed-list li {
  padding: 5px 12px;
  font-size: 11.5px;
  line-height: 1.35;
  border-bottom: 1px solid rgba(31, 43, 58, .5);
  cursor: default;
}
.feed-list li.geo { cursor: pointer; }
.feed-list li.geo:hover { background: rgba(58, 160, 255, .08); }
.feed-list li .f-meta { color: var(--muted); font-size: 10px; margin-bottom: 1px; display: flex; gap: 6px; }
.feed-list li .f-meta .f-src { color: #557; }
.feed-list li .f-txt { color: #c4d0dc; word-break: break-word; }
.feed-list li.muted { color: var(--muted); }

/* ── статистика за добу ────────────────────────── */
.stats-box { padding: 8px 12px 10px; }
.stats-totals { font-size: 12px; margin-bottom: 7px; }
.stats-totals b { font-weight: 700; }
.stats-chart {
  display: flex; align-items: flex-end; gap: 2px;
  height: 42px;
}
.stats-chart .bar {
  flex: 1;
  min-height: 2px;
  background: linear-gradient(to top, #7a2030, #e11d2e);
  border-radius: 2px 2px 0 0;
  opacity: .85;
}
.stats-chart .bar.b0 { background: #223140; }

/* ── плашка носіїв (МіГ-31К / стратеги / Калібри) ─ */
.carrier-bar {
  position: fixed;
  top: 12px; right: 12px;
  z-index: 1200;
  display: flex; flex-direction: column; gap: 6px;
  max-width: min(340px, calc(100vw - 24px));
}
.carrier-chip {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 12.5px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
  backdrop-filter: blur(6px);
}
.carrier-chip .c-ago { color: var(--muted); font-weight: 400; font-size: 11px; margin-left: auto; white-space: nowrap; }
.carrier-chip.danger {
  border-color: var(--alert);
  box-shadow: 0 0 12px rgba(225, 29, 46, .35);
  animation: carrier-danger 1.4s ease-in-out infinite;
}
@keyframes carrier-danger {
  0%, 100% { box-shadow: 0 0 6px rgba(225, 29, 46, .25); }
  50%      { box-shadow: 0 0 16px rgba(225, 29, 46, .6); }
}

@media (max-width: 640px) {
  .carrier-bar { top: 64px; right: 12px; left: 12px; max-width: none; }
  .carrier-chip { font-size: 11.5px; padding: 6px 10px; }
}

/* ── демо-банер ────────────────────────────────── */
.demo-banner {
  position: fixed;
  bottom: 64px; left: 50%;
  transform: translateX(-50%);
  z-index: 1500;
  background: #3d2f07;
  border: 1px solid #8a6d1a;
  color: #ffd964;
  padding: 7px 14px;
  border-radius: 10px;
  font-size: 12px;
}
.demo-banner code { background: #574508; padding: 0 4px; border-radius: 4px; }

/* ── маркери загроз (v6: кільце + чіп + курс) ──── */
.tmark {
  position: relative;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
}
.tmark-ring {
  position: absolute; inset: 2px;
  border: 2px solid var(--c);
  border-radius: 50%;
  opacity: 0;
  animation: t-ping 1.8s ease-out infinite;
  pointer-events: none;
}
.tmark-static .tmark-ring { animation-duration: 2.6s; }
@keyframes t-ping {
  0%   { transform: scale(.4); opacity: .9; }
  80%  { transform: scale(1.5); opacity: 0; }
  100% { transform: scale(1.5); opacity: 0; }
}
.tmark-ico {
  display: inline-block;
  font-size: 19px; line-height: 1;
  color: var(--c);
  text-shadow: 0 0 5px #000, 0 0 10px #000;
  filter: drop-shadow(0 0 5px var(--c));
}
.tmark-chip {
  position: absolute;
  left: 28px; top: 50%;
  transform: translateY(-50%);
  background: rgba(8, 12, 17, .88);
  border: 1px solid var(--c);
  color: #f2f6fa;
  font-size: 10px; font-weight: 600; line-height: 1.25;
  padding: 1px 6px;
  border-radius: 7px;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: none;
}
#map.hide-chips .tmark-chip { display: none; }
.tmark.arrived .tmark-ico { animation: threat-impact .9s ease-in-out infinite; }
.tmark.arrived .tmark-ring { animation-duration: .9s; }

path.course-line { animation: dash-flow 1.1s linear infinite; }
@keyframes dash-flow { to { stroke-dashoffset: -14; } }

.t-dest {
  font-size: 14px; line-height: 16px;
  text-align: center;
  opacity: .85;
  text-shadow: 0 0 5px #000;
  animation: t-dest-pulse 1.4s ease-in-out infinite;
}
@keyframes t-dest-pulse {
  0%, 100% { opacity: .5; }
  50%      { opacity: 1; }
}
.leaflet-popup-content-wrapper {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 10px;
}
.leaflet-popup-tip { background: var(--panel); }
@keyframes threat-impact {
  0%, 100% { transform: scale(1);   filter: drop-shadow(0 0 4px var(--c)); }
  50%      { transform: scale(1.6); filter: drop-shadow(0 0 14px var(--c)); }
}
.threat-pop b { text-transform: uppercase; font-size: 12px; letter-spacing: .4px; }
.threat-pop .tp-meta { color: var(--muted); font-size: 11px; margin-top: 3px; }
.threat-pop .ok { color: #2ecc71; }
.threat-pop .warn { color: var(--alert-soft); }

/* ── мобільна версія ───────────────────────────── */
@media (max-width: 640px) {
  .top-panel { right: 12px; padding: 8px 12px; }
  .brand h1 { font-size: 14px; }
  .meta { font-size: 11px; }

  /* панель → нижня шторка */
  .side-panel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 56dvh;
    z-index: 1100;
    border-radius: 14px 14px 0 0;
    border-bottom: none;
    transform: translateY(calc(100% - 46px));
    transition: transform .28s ease;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .side-panel.open { transform: none; }
  .sheet-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 46px;
    padding: 8px 16px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--panel-border);
    color: var(--text);
    font: inherit; font-weight: 600; font-size: 13px;
    cursor: pointer;
    position: sticky; top: 0;
    background: var(--panel);
  }
  .sheet-toggle .chev { color: var(--muted); transition: transform .28s; font-size: 11px; }
  .side-panel.open .sheet-toggle .chev { transform: rotate(180deg); }
  #alertList, #threatList { overflow-y: visible; }

  /* легенда — лише кольори, над шторкою */
  .legend-panel {
    bottom: 58px;
    font-size: 11px; gap: 4px 10px;
    padding: 6px 10px;
    background: rgba(13, 19, 27, .72);
  }
  .lg-threats, .credit { display: none; }

  /* кнопки зуму не потрібні — пінч */
  .leaflet-control-zoom { display: none; }

  .demo-banner { bottom: auto; top: 66px; width: max-content; max-width: calc(100vw - 24px); }
  .toast { max-width: calc(100vw - 24px); font-size: 13px; }
}
