/* --- LAYOUT CHÍNH --- */
.messenger-container {
    display: flex;
    height: 85vh; /* Chiều cao cố định */
    background-color: #fff;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
    overflow: hidden;
    border: 1px solid #e5e5e5;
}

/* --- SIDEBAR --- */
.messenger-sidebar {
    width: 350px;
    border-right: 1px solid #eff2f5;
    display: flex;
    flex-direction: column;
    background-color: #fff;
}

.sidebar-header {
    padding: 20px;
}

.search-bar-wrapper {
    background-color: #f1f5f9;
    border-radius: 12px;
    padding: 8px 15px;
    display: flex;
    align-items: center;
}

.search-icon { color: #64748b; margin-right: 10px; }
.search-input {
    border: none; background: transparent; width: 100%; outline: none;
    color: #1e293b;
}
.search-input::placeholder { color: #94a3b8; }

.btn-new-chat {
    width: 100%;
    padding: 10px;
    border: none;
    background-color: rgba(99, 102, 241, 0.08);
    color: var(--primary-color);
    border-radius: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
}
.btn-new-chat:hover {
    background-color: rgba(99, 102, 241, 0.15);
}

.nav-pills .nav-link {
    border-radius: 12px !important;
    font-weight: 600 !important;
    color: #64748b !important;
    padding: 8px 16px !important;
    transition: all 0.25s ease !important;
}

.nav-pills .nav-link.active {
    background: var(--primary-gradient) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25) !important;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* Item trong danh sách chat */
.user-list-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
    color: inherit;
    margin-bottom: 5px;
}

.user-list-item:hover { background-color: #f8fafc; }
.user-list-item.active { background-color: rgba(99, 102, 241, 0.08); color: var(--primary-color) !important; }

.user-avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-size: 18px;
    margin-right: 12px;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

/*
 * FIX UI (Chat sidebar): Đưa trạng thái Online/Offline xuống dòng dưới tên.
 * Ảnh hiện tại (bug) đang hiển thị tên + trạng thái trên cùng 1 dòng.
 * Ép các phần tử con trong .user-info hiển thị theo cột để luôn xuống dòng.
 */
.messenger-sidebar .user-list-item .user-info,
.user-list-modal .user-list-item .user-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.messenger-sidebar .user-list-item .user-status-text,
.user-list-modal .user-list-item .user-status-text {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Tăng độ ổn định khoảng cách giữa tên và trạng thái (đặc biệt khi tên có thêm class .room-name) */
.messenger-sidebar .user-name-row,
.user-list-modal .user-name-row {
    margin-bottom: 6px;
}

.user-name-row .user-name {
    margin-bottom: 0;
}
.user-name { font-weight: 600; display: block; color: #050505; margin-bottom: 6px;}
.user-status-text { font-size: 13px; color: #65676b; }
/* Dot trước Online/Offline */
.user-status-text .status-dot{
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    display: inline-block;
}

.user-status-text .status-dot.online{
    background: #28a745;
}

/* Tên phòng chat cần position:relative để .unread-dot (position:absolute) bám đúng vị trí */
.room-name {
    position: relative;
    display: inline-block;
}

/* --- MAIN CHAT WINDOW --- */
.messenger-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #fff;
}

/* Welcome Screen */
.welcome-screen {
    height: 100%;
    display: flex; align-items: center; justify-content: center;
    text-align: center; color: #65676b;
}
.welcome-icon { font-size: 60px; margin-bottom: 20px; }

.chat-window {
    display: flex; flex-direction: column; height: 100%;
}

/* Header Chat */
.chat-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eff2f5;
    display: flex; align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    z-index: 10;
}

/* Messages Area */
.chat-messages-area {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Footer Input */
.chat-footer {
    padding: 15px;
    border-top: 1px solid #eff2f5;
}

.message-form {
    display: flex; align-items: flex-end; gap: 10px;
}

.footer-actions { display: flex; gap: 5px; margin-bottom: 5px; }
.action-btn {
    background: none; border: none; font-size: 20px;
    cursor: pointer; color: var(--primary-color); padding: 5px;
    border-radius: 50%; transition: all 0.2s ease;
}
.action-btn:hover { background-color: #f1f5f9; }

.input-wrapper {
    flex: 1;
    background-color: #f0f2f5;
    border-radius: 20px;
    padding: 8px 15px;
    display: flex; align-items: center;
}

.msg-input {
    flex: 1; border: none; background: transparent;
    outline: none; max-height: 100px; overflow-y: auto;
}

.send-btn {
    background: none; border: none;
    color: var(--primary-color); font-size: 20px; cursor: pointer;
    margin-left: 10px; transition: all 0.2s ease;
}
.send-btn:hover { transform: scale(1.1); }
.send-btn:disabled { color: #ccc; cursor: default; }

/* --- BONG BÓNG CHAT (MESSAGE BUBBLES) --- */
.msg-row {
    display: flex;
    align-items: flex-end;
    margin-bottom: 2px;
    position: relative; /* Để chứa menu option */
}
.msg-row:hover .msg-actions { opacity: 1; }

/* Style cho tin nhắn gửi đi (User hiện tại) */
.msg-row.sent {
    justify-content: flex-end;
}

.msg-row.sent .msg-content {
    background: var(--primary-gradient);
    color: white;
    border-radius: 18px 18px 4px 18px;
    order: 1;
}
.msg-row.sent .msg-actions { order: 0; margin-right: 10px; }


/* Style cho tin nhắn nhận (Người khác) */
.msg-row.received {
    justify-content: flex-start;
}

.msg-row.received .msg-content {
    background-color: #f0f2f5; /* Màu xám Messenger */
    color: #050505;
    border-radius: 18px 18px 18px 4px;
}
.msg-row.received .msg-actions { margin-left: 10px; }

/* Avatar nhỏ bên cạnh tin nhắn nhận */
.msg-avatar-small {
    width: 28px; height: 28px;
    border-radius: 50%;
    margin-right: 8px;
    background-color: #ddd;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: bold; color: #555;
    flex-shrink: 0;
}

/* Nội dung bên trong bubble */
.msg-content {
    padding: 10px 16px;
    max-width: 70%;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    position: relative;
}

/* Tin nhắn đã thu hồi */
.msg-content.recalled {
    background-color: transparent !important;
    border: 1px solid #e5e5e5;
    color: #888 !important;
    font-style: italic;
    box-shadow: none;
}

/* Hình ảnh trong tin nhắn */
.msg-image {
    border-radius: 15px;
    max-width: 100%;
    cursor: pointer;
    transition: 0.2s;
}
.msg-image:hover { opacity: 0.9; }

/* File đính kèm */
.msg-file {
    display: flex; align-items: center;
    background: rgba(255,255,255,0.2);
    padding: 8px; border-radius: 10px;
}
.received .msg-file { background: rgba(0,0,0,0.05); }
.msg-file a { color: inherit; text-decoration: none; font-weight: bold; margin-left: auto;}

/* --- MENU ACTIONS (3 CHẤM) --- */
.msg-actions {
    opacity: 0; /* Ẩn mặc định, hiện khi hover */
    transition: opacity 0.2s;
    position: relative;
    display: flex; align-items: center;
}

.btn-option {
    background: #f0f2f5;
    border: none; border-radius: 50%;
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: #65676b;
}
.btn-option:hover { background-color: #e4e6eb; }

/* Popup thu hồi */
.action-popup {
    display: none;
    position: absolute;
    bottom: 100%; left: 50%; transform: translateX(-50%);
    background: white; border-radius: 8px;
    padding: 5px; min-width: 100px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    z-index: 100;
}
.action-popup.show { display: block; }
.action-item {
    padding: 8px; font-size: 13px; color: #dc3545;
    cursor: pointer; text-align: center; font-weight: 600;
}
.action-item:hover { background-color: #f8f9fa; }

/* --- FILE PREVIEW TRƯỚC KHI GỬI --- */
.file-preview-box {
    padding: 10px 20px;
    background-color: #f9f9f9;
    border-top: 1px solid #eee;
}
.preview-content {
    display: flex; align-items: center;
    background: white; padding: 10px;
    border-radius: 10px; border: 1px solid #ddd;
    width: fit-content;
}
.preview-icon { font-size: 24px; margin-right: 10px; }
.btn-close-preview {
    background: none; border: none; color: #999;
    font-size: 16px; cursor: pointer; margin-left: 15px;
}

/* Scrollbar đẹp */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #bcc0c4; border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }
/* --- GIỮ NGUYÊN CSS CŨ CỦA BẠN --- */
/* ... (Copy toàn bộ nội dung cũ ở đây) ... */

/* --- THÊM MỚI CHO TẠO NHÓM --- */

/* Item chọn user khi tạo nhóm */
.user-select-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
    margin-bottom: 5px;
}

.user-select-item:hover {
    background-color: #f5f5f5;
}

.user-select-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 12px;
    accent-color: #667eea; /* Màu checkbox khi checked */
    cursor: pointer;
    flex-shrink: 0;
}

/* Nút nhóm */
#new-group-btn:hover {
    background-color: #dbeaff !important;
}
/* Thêm vào chat.css nếu cần chỉnh avatar trong modal */
.user-avatar-small {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-size: 14px;
    flex-shrink: 0;
}
/* Ẩn tuyệt đối nút chọn file thô */
#file-input {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
}
/* --- TRẠNG THÁI KẾT NỐI --- */
#connection-status {
    display: none; /* Mặc định ẩn */
    background-color: #dc3545;
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 0.9rem;
    font-weight: bold;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    border-top-left-radius: 15px; /* Bo góc theo khung chat */
    border-top-right-radius: 15px;
}

#connection-status.reconnecting {
    background-color: #ffc107; /* Màu vàng khi đang thử kết nối lại */
    color: #333;
}

/* --- NÚT 'TIN NHẮN MỚI' (Khi đang scroll ở trên) --- */
#new-message-alert {
    display: none;
    position: absolute;
    bottom: 80px; /* Nằm trên thanh nhập liệu */
    left: 50%;
    transform: translateX(-50%);
    background-color: #667eea;
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    font-size: 0.85rem;
    z-index: 90;
    animation: fadeInUp 0.3s ease;
}

#new-message-alert:hover {
    background-color: #5a6fd6;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translate(-50%, 10px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}
/* ... Giữ nguyên các code cũ ... */

/* --- STYLE CHO AUDIO MESSAGE --- */
.msg-audio {
    display: flex;
    align-items: center;
    min-width: 250px;
}

.msg-audio audio {
    height: 40px;
    width: 100%;
    outline: none;
    border-radius: 20px;
}
.unread-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #ff3b30;
    border-radius: 50%;
    margin-left: 6px;
    vertical-align: middle;
    box-shadow: 0 0 2px rgba(255, 59, 48, 0.5);
}

/* Tùy chỉnh màu trình phát audio trên Chrome */
.msg-audio audio::-webkit-media-controls-panel {
    background-color: #f1f3f4;
}

.sent .msg-audio audio::-webkit-media-controls-panel {
    background-color: #eef2ff; /* Màu hơi tím nhạt cho tin nhắn gửi đi */
}
