/* App WEB de chat · SOLO la maqueta del hilo (§C, 17-sep-2026): los tokens de
 * color, el reset de base y el acento ya vienen de sx.css + ui.css (enlazados
 * ANTES que este fichero en index.html) — antes este `:root` los duplicaba con
 * sus propios nombres (`--ink`, `--muted`, `--faint`, `--hairline`, `--elev-*`,
 * un `--accent` periwinkle propio) y por eso esta app tenía su propio acento en
 * vez del de toda la web. La cabecera (antes `.topbar`/`.brand-link`/`.acct`/
 * `.who`/`.plan-badge`) también sale de aquí: ahora es `.app-header` +
 * `.pill-sx`, compartida con /app/notas/, en ui.css.
 *
 * DOS CARAS, UN COMPONENTE: por encima de 720px el turno se pinta ESTILO
 * DOCUMENTO (como Saelyx para Mac — ConversationTurnRow: sin burbuja, ancho
 * completo, glifo solo al abrir racha). Por debajo, ESTILO BURBUJA (como
 * Saelyx en iPhone — NoteTurnCard: Saelyx a la izquierda con riel de acento,
 * usuario a la derecha). La media query de 720px es la misma que ya usa
 * `esMovil` en app-promo.js — no se inventa un umbral nuevo. */

/* ── Aurora ambiente (idéntica a app/voz/voz.css) ── */
.aurora {
  position: fixed; inset: -20% -10% auto -10%; height: 70vh; z-index: 0;
  pointer-events: none; filter: blur(80px); opacity: 0.5;
  background:
    radial-gradient(40% 50% at 22% 30%, rgba(92,219,252,0.30) 0%, transparent 70%),
    radial-gradient(38% 46% at 78% 20%, rgba(130,117,247,0.30) 0%, transparent 70%),
    radial-gradient(34% 40% at 55% 60%, rgba(247,110,201,0.18) 0%, transparent 70%);
  animation: aurora-drift 22s var(--ease-in-out) infinite alternate;
}
@keyframes aurora-drift { from { transform: translateY(-4%) scale(1); } to { transform: translateY(4%) scale(1.06); } }

/* ── Micro-orbe (glifo de Saelyx en el hilo) · subset del orbe grande ── */
.mini-orb { width: 28px; height: 28px; border-radius: 50%; position: relative; flex: 0 0 auto; }
.mini-orb::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background:
    radial-gradient(60% 60% at 40% 34%, var(--orb-core) 0%, transparent 55%),
    conic-gradient(from 200deg at 50% 50%, var(--orb-cyan), var(--orb-violet), var(--orb-pink), var(--orb-peach), var(--orb-cyan));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.20), 0 0 10px -2px rgba(130,117,247,0.55);
}
.mini-orb.pulsing::before { animation: mini-orb-pulse 1.6s ease-in-out infinite; }
@keyframes mini-orb-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

.user-glyph {
  width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--bg-elev-2); border: 1px solid var(--stroke-hairline);
  color: var(--text-secondary); font-size: 13px;
}
.user-glyph svg { width: 14px; height: 14px; }

/* ── Layout principal ── */
.chat-wrap {
  position: relative; z-index: 10;
  display: flex; flex-direction: column;
  max-width: 860px; margin: 0 auto;
  /* --app-header-h (ui.css) refleja la altura REAL de .app-header en vez de
     un 64px fijo -- a ≤560px la cabecera pasa a dos filas y crece bastante
     más que eso. */
  height: calc(100vh - var(--app-header-h));
}
.chat-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 4px 20px 14px;
}
.chat-head h1 { font-size: 17px; margin: 0; font-weight: 600; }
.chat-head .state {
  font-size: 12px; color: var(--text-tertiary); transition: color .18s ease;
}
.chat-head .state.live { color: var(--accent); }
.chat-quota {
  font-size: 11px; font-variant-numeric: tabular-nums; color: var(--text-tertiary);
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--stroke-hairline);
  white-space: nowrap;
}
.chat-quota.exhausted { color: #F58C8C; border-color: rgba(245,140,140,0.4); }

/* La píldora de herramienta en curso (`#tool-pill`) usa `.pill-sx` de ui.css
 * directamente -- nada que declarar aquí. Solo el hueco entre el hilo y ella: */
#tool-pill { margin: 0 20px 8px; width: fit-content; }

/* ── Hilo ── */
.thread {
  flex: 1; overflow-y: auto; padding: 8px 20px 24px;
  display: flex; flex-direction: column; gap: 4px;
}
.empty-state {
  margin: auto; text-align: center; max-width: 340px; color: var(--text-secondary);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.empty-state h2 { font-size: 16px; margin: 0; color: var(--text-primary); }
.empty-state p { font-size: 13px; line-height: 1.5; margin: 0; color: var(--text-tertiary); }

/* Fila de turno · ESTILO DOCUMENTO por defecto (escritorio) — sin burbuja,
 * ancho completo, riel de glifo reservado, separador hairline entre rachas. */
.turn { display: flex; gap: 14px; padding: 3px 0; align-items: flex-start; }
.turn .rail { width: 28px; flex: 0 0 28px; display: flex; justify-content: center; }
.turn .rail:empty::before { content: ""; display: block; width: 1px; }
.turn .col { flex: 1; min-width: 0; }
.turn .meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.turn .meta .name { font-size: 13px; font-weight: 600; }
.turn[data-speaker="saelyx"] .meta .name { color: var(--accent); }
.turn[data-speaker="user"] .meta .name { color: var(--text-secondary); }
.turn .meta .time { font-size: 11px; color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.turn .text {
  font-size: 14.5px; line-height: 1.55; color: var(--text-primary); white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.turn .text p { margin: 0 0 8px; }
.turn .text p:last-child { margin-bottom: 0; }
.turn .text code { background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 4px; font-size: 0.92em; }
.turn .text strong { font-weight: 700; }
.turn[data-speaker="user"] .text { color: var(--text-secondary); }

/* Fuentes citadas */
.refs { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.ref-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 10px;
  background: var(--accent-glow-soft); border: 1px solid var(--stroke-accent);
  font-size: 12px; color: var(--text-secondary);
}
.ref-chip .t { color: var(--text-primary); font-weight: 600; }
.ref-chip svg { flex: 0 0 auto; color: var(--accent); width: 13px; height: 13px; }

/* Documento generado */
.doc-card {
  display: flex; align-items: center; gap: 10px;
  margin-top: 8px; padding: 11px 14px; border-radius: 12px;
  background: var(--accent); color: #0B0E10; text-decoration: none;
  font-size: 13px; font-weight: 600; width: fit-content; max-width: 100%;
  box-shadow: 0 8px 22px -10px var(--accent-glow);
}
.doc-card svg { flex: 0 0 auto; width: 16px; height: 16px; }
.doc-card .fn { font-weight: 400; opacity: .85; font-size: 12px; }

/* Escribiendo… */
.typing { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.typing .dots { display: flex; gap: 4px; padding: 10px 12px; border-radius: 14px; background: var(--bg-elev-1); border: 1px solid var(--stroke-hairline); }
.typing .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-tertiary); animation: typing-bounce 1.1s ease-in-out infinite; }
.typing .dot:nth-child(2) { animation-delay: .15s; }
.typing .dot:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-3px); } }

/* ── Compositor ── */
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--stroke-hairline);
  background: rgba(0,0,0,0.55); backdrop-filter: blur(14px);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 42px;
  background: var(--bg-elev-1); color: var(--text-primary);
  border: 1px solid var(--stroke-hairline); border-radius: 18px;
  padding: 10px 16px; font: 14.5px/1.4 "Inter", system-ui, sans-serif;
  outline: none; transition: border-color .15s ease;
}
.composer textarea:focus { border-color: var(--stroke-accent); }
.composer textarea::placeholder { color: var(--text-tertiary); }
.composer button {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer; display: grid; place-items: center;
  background: var(--bg-elev-2); color: var(--text-tertiary);
  transition: background .18s ease, color .18s ease, box-shadow .18s ease;
}
.composer button svg { width: 16px; height: 16px; }
/* `.ready` (el botón encendido, con texto) lo redefine ui.css entero, con el
 * degradado del botón primario del Mac -- nada que decir aquí. */
.composer button:disabled { cursor: not-allowed; opacity: .6; }

.load-error {
  margin: auto; text-align: center; color: var(--text-tertiary); font-size: 13px; padding: 20px;
}
.load-error button {
  margin-top: 10px; background: var(--accent-glow-soft); color: var(--text-primary);
  border: 1px solid var(--stroke-accent); border-radius: 999px;
  padding: 8px 18px; font-size: 13px; cursor: pointer;
}

/* ══════════════════════════════════════════════════════════════════════════
   CARA MÓVIL (≤720px, mismo umbral que esMovil en app-promo.js) · burbuja,
   como NoteTurnCard en iPhone: Saelyx izq. con riel de acento + fondo elev-1,
   usuario der. con fondo elev-2, avatar solo al abrir racha, orden más-nuevo-
   abajo (igual que en escritorio: aquí NO se invierte, a diferencia de la Mac,
   porque en el móvil "más nuevo abajo con scroll" es el patrón ya aprendido
   de cualquier chat).
   ════════════════════════════════════════════════════════════════════════ */
@media (max-width: 720px) {
  /* .app-header sigue en flujo normal (no está fixed): un 100dvh a secas no
     restaba su altura y el compositor quedaba por debajo del borde de la
     pantalla, tanto en la franja de cabecera de una fila (561-720px) como,
     peor, en la de dos filas (≤560px). */
  .chat-wrap { height: calc(100dvh - var(--app-header-h)); }
  .chat-head { padding: 2px 14px 10px; }
  .thread { padding: 6px 12px 16px; gap: 10px; }

  .turn { align-items: flex-end; }
  .turn[data-speaker="saelyx"] { padding-right: 15%; }
  .turn[data-speaker="user"] { padding-left: 15%; flex-direction: row-reverse; }
  .turn[data-speaker="user"] .rail { justify-content: center; }

  .turn .col {
    padding: 10px 13px; border-radius: 16px;
    border: 1px solid var(--stroke-hairline);
  }
  .turn[data-speaker="saelyx"] .col {
    background: var(--bg-elev-1); position: relative; border-top-left-radius: 5px;
  }
  .turn[data-speaker="saelyx"] .col::before {
    content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
    border-radius: 3px; background: var(--accent);
  }
  .turn[data-speaker="user"] .col { background: var(--bg-elev-2); border-top-right-radius: 5px; }

  .composer { padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .aurora, .mini-orb.pulsing::before, .typing .dot { animation: none; }
}
