/* ─── Chat Widget Styles ─────────────────────────────────────────────────── */

#chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

/* Button Row (label + circular button) */
#chat-btn-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Status Label */
#chat-btn-label {
    background: #fff;
    color: #16a34a;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 2px 12px rgba(0,0,0,0.12);
    white-space: nowrap;
    transition: color 0.3s ease, opacity 0.2s ease;
}

#chat-btn-label.offline {
    color: #6366f1;
}

/* Floating Button - Circular */
#chat-toggle-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(34, 197, 94, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.3s ease;
    position: relative;
    flex-shrink: 0;
}

#chat-toggle-btn.offline {
    background: linear-gradient(135deg, #64748b, #475569);
    box-shadow: 0 4px 20px rgba(100, 116, 139, 0.4);
}

#chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(34, 197, 94, 0.5);
}

#chat-toggle-btn.offline:hover {
    box-shadow: 0 6px 25px rgba(100, 116, 139, 0.5);
}

#chat-toggle-btn svg {
    width: 24px;
    height: 24px;
    fill: #fff;
    transition: opacity 0.2s;
}

#chat-toggle-btn.open svg.icon-chat { display: none; }
#chat-toggle-btn.open svg.icon-close { display: block !important; }
#chat-toggle-btn svg.icon-close { display: none; }

/* Unread badge */
#chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    display: none;
}

/* Chat Window */
#chat-window {
    width: 340px;
    height: 480px;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: chatSlideIn 0.25s ease;
}

#chat-window.open {
    display: flex;
}

@keyframes chatSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
#chat-header {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

#chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
}

#chat-header-avatar svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}

#chat-header-info {
    flex: 1;
}

#chat-header-info .chat-title {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    line-height: 1.2;
}

#chat-header-info .chat-status {
    font-size: 11px;
    color: rgba(255,255,255,0.75);
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
}

#chat-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.8);
    padding: 4px;
    border-radius: 6px;
    transition: background 0.15s;
}

#chat-close-btn:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
}

/* Messages area */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8f9fc;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

/* Welcome message */
.chat-welcome {
    text-align: center;
    padding: 20px 10px;
    color: #6b7280;
}

.chat-welcome svg {
    width: 40px;
    height: 40px;
    fill: #6366f1;
    opacity: 0.5;
    margin-bottom: 10px;
}

.chat-welcome p {
    font-size: 13px;
    line-height: 1.5;
}

/* Message bubble */
.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

.chat-msg.user {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-msg.admin {
    align-self: flex-start;
    align-items: flex-start;
    max-width: 92%;
}

.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.55;
    word-break: break-word;
    overflow-wrap: break-word;
}

.chat-msg.user .chat-msg-bubble {
    background: #6366f1;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.admin .chat-msg-bubble {
    background: #fff;
    color: #1e293b;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* ─── Enterprise chat formatting ─── */

.chat-msg-bubble strong {
    font-weight: 700;
}

.chat-msg-bubble em {
    font-style: italic;
    opacity: 0.9;
}

/* Section headers */
.chat-msg-bubble .cb-h2 {
    font-weight: 700;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin: 10px 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(0,0,0,0.08);
    color: #4f46e5;
}

.chat-msg-bubble .cb-h3 {
    font-weight: 700;
    font-size: 12px;
    margin: 8px 0 4px;
    color: inherit;
    opacity: 0.85;
}

/* Ordered steps (1, 2, 3...) */
.chat-msg-bubble .cb-step {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 5px 0;
    padding: 6px 8px;
    background: rgba(99, 102, 241, 0.06);
    border-radius: 8px;
    border-left: 2px solid #6366f1;
}

.chat-msg-bubble .cb-step-num {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #6366f1;
    color: #fff;
    border-radius: 50%;
    font-size: 10px;
    font-weight: 700;
    margin-top: 1px;
}

/* Unordered list items */
.chat-msg-bubble .cb-list-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 3px 0;
    padding: 2px 0;
}

.chat-msg-bubble .cb-bullet {
    flex-shrink: 0;
    width: 5px;
    height: 5px;
    background: #6366f1;
    border-radius: 50%;
    margin-top: 7px;
}

/* Paragraph gap */
.chat-msg-bubble .cb-gap {
    height: 8px;
}

/* Divider */
.chat-msg-bubble .cb-divider {
    height: 1px;
    background: rgba(0,0,0,0.08);
    margin: 8px 0;
}

/* Legacy fallback */
.chat-msg-bubble ul {
    margin: 6px 0;
    padding-left: 0;
    list-style: none;
}

.chat-msg-bubble ul li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 3px;
    padding: 2px 0;
}

.chat-msg-bubble ul li::before {
    content: "";
    flex-shrink: 0;
    width: 5px;
    height: 5px;
    background: #6366f1;
    border-radius: 50%;
    margin-top: 7px;
}

.chat-msg-bubble br + br {
    display: block;
    content: "";
    margin-top: 4px;
}

.chat-msg-time {
    font-size: 10px;
    color: #9ca3af;
    margin-top: 3px;
    padding: 0 4px;
}

/* Typing indicator */
#chat-typing {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    background: #fff;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

#chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typing-dot 1.2s infinite;
}

#chat-typing span:nth-child(2) { animation-delay: 0.2s; }
#chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Pending message */
.chat-pending {
    text-align: center;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 12px;
    color: #856404;
}

/* Input area */
#chat-footer {
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 22px;
    padding: 9px 14px;
    font-size: 13px;
    resize: none;
    outline: none;
    max-height: 90px;
    line-height: 1.4;
    font-family: inherit;
    color: #1e293b;
    background: #f9fafb;
    transition: border-color 0.15s;
}

#chat-input:focus {
    border-color: #6366f1;
    background: #fff;
}

#chat-input::placeholder { color: #9ca3af; }

#chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #6366f1;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}

#chat-send-btn:hover { background: #4f46e5; }
#chat-send-btn:active { transform: scale(0.92); }

#chat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* Session closed */
.chat-closed-msg {
    text-align: center;
    font-size: 12px;
    color: #9ca3af;
    padding: 8px;
    border-top: 1px solid #e5e7eb;
}

/* Dark mode support */
[data-theme="dark"] #chat-btn-label {
    background: #1e293b;
    color: #4ade80;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}

[data-theme="dark"] #chat-btn-label.offline {
    color: #818cf8;
}

[data-theme="dark"] #chat-window {
    background: #1e293b;
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}

[data-theme="dark"] #chat-messages {
    background: #0f172a;
}

[data-theme="dark"] .chat-msg.admin .chat-msg-bubble {
    background: #1e293b;
    color: #f1f5f9;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

[data-theme="dark"] .chat-msg-bubble .cb-h2 {
    color: #818cf8;
    border-bottom-color: rgba(255,255,255,0.08);
}

[data-theme="dark"] .chat-msg-bubble .cb-step {
    background: rgba(99, 102, 241, 0.1);
}

[data-theme="dark"] .chat-msg-bubble .cb-divider {
    background: rgba(255,255,255,0.08);
}

[data-theme="dark"] #chat-footer {
    background: #1e293b;
    border-top-color: #334155;
}

[data-theme="dark"] #chat-input {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}

[data-theme="dark"] #chat-input:focus {
    border-color: #6366f1;
    background: #1e293b;
}

/* Mobile - above bottom nav (70px height) */
@media (max-width: 480px) {
    #chat-window {
        width: calc(100vw - 24px);
        height: 60vh;
        right: 0;
        bottom: 70px;
    }

    #chat-bubble {
        right: 12px;
        bottom: 80px;
    }

    #chat-btn-label {
        font-size: 11px;
        padding: 6px 12px;
    }

    #chat-toggle-btn {
        width: 48px;
        height: 48px;
    }
}

