/* static/css/style.css */

/* === 1. 全局工具与基础设置 === */
[v-cloak] {
    display: none !important;
}

.z-30 {
    z-index: 30;
}

.z-20 {
    z-index: 20;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.015em;
}

/* === 2. 滚动条美化 === */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* === 3. 动画关键帧 === */
.animate-fade-in-up {
    animation: fadeInUp 0.5s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes zoomIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* === 4. UI 组件样式 (模态框、背景、输入预览) === */
.settings-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.settings-modal {
    background: white;
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: zoomIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.bg-grid-pattern {
    background-color: transparent;
    background-image: radial-gradient(#e5e7eb 1px, transparent 1px);
    background-size: 24px 24px;
}

.dark .bg-grid-pattern {
    background-image: radial-gradient(#374151 1px, transparent 1px);
}

.input-preview-item {
    position: relative;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
    background: #f9fafb;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 3rem;
    min-width: 3rem;
}

.dark .input-preview-item {
    border-color: #4b5563;
    background: #374151;
}

textarea {
    min-height: 24px;
    max-height: 200px;
}

/* === 5. 聊天气泡特定内容 (媒体、DeepThink) === */
.chat-image-preview {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    margin: 4px 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
    object-fit: cover;
    display: block;
}

/* 用户消息气泡中的图片样式 */
.user-message-bubble img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    margin: 4px 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: block;
}

.user-message-bubble .my-2 {
    margin: 4px 0;
}

.user-message-bubble p {
    margin: 0;
    white-space: pre-wrap;
}

/* 媒体容器 */
.media-container {
    margin: 10px 0;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

.media-container video,
.chat-video-player {
    width: 100%;
    max-height: 400px;
    display: block;
}

.chat-audio-player {
    width: 100%;
    min-width: 240px;
    height: 40px;
    margin: 8px 0;
    border-radius: 20px;
    outline: none;
}

/* 深度思考 (Thinking Block) */
details.think-block {
    background-color: rgba(241, 245, 249, 0.5);
    border-left: 3px solid #94a3b8;
    margin: 8px 0;
    border-radius: 4px;
    font-size: 0.9em;
    overflow: hidden;
}

.dark details.think-block {
    background-color: rgba(30, 41, 59, 0.5);
    border-left-color: #475569;
}

details.think-block summary {
    padding: 6px 10px;
    background-color: rgba(0, 0, 0, 0.03);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85em;
    color: #64748b;
    user-select: none;
}

.dark details.think-block summary {
    color: #94a3b8;
    background-color: rgba(255, 255, 255, 0.03);
}

details.think-block div.content {
    padding: 10px;
    white-space: pre-wrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: #475569;
    font-size: 0.9em;
    line-height: 1.5;
}

.dark details.think-block div.content {
    color: #cbd5e1;
}

/* === 6. 文件卡片 (DeepSeek 风格) === */
.ds-file-card {
    display: flex;
    align-items: center;
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 10px 14px;
    margin-right: 10px;
    min-width: 200px;
    max-width: 260px;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: all 0.2s;
}

.dark .ds-file-card {
    background-color: #2c2e33;
    border-color: #373a40;
}

.ds-file-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 4px 6px rgba(59, 130, 246, 0.1);
}

.ds-file-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background-color: #eff6ff;
    color: #3b82f6;
    font-size: 18px;
    margin-right: 12px;
    flex-shrink: 0;
}

.dark .ds-file-icon {
    background-color: rgba(59, 130, 246, 0.15);
}

.ds-file-info {
    flex: 1;
    overflow: hidden;
}

.ds-file-name {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.dark .ds-file-name {
    color: #e5e7eb;
}

.ds-file-size {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 1px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.ds-file-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.ds-file-card:hover .ds-file-remove {
    opacity: 1;
}

/* === 7. Markdown 正文排版 === */
.markdown-body {
    font-size: 15px;
    line-height: 1.75;
    color: #374151;
}

.dark .markdown-body {
    color: #d1d5db;
}

/* 标题 */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    font-weight: 700;
    color: #111827;
    margin-top: 1.5em;
    margin-bottom: 0.6em;
    line-height: 1.3;
}

.dark .markdown-body h1,
.dark .markdown-body h2,
.dark .markdown-body h3,
.dark .markdown-body h4 {
    color: #f3f4f6;
}

.markdown-body h1 {
    font-size: 1.6em;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 0.3em;
}

.markdown-body h2 {
    font-size: 1.4em;
}

.markdown-body h3 {
    font-size: 1.25em;
}

.markdown-body h4 {
    font-size: 1.1em;
}

/* 基础元素 */
.markdown-body p {
    margin-bottom: 1.2em;
}

.markdown-body p:last-child {
    margin-bottom: 0;
}

.markdown-body hr {
    height: 1px;
    border: none;
    background-color: #e5e7eb;
    margin: 2.5em 0;
}

.dark .markdown-body hr {
    background-color: #374151;
}

.markdown-body ul {
    list-style-type: disc;
    padding-left: 1.5em;
    margin-bottom: 1.2em;
}

.markdown-body ol {
    list-style-type: decimal;
    padding-left: 1.5em;
    margin-bottom: 1.2em;
}

.markdown-body li {
    margin-bottom: 0.4em;
}

/* 链接与引用 */
.markdown-body a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
    word-break: break-all;
}

.markdown-body a:hover {
    text-decoration: underline;
}

.dark .markdown-body a {
    color: #60a5fa;
}

.markdown-body blockquote {
    border-left: 4px solid #3b82f6;
    background-color: #f9fafb;
    padding: 0.5em 1em;
    margin: 1.5em 0;
    color: #555;
    font-style: italic;
    border-radius: 0 4px 4px 0;
}

.dark .markdown-body blockquote {
    background-color: #1f2937;
    border-left-color: #60a5fa;
    color: #9ca3af;
}

.markdown-body img,
.markdown-body video {
    max-width: 100%;
    border-radius: 8px;
    margin: 1.2em 0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.markdown-body audio {
    width: 100%;
    min-width: 200px;
    outline: none;
}

/* 表格 */
.markdown-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 1.2em 0;
    overflow-x: auto;
    display: block;
}

.markdown-body th,
.markdown-body td {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
}

.markdown-body th {
    font-weight: 600;
    background-color: #f3f4f6;
    text-align: left;
}

.markdown-body tr:nth-child(2n) {
    background-color: #f9fafb;
}

.dark .markdown-body th,
.dark .markdown-body td {
    border-color: #374151;
}

.dark .markdown-body th {
    background-color: #1f2937;
    color: #e5e5e5;
}

.dark .markdown-body tr:nth-child(2n) {
    background-color: #1a1b1e;
}

/* === 8. 代码块与高亮 === */
.markdown-body pre {
    background: #f3f4f6;
    padding: 12px 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1.2em 0;
    font-size: 0.9em;
    line-height: 1.5;
    border: 1px solid #e5e7eb;
    text-align: left;
    direction: ltr;
}

.dark .markdown-body pre {
    background: #1e1e1e !important;
    border-color: #333;
    color: #e5e5e5;
}

.markdown-body code {
    background: #f1f5f9;
    color: #ea580c;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.9em;
}

.dark .markdown-body code {
    background: transparent;
    color: #e5e5e5;
}

/* 复制代码按钮容器 */
.code-block-wrapper {
    position: relative;
    margin: 1.2em 0;
    max-width: 100%;  /* [新增] 限制最大宽度 */
    min-width: 0;     /* [新增] 防止 Flexbox 子元素溢出 */
    overflow: hidden; /* [修复] 防止内容溢出气泡 */
}

.code-block-wrapper pre {
    margin: 0 !important;
    padding-top: 35px !important;
    overflow-x: auto; /* [修复] 让 pre 内部滚动，而不是撑开 wrapper */
}

/* [新增] 代码操作按钮容器 */
.code-actions {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 6px;
    /* [修复] 确保按钮不会溢出 */
    max-width: calc(100% - 80px); /* 给语言标签留空间 */
}

.copy-code-btn,
.run-code-btn {
    padding: 4px 8px;
    font-size: 12px;
    color: #6b7280;
    background-color: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.copy-code-btn:hover {
    background-color: white;
    color: #2563eb;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* [新增] 运行按钮样式 */
.run-code-btn {
    color: #059669;
    background-color: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
}

.run-code-btn:hover {
    background-color: #10b981;
    color: white;
    border-color: #10b981;
    box-shadow: 0 1px 4px rgba(16, 185, 129, 0.3);
}

.dark .copy-code-btn,
.dark .run-code-btn {
    color: #9ca3af;
    background-color: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

.dark .copy-code-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #60a5fa;
}

.dark .run-code-btn {
    color: #34d399;
    background-color: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.2);
}

.dark .run-code-btn:hover {
    background-color: #10b981;
    color: white;
}

.code-lang-label {
    position: absolute;
    top: 8px;
    left: 12px;
    font-size: 11px;
    color: #9ca3af;
    font-family: monospace;
    pointer-events: none;
    font-weight: bold;
    text-transform: uppercase;
}

/* Highlight.js 暗黑模式微调 */
html.dark .hljs-keyword,
html.dark .hljs-selector-tag,
html.dark .hljs-literal,
html.dark .hljs-section,
html.dark .hljs-link {
    color: #569cd6 !important;
}

html.dark .hljs-string,
html.dark .hljs-title,
html.dark .hljs-name,
html.dark .hljs-type,
html.dark .hljs-attribute,
html.dark .hljs-symbol,
html.dark .hljs-bullet,
html.dark .hljs-addition,
html.dark .hljs-variable,
html.dark .hljs-template-tag,
html.dark .hljs-template-variable {
    color: #ce9178 !important;
}

html.dark .hljs-comment,
html.dark .hljs-quote,
html.dark .hljs-meta {
    color: #6a9955 !important;
}

/* 瀑布流布局 */
.masonry-columns {
    column-count: 1;
    column-gap: 1.5rem;
}

@media (min-width: 768px) {
    .masonry-columns {
        column-count: 2;
    }
}

@media (min-width: 1024px) {
    .masonry-columns {
        column-count: 3;
    }
}

.break-inside-avoid {
    break-inside: avoid-column;
    page-break-inside: avoid;
}

/* === [修复] 移动端代码块溢出问题 === */
@media (max-width: 768px) {
    /* 强制限制 Markdown 内部容器的最大宽度 */
    .markdown-body {
        max-width: 100%;
        overflow-x: hidden; /* 防止文字本身撑开 */
    }

    /* 核心修复：强制限制代码块外层容器的宽度 */
    /* calc(100vw - 100px) 是为了减去头像(约40px)、内边距和气泡间隙 */
    .code-block-wrapper {
        max-width: calc(100vw - 100px) !important;
        display: block; /* 确保它独占一行，不被 inline 属性影响 */
    }

    /* 确保 pre 标签出现滚动条而不是撑开 */
    .markdown-body pre {
        max-width: 100% !important;
        white-space: pre; /* 保持代码不换行 */
        overflow-x: auto !important; /* 强制显示横向滚动条 */
        display: block;
    }
    
    /* 修复表格在移动端撑开的问题 */
    .markdown-body table {
        display: block;
        width: 100%;
        overflow-x: auto;
        max-width: calc(100vw - 100px) !important;
    }
}