/* ===== AI Chatbot Widget (Tâm An CFO) ===== */
#chatbot-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
    font-family: 'Inter', sans-serif;
}

#chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #004A80 0%, #0088CC 100%);
    color: #fff;
    border: none;
    box-shadow: 0 10px 30px rgba(0, 74, 128, 0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}
#chatbot-toggle:hover {
    transform: scale(1.08) rotate(-4deg);
    box-shadow: 0 14px 36px rgba(0, 74, 128, 0.45);
}
#chatbot-toggle .material-symbols-outlined { font-size: 28px; }

.chatbot-window {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    border-radius: 20px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.25);
    transform-origin: bottom right;
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.chatbot-window.hidden { display: none; }
.chatbot-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: linear-gradient(135deg, #004A80 0%, #0088CC 100%);
    color: #fff;
    flex-shrink: 0;
}
.chatbot-header-info { display: flex; align-items: center; gap: 12px; }
.chatbot-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.chatbot-name { font-weight: 600; font-size: 14px; margin: 0; }
.chatbot-status {
    font-size: 12px; opacity: 0.85; display: flex; align-items: center; gap: 6px; margin: 2px 0 0;
}
.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #4ade80;
    animation: statusPulse 1.8s infinite;
}
@keyframes statusPulse {
    0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); }
    70% { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}
.chatbot-header-actions { display: flex; gap: 4px; }
.chatbot-header-actions button {
    background: transparent; border: none; color: #fff; cursor: pointer;
    width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s ease;
}
.chatbot-header-actions button:hover { background: rgba(255, 255, 255, 0.15); }
.chatbot-header-actions button .material-symbols-outlined { font-size: 20px; }
#chatbot-refresh.spinning .material-symbols-outlined { animation: chatbot-spin 0.5s linear; }
@keyframes chatbot-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    background: rgba(248, 250, 252, 0.4);
}
.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    animation: chatbot-bubble-in 0.3s ease both;
    word-wrap: break-word;
}
@keyframes chatbot-bubble-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-bubble.bot {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #E1E1E1;
    border-bottom-left-radius: 4px;
    color: #1b1c1c;
}
.chat-bubble.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #004A80 0%, #0088CC 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.typing-indicator {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #E1E1E1;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.typing-indicator span {
    width: 6px; height: 6px; border-radius: 50%;
    background: #94a3b8;
    animation: chatbot-typing-bounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatbot-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-5px); opacity: 1; }
}

.chatbot-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid rgba(225, 225, 225, 0.6);
    background: rgba(255, 255, 255, 0.6);
    flex-shrink: 0;
}
#chatbot-input {
    flex: 1;
    border: 1px solid #E1E1E1;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    background: #fff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#chatbot-input:focus { border-color: #0088CC; box-shadow: 0 0 0 3px rgba(0, 136, 204, 0.15); }
#chatbot-send {
    width: 38px; height: 38px; border-radius: 10px; border: none;
    background: #004A80; color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}
#chatbot-send:hover:not(:disabled) { background: #0088CC; transform: scale(1.05); }
#chatbot-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---- Markdown rendering ---- */
.chat-markdown p { margin: 0 0 8px; line-height: 1.6; }
.chat-markdown p:last-child { margin-bottom: 0; }
.chat-markdown ul, .chat-markdown ol { margin: 0 0 8px 20px; padding: 0; }
.chat-markdown li { margin-bottom: 4px; line-height: 1.5; }
.chat-markdown strong { font-weight: 700; color: #0088CC; }
.chat-markdown code {
    background: #1b1c1c;
    color: #e2e8f0;
    font-family: 'Fira Code', Consolas, monospace;
    font-size: 12.5px;
    padding: 2px 6px;
    border-radius: 4px;
}
.chat-markdown pre {
    background: #1b1c1c;
    color: #e2e8f0;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0 0 8px;
}
.chat-markdown pre code { background: transparent; padding: 0; }
.chat-markdown blockquote {
    border-left: 3px solid #0088CC;
    padding-left: 10px;
    margin: 0 0 8px;
    color: #64748b;
}
.chat-markdown a { color: #0088CC; text-decoration: underline; }

@media (max-width: 480px) {
    #chatbot-root { bottom: 16px; right: 16px; }
    .chatbot-window {
        width: calc(100vw - 24px);
        height: calc(100vh - 100px);
        right: -8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #chatbot-toggle, .chatbot-window, .chat-bubble, .status-dot,
    #chatbot-refresh.spinning .material-symbols-outlined,
    .typing-indicator span {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}
