/**
 * AI Chat Assistant - Frontend Styles
 * 前端样式 - 参考子比主题设计风格
 */

:root {
    --ai-chat-primary: #f04494;
    --ai-chat-primary-dark: #d63a7e;
    --ai-chat-primary-light: #ff5da7;
    --ai-chat-shadow: rgba(253, 83, 161, 0.4);
    
    --ai-chat-text: #4e5358;
    --ai-chat-text-light: #777;
    --ai-chat-text-muted: #999;
    
    --ai-chat-bg: #fff;
    --ai-chat-bg-gray: #f5f6f7;
    --ai-chat-bg-hover: #fafafa;
    
    --ai-chat-border: rgba(50, 50, 50, 0.06);
    --ai-chat-border-light: rgba(0, 0, 0, 0.03);
    
    --ai-chat-radius: 8px;
    --ai-chat-radius-sm: 4px;
    --ai-chat-radius-lg: 12px;
    
    --ai-chat-shadow-sm: 0 2px 8px rgba(116, 116, 116, 0.08);
    --ai-chat-shadow-md: 0 4px 16px rgba(116, 116, 116, 0.12);
    --ai-chat-shadow-lg: 0 8px 32px rgba(116, 116, 116, 0.16);
}

body.dark-theme {
    --ai-chat-text: #e5eef7;
    --ai-chat-text-light: #b4b6bb;
    --ai-chat-text-muted: #888a8f;
    
    --ai-chat-bg: #323335;
    --ai-chat-bg-gray: #292a2d;
    --ai-chat-bg-hover: #3a3b3d;
    
    --ai-chat-border: rgba(114, 114, 114, 0.1);
    --ai-chat-border-light: rgba(184, 184, 184, 0.02);
    
    --ai-chat-shadow-sm: 0 2px 8px rgba(24, 24, 24, 0.1);
    --ai-chat-shadow-md: 0 4px 16px rgba(24, 24, 24, 0.15);
    --ai-chat-shadow-lg: 0 8px 32px rgba(24, 24, 24, 0.2);
}

/* 文章内容按钮 */
.ai-chat-content-button-wrap {
    margin: 20px 0 30px 0;
    text-align: left;
    padding: 0;
}

/* 子比主题中在标题下方的样式 */
.zib-widget .ai-chat-content-button-wrap,
.article-header .ai-chat-content-button-wrap {
    margin: 15px 0 20px 0;
}

/* 标题后的按钮，左对齐更自然 */
.entry-header .ai-chat-content-button-wrap {
    margin-top: 15px;
    margin-bottom: 20px;
}

.ai-chat-content-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--ai-chat-primary) 0%, var(--ai-chat-primary-light) 100%);
    color: #fff;
    border: none;
    border-radius: var(--ai-chat-radius);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--ai-chat-shadow-sm);
}

.ai-chat-content-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--ai-chat-shadow);
}

.ai-chat-content-button:active {
    transform: translateY(0);
}

.ai-chat-content-button svg {
    flex-shrink: 0;
}

/* 悬浮按钮 */
.ai-chat-float-button {
    position: absolute !important;
    z-index: 999999 !important;
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: var(--ai-chat-bg);
    color: var(--ai-chat-primary);
    border: 1px solid var(--ai-chat-border);
    border-radius: 50px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--ai-chat-shadow-md);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    white-space: nowrap;
    pointer-events: auto;
}

.ai-chat-float-button:hover {
    background: var(--ai-chat-primary) !important;
    color: #fff !important;
    transform: scale(1.05);
    box-shadow: 0 6px 20px var(--ai-chat-shadow);
}

.ai-chat-float-button svg {
    flex-shrink: 0;
}

/* 确保按钮在所有主题中都可见 */
body .ai-chat-float-button {
    display: none;
}

body .ai-chat-float-button[style*="display: block"],
body .ai-chat-float-button[style*="display: inline-flex"] {
    display: inline-flex !important;
}

/* 模态框 - 改为非模态对话框，不阻止页面操作 */
.ai-chat-modal {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    display: none;
    max-width: 450px;
    width: calc(100vw - 40px);
    animation: aiChatModalSlideUp 0.3s ease;
}

/* 移除遮罩层，使其不阻止页面交互 */
.ai-chat-modal-overlay {
    display: none;
}

.ai-chat-modal-content {
    position: relative;
    width: 100%;
    max-height: 600px;
    background: var(--ai-chat-bg);
    border-radius: var(--ai-chat-radius-lg);
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aiChatModalSlideUp 0.3s ease;
}

/* 从下往上滑入动画 */
@keyframes aiChatModalSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 保留旧动画以兼容 */
@keyframes aiChatModalSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 模态框头部 */
.ai-chat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--ai-chat-border);
    background: var(--ai-chat-bg);
}

.ai-chat-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--ai-chat-text);
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-modal-header h3 svg {
    color: var(--ai-chat-primary);
}

/* 文章上下文标识 */
.ai-chat-context-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    margin-left: 8px;
    padding: 4px 8px;
    background: linear-gradient(135deg, var(--ai-chat-primary) 0%, #667eea 100%);
    color: white;
    border-radius: var(--ai-chat-radius-sm);
    font-weight: normal;
    animation: aiChatBadgePulse 2s ease-in-out infinite;
    cursor: help;
}

@keyframes aiChatBadgePulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }
}

.ai-chat-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--ai-chat-radius-sm);
    color: var(--ai-chat-text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* 模态框主体 */
.ai-chat-modal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 消息容器 */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    background: var(--ai-chat-bg-gray);
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

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

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

/* 消息项 */
.ai-chat-message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: aiChatMessageFadeIn 0.3s ease;
}

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

.ai-chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--ai-chat-bg);
    border: 2px solid var(--ai-chat-border);
    color: var(--ai-chat-primary);
}

.ai-chat-message-user .ai-chat-message-avatar {
    order: 2;
    background: linear-gradient(135deg, var(--ai-chat-primary) 0%, var(--ai-chat-primary-light) 100%);
    border-color: var(--ai-chat-primary);
    color: #fff;
}

.ai-chat-message-content {
    flex: 1;
    background: var(--ai-chat-bg);
    border-radius: var(--ai-chat-radius);
    padding: 12px 16px;
    box-shadow: var(--ai-chat-shadow-sm);
}

.ai-chat-message-user .ai-chat-message-content {
    order: 1;
    background: linear-gradient(135deg, var(--ai-chat-primary) 0%, var(--ai-chat-primary-light) 100%);
    color: #fff;
}

.ai-chat-message-content p {
    margin: 0;
    font-size: 14px;
    line-height: 1.6;
    color: inherit;
}

.ai-chat-message-assistant .ai-chat-message-content p {
    color: var(--ai-chat-text);
}

.ai-chat-message-error .ai-chat-message-avatar {
    background: #ff4d4f;
    border-color: #ff4d4f;
    color: #fff;
}

.ai-chat-message-error .ai-chat-message-content {
    background: #fff2f0;
    border: 1px solid #ffccc7;
}

body.dark-theme .ai-chat-message-error .ai-chat-message-content {
    background: #2a1215;
    border-color: #58181c;
}

.ai-chat-message-error .ai-chat-message-content p {
    color: #cf1322;
}

body.dark-theme .ai-chat-message-error .ai-chat-message-content p {
    color: #ff7875;
}

/* 输入中指示器 */
.ai-chat-typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.ai-chat-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ai-chat-text-muted);
    animation: aiChatTypingBounce 1.4s infinite both;
}

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

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

@keyframes aiChatTypingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* 输入区域 */
.ai-chat-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--ai-chat-border);
    background: var(--ai-chat-bg);
}

/* 快捷操作按钮 */
.ai-chat-quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.ai-chat-quick-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--ai-chat-bg-gray);
    border: 1px solid var(--ai-chat-border);
    border-radius: var(--ai-chat-radius-sm);
    color: var(--ai-chat-text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-chat-quick-btn:hover {
    background: var(--ai-chat-bg-hover);
    border-color: var(--ai-chat-primary);
    color: var(--ai-chat-primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ai-chat-quick-btn:active {
    transform: translateY(0);
}

.ai-chat-quick-btn svg {
    flex-shrink: 0;
}

.ai-chat-quick-btn span {
    white-space: nowrap;
}

/* 输入区域底部（输入框和发送按钮） */
.ai-chat-input-bottom {
    display: flex;
    gap: 12px;
}

.ai-chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 150px;
    padding: 12px 16px;
    background: var(--ai-chat-bg-gray);
    border: 1px solid var(--ai-chat-border);
    border-radius: var(--ai-chat-radius);
    font-size: 14px;
    line-height: 1.5;
    color: var(--ai-chat-text);
    resize: none;
    outline: none;
    transition: all 0.2s ease;
    font-family: inherit;
}

.ai-chat-input:focus {
    border-color: var(--ai-chat-primary);
    box-shadow: 0 0 0 3px rgba(240, 68, 148, 0.1);
}

.ai-chat-input::placeholder {
    color: var(--ai-chat-text-muted);
}

.ai-chat-send-button {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--ai-chat-primary) 0%, var(--ai-chat-primary-light) 100%);
    border: none;
    border-radius: var(--ai-chat-radius);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ai-chat-send-button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px var(--ai-chat-shadow);
}

.ai-chat-send-button:active {
    transform: scale(0.95);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .ai-chat-modal {
        bottom: 0;
        right: 0;
        left: 0;
        max-width: 100%;
        width: 100%;
        border-radius: 0;
    }
    
    .ai-chat-modal-content {
        max-width: 100%;
        max-height: 70vh;
        border-radius: 16px 16px 0 0;
    }
    
    .ai-chat-modal-header {
        padding: 16px 20px;
    }
    
    .ai-chat-messages {
        padding: 16px 20px;
    }
    
    .ai-chat-input-wrapper {
        padding: 12px 20px;
    }
    
    .ai-chat-message-avatar {
        width: 32px;
        height: 32px;
    }
    
    .ai-chat-message-avatar svg {
        width: 16px;
        height: 16px;
    }
}

/* 动画优化 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

