/* ========================================
   AIcountant - AI Chatbot Widget
   Design System v3 compatible
   ======================================== */

/* ── Chatbot Toggle Button ── */
.chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary, #1B3A5C);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 1600;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg, 0 10px 15px -3px rgb(0 0 0 / 0.08));
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.chatbot-toggle:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl, 0 20px 25px -5px rgb(0 0 0 / 0.08));
    background: var(--primary-dark, #122844);
}

.chatbot-toggle svg {
    width: 28px;
    height: 28px;
    transition: transform 0.2s ease, opacity 0.15s ease;
}

.chatbot-toggle .chatbot-icon-close {
    display: none;
}

.chatbot-toggle.active .chatbot-icon-open {
    display: none;
}

.chatbot-toggle.active .chatbot-icon-close {
    display: block;
}

/* ── Chatbot Window ── */
.chatbot-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: var(--bg-white, #FAFAF7);
    border-radius: var(--radius-xl, 12px);
    box-shadow: var(--shadow-xl, 0 20px 25px -5px rgb(0 0 0 / 0.08));
    border: 1px solid var(--border, #E8E4DC);
    z-index: 1599;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.chatbot-window.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Header ── */
.chatbot-header {
    background: var(--primary, #1B3A5C);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chatbot-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-header-avatar svg {
    width: 20px;
    height: 20px;
}

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

.chatbot-header-title {
    font-family: var(--font-sans, 'Plus Jakarta Sans', sans-serif);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
}

.chatbot-header-subtitle {
    font-size: 12px;
    opacity: 0.8;
    line-height: 1.3;
}

/* ── Messages Area ── */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

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

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--border, #E8E4DC);
    border-radius: 2px;
}

/* ── Message Bubbles ── */
.chatbot-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius-lg, 8px);
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    font-family: var(--font-sans, 'Plus Jakarta Sans', sans-serif);
}

.chatbot-msg-bot {
    align-self: flex-start;
    background: var(--bg-light, #F3F0E8);
    color: var(--text-dark, #1C1C1E);
    border-bottom-left-radius: var(--radius-sm, 4px);
}

.chatbot-msg-user {
    align-self: flex-end;
    background: var(--primary, #1B3A5C);
    color: #fff;
    border-bottom-right-radius: var(--radius-sm, 4px);
}

/* ── Typing Indicator ── */
.chatbot-typing {
    align-self: flex-start;
    background: var(--bg-light, #F3F0E8);
    padding: 12px 18px;
    border-radius: var(--radius-lg, 8px);
    border-bottom-left-radius: var(--radius-sm, 4px);
    display: none;
    gap: 4px;
    align-items: center;
}

.chatbot-typing.active {
    display: flex;
}

.chatbot-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-light, #9A958E);
    animation: chatbot-bounce 1.4s ease-in-out infinite;
}

.chatbot-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chatbot-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* ── Input Area ── */
.chatbot-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border, #E8E4DC);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--bg-white, #FAFAF7);
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    border: 1px solid var(--border, #E8E4DC);
    border-radius: var(--radius, 6px);
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--font-sans, 'Plus Jakarta Sans', sans-serif);
    color: var(--text-dark, #1C1C1E);
    background: #fff;
    resize: none;
    max-height: 80px;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.2s ease;
}

.chatbot-input:focus {
    border-color: var(--primary, #1B3A5C);
}

.chatbot-input::placeholder {
    color: var(--text-light, #9A958E);
}

.chatbot-send {
    width: 40px;
    height: 40px;
    border-radius: var(--radius, 6px);
    background: var(--primary, #1B3A5C);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.2s ease, opacity 0.2s ease;
}

.chatbot-send:hover {
    background: var(--primary-dark, #122844);
}

.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-send svg {
    width: 18px;
    height: 18px;
}

/* ── Error Message ── */
.chatbot-msg-error {
    align-self: flex-start;
    background: #FEF2F2;
    color: var(--error, #8B2020);
    border: 1px solid #FECACA;
    border-bottom-left-radius: var(--radius-sm, 4px);
    font-size: 13px;
}

/* ── Powered By ── */
.chatbot-footer {
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: var(--text-light, #9A958E);
    border-top: 1px solid var(--border, #E8E4DC);
    flex-shrink: 0;
}

/* ── Quick Replies ── */
.chatbot-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
}

.chatbot-quick-reply {
    padding: 6px 12px;
    border: 1px solid var(--border, #E8E4DC);
    border-radius: 16px;
    background: #fff;
    color: var(--primary, #1B3A5C);
    font-size: 13px;
    cursor: pointer;
    font-family: var(--font-sans, 'Plus Jakarta Sans', sans-serif);
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chatbot-quick-reply:hover {
    background: var(--primary-light, #E5EDF5);
    border-color: var(--primary, #1B3A5C);
}

/* ── Mobile Responsive ── */
@media (max-width: 480px) {
    .chatbot-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 75vh;
        border-radius: var(--radius-xl, 12px) var(--radius-xl, 12px) 0 0;
        border-bottom: none;
    }

    .chatbot-toggle {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }

    .chatbot-toggle svg {
        width: 24px;
        height: 24px;
    }
}

/* ── Hide WhatsApp float when chatbot is open ── */
body:has(.chatbot-window.active) .whatsapp-float {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
    .chatbot-window {
        transition: opacity 0.1s ease;
        transform: none !important;
    }

    .chatbot-typing-dot {
        animation: none;
    }

    .chatbot-toggle {
        transition: none;
    }
}
