/* =============================================
   CHAT SYSTEM STYLES v3 - Bright Modern Theme
   ============================================= */

/* --- CSS Variables --- */
:root {
    --chat-primary: #4f8cff;
    --chat-primary-dark: #3b6fd9;
    --chat-primary-light: #7eb3ff;
    --chat-accent: #f472b6;
    --chat-bg: #ffffff;
    --chat-bg-subtle: #f0f4fa;
    --chat-bg-msg: #e8edf5;
    --chat-text: #1a2233;
    --chat-text-muted: #7b8a9e;
    --chat-border: #dce3ed;
    --chat-shadow: rgba(0,0,0,0.08);
    --chat-own-bg: var(--chat-primary);
    --chat-own-text: #fff;
    --chat-radius: 14px;
    --chat-transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Floating Action Button (nhỏ, mờ, kéo thả) --- */
.chat-fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #4CAF50;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 4px 20px rgba(79,140,255,0.35);
    z-index: 9999;
    transition: all var(--chat-transition);
    opacity: 0.55;
    user-select: none;
    touch-action: none;
}
.chat-fab:hover {
    opacity: 1;
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(79,140,255,0.5);
}
.chat-fab-active {
    opacity: 1;
    background: var(--chat-primary-dark);
}
.chat-fab-notify {
    animation: chat-pulse 2s infinite;
    opacity: 0.85;
}
@keyframes chat-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(79,140,255,0.35); }
    50% { box-shadow: 0 4px 30px rgba(244,114,182,0.6); }
}
.chat-fab-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #F44336;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--chat-bg);
    box-shadow: 0 2px 8px rgba(236,72,153,0.3);
}

/* --- Chat Panel --- */
.chat-panel {
    position: fixed;
    bottom: 74px;
    right: 20px;
    width: 370px;
    max-height: 540px;
    background: var(--chat-bg);
    border-radius: 16px;
    box-shadow: 0 8px 32px var(--chat-shadow), 0 0 0 1px var(--chat-border);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: fadeInPopup 0.25s ease-out forwards !important;
}
@keyframes fadeInPopup {
    0% {
        opacity: 0;
        transform: translateY(-5px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}
@keyframes chat-slide-up {
    from { opacity: 0; transform: translateY(16px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-panel-header {
    background: #4CAF50;
    color: #fff;
    padding: 16px 16px 12px;
}
.chat-panel-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.chat-panel-header h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color:#fff !important;
}
.chat-panel-header h4 i{
    margin-right:10px;
}
.chat-panel-tabs {
    display: flex;
    gap: 4px;
}
.chat-panel-tabs button {
    flex: 1;
    padding: 7px 12px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.75);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all var(--chat-transition);
    backdrop-filter: blur(4px);
}
    .chat-panel-tabs button i{
        margin-right:6px;
    }
    .chat-panel-tabs button.active {
        background: rgba(255,255,255,0.25);
        color: #fff;
        font-weight: 700;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
.chat-panel-tabs button:hover:not(.active) {
    background: rgba(255,255,255,0.15);
    color: #fff;
}
.chat-panel-body {
    flex: 1;
    overflow-y: auto;
    max-height: 420px;
}
.chat-panel-body::-webkit-scrollbar { width: 4px; }
.chat-panel-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* --- Room list --- */
.chat-room-list, .chat-user-list { padding: 4px 0; }
.chat-room-item, .chat-user-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    cursor: pointer;
    transition: all var(--chat-transition);
    gap: 12px;
    border-left: 3px solid transparent;
    border-bottom:1px solid #e2e8f0;
}
    .chat-room-item:last-child,
    .chat-user-item:last-child {
        border-bottom: 0px solid #e2e8f0;
    }
    .chat-room-item:hover, .chat-user-item:hover {
        background: var(--chat-bg-subtle);
        border-left-color: var(--chat-primary-light);
    }
.chat-room-unread {
    background: #F1F8E9;
    border-left-color: #4CAF50 !important;
}
.chat-room-avatar, .chat-user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f8cff, #a78bfa);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
    position: relative;
    box-shadow: 0 2px 8px rgba(99,102,241,0.2);
}
.chat-room-avatar-group {
    background: linear-gradient(135deg, #7c6fff, #f472b6);
}
.chat-room-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}
.chat-user-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}
.chat-online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fff;
    box-shadow: 0 0 6px rgba(34,197,94,0.4);
}
.chat-room-info, .chat-user-info { flex: 1; min-width: 0; }
.chat-room-name, .chat-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--chat-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}
.chat-room-type-badge {
    font-size: 10px;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.chat-room-type-badge.chat-room-type-group {
    color: var(--chat-primary);
}
.chat-room-type-badge.chat-room-type-private {
    color: var(--chat-accent, #805ad5);
}
.chat-room-last-msg {
    font-size: 12px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.chat-room-item.chat-room-unread .chat-room-last-msg {
    color: #388E3C;
}
    .chat-user-dept {
        font-size: 11px;
        color: var(--chat-text-muted);
    }
.chat-user-action {
    color: var(--chat-primary-light);
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.2s;
}
.chat-user-item:hover .chat-user-action { opacity: 1; }
.chat-room-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}
.chat-room-time { font-size: 10px; color: var(--chat-text-muted); }
.chat-badge {
    background: #E91E63;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* --- Chat Windows --- */
.chat-windows-container {
    position: fixed;
    bottom: 0;
    right: 74px;
    display: flex;
    gap: 8px;
    z-index: 10001;
    flex-direction: row-reverse;
    pointer-events: none;
}
.chat-windows-container > * { pointer-events: auto; }
.chat-window {
    width: 440px;
    height: 560px;
    background: var(--chat-bg);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 32px var(--chat-shadow), 0 0 0 1px var(--chat-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: calc(100vh - 60px);
    position: relative;
    border: 2px solid #4CAF50;
}
@keyframes chat-window-appear {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-window-minimized {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    resize: none !important;
}
.chat-window-header {
    background: #4CAF50;
    color: #fff;
    padding: 11px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: grab;
    user-select: none;
    box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
    margin-bottom: 5px !important;
}
.chat-window-header:active { cursor: grabbing; }
.chat-window-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color:#fff !important;
}
.chat-window-title .chat-badge { margin-left: 6px; }
.chat-window-actions { display: flex; gap: 4px; align-items: center; }
.chat-header-menu { position: relative; }
.chat-header-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    min-width: 180px;
    z-index: 100;
    padding: 4px 0;
    animation: chatFadeIn 0.12s ease;
}
.chat-header-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 14px;
    border: none;
    background: none;
    font-size: 12px;
    color: var(--chat-text);
    cursor: pointer;
    transition: background 0.12s;
    white-space: nowrap;
}
.chat-header-dropdown-item:hover { background: #f1f5f9; }
.chat-header-dropdown-item i { width: 16px; text-align: center; color: #64748b; }
.chat-header-dropdown-danger { color: #ef4444; }
.chat-header-dropdown-danger:hover { background: #fee2e2; }
.chat-header-dropdown-danger i { color: #ef4444; }
.chat-btn-icon {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all var(--chat-transition);
}
.chat-btn-icon:hover { background: rgba(255,255,255,0.25); }

/* --- Chat Body --- */

.chat-window-body {
    flex: 1;
    overflow-y: auto;
    overflow-x:hidden;
    padding: 10px;
    background: var(--chat-bg-subtle);
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}
    .chat-window-body::-webkit-scrollbar {
        width: 8px;
        background-color: #F5F5F5;
    }
    .chat-window-body::-webkit-scrollbar-thumb {
        border-radius: 6px;
    }
.chat-loading {
    text-align: center;
    padding: 20px;
    color: var(--chat-text-muted);
    font-size: 13px;
}
.chat-empty {
    text-align: center;
    padding: 40px 16px;
    color: var(--chat-text-muted);
    font-size: 13px;
}
.chat-load-more { text-align: center; padding: 6px; }
.chat-btn-loadmore {
    border: none;
    background: #e2e8f0;
    color: #475569;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}
.chat-btn-loadmore:hover { background: #cbd5e1; }

/* --- Messages --- */
.chat-msg:first-child {
    margin-top: 35px;
}
.chat-msg {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-bottom:20px !important;
}
.chat-msg-own {
    margin-left: auto;
    flex-direction: row-reverse;
}
.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #F57C00;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 6px;
    letter-spacing: 2px;
    box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px;
}
.chat-bubble-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
}
.chat-msg-own .chat-bubble-wrap { flex-direction: row-reverse; }
.chat-bubble {
    background: #fff;
    padding: 8px 12px;
    border-radius: var(--chat-radius);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    min-width: 60px;
    transition: box-shadow 0.2s;
}
.chat-bubble:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.chat-msg-own .chat-bubble {
    background: #fff;
    color: #000;
    border-bottom-left-radius: var(--chat-radius);
    border-bottom-right-radius: 4px;
}
.chat-sender {
    font-size: 11px;
    font-weight: 700;
    color: var(--chat-primary);
    margin-bottom: 2px;
}
.chat-text {
    font-size: 13px;
    line-height: 1.5;
    margin-top:5px;
    color:#000;
    word-break: break-word;
}
    .chat-text img{
        max-width:100%;
        height:auto;
    }
    .chat-meta {
        display: flex;
        align-items: center;
        gap: 6px;
        margin-top: 5px;
    }
.chat-time {
    font-size: 10px;
    color: var(--chat-text-muted);
    margin-right:5px;
    user-select:none;
    position:inherit;
}
.chat-msg-own .chat-time {
    color: #9E9E9E;
}
.chat-edited {
    font-size: 9px;
    color: var(--chat-text-muted);
    font-style: italic;
    margin-left: 5px;
    user-select: none;
    position: inherit;
}

/* Message action buttons */
.chat-msg {
    position: relative;
    padding-bottom: 4px;
}
.chat-bubble-wrap {
    position: relative;
}
.chat-msg-action-bar {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 0;
    display: none;
    align-items: center;
    gap: 2px;
    background: var(--chat-bg);
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 5px;
    padding: 2px 4px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    z-index: 10;
    background-color: #fff;
    pointer-events: auto;
}
.chat-msg-action-bar::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -10px;
    height: 10px;
}
.chat-msg-own .chat-msg-action-bar {
    right: 0;
    left: auto;
}
.chat-msg:hover .chat-msg-action-bar,
.chat-msg-action-bar:hover {
    display: flex;
}
.chat-msg-action-bar.show {
    display: flex;
}
.chat-msg:hover {
    z-index: 5;
}
.chat-msg-action-btn {
    width: 35px;
    height: 35px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    transition: all 0.15s;
}
.chat-msg-action-btn:hover { background: #f1f5f9; color: var(--chat-primary); }
.chat-msg-action-delete:hover { color: #ef4444; background: #fee2e2; }
.chat-pinned-icon { color: var(--chat-accent); }

/* Reaction picker dropdown */
.chat-reaction-picker {
    position: relative;
    padding-top: 0px;
}
.chat-reaction-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 1px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: 20px;
    padding: 4px 6px;
    gap: 2px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    white-space: nowrap;
    z-index: 20;
    pointer-events: auto;
}
.chat-reaction-dropdown.open {
    display: flex;
}
.chat-reaction-picker:focus-within .chat-reaction-dropdown {
    display: flex;
}
.chat-reaction-picker:hover .chat-reaction-dropdown,
.chat-reaction-dropdown:hover {
    display: flex;
}
.chat-reaction-emoji {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    font-size: 18px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s;
}
.chat-reaction-emoji:hover {
    background: #f1f5f9;
    transform: scale(1.3);
}

/* Reaction count badges */
.chat-reaction-counts {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
    margin-left: 42px;
    position:absolute;
    height:10px;
    bottom:0px;
  
}
.chat-msg-own .chat-reaction-counts {
    margin-left: auto;
    margin-right: 8px;
    justify-content: flex-end;
}
.chat-reaction-badge {
    position: relative;
    border: 0px solid var(--chat-border);
    background-color: #E8F5E9 !important;
    border-radius: 12px;
    padding: 2px 5px;
    font-size: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.chat-reaction-badge:hover {
    border-color: var(--chat-primary);
    box-shadow: 0 2px 8px rgba(79,140,255,0.2);
}
.chat-reaction-badge.active {
    background: #eef2ff;
    border-color: var(--chat-primary);
    color: var(--chat-primary-dark);
}
.chat-msg-own .chat-reaction-badge {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.3);
    color: #0288D1;
}
.chat-msg-own .chat-reaction-badge.active {
    background: rgba(255,255,255,0.3);
}

/* Reaction users tooltip */
.chat-reaction-users-tip {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 30;
    margin-bottom: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    pointer-events: none;
}
.chat-reaction-users-tip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: #1e293b;
}
.chat-reaction-badge:hover .chat-reaction-users-tip {
    display: block;
}

.chat-search-highlight {
    background: #fde68a;
    color: #7c2d12;
    border-radius: 3px;
    padding: 0 2px;
}

.chat-preview-actions {
    position: absolute;
    top: 24px;
    right: 24px;
    z-index: 2;
}

.chat-poll-create-panel {
    border-top: 1px solid var(--chat-border);
    padding: 10px 12px;
    display: grid;
    gap: 8px;
    background: #f8fafc;
}

/* Poll display - centered prominent style */
.chat-poll-box-centered {
    background: linear-gradient(135deg, #f8fafc, #eef2ff);
    border: 1px solid var(--chat-primary-light);
    border-radius: 14px;
    padding: 16px;
    min-width: 280px;
    max-width: 360px;
}
.chat-poll-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--chat-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.chat-poll-question-text {
    font-size: 14px;
    font-weight: 700;
    color: var(--chat-text);
    margin-bottom: 12px;
    line-height: 1.4;
}
.chat-poll-option-bar {
    position: relative;
    width: 100%;
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 6px;
    background: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s;
}
.chat-poll-option-bar:hover {
    border-color: var(--chat-primary-light);
    box-shadow: 0 2px 8px rgba(79,140,255,0.12);
}
.chat-poll-option-bar.voted {
    border-color: var(--chat-primary);
    background: #f0f4ff;
}
.chat-poll-option-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: rgba(79,140,255,0.1);
    border-radius: 10px;
    transition: width 0.4s ease;
    pointer-events: none;
}
.chat-poll-option-bar.voted .chat-poll-option-fill {
    background: rgba(79,140,255,0.18);
}
.chat-poll-option-label {
    position: relative;
    z-index: 1;
    font-weight: 500;
}
.chat-poll-option-count {
    position: relative;
    z-index: 1;
    font-size: 12px;
    color: var(--chat-text-muted);
    font-weight: 600;
}
.chat-poll-total {
    font-size: 11px;
    color: var(--chat-text-muted);
    margin-top: 8px;
    text-align: center;
}

/* Image media actions overlay */
.chat-media {
    margin-top:5px;
    margin-bottom:5px;
    position: relative;
    display: inline-block;
}
.chat-media-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: none;
    gap: 4px;
}
.chat-media:hover .chat-media-actions {
    display: flex;
}
.chat-media-actions a {
    width: 28px;
    height: 28px;
    background: rgba(0,0,0,0.55);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    text-decoration: none;
    transition: all 0.15s;
}
.chat-media-actions a:hover {
    background: rgba(0,0,0,0.8);
}
.chat-file-size-inline {
    color: #7B1FA2;
    font-size: 10px;
    margin-left:5px;
}

/* Time tooltip styled */
.chat-time-wrap {
    position: relative;
    display: inline-block;
}
.chat-time-tooltip {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 20;
    margin-bottom: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    pointer-events: none;
}
.chat-time-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: #1e293b;
}
.chat-time-wrap:hover .chat-time-tooltip {
    display: block;
}

/* Pinned message bar */
.chat-pinned-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: linear-gradient(90deg, #fef3c7, #fffbeb);
    border-bottom: 1px solid #fde68a;
    font-size: 12px;
    color: #92400e;
    cursor: pointer;
    transition: background 0.15s;
}
.chat-pinned-bar:hover {
    background: linear-gradient(90deg, #fde68a, #fef3c7);
}
.chat-pinned-bar i {
    color: #d97706;
}
.chat-pinned-bar-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Fullscreen mode */
.chat-window-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    z-index: 99999 !important;
    resize: none !important;
}

/* Mention popup */
.chat-mention-popup {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    z-index: 20;
    margin-bottom: 4px;
}
.chat-mention-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.12s;
}
.chat-mention-item:hover {
    background: var(--chat-bg-subtle);
}
.chat-mention-item-name {
    font-weight: 600;
}
.chat-mention-item-dept {
    font-size: 11px;
    color: var(--chat-text-muted);
}

/* --- Media --- */
.chat-media img {
    max-width: 100%;
    max-height: 250px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}
.chat-media img:hover { opacity: 0.9; transform: scale(1.01); }
.chat-filename {
    font-size: 11px;
    color: #3F51B5;
    margin-top: 2px;
    user-select:none;
    pointer-events:none;
}


/* --- File box --- */
.chat-file-box {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top:10px;
    padding: 8px 10px;
    background: var(--chat-bg-subtle);
    border-radius: 10px;
    min-width: 200px;
    border: 1px solid var(--chat-border);
    max-width:88%;
}

.chat-file-icon { font-size: 22px; color: var(--chat-primary); flex-shrink: 0; }
.chat-file-info { flex: 1; min-width: 0; }
.chat-file-name {
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select:none;
    pointer-events:none;
}
.chat-file-size {
    font-size: 11px;
    color: #7B1FA2;
    margin: 5px;
    user-select: none;
    pointer-events: none;
}
.chat-file-download {
    color: var(--chat-primary);
    font-size: 15px;
    padding: 4px;
    text-decoration: none;
    transition: transform 0.2s;
}
.chat-file-download:hover { transform: scale(1.15); }

/* --- Typing --- */
.chat-typing {
    font-size: 12px;
    color: var(--chat-text-muted);
    padding: 4px 8px;
    font-style: italic;
}

/* --- Edit banner --- */
.chat-edit-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #eef2ff;
    color: var(--chat-primary);
    font-size: 12px;
    font-weight: 600;
    border-left: 3px solid var(--chat-primary);
}
.chat-edit-banner button {
    margin-left: auto;
    border: none;
    background: none;
    color: var(--chat-text-muted);
    cursor: pointer;
    font-size: 12px;
}
.chat-edit-banner button:hover { color: var(--chat-text); }

/* --- Footer (input) --- */
.chat-window-footer {
    border-top: 1px solid var(--chat-border);
    background: var(--chat-bg);
    flex-shrink: 0;
}
.chat-toolbar {
    display: flex;
    align-items: center;
    gap: 1px;
    padding: 4px 8px;
    border-bottom: 1px solid #f1f5f9;
}
.chat-toolbar-sep {
    width: 1px;
    height: 18px;
    background: var(--chat-border);
    margin: 0 4px;
}
.chat-btn-tool {
    width: 28px;
    height: 26px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.15s;
    position: relative;
}
.chat-btn-tool:hover { background: #f1f5f9; color: var(--chat-primary); }
.chat-color-palette-wrap { position: relative; }
.chat-color-palette {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    padding: 6px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 10;
}
.chat-color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid #e2e8f0;
    transition: transform 0.1s;
}
.chat-color-swatch:hover { transform: scale(1.2); border-color: var(--chat-primary); }
.chat-fontsize-wrap { display: flex; align-items: center; }
.chat-fontsize-select {
    height: 26px;
    border: 1px solid var(--chat-border);
    border-radius: 5px;
    background: transparent;
    color: #64748b;
    font-size: 11px;
    padding: 0 4px;
    cursor: pointer;
    outline: none;
}
.chat-fontsize-select:hover { border-color: var(--chat-primary); }
.chat-input-area {
    display: flex;
    align-items: flex-end;
    padding: 6px 8px;
    gap: 6px;
}
.chat-input-wrap { flex: 1; }
.chat-editor {
    width: 100%;
    min-height: 36px;
    max-height: 80px;
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    padding: 7px 10px;
    font-size: 13px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
    overflow-y: auto;
    line-height: 1.4;
    word-break: break-word;
}
    .chat-editor:focus {
        border-color: #4CAF50;
        box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
    }
.chat-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--chat-text-muted);
    pointer-events: none;
}
.chat-btn-send {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: #4CAF50;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(79,140,255,0.3);
}
    .chat-btn-send:hover {
        background: #388E3C;
        transform: scale(1.05);
    }
.chat-btn-send:disabled { background: #cbd5e1; cursor: default; box-shadow: none; }
.chat-upload-progress {
    padding: 4px 12px;
    font-size: 12px;
    color: var(--chat-primary);
    text-align: center;
}

/* --- Emoji picker --- */
.chat-emoji-picker {
    display: flex;
    flex-wrap: wrap;
    padding: 8px;
    max-height: 150px;
    overflow-y: auto;
    border-top: 1px solid var(--chat-border);
    background: var(--chat-bg-subtle);
    gap: 1px;
}
.chat-emoji-item {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 6px;
    font-size: 17px;
    transition: all 0.15s;
}
.chat-emoji-item:hover { background: #e2e8f0; transform: scale(1.25); }

/* --- Preview overlay --- */
.chat-preview-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.88);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    animation: chat-fade-in 0.2s;
}
@keyframes chat-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
.chat-preview-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 10px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

/* --- Group Creation Modal --- */
.chat-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15,23,42,0.5);
    backdrop-filter: blur(4px);
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: chat-fade-in 0.2s;
}
.chat-modal {
    background: var(--chat-bg);
    border-radius: 16px;
    width: 420px !important;
    max-height: 80vh;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-bottom: 1px solid var(--chat-border);
}
    .chat-modal-header h5 {
        margin: 0;
        font-size: 15px;
        font-weight: 700;
        color: #7B1FA2;
        user-select:none;
        pointer-events:none;
    }
        .chat-modal-header h5 i{margin-right:6px;}
        .chat-modal-header .chat-btn-icon {
            background: #f1f5f9;
            color: #64748b;
        }
.chat-modal-body {
    padding: 10px;
    overflow-y: auto;
    flex: 1;
}
.chat-form-group { margin-bottom: 14px; }
.chat-form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--chat-text);
    margin-bottom: 5px;
}
.chat-form-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    box-sizing: border-box;
}
.chat-form-input:focus { border-color: var(--chat-primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.chat-selected-members {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 10px;
}
.chat-member-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: #eef2ff;
    color: var(--chat-primary);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}
.chat-member-chip i { cursor: pointer; font-size: 10px; opacity: 0.6; }
.chat-member-chip i:hover { opacity: 1; }
.chat-search-results {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--chat-border);
    border-radius: 8px;
}
.chat-search-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
}
.chat-search-item:hover:not(.disabled) { background: var(--chat-bg-subtle); }
.chat-search-item.disabled { opacity: 0.4; cursor: default; }
.chat-search-user { font-size: 11px; color: var(--chat-text-muted); }
.chat-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--chat-border);
}
.chat-btn-cancel {
    padding: 7px 16px;
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    background: var(--chat-bg);
    color: var(--chat-text);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.chat-btn-cancel:hover { background: #f1f5f9; }
.chat-btn-primary {
    padding: 7px 16px;
    border: none;
    border-radius: 8px;
    background: var(--chat-primary);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(79,140,255,0.3);
}
.chat-btn-primary:hover { background: var(--chat-primary-dark); }
.chat-btn-primary:disabled { background: #cbd5e1; cursor: default; box-shadow: none; }

/* --- Edit History --- */
.chat-edit-history-modal { max-width: 420px; }
.chat-edit-history-item {
    padding: 8px 0;
    border-bottom: 1px solid var(--chat-border);
    font-size: 12px;
}
.chat-edit-history-item:last-child { border-bottom: none; }
.chat-edit-history-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    color: var(--chat-text-muted);
    font-size: 11px;
}
.chat-edit-label {
    font-weight: 600;
    font-size: 11px;
    margin-right: 4px;
}
.chat-edit-history-old {
    background: #fef2f2;
    border-radius: 4px;
    padding: 4px 6px;
    margin-bottom: 2px;
    text-decoration: line-through;
    color: #b91c1c;
}
.chat-edit-history-new {
    background: #f0fdf4;
    border-radius: 4px;
    padding: 4px 6px;
    color: #166534;
}
.chat-btn-history {
    background: none;
    border: none;
    color: var(--chat-text-muted);
    cursor: pointer;
    font-size: 9px;
    padding: 0 2px;
}
.chat-btn-history:hover { color: var(--chat-primary); }

/* --- Deleted message placeholder --- */
.chat-msg-deleted .chat-bubble {
    background: #f8f9fb;
    border: 1px dashed var(--chat-border);
    box-shadow: none;
}
.chat-msg-deleted .chat-deleted-note {
    font-size: 12px;
    color: var(--chat-text-muted);
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 6px;
    color: #D32F2F;
}
.chat-msg-deleted .chat-deleted-note i { font-size: 11px; }

/* --- Avatar with image --- */
.chat-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

/* --- Richer sender info --- */
.chat-sender-info {

    align-items: baseline;
    gap: 6px;
    margin-bottom: 2px;
    user-select:none;
    pointer-events:none;
}
.chat-sender-name {
    font-size: 12px;
    font-weight: 700;
    color: #1565C0;
}
.chat-sender-username {
    font-size: 10px;
    color: #388E3C;
    display: inline-block;
    margin-left: 10px;
    vertical-align: top;
    font-weight: 500;
}
.chat-sender-dept {
    font-size: 10px;
    color: #607D8B;
    display: inline-block;
    margin-left: 5px;
    vertical-align: top;
    background-color:#f5f5f5;
    padding:2px 5px;
    margin-top:-3px;
}

/* --- Resize handle --- */
.chat-window {
    resize: both;
    overflow: hidden;
    min-width: 325px;
    min-height: 280px;
}
.chat-window::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, var(--chat-border) 50%);
    border-radius: 0 0 0 0;
    z-index: 5;
}

/* --- Highlight palette --- */
.chat-highlight-palette-wrap { position: relative; }
.chat-highlight-palette {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    padding: 6px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 10;
}

/* --- Delete room button in header --- */
.chat-window-actions .chat-btn-icon-danger:hover {
    background: rgba(239,68,68,0.3);
    color: #fee2e2;
}

/* --- Contact search & offline dot --- */
.chat-contact-search {
    padding: 10px 5px;
    border-bottom: 1px solid var(--chat-border);
}
    .chat-contact-search .chat-form-input {
        border-radius: 10px;
        padding: 7px 14px;
        font-size: 13px;
        background: #F5F5F5;
        font-weight: 500;
        color: #C2185B;
    }
.chat-section-label {
    padding: 8px 14px 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--chat-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.chat-section-label .text-success { color: #22c55e; font-size: 8px; }
.chat-offline-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #94a3b8;
    border: 2px solid #fff;
}

/* --- Sender change spacing --- */
.chat-msg-new-sender {
    margin-top: 25px !important;
}

/* --- Unread marker --- */
.chat-unread-marker {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    margin: 8px 0;
}
.chat-unread-marker::before,
.chat-unread-marker::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--chat-accent);
}
.chat-unread-marker span {
    font-size: 11px;
    font-weight: 600;
    color: var(--chat-accent);
    white-space: nowrap;
}

/* --- Unread message highlight --- */
.chat-msg-unread .chat-bubble {
    border-left: 3px solid var(--chat-accent);
    background: linear-gradient(90deg, rgba(99,102,241,0.06) 0%, transparent 100%);
    animation: chat-unread-pulse 2s ease-out 1;
}
@keyframes chat-unread-pulse {
    0% { background: rgba(99,102,241,0.15); }
    100% { background: linear-gradient(90deg, rgba(99,102,241,0.06) 0%, transparent 100%); }
}

/* --- Rich search item (group creation & management) --- */
.chat-search-item-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f8cff, #a78bfa);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
}
.chat-search-item-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}
.chat-search-item-info {
    flex: 1;
    min-width: 0;
}
.chat-search-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--chat-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin:10px !important;
}
.chat-search-item-meta {
    font-size: 11px;
    color: var(--chat-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 10px !important;
}

/* --- Room avatar edit --- */
.chat-room-avatar-edit {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--chat-bg-subtle);
    border: 2px dashed var(--chat-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin: 0 auto 8px;
    overflow: hidden;
    transition: all 0.2s;
    position: relative;
}
.chat-room-avatar-edit:hover {
    border-color: var(--chat-primary);
    background: #eef2ff;
}
.chat-room-avatar-edit img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.chat-avatar-edit-label {
    font-size: 10px;
    color: var(--chat-text-muted);
    margin-top: 2px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .chat-panel {
        width: calc(100vw - 16px);
        right: 8px;
        bottom: 68px;
        max-height: 75vh;
    }
    .chat-windows-container {
        right: 0;
        flex-direction: column;
    }
    .chat-window {
        width: 100vw;
        height: 65vh;
        border-radius: 16px 16px 0 0;
    }
}

/* Room search bar */
.chat-room-search-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: #f8fafc;
    border-bottom: 1px solid var(--chat-border);
}
.chat-room-search-bar .chat-form-input {
    flex: 1;
    font-size: 12px;
    padding: 5px 10px;
}
.chat-room-search-results {
    max-height: 200px;
    overflow-y: auto;
    border-bottom: 1px solid var(--chat-border);
    background: #fff;
}
.chat-room-search-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: background 0.12s;
}
.chat-room-search-item:hover { background: #f1f5f9; }
.chat-room-search-snippet { color: #64748b; font-size: 11px; }
.chat-room-search-time { color: var(--chat-text-muted); font-size: 10px; }

/* Pinned messages list panel */
.chat-pinned-list-panel {
    max-height: 250px;
    overflow-y: auto;
    border-bottom: 1px solid var(--chat-border);
    background: #fffbeb;
}
.chat-pinned-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 12px;
    border-bottom: 1px solid #fde68a;
    background: #fef3c7;
}
.chat-pinned-list-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #fef3c7;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: background 0.12s;
}
.chat-pinned-list-item:hover { background: #fef9c3; }
.chat-pinned-list-item span { color: #64748b; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .chat-modal {
        width: calc(100vw - 32px);
    }
}
