@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* === Base elements === */
#aiChatFloatingBtn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #36a2eb, #1c8de8);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(54,162,235,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.3s;
}

#aiChatFloatingBtn:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(54,162,235,0.6); }

#aiChatPanel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    z-index: 9999;
    width: 450px;
    height: 550px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.ai-chat-header {
    background: linear-gradient(135deg, #36a2eb, #1c8de8);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-chat-header-title {
    font-weight: 600;
    font-size: 15px;
}

.ai-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

#aiChatMaximizeBtn,
#aiChatCloseBtn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
}

#aiChatMaximizeBtn { font-size: 16px; }
#aiChatCloseBtn { font-size: 18px; }

#aiChatMessages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8f9fa;
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}

#aiChatMessages::-webkit-scrollbar { width: 5px; }
#aiChatMessages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

#aiChatLoadingMore {
    display: none;
    align-self: center;
    font-size: 11px;
    color: #999;
}

.welcome-msg {
    align-self: flex-start;
    background: #fff;
    border-radius: 12px 12px 12px 4px;
    padding: 10px 14px;
    max-width: 85%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    font-size: 13px;
    line-height: 1.5;
    color: #333;
}

.ai-chat-warning-area {
    padding: 8px 16px;
    background: #fff;
    border-top: 1px solid #eee;
}

.ai-chat-warning {
    background: #fff3cd;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 11px;
    color: #856404;
    text-align: center;
    border: 1px solid #ffeeba;
}

.ai-chat-warning .simple-icon-warning {
    margin-right: 4px;
}

#aiChatTypingIndicator {
    display: none;
    padding: 0 16px 8px;
}

.ai-chat-typing-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-thinking-status {
    font-size: 11px;
    color: #1890ff;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1 1 0;
    min-width: 0;
    display: inline-block;
    vertical-align: middle;
    animation: thinkingFadeIn 0.3s ease;
}

.ai-chat-typing-dots {
    background: #fff;
    border-radius: 12px 12px 12px 4px;
    padding: 10px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    display: inline-flex;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #36a2eb;
    border-radius: 50%;
    display: inline-block;
    animation: typingBounce 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

#aiChatTypingIndicator .ai-chat-btn-cancel {
    background: transparent !important;
    color: #ff4d4f !important;
    border: 1px solid #ff4d4f !important;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

#aiChatTypingIndicator .ai-chat-btn-cancel:hover {
    background: #ff4d4f !important;
    color: #fff !important;
}

#aiChatCancelBtn .simple-icon-cross {
    margin-right: 3px;
}

.ai-chat-input-area {
    padding: 12px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    background: #fff;
}

#aiChatInput {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px 12px;
    resize: none;
    outline: none;
    font-size: 13px;
    font-family: inherit;
    line-height: 1.4;
}

#aiChatSendBtn {
    background: linear-gradient(135deg, #36a2eb, #1c8de8);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0 16px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
}

#aiChatResizeLeft,
#aiChatResizeBottom,
#aiChatResizeCorner {
    position: fixed;
    z-index: 10001;
    display: none;
    background: transparent;
}

#aiChatResizeLeft {
    width: 8px;
    height: 100%;
    top: 0;
    cursor: ew-resize;
}

#aiChatResizeBottom {
    width: 100%;
    height: 8px;
    left: 0;
    cursor: ns-resize;
}

#aiChatResizeCorner {
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
}

.msg-user { align-self: flex-end !important; background: linear-gradient(135deg, #6ccff6, #4db8db) !important; color: #fff !important; border-radius: 12px 12px 4px 12px !important; }
.msg-ai { align-self: flex-start !important; background: #fff !important; color: #333 !important; border-radius: 12px 12px 12px 4px !important; }
.msg-error { align-self: center !important; background: #fee !important; color: #c00 !important; border-radius: 8px !important; font-size: 12px !important; }
.msg-cancelled { align-self: center !important; background: #f5f5f5 !important; color: #999 !important; border-radius: 8px !important; font-size: 12px !important; font-style: italic !important; }

#aiChatResizeLeft:hover, #aiChatResizeBottom:hover, #aiChatResizeCorner:hover { background: rgba(54,162,235,0.15) !important; }
#aiChatResizeLeft::after, #aiChatResizeBottom::after, #aiChatResizeCorner::after {
    content: ''; position: absolute; background: rgba(54,162,235,0.3); border-radius: 2px;
}
#aiChatResizeLeft::after { right: 3px; top: 20%; height: 60%; width: 2px; }
#aiChatResizeBottom::after { left: 20%; bottom: 3px; width: 60%; height: 2px; }
#aiChatResizeCorner::after { right: 4px; bottom: 4px; width: 8px; height: 8px; border-right: 2px solid rgba(54,162,235,0.4); border-bottom: 2px solid rgba(54,162,235,0.4); }

/* Dark mode overrides */
#aiChatPanel.ai-dark { background: #232223 !important; box-shadow: 0 8px 32px rgba(0,0,0,0.5) !important; }
#aiChatPanel.ai-dark #aiChatMessages { background: #1b191b !important; }
#aiChatPanel.ai-dark #aiChatMessages::-webkit-scrollbar-thumb { background: #424242 !important; }
#aiChatPanel.ai-dark .msg-ai { background: #232223 !important; color: #d1d1d1 !important; }
#aiChatPanel.ai-dark .msg-error { background: #3a1a1a !important; color: #f5a0a0 !important; }
#aiChatPanel.ai-dark .msg-cancelled { background: #2a2a2a !important; color: #888 !important; }
#aiChatPanel.ai-dark #aiChatTypingIndicator > div > div:first-child { background: #232223 !important; }
#aiChatPanel.ai-dark #aiChatTypingIndicator > div { background: #232223 !important; }
#aiChatPanel.ai-dark .welcome-msg { background: #232223 !important; color: #d1d1d1 !important; }
#aiChatPanel.ai-dark .ai-chat-warning-area { background: #232223 !important; border-top-color: #424242 !important; }
#aiChatPanel.ai-dark .ai-chat-warning { background: #3a3520 !important; color: #d4c45a !important; border-color: #4a4428 !important; }
#aiChatPanel.ai-dark .ai-chat-input-area { background: #232223 !important; border-top-color: #424242 !important; }
#aiChatPanel.ai-dark #aiChatInput { background: #1b191b !important; border-color: #424242 !important; color: #d1d1d1 !important; }
#aiChatPanel.ai-dark #aiChatInput::placeholder { color: #707070 !important; }
#aiChatPanel.ai-dark .ai-chat-code { background: #333 !important; color: #e0e0e0 !important; }
#aiChatPanel.ai-dark #aiChatLoadMore { border-color: #5a9fd4 !important; color: #5a9fd4 !important; }
#aiChatPanel.ai-dark #aiChatLoadingMore { color: #707070 !important; }
.msg-time { font-size: 10px !important; color: #999 !important; padding: 0 4px !important; }
.msg-user + .msg-time, .msg-wrapper > .msg-time:last-child { text-align: right !important; }
.msg-wrapper:first-child .msg-time { text-align: left !important; }
#aiChatPanel.ai-dark .msg-time { color: #707070 !important; }

/* === Thinking status === */
.ai-thinking-status {
    font-size: 11px;
    color: #1890ff;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    display: inline-block;
    vertical-align: middle;
    animation: thinkingFadeIn 0.3s ease;
}

@keyframes thinkingFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#aiChatPanel.ai-dark .ai-thinking-status {
    color: #69b2ff !important;
}

/* Mobile responsive */
@media (max-width: 600px) {
    #aiChatFloatingBtn {
        bottom: 16px !important;
        right: 16px !important;
        width: 52px !important;
        height: 52px !important;
        font-size: 20px !important;
    }
    #aiChatPanel {
        width: calc(100vw - 16px) !important;
        height: calc(100vh - 80px) !important;
        bottom: 76px !important;
        right: 8px !important;
        border-radius: 12px !important;
    }
    #aiChatPanel .welcome-msg {
        max-width: 95% !important;
    }
    #aiChatMessages > .msg-wrapper {
        max-width: 95% !important;
    }
    #aiChatInput {
        font-size: 16px !important;
    }
    #aiChatResizeLeft, #aiChatResizeBottom, #aiChatResizeCorner {
        display: none !important;
    }
}

@media (max-width: 400px) {
    #aiChatFloatingBtn {
        bottom: 12px !important;
        right: 12px !important;
        width: 46px !important;
        height: 46px !important;
        font-size: 18px !important;
    }
    #aiChatPanel {
        height: calc(100vh - 70px) !important;
        bottom: 64px !important;
        right: 4px !important;
        width: calc(100vw - 8px) !important;
    }
}
