/* ── Fuentes ── */
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=DM+Sans:wght@300;400;600&display=swap');

/* ── Variables ── */
:root {
  --bg:        #0b0f1a;
  --panel:     #111827;
  --panel2:    #1a2236;
  --border:    #1f2d45;
  --accent:    #5eead4;
  --accent2:   #7dd3fc;
  --warn:      #fbbf24;
  --danger:    #ef4444;
  --text:      #e2e8f0;
  --muted:     #64748b;
  --mono:      'Space Mono', monospace;
  --sans:      'DM Sans', sans-serif;
  --radius:    8px;
  --shadow:    0 4px 24px rgba(0,0,0,.5);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .03em;
}

.logo svg { width: 28px; height: 28px; }

.logo span em {
  font-style: normal;
  color: var(--muted);
  font-weight: 400;
}

.stats-bar {
  display: flex;
  gap: 20px;
  margin-left: auto;
  align-items: center;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.stat-val {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.stat-lbl {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .08em;
  text-transform: uppercase;
}

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

@keyframes spin { to { transform: rotate(360deg); } }

.last-update {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
}

/* ── Layout ── */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Mapa ── */
#map {
  flex: 1;
  background: #0d1520;
}

.leaflet-tile-pane { filter: saturate(.85); }

/* ── Buscador en header ── */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  color: var(--muted);
  pointer-events: none;
  flex-shrink: 0;
  transition: color .2s;
}

.search-wrap:focus-within .search-icon { color: var(--accent); }

.search-input {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 14px 7px 32px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  width: 220px;
  transition: border-color .2s, box-shadow .2s;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(94,234,212,.12);
}

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

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 300px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 2000;
  max-height: 220px;
  overflow-y: auto;
  display: none;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.search-dropdown.open { display: block; }

.search-result {
  padding: 9px 14px;
  border-bottom: 1px solid rgba(31,45,69,.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background .12s;
}

.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.active { background: var(--panel2); }

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

.dot-recent  { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.dot-active  { background: var(--accent2); }
.dot-old     { background: var(--muted); }
.dot-gateway { background: var(--warn); box-shadow: 0 0 6px var(--warn); }

.result-name {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.result-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Panel de detalle ── */
.detail-panel {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 320px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 500;
  display: none;
  font-size: 13px;
}

.detail-panel.visible { display: block; animation: slideUp .2s ease; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.detail-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.detail-title {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  flex: 1;
}

.detail-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px;
}

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

.detail-body { padding: 14px 16px; }

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid rgba(31,45,69,.4);
}

.detail-row:last-child { border: none; }

.detail-key {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.detail-val {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  text-align: right;
  max-width: 55%;
  word-break: break-all;
}

.detail-val.accent { color: var(--accent); }

/* ── Leyenda ── */
.legend {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  z-index: 500;
  font-size: 11px;
}

.legend-title {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  color: var(--text);
}

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

.legend-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 7px 0;
}

.legend-line { flex-shrink: 0; }

/* ── Empty state ── */
.empty-state {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.empty-state svg { margin-bottom: 12px; opacity: .3; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 13px;
  font-family: var(--mono);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}

.toast.show { opacity: 1; }

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

/* ── Filtros ── */
.filter-toggle-btn {
  display: none; /* solo visible en móvil, posicionado en el mapa */
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000; /* por encima de los panes de Leaflet */
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
  box-shadow: var(--shadow);
}

.filter-toggle-btn svg { width: 15px; height: 15px; }

.filter-toggle-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(94,234,212,.1);
}

.filter-panel {
  position: absolute;
  bottom: 20px;
  left: 20px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fchip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  opacity: .45;
  text-decoration: line-through;
}

.fchip.active {
  color: var(--text);
  opacity: 1;
  text-decoration: none;
}

.fchip.active:hover { border-color: var(--accent); }

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

/* ── Zoom control ── */
.map-zoom-ctrl {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 10px;
}

.map-zoom-btn {
  width: 32px;
  height: 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* ── Nodo seleccionado ── */
.sel-marker {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sel-pulse {
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid;
  animation: sel-pulse 1.6s ease-out infinite;
}

.sel-pulse2 {
  animation-delay: .8s;
}

.sel-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid #1e293b;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}

@keyframes sel-pulse {
  0%   { transform: scale(.2); opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}

/* ── Leaflet overrides ── */
.leaflet-popup-content-wrapper {
  background: var(--panel) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  box-shadow: var(--shadow) !important;
  color: var(--text) !important;
  font-family: var(--sans) !important;
  font-size: 13px !important;
}

.leaflet-popup-tip { background: var(--panel) !important; }
.leaflet-popup-close-button { color: var(--muted) !important; }

/* ── Loading overlay ── */
#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  gap: 20px;
  transition: opacity .4s;
}

#loading.hidden { opacity: 0; pointer-events: none; }

.loader-ring {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.loader-text {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  letter-spacing: .1em;
}

/* ── Modo embed (?embed en la URL) ── */
body.embed-mode header {
  background: transparent;
  border: none;
  padding: 0;
  position: absolute;
  top: 10px;
  right: 10px;
  width: auto;
  z-index: 1000;
}

body.embed-mode .logo,
body.embed-mode .stat,
body.embed-mode .sep,
body.embed-mode .last-update {
  display: none;
}

body.embed-mode .stats-bar {
  margin-left: 0;
}

body.embed-mode .search-input {
  background: var(--panel);
  box-shadow: var(--shadow);
  border-color: var(--border);
}

@media (max-width: 768px) {
  body.embed-mode .filter-toggle-btn {
    top: 58px; /* debajo del buscador flotante */
  }
}

@media (max-width: 768px) {
  /* ── Header compacto ── */
  header {
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    gap: 10px;
  }

  .logo svg { width: 20px; height: 20px; }

  .logo span { font-size: 11px; }

  .logo span em { display: none; }

  .stats-bar { gap: 10px; flex: 1; }

  /* Ocultar stats y separadores en móvil */
  .stat, .sep, .last-update { display: none; }

  /* Buscador ocupa el espacio restante */
  .search-wrap { flex: 1; }

  .search-input {
    width: 100%;
    font-size: 14px; /* evita zoom automático en iOS */
  }

  .search-dropdown {
    width: 100vw;
    left: auto;
    right: -12px;
    border-radius: 0 0 var(--radius) var(--radius);
  }

  /* ── Panel de detalle: bottom sheet ── */
  .detail-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    border-radius: 14px 14px 0 0;
    max-height: 55vh;
    overflow-y: auto;
  }

  .detail-panel.visible {
    animation: slideUpMobile .25s ease;
  }

  @keyframes slideUpMobile {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);   opacity: 1; }
  }

  /* ── Filtros: fila horizontal scrollable ── */
  /* ── Botón filtro flotante en el mapa ── */
  .filter-toggle-btn { display: flex; }

  /* ── Panel filtros como dropdown ── */
  .filter-panel {
    display: none;
    position: absolute;
    bottom: auto;
    left: auto;
    width: 190px;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 2000;
  }

  .filter-panel.open { display: flex; }

  .fchip { width: 100%; }

  body.detail-open .filter-panel { display: none !important; }

  /* ── Leyenda oculta en móvil ── */
  .legend { display: none; }

  /* ── Zoom y filtro más grandes para touch ── */
  .map-zoom-btn {
    width: 40px;
    height: 40px;
    font-size: 22px;
  }

  .filter-toggle-btn {
    width: 40px;
    height: 40px;
  }

  .filter-toggle-btn svg { width: 18px; height: 18px; }
}
