/* Jarvis Panel — estilos */

:root {
  --cyan: #3ddbff;
  --cyan-soft: rgba(61, 219, 255, 0.55);
  --cyan-faint: rgba(61, 219, 255, 0.16);
  --cyan-line: rgba(61, 219, 255, 0.28);
  --white: #eafcff;
  --text: #cfe9f0;
  --muted: #6f97a3;
  --bg: #03070b;
  --panel: rgba(8, 26, 36, 0.42);
  --danger: #ff5d6c;
  --ok: #4dffb5;
  --warn: #ffc65c;
  --glow: 0 0 6px rgba(61, 219, 255, 0.8), 0 0 18px rgba(61, 219, 255, 0.35);
  --font-hud: 'Rajdhani', 'Orbitron', system-ui, sans-serif;
  --font-title: 'Orbitron', 'Rajdhani', system-ui, sans-serif;
  --font-text: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --level: 0;
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font-text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Fondo ---------- */
.bg-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(61, 219, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(61, 219, 255, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(61, 219, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(61, 219, 255, 0.025) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  background-position: center;
}
.bg-vignette {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at center, rgba(61, 219, 255, 0.07) 0%, transparent 45%),
    radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.85) 100%);
}

.hud-label {
  font-family: var(--font-hud);
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--cyan-soft);
  margin: 0;
}

/* ---------- Estructura ---------- */
.shell {
  position: relative; z-index: 1;
  height: 100dvh;
  /* Flex en columna: los elementos ocultos (pestañas, aviso) no descolocan al resto. */
  display: flex;
  flex-direction: column;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  gap: 12px;
}
.shell > .layout { flex: 1; }
.shell > .notice { align-self: center; }
.shell > .composer { align-self: center; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--cyan-line);
  padding-bottom: 10px;
}
.topbar-side { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-right { justify-content: flex-end; gap: 14px; }

.brand { text-align: center; }
.brand h1 {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: clamp(1.1rem, 2.4vw, 1.7rem);
  letter-spacing: 0.55em;
  padding-left: 0.55em; /* compensa el espaciado final */
  color: var(--white);
  text-shadow: var(--glow);
}
.brand-sub {
  margin: 2px 0 0;
  font-family: var(--font-hud);
  font-size: 0.68rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--muted);
}

.clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.clock-time {
  font-family: var(--font-title);
  font-size: 1.15rem;
  color: var(--cyan);
  text-shadow: var(--glow);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}
.clock-date {
  font-family: var(--font-hud);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--cyan-line);
  background: rgba(61, 219, 255, 0.05);
  border-radius: 50%;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.icon-btn:hover { background: var(--cyan-faint); border-color: var(--cyan-soft); box-shadow: var(--glow); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: var(--cyan); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .ico-speaker { fill: var(--cyan-faint); }
.icon-btn .ico-mute { display: none; }
.icon-btn[aria-pressed='true'] .ico-waves { display: none; }
.icon-btn[aria-pressed='true'] .ico-mute { display: inline; stroke: var(--danger); }
.icon-btn[aria-pressed='true'] { border-color: rgba(255, 93, 108, 0.5); }

.hermes-dot {
  width: 9px; height: 9px; border-radius: 50%;
  display: inline-block; flex: none;
  background: var(--muted);
}
.hermes-dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.hermes-dot.down { background: var(--danger); box-shadow: 0 0 8px var(--danger); animation: blink 1.2s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

/* ---------- Pestañas (solo móvil) ---------- */
.tabs { display: none; }

/* ---------- Layout principal ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(230px, 280px) 1fr minmax(300px, 400px);
  gap: 18px;
  min-height: 0;
}

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--cyan-line);
  border-radius: 4px;
  padding: 16px 18px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: inset 0 0 30px rgba(61, 219, 255, 0.04);
  min-height: 0;
}
/* Esquinas tipo HUD */
.panel::before,
.panel::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  border: 2px solid var(--cyan);
  pointer-events: none;
  filter: drop-shadow(0 0 4px rgba(61, 219, 255, 0.7));
}
.panel::before { top: -2px; left: -2px; border-right: 0; border-bottom: 0; }
.panel::after { bottom: -2px; right: -2px; border-left: 0; border-top: 0; }

.panel-title {
  margin: 0 0 14px;
  font-family: var(--font-hud);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--cyan);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }

.panel-status { display: flex; flex-direction: column; overflow-y: auto; }
.stats { margin: 0; display: grid; gap: 2px; }
.stat {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  padding: 9px 0;
  border-bottom: 1px dashed rgba(61, 219, 255, 0.14);
}
.stat dt {
  font-family: var(--font-hud); font-size: 0.75rem; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--muted);
}
.stat dd {
  margin: 0; display: flex; align-items: center; gap: 8px; justify-content: flex-end;
  font-family: var(--font-hud); font-weight: 600; font-size: 0.98rem; color: var(--white);
  text-align: right;
}
.stat-detail dd { font-family: var(--font-text); font-weight: 400; font-size: 0.8rem; color: var(--text); }
.stat dd.is-ok { color: var(--ok); }
.stat dd.is-down { color: var(--danger); }
.stat dd.is-warn { color: var(--warn); }

.hud-bars { display: flex; gap: 5px; align-items: flex-end; height: 34px; margin: 22px 0 10px; }
.hud-bars span {
  flex: 1; background: linear-gradient(to top, var(--cyan-soft), transparent);
  opacity: 0.55; height: 30%;
  animation: bars 2.6s ease-in-out infinite;
}
.hud-bars span:nth-child(2n) { animation-delay: -0.6s; }
.hud-bars span:nth-child(3n) { animation-delay: -1.3s; }
.hud-bars span:nth-child(5n) { animation-delay: -1.9s; }
@keyframes bars { 50% { height: 95%; opacity: 0.9; } }
.panel-foot { margin-top: auto; font-size: 0.65rem; color: var(--muted); }

/* ---------- Núcleo / reactor ---------- */
.core {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 0; gap: 10px;
}
.reactor-wrap {
  width: min(100%, 62vh, 520px);
  aspect-ratio: 1;
  position: relative;
}
.reactor { width: 100%; height: 100%; overflow: visible; display: block; }
/* El viewBox está centrado en (0,0): ahí deben girar y escalar todos los anillos. */
.reactor g { transform-box: view-box; transform-origin: 0 0; }

.reactor .r-stroke { fill: none; stroke: var(--cyan); }
.reactor .r-dim { stroke-opacity: 0.35; }
.reactor .r-tick { stroke: var(--cyan); stroke-width: 1.4; stroke-opacity: 0.6; }
.reactor .r-tick.major { stroke-width: 2.4; stroke-opacity: 1; }
.reactor .r-fill { fill: var(--cyan); }
.reactor .r-white { stroke: var(--white); }
.reactor .r-glow { filter: drop-shadow(0 0 4px rgba(61, 219, 255, 0.9)) drop-shadow(0 0 14px rgba(61, 219, 255, 0.4)); }
.reactor .r-halo { fill: url(#coreHalo); opacity: calc(0.45 + var(--level) * 0.55); }
.reactor .r-core { fill: url(#coreGrad); }
.reactor .r-label { fill: var(--cyan); font-family: var(--font-hud); font-size: 9px; letter-spacing: 3px; opacity: 0.7; }

body.state-listening .reactor .r-stroke,
body.state-listening .reactor .r-tick { stroke: #8ff0ff; }
body.state-listening .reactor { filter: drop-shadow(0 0 18px rgba(61, 219, 255, 0.55)); }
body.state-thinking .reactor { filter: drop-shadow(0 0 10px rgba(61, 219, 255, 0.35)); }
body.state-speaking .reactor { filter: drop-shadow(0 0 calc(8px + var(--level) * 26px) rgba(61, 219, 255, 0.6)); }
body.state-error .reactor .r-stroke,
body.state-error .reactor .r-tick { stroke: var(--danger); }

.core-state { min-height: 1.2em; color: var(--cyan); text-shadow: var(--glow); }
body.state-error .core-state { color: var(--danger); text-shadow: 0 0 8px rgba(255, 93, 108, 0.6); }
.caption {
  margin: 0;
  max-width: 640px;
  min-height: 3em;
  max-height: 7.5em;
  overflow: hidden;
  text-align: center;
  color: var(--white);
  font-size: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  opacity: 0.9;
}
.caption.interim { color: var(--cyan); font-style: italic; }

/* ---------- Chat ---------- */
.panel-chat { display: flex; flex-direction: column; }
.messages {
  list-style: none; margin: 0; padding: 0 4px 0 0;
  flex: 1; overflow-y: auto; min-height: 0;
  display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: thin; scrollbar-color: var(--cyan-line) transparent;
}
.msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 3px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
  position: relative;
}
.msg-meta {
  display: block; margin-bottom: 3px;
  font-family: var(--font-hud); font-size: 0.68rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted);
}
.msg.user {
  align-self: flex-end;
  background: rgba(234, 252, 255, 0.07);
  border: 1px solid rgba(234, 252, 255, 0.18);
  color: var(--white);
}
.msg.assistant {
  align-self: flex-start;
  background: rgba(61, 219, 255, 0.07);
  border: 1px solid var(--cyan-line);
  border-left: 2px solid var(--cyan);
}
.msg.error {
  align-self: stretch; max-width: none;
  background: rgba(255, 93, 108, 0.08);
  border: 1px solid rgba(255, 93, 108, 0.45);
  border-left: 3px solid var(--danger);
  color: #ffd2d7;
}
.msg.error .msg-meta { color: var(--danger); }
.msg.streaming .msg-body::after {
  content: '▍'; color: var(--cyan); margin-left: 1px;
  animation: blink 0.9s steps(2) infinite;
}
.empty {
  margin: auto; text-align: center; color: var(--muted);
  font-family: var(--font-hud); letter-spacing: 0.15em; text-transform: uppercase; font-size: 0.8rem;
}

.text-btn {
  background: none; border: 1px solid var(--cyan-line); border-radius: 2px;
  padding: 4px 10px;
  font-family: var(--font-hud); font-weight: 600; font-size: 0.72rem; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--cyan);
  transition: background 0.2s, box-shadow 0.2s;
}
.text-btn:hover { background: var(--cyan-faint); box-shadow: var(--glow); }

/* ---------- Avisos ---------- */
.notice {
  justify-self: center;
  max-width: 720px;
  padding: 8px 16px;
  border: 1px solid rgba(255, 198, 92, 0.5);
  background: rgba(255, 198, 92, 0.08);
  color: #ffe3ad;
  font-size: 0.85rem;
  border-radius: 3px;
  text-align: center;
}
.notice.error { border-color: rgba(255, 93, 108, 0.55); background: rgba(255, 93, 108, 0.1); color: #ffd2d7; }

/* ---------- Barra inferior ---------- */
.composer {
  display: flex; align-items: center; gap: 14px;
  max-width: 980px; width: 100%; justify-self: center;
}
#composer {
  flex: 1; display: flex; align-items: flex-end; gap: 8px;
  background: rgba(8, 26, 36, 0.6);
  border: 1px solid var(--cyan-line);
  border-radius: 28px;
  padding: 6px 6px 6px 20px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#composer:focus-within { border-color: var(--cyan-soft); box-shadow: 0 0 0 1px var(--cyan-faint), 0 0 20px rgba(61, 219, 255, 0.15); }
#input {
  flex: 1; resize: none; border: 0; background: transparent; outline: none;
  max-height: 140px; padding: 10px 0; line-height: 1.4;
  color: var(--white);
}
#input::placeholder { color: var(--muted); }

.send-btn {
  width: 44px; height: 44px; flex: none;
  border-radius: 50%; border: 0;
  background: var(--cyan);
  display: grid; place-items: center;
  box-shadow: var(--glow);
  transition: transform 0.15s, opacity 0.2s;
}
.send-btn:hover { transform: scale(1.06); }
.send-btn:disabled { opacity: 0.35; cursor: default; transform: none; box-shadow: none; }
.send-btn svg { width: 20px; height: 20px; fill: var(--bg); }
.send-btn .ico-stop { display: none; }
.send-btn.is-stop { background: var(--white); }
.send-btn.is-stop .ico-send { display: none; }
.send-btn.is-stop .ico-stop { display: inline; }

.mic-btn {
  width: 72px; height: 72px; flex: none;
  border-radius: 50%;
  border: 2px solid var(--cyan);
  background: radial-gradient(circle, rgba(61, 219, 255, 0.22), rgba(61, 219, 255, 0.04) 70%);
  display: grid; place-items: center;
  box-shadow: var(--glow), inset 0 0 16px rgba(61, 219, 255, 0.25);
  transition: transform 0.15s, background 0.2s, box-shadow 0.2s;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.mic-btn:hover { transform: scale(1.05); }
.mic-btn svg { width: 30px; height: 30px; fill: none; stroke: var(--white); stroke-width: 1.8; stroke-linecap: round; }
.mic-btn svg rect { fill: rgba(234, 252, 255, 0.2); }
.mic-btn[aria-pressed='true'] {
  background: radial-gradient(circle, rgba(61, 219, 255, 0.65), rgba(61, 219, 255, 0.15) 70%);
  animation: micPulse 1.1s ease-in-out infinite;
}
.mic-btn:disabled { opacity: 0.3; cursor: not-allowed; animation: none; transform: none; box-shadow: none; }
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(61, 219, 255, 0.55), var(--glow); }
  50% { box-shadow: 0 0 0 14px rgba(61, 219, 255, 0), var(--glow); }
}

/* ---------- Login ---------- */
.login-page { overflow: auto; }
.login {
  position: relative; z-index: 1;
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px 16px;
}
.reactor-small { width: min(230px, 55vw); height: auto; aspect-ratio: 1; margin-bottom: 8px; }
.login-title {
  margin: 0;
  font-family: var(--font-title); font-weight: 700;
  font-size: 1.6rem; letter-spacing: 0.55em; padding-left: 0.55em;
  color: var(--white); text-shadow: var(--glow);
}
.login-form {
  margin-top: 18px;
  width: min(340px, 100%);
  display: flex; flex-direction: column; gap: 10px;
}
.login-form input {
  background: rgba(3, 7, 11, 0.6);
  border: 1px solid var(--cyan-line);
  border-radius: 3px;
  padding: 11px 12px;
  color: var(--white);
  outline: none;
  letter-spacing: 0.1em;
}
.login-form input:focus { border-color: var(--cyan); box-shadow: 0 0 12px rgba(61, 219, 255, 0.25); }
.primary-btn {
  margin-top: 4px;
  padding: 11px;
  border: 0; border-radius: 3px;
  background: var(--cyan); color: var(--bg);
  font-family: var(--font-hud); font-weight: 700; font-size: 0.95rem; letter-spacing: 0.3em; text-transform: uppercase;
  box-shadow: var(--glow);
}
.primary-btn:disabled { opacity: 0.5; cursor: progress; }
.login-error { margin: 4px 0 0; color: var(--danger); font-size: 0.85rem; }

/* ---------- Móvil: los paneles pasan a pestañas ---------- */
@media (max-width: 900px) {
  .shell { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); gap: 8px; }
  .topbar { grid-template-columns: auto 1fr auto; gap: 8px; }
  .brand { text-align: left; }
  .brand h1 { letter-spacing: 0.3em; padding-left: 0; font-size: 1rem; }
  .brand-sub, .topbar-side:first-child .hud-label { display: none; }
  .topbar-right { gap: 8px; }
  .clock-time { font-size: 0.95rem; }
  .clock-date { font-size: 0.62rem; }
  .icon-btn { width: 34px; height: 34px; }

  .tabs {
    display: grid; grid-template-columns: repeat(3, 1fr);
    border: 1px solid var(--cyan-line); border-radius: 3px; overflow: hidden;
  }
  .tabs button {
    background: transparent; border: 0; padding: 8px 4px;
    font-family: var(--font-hud); font-weight: 600; font-size: 0.8rem; letter-spacing: 0.18em; text-transform: uppercase;
    color: var(--muted);
  }
  .tabs button + button { border-left: 1px solid var(--cyan-line); }
  .tabs button[aria-selected='true'] { background: var(--cyan-faint); color: var(--cyan); text-shadow: var(--glow); }
  .tab-badge {
    display: inline-block; width: 7px; height: 7px; border-radius: 50%;
    background: var(--cyan); box-shadow: var(--glow); vertical-align: middle; margin-left: 4px;
  }
  .tab-badge[hidden] { display: none; }

  .layout { grid-template-columns: 1fr; }
  .layout > [data-pane] { display: none; }
  .layout > [data-pane].is-active { display: flex; }
  .reactor-wrap { width: min(86vw, 46vh); }
  .caption { font-size: 0.92rem; }

  .composer { gap: 10px; }
  #composer { padding-left: 14px; }
  .mic-btn { width: 60px; height: 60px; }
  .send-btn { width: 40px; height: 40px; }
  .msg { max-width: 94%; }
}

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
