/* AI Chat Widget - Modern Sidebar Style */
:root {
    --ai-theme-color: #667eea;
    --ai-theme-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

#ai-chat-widget {
    position: fixed;
    bottom: 20px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

#ai-chat-widget.ai-position-right {
    right: 0;
}

#ai-chat-widget.ai-position-left {
    left: 0;
}

/* Toggle Button */
.ai-chat-toggle {
    position: absolute;
    bottom: 0;
    width: 60px;
    height: 60px;
    background: var(--ai-theme-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4), 0 0 0 0 rgba(102, 126, 234, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: #fff;
    animation: ai-pulse 2s infinite;
}

#ai-chat-widget.ai-position-right .ai-chat-toggle {
    right: 20px;
}

#ai-chat-widget.ai-position-left .ai-chat-toggle {
    left: 20px;
}

@keyframes ai-pulse {
    0% { box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4), 0 0 0 0 rgba(102, 126, 234, 0.4); }
    70% { box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4), 0 0 0 10px rgba(102, 126, 234, 0); }
    100% { box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4), 0 0 0 0 rgba(102, 126, 234, 0); }
}

.ai-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
    animation: none;
}

.ai-chat-toggle svg {
    width: 26px;
    height: 26px;
}

.ai-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: #fff;
    font-size: 12px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* Chat Panel */
.ai-chat-panel {
    position: absolute;
    bottom: 75px;
    width: 400px;
    height: 560px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#ai-chat-widget.ai-position-right .ai-chat-panel {
    right: 20px;
}

#ai-chat-widget.ai-position-left .ai-chat-panel {
    left: 20px;
}

#ai-chat-widget.ai-chat-expanded .ai-chat-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

#ai-chat-widget.ai-chat-expanded .ai-chat-toggle {
    animation: none;
    background: linear-gradient(135deg, #a8a8a8 0%, #888 100%);
}

/* Header */
.ai-chat-header {
    padding: 18px 20px;
    background: var(--ai-theme-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.ai-chat-header::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 0;
    right: 0;
    height: 20px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.05), transparent);
    pointer-events: none;
}

.ai-chat-title-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-avatar svg {
    width: 20px;
    height: 20px;
}

.ai-chat-title {
    font-size: 16px;
    font-weight: 600;
}

.ai-chat-status {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-chat-status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #4ade80;
    border-radius: 50%;
}

.ai-chat-actions {
    display: flex;
    gap: 6px;
}

.ai-chat-actions button {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: all 0.2s;
}

.ai-chat-actions button:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

/* Messages Area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: linear-gradient(180deg, #f8f9fc 0%, #fff 100%);
}

.ai-chat-messages::-webkit-scrollbar {
    width: 5px;
}

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

.ai-msg {
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.ai-msg-user {
    flex-direction: row-reverse;
}

.ai-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-msg-bot .ai-msg-avatar {
    background: var(--ai-theme-gradient);
    color: #fff;
}

.ai-msg-user .ai-msg-avatar {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: #fff;
}

.ai-msg-avatar svg {
    width: 16px;
    height: 16px;
}

.ai-msg-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    position: relative;
}

.ai-msg-bot .ai-msg-content {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.ai-msg-user .ai-msg-content {
    background: var(--ai-theme-gradient);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.ai-msg-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 13px;
}

.ai-msg-user .ai-msg-content code {
    background: rgba(255, 255, 255, 0.2);
}

/* Typing Indicator */
.ai-typing {
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    align-items: center;
}

.ai-typing span {
    width: 8px;
    height: 8px;
    background: var(--ai-theme-color);
    border-radius: 50%;
    animation: ai-typing 1.4s infinite ease-in-out;
}

.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-10px); opacity: 1; }
}

/* Input Area */
.ai-chat-input-area {
    padding: 16px 20px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#ai-chat-input {
    flex: 1;
    border: 2px solid #f0f0f0;
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    line-height: 1.4;
}

#ai-chat-input:focus {
    border-color: var(--ai-theme-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#ai-chat-input::placeholder {
    color: #aaa;
}

#ai-send-btn {
    width: 44px;
    height: 44px;
    background: var(--ai-theme-gradient);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

#ai-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

#ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#ai-send-btn svg {
    width: 20px;
    height: 20px;
}

/* Error Message */
.ai-msg-error .ai-msg-content {
    background: #fff5f5;
    color: #c53030;
    border: 1px solid #feb2b2;
}

/* Welcome Message */
.ai-welcome-msg {
    text-align: center;
    padding: 20px;
}

.ai-welcome-msg .ai-msg-content {
    display: inline-block;
    background: linear-gradient(135deg, #f8f9fc 0%, #fff 100%);
    border: 1px solid #eee;
    max-width: 90%;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .ai-chat-panel {
        width: calc(100vw - 20px);
        height: 70vh;
        bottom: 75px;
    }
    
    #ai-chat-widget.ai-position-right .ai-chat-panel,
    #ai-chat-widget.ai-position-left .ai-chat-panel {
        right: 10px;
    }
    
    #ai-chat-widget.ai-position-right .ai-chat-toggle {
        right: 15px;
    }
    
    #ai-chat-widget.ai-position-left .ai-chat-toggle {
        left: 15px;
    }
    
    .ai-msg-content {
        max-width: 85%;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .ai-chat-panel {
        background: #1a1a2e;
    }
    
    .ai-chat-messages {
        background: linear-gradient(180deg, #16162a 0%, #1a1a2e 100%);
    }
    
    .ai-msg-bot .ai-msg-content {
        background: #252542;
        color: #e0e0e0;
    }
    
    .ai-chat-input-area {
        background: #1a1a2e;
        border-top-color: #2a2a4a;
    }
    
    #ai-chat-input {
        background: #252542;
        border-color: #3a3a5a;
        color: #e0e0e0;
    }
    
    #ai-chat-input:focus {
        border-color: var(--ai-theme-color);
    }
}
