:root {
  --fondo: #05090f;
  --panel: #0b131d;
  --panel-2: #101b28;
  --borde: #1a2a3c;
  --texto: #dbe7f3;
  --tenue: #7d91a8;
  --acento: #36e0ff;
  --acento-2: #ffb547;
  --peligro: #ff6b6b;
  --ok: #4be3a0;
  --radio: 14px;
  --sans: 'Space Grotesk', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% 110%, #0d2233 0%, var(--fondo) 60%);
  color: var(--texto);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }

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

/* ---------- Login ---------- */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-caja { width: 100%; max-width: 340px; text-align: center; }
.login-caja h1 { margin: 18px 0 2px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.sub { color: var(--tenue); margin: 0 0 28px; font-family: var(--mono); font-size: 13px; }
#form-login { display: grid; gap: 12px; }
#form-login input, .buscar, .escribir input {
  width: 100%; padding: 14px 16px; border-radius: var(--radio);
  border: 1px solid var(--borde); background: var(--panel); color: var(--texto); outline: none;
}
#form-login input:focus, .buscar:focus, .escribir input:focus { border-color: var(--acento); }
#form-login button {
  padding: 14px; border-radius: var(--radio); border: 0; background: var(--acento); color: #00131a; font-weight: 600;
}
.error { color: var(--peligro); min-height: 1.2em; font-size: 14px; margin: 0; }

/* ---------- Barra ---------- */
.barra {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(5, 9, 15, .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--borde);
}
.marca { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; font-size: 14px; }
.punto { width: 8px; height: 8px; border-radius: 50%; background: var(--acento); box-shadow: 0 0 10px var(--acento); }
.tabs { display: flex; gap: 4px; background: var(--panel); padding: 4px; border-radius: 999px; border: 1px solid var(--borde); }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 999px; font-size: 13px; color: var(--tenue); }
.tabs button.activa { background: var(--panel-2); color: var(--acento); }

.tab { flex: 1; display: flex; flex-direction: column; padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px); max-width: 720px; width: 100%; margin: 0 auto; }

/* ---------- Chat ---------- */
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; min-height: 120px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 16px; line-height: 1.45; font-size: 15.5px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--panel-2); border: 1px solid var(--borde); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: rgba(54, 224, 255, .07); border: 1px solid rgba(54, 224, 255, .25); border-bottom-left-radius: 4px; }
.msg .meta { display: block; margin-top: 6px; font-family: var(--mono); font-size: 11px; color: var(--tenue); }
.msg.error { border-color: rgba(255, 107, 107, .5); background: rgba(255, 107, 107, .08); }
.vacio { margin: auto; text-align: center; color: var(--tenue); font-size: 14px; line-height: 1.6; }
.vacio b { color: var(--texto); font-weight: 500; }

/* ---------- Controles / núcleo ---------- */
.controles { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 8px; }
.estado { font-family: var(--mono); font-size: 12px; color: var(--tenue); min-height: 1.3em; text-align: center; }
.mic { border: 0; background: none; padding: 0; -webkit-tap-highlight-color: transparent; }

.nucleo { position: relative; width: 112px; height: 112px; }
.nucleo span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--acento); opacity: .35; }
.nucleo span:nth-child(1) { inset: 34px; background: radial-gradient(circle, #bff6ff 0%, var(--acento) 45%, rgba(54,224,255,0) 75%); border: 0; opacity: .9; box-shadow: 0 0 30px var(--acento); }
.nucleo span:nth-child(2) { inset: 18px; border-style: dashed; animation: girar 14s linear infinite; }
.nucleo span:nth-child(3) { inset: 2px; opacity: .2; }
.nucleo.pequeno { width: 72px; height: 72px; margin: 0 auto; }
.nucleo.pequeno span:nth-child(1) { inset: 22px; }
.nucleo.pequeno span:nth-child(2) { inset: 11px; }

body.escuchando .nucleo span:nth-child(1) { animation: latir 1s ease-in-out infinite; }
body.escuchando .nucleo span:nth-child(3) { opacity: .7; animation: onda 1.2s ease-out infinite; }
body.pensando .nucleo span:nth-child(2) { animation: girar 1.2s linear infinite; opacity: .8; border-color: var(--acento-2); }
body.pensando .nucleo span:nth-child(1) { background: radial-gradient(circle, #fff1d6 0%, var(--acento-2) 45%, rgba(255,181,71,0) 75%); box-shadow: 0 0 30px var(--acento-2); }
body.hablando .nucleo span:nth-child(1) { animation: latir .45s ease-in-out infinite; }

@keyframes girar { to { transform: rotate(360deg); } }
@keyframes latir { 50% { transform: scale(1.18); } }
@keyframes onda { from { transform: scale(.9); opacity: .8; } to { transform: scale(1.25); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .nucleo span { animation: none !important; } }

.opciones { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 14px; font-size: 13px; color: var(--tenue); }
.toggle { display: flex; align-items: center; gap: 6px; }
.toggle input { accent-color: var(--acento); width: 16px; height: 16px; }
.link { border: 0; background: none; color: var(--acento); font-size: 13px; padding: 4px 0; text-decoration: underline; text-underline-offset: 3px; }

.escribir { display: flex; gap: 8px; width: 100%; }
.escribir button { flex: 0 0 48px; border-radius: var(--radio); border: 1px solid var(--borde); background: var(--panel); color: var(--acento); }

/* ---------- Listas ---------- */
.buscar { margin-bottom: 4px; }
.titulo { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--tenue); font-weight: 500; margin: 18px 0 8px; }
.ayuda { color: var(--tenue); font-size: 13px; margin: 0 0 8px; }
.lista { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; }
.item.clic { cursor: pointer; }
.item .cuerpo { flex: 1; min-width: 0; }
.item .nombre { font-weight: 500; }
.item .linea { color: var(--tenue); font-size: 13px; margin-top: 2px; }
.item .texto { font-size: 14.5px; line-height: 1.45; }
.item .fecha { font-family: var(--mono); font-size: 11px; color: var(--tenue); margin-top: 6px; }
.chip { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--borde); color: var(--tenue); margin: 0 6px 6px 0; }
.chip.alta { border-color: rgba(255,181,71,.5); color: var(--acento-2); }
.accion { border: 1px solid var(--borde); background: var(--panel-2); border-radius: 10px; padding: 6px 10px; font-size: 12px; color: var(--tenue); flex: 0 0 auto; }
.accion.ok { color: var(--ok); }
.accion.borrar { color: var(--peligro); }
.nada { color: var(--tenue); font-size: 14px; padding: 8px 2px; }
.pie { margin-top: auto; padding-top: 24px; display: flex; justify-content: space-between; }

/* ---------- Hoja de detalle ---------- */
.hoja { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; }
.hoja-caja { position: relative; width: 100%; max-width: 720px; max-height: 85dvh; overflow-y: auto; background: var(--fondo); border: 1px solid var(--borde); border-radius: 20px 20px 0 0; padding: 20px 16px calc(env(safe-area-inset-bottom) + 20px); }
.cerrar { position: absolute; right: 12px; top: 12px; border: 0; background: var(--panel); width: 34px; height: 34px; border-radius: 50%; }
.hoja h3 { margin: 0 40px 4px 0; font-size: 20px; font-weight: 600; }
.ficha { display: grid; gap: 8px; margin: 14px 0; }
.ficha label { font-size: 12px; color: var(--tenue); display: grid; gap: 4px; }
.ficha input, .ficha textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--borde); background: var(--panel); color: var(--texto); font: inherit; }
.ficha textarea { min-height: 70px; resize: vertical; }
.fila-botones { display: flex; gap: 8px; justify-content: space-between; margin-top: 4px; }

.activar { position: fixed; inset: 0; z-index: 40; border: 0; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: rgba(5, 9, 15, .94); color: var(--texto); font-size: 18px; font-weight: 500; padding: 24px; text-align: center; }
.activar small { color: var(--tenue); font-size: 13px; font-weight: 400; font-family: var(--mono); }
.activar .nucleo span:nth-child(1) { animation: latir 1.6s ease-in-out infinite; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%); z-index: 30;
  background: var(--panel-2); border: 1px solid var(--acento); color: var(--texto); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); }
