/* 聊天机器人通用样式 */
.chat-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1001;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(45deg, #00d4ff, #9b59b6);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 10px 30px rgba(0, 212, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-toggle:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 40px rgba(0, 212, 255, 0.4);
}

.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.1), rgba(155, 89, 182, 0.1));
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    display: none;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.chat-window.open {
    display: flex;
    opacity: 1;
    transform: translateY(0);
    animation: slideUp 0.3s ease;
}

.chat-window.closing {
    opacity: 0;
    transform: translateY(20px);
    animation: slideDown 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(20px);
    }
}

.chat-header {
    padding: 20px;
    border-bottom: 1px solid rgba(0, 212, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.2);
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.chat-header-controls {
    display: flex;
    gap: 10px;
}

.chat-fullscreen-btn,
.chat-minimize-btn {
    background: none;
    border: none;
    color: #00d4ff;
    font-size: 16px;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.3s ease;
    opacity: 0.7;
}

.chat-fullscreen-btn:hover,
.chat-minimize-btn:hover {
    opacity: 1;
    background: rgba(0, 212, 255, 0.1);
    transform: scale(1.1);
}

.chat-header .user-avatar {
    font-size: 24px;
}

.chat-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-header p {
    margin: 0;
    font-size: 12px;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: rgba(0, 0, 0, 0.1);
}

.message {
    padding: 12px 18px;
    border-radius: 18px;
    max-width: 80%;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.4;
}

.message.user {
    background: linear-gradient(45deg, #00d4ff, #9b59b6);
    color: white;
    align-self: flex-end;
}

.message.ai {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    align-self: flex-start;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-input-container {
    padding: 20px;
    border-top: 1px solid rgba(0, 212, 255, 0.3);
    display: flex;
    gap: 10px;
    background: rgba(0, 0, 0, 0.2);
}

.chat-input {
    flex: 1;
    padding: 12px 18px;
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
}

.chat-input:focus {
    border-color: rgba(0, 212, 255, 0.6);
    background: rgba(0, 0, 0, 0.4);
}

.chat-input::placeholder {
    color: #b0b0b0;
}

.chat-send {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(45deg, #00d4ff, #9b59b6);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.chat-send:hover {
    transform: scale(1.1);
}

/* 隐藏聊天消息滚动条 */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 212, 255, 0.5);
    border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 212, 255, 0.7);
}

/* 全屏模式样式 */
.chat-window {
    transition: none; /* 移除默认transition避免冲突 */
    will-change: transform; /* 提示浏览器优化transform */
}

.chat-window.fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    border-radius: 0 !important;
    z-index: 9999 !important;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.05), rgba(155, 89, 182, 0.05));
    backdrop-filter: blur(20px);
    border: none;
    transform-origin: bottom right;
    animation: expandToFullscreen 0.35s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
    backface-visibility: hidden; /* 启用硬件加速 */
    perspective: 1000px; /* 启用3D硬件加速 */
    overflow: hidden; /* 确保全屏窗口自身处理滚动 */
}

.chat-window.minimizing {
    animation: shrinkFromFullscreen 0.45s cubic-bezier(0.55, 0.06, 0.68, 0.19) forwards;
    backface-visibility: hidden;
    perspective: 1000px;
}

/* 移除旧的淡出/淡入动画，改用JavaScript控制的transition */

/* 使用transform实现更流畅的动画 */
@keyframes expandToFullscreen {
    0% {
        transform: scale(0.35) translate3d(calc(100vw - 380px), calc(100vh - 580px), 0);
        border-radius: 20px;
        opacity: 1;
    }
    100% {
        transform: scale(1) translate3d(0, 0, 0);
        border-radius: 0px;
        opacity: 1;
    }
}

@keyframes shrinkFromFullscreen {
    0% {
        transform: scale(1) translate3d(0, 0, 0);
        border-radius: 0px;
        opacity: 1;
    }
    100% {
        transform: scale(0.35) translate3d(calc(100vw - 380px), calc(100vh - 580px), 0);
        border-radius: 20px;
        opacity: 0.9;
    }
}

.chat-window.fullscreen .chat-messages {
    font-size: 16px;
    line-height: 1.6;
    padding: 30px;
    overflow-y: auto; /* 允许消息区域滚动 */
    max-height: calc(100vh - 160px); /* 减去头部和输入区域的高度 */
}

.chat-window.fullscreen .message {
    max-width: 80%;
    margin-bottom: 20px;
    font-size: 16px;
    padding: 15px 20px;
}

.chat-window.fullscreen .chat-input-container {
    padding: 30px;
}

.chat-window.fullscreen .chat-input {
    font-size: 16px;
    padding: 15px 25px;
}

.chat-window.fullscreen .chat-send {
    width: 50px;
    height: 50px;
    font-size: 18px;
}

.chat-window.fullscreen .chat-header {
    padding: 25px 30px;
}

.chat-window.fullscreen .chat-header-left .user-avatar {
    font-size: 28px;
}

.chat-window.fullscreen .chat-header h4 {
    font-size: 20px;
}

.chat-window.fullscreen .chat-header p {
    font-size: 14px;
}

/* 思考动画样式 */
.message.thinking {
    opacity: 0.8;
    position: relative;
}

.thinking-dots {
    margin-right: 10px;
}

.dots-animation {
    display: inline-flex;
    gap: 2px;
}

.dots-animation span {
    width: 4px;
    height: 4px;
    background: #00d4ff;
    border-radius: 50%;
    display: inline-block;
    animation: thinking 1.4s infinite both;
}

.dots-animation span:nth-child(1) {
    animation-delay: 0s;
}

.dots-animation span:nth-child(2) {
    animation-delay: 0.2s;
}

.dots-animation span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes thinking {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 移动端适配 */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 20px;
        right: 20px;
    }
    
    .chat-toggle {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .chat-window {
        width: 300px;
        height: 400px;
        bottom: 70px;
    }
    
    .chat-window.fullscreen {
        width: 100vw !important;
        height: 100vh !important;
    }
    
    .chat-window.fullscreen .chat-messages {
        padding: 20px;
        font-size: 15px;
        overflow-y: auto;
        max-height: calc(100vh - 140px); /* 移动端减去头部和输入区域的高度 */
    }
    
    .chat-window.fullscreen .message {
        font-size: 15px;
        padding: 12px 16px;
        max-width: 90%;
    }
    
    .chat-window.fullscreen .chat-input-container {
        padding: 20px;
    }
    
    .chat-window.fullscreen .chat-header {
        padding: 20px;
    }
    
    /* 移动端动画调整 */
    @keyframes expandToFullscreen {
        0% {
            transform: scale(0.3) translate3d(calc(100vw - 320px), calc(100vh - 470px), 0);
            border-radius: 20px;
            opacity: 1;
        }
        100% {
            transform: scale(1) translate3d(0, 0, 0);
            border-radius: 0px;
            opacity: 1;
        }
    }
    
    @keyframes shrinkFromFullscreen {
        0% {
            transform: scale(1) translate3d(0, 0, 0);
            border-radius: 0px;
            opacity: 1;
        }
        100% {
            transform: scale(0.3) translate3d(calc(100vw - 320px), calc(100vh - 470px), 0);
            border-radius: 20px;
            opacity: 0.9;
        }
    }
    
    .chat-header {
        padding: 15px;
    }
    
    .chat-messages {
        padding: 15px;
    }
    
    .chat-input-container {
        padding: 15px;
    }
}

@media (max-width: 480px) {
    .chat-window {
        width: 280px;
        height: 350px;
        right: -10px;
    }
}

/* ===========================================
   Markdown样式支持 (用于AI消息)
   =========================================== */

/* AI消息中的Markdown内容 */
.message.ai .markdown-content {
    line-height: 1.6;
    color: #e0e0e0;
    word-wrap: break-word;
}

/* 标题样式 */
.message.ai .markdown-content h1,
.message.ai .markdown-content h2,
.message.ai .markdown-content h3,
.message.ai .markdown-content h4,
.message.ai .markdown-content h5,
.message.ai .markdown-content h6 {
    color: #00d4ff;
    margin: 12px 0 6px 0;
    font-weight: 600;
    line-height: 1.25;
}

.message.ai .markdown-content h1 {
    font-size: 1.4em;
    border-bottom: 1px solid #00d4ff;
    padding-bottom: 4px;
}

.message.ai .markdown-content h2 {
    font-size: 1.2em;
    border-bottom: 1px solid #444;
    padding-bottom: 2px;
}

.message.ai .markdown-content h3 {
    font-size: 1.1em;
}

.message.ai .markdown-content h4,
.message.ai .markdown-content h5,
.message.ai .markdown-content h6 {
    font-size: 1em;
    color: #b0b0b0;
}

/* 段落样式 */
.message.ai .markdown-content p {
    margin: 6px 0;
    color: #e0e0e0;
}

/* 强调文本 */
.message.ai .markdown-content strong {
    color: #fff;
    font-weight: 600;
}

.message.ai .markdown-content em {
    color: #f0f0f0;
    font-style: italic;
}

/* 代码样式 */
.message.ai .markdown-content code {
    background: rgba(255, 255, 255, 0.15);
    color: #ff6b6b;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85em;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.message.ai .markdown-content pre {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    padding: 12px;
    margin: 8px 0;
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.8em;
    line-height: 1.4;
}

.message.ai .markdown-content pre code {
    background: transparent;
    color: #e0e0e0;
    padding: 0;
    border: none;
    font-size: inherit;
}

/* 链接样式 */
.message.ai .markdown-content a {
    color: #00d4ff;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

.message.ai .markdown-content a:hover {
    color: #ffffff;
    border-bottom-color: #00d4ff;
}

/* 列表样式 */
.message.ai .markdown-content ul,
.message.ai .markdown-content ol {
    margin: 6px 0;
    padding-left: 20px;
}

.message.ai .markdown-content li {
    margin: 2px 0;
    color: #e0e0e0;
}

.message.ai .markdown-content ul li {
    list-style-type: none;
    position: relative;
}

.message.ai .markdown-content ul li::before {
    content: '•';
    color: #00d4ff;
    font-weight: bold;
    position: absolute;
    left: -14px;
}

/* 引用样式 */
.message.ai .markdown-content blockquote {
    margin: 8px 0;
    padding: 8px 12px;
    background: rgba(0, 212, 255, 0.1);
    border-left: 3px solid #00d4ff;
    border-radius: 0 3px 3px 0;
    color: #f0f0f0;
    font-style: italic;
}

.message.ai .markdown-content blockquote p {
    margin: 0;
}

/* 水平分割线 */
.message.ai .markdown-content hr {
    border: none;
    border-top: 1px solid #444;
    margin: 12px 0;
    opacity: 0.6;
}

/* 数学公式样式 */
.message.ai .markdown-content .math-inline {
    background: rgba(255, 255, 255, 0.15);
    color: #4caf50;
    padding: 1px 4px;
    border-radius: 3px;
    font-family: 'Times New Roman', serif;
    font-style: italic;
    font-size: 0.9em;
}

.message.ai .markdown-content .math-block {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(76, 175, 80, 0.3);
    border-radius: 6px;
    padding: 12px;
    margin: 8px 0;
    color: #4caf50;
    font-family: 'Times New Roman', serif;
    font-style: italic;
    text-align: center;
    font-size: 1em;
}

/* 响应式调整 */
@media (max-width: 768px) {
    .message.ai .markdown-content {
        font-size: 13px;
    }
    
    .message.ai .markdown-content h1 {
        font-size: 1.3em;
    }
    
    .message.ai .markdown-content h2 {
        font-size: 1.15em;
    }
    
    .message.ai .markdown-content pre {
        padding: 8px;
        font-size: 0.75em;
    }
    
    .message.ai .markdown-content ul,
    .message.ai .markdown-content ol {
        padding-left: 16px;
    }
}
