/* ============================================
   Chatbot CSS - Chat Bubbles, Conversation List, CRM Cards
   Glassmorphism + Dark Mode compatible
   ============================================ */

/* Chat bubble base */
.chat-bubble {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-bubble-inbound {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.chat-bubble-outbound {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    color: white;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

.chat-bubble-bot {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

.chat-bubble-agent {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.chat-bubble-time {
    font-size: 0.65rem;
    margin-top: 0.25rem;
    text-align: right;
}

.chat-bubble-inbound .chat-bubble-time {
    color: var(--text-tertiary);
}

.chat-bubble-outbound .chat-bubble-time {
    opacity: 0.6;
}

/* Chat container */
.chat-messages-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    padding: 1rem 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.chat-messages-container::-webkit-scrollbar {
    width: 6px;
}

.chat-messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* Message input */
.chat-input-container {
    display: flex;
    gap: 0.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.chat-input {
    flex: 1;
    padding: 0.65rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #8b5cf6;
}

.chat-send-btn {
    padding: 0.65rem 1.25rem;
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.2s;
}

.chat-send-btn:hover {
    opacity: 0.9;
}

/* Conversation list item */
.conv-list-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    text-decoration: none;
    transition: all 0.15s;
}

.conv-list-item:hover {
    border-color: rgba(139, 92, 246, 0.3);
    transform: translateX(2px);
}

/* Contact CRM card */
.contact-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1.5rem;
    backdrop-filter: blur(12px);
}

.contact-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.5rem;
}

.contact-tag {
    padding: 0.2rem 0.5rem;
    background: rgba(139, 92, 246, 0.1);
    color: #8b5cf6;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 500;
}

/* Connection status badge */
.connection-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
}

.connection-badge-connected {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.connection-badge-disconnected {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.connection-badge-error {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.connection-badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* QR Code container */
.qr-code-container {
    text-align: center;
    padding: 1.5rem;
}

.qr-code-img {
    width: 200px;
    height: 200px;
    border-radius: 12px;
    border: 3px solid var(--border-color);
    margin: 0 auto 0.75rem;
    display: block;
}

.qr-code-placeholder {
    width: 200px;
    height: 200px;
    border-radius: 12px;
    margin: 0 auto 0.75rem;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border-color);
}

/* Header disconnection notification bar */
.chatbot-disconnect-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 99999;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 2px 12px rgba(239, 68, 68, 0.3);
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.chatbot-disconnect-bar.visible {
    transform: translateY(0);
}

.chatbot-disconnect-bar a {
    color: white;
    text-decoration: underline;
    font-weight: 600;
}

.chatbot-disconnect-bar .dismiss-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.5rem;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* Platform icon colors */
.platform-whatsapp { color: #25D366; }
.platform-telegram { color: #0088cc; }
.platform-whatsapp-bg { background: rgba(37, 211, 102, 0.1); }
.platform-telegram-bg { background: rgba(0, 136, 204, 0.1); }

/* Delivery status icons */
.delivery-sent { color: var(--text-tertiary); }
.delivery-delivered { color: var(--text-secondary); }
.delivery-read { color: #3b82f6; }
.delivery-failed { color: #ef4444; }

/* Dark mode adjustments */
[data-theme="dark"] .chat-bubble-inbound {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .qr-code-img {
    border-color: rgba(255, 255, 255, 0.1);
    filter: brightness(0.95);
}

/* RTL support */
[dir="rtl"] .conv-list-item:hover {
    transform: translateX(-2px);
}

[dir="rtl"] .chat-bubble-inbound {
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 4px;
}

[dir="rtl"] .chat-bubble-outbound {
    border-bottom-right-radius: 14px;
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .chat-bubble-time {
    text-align: left;
}
