/* ============================================
   AI THREAT MAP — Cybersecurity Dark Theme
   ============================================ */

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #0d1220;
  --bg-card: #111827;
  --bg-elevated: #1a2235;
  --border: rgba(0, 240, 255, 0.1);
  --border-bright: rgba(0, 240, 255, 0.25);
  --text-primary: #e2e8f0;
  --text-secondary: #8892a4;
  --text-muted: #4a5568;
  --cyan: #00f0ff;
  --red: #ff3333;
  --orange: #ff8c00;
  --yellow: #ffd700;
  --magenta: #ff00ff;
  --green: #00ff88;
  --cyan-glow: rgba(0, 240, 255, 0.15);
  --red-glow: rgba(255, 51, 51, 0.15);
  --sidebar-width: 320px;
  --header-height: 56px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============================================
   HEADER
   ============================================ */

#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(10, 14, 23, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  display: flex;
  align-items: center;
  animation: rotate-slow 20s linear infinite;
}

@keyframes rotate-slow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.header-title h1 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--cyan);
  line-height: 1.2;
}

.header-subtitle {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--cyan);
  line-height: 1;
}

.stat-label {
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
}

.live-indicator {
  flex-direction: row;
  gap: 6px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 0 0 8px var(--green);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.mobile-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 6px;
  cursor: pointer;
}

.mobile-toggle span {
  width: 18px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  transition: 0.3s ease;
}

/* ============================================
   SIDEBAR
   ============================================ */

.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  background: rgba(13, 18, 32, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 900;
  transition: transform 0.3s ease;
}

.sidebar-inner {
  padding: 16px;
}

.sidebar-section {
  margin-bottom: 20px;
}

.section-label {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-muted);
  margin-bottom: 10px;
  text-transform: uppercase;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  transition: border-color 0.2s;
}

.search-box:focus-within {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px var(--cyan-glow);
}

.search-box svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box input {
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  width: 100%;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  width: 100%;
}

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

.filter-btn.active {
  background: rgba(0, 240, 255, 0.08);
  border-color: rgba(0, 240, 255, 0.2);
  color: var(--cyan);
}

.filter-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.filter-count {
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  opacity: 0.6;
}

.actor-flag {
  font-size: 14px;
  width: 20px;
  text-align: center;
}

/* Stats Chart */
#stats-chart {
  width: 100%;
  max-width: 260px;
  margin: 0 auto;
  display: block;
}

/* Legend */
.legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-dot.pulsing {
  background: var(--cyan);
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 0 0 6px var(--cyan);
}

/* Scrollbar */
.sidebar::-webkit-scrollbar {
  width: 4px;
}
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-bright);
  border-radius: 2px;
}

/* ============================================
   MAP
   ============================================ */

#map {
  position: fixed;
  top: var(--header-height);
  left: var(--sidebar-width);
  right: 0;
  bottom: 0;
  z-index: 1;
  background: var(--bg-primary);
}

/* Leaflet overrides */
.leaflet-container {
  background: var(--bg-primary) !important;
  font-family: 'Inter', sans-serif !important;
}

.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important;
}

.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-bottom: 1px solid var(--border) !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-elevated) !important;
  color: var(--cyan) !important;
}

.leaflet-control-attribution {
  background: rgba(10, 14, 23, 0.8) !important;
  color: var(--text-muted) !important;
  font-size: 9px !important;
}

.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

/* Marker cluster overrides */
.marker-cluster {
  background: rgba(0, 240, 255, 0.15) !important;
  border: 1px solid rgba(0, 240, 255, 0.4) !important;
}

.marker-cluster div {
  background: rgba(0, 240, 255, 0.3) !important;
  color: var(--text-primary) !important;
  font-family: 'JetBrains Mono', monospace !important;
  font-weight: 700 !important;
  font-size: 12px !important;
}

.marker-cluster-small {
  background: rgba(0, 240, 255, 0.12) !important;
}
.marker-cluster-small div {
  background: rgba(0, 240, 255, 0.25) !important;
}
.marker-cluster-medium {
  background: rgba(255, 140, 0, 0.12) !important;
}
.marker-cluster-medium div {
  background: rgba(255, 140, 0, 0.3) !important;
}
.marker-cluster-large {
  background: rgba(255, 51, 51, 0.12) !important;
}
.marker-cluster-large div {
  background: rgba(255, 51, 51, 0.3) !important;
}

/* Custom marker */
.threat-marker {
  position: relative;
}

.threat-marker-inner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.threat-marker-inner:hover {
  transform: scale(1.4);
}

.threat-marker-inner.active-threat {
  animation: marker-pulse 2.5s ease-in-out infinite;
}

@keyframes marker-pulse {
  0%, 100% {
    box-shadow: 0 0 4px currentColor, 0 0 8px currentColor;
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 8px currentColor, 0 0 20px currentColor, 0 0 40px currentColor;
    transform: scale(1.15);
  }
}

/* Ripple ring for active threats */
.marker-ripple {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin-top: -20px;
  margin-left: -20px;
  border-radius: 50%;
  border: 1px solid;
  opacity: 0;
  animation: ripple 3s ease-out infinite;
  pointer-events: none;
}

@keyframes ripple {
  0% { transform: scale(0.3); opacity: 0.6; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* ============================================
   TOOLTIP
   ============================================ */

.threat-tooltip {
  background: rgba(13, 18, 32, 0.97) !important;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-bright) !important;
  border-radius: 12px !important;
  padding: 0 !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 240, 255, 0.05) !important;
  max-width: 400px !important;
  min-width: 320px;
  white-space: normal !important;
  word-wrap: break-word;
}

.threat-tooltip::before {
  border-right-color: var(--border-bright) !important;
}

.leaflet-tooltip-top::before,
.leaflet-tooltip-bottom::before,
.leaflet-tooltip-left::before,
.leaflet-tooltip-right::before {
  border-color: transparent !important;
}

.tooltip-content {
  padding: 16px;
}

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

.tooltip-title {
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

.tooltip-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}

.tooltip-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 11px;
}

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

.tooltip-meta-item strong {
  color: var(--text-primary);
  font-weight: 600;
}

.tooltip-desc {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.tooltip-impact {
  font-size: 11px;
  line-height: 1.5;
  color: var(--red);
  padding: 8px 10px;
  background: var(--red-glow);
  border-radius: 6px;
  border-left: 3px solid var(--red);
  margin-bottom: 10px;
}

.tooltip-impact strong {
  color: var(--red);
}

.tooltip-ttps {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.ttp-badge {
  display: inline-flex;
  padding: 2px 6px;
  background: rgba(0, 240, 255, 0.08);
  border: 1px solid rgba(0, 240, 255, 0.15);
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--cyan);
  letter-spacing: 0.3px;
}

/* ============================================
   DETAIL PANEL (Mobile)
   ============================================ */

.detail-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: rgba(13, 18, 32, 0.98);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-bright);
  border-radius: 16px 16px 0 0;
  padding: 20px;
  overflow-y: auto;
  z-index: 1100;
  transform: translateY(0);
  transition: transform 0.3s ease;
}

.detail-panel.hidden {
  transform: translateY(100%);
  pointer-events: none;
}

.detail-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.detail-close:hover {
  color: var(--text-primary);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    width: 300px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  #map {
    left: 0;
  }

  .mobile-toggle {
    display: flex;
  }

  .header-stats {
    display: none;
  }

  .header-title h1 {
    font-size: 14px;
  }

  /* Override tooltip for mobile — use detail panel instead */
  .leaflet-tooltip {
    display: none !important;
  }
}

@media (min-width: 901px) {
  .detail-panel {
    display: none !important;
  }
}

@media (max-width: 480px) {
  #header {
    padding: 0 12px;
  }

  .header-title h1 {
    font-size: 12px;
    letter-spacing: 2px;
  }

  .header-subtitle {
    display: none;
  }
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.sidebar-section {
  animation: fade-in 0.4s ease forwards;
}

.sidebar-section:nth-child(2) { animation-delay: 0.05s; }
.sidebar-section:nth-child(3) { animation-delay: 0.1s; }
.sidebar-section:nth-child(4) { animation-delay: 0.15s; }
.sidebar-section:nth-child(5) { animation-delay: 0.2s; }
.sidebar-section:nth-child(6) { animation-delay: 0.25s; }

/* Scanline overlay effect on the map */
#map::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 240, 255, 0.01) 2px,
    rgba(0, 240, 255, 0.01) 4px
  );
  pointer-events: none;
  z-index: 2;
}

/* Admin link button in header */
#admin-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  color: var(--text-muted, #4a5a78);
  border: 1px solid rgba(0,240,255,0.12);
  background: transparent;
  transition: color 0.18s, border-color 0.18s, background 0.18s;
  flex-shrink: 0;
  margin-right: 4px;
}
#admin-link:hover {
  color: #00f0ff;
  border-color: rgba(0,240,255,0.35);
  background: rgba(0,240,255,0.06);
}
