/* ========== AI Chat Assistant - Floating Widget ========== */
/* ai-chat.css - 悬浮AI助手聊天窗口样式 */

/* -- Floating Button -- */
.ai-chat-fab {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #2563eb;
    box-shadow: 0 4px 20px rgba(37,99,235,0.25);
    cursor: pointer;
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}
.ai-chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(37,99,235,0.35);
}
.ai-chat-fab svg {
    width: 32px;
    height: 32px;
    fill: #2563eb;
}
.ai-chat-fab .ai-fab-pulse {
    position: absolute;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(37,99,235,0.15);
    animation: ai-pulse 2s infinite;
}
@keyframes ai-pulse {
    0% { transform: scale(1); opacity: 0.7; }
    70% { transform: scale(1.4); opacity: 0; }
    100% { transform: scale(1.4); opacity: 0; }
}

/* -- Chat Window -- */
.ai-chat-window {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 30vw;
    min-width: 380px;
    max-width: 520px;
    height: 60vh;
    min-height: 440px;
    max-height: 700px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    z-index: 99999;
    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-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* -- Header -- */
.ai-chat-header {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #fff;
    flex-shrink: 0;
}
.ai-chat-header-icon {
    width: 28px;
    height: 28px;
    margin-right: 10px;
    fill: #fff;
}
.ai-chat-header-title {
    font-size: 15px;
    font-weight: 600;
    flex: 1;
    letter-spacing: 0.3px;
}
.ai-chat-close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}
.ai-chat-close-btn:hover {
    opacity: 1;
}

/* -- Messages Area -- */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8fafc;
}
.ai-chat-messages::-webkit-scrollbar {
    width: 5px;
}
.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* -- Message Bubbles -- */
.ai-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: ai-msg-in 0.3s ease;
}
@keyframes ai-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.ai-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.ai-msg.bot {
    align-self: flex-start;
}
.ai-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.ai-msg.bot .ai-msg-avatar {
    background: #dbeafe;
    color: #2563eb;
}
.ai-msg.user .ai-msg-avatar {
    background: #e0e7ff;
    color: #4f46e5;
}
.ai-msg-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
}
.ai-msg.bot .ai-msg-bubble {
    background: #fff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-top-left-radius: 4px;
}
.ai-msg.user .ai-msg-bubble {
    background: #2563eb;
    color: #fff;
    border-top-right-radius: 4px;
}

/* -- Typing Indicator (with progress) -- */
.ai-typing-wrap {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    border-top-left-radius: 4px;
    overflow: hidden;
    width: fit-content;
    min-width: 180px;
    max-width: 260px;
}
.ai-typing-progress {
    height: 3px;
    background: #e2e8f0;
    border-radius: 3px 3px 0 0;
    overflow: hidden;
}
.ai-typing-bar {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, #2563eb 0%, #60a5fa 50%, #2563eb 100%);
    background-size: 200% 100%;
    border-radius: 3px;
    animation: ai-bar-slide 1.8s ease-in-out infinite;
}
@keyframes ai-bar-slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}
.ai-typing-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
}
.ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.ai-typing-dot {
    width: 5px;
    height: 5px;
    background: #94a3b8;
    border-radius: 50%;
    animation: ai-typing-bounce 1.4s infinite ease-in-out both;
}
.ai-typing-dot:nth-child(1) { animation-delay: 0s; }
.ai-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.32s; }
@keyframes ai-typing-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}
.ai-typing-text {
    font-size: 11.5px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* -- Status Indicator -- */
.ai-chat-header-status {
    font-size: 11px;
    opacity: 0.8;
    margin-left: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.ai-status-online::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #34d399;
    display: inline-block;
}
.ai-status-offline::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #f87171;
    display: inline-block;
}
.ai-status-connecting::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fbbf24;
    display: inline-block;
    animation: ai-status-blink 1s infinite;
}
@keyframes ai-status-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* -- Timeout & Error Bubbles -- */
.ai-timeout-bubble,
.ai-error-bubble {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.ai-timeout-bubble > div,
.ai-error-bubble > div {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}
.ai-timeout-icon {
    flex-shrink: 0;
    margin-top: 1px;
}
.ai-retry-btn {
    align-self: flex-start;
    padding: 5px 14px;
    border: 1px solid #2563eb;
    border-radius: 6px;
    background: #fff;
    color: #2563eb;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 2px;
}
.ai-retry-btn:hover {
    background: #2563eb;
    color: #fff;
}

/* -- Data Cards (product, factory, cost) -- */
.ai-data-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}
.ai-data-card {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 12.5px;
    cursor: pointer;
    transition: all 0.2s;
}
.ai-data-card:hover {
    border-color: #2563eb;
    background: #eff6ff;
}
.ai-data-card-title {
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 4px;
    font-size: 13px;
}
.ai-data-card-meta {
    color: #64748b;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
}
.ai-data-card-meta span {
    white-space: nowrap;
}
.ai-data-card-score {
    display: inline-block;
    background: #2563eb;
    color: #fff;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}
.ai-data-card-btn {
    display: inline-block;
    margin-top: 6px;
    padding: 4px 12px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
}
.ai-data-card-btn:hover {
    background: #1d4ed8;
}

/* -- Cost Result Card -- */
.ai-cost-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px;
    margin-top: 8px;
}
.ai-cost-card table {
    width: 100%;
    font-size: 12.5px;
    border-collapse: collapse;
}
.ai-cost-card td {
    padding: 4px 0;
    color: #475569;
}
.ai-cost-card td:last-child {
    text-align: right;
    font-weight: 500;
    color: #1e293b;
}
.ai-cost-card .ai-cost-total {
    border-top: 2px solid #2563eb;
    font-weight: 700;
    color: #2563eb;
    font-size: 14px;
}

/* -- Input Area -- */
.ai-chat-input-area {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
    gap: 8px;
}

/* -- Upload Button -- */
.ai-chat-upload-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
}
.ai-chat-upload-btn:hover {
    border-color: #2563eb;
    background: #eff6ff;
    color: #2563eb;
}
.ai-chat-upload-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* -- Upload Preview Area -- */
.ai-chat-upload-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px 4px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
    max-height: 120px;
    overflow-y: auto;
}
.ai-preview-item {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.ai-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.ai-preview-item.ai-preview-file {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    padding: 4px;
}
.ai-preview-item.ai-preview-file svg {
    width: 24px;
    height: 24px;
    fill: #64748b;
    flex-shrink: 0;
}
.ai-preview-filename {
    font-size: 9px;
    color: #475569;
    text-align: center;
    line-height: 1.2;
    margin-top: 2px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ai-preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    padding: 0;
}
.ai-preview-item:hover .ai-preview-remove {
    opacity: 1;
}

/* -- File Message Bubbles -- */
.ai-file-bubble {
    padding: 8px 10px !important;
}
.ai-chat-img-wrap {
    max-width: 200px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 4px;
}
.ai-chat-img {
    max-width: 100%;
    max-height: 180px;
    display: block;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}
.ai-chat-img:hover {
    opacity: 0.9;
}
.ai-file-icon {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}
.ai-file-icon svg {
    width: 36px;
    height: 36px;
}
.ai-msg.user .ai-file-bubble {
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-msg.user .ai-file-bubble .ai-chat-img-wrap {
    /* image type - vertical layout */
}
.ai-msg.user .ai-file-bubble .ai-file-info {
    flex: 1;
    min-width: 0;
}
.ai-file-name {
    font-size: 12px;
    color: rgba(255,255,255,0.9);
    word-break: break-all;
    line-height: 1.3;
}
.ai-file-size {
    font-size: 10px;
    color: rgba(255,255,255,0.65);
}
.ai-msg.bot .ai-file-name {
    color: #1e293b;
}
.ai-msg.bot .ai-file-size {
    color: #94a3b8;
}

/* -- Toast Notification -- */
.ai-chat-toast {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30,41,59,0.9);
    color: #fff;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 12px;
    z-index: 10;
    white-space: nowrap;
    animation: ai-toast-in 0.3s ease;
    pointer-events: none;
}
@keyframes ai-toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(8px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* -- Drag Over Effect -- */
.ai-chat-messages.ai-drag-over {
    background: #eff6ff;
    outline: 2px dashed #2563eb;
    outline-offset: -4px;
}

/* -- Image Lightbox -- */
.ai-chat-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    animation: ai-lightbox-in 0.2s ease;
}
@keyframes ai-lightbox-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
.ai-chat-lightbox img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.ai-chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 13.5px;
    outline: none;
    transition: border-color 0.2s;
    background: #f9fafb;
}
.ai-chat-input:focus {
    border-color: #2563eb;
    background: #fff;
}
.ai-chat-input::placeholder {
    color: #9ca3af;
}
.ai-chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}
.ai-chat-send-btn:hover {
    background: #1d4ed8;
}
.ai-chat-send-btn:disabled {
    background: #93c5fd;
    cursor: not-allowed;
}
.ai-chat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* -- Welcome Message -- */
.ai-welcome {
    text-align: center;
    padding: 20px 16px;
}
.ai-welcome-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    background: #dbeafe;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ai-welcome-icon svg {
    width: 26px;
    height: 26px;
    fill: #2563eb;
}
.ai-welcome h3 {
    font-size: 15px;
    color: #1e293b;
    margin: 0 0 6px;
}
.ai-welcome p {
    font-size: 12.5px;
    color: #64748b;
    margin: 0 0 14px;
}
.ai-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}
.ai-quick-btn {
    padding: 6px 12px;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    background: #fff;
    font-size: 12px;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.ai-quick-btn:hover {
    border-color: #2563eb;
    color: #2563eb;
    background: #eff6ff;
}

/* ========== Mobile Responsive ========== */
@media (max-width: 768px) {
    .ai-chat-fab {
        bottom: 20px;
        right: 20px;
        width: 52px;
        height: 52px;
    }
    .ai-chat-fab svg {
        width: 26px;
        height: 26px;
    }
    .ai-chat-fab .ai-fab-pulse {
        width: 52px;
        height: 52px;
    }
    .ai-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100vw;
        max-width: 100vw;
        min-width: unset;
        height: 75vh;
        max-height: 75vh;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
    }
    .ai-chat-window.open {
        transform: translateY(0);
    }
}
