/* Contenedor principal del chat */
.chat-container {
    display: flex;
    height: 100%;
    min-height: 600px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* Barras laterales */
.chat-sidebar {
    width: 280px;
    border-right: 1px solid #eee;
    padding: 20px;
    background: #f8f9fa;
}
.chat-sidebar h5 {
    margin-top: 0;
    margin-bottom: 10px;
}
.chat-sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.chat-sidebar li {
    padding: 8px;
    cursor: pointer;
    border-bottom: 1px solid #ddd;
}
.chat-sidebar li:hover {
    background-color: #e9ecef;
}
.new-chat {
    margin-top: 15px;
}
.new-chat select,
.new-chat button {
    width: 100%;
    padding: 6px;
    margin-top: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

/* Área principal del chat */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    height: 83vh;
}
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #fff;
    border-radius: 8px;
    height: 400px; /* Set a fixed height */d height */
    min-height: auto; /* Override min-height *//* Override min-height */
    margin-bottom: 20px;
    border: 1px solid #eee;
}

/* Estilos para cada mensaje */
.chat-message {
    margin-bottom: 15px;
    padding: 12px;
    border-radius: 8px;
    max-width: 80%;
}
.chat-message-header {
    font-size: 0.9em;
    margin-bottom: 5px;
}
.chat-message-body {
    padding: 8px;
    border-radius: 4px;
}
.chat-message-sent {
    background: #007bff;
    color: white;
    margin-left: auto;
}
.chat-message-received {
    background: #f1f3f4;
    color: #333;
}
.chat-message-sent .chat-message-body {
    text-align: right;
}
.chat-message-received .chat-message-body {
    background-color: #f1f1f1; /* Gris muy claro */
    text-align: left;
}
.chat-attachment img {
    max-width: 200px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

/* Nuevo formulario (textarea-wrapper) para el chat */
.textarea-wrapper {
    position: relative;
}
.textarea-wrapper input#chat_message {
    width: 100%;
    padding: 5px 50px 5px 110px; /* se deja espacio para dos botones en la parte izquierda */
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.4;
    box-sizing: border-box;
    height: 40px;
}
.textarea-wrapper button.attachment-btn,
.textarea-wrapper button.record-btn,
.textarea-wrapper button.send-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: #666;
}
.textarea-wrapper button.attachment-btn {
    left: 10px;
    z-index: 2;
}
.textarea-wrapper button.attachment-btn:hover {
    color: #333;
    cursor: pointer;
}
#chat-form input[type="file"] {
    display: none;
    position: absolute;
    left: -9999px;
}
.textarea-wrapper button.record-btn {
    left: 60px;
}
.textarea-wrapper button.send-btn {
    right: 10px;
}
/* Opcional: efectos hover para los botones */
.textarea-wrapper button.attachment-btn:hover,
.textarea-wrapper button.record-btn:hover,
.textarea-wrapper button.send-btn:hover {
    color: #333;
}

/* Input file oculto */
#chat-form input[type="file"] {
    display: none;
}

/* Autocomplete para búsqueda de usuarios */
.new-chat {
    position: relative;
}
#user-search {
    width: 100%;
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
}
#user-suggestions {
    position: absolute;
    width: 360px;
    left: 120px;
    right: 0;
    border: 1px solid #ccc;
    background-color: #fff;
    z-index: 1000; /* Ensure it's on top */
    max-height: 200px;
    overflow-y: auto;
    display: none;
    margin: 0;
    padding: 0;
    list-style: none;
}
#user-suggestions li {
    padding: 6px;
    cursor: pointer;
}
#user-suggestions li:hover {
    background-color: #e9ecef;
}

/* Nuevo estilo para el botón de adjuntar archivo representado por un ícono */
.chat-attachment-label {
    display: inline-block;
    width: 40px;
    height: 40px;
    background-color: #f8f9fa;
    border: 1px solid #ccc;
    border-radius: 50%;
    cursor: pointer;
    margin-left: 10px;
    /* Se utiliza un ícono de clip, codificado en SVG */
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="%23000" viewBox="0 0 24 24"><path d="M21.44 11.05l-9.9 9.9a5.35 5.35 0 0 1-7.58-7.57l9.9-9.9A3.17 3.17 0 0 1 18.3 3a3.17 3.17 0 0 1 0 4.48l-9.9 9.9a1.17 1.17 0 0 1-1.65-1.65l9.9-9.9a1.17 1.17 0 1 0-1.65-1.65l-9.9 9.9a3.17 3.17 0 0 0 0 4.48 3.17 3.17 0 0 0 4.48 0l9.9-9.9a5.35 5.35 0 0 0-7.58-7.57L3.05 9.2"/></svg>');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 20px 20px;
}

/* Agregar estilo para el placeholder cuando no hay mensajes */
.chat-placeholder {
    text-align: center;
    color: #6c757d;
    padding: 20px;
    font-style: italic;
}

/* Forzar el formulario a quedar abajo en chat-main */
.chat-main form {
    margin-top: auto;
}

/* Nuevo estilo para el botón de descarga de documento */
.download-btn {
    display: inline-block;
    padding: 6px 12px;
    background-color: #0d6efd;
    color: #fff;
    border: none;
    border-radius: 4px;
    text-decoration: none;
    font-size: 14px;
    transition: background-color 0.2s;
}
.download-btn i {
    margin-right: 4px;
}
.download-btn:hover {
    background-color: #0b5ed7;
}

/* Estilos para el ícono de notificación */
.chat-notification-icon {
    position: relative;
    display: inline-block;
}
.chat-notification-icon i {
    color: #ffffff!important; /* Set icon color to white */
}
.chat-notification-icon i {
    font-size: 24px;
    color: #666;
}
.chat-notification-icon .unread-count {
    position: absolute;
    top: -8px;
    right: -8px;
    background-color: #f44;
    color: #fff;
    border-radius: 50%;
    padding: 2px 7px;
    font-size: 10px;
    min-width: 20px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); /* Shadow for depth */
}
.chat-notification-icon .unread-count {
    /* Estilo para el badge de mensajes no leídos en la lista de conversaciones */
    .unread-badge {
        position: absolute;
        right: 10px;
        background: #ff4444;
        color: white;
        border-radius: 50%;
        padding: 2px 8px;
        font-size: 12px;
        font-weight: bold;
    }
    #chat-conversations {
        margin-top: 15px;
    }
    #chat-conversations li {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 15px;
        margin-bottom: 5px;
        background-color: #ffffff;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        transition: all 0.3s ease;
    }
    #chat-conversations li:hover {
        background-color: #f8f9fa;
        transform: translateX(5px);
    }
    #chat-conversations .unread-badge {
        position: absolute;
        top: -8px;
        right: -8px;
        background-color: #f44;
        color: #fff;
        border-radius: 50px;
        padding: 2px 7px;
        font-size: 9px;
        box-shadow: 0 0 5px rgb(0 0 0 / .3);
    }
    #chat-conversations li:hover {
        background-color: #f5f5f5;
    }
    text-align: center;
    font-weight: bold;
}
.chat-notification-icon a {
    text-decoration: none;
    display: block;
}

/* Estilo para mensajes no leídos en el chat */
.chat-message-received.unread .chat-message-body {
    border-left: 3px solid #ff4444;
}

/* Diálogo de confirmación para borrar mensajes */
.delete-confirm-dialog {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border: 1px solid #ddd;
    padding: 20px;
    z-index: 10000;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
.delete-confirm-dialog p {
    margin-bottom: 20px;
}
.delete-confirm-dialog .dialog-buttons {
    text-align: right;
}
.delete-confirm-dialog .dialog-buttons button {
    padding: 6px 12px;
    margin-left: 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
.delete-confirm-dialog .cancel-delete {
    background: #ccc;
    color: #000;
}
.delete-confirm-dialog .confirm-delete {
    background: #f44;
    color: #fff;
}

/* Modal Overlay */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Black with 50% opacity */
    z-index: 9999; /* Ensure it's on top of everything */
}

.chat-categories li, .chat-conversations li {
    padding: 12px 15px;
    margin-bottom: 8px;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.chat-categories li:hover, .chat-conversations li:hover {
    background: #e9ecef;
    transform: translateX(5px);
}

.chat-message.unread {
    border-left: 4px solid #ff4444;
}

#chat-form {
    position: relative;
    bottom: 0;
    left: 0;
    right: 0;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border-top: 1px solid #eee;
}

#chat-form textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
    min-height: 60px;
}

.chat-form-buttons {
    display: flex;
    gap: 5px; /* Reducir la separación entre los botones */
    margin-top: 10px;
}

.chat-form-buttons button {
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-form-buttons .attachment-btn,
.chat-form-buttons .record-btn {
    width: 15%; /* Ancho para los botones de adjuntar y grabar */
    flex-shrink: 0; /* Evitar que se encojan */
}

.chat-form-buttons .send-button {
    width: 70%; /* Ancho para el botón de enviar */
    margin-left: auto; /* Empujar el botón de enviar a la derecha */
}

.send-button {
    background: #007bff;
    color: white;
}

.send-button:hover {
    background: #0056b3;
}

.chat-form-buttons .record-btn.recording {
    animation: blinker 1s linear infinite;
}

@keyframes blinker {
  50% {
    opacity: 0;
  }
}

span.unread-badge {
    background-color: #f44;
    color: #fff;
    border-radius: 50%;
    padding: 2px 7px;
    font-size: 11px;
    min-width: 20px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}

/* Estilos para la información del usuario seleccionado */
#selected-user-info {
    padding: 10px;
    background-color: #f0f0f0;
    margin-bottom: 10px;
    text-align: left;
    font-weight: bold;
    border-radius: 5px;
    position: relative; /* Add relative positioning */
}

/* Style for the back arrow icon */
#selected-user-info .back-arrow {
    cursor: pointer;
    font-size: 18px;
    width: 20px;
    color: #666;
    margin-top: 0px;
    display: none;
}

#selected-user-info .back-arrow:hover {
    color: #333;
}

/* Estilo para resaltar la conversación seleccionada */
#chat-conversations li.selected {
    font-weight: bold;
}


/* Media query para pantallas más pequeñas (móviles) */
@media (max-width: 768px) {
    .chat-container {
        flex-direction: column; /* Apilar la barra lateral y el área principal */
    }

    .chat-sidebar {
        width: 100%; /* La barra lateral ocupa todo el ancho */
        border-right: none;
        border-bottom: 1px solid #eee;
        padding: 10px;
    }

    .chat-main {
        padding: 10px;
    }

    #chat-messages {
        height: 52vh; /* Ajustar la altura automáticamente */
        min-height: 300px; /* Establecer una altura mínima */
        margin-bottom: 10px;
    }

    #user-suggestions {
        width: 90%;
        left: 5%;
    }

    /* Ajustar el tamaño de fuente para pantallas más pequeñas */
    .chat-message-header {
        font-size: 0.8em;
    }

    .chat-message-body {
        font-size: 0.9em;
    }

    /* Ajustar el formulario del chat */
    #chat-form textarea {
        min-height: 40px;
        font-size: 12px;
    }

    .chat-form-buttons {
        flex-direction: row; /* Poner los botones en una fila */
        justify-content: space-between; /* Espaciar los botones */
    }

    .chat-form-buttons button {
        /* Eliminar el ancho completo */
        margin-bottom: 5px;
    }
    #selected-user-info .back-arrow {
        display: block;
    }
}

/* Loading overlay */
.chat-main .chat-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.chat-loading-spinner {
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 2s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Hide initially */
#selected-user-info,
#chat-form {
    display: none;
}

/* Last message time style */
.last-message-time {
    font-size: 10px;
    color: #a9a9a9;
    font-style: italic;
    font-size: smaller;
    color: grey;
}

/* Back button style */
.back-button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    margin-bottom: 10px;
    display: none; /* Hidden by default */
}

.back-button i {
    margin-right: 5px;
}

body.conversation-view .chat-sidebar {
    display: none;
}

body.conversation-view .chat-main {
    display: block;
}
