/* ============================================================
   BioAce - Doubao-style UI (豆包风格)
   ============================================================ */

:root {
    --bg-primary: #f5f5f5;
    --bg-sidebar: #f0f0f0;
    --bg-white: #ffffff;
    --bg-chat: #fafafa;
    --bg-user-msg: #e8f4fd;
    --bg-ai-msg: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-hint: #999999;
    --border-color: #e5e5e5;
    --accent: #4f6ef7;
    --accent-hover: #3b5de7;
    --accent-light: #eef1ff;
    --danger: #e74c3c;
    --success: #27ae60;
    --warning: #f39c12;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --sidebar-width: 280px;
    --topbar-height: 56px;
    --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.6;
}

/* App Container */
.app-container { display: flex; height: 100vh; width: 100vw; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-width); min-width: var(--sidebar-width);
    background: var(--bg-sidebar); border-right: 1px solid var(--border-color);
    display: flex; flex-direction: column; overflow: hidden;
    transition: width var(--transition), min-width var(--transition), opacity var(--transition);
}
.sidebar.collapsed { width: 0; min-width: 0; opacity: 0; border-right: none; }
.sidebar.dragging { transition: none; }  /* 拖拽时关闭动画，跟手 */

/* 侧边栏拖拽手柄 */
.sidebar-resize-handle {
    width: 6px; min-width: 6px;
    background: transparent;
    cursor: col-resize;
    position: relative;
    z-index: 10;
    transition: background 0.15s;
}
.sidebar-resize-handle:hover,
.sidebar-resize-handle.active {
    background: var(--border-color);
}
.sidebar-resize-handle::after {
    content: '';
    position: absolute; top: 0; bottom: 0; left: 50%;
    width: 2px; transform: translateX(-50%);
    background: transparent;
    transition: background 0.15s;
}
.sidebar-resize-handle:hover::after,
.sidebar-resize-handle.active::after {
    background: var(--primary-color);
}
.sidebar-header { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.logo-icon { font-size: 28px; }
.logo-text { font-size: 20px; font-weight: 700; color: var(--text-primary); letter-spacing: -0.5px; }

.btn-new-chat {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; padding: 10px 16px; background: var(--bg-white);
    border: 1px solid var(--border-color); border-radius: var(--radius-md);
    color: var(--text-primary); font-size: 14px; cursor: pointer; transition: all var(--transition);
}
.btn-new-chat:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }

.conversation-list { flex: 1; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; }

.conversation-item {
    padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer;
    transition: background var(--transition); display: flex; align-items: center;
    gap: 8px; font-size: 13px; color: var(--text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conversation-item:hover { background: var(--bg-white); }
.conversation-item.active { background: var(--bg-white); color: var(--text-primary); font-weight: 500; box-shadow: var(--shadow-sm); }
.conversation-item .conv-icon { font-size: 16px; flex-shrink: 0; }
.conversation-item .conv-preview { overflow: hidden; text-overflow: ellipsis; }
.conversation-item .conv-delete { margin-left: auto; padding: 2px 6px; border-radius: 4px; color: var(--text-hint); font-size: 14px; flex-shrink: 0; display: none; background: none; border: none; cursor: pointer; }
.conversation-item:hover .conv-delete { display: block; }
.conversation-item .conv-delete:hover { background: rgba(231,76,60,0.1); color: var(--danger); }

.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border-color); }
.user-info { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-light); display: flex; align-items: center; justify-content: center; font-size: 18px; }
.user-name { font-size: 13px; color: var(--text-secondary); }

/* Main Content */
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100vh; }

/* Top Bar */
.top-bar { height: var(--topbar-height); display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid var(--border-color); background: var(--bg-white); gap: 12px; flex-shrink: 0; }
.btn-toggle-sidebar {
    width: 36px; height: 36px;
    background: transparent; border: 1px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer; color: var(--text-hint);
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s ease;
}
.btn-toggle-sidebar:hover {
    background: var(--bg-primary); color: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.15);
    transform: scale(1.08);
}
.conversation-title { flex: 1; font-size: 16px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-badge { font-size: 12px; padding: 4px 10px; background: var(--accent-light); color: var(--accent); border-radius: 20px; font-weight: 500; }

/* Chat Container */
.chat-container { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; background: var(--bg-chat); }

/* Welcome Screen */
.welcome-screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px 20px; max-width: 700px; margin: 0 auto; width: 100%; }
.welcome-icon { font-size: 64px; margin-bottom: 16px; }
.welcome-screen h2 { font-size: 28px; font-weight: 700; margin-bottom: 8px; color: var(--text-primary); }
.welcome-subtitle { color: var(--text-secondary); font-size: 15px; margin-bottom: 32px; }
.welcome-features { display: flex; gap: 16px; margin-bottom: 36px; flex-wrap: wrap; justify-content: center; }
.feature-card { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 20px 24px; background: var(--bg-white); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); min-width: 150px; transition: all var(--transition); }
.feature-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.feature-icon { font-size: 28px; }
.feature-card span:nth-child(2) { font-weight: 600; font-size: 14px; color: var(--text-primary); }
.feature-card small { color: var(--text-hint); font-size: 12px; }
.quick-prompts { width: 100%; }
.quick-prompts-title { font-size: 13px; color: var(--text-hint); margin-bottom: 12px; }
.prompt-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.prompt-chip { padding: 8px 16px; background: var(--bg-white); border: 1px solid var(--border-color); border-radius: 20px; font-size: 13px; color: var(--text-secondary); cursor: pointer; transition: all var(--transition); white-space: nowrap; }
.prompt-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* File card (豆包风格) */
.file-card { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--bg-white); border: 1px solid var(--border-color); border-radius: var(--radius-md); max-width: 260px; cursor: default; }
.file-card-icon { font-size: 28px; flex-shrink: 0; }
.file-card-info { display: flex; flex-direction: column; min-width: 0; }
.file-card-name { font-size: 13px; font-weight: 500; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card-type { font-size: 11px; color: var(--text-hint); }

/* Messages */
.messages-list { display: flex; flex-direction: column; gap: 20px; max-width: 800px; width: 100%; margin: 0 auto; padding-bottom: 20px; }
.message { display: flex; gap: 0; animation: fadeInUp 0.3s ease; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }
.message-body { max-width: 85%; min-width: 0; }
.message-content { padding: 12px 16px; border-radius: var(--radius-md); font-size: 14px; line-height: 1.8; word-break: break-word; overflow-wrap: break-word; }
.message.user .message-content { background: var(--bg-user-msg); border-bottom-right-radius: 4px; }
.message.assistant .message-content { background: var(--bg-ai-msg); border-bottom-left-radius: 4px; box-shadow: var(--shadow-sm); }
.message.assistant .message-content h1 { font-size: 1.4em; margin: 16px 0 8px; }
.message.assistant .message-content h2 { font-size: 1.2em; margin: 14px 0 6px; }
.message.assistant .message-content h3 { font-size: 1.1em; margin: 12px 0 4px; }
.message.assistant .message-content p { margin: 8px 0; }
.message.assistant .message-content ul, .message.assistant .message-content ol { margin: 8px 0; padding-left: 20px; }
.message.assistant .message-content li { margin: 4px 0; }
.message.assistant .message-content code { background: #f0f0f0; padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.message.assistant .message-content pre { background: #f5f5f5; padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; margin: 8px 0; }
.message.assistant .message-content pre code { background: none; padding: 0; }
.message.assistant .message-content table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.message.assistant .message-content th, .message.assistant .message-content td { border: 1px solid var(--border-color); padding: 8px 12px; text-align: left; }
.message.assistant .message-content th { background: #f0f4ff; font-weight: 600; }
.message.assistant .message-content blockquote { border-left: 3px solid var(--accent); margin: 8px 0; color: var(--text-secondary); background: var(--accent-light); padding: 8px 12px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.message-actions { display: flex; gap: 8px; margin-top: 6px; opacity: 0; transition: opacity 0.2s; }
.message:hover .message-actions { opacity: 1; }
.message-actions button { background: none; border: none; cursor: pointer; font-size: 12px; color: var(--text-hint); padding: 2px 8px; border-radius: 4px; transition: all 0.2s; }
.message-actions button:hover { background: var(--bg-primary); color: var(--accent); }
.message-time { font-size: 11px; color: var(--text-hint); margin-top: 4px; padding: 0 4px; }

/* Bottom action buttons (copy / download / fullscreen) */
.msg-actions { display: flex; gap: 4px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border-color); }
.msg-actions button { display: flex; align-items: center; gap: 4px; background: none; border: 1px solid var(--border-color); cursor: pointer; font-size: 12px; color: var(--text-secondary); padding: 5px 12px; border-radius: 6px; transition: all 0.15s; }
.msg-actions button:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.msg-actions button.btn-download { background: var(--accent); color: #fff; border-color: var(--accent); }
.msg-actions button.btn-download:hover { background: var(--accent-hover); }

/* Inline suggestion chips (in AI message after upload) */
.suggestion-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.suggestion-chip { padding: 6px 14px; background: var(--accent-light); border: 1px solid var(--accent); border-radius: 16px; font-size: 13px; color: var(--accent); cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.suggestion-chip:hover { background: var(--accent); color: #fff; }

/* Streaming indicator */
.streaming-indicator { display: inline-block; width: 8px; height: 8px; background: var(--accent); border-radius: 50%; margin-left: 4px; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Input Area */
.input-area { padding: 16px 20px; background: var(--bg-white); border-top: 1px solid var(--border-color); flex-shrink: 0; }
.input-container { max-width: 800px; margin: 0 auto; }
.file-preview { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--accent-light); border-radius: var(--radius-sm); margin-bottom: 8px; font-size: 13px; }
.file-preview-icon { font-size: 16px; }
.file-preview-name { flex: 1; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-preview-remove { background: none; border: none; cursor: pointer; color: var(--text-hint); font-size: 16px; padding: 2px 6px; border-radius: 4px; transition: all var(--transition); }
.file-preview-remove:hover { background: rgba(0,0,0,0.1); color: var(--danger); }
.input-wrapper { display: flex; align-items: flex-end; gap: 8px; background: var(--bg-chat); border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 8px 12px; transition: border-color var(--transition); }
.input-wrapper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.1); }
.btn-attach { background: none; border: none; cursor: pointer; padding: 6px; border-radius: var(--radius-sm); color: var(--text-hint); display: flex; align-items: center; transition: all var(--transition); flex-shrink: 0; }
.btn-attach:hover { color: var(--accent); background: var(--accent-light); }
#messageInput { flex: 1; border: none; background: transparent; font-size: 14px; line-height: 1.6; color: var(--text-primary); resize: none; outline: none; max-height: 120px; font-family: inherit; padding: 4px 0; }
#messageInput::placeholder { color: var(--text-hint); }
.btn-send { background: var(--accent); border: none; cursor: pointer; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; transition: all var(--transition); flex-shrink: 0; }
.btn-send:hover { background: var(--accent-hover); transform: scale(1.05); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
/* 停止状态：默认蓝色，hover 变红 */
.btn-send.streaming { background: var(--accent); }
.btn-send.streaming:hover { background: var(--danger); }
.btn-send.streaming svg.send-icon { display: none; }
.btn-send.streaming svg.stop-icon { display: block; }
.btn-send svg.stop-icon { display: none; }
.btn-send:not(.streaming) svg.stop-icon { display: none; }
.btn-send:not(.streaming) svg.send-icon { display: block; }
.input-hint { text-align: center; font-size: 11px; color: var(--text-hint); margin-top: 8px; }

/* Loading Overlay */
.loading-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.85); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1000; gap: 16px; }
.loading-spinner { width: 40px; height: 40px; border: 3px solid var(--border-color); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay p { color: var(--text-secondary); font-size: 14px; }

/* Typing indicator */
.typing-indicator { display: flex; gap: 4px; padding: 4px 0; }
.typing-indicator span { width: 6px; height: 6px; background: var(--text-hint); border-radius: 50%; animation: typingBounce 1.4s infinite ease; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* Scroll-to-bottom button (above input area) */
.scroll-to-bottom { width: 32px; height: 32px; border-radius: 50%; background: var(--bg-white); border: 1px solid var(--border-color); box-shadow: 0 2px 8px rgba(0,0,0,0.1); cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text-hint); transition: all 0.2s; margin: 0 auto 10px auto; animation: fadeInDown 0.25s ease; }
.scroll-to-bottom:hover { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: 0 2px 12px rgba(79,110,247,0.3); }
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* JSON block with toolbar */
.json-block { position: relative; background: #f8f9fb; border: 1px solid var(--border-color); border-radius: var(--radius-md); margin: 12px 0; overflow: hidden; }
.json-block-toolbar { display: flex; justify-content: flex-end; gap: 4px; padding: 6px 10px; background: #eef1f7; border-bottom: 1px solid var(--border-color); }
.json-block-toolbar button { background: none; border: none; cursor: pointer; width: 30px; height: 30px; color: var(--text-hint); padding: 0; border-radius: 6px; transition: all 0.15s; display: flex; align-items: center; justify-content: center; }
.json-block-toolbar button:hover { background: rgba(0,0,0,0.06); color: var(--text-primary); }
.json-block-toolbar button.btn-download:hover { color: var(--accent); }
.json-block-body { padding: 12px 16px; max-height: 400px; overflow-y: auto; }
.json-block-body pre { margin: 0; padding: 0; background: transparent; font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 2000; display: flex; align-items: center; justify-content: center; }
.modal-container { background: var(--bg-white); border-radius: var(--radius-lg); width: 90vw; max-width: 900px; max-height: 85vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border-color); }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--text-hint); padding: 4px 8px; border-radius: 4px; transition: all 0.15s; }
.modal-close:hover { background: var(--bg-primary); color: var(--text-primary); }
.modal-body { flex: 1; overflow-y: auto; padding: 20px; font-size: 13px; line-height: 1.8; }
.modal-body pre { margin: 0; white-space: pre-wrap; word-break: break-all; font-size: 12px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d0d0d0; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b0b0b0; }

/* Drop Overlay (拖拽上传) */
.drop-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(79,110,247,0.12); z-index: 999; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.drop-zone { background: var(--bg-white); border: 3px dashed var(--accent); border-radius: var(--radius-xl); padding: 48px 64px; text-align: center; pointer-events: none; }
.drop-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.drop-zone p { font-size: 18px; font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.drop-zone small { font-size: 13px; color: var(--text-hint); }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; box-shadow: var(--shadow-lg); }
    .sidebar.collapsed { left: -280px; width: 280px; min-width: 280px; opacity: 1; }
    .welcome-features { flex-direction: column; }
    .messages-list { padding: 0 8px; }
    .chat-container { padding: 12px; }
}
