/* ==================== CHAT MESSENGER ==================== */

/* Chat icon button in sidebar */
.chat-trigger-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 10px;
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.9);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
    flex-shrink: 0;
}
.chat-trigger-btn:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
}
.chat-trigger-btn .chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(239,68,68,0.4);
}
.chat-badge:empty { display: none; }

/* Messenger popup */
.chat-popup {
    display: none;
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 420px;
    height: 580px;
    max-height: calc(100vh - 32px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18), 0 2px 12px rgba(0,0,0,0.08);
    z-index: 9999;
    flex-direction: column;
    overflow: hidden;
    animation: chatPopIn 0.2s ease;
}
.chat-popup.open { display: flex; }

@keyframes chatPopIn {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Chat header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    color: #fff;
    flex-shrink: 0;
}
.chat-header-title {
    font-size: 15px;
    font-weight: 600;
    flex: 1;
}
.chat-header-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
}
.chat-header-btn:hover { background: rgba(255,255,255,0.25); }

/* Chat views */
.chat-view { display: none; flex-direction: column; flex: 1; min-height: 0; }
.chat-view.active { display: flex; }

/* Chat tabs */
.chat-tabs {
    display: flex;
    border-bottom: 2px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
}
.chat-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 8px;
    font-size: 13px;
    font-weight: 500;
    color: #64748b;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}
.chat-tab:hover { color: #1e3a5f; background: #f1f5f9; }
.chat-tab.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    font-weight: 600;
}
.chat-tab[data-chat-tab="client"].active {
    color: #ea580c;
    border-bottom-color: #ea580c;
}
.chat-tab-badge {
    display: none;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
}

/* Client chat banner */
.chat-client-banner {
    padding: 8px 14px;
    background: linear-gradient(90deg, #fff7ed, #fef3c7);
    color: #c2410c;
    font-size: 12px;
    font-weight: 500;
    border-bottom: 1px solid #fed7aa;
    flex-shrink: 0;
}
.chat-client-banner i {
    margin-right: 6px;
    color: #ea580c;
}

/* Client message header color override */
.chat-msg-header-client {
    background: linear-gradient(135deg, #c2410c 0%, #ea580c 100%) !important;
}

/* Client chat hint in bottom actions */
.chat-client-hint {
    font-size: 12px;
    color: #94a3b8;
    text-align: center;
    padding: 8px;
}
.chat-client-hint i { margin-right: 4px; }

/* Room list view */
.chat-search {
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
}
.chat-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    background: #f8fafc;
    box-sizing: border-box;
}
.chat-search input:focus { border-color: #3b82f6; outline: none; background: #fff; }

.chat-room-list {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.chat-room-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.12s;
    border-bottom: 1px solid #f8fafc;
}
.chat-room-item:hover { background: #f1f5f9; }
.chat-room-item.unread { background: #eff6ff; }
.chat-room-item.unread:hover { background: #dbeafe; }

.chat-room-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-size: 15px;
    font-weight: 600;
    flex-shrink: 0;
    overflow: hidden;
}
.chat-room-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-room-info { flex: 1; min-width: 0; }
.chat-room-name {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-room-last-msg {
    font-size: 12px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.chat-room-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}
.chat-room-time {
    font-size: 11px;
    color: #94a3b8;
}
.chat-room-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #3b82f6;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-bottom-actions {
    display: flex;
    gap: 6px;
    padding: 8px 14px;
    flex-shrink: 0;
}
.chat-new-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 8px;
    border: 2px dashed #e2e8f0;
    border-radius: 10px;
    background: transparent;
    color: #64748b;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    flex: 1;
    white-space: nowrap;
}
.chat-new-btn:hover { border-color: #3b82f6; color: #3b82f6; background: #eff6ff; }

.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #94a3b8;
    font-size: 13px;
    gap: 8px;
}
.chat-empty i { font-size: 36px; opacity: 0.4; }

/* Message view */
.chat-msg-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    flex-shrink: 0;
}
.chat-msg-back {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: #f1f5f9; border-radius: 8px;
    cursor: pointer; color: #64748b; font-size: 13px;
}
.chat-msg-back:hover { background: #e2e8f0; }
.chat-msg-name {
    font-size: 14px; font-weight: 600; color: #1e293b; flex: 1;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-msg-status { font-size: 11px; color: #94a3b8; }

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overscroll-behavior: contain;
    background: #fafbfc;
}

.chat-msg-date-sep {
    text-align: center;
    font-size: 11px;
    color: #94a3b8;
    padding: 8px 0;
}

.chat-msg {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: msgFadeIn 0.15s ease;
}
.chat-msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg.theirs { align-self: flex-start; }

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-msg-avatar-sm {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    background: #e2e8f0; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; color: #64748b; font-weight: 600;
}
.chat-msg-avatar-sm img { width: 100%; height: 100%; object-fit: cover; }

.chat-bubble {
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.45;
    position: relative;
    word-break: break-word;
}
.chat-msg.mine .chat-bubble {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg.theirs .chat-bubble {
    background: #f1f5f9;
    color: #1e293b;
    border-bottom-left-radius: 4px;
}

.chat-bubble-reply {
    padding: 4px 8px;
    margin-bottom: 4px;
    border-radius: 6px;
    font-size: 11px;
    opacity: 0.85;
    border-left: 3px solid;
    cursor: pointer;
}
.chat-msg.mine .chat-bubble-reply {
    background: rgba(255,255,255,0.15);
    border-left-color: rgba(255,255,255,0.5);
}
.chat-msg.theirs .chat-bubble-reply {
    background: rgba(0,0,0,0.04);
    border-left-color: #3b82f6;
}
.chat-bubble-reply-name { font-weight: 600; font-size: 10px; }
.chat-bubble-reply-text { margin-top: 1px; }

.chat-bubble-text {}
.chat-bubble-file {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}
.chat-bubble-file a {
    font-size: 12px;
    text-decoration: underline;
}
.chat-msg.mine .chat-bubble-file a { color: rgba(255,255,255,0.9); }
.chat-msg.theirs .chat-bubble-file a { color: #3b82f6; }

.chat-bubble-img {
    max-width: 220px;
    max-height: 180px;
    border-radius: 10px;
    cursor: pointer;
    margin-bottom: 2px;
}

.chat-bubble-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    font-size: 10px;
    opacity: 0.65;
    justify-content: flex-end;
}
.chat-bubble-edited { font-style: italic; }

.chat-msg-deleted {
    font-style: italic;
    opacity: 0.5;
    font-size: 12px;
    padding: 6px 12px;
}

/* Context menu on message */
.chat-msg-actions {
    display: none;
    position: absolute;
    top: -30px;
    right: 0;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    padding: 4px;
    gap: 2px;
    z-index: 10;
}
.chat-bubble:hover .chat-msg-actions { display: flex; }
.chat-msg-action-btn {
    width: 26px; height: 26px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: transparent; color: #64748b;
    border-radius: 6px; cursor: pointer; font-size: 11px;
}
.chat-msg-action-btn:hover { background: #f1f5f9; color: #1e293b; }

/* Reply bar */
.chat-reply-bar {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-top: 1px solid #f1f5f9;
    background: #fafbfc;
    font-size: 12px;
    color: #64748b;
}
.chat-reply-bar.active { display: flex; }
.chat-reply-bar-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-reply-bar-close {
    border: none; background: transparent; color: #94a3b8; cursor: pointer;
    font-size: 14px; padding: 0 4px;
}

/* Typing indicator */
.chat-typing {
    display: none;
    padding: 4px 14px;
    font-size: 11px;
    color: #94a3b8;
    font-style: italic;
}
.chat-typing.active { display: block; }

/* Input area */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid #f1f5f9;
    background: #fff;
    flex-shrink: 0;
}
.chat-input-field {
    flex: 1;
    min-height: 36px;
    max-height: 100px;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    font-size: 13px;
    resize: none;
    overflow-y: auto;
    font-family: inherit;
    line-height: 1.4;
    box-sizing: border-box;
}
.chat-input-field:focus { border-color: #3b82f6; outline: none; }

.chat-input-btn {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border: none; border-radius: 50%; cursor: pointer;
    font-size: 14px; flex-shrink: 0; transition: all 0.15s;
}
.chat-attach-btn {
    background: #f1f5f9;
    color: #64748b;
}
.chat-attach-btn:hover { background: #e2e8f0; color: #1e293b; }
.chat-send-btn {
    background: #3b82f6;
    color: #fff;
}
.chat-send-btn:hover { background: #2563eb; }
.chat-send-btn:disabled { background: #cbd5e1; cursor: default; }

/* New chat view */
.chat-user-list {
    flex: 1;
    overflow-y: auto;
}
.chat-user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.12s;
    border-bottom: 1px solid #f8fafc;
}
.chat-user-item:hover { background: #f1f5f9; }
.chat-user-item .online-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #22c55e;
    flex-shrink: 0;
}
.chat-user-item .offline-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #cbd5e1;
    flex-shrink: 0;
}
.chat-user-name { font-size: 13px; font-weight: 600; color: #1e293b; }
.chat-user-role { font-size: 11px; color: #94a3b8; }

/* Group creation - user checkbox */
.chat-group-checkbox {
    width: 22px;
    height: 22px;
    border: 2px solid #cbd5e1;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 11px;
    flex-shrink: 0;
    transition: all 0.15s;
}
.chat-group-checkbox.checked {
    background: #3b82f6;
    border-color: #3b82f6;
}
.chat-user-item.selected {
    background: #eff6ff;
}

/* Chat info / settings */
.chat-info-section {
    padding: 12px 0;
    border-bottom: 1px solid #f1f5f9;
}
.chat-info-section:last-child { border-bottom: none; }

.chat-info-icon {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
}
.chat-info-avatar-placeholder {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 600;
    color: #64748b;
}
.chat-info-name {
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 2px;
}
.chat-info-type {
    text-align: center;
    font-size: 12px;
    color: #94a3b8;
}
.chat-info-label {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
}
.chat-info-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 0;
    border: none;
    background: transparent;
    font-size: 13px;
    color: #1e293b;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.12s;
    text-align: left;
}
.chat-info-row:hover { background: #f8fafc; }
.chat-info-row i { width: 20px; text-align: center; color: #64748b; }

.chat-info-danger { color: #ef4444 !important; }
.chat-info-danger i { color: #ef4444 !important; }
.chat-info-danger:hover { background: #fef2f2 !important; }

.chat-info-participant {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
}
.chat-info-remove-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: #ef4444;
    cursor: pointer;
    border-radius: 6px;
    font-size: 11px;
    opacity: 0;
    transition: all 0.15s;
}
.chat-info-participant:hover .chat-info-remove-btn { opacity: 1; }
.chat-info-remove-btn:hover { background: #fef2f2; }

.chat-info-action-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: #3b82f6;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}
.chat-info-action-btn:hover { background: #2563eb; }

/* Mobile */
@media (max-width: 768px) {
    .chat-popup {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
}
