/* Chat Assistant 完整样式 */
.chat-assistant-widget {
    position: fixed;
    z-index: 10000;
    bottom: 30px;
    right: 30px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transition: left 0.3s ease, top 0.3s ease, right 0.3s ease, bottom 0.3s ease;
}

/* 悬浮按钮 */
.chat-assistant-button {
    width: 60px;
    height: 60px;
    background: #9735F9;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    /* cursor: pointer; */
    cursor: move;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    border: none;
    padding: 0;
    /* 移除绝对定位，使用默认流式布局 */
    position: static;
}

.chat-assistant-button:hover {
    background: #005a87;
    transform: scale(1.05);
}

.chat-assistant-button.dragging {
    cursor: grabbing;
    transform: scale(1.1);
}

.chat-icon {
    object-fit: contain;
    /* filter: brightness(0) invert(1); */
    transition: transform 0.3s ease;
    pointer-events: none; 
}

.chat-assistant-button:hover .chat-icon {
    transform: scale(1.1);
}

.chat-assistant-widget.dragging {
    user-select: none;
}

.chat-assistant-widget.dragging .chat-assistant-button,
.chat-assistant-widget.dragging .chat-assistant-container {
    transition: none;
}

/* 对话框容器 */
.chat-assistant-container {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.chat-assistant-container.active {
    display: flex;
}

/* 头部 */
.chat-header {
    background: #9735F9;
    color: white;
    padding: 15px;
    cursor: move;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-header.dragging {
    cursor: grabbing;
}

.close-button {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-button:hover {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f8f9fa;
}

/* 消息样式 - 外部头像 */
.message {
    margin-bottom: 20px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

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

.message.assistant {
    flex-direction: row;
}

/* 外部头像 */
.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.message.user .message-avatar {
    background: #005a87;
    /* order: 2; */
}

.message.assistant .message-avatar {
    background: #f0f0f0;
    border: 1px solid #e1e5e9;
    order: 1;
}

.avatar-icon {
    object-fit: contain; /* 保持比例 */
    display: block;
}

.message.user .avatar-icon {
    filter: brightness(0) invert(1);
}

.message.assistant .avatar-icon {
    /* filter: brightness(0.7); */
    filter: brightness(1);
}

.avatar-icon.cover {
    object-fit: cover; /* 填充整个容器，可能会裁剪 */
    width: 100%;
    height: 100%;
}

/* 消息气泡 */
.message-bubble {
    max-width: calc(100% - 60px);
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
    position: relative;
}

.message.user .message-bubble {
    background: #007cba;
    color: white;
    border-bottom-right-radius: 4px;
    order: 1;
}

.message.assistant .message-bubble {
    background: white;
    color: #333;
    border: 1px solid #e1e5e9;
    border-bottom-left-radius: 4px;
    order: 2;
}

/* 流式消息 */
.message.streaming .message-bubble {
    background: #f8f9fa;
    border-left: 3px solid #007cba;
}

/* 输入区域 */
.chat-input-container {
    padding: 15px;
    border-top: 1px solid #e1e5e9;
    background: white;
}

.chat-input-wrapper {
    display: flex;
    gap: 10px;
}

.chat-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #e1e5e9;
    border-radius: 20px;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    max-height: 100px;
}

.chat-input:focus {
    border-color: #B269FB;
}

/* 发送按钮 */
.send-button {
    background: #9735F9;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    padding: 0;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background: #B269FB;
    transform: scale(1.05);
}

.send-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.send-icon {
    /* width: 20px;
    height: 20px; */
    object-fit: contain;
    /* filter: brightness(0) invert(1); */
    transition: transform 0.3s ease;
}

.send-button:hover:not(:disabled) .send-icon {
    transform: scale(1.1);
}

.send-button:disabled .send-icon {
    opacity: 0.5;
}

/* 加载状态 */
.send-button.loading .send-icon {
    display: none;
}

.send-button.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* 拖拽样式 */
.chat-assistant-widget.dragging {
    user-select: none;
}

.chat-assistant-widget.dragging .chat-assistant-button,
.chat-assistant-widget.dragging .chat-assistant-container {
    transition: none;
}

/* 打字指示器 */
.typing-indicator {
    display: none;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
}

.typing-indicator.active {
    display: flex;
}

.typing-indicator .message-avatar {
    background: #f0f0f0;
    border: 1px solid #e1e5e9;
}

.typing-dots {
    background: white;
    border: 1px solid #e1e5e9;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    max-width: calc(100% - 60px);
}

.typing-dots span {
    animation: typing 1.4s infinite;
    background: #999;
    border-radius: 50%;
    display: inline-block;
    height: 6px;
    margin: 0 1px;
    width: 6px;
}

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

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

/* Markdown 消息内容样式 */
.message-content {
    line-height: 1.6;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 1em 0 0.5em 0;
    font-weight: 600;
    line-height: 1.25;
}

.message-content h1 { font-size: 1.5em; }
.message-content h2 { font-size: 1.3em; }
.message-content h3 { font-size: 1.2em; }
.message-content h4 { font-size: 1.1em; }
.message-content h5 { font-size: 1em; }
.message-content h6 { font-size: 0.9em; color: #666; }

.message-content p {
    margin: 0.5em 0;
}

.message-content ul,
.message-content ol {
    margin: 0.5em 0;
    padding-left: 2em;
}

.message-content li {
    margin: 0.25em 0;
}

.message-content blockquote {
    margin: 0.5em 0;
    padding: 0.5em 1em;
    border-left: 4px solid #007cba;
    background: #f8f9fa;
    color: #555;
}

.message-content table {
    border-collapse: collapse;
    margin: 0.5em 0;
    width: 100%;
}

.message-content th,
.message-content td {
    border: 1px solid #ddd;
    padding: 0.5em;
    text-align: left;
}

.message-content th {
    background: #f5f5f5;
    font-weight: 600;
}

.message-content tr:nth-child(even) {
    background: #f9f9f9;
}

/* 代码样式 */
.message-content code {
    background: #f4f4f4;
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: #f8f8f8;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    padding: 1em;
    margin: 0.5em 0;
    overflow-x: auto;
}

.message-content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}

.inline-code {
    background: #f4f4f4 !important;
    padding: 0.2em 0.4em !important;
    border-radius: 3px !important;
    font-size: 0.9em !important;
    color: #e83e8c !important;
}

/* 链接样式 */
.message-content a {
    color: #007cba;
    text-decoration: underline;
}

.message-content a:hover {
    color: #005a87;
}

.message-content strong {
    font-weight: 600;
}

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

.message-content hr {
    border: none;
    border-top: 1px solid #e1e5e9;
    margin: 1em 0;
}

.message-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 0.5em 0;
}

/* 流式消息的特殊处理 */
.message.streaming .message-content {
    white-space: pre-wrap;
}

.message.streaming .message-content * {
    display: inline;
}

.message.streaming .message-content pre,
.message.streaming .message-content code {
    display: block;
    white-space: pre;
}

/* 滚动条样式 */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

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

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

/* 临时消息样式 */
.temp-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 4px;
    z-index: 10001;
    font-size: 14px;
}

/* 动画 */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* 光标动画 */
.message.streaming .message-content::after {
    content: '▊';
    animation: blink 1s infinite;
    margin-left: 2px;
}

/* 响应式设计 */
@media (max-width: 480px) {
    .chat-assistant-widget {
        bottom: 10px;
        right: 10px;
    }
    
    .chat-assistant-container {
        width: calc(100vw - 40px);
        height: 70vh;
        right: 0;
        bottom: 70px;
    }
    
    .chat-assistant-button {
        width: 50px;
        height: 50px;
    }
    
    .chat-icon {
        width: 24px;
        height: 24px;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        padding: 5px;
    }
    
    
    .message-bubble {
        max-width: calc(100% - 50px);
        padding: 10px 14px;
    }
    
    .send-button {
        width: 36px;
        height: 36px;
    }
    
    /* .send-icon {
        width: 18px;
        height: 18px;
    } */
    
    .chat-messages {
        padding: 12px;
    }
    
    .chat-input-container {
        padding: 12px;
    }
    
    .message-content pre {
        font-size: 0.8em;
        padding: 0.75em;
    }
    
    .message-content ul,
    .message-content ol {
        padding-left: 1.5em;
    }
}

/* 全局拖拽光标 */
body.grabbing-cursor {
    cursor: grabbing !important;
}

body.resizing-cursor {
    cursor: nwse-resize !important;
}