/* ================================================
   1. CẤU TRÚC LAYOUT TỔNG THỂ & CHỐNG KÉO GIÃN
   ================================================ */
html:has(.chat-page),
body:has(.chat-page) {
    height: 100%;
    overflow: hidden;
}

    body:has(.chat-page) .page-content {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

.content-wrapper:has(.chat-page) {
    overflow: hidden !important;
    flex: 1 !important;
    min-height: 0 !important;
}

    .content-wrapper:has(.chat-page) .page-header {
        display: none !important;
    }

.content:has(.chat-page) {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 26px 0 4px 0 !important; /* Căn chỉnh khoảng cách dưới Header app */
    min-height: 0;
}

/* Khóa chặt chiều cao màn hình chat */
.chat-page {
    display: flex;
    flex: 1;
    width: 100%;
    height: calc(100vh - 56px) !important;
    max-height: calc(100vh - 56px) !important;
    overflow: hidden !important;
    background-color: #fff;
}

/* ================================================
   2. SIDEBAR (DANH SÁCH CUỘC TRÒ CHUYỆN)
   ================================================ */
.chat-sidebar {
    width: 320px;
    min-width: 320px;
    background-color: #f8f9fa !important; /* Nền xám nhạt */
    border-right: 1px solid #f0f0f0;
    display: flex;
    flex-direction: column;
    height: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
}

.chat-sidebar-inner {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.chat-sidebar-header,
.chat-search-box {
    background-color: #fff !important;
    border-bottom: 1px solid #e9ecef !important;
    padding: 14px 16px;
    display: flex;
    align-items: center;
}

.chat-search-box {
    padding: 10px 12px;
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
}

/* Card User */
.conversation-item {
    display: flex;
    align-items: center;
    cursor: pointer;
    background-color: #fff !important;
    margin: 8px 12px !important;
    padding: 12px 14px !important;
    border-radius: 12px !important;
    border: 1px solid #e9ecef !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02) !important;
    transition: all 0.2s ease-in-out !important;
}

    .conversation-item:hover {
        background-color: #ffffff !important;
        border-color: #ced4da !important;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05) !important;
        transform: translateY(-1px);
    }

    .conversation-item.active {
        background-color: #e7f3ff !important;
        color: #305669;
        border-color: #a3cbf7 !important;
        box-shadow: 0 4px 10px rgba(13, 110, 253, 0.08) !important;
    }

/* Nút xóa hội thoại */
.btn-xoa-hoithoai {
    display: none;
    flex-shrink: 0;
    background: none;
    border: none;
    color: #adb5bd;
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    line-height: 1;
}

.btn-xoa-hoithoai:hover {
    color: #dc3545;
    background-color: #fff0f0;
}

.conversation-item:hover .btn-xoa-hoithoai,
.conversation-item.confirming .btn-xoa-hoithoai {
    display: flex;
    align-items: center;
}

.xac-nhan-xoa {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    white-space: nowrap;
}

.btn-xs {
    font-size: 0.75rem;
    line-height: 1.2;
}

/* Thông tin Text Sidebar */
.conv-info {
    flex: 1;
    min-width: 0;
}

.conv-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.conv-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: #1c1e21;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-time {
    font-size: 0.75rem;
    color: #65676b;
    white-space: nowrap;
    margin-left: 6px;
}

.conv-last-msg {
    font-size: .8rem;
    display: flex;
    align-items: center;
    gap: 4px;
    overflow: hidden;
}

    .conv-last-msg > span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

.badge-unread {
    background: #e41e3f;
    color: #fff;
    border-radius: 10px;
    padding: 1px 6px;
    font-size: .68rem;
    font-weight: 600;
    flex-shrink: 0;
    margin-left: auto;
    box-shadow: 0 2px 4px rgba(228, 30, 63, 0.2);
}

/* Tìm kiếm Sidebar */
.chat-search-results {
    border-bottom: 1px solid #dee2e6;
    max-height: 200px;
    overflow-y: auto;
}

.search-result-item {
    display: flex;
    align-items: center;
    padding: 8px 14px;
    cursor: pointer;
    transition: background .15s;
}

    .search-result-item:hover {
        background: #f0f4ff;
    }

/* ================================================
   3. KHUNG CHAT CHÍNH (MAIN CHAT)
   ================================================ */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
    background: #fff;
    min-width: 0;
    height: 100% !important;
    max-height: 100% !important;
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #adb5bd;
}

.chat-empty-icon {
    font-size: 4rem;
    opacity: .4;
}

.chat-window-wrap {
    height: 100% !important;
    max-height: 100% !important;
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
    border: 1px solid #ced4da !important;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    border-radius: 12px;
}

.chat-window-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background-color: #f0f4ff !important;
    border-bottom: 1px solid #dbe4ff !important;
    flex-shrink: 0;
}

.message-list {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background-color: #edf1f5 !important; /* Nền khu vực nhắn tin */
    min-height: 0 !important; /* Rất quan trọng để tránh tràn */
    overflow-y: auto !important;
}

/* ================================================
   4. BONG BÓNG TIN NHẮN (BUBBLES)
   ================================================ */
.message-bubble-wrap {
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    max-width: 100%;
}

.msg-content-wrap {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
}

.message-bubble-wrap.mine {
    align-self: flex-end;
}

    .message-bubble-wrap.mine .msg-content-wrap {
        align-items: flex-end;
    }

.message-bubble-wrap.theirs {
    align-self: flex-start;
    flex-direction: row;
    gap: 6px;
    max-width: 75%;
}

    .message-bubble-wrap.theirs .msg-content-wrap {
        align-items: flex-start;
    }

.msg-bubble-row {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative !important;
    max-width: 100%;
}

.message-bubble-wrap.mine .msg-bubble-row {
    flex-direction: row-reverse;
}

.msg-bubble {
    padding: 8px 12px 6px 12px;
    font-size: 0.93rem;
    line-height: 1.4;
    word-break: break-word;
    border: none !important;
}

/* Tin nhắn Mình gửi */
.bubble-mine {
    background: #cce4fb !important;
    color: #1a2e40 !important;
    border-radius: 18px 18px 4px 18px !important;
    box-shadow: 0 1px 3px rgba(0, 100, 200, 0.1) !important;
}

/* Tin nhắn Người khác */
.bubble-theirs {
    background-color: #ffffff !important;
    color: #212529 !important;
    border-radius: 18px 18px 18px 4px !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07) !important;
}

.highlight-bubble .msg-bubble {
    box-shadow: 0 0 0 3px #ffe16a !important;
    transition: box-shadow 0.5s ease;
}

.msg-text {
    font-size: .875rem;
    white-space: pre-wrap;
}

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 1px;
}

.msg-time {
    font-size: 0.7rem;
    margin-top: 0;
    opacity: 0.7;
    display: block;
    text-align: right;
}

.bubble-mine .msg-time {
    color: rgba(26, 46, 64, 0.55);
}

.msg-sender-name {
    font-size: .72rem;
    color: #6c757d;
    margin-bottom: 2px;
    padding-left: 2px;
}

.msg-image {
    max-width: 200px;
    border-radius: 8px;
}

.msg-file {
    display: flex;
    align-items: center;
    gap: 6px;
    color: inherit;
    text-decoration: none;
}

/* Avatar Chung */
.conv-avatar-wrap .conv-avatar, .msg-avatar {
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
    border: 2px solid #fff;
}

.conv-avatar-wrap {
    position: relative;
    flex-shrink: 0;
    margin-right: 10px;
}

.msg-avatar-wrap {
    align-self: flex-end;
    margin-right: 8px;
    flex-shrink: 0;
}

.msg-avatar-clickable {
    cursor: pointer;
    transition: opacity 0.15s, transform 0.15s;
}

    .msg-avatar-clickable:hover {
        opacity: 0.85;
        transform: scale(1.08);
    }

/* Popup xem ảnh avatar lớn */
.avatar-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeInOverlay 0.15s ease;
}

@keyframes fadeInOverlay {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.avatar-preview-box {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    background: #fff;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.3);
    animation: popIn 0.18s ease;
}

@keyframes popIn {
    from { transform: scale(0.85); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

.avatar-preview-img {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.avatar-preview-name {
    font-weight: 600;
    font-size: 1rem;
    color: #1c2b3a;
}

.avatar-preview-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1rem;
    color: #adb5bd;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    border-radius: 50%;
    transition: color 0.15s, background 0.15s;
}

    .avatar-preview-close:hover {
        color: #dc3545;
        background: #fff0f0;
    }

.conv-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
}

.conv-avatar-sm {
    width: 34px;
    height: 34px;
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.online-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #28a745;
    border: 2px solid #fff;
}

/* Avatar Default */
.conv-avatar-default, .msg-avatar-default {
    background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%) !important;
    color: #495057 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.conv-avatar-default {
    font-size: 1rem;
}

.msg-avatar-default {
    font-size: .7rem;
}

/* ================================================
   5. MENU CÔNG CỤ HOVER (TRẢ LỜI, SỬA, XÓA)
   ================================================ */
.msg-action-menu {
    position: absolute;
    bottom: calc(100% + 4px);
    transform: none;
    display: flex;
    gap: 4px;
    z-index: 200;
    background: #fff;
    padding: 4px;
    border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    opacity: 0;
    visibility: hidden;
    animation: fadeInMenu 0.15s ease-in-out;
    white-space: nowrap;
}

.message-bubble-wrap:hover .msg-action-menu {
    opacity: 1;
    visibility: visible;
}

.message-bubble-wrap.theirs .msg-action-menu {
    left: 0;
    right: auto;
    margin-left: 0;
}

.message-bubble-wrap.mine .msg-action-menu {
    right: 0;
    left: auto;
    margin-right: 0;
}

/* Cầu tàng hình chống chết vùng Hover - tạo vùng mở rộng xuống đến bubble */
.msg-action-menu::before {
    content: "";
    position: absolute;
    bottom: -8px;
    left: 0;
    right: 0;
    height: 12px;
    background: transparent;
}

.message-bubble-wrap.mine .msg-action-menu::before {
    right: 0;
}

.message-bubble-wrap.theirs .msg-action-menu::before {
    left: 0;
}

@keyframes fadeInMenu {
    from {
        opacity: 0;
        transform: translateY(4px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.msg-action-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #65676b;
    transition: all 0.15s;
}

    .msg-action-btn:hover {
        background-color: #f0f2f5;
        color: #050505;
    }

    .msg-action-btn.text-danger:hover {
        color: #dc3545;
        background-color: #ffe6e6;
    }

.msg-emoji-quick {
    position: absolute;
    bottom: calc(100% + 4px);
    background: #fff;
    border: 1px solid #eaeaea;
    border-radius: 30px;
    padding: 6px 10px;
    display: flex;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 300;
    white-space: nowrap;
}

.emoji-quick-left {
    left: 0;
    right: auto;
}

.emoji-quick-right {
    right: 0;
    left: auto;
}

.action-menu-left {
    left: 0;
    right: auto;
}

.action-menu-right {
    right: 0;
    left: auto;
}

.emoji-quick-btn {
    border: none;
    background: transparent;
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.1s;
}

    .emoji-quick-btn:hover {
        transform: scale(1.2);
    }

/* ================================================
   6. GIAO DIỆN REPLY (TRẢ LỜI TIN NHẮN)
   ================================================ */
.msg-reply-preview {
    display: flex;
    align-items: center;
    background-color: #f8f9fa;
    padding: 8px 14px;
    margin: 10px 10px 0 10px;
    border: 1px solid #e9ecef;
    border-left: 4px solid #305669;
    border-radius: 6px;
}

.reply-preview-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-right: 10px;
}

.reply-preview-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #305669;
}

.reply-preview-text {
    font-size: 0.85rem;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-preview-close {
    background: transparent;
    border: none;
    color: #adb5bd;
    cursor: pointer;
    font-size: 1rem;
    padding: 0 4px;
}

    .reply-preview-close:hover {
        color: #dc3545;
    }

.msg-reply-ref {
    background-color: rgba(0, 0, 0, 0.06);
    padding: 6px 10px;
    border-radius: 8px;
    margin-bottom: 8px;
    border-left: 3px solid #adb5bd;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.reply-ref-mine {
    background-color: rgba(0, 90, 180, 0.12);
    border-left-color: #3d8fd4;
    color: #1a2e40;
}

.reply-ref-theirs {
    background-color: rgba(0, 0, 0, 0.05);
    border-left-color: #6c757d;
    color: #212529;
}

.reply-ref-name {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.reply-ref-text {
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.9;
}

/* ================================================
   7. THANH CÔNG CỤ SOẠN THẢO (INPUT & TOOLBAR)
   ================================================ */
.message-input-wrap {
    display: flex;
    flex-direction: column;
    border-top: 1px solid #dee2e6;
    background: #fff;
}

.msg-toolbar {
    display: flex;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    align-items: center;
    gap: 4px !important;
    padding: 6px 10px;
    background: #f8f9fa;
    border-bottom: 1px solid #f0f0f0;
}

    .msg-toolbar::-webkit-scrollbar {
        height: 0px;
        background: transparent;
    }

.msg-tool-btn {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.9rem;
    color: #333;
    transition: background 0.15s;
}

    .msg-tool-btn:hover {
        background: #e9ecef;
    }

    .msg-tool-btn.active {
        background: #d0e8ff;
        color: #0060c0;
        border-color: #90bfef;
    }

.msg-tool-select {
    border: 1px solid #ddd;
    border-radius: 4px;
    height: 30px;
    padding: 0 6px;
    font-size: 0.85rem;
    outline: none;
    background: #fff;
    cursor: pointer;
}

.msg-tool-color {
    border: none;
    width: 30px;
    height: 30px;
    padding: 0;
    cursor: pointer;
    background: transparent;
}

/* ── Color palette popup ─────────────────────────── */
.msg-color-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.msg-color-toggle {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 0 5px !important;
}

.msg-color-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,.25);
    flex-shrink: 0;
}

.msg-color-palette {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    z-index: 200;
    background: #fff;
    border: 1px solid #dde3f0;
    border-radius: 8px;
    padding: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
    display: grid;
    grid-template-columns: repeat(5, 22px);
    gap: 4px;
}

/* Popup màu — position:fixed thoát overflow:hidden của container cha */
.msg-color-palette-fixed {
    position: fixed;
    z-index: 9999;
    background: #fff;
    border: 1px solid #dde3f0;
    border-radius: 8px;
    padding: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,.16);
    display: grid;
    grid-template-columns: repeat(5, 22px);
    gap: 4px;
}

.msg-color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform .1s, border-color .1s;
    padding: 0;
}

.msg-color-swatch:hover {
    transform: scale(1.2);
    border-color: rgba(0,0,0,.3);
}

.msg-color-swatch.active {
    border-color: #3b82f6;
    outline: 2px solid #3b82f650;
}

.msg-tool-divider {
    width: 1px;
    height: 20px;
    background: #ccc;
    margin: 0 4px;
}

.message-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px !important;
    background: #fff;
    flex-shrink: 0;
}

.msg-input-richtext {
    flex: 1;
    background-color: #f0f2f5;
    border: none !important;
    border-radius: 20px !important;
    padding: 8px 12px !important;
    min-height: 40px;
    max-height: 150px;
    overflow-y: auto;
    outline: none;
    transition: background-color .15s;
    font-size: .875rem;
    line-height: 1.4;
}

    .msg-input-richtext:focus {
        background-color: #e4e6eb;
    }

.btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent;
    color: #0084ff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    transition: background .15s, color .15s;
}

    .btn-send:hover:not(:disabled) {
        background: #f0f2f5;
        color: #0072ff;
    }

    .btn-send:disabled, .btn-send.disabled {
        opacity: .4;
        cursor: default;
        color: #adb5bd;
    }

/* Khu vực chọn Emoji Tool */
.msg-emoji-wrap {
    position: relative;
}

/* Popup Emoji — position:fixed thoát overflow:hidden của container cha */
.emoji-picker-fixed {
    position: fixed;
    z-index: 9999;
    width: 260px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.14);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    max-height: 220px;
    overflow-y: auto;
}

/* Giữ tương thích với emoji-picker cũ (dùng trong các nơi khác nếu có) */
.emoji-picker {
    position: absolute;
    bottom: 40px;
    left: 0;
    width: 250px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
}

.emoji-btn {
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
}

    .emoji-btn:hover {
        background: #f0f2f5;
        border-radius: 4px;
    }

/* Gõ chữ Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    margin-bottom: 4px;
}

    .typing-indicator span {
        width: 7px;
        height: 7px;
        background: #adb5bd;
        border-radius: 50%;
        animation: typingBounce 1.2s infinite ease-in-out;
    }

        .typing-indicator span:nth-child(2) {
            animation-delay: .2s;
        }

        .typing-indicator span:nth-child(3) {
            animation-delay: .4s;
        }

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-6px);
    }
}

/* ================================================
   8. CHAT POPUP (CỬA SỔ NHỎ GÓC PHẢI DƯỚI)
   ================================================ */
.chat-popup-container {
    position: fixed;
    bottom: 0;
    right: 16px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    z-index: 1050;
}

/* Ẩn popup khi ở trang full /chat */
body:has(.chat-page) .chat-popup-container {
    display: none !important;
}

.chat-popup-panel {
    width: 56px;
    /*background: #fff;*/
    border-radius: 12px 12px 0 0;
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
    overflow: hidden;
    transition: width .2s, height .2s;
}

    .chat-popup-panel.expanded {
        width: 300px;
    }

.chat-popup-toggle {
    width: 56px;
    height: 56px;
    background: #305669;
    color: #fff;
    border: none;
    border-radius: 12px 12px 0 0;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.chat-popup-toggle:hover {
    opacity: 1;
}

.chat-badge-total {
    position: absolute;
    top: 6px;
    right: 6px;
    background: #dc3545;
    color: #fff;
    border-radius: 10px;
    padding: 1px 5px;
    font-size: .65rem;
    font-weight: 700;
    min-width: 16px;
    text-align: center;
}

.chat-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f0;
    background: #305669;
    color: #fff;
}

.chat-popup-header-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 4px;
    border: none;
    background: rgba(255,255,255,.15);
    color: #fff;
    font-size: .85rem;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s;
    flex-shrink: 0;
}

    .chat-popup-header-btn:hover {
        background: rgba(255,255,255,.3);
        color: #fff;
    }

.chat-popup-search {
    padding: 8px 10px;
    border-bottom: 1px solid #f0f0f0;
}

.chat-popup-list {
    max-height: 320px;
    overflow-y: auto;
}

.chat-popup-window {
    width: 280px;
    background: #fff;
    border: 1px solid #ced4da !important;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 12px 12px 0 0 !important;
    border-bottom: none !important;
}

.popup-win-header {
    display: flex;
    align-items: center;
    padding: 10px;
    background-color: #f0f4ff !important;
    border-bottom: 1px solid #dbe4ff !important;
    cursor: pointer;
    user-select: none;
}

.popup-win-unread {
    background: #dc3545;
    color: #fff;
    border-radius: 10px;
    padding: 1px 5px;
    font-size: .65rem;
    font-weight: 700;
    min-width: 16px;
    text-align: center;
    margin-left: 4px;
    flex-shrink: 0;
}

.btn-popup-action {
    background: none;
    border: none;
    padding: 2px 5px;
    color: #6c757d;
    cursor: pointer;
    border-radius: 4px;
    font-size: .8rem;
}

    .btn-popup-action:hover {
        background: #f0f0f0;
    }

.popup-win-body {
    display: flex;
    flex-direction: column;
    height: 360px;
}

.popup-message-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    background: #fff;
}

    .popup-message-list .message-bubble-wrap {
        max-width: 85%;
    }

/* ================================================
   9. ĐIỀU HƯỚNG RESPONSIVE (MOBILE)
   ================================================ */
@media (max-width: 768px) {
    .chat-popup-window {
        display: none;
    }

    .chat-sidebar, .chat-main {
        width: 100% !important;
        min-width: 100% !important;
    }

    .chat-mobile-hidden {
        display: none !important;
    }
}
