:root {
    --primary-color: #0084ff;
    --primary-gradient: linear-gradient(135deg, #0084ff 0%, #00c6ff 100%);
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --text-primary: #050505;
    --text-secondary: #65676b;
    --border-color: #e4e6eb;
    --msg-sent: linear-gradient(135deg, #0084ff 0%, #0066ff 100%);
    --msg-received: #f0f2f5;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    background: var(--bg-color);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.chat-container {
    width: 100%;
    max-width: 1280px;
    height: 95vh;
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.08);
    display: flex;
    align-items: stretch; /* Đảm bảo cả sidebar và chat-main căn đều chiều cao từ sát mép trên */
    overflow: hidden;
    will-change: transform;
    contain: layout style;
}

/* Sidebar bên trái */
.chat-sidebar {
    width: 320px;
    border-right: 1px solid var(--border-color);
    background: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Đẩy nội dung lên sát mép trên */
}

/* Header tiêu đề Sidebar - Sửa lỗi bị lệch/tụt xuống */
.sidebar-header {
    height: 65px; /* Chiều cao cố định chuẩn khớp với .chat-header bên phải */
    padding: 0 20px;
    font-size: 1.1rem;
    font-weight: 700;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center; /* Căn giữa chữ theo chiều dọc */
    box-sizing: border-box;
}

.user-list, .history-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.user-item {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.15s ease;
    border-bottom: 1px solid #f7f8fa;
}

.user-item:hover, .user-item.active {
    background: #eef6ff;
}

/* Khu vực Chat trung tâm */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
}

/* Header thanh trò chuyện chính */
.chat-header {
    height: 65px; /* Bằng chiều cao với .sidebar-header */
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    box-sizing: border-box;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-wrapper {
    position: relative;
    width: 42px;
    height: 42px;
}

.avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.status-dot {
    width: 10px;
    height: 10px;
    background: #10b981;
    border: 2px solid #fff;
    border-radius: 50%;
    position: absolute;
    bottom: 0;
    right: 0;
}

.header-user-info .name {
    font-weight: 700;
    font-size: 1rem;
}

.header-user-info .status {
    font-size: 0.78rem;
    color: #10b981;
}

.btn-end-chat {
    background: #ff3b30;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.btn-end-chat:hover {
    transform: scale(1.04);
}

/* Khung tin nhắn */
.chat-box {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8fafc;
    scroll-behavior: smooth;
}

.message {
    max-width: 60%;
    padding: 10px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-wrap: break-word;
    animation: fadeInSlide 0.2s ease forwards;
    will-change: transform, opacity;
}

.message.sent {
    align-self: flex-end;
    background: var(--msg-sent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background: var(--msg-received);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message img.chat-img {
    max-width: 100%;
    border-radius: 12px;
    margin-top: 6px;
}

.message .time {
    font-size: 0.7rem;
    margin-top: 4px;
    opacity: 0.75;
    text-align: right;
}

/* Khung nhập tin nhắn */
.chat-input-area {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-upload {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.4rem;
    cursor: pointer;
    background: #f0f2f5;
}

.chat-input-area input[type="text"] {
    flex: 1;
    padding: 12px 18px;
    border: 1px solid var(--border-color);
    border-radius: 25px;
    outline: none;
    background: #f8fafc;
}

.btn-send {
    padding: 10px 22px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
}

/* Right Admin Toolkit Panel */
.admin-toolbar {
    width: 260px;
    border-left: 1px solid var(--border-color);
    padding: 20px;
    background: #fafbfc;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.tool-card {
    background: #ffffff;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}

.tool-card h4 {
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.btn-tool {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 8px;
}

.btn-ban { background: #fee2e2; color: #dc2626; }
.btn-unban { background: #d1fae5; color: #059669; }
.btn-history { background: #e0e7ff; color: #4338ca; }

/* Modal Yêu cầu Đăng nhập */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999;
}

.modal-box {
    background: white;
    padding: 30px;
    border-radius: 16px;
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.modal-box button {
    margin-top: 18px;
    padding: 10px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
}

@keyframes fadeInSlide {
    from { opacity: 0; transform: translate3d(0, 8px, 0); }
    to { opacity: 1; transform: translate3d(0, 0, 0); }
}