/* The Lab — v0.1 (grid + ficha) — estilo industrial oscuro, zero-dep */

:root {
  --bg: #0b0f17;
  --panel: #111827;
  --panel2: #0f172a;
  --line: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --ok: #34d399;
  --warn: #fbbf24;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: radial-gradient(1200px 600px at 70% -10%, #16233f 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; backdrop-filter: blur(12px); background: rgba(11,15,23,.8); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; }
.brand-badge {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7c3aed); font-size: 14px; font-weight: 800;
}
.brand-sub { color: var(--muted); font-weight: 400; font-size: 13px; }
.topbar nav a { color: var(--muted); text-decoration: none; font-size: 14px; margin-left: 18px; }
.topbar nav a:hover { color: var(--text); }

/* 📱 móvil: brand + nav apilados — sin solapamiento de letras */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 6px 10px; padding: 10px 14px; }
  .brand-sub { display: none; }
  .topbar nav { width: 100%; display: flex; align-items: center; gap: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .topbar nav a { margin-left: 0; white-space: nowrap; font-size: 13px; flex-shrink: 0; }
}

.hero { max-width: 1080px; margin: 0 auto; padding: 64px 24px 28px; text-align: center; }
.hero h1 { font-size: clamp(32px, 6vw, 58px); font-weight: 800; letter-spacing: -1.5px; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero-sub { color: var(--muted); max-width: 620px; margin: 14px auto 22px; font-size: 17px; line-height: 1.55; }
.hero-meta { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px;
  font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 7px;
}
.pill.live { color: var(--ok); border-color: rgba(52,211,153,.35); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); animation: pulse 1.8s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.grid {
  max-width: 1080px; margin: 0 auto; padding: 18px 24px 40px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px;
}
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid var(--line); border-radius: 16px; padding: 18px;
  cursor: pointer; transition: transform .15s, border-color .15s, box-shadow .15s;
  display: flex; flex-direction: column; gap: 10px;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.card-head { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 800; font-size: 18px;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
}
.avatar.big { width: 64px; height: 64px; font-size: 26px; border-radius: 16px; }
.idline h2 { font-size: 17px; font-weight: 700; }
.role { color: var(--muted); font-size: 12.5px; display: block; margin-top: 2px; }
.status { width: 10px; height: 10px; border-radius: 50%; margin-left: auto; flex-shrink: 0; }
.status.online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status.soon { background: var(--warn); }
.specialty { font-size: 13.5px; color: var(--text); line-height: 1.5; }
.personality { font-size: 12.5px; color: var(--muted); font-style: italic; line-height: 1.45; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.voice { font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  border-radius: 10px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.primary.big { padding: 13px 26px; font-size: 16px; border-radius: 12px; }
.btn.ghost { width: 38px; padding: 8px 0; }

.lab-note { max-width: 760px; margin: 0 auto 60px; padding: 0 24px; }
.lab-note h2 { font-size: 20px; margin-bottom: 14px; }
.lab-note ol { list-style: none; counter-reset: step; display: grid; gap: 10px; }
.lab-note li { counter-increment: step; display: flex; gap: 12px; color: var(--muted); font-size: 14.5px; line-height: 1.5; }
.lab-note li::before {
  content: counter(step); width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}

footer { border-top: 1px solid var(--line); padding: 22px; text-align: center; color: var(--muted); font-size: 13px; }
footer a { color: var(--accent); text-decoration: none; }

/* Modal */
.modal {
  border: 1px solid var(--line); border-radius: 18px; background: var(--panel);
  color: var(--text); padding: 0; max-width: 460px; width: 92%;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
}
.modal::backdrop { background: rgba(2,6,14,.72); backdrop-filter: blur(4px); }
.modal-inner { padding: 26px; position: relative; display: grid; gap: 14px; }
.modal-close {
  position: absolute; top: 14px; right: 14px; background: none; border: none;
  color: var(--muted); font-size: 17px; cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal-head { display: flex; align-items: center; gap: 16px; }
.modal-specialty { font-size: 14.5px; line-height: 1.55; }
.modal-personality { color: var(--muted); font-style: italic; font-size: 13.5px; }
.modal-voice { color: var(--muted); font-size: 13px; }
.modal-hint { font-size: 12px; color: var(--warn); line-height: 1.5; }
.passcode {
  width: 100%; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; color: var(--text); font-size: 13.5px; outline: none;
}
.passcode:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 12px; margin-top: 6px; }

/* Overlay de llamada */
#call-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(2, 6, 14, .86); backdrop-filter: blur(8px);
  display: grid; place-items: center; padding: 20px;
}
.call-panel {
  width: min(680px, 100%); background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid var(--line); border-radius: 20px; padding: 22px;
  display: grid; gap: 16px; box-shadow: 0 30px 90px rgba(0, 0, 0, .6);
}
.call-head { display: flex; align-items: center; gap: 14px; }
.call-live { font-size: 13px; color: var(--ok); display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.call-timer { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 15px; font-weight: 700; }
.call-hangup {
  width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  background: #ef4444; color: #fff; font-size: 17px; transition: transform .15s;
}
.call-hangup:hover { transform: scale(1.08); }
.call-transcript {
  height: 300px; overflow-y: auto; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; display: grid; gap: 8px; align-content: start;
  font-size: 14px; line-height: 1.5;
}
.call-transcript p { margin: 0; }
.call-empty { color: var(--muted); font-style: italic; }
.t-user { color: var(--text); }
.t-agent { color: var(--accent); }
.call-note { font-size: 12px; color: var(--muted); text-align: center; }

/* toast de feedback (samples sin claves) */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1a1a1a; border: 1px solid var(--accent); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; z-index: 1100;
  box-shadow: 0 4px 24px rgba(0,0,0,.5); animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* 💬 panel de chat de texto */
.chat-panel {
  position: fixed; right: 20px; bottom: 20px; width: 340px; max-width: calc(100vw - 40px);
  background: #141414; border: 1px solid #2a2a2a; border-radius: 14px; z-index: 800;
  display: flex; flex-direction: column; box-shadow: 0 8px 40px rgba(0,0,0,.6); overflow: hidden;
}
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: #1a1a1a; border-bottom: 1px solid #2a2a2a; font-weight: 600; font-size: 13px; }
.chat-close { background: none; border: none; color: var(--muted); font-size: 14px; cursor: pointer; }
.chat-body { height: 260px; overflow-y: auto; padding: 12px 14px; font-size: 13px; display: flex; flex-direction: column; gap: 8px; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid #2a2a2a; }
.chat-form input { flex: 1; background: #1a1a1a; border: 1px solid #2a2a2a; color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.chat-form .btn { padding: 8px 12px; }

/* estados disabled + botón de descarga */
.btn:disabled, .btn[disabled] { opacity: .45; cursor: not-allowed; filter: grayscale(.4); }
.call-download {
  background: none; border: 1px solid #2a2a2a; color: var(--muted); border-radius: 8px;
  width: 34px; height: 34px; font-size: 15px; cursor: pointer; margin-right: 6px;
  transition: border-color .2s, color .2s;
}
.call-download:hover { border-color: var(--accent); color: var(--text); }

/* El atributo hidden debe ganar SIEMPRE (los display:grid/flex de autor lo pisaban y el overlay/chat se veían al cargar) */
[hidden] { display: none !important; }

/* ⏳ estado de tarea asíncrona en el chat */
.t-task { color: var(--muted); font-size: 12.5px; font-style: italic; padding: 6px 10px; margin: 4px 0; border-left: 2px solid var(--accent); background: rgba(255,255,255,.03); border-radius: 6px; }

/* ── Fix Safari/iOS ───────────────────────────────────────────
   1) inputs con font-size >= 16px → sin zoom automático al enfocar
   2) touch-action: manipulation → sin doble-tap zoom ni delay de 300ms
   3) text-size-adjust fijo → sin reflow de texto en landscape/rotación */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
input, select, textarea { font-size: 16px !important; }
button, .card, .btn, a, .chat-close, .call-hangup, .call-download { touch-action: manipulation; }

/* 🏛️ Sala de Equipo — panel de reuniones orquestadas */
.team-panel {
  position: fixed; right: 20px; bottom: 20px; width: 420px; max-width: calc(100vw - 40px);
  height: min(82vh, 680px);
  background: #141414; border: 1px solid #2a2a2a; border-radius: 14px; z-index: 850;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.team-pick {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px;
  border-bottom: 1px solid #222; background: #101010;
}
.pick-chip {
  border: 1px solid #2e2e2e; background: transparent; color: #cfcfcf;
  border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer;
  transition: all .15s ease;
}
.pick-chip.on { background: var(--accent, #22d3ee); border-color: transparent; color: #081018; font-weight: 600; }
.team-phase {
  padding: 7px 14px; font-size: 12.5px; color: #9ca3af;
  border-bottom: 1px solid #1c1c1c; background: #121212;
}
.t-round {
  margin: 12px 0 4px; font-size: 12px; font-weight: 700; color: #6ee7b7;
  text-transform: uppercase; letter-spacing: .04em;
}
.t-acta {
  margin: 12px 4px 8px; padding: 12px; border-radius: 10px;
  background: #0d1117; border: 1px solid #2a2a2a; border-left: 3px solid #fbbf24;
  white-space: pre-wrap; font-size: 12.5px; line-height: 1.55; color: #e5e7eb;
}
@media (max-width: 520px) {
  .team-panel { right: 10px; bottom: 10px; width: calc(100vw - 20px); height: 78vh; height: 78dvh; }
  .chat-panel { right: 10px; bottom: 10px; }
}

/* 🧹 borrar historial de chat 1:1 */
.chat-clear {
  display: block; margin: 10px auto 4px; padding: 6px 12px;
  border: 1px solid #2e2e2e; background: transparent; color: #9ca3af;
  border-radius: 999px; font-size: 12px; cursor: pointer;
  touch-action: manipulation;
}
.chat-clear:hover { border-color: #f87171; color: #f87171; }

/* ── v0.5: markdown + copiar + pantalla completa (port VSV ChatWidgetV2) ── */
.hidden { display: none !important; }

/* burbujas de mensaje con markdown */
.msg { display: flex; flex-direction: column; gap: 2px; }
.msg-agent { align-items: flex-start; }
.msg-user { align-items: flex-end; }
.bubble { max-width: 100%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.55; word-break: break-word; overflow-wrap: anywhere; }
.msg-agent .bubble { background: #151d2e; border: 1px solid #26324a; color: #e2e8f0; border-top-left-radius: 3px; }
.msg-user .bubble { background: #16324f; border: 1px solid #24486e; color: #f1f5f9; border-top-right-radius: 3px; }
.msg-actions { display: flex; gap: 6px; margin: 1px 0 2px 4px; }
.cp-btn {
  background: none; border: 1px solid #2e3a52; color: var(--muted);
  border-radius: 8px; padding: 3px 9px; font-size: 11px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; transition: all .15s; touch-action: manipulation;
}
.cp-btn:hover { border-color: var(--accent); color: var(--text); }
.cp-btn.mini { padding: 2px 6px; font-size: 11px; }

/* elementos markdown */
.bubble a, .t-agent a, .t-acta a { color: #7dd3fc; text-decoration: underline; text-decoration-color: rgba(125,211,252,.4); }
.bubble strong, .t-acta strong { color: #f8fafc; }
.md-h { margin: 8px 0 4px; font-weight: 700; color: #f8fafc; }
.md-li { display: flex; gap: 6px; margin: 2px 0; }
.md-bullet { color: var(--accent); flex-shrink: 0; }
.md-table { overflow-x: auto; margin: 6px 0; }
.md-table table { border-collapse: collapse; width: 100%; font-size: 12px; }
.md-table th { text-align: left; font-weight: 600; color: var(--accent); border-bottom: 1px solid #334155; padding: 5px 8px; }
.md-table td { border-bottom: 1px solid #1e293b; padding: 5px 8px; vertical-align: top; }
.md-code {
  background: #0b0f17; border: 1px solid #26324a; border-radius: 10px;
  padding: 10px 12px; overflow-x: auto; margin: 6px 0;
  font-family: "JetBrains Mono", ui-monospace, "Cascadia Code", monospace;
  font-size: 12px; line-height: 1.5; color: #a5f3fc; white-space: pre;
}
.md-inline {
  background: #0b0f17; border: 1px solid #26324a; border-radius: 5px;
  padding: 1px 5px; font-family: "JetBrains Mono", ui-monospace, "Cascadia Code", monospace;
  font-size: 12px; color: #a5f3fc;
}

/* cabecera de paneles: acciones (expand + cerrar) */
.head-actions { display: flex; align-items: center; gap: 10px; }
.chat-expand { background: none; border: none; color: var(--muted); cursor: pointer; display: inline-flex; padding: 3px; border-radius: 6px; transition: color .15s; touch-action: manipulation; }
.chat-expand:hover { color: var(--text); }
.chat-expand svg { width: 16px; height: 16px; }

/* pantalla completa de chat y sala */
.chat-panel.fs, .team-panel.fs {
  position: fixed; inset: 0; width: 100vw; max-width: none;
  height: 100vh; height: 100dvh; border-radius: 0; border: none; z-index: 900;
}
/* body SIEMPRE flexible dentro del panel (normal y fs) — el contenido manda, el resto scroll */
.chat-panel .chat-body { height: auto; flex: 1 1 auto; min-height: 0; }
.chat-panel.fs .chat-body { height: auto; flex: 1 1 auto; min-height: 0; }
/* modo ventana (no-fs): altura cómoda fija para que no colapse a mini con poco contenido */
.chat-panel:not(.fs) .chat-body { height: 340px; flex: 0 0 auto; }
.team-panel .chat-body { height: auto; flex: 1 1 auto; min-height: 120px; }

/* transcript de llamada: markdown + quién habla */
.t-who { color: var(--muted); font-weight: 600; }
.call-transcript .t-agent { display: flex; align-items: flex-start; gap: 6px; flex-wrap: wrap; }

/* ── v0.6: streaming, fuentes, token trail, feedback, mic, chips, scroll ── */

/* burbuja en streaming (texto plano mientras llega el SSE) */
.streaming { white-space: pre-wrap; word-break: break-word; }
.streaming:empty::after { content: "…"; color: var(--muted); animation: pulse 1.2s infinite; }

/* chips de sugerencias (estado vacío) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip {
  border: 1px solid #2e3a52; background: transparent; color: #b8c4d9;
  border-radius: 999px; padding: 6px 12px; font-size: 12px; cursor: pointer;
  transition: all .15s; touch-action: manipulation; text-align: left; line-height: 1.35;
}
.chip:hover { border-color: var(--accent); color: var(--text); background: rgba(56,189,248,.08); }

/* micrófono (dictado) */
.mic-btn {
  background: #1a1a1a; border: 1px solid #2a2a2a; color: var(--muted);
  border-radius: 8px; width: 36px; font-size: 15px; cursor: pointer;
  transition: all .15s; touch-action: manipulation; flex-shrink: 0;
}
.mic-btn:hover { border-color: var(--accent); color: var(--text); }
.mic-btn.rec { border-color: #ef4444; color: #ef4444; animation: pulse 1.2s infinite; background: rgba(239,68,68,.12); }

/* toggle pensamiento profundo (Ox-Alpha vía OpenRouter) */
.deep-btn {
  background: #1a1a1a; border: 1px solid #2a2a2a; color: var(--muted);
  border-radius: 8px; width: 36px; font-size: 15px; cursor: pointer;
  transition: all .15s; touch-action: manipulation; flex-shrink: 0;
}
.deep-btn:hover { border-color: var(--accent); color: var(--text); }
.deep-btn.on {
  border-color: #a78bfa; color: #a78bfa; background: rgba(167,139,250,.12);
  box-shadow: 0 0 8px rgba(167,139,250,.25);
}

/* fuentes de la KB (colapsable) */
.srcs { margin-top: 6px; border-top: 1px dashed #26324a; padding-top: 6px; }
.srcs-toggle {
  background: none; border: none; color: var(--muted); font-size: 11.5px;
  cursor: pointer; padding: 0; display: inline-flex; align-items: center; gap: 4px;
  transition: color .15s; touch-action: manipulation;
}
.srcs-toggle:hover { color: var(--accent); }
.srcs-list { margin-top: 6px; display: grid; gap: 3px; }
.src-item { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.src-item a { color: #7dd3fc; text-decoration: underline; text-decoration-color: rgba(125,211,252,.4); }
.src-score { color: #64748b; }

/* token trail */
.trail {
  margin-top: 5px; font-size: 10.5px; color: #64748b;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  border-top: 1px dashed #1e293b; padding-top: 4px;
}

/* feedback 👍👎 */
.fb { display: inline-flex; gap: 4px; margin-left: 6px; }
.fb-btn {
  background: none; border: 1px solid transparent; color: var(--muted);
  border-radius: 6px; padding: 2px 6px; font-size: 12px; cursor: pointer;
  transition: all .15s; touch-action: manipulation;
}
.fb-btn:hover { border-color: #2e3a52; }
.fb-btn.on { border-color: var(--accent); background: rgba(56,189,248,.12); }

/* 🔊 TTS por mensaje */
.tts-btn {
  background: none; border: 1px solid #2e3a52; color: var(--muted);
  border-radius: 8px; padding: 3px 9px; font-size: 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; transition: all .15s; touch-action: manipulation;
}
.tts-btn:hover { border-color: var(--accent); color: var(--text); }
.tts-btn.playing { border-color: var(--accent); color: var(--accent); background: rgba(56,189,248,.12); animation: pulse 1.2s infinite; }

/* botón flotante scroll al final */
.scroll-btn {
  position: absolute; right: 14px; bottom: 64px; z-index: 6;
  width: 32px; height: 32px; border-radius: 50%;
  background: #1a1a1a; border: 1px solid #2e3a52; color: var(--muted);
  font-size: 16px; cursor: pointer; display: grid; place-items: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.45); transition: all .15s; touch-action: manipulation;
}
.scroll-btn:hover { border-color: var(--accent); color: var(--text); }

/* 💬 respuesta final para el visitante (destacada) */
.final-wrap { margin-top: 14px; }
.final-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--accent); margin-bottom: 6px;
}
.final-msg {
  background: linear-gradient(180deg, #13233b, #0f1a2c);
  border: 1px solid rgba(56,189,248,.45); border-left: 3px solid var(--accent);
  border-radius: 12px; padding: 12px 14px;
  font-size: 13.5px; line-height: 1.6; color: #e2e8f0;
}
.final-msg a { color: #7dd3fc; text-decoration: underline; text-decoration-color: rgba(125,211,252,.4); }
.final-msg strong { color: #f8fafc; }
