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

html, body {
  height: 100%;
  font-family: "Roboto", -apple-system, "Segoe UI", Arial, sans-serif;
}

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Панель — наложением поверх карты, полупрозрачная (карта видна сквозь неё). */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 300px;
  height: 100%;
  z-index: 800;
  padding: 20px;
  /* Плотная тёмная панель, чуть светлее карты + край и тень — чтобы визуально
     отделялась от карты, а не сливалась с тёмным фоном. */
  background: rgba(22, 28, 36, 0.94);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-right: 1px solid #2b3540;
  box-shadow: 2px 0 16px rgba(0, 0, 0, 0.5);
  color: #e4e7eb;
  overflow-y: auto;
}

#sidebar h1 {
  font-size: 20px;
  margin-bottom: 6px;
}

.hint {
  font-size: 13px;
  color: #9aa5b1;
  margin-bottom: 18px;
  line-height: 1.4;
}

/* Описание сайта (правится в админке) */
.site-desc {
  font-size: 13px;
  color: #cbd2d9;
  line-height: 1.45;
  margin-bottom: 12px;
}
.site-desc:empty {
  display: none;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #9aa5b1;
  margin-bottom: 6px;
}

select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #3e4c59;
  border-radius: 6px;
  background: #323f4b;
  color: #e4e7eb;
  font-size: 14px;
}

/* --- Легенда-фильтр --- */
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 14px;
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
  color: #e4e7eb;
}

.legend-row input {
  cursor: pointer;
  accent-color: #2f80ed;
}

/* Цветной кружок в легенде и списке */
.dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

button {
  width: 100%;
  padding: 9px;
  margin-bottom: 8px;
  border: none;
  border-radius: 6px;
  background: #2f80ed;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover {
  background: #2668c4;
}

#map {
  flex: 1;
  width: 100%;
  height: 100%;
  background: #0e1116;
}

/* Панель лежит поверх карты — уводим левые контролы Leaflet из-под неё. */
.leaflet-left {
  left: 300px;
}

/* Элементы только для админ-страницы (/admin) */
.admin-only {
  display: none;
}
body.admin .admin-only {
  display: block;
}

/* Курсор в режиме постановки метки */
.leaflet-container.placing-cursor {
  cursor: crosshair;
}

/* --- Таймлайн (фильтр по дате добавления) --- */
#timeline {
  position: fixed;
  bottom: 0;
  left: 300px; /* ширина сайдбара на десктопе */
  right: 0;
  z-index: 900;
  padding: 8px 16px 10px;
  /* Градиент: снизу чёрный как карта → вверх в прозрачность. */
  background: linear-gradient(to top, #0e1116 0%, rgba(14, 17, 22, 0) 100%);
  color: #e4e7eb;
}

.tl-top {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
#tl-label {
  font-weight: 600;
}
.tl-count {
  color: #9aa5b1;
  font-size: 12px;
}
#tl-reset {
  width: auto;
  margin: 0 0 0 auto;
  padding: 3px 9px;
  font-size: 12px;
  background: #52606d;
}
#tl-reset:hover {
  background: #3e4c59;
}

/* Двойной ползунок: две range-дорожки друг поверх друга */
.tl-slider {
  position: relative;
  height: 26px;
  margin-top: 4px;
}
.tl-track,
.tl-range {
  position: absolute;
  top: 11px;
  height: 4px;
  border-radius: 2px;
}
.tl-track {
  left: 0;
  right: 0;
  background: #3e4c59;
}
.tl-range {
  background: #2f80ed;
}
.tl-slider input[type="range"] {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 26px;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  pointer-events: none; /* кликабельны только «бегунки» */
}
.tl-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #2f80ed;
  border: 2px solid #fff;
  cursor: pointer;
}
.tl-slider input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2f80ed;
  border: 2px solid #fff;
  cursor: pointer;
}

.tl-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-size: 11px;
  color: #9aa5b1;
}

/* Поднимаем нижние контролы Leaflet (копирайт) над таймлайном.
   Таймлайн ~86px высотой — берём с запасом. */
.leaflet-bottom {
  bottom: 94px;
}

@media (max-width: 640px) {
  #timeline {
    left: 0; /* на мобильном карта во весь экран */
  }
  /* Панель уезжает в шторку — контролы Leaflet возвращаем к левому краю. */
  .leaflet-left {
    left: 0;
  }
}

/* --- Экран входа админа --- */
#admin-gate {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: #0e1116;
  display: flex;
  align-items: center;
  justify-content: center;
}
#admin-gate[hidden] {
  display: none;
}
#admin-gate-box {
  width: 320px;
  max-width: 90vw;
  padding: 26px 24px;
  background: #1f2933;
  border: 1px solid #3e4c59;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  text-align: center;
}
#admin-gate-box h2 {
  font-size: 20px;
  margin-bottom: 6px;
}
#gate-pass {
  width: 100%;
  padding: 10px;
  margin: 14px 0 10px;
  border: 1px solid #3e4c59;
  border-radius: 6px;
  background: #323f4b;
  color: #e4e7eb;
  font-size: 15px;
}
#gate-error {
  color: #e74c3c;
  font-size: 13px;
  margin-top: 8px;
  min-height: 16px;
}

/* --- Метки-кружки и кластеры --- */
/* Убираем белую подложку у divIcon по умолчанию. */
.leaflet-div-icon {
  background: transparent;
  border: none;
}
.marker-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.6);
  box-sizing: border-box;
}
.cluster-badge {
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.55);
  box-sizing: border-box;
}

/* Активная кнопка «Добавить метку» (режим включён) */
#btn-add.active {
  background: #c0392b;
}
#btn-add.active:hover {
  background: #a93226;
}

/* --- Модальная форма --- */
#modal-backdrop,
#cat-modal-backdrop,
#desc-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
#modal-backdrop[hidden],
#cat-modal-backdrop[hidden],
#desc-modal-backdrop[hidden] {
  display: none;
}

#modal,
#cat-modal,
#desc-modal {
  width: 340px;
  max-width: 90vw;
  background: #1f2933;
  color: #e4e7eb;
  border: 1px solid #3e4c59;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

/* Крестик закрытия формы метки — в верхнем левом углу. */
#modal {
  position: relative;
}
#modal h2 {
  padding-left: 32px; /* освобождаем место под крестик */
}
.modal-close {
  position: absolute;
  top: 14px;
  left: 12px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  color: #9aa5b1;
  font-size: 20px;
  line-height: 26px;
  text-align: center;
  cursor: pointer;
  border-radius: 6px;
}
.modal-close:hover {
  background: #3e4c59;
  color: #fff;
}

#modal h2,
#cat-modal h2,
#desc-modal h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

.modal-cat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #cbd2d9;
  margin-bottom: 14px;
}

#modal label,
#cat-modal label,
#desc-modal label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #9aa5b1;
  margin: 10px 0 5px;
}

#modal input,
#modal textarea,
#cat-modal input,
#desc-modal input,
#desc-modal textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #3e4c59;
  border-radius: 6px;
  background: #323f4b;
  color: #e4e7eb;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
#cat-modal input[type="color"] {
  height: 38px;
  padding: 2px;
}
#cat-modal .modal-cat input {
  width: auto;
}

/* Список категорий в админке */
.cat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 14px;
}
.cat-row .cat-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cat-row button {
  width: auto;
  margin: 0;
  padding: 3px 7px;
  font-size: 13px;
  background: #52606d;
}
.cat-row button:hover {
  background: #3e4c59;
}

#m-media {
  padding: 6px;
  font-size: 13px;
}

/* Предупреждение о том, чего не решает вычистка метаданных */
.warn-note {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.4;
  color: #f1c40f;
}

.muted {
  color: #9aa5b1;
  text-transform: none;
  letter-spacing: normal;
  font-size: 11px;
}

#m-upload {
  margin-top: 10px;
}
#m-upload progress {
  width: 100%;
  height: 8px;
  accent-color: #2f80ed;
}
#m-upload-text {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: #9aa5b1;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.modal-actions button {
  margin-bottom: 0;
}

.modal-actions .secondary {
  background: #52606d;
}
.modal-actions .secondary:hover {
  background: #3e4c59;
}

/* --- Тёмная тема для элементов Leaflet --- */
/* Leaflet задаёт свой шрифт — подменяем на Roboto (попапы, контролы). */
.leaflet-container {
  font-family: "Roboto", -apple-system, "Segoe UI", Arial, sans-serif;
}

.leaflet-bar a,
.leaflet-bar a:hover {
  background: #1f2933;
  color: #e4e7eb;
  border-bottom-color: #3e4c59;
}

.leaflet-bar a:hover {
  background: #323f4b;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: #1f2933;
  color: #e4e7eb;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.5);
}

.leaflet-popup-content a {
  color: #6ab0ff;
}

/* Прокручиваемый попап (когда контент выше maxHeight): скролл только по нужде,
   аккуратный тонкий скроллбар сбоку под тёмную тему, без лишней рамки снизу. */
.leaflet-popup-scrolled {
  overflow-y: auto;
  border-bottom: none !important;
  border-top: none !important;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: #52606d #1f2933;
}
.leaflet-popup-scrolled::-webkit-scrollbar {
  width: 8px;
}
.leaflet-popup-scrolled::-webkit-scrollbar-track {
  background: transparent;
}
.leaflet-popup-scrolled::-webkit-scrollbar-thumb {
  background: #52606d;
  border-radius: 4px;
}
.leaflet-popup-scrolled::-webkit-scrollbar-thumb:hover {
  background: #7b8794;
}

.leaflet-container a.leaflet-popup-close-button {
  color: #9aa5b1;
}

.leaflet-control-attribution {
  background: rgba(31, 41, 51, 0.85) !important;
  color: #9aa5b1;
}

/* Убираем флажок Украины из копирайта Leaflet */
.leaflet-attribution-flag {
  display: none !important;
}

.leaflet-control-attribution a {
  color: #6ab0ff;
}

.popup-cat {
  font-size: 12px;
  color: #9aa5b1;
}

.popup-meta {
  margin-top: 4px;
  font-size: 11px;
  color: #9aa5b1;
}

.tg-embed {
  display: block;
  width: 100%;
  height: 320px;
  border: 0;
  margin-top: 6px;
  border-radius: 8px;
  background: #16202b;
}

.popup-tg {
  display: inline-block;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
}

.popup-del {
  margin-top: 8px;
  width: auto;
  padding: 5px 10px;
  background: #c0392b;
  font-size: 12px;
}

.popup-del:hover {
  background: #a93226;
}

/* --- Голосование по метке (подтвердить / опровергнуть) --- */
.popup-votes {
  display: flex;
  gap: 14px;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
}
.vote-count.confirm {
  color: #27ae60;
}
.vote-count.deny {
  color: #e74c3c;
}

.status-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.status-actions .st-btn {
  width: auto;
  margin-bottom: 0;
  padding: 4px 10px;
  font-size: 12px;
}

.st-btn.confirm {
  background: #27ae60;
}
.st-btn.confirm:hover {
  background: #1f8f4d;
}
.st-btn.deny {
  background: #52606d;
}
.st-btn.deny:hover {
  background: #3e4c59;
}

/* Выбранная пользователем кнопка и заблокированные после голоса */
.st-btn.chosen {
  outline: 2px solid #fff;
  outline-offset: 1px;
}
.st-btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.st-btn.deny:disabled:hover {
  background: #52606d;
}
.st-btn.confirm:disabled:hover {
  background: #27ae60;
}

.vote-note {
  margin-top: 6px;
  font-size: 11px;
  color: #9aa5b1;
}

#admin-box {
  padding: 12px;
  background: #16202b;
  border: 1px solid #3e4c59;
  border-radius: 8px;
}

#admin-status {
  font-size: 13px;
  margin-bottom: 8px;
  color: #cbd2d9;
}

#admin-box button {
  margin-bottom: 0;
  background: #52606d;
}

#admin-box button:hover {
  background: #3e4c59;
}

#cat-hint {
  margin: 6px 0 0;
}

/* --- Мобильная версия: карта на весь экран + выезжающая панель --- */
.menu-toggle {
  display: none; /* показывается только на узких экранах */
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1200;
  width: 46px;
  height: 46px;
  margin: 0;
  padding: 0;
  border-radius: 10px;
  background: #1f2933;
  color: #e4e7eb;
  font-size: 22px;
  line-height: 46px;
  text-align: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}
.menu-toggle:hover {
  background: #323f4b;
}

.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1150;
}

@media (max-width: 640px) {
  .menu-toggle {
    display: block;
  }

  /* Карта занимает весь экран */
  #map {
    height: 100%;
    width: 100%;
  }

  /* Панель — выезжающая шторка слева */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 82%;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1180;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.5);
  }

  body.drawer-open #sidebar {
    transform: translateX(0);
  }
  body.drawer-open .drawer-backdrop {
    display: block;
  }
}

/* ==================== СВЕТЛАЯ ТЕМА (класс body.theme-light) ====================
   Наложение поверх тёмной палитры — базовые правила не меняются. Включается
   переключателем «Светлая тема»; выбор сохраняется в localStorage. */
body.theme-light #sidebar {
  background: rgba(247, 249, 251, 0.94);
  color: #1f2933;
  border-right: 1px solid #cbd2d9;
  box-shadow: 2px 0 16px rgba(0, 0, 0, 0.12);
}
body.theme-light .hint,
body.theme-light .field label,
body.theme-light .tl-count,
body.theme-light .popup-cat,
body.theme-light .popup-meta {
  color: #52606d;
}
body.theme-light .site-desc {
  color: #3e4c59;
}
body.theme-light .legend-row {
  color: #1f2933;
}
body.theme-light .dot {
  border-color: rgba(0, 0, 0, 0.35);
}

/* Поля ввода / селекты */
body.theme-light select,
body.theme-light #modal input,
body.theme-light #modal textarea,
body.theme-light #cat-modal input,
body.theme-light #desc-modal input,
body.theme-light #desc-modal textarea {
  background: #fff;
  color: #1f2933;
  border-color: #cbd2d9;
}

/* Модальные окна */
body.theme-light #modal,
body.theme-light #cat-modal,
body.theme-light #desc-modal {
  background: #fff;
  color: #1f2933;
  border-color: #cbd2d9;
}
body.theme-light #modal label,
body.theme-light #cat-modal label,
body.theme-light #desc-modal label,
body.theme-light .modal-cat {
  color: #52606d;
}
body.theme-light .modal-close {
  color: #52606d;
}
body.theme-light .modal-close:hover {
  background: #e4e7eb;
  color: #1f2933;
}

/* Всплывающий попап метки */
body.theme-light .leaflet-popup-content-wrapper,
body.theme-light .leaflet-popup-tip {
  background: #fff;
  color: #1f2933;
}
body.theme-light .leaflet-popup-content a {
  color: #1a6fd4;
}
body.theme-light .leaflet-container a.leaflet-popup-close-button {
  color: #52606d;
}
body.theme-light .leaflet-popup-scrolled {
  scrollbar-color: #b0b8c0 #fff;
}
body.theme-light .leaflet-popup-scrolled::-webkit-scrollbar-thumb {
  background: #b0b8c0;
}

/* Таймлайн */
body.theme-light #timeline {
  background: linear-gradient(to top, rgba(247, 249, 251, 0.95) 0%, rgba(247, 249, 251, 0) 100%);
  color: #1f2933;
}
body.theme-light .tl-track {
  background: #cbd2d9;
}

/* Метки и кластеры: тёмная обводка вместо белой — чтобы читались на светлой карте */
body.theme-light .marker-dot,
body.theme-light .cluster-badge {
  border-color: #1f2933;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
}

/* --- Поле адреса / выбор точки в окне добавления метки --- */
#m-loc-field {
  margin-bottom: 6px;
}
.addr-row {
  display: flex;
  gap: 6px;
}
.addr-row input {
  flex: 1;
}
.addr-btn {
  width: auto;
  white-space: nowrap;
  margin-bottom: 8px;
}
.loc-status {
  font-size: 12px;
  color: #27ae60;
  margin-top: 4px;
  min-height: 15px;
  line-height: 1.3;
  word-break: break-word;
}
.loc-status.err {
  color: #e74c3c;
}

/* Баннер-подсказка в режиме «Указать на карте» */
#pick-hint {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  background: #2f80ed;
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.4);
}
#pick-hint[hidden] {
  display: none;
}

/* --- Окно редактирования метки (админ) --- */
#edit-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
#edit-modal-backdrop[hidden] {
  display: none;
}
#edit-modal {
  position: relative;
  width: 340px;
  max-width: 90vw;
  background: #1f2933;
  color: #e4e7eb;
  border: 1px solid #3e4c59;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
#edit-modal h2 {
  font-size: 18px;
  margin-bottom: 12px;
  padding-left: 32px;
}
#edit-modal label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #9aa5b1;
  margin: 10px 0 5px;
}
#edit-modal select,
#edit-modal input,
#edit-modal textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #3e4c59;
  border-radius: 6px;
  background: #323f4b;
  color: #e4e7eb;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

/* Кнопки админа в попапе (изменить/удалить) */
.popup-admin {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.popup-admin button {
  width: auto;
  margin: 0;
  padding: 5px 10px;
  font-size: 12px;
}
.popup-edit {
  background: #3e4c59;
}
.popup-edit:hover {
  background: #52606d;
}

/* Светлая тема для окна редактирования */
body.theme-light #edit-modal {
  background: #fff;
  color: #1f2933;
  border-color: #cbd2d9;
}
body.theme-light #edit-modal label {
  color: #52606d;
}
body.theme-light #edit-modal select,
body.theme-light #edit-modal input,
body.theme-light #edit-modal textarea {
  background: #fff;
  color: #1f2933;
  border-color: #cbd2d9;
}
