/* ===== Map root ===== */
#map { position: absolute; inset: 0; }

/* === ТЕМАТИЧЕСКИЕ ПЕРЕМЕННЫЕ ДЛЯ КАРТЫ / ОВЕРЛЕЯ === */
:root {
  --map-overlay-bg: #ffffff;
  --map-overlay-text: #111111;
  --map-overlay-heading: #555555;
  --map-overlay-border: #eeeeee;
  --map-overlay-shadow: 0 8px 26px rgba(0,0,0,.18);

  --map-opacity-text: #444444;
  --map-attribution-text: #777777;

  --map-burger-bg: #111111;
  --map-burger-text: #ffffff;

  --map-timeline-bg: rgba(255,255,255,.92);
  --map-timeline-label: #222222;
  --map-timeline-year-label: #333333;
  --map-timeline-month: #555555;
  --map-timeline-month-disabled: #bbbbbb;
  --map-timeline-slider-track: #e7e7e7;
  --map-timeline-slider-thumb: #111111;
  --map-timeline-year-btn-hover-bg: rgba(0,0,0,.06);
  --map-timeline-year-arrow: #111111;

  --map-timebar-bg: rgba(255,255,255,.95);
  --map-timebar-title: #000000;
  --map-timebar-label: #555555;
  --map-timebar-track-bg: #e6e9ef;
  --map-timebar-range-bg: #111111;
  --map-timebar-year-btn-bg: #ffffff;
  --map-timebar-year-btn-border: #d0d6e0;
  --map-timebar-year-btn-text: #000000;
  --map-timebar-year-btn-active-bg: #111111;
  --map-timebar-year-btn-active-border: #111111;
  --map-timebar-year-btn-active-text: #ffffff;

  --map-slider-thumb-border: #ffffff;

  /* Popup (light) */
  --popup-bg: #ffffff;
  --popup-text: #111827;
  --popup-border: #e5e7eb;
  --popup-strong: #111827;
  --popup-link: #2563eb;
  --popup-link-hover: #1d4ed8;

  /* Attribution control (light) */
  --map-attrib-bg: rgba(255,255,255,0.9);
  --map-attrib-border: #dddddd;
  --map-attrib-text: #555555;
  --map-attrib-link: #2563eb;
  --map-attrib-link-hover: #1d4ed8;

  /* цвета векторных слоёв (используются также в JS через getComputedStyle) */
  --vector-color-latest: #ff0000;
  --vector-color-older:  #ff832a;
}

/* Тёмная тема */
body.dark {
  --map-overlay-bg: #1f2021;
  --map-overlay-text: #e5e7eb;
  --map-overlay-heading: #9ca3af;
  --map-overlay-border: #333333;
  --map-overlay-shadow: 0 8px 26px rgba(0,0,0,.5);

  --map-opacity-text: #d1d5db;
  --map-attribution-text: #9ca3af;

  --map-burger-bg: #e5e7eb;
  --map-burger-text: #111111;

  --map-timeline-bg: rgba(32,32,32,.9);
  --map-timeline-label: #e5e7eb;
  --map-timeline-year-label: #e5e7eb;
  --map-timeline-month: #d1d5db;
  --map-timeline-month-disabled: #4b5563;
  --map-timeline-slider-track: #374151;
  --map-timeline-slider-thumb: #e5e7eb;
  --map-timeline-year-btn-hover-bg: rgba(255,255,255,.06);
  --map-timeline-year-arrow: #e5e7eb;

  --map-timebar-bg: rgba(24,24,27,.96);
  --map-timebar-title: #e5e7eb;
  --map-timebar-label: #9ca3af;
  --map-timebar-track-bg: #374151;
  --map-timebar-range-bg: #ffffff;
  --map-timebar-year-btn-bg: #111827;
  --map-timebar-year-btn-border: #4b5563;
  --map-timebar-year-btn-text: #e5e7eb;
  --map-timebar-year-btn-active-bg: #e5e7eb;
  --map-timebar-year-btn-active-border: #e5e7eb;
  --map-timebar-year-btn-active-text: #111827;

  --map-slider-thumb-border: #ffffff;

  /* Popup (dark) */
  --popup-bg: #111827;
  --popup-text: #e5e7eb;
  --popup-border: #374151;
  --popup-strong: #f9fafb;
  --popup-link: #60a5fa;
  --popup-link-hover: #93c5fd;

  /* Attribution control (dark) */
  --map-attrib-bg: rgba(17,24,39,0.9);   /* почти #111827 с прозрачностью */
  --map-attrib-border: #374151;
  --map-attrib-text: #9ca3af;
  --map-attrib-link: #93c5fd;
  --map-attrib-link-hover: #bfdbfe;

}

/* ===== Right overlay panel (SCOPED) ===== */
#overlay{
  position: absolute; top: 1rem; right: 1rem;
  font: 600 14px/1.35 system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  background: var(--map-overlay-bg);
  color: var(--map-overlay-text);
  border-radius: 10px;
  padding: .75rem .85rem;
  box-shadow: var(--map-overlay-shadow);
  z-index: 10;
  min-width: 260px; max-width: 320px;
  max-height: calc(100dvh - 2rem);
  overflow:auto;
}
#overlay h3{
  margin:.25rem 0 .5rem;
  font-size:13px;
  text-transform:uppercase;
  letter-spacing:.04em;
  color:var(--map-overlay-heading);
}

#overlay .group{
  padding-bottom:.5rem;
  border-bottom:1px solid var(--map-overlay-border);
  margin-bottom:.6rem;
}
#overlay .row{
  display:grid;
  grid-template-columns:1.2rem 1fr;
  align-items:center;
  column-gap:.5rem;
  padding:.35rem 0;
}
#overlay .row label{
  cursor:pointer;
  user-select:none;
}
#overlay .opacity{
  display:flex;
  gap:.6rem;
  align-items:center;
  font-weight:500;
  color:var(--map-opacity-text);
  margin-top:.2rem;
}
#overlay .opacity input[type="range"]{
  width:100%;
}
#overlay .attribution{
  margin-top:.4rem;
  font-weight:500;
  font-size:12px;
  color:var(--map-attribution-text);
}
#overlay .attribution a{
  color:inherit;
  text-decoration:underline;
}

/* ===== Burger (mobile) — scoped via ID ===== */
#menuToggle{
  position:absolute;
  top:.75rem; right:.75rem;
  z-index: 11;
  display:none;
  border:0;
  border-radius:10px;
  padding:.5rem .65rem;
  font:700 18px/1 system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  background:var(--map-burger-bg);
  color:var(--map-burger-text);
  box-shadow: 0 6px 18px rgba(0,0,0,.2);
  cursor:pointer;
}
#menuToggle:active{ transform: translateY(1px); }

@media (max-width: 768px){
  #menuToggle{ display:block; }
  #overlay{ display:none; }
  #overlay.open{ display:block; }
  #overlay{ min-width:70vw; max-width:86vw; }
  #map { position: absolute; inset: 0; }
}

/* ===== Raster timeline (SCOPED by ID) ===== */
#timeline{
  position: absolute;
  left: 50%;
  bottom: 50px;
  transform: translateX(-50%);
  width: 90%;
  z-index: 8;
  background: var(--map-timeline-bg);
  backdrop-filter: blur(4px);
  border-radius: 10px;
  padding: .6rem .75rem .7rem;
  box-shadow: 0 8px 20px rgba(0,0,0,.15);
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto auto;
  gap: .35rem .5rem;
  align-items: center;
}
#timeline.hidden{ display:none; }

#selDateLabel{
  grid-column: 1 / -1;
  text-align: center;
  font: 700 13px/1.2 system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  color:var(--map-timeline-label);
}

.yearBtn{
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  position: relative;
  border-radius: 6px;
}
.yearBtn:hover{ background: var(--map-timeline-year-btn-hover-bg); }
.yearBtn:active{ transform: translateY(1px); }
.yearBtn.left::before,
.yearBtn.right::before{
  content:"";
  position:absolute;
  top:50%;
  transform: translateY(-50%);
  width: 0; height: 0;
  border-style: solid;
}
.yearBtn.left::before{
  left: 12px;
  border-width: 8px 10px 8px 0;
  border-color: transparent var(--map-timeline-year-arrow) transparent transparent;
}
.yearBtn.right::before{
  right: 12px;
  border-width: 8px 0 8px 10px;
  border-color: transparent transparent transparent var(--map-timeline-year-arrow);
}

#monthSlider{
  grid-column: 2;
  -webkit-appearance: none; appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--map-timeline-slider-track);
  outline: none;
}
#monthSlider::-webkit-slider-thumb{
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--map-timeline-slider-thumb);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
#monthSlider::-moz-range-thumb{
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--map-timeline-slider-thumb);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  border: 0;
}

#monthTicks{
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0;
  margin-top: .2rem;
  font: 600 10px/1 system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  color:var(--map-timeline-month);
  user-select: none;
}
#monthTicks span{ text-align: center; }
#monthTicks span.disabled{ color:var(--map-timeline-month-disabled); }

#yearLabel{
  grid-column: 2;
  justify-self: center;
  font: 700 12px/1.2 system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  color:var(--map-timeline-year-label);
}

/* ===== Vector timeline (SCOPED by ID + class) ===== */
#timebar-vector{
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  background: var(--map-timebar-bg);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0,0,0,.22);
  padding: 10px 12px;
  font: 13px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  z-index: 9;
  bottom: 50px;
  transition: bottom .15s ease;
}
#timebar-vector.hidden{ display:none; }

#timebar-vector .timebar-title {
  font-weight: 600;
  margin: 0 0 6px;
  color: var(--map-timebar-title);
}
#timebar-vector .timebar-grid { display: grid; gap: 8px; }
#timebar-vector .timebar-labels {
  display: flex;
  justify-content: space-between;
  color: var(--map-timebar-label);
  font-size: 12px;
}
#timebar-vector .timebar-controls {
  position: relative;
  height: 32px;
}
#timebar-vector .timebar-controls input[type="range"] {
  position: absolute;
  left: 0; right: 0;
  width: 100%;
  height: 30px;
  margin: 0;
  -webkit-appearance: none;
  background: none;
  pointer-events: none;
}
#timebar-vector .timebar-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--map-timebar-range-bg);
  box-shadow: 0 0 0 4px #0000 inset;
  border: 2px solid var(--map-slider-thumb-border);
}
#timebar-vector .timebar-controls input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--map-timebar-range-bg);
  border: 2px solid var(--map-slider-thumb-border);
}
#timebar-vector .range-min { z-index: 2; }
#timebar-vector .range-max { z-index: 1; }

#timebar-vector .timebar-track {
  position: absolute;
  top: 14px;
  left: 0;
  height: 4px;
  width: 100%;
  background: var(--map-timebar-track-bg);
  border-radius: 2px;
}
#timebar-vector .timebar-range {
  position: absolute;
  top: 14px;
  height: 4px;
  background: var(--map-timebar-range-bg);
  border-radius: 2px;
}

#timebar-vector .years-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
#timebar-vector .years-row button {
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--map-timebar-year-btn-border);
  background: var(--map-timebar-year-btn-bg);
  cursor: pointer;
  font-size: 12px;
  color: var(--map-timebar-year-btn-text);
}
#timebar-vector .years-row button.active {
  background: var(--map-timebar-year-btn-active-bg);
  color: var(--map-timebar-year-btn-active-text);
  border-color: var(--map-timebar-year-btn-active-border);
}

/* ==== POPUP (vector click) ==== */

.maplibregl-popup-content {
  background: var(--popup-bg);
  color: var(--popup-text);
  border-radius: 10px;
  border: 1px solid var(--popup-border);
  padding: 8px 10px;
  font: 13px/1.35 system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
}

/* Changes + Licenses — одинаковые отступы между строками */
.changes-popup-row + .changes-popup-row,
.licenses-popup-row + .licenses-popup-row {
  margin-top: 2px;
}

/* Горизонтальная линия в попапе */
.changes-popup-hr,
.licenses-popup-hr {
  border: none;
  border-top: 1px solid var(--popup-border);
  margin: 6px 0;
}

/* Выделение <strong> в попапах */
.changes-popup strong,
.licenses-popup strong {
  color: var(--popup-strong);
}

/* Ссылки только в changes-popup (в licenses нет) */
.changes-popup a {
  color: var(--popup-link);
  text-decoration: none;
  font-weight: 600;
}
.changes-popup a:hover {
  text-decoration: underline;
  color: var(--popup-link-hover);
}

/* ===== Licenses popup navigation ===== */

.licenses-popup {
  /* базовые стили уже наследуются от .maplibregl-popup-content */
}

.licenses-popup-nav {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.licenses-nav-counter {
  font-size: 11px;
  opacity: 0.8;
}

.licenses-nav-btn {
  border: 1px solid var(--popup-border);
  background: transparent;
  color: var(--popup-text);
  border-radius: 4px;
  padding: 0 6px;
  font-size: 11px;
  line-height: 1.4;
  cursor: pointer;
}

.licenses-nav-btn:hover {
  background: rgba(255, 255, 255, 0.06); /* чуть заметный hover, в светлой теме будет почти не виден, но ок */
}


/* ===== MapLibre attribution control (themed) ===== */

.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib {
  background: var(--map-attrib-bg);
  color: var(--map-attrib-text);
  border-radius: 8px;
  border: 1px solid var(--map-attrib-border);
  padding: 2px 6px;
  font: 11px/1.3 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  margin: 0 4px 4px 0; /* чуть отступить от краёв */
}

.maplibregl-ctrl-attrib a {
  color: var(--map-attrib-link);
  text-decoration: none;
}
.maplibregl-ctrl-attrib a:hover {
  text-decoration: underline;
  color: var(--map-attrib-link-hover);
}

/* убираем лишние разделители, если хочешь более спокойный вид */
.maplibregl-ctrl-attrib-inner {
  white-space: nowrap;
}
