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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #1a1a2e;
  color: #ecf0f1;
}

header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.8rem 1.5rem;
  background: #16213e;
  border-bottom: 2px solid #0f3460;
}

header h1 {
  font-size: 1.3rem;
  font-weight: 600;
  color: #e94560;
  white-space: nowrap;
}

#filtros {
  display: flex;
  gap: 0.4rem;
}

#filtros button {
  padding: 0.35rem 0.8rem;
  border: 1px solid #0f3460;
  border-radius: 4px;
  background: transparent;
  color: #ecf0f1;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}

#filtros button:hover {
  background: #0f3460;
}

#filtros button.activo {
  background: #e94560;
  border-color: #e94560;
}

#buscar {
  margin-left: auto;
  padding: 0.35rem 0.7rem;
  border: 1px solid #0f3460;
  border-radius: 4px;
  background: #1a1a2e;
  color: #ecf0f1;
  font-size: 0.85rem;
  width: 200px;
}

#buscar:focus {
  outline: none;
  border-color: #e94560;
}

main {
  position: relative;
  height: calc(100vh - 52px);
}

#grafo {
  position: relative;
  width: 100%;
  height: 100%;
}

#loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  color: #999;
  font-size: 0.9rem;
  z-index: 20;
}

#loading.oculto {
  display: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #0f3460;
  border-top-color: #e94560;
  border-radius: 50%;
  animation: girar 0.8s linear infinite;
}

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

#leyenda {
  position: absolute;
  bottom: 20px;
  left: 20px;
  background: rgba(20, 20, 35, 0.85);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  color: #ccc;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}

.punto {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

#panel {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 280px;
  max-height: calc(100vh - 6rem);
  padding: 1rem;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#panel.oculto {
  display: none;
}

#cerrar-panel {
  float: right;
  background: none;
  border: none;
  color: #ecf0f1;
  font-size: 1.3rem;
  cursor: pointer;
}

#panel h2 {
  font-size: 1.1rem;
  margin-bottom: 0.3rem;
}

#panel-tipo {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: #e94560;
  letter-spacing: 1px;
  margin-bottom: 0.5rem;
}

#panel-desc {
  font-size: 0.85rem;
  color: #bdc3c7;
  margin-bottom: 0.8rem;
}

#panel h3 {
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  color: #e94560;
}

#panel-relaciones {
  list-style: none;
  font-size: 0.8rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding-right: 4px;
}

#panel-relaciones::-webkit-scrollbar {
  width: 6px;
}

#panel-relaciones::-webkit-scrollbar-thumb {
  background: #0f3460;
  border-radius: 3px;
}

#panel-relaciones li {
  padding: 0.25rem 0;
  border-bottom: 1px solid #0f3460;
}

.resaltado {
  border-width: 3px !important;
  border-color: #e94560 !important;
}

.seleccionado {
  border-width: 4px !important;
  border-color: #e94560 !important;
  z-index: 10;
  width: 40 !important;
  height: 40 !important;
}

.vecino {
  border-width: 2px !important;
  border-color: #fff !important;
  opacity: 1 !important;
}

.fuera-vecindario {
  opacity: 0.03 !important;
}

.arista-conectada {
  line-color: #e94560 !important;
  target-arrow-color: #e94560 !important;
  text-opacity: 1 !important;
  color: #e94560 !important;
  width: 2.5px !important;
  z-index: 5;
}

.arista-fuera {
  opacity: 0.03 !important;
}

.relacion-link {
  cursor: pointer;
}

.relacion-link:hover {
  color: #fff;
  text-decoration: underline;
}

#panel-cita {
  background: rgba(255, 255, 255, 0.05);
  border-left: 3px solid #e94560;
  padding: 8px 10px;
  margin: 8px 0;
  font-size: 12px;
  line-height: 1.4;
  color: #ccc;
}

#panel-cita em {
  color: #ecf0f1;
}

#panel-cita.oculto {
  display: none;
}

#tooltip {
  position: fixed;
  pointer-events: none;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 6px;
  padding: 8px 12px;
  max-width: 280px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  font-size: 0.8rem;
  line-height: 1.4;
}

#tooltip.oculto {
  display: none;
}

#tooltip-tipo {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: #e94560;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

#tooltip-nombre {
  font-weight: 600;
  color: #ecf0f1;
  margin-bottom: 4px;
}

#tooltip-desc {
  color: #bdc3c7;
  font-size: 0.75rem;
}

/* ── Responsive: Tablet ────────────────────────────────────────────── */

@media (max-width: 900px) {
  header {
    flex-wrap: wrap;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
  }

  header h1 {
    font-size: 1.1rem;
  }

  #filtros {
    flex-wrap: wrap;
    gap: 0.3rem;
  }

  #filtros button {
    padding: 0.3rem 0.6rem;
    font-size: 0.7rem;
  }

  #buscar {
    width: 160px;
    font-size: 0.8rem;
  }

  #panel {
    width: 260px;
  }

  #leyenda {
    font-size: 11px;
    padding: 8px 10px;
  }
}

/* ── Responsive: Móvil ─────────────────────────────────────────────── */

@media (max-width: 600px) {
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.5rem 0.8rem;
  }

  header h1 {
    font-size: 1rem;
    text-align: center;
  }

  #filtros {
    justify-content: center;
    flex-wrap: wrap;
  }

  #filtros button {
    padding: 0.25rem 0.5rem;
    font-size: 0.65rem;
  }

  #buscar {
    margin-left: 0;
    width: 100%;
    font-size: 0.85rem;
    padding: 0.4rem 0.6rem;
  }

  main {
    height: calc(100vh - 100px);
  }

  #panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    max-height: 55vh;
    border-radius: 12px 12px 0 0;
    border-bottom: none;
    z-index: 50;
  }

  #leyenda {
    bottom: 10px;
    left: 10px;
    padding: 6px 8px;
    font-size: 10px;
    gap: 2px;
  }

  .punto {
    width: 8px;
    height: 8px;
    margin-right: 4px;
  }

  #tooltip {
    max-width: 200px;
    font-size: 0.7rem;
  }
}
