/* ============================================
   AI 对话悬浮窗口样式
   ============================================ */
.ai-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

/* 浮动按钮 */
.ai-chat-fab {
    height: 48px;
    border-radius: 24px;
    background: linear-gradient(135deg, #1a7a54 0%, #0d3b2e 100%);
    box-shadow: 0 4px 16px rgba(13, 59, 46, 0.35);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 16px 0 12px;
    transition: transform 0.3s, box-shadow 0.3s;
    position: relative;
    white-space: nowrap;
    z-index: 3;
}
.ai-chat-fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(13, 59, 46, 0.45);
}
.ai-chat-fab svg {
    width: 24px;
    height: 24px;
    fill: #fff;
    flex-shrink: 0;
}
.ai-chat-fab .ai-chat-fab-text {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    letter-spacing: 0.5px;
}
.ai-chat-fab .ai-chat-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #52c41a;
    border: 2px solid #fff;
    display: none;
}
.ai-chat-fab.has-new .ai-chat-dot {
    display: block;
}

/* 遮罩层 */
.ai-chat-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1;
    display: none;
    pointer-events: none;
}
.ai-chat-backdrop.show {
    display: block;
    pointer-events: auto;
}

/* 聊天面板 */
.ai-chat-panel {
    position: fixed;
    bottom: 80px;
    right: 24px;
    width: 380px;
    height: 520px;
    min-width: 300px;
    min-height: 360px;
    max-width: 90vw;
    max-height: 90vh;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e8ecf0;
    z-index: 2;
}
.ai-chat-panel.open {
    display: flex;
}

/* 面板头部 */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 10px 14px;
    background: linear-gradient(135deg, #1a7a54 0%, #0d3b2e 100%);
    color: #fff;
    flex-shrink: 0;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
}
.ai-chat-header-title {
    font-size: 15px;
    font-weight: 600;
}
.ai-chat-header-actions {
    display: flex;
    gap: 8px;
}
.ai-chat-header-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
}
.ai-chat-header-btn:hover {
    background: rgba(255,255,255,0.35);
}

/* 关闭按钮 - 红色醒目 */
.ai-chat-close-btn {
    background: #ff4d4f;
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
}
.ai-chat-close-btn:hover {
    background: #cf1322;
    transform: scale(1.1);
}

/* 缩放拖拽手柄 */
.ai-chat-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    z-index: 10;
    background: linear-gradient(135deg, transparent 40%, #c0c0c0 40%, #c0c0c0 45%, transparent 45%, transparent 55%, #c0c0c0 55%, #c0c0c0 60%, transparent 60%, transparent 70%, #c0c0c0 70%, #c0c0c0 75%, transparent 75%);
    border-radius: 0 0 16px 0;
}
.ai-chat-resize-handle:hover {
    background: linear-gradient(135deg, transparent 40%, #1a7a54 40%, #1a7a54 45%, transparent 45%, transparent 55%, #1a7a54 55%, #1a7a54 60%, transparent 60%, transparent 70%, #1a7a54 70%, #1a7a54 75%, transparent 75%);
}

/* 消息列表 */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #f7f8fa;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.ai-chat-messages::-webkit-scrollbar {
    width: 4px;
}
.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #d0d5dd;
    border-radius: 2px;
}

/* 消息气泡 */
.ai-chat-msg {
    display: flex;
    animation: aiChatFadeIn 0.3s ease;
}
@keyframes aiChatFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.ai-chat-msg.user {
    justify-content: flex-end;
}
.ai-chat-msg.assistant {
    justify-content: flex-start;
}
.ai-chat-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
}
.ai-chat-msg.user .ai-chat-bubble {
    background: linear-gradient(135deg, #1a7a54 0%, #0d3b2e 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-chat-msg.assistant .ai-chat-bubble {
    background: #fff;
    color: #1a1a2e;
    border: 1px solid #e8ecf0;
    border-bottom-left-radius: 4px;
}
.ai-chat-msg.failed .ai-chat-bubble {
    background: #fff2f0;
    border-color: #ffccc7;
    color: #cf1322;
}

/* 加载指示器 */
.ai-chat-typing {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e8ecf0;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    display: none;
}
.ai-chat-typing.show {
    display: flex;
}
.ai-chat-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #a0a0a0;
    animation: aiChatBounce 1.4s infinite ease-in-out both;
}
.ai-chat-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ai-chat-typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes aiChatBounce {
    0%, 80%, 100% { transform: scale(0.6); }
    40% { transform: scale(1); }
}

/* 空状态 */
.ai-chat-empty {
    text-align: center;
    color: #a0a0a0;
    padding: 40px 20px;
    font-size: 13px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.ai-chat-empty svg {
    width: 48px;
    height: 48px;
    opacity: 0.3;
}

/* 底部输入区 */
.ai-chat-input-area {
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid #e8ecf0;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}
.ai-chat-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.5;
    max-height: 100px;
    transition: border-color 0.2s;
}
.ai-chat-input:focus {
    border-color: #1a7a54;
}
.ai-chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #1a7a54;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.ai-chat-send-btn:hover {
    background: #0d3b2e;
}
.ai-chat-send-btn:disabled {
    background: #c0c0c0;
    cursor: not-allowed;
}
.ai-chat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* 响应式 */
@media (max-width: 480px) {
    .ai-chat-panel {
        width: calc(100vw - 32px) !important;
        height: 480px !important;
        left: 16px !important;
        right: auto !important;
        bottom: 76px !important;
        top: auto !important;
    }
    .ai-chat-widget {
        bottom: 16px;
        right: 16px;
    }
    .ai-chat-fab {
        height: 42px;
        padding: 0 12px 0 10px;
        border-radius: 21px;
    }
    .ai-chat-fab svg {
        width: 20px;
        height: 20px;
    }
    .ai-chat-fab .ai-chat-fab-text {
        font-size: 13px;
    }
}