/* 智能助手侧边栏样式 */

/* 入口按钮样式 */
.ai-assistant-btn {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1890ff, #096dd9);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(24, 144, 255, 0.3);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
}

.ai-assistant-btn:hover {
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 6px 20px rgba(24, 144, 255, 0.4);
}

.ai-assistant-btn:active {
    transform: scale(0.95);
}

.ai-assistant-icon {
    font-size: 24px;
    color: white;
    transition: all 0.3s ease;
}

/* 亮色主题下的按钮样式 */
html[data-theme="light"] .ai-assistant-btn {
    background: linear-gradient(135deg, #1890ff, #096dd9);
    box-shadow: 0 4px 12px rgba(24, 144, 255, 0.3);
}

html[data-theme="light"] .ai-assistant-btn:hover {
    box-shadow: 0 6px 20px rgba(24, 144, 255, 0.4);
}

/* 暗色主题下的按钮样式 */
html[data-theme="dark"] .ai-assistant-btn {
    background: linear-gradient(135deg, #00eaff, #00b3cc);
    box-shadow: 0 4px 12px rgba(0, 234, 255, 0.3);
}

html[data-theme="dark"] .ai-assistant-btn:hover {
    box-shadow: 0 6px 20px rgba(0, 234, 255, 0.4);
}

/* 侧边栏容器 */
.ai-assistant-sidebar {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100vh;
    background: var(--bg-color);
    border-left: 1px solid var(--border-color);
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.1);
    z-index: 1001;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.ai-assistant-sidebar.open {
    right: 0;
}

/* 亮色主题下的侧边栏 */
html[data-theme="light"] .ai-assistant-sidebar {
    background: rgba(255, 255, 255, 0.9);
    border-left: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.1);
}

/* 暗色主题下的侧边栏 */
html[data-theme="dark"] .ai-assistant-sidebar {
    background: rgba(33, 37, 41, 0.95);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.3);
}

/* 侧边栏头部 */
.ai-assistant-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.ai-assistant-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-color);
}

.ai-assistant-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-color-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ai-assistant-close:hover {
    background: var(--bg-color-secondary);
    color: var(--text-color);
}

/* 对话区域 */
.ai-assistant-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 消息气泡样式 */
.ai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    animation: messageSlideIn 0.3s ease-out;
    position: relative;
    line-height: 1.5;
}

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

/* 用户消息 */
.ai-message.user {
    align-self: flex-end;
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

/* AI消息 */
.ai-message.ai {
    align-self: flex-start;
    background: var(--bg-color-secondary);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
}

/* 亮色主题消息样式 */
html[data-theme="light"] .ai-message.ai {
    background: rgba(241, 243, 244, 0.8);
    color: #333;
}

/* 暗色主题消息样式 */
html[data-theme="dark"] .ai-message.ai {
    background: rgba(52, 58, 64, 0.8);
    color: #f8f9fa;
}

/* 代码块滚动条样式 */
.ai-message.ai pre::-webkit-scrollbar {
    height: 6px;
}

.ai-message.ai pre::-webkit-scrollbar-track {
    background: transparent;
}

.ai-message.ai pre::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.ai-message.ai pre::-webkit-scrollbar-thumb:hover {
    background: var(--text-color-muted);
}

/* 加载状态消息 */
.ai-message.loading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--bg-color-secondary);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

/* 亮色主题加载状态 */
html[data-theme="light"] .ai-message.loading {
    background: rgba(241, 243, 244, 0.8);
}

/* 暗色主题加载状态 */
html[data-theme="dark"] .ai-message.loading {
    background: rgba(52, 58, 64, 0.8);
}

.loading-dots {
    display: flex;
    gap: 6px;
    align-items: center;
}

.loading-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: loadingPulse 1.4s infinite ease-in-out;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

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

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

.loading-dot:nth-child(3) { 
    background: #52c41a;
}

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

/* 发送按钮加载状态 */
.ai-assistant-send.loading {
    position: relative;
    pointer-events: none;
    background: var(--border-color);
}

.ai-assistant-send.loading svg {
    opacity: 0;
}

.ai-assistant-send.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    top: 50%;
    left: 50%;
    margin-left: -10px;
    margin-top: -10px;
}

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

/* 整体加载遮罩 */
.ai-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(2px);
}

.ai-loading-text {
    font-size: 14px;
    color: var(--text-color-secondary);
    margin-left: 8px;
    animation: fadeInOut 2s infinite;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* 输入区域 */
.ai-assistant-input-area {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    gap: 10px;
}

.ai-assistant-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    outline: none;
    font-size: 14px;
    background: var(--bg-color);
    color: var(--text-color);
    transition: all 0.2s ease;
}

.ai-assistant-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

/* 亮色主题输入框 */
html[data-theme="light"] .ai-assistant-input {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: #333;
}

html[data-theme="light"] .ai-assistant-input:focus {
    border-color: #1890ff;
    box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

/* 暗色主题输入框 */
html[data-theme="dark"] .ai-assistant-input {
    background: rgba(52, 58, 64, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #f8f9fa;
}

html[data-theme="dark"] .ai-assistant-input:focus {
    border-color: #00eaff;
    box-shadow: 0 0 0 2px rgba(0, 234, 255, 0.2);
}

.ai-assistant-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ai-assistant-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(24, 144, 255, 0.3);
}

.ai-assistant-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.ai-assistant-send svg {
    width: 18px;
    height: 18px;
}

/* 空状态提示 */
.ai-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-color-muted);
}

.ai-empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.6;
}

.ai-empty-state-text {
    font-size: 14px;
    margin: 0;
}

/* 错误提示 */
.ai-error-message {
    background: #fff2f0;
    border: 1px solid #ffccc7;
    color: #ff4d4f;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 14px;
}

html[data-theme="dark"] .ai-error-message {
    background: rgba(255, 77, 79, 0.1);
    border: 1px solid rgba(255, 77, 79, 0.3);
    color: #ff7875;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .ai-assistant-sidebar {
        width: 100vw;
        right: -100vw;
    }
    
    .ai-assistant-btn {
        width: 50px;
        height: 50px;
        right: 16px;
        bottom: 16px;
    }
    
    .ai-assistant-icon {
        font-size: 20px;
    }
    
    /* 移动端Markdown样式调整 */
    .ai-message.ai pre {
        padding: 8px;
        font-size: 13px;
    }
    
    .ai-message.ai {
        padding: 10px 12px;
        font-size: 14px;
    }
}

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

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

.ai-assistant-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.ai-assistant-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-color-muted);
}

/* Markdown样式 - 适配markdown-it渲染 */
.ai-message.ai code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.ai-message.ai pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

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

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

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

.ai-message.ai a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px dashed var(--primary-color);
}

.ai-message.ai a:hover {
    text-decoration: underline;
}

.ai-message.ai ul, .ai-message.ai ol {
    padding-left: 20px;
    margin: 8px 0;
}

.ai-message.ai li {
    margin: 4px 0;
}

.ai-message.ai blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 16px;
    margin: 8px 0;
    color: var(--text-color-secondary);
}

.ai-message.ai h1, .ai-message.ai h2, .ai-message.ai h3, 
.ai-message.ai h4, .ai-message.ai h5, .ai-message.ai h6 {
    margin: 16px 0 8px 0;
    font-weight: 600;
}

.ai-message.ai table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
}

.ai-message.ai th, .ai-message.ai td {
    border: 1px solid var(--border-color);
    padding: 8px;
    text-align: left;
}

.ai-message.ai th {
    background: var(--bg-color-secondary);
    font-weight: 600;
}

/* 暗色主题下的Markdown样式 */
html[data-theme="dark"] .ai-message.ai code {
    background: rgba(255, 255, 255, 0.1);
}

html[data-theme="dark"] .ai-message.ai pre {
    background: rgba(255, 255, 255, 0.05);
}

html[data-theme="dark"] .ai-message.ai blockquote {
    border-left-color: var(--primary-color);
    color: var(--text-color-secondary);
}

html[data-theme="dark"] .ai-message.ai th {
    background: rgba(255, 255, 255, 0.1);
}

/* 流式消息样式 */
.stream-content {
    min-height: 20px;
}

/* 打字机效果动画 */
.typewriter {
    overflow: hidden;
    border-right: 2px solid;
    white-space: nowrap;
    animation: typing 2s steps(40, end), blink-caret 0.75s step-end infinite;
}

@keyframes typing {
    from { width: 0 }
    to { width: 100% }
}

@keyframes blink-caret {
    from, to { border-color: transparent }
    50% { border-color: currentColor }
}