:root {
  --bg-primary: #0b111e;
  --bg-secondary: #111827;
  --bg-card: #192234;
  --bg-card-hover: #212d45;
  --border-subtle: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(56, 189, 248, 0.42);
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent-blue: #38bdf8;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;
  --accent-green: #22c55e;
  --accent-purple: #a855f7;
  --accent-rose: #f43f5e;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Верхняя панель навигации */
.topbar {
  height: 58px;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  gap: 12px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-pulse {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-red);
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  animation: radarPulse 2s infinite;
}

@keyframes radarPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.3px;
  color: var(--text-primary);
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.city-select,
.search-input,
.form-input,
.form-select,
.form-textarea {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.city-select:focus,
.search-input:focus,
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent-blue);
}

.security-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #4ade80;
  white-space: nowrap;
}

/* Основной макет: Боковая панель + Карта */
.workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.sidebar {
  width: 470px;
  max-width: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 500;
  flex-shrink: 0;
}

.nav-tabs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  background: #0d1424;
  border-bottom: 1px solid var(--border-subtle);
  padding: 4px;
  gap: 3px;
}

.nav-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 600;
  padding: 7px 3px;
  border-radius: 7px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.nav-tab.active {
  background: var(--bg-card);
  color: var(--accent-blue);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.35);
}

.tab-pane {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  gap: 12px;
}

.tab-pane.active {
  display: flex;
}

/* Фильтры триггеров */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
}

.chip:hover {
  border-color: rgba(255, 255, 255, 0.3);
}

.chip.active {
  border-color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.16);
  color: #fff;
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Статистическая сводка */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}

.stat-val {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-lbl {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Карточки инцидентов */
.incident-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.incident-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  transition: all 0.15s;
  cursor: pointer;
}

.incident-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}

.incident-card.ambiguous-border {
  border-left: 4px solid #facc15;
}

.incident-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.trigger-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.precision-tag {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 5px;
  font-weight: 600;
}

.precision-exact {
  background: rgba(34, 197, 94, 0.16);
  color: #4ade80;
}

.precision-approximate {
  background: rgba(56, 189, 248, 0.16);
  color: #38bdf8;
}

.precision-ambiguous {
  background: rgba(250, 204, 21, 0.18);
  color: #facc15;
}

.incident-title {
  font-size: 13.5px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.incident-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 8px;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.confidence-bar-wrap {
  flex: 1;
  min-width: 80px;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  overflow: hidden;
}

.confidence-bar-fill {
  height: 100%;
  border-radius: 99px;
}

/* Список связанных кандидатов для неоднозначных меток («На Маке...») */
.candidates-box {
  background: rgba(250, 204, 21, 0.07);
  border: 1px dashed rgba(250, 204, 21, 0.45);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
}

.candidates-title {
  font-size: 11px;
  font-weight: 700;
  color: #facc15;
  margin-bottom: 6px;
}

.candidate-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11.5px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.candidate-item:last-child {
  border-bottom: none;
}

/* Шаги рассуждения ИИ */
.reasoning-box {
  background: rgba(15, 23, 42, 0.65);
  border-radius: 7px;
  padding: 7px 9px;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.reasoning-step {
  margin-bottom: 3px;
  line-height: 1.35;
}

/* Кнопки действий */
.action-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.btn:hover {
  border-color: var(--accent-blue);
}

.btn-primary {
  background: var(--accent-blue);
  color: #090d16;
  border-color: var(--accent-blue);
}

.btn-primary:hover {
  background: #7dd3fc;
}

.btn-confirm {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.35);
}

.btn-clear {
  background: rgba(148, 163, 184, 0.14);
  color: #cbd5e1;
}

.btn-warn {
  background: rgba(250, 204, 21, 0.18);
  color: #facc15;
  border-color: rgba(250, 204, 21, 0.4);
}

/* Область карты */
.map-wrapper {
  flex: 1;
  position: relative;
  height: 100%;
}

#map {
  width: 100%;
  height: 100%;
  background: #0b111e;
}

/* Тёмный радарный режим для официальных бесплатных тайлов OpenStreetMap (без API-ключей) */
.leaflet-container.dark-map-mode .leaflet-tile-pane {
  filter: invert(100%) hue-rotate(180deg) brightness(94%) contrast(92%);
}

.map-top-controls {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 600;
  display: flex;
  gap: 8px;
}

/* Плавающая легенда поверх карты */
.map-overlay-legend {
  position: absolute;
  bottom: 20px;
  right: 16px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 12px;
  z-index: 600;
  font-size: 11.5px;
  max-width: 280px;
}

.legend-title {
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-primary);
  font-size: 12px;
}

.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

/* Кастомные маркеры Leaflet */
.tactical-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #0b111e;
  font-weight: 800;
  font-size: 11px;
  border: 2px solid #ffffff;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.75);
}

.candidate-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #1e293b;
  color: #facc15;
  font-weight: 800;
  font-size: 11px;
  border: 2px dashed #facc15;
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.45);
}

.leaflet-popup-content-wrapper {
  background: #131c2e !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-strong);
  border-radius: 10px !important;
}

.leaflet-popup-tip {
  background: #131c2e !important;
}

/* Пресеты тестирования ИИ */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preset-btn {
  text-align: left;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  color: var(--text-secondary);
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 11.5px;
  cursor: pointer;
  transition: all 0.15s;
}

.preset-btn:hover {
  background: rgba(56, 189, 248, 0.16);
  color: #fff;
}

.bot-preview-box {
  background: #0d1526;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bot-map-img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.bot-text-output {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11.5px;
  white-space: pre-wrap;
  color: var(--text-secondary);
  line-height: 1.45;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px;
  border-radius: 6px;
}

/* Мобильный переключатель режимов экрана (скрыт на ПК) */
.mobile-view-switcher {
  display: none;
}

/* Пульсирующий синий маркер текущей геопозиции пользователя (GPS телефона) */
.user-gps-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #38bdf8;
  border: 3px solid #ffffff;
  box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.8);
  animation: gpsPulse 2s infinite;
}

@keyframes gpsPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.75);
  }
  70% {
    box-shadow: 0 0 0 14px rgba(56, 189, 248, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(56, 189, 248, 0);
  }
}

@media (max-width: 900px) {
  .topbar {
    height: auto;
    min-height: 48px;
    padding: 6px 10px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .brand-title {
    font-size: 13px;
  }

  .brand-subtitle,
  #mirrorStatusBadge,
  .hide-on-mobile {
    display: none !important;
  }

  .topbar-controls {
    width: 100%;
    gap: 6px;
    flex-wrap: nowrap;
  }

  .city-select {
    padding: 6px 8px;
    font-size: 12.5px;
    flex-shrink: 0;
  }

  .search-input {
    flex: 1;
    min-width: 0;
    padding: 6px 9px;
    font-size: 12.5px;
  }

  #liveMonitorTopBadge {
    font-size: 10px;
    padding: 4px 7px;
  }

  .workspace {
    flex-direction: column-reverse;
    padding-bottom: calc(44px + env(safe-area-inset-bottom, 0px));
  }

  .sidebar {
    width: 100%;
    height: 52%;
    border-right: none;
    border-top: 1px solid var(--border-subtle);
  }

  .map-wrapper {
    height: 48%;
    width: 100%;
  }

  /* Режим «Вся карта» на телефоне */
  .workspace.mobile-map-full .sidebar {
    display: none !important;
  }
  .workspace.mobile-map-full .map-wrapper {
    height: 100% !important;
  }

  /* Режим «Список / Меню» на телефоне */
  .workspace.mobile-list-full .map-wrapper {
    display: none !important;
  }
  .workspace.mobile-list-full .sidebar {
    height: 100% !important;
  }

  .map-top-controls {
    top: 8px;
    right: 8px;
    left: 48px;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 5px;
  }

  .map-top-controls .btn {
    padding: 5px 8px;
    font-size: 11px;
  }

  .map-overlay-legend {
    bottom: 10px;
    right: 8px;
    padding: 7px 9px;
    font-size: 10.5px;
    max-width: 215px;
  }

  .map-overlay-legend.collapsed #mapLegendGrid {
    display: none;
  }

  .map-overlay-legend.collapsed .legend-title {
    margin-bottom: 0;
  }

  .mobile-view-switcher {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(44px + env(safe-area-inset-bottom, 0px));
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom, 0px)) 8px;
    background: rgba(11, 17, 30, 0.97);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(56, 189, 248, 0.3);
    z-index: 2500;
    gap: 6px;
  }

  .mobile-view-btn {
    background: rgba(25, 34, 52, 0.9);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }

  .mobile-view-btn.active {
    background: rgba(56, 189, 248, 0.2);
    border-color: var(--accent-blue);
    color: #fff;
  }
}
