/* Estilos generales del chat */
.chat-container,
.chat-admin-container {
    max-width: 800px;
    margin: 20px auto;
    font-family: Arial, sans-serif;
}

/* Chat de usuario */
.chat-header {
    background: #007cba;
    color: white;
    padding: 15px 20px;
    border-radius: 10px 10px 0 0;
}

.chat-header h3 {
    margin: 0 0 5px 0;
    font-size: 1.3em;
}

.usuario-info {
    font-size: 0.9em;
    opacity: 0.9;
}

.chat-mensajes {
    height: 400px;
    overflow-y: auto;
    border: 1px solid #ddd;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 5px;
    margin-bottom: 15px;
}

.chat-formulario {
    display: flex;
    gap: 10px;
    padding: 15px;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 10px 10px;
}

#mensaje-usuario,
#mensaje-admin {
    flex: 1;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 5px;
    resize: vertical;
    font-family: inherit;
    font-size: 14px;
}

/* Botones */
.chat-boton,
.chat-boton-admin {
    background: #007cba;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: background 0.3s;
}

.chat-boton:hover,
.chat-boton-admin:hover {
    background: #005a87;
}

.chat-boton-secundario {
    background: #6c757d;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
}

.chat-boton-secundario:hover {
    background: #545b62;
}

/* Panel de administrador */
.chat-admin-header {
    background: #28a745;
    color: white;
    padding: 15px 20px;
    border-radius: 10px 10px 0 0;
    margin-bottom: 20px;
}

.chat-admin-header h3 {
    margin: 0 0 5px 0;
}

.chat-admin-panel {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    min-height: 600px;
}

.usuarios-lista {
    background: white;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 15px;
}

.usuarios-lista h4 {
    margin: 0 0 15px 0;
    color: #333;
    border-bottom: 2px solid #007cba;
    padding-bottom: 8px;
}

#lista-usuarios {
    max-height: 500px;
    overflow-y: auto;
    min-height: 100px;
}

.usuario-chat {
    padding: 12px;
    margin: 8px 0;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s;
    border-left: 4px solid transparent;
}

.usuario-chat:hover {
    background: #007cba;
    color: white;
    border-color: #007cba;
    border-left-color: #007cba;
    transform: translateX(5px);
}

.usuario-chat.seleccionado {
    background: #007cba;
    color: white;
    border-color: #007cba;
    border-left-color: #28a745;
    transform: translateX(5px);
}

.usuario-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.usuario-id {
    font-size: 0.8em;
    opacity: 0.7;
}

.usuario-ultimo-mensaje {
    font-size: 0.85em;
    opacity: 0.8;
    font-style: italic;
}

.chat-conversacion {
    background: white;
    border: 1px solid #ddd;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    border: 2px solid #007cba;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.conversacion-header {
    background: #f8f9fa;
    padding: 15px;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversacion-header h4 {
    margin: 0;
    color: #333;
}

/* ÁREA DE MENSAJES DEL ADMINISTRADOR CON SCROLL MEJORADO */
.chat-mensajes-admin {
    height: 400px !important;
    overflow-y: auto !important;
    border: 1px solid #ddd !important;
    padding: 15px !important;
    background: #f9f9f9 !important;
    border-radius: 5px !important;
    margin-bottom: 15px !important;
    flex: 1;
}

.chat-formulario-admin {
    padding: 15px;
    border-top: 1px solid #dee2e6;
    display: flex;
    gap: 10px;
}

/* Estilos de mensajes */
.mensaje-chat {
    margin-bottom: 15px;
    max-width: 85%;
}

.mensaje-usuario {
    margin-right: auto;
}

.mensaje-admin {
    margin-left: auto;
}

.mensaje-contenido {
    padding: 12px;
    border-radius: 10px;
    position: relative;
    max-width: 100%;
    overflow: hidden;
}

.mensaje-usuario .mensaje-contenido {
    background: #e3f2fd;
    border: 1px solid #bbdefb;
}

.mensaje-admin .mensaje-contenido {
    background: #f3e5f5;
    border: 1px solid #e1bee7;
    text-align: right;
}

.mensaje-cabecera {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.mensaje-cabecera strong {
    font-size: 0.9em;
    color: #555;
}

.mensaje-fecha {
    font-size: 0.75em;
    color: #777;
}

.mensaje-texto {
    color: #333;
    line-height: 1.4;
    word-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    overflow-wrap: break-word;
}

/* Estados y mensajes informativos */
.chat-mensaje-info,
.chat-mensaje-error,
.chat-sin-mensajes,
.chat-sin-usuarios {
    text-align: center;
    padding: 20px;
    color: #666;
    font-style: italic;
    background: #f8f9fa;
    border-radius: 5px;
    margin: 10px 0;
}

.chat-mensaje-error {
    color: #dc3545;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
}

.chat-mensaje-info {
    color: #0c5460;
    background: #d1ecf1;
    border: 1px solid #bee5eb;
}

/* Estilos para estados de carga y error */
.chat-loading {
    text-align: center;
    padding: 20px;
    color: #666;
    font-style: italic;
    background: #f8f9fa;
    border-radius: 5px;
    margin: 10px 0;
}

.chat-error {
    text-align: center;
    padding: 20px;
    color: #dc3545;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 5px;
    margin: 10px 0;
}

/* Scroll personalizado MEJORADO */
.chat-mensajes::-webkit-scrollbar,
.chat-mensajes-admin::-webkit-scrollbar,
#lista-usuarios::-webkit-scrollbar {
    width: 8px;
}

.chat-mensajes::-webkit-scrollbar-track,
.chat-mensajes-admin::-webkit-scrollbar-track,
#lista-usuarios::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.chat-mensajes::-webkit-scrollbar-thumb,
.chat-mensajes-admin::-webkit-scrollbar-thumb,
#lista-usuarios::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.chat-mensajes::-webkit-scrollbar-thumb:hover,
.chat-mensajes-admin::-webkit-scrollbar-thumb:hover,
#lista-usuarios::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Estados del botón de enviar */
#enviar-respuesta:disabled,
#enviar-mensaje:disabled {
    opacity: 0.6 !important;
    cursor: not-allowed !important;
    background: #6c757d !important;
}

/* Mejorar el área de texto para respuestas */
#mensaje-admin {
    min-height: 80px !important;
    max-height: 150px !important;
    resize: vertical !important;
}

/* Responsive */
@media (max-width: 768px) {
    .chat-admin-panel {
        grid-template-columns: 1fr;
    }
    
    .usuarios-lista {
        order: 2;
    }
    
    .chat-conversacion {
        order: 1;
    }
    
    .mensaje-chat {
        max-width: 90%;
    }
    
    .chat-formulario,
    .chat-formulario-admin {
        flex-direction: column;
    }
    
    .chat-mensajes,
    .chat-mensajes-admin {
        height: 300px !important;
    }
}