* { box-sizing: border-box; }
[hidden] { display: none !important; }
:root {
  --bg: #0b0f19;
  --panel: #111927;
  --panel-2: #161c2a;
  --border: rgba(255,255,255,.08);
  --accent: #00d9d9;
  --accent-ink: #06222a;
  --text: #f5f7fb;
  --text-soft: #a6b0c3;
  --green: #10b981;
  --amber: #ffca28;
}
html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  margin: 0;
}

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
}
.back-link { color: var(--text-soft); text-decoration: none; font-size: .85rem; }
.back-link:hover { color: var(--accent); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .9rem; }
.brand-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }

main { max-width: 1180px; margin: 0 auto; padding: 40px 24px 80px; }

.intro { max-width: 720px; margin: 0 auto 40px; text-align: center; }
.intro-eyebrow {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 10px;
}
.intro h1 { font-size: 1.9rem; margin: 0 0 14px; line-height: 1.25; }
.intro p { color: var(--text-soft); line-height: 1.6; font-size: .96rem; }
.intro p a { color: var(--accent); }
.intro-actions { display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 24px; flex-wrap: wrap; }

.btn-play {
  background: linear-gradient(135deg, var(--accent), #00b8b8);
  color: var(--accent-ink); border: none; border-radius: 10px;
  padding: 13px 26px; font-weight: 700; font-size: .95rem; cursor: pointer;
  transition: transform .15s ease, opacity .15s ease;
}
.btn-play:hover { transform: translateY(-1px); }

.mode-toggle, .vista-toggle { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.mode-btn, .vista-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text-soft);
  border-radius: 8px; padding: 8px 14px; font-size: .82rem; font-weight: 600; cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}
.mode-btn:hover, .vista-btn:hover { color: var(--text); }
.mode-btn.active, .vista-btn.active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.mode-btn-fullscreen { margin-left: 6px; color: var(--text-soft); }
.mode-btn-fullscreen:hover { color: var(--accent); border-color: var(--accent); }

.stage-wrap { max-width: 1080px; margin: 0 auto; }
.stage-wrap:fullscreen { background: var(--bg); display: flex; flex-direction: column; justify-content: center; padding: 24px; }

.stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: var(--border);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  min-height: 560px;
}

/* ---------- Modo mobile (Tarea 3.1, misma respuesta que Tarea 2): acá no van las dos vistas
   lado a lado (el teléfono es angosto) -- se alterna cuál de las dos se ve con el
   vista-toggle de arriba, cada una a pantalla completa dentro del mismo marco de teléfono. */
.stage[data-mode="mobile"] {
  display: flex; justify-content: center; align-items: flex-start;
  background: transparent; border: none; padding: 0; min-height: 0;
}
.stage[data-mode="mobile"] .stage-client,
.stage[data-mode="mobile"] .stage-agent {
  width: 320px; height: 640px; flex: none;
  border: 10px solid #1c2536; border-radius: 42px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5), 0 0 0 1px var(--border);
  position: relative;
}
.stage[data-mode="mobile"] .stage-client::before,
.stage[data-mode="mobile"] .stage-agent::before {
  content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 120px; height: 22px; background: #1c2536; border-radius: 0 0 14px 14px; z-index: 2;
}
.stage[data-mode="mobile"] .device-label { display: none; }
.stage[data-mode="mobile"] .client-viewport { padding: 0; }
.stage[data-mode="mobile"] .client-window { inset: 0; border-radius: 0; }
.stage[data-mode="mobile"][data-vista="cliente"] .stage-agent { display: none; }
.stage[data-mode="mobile"][data-vista="agente"] .stage-client { display: none; }
/* Dentro del teléfono, el panel de agente pasa a navegación lista→thread (patrón de app de
   chat mobile real) en vez de sidebar+thread lado a lado -- 220px de sidebar no entra en un
   teléfono de 320px de ancho. */
.stage[data-mode="mobile"] .agent-body { grid-template-columns: 1fr; }
.stage[data-mode="mobile"] .agent-sidebar { border-right: none; }
.stage[data-mode="mobile"] .agent-panel:not(.mostrar-thread) .agent-thread { display: none; }
.stage[data-mode="mobile"] .agent-panel.mostrar-thread .agent-sidebar { display: none; }
.btn-volver-lista { display: none; background: transparent; border: none; color: var(--text-soft); font-size: 1.1rem; cursor: pointer; padding: 4px 8px 4px 0; }
.stage[data-mode="mobile"] .btn-volver-lista { display: inline-flex; }

.stage-half { background: var(--panel); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.device-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-soft);
  padding: 10px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}

/* ---------- Client side ---------- */
.client-viewport { position: relative; flex: 1; background: #05070c; display: flex; align-items: flex-end; justify-content: flex-end; padding: 20px; }
.client-bubble {
  width: 54px; height: 54px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #00b8b8);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent-ink); box-shadow: 0 8px 24px rgba(0,217,217,.35);
  cursor: pointer; border: none;
  transition: transform .2s ease, opacity .2s ease;
}
.client-bubble:hover { transform: scale(1.06); }
.client-bubble svg { width: 26px; height: 26px; }

.client-window {
  position: absolute; inset: 20px;
  background: #0f1522; border: 1px solid var(--border); border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,.4);
  animation: popIn .25s ease;
}
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.client-window-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; background: var(--panel-2); border-bottom: 1px solid var(--border);
  font-size: .85rem; font-weight: 600;
}
.client-window-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.client-window-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.client-window-typing { padding: 0 14px 8px; font-size: .76rem; color: var(--text-soft); display: flex; align-items: center; gap: 8px; }

.msg { max-width: 82%; padding: 9px 12px; border-radius: 12px; font-size: .85rem; line-height: 1.45; animation: msgIn .2s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-in  { align-self: flex-start; background: #1b2333; color: var(--text); border-bottom-left-radius: 3px; }
.msg-out { align-self: flex-end; background: linear-gradient(135deg, var(--accent), #00b8b8); color: var(--accent-ink); font-weight: 500; border-bottom-right-radius: 3px; }

.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* Formularios reales (Tarea 3.1: acá SÍ se escribe de verdad, a diferencia de la demo
   coreografiada donde los inputs eran readonly). */
.client-window-input, .agent-thread-input {
  border-top: 1px solid var(--border); padding: 10px; display: flex; gap: 8px;
}
.client-window-input input, .agent-thread-input input {
  flex: 1; background: #0b0f19; border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; color: var(--text); font-size: .85rem; outline: none;
}
.client-window-input input:focus, .agent-thread-input input:focus { border-color: var(--accent); }
.btn-enviar {
  background: var(--accent); color: var(--accent-ink); border: none; border-radius: 8px;
  width: 36px; flex-shrink: 0; cursor: pointer; font-size: .95rem; transition: transform .15s ease;
}
.btn-enviar:hover { transform: scale(1.05); }

/* ---------- Agent side ---------- */
.agent-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.agent-body { flex: 1; display: grid; grid-template-columns: 220px 1fr; min-height: 0; }
.agent-sidebar { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.agent-sidebar-head { padding: 10px; border-bottom: 1px solid var(--border); }
.agent-search {
  width: 100%; background: #0b0f19; border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; color: var(--text); font-size: .8rem;
}
.agent-chat-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.agent-chat-item {
  display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 9px; cursor: pointer;
  transition: background .15s ease; margin-bottom: 3px; position: relative;
}
.agent-chat-item:hover { background: rgba(255,255,255,.04); }
.agent-chat-item.selected { background: rgba(0,217,217,.1); }
.agent-chat-item.entering { animation: itemPulse 1s ease; }
@keyframes itemPulse { 0% { background: rgba(0,217,217,.35); } 100% { background: transparent; } }

.chat-avatar-circle {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .82rem; font-weight: 700; color: #fff;
}
.agent-chat-item-info { min-width: 0; flex: 1; }
.agent-chat-item-name { font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.agent-chat-item-preview { font-size: .72rem; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.agent-thread { display: flex; flex-direction: column; min-height: 0; position: relative; }
.agent-thread-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-soft); font-size: .85rem; text-align: center; padding: 0 20px; }
.agent-thread-open { flex: 1; display: flex; flex-direction: column; min-height: 0; animation: msgIn .2s ease; }
.agent-thread-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.agent-thread-name { font-size: .88rem; font-weight: 700; }
.agent-thread-status { font-size: .72rem; color: var(--amber); }
.agent-thread-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.agent-thread-typing { padding: 0 16px 8px; font-size: .76rem; color: var(--text-soft); display: flex; align-items: center; gap: 8px; }
.agent-thread-fija-nota { padding: 8px 16px; font-size: .72rem; color: var(--text-soft); font-style: italic; border-top: 1px solid var(--border); }

/* Scrollbar dark (mismo criterio que el resto de las demos y la interfaz real) */
.client-window-body, .agent-chat-list, .agent-thread-messages {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.25) transparent;
}
.client-window-body::-webkit-scrollbar, .agent-chat-list::-webkit-scrollbar, .agent-thread-messages::-webkit-scrollbar { width: 8px; }
.client-window-body::-webkit-scrollbar-track, .agent-chat-list::-webkit-scrollbar-track, .agent-thread-messages::-webkit-scrollbar-track { background: transparent; }
.client-window-body::-webkit-scrollbar-thumb, .agent-chat-list::-webkit-scrollbar-thumb, .agent-thread-messages::-webkit-scrollbar-thumb { background-color: rgba(255,255,255,.25); border-radius: 8px; }

.footnote { max-width: 720px; margin: 40px auto 0; text-align: center; }
.footnote p { color: var(--text-soft); font-size: .78rem; line-height: 1.6; }

@media (max-width: 860px) {
  .stage:not([data-mode="mobile"]) { grid-template-columns: 1fr; }
  .intro h1 { font-size: 1.5rem; }
}

@media (max-width: 480px) {
  #btnModeDesktop { display: none; }
  .stage[data-mode="mobile"] .stage-client,
  .stage[data-mode="mobile"] .stage-agent {
    width: 100%; max-width: 100%; height: 72vh; border-radius: 0; border-width: 6px;
  }
}
