/* ========== AI Chat 页面样式 ========== */
:root {
    --ai-pri: #1D5BFF;
    --ai-pri-l: #4C86FF;
    --ai-pri-d: #0E4BC9;
    --ai-pri-h: #4C86FF;
    --ai-pri-bg: rgba(29, 91, 255, 0.08);
    --ai-pri-glow: rgba(29, 91, 255, 0.2);
    --ai-user-bg: linear-gradient(135deg, #1D5BFF 0%, #00c7ff 100%);
    --ai-user-text: #ffffff;
    --ai-bot-bg: #ffffff;
    --ai-bot-text: #1c1c1e;
    --ai-sidebar-bg: #f2f2f7;
    --ai-sidebar-border: #e5e5ea;
    --ai-header-bg: rgba(255, 255, 255, 0.85);
    --ai-input-bg: #ffffff;
    --ai-card-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.05);
    --ai-card-shadow-hover: 0 2px 6px rgba(0, 0, 0, 0.04), 0 10px 24px -8px rgba(29, 91, 255, 0.18);
}

/* ========== 错误信息气泡 ========== */
.ai-error-bubble {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: 14px;
    line-height: 1.5;
}

.dark-mode .ai-error-bubble {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}


.dark-mode {
    --ai-pri: #818cf8;
    --ai-pri-l: #a5b4fc;
    --ai-pri-d: #6366f1;
    --ai-pri-h: #a5b4fc;
    --ai-pri-bg: rgba(99, 102, 241, 0.15);
    --ai-pri-glow: rgba(99, 102, 241, 0.25);
    --ai-user-bg: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --ai-user-text: #ffffff;
    --ai-bot-bg: #1e293b;
    --ai-bot-text: #f1f5f9;
    --ai-sidebar-bg: #0f172a;
    --ai-sidebar-border: #1e293b;
    --ai-header-bg: rgba(15, 23, 42, 0.85);
    --ai-input-bg: #0f172a;
    --ai-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.4);
    --ai-card-shadow-hover: 0 10px 25px rgba(99, 102, 241, 0.2), 0 4px 10px rgba(0, 0, 0, 0.3);
}

.ai-app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: var(--bg);
}

/* ========== Auth Gate (未登录/无权限门禁) ========== */
.ai-auth-gate {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100vw;
    height: 100vh;
    background: var(--bg);
    padding: 24px;
    box-sizing: border-box;
}
.ai-auth-gate-inner {
    text-align: center;
    max-width: 420px;
    width: 100%;
}
.ai-auth-gate-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: var(--ai-pri-bg);
    color: var(--ai-pri);
    margin-bottom: 24px;
}
.ai-auth-gate-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--t1);
    margin: 0 0 12px;
}
.ai-auth-gate-text {
    font-size: 15px;
    color: var(--t2);
    line-height: 1.6;
    margin: 0 0 32px;
}
.ai-auth-gate-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}
.ai-auth-gate-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    border: none;
    min-width: 200px;
    justify-content: center;
}
.ai-auth-gate-btn-primary {
    background: var(--ai-pri);
    color: #fff;
}
.ai-auth-gate-btn-primary:hover {
    background: var(--ai-pri-d);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--ai-pri-glow);
}
.ai-auth-gate-btn-default {
    background: transparent;
    color: var(--t2);
    border: 1px solid var(--line);
}
.ai-auth-gate-btn-default:hover {
    background: var(--ai-pri-bg);
    color: var(--ai-pri);
}

/* ========== Sidebar ========== */
.ai-sidebar {
    width: 280px;
    min-width: 280px;
    height: 100%;
    background: var(--ai-sidebar-bg);
    border-right: 1px solid var(--ai-sidebar-border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

.ai-sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--ai-sidebar-border);
}

.ai-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 700;
    color: var(--t1);
    margin-bottom: 16px;
}

.ai-sidebar-brand svg {
    color: var(--ai-pri);
}

.ai-new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 9px;
    border: 1px solid var(--ai-pri);
    background: var(--ai-pri-bg);
    color: var(--ai-pri);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-new-chat-btn:hover {
    background: var(--ai-pri);
    color: white;
}

.ai-new-chat-btn:active {
    background: var(--ai-pri-d);
}

.ai-sidebar-section {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
}

.ai-sidebar-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--t3);
    margin-bottom: 8px;
    padding: 0 8px;
}

.ai-chat-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 32px 16px;
    color: var(--t3);
    font-size: 13px;
    text-align: center;
}

.ai-chat-empty svg {
    opacity: 0.3;
}

.ai-chat-empty p {
    font-weight: 500;
    color: var(--t2);
    margin: 0;
}

.ai-chat-empty small {
    font-size: 11px;
    opacity: 0.7;
}

.ai-chat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    font-size: 13px;
    color: var(--t2);
    position: relative;
}

.ai-chat-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.dark-mode .ai-chat-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.ai-chat-item.active {
    background: var(--ai-pri-bg);
    color: var(--ai-pri);
    font-weight: 500;
}

.ai-chat-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    background: var(--ai-pri);
    border-radius: 0 2px 2px 0;
}

.ai-chat-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Type icons in sidebar chat list */
.ai-chat-item-type-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

/* Streaming badge in sidebar chat list */
.ai-chat-streaming-badge {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ai-pri);
    flex-shrink: 0;
    animation: aiStreamPulse 1.4s infinite;
}

@keyframes aiStreamPulse {
    0%, 100% { opacity: 0.4; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

.ai-chat-item-delete {
    display: flex;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: #94a3b8;
    opacity: 0;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.ai-chat-item:hover .ai-chat-item-delete {
    opacity: 1;
}

.ai-chat-item-delete:hover {
    background: rgba(255, 59, 48, 0.15);
    color: #ff3b30;
    transform: scale(1.1);
}

.ai-chat-item-cancel {
    display: flex;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: none;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    margin-right: 4px;
}

.ai-chat-item-cancel:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #dc2626;
    transform: scale(1.1);
}

.ai-chat-item-rename:hover {
    background: var(--ai-pri-bg) !important;
    color: var(--ai-pri) !important;
}

.ai-sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid var(--ai-sidebar-border);
}

.ai-sidebar-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--t2);
    text-decoration: none;
    font-size: 13px;
    transition: background 0.15s ease, color 0.15s ease;
}

.ai-sidebar-link:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--ai-pri);
}

.dark-mode .ai-sidebar-link:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* ========== Main Area ========== */
.ai-sidebar-overlay {
    display: none;
}

.ai-main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%;
    background: var(--bg);
    position: relative;
}

.ai-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--ai-sidebar-border);
    background: var(--ai-header-bg);
    flex-wrap: wrap;
}

.ai-mobile-menu-btn {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--t2);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-header-info {
    flex: 1;
    min-width: 0;
}

.ai-header-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--t1);
    letter-spacing: -0.2px;
}

.ai-header-sub {
    font-size: 12px;
    color: var(--t3);
    margin-top: 2px;
    font-weight: 400;
}

.ai-header-actions {
    display: flex;
    gap: 4px;
}

/* Header model selector */
.ai-header-model {
    position: relative;
    flex-shrink: 0;
}

.ai-header-model .ai-model-selector {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--ai-sidebar-border);
    background: transparent;
    color: var(--t3);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    white-space: nowrap;
    max-width: 200px;
}

.ai-header-model .ai-model-selector:hover {
    border-color: var(--ai-pri);
    color: var(--ai-pri);
    background: var(--ai-pri-bg);
}

.ai-header-model .ai-model-selector span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-header-model .ai-model-selector svg {
    width: 14px !important;
    height: 14px !important;
    flex-shrink: 0;
}

.ai-header-model .ai-model-selector svg:last-child {
    width: 12px !important;
    height: 12px !important;
    opacity: 0.7;
}

.ai-header-model .ai-model-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: white;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    padding: 6px;
    min-width: 220px;
    z-index: 50;
}

.dark-mode .ai-header-model .ai-model-dropdown {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.ai-header-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--t3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}

.ai-header-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--ai-pri);
}

.dark-mode .ai-header-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* ========== Content Area ========== */
.ai-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}

/* Welcome Screen */
.ai-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    max-width: 680px;
    margin: 0 auto;
    padding: 40px 20px;
    text-align: center;
}

.ai-welcome-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: var(--ai-pri);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.ai-welcome-icon svg {
    color: white;
    width: 28px !important;
    height: 28px !important;
}

.ai-welcome h1 {
    font-size: 22px;
    font-weight: 600;
    color: var(--t1);
    margin-bottom: 6px;
    letter-spacing: -0.2px;
}

.ai-welcome > p {
    font-size: 14px;
    color: var(--t3);
    margin-bottom: 28px;
    line-height: 1.6;
}

.ai-suggestion-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 560px;
}

.ai-suggestion-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--ai-sidebar-border);
    background: var(--ai-bot-bg);
    cursor: pointer;
    transition: all 0.18s ease;
    text-align: left;
    font-size: 13px;
    color: var(--t2);
    line-height: 1.5;
}

.ai-suggestion-card:hover {
    border-color: var(--ai-pri);
    color: var(--t1);
}

.ai-suggestion-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--ai-pri-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ai-pri);
    transition: all 0.18s ease;
}

.ai-suggestion-icon svg,
.ai-suggestion-icon i {
    width: 14px !important;
    height: 14px !important;
}

.ai-suggestion-card:hover .ai-suggestion-icon {
    background: var(--ai-pri);
    color: white;
}

/* ========== Unified Messages Container ========== */
.ai-messages,
.ai-messages-unified {
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding-bottom: 24px;
    contain: content;
}

.ai-message {
    display: flex;
    gap: 12px;
    animation: aiMsgIn 0.25s ease;
    position: relative;
    align-items: flex-start;
    contain: layout style;
}

.ai-message:hover .ai-msg-timestamp {
    opacity: 1;
}

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

.ai-message.user {
    justify-content: flex-end;
}

.ai-msg-bubble-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.ai-msg-bubble {
    font-size: 15px;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
    overflow-wrap: anywhere;
}

/* Paragraph typography */
.ai-msg-bubble p {
    text-wrap: pretty;
}

/* Headings typography */
.ai-msg-bubble h1,
.ai-msg-bubble h2,
.ai-msg-bubble h3,
.ai-msg-bubble h4,
.ai-msg-bubble h5,
.ai-msg-bubble h6 {
    text-wrap: balance;
    letter-spacing: -0.2px;
}

.ai-message.user .ai-msg-bubble-wrap {
    align-items: flex-end;
    max-width: 85%;
    position: relative;
}

/* User message actions float below bubble without affecting bubble height */
.ai-message.user .ai-msg-actions {
    position: absolute;
    top: calc(100% + 2px);
    right: 0;
    margin-top: 0;
}

.ai-message.user .ai-msg-bubble {
    background: var(--ai-pri-bg);
    color: var(--t1);
    padding: 14px 18px;
    border-radius: 18px 18px 4px 18px;
    max-width: 100%;
    display: inline-block;
    word-break: break-word;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.ai-message.user .ai-msg-action-btn {
    color: var(--t3);
}

.ai-message.user .ai-msg-action-btn:hover {
    background: var(--ai-pri-bg);
    color: var(--ai-pri);
}

.ai-message.user .ai-msg-timestamp {
    color: var(--t3);
}

.ai-message.assistant .ai-msg-bubble-wrap {
    max-width: 90%;
}

/* 生成内容（图片/视频）允许更宽的展示区域 */
.ai-message.assistant:has(.ai-image-grid) .ai-msg-bubble-wrap,
.ai-message.assistant:has(.ai-video-placeholder) .ai-msg-bubble-wrap,
.ai-message.assistant:has(.ai-video-player) .ai-msg-bubble-wrap {
    max-width: 100%;
}

.ai-message.assistant .ai-msg-bubble {
    background: var(--ai-assistant-bg, #f8fafc);
    color: var(--ai-assistant-text, var(--t1));
    padding: 14px 18px;
    border-radius: 18px 18px 18px 4px;
    max-width: 100%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* 生成内容的气泡减少内边距 */
.ai-message.assistant:has(.ai-image-grid) .ai-msg-bubble,
.ai-message.assistant:has(.ai-video-placeholder) .ai-msg-bubble,
.ai-message.assistant:has(.ai-video-player) .ai-msg-bubble {
    padding: 12px;
}

.dark-mode .ai-message.assistant .ai-msg-bubble {
    background: var(--ai-assistant-bg-dark, #1e293b);
}

.ai-msg-timestamp {
    font-size: 11px;
    color: var(--t3);
    margin-top: 6px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.ai-message.user .ai-msg-timestamp {
    text-align: right;
}

/* ========== Inline Code ========== */
.ai-msg-bubble code {
    font-family: "SF Mono", "Fira Code", "JetBrains Mono", Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.5;
}

.ai-msg-bubble :not(pre) code {
    background: rgba(29, 91, 255, 0.1);
    color: var(--ai-pri-d);
    padding: 2px 7px;
    border-radius: 5px;
    font-size: 12.5px;
    border: 1px solid rgba(29, 91, 255, 0.15);
}

.dark-mode .ai-msg-bubble :not(pre) code {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.2);
    color: var(--ai-pri-l);
}

/* Reset inline-code styles for code inside <pre> / code blocks.
   The :not(pre) selector above matches code inside <pre> too, because
   intermediate <div> wrappers are not <pre>. This override fixes that. */
.ai-msg-bubble pre code,
.ai-code-block code {
    background: transparent !important;
    padding: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    color: inherit;
    font-size: 13px;
}

/* ========== Code Blocks (Light Editor Style) ========== */
.ai-code-block {
    position: relative;
    margin: 14px 0 16px;
    border-radius: 10px;
    background: transparent;
    overflow: hidden;
    border: 1px solid #d0d7de;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Streaming code block — highlight border while code is being generated */
.ai-code-block-streaming {
    border-color: var(--ai-pri);
    box-shadow: 0 0 0 2px var(--ai-pri-glow);
}

.dark-mode .ai-code-block-streaming {
    box-shadow: 0 0 0 2px var(--ai-pri-glow);
}

/* "生成中" badge in the code header */
.ai-code-streaming-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: 10px;
    padding: 2px 9px;
    border-radius: 10px;
    background: var(--ai-pri-bg);
    color: var(--ai-pri);
    font-size: 10px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    line-height: 1.5;
}

.ai-code-streaming-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ai-pri);
    animation: aiStreamPulse 1.4s infinite;
}

/* Blinking cursor at the end of streaming code - removed */
.ai-code-cursor {
    display: none;
}

.ai-code-block:hover {
    border-color: #b0b8c0;
}

.dark-mode .ai-code-block {
    background: transparent;
    border-color: #30363d;
    box-shadow: none;
}

.dark-mode .ai-code-block:hover {
    border-color: #484f58;
}

/* Header bar */
.ai-code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: rgba(0,0,0,0.02);
    border-bottom: 1px solid #d0d7de;
    user-select: none;
}

.dark-mode .ai-code-header {
    background: transparent;
    border-bottom-color: #30363d;
}

.ai-code-lang {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Window control dots */
.ai-code-lang-dots {
    display: flex;
    gap: 6px;
}

.ai-code-lang-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.ai-code-lang-text {
    font-size: 12px;
    font-weight: 600;
    color: #57606a;
    margin-left: 4px;
    text-transform: capitalize;
    letter-spacing: 0.3px;
}

.dark-mode .ai-code-lang-text {
    color: #8b949e;
}

/* Copy button */
.ai-code-copy-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid #d0d7de;
    background: transparent;
    color: #57606a;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.ai-code-copy-btn:hover {
    background: var(--ai-pri);
    color: #ffffff;
    border-color: var(--ai-pri);
}

.ai-code-copy-btn.copied {
    background: #1a7f37;
    color: #ffffff;
    border-color: #1a7f37;
}

.dark-mode .ai-code-copy-btn {
    border-color: #30363d;
    background: transparent;
    color: #8b949e;
}

.dark-mode .ai-code-copy-btn:hover {
    background: var(--ai-pri);
    color: #ffffff;
    border-color: var(--ai-pri);
}

.dark-mode .ai-code-copy-btn.copied {
    background: #2ea043;
    color: #ffffff;
    border-color: #2ea043;
}

.ai-code-copy-btn svg {
    flex-shrink: 0;
}

/* Code body with line numbers */
.ai-code-body {
    display: flex;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: #c0c8d0 transparent;
}

.ai-code-body::-webkit-scrollbar {
    height: 6px;
}

.ai-code-body::-webkit-scrollbar-track {
    background: transparent;
}

.ai-code-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 3px;
}

.ai-code-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

.dark-mode .ai-code-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

.dark-mode .ai-code-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Line numbers gutter */
.ai-code-lines {
    display: flex;
    flex-direction: column;
    padding: 12px 0 12px 8px;
    min-width: 44px;
    text-align: right;
    user-select: none;
    border-right: 1px solid #d0d7de;
    background: transparent;
    flex-shrink: 0;
}

.dark-mode .ai-code-lines {
    border-right-color: #30363d;
    background: transparent;
}

.ai-code-lines span {
    display: block;
    padding: 0 8px 0 0;
    font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
    font-size: 13px;
    line-height: 1.45;
    color: #8b949e;
    height: 1.45em;
    overflow: hidden;
}

.dark-mode .ai-code-lines span {
    color: #484f58;
}

/* Code content area */
.ai-code-block pre {
    margin: 0;
    padding: 12px 16px;
    background: transparent;
    overflow: visible;
    font-size: 13px;
    line-height: 1.45;
    color: #24292f;
    flex: 1;
    min-width: 0;
    font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
}

.dark-mode .ai-code-block pre {
    color: #c9d1d9;
}

.ai-code-block code {
    font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
    font-size: 13px;
    line-height: 1.45;
    white-space: pre;
    word-wrap: normal;
}

/* Prism.js Light theme syntax highlighting colors */
.ai-code-block code[class*="language-"],
.ai-code-block pre[class*="language-"] {
    color: #24292f;
    text-shadow: none;
    font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
    font-size: 13px;
    direction: ltr;
}

/* Make tokens display inline-block so they can share line-height tightly */
.ai-code-block .token {
    white-space: pre !important;
    display: inline !important;
}

/* Blank lines don't get extra spacing */
.ai-code-block pre > code > br {
    display: none;
}

.ai-code-block .token.comment,
.ai-code-block .token.prolog,
.ai-code-block .token.doctype,
.ai-code-block .token.cdata {
    color: #6a737d;
}

.ai-code-block .token.punctuation {
    color: #24292f;
}

.ai-code-block .token.property,
.ai-code-block .token.tag,
.ai-code-block .token.constant,
.ai-code-block .token.symbol,
.ai-code-block .token.deleted {
    color: #d73a49;
}

.ai-code-block .token.boolean,
.ai-code-block .token.number {
    color: #005cc5;
}

.ai-code-block .token.selector,
.ai-code-block .token.attr-name,
.ai-code-block .token.string,
.ai-code-block .token.char,
.ai-code-block .token.builtin,
.ai-code-block .token.inserted {
    color: #032f62;
}

.ai-code-block .token.operator,
.ai-code-block .token.entity,
.ai-code-block .token.url,
.language-css .ai-code-block .token.string,
.style .ai-code-block .token.string,
.ai-code-block .token.variable {
    color: #24292f;
}

.ai-code-block .token.atrule,
.ai-code-block .token.attr-value,
.ai-code-block .token.function,
.ai-code-block .token.class-name {
    color: #e36209;
}

.ai-code-block .token.keyword {
    color: #d73a49;
}

.ai-code-block .token.regex,
.ai-code-block .token.important {
    color: #cd6833;
}

.ai-code-block .token.important,
.ai-code-block .token.bold {
    font-weight: bold;
}

.ai-code-block .token.italic {
    font-style: italic;
}

.ai-code-block .token.entity {
    cursor: help;
}

.ai-msg-bubble p {
    margin-bottom: 8px;
}

/* Code blocks and tables: tabular-nums for better number alignment */
.ai-code-block pre,
.ai-code-block code,
.ai-markdown-table th,
.ai-markdown-table td {
    font-variant-numeric: tabular-nums;
}

.ai-msg-bubble p:last-child {
    margin-bottom: 0;
}

.ai-msg-bubble ul, .ai-msg-bubble ol {
    padding-left: 20px;
    margin: 8px 0;
}

.ai-msg-bubble li {
    margin-bottom: 4px;
    line-height: 1.55;
}

.ai-msg-bubble h1, .ai-msg-bubble h2, .ai-msg-bubble h3,
.ai-msg-bubble h4, .ai-msg-bubble h5, .ai-msg-bubble h6 {
    margin: 14px 0 8px;
    font-weight: 600;
    color: var(--t1);
    scroll-margin-top: 80px;
    line-height: 1.3;
}

.ai-msg-bubble h1 { font-size: 19px; border-bottom: 2px solid var(--ai-sidebar-border); padding-bottom: 6px; }
.ai-msg-bubble h2 { font-size: 16px; border-bottom: 1px solid var(--ai-sidebar-border); padding-bottom: 4px; }
.ai-msg-bubble h3 { font-size: 15px; }
.ai-msg-bubble h4 { font-size: 14px; }
.ai-msg-bubble h5 { font-size: 13px; color: var(--t2); }
.ai-msg-bubble h6 { font-size: 12px; color: var(--t3); text-transform: uppercase; letter-spacing: 0.5px; }

.ai-msg-bubble h1:first-child, .ai-msg-bubble h2:first-child, .ai-msg-bubble h3:first-child,
.ai-msg-bubble h4:first-child, .ai-msg-bubble h5:first-child, .ai-msg-bubble h6:first-child {
    margin-top: 0;
}

.dark-mode .ai-msg-bubble h1 { border-bottom-color: #334155; }
.dark-mode .ai-msg-bubble h2 { border-bottom-color: #334155; }

/* Horizontal rule */
.ai-msg-bubble hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--ai-sidebar-border), transparent);
    margin: 16px 0;
}

.dark-mode .ai-msg-bubble hr {
    background: linear-gradient(90deg, transparent, #334155, transparent);
}

/* Strikethrough */
.ai-msg-bubble del {
    text-decoration: line-through;
    opacity: 0.6;
}

/* Highlight */
.ai-msg-bubble mark {
    background: linear-gradient(180deg, #fef08a 0%, #fde047 100%);
    color: var(--t1);
    padding: 1px 5px;
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.dark-mode .ai-msg-bubble mark {
    background: linear-gradient(180deg, #854d0e 0%, #713f12 100%);
    color: #fef08a;
}

/* Links */
.ai-msg-bubble a {
    color: var(--ai-pri);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s, background-color 0.2s, color 0.2s;
    border-radius: 3px;
}

.ai-msg-bubble a:hover {
    border-bottom-color: var(--ai-pri);
    background: var(--ai-pri-bg);
    padding: 0 3px;
    margin: 0 -3px;
}

/* Task lists — checkbox + label layout */
.ai-task-list {
    list-style: none;
    padding-left: 0;
    margin: 8px 0;
}

.ai-task-list .ai-task-list {
    margin: 4px 0 4px 8px;
}

.ai-task-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 6px;
    list-style: none;
}

.ai-task-item > input[type="checkbox"] {
    margin-top: 4px;
    flex-shrink: 0;
    cursor: default;
    accent-color: var(--ai-pri);
    width: 15px;
    height: 15px;
}

.ai-task-item > label {
    flex: 1;
    cursor: default;
    user-select: text;
    line-height: 1.6;
}

.ai-task-item:has(> input[type="checkbox"]:checked) > label {
    color: var(--t3);
    text-decoration: line-through;
    opacity: 0.7;
}

/* Nested list indentation (any depth) */
.ai-msg-bubble ul ul,
.ai-msg-bubble ol ol,
.ai-msg-bubble ul ol,
.ai-msg-bubble ol ul {
    margin: 4px 0;
    padding-left: 18px;
}

.ai-msg-bubble li > ul,
.ai-msg-bubble li > ol {
    margin: 4px 0;
    padding-left: 18px;
}

/* Typing indicator */
.ai-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.ai-typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--t3);
    animation: aiTyping 1.4s infinite;
}

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

@keyframes aiTyping {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* Copy button on assistant messages */
.ai-msg-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.ai-message:hover .ai-msg-actions {
    opacity: 1;
}

.ai-msg-action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--t3);
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.ai-msg-action-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--t2);
}

.dark-mode .ai-msg-action-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.ai-msg-action-btn i {
    width: 12px !important;
    height: 12px !important;
}

/* ========== Input Area ========== */
.ai-input-area {
    padding: 8px 24px 14px;
    background: transparent;
    flex-shrink: 0;
}

.ai-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    background: var(--ai-input-bg);
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 12px 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.dark-mode .ai-input-wrapper {
    border-color: #334155;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.ai-input-wrapper:focus-within {
    border-color: var(--ai-pri);
    box-shadow: 0 0 0 3px var(--ai-pri-glow);
}

.ai-input-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ai-input-tools-left {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.ai-input-tools-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.ai-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--t3);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}

.ai-tool-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--t2);
}

.dark-mode .ai-tool-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.ai-tool-btn.active {
    background: var(--ai-pri-bg);
    color: var(--ai-pri);
}

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

.ai-model-switch-btn {
    font-size: 12px;
}

.ai-model-switch-btn span {
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-model-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ai-model-option:hover {
    background: var(--ai-pri-bg);
}

.ai-model-option.active {
    background: var(--ai-pri-bg);
    color: var(--ai-pri);
}

.ai-model-option-radio {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-model-option.active .ai-model-option-radio {
    border-color: var(--ai-pri);
}

.ai-model-option.active .ai-model-option-radio::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ai-pri);
}

.ai-model-option-info {
    flex: 1;
    min-width: 0;
}

.ai-model-option-name {
    font-size: 13px;
    font-weight: 600;
}

.ai-model-option-desc {
    font-size: 11px;
    color: var(--t3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-textarea {
    width: 100%;
    resize: none;
    padding: 4px 0;
    border: none;
    background: transparent;
    color: var(--t1);
    font-size: 14px;
    line-height: 1.6;
    font-family: inherit;
    outline: none;
    max-height: 200px;
    min-height: 24px;
    box-sizing: border-box;
}

.ai-textarea::placeholder {
    color: #94a3b8;
}

.ai-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--ai-pri);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.18s ease, transform 0.1s ease;
}

.ai-send-btn:hover {
    background: var(--ai-pri-d);
}

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

.ai-send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

.dark-mode .ai-send-btn:disabled {
    background: #475569;
}

.ai-stop-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: #ef4444;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.18s ease, transform 0.1s ease;
}

.ai-stop-btn:hover {
    background: #dc2626;
}

.ai-stop-btn:active {
    transform: scale(0.95);
}

.ai-input-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 800px;
    margin: 0 auto;
    font-size: 11px;
    color: var(--t3);
    padding-top: 6px;
    opacity: 0.7;
}

.ai-input-footer-left,
.ai-input-footer-right {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.ai-input-footer-right {
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-char-count {
    font-variant-numeric: tabular-nums;
    min-width: 34px;
    text-align: right;
}

.ai-footer-sep {
    opacity: 0.6;
}

@media (max-width: 640px) {
    .ai-input-footer-left {
        display: none;
    }

    .ai-input-footer {
        justify-content: center;
    }
}

.ai-gen-status-badge {
    background: #3b82f6;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    color: #fff;
    vertical-align: middle;
}

.ai-msg-empty-note {
    color: var(--t3);
    font-size: 12px;
    font-style: italic;
}

.ai-input-counter {
    font-size: 11px;
    color: var(--t3);
    margin-top: 8px;
    opacity: 0.6;
}

/* ========== Avatars ========== */
.ai-msg-avatar {
    display: none;
}

/* ========== Scroll-to-Bottom FAB ========== */
.ai-scroll-bottom-btn {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--ai-sidebar-border);
    background: var(--ai-bot-bg);
    color: var(--t2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: background 0.15s ease, color 0.15s ease;
    z-index: 10;
}

.ai-scroll-bottom-btn:hover {
    background: var(--ai-pri);
    color: white;
    border-color: var(--ai-pri);
}

/* ========== Sidebar Date Group Labels ========== */
.ai-chat-group-label {
    padding: 12px 12px 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--t3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    user-select: none;
}

/* ========== Mobile Responsive ========== */
@media (max-width: 768px) {
    .ai-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    .ai-sidebar.open {
        transform: translateX(0);
    }

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

    .ai-sidebar-overlay.show {
        display: block;
    }

    .ai-mobile-menu-btn {
        display: flex;
    }

    .ai-suggestion-grid {
        grid-template-columns: 1fr;
    }

    .ai-code-block {
        border-radius: 8px;
        margin: 10px -8px;
    }

    .ai-code-lines {
        min-width: 36px;
    }

    .ai-code-lines span {
        font-size: 11px;
        padding: 0 8px 0 4px;
    }

    .ai-code-block pre {
        font-size: 13px;
        padding: 12px 10px;
    }

    /* 输入框移动端适配 */
    .ai-input-area {
        padding: 12px 16px 16px;
    }

    .ai-input-wrapper {
        padding: 10px 14px;
        border-radius: 16px;
    }

    .ai-tool-btn span {
        display: none;
    }

    .ai-header-model .ai-model-selector span {
        display: none;
    }

    .ai-header-model .ai-model-selector {
        padding: 8px;
        border: none;
        background: transparent;
        min-width: 36px;
        min-height: 36px;
        justify-content: center;
    }

    .ai-tool-btn {
        padding: 6px 8px;
    }

    .ai-send-btn {
        width: 32px;
        height: 32px;
    }

    .ai-stop-btn {
        width: 28px;
        height: 28px;
    }

    .ai-input-mode-tabs {
        margin-bottom: 6px;
    }

    .ai-input-mode-tab {
        padding: 6px 12px;
        font-size: 11px;
        min-height: 36px;
    }

    .ai-input-mode-tab span {
        display: none;
    }

    .ai-msg-avatar {
        width: 28px;
        height: 28px;
    }

    .ai-msg-avatar svg {
        width: 14px !important;
        height: 14px !important;
    }

    .ai-header-sub {
        display: none;
    }

    .ai-header {
        padding: 12px 16px;
    }

    .ai-content {
        padding: 12px;
    }

    .ai-message.user .ai-msg-bubble-wrap {
        max-width: 90%;
    }

    .ai-message.assistant .ai-msg-bubble-wrap {
        max-width: 95%;
    }

    .ai-scroll-bottom-btn {
        bottom: 80px;
    }
}

/* Scrollbar styling */
.ai-content::-webkit-scrollbar {
    width: 6px;
}

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

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

.ai-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* Loading dots for streaming - cursor removed */
.ai-streaming-cursor::after {
    content: none;
}

@keyframes aiCursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* ========== Toast notification ========== */
.ai-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 10px;
    background: #1e293b;
    color: white;
    font-size: 13px;
    z-index: 1000;
    animation: aiToastIn 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.dark-mode .ai-toast {
    background: #f1f5f9;
    color: #1e293b;
}

@keyframes aiToastIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========== Search Box ========== */
.ai-search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--ai-sidebar-border);
    margin-bottom: 8px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.dark-mode .ai-search-box {
    background: rgba(255, 255, 255, 0.05);
}

.ai-search-box:focus-within {
    border-color: var(--ai-pri);
    box-shadow: 0 0 0 2px var(--ai-pri-glow);
}

.ai-search-box svg {
    color: var(--t3);
    flex-shrink: 0;
}

.ai-search-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 13px;
    color: var(--t2);
    min-width: 0;
}

.ai-search-input::placeholder {
    color: var(--t3);
}

/* ========== Tables ========== */
.ai-markdown-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 14px 0 16px;
    font-size: 14px;
    overflow: hidden;
    border-radius: 10px;
    border: 1px solid var(--ai-sidebar-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.ai-markdown-table th,
.ai-markdown-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--ai-sidebar-border);
    line-height: 1.5;
}

.ai-markdown-table th {
    background: rgba(29, 91, 255, 0.06);
    font-weight: 600;
    color: var(--ai-pri-d);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.dark-mode .ai-markdown-table th {
    background: rgba(99, 102, 241, 0.12);
}

.ai-markdown-table tr:last-child td {
    border-bottom: none;
}

.ai-markdown-table tr:hover td {
    background: rgba(29, 91, 255, 0.04);
}

.dark-mode .ai-markdown-table tr:hover td {
    background: rgba(99, 102, 241, 0.08);
}

/* ========== Blockquotes (multi-line, nested supported) ========== */
.ai-msg-bubble blockquote {
    margin: 10px 0;
    padding: 10px 16px;
    border-left: 4px solid var(--ai-pri);
    background: linear-gradient(135deg, rgba(29, 91, 255, 0.06) 0%, rgba(0, 199, 255, 0.04) 100%);
    border-radius: 0 10px 10px 0;
    color: var(--t2);
    font-style: italic;
    line-height: 1.6;
}

.ai-msg-bubble blockquote blockquote {
    margin: 8px 0 0;
    border-left-color: var(--ai-pri-l);
    background: rgba(0, 199, 255, 0.04);
}

.dark-mode .ai-msg-bubble blockquote {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.06) 100%);
}

.dark-mode .ai-msg-bubble blockquote blockquote {
    background: rgba(139, 92, 246, 0.08);
}

.ai-msg-bubble blockquote p {
    margin: 0 0 6px;
}

.ai-msg-bubble blockquote p:last-child {
    margin-bottom: 0;
}

.ai-msg-bubble blockquote > *:first-child {
    margin-top: 0;
}

.ai-msg-bubble blockquote > *:last-child {
    margin-bottom: 0;
}

/* Allow lists/headings/code inside blockquotes to render non-italic */
.ai-msg-bubble blockquote ul,
.ai-msg-bubble blockquote ol,
.ai-msg-bubble blockquote h1,
.ai-msg-bubble blockquote h2,
.ai-msg-bubble blockquote h3,
.ai-msg-bubble blockquote h4,
.ai-msg-bubble blockquote h5,
.ai-msg-bubble blockquote h6,
.ai-msg-bubble blockquote pre,
.ai-msg-bubble blockquote .ai-code-block,
.ai-msg-bubble blockquote .ai-markdown-table {
    font-style: normal;
}

/* ========== Message Action Button Danger ========== */
.ai-msg-action-btn-danger:hover {
    background: rgba(255, 59, 48, 0.1);
    color: #ff3b30;
}

.dark-mode .ai-msg-action-btn-danger:hover {
    background: rgba(255, 59, 48, 0.15);
}

/* ========== Code Preview Editor ========== */

/* Tab bar for switching between code and preview */
/* ========== Code Block Tabs ========== */
.ai-code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: linear-gradient(135deg, #f8f9fb 0%, #f1f3f5 100%);
    border-bottom: 1px solid #e2e8f0;
    gap: 12px;
}

.dark-mode .ai-code-header {
    background: linear-gradient(135deg, #1c2128 0%, #161b22 100%);
    border-bottom-color: #30363d;
}

.ai-code-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    min-width: 0;
}

.ai-code-tabs {
    display: flex;
    gap: 2px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    padding: 2px;
}

.dark-mode .ai-code-tabs {
    background: rgba(255, 255, 255, 0.05);
}

.ai-code-tab {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    border: none;
    background: transparent;
    border-radius: 4px;
    transition: all 0.15s ease;
    user-select: none;
    white-space: nowrap;
}

.ai-code-tab svg {
    width: 12px;
    height: 12px;
}

.ai-code-tab:hover {
    color: #475569;
    background: rgba(0, 0, 0, 0.03);
}

.dark-mode .ai-code-tab:hover {
    color: #cbd5e1;
    background: rgba(255, 255, 255, 0.05);
}

.ai-code-tab.active {
    color: var(--ai-pri);
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.dark-mode .ai-code-tab.active {
    color: #818cf8;
    background: #2d333b;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* ========== Code Panes ========== */
.ai-code-pane {
    position: relative;
}

.ai-code-pane-code {
    display: block;
}

.ai-code-pane-preview {
    display: none;
}

/* When shown via inline style, override the CSS default */
.ai-code-pane-preview[style*="display: block"] {
    display: block !important;
}

/* Code body inside preview should not scroll when preview is shown */
.ai-code-pane-preview .ai-preview-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ========== Preview Content ========== */
.ai-preview-content {
    background: #ffffff;
    min-height: 400px;
    max-height: 800px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.dark-mode .ai-preview-content {
    background: #0d1117;
}

.ai-preview-content-js {
    min-height: 300px;
}

.ai-preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.dark-mode .ai-preview-toolbar {
    background: #161b22;
    border-bottom-color: #30363d;
}

.ai-preview-type-label {
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dark-mode .ai-preview-type-label {
    color: #94a3b8;
}

.ai-preview-toolbar-actions {
    display: flex;
    gap: 4px;
}

/* ========== Preview Action Buttons ========== */
.ai-preview-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 4px;
    border: 1px solid #cbd5e1;
    background: white;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
}

.ai-preview-action-btn:hover {
    border-color: var(--ai-pri, #1D5BFF);
    color: var(--ai-pri, #1D5BFF);
    background: rgba(29, 91, 255, 0.08);
}

.ai-preview-action-btn svg {
    width: 13px !important;
    height: 13px !important;
}

/* ========== Preview Iframe ========== */
.ai-code-preview-iframe {
    width: 100%;
    flex: 1;
    min-height: 350px;
    max-height: 750px;
    border: none;
    background: white;
    display: block;
}

/* Preview loading state */
.ai-code-pane-preview {
    animation: aiFadeIn 0.2s ease-out;
}

@keyframes aiFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Tab switch animation */
.ai-code-tab {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Active tab indicator */
.ai-code-tab.active {
    position: relative;
}

.ai-code-tab.active::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    background: white;
    border-radius: 4px;
    z-index: -1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.dark-mode .ai-code-tab.active::before {
    background: #2d333b;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.ai-preview-content-js .js-console-output {
    flex: 1;
    min-height: 100px;
    max-height: 500px;
}

/* ========== Refresh Animation ========== */
@keyframes aiPreviewRefresh {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.ai-preview-toolbar.ai-preview-refreshing svg {
    animation: aiPreviewRefresh 0.6s linear;
}

.ai-preview-action-btn.ai-preview-refreshing svg {
    animation: aiPreviewRefresh 0.6s linear;
}

/* Fullscreen overlay */
.ai-preview-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    display: flex;
    flex-direction: column;
}

/* Dark mode support for new preview */
.dark-mode .ai-preview-action-btn {
    border-color: #30363d;
    background: #161b22;
    color: #8b949e;
}

.dark-mode .ai-preview-action-btn:hover {
    border-color: #818cf8;
    color: #818cf8;
    background: rgba(99, 102, 241, 0.1);
}

/* JS Console output */
.js-console-output {
    padding: 12px;
    background: #1e293b;
    min-height: 100px;
    max-height: 400px;
    overflow-y: auto;
    font-family: "SF Mono", "Fira Code", Consolas, monospace;
    font-size: 12px;
    line-height: 1.6;
}

.dark-mode .js-console-output {
    background: #0f172a;
}

.js-console {
    padding: 4px 8px;
    margin: 2px 0;
    border-radius: 4px;
    color: #e2e8f0;
}

.js-console-log {
    background: rgba(29, 91, 255, 0.1);
}

.js-console-warn {
    background: rgba(245, 158, 11, 0.1);
    color: #fbbf24;
}

.js-console-error {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

.js-console-info {
    background: rgba(14, 165, 233, 0.1);
    color: #38bdf8;
}

/* CSS sample content styling */
.sample-content {
    padding: 20px;
    font-family: system-ui, -apple-system, sans-serif;
    max-width: 800px;
    margin: 0 auto;
}

.sample-button {
    display: inline-block;
    padding: 8px 16px;
    background: #1D5BFF;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    margin: 10px 0;
}

/* ========== 输入区域内嵌模式标签 ========== */
.ai-input-mode-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.ai-input-mode-tab {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: none;
    background: transparent;
    color: var(--t3);
    font-size: 12px;
    font-weight: 500;
    border-radius: 7px;
    cursor: pointer;
    transition: color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.ai-input-mode-tab:hover {
    color: var(--t2);
    background: rgba(0, 0, 0, 0.04);
    transform: translateY(-1px);
}

.dark-mode .ai-input-mode-tab:hover {
    background: rgba(255, 255, 255, 0.06);
}

.ai-input-mode-tab.active {
    background: var(--ai-pri-bg);
    color: var(--ai-pri);
    box-shadow: 0 0 0 1px var(--ai-pri-glow);
}

.ai-input-mode-tab svg {
    width: 14px !important;
    height: 14px !important;
    transition: transform 0.2s ease;
}

.ai-input-mode-tab.active svg {
    transform: scale(1.08);
}



/* ========== 生成结果（用于对话内嵌的图片/视频消息） ========== */

.ai-gen-results {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.ai-gen-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 80px 20px;
    color: #94a3b8;
    text-align: center;
}

.ai-gen-empty p {
    margin: 0;
    font-size: 14px;
}

.ai-gen-item {
    background: var(--ai-bot-bg);
    border: 1px solid var(--ai-sidebar-border);
    border-radius: 14px;
    padding: 16px;
    box-shadow: var(--ai-card-shadow);
}

.ai-gen-prompt {
    margin-top: 12px;
    padding: 8px 12px;
    background: var(--ai-pri-bg);
    border-radius: 8px;
    font-size: 13px;
    color: #64748b;
    line-height: 1.5;
    word-break: break-word;
}

/* 对话内嵌的 gen-prompt 样式 */
.ai-msg-bubble .ai-gen-prompt {
    margin: 8px 0;
    padding: 8px 12px;
    background: rgba(29, 91, 255, 0.08);
    border-left: 3px solid var(--ai-pri);
    border-radius: 6px;
    font-size: 12.5px;
    color: var(--t2);
    font-style: italic;
}

.dark-mode .ai-msg-bubble .ai-gen-prompt {
    color: #94a3b8;
    background: rgba(99, 102, 241, 0.12);
}

.dark-mode .ai-gen-prompt {
    color: #94a3b8;
}

/* 历史记录标记 */
.ai-gen-history-item {
    opacity: 0.85;
    border-style: dashed;
}

.ai-gen-meta {
    margin-top: 6px;
    font-size: 11px;
    color: #94a3b8;
    text-align: right;
}

.dark-mode .ai-gen-meta {
    color: #64748b;
}

/* 图片画廊 */
.ai-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}

/* 根据图片数量智能布局：单图大图、双图并排、三/四图网格 */
.ai-image-grid[data-count="1"] {
    grid-template-columns: 1fr;
}
.ai-image-grid[data-count="2"] {
    grid-template-columns: repeat(2, 1fr);
}
.ai-image-grid[data-count="3"] {
    grid-template-columns: repeat(3, 1fr);
}
.ai-image-grid[data-count="4"] {
    grid-template-columns: repeat(2, 1fr);
}

.ai-image-card {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #f5f6f7;
    aspect-ratio: 1 / 1;
    min-height: 180px;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.25s ease;
    /* 图片生成完成时淡入动画 */
    opacity: 0;
    animation: ai-img-fade-in 0.5s ease forwards;
}

@keyframes ai-img-fade-in {
    from {
        opacity: 0;
        transform: scale(0.94) translateY(6px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* 图片逐一错开淡入 */
.ai-image-card:nth-child(1) { animation-delay: 0s; }
.ai-image-card:nth-child(2) { animation-delay: 0.08s; }
.ai-image-card:nth-child(3) { animation-delay: 0.16s; }
.ai-image-card:nth-child(4) { animation-delay: 0.24s; }

.ai-image-card:hover {
    transform: translateY(-3px) scale(1.01);
    box-shadow: 0 8px 24px rgba(29, 91, 255, 0.22), 0 2px 8px rgba(0, 0, 0, 0.08);
}

.ai-image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ai-image-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.ai-image-card:hover .ai-image-actions {
    opacity: 1;
}

.ai-image-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
    backdrop-filter: blur(4px);
}

.ai-image-action-btn:hover {
    background: rgba(0, 0, 0, 0.85);
}

/* 视频播放器（对话内） */
.ai-msg-bubble .ai-video-player {
    width: 100%;
    max-height: 720px;
    border-radius: 12px;
    background: #000;
    display: block;
    margin: 10px 0;
}

/* 对话内的视频操作按钮 */
.ai-msg-bubble .ai-video-actions {
    margin-top: 8px;
    display: flex;
    gap: 8px;
}

.ai-msg-bubble .ai-video-actions .ai-image-action-btn {
    padding: 7px 14px; /* Override padding */
    font-size: 12px;   /* Add specific font-size */
}

.ai-msg-bubble .ai-video-actions .ai-image-action-btn:hover {
    background: var(--ai-pri-d);
}

.ai-video-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
}

.ai-video-actions .ai-image-action-btn {
    background: var(--ai-pri);
    color: #fff;
    padding: 8px 14px; /* Set a default padding */
    border-radius: 8px;
}

.ai-video-actions .ai-image-action-btn:hover {
    background: var(--ai-pri-d);
}

/* 加载状态 */
.ai-gen-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 36px 24px;
    text-align: center;
}

/* 对话内的 gen-loading 样式 */
.ai-msg-bubble .ai-gen-loading {
    padding: 20px;
    background: transparent;
    border: none;
    box-shadow: none;
}

/* 加载头部（spinner + 文本） */
.ai-gen-loading-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.ai-gen-loading-text {
    font-size: 14px;
    color: #64748b;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ai-gen-loading-dots {
    display: inline-block;
    width: 1.5ch;
    text-align: left;
    margin-left: 1px;
    overflow: hidden;
    vertical-align: bottom;
    animation: ai-loading-dots 1.4s steps(4, end) infinite;
}

.ai-gen-loading-dots::after {
    content: '...';
}

@keyframes ai-loading-dots {
    0% { width: 0; opacity: 0; }
    25% { width: 0.5ch; opacity: 1; }
    50% { width: 1ch; opacity: 1; }
    75% { width: 1.5ch; opacity: 1; }
    100% { width: 0; opacity: 0; }
}

.ai-gen-progress {
    font-size: 13px;
    color: #94a3b8;
}

.dark-mode .ai-gen-loading-text {
    color: #cbd5e1;
}

.ai-gen-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid #e5e7eb;
    border-top-color: var(--ai-pri);
    animation: ai-gen-spin 1s linear infinite;
}

@keyframes ai-gen-spin {
    to { transform: rotate(360deg); }
}

/* 视频生成进度条 */
.ai-gen-progress-bar {
    position: relative;
    width: 100%;
    height: 6px;
    background: var(--ai-pri-bg);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 10px;
}

.ai-gen-progress-bar-track {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 30%;
    background: linear-gradient(90deg, var(--ai-pri) 0%, var(--ai-pri-l) 50%, var(--ai-pri) 100%);
    background-size: 200% 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
    animation: ai-progress-sweep 1.8s linear infinite;
}

@keyframes ai-progress-sweep {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.ai-gen-progress-bar-track.ai-gen-progress-indeterminate {
    width: 40% !important;
    animation: ai-progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes ai-progress-indeterminate {
    0% { left: -40%; }
    50% { left: 100%; }
    100% { left: -40%; }
}

.ai-gen-progress-bar-track::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 24px;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5));
    border-radius: 999px;
}

/* 对话内图片加载 */
.ai-chat-img-loading {
    display: flex;
    align-items: center;
    gap: 14px;
    color: #64748b;
    font-size: 14px;
    padding: 16px;
}

.ai-chat-img-loading .ai-gen-spinner {
    width: 36px;
    height: 36px;
}

/* ========== 生成工具栏（尺寸/数量/图片URL） ========== */
.ai-gen-toolbar {
    display: flex;
    gap: 6px;
    padding: 6px 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    align-items: center;
    background: var(--ai-pri-bg);
    border: 1px solid var(--ai-sidebar-border);
    border-radius: 12px;
    animation: ai-toolbar-slide-in 0.25s ease;
}

@keyframes ai-toolbar-slide-in {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dark-mode .ai-gen-toolbar {
    border-color: #334155;
}

.ai-gen-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--ai-bot-bg);
    color: var(--t3);
    font-size: 13px;
    border: 1px solid var(--ai-sidebar-border);
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.ai-gen-option:hover {
    color: var(--ai-pri);
    border-color: var(--ai-pri-l);
    box-shadow: 0 0 0 3px var(--ai-pri-bg);
}

.dark-mode .ai-gen-option {
    background: rgba(255, 255, 255, 0.04);
    border-color: #334155;
}

.dark-mode .ai-gen-option:hover {
    background: rgba(99, 102, 241, 0.12);
    color: var(--ai-pri-l);
    border-color: var(--ai-pri);
}

.ai-gen-option-full {
    flex: 1;
    min-width: 200px;
}

.ai-gen-divider {
    width: 1px;
    height: 22px;
    background: var(--ai-sidebar-border);
    margin: 0 2px;
    opacity: 0.7;
}

.dark-mode .ai-gen-divider {
    background: #334155;
}

.ai-gen-select,
.ai-gen-input {
    border: none;
    background: transparent;
    color: var(--t2);
    font-size: 13px;
    outline: none;
    cursor: pointer;
    font-family: inherit;
}

.ai-gen-input {
    flex: 1;
    cursor: text;
}

.ai-gen-select:focus,
.ai-gen-input:focus {
    outline: none;
}

.ai-gen-select {
    min-width: 120px;
}

.ai-gen-input::placeholder {
    color: var(--t3);
}

.ai-gen-option svg {
    color: var(--ai-pri);
    flex-shrink: 0;
    opacity: 0.85;
}

/* ========== 对话内图片生成切换按钮 ========== */
.ai-img-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--t3);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
}

.ai-img-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--t2);
}

.dark-mode .ai-img-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.ai-img-toggle-btn.active {
    background: var(--ai-pri-bg);
    color: var(--ai-pri);
}

.dark-mode .ai-img-toggle-btn {
    color: #94a3b8;
}

/* 对话内图片样式 */
.ai-msg-bubble img {
    max-width: 100%;
    border-radius: 10px;
    margin: 6px 0;
    display: block;
    cursor: pointer;
    /* Markdown 图片淡入 */
    opacity: 0;
    transition: opacity 0.5s ease;
}

.ai-msg-bubble img {
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.ai-msg-bubble img.ai-img-loaded {
    opacity: 1;
    transform: scale(1);
}

/* 对话内的图片网格（用于生图结果） */
.ai-msg-bubble .ai-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

/* 对话内单图放大展示，不被 minmax 限制成多列 */
.ai-msg-bubble .ai-image-grid[data-count="1"] {
    grid-template-columns: 1fr;
}

@media (max-width: 600px) {
    .ai-msg-bubble .ai-image-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }
}

.ai-msg-bubble .ai-image-card {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* 对话内的图片也支持逐一淡入 */
.ai-msg-bubble .ai-image-grid .ai-image-card:nth-child(1) { animation-delay: 0s; }
.ai-msg-bubble .ai-image-grid .ai-image-card:nth-child(2) { animation-delay: 0.1s; }
.ai-msg-bubble .ai-image-grid .ai-image-card:nth-child(3) { animation-delay: 0.2s; }
.ai-msg-bubble .ai-image-grid .ai-image-card:nth-child(4) { animation-delay: 0.3s; }

.ai-image-card.ai-skeleton-card {
    background: #f5f6f7;
    border: 1px solid #e5e7eb;
    opacity: 1;
}



.ai-image-card.ai-skeleton-card img {
    opacity: 0; /* Hide the image until loaded */
}

.dark-mode .ai-msg-bubble .ai-image-card {
    background: #334155;
}

.dark-mode .ai-image-card.ai-skeleton-card {
    background: #334155;
    border: 1px solid #475569;
}

.ai-msg-bubble .ai-image-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(29, 91, 255, 0.2);
}

.ai-msg-bubble .ai-image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    /* 图片加载完成时淡入 */
    opacity: 0;
    transition: opacity 0.4s ease;
}

.ai-msg-bubble .ai-image-card img {
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.ai-msg-bubble .ai-image-card img.ai-img-loaded {
    opacity: 1;
    transform: scale(1);
}

/* 图片骨架屏 - 简洁风格 */
.ai-image-card::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Crect x='3' y='3' width='18' height='18' rx='2' ry='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpolyline points='21 15 16 10 5 21'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.8;
    z-index: 2;
}

.dark-mode .ai-image-card::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Crect x='3' y='3' width='18' height='18' rx='2' ry='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpolyline points='21 15 16 10 5 21'/%3E%3C/svg%3E");
}

.ai-image-card:has(img.ai-img-loaded)::after,
.ai-image-card:has(video)::after {
    opacity: 0;
    pointer-events: none;
}

/* ========== 图片加载失败状态 ========== */
.ai-image-card.ai-img-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
}

.ai-image-card.ai-img-error::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ef4444' stroke-width='1.5'%3E%3Crect x='3' y='3' width='18' height='18' rx='2' ry='2'/%3E%3Cpath d='M9 9l6 6M15 9l-6 6'/%3E%3C/svg%3E");
    opacity: 0.4;
}

.ai-image-card.ai-img-error img {
    display: none;
}

.dark-mode .ai-image-card.ai-img-error {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
}

.ai-img-retry {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    background: rgba(29, 91, 255, 0.9);
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    z-index: 5;
    transition: background 0.15s ease;
    backdrop-filter: blur(4px);
}

.ai-img-retry:hover {
    background: var(--ai-pri);
}

.ai-img-retry svg {
    flex-shrink: 0;
}

/* 图片容器内部 z-index 调整 */
.ai-image-card img {
    position: relative;
    z-index: 2;
}

.ai-image-actions {
    position: relative;
    z-index: 3;
}

.ai-msg-bubble .ai-image-actions {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.ai-msg-bubble .ai-image-card:hover .ai-image-actions {
    opacity: 1;
}

/* Video Placeholder (Skeleton) */
.ai-video-placeholder {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #f5f6f7;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease;
}

/* 在图片网格容器内时，由 grid 的 margin/gap 统一控制间距，移除自身 margin */
.ai-image-grid .ai-video-placeholder {
    margin-bottom: 0;
}

.dark-mode .ai-video-placeholder {
    background: #334155;
    border-color: #475569;
}

/* 加载中：简洁播放图标 */
.ai-video-placeholder.ai-skeleton-card::after {
    content: '';
    position: absolute;
    width: 48px;
    height: 48px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d1d5db' stroke-width='1.5'%3E%3Cpolygon points='5 3 19 12 5 21 5 3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.5;
    z-index: 1;
}

.dark-mode .ai-video-placeholder.ai-skeleton-card::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='1.5'%3E%3Cpolygon points='5 3 19 12 5 21 5 3'/%3E%3C/svg%3E");
}

.ai-video-placeholder video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    opacity: 0;
    transform: scale(1.02);
    transition: opacity 0.5s ease, transform 0.5s ease;
    position: relative;
    z-index: 2;
}

.ai-video-placeholder video.ai-video-loaded {
    opacity: 1;
    transform: scale(1);
}

.ai-video-actions {
    position: absolute;
    bottom: 10px;
    left: 10px;
    display: flex;
    gap: 8px;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.ai-video-placeholder:hover .ai-video-actions {
    opacity: 1;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .ai-image-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 8px;
    }

    /* 单图保持较大尺寸，2/3/4 图在窄屏下统一两列 */
    .ai-image-grid[data-count="1"] {
        max-width: 100%;
    }
    .ai-image-grid[data-count="3"] {
        grid-template-columns: repeat(2, 1fr);
    }
    .ai-image-grid[data-count="4"] {
        grid-template-columns: repeat(2, 1fr);
    }

    .ai-gen-toolbar {
        gap: 4px;
        padding: 5px 6px;
        margin-bottom: 8px;
    }

    .ai-gen-option {
        padding: 4px 8px;
        font-size: 12px;
    }

    .ai-gen-option i,
    .ai-gen-option svg {
        width: 14px !important;
        height: 14px !important;
    }

    .ai-gen-select {
        min-width: 88px;
        font-size: 12px;
    }

    .ai-gen-input {
        font-size: 12px;
    }

    .ai-gen-divider {
        height: 16px;
        margin: 0 2px;
    }

    .ai-image-actions {
        opacity: 1;
    }

    /* 视频占位播放图标略小 */
    .ai-video-placeholder.ai-skeleton-card::after {
        width: 44px;
        height: 44px;
        background-size: 22px;
    }

    .ai-gen-spinner {
        width: 30px;
        height: 30px;
        border-width: 2.5px;
    }
}

.sample-link {
    color: #1D5BFF;
    text-decoration: underline;
    margin: 10px 0;
    display: inline-block;
}

.sample-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
}

.sample-table th,
.sample-table td {
    border: 1px solid #e2e8f0;
    padding: 8px 12px;
    text-align: left;
}

.sample-table th {
    background: #f8fafc;
    font-weight: 600;
}

/* ========== Extended Markdown Elements ========== */

/* Table wrapper — enables horizontal scroll for wide tables on small screens */
.ai-table-wrap {
    margin: 14px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
}

.ai-table-wrap .ai-markdown-table {
    margin: 0;
    min-width: 100%;
}

/* ========== Keyboard keys <kbd> ========== */
.ai-msg-bubble kbd,
.ai-kbd {
    display: inline-block;
    padding: 2px 7px;
    margin: 0 2px;
    font-family: "SF Mono", "Fira Code", "JetBrains Mono", Consolas, monospace;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.4;
    color: #1f2328;
    background: #f6f8fa;
    border: 1px solid rgba(175, 184, 193, 0.4);
    border-bottom-width: 2px;
    border-radius: 6px;
    box-shadow: inset 0 -1px 0 rgba(175, 184, 193, 0.2);
    vertical-align: middle;
    white-space: nowrap;
}

.dark-mode .ai-msg-bubble kbd,
.dark-mode .ai-kbd {
    background: #21262d;
    color: #e6edf3;
    border-color: rgba(139, 148, 158, 0.6);
    box-shadow: inset 0 -1px 0 rgba(139, 148, 158, 0.3);
}

/* ========== Subscript & Superscript ========== */
.ai-msg-bubble sub {
    font-size: 0.75em;
    vertical-align: sub;
    line-height: 0;
}

.ai-msg-bubble sup {
    font-size: 0.75em;
    vertical-align: super;
    line-height: 0;
}

.ai-msg-bubble sup a {
    /* Footnote-style sup links: keep subtle styling */
    font-size: 0.85em;
    text-decoration: none;
    color: var(--ai-pri);
    font-weight: 600;
    padding: 0 2px;
}

/* ========== Definition Lists <dl> ========== */
.ai-msg-bubble dl.ai-deflist {
    margin: 12px 0;
    padding: 0;
    border-left: 3px solid var(--ai-sidebar-border);
    padding-left: 16px;
}

.dark-mode .ai-msg-bubble dl.ai-deflist {
    border-left-color: #334155;
}

.ai-msg-bubble dl.ai-deflist dt {
    font-weight: 600;
    color: var(--t1);
    margin-top: 10px;
    font-size: 14px;
}

.ai-msg-bubble dl.ai-deflist dt:first-child {
    margin-top: 0;
}

.ai-msg-bubble dl.ai-deflist dd {
    margin: 4px 0 0;
    padding: 0;
    color: var(--t2);
    font-size: 13.5px;
    line-height: 1.7;
}

/* ========== Footnotes section ========== */
.ai-footnotes {
    margin-top: 24px;
    padding-top: 12px;
    border-top: 1px solid var(--ai-sidebar-border);
    font-size: 12.5px;
    color: var(--t2);
}

.dark-mode .ai-footnotes {
    border-top-color: #334155;
}

.ai-footnotes hr {
    display: none;
}

.ai-footnotes ol {
    padding-left: 20px;
    margin: 0;
}

.ai-footnotes li {
    margin-bottom: 6px;
    line-height: 1.6;
    word-break: break-word;
}

.ai-footnote-ref {
    font-size: 0.75em;
    vertical-align: super;
    line-height: 0;
}

.ai-footnote-ref a {
    text-decoration: none;
    color: var(--ai-pri);
    font-weight: 600;
    padding: 0 2px;
}

.ai-footnote-back {
    text-decoration: none;
    color: var(--ai-pri);
    font-size: 1em;
    margin-left: 4px;
}

/* ========== Math formulas (basic styled code) ========== */
.ai-math-block {
    display: block;
    margin: 14px auto;
    padding: 14px 18px;
    background: linear-gradient(135deg, rgba(29, 91, 255, 0.06) 0%, rgba(0, 199, 255, 0.04) 100%);
    border-left: 3px solid var(--ai-pri);
    border-radius: 0 10px 10px 0;
    overflow-x: auto;
    text-align: center;
}

.dark-mode .ai-math-block {
    background: rgba(99, 102, 241, 0.1);
}

.ai-math-block code {
    font-family: "SF Mono", "Fira Code", "JetBrains Mono", "Cambria Math", Consolas, monospace;
    font-size: 14px;
    color: var(--t1);
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    white-space: pre;
}

.ai-math-inline {
    display: inline;
    padding: 1px 5px;
    margin: 0 1px;
    border-radius: 4px;
    background: rgba(29, 91, 255, 0.08);
}

.ai-math-inline code {
    font-family: "SF Mono", "Fira Code", "JetBrains Mono", "Cambria Math", Consolas, monospace;
    font-size: 0.92em;
    color: var(--ai-pri-d);
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
}

.dark-mode .ai-math-inline {
    background: rgba(99, 102, 241, 0.15);
}

.dark-mode .ai-math-inline code {
    color: var(--ai-pri-l);
}

/* ========== Links inside paragraphs: subtle spacing ========== */
.ai-msg-bubble p a code,
.ai-msg-bubble li a code {
    /* inline code inside link stays readable */
    color: inherit;
}

/* ========== Image styling refinement ========== */
.ai-msg-bubble img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 8px 0;
    display: block;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.dark-mode .ai-msg-bubble img {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ========== Bold/italic combinations ========== */
.ai-msg-bubble strong em,
.ai-msg-bubble em strong {
    font-weight: 700;
    font-style: italic;
}

/* ========== Heading anchor link styling (for id-based jumps) ========== */
.ai-msg-bubble h1[id],
.ai-msg-bubble h2[id],
.ai-msg-bubble h3[id],
.ai-msg-bubble h4[id],
.ai-msg-bubble h5[id],
.ai-msg-bubble h6[id] {
    scroll-margin-top: 80px;
}

/* ========== Blockquote list spacing fix ========== */
.ai-msg-bubble blockquote li {
    margin-bottom: 4px;
}

/* ========== Inline code inside table cells ========== */
.ai-markdown-table code {
    background: rgba(29, 91, 255, 0.1);
    color: var(--ai-pri-d);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.92em;
    border: 1px solid rgba(29, 91, 255, 0.15);
}

.dark-mode .ai-markdown-table code {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.2);
    color: var(--ai-pri-l);
}

/* ========== Hard line break <br> ========== */
.ai-msg-bubble br {
    line-height: 1.7;
}

/* ========== Mobile adjustments for new elements ========== */
@media (max-width: 768px) {
    .ai-msg-bubble kbd,
    .ai-kbd {
        font-size: 11px;
        padding: 1px 5px;
    }

    .ai-math-block {
        padding: 10px 12px;
        font-size: 12px;
    }

    .ai-table-wrap {
        margin: 10px -8px;
    }

    .ai-footnotes {
        font-size: 11.5px;
    }

    .ai-msg-bubble dl.ai-deflist {
        padding-left: 12px;
    }
}



/* ========== Load Earlier Button ========== */
.ai-load-earlier-btn {
    align-self: center;
    padding: 6px 18px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--card);
    color: var(--t2);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 8px;
}
.ai-load-earlier-btn:hover {
    background: var(--pri-bg);
    color: var(--pri);
    border-color: var(--pri);
}

/* ========== 文案库参考（grounding） ========== */
.ai-ref-strip {
    display: flex;
    gap: 6px;
    padding: 6px 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
    align-items: center;
    background: var(--ai-pri-bg);
    border: 1px solid var(--ai-sidebar-border);
    border-radius: 12px;
    animation: ai-toolbar-slide-in 0.25s ease;
}

.dark-mode .ai-ref-strip {
    border-color: #334155;
}

.ai-ref-strip-label {
    font-size: 12px;
    color: var(--t3);
    padding-left: 2px;
}

.ai-ref-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 240px;
    padding: 4px 6px 4px 10px;
    border-radius: 8px;
    background: var(--ai-bot-bg);
    border: 1px solid var(--ai-sidebar-border);
    color: var(--t2);
    font-size: 12.5px;
}

.dark-mode .ai-ref-chip {
    background: rgba(255, 255, 255, 0.04);
    border-color: #334155;
}

.ai-ref-chip-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-ref-chip-remove {
    flex: none;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--t3);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease;
}

.ai-ref-chip-remove:hover {
    background: var(--ai-pri-bg);
    color: var(--ai-pri);
}

/* 助手气泡下方的来源条 */
.ai-msg-refs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 6px;
}

.ai-msg-refs-label {
    font-size: 11.5px;
    color: var(--t3);
}

.ai-msg-ref-chip {
    display: inline-block;
    max-width: 200px;
    padding: 2px 9px;
    border-radius: 20px;
    border: 1px solid var(--ai-sidebar-border);
    background: var(--ai-bot-bg);
    color: var(--t2);
    font-size: 11.5px;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.ai-msg-ref-chip:hover {
    color: var(--ai-pri);
    border-color: var(--ai-pri-l);
    background: var(--ai-pri-bg);
}

.ai-msg-ref-chip.is-pinned {
    border-color: var(--ai-pri-l);
    color: var(--ai-pri);
}

.dark-mode .ai-msg-ref-chip {
    background: rgba(255, 255, 255, 0.04);
    border-color: #334155;
}

.dark-mode .ai-msg-ref-chip:hover {
    background: rgba(99, 102, 241, 0.12);
}

@media (max-width: 640px) {
    .ai-ref-chip {
        max-width: 160px;
    }

    .ai-msg-ref-chip {
        max-width: 140px;
    }
}
