/* --- Базовые настройки и сброс --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #000000;
  color: #ededed;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 11.5px;
  letter-spacing: 0.3px;
}

#map {
  width: 100vw;
  height: 100vh;
  z-index: 1;
  background: #000000;
}

/* Монохромная контрастная подложка карты */
.leaflet-tile-pane {
  filter: grayscale(100%) contrast(110%) brightness(88%);
}

/* --- 1. Модальное окно авторизации --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(5px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  width: 100%;
  max-width: 380px;
  background: #050505;
  border: 1px solid #262626;
  border-radius: 4px;
  padding: 30px 24px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.9);
}

.modal-header {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #ffffff;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.modal-desc {
  font-size: 11px;
  color: #737373;
  margin-bottom: 22px;
}

.modal-box input[type="password"] {
  width: 100%;
  padding: 9px 12px;
  background: #000000;
  border: 1px solid #262626;
  border-radius: 3px;
  color: #ffffff;
  font-family: inherit;
  font-size: 12px;
  outline: none;
  margin-bottom: 14px;
}

.modal-box input[type="password"]:focus {
  border-color: #ffffff;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* --- 2. Кнопки (Монохромная инверсия) --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 7px 12px;
  background: #000000;
  color: #d4d4d4;
  border: 1px solid #262626;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.12s ease;
  outline: none;
}

.btn:hover {
  background: #ffffff;
  color: #000000;
  border-color: #ffffff;
}

.btn-nav {
  padding: 4px 8px;
  font-size: 11px;
}

.btn-hq {
  background: #ffffff;
  border-color: #ffffff;
  color: #000000;
  font-weight: 700;
  padding: 9px;
}
.btn-hq:hover {
  background: #d4d4d4;
  border-color: #d4d4d4;
}

.btn-observer {
  background: #0a0a0a;
  color: #a3a3a3;
  padding: 9px;
}
.btn-observer:hover {
  background: #ffffff;
  color: #000000;
  border-color: #ffffff;
}

/* --- 3. Верхняя временная панель --- */
.timeline-bar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #050505;
  border: 1px solid #262626;
  border-radius: 4px;
  padding: 5px 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
  max-width: 95vw;
}

.timeline-slider-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

#time-slider {
  width: 200px;
  accent-color: #ffffff;
  cursor: pointer;
}

.date-badge {
  font-size: 11px;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
  background: #000000;
  padding: 4px 8px;
  border-radius: 2px;
  border: 1px solid #262626;
  letter-spacing: 0.5px;
}

.timeline-actions {
  display: flex;
  gap: 6px;
}

/* --- 4. Панель управления слева (Штаб) --- */
.panel {
  position: absolute;
  top: 60px;
  bottom: 16px;
  width: 290px;
  z-index: 1000;
  background: #050505;
  border: 1px solid #262626;
  border-radius: 4px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.8);
}

.panel-left { left: 16px; }

.panel-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #737373;
  border-bottom: 1px solid #1a1a1a;
  padding-bottom: 4px;
  text-transform: uppercase;
}

/* Фракции */
.faction-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.mil-btn {
  background: #000000;
  border: 1px solid #1f1f1f;
  border-left: 3px solid var(--c);
  border-radius: 2px;
  color: #a3a3a3;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 9.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.12s ease;
}

.mil-btn:hover {
  background: #141414;
  color: #ffffff;
  border-color: #333333;
  border-left-color: var(--c);
}

.mil-btn.active {
  background: #ffffff;
  color: #000000;
  border-color: #ffffff;
  border-left-color: var(--c);
  font-weight: 700;
}

/* Инструменты рисования */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.tool-btn {
  background: #000000;
  border: 1px solid #1f1f1f;
  border-radius: 2px;
  color: #a3a3a3;
  padding: 6px 2px;
  font-family: inherit;
  font-size: 9.5px;
  cursor: pointer;
  transition: all 0.12s;
}

.tool-btn:hover {
  background: #1a1a1a;
  color: #ffffff;
}

.tool-btn.active {
  background: #ffffff;
  border-color: #ffffff;
  color: #000000;
  font-weight: 700;
}

/* Маркеры */
.marker-palette {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.marker-btn {
  background: #000000;
  border: 1px solid #1f1f1f;
  border-radius: 2px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: #737373;
  font-family: inherit;
  font-size: 9px;
  transition: all 0.12s;
}

.marker-btn img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  filter: grayscale(100%) brightness(85%);
  transition: filter 0.12s;
}

.marker-btn:hover {
  background: #141414;
  color: #ffffff;
  border-color: #333333;
}
.marker-btn:hover img {
  filter: grayscale(0%) brightness(100%);
}

.marker-btn.active {
  background: #ffffff;
  border-color: #ffffff;
  color: #000000;
  font-weight: 700;
}
.marker-btn.active img {
  filter: invert(100%);
}

/* Кнопки управления и переноса */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.btn-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  margin-right: 8px;
  display: inline-block;
  background: #ffffff;
}

.btn-action-copy-zone { border-left: 3px solid #ffffff; justify-content: flex-start; }
.btn-action-copy-marker { border-left: 3px solid #a3a3a3; justify-content: flex-start; }
.btn-action-clear-hour { border-left: 3px solid #737373; justify-content: flex-start; }
.btn-action-clear-db { border-left: 3px solid #ef4444; justify-content: flex-start; color: #ef4444; }
.btn-action-clear-db:hover { background: #ef4444; color: #ffffff; border-color: #ef4444; }

/* --- 5. Всплывающие панели (Каталог и Хронология) --- */
.popup-panel {
  position: absolute;
  top: 60px;
  right: 16px;
  width: 310px;
  max-height: 82vh;
  z-index: 1001;
  background: #050505;
  border: 1px solid #262626;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  padding: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}

.popup-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #1f1f1f;
  padding-bottom: 6px;
  margin-bottom: 8px;
  font-weight: 700;
  color: #ffffff;
  text-transform: uppercase;
}

.close-btn {
  background: none;
  border: none;
  color: #737373;
  font-size: 16px;
  cursor: pointer;
}
.close-btn:hover { color: #ffffff; }

.catalog-content {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cat-nav-card {
  background: #000000;
  border: 1px solid #1f1f1f;
  border-radius: 3px;
  padding: 8px;
  cursor: pointer;
  transition: all 0.12s;
}
.cat-nav-card:hover { border-color: #ffffff; }
.cat-nav-card .title { font-weight: 600; color: #ffffff; display: flex; align-items: center; }
.cat-nav-card .desc { font-size: 9.5px; color: #737373; margin-top: 2px; }

details.cat-det {
  border: 1px solid #1a1a1a;
  border-radius: 2px;
  background: #000000;
  margin-bottom: 4px;
}
summary.cat-sum {
  padding: 5px 6px;
  cursor: pointer;
  color: #a3a3a3;
  font-weight: 600;
  outline: none;
}
summary.cat-sum:hover { color: #ffffff; }

.cat-children {
  padding: 4px 6px;
  border-left: 1px solid #1f1f1f;
  margin-left: 6px;
}

.cat-unit-item {
  padding: 4px 6px;
  margin: 2px 0;
  background: #050505;
  border: 1px solid #1a1a1a;
  border-radius: 2px;
  cursor: pointer;
  color: #8a8a8a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.12s;
}
.cat-unit-item:hover { background: #ffffff; color: #000000; border-color: #ffffff; font-weight: 600; }
.cat-unit-item.deployed { border-color: #ffffff; color: #ffffff; font-weight: 600; }

.chrono-controls {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

/* Маркеры карты */
.custom-map-marker {
  border-radius: 50%;
  border: 1.5px solid #ffffff;
  overflow: hidden;
  background: #000000;
}
.custom-map-marker img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.unit-label {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: #000000;
  color: #ffffff;
  font-size: 8px;
  font-weight: 600;
  padding: 1px 3px;
  border: 1px solid #333333;
  border-radius: 2px;
  white-space: nowrap;
}

/* Попапы Leaflet */
.leaflet-popup-content-wrapper {
  background: #050505 !important;
  color: #ededed !important;
  border: 1px solid #262626 !important;
  border-radius: 4px !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.9) !important;
  font-family: inherit !important;
}
.leaflet-popup-tip { background: #050505 !important; }
.popup-input {
  width: 100%;
  background: #000000;
  border: 1px solid #262626;
  border-radius: 2px;
  color: #ffffff;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 11px;
  margin-bottom: 6px;
  outline: none;
}
.popup-input:focus { border-color: #ffffff; }

.btn-save-pop {
  width: 100%;
  background: #ffffff;
  border: none;
  border-radius: 2px;
  color: #000000;
  padding: 7px;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  font-size: 10px;
}
.btn-save-pop:hover { background: #cccccc; }

/* Кастомный тонкий скроллбар */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: #000000; }
::-webkit-scrollbar-thumb { background: #1f1f1f; border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: #333333; }

/* Мобильная кнопка */
.mobile-toggle-btn {
  display: none;
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 1002;
  width: 42px;
  height: 42px;
  background: #000000;
  border: 1px solid #ffffff;
  color: #ffffff;
  font-size: 16px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Мобильный адаптив */
@media (max-width: 768px) {
  .mobile-toggle-btn { display: flex; }
  
  .timeline-bar {
    top: 8px;
    width: 95vw;
    padding: 6px 10px;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  #time-slider { width: 130px; }
  
  .panel-left {
    position: fixed;
    top: 56px;
    left: -110%;
    width: 82vw;
    bottom: 16px;
    transition: left 0.2s ease;
    z-index: 1005;
  }
  .panel-left.mobile-open { left: 10px; }
  
  .popup-panel {
    right: 50%;
    transform: translateX(50%);
    width: 90vw;
  }
}