/* Тёмная тема карты событий. Свой origin, никаких внешних шрифтов и CDN. */

:root {
  --bg: #0b1016;
  --panel: rgba(16, 23, 32, 0.88);
  --panel-border: rgba(120, 140, 165, 0.22);
  --text: #e6ecf3;
  --muted: #93a1b1;
  --accent: #3fb1ce;
}

* { box-sizing: border-box; }

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

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

/* Две колонки панелей поверх карты. Рейка сама клики не ловит — иначе промежутки между панелями
   съедали бы клики по карте; ловят только сами панели. */
.rail {
  position: absolute;
  top: 12px;
  bottom: 34px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}
.rail--left { left: 12px; width: 340px; }
.rail--right { right: 12px; width: 300px; }

.panel {
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

/* Только лента умеет сжиматься и скроллиться: остальные панели показываются целиком. */
.panel--head, .panel--controls, .panel--legend { flex: 0 0 auto; }
.panel--feed {
  display: flex;
  flex-direction: column;
  min-height: 120px;
  overflow: hidden;
}

h1 { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
h2 { margin: 0 0 8px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
p { margin: 0 0 6px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.status { margin-top: 8px; font-variant-numeric: tabular-nums; }

.control { display: block; margin-bottom: 12px; }
.control > span { display: block; margin-bottom: 4px; color: var(--muted); }
.control input[type="range"] { width: 100%; accent-color: var(--accent); }
.control--check { display: flex; align-items: center; gap: 8px; }
.control--check > span { margin: 0; color: var(--text); }

.segmented { display: flex; gap: 6px; }
.segmented label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  cursor: pointer;
}
.segmented label:has(input:checked) {
  border-color: rgba(63, 177, 206, 0.6);
  background: rgba(63, 177, 206, 0.14);
}

#step {
  width: 100%;
  padding: 6px 8px;
  color: var(--text);
  background: #121a24;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font: inherit;
}

.control--buttons { display: flex; gap: 8px; }

.btn {
  width: 100%;
  padding: 8px 10px;
  color: var(--text);
  background: rgba(63, 177, 206, 0.16);
  border: 1px solid rgba(63, 177, 206, 0.5);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { background: rgba(63, 177, 206, 0.28); }
.btn[disabled] { opacity: .5; cursor: progress; }

#legend { margin: 0; padding: 0; list-style: none; }
#legend li { margin-bottom: 2px; }
#legend .legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 3px 4px;
  color: inherit;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
#legend .legend-item:hover { background: rgba(120, 140, 165, 0.14); }
#legend .legend-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Выключенная группа: гасим целиком, но счётчик оставляем читаемым — видно, сколько скрыто. */
#legend .legend-item[aria-pressed="false"] { opacity: 0.42; }
#legend .legend-item[aria-pressed="false"] .swatch { box-shadow: inset 0 0 0 2px var(--panel); }
#legend .swatch { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
#legend .count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.btn--slim { width: auto; margin-top: 6px; padding: 4px 8px; font-size: 12px; }

/* --- лента событий --- */

.search {
  width: 100%;
  margin-bottom: 8px;
  padding: 6px 8px;
  color: var(--text);
  background: #121a24;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font: inherit;
}
.search::placeholder { color: #6b7785; }
.search:disabled { opacity: .5; }

.feed {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  /* Полоса прокрутки в тёмной теме по умолчанию светлая и лезет в глаза */
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 140, 165, 0.45) transparent;
}
.feed-item {
  display: flex;
  gap: 8px;
  width: 100%;
  padding: 6px 6px;
  color: inherit;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.feed-item:hover { background: rgba(120, 140, 165, 0.14); }
.feed-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.feed-item.is-selected { background: rgba(63, 177, 206, 0.18); border-color: rgba(63, 177, 206, 0.5); }
.feed-dot { width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; flex: 0 0 auto; }
.feed-body { min-width: 0; flex: 1 1 auto; }
.feed-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-meta { color: var(--muted); font-size: 12px; }
.feed-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.feed-empty { padding: 6px; color: var(--muted); }

/* Шкала интенсивности для режима плотности — те же цвета, что в heatmap-ramp карты. */
.gradient {
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, #22506b, #3fb1ce, #f2c14e, #f4823c, #e8425f);
}
.gradient-labels {
  display: flex;
  justify-content: space-between;
  margin: 4px 0 6px;
  font-size: 12px;
  color: var(--muted);
}

.attribution {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 2;
  font-size: 11px;
  color: var(--muted);
}
.attribution a { color: var(--muted); }

/* Попап MapLibre под тёмную тему */
.maplibregl-popup-content {
  background: #121a24;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 14px;
  max-width: 300px;
  font: inherit;
  /* С дюжиной первоисточников попап перерастает экран и нижняя часть уезжает за край: MapLibre
     высоту не ограничивает. Скроллим попап целиком, а не список внутри него — вложенный скролл
     в маленьком окне нащупать мышью почти невозможно. */
  max-height: 55vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 140, 165, 0.45) transparent;
}
.maplibregl-popup-close-button { color: var(--muted); font-size: 17px; padding: 2px 7px; }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: #121a24; }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #121a24; }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: #121a24; }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: #121a24; }

.pop-title { font-weight: 600; margin-bottom: 2px; }
.pop-type { color: var(--accent); margin-bottom: 6px; }
.pop-row { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.pop-row b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.pop-warn { margin-top: 6px; color: #f2c14e; font-size: 12px; }
.pop-link { display: inline-block; color: var(--accent); }

/* Список первоисточников: в крупном кластере их дюжина — скроллим, а не растим попап на весь экран */
.pop-sources { margin-top: 10px; border-top: 1px solid var(--panel-border); padding-top: 8px; }
.pop-sources-title {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.pop-links { margin: 0 0 4px; padding: 0; list-style: none; }
.pop-links li { margin-bottom: 2px; }
.pop-links li::before { content: "· "; color: var(--muted); }

@media (max-width: 900px) {
  .rail {
    position: static;
    width: auto;
    margin: 12px;
    pointer-events: auto;
  }
  .panel--legend { display: none; }
  .panel--feed { max-height: 40vh; }
  #map { position: relative; height: 60vh; }
}
