/* style.css - CODIGO COMPLETO Y CORREGIDO FINAL con ALINEACIÓN INTERNA ESTABLE */

/* --- Variables Globales --- */
:root {
    --primary-color: #607d8b;     /* Azul Grisáceo para títulos/botones */
    --secondary-color: #6c757d;    
    --background-dark: #f0f2f5;    /* Fondo del cuerpo */
    --background-light: #ffffff;   /* Fondo del contenedor general */
    --wa-background-chat: #ECE5DD; 
    --wa-outgoing: #DCF8C6;        /* Verde claro (Mensaje saliente/Usuario) */
    --wa-incoming: #FFFFFF;        /* Blanco (Mensaje entrante/Sistema) */
    --border-color: #dee2e6;      
    --font-family: Arial, sans-serif;
}

/* --- Estilos Base --- */
body {
    font-family: var(--font-family);
    background-color: var(--background-dark); 
    margin: 0;
    padding: 0; 
    line-height: 1.6;
}

.container {
    width: 100%; 
    background-color: var(--background-light); 
    padding: 30px;
    border-radius: 0; 
    box-shadow: none; 
    min-height: 50vh; 
    box-sizing: border-box; 
}

h2 {
    color: var(--primary-color);
    padding-bottom: 5px;
    margin-top: 30px;
    margin-bottom: 15px;
}

h3 {
    margin-top: 20px;
    color: var(--secondary-color);
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 30px 0;
}

/* --- Estilos de Formularios (Botones e Inputs) --- */
input[type="file"],
input[type="submit"],
button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    font-size: 16px;
}

input[type="submit"]:hover,
button:hover {
    background-color: #455a64; 
}

input[type="file"] {
    background: none;
    color: initial;
    padding: 0;
    margin-right: 10px;
}

textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    box-sizing: border-box; 
    margin-bottom: 15px;
}

/* Estilo específico para el formulario de subida de archivo */
form[enctype="multipart/form-data"] {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

/* --- Mensajes de Éxito/Alerta --- */
.alert {
    padding: 10px;
    margin-bottom: 20px;
    border-radius: 4px;
    font-weight: bold;
}

.alert.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* --- Estilos del Chat (Optimización de Altura y Alineación Dinámica) --- */
.chat-container {
    max-height: 400px; 
    overflow-y: auto; 
    padding: 10px;
    border: none; 
    border-radius: 4px;
    background-color: var(--wa-background-chat); 
    margin-bottom: 15px;
    display: flow-root; /* Clearfix moderno */
}

.message {
    position: relative; 
    padding: 4px 8px; /* Ultra compacto verticalmente (Altura) */
    border-radius: 12px;
    margin: 3px 0; 
    max-width: 65%; /* Ancho compacto */
    word-wrap: break-word; 
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1); 
    clear: both; 
    font-size: 13px; 
}

/* Burbuja Entrante (Otros Usuarios/Sistema - Izquierda) */
.system-message {
    background-color: var(--wa-incoming); /* Blanco */
    color: #333; 
    float: left;
    margin-right: 25%; /* Crea espacio en el lado derecho */
    margin-left: 8px; 
    padding-left: 25px; 
}

/* Papelera en mensajes entrantes (izquierda) */
.system-message .delete-link {
    left: 5px; 
    right: auto; 
}

/* Burbuja Saliente (TÚ - Derecha) */
.user-message {
    background-color: var(--wa-outgoing); 
    color: #333; 
    float: right;
    margin-left: 25%; /* Crea espacio en el lado izquierdo */
    margin-right: 8px; 
    padding-right: 25px; 
}

/* Papelera en mensajes salientes (derecha) */
.user-message .delete-link {
    right: 5px; 
    left: auto; 
}

/* --- CLAVE: ALINEACIÓN DEL TEXTO Y LA HORA --- */
.message-content {
    white-space: pre-wrap; 
    margin-bottom: 0px; 
    line-height: 1.2;
    text-align: left !important; /* FUERZA EL CONTENIDO PRINCIPAL A LA IZQUIERDA */
}

.message-author {
    font-weight: bold;
    color: #007bff; /* Color azul para el autor */
    display: inline-block; 
    text-align: left;
}

.message-time {
    display: block;
    text-align: right; /* Por defecto, la hora se alinea a la derecha (para mensajes salientes) */
    font-size: 10px;
    color: rgba(0, 0, 0, 0.5); 
    margin-top: 0px; 
    line-height: 1; 
}

/* CLAVE FINAL: SOBRESCRIBIR LA ALINEACIÓN INTERNA PARA MENSAJES DE LA IZQUIERDA */
.system-message .message-content,
.system-message .message-time {
    text-align: left !important; /* FUERZA EL TEXTO Y LA HORA A LA IZQUIERDA */
    width: 100%; /* Ocupa el ancho para alinear */
}

.system-message .message-time {
    padding-left: 20px; /* Ajuste para que la hora no se pegue al borde */
}

/* Colores de la hora por burbuja */
.user-message .message-time {
    color: #2ecc71 !important; /* Verde */
}

.system-message .message-time {
    color: #e74c3c !important; /* Rojo */
}

.delete-link {
    color: rgba(0, 0, 0, 0.4); 
    text-decoration: none;
    font-size: 13px; 
    position: absolute;
    top: 5px; 
}

.no-messages {
    text-align: center;
    color: var(--secondary-color);
    padding: 20px;
    clear: both;
}

/* Formulario de envío */
.chat-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-form textarea {
    min-height: 80px; 
}

.chat-form button {
    align-self: flex-end; 
    width: auto;
}

/* --- Archivos Disponibles (LISTADO Y VISTA PREVIA) --- */
.file-list {
    list-style: none;
    padding: 0;
    clear: both; 
}

.file-item {
    background-color: var(--background-dark);
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 8px;
    display: flex; 
    align-items: center;
    gap: 15px;
}

.file-preview-area {
    width: 50px; 
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 5px;
    background-color: var(--border-color);
    flex-shrink: 0; 
}

/* Estilo para las miniaturas de imagen */
.file-thumbnail {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain; 
    border-radius: 3px;
}

/* Estilo para el icono genérico (PDF, DOCX, TXT, etc.) */
.file-icon {
    font-weight: bold;
    color: var(--primary-color);
    font-size: 12px;
    padding: 5px;
    text-align: center;
    line-height: 1;
}

.file-info {
    flex-grow: 1;
}

.file-info a {
    color: #333; 
    text-decoration: none;
    font-weight: normal;
}

.file-info a:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

.file-info small {
    display: block;
    color: var(--secondary-color);
    font-size: 11px;
    margin-top: 3px;
}

/* --- Estilos de Eliminación --- */
.delete-file-action {
    margin-left: auto; 
    flex-shrink: 0;
}

.delete-file-btn {
    display: inline-block;
    background-color: #e74c3c; 
    color: white !important; 
    border-radius: 4px;
    padding: 5px 8px;
    font-size: 12px;
    text-decoration: none !important; 
    transition: background-color 0.2s;
}

.delete-file-btn:hover {
    background-color: #c0392b; 
}

/* --- Estilos del Login --- */
.login-container {
    max-width: 400px; 
    margin: 100px auto; 
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background-color: var(--background-light);
}

.login-form label {
    display: block;
    margin-top: 10px;
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
}

.login-form input[type="text"],
.login-form input[type="password"] {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    box-sizing: border-box;
    margin-bottom: 15px;
}

.login-form button[type="submit"] {
    width: 100%;
    padding: 12px;
}

/* --- Media Query para VISTA MÓVIL (Responsividad) --- */
@media (max-width: 600px) {
    body {
        padding: 0; 
    }
    .container {
        padding: 15px; 
    }
    
    .chat-form button {
        align-self: stretch; 
        width: 100%;
    }
    
    /* Reglas para evitar solapamiento de Subida de Archivos en móvil */
    form[enctype="multipart/form-data"] {
        flex-direction: column; 
        align-items: flex-start; 
        gap: 15px; 
    }

    input[type="file"] {
        width: 100%;
        margin-right: 0;
    }
    
    form[enctype="multipart/form-data"] button[type="submit"] {
        width: 100%;
        align-self: stretch; 
    }
    
    .delete-file-action {
        width: 100%;
    }

    .delete-file-btn {
        width: 100%;
        text-align: center;
        box-sizing: border-box; 
    }

    .file-item {
        flex-wrap: wrap; 
    }
    
    .file-info {
        width: 100%; 
        order: -1; 
    }
}