/* =================================================
  Loliando - mensajes.css (VERSIÓN COMPLETA CORREGIDA)
  ========================================================= */

:root {
  --bg-mensajes: #f8f9fa;
  --border-light: #e1e4e8;
  --primary-color: #00a650;
  --primary-hover: #008a43;
  --secondary-color: #6c757d;
  --success-color: #28a745;
  --warning-color: #ffc107;
  --danger-color: #dc3545;
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --bg-card: #ffffff;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --radius: 12px;
  --radius-sm: 6px;
  --whatsapp-green: #00a650;
  --whatsapp-light-green: #e8f5e8;
  --whatsapp-chat-bg: #e5ddd5;
  --editor-height: 62px;
}

/* ======================
   ESTILOS BASE
   ====================== */
* {
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-mensajes);
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
}

/* ======================
   ESTRUCTURA PRINCIPAL CORREGIDA
   ====================== */
.contenedor-mensajes {
  display: grid;
  grid-template-columns: 350px 1fr 300px;
  grid-template-rows: 1fr auto;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  gap: 0;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  grid-template-areas:
    "conversaciones chat info"
    "editor editor editor";
  position: relative;
  z-index: 1;
}

/* ======================
   PANEL CONVERSACIONES CON SCROLL FUNCIONAL
   ====================== */
.panel-conversaciones {
  grid-area: conversaciones;
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  transition: transform 0.3s ease;
  height: 100%;
  position: relative;
  z-index: 100;
  overflow: hidden;
}

.cabecera-panel {
  padding: 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--whatsapp-light-green);
  flex-shrink: 0;
}

.cabecera-panel h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: 1.5rem;
  font-weight: 600;
}

.btn-nuevo-mensaje {
  background: var(--whatsapp-green);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: background-color 0.2s;
}

.btn-nuevo-mensaje:hover {
  background: var(--primary-hover);
}

.buscador-conversaciones {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-light);
  background: white;
  flex-shrink: 0;
}

.buscador-conversaciones input {
  width: 100%;
  padding: 10px 15px;
  border: 1px solid var(--border-light);
  border-radius: 20px;
  font-size: 14px;
  background: #f8f9fa;
  outline: none;
  transition: border-color 0.2s;
}

.buscador-conversaciones input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(0, 166, 80, 0.1);
}

.lista-conversaciones {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  background: white;
  position: relative;
  z-index: 110;
  height: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.estado-vacio {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.icono-vacio {
  font-size: 48px;
  margin-bottom: 15px;
  opacity: 0.5;
}

.estado-vacio p {
  margin: 0 0 20px 0;
  font-size: 16px;
}

.estado-vacio .btn-primario {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
}

.estado-vacio .btn-primario:hover {
  background: var(--primary-hover);
}

.conversacion-item {
  position: relative;
  background: white;
  user-select: none;
  overflow: visible;
  z-index: 120;
  border-bottom: 1px solid var(--border-light);
}

.conversacion-item-content {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  cursor: pointer;
  transition: background-color 0.2s;
  background: white;
  position: relative;
  z-index: 130;
  width: 100%;
  min-height: 80px;
}

.conversacion-item.activa .conversacion-item-content {
  background-color: var(--whatsapp-light-green);
  border-right: 3px solid var(--whatsapp-green);
}

.conversacion-item-content:hover {
  background-color: #f8f9fa;
}

.avatar-conversacion {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color), #00c853);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
  margin-right: 15px;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar-inicial {
  font-size: 18px;
  font-weight: bold;
  color: white;
}

.info-conversacion {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.nombre-conversacion {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 15px;
}

.ultimo-mensaje {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.producto-conversacion {
  font-size: 12px;
  color: var(--primary-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.info-extra {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 10px;
  transition: all 0.3s ease;
}

.fecha-conversacion {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: opacity 0.3s ease;
}

.contador-no-leidos {
  background: var(--whatsapp-green);
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.btn-eliminar-desktop {
  display: flex;
  background: none;
  border: none;
  color: #dc3545;
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.3s ease;
  margin-left: 8px;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  background: rgba(220, 53, 69, 0.1);
  opacity: 0;
  transform: scale(0.8);
  z-index: 140;
  position: relative;
}

.btn-eliminar-desktop:hover {
  background: rgba(220, 53, 69, 0.2);
  transform: scale(1);
  color: #dc3545;
}

.conversacion-item:hover .btn-eliminar-desktop {
  opacity: 1;
  transform: scale(1);
}

.conversacion-item:hover .fecha-conversacion {
  opacity: 0;
}

.area-chat {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  background: var(--whatsapp-chat-bg);
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.cabecera-chat {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  background: #f0f0f0;
  backdrop-filter: blur(10px);
  flex: 0 0 auto;
  position: relative;
  z-index: 150;
  gap: 12px;
  height: 70px;
  width: 100%;
}

.btn-volver-conversaciones {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  color: var(--text-primary);
  border-radius: 50%;
  transition: background-color 0.2s;
  display: none;
  align-items: center;
  justify-content: center;
}

.btn-volver-conversaciones:hover {
  background: rgba(0, 0, 0, 0.1);
}

.info-chat {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.avatar-chat-link,
.nombre-chat-link {
  text-decoration: none;
  display: flex;
  align-items: center;
}

.avatar-chat-link:hover .avatar-chat,
.nombre-chat-link:hover .nombre-chat {
  transform: scale(1.05);
  color: var(--primary-color);
}

.avatar-chat-container {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.avatar-chat {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}

.avatar-chat:not(.conversacion-activa) {
  background: #cccccc;
}

.avatar-chat:not(.conversacion-activa) .avatar-chat-inicial {
  color: #666666;
}

.avatar-chat.conversacion-activa {
  background: linear-gradient(135deg, var(--primary-color), #00c853);
}

.avatar-chat.conversacion-activa .avatar-chat-inicial {
  color: white;
}

.avatar-chat-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar-chat-inicial {
  font-size: 18px;
  font-weight: bold;
  color: white;
}

.detalles-chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  cursor: pointer;
}

.nombre-chat {
  margin: 0 0 2px 0;
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s;
}

.nombre-chat-link:hover .nombre-chat {
  color: var(--primary-color);
}

.estado-chat {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.acciones-chat {
  display: flex;
  gap: 8px;
}

.btn-accion {
  background: none;
  border: 1px solid var(--border-light);
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-accion:hover {
  background: #f8f9fa;
}

.mensajes-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: transparent;
  min-height: 0;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  padding-top: 10px;
  padding-bottom: 20px;
  height: auto;
  position: relative;
}

.mensaje-bienvenida {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.icono-bienvenida {
  font-size: 64px;
  margin-bottom: 20px;
  opacity: 0.7;
}

.mensaje-bienvenida h3 {
  margin: 0 0 10px 0;
  color: var(--text-primary);
  font-size: 24px;
  font-weight: 600;
}

.mensaje-bienvenida p {
  margin: 0;
  font-size: 16px;
  max-width: 300px;
  line-height: 1.5;
}

.mensaje {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 8px;
  position: relative;
  animation: messageSlide 0.3s ease-out;
  margin: 2px 0;
  word-wrap: break-word;
}

.contenedor-adjuntos {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.contenedor-adjuntos img,
.mensaje img {
  display: block;
  width: auto;
  height: auto;
  max-width: 320px;
  max-height: 220px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.contenedor-adjuntos img.small {
  max-width: 220px;
  max-height: 160px;
}

@media (max-width: 968px) {

  .contenedor-adjuntos img,
  .mensaje img {
    max-width: calc(100vw - 120px);
    max-height: 240px;
  }
}

.mensaje.recibido {
  align-self: flex-start;
  background: white;
  border-top-left-radius: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.mensaje.enviado {
  align-self: flex-end;
  background: #dcf8c6;
  border-top-right-radius: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.cabecera-mensaje {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 12px;
  opacity: 0.8;
}

.remitente-mensaje {
  font-weight: 600;
}

.mensaje.enviado .remitente-mensaje {
  color: rgba(0, 0, 0, 0.7);
}

.mensaje.recibido .remitente-mensaje {
  color: var(--text-secondary);
}

.fecha-mensaje {
  font-size: 11px;
  margin-left: 8px;
}

.texto-mensaje {
  margin: 0;
  line-height: 1.4;
  word-wrap: break-word;
  font-size: 14px;
}

.mensaje.enviado .texto-mensaje {
  color: #000;
}

/* ======================
   EDITOR GLOBAL - MODIFICADO PARA MÓVILES
   ====================== */
.editor-global {
  grid-area: editor;
  background: #f0f0f0;
  border-top: 1px solid #ddd;
  z-index: 100;
  display: none;
  width: 100%;
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 -6px 16px rgba(0, 0, 0, 0.04);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.editor-global.visible {
  display: block !important;
}

.editor-mensajes {
  display: flex;
  align-items: center;
  padding: 10px 15px;
  gap: 8px;
  min-height: 62px;
  max-width: 1400px;
  margin: 0 auto;
  background: #f0f0f0;
}

.acciones-mensaje {
  display: flex;
  align-items: center;
}

.btn-adjuntar {
  background: none;
  border: none;
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
}

.btn-adjuntar:hover {
  background: rgba(0, 0, 0, 0.1);
}

.area-texto {
  flex: 1;
  display: flex;
  align-items: center;
}

.area-texto textarea {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 25px;
  font-size: 15px;
  outline: none;
  background: #fff;
  resize: none;
  font-family: "Segoe UI", Tahoma, sans-serif;
  max-height: 120px;
  overflow-y: auto;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn-enviar {
  border: none;
  padding: 10px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--whatsapp-green);
  color: #fff;
}

.btn-enviar:hover {
  background: var(--primary-hover);
}

.btn-enviar:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-enviar:disabled:hover {
  background: var(--whatsapp-green);
}

.panel-informacion {
  grid-area: info;
  border-left: 1px solid var(--border-light);
  background: var(--bg-card);
  display: none;
  height: 100%;
  overflow: hidden;
}

.cabecera-info {
  padding: 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cabecera-info h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
}

.btn-cerrar-info {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.btn-cerrar-info:hover {
  background: #f8f9fa;
}

.contenido-info {
  padding: 20px;
}

.info-producto-chat {
  text-align: center;
}

.info-producto-chat h4 {
  margin: 0 0 15px 0;
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
}

.info-producto-chat img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 8px;
  margin: 10px 0;
  border: 1px solid var(--border-light);
}

.info-producto-chat p {
  margin: 8px 0;
  color: var(--text-primary);
  text-align: left;
}

.info-producto-chat strong {
  color: var(--text-secondary);
}

.info-producto-chat .btn-primario {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  margin-top: 15px;
  width: 100%;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.info-producto-chat .btn-primario:hover {
  background: var(--primary-hover);
}

.adjuntos-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
  padding: 10px;
  background: #f9f9f9;
  border-radius: 10px;
  border: 1px dashed #ddd;
}

.archivo-preview {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.archivo-preview img {
  width: 100%;
  height: 70px;
  object-fit: cover;
}

.archivo-preview .nombre-archivo {
  font-size: 10px;
  padding: 4px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.9);
}

.btn-eliminar-archivo {
  position: absolute;
  top: 2px;
  right: 2px;
  background: #ff4757;
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.3s ease-out;
}

.modal-contenido {
  background-color: white;
  margin: 5% auto;
  padding: 0;
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideIn 0.3s ease-out;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.modal-cabecera {
  padding: 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-cabecera h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 20px;
  font-weight: 600;
}

.modal-cerrar {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.modal-cerrar:hover {
  background: #f8f9fa;
}

.modal-cuerpo {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary-color);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
  max-height: 200px;
}

.modal-pie {
  padding: 15px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: background-color 0.2s;
}

.btn-primario {
  background: var(--primary-color);
  color: white;
}

.btn-primario:hover {
  background: var(--primary-hover);
}

.btn-secundario {
  background: var(--secondary-color);
  color: white;
}

.btn-secundario:hover {
  background: #5a6268;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn:disabled:hover {
  background: var(--primary-color);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes messageSlide {
  from {
    transform: translateY(10px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.lista-conversaciones::-webkit-scrollbar,
.mensajes-container::-webkit-scrollbar {
  width: 6px;
}

.lista-conversaciones::-webkit-scrollbar-track,
.mensajes-container::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.lista-conversaciones::-webkit-scrollbar-thumb,
.mensajes-container::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.lista-conversaciones::-webkit-scrollbar-thumb:hover,
.mensajes-container::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

.delete-button-longpress {
  position: absolute;
  top: 50%;
  right: 20px;
  transform: translateY(-50%) scale(0.8);
  background: linear-gradient(135deg, #dc3545, #c82333);
  color: white;
  border: none;
  padding: 12px 18px;
  border-radius: 25px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  z-index: 200;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  box-shadow: 0 4px 15px rgba(220, 53, 69, 0.4);
  white-space: nowrap;
  pointer-events: auto;
  min-width: 100px;
  text-align: center;
}

.delete-button-longpress.visible {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

.delete-button-longpress:hover {
  background: linear-gradient(135deg, #c82333, #bd2130);
  transform: translateY(-50%) scale(1.05);
  box-shadow: 0 6px 20px rgba(220, 53, 69, 0.5);
}

.conversacion-item.show-delete-button .conversacion-item-content {
  background-color: #fff5f5;
  border-right: 3px solid #dc3545;
  padding-right: 120px;
}

.conversacion-item:active .conversacion-item-content {
  background-color: #f8f9fa;
}

@keyframes longPressPulse {
  0% {
    background-color: white;
  }

  50% {
    background-color: #fff5f5;
  }

  100% {
    background-color: white;
  }
}

.conversacion-item.long-press-active .conversacion-item-content {
  animation: longPressPulse 0.5s ease-in-out;
}

.conversacion-item {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

@keyframes longPressPulse {
  0% {
    background-color: white;
  }

  50% {
    background-color: #fff5f5;
  }

  100% {
    background-color: white;
  }
}

.conversacion-item.long-press-active .conversacion-item-content {
  animation: longPressPulse 0.5s ease-in-out;
}

/* ======================
   VERSIÓN MÓVIL - ESTILO WHATSAPP (FINAL)
   ====================== */
@media (max-width: 968px) {

  /* Bloquear scroll del body */
  body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
  }

  /* Contenedor principal - Ocupa toda la pantalla */
  .contenedor-mensajes {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    background: #fff;
    z-index: 9999;
    display: flex;
    flex-direction: column;
  }

  /* Área de chat - Flex container */
  .area-chat {
    position: relative;
    flex: 1;
    display: none;
    /* Oculto por defecto en móvil */
    flex-direction: column;
    overflow: hidden;
    height: 100%;
  }

  /* Cabecera - SIEMPRE VISIBLE ARRIBA */
  .cabecera-chat {
    position: relative;
    flex-shrink: 0;
    z-index: 1002;
    height: 60px;
    background: var(--whatsapp-green);
    width: 100%;
  }

  /* Contenedor de mensajes - SCROLL AQUÍ */
  .mensajes-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    /* Normal order */
    padding: 15px 10px;
    padding-bottom: 20px;
    /* Espacio extra al final */
    background: var(--whatsapp-chat-bg);
    -webkit-overflow-scrolling: touch;
  }

  /* Editor - SIEMPRE VISIBLE ABAJO DENTRO DEL FLEX */
  .editor-global {
    position: relative;
    flex-shrink: 0;
    z-index: 1002;
    background: #f0f0f0;
    border-top: 1px solid #ddd;
    padding-bottom: env(safe-area-inset-bottom, 20px);
    display: flex !important;
    /* Flex para alinear contenido */
    width: 100%;
  }

  /* Ocultar editor si no estamos en modo chat (aunque al estar dentro de area-chat ya se oculta con él) */
  .area-chat[style*="display: none"] .editor-global {
    display: none !important;
  }

  /* Ajustes para cuando el teclado está abierto (viewport resize) */
  @media (interactive-widget: resizes-content) {
    .contenedor-mensajes {
      height: 100dvh;
    }
  }
}

.editor-global.visible {
  display: block !important;
}

.editor-mensajes {
  padding: 12px 15px;
  min-height: 70px;
  max-width: 100%;
  margin: 0;
  background: #f0f0f0;
  gap: 10px;
}

.area-texto textarea {
  padding: 12px 16px;
  font-size: 16px;
  border-radius: 20px;
  border: 1px solid #ddd;
}

.btn-adjuntar,
.btn-enviar {
  width: 44px;
  height: 44px;
  font-size: 22px;
}

.panel-conversaciones {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 400;
  transform: translateX(0);
  /* Visible por defecto */
  transition: transform 0.3s ease;
  border-right: none;
  display: flex !important;
  overflow: hidden;
}

.lista-conversaciones {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  background: white;
  min-height: 0;
  position: relative;
  z-index: 410;
  height: auto !important;
  -webkit-overflow-scrolling: touch;
}

/* Clase para ocultar el panel cuando se abre el chat */
.panel-conversaciones.mobile-hidden {
  transform: translateX(-100%);
}

/* Visibilidad gestionada por JS, pero aseguramos flex cuando es visible */
.area-chat.mobile-visible {
  display: flex !important;
}

.btn-volver-conversaciones {
  display: flex !important;
}

.panel-informacion {
  display: none !important;
}

.conversacion-item {
  padding: 12px 15px;
  overflow: visible;
  z-index: 420;
}

.conversacion-item-content {
  background: white;
  position: relative;
  z-index: 430;
  width: 100%;
  min-height: 80px;
  padding: 15px 20px;
}

.btn-eliminar-desktop {
  display: none !important;
}

.fecha-conversacion {
  opacity: 1 !important;
}

.conversacion-item {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.avatar-conversacion,
.avatar-chat {
  width: 40px;
  height: 40px;
  font-size: 16px;
}

.avatar-conversacion {
  margin-right: 12px;
}

.nombre-conversacion,
.nombre-chat {
  font-size: 16px;
}

.ultimo-mensaje {
  font-size: 14px;
}

.cabecera-panel {
  padding: 15px;
  background: var(--whatsapp-green);
  color: white;
}

.cabecera-panel h2 {
  color: white;
  font-size: 20px;
}

.btn-nuevo-mensaje {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.btn-nuevo-mensaje:hover {
  background: rgba(255, 255, 255, 0.3);
}

.acciones-chat {
  display: none;
}


/* ======================
   MÓVIL PEQUEÑO - EDITOR MEJORADO
   ====================== */
@media (max-width: 480px) {
  .cabecera-chat {
    padding: 8px 12px;
    height: 55px;
  }

  .mensajes-container {
    padding: 10px 8px;
    padding-bottom: 110px;
  }

  .mensaje {
    max-width: 90%;
    padding: 5px 8px;
  }

  .editor-global {
    padding-bottom: max(18px, env(safe-area-inset-bottom, 18px));
  }

  .editor-mensajes {
    padding: 10px 12px;
    min-height: 65px;
  }

  .area-texto textarea {
    padding: 10px 14px;
    font-size: 15px;
  }

  .btn-adjuntar,
  .btn-enviar {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .avatar-conversacion,
  .avatar-chat {
    width: 35px;
    height: 35px;
    font-size: 14px;
  }

  .nombre-chat {
    font-size: 15px;
  }

  .conversacion-item {
    padding: 10px 12px;
  }

  .avatar-conversacion {
    width: 35px;
    height: 35px;
    font-size: 14px;
    margin-right: 10px;
  }

  .delete-button-longpress {
    right: 12px;
    padding: 8px 14px;
    font-size: 12px;
    min-width: 80px;
  }

  .conversacion-item.show-delete-button .conversacion-item-content {
    padding-right: 100px;
  }
}

/* ======================
   SAFARI iOS - EDITOR ESPECÍFICO
   ====================== */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 968px) {
    .editor-global {
      padding-bottom: max(25px, env(safe-area-inset-bottom, 25px));
    }

    .mensajes-container {
      height: calc(100vh - 150px) !important;
      padding-bottom: 110px;
    }

    .area-texto textarea {
      font-size: 16px;
      line-height: 1.4;
    }

    body {
      padding-bottom: calc(68px + max(20px, env(safe-area-inset-bottom))) !important;
    }
  }
}

/* ======================
   ANDROID CHROME - AJUSTES ESPECÍFICOS
   ====================== */
@supports not (-webkit-touch-callout: none) {
  @media (max-width: 968px) {
    .editor-global {
      padding-bottom: max(15px, env(safe-area-inset-bottom, 15px));
    }

    .editor-mensajes {
      padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
    }
  }
}

/* ======================
   SOPORTE PARA SAFE AREAS
   ====================== */
@supports (padding: max(0px)) {
  @media (max-width: 968px) {
    .editor-global {
      padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
    }

    body {
      padding-bottom: env(safe-area-inset-bottom);
    }

    .contenedor-mensajes {
      padding-bottom: env(safe-area-inset-bottom);
    }
  }
}

.lista-conversaciones,
.mensajes-container {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch !important;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  height: auto;
  min-height: 0;
  flex: 1;
}

@supports (-webkit-touch-callout: none) {

  .lista-conversaciones,
  .mensajes-container {
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }
}

.lista-conversaciones *,
.mensajes-container * {
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

@media (max-width: 968px) {
  .lista-conversaciones {
    height: calc(100vh - 130px) !important;
    max-height: none !important;
  }

  .mensajes-container {
    height: calc(100vh - 130px) !important;
    max-height: none !important;
  }

  .conversacion-item:active {
    background-color: #f8f9fa;
  }

  .conversacion-item.show-delete-button:active {
    background-color: #fff5f5;
  }

  .delete-button-longpress {
    z-index: 250;
  }

  .delete-button-longpress {
    right: 15px;
    padding: 10px 16px;
    font-size: 13px;
    min-width: 90px;
    z-index: 250;
  }

  .conversacion-item.show-delete-button .conversacion-item-content {
    padding-right: 110px;
    transition: padding-right 0.3s ease;
  }

  .conversacion-item:active {
    background-color: #f8f9fa;
  }

  .conversacion-item.show-delete-button:active {
    background-color: #fff5f5;
  }
}

.panel-conversaciones,
.area-chat {
  min-height: 0;
  overflow: hidden;
}

.oculto {
  display: none !important;
}

.visible {
  display: block !important;
}

.flex {
  display: flex;
}

.texto-centro {
  text-align: center;
}

.auto-resize {
  resize: none;
  overflow-y: auto;
  min-height: 40px;
  max-height: 120px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

html {
  scroll-behavior: smooth;
}

.conversacion-item {
  position: relative;
  overflow: visible !important;
}

.conversacion-item-content {
  position: relative;
  z-index: 130;
  transition: all 0.3s ease;
}

@media (max-width: 968px) {
  .conversacion-item {
    z-index: 120;
  }

  .delete-button-longpress {
    z-index: 300;
  }

  .conversacion-item.show-delete-button {
    z-index: 350;
  }
}

#nuevoDestinatario {
  font-family: 'Courier New', monospace;
  letter-spacing: 0.5px;
}

#nuevoDestinatario:focus {
  border-color: #4CAF50;
  box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

#nuevoDestinatario::placeholder {
  color: #999;
  font-style: italic;
  font-size: 0.9em;
}

.info-archivo {
  flex: 1;
  min-width: 0;
}

.nombre-archivo {
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tamaño-archivo {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
}

.archivo-preview {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e9ecef;
  min-width: 0;
  flex: 1;
}

.archivo-preview img {
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.icono-archivo {
  font-size: 24px;
  flex-shrink: 0;
}

.btn-eliminar-archivo {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ff4757;
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.adjuntos-preview {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  max-height: 200px;
  overflow-y: auto;
}