/**
 * AI 生成系统 v8 - 统一聊天界面样式
 * 修复：微信缓存问题、对话框支持上传文件、统一AI图标风格
 */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, "Microsoft YaHei", "PingFang SC", sans-serif;
    background: linear-gradient(135deg, #e0e7ff 0%, #ddd6fe 30%, #c7d2fe 55%, #e0e7ff 80%, #ede9fe 100%);
    color: #1f2937; min-height: 100vh; min-height: -webkit-fill-available; overflow-x: hidden;
}

#particle-canvas {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 0; pointer-events: none;
}

body::before, body::after {
    content: ''; position: fixed; border-radius: 50%; z-index: 0; pointer-events: none;
}
body::before {
    top: -180px; right: -80px; width: 500px; height: 500px;
    background: radial-gradient(circle, rgba(99,102,241,0.22) 0%, transparent 70%);
    filter: blur(80px);
}
body::after {
    bottom: -200px; left: -120px; width: 600px; height: 600px;
    background: radial-gradient(circle, rgba(139,92,246,0.18) 0%, transparent 70%);
    filter: blur(90px);
}

.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.3); z-index: 99;
}
.sidebar-overlay.active { display: block; }

.sidebar {
    position: fixed; top: 0; left: 0; width: 320px; height: 100vh;
    background: rgba(255,255,255,0.9); backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-right: 1px solid rgba(99,102,241,0.08);
    z-index: 100; transform: translateX(-100%);
    transition: transform 0.3s ease; display: flex; flex-direction: column;
    overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid rgba(99,102,241,0.06);
}
.sidebar-title { font-weight: 700; font-size: 16px; color: #1e293b; }
.sidebar-close {
    background: none; border: none; font-size: 20px; color: #9ca3af;
    cursor: pointer; padding: 8px 12px; border-radius: 8px; min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
}
.sidebar-close:hover { background: rgba(99,102,241,0.08); color: #6366f1; }

.sidebar-body { flex: 1; padding: 16px 20px; overflow-y: auto; }
.sidebar-section { margin-bottom: 16px; }
.sidebar-group { margin-bottom: 12px; }
.sidebar-footer { padding: 12px 20px; border-top: 1px solid rgba(99,102,241,0.06); }

.upload-label {
    display: block; padding: 12px; text-align: center; border: 2px dashed rgba(99,102,241,0.2);
    border-radius: 10px; color: #6366f1; font-size: 13px; cursor: pointer;
    transition: all 0.2s; font-weight: 500;
}
.upload-label:hover { border-color: rgba(99,102,241,0.4); background: rgba(99,102,241,0.04); }

input[type="file"] { display: none; }

.sidebar-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.sidebar-preview-item {
    position: relative; width: 56px; height: 56px; border-radius: 8px; overflow: hidden;
    border: 1px solid rgba(99,102,241,0.1);
}
.sidebar-preview-item img { width: 100%; height: 100%; object-fit: cover; }
.preview-remove {
    position: absolute; top: 0; right: 0; background: rgba(239,68,68,0.85);
    color: #fff; font-size: 10px; width: 18px; height: 18px; border-radius: 0 0 0 8px;
    display: flex; align-items: center; justify-content: center; cursor: pointer; border: none;
}

.label { display: block; color: #374151; font-weight: 600; margin: 10px 0 6px; font-size: 13px; }
.input, .textarea {
    width: 100%; border: 1px solid rgba(99,102,241,0.12); border-radius: 10px;
    padding: 10px 12px; outline: none; font-size: 14px;
    background: rgba(255,255,255,0.65); color: #1f2937; transition: all 0.2s;
}
.input:focus, .textarea:focus { border-color: rgba(99,102,241,0.35); background: rgba(255,255,255,0.85); }
.input { appearance: none; -webkit-appearance: none; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px;
}
select option { background: #fff; color: #1f2937; }
.textarea { height: 70px; resize: vertical; line-height: 1.5; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #374151; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; accent-color: #6366f1; }
.range-input { width: 100%; margin-top: 4px; accent-color: #6366f1; }
.range-value { font-size: 13px; color: #6366f1; font-weight: 600; }
.btn-outline {
    width: 100%; padding: 8px; border: 1px solid rgba(99,102,241,0.2);
    border-radius: 8px; background: transparent; color: #6366f1; font-size: 13px;
    cursor: pointer; min-height: 44px;
}
.btn-outline:hover { background: rgba(99,102,241,0.06); }

.page {
    position: relative; z-index: 1; display: flex; flex-direction: column;
    min-height: 100vh;
}

.header {
    height: 56px; display: flex; align-items: center;
    padding: 0 16px; gap: 10px;
    background: rgba(255,255,255,0.65); backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(99,102,241,0.06);
    position: sticky; top: 0; z-index: 50;
    /* 刘海屏适配 */
    padding-top: env(safe-area-inset-top);
    box-sizing: content-box;
}

.menu-btn-wrap {
    position: relative; z-index: 60;
    min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
}
.menu-btn {
    background: none; border: none; font-size: 24px; line-height: 1;
    color: #4b5563; cursor: pointer; padding: 8px;
    min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px; touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.menu-btn:hover { background: rgba(99,102,241,0.08); color: #6366f1; }
.menu-btn:active { background: rgba(99,102,241,0.15); }

.header-title {
    margin: 0; font-size: 17px; font-weight: 700;
    background: linear-gradient(135deg, #4338ca, #7c3aed);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; white-space: nowrap;
}
.current-model {
    margin-left: auto; padding: 4px 10px;
    background: rgba(99,102,241,0.08); border-radius: 6px;
    font-size: 12px; color: #6366f1; font-weight: 600;
}

.main-area { flex: 1; display: flex; flex-direction: column; height: calc(100vh - 56px); height: calc(100dvh - 56px); overflow: hidden; }

.chat-messages {
    flex: 1; overflow-y: auto; padding: 24px 0;
    display: flex; flex-direction: column; gap: 18px;
}
.chat-welcome {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; flex: 1; color: #9ca3af; gap: 12px;
}
.chat-welcome-icon { font-size: 48px; }
.chat-welcome p { font-size: 14px; }

.chat-msg { display: flex; gap: 10px; max-width: 900px; margin: 0 auto; width: 100%; padding: 0 24px; }
.msg-user { flex-direction: row-reverse; }
.msg-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.msg-avatar-user { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; }
.msg-avatar-ai {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff; overflow: hidden;
}
.msg-avatar-ai svg { width: 22px; height: 22px; }
.msg-bubble {
    max-width: 80%; border-radius: 16px; padding: 12px 16px;
    line-height: 1.7; font-size: 14.5px; word-break: break-word;
}
.msg-user .msg-bubble {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff; border-bottom-right-radius: 4px;
}
.msg-ai .msg-bubble {
    background: rgba(255,255,255,0.65); backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.6); color: #1f2937;
    border-bottom-left-radius: 4px;
}
.msg-model-tag { font-size: 11px; color: rgba(107,114,128,0.7); margin-bottom: 4px; }
.msg-user .msg-model-tag { color: rgba(255,255,255,0.6); }
.msg-content strong { color: #312e81; }

.user-images { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.user-images img { max-width: 120px; max-height: 100px; border-radius: 8px; }

.paste-preview {
    display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 24px 0;
    max-width: 900px; margin: 0 auto; width: 100%;
}
.paste-item {
    position: relative; width: 64px; height: 64px; border-radius: 8px;
    overflow: hidden; border: 2px solid rgba(99,102,241,0.15);
}
.paste-item img { width: 100%; height: 100%; object-fit: cover; }
.paste-item.file-tag {
    width: auto; height: auto; padding: 6px 10px; border-radius: 8px;
    background: rgba(99,102,241,0.08); border-color: rgba(99,102,241,0.15);
    display: flex; align-items: center; gap: 4px;
}
.paste-remove {
    position: absolute; top: 0; right: 0; background: rgba(239,68,68,0.85);
    color: #fff; font-size: 11px; width: 20px; height: 20px; border-radius: 0 0 0 8px;
    display: flex; align-items: center; justify-content: center; cursor: pointer; border: none;
}

.chat-input-area {
    padding: 12px 24px; background: rgba(255,255,255,0.45);
    backdrop-filter: blur(16px); border-top: 1px solid rgba(99,102,241,0.06);
}
.chat-input-wrap { max-width: 900px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.chat-input {
    flex: 1; border: 1px solid rgba(99,102,241,0.12); border-radius: 14px;
    padding: 12px 16px; font-size: 15px; background: rgba(255,255,255,0.7);
    color: #1f2937; resize: none; outline: none; line-height: 1.5;
    font-family: inherit; max-height: 120px; overflow-y: auto;
}
.chat-input:focus { border-color: rgba(99,102,241,0.35); box-shadow: 0 0 0 3px rgba(99,102,241,0.08); }
.chat-input::placeholder { color: rgba(107,114,128,0.5); }
.chat-send-btn {
    padding: 12px 24px; border: none; border-radius: 14px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
    min-height: 44px; white-space: nowrap; transition: all 0.2s;
}
.chat-send-btn:hover:not(:disabled) { box-shadow: 0 4px 16px rgba(99,102,241,0.4); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* 文件上传按钮 */
.chat-file-btn {
    width: 44px; height: 44px; border-radius: 12px;
    background: rgba(99,102,241,0.08); color: #6366f1;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 300; cursor: pointer;
    flex-shrink: 0; transition: all 0.2s; border: none;
}
.chat-file-btn:hover { background: rgba(99,102,241,0.15); }

/* 代码块 - 左右分栏预览 */
.code-block {
    margin: 12px 0; border-radius: 12px; overflow: hidden;
    border: 1px solid rgba(99,102,241,0.12); background: #fff;
}
.code-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 14px; background: linear-gradient(135deg, #f5f3ff, #ede9fe);
    border-bottom: 1px solid rgba(99,102,241,0.08);
}
.code-lang { font-size: 12px; font-weight: 700; color: #6366f1; text-transform: uppercase; letter-spacing: 0.5px; }
.code-actions { display: flex; gap: 6px; }
.code-run-btn, .code-copy-btn {
    padding: 4px 12px; border: none; border-radius: 6px;
    font-size: 12px; cursor: pointer; font-weight: 600; transition: all 0.2s;
}
.code-run-btn { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; }
.code-run-btn:hover { box-shadow: 0 2px 8px rgba(99,102,241,0.3); }
.code-copy-btn { background: rgba(255,255,255,0.8); color: #6b7280; border: 1px solid rgba(99,102,241,0.1); }
.code-copy-btn:hover { color: #4338ca; }

.code-body { display: flex; min-height: 0; }
.code-left { width: 100%; transition: width 0.3s ease; overflow: auto; }
.code-block.has-preview .code-left { width: 50%; border-right: 1px solid rgba(99,102,241,0.1); }
.code-block pre {
    margin: 0; padding: 14px 16px; font-size: 13px;
    background: #1e1e2e; color: #cdd6f4; overflow-x: auto;
    line-height: 1.6; max-height: 500px; overflow-y: auto;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}
.code-block pre code { font-family: inherit; }
.code-right { width: 50%; display: flex; flex-direction: column; background: #fff; }
.preview-label {
    padding: 6px 14px; font-size: 12px; font-weight: 600; color: #6366f1;
    background: linear-gradient(135deg, #f5f3ff, #ede9fe);
    border-bottom: 1px solid rgba(99,102,241,0.06);
}
.code-iframe { width: 100%; flex: 1; min-height: 300px; max-height: 500px; border: none; background: #fff; }

/* 代码预览 - 全屏模态弹窗 */
.preview-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); z-index: 9999;
    display: flex; justify-content: center; align-items: center;
    opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s;
    backdrop-filter: blur(4px);
}
.preview-overlay.open { opacity: 1; visibility: visible; }
.preview-panel {
    width: 80%; height: 85%; max-width: 1400px;
    background: #fff; border-radius: 16px; overflow: hidden;
    display: flex; flex-direction: column;
    box-shadow: 0 8px 48px rgba(0,0,0,0.25);
    border: 1px solid rgba(99,102,241,0.1);
}
.preview-panel-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 24px; background: linear-gradient(135deg, #f5f3ff, #ede9fe);
    border-bottom: 1px solid rgba(99,102,241,0.1);
}
.preview-panel-title { font-size: 15px; font-weight: 700; color: #4338ca; }
.preview-panel-close {
    background: none; border: 1px solid rgba(99,102,241,0.15); font-size: 18px; color: #6b7280;
    cursor: pointer; padding: 8px 14px; border-radius: 8px;
    min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.preview-panel-close:hover { background: rgba(99,102,241,0.08); color: #6366f1; border-color: rgba(99,102,241,0.3); }
.preview-panel-iframe {
    flex: 1; width: 100%; border: none; background: #fff;
}

.inline-code { background: rgba(99,102,241,0.08); padding: 2px 6px; border-radius: 4px; font-size: 13px; color: #4338ca; font-family: 'Consolas', monospace; }
.msg-user .inline-code { background: rgba(255,255,255,0.2); color: #fff; }

.typing { display: inline-block; animation: blink 1s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }
.msg-error { color: #ef4444; }
.msg-info { color: #6b7280; }

.generate-result { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px,1fr)); gap: 20px; }
.result-card {
    background: rgba(255,255,255,0.75); backdrop-filter: blur(10px);
    border-radius: 14px; padding: 12px; border: 1px solid rgba(255,255,255,0.6);
    box-shadow: 0 2px 8px rgba(99,102,241,0.08);
}
.result-card img, .result-card video { width: 100%; border-radius: 10px; display: block; background: #000; }
.result-card a { display: block; margin-top: 10px; text-align: center; color: #6366f1; text-decoration: none; font-weight: 500; }
.task-info { background: rgba(99,102,241,0.06); border: 1px solid rgba(99,102,241,0.12); border-radius: 12px; padding: 14px; color: #4338ca; font-size: 14px; line-height: 1.8; }

.site-footer {
    text-align: center; padding: 10px 16px; font-size: 12px; color: #9ca3af;
    background: rgba(255,255,255,0.35); backdrop-filter: blur(8px);
    border-top: 1px solid rgba(99,102,241,0.06); line-height: 1.6;
}
.footer-dot { margin: 0 8px; color: #d1d5db; }
.site-footer a { color: #6366f1; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(99,102,241,0.3); }

@media screen and (max-width: 600px) {
    body { background: linear-gradient(135deg, #e0e7ff, #ede9fe); }
    #particle-canvas { display: none; }
    body::before, body::after { display: none; }
    .sidebar { width: 88vw; max-width: 88vw; }
    /* 手机端header适配刘海屏 */
    .header { 
        padding: 0 10px; 
        padding-top: max(10px, env(safe-area-inset-top));
        height: auto;
        min-height: 56px;
    }
    .header-title { font-size: 15px; }
    .current-model { font-size: 11px; padding: 3px 8px; }
    .chat-messages { padding: 16px 0; gap: 14px; }
    .chat-msg { padding: 0 10px; }
    .msg-bubble { max-width: 88%; font-size: 14px; padding: 10px 14px; }
    /* font-size: 16px 防止iOS缩放 */
    .chat-input { font-size: 16px; padding: 10px 14px; }
    .chat-send-btn { padding: 10px 18px; font-size: 14px; }
    .chat-input-area { 
        padding: 8px 10px; 
        padding-bottom: max(8px, env(safe-area-inset-bottom)); 
    }
    .paste-preview { padding: 8px 10px 0; }
    .code-body { flex-direction: column; }
    .code-left { width: 100% !important; }
    .code-right { width: 100%; }
    .code-block.has-preview .code-left { width: 100% !important; border-right: none; border-bottom: 1px solid rgba(99,102,241,0.1); }
    .code-iframe { min-height: 200px; max-height: 350px; }
    .code-block pre { max-height: 300px; font-size: 12px; }
    .generate-result { grid-template-columns: 1fr; }
    .site-footer { padding: 8px 10px; font-size: 11px; }
    .footer-dot { margin: 0 4px; }
    /* 手机端预览弹窗全屏 */
    .preview-panel { width: 98%; height: 95%; max-width: none; border-radius: 12px; }
    .preview-panel-header { padding: 10px 14px; }
    .preview-panel-title { font-size: 14px; }
    .preview-panel-close { padding: 6px 10px; font-size: 16px; }
}

/* ========== 新增样式 v13 ========== */

/* 旋转加载动画 */
.loading-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #6366f1;
    font-size: 14px;
}
.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(99,102,241,0.2);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 小号旋转（代码块生成中） */
.spinner-small {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(99,102,241,0.2);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}
.code-generating-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #6366f1;
    font-weight: 600;
}

/* 流式闪烁光标 */
.streaming-cursor {
    display: inline;
    animation: cursor-blink 1s step-end infinite;
    color: #6366f1;
    font-weight: 300;
}
@keyframes cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* 代码块生成中状态 */
.code-block.generating {
    border-color: rgba(99,102,241,0.3);
}
.code-block.generating .code-header {
    background: linear-gradient(135deg, #f5f3ff, #e0e7ff);
}

/* 停止按钮样式 */
.chat-stop-btn {
    background: linear-gradient(135deg, #ef4444, #dc2626) !important;
}
.chat-stop-btn:hover {
    box-shadow: 0 4px 16px rgba(239,68,68,0.4) !important;
}
.stop-icon {
    font-size: 18px;
    line-height: 1;
}

/* 生成中断提示 */
.msg-interrupted {
    color: #ef4444;
    font-size: 12px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed rgba(239,68,68,0.3);
}
