/* ===================== JARVIS — pantalla completa =====================
   Página standalone (pensada para abrir en una pestaña aparte, o en un monitor/TV
   segundo) con un visualizador circular animado. No depende de index.html --
   lee la config guardada (emi1719_ai_backend_url, emi1719_ai_app_secret,
   emi1719_python_ejecutor_url) directo de localStorage, que ya está compartido
   porque vive en el mismo dominio. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #05070a;
  overflow: hidden;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
}

#jpFondo {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #0a1420 0%, #05070a 70%);
}

#jpVisualizador {
  position: relative;
  width: min(60vmin, 420px);
  height: min(60vmin, 420px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.jp-anillo {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid rgba(91, 157, 255, 0.25);
  animation: jp-girar 40s linear infinite;
}

.jp-anillo::before {
  content: '';
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  border: 1px dashed rgba(91, 157, 255, 0.15);
}

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

#jpSpikes {
  position: absolute;
  width: 100%;
  height: 100%;
}

#jpSpikes .jp-spike {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 14px;
  background: #5b9dff;
  border-radius: 2px;
  transform-origin: center 0;
  opacity: 0.55;
  transition: height 0.12s ease, background 0.3s ease;
}

#jpNucleo {
  position: relative;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #5b9dff, #1c4587 70%);
  box-shadow: 0 0 40px 6px rgba(91, 157, 255, 0.35);
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}

/* --- estados --- */
#jpFondo.jp-escuchando #jpNucleo {
  background: radial-gradient(circle at 35% 30%, #ff5b6a, #7a1620 70%);
  box-shadow: 0 0 50px 10px rgba(255, 91, 106, 0.45);
  animation: jp-pulso-suave 1s ease-in-out infinite;
}
#jpFondo.jp-escuchando #jpSpikes .jp-spike { background: #ff5b6a; }

#jpFondo.jp-pensando #jpNucleo {
  background: radial-gradient(circle at 35% 30%, #d9a441, #7a4706 70%);
  box-shadow: 0 0 45px 8px rgba(217, 164, 65, 0.4);
}
#jpFondo.jp-pensando .jp-anillo { animation-duration: 3s; }
#jpFondo.jp-pensando #jpSpikes .jp-spike { background: #d9a441; }

#jpFondo.jp-hablando #jpNucleo {
  background: radial-gradient(circle at 35% 30%, #3ecf8e, #076239 70%);
  box-shadow: 0 0 55px 10px rgba(62, 207, 142, 0.45);
  animation: jp-pulso-fuerte 0.5s ease-in-out infinite;
}
#jpFondo.jp-hablando #jpSpikes .jp-spike { background: #3ecf8e; }

@keyframes jp-pulso-suave {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes jp-pulso-fuerte {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

#jpTexto {
  margin-top: 44px;
  max-width: 80vw;
  min-height: 3em;
  text-align: center;
  color: #e6e9ee;
  font-size: clamp(1rem, 2.4vw, 1.5rem);
  line-height: 1.5;
}

#jpEstado {
  margin-top: 14px;
  letter-spacing: 0.18em;
  font-size: 0.8rem;
  color: #5b9dff;
  text-transform: uppercase;
}
#jpFondo.jp-escuchando #jpEstado { color: #ff5b6a; }
#jpFondo.jp-pensando #jpEstado { color: #d9a441; }
#jpFondo.jp-hablando #jpEstado { color: #3ecf8e; }

#jpMicBtn {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: #1c4587;
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(91, 157, 255, 0.4);
}
#jpMicBtn:hover { background: #2a5cad; }

#jpCerrarBtn {
  position: absolute;
  top: 20px;
  right: 24px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: #e6e9ee;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
}
#jpCerrarBtn:hover { border-color: #ff5b6a; color: #ff5b6a; }

/* ===================== Toolbar (chat / estudio / config / accesos rápidos) ===================== */

#jpToolbar {
  position: absolute;
  top: 20px;
  left: 24px;
  right: 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  z-index: 20;
  max-width: calc(100vw - 48px);
}

.jp-tool-btn {
  background: rgba(10, 20, 32, 0.7);
  border: 1px solid rgba(91, 157, 255, 0.35);
  color: #e6e9ee;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.jp-tool-btn:hover {
  border-color: #5b9dff;
  box-shadow: 0 0 12px rgba(91, 157, 255, 0.35);
}

.jp-toolbar-separador {
  width: 1px;
  height: 22px;
  background: rgba(91, 157, 255, 0.25);
  margin: 0 2px;
}

/* ===================== Panel de chat ===================== */

#jpChatPanel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(360px, 90vw);
  height: 100vh;
  background: rgba(5, 9, 14, 0.92);
  border-left: 1px solid rgba(91, 157, 255, 0.35);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  z-index: 30;
  font-family: inherit;
  color: #e6e9ee;
}

#jpChatHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(91, 157, 255, 0.2);
  letter-spacing: 0.08em;
  color: #5b9dff;
  font-size: 0.85rem;
  text-transform: uppercase;
}

#jpChatLog {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.9rem;
}

.jp-msg {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 10px;
  line-height: 1.4;
  word-break: break-word;
}
.jp-msg-usuario {
  align-self: flex-end;
  background: rgba(91, 157, 255, 0.18);
  border: 1px solid rgba(91, 157, 255, 0.35);
}
.jp-msg-jarvis {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.jp-msg-sistema {
  align-self: center;
  background: transparent;
  color: rgba(230, 233, 238, 0.55);
  font-size: 0.78rem;
  font-style: italic;
}

#jpChatInputRow {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid rgba(91, 157, 255, 0.2);
}
#jpChatInput {
  flex: 1;
  background: #0a1420;
  border: 1px solid rgba(91, 157, 255, 0.3);
  border-radius: 8px;
  color: #e6e9ee;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.85rem;
}
#jpChatInput:focus { outline: none; border-color: #5b9dff; }
#jpChatSendBtn {
  background: #1c4587;
  border: none;
  color: #fff;
  width: 38px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
}
#jpChatSendBtn:hover { background: #2a5cad; }

/* ===================== Modal genérico (estudio de voz / configuración) ===================== */

.jp-modal-fondo {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}

.jp-modal-caja {
  background: #0a1420;
  border: 1px solid rgba(91, 157, 255, 0.4);
  border-radius: 14px;
  padding: 20px;
  max-width: 420px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  color: #e6e9ee;
  font-family: inherit;
}

.jp-modal-titulo {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  color: #5b9dff;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.jp-modal-cerrar {
  background: none;
  border: none;
  color: #e6e9ee;
  font-size: 18px;
  cursor: pointer;
}

.jp-modal-seccion { margin-bottom: 18px; }
.jp-modal-etiqueta { font-weight: 600; margin-bottom: 6px; font-size: 0.85rem; }

.jp-modal-input, .jp-modal-file {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(91, 157, 255, 0.3);
  background: #05070a;
  color: #e6e9ee;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 0.85rem;
}
.jp-modal-input:focus { outline: none; border-color: #5b9dff; }

.jp-modal-boton {
  margin-top: 6px;
  background: #5b9dff;
  color: #05070a;
  border: none;
  padding: 7px 14px;
  border-radius: 16px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}
.jp-modal-boton:hover { filter: brightness(1.1); }

.jp-modal-resultado {
  margin-top: 8px;
  font-size: 0.78rem;
  color: rgba(230, 233, 238, 0.7);
  white-space: pre-wrap;
}

/* ===================== Constelación decorativa (nodos de apps + partículas) =====================
   Puramente visual: llena el espacio vacío alrededor de la esfera con nodos que
   representan apps conectables (Gmail, Calendar, Fotos, GitHub, Notion, Slack) y
   partículas ambiente. Los nodos ya CONECTADOS via Composio brillan más fuerte
   (clase .jp-activo, la pone jarvis-pantalla.js al cargar). pointer-events: none
   para que nunca interfiera con toolbar/mic/texto. */

#jpConstelacion {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.jp-nodo {
  position: absolute;
  width: 42px;
  height: 42px;
  margin: -21px 0 0 -21px;
  border-radius: 50%;
  background: rgba(13, 30, 13, 0.85);
  border: 1.5px solid rgba(0, 255, 102, 0.55);
  box-shadow: 0 0 12px rgba(0, 255, 102, 0.3), inset 0 0 10px rgba(0, 255, 102, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #8fd88f;
  animation-name: jp-flotar;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  transition: border-color 0.6s ease, box-shadow 0.6s ease, color 0.6s ease, background 0.6s ease;
}

.jp-nodo.jp-activo {
  border-color: #00ff66;
  color: #eaffea;
  background: rgba(15, 60, 25, 0.9);
  box-shadow: 0 0 24px rgba(0, 255, 102, 0.75), inset 0 0 12px rgba(180, 255, 200, 0.3);
}

@keyframes jp-flotar {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(5px, -9px); }
}

.jp-particula {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #4dff9e;
  box-shadow: 0 0 6px 1px rgba(0, 255, 102, 0.65);
  opacity: 0.45;
  animation-name: jp-parpadear;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}

@keyframes jp-parpadear {
  0%, 100% { opacity: 0.3; transform: translate(0, 0); }
  50% { opacity: 0.85; transform: translate(4px, -6px); }
}

@media (max-width: 640px) {
  .jp-nodo { width: 30px; height: 30px; margin: -15px 0 0 -15px; font-size: 0.52rem; }
}

/* ===================== HUD extra: anillo de marcas radar, barrido, medidores =====================
   Puramente visual, estilo "Jarvis / Iron Man": un anillo con marcas tipo radar
   girando lento alrededor de la esfera, un barrido de luz que la recorre, y unos
   medidores circulares (como gauges) repartidos por la pantalla. Todo con
   CSS puro (conic-gradient), sin imagenes ni SVG, en el mismo verde del resto. */

#jpAnilloTicks {
  position: absolute;
  width: 120%;
  height: 120%;
  top: -10%;
  left: -10%;
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(0, 255, 102, 0.5) 0deg 1.2deg, transparent 1.2deg 9deg);
  -webkit-mask: radial-gradient(circle, transparent 61%, black 62%, black 64%, transparent 65%);
  mask: radial-gradient(circle, transparent 61%, black 62%, black 64%, transparent 65%);
  animation: jp-girar 90s linear infinite reverse;
  opacity: 0.85;
  pointer-events: none;
}

#jpBarrido {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(0, 255, 102, 0.35), transparent 35deg, transparent 360deg);
  animation: jp-girar 5s linear infinite;
  mix-blend-mode: screen;
  pointer-events: none;
}

.jp-gauge {
  position: absolute;
  width: 60px;
  height: 60px;
  margin: -30px 0 0 -30px;
  border-radius: 50%;
  background: conic-gradient(#00ff66 var(--valor, 60%), rgba(0, 255, 102, 0.12) 0);
  -webkit-mask: radial-gradient(circle, transparent 62%, black 63%);
  mask: radial-gradient(circle, transparent 62%, black 63%);
  opacity: 0.7;
  animation: jp-gauge-pulsar 6s ease-in-out infinite;
}

@keyframes jp-gauge-pulsar {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.9; }
}

@media (max-width: 640px) {
  .jp-gauge { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
}

@media (prefers-reduced-motion: reduce) {
  .jp-nodo, .jp-particula, #jpAnilloTicks, #jpBarrido, .jp-gauge { animation: none !important; }
}
