/* ============================================================
   detail.css  –  Panel de detalle (solo lectura)
   - Hilo de mensajes (Mensajes Directos / Correos), estilo WhatsApp
   - Vista de llamada (resumen + transcripción)
   ============================================================ */

.detail-body {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  background: var(--wa-bg);
}

/* ── Hilo de mensajes ────────────────────────────────────────── */
.detail-thread {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 100%;
  min-width: 0;
}

.wa-date-sep { display: flex; align-items: center; justify-content: center; margin: 8px 0; }
.wa-date-sep span {
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(4px);
  color: var(--gray-600);
  font-size: .72rem;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: var(--r-full);
  box-shadow: var(--shadow-sm);
}

.wa-bubble-wrap { display: flex; margin: 1px 0; min-width: 0; animation: bubbleIn 200ms cubic-bezier(.4,0,.2,1) both; }
.wa-bubble-wrap.in  { justify-content: flex-start; }
.wa-bubble-wrap.out { justify-content: flex-end; }
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

.wa-bubble {
  max-width: 68%;
  min-width: 0;
  padding: 7px 10px 18px;
  border-radius: 8px;
  position: relative;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(18,33,31,.14);
  line-height: 1.45;
}
.wa-bubble-wrap.in  .wa-bubble { background: var(--wa-in);  border-top-left-radius: 2px; }
.wa-bubble-wrap.out .wa-bubble { background: var(--wa-out); border-top-right-radius: 2px; }

.wa-bubble::before { content: ''; position: absolute; top: 0; width: 0; height: 0; }
.wa-bubble-wrap.in  .wa-bubble::before { left: -8px;  border-top: 8px solid var(--wa-in);  border-left: 8px solid transparent; }
.wa-bubble-wrap.out .wa-bubble::before { right: -8px; border-top: 8px solid var(--wa-out); border-right: 8px solid transparent; }

.wa-bubble-asunto { font-size: .74rem; font-weight: 700; color: var(--brand-700); margin-bottom: 3px; }
.wa-bubble-text { font-family: var(--font-ui); font-size: .88rem; color: var(--gray-800); }
.wa-bubble-meta {
  position: absolute; bottom: 4px; right: 10px;
  color: var(--gray-500); font-size: .66rem; white-space: nowrap;
}

/* Mensaje escrito por una persona del equipo desde la web (no por Sara) */
.wa-bubble-equipo { background: var(--brand-50); border: 1px solid var(--brand-100); }
.wa-bubble-wrap.out .wa-bubble-equipo::before { border-top-color: var(--brand-50); }
.wa-bubble-label {
  font-size: .64rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--brand-700); margin-bottom: 2px;
}
.wa-envio { font-size: .72rem; margin-left: 2px; }
.wa-envio-error { color: var(--red-600); }

/* Resumen de la conversación (lo escribe el backend), bajo el nombre en la cabecera */
.detail-header-resumen {
  display: block;
  font-size: .72rem; font-style: italic; color: var(--gray-500);
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Caja para escribir como "equipo" (solo WhatsApp) */
.detail-compose {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-0);
  flex-shrink: 0;
}
.detail-compose[hidden] { display: none; }
.detail-compose textarea {
  flex: 1; resize: none;
  min-height: 38px; max-height: 90px;
  border: 1.5px solid var(--gray-200); border-radius: var(--r-lg);
  padding: 9px 14px; font-size: .85rem; line-height: 1.3;
  color: var(--tinta); background: var(--gray-50);
}
.detail-compose textarea:focus { outline: none; border-color: var(--brand-500); background: #fff; }
.detail-compose button {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: var(--brand-600); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-fast);
}
.detail-compose button:hover:not(:disabled) { background: var(--brand-700); }
.detail-compose button:disabled { opacity: .5; cursor: default; }
.detail-compose button svg { width: 17px; height: 17px; }

/* ── Vista de llamada ────────────────────────────────────────── */
.detail-call { padding: 16px 20px 24px; background: var(--hueso); min-height: 100%; }
.call-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.call-chip {
  font-size: .68rem; font-weight: 700; letter-spacing: .04em;
  padding: 2px 9px; border-radius: var(--r-full);
  background: var(--amber-100); color: var(--amber-700);
}
.call-summary { padding: 14px 16px; border-radius: var(--r-lg); background: var(--brand-50); border: 1px solid var(--brand-100); margin-bottom: 16px; }
.call-label { font-size: .68rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--brand-600); margin-bottom: 5px; }
.call-summary-text { font-size: .85rem; line-height: 1.5; color: var(--tinta); }

.call-transcript { display: flex; flex-direction: column; gap: 8px; }
.call-turn { max-width: 82%; padding: 7px 11px 8px; border-radius: 12px; }
.call-turn-who { font-size: .64rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 2px; }
.call-turn-text { font-size: .85rem; line-height: 1.45; color: var(--tinta); word-break: break-word; }
.call-turn.contacto  { align-self: flex-start; background: #fff; border-top-left-radius: 3px; box-shadow: var(--shadow-sm); }
.call-turn.contacto  .call-turn-who { color: var(--gray-600); }
.call-turn.asistente { align-self: flex-end; background: var(--amber-100); border-top-right-radius: 3px; }
.call-turn.asistente .call-turn-who { color: var(--amber-700); text-align: right; }
.call-empty { font-size: .85rem; color: var(--gray-500); }

/* Quién/por qué terminó la llamada (campo motivo_fin): cuadro centrado
   debajo de la transcripción, texto tal cual viene de la base de datos. */
.call-motivo-fin {
  margin: 18px auto 0;
  width: fit-content;
  max-width: 80%;
  padding: 8px 16px;
  border-radius: var(--r-md);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  color: var(--gray-600);
  font-size: .78rem;
  font-weight: 600;
  text-align: center;
}

/* "Responder por WhatsApp" desde el detalle de una llamada ───────────── */
.call-actions { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 18px; }
.call-actions-hint {
  max-width: 420px;
  text-align: center;
  font-size: .72rem;
  line-height: 1.35;
  color: var(--gray-500);
}
.btn-responder-whatsapp {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--r-full);
  background: var(--brand-500);
  color: #fff;
  font-size: .82rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  transition: background var(--t-fast);
}
.btn-responder-whatsapp svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-responder-whatsapp:hover:not(:disabled) { background: var(--brand-600); }
.btn-responder-whatsapp:disabled { opacity: .6; cursor: default; }

/* ── Icono de canal en la cabecera de detalle (color según vía) ─ */
.detail-header-canal.whatsapp { background: var(--brand-100); color: var(--brand-700); }
.detail-header-canal.email    { background: var(--amber-100); color: var(--amber-700); }
.detail-header-canal.llamada  { background: var(--gray-100);  color: var(--gray-600); }
