.chat-container {
    height: 80vh;
    display: flex;
    flex-direction: column;
}

.chat-header {
    flex-shrink: 0;
    background: white;
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 5px;
}

.chat-header-info:hover {
    cursor: pointer;
    border-radius: 10px;
    background-color: var(--bs-secondary-bg);
}

.chat-header-info img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-header-title h6 {
    margin: 0;
    font-weight: 600;
}

.chat-header-title small {
    color: #666;
    font-size: 12px;
}

.message-section {
    flex: 1;
    background: #ffffff;
    padding: 12px;
    overflow-y: auto;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    display: flex;
    /* Giữ nguyên chiều dọc nhưng đảo ngược vị trí bắt đầu */
    flex-direction: column-reverse;
}

/* Thêm dòng này để các group tin nhắn không bị đảo ngược nội dung bên trong */
.chat-messages > * {
    flex-shrink: 0;
}

.message-group {
    margin-bottom: 20px;
}

.message-date {
    display: flex;
    justify-content: center;
    margin: 20px 0 10px 0;
    width: 100%;
}

.message-date span {
    background: #e3e3e3;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    color: #666;
}

.message {
    display: flex;
    margin-bottom: 15px;
    gap: 10px;
}

.message.sent {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
}

.message-content {
    max-width: 70%;
}

.message.sent .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.message-bubble {
    padding: 10px 15px;
    border-radius: 18px;
    margin-bottom: 4px;
    word-wrap: break-word;
}

.message.received .message-bubble {
    background: white;
    border: 1px solid #e0e0e0;
    border-top-left-radius: 4px;
}

.message.sent .message-bubble {
    background: #e3f2fd;
    border: 1px solid #bbdefb;
    border-top-right-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: #999;
    padding: 0 5px;
}

.chat-input {
    background: white;
    border-top: 1px solid #e0e0e0;
    padding: 15px 20px;
    flex-shrink: 0;
}

.chat-input-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-input-group input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    padding: 10px 20px;
    outline: none;
}

.chat-input-group input:focus {
    border-color: #5e72e4;
}

.btn-send {
    background: #5e72e4;
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.btn-send:hover {
    background: #4c63d2;
}

.user-list {
    height: calc(100vh - 65px);
    background: white;
    border-radius: 8px;
    overflow: hidden;
}

.user-list-header {
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.user-list-header input {
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 8px 15px;
    font-size: 14px;
}

#createGroupBtn {
    border-radius: 50%;
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-list-body {
    padding-bottom: 60px;
    overflow-y: auto;
    height: calc(100% - 60px);
}

.user-item {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    border-bottom: 1px solid #f5f5f5;
    transition: background 0.2s;
}

.user-item:hover {
    background: #f8f9fa;
}

.user-item.active {
    background: #e3f2fd;
}

.user-item img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.user-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 60%;
}

.user-item-info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.user-item-info-header h6 {
    margin: 0;
    font-size: 14px;

    /*  chống xô layout */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-item-info-header .left {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0; /*  cực quan trọng để ellipsis hoạt động */
    flex: 1;
}

.user-item-info-header .time {
    flex-shrink: 0;
    font-size: 11px;
    color: #6b7280;
}

.user-item-info h6 {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.user-item-info p {
    font-size: 13px;
    color: #6c757d;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 0;
}

.user-item-info p.newMessage, .user-item-info .time.newMessage {
    font-weight: 600;
    color: rgba(0, 0, 0, 0.8);
}

.user-badge {
    position: absolute;
    margin-top: 20px;
    right: 10px;
    width: 16px;
    height: 16px;
    background: #f44336;
    color: white;
    border-radius: 50%;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.dropdown-menu {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.logo-brand {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-room-item {
    position: relative;
}

.chat-room-item .badge {
    font-size: 10px;
    padding: 2px 6px;
}

.user-list-body::-webkit-scrollbar {
    width: 6px;
}

.user-list-body::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.user-list-body::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.user-list-body::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Group creation modal styles */
.member-item:hover {
    background-color: #f8f9fa;
}

.member-item.selected {
    background-color: #e3f2fd;
}

.selected-member-item {
    background-color: white;
}

.selected-member-item:hover {
    background-color: #f8f9fa;
}

#memberList::-webkit-scrollbar,
#selectedMembers::-webkit-scrollbar {
    width: 6px;
}

#memberList::-webkit-scrollbar-track,
#selectedMembers::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#memberList::-webkit-scrollbar-thumb,
#selectedMembers::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

#memberList::-webkit-scrollbar-thumb:hover,
#selectedMembers::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.remove-member-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* nav type message */
.chat-filter-tabs {
    display: flex;
    gap: 14px;
    border-bottom: 1px solid #eee;
    margin-bottom: 6px;
    padding: 0 4px;
}

.chat-filter-tabs .nav-link {
    background: none !important;
    border: none;
    font-size: 12.5px;
    padding: 4px 0;
    color: #666;
    border-radius: 0;
    position: relative;
    transition: 0.2s;
}

.chat-filter-tabs .nav-link:hover {
    color: #000;
}

.chat-filter-tabs .nav-link.active {
    color: #0d6efd;
    font-weight: 600;
}

/* gạch chân */
.chat-filter-tabs .nav-link.active::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -7px;
    width: 100%;
    height: 2px;
    background: #0d6efd;
    border-radius: 2px;
}

/* css chat system room */
.chat-room-item.system {
    height: 80px;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.28), #fff);
}

/* css modal create new message or group message */
.chat-create-modal .modal-content {
    border-radius: 18px;
}

/* tab */
.chat-tabs {
    display: flex;
    background: #f3f4f6;
    border-radius: 12px;
    padding: 4px;
    margin: 0 16px;
}

.chat-tab {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px;
    border-radius: 10px;
    font-weight: 500;
}

.chat-tab.active {
    background: #fff;
    color: #2563eb;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* search */
.search-input {
    border-radius: 12px;
}

/* member list box */
.member-box {
    height: 320px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    padding: 6px;
}

.member-selected {
    background: #f9fafb;
}

/* empty */
.empty {
    text-align: center;
    padding-top: 70px;
    color: #9ca3af;
}

.empty i {
    font-size: 32px;
}

/* css dropdown menu chat room options */
.dropdown-menu {
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    padding: 8px 0;
}

.dropdown-item {
    padding: 8px 16px;
    font-size: 14px;
    transition: all 0.2s;
}

.dropdown-item:hover {
    background: #f0f2f5;
}

.dropdown-item i {
    width: 20px;
    text-align: center;
}

/* css disable event ở item thành viên dc tìm kiếm */
.member-disabled {
    pointer-events: none;
    cursor: not-allowed;
}

/* css modal info member chat */
.room-info-dialog .modal-content {
    max-height: 430px;
    display: flex;
}

.room-info-dialog .modal-body {
    overflow-y: hidden;
}

#memberSection {
    height: 255px;
    overflow-y: auto;
}

/* css thanh gửi tin nhắn  , button ẹmoji img */
.chat-input-group {
    background: #fff;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chat-input-group input {
    border: none;
    outline: none;
    background: #f1f3f5;
    padding: 8px 12px;
    border-radius: 20px;
}

.btn-action {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: 0.15s;
}

.btn-action:hover {
    background: #f1f3f5;
}

.btn-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: #0d6efd;
    color: white;
}

/* css image preiview */


/* khung input */
.input-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column; /* ảnh trên, input dưới */
    gap: 6px;

    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 8px 12px;
    background: #fff;
    flex-shrink: 0;
    max-height: 170px;
    overflow-y: auto;
}


/* text input */
.text-input {
    width: 100%;
    border: none;
    outline: none;
}

/* preview */
.image-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
}

/* mỗi ảnh */
.preview-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid #ab8cca;
    flex-shrink: 0;
    transition: 0.2s;
}

.preview-item:hover {
    border-color: #764ba2;
    transform: scale(1.05);
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

/* nút xoá */
.preview-item .remove {
    position: absolute;
    top: -6px;
    right: -6px;

    width: 22px;
    height: 22px;

    background: #ff4d4f;
    color: #fff;
    font-size: 14px;
    font-weight: bold;

    border-radius: 50%;
    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;

    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.btn-action {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
}

.preview-item .remove {
    opacity: 0;
    transition: .2s;
}

.preview-item:hover .remove {
    opacity: 1;
}

/* modal view full img */
.image-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.image-modal img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 6px;
}

.close-btn-imageModal {
    position: absolute;
    top: 20px;
    right: 25px;
    font-size: 28px;
    color: white;
    cursor: pointer;
    user-select: none;
}

/* css message có ảnh */
.message.received .image-message {
    display: flex;
    flex-direction: column; /*  xếp dọc */
    gap: 6px;
    padding-bottom: 5px;
}

.message.sent .image-message {
    display: flex;
    align-items: flex-end;
    flex-direction: column; /*  xếp dọc */
    gap: 6px;
    padding-bottom: 5px;
}

.image-text {
    background: #f1f1f1;
    padding: 6px 10px;
    border-radius: 12px;

    display: inline-block; /*  tự fit theo text */
    width: fit-content;
}

.chat-image {
    max-width: 240px;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

/* ===== SENT (mạnh hơn 1 chút) ===== */
.sent .chat-image.selected {
    background: rgba(59,130,246,0.15);
    border-color: #3b82f6;
    box-shadow: 0 4px 14px rgba(59,130,246,.28);
    transform: scale(1.02);
}


/* ===== RECEIVED (nhẹ hơn) ===== */
.received .chat-image.selected {
    background: #e9f7ef;   /* nhạt hơn #d1e7dd */
    border-color: #198754;
    color: #0f5132;
    box-shadow: 0 2px 8px rgba(25,135,84,.15);
}

/* css div hiển thị đã rời nhóm */
.system-wrapper{
    display:flex;
    justify-content:center;
    margin:18px 0;
}

.system-pill{
    background:#f1f5f9;
    color:#64748b;
    font-size:12.5px;
    padding:6px 14px;
    border-radius:999px;
    border:1px solid #e2e8f0;
    font-weight:500;
}
/* css member là trưởng nhóm */
/* highlight row leader */
.member-item.leader {
    background: #fff9e6;
}

/* badge crown */
.leader-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    background: #fbbf24;
    color: #7c2d12;
    font-weight: 600;
    white-space: nowrap;
}
/*  css text message delete */

.message-bubble.deleted {
  background: #f1f1f1 !important;
  color: #888;
  font-style: italic;
  border: 1px dashed #ccc;
}

/*  css thong báo tin nhắn mới các tab  */
.unread-badge {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #ff3b30;
  border-radius: 50%;
  display: inline-block;
  right: -8px;
  bottom: 14px;
}

/*  css không cho chat  */
.chat-restricted-message {
  background: linear-gradient(135deg, #fff3cd, #ffe69c);
  color: #856404;
  padding: 12px;
  border-radius: 10px;
  font-size: 14px;
  gap: 8px;
  border: 1px solid #ffe69c;
  display: flex;
  justify-content: center;
}

.chat-restricted-message i {
  font-size: 16px;
}

/*  css button edit room ( ten phong , avatar ) */
.chat-header-title {
  position: relative;
  display: flex;
  align-items: flex-start;
  flex-direction: column;
}

.group-edit-btn {
  background: transparent;
  border: none;
  padding: 2px 4px;
  margin-left: 6px;
  font-size: 14px;
  color: #6c757d; /* màu bạn đang dùng */
  opacity: 0;
  transition: opacity 0.2s ease, color 0.2s ease;
  cursor: pointer;
}

.group-edit-btn:hover {
  color: #0d6efd; /* hover xanh nhẹ */
}

.chat-header-title:hover .group-edit-btn {
  opacity: 1;
}

/*  css modal edit room name */
.group-avatar-wrapper {
  cursor: pointer;
}

.avatar-edit-btn {
  display: flex;
  align-items: center;
  position: absolute;
  width: 24px;
  height: 24px; 
  bottom: 10px;
  right: 0;
  background: white;
  border-radius: 50%;
  padding: 6px;
  font-size: 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: all 0.2s ease;
}

.avatar-edit-btn:hover {
  background: #f1f1f1;
}

#groupAvatarPreview {
  transition: 0.2s ease;
}

#groupAvatarPreview:hover {
  opacity: 0.85;
}