/* =================================================
  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);
}

/* ✅ CORRECCIÓN CRÍTICA: LISTA CONVERSACIONES CON SCROLL FUNCIONAL */
.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;
}

/* ======================
   ITEMS DE CONVERSACIÓN
   ====================== */
.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;
}

/* ======================
   BOTONES ELIMINAR CONVERSACIÓN
   ====================== */
.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;
}

/* ======================
   ÁREA DE CHAT CON SCROLL FUNCIONAL
   ====================== */
.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;
}

/* ✅ CORRECCIÓN CRÍTICA: CONTENEDOR MENSAJES CON SCROLL FUNCIONAL */
.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;
}

/* ======================
   MENSAJES INDIVIDUALES
   ====================== */
.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;
}

/* ======================
   ADJUNTOS (IMAGENES EN CONVERSACIÓN)
   ====================== */
/* Container for attachments inside a message */
.contenedor-adjuntos {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

/* Attachment image previews: limit size, preserve aspect ratio */
.contenedor-adjuntos img,
.mensaje img {
  display: block;
  width: auto;
  height: auto;
  max-width: 320px;   /* desktop max width for previews */
  max-height: 220px;  /* desktop max height */
  border-radius: 8px;
  object-fit: cover;   /* crop to fill the box if necessary */
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* If multiple attachments, scale them down to fit nicely */
.contenedor-adjuntos img.small {
  max-width: 220px;
  max-height: 160px;
}

/* Mobile adjustments: make previews wider relative to the screen */
@media (max-width: 968px) {
  .contenedor-adjuntos img,
  .mensaje img {
    max-width: calc(100vw - 120px); /* allow large previews but leave space for padding/header */
    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
   ====================== */
.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 INFORMACIÓN
   ====================== */
.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);
}

/* ======================
   COMPONENTES ADICIONALES
   ====================== */
.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
   ====================== */
.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);
}

/* ======================
   ANIMACIONES
   ====================== */
@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; }
}

/* ======================
   SCROLLBARS
   ====================== */
.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;
}

/* ======================
   BOTÓN ELIMINAR LONG PRESS (CORRECCIÓN COMPLETA)
   ====================== */

.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);
}

/* Estado cuando se muestra el botón eliminar */
.conversacion-item.show-delete-button .conversacion-item-content {
    background-color: #fff5f5;
    border-right: 3px solid #dc3545;
    padding-right: 120px; /* ✅ ESPACIO para el botón */
}

/* Feedback visual durante el long press */
.conversacion-item:active .conversacion-item-content {
    background-color: #f8f9fa;
}

/* Animación sutil para el long press */
@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;
}

/* Prevenir selection de texto durante long press */
.conversacion-item {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ✅ ANIMACIÓN SUTIL PARA EL LONG PRESS */
@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 CORREGIDA
   ====================== */
@media (max-width: 968px) {
  .contenedor-mensajes {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    grid-template-areas: 
      "chat"
      "editor";
    height: 100vh;
    position: relative;
    overflow: hidden;
  }
  
  .area-chat {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  
  .cabecera-chat {
    position: sticky;
    top: 0;
    left: 0;
    width: 100%;
    background: var(--whatsapp-green);
    color: white;
    border-bottom: none;
    z-index: 200;
    flex-shrink: 0;
    height: 60px;
    padding: 10px 15px;
  }
  
  .cabecera-chat .detalles-chat .nombre-chat {
    color: white;
    margin: 0;
    font-size: 16px;
  }

  .cabecera-chat .estado-chat {
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
  }

  .cabecera-chat .btn-accion {
    color: white;
    border: none;
    background: rgba(255, 255, 255, 0.2);
  }

  .cabecera-chat .btn-accion:hover {
    background: rgba(255, 255, 255, 0.3);
  }

  /* ✅ CORRECCIÓN CRÍTICA: MENSAJES CONTAINER EN MÓVIL */
  .mensajes-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px 10px;
    gap: 6px;
    min-height: 0;
    height: auto !important;
    padding-bottom: 20px;
    -webkit-overflow-scrolling: touch;
  }

  .editor-global {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    background: #f0f0f0;
    border-top: 1px solid #ddd;
    z-index: 300;
    display: none;
  }

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

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

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

  .mensaje {
    max-width: 85%;
    padding: 6px 10px;
  }

  .texto-mensaje {
    font-size: 15px;
  }

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

  /* ✅ CORRECCIÓN CRÍTICA: LISTA CONVERSACIONES EN MÓVIL */
  .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;
  }

  .panel-conversaciones.mobile-visible {
    transform: translateX(0);
  }

  .area-chat.mobile-hidden {
    display: none;
  }

  .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;
  }

  /* Ocultar botón eliminar de desktop en móvil */
  .btn-eliminar-desktop {
    display: none !important;
  }
  
  /* Mostrar siempre la fecha en móvil */
  .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
   ====================== */
@media (max-width: 480px) {
  .cabecera-chat {
    padding: 8px 12px;
    height: 55px;
  }

  .mensajes-container {
    height: calc(100vh - 125px) !important;
    padding: 10px 8px;
    padding-bottom: 75px;
  }

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

  .editor-mensajes {
    padding: 8px;
    min-height: 55px;
  }

  .area-texto textarea {
    padding: 8px 12px;
  }

  .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; /* ✅ MENOS ESPACIO en móvil pequeño */
    }
}

/* ======================
   SAFARI iOS
   ====================== */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 968px) {
    .mensajes-container {
      height: calc(100vh - 140px) !important;
      padding-bottom: 90px;
    }
    
    .editor-global {
      padding-bottom: env(safe-area-inset-bottom);
    }
  }
}

/* ======================
   CORRECCIONES ESPECÍFICAS PARA SCROLL
   ====================== */

/* ✅ GARANTIZAR QUE LOS CONTENEDORES DE SCROLL FUNCIONEN */
.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;
}

/* ✅ PREVENIR PROBLEMAS DE RENDER EN iOS */
@supports (-webkit-touch-callout: none) {
  .lista-conversaciones,
  .mensajes-container {
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }
}

/* ✅ MEJORAR RENDIMIENTO DEL SCROLL */
.lista-conversaciones *,
.mensajes-container * {
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

/* ✅ CORRECCIÓN: ELIMINAR CONFLICTOS DE ALTURA */
@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;
    }
    
    /* Asegurar que el botón sea clickeable en móvil */
    .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; /* ✅ ESPACIO para el botón en móvil */
        transition: padding-right 0.3s ease;
    }
    
    /* Mejorar el feedback táctil en móvil */
    .conversacion-item:active {
        background-color: #f8f9fa;
    }
    
    .conversacion-item.show-delete-button:active {
        background-color: #fff5f5;
    }
}

/* ✅ GARANTIZAR QUE LOS CONTENEDORES PADRES NO INTERFIERAN */
.panel-conversaciones,
.area-chat {
  min-height: 0;
  overflow: hidden;
}

/* ======================
   UTILIDADES
   ====================== */
.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;
}

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

html {
  scroll-behavior: smooth;
}

/* ======================
   CORRECCIÓN ESPECÍFICA PARA POSICIONAMIENTO DEL BOTÓN
   ====================== */

.conversacion-item {
    position: relative;
    overflow: visible !important; /* ✅ PERMITIR que el botón se vea */
}

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

/* ✅ GARANTIZAR que el botón esté por encima de todo en móvil */
@media (max-width: 968px) {
    .conversacion-item {
        z-index: 120;
    }
    
    .delete-button-longpress {
        z-index: 300; /* ✅ ALTO z-index para estar por encima */
    }
    
    .conversacion-item.show-delete-button {
        z-index: 350; /* ✅ AÚN MÁS ALTO cuando está activo */
    }
}

/* Para mensajes.html - input de buscar usuario */
#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;
}

/* Estilos para información de archivos comprimidos */
.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;
}