/* Mapa Sistema Neuronal — HUD */
:root {
  --bg: #04060d;
  --panel: rgba(10, 16, 30, 0.82);
  --panel-border: rgba(120, 180, 255, 0.16);
  --text: #dfe9f5;
  --text-dim: #8fa4bd;
  --accent: #7fd4ff;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', monospace;
  --sans: 'Chakra Petch', 'Segoe UI', system-ui, sans-serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--bg); }
body {
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(ellipse 120% 80% at 70% 20%, rgba(30, 45, 90, 0.35), transparent 60%),
    radial-gradient(ellipse 100% 90% at 20% 85%, rgba(60, 25, 80, 0.25), transparent 55%),
    var(--bg);
  -webkit-user-select: none; user-select: none;
  touch-action: none;
}
body::after { /* viñeta sutil */
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 3;
  background: radial-gradient(ellipse 140% 110% at 50% 45%, transparent 60%, rgba(0,0,4,0.55) 100%);
}
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 1; }
#labels { position: fixed; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.plabel {
  position: absolute; transform: translate(-50%, -50%);
  font-family: var(--sans); font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; white-space: nowrap;
  color: var(--text); text-shadow: 0 0 8px rgba(0,0,0,0.9), 0 0 18px currentColor;
  pointer-events: auto; cursor: pointer; transition: opacity .2s;
}
.plabel small { display: block; text-align: center; font-weight: 300; letter-spacing: .08em; color: var(--text-dim); text-shadow: 0 0 6px #000; }

#tooltip {
  position: fixed; z-index: 6; pointer-events: none;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 6px; padding: 6px 10px; font-family: var(--mono); font-size: 12px;
  backdrop-filter: blur(6px); max-width: 320px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}
#tooltip .tt-proj { color: var(--text-dim); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }

/* ---- HUD superior ---- */
#hud-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 22px; pointer-events: none; gap: 14px;
}
#brand { pointer-events: auto; }
#brand h1 {
  font-size: 17px; font-weight: 700; letter-spacing: 0.26em;
  background: linear-gradient(90deg, #eaf6ff, #7fd4ff 60%, #b388ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 12px rgba(127, 212, 255, 0.35));
}
#stats { margin-top: 6px; font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
#stats b { color: var(--accent); font-weight: 600; }
#stats .sep { margin: 0 6px; opacity: .5; }

#searchbox { position: relative; pointer-events: auto; width: min(320px, 44vw); }
#search {
  width: 100%; padding: 9px 14px; border-radius: 8px;
  border: 1px solid var(--panel-border); background: var(--panel);
  color: var(--text); font-family: var(--mono); font-size: 13px;
  outline: none; backdrop-filter: blur(8px);
}
#search:focus { border-color: rgba(127, 212, 255, 0.55); box-shadow: 0 0 0 2px rgba(127,212,255,0.12), 0 0 22px rgba(127,212,255,0.1); }
#search::placeholder { color: #5c7089; }
#search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; max-height: 46vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 8px;
  backdrop-filter: blur(10px); box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
.sr-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid rgba(120,180,255,0.06); }
.sr-item:hover, .sr-item.active { background: rgba(127, 212, 255, 0.1); }
.sr-item .sr-name { font-family: var(--mono); font-size: 12.5px; color: var(--text); }
.sr-item .sr-meta { font-size: 10.5px; color: var(--text-dim); letter-spacing: .05em; margin-top: 2px; }
.sr-item .sr-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: baseline; }
.sr-empty { padding: 10px 12px; color: var(--text-dim); font-size: 12px; font-style: italic; }

/* ---- leyenda ---- */
#legend {
  position: fixed; left: 18px; bottom: 18px; z-index: 5;
  width: 252px; max-height: 56vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px;
  backdrop-filter: blur(10px); overflow: hidden;
}
#legend-toggle {
  all: unset; cursor: pointer; padding: 10px 14px; font-family: var(--sans);
  font-size: 12px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--accent); display: block;
}
#legend-toggle:hover { color: #fff; }
#legend-list { overflow-y: auto; padding: 0 6px 8px; }
#legend.collapsed #legend-list { display: none; }
.lg-item {
  display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px;
  cursor: pointer; font-size: 12px;
}
.lg-item:hover { background: rgba(127, 212, 255, 0.08); }
.lg-item.active { background: rgba(127, 212, 255, 0.16); outline: 1px solid rgba(127,212,255,0.35); }
.lg-item.dimmed { opacity: 0.38; }
.lg-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 8px currentColor; }
.lg-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lg-count { font-family: var(--mono); font-size: 10px; color: var(--text-dim); }

/* ---- botones ---- */
#controls { position: fixed; right: 18px; bottom: 18px; z-index: 5; display: flex; gap: 8px; }
#controls button {
  all: unset; cursor: pointer; padding: 9px 16px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--panel-border);
  font-family: var(--sans); font-size: 12.5px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--text); backdrop-filter: blur(8px); transition: all .15s;
}
#controls button:hover { border-color: rgba(127,212,255,0.5); color: #fff; box-shadow: 0 0 18px rgba(127,212,255,0.15); }
#controls button.on { background: rgba(127, 212, 255, 0.18); border-color: var(--accent); color: #fff; }
#controls button:disabled { opacity: .45; cursor: wait; }
#btn-regen { font-size: 11.5px; opacity: .8; }

/* ---- tarjeta de detalle ---- */
#detail {
  position: fixed; right: 18px; top: 84px; z-index: 6; width: min(340px, calc(100vw - 36px));
  max-height: calc(100vh - 190px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px;
  backdrop-filter: blur(12px); padding: 16px 18px;
  box-shadow: 0 14px 50px rgba(0,0,0,0.6);
  animation: slideIn .22s ease;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
#detail-close {
  all: unset; position: absolute; top: 10px; right: 12px; cursor: pointer;
  color: var(--text-dim); font-size: 14px; padding: 4px;
}
#detail-close:hover { color: #fff; }
#detail h2 { font-family: var(--mono); font-size: 15px; word-break: break-all; padding-right: 20px; }
#detail .d-badges { margin: 8px 0 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase; font-weight: 600;
  padding: 3px 8px; border-radius: 20px; border: 1px solid currentColor;
}
#detail .d-row { font-size: 12px; margin: 5px 0; color: var(--text-dim); }
#detail .d-row b { color: var(--text); font-weight: 400; font-family: var(--mono); font-size: 11.5px; word-break: break-all; }
#detail h3 {
  margin: 14px 0 6px; font-size: 10.5px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--text-dim); font-weight: 600;
}
.d-conn {
  display: flex; align-items: center; gap: 7px; padding: 4px 6px; margin: 1px 0;
  border-radius: 5px; cursor: pointer; font-family: var(--mono); font-size: 11.5px;
}
.d-conn:hover { background: rgba(127,212,255,0.1); }
.d-conn .c-dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.d-conn .c-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-conn .c-kind { font-size: 9px; color: var(--text-dim); letter-spacing: .08em; text-transform: uppercase; }
.d-more { font-size: 11px; color: var(--text-dim); font-style: italic; padding: 4px 6px; }

/* ---- selector de vistas ---- */
#views {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 5;
  display: flex; gap: 4px; padding: 5px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--panel-border); backdrop-filter: blur(8px);
}
#views button {
  all: unset; cursor: pointer; padding: 6px 12px; border-radius: 7px;
  font-family: var(--sans); font-size: 11.5px; font-weight: 600; letter-spacing: 0.06em;
  color: var(--text-dim); transition: all .15s; white-space: nowrap;
}
#views button:hover { color: #fff; }
#views button.on {
  background: rgba(127, 212, 255, 0.16); color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(127, 212, 255, 0.35);
}

#hint {
  position: fixed; bottom: 62px; left: 50%; transform: translateX(-50%); z-index: 4;
  font-size: 11px; letter-spacing: .1em; color: var(--text-dim); opacity: 0.85;
  pointer-events: none; transition: opacity 1s; text-shadow: 0 1px 4px #000;
}
#hint.fade { opacity: 0; }

/* ---- arranque ---- */
#boot {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: var(--bg); transition: opacity .8s ease; pointer-events: none;
}
#boot.fade { opacity: 0; }
#boot-inner { text-align: center; color: var(--text-dim); font-size: 13px; letter-spacing: .3em; text-transform: uppercase; }
.pulse-ring {
  width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 50%;
  border: 1px solid var(--accent); animation: ringPulse 1.6s ease-out infinite;
  box-shadow: 0 0 30px rgba(127,212,255,0.3) inset, 0 0 30px rgba(127,212,255,0.2);
}
@keyframes ringPulse { 0% { transform: scale(.6); opacity: 1; } 100% { transform: scale(1.4); opacity: 0; } }

#err {
  position: fixed; left: 50%; bottom: 64px; transform: translateX(-50%); z-index: 30;
  background: rgba(60, 12, 18, 0.92); border: 1px solid #ff8a80; color: #ffd6d3;
  padding: 10px 16px; border-radius: 8px; font-family: var(--mono); font-size: 12px; max-width: 80vw;
}
.hidden { display: none !important; }

/* ---- capa de actividad en vivo (aditiva, no toca lo existente) ---- */
#btn-live { position: relative; }
#btn-live::after {
  content: ''; position: absolute; top: 7px; right: 7px; width: 5px; height: 5px;
  border-radius: 50%; background: #5c7089; transition: background .3s, box-shadow .3s;
}
#btn-live.live-conn::after { background: #69f0ae; box-shadow: 0 0 6px #69f0ae; }
#btn-live:not(.on)::after { background: #45536a; box-shadow: none; }

#live-ticker {
  position: fixed; top: 76px; left: 22px; z-index: 4; max-width: min(400px, 60vw);
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 11px; color: var(--text-dim);
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 8px;
  padding: 6px 10px; backdrop-filter: blur(8px);
  pointer-events: none; opacity: 0; transition: opacity .45s ease;
  text-shadow: 0 1px 3px #000; white-space: nowrap; overflow: hidden;
}
#live-ticker.show { opacity: 0.92; }
#live-ticker .lt-ic { font-size: 13px; flex: none; filter: drop-shadow(0 0 5px currentColor); }
#live-ticker .lt-plat { font-weight: 600; letter-spacing: .05em; flex: none; }
#live-ticker .lt-txt { overflow: hidden; text-overflow: ellipsis; color: var(--text); }
#live-ticker .lt-hora { color: var(--text-dim); flex: none; opacity: .8; }

/* ---- móvil ---- */
@media (max-width: 720px) {
  #hud-top { padding: 12px 14px; flex-wrap: wrap; }
  #brand h1 { font-size: 12.5px; letter-spacing: 0.18em; }
  #stats { font-size: 10.5px; }
  #searchbox { width: 100%; order: 3; }
  #legend { left: 10px; bottom: 110px; width: 200px; max-height: 40vh; }
  #controls { right: 10px; bottom: 12px; left: auto; }
  #controls button { padding: 8px 12px; font-size: 11.5px; }
  #views { bottom: 58px; padding: 4px; gap: 2px; max-width: calc(100vw - 20px); overflow-x: auto; }
  #views button { padding: 5px 8px; font-size: 10.5px; }
  #detail { top: auto; bottom: 60px; right: 10px; max-height: 52vh; }
  #hint { display: none; }
  #live-ticker { top: 118px; left: 12px; max-width: calc(100vw - 24px); font-size: 10px; }
}
