/* ==========================================================================
   Chat en vivo - Te Gestiona
   Usa las variables de style.css (--bg, --accent, --border, ...)
   ========================================================================== */

body.chat-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px 420px at 15% -10%, rgba(43, 138, 143, 0.07), transparent 60%),
    var(--bg);
}
body.chat-page .site-header { flex: 0 0 auto; }

.rt-wrap { flex: 1 1 auto; width: 100%; padding: 26px 16px 34px; }

.rt-shell {
  max-width: 880px;
  margin: 0 auto;
  height: calc(100vh - 210px);
  min-height: 470px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- cabecera ---------- */
.rt-head { padding: 18px 20px 14px; gap: 1px; }
.rt-head .spec-avatar { width: 62px; height: 62px; border-width: 2px; margin-bottom: 9px; }
.rt-head .spec-name { font-size: 1.06rem; }
.rt-head .spec-role { font-size: 0.85rem; }
.rt-head .spec-status { margin-top: 5px; font-size: 0.78rem; }

/* ---------- aviso de error ---------- */
.rt-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 16px;
  background: #fdecea;
  color: #8f2016;
  border-bottom: 1px solid #f3c8c2;
  font-size: 0.85rem;
}
.rt-alert[hidden] { display: none; }
.rt-retry {
  background: #8f2016;
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

/* ---------- zona de mensajes ---------- */
.rt-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  overflow-anchor: none;
  padding: 18px 20px 22px;
  background:
    linear-gradient(180deg, rgba(240, 247, 247, 0.55), rgba(250, 250, 249, 0));
  scrollbar-width: thin;
}
.rt-day {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 14px;
  align-self: center;
  margin: 0 auto 16px;
  display: inline-block;
  width: fit-content;
}
#rtFeed { display: flex; flex-direction: column; gap: 14px; }

.rt-body .bubble {
  max-width: 84%;
  overflow-wrap: anywhere;
  line-height: 1.55;
  animation: rtIn 0.25s ease both;
  box-shadow: 0 2px 8px rgba(26, 26, 26, 0.05);
}
.rt-body .bubble p { margin: 0 0 8px; }
.rt-body .bubble p:last-child { margin-bottom: 0; }
.rt-body .bubble ul { margin: 6px 0 4px; padding-left: 18px; }
.rt-body .bubble li { margin: 3px 0; }
.rt-body .bubble b { font-weight: 800; }
.rt-body .bubble h4 {
  margin: 14px 0 6px;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--accent-deep);
  letter-spacing: 0.01em;
}
.rt-body .bubble h4:first-child { margin-top: 0; }
.rt-body .bubble code {
  background: rgba(26, 26, 26, 0.07);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.88em;
}
.rt-body .bubble.user code { background: rgba(255, 255, 255, 0.22); }
.rt-body .bubble pre {
  background: #1f2937;
  color: #e5e7eb;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.82rem;
  margin: 6px 0;
}
.rt-body .bubble.user pre { background: rgba(255, 255, 255, 0.2); color: #fff; }
.rt-body .bubble a { color: var(--accent-deep); font-weight: 700; }
.rt-body .bubble.user a { color: #eafafa; }

@keyframes rtIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- el caso del cliente queda fijado arriba ---------- */
.rt-body .bubble.rt-case {
  position: sticky;
  top: 0;
  z-index: 4;
  max-height: 38vh;
  overflow-y: auto;
  box-shadow: 0 6px 20px rgba(26, 26, 26, 0.16);
}
.rt-case-tag {
  display: block;
  margin-bottom: 6px;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.8;
}

/* ---------- indicador de escritura ---------- */
.rt-typing { display: inline-flex; align-items: center; gap: 5px; padding: 5px 3px; }
.rt-typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  opacity: 0.3;
  animation: rtDot 1.2s infinite ease-in-out;
}
.rt-typing i:nth-child(2) { animation-delay: 0.18s; }
.rt-typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes rtDot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-4px); }
}

/* ---------- redacción ---------- */
.rt-composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-alt);
}
.rt-label {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.rt-composer textarea {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.45;
  max-height: 140px;
  overflow-y: auto;
}
.rt-composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(43, 138, 143, 0.15);
}
.rt-composer textarea:disabled { background: var(--surface-2); color: var(--muted); }
.rt-send { flex: 0 0 auto; padding: 12px 22px; border-radius: 12px; }

/* ---------- pie ---------- */
.rt-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.73rem;
  color: var(--muted);
}
.rt-clear {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 0.72rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.rt-clear:hover { border-color: var(--red); color: var(--red); }

/* ---------- móvil ---------- */
@media (max-width: 640px) {
  .rt-wrap { padding: 14px 10px 20px; }
  .rt-shell { height: calc(100vh - 160px); min-height: 420px; border-radius: 12px; }
  .rt-head { padding: 14px 16px 12px; }
  .rt-head .spec-avatar { width: 50px; height: 50px; }
  .rt-head .spec-name { font-size: 0.98rem; }
  .rt-body { padding: 16px 12px 18px; }
  .rt-body .bubble { max-width: 92%; font-size: 0.9rem; }
  .rt-composer { padding: 10px; gap: 8px; }
  .rt-composer textarea { font-size: 16px; } /* evita el zoom automático en iOS */
  .rt-send { padding: 11px 15px; }
  .rt-foot { flex-direction: column; align-items: flex-start; gap: 7px; }
}
