/* Estilos generales y para la página de login/registro */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: #f0f2f5;
    overflow: hidden;
}

/* --- Estructura Principal del Chat --- */
.main-container { display: flex; height: 100vh; width: 100vw; }
#side-panel { width: 30%; min-width: 280px; max-width: 400px; display: flex; flex-direction: column; border-right: 1px solid #d1d7db; background-color: #fff; }
#chat-panel { flex-grow: 1; display: flex; flex-direction: column; background-color: #e5ddd5; }

/* --- Panel Izquierdo --- */
#side-panel-header, #chat-header { display: flex; align-items: center; height: 60px; padding: 0 16px; background-color: #f0f2f5; border-bottom: 1px solid #d1d7db; flex-shrink: 0; }
#side-panel-header { justify-content: space-between; }
#user-list { flex-grow: 1; overflow-y: auto; }
.user-list-item { display: flex; align-items: center; padding: 8px 16px; cursor: pointer; border-bottom: 1px solid #f0f2f5; }
.user-list-item:hover { background-color: #f5f5f5; }
.user-list-item.active { background-color: #0d6efd; color: white; }
.user-list-item .username { flex-grow: 1; }
.unread-badge { background-color: #25d366; color: white; font-size: 0.75rem; font-weight: bold; border-radius: 50%; min-width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; }

/* --- Panel Derecho (Chat) --- */
#welcome-screen, #chat-area { flex-grow: 1; display: flex; flex-direction: column; min-height: 0; }
#welcome-screen { justify-content: center; align-items: center; text-align: center; color: #555; background-color: #f8f9fa; }
#chat-header { justify-content: space-between; }
#chat-header strong { display: flex; align-items: center; }
.chat-header-buttons { display: flex; gap: 8px; }
.chat-header-buttons .btn { font-size: 1.2rem; color: #54656f; }

/* Barra de Búsqueda */
#search-bar { display: flex; align-items: center; padding: 8px 16px; background-color: #fff; border-bottom: 1px solid #d1d7db; flex-shrink: 0; }
#search-input { border-radius: 20px; }

#chat-box { flex-grow: 1; overflow-y: auto; padding: 1rem; }
#alert-container { padding: 0 1rem; }
#chat-footer { padding: 10px 16px; background-color: #f0f2f5; flex-shrink: 0; }
#chat-footer.disabled { opacity: 0.6; pointer-events: none; }

/* Burbujas de Mensajes */
.message-wrapper { display: flex; margin-bottom: 8px; max-width: 100%; }
.message-bubble { padding: 8px 12px; border-radius: 8px; max-width: 70%; word-wrap: break-word; position: relative; padding-bottom: 22px; min-width: 90px; }
.message-wrapper.sent { justify-content: flex-end; }
.message-wrapper.sent .message-bubble { background-color: #dcf8c6; }
.message-wrapper.received { justify-content: flex-start; }
.message-wrapper.received .message-bubble { background-color: #fff; border: 1px solid #eee; }
.message-bubble mark { background-color: #ffc107; padding: 0; }

/* Metadatos del Mensaje */
.message-meta { position: absolute; bottom: 5px; right: 8px; display: flex; align-items: center; font-size: 0.7rem; color: #667781; }
.message-wrapper.sent .message-meta { color: #66778199; }
.read-receipt { width: 6px; height: 6px; border-radius: 50%; background-color: #8696a0; margin-left: 5px; }
.read-receipt.seen { background-color: #53bdeb; }

/* Archivos y Avatares */
#attach-btn { font-size: 1.2rem; color: #54656f; padding: 6px 10px; }
.file-attachment-preview { display: flex; align-items: center; cursor: pointer; }
.file-attachment-preview i { font-size: 2rem; color: #54656f; margin-right: 12px; }
.file-info .file-name { font-weight: 500; word-break: break-all; }
.image-preview { max-width: 250px; max-height: 200px; height: auto; border-radius: 8px; cursor: pointer; object-fit: cover; margin-bottom: 5px; }
.user-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; margin-right: 12px; background-color: #e0e0e0; position: relative; }
#chat-header .user-avatar { width: 38px; height: 38px; }

/* --- INICIO DE LA CORRECCIÓN: Estilos para el estado Online/Offline --- */
.user-list-item.online .user-avatar::after,
#chat-header.online .user-avatar::after {
    content: '';
    position: absolute;
    bottom: 2px;
    right: 10px; /* Ajustado para que no se pegue al borde */
    width: 10px;
    height: 10px;
    background-color: #25d366; /* Verde online */
    border: 2px solid white;
    border-radius: 50%;
    box-sizing: content-box;
}

#chat-header.online .user-avatar::after {
    right: 12px; /* Pequeño ajuste para la cabecera */
    bottom: 1px;
}
/* --- FIN DE LA CORRECCIÓN --- */

/* Divisor de Fecha */
.date-divider { display: flex; align-items: center; text-align: center; margin: 1.5rem 2rem; }
.date-divider::before, .date-divider::after { content: ''; flex: 1; border-bottom: 1px solid #d1d7db; }
.date-divider:not(:empty)::before { margin-right: .75em; }
.date-divider:not(:empty)::after { margin-left: .75em; }
.date-divider span { background-color: #e5ddd5; color: #54656f; padding: 4px 12px; font-size: 0.75rem; font-weight: 500; border-radius: 8px; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05); }

/* Modal de Vista Previa */
#filePreviewModal .modal-dialog { max-width: 90vw; height: 90vh; margin-top: 2.5vh; }
#filePreviewModal .modal-content, #filePreviewModal .modal-body { height: 100%; }
#filePreviewModal .modal-body { background-color: #f0f2f5; display: flex; align-items: center; justify-content: center; padding: 0.5rem; }
#modal-content-wrapper { width: 100%; height: 100%; }
#modal-content-wrapper img, #modal-content-wrapper video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
#modal-content-wrapper iframe { width: 100%; height: 100%; border: none; }
.download-button-wrapper { padding: 40px; }

/* Modal de Galería de Archivos */
.files-grid-scroll-container { max-height: 500px; overflow-y: auto; padding-right: 10px; }
#all-files-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.file-grid-item { position: relative; cursor: pointer; border-radius: 8px; overflow: hidden; background-color: #e0e0e0; aspect-ratio: 1 / 1; }
.file-grid-item img { width: 100%; height: 100%; object-fit: cover; }
.file-grid-item .file-icon-wrapper { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 10px; }
.file-grid-item .file-icon-wrapper i { font-size: 3rem; }
.file-grid-item .file-name-overlay { position: absolute; bottom: 0; left: 0; width: 100%; background: linear-gradient(to top, rgba(0,0,0,0.7), transparent); color: white; font-size: 0.8rem; padding: 15px 8px 8px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Banner de Reconexión */
#reconnect-banner { position: fixed; top: 0; left: 0; width: 100%; background-color: #ffc107; color: #333; text-align: center; padding: 5px 0; font-size: 0.9rem; z-index: 9999; transition: transform 0.3s ease-in-out; }
#reconnect-banner.d-none { transform: translateY(-100%); }

/* --- Estilos para la Barra de Progreso de Subida --- */
.upload-placeholder { display: flex; align-items: center; width: 250px; }
.upload-placeholder i { font-size: 2rem; color: #54656f; margin-right: 12px; }
.upload-info { flex-grow: 1; }
.upload-info .file-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-bar-container { height: 6px; width: 100%; background-color: #d1d7db; border-radius: 3px; margin-top: 5px; overflow: hidden; }
.progress-bar-fill { height: 100%; width: 0%; background-color: #00a884; border-radius: 3px; transition: width 0.2s ease-out; }

/* Banner de Notificaciones */
#notification-banner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #007bff;
    color: white;
    text-align: center;
    padding: 10px 0;
    font-size: 0.9rem;
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}
#notification-banner.d-none {
    display: none !important;
}
