:root {
    --sidebar-w: 280px;
    --sidebar-collapsed-w: 70px;
    --muted-bg: #f8f9fa;
    --border: rgba(0, 0, 0, .08);
    --secondary: #212529;
    --primary: #0d6efd;
    --success: #46b450;
    --danger: #dc3232;
}

[data-theme-color="blue"] { --primary: #0d6efd; }
[data-theme-color="green"] { --primary: #198754; --success: #20c997; }
[data-theme-color="purple"] { --primary: #6f42c1; }

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    max-width: 100%;
}

html {
    overflow-x: hidden;
    width: 100%;
}

body {
    background: #fff;
    overflow: hidden;
    overflow-x: hidden;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    max-width: 100vw;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* 允许特定元素水平滚动 */
.chat-container,
.sidebar-content,
.settings-panel-body,
.file-content-preview,
pre {
    max-width: none;
}


/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    border-right: 1px solid var(--border);
    background: #fff;
    height: 100vh;
    height: 100dvh;
    position: fixed;
    left: 0;
    top: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-w);
}

.sidebar.collapsed .brand-icon-expanded {
    display: none;
}

.sidebar.collapsed .brand-text-label {
    display: none;
}

.sidebar.collapsed .brand-text {
    width: auto;
    opacity: 1;
    overflow: visible;
    justify-content: center;
}

.sidebar.collapsed .brand-text .webheaderimg {
    margin: 0;
}

.sidebar.collapsed .brand {
    justify-content: center;
}

.sidebar.collapsed .nav-text,
.sidebar.collapsed .chat-item .title,
.sidebar.collapsed .section-title,
.sidebar.collapsed .chat-item-actions {
    opacity: 0;
    width: 0;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar.collapsed .btn-new-chat span {
    display: none;
}

.sidebar.collapsed .btn-new-chat {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
}

.sidebar .brand {
    height: 56px;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.brand-text {
    transition: all 0.3s ease;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .2);
    border-radius: 3px;
}

.section-title {
    transition: all 0.3s ease;
    padding-left: 0.55rem;
}

.nav-soft .nav-link {
    color: #212529;
    border-radius: .6rem;
    padding: .55rem .75rem;
    display: flex;
    gap: .6rem;
    align-items: center;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.nav-soft .nav-link:hover {
    background: var(--muted-bg);
}

.nav-soft .nav-link.active {
    background: rgba(13, 110, 253, .08);
    color: var(--primary);
    font-weight: 600;
}

.nav-soft .nav-link i {
    flex-shrink: 0;
}

.nav-text {
    transition: all 0.3s ease;
}

/* 聊天项布局 */
.chat-item {
    border-radius: .6rem;
    padding: 0.7rem 0.55rem;
    display: flex;
    align-items: center;
    gap: .6rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.chat-item:hover {
    background: var(--muted-bg);
}

.chat-item.active {
    background: rgba(13, 110, 253, .08);
}

.chat-item:hover .chat-item-actions {
    opacity: 1;
}

.chat-item i {
    flex-shrink: 0;
}

.chat-drag-handle {
    cursor: grab;
    padding: 0 .2rem;
    color: #adb5bd;
    flex-shrink: 0;
    touch-action: none;
}

.sidebar.collapsed .chat-drag-handle {
    display: none !important;
}

.chat-item-icon-collapsed {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 .2rem;
    color: #adb5bd;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}

.sidebar.collapsed .chat-item-icon-collapsed {
    display: flex;
}

/* 折叠时在 sidebar 右侧对应聊天位置显示的标题气泡（单一元素，由 JS 定位） */
.sidebar-title-bubble {
    position: absolute;
    left: 100%;
    margin-left: 8px;
    padding: 4px 12px;
    font-size: 0.8rem;
    white-space: nowrap;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    color:#fff;
    background: #151c26;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
    z-index: 1001;
    pointer-events: none;
    transform: translateY(-50%);
    display: none;
    transition: opacity 0.08s ease;
}

.sidebar:not(.collapsed) .sidebar-title-bubble {
    display: none !important;
}

.sidebar-title-bubble.visible {
    display: block;
}

.chat-drag-handle:active {
    cursor: grabbing;
}

.chat-item.chat-item-dragging {
    opacity: 0.6;
}

.chat-item.chat-item-drag-over {
    border-radius: .6rem;
    outline: 2px dashed var(--primary);
    outline-offset: 2px;
}

.chat-item .title {
    flex: 1;
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.3s ease;
}

/* 删除按钮（默认显示） */
.chat-item-actions {
    display: flex;
    gap: .25rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-item:hover .chat-item-actions {
    opacity: 1;
}

.chat-item-actions button {
    border: none;
    background: transparent;
    padding: .25rem;
    cursor: pointer;
    border-radius: .375rem;
    color: #6c757d;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.chat-item-actions button:hover {
    background: rgba(0, 0, 0, .1);
    color: #212529;
}

/* 删除确认按钮（默认隐藏） */
.chat-item-delete-confirm {
    display: none;
    gap: .25rem;
    position: absolute;
    right: .5rem;
    background: white;
    padding: .25rem;
    border-radius: .375rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
    z-index: 10;
}

/* 删除模式下显示确认按钮，隐藏删除图标 */
.chat-item.deleting .chat-item-delete-confirm {
    display: flex;
}

.chat-item.deleting .chat-item-actions {
    display: none;
}

.chat-item-delete-confirm button {
    border: none;
    padding: .35rem .6rem;
    cursor: pointer;
    border-radius: .375rem;
    font-size: .75rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: .3rem;
    font-weight: 500;
}

.chat-item-delete-confirm .confirm-delete {
    background: var(--danger);
    color: white;
}

.chat-item-delete-confirm .confirm-delete:hover {
    background: #c82333;
    transform: scale(1.05);
}

.chat-item-delete-confirm .cancel-delete {
    background: var(--muted-bg);
    color: #495057;
}

.chat-item-delete-confirm .cancel-delete:hover {
    background: #dee2e6;
    color: #212529;
}

/* 删除动画 */
.chat-item.deleting {
    background: rgba(220, 53, 69, 0.05);
    animation: shake 0.3s ease;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.chat-item.fade-out {
    animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(-20px);
        height: 0;
        padding: 0;
        margin: 0;
    }
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-w);
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

.main-content.expanded {
    margin-left: var(--sidebar-collapsed-w);
}

/* Topbar */
.topbar {
    min-height: 56px;
    padding: env(safe-area-inset-top, 0) 1rem 0 1rem;
    border-bottom: 1px solid var(--border);
    background: #fff;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.toggle-sidebar-btn {
    border: none;
    background: transparent;
    padding: .5rem;
    cursor: pointer;
    border-radius: .5rem;
    transition: all 0.2s ease;
    color: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toggle-sidebar-btn:hover {
    background: var(--muted-bg);
}

.chat-title {
    flex: 1;
    font-weight: 500;
    font-size: .95rem;
    color: #212529;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Chat Area */
.chat-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

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

.chat-container::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .15);
    border-radius: 3px;
}

.chat-messages {
    width: 100%;
    max-width: 720px;
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    transition: all 0.5s ease;
}

.welcome-screen.hidden {
    display: none;
}

.logo-circle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(255, 193, 7, .25);
    display: grid;
    place-items: center;
    font-size: 28px;
    margin-bottom: 1rem;
}

/* Chat Messages */
.chat-message {
    display: flex;
    margin-bottom: 2rem;
    animation: slideIn 0.3s ease;
    gap: .75rem;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-avatar.ai {
    background: rgba(255, 193, 7, .25);
    color: #f59e0b;
}

.chat-avatar.user {
    background: rgba(102, 126, 234, .15);
    color: #667eea;
    margin-top: 0.35rem;
}

.chat-bubble {
    max-width: 98%;
    padding: .75rem 1rem;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.5;
    padding-right: 0.5rem;
}

.chat-bubble.user {
    background: #f8f9fa;
    color: #212529;
    padding-top: .55rem;
}

.chat-bubble.ai {
    background: transparent;
    color: #212529;
    padding-top: .25rem;
    padding-left: 0.55rem;
}

/* Markdown 内容样式 */
.chat-bubble.ai .markdown-content {
    line-height: 1.6;
}

.chat-bubble.ai .markdown-content h1,
.chat-bubble.ai .markdown-content h2,
.chat-bubble.ai .markdown-content h3 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
}

.chat-bubble.ai .markdown-content h1 {
    font-size: 1.5em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.3em;
}

.chat-bubble.ai .markdown-content h2 {
    font-size: 1.3em;
}

.chat-bubble.ai .markdown-content h3 {
    font-size: 1.1em;
}

.chat-bubble.ai .markdown-content p {
    margin-bottom: 0.8em;
}

.chat-bubble.ai .markdown-content ul,
.chat-bubble.ai .markdown-content ol {
    margin-bottom: 0.8em;
    padding-left: 2em;
}

.chat-bubble.ai .markdown-content li {
    margin-bottom: 0.3em;
}

.chat-bubble.ai .markdown-content code {
    background: #f6f8fa;
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.chat-bubble.ai .markdown-content pre {
    background: #f6f8fa;
    border-radius: 6px;
    padding: 2.5em 1em 1em 1em;
    overflow-x: auto;
    margin: 1em 0;
    position: relative;
}

.chat-bubble.ai .markdown-content pre code {
    background: transparent;
    padding: 0;
    font-size: 0.875em;
    line-height: 1.5;
}

.chat-bubble.ai .markdown-content blockquote {
    border-left: 3px solid var(--border);
    padding-left: 1em;
    margin: 1em 0;
    color: #6c757d;
}

.chat-bubble.ai .markdown-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

.chat-bubble.ai .markdown-content table th,
.chat-bubble.ai .markdown-content table td {
    border: 1px solid var(--border);
    padding: 0.5em;
}

.chat-bubble.ai .markdown-content table th {
    background: var(--muted-bg);
    font-weight: 600;
}

.chat-bubble.ai .markdown-content a {
    color: var(--primary);
    text-decoration: none;
}

.chat-bubble.ai .markdown-content a:hover {
    text-decoration: underline;
}

.chat-bubble.ai .markdown-content img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 0.5em 0;
}

/* 代码块包装器 */
.code-block-wrapper {
    position: relative;
    margin: 1em 0;
}

/* 代码语言标签 */
.code-language {
    position: absolute;
    top: 0.5em;
    left: 0.5em;
    background: rgba(0, 0, 0, 0.1);
    padding: 0.2em 0.5em;
    border-radius: 3px;
    font-size: 0.75em;
    color: #6c757d;
    text-transform: uppercase;
    z-index: 1;
}

/* 代码复制按钮 */
.code-copy-btn {
    position: absolute;
    top: 0.5em;
    right: 0.5em;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.4em 0.8em;
    font-size: 0.8em;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.4em;
    z-index: 2;
    color: #6c757d;
}

.code-block-wrapper:hover .code-copy-btn {
    opacity: 1;
}

.code-copy-btn:hover {
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    color: #212529;
}

.code-copy-btn:active {
    transform: scale(0.95);
}

.code-copy-btn.copied {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.code-copy-btn i {
    font-size: 1em;
}

.code-copy-btn span {
    font-size: 0.9em;
}

/* 数学公式样式 */
.chat-bubble.ai .markdown-content mjx-container {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
}

.chat-bubble.ai .markdown-content mjx-container[display="true"] {
    display: block;
    text-align: center;
    margin: 1em 0;
}

.chat-bubble.ai .markdown-content mjx-container[jax="CHTML"][display="false"] {
    display: inline-block;
    vertical-align: middle;
}

/* File Attachment */
.file-attachment {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    background: var(--muted-bg);
    border-radius: .5rem;
    margin-top: .5rem;
    font-size: .875rem;
}

.file-attachment .file-icon {
    width: 32px;
    height: 32px;
    background: white;
    border-radius: .375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}

.file-attachment .file-info {
    flex: 1;
}

.file-attachment .file-name {
    font-weight: 500;
    display: block;
}

.file-attachment .file-size {
    font-size: .75rem;
    color: #6c757d;
}

/* Message Actions 优化 */
.message-actions {
    display: flex;
    gap: .5rem;
    margin-top: .75rem;
    padding-left: 0.45rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    flex-wrap: wrap;
}

.chat-message:hover .message-actions {
    opacity: 1;
}

.message-actions button {
    border: 1px solid var(--border);
    ;
    background: white;
    padding: .35rem .65rem;
    cursor: pointer;
    border-radius: .35rem;
    color: #6c757d;
    font-size: .85rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: .4rem;
}

.message-actions button:hover:not(:disabled) {
    background: var(--muted-bg);
    color: var(--secondary);
    border-color: #adb5bd;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, .1);
}

.message-actions button:active:not(:disabled) {
    transform: translateY(0);
}

.message-actions button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.message-actions button i {
    font-size: 1em;
}

.message-actions button.copied {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.message-actions button.liked {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.message-actions button.disliked {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.message-actions button.retrying i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* 消息时间戳与模型名 */
.message-meta {
    font-size: 0.75rem;
    color: #6c757d;
    margin-top: 0.5rem;
    padding-left: 0.45rem;
    display: block;
}
.message-meta .message-timestamp {
    margin: 0;
    padding: 0;
    display: inline;
}
.message-meta .message-model {
    display: inline;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: .5rem 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #adb5bd;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.7;
    }

    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* Input Area */
.input-area {
    /* border-top: 1px solid var(--border); */
    background: #fff;
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
    flex-shrink: 0;
}

.input-container {
    max-width: 720px;
    margin: 0 auto;
}

.prompt-shell {
    border: 2px solid var(--border);
    border-radius: 12px;
    background: #fff;
    padding: .35rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .04);
    transition: all 0.3s ease;
}

.prompt-shell:focus-within {
    box-shadow: 0 4px 16px rgba(0, 0, 0, .08);
    border-color: rgba(13, 110, 253, .39);
}

.prompt-shell textarea {
    border: 0;
    outline: none;
    resize: none;
    box-shadow: none;
    padding: .55rem .65rem;
    max-height: 200px;
    width: 100%;
    font-size: .95rem;
    line-height: 1.5;
}

.prompt-shell textarea:focus {
    border: 0;
    outline: none;
    resize: none;
    box-shadow: none;
}

.current-role-indicator {
    min-height: 1.25rem;
    padding-left: 0.6rem;
    line-height: 1.25;
    color: var(--bs-secondary, #6c757d);
}

.prompt-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .25rem;
}

.input-actions {
    display: flex;
    gap: .5rem;
    align-items: center;
}

.input-actions button {
    border: none;
    background: transparent;
    padding: .5rem;
    border-radius: .5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #6c757d;
}

.input-actions button:hover:not(:disabled) {
    background: var(--muted-bg);
    color: #212529;
}

.input-actions button.send-btn {
    background: var(--primary);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.input-actions button.send-btn:hover:not(:disabled) {
    background: #0b5ed7;
}

.input-actions button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#voiceBtn.recording {
    background: var(--danger);
    color: white;
    animation: voice-pulse 1s ease-in-out infinite;
}

@keyframes voice-pulse {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(220, 53, 69, .4);
    }

    50% {
        opacity: .95;
        box-shadow: 0 0 0 8px rgba(220, 53, 69, 0);
    }
}

.voice-mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .75rem;
    color: #6c757d;
    cursor: pointer;
    user-select: none;
}

.voice-mode-toggle input {
    margin: 0;
}

.voice-mode-toggle:hover {
    color: #212529;
}

.input-hint {
    text-align: center;
    font-size: .75rem;
    color: #6c757d;
    margin-top: .5rem;
}

/* File Upload Area */
.file-upload-area {
    display: none;
    padding: .5rem;
    border-top: 1px solid var(--border);
}

.file-upload-area.active {
    display: block;
}

.uploaded-files {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.uploaded-file {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    background: var(--muted-bg);
    border-radius: .5rem;
    font-size: .875rem;
    position: relative;
}

.uploaded-file .remove-file {
    background: none;
    border: none;
    color: #6c757d;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
}

.uploaded-file .remove-file:hover {
    color: var(--danger);
}

/* 图片预览 */
.uploaded-file.image {
    flex-direction: column;
    align-items: flex-start;
    max-width: 200px;
}

.uploaded-file.image .image-preview {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: .375rem;
    margin-bottom: .5rem;
}

.uploaded-file.image .file-info {
    width: 100%;
}

.message-image {
    max-width: 300px;
    border-radius: .5rem;
    margin-top: .5rem;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.message-image:hover {
    transform: scale(1.02);
}

/* 文件分析状态 */
.file-analyzing {
    opacity: 0.7;
}

.analyzing-badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .25rem .5rem;
    background: rgba(13, 110, 253, 0.1);
    color: var(--primary);
    border-radius: .375rem;
    font-size: .75rem;
    margin-left: .5rem;
}

.analyzing-badge i {
    animation: spin 1s linear infinite;
}

.file-analyzing-progress {
    width: 100%;
    height: 3px;
    background: #e9ecef;
    border-radius: 2px;
    overflow: hidden;
    margin-top: .5rem;
}

.file-analyzing-progress-bar {
    height: 100%;
    background: var(--primary);
    animation: progress 2s ease-in-out infinite;
}

@keyframes progress {
    0% {
        width: 0%;
        margin-left: 0%;
    }

    50% {
        width: 50%;
        margin-left: 25%;
    }

    100% {
        width: 0%;
        margin-left: 100%;
    }
}

/* 文件内容预览 */
.file-content-preview {
    background: var(--muted-bg);
    border-radius: .5rem;
    padding: .75rem;
    margin-top: .5rem;
    max-height: 75px;
    overflow-y: auto;
    font-size: .875rem;
    font-family: 'Consolas', 'Monaco', monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.file-content-preview::-webkit-scrollbar {
    width: 4px;
}

.file-content-preview::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .2);
    border-radius: 2px;
}

.file-stats {
    display: flex;
    gap: .75rem;
    margin-top: .5rem;
    font-size: .75rem;
    color: #6c757d;
    flex-wrap: wrap;
}

.file-stats span {
    display: flex;
    align-items: center;
    gap: .25rem;
}

/* 图片查看器 */
.image-viewer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.image-viewer.active {
    display: flex;
}

.image-viewer img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

.image-viewer .close-viewer {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    right: -400px;
    top: 0;
    width: 400px;
    height: 100vh;
    background: white;
    box-shadow: -2px 0 8px rgba(0, 0, 0, .1);
    transition: right 0.3s ease;
    z-index: 1001;
    overflow-y: auto;
}

.settings-panel.active {
    right: 0;
}

.settings-panel-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
}

.settings-panel-body {
    padding: 1rem;
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group label {
    display: block;
    font-weight: 500;
    margin-bottom: .5rem;
    font-size: .9rem;
}

.setting-group .form-text {
    font-size: .8rem;
    color: #6c757d;
    margin-top: .25rem;
}

.range-value {
    display: inline-block;
    min-width: 50px;
    text-align: right;
    font-weight: 500;
    color: var(--primary);
}

/* 流式输出光标动画 */
.markdown-content.streaming::after {
    content: '▋';
    animation: blink 1s infinite;
    margin-left: 2px;
}

@keyframes blink {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: #6c757d;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
}

/* Mobile */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0 !important;
    }

    .settings-panel {
        width: 100%;
        right: -100%;
    }
}

.message-actions .delete-btn:hover:not(:disabled) {
    color: var(--danger);
    border-color: var(--danger);
}

.message-actions .read-aloud-btn:hover:not(:disabled) {
    color: var(--primary);
    border-color: var(--primary);
}

.message-actions button.reading {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.message-actions button.reading i {
    animation: spin 1s linear infinite;
}

.message-actions .retry-btn {
    animation: fadeIn 0.3s ease;
}

.message-actions .retry-btn:hover:not(:disabled) {
    color: var(--secondary);
    border-color: var(--secondary);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0 !important;
    }

    .settings-panel {
        width: 100%;
        right: -100%;
    }

    .settings-panel.active {
        right: 0;
    }

    .settings-overlay.active {
        display: block;
    }
}

/* 空对话样式 */
.chat-item.empty-chat {
    opacity: 0.7;
}

.chat-item.empty-chat .title {
    color: #6c757d;
}

.chat-item.empty-chat:hover {
    opacity: 1;
}

.chat-item-actions button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.chat-item-actions button:disabled:hover {
    background: transparent;
    color: #6c757d;
}

/* 最后一个p标签和第一个p标签的margin-bottom和margin-top为0 */
.markdown-content>*:last-child {
    margin-bottom: 0 !important;
}

.markdown-content>*:first-child {
    margin-top: 0 !important;
}

/* 设置面板 - 支持的文件类型说明 */
.setting-file-types-desc {
    font-size: 0.85rem;
    line-height: 1.8;
}

/* 文件内容弹窗正文 */
.file-content-modal-body {
    white-space: pre-wrap;
    font-family: Consolas, monospace;
    font-size: 0.9rem;
}

/* ========== 移动端：隐藏头像、防缩放 ========== */
@media (max-width: 768px) {
    .chat-avatar {
        display: none !important;
    }

    .chat-message .chat-bubble {
        max-width: 95%;
    }

    /* 输入框至少 16px 避免 iOS 自动缩放 */
    .prompt-shell textarea,
    .form-control#userInput {
        font-size: 16px !important;
    }
}

/* 移动端：考虑浏览器地址栏/操作栏，使用 dvh 与安全区 */
@supports (height: 100dvh) {
    body {
        min-height: 100dvh;
        min-height: -webkit-fill-available;
    }

    .main-content {
        min-height: 100dvh;
        min-height: -webkit-fill-available;
    }
}

/* ========== 暗黑模式 ========== */
[data-theme="dark"] {
    --muted-bg: #1e1e1e;
    --secondary: #6c757d;
    --border: rgba(255, 255, 255, .1);
    --primary: #58a6ff;
    --success: #3fb950;
    --danger: #f85149;
}

[data-theme="dark"] body {
    background: #0d1117;
    color: #e6edf3;
}

[data-theme="dark"] .sidebar {
    background: #161b22;
    border-right-color: var(--border);
}

[data-theme="dark"] .main-content,
[data-theme="dark"] .topbar {
    background: #0d1117;
    border-color: var(--border);
}

[data-theme="dark"] .chat-title {
    color: #e6edf3;
}

[data-theme="dark"] .chat-bubble.user {
    background: #21262d;
    color: #e6edf3;
}

[data-theme="dark"] .chat-bubble.ai {
    color: #e6edf3;
}

[data-theme="dark"] .chat-container {
    background: #0d1117;
}

[data-theme="dark"] .input-area {
    background: #161b22;
    border-color: var(--border);
}

[data-theme="dark"] .prompt-shell {
    background: #21262d;
    border-color: var(--border);
}

[data-theme="dark"] .prompt-shell textarea {
    background: transparent;
    color: #e6edf3;
}

[data-theme="dark"] .welcome-screen .logo-circle {
    background: #21262d;
    color: #e6edf3;
}

[data-theme="dark"] .welcome-screen h4,
[data-theme="dark"] .welcome-screen p {
    color: #e6edf3;
}

[data-theme="dark"] .chat-item:hover,
[data-theme="dark"] .chat-item.active {
    background: rgba(255, 255, 255, .06);
}

[data-theme="dark"] .chat-item .title {
    color: #e6edf3;
}

[data-theme="dark"] .settings-panel {
    background: #161b22;
}

[data-theme="dark"] .settings-panel-header {
    background: #161b22;
    border-color: var(--border);
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
    background: #21262d;
    border-color: var(--border);
    color: #e6edf3;
}

[data-theme="dark"] .markdown-content code {
    background: #343a40 !important;
}

/* 思考过程单独展示 */
.thinking-block {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--muted-bg);
}
.thinking-block .thinking-summary {
    cursor: pointer;
    padding: 6px 10px;
    font-size: 0.9rem;
    list-style: none;
    user-select: none;
}
.thinking-block .thinking-summary::-webkit-details-marker { display: none; }
.thinking-block .thinking-content {
    padding: 10px 12px;
    font-size: 0.85rem;
    max-height: 280px;
    overflow-y: auto;
}
.thinking-block .thinking-content p { margin-bottom: 0.5rem; }

/* 多版本回复切换 */
.version-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.version-switcher .version-tab {
    font-size: 0.75rem;
}

.current-model-indicator{
    min-width: 85px;
}

[data-theme="dark"] .toast-container .toast {
    background: #21262d !important;
    border: 1px solid var(--border);
}

/* 暗黑模式：保证文字可见 */
[data-theme="dark"] .text-secondary,
[data-theme="dark"] .text-muted,
[data-theme="dark"] .small,
[data-theme="dark"] .form-text,
[data-theme="dark"] .description,
[data-theme="dark"] label,
[data-theme="dark"] .bi,
[data-theme="dark"] .nav-text,
[data-theme="dark"] .chat-drag-handle {
    color: #8b949e !important;
}

[data-theme="dark"] .chat-item-icon-collapsed {
    color: #8b949e;
}

[data-theme="dark"] .sidebar-title-bubble {
    background: #21262d;
    border-color: #30363d;
    color: #e6edf3;
}

[data-theme="dark"] .toast-body {
    color: #e6edf3 !important;
}

[data-theme="dark"] .badge.bg-secondary {
    background: #30363d !important;
    color: #e6edf3 !important;
}

/* 暗黑模式：Highlight.js pre/code 兼容 */
[data-theme="dark"] .markdown-content pre,
[data-theme="dark"] .markdown-content pre code,
[data-theme="dark"] .hljs {
    background: #161b22 !important;
    color: #e6edf3 !important;
    /* border: 1px solid var(--border); */
}

[data-theme="dark"] .hljs-keyword,
[data-theme="dark"] .hljs-selector-tag,
[data-theme="dark"] .hljs-built_in { color: #ff7b72; }

[data-theme="dark"] .hljs-string,
[data-theme="dark"] .hljs-attr { color: #a5d6ff; }

[data-theme="dark"] .hljs-number,
[data-theme="dark"] .hljs-literal { color: #79c0ff; }

[data-theme="dark"] .hljs-comment,
[data-theme="dark"] .hljs-doctag { color: #8b949e; }

[data-theme="dark"] .hljs-title,
[data-theme="dark"] .hljs-section { color: #d2a8ff; }

[data-theme="dark"] .hljs-function .hljs-title { color: #d2a8ff; }

[data-theme="dark"] .hljs-params { color: #e6edf3; }

[data-theme="dark"] .hljs-meta { color: #8b949e; }