/* AI助手聊天界面样式 */
.ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.ai-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--button-bg);
    color: var(--button-text);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
}

.ai-chat-toggle:hover {
    transform: scale(1.1);
    background: var(--button-hover-bg);
}

.ai-chat-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 350px;
    height: 500px;
    background: var(--ai-chat-bg);
    border-radius: 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

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

.ai-chat-header {
    padding: 15px 20px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.ai-chat-close {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 20px;
    padding: 5px;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth; /* 平滑滚动效果 */
}

.ai-chat-message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 15px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); /* 添加轻微阴影 */
    word-wrap: break-word; /* 确保长文本换行 */
    transition: transform 0.2s ease; /* 添加过渡效果 */
}

/* 消息内容容器 */
.message-content {
    width: 100%;
}

.ai-chat-message.user {
    align-self: flex-end;
    background: var(--ai-chat-message-user-bg);
    color: var(--button-text);
    border-bottom-right-radius: 5px;
    margin-left: 40px; /* 为用户消息留出左侧空间，保持对称 */
}

.ai-chat-message.bot {
    align-self: flex-start;
    background: var(--ai-chat-message-bot-bg);
    color: var(--text-primary);
    border-bottom-left-radius: 5px;
    padding-left: 16px; /* 恢复正常内边距 */
    margin-left: 50px; /* 为头像留出空间 */
    margin-right: 40px; /* 为AI消息留出右侧空间，保持对称 */
}

/* AI头像样式 */
.ai-avatar {
    position: absolute;
    left: -45px; /* 调整位置，使头像与消息气泡有适当间距 */
    top: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background-color: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 添加轻微阴影 */
    border: 2px solid var(--border-color); /* 添加边框 */
}

.ai-avatar img, .ai-avatar svg {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 添加消息时间戳样式 */
.message-timestamp {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: right;
    opacity: 0.7;
}

/* 添加打字指示器样式 */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: var(--ai-chat-message-bot-bg);
    border-radius: 15px;
    margin-left: 50px;
    margin-top: 5px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.typing-indicator.active {
    opacity: 1;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-primary);
    border-radius: 50%;
    display: inline-block;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.6;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Markdown样式 */
.ai-chat-message.bot h2 {
    font-size: 1.4em;
    margin: 0.8em 0 0.4em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
}

.ai-chat-message.bot h3 {
    font-size: 1.2em;
    margin: 0.6em 0 0.3em;
}

.ai-chat-message.bot ul, 
.ai-chat-message.bot ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.ai-chat-message.bot li {
    margin: 0.3em 0;
}

.ai-chat-message.bot code {
    background: var(--code-bg);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
}

.ai-chat-message.bot pre {
    background: var(--code-bg);
    padding: 1em;
    border-radius: 5px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.ai-chat-message.bot blockquote {
    border-left: 4px solid var(--border-color);
    margin: 0.5em 0;
    padding: 0.5em 1em;
    background: var(--blockquote-bg);
    border-radius: 3px;
}

.ai-chat-message.bot strong {
    font-weight: 600;
}

.ai-chat-message.bot em {
    font-style: italic;
}

.ai-chat-message.bot p {
    margin: 0.5em 0;
}

.ai-chat-input-container {
    padding: 12px 15px;
    background: var(--ai-chat-input-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-input {
    flex: 1;
    padding: 8px 15px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    resize: none;
    height: 40px;
    line-height: 20px;
    outline: none;
}

.ai-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--button-bg);
    color: var(--button-text);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.3s ease;
}

.ai-chat-send:hover {
    background: var(--button-hover-bg);
    transform: scale(1.05);
}

/* 移动设备响应式设计 */
@media (max-width: 480px) {
    .ai-chat-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100vh; /* 使用视口高度 */
        margin: 0;
        border-radius: 0;
        z-index: 1001;
        display: flex;
        flex-direction: column;
    }

    .ai-chat-header {
        padding: 15px;
        font-size: 16px;
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
        background: var(--bg-secondary-transparent);
        position: sticky;
        top: 0;
        z-index: 2;
    }

    .ai-chat-messages {
        flex: 1;
        padding: 15px;
        font-size: 15px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* 增加iOS滚动流畅度 */
    }

    .ai-chat-message {
        max-width: 88%;
        padding: 12px 16px;
        font-size: 15px;
        line-height: 1.5;
    }

    .ai-chat-message.user {
        margin-left: 15%;
        margin-right: 10px;
    }

    .ai-chat-message.bot {
        margin-right: 15%;
        margin-left: 45px;
    }

    .ai-avatar {
        width: 32px;
        height: 32px;
        left: -38px;
        border-width: 1.5px;
    }

    .ai-chat-input-container {
        padding: 10px 15px;
        background: var(--bg-secondary-transparent);
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
        position: sticky;
        bottom: 0;
        z-index: 2;
        border-top: 1px solid var(--border-color);
    }

    .ai-chat-input {
        height: 40px;
        font-size: 15px;
        padding: 8px 15px;
        max-height: 120px; /* 限制输入框最大高度 */
        border-radius: 18px;
    }

    .ai-chat-send {
        width: 40px;
        height: 40px;
        font-size: 18px;
        flex-shrink: 0;
    }

    .ai-chat-toggle {
        width: 50px;
        height: 50px;
        bottom: 15px;
        right: 15px;
        font-size: 24px;
        z-index: 1000;
    }

    /* 添加安全区域适配 */
    @supports (padding: max(0px)) {
        .ai-chat-input-container {
            padding-bottom: max(10px, env(safe-area-inset-bottom));
        }
        
        .ai-chat-toggle {
            bottom: max(15px, env(safe-area-inset-bottom));
        }
    }
}

/* 添加新的透明背景变量 */
:root {
    --bg-secondary-transparent: rgba(var(--bg-secondary-rgb), 0.85);
}

@media (max-width: 1000px) {
    .ai-chat-toggle {
        width: 120px;
        height: 120px;
        font-size: 48px;
    }

    .ai-chat-message {
        max-width: 90%;
        font-size: 15px;
    }

    .ai-chat-input {
        font-size: 15px;
        height: 42px;
    }
}