/* ============================================
   chat.css - Floating Chat Widget Styles
   Adapted for CRM SPA (uses CRM CSS variables)
   ============================================ */

/* Floating Chat Button */
.chat-floating-btn {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4), 0 0 0 4px rgba(102, 126, 234, 0.1);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.chat-floating-btn:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 6px 30px rgba(102, 126, 234, 0.5), 0 0 0 6px rgba(102, 126, 234, 0.15);
}

.chat-floating-btn.has-unread::after {
    content: attr(data-unread);
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    font-size: 12px;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
    animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Chat Widget Container */
.chat-widget {
    position: fixed;
    bottom: 95px;
    right: 25px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 130px);
    background: var(--bg-secondary);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    z-index: 9998;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: chatSlideUp 0.3s ease;
}

.chat-widget.active { display: flex; }

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

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-left { display: flex; align-items: center; gap: 12px; flex: 1; }

.chat-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: bold; text-transform: uppercase;
}

.chat-avatar.group { background: rgba(255,255,255,0.3); }

.chat-header-info { flex: 1; min-width: 0; }

.chat-title {
    font-weight: 600; font-size: 16px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.chat-status {
    font-size: 12px; opacity: 0.9;
    display: flex; align-items: center; gap: 5px;
}

.chat-header-actions { display: flex; gap: 8px; }

.chat-header-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: none; color: white; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}

.chat-header-btn:hover { background: rgba(255,255,255,0.25); transform: scale(1.1); }

/* Chat Body - Conversations List */
.chat-body {
    flex: 1; overflow-y: auto;
    background: var(--bg-primary);
}

.chat-conversations { padding: 10px; }

.chat-conversation-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px; border-radius: 12px;
    cursor: pointer; transition: all 0.2s;
    background: var(--bg-secondary);
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.chat-conversation-item:hover { background: var(--bg-tertiary); transform: translateX(3px); }

.chat-conversation-item.unread {
    background: rgba(102, 126, 234, 0.1);
    border-left: 3px solid #667eea;
}

.chat-conversation-item.active {
    background: linear-gradient(135deg, rgba(102,126,234,0.08) 0%, rgba(118,75,162,0.08) 100%);
    border-left: 3px solid #667eea;
}

.chat-conv-avatar {
    width: 50px; height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: bold; flex-shrink: 0;
    position: relative;
}

.chat-conv-avatar.group { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); }

.chat-conv-info { flex: 1; min-width: 0; }

.chat-conv-title {
    font-weight: 600; font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.chat-conv-preview {
    font-size: 12px; color: var(--text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 3px;
}

.chat-conv-preview.media { display: flex; align-items: center; gap: 4px; }

.chat-conv-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.chat-conv-time { font-size: 11px; color: var(--text-secondary); opacity: 0.7; }

.chat-conv-badge {
    background: #ff4757; color: white;
    font-size: 11px; font-weight: bold;
    padding: 2px 8px; border-radius: 10px;
    min-width: 20px; text-align: center;
}

/* New Chat Button */
.chat-new-btn {
    position: sticky; bottom: 10px; left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; border: none;
    padding: 12px 24px; border-radius: 25px;
    cursor: pointer; font-weight: 600;
    display: flex; align-items: center; gap: 8px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.3s; margin: 10px auto;
}

.chat-new-btn:hover {
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

/* Messages Area */
.chat-messages {
    flex: 1; overflow-y: auto; padding: 20px;
    display: flex; flex-direction: column; gap: 12px;
    background: var(--bg-primary);
}

.chat-message {
    max-width: 75%; display: flex; flex-direction: column;
    animation: messageAppear 0.3s ease;
}

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

.chat-message.own { align-self: flex-end; }
.chat-message.other { align-self: flex-start; }

.chat-message-bubble {
    padding: 12px 16px; border-radius: 18px;
    position: relative; word-break: break-word;
}

.chat-message.own .chat-message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; border-bottom-right-radius: 4px;
}

.chat-message.other .chat-message-bubble {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.chat-message-sender {
    font-size: 11px; color: var(--text-secondary);
    margin-bottom: 4px; font-weight: 500;
}

.chat-message-content { font-size: 14px; line-height: 1.5; }
.chat-message-content a { color: inherit; text-decoration: underline; }
.chat-message.own .chat-message-content a { color: rgba(255,255,255,0.9); }

/* Media Messages */
.chat-message-media { border-radius: 12px; overflow: hidden; max-width: 250px; }
.chat-message-media img { width: 100%; height: auto; display: block; cursor: pointer; transition: transform 0.3s; }
.chat-message-media img:hover { transform: scale(1.02); }
.chat-message-media video { width: 100%; max-height: 200px; border-radius: 12px; }
.chat-message-media.audio { display: flex; align-items: center; gap: 10px; padding: 10px; background: rgba(0,0,0,0.05); border-radius: 8px; }

.chat-message-file {
    display: flex; align-items: center; gap: 12px;
    padding: 12px; background: rgba(0,0,0,0.05);
    border-radius: 12px; text-decoration: none; color: inherit;
    transition: background 0.2s;
}

.chat-message-file:hover { background: rgba(0,0,0,0.1); }
.chat-message-file i { font-size: 24px; color: #667eea; }
.chat-message-file-info { flex: 1; min-width: 0; }
.chat-message-file-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-message-file-size { font-size: 11px; color: var(--text-secondary); }

/* Reply Message */
.chat-message-reply {
    padding: 8px 12px; background: rgba(0,0,0,0.05);
    border-radius: 8px; margin-bottom: 8px;
    border-left: 3px solid #667eea;
}

.chat-message-reply-sender { font-size: 11px; font-weight: 600; color: #667eea; }
.chat-message-reply-text { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Message Reactions */
.chat-message-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }

.chat-reaction {
    background: rgba(0,0,0,0.05); border-radius: 12px;
    padding: 2px 8px; font-size: 12px; cursor: pointer;
    transition: all 0.2s; user-select: none;
}

.chat-reaction:hover { background: rgba(0,0,0,0.1); transform: scale(1.1); }
.chat-reaction.user-reacted { background: rgba(102, 126, 234, 0.2); }

/* Message Meta */
.chat-message-meta {
    display: flex; align-items: center; gap: 6px;
    margin-top: 4px; font-size: 11px; color: var(--text-secondary); opacity: 0.7;
}

.chat-message.own .chat-message-meta { justify-content: flex-end; }
.chat-message-edited { font-style: italic; }
.chat-message-read { color: var(--text-secondary); }
.chat-message-read.read { color: var(--success); }
.chat-message-read.unread { color: var(--text-secondary); }

/* Message Actions */
.chat-message-actions {
    position: absolute; top: -30px; right: 0;
    display: none; background: var(--bg-secondary);
    border-radius: 20px; padding: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15); z-index: 10;
}

.chat-message:hover .chat-message-actions { display: flex; gap: 4px; }

.chat-message-action-btn {
    width: 28px; height: 28px; border-radius: 50%;
    border: none; background: transparent; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; color: var(--text-secondary);
}

.chat-message-action-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }

/* Input Area */
.chat-input-area {
    padding: 15px 20px; background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 10px; flex-shrink: 0;
}

.chat-reply-preview {
    display: none; align-items: center; gap: 10px;
    padding: 10px 15px; background: var(--bg-tertiary);
    border-radius: 8px; border-left: 3px solid #667eea;
}

.chat-reply-preview.active { display: flex; }
.chat-reply-content { flex: 1; min-width: 0; }
.chat-reply-cancel { background: none; border: none; cursor: pointer; color: var(--text-secondary); }

.chat-input-row { display: flex; align-items: flex-end; gap: 10px; }

.chat-input {
    flex: 1; padding: 12px 18px;
    border: 1px solid var(--border); border-radius: 24px;
    font-size: 14px; resize: none; max-height: 120px; min-height: 44px;
    transition: all 0.2s; font-family: inherit;
    background: var(--bg-primary); color: var(--text-primary);
}

.chat-input:focus {
    outline: none; border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-input-actions { display: flex; gap: 8px; }

.chat-input-btn {
    width: 44px; height: 44px; border-radius: 50%;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; font-size: 18px;
}

.chat-input-btn.attach { background: var(--bg-tertiary); color: var(--text-secondary); }
.chat-input-btn.attach:hover { background: var(--border); }
.chat-input-btn.send { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }
.chat-input-btn.send:hover { transform: scale(1.1); box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4); }
.chat-input-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* File Upload Preview */
.chat-file-preview {
    display: none; align-items: center; gap: 10px;
    padding: 10px 15px; background: var(--bg-tertiary); border-radius: 8px;
}

.chat-file-preview.active { display: flex; }
.chat-file-preview-thumb { width: 50px; height: 50px; border-radius: 8px; object-fit: cover; background: var(--border); }
.chat-file-preview-info { flex: 1; min-width: 0; }
.chat-file-preview-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-primary); }
.chat-file-preview-size { font-size: 11px; color: var(--text-secondary); }
.chat-file-preview-cancel { background: none; border: none; cursor: pointer; color: var(--error); font-size: 18px; }

/* New Conversation Modal */
.chat-modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); display: none;
    align-items: center; justify-content: center; z-index: 10000;
}

.chat-modal-overlay.active { display: flex; }

.chat-modal {
    background: var(--bg-secondary); border-radius: 16px;
    width: 90%; max-width: 400px; max-height: 80vh;
    display: flex; flex-direction: column; overflow: hidden;
    animation: modalAppear 0.3s ease;
}

@keyframes modalAppear {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.chat-modal-header {
    padding: 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}

.chat-modal-header h3 { margin: 0; font-size: 18px; color: var(--text-primary); }
.chat-modal-close { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--text-secondary); }
.chat-modal-close:hover { color: var(--text-primary); }

.chat-modal-body { flex: 1; overflow-y: auto; padding: 15px; }

.chat-user-list { display: flex; flex-direction: column; gap: 8px; }

.chat-user-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px; border-radius: 12px;
    cursor: pointer; transition: all 0.2s;
}

.chat-user-item:hover { background: var(--bg-tertiary); }

.chat-user-item.selected {
    background: linear-gradient(135deg, rgba(102,126,234,0.1) 0%, rgba(118,75,162,0.1) 100%);
    border: 2px solid #667eea;
}

.chat-user-avatar {
    width: 45px; height: 45px; border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: bold; text-transform: uppercase;
}

.chat-user-info { flex: 1; }
.chat-user-name { font-weight: 600; font-size: 15px; color: var(--text-primary); }
.chat-user-role { font-size: 12px; color: var(--text-secondary); }

.chat-modal-footer {
    padding: 15px 20px; border-top: 1px solid var(--border);
    display: flex; gap: 10px;
}

.chat-modal-footer input {
    flex: 1; padding: 12px 15px;
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 14px; background: var(--bg-primary); color: var(--text-primary);
}

.chat-modal-footer button {
    padding: 12px 20px; border: none; border-radius: 8px;
    cursor: pointer; font-weight: 600; transition: all 0.2s;
}

.chat-btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }
.chat-btn-secondary:hover { background: var(--border); }
.chat-btn-primary { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }

/* Date Divider */
.chat-date-divider {
    display: flex; align-items: center; justify-content: center;
    margin: 20px 0; position: relative;
}

.chat-date-divider::before {
    content: ''; position: absolute; left: 0; right: 0;
    height: 1px; background: var(--border);
}

.chat-date-divider span {
    background: var(--bg-primary); padding: 0 15px;
    font-size: 12px; color: var(--text-secondary); position: relative;
}

/* Empty State */
.chat-empty-state {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 60px 20px; text-align: center; color: var(--text-secondary);
}

.chat-empty-state i { font-size: 60px; margin-bottom: 20px; opacity: 0.3; }
.chat-empty-state h4 { font-size: 18px; margin-bottom: 10px; color: var(--text-primary); }

/* Reaction Picker */
.chat-reaction-picker {
    position: fixed; background: var(--bg-secondary);
    border-radius: 30px; padding: 8px 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    display: none; flex-wrap: wrap; gap: 5px; z-index: 10001;
}

.chat-reaction-picker.active { display: flex; }

.chat-reaction-btn {
    font-size: 22px; background: none; border: none;
    cursor: pointer; padding: 5px; border-radius: 50%;
    transition: transform 0.2s;
}

.chat-reaction-btn:hover { transform: scale(1.3); }

/* Online Status Indicators */
.chat-status-dot {
    display: inline-block; width: 8px; height: 8px;
    border-radius: 50%; margin-left: 6px; vertical-align: middle;
}

.chat-status-dot.online { background: var(--success); box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.3); animation: pulse-green 2s infinite; }
.chat-status-dot.recent { background: var(--warning); }
.chat-status-dot.offline { background: var(--text-secondary); }

.chat-status-online-dot {
    display: inline-block; width: 8px; height: 8px;
    border-radius: 50%; margin-left: 6px;
    background: var(--success); vertical-align: middle;
}

@keyframes pulse-green {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
}

.chat-conv-avatar.online::after {
    content: ''; position: absolute; bottom: 2px; right: 2px;
    width: 12px; height: 12px; background: var(--success);
    border: 2px solid var(--bg-secondary); border-radius: 50%;
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar,
.chat-body::-webkit-scrollbar,
.chat-modal-body::-webkit-scrollbar { width: 6px; }

.chat-messages::-webkit-scrollbar-track,
.chat-body::-webkit-scrollbar-track,
.chat-modal-body::-webkit-scrollbar-track { background: transparent; }

.chat-messages::-webkit-scrollbar-thumb,
.chat-body::-webkit-scrollbar-thumb,
.chat-modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-body::-webkit-scrollbar-thumb:hover,
.chat-modal-body::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* Responsive */
@media (max-width: 480px) {
    .chat-widget {
        width: calc(100vw - 40px);
        height: calc(100vh - 130px);
        right: 20px; bottom: 85px;
    }
    .chat-floating-btn { bottom: 15px; right: 15px; }
}
