/* AI ChatBot Floating Widget */
.ai-chatbot {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 480px;
    max-height: 800px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    transform: translateY(0);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chatbot.open {
    display: flex;
}

.ai-chatbot.minimized {
    max-height: 60px;
    transform: translateY(0);
}

.ai-chatbot.minimized .chatbot-messages,
.ai-chatbot.minimized .chatbot-input-area {
    display: none;
}

/* ChatBot Header */
.chatbot-header {
    background: linear-gradient(135deg, #26a86d 0%, #1e8a4f 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 16px 16px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}

.chatbot-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-avatar {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.chatbot-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.chatbot-title .beta-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 6px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 10px;
    font-weight: 700;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chatbot-status {
    font-size: 12px;
    opacity: 0.9;
    margin: 2px 0 0 0;
}

.chatbot-controls {
    display: flex;
    gap: 8px;
}

.chatbot-control-btn {
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chatbot-control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Messages Container */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
    max-height: 650px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

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

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 10px;
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 600;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #26a86d 0%, #1e8a4f 100%);
    color: white;
}

.message.assistant .message-avatar {
    background: #e2e8f0;
    color: #4a5568;
}

.message-content {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #26a86d 0%, #1e8a4f 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: white;
    color: #2d3748;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.message-time {
    font-size: 11px;
    color: #a0aec0;
    padding: 0 8px;
}

/* Markdown Content Styling */
.markdown-content {
    word-break: break-word;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    margin: 8px 0 6px 0;
    font-weight: 600;
    color: #1a202c;
}

.markdown-content h1 { font-size: 18px; }
.markdown-content h2 { font-size: 16px; }
.markdown-content h3 { font-size: 15px; }
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 { font-size: 14px; }

.markdown-content p {
    margin: 4px 0;
    line-height: 1.5;
}

.markdown-content ul,
.markdown-content ol {
    margin: 4px 0 4px 16px;
    padding: 0;
}

.markdown-content li {
    margin: 2px 0;
    line-height: 1.5;
}

.markdown-content code {
    background: #f1f5f9;
    color: #e74c3c;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.markdown-content pre {
    background: #f1f5f9;
    border-radius: 4px;
    padding: 8px;
    overflow-x: auto;
    margin: 4px 0;
    font-size: 12px;
    line-height: 1.4;
}

.markdown-content pre code {
    background: none;
    color: #2c3e50;
    padding: 0;
    border-radius: 0;
}

.markdown-content blockquote {
    border-left: 3px solid #26a86d;
    margin: 4px 0;
    padding: 0 8px;
    color: #718096;
    font-style: italic;
}

.markdown-content strong {
    font-weight: 600;
    color: #1a202c;
}

.markdown-content em {
    font-style: italic;
}

.markdown-content table {
    border-collapse: collapse;
    margin: 4px 0;
    font-size: 12px;
}

.markdown-content table th,
.markdown-content table td {
    border: 1px solid #cbd5e0;
    padding: 6px 8px;
    text-align: left;
}

.markdown-content table th {
    background: #edf2f7;
    font-weight: 600;
}

.markdown-content a {
    color: #26a86d;
    text-decoration: none;
}

.markdown-content a:hover {
    text-decoration: underline;
}

/* Chart Container in Message */
.chatbot-message-chart {
    background: white;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-top: 8px;
    position: relative;
}

.chatbot-chart-header {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    gap: 6px;
    z-index: 10;
}

.chatbot-chart-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    background-color: transparent !important;
    background-image: none !important;
    border: none !important;
    border-radius: 0 !important;
    color: #64748b;
    font-size: 18px;
    cursor: pointer;
    transition: color 0.2s;
    text-decoration: none !important;
    box-shadow: none !important;
    outline: none !important;
}

.chatbot-chart-action-btn:hover,
.chatbot-chart-action-btn:focus,
.chatbot-chart-action-btn:active {
    background: transparent !important;
    background-color: transparent !important;
    background-image: none !important;
    border: none !important;
    color: #26a86d;
    box-shadow: none !important;
    outline: none !important;
}

.chatbot-chart-action-btn i {
    font-size: 16px;
}

.chatbot-message-chart-container {
    width: 100%;
    height: 250px;
    border-radius: 4px;
}

/* Map Container in Message */
.message-map {
    background: white;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-top: 8px;
}

.message-map-container {
    width: 100%;
    height: 500px;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
}

/* Example Questions */
.message-examples {
    margin-top: 12px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.example-title {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 8px;
}

.example-btn {
    display: block;
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 6px;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    text-align: left;
    font-size: 13px;
    color: #334155;
    cursor: pointer;
    transition: all 0.2s;
}

.example-btn:last-child {
    margin-bottom: 0;
}

.example-btn:hover {
    background: #26a86d;
    color: white;
    border-color: #26a86d;
    transform: translateX(2px);
}

/* Message Actions */
.message-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    color: #64748b;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #475569;
}

.action-btn i {
    font-size: 14px;
}

.regenerate-btn:hover {
    background: #dbeafe;
    border-color: #3b82f6;
    color: #3b82f6;
}

.feedback-btn.active {
    background: #dcfce7;
    border-color: #22c55e;
    color: #22c55e;
}

.feedback-btn[data-feedback="dislike"].active {
    background: #fee2e2;
    border-color: #ef4444;
    color: #ef4444;
}

/* Loading Indicator */
.message-loading {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    background: white;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.message-loading::before,
.message-loading::after {
    display: none !important;
}

.loading-dot {
    width: 8px;
    height: 8px;
    background: #cbd5e0;
    border-radius: 50%;
    animation: loadingBounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loadingBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Loading Spinner - Wave Dots Animation */
.loading-spinner {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 20px;
    animation: none !important;
    transform: none !important;
    border: none !important;
    border-radius: 0 !important;
    width: auto !important;
}

.loading-spinner::before,
.loading-spinner::after {
    display: none !important;
}

.loading-spinner .dot {
    width: 8px;
    height: 8px;
    background: #26a86d;
    border-radius: 50%;
    animation: wave 1.4s ease-in-out infinite;
}

.loading-spinner .dot:nth-child(1) {
    animation-delay: 0s;
}

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

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

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

/* Progress Steps Display */
.progress-steps {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
    background: #f7fafc;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 11px;
    margin-top: 4px;
}

.progress-step {
    padding: 2px 6px;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    animation: fadeIn 0.25s ease-in-out;
    line-height: 1.4;
}

.progress-step::before {
    display: none !important;
}

.progress-step:last-child {
    color: #26a86d;
    font-weight: 500;
}

/* 波浪式动画效果 */
.progress-step:last-child::after {
    content: '';
    display: inline-flex;
    gap: 2px;
    margin-left: 4px;
}

.progress-step:last-child::after {
    content: '●●●';
    letter-spacing: 2px;
    animation: waveDots 1.4s infinite;
}

@keyframes waveDots {
    0%, 20% {
        opacity: 1;
        text-shadow: 0 0 0 currentColor;
    }
    40% {
        opacity: 0.4;
        text-shadow: 0 -2px 0 currentColor;
    }
    60% {
        opacity: 0.4;
        text-shadow: 0 2px 0 currentColor;
    }
    80%, 100% {
        opacity: 1;
        text-shadow: 0 0 0 currentColor;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateX(-4px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Fullscreen Mode */
.ai-chatbot.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
    max-height: none;
    border-radius: 0;
    z-index: 99999;
    display: flex;
    flex-direction: column;
}

.ai-chatbot.fullscreen .chatbot-header {
    border-radius: 0;
    flex-shrink: 0;
}

.ai-chatbot.fullscreen .chatbot-messages {
    flex: 1;
    max-height: none;
    overflow-y: auto;
}

.ai-chatbot.fullscreen .chatbot-input-area {
    border-radius: 0;
    flex-shrink: 0;
}

.chatbot-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e2e8f0;
    border-radius: 0 0 16px 16px;
    display: flex;
    gap: 10px;
    align-items: center;
}

.chatbot-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    transition: border-color 0.2s;
}

.chatbot-input:focus {
    outline: none;
    border-color: #26a86d;
    box-shadow: 0 0 0 3px rgba(38, 168, 109, 0.1);
}

.chatbot-send-btn {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #26a86d 0%, #1e8a4f 100%);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

.chatbot-send-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.chatbot-send-btn:active:not(:disabled) {
    transform: translateY(0);
}

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

/* Empty State */
.chatbot-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #718096;
}

.chatbot-empty-state i {
    font-size: 48px;
    color: #cbd5e0;
    margin-bottom: 16px;
}

.chatbot-empty-state h4 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #4a5568;
}

.chatbot-empty-state p {
    font-size: 14px;
    margin: 0;
}

/* Floating Button (when minimized to icon only) */
.ai-chatbot-fab {
    position: fixed;
    bottom: 30px !important;
    right: 30px !important;
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #26a86d 0%, #1e8a4f 100%);
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(38, 168, 109, 0.4),
                inset -2px -2px 8px rgba(0, 0, 0, 0.1),
                inset 2px 2px 8px rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10000 !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s;
    border: 2px solid rgba(255, 255, 255, 0.2);
    padding: 0;
    margin: 0;
}

.ai-chatbot-fab:hover {
    transform: scale(1.1) rotateY(5deg);
    box-shadow: 0 8px 40px rgba(38, 168, 109, 0.7),
                inset -2px -2px 8px rgba(0, 0, 0, 0.1),
                inset 2px 2px 8px rgba(255, 255, 255, 0.2);
}

.ai-chatbot-fab.hidden {
    display: none !important;
    visibility: hidden !important;
}

.ai-chatbot-fab.hidden::before,
.ai-chatbot-fab.hidden::after {
    display: none !important;
    visibility: hidden !important;
    content: none !important;
    border: none !important;
    animation: none !important;
    opacity: 0 !important;
}

/* Outer ring animation */
.ai-chatbot-fab:not(.hidden)::before {
    content: '';
    position: absolute;
    width: 85px;
    height: 85px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top: 2px solid rgba(38, 168, 109, 0.5);
    border-right: 2px solid rgba(38, 168, 109, 0.5);
    animation: rotate 3s linear infinite;
    pointer-events: none;
}

/* Inner glow effect */
.ai-chatbot-fab:not(.hidden)::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.4), transparent 50%);
    pointer-events: none;
    z-index: 1;
}

.ai-chatbot-fab i {
    color: white;
    font-size: 32px;
    position: relative;
    z-index: 2;
    animation: aiGlow 2.5s ease-in-out infinite;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.ai-chatbot-fab .fab-label {
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 3;
}

.ai-chatbot-fab:hover .fab-label {
    opacity: 1;
}

@keyframes aiGlow {
    0%, 100% {
        text-shadow: 0 0 15px rgba(255, 255, 255, 0.6),
                    0 0 25px rgba(38, 168, 109, 0.4);
        transform: scale(1);
    }
    50% {
        text-shadow: 0 0 20px rgba(255, 255, 255, 0.8),
                    0 0 30px rgba(38, 168, 109, 0.6);
        transform: scale(1.05);
    }
}

@keyframes rotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Notification Badge */
.chatbot-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    border: 2px solid white;
}

/* Responsive Design */
@media (max-width: 768px) {
    .ai-chatbot {
        width: calc(100vw - 40px);
        right: 20px;
        bottom: 20px;
        max-height: calc(100vh - 100px);
    }

    .chatbot-messages {
        max-height: calc(100vh - 250px);
    }

    .message-content {
        max-width: 80%;
    }
}
