/* ─── Chat Widget ──────────────────────────────────────────── */

#chat-widget {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
}

/* Bubble button */
#chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #4f46e5;
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}
#chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.5);
}

/* Badge */
#chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    background: #ef4444;
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    line-height: 1;
}

/* Panel */
#chat-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 370px;
    height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
#chat-header {
    background: #4f46e5;
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
#chat-header span {
    font-weight: 600;
    font-size: 15px;
}
#chat-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    line-height: 1;
    opacity: 0.8;
}
#chat-close:hover {
    opacity: 1;
}

/* Messages area */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
#chat-messages::-webkit-scrollbar {
    width: 5px;
}
#chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

/* Message bubbles */
.chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.chat-msg.bot {
    align-self: flex-start;
    background: #f3f4f6;
    color: #1f2937;
    border-bottom-left-radius: 4px;
}
.chat-msg.user {
    align-self: flex-end;
    background: #4f46e5;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg.admin {
    align-self: flex-start;
    background: #ecfdf5;
    color: #065f46;
    border-bottom-left-radius: 4px;
    border-left: 3px solid #10b981;
}
.chat-msg .msg-sender-label {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    opacity: 0.7;
}

/* Markdown in messages */
.chat-msg strong {
    font-weight: 700;
}

/* Quick replies */
#chat-quick-replies {
    padding: 8px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
}
#chat-quick-replies:empty {
    display: none;
    padding: 0;
}
.chat-qr-btn {
    background: #fff;
    color: #4f46e5;
    border: 1.5px solid #4f46e5;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.chat-qr-btn:hover {
    background: #4f46e5;
    color: #fff;
}

/* Input area */
#chat-input-area {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    gap: 8px;
    flex-shrink: 0;
}
#chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}
#chat-input:focus {
    border-color: #4f46e5;
}
#chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #4f46e5;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: background 0.15s;
}
#chat-send:hover {
    background: #4338ca;
}

/* Typing indicator */
.chat-typing {
    align-self: flex-start;
    padding: 10px 14px;
    background: #f3f4f6;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 4px;
}
.chat-typing span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: chatTypingDot 1.4s infinite ease-in-out both;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatTypingDot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ─── Mobile responsive ──────────────────────────────────── */
@media (max-width: 480px) {
    #chat-panel {
        width: calc(100vw - 16px);
        height: calc(100vh - 120px);
        bottom: 80px;
        right: 8px;
        border-radius: 12px;
    }
    #chat-bubble {
        bottom: 16px;
        right: 16px;
    }
}

/* ─── WhatsApp Button ────────────────────────────────────── */
.chat-wa-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 8px 16px;
    background: #25D366;
    color: #fff !important;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none !important;
    transition: background 0.2s;
    line-height: 1;
}
.chat-wa-btn:hover {
    background: #1ebe5d;
}
.chat-wa-btn svg {
    flex-shrink: 0;
}

/* ─── Admin Panel Styles ──────────────────────────────────── */

.chat-admin-container {
    display: flex;
    gap: 0;
    height: calc(100vh - 60px);
    background: #f9fafb;
}

/* Room list sidebar */
.chat-admin-rooms {
    width: 340px;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    overflow-y: auto;
    flex-shrink: 0;
}
.chat-admin-rooms .room-item {
    padding: 14px 16px;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
    display: block;
    color: inherit;
}
.chat-admin-rooms .room-item:hover,
.chat-admin-rooms .room-item.active {
    background: #f0f0ff;
}
.chat-admin-rooms .room-item .room-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.chat-admin-rooms .room-item .room-username {
    font-weight: 600;
    font-size: 14px;
}
.chat-admin-rooms .room-item .room-time {
    font-size: 11px;
    color: #9ca3af;
}
.chat-admin-rooms .room-item .room-preview {
    font-size: 13px;
    color: #6b7280;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Status badges */
.chat-status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.chat-status-badge.escalated {
    background: #fef2f2;
    color: #dc2626;
}
.chat-status-badge.bot {
    background: #f0f9ff;
    color: #0284c7;
}
.chat-status-badge.resolved {
    background: #f0fdf4;
    color: #16a34a;
}
.chat-status-badge.closed {
    background: #f3f4f6;
    color: #6b7280;
}

/* Unread badge in room list */
.room-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    background: #ef4444;
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    padding: 0 5px;
}

/* Admin conversation area */
.chat-admin-conversation {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-admin-conv-header {
    padding: 14px 20px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chat-admin-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.chat-admin-input-area {
    padding: 12px 20px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    display: flex;
    gap: 8px;
}
.chat-admin-input-area input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
}
.chat-admin-input-area input:focus {
    border-color: #4f46e5;
}
.chat-admin-input-area button {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

/* User context panel */
.chat-user-context {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 12px 20px 0;
    font-size: 13px;
}
.chat-user-context .context-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}
.chat-user-context .context-item {
    display: flex;
    gap: 4px;
}
.chat-user-context .context-label {
    font-weight: 600;
    color: #475569;
}
.chat-user-context .context-value {
    color: #1e293b;
}
