/* ==========================================================================
   CHAT DIAMANTE v1.0 — capa visual del chat propio de eXpertoTelceL
   Encargo 62. Solo estilo: no toca JS, ni backend, ni el lanzador.
   Objetivo: quitar la piel de WhatsApp del hilo y adoptar el ritmo de lectura
   de una app de asistente (respuesta sin burbuja, ancho completo, aire).
   ========================================================================== */

/* --- Tokens ------------------------------------------------------------- */
#claudio-wa-chat {
  --cd-superficie: #ffffff;
  --cd-tinta: #1f1f1f;
  --cd-tinta-suave: #5f6368;
  --cd-burbuja-visitante: #f2f0f0;
  --cd-linea: #e3e3e3;
  --cd-cian: #00bfff;
  --cd-fuente: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

/* --- Lienzo de la conversación ------------------------------------------ */
html body #claudio-wa-chat .cwa-messages {
  background: var(--cd-superficie);
  padding: 20px 18px 24px;
  gap: 20px;
  scroll-behavior: smooth;
}

/* --- Mensaje: base sin herencia de mensajería ---------------------------- */
html body #claudio-wa-chat .cwa-msg {
  max-width: 100%;
  box-shadow: none;
  font-family: var(--cd-fuente);
  font-size: 17px;
  line-height: 24px;
  letter-spacing: normal;
}

/* --- CLAUDIO: texto plano, ancho completo, sin burbuja ------------------- */
html body #claudio-wa-chat .cwa-msg-bot {
  background: transparent;
  color: var(--cd-tinta);
  border-radius: 0;
  border-top-left-radius: 0;
  padding: 0;
  align-self: stretch;
  max-width: 100%;
  box-shadow: none;
}

/* --- Visitante: única burbuja, gris neutro, alineada a la derecha -------- */
html body #claudio-wa-chat .cwa-msg-user {
  background: var(--cd-burbuja-visitante);
  color: var(--cd-tinta);
  border-radius: 20px;
  border-top-right-radius: 20px;
  padding: 12px 18px;
  max-width: 85%;
  align-self: flex-end;
  box-shadow: none;
}

/* --- Fuera reloj y acuses de lectura ------------------------------------ */
html body #claudio-wa-chat .cwa-msg-time,
html body #claudio-wa-chat .cwa-msg-check,
html body #claudio-wa-chat .cwa-msg-check.leido {
  display: none;
}

/* --- Avisos de sistema: discretos, sin cursiva de mensajería ------------- */
html body #claudio-wa-chat .cwa-msg-system {
  font-style: normal;
  font-size: 12.5px;
  line-height: 18px;
  color: var(--cd-tinta-suave);
  background: transparent;
  padding: 4px 0;
}

/* --- Tipografía interna de la respuesta --------------------------------- */
html body #claudio-wa-chat .cwa-msg-bot p {
  margin: 0 0 12px;
}
html body #claudio-wa-chat .cwa-msg-bot p:last-child {
  margin-bottom: 0;
}
html body #claudio-wa-chat .cwa-msg-bot h1,
html body #claudio-wa-chat .cwa-msg-bot h2,
html body #claudio-wa-chat .cwa-msg-bot h3,
html body #claudio-wa-chat .cwa-msg-bot h4 {
  font-size: 19px;
  line-height: 26px;
  font-weight: 500;
  color: var(--cd-tinta);
  margin: 22px 0 8px;
}
html body #claudio-wa-chat .cwa-msg-bot h1:first-child,
html body #claudio-wa-chat .cwa-msg-bot h2:first-child,
html body #claudio-wa-chat .cwa-msg-bot h3:first-child {
  margin-top: 0;
}
html body #claudio-wa-chat .cwa-msg-bot strong,
html body #claudio-wa-chat .cwa-msg-bot b {
  font-weight: 600;
  color: var(--cd-tinta);
}
html body #claudio-wa-chat .cwa-msg-bot ul,
html body #claudio-wa-chat .cwa-msg-bot ol {
  margin: 0 0 12px;
  padding-left: 22px;
}
html body #claudio-wa-chat .cwa-msg-bot li {
  margin-bottom: 8px;
}
html body #claudio-wa-chat .cwa-msg-bot li::marker {
  color: var(--cd-tinta-suave);
}
html body #claudio-wa-chat .cwa-msg-bot a {
  color: #0072e6;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* --- Tablas aireadas, sin rejilla --------------------------------------- */
html body #claudio-wa-chat .cwa-msg-bot table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0 14px;
  font-size: 15px;
  line-height: 21px;
}
html body #claudio-wa-chat .cwa-msg-bot th,
html body #claudio-wa-chat .cwa-msg-bot td {
  text-align: left;
  padding: 10px 12px 10px 0;
  border: 0;
  border-bottom: 1px solid var(--cd-linea);
  vertical-align: top;
}
html body #claudio-wa-chat .cwa-msg-bot th {
  font-weight: 500;
  color: var(--cd-tinta-suave);
}
html body #claudio-wa-chat .cwa-msg-bot tr:last-child td {
  border-bottom: 0;
}

/* --- "CLAUDIO está escribiendo": tres puntos, sin burbuja --------------- */
html body #claudio-wa-chat .cwa-typing {
  background: transparent;
  border-radius: 0;
  padding: 2px 0 6px;
  box-shadow: none;
}
html body #claudio-wa-chat .cwa-typing span {
  background: var(--cd-tinta-suave);
}

/* --- Barra de escritura: píldora limpia ---------------------------------
   Nota de verificación: el área segura del teléfono NO se toca aquí. El
   widget ya trae, y funciona, `@media (max-width:480px) { .cwa-input-area
   { padding: max(8px, env(safe-area-inset-bottom)) } }`. Duplicarlo con un
   calc() propio lo rompía: env() no resuelve dentro de un iframe y la
   declaración se descartaba. Se deja el original en paz.                  */
html body #claudio-wa-chat .cwa-input-area {
  background: var(--cd-superficie);
  border-top: 1px solid var(--cd-linea);
}
/* La caja de escribir conserva su tipografía original a propósito: es angosta
   (168 px entre los botones) y Poppins hace saltar el texto a dos líneas. */
html body #claudio-wa-chat .cwa-input {
  border-radius: 24px;
}

/* --- Cabecera: mismo azul, respiración de app --------------------------- */
html body #claudio-wa-chat .cwa-name,
html body #claudio-wa-chat .cwa-status {
  font-family: var(--cd-fuente);
}

/* --- Móvil: el hilo se lee a ancho de teléfono -------------------------- */
@media (max-width: 640px) {
  html body #claudio-wa-chat .cwa-messages {
    padding: 18px 16px 22px;
    gap: 18px;
  }
  html body #claudio-wa-chat .cwa-msg {
    font-size: 16.5px;
    line-height: 24px;
  }
  html body #claudio-wa-chat .cwa-msg-user {
    max-width: 88%;
  }
}

/* --- Accesibilidad: respeta "reducir movimiento" ------------------------ */
@media (prefers-reduced-motion: reduce) {
  html body #claudio-wa-chat .cwa-messages {
    scroll-behavior: auto;
  }
}

/* ==========================================================================
   v1.1 — Encargo 101: "la ✕ no minimiza el chat" (reportado desde iPhone)
   --------------------------------------------------------------------------
   La lógica de cerrar SIEMPRE funcionó: un click sobre #cwa-close-btn quita
   la clase .open, oculta el panel y conserva cid e historial. Verificado.
   El defecto era de puntería, no de código, y por eso el arreglo anterior
   —hecho sobre el JS— no cambió nada:

     · la ✕ medía 32x32 px (el mínimo táctil es 44: Apple HIG y WCAG 2.5.5)
     · a solo 14 px tenía el botón ⛶ de expandir
     · y ⛶ NO HACE NADA en teléfono: bajo 480px .cwa-expanded aplica
       100vw / 100dvh / inset:0, que es exactamente lo que el panel abierto
       ya es. Un pulgar que fallaba por 3 mm daba en ⛶ y no pasaba nada.

   Sin señal de error, el contacto concluye "la ✕ no sirve". Y tenía razón.
   ========================================================================== */
@media (max-width: 480px) {
  /* Fuera el botón que no hace nada aquí y que se robaba los toques. */
  html body #claudio-wa-chat .cwa-expand {
    display: none;
  }
  /* 44x44 reales de área tocable, sin agrandar el icono. */
  html body #claudio-wa-chat .cwa-close,
  html body #claudio-wa-chat .cwa-menu {
    min-width: 44px;
    min-height: 44px;
    flex: 0 0 auto;
  }
  html body #claudio-wa-chat .cwa-header {
    gap: 10px;
  }
}
