:root {
  --fondo: #060913;
  --cian: #00f3ff;
  --magenta: #ff007f;
  --verde: #00ff9d;
  --vidrio: rgba(15, 23, 42, 0.65);
  --texto: #f8fafc;
  --texto-2: #cbd5e1;
  --tenue: #8291a8;
  --linea: rgba(0, 243, 255, 0.18);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --titulo: 'Orbitron', sans-serif;
  --cuerpo: 'Rajdhani', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background-color: var(--fondo);
  background-image: linear-gradient(rgba(0,243,255,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(0,243,255,.035) 1px, transparent 1px);
  background-size: 40px 40px;
  color: var(--texto);
  font-family: var(--cuerpo);
  font-size: 16px;
}
button { font: inherit; color: inherit; cursor: pointer; }
.oculto { position: absolute; left: -9999px; }
[hidden] { display: none !important; }

.app { min-height: 100dvh; display: flex; flex-direction: column; }

/* Encabezado */
.top { display: flex; align-items: center; gap: 22px; padding: 12px 24px; border-bottom: 1px solid var(--linea); background: rgba(6,9,19,.75); flex-wrap: wrap; }
.marca { font-family: var(--titulo); font-weight: 800; font-size: 20px; letter-spacing: 4px; color: var(--cian); text-shadow: 0 0 12px rgba(0,243,255,.7); white-space: nowrap; }
.marca span { font-weight: 400; color: var(--texto); text-shadow: none; }
.marca.grande { font-size: 40px; }
.mision { flex: 1 1 320px; display: flex; align-items: center; gap: 12px; min-width: 0; }
.mision-tag { font-family: var(--mono); font-size: 11px; padding: 4px 8px; border: 1px solid var(--magenta); color: var(--magenta); border-radius: 4px; white-space: nowrap; }
.mision-txt { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metricas { display: flex; align-items: center; gap: 14px; font-family: var(--mono); font-size: 11px; color: var(--tenue); flex-wrap: wrap; }
.metricas b { color: var(--texto); font-weight: 500; }
.btn-chico { font-family: var(--mono); font-size: 11px; padding: 7px 10px; min-height: 32px; border-radius: 6px; border: 1px solid rgba(0,243,255,.35); background: transparent; color: var(--cian); }
.btn-chico:hover { background: rgba(0,243,255,.08); }
.btn-chico[aria-pressed="false"] { color: var(--tenue); border-color: rgba(130,145,168,.4); }

/* Disposición */
.main { flex: 1; display: flex; min-height: 0; }
.escenario { position: relative; flex: 1 1 auto; aspect-ratio: 860 / 734; max-height: calc(100dvh - 60px); align-self: center; width: min(100%, calc((100dvh - 60px) * 860 / 734)); overflow: hidden; }
.panel { flex: 0 0 420px; display: flex; flex-direction: column; border-left: 1px solid var(--linea); background: rgba(6,9,19,.6); max-height: calc(100dvh - 60px); }

/* Haces de luz */
.haces { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; filter: drop-shadow(0 0 5px rgba(0,243,255,.8)); }
.haz { stroke: var(--cian); stroke-opacity: .22; stroke-width: 2; transition: stroke .3s, stroke-opacity .3s, stroke-width .3s; }
.haz.activo { stroke-opacity: 1; stroke-width: 4; }
.haz.trabajando, .haz.corrigiendo { stroke: var(--verde); }
.haz.hablando { stroke: var(--magenta); }
.pulso { stroke: #fff; stroke-width: 2; stroke-dasharray: 4 16; animation: fluir 1.2s linear infinite; opacity: 0; transition: opacity .3s; }
.pulso.activo { opacity: 1; }
.haz-directo { stroke: var(--magenta); stroke-width: 2; stroke-dasharray: 4 14; animation: fluir 1s linear infinite; }
@keyframes fluir { to { stroke-dashoffset: -60; } }

/* Estados del Director */
.estados { position: absolute; left: 3%; top: 3%; display: flex; flex-direction: column; gap: 8px; z-index: 2; }
.estados-titulo { font-family: var(--mono); font-size: 11px; letter-spacing: 2px; color: var(--tenue); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-family: var(--mono); font-size: 10px; padding: 4px 7px; border-radius: 4px; border: 1px solid rgba(130,145,168,.45); color: var(--tenue); transition: all .25s; }
.chip.activo { color: var(--fondo); background: var(--cian); border-color: var(--cian); box-shadow: 0 0 12px rgba(0,243,255,.7); }

/* Núcleo */
.nucleo { position: absolute; left: 50%; top: 49%; width: 34%; aspect-ratio: 1; transform: translate(-50%, -50%); }
.nucleo canvas { width: 100%; height: 100%; display: block; }
.nucleo-nombre { position: absolute; left: 0; right: 0; bottom: -4%; text-align: center; font-family: var(--titulo); font-weight: 600; font-size: clamp(13px, 1.6vw, 18px); text-shadow: 0 0 10px rgba(0,243,255,.8); }

/* Agentes */
.pod { position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -50%); width: clamp(54px, 14%, 124px); display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 0; border: none; background: none; z-index: 2; animation: flotar 4s ease-in-out infinite; }
.pod:nth-of-type(2n) { animation-delay: -1.3s; }
.pod:nth-of-type(3n) { animation-delay: -2.6s; }
@keyframes flotar { 0%,100% { translate: 0 0; } 50% { translate: 0 -6px; } }
.emblema { width: 100%; aspect-ratio: 1; border-radius: 14px; background: var(--vidrio); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid rgba(130,145,168,.45); display: flex; align-items: center; justify-content: center; transition: border-color .3s, box-shadow .3s, background .3s; }
.emblema svg { width: 78%; height: 78%; }
.pod-codigo { font-family: var(--mono); font-size: 10px; color: var(--tenue); white-space: nowrap; }
.pod-codigo b { font-weight: 400; }
.pod-nombre { font-family: var(--titulo); font-size: clamp(10px, 1.1vw, 13px); font-weight: 600; }
.pod.trabajando .emblema, .pod.corrigiendo .emblema { border-color: var(--verde); box-shadow: 0 0 22px rgba(0,255,157,.4); }
.pod.trabajando .pod-codigo, .pod.corrigiendo .pod-codigo { color: var(--verde); }
.pod.hablando .emblema, .pod.emite .emblema { border-color: var(--magenta); box-shadow: 0 0 26px rgba(255,0,127,.55); background: rgba(40,8,20,.75); }
.pod.hablando .pod-codigo { color: var(--magenta); }
.pod.listo .emblema { border-color: rgba(0,243,255,.6); box-shadow: 0 0 14px rgba(0,243,255,.25); }
.pod.listo .pod-codigo { color: var(--cian); }
.pod:focus-visible .emblema { outline: 2px solid var(--cian); outline-offset: 3px; }

/* Progreso */
.progreso { position: absolute; left: 3%; bottom: 3%; width: 38%; display: flex; flex-direction: column; gap: 8px; }
.progreso-titulo, .progreso-txt { font-family: var(--mono); font-size: 11px; color: var(--tenue); letter-spacing: 1px; }
.barras { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.barras i { height: 6px; background: rgba(130,145,168,.3); transition: background .3s, box-shadow .3s; }
.barras i.hecho { background: var(--verde); box-shadow: 0 0 8px var(--verde); }
.barras i.actual { background: var(--magenta); box-shadow: 0 0 8px var(--magenta); }

/* Panel de transmisiones */
.panel-cab { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--linea); font-family: var(--titulo); font-size: 13px; letter-spacing: 3px; }
.en-vivo { font-family: var(--mono); font-size: 11px; letter-spacing: 0; color: var(--verde); }
.feed { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.tx { padding: 10px 14px; border-radius: 12px; background: var(--vidrio); border: 1px solid rgba(0,243,255,.22); animation: entrar .35s ease-out; }
@keyframes entrar { from { opacity: 0; transform: translateY(6px); } }
.tx-cab { font-family: var(--mono); font-size: 10px; color: var(--tenue); margin-bottom: 3px; }
.tx-txt { color: var(--texto-2); line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; }
.tx.vos { border-color: rgba(130,145,168,.4); background: rgba(30,41,59,.55); }
.tx.director { background: rgba(0,243,255,.08); border-color: rgba(0,243,255,.5); }
.tx.director .tx-cab { color: var(--cian); }
.tx.alerta { background: rgba(255,0,127,.1); border-color: var(--magenta); box-shadow: 0 0 16px rgba(255,0,127,.2); }
.tx.alerta .tx-cab { color: var(--magenta); }
.tx.alerta .tx-txt { color: var(--texto); }
.tx.ok .tx-cab { color: var(--verde); }
.tx.error { border-color: #ff6b6b; }
.tx img { width: 100%; border-radius: 8px; margin-top: 6px; display: block; }
.tx-voz { display: flex; align-items: center; gap: 10px; margin: 6px 0 4px; }
.btn-play { width: 30px; height: 30px; border-radius: 50%; border: none; background: var(--cian); display: grid; place-items: center; box-shadow: 0 0 10px rgba(0,243,255,.7); flex: none; }
.onda { display: flex; align-items: center; gap: 3px; height: 26px; }
.onda i { width: 4px; border-radius: 2px; background: var(--cian); height: 30%; }
.onda.sonando i { animation: eq .9s ease-in-out infinite; }
.onda i:nth-child(2n) { animation-delay: .15s; } .onda i:nth-child(3n) { animation-delay: .3s; } .onda i:nth-child(5n) { animation-delay: .45s; }
@keyframes eq { 0%,100% { height: 25%; } 50% { height: 100%; } }
.escribiendo { font-family: var(--mono); font-size: 12px; color: var(--tenue); }
.escribiendo::after { content: '_'; animation: titilar 1s steps(2) infinite; }
@keyframes titilar { 50% { opacity: 0; } }

.btn-informe { margin: 0 16px 10px; min-height: 44px; border-radius: 10px; border: 1px solid var(--verde); background: rgba(0,255,157,.1); color: var(--verde); font-family: var(--titulo); font-size: 12px; letter-spacing: 2px; box-shadow: 0 0 16px rgba(0,255,157,.25); }

.redactar { display: flex; gap: 8px; align-items: flex-end; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--linea); }
.redactar textarea { flex: 1; min-height: 46px; max-height: 160px; resize: none; padding: 12px 14px; border-radius: 10px; border: 1px solid rgba(0,243,255,.35); background: var(--vidrio); color: var(--texto); font-family: var(--cuerpo); font-size: 16px; line-height: 1.3; }
.redactar textarea:focus { outline: none; border-color: var(--cian); box-shadow: 0 0 0 1px var(--cian); }
.btn-mic, .btn-enviar { width: 46px; height: 46px; flex: none; border-radius: 50%; border: none; display: grid; place-items: center; }
.btn-mic { background: var(--cian); color: var(--fondo); box-shadow: 0 0 16px rgba(0,243,255,.75); }
.btn-mic.escuchando { background: var(--magenta); color: #fff; box-shadow: 0 0 22px rgba(255,0,127,.9); animation: latir 1s ease-in-out infinite; }
@keyframes latir { 50% { transform: scale(1.08); } }
.btn-enviar { background: transparent; border: 1px solid rgba(0,243,255,.5); color: var(--cian); }
.btn-enviar:disabled, .btn-mic:disabled { opacity: .4; cursor: not-allowed; }

/* Capas (login, informe, historial) */
.capa { position: fixed; inset: 0; background: rgba(3,5,12,.82); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 16px; z-index: 20; }
.tarjeta { background: #0b1120; border: 1px solid rgba(0,243,255,.35); border-radius: 16px; box-shadow: 0 0 40px rgba(0,243,255,.15); }
.login { padding: 40px 32px; text-align: center; max-width: 380px; width: 100%; }
.login p { color: var(--texto-2); font-size: 18px; }
.nota { color: #ff8fa3; font-size: 15px; min-height: 1em; }
.btn-principal { margin-top: 12px; min-height: 48px; padding: 0 24px; border-radius: 10px; border: none; background: var(--cian); color: var(--fondo); font-family: var(--titulo); font-weight: 600; box-shadow: 0 0 18px rgba(0,243,255,.6); }
.informe, .historial { width: min(920px, 100%); max-height: 92dvh; display: flex; flex-direction: column; }
.informe-cab { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--linea); font-family: var(--titulo); font-size: 13px; letter-spacing: 2px; flex-wrap: wrap; }
.informe-acciones { display: flex; gap: 8px; flex-wrap: wrap; }
.informe-cuerpo, .lista { overflow-y: auto; padding: 18px 22px; }
.md { color: var(--texto-2); font-size: 17px; line-height: 1.55; }
.md h1, .md h2, .md h3 { font-family: var(--titulo); color: var(--texto); font-weight: 600; letter-spacing: 1px; }
.md h1 { font-size: 22px; } .md h2 { font-size: 18px; } .md h3 { font-size: 15px; }
.md a { color: var(--cian); }
.md code { font-family: var(--mono); font-size: 13px; background: rgba(0,243,255,.08); padding: 1px 5px; border-radius: 4px; }
.md pre { position: relative; background: #050811; border: 1px solid var(--linea); border-radius: 10px; padding: 14px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--linea); padding: 6px 10px; text-align: left; }
.btn-copiar-codigo { position: absolute; top: 8px; right: 8px; }
.imagenes { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin: 18px 0; }
.imagenes figure { margin: 0; background: var(--vidrio); border: 1px solid var(--linea); border-radius: 12px; overflow: hidden; }
.imagenes img { width: 100%; display: block; }
.imagenes figcaption { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; font-family: var(--mono); font-size: 12px; color: var(--texto-2); }
.imagenes a { color: var(--cian); }
.aportes details { border: 1px solid var(--linea); border-radius: 10px; margin-top: 10px; background: rgba(15,23,42,.4); }
.aportes summary { padding: 10px 14px; font-family: var(--titulo); font-size: 12px; letter-spacing: 1px; cursor: pointer; }
.aportes .md { padding: 0 14px 12px; font-size: 16px; }
.lista button { display: block; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 8px; border-radius: 10px; border: 1px solid var(--linea); background: var(--vidrio); }
.lista button:hover { border-color: var(--cian); }
.lista small { display: block; font-family: var(--mono); font-size: 11px; color: var(--tenue); margin-top: 4px; }

/* Celular */
@media (max-width: 900px) {
  .main { flex-direction: column; }
  .escenario { width: 100%; max-height: none; }
  .panel { flex: 1 1 auto; border-left: none; border-top: 1px solid var(--linea); max-height: none; min-height: 50dvh; }
  .top { gap: 10px; padding: 10px 14px; }
  .mision { order: 3; flex-basis: 100%; }
  .estados { display: none; }
  .pod-codigo { font-size: 8px; }
  .progreso { width: 46%; }
  .progreso-txt { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Versión 2: destinatario, adjuntos, memoria */
.para { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 16px 8px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--verde); background: rgba(0,255,157,.08); font-family: var(--mono); font-size: 11px; color: var(--verde); }
.para b { font-weight: 500; }
.adjuntos { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px; }
.adjuntos:not(:empty) { padding-bottom: 8px; }
.adjunto { display: flex; align-items: center; gap: 8px; max-width: 100%; padding: 4px 6px 4px 4px; border-radius: 10px; border: 1px solid rgba(0,243,255,.35); background: var(--vidrio); font-family: var(--mono); font-size: 11px; color: var(--texto-2); }
.adjunto img, .adjunto .icono { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; flex: none; display: grid; place-items: center; background: rgba(0,243,255,.1); color: var(--cian); }
.adjunto span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.adjunto small { display: block; color: var(--tenue); font-size: 10px; }
.adjunto button { border: none; background: none; color: var(--tenue); font-size: 16px; min-width: 28px; min-height: 28px; }
.adjunto.cargando { opacity: .6; }
.btn-clip { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 1px solid rgba(0,243,255,.5); background: transparent; color: var(--cian); display: grid; place-items: center; }
.tx-adjuntos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tx-adjuntos span { font-family: var(--mono); font-size: 10px; padding: 3px 6px; border-radius: 4px; background: rgba(0,243,255,.1); color: var(--cian); }
.tx-adjuntos img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; margin: 0; }
.tx.agente-directo { border-color: rgba(0,255,157,.5); background: rgba(0,255,157,.06); }
.tx.agente-directo .tx-cab { color: var(--verde); }
.pod { cursor: pointer; }
.pod.elegido .emblema { outline: 2px solid var(--verde); outline-offset: 4px; }
.etiqueta { font-family: var(--titulo); font-size: 12px; letter-spacing: 2px; color: var(--texto); margin: 8px 0 4px; display: block; }
.ayuda { color: var(--tenue); font-size: 15px; margin: 0 0 10px; }
.memoria-datos { width: 100%; resize: vertical; padding: 12px; border-radius: 10px; border: 1px solid rgba(0,243,255,.35); background: var(--vidrio); color: var(--texto); font-family: var(--cuerpo); font-size: 16px; margin-bottom: 18px; }
.aprendizaje { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border: 1px solid var(--linea); border-radius: 8px; margin-bottom: 6px; color: var(--texto-2); }
.aprendizaje b { font-family: var(--mono); font-size: 10px; font-weight: 400; color: var(--cian); white-space: nowrap; padding-top: 3px; }
.aprendizaje span { flex: 1; }
.aprendizaje button { border: none; background: none; color: var(--tenue); font-size: 16px; min-width: 28px; }
.btn-chico.marcado { background: rgba(0,255,157,.15); border-color: var(--verde); color: var(--verde); }
@media (max-width: 900px) { .adjunto span { max-width: 110px; } }
