/* =====================================================
   CHAT CRM — chat.css (CORREGIDO FINAL + MULTIMEDIA)
   ===================================================== */

/* ============ Overlay del chat ============ */
#chatModal.modal-overlay{
  position: fixed; inset: 0;
  display: none;
  justify-content: center; align-items: center;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(5px);
  z-index: 9999;
}
#chatModal.modal-overlay.show{ display:flex; }

/* ============ Ventana principal ============ */
#chatModal .pro-modal{
  display: flex;
  width: 95%; max-width: 1200px; height: 90vh;
  background: #1e1e24;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px; overflow: hidden;
  box-shadow: 0 25px 50px rgba(0,0,0,.6);
}

/* ============ Panel de conversación (Izquierda) ============ */
#chatModal .chat-main-panel{
  flex: 1; display: flex; flex-direction: column;
  background: #0b141a;
  background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
  background-blend-mode: overlay;
  min-width: 0; /* Vital para evitar desbordes */
}

/* Header */
#chatModal .chat-header-pro{
  height: 65px; padding: 0 16px;
  background: #202c33;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex; align-items:center; justify-content: space-between;
}
#chatModal .header-info-group{ display:flex; align-items:center; gap:12px; overflow: hidden; }

#chatModal .header-name-input{
  background: transparent; border: none; outline: none; color: #fff;
  font-size: 1.1rem; font-weight: 700; padding: 6px 8px; border-radius: 8px;
  min-width: 120px;
}
#chatModal .header-name-input::placeholder{ color: rgba(255,255,255,.45); }
#chatModal .header-name-input:focus{ background: rgba(255,255,255,.04); }

/* Selector de Etapa (Arreglado estilo botón/pill) */
#chatModal .stage-selector-wrapper{
  display:flex; align-items:center; gap:8px;
  padding-left:10px; border-left:1px solid rgba(255,255,255,.12);
}
#chatModal .stage-dot{ color: #10b981; font-size: 1.2rem; line-height: 0; }
#chatModal .header-stage-select{
  background:#2a3942; border:1px solid rgba(255,255,255,.12);
  color:#fff; padding:6px 12px; border-radius:20px; font-size:.85rem;
  cursor: pointer; outline: none;
  /* Eliminar estilo nativo para consistencia */
  -webkit-appearance: none; appearance: none;
  text-align: center; font-weight: 600;
  min-width: 100px;
}
#chatModal .header-stage-select:hover{ background: #354652; }

/* Mensajes Base */
#chatModal .chat-messages-area{
  flex:1; padding:18px; display:flex; flex-direction:column; gap:8px;
  overflow-y:auto;
}
#chatModal .msg{
  max-width:75%; padding:8px 12px; border-radius:8px; font-size:.95rem;
  box-shadow:0 1px 2px rgba(0,0,0,.3); word-wrap:break-word;
  position: relative;
}
#chatModal .msg.sent{ background: #005c4b; color:#fff; align-self:flex-end; border-top-right-radius:0; }
#chatModal .msg.received{ background: #202c33; color:#fff; align-self:flex-start; border-top-left-radius:0; }
#chatModal .msg-meta{ display:flex; justify-content:flex-end; gap:6px; opacity:.7; font-size:.7rem; margin-top:4px; }

/* ============ Multimedia y Stickers (NUEVO - IMPRESCINDIBLE) ============ */

/* Imágenes dentro del chat */
#chatModal .msg-img {
    max-width: 100%;
    border-radius: 6px;
    margin-bottom: 5px;
    cursor: pointer;
    display: block;
    transition: transform 0.2s;
}
#chatModal .msg-img:hover { transform: scale(1.02); }

/* Audios (Reproductor nativo ajustado) */
#chatModal .msg-audio {
    width: 260px;
    height: 40px;
    margin-top: 5px;
    border-radius: 20px;
}

/* STICKERS: Sin fondo, sin sombra, flotantes */
#chatModal .msg.sticker-msg {
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
}
#chatModal .msg.sticker-msg .msg-img {
    width: 150px; /* Tamaño estándar sticker */
    max-width: 150px;
    margin-bottom: 0;
}
/* Ocultamos meta data o la hacemos muy sutil en stickers */
#chatModal .msg.sticker-msg .msg-meta {
    color: rgba(255,255,255,0.6);
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    margin-top: -15px; /* Subir un poco la hora */
    padding-right: 5px;
    position: relative;
    z-index: 2;
}

/* Archivos / Documentos */
#chatModal .msg-file {
    display: flex; align-items: center; gap: 12px;
    background: rgba(0,0,0,0.2);
    padding: 10px; border-radius: 6px;
    text-decoration: none; color: inherit;
    margin-bottom: 5px; border: 1px solid rgba(255,255,255,0.1);
}
#chatModal .msg-file i { font-size: 1.5rem; color: #ef4444; } /* Icono rojo */
#chatModal .msg-file:hover { background: rgba(0,0,0,0.3); }

/* Ticks de lectura */
.tick-read { color: #53bdeb !important; } /* Azul leído */
.tick-delivered { color: #8696a0; } /* Gris entregado */

/* ============ Fin Multimedia ============ */

/* Footer Input */
#chatModal .chat-footer-pro{
  background:#202c33; padding:10px; display:flex; gap:10px; align-items:center;
}
#chatModal .input-wrapper{
  flex:1; display:flex; align-items:center; gap:10px;
  padding:8px 14px; border-radius:24px;
  background:#2a3942; border:1px solid rgba(255,255,255,.1);
}
#chatModal .input-wrapper input{
  flex:1; background:transparent; border:none; color:#fff; padding:4px; font-size:1rem; outline: none;
}
#chatModal .btn-icon{ background:none; border:none; color:#8696a0; cursor:pointer; font-size:1.1rem; display:flex; align-items:center; justify-content:center; }
#chatModal .btn-icon:hover{ color:#fff; }

/* Botón micrófono activo (grabando) */
#chatModal .btn-icon.mic-active { color: #ef4444; animation: pulse 1s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

#chatModal .btn-send-round{
  width:45px; height:45px; display:grid; place-content:center; border-radius:50%;
  border:none; cursor:pointer; background: #10b981; color: white;
  box-shadow: 0 4px 10px rgba(16,185,129,.3); flex-shrink: 0;
}
#chatModal .btn-send-round:hover{ background: #0e9f6e; transform: scale(1.05); }

/* Menú de adjuntos */
#chatModal .attach-menu{
  position:absolute; bottom:55px; left:0; display:none; flex-direction:column; gap:6px;
  background:#233138; border:1px solid rgba(255,255,255,0.1); border-radius:12px; padding:10px; min-width:160px;
  box-shadow:0 8px 24px rgba(0,0,0,.5); z-index:100;
}
#chatModal .attach-menu.show{ display:flex; animation:fadeIn .2s both; }
#chatModal .attach-item{ display:flex; align-items:center; gap:12px; color:#d1d7db; padding:10px; border-radius:8px; cursor:pointer; font-size: 0.95rem;}
#chatModal .attach-item:hover{ background:rgba(255,255,255,.08); color: white; }
@keyframes fadeIn{ from{opacity:0; transform: translateY(4px);} to{opacity:1; transform:none;} }

/* ============ Panel lateral (Derecha - SOLUCION LAYOUT) ============ */
#chatModal .info-sidebar-pro{
  width:340px; background:#111b21; border-left:1px solid rgba(255,255,255,.12);
  padding:20px; overflow-y:auto; display: flex; flex-direction: column; gap: 20px;
  flex-shrink: 0;
}

#chatModal .sidebar-header h3{ margin:0; font-size:1.1rem; color: #e9edef; display:flex; align-items:center; gap:10px; }
#chatModal .attr-row{ width: 100%; display: flex; flex-direction: column; gap: 8px; }
#chatModal .attr-label{
  font-size:.75rem; font-weight:700; color:#8696a0;
  text-transform:uppercase; letter-spacing: 0.5px;
}

/* SOLUCION TELEFONO */
#chatModal .input-group-dark{
  display:flex; align-items:center; gap:12px; padding:12px;
  background:#202c33; border:1px solid rgba(255,255,255,.1); border-radius:8px;
  width: 100%; box-sizing: border-box;
}
#chatModal .input-group-dark input{
  background:transparent; border:none; outline:none; color:#d1d7db;
  font-size: 1rem; width: 100%; min-width: 0; 
  flex: 1;
}

/* SOLUCION CARGA MANUAL */
#chatModal .money-control-wrapper{
  display:flex; align-items:center; gap:8px; width: 100%;
}
#chatModal .btn-math{
  width:40px; height:40px; display:flex; align-items: center; justify-content: center;
  border:none; border-radius:8px; background:#2a3942; color:#fff; cursor:pointer; font-size: 1.1rem; flex-shrink: 0;
}
#chatModal .btn-math:hover{ background: #37404a; }
#chatModal .btn-math.danger:active{ background:#ef4444; }
#chatModal .btn-math.success:active{ background:#10b981; }

#chatModal .money-input-container{
  flex:1; display:flex; align-items:center; justify-content: space-between;
  background:#2a3942; border-radius:8px; padding:0 12px; height: 40px;
}
#chatModal .currency-symbol{ color:#8696a0; font-weight:600; }
#chatModal .money-input{
  background:transparent !important; border:none !important; outline:none !important;
  color:#fff; font-weight:600; font-size:1rem; text-align:right; width: 100%; min-width: 0;
}

/* SOLUCION SALDO TOTAL */
#chatModal .total-display{
  display:flex; align-items:center; justify-content:space-between;
  background: rgba(16,185,129,.1); border:1px solid rgba(16,185,129,.3);
  border-radius:8px; padding:15px; width: 100%; box-sizing: border-box;
}
#chatModal .total-display > span{
  color: #10b981; font-weight:700; font-size: 1.2rem;
}
#chatModal .money-input-readonly{
  background:transparent !important; border:none !important; outline:none;
  color: #10b981 !important; font-weight:800; font-size:1.5rem; text-align:left; width: 100px; flex: 1;
}

/* Notas */
#chatModal .notes-wrapper textarea{
  width:100%; min-height:100px; resize:none;
  background: #202c33; border:1px solid rgba(255,255,255,.1);
  color:#d1d7db; padding:12px; border-radius:8px; outline:none; box-sizing: border-box;
  font-family: inherit;
}
#chatModal .notes-wrapper textarea:focus{ border-color: #00a884; }

/* Multimedia Grid */
#chatModal .media-grid{ display:grid; grid-template-columns:repeat(3,1fr); gap:8px; }
#chatModal .media-item{ aspect-ratio: 1/1; border-radius: 6px; overflow: hidden; background: #000; cursor: pointer;}
#chatModal .media-item img{ width: 100%; height: 100%; object-fit: cover; opacity: 0.8; transition: opacity 0.2s;}
#chatModal .media-item img:hover{ opacity: 1; }

/* Responsive */
@media (max-width: 900px){
  #chatModal .pro-modal{ flex-direction: column; height: 100%; width: 100%; border-radius: 0; }
  #chatModal .chat-main-panel{ height: 60vh; }
  #chatModal .info-sidebar-pro{ width: 100%; flex: 1; border-left: none; border-top: 1px solid rgba(255,255,255,.1); }
}

/* Contenedor Stage */
.stage-container {
    display: flex; align-items: center;
    background-color: #232d36;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 2px 10px; margin-left: 15px; position: relative;
}

.status-dot {
    width: 8px; height: 8px;
    background-color: #00e676;
    border-radius: 50%; margin-right: 8px; pointer-events: none;
}

.custom-select {
    background: transparent; border: none;
    color: #e9edef; font-size: 0.9rem;
    cursor: pointer; appearance: none; -webkit-appearance: none;
    outline: none; padding-right: 5px; font-weight: 500;
}
.custom-select option { background-color: #111b21; color: white; padding: 10px; }

/* Separador de Fechas */
#chatModal .date-separator-container {
    display: flex; justify-content: center;
    margin: 20px 0; width: 100%;
}

#chatModal .date-separator {
    background-color: #1f2c34; color: #8696a0;
    font-size: 0.75rem; padding: 6px 12px;
    border-radius: 8px; text-transform: uppercase;
    font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}