* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --primary: #4f46e5; --primary-hover: #4338ca; --primary-light: #eef2ff;
    --bg: #f8fafc; --bg-sidebar: #1e293b; --bg-sidebar-hover: #334155;
    --text: #1e293b; --text-light: #64748b; --text-lighter: #94a3b8;
    --border: #e2e8f0; --white: #fff; --user-bubble: #4f46e5;
    --success: #10b981; --error: #ef4444; --warning: #f59e0b;
    --radius: 12px; --radius-sm: 8px; --shadow: 0 1px 3px rgba(0,0,0,.1);
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg); color: var(--text); height: 100vh; overflow: hidden;
}

/* 登录 */
.login-container { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, #667eea, #764ba2); }
.login-box { background: #fff; padding: 40px; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,.2); text-align: center; width: 340px; }
.login-icon { font-size: 48px; margin-bottom: 16px; }
.login-box h2 { font-size: 22px; margin-bottom: 8px; }
.login-box p { color: var(--text-light); margin-bottom: 20px; font-size: 14px; }
.login-box input { width: 100%; padding: 12px; border: 2px solid var(--border); border-radius: 8px; font-size: 15px; margin-bottom: 14px; }
.login-box input:focus { outline: none; border-color: var(--primary); }
.login-box button { width: 100%; padding: 12px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; }
.login-box button:hover { background: var(--primary-hover); }
.login-error { color: var(--error); margin-top: 10px; font-size: 13px; min-height: 18px; }

/* 布局 */
.app-container { display: flex; height: 100vh; }
.sidebar { width: 260px; background: var(--bg-sidebar); color: #cbd5e1; display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 18px; border-bottom: 1px solid rgba(255,255,255,.1); }
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 26px; }
.logo-text { font-size: 17px; font-weight: 700; color: #fff; }

/* 状态卡片 */
.model-status-card { margin: 14px; padding: 12px; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.1); border-radius: 8px; }
.status-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warning); animation: pulse 2s infinite; }
.status-dot.online { background: var(--success); animation: none; }
.status-dot.offline { background: var(--error); animation: none; }
.status-text { font-size: 13px; font-weight: 600; color: #fff; }
.status-detail { font-size: 11px; color: var(--text-lighter); }
.status-row { display: flex; justify-content: space-between; padding: 2px 0; }
.status-row strong { color: #e2e8f0; font-weight: 500; }
.status-refresh-btn { width: 100%; margin-top: 8px; padding: 5px; background: rgba(255,255,255,.1); border: none; border-radius: 5px; color: #cbd5e1; font-size: 11px; cursor: pointer; }
.status-refresh-btn:hover { background: rgba(255,255,255,.2); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* 低配提示 */
.low-mem-tip { margin: 0 14px 14px; padding: 10px 12px; background: rgba(245,158,11,.15); border: 1px solid rgba(245,158,11,.3); border-radius: 8px; display: flex; gap: 8px; align-items: flex-start; }
.tip-icon { font-size: 16px; flex-shrink: 0; }
.tip-text { font-size: 11px; color: #fbbf24; line-height: 1.4; }
.tip-text strong { display: block; color: #fcd34d; font-size: 12px; margin-bottom: 2px; }

.sidebar-actions { padding: 0 14px 14px; }
.btn-new-chat { width: 100%; padding: 10px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 5px; }
.btn-new-chat:hover { background: var(--primary-hover); }

.sidebar-section { padding: 14px; border-top: 1px solid rgba(255,255,255,.05); flex: 1; overflow-y: auto; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-lighter); margin-bottom: 10px; font-weight: 600; }
.quick-actions { display: flex; flex-direction: column; gap: 5px; }
.quick-btn { display: flex; align-items: center; gap: 7px; padding: 8px 10px; background: transparent; border: 1px solid rgba(255,255,255,.1); border-radius: 7px; color: #cbd5e1; font-size: 12px; cursor: pointer; text-align: left; }
.quick-btn:hover { background: var(--bg-sidebar-hover); }
.quick-btn span { font-size: 14px; }

.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.1); }
.model-info { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--text-lighter); }
.model-dot { width: 7px; height: 7px; background: var(--success); border-radius: 50%; }

/* 主内容 */
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { padding: 14px 20px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.topbar-title h1 { font-size: 18px; font-weight: 700; }
.topbar-subtitle { font-size: 12px; color: var(--text-light); }
.icon-btn { padding: 7px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 7px; font-size: 12px; cursor: pointer; color: var(--text); }
.icon-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

/* 聊天 */
.chat-container { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.chat-container::-webkit-scrollbar { width: 5px; }
.chat-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.message { display: flex; gap: 10px; max-width: 88%; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; background: var(--primary-light); }
.message.user .message-avatar { background: var(--primary); }
.message-bubble { padding: 12px 16px; border-radius: 10px; line-height: 1.65; font-size: 13px; word-break: break-word; }
.message.assistant .message-bubble { background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow); border-top-left-radius: 4px; }
.message.user .message-bubble { background: var(--user-bubble); color: #fff; border-top-right-radius: 4px; }
.message-bubble p { margin-bottom: 6px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul { margin: 6px 0; padding-left: 18px; }
.message-bubble li { margin-bottom: 3px; }
.message-bubble code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 3px; font-family: Consolas, monospace; font-size: 12px; }
.message.user .message-bubble code { background: rgba(255,255,255,.2); }

/* 代码块 */
.code-block-wrapper { margin: 10px 0; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; background: #1e293b; }
.code-block-header { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; background: #0f172a; color: #94a3b8; font-size: 11px; }
.code-lang { font-weight: 600; text-transform: uppercase; }
.code-filename { color: #64748b; margin-left: 6px; }
.code-actions { display: flex; gap: 5px; }
.code-action-btn { padding: 3px 8px; background: rgba(255,255,255,.1); border: none; border-radius: 3px; color: #cbd5e1; font-size: 10px; cursor: pointer; }
.code-action-btn:hover { background: rgba(255,255,255,.2); }
.code-block-wrapper pre { margin: 0; padding: 12px; overflow-x: auto; font-family: Consolas, monospace; font-size: 12px; line-height: 1.55; color: #e2e8f0; max-height: 350px; overflow-y: auto; }
.code-block-wrapper pre::-webkit-scrollbar { height: 5px; width: 5px; }
.code-block-wrapper pre::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }

/* 加载 */
.typing-indicator { display: flex; gap: 4px; padding: 6px 0; }
.typing-indicator span { width: 7px; height: 7px; background: var(--text-lighter); border-radius: 50%; animation: typing 1.4s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes typing { 0%,60%,100%{transform:translateY(0);opacity:.4} 30%{transform:translateY(-7px);opacity:1} }
.loading-hint { font-size: 11px; color: var(--text-lighter); margin-top: 5px; font-style: italic; }

/* 上传文件 */
.uploaded-files { padding: 0 20px; display: flex; flex-wrap: wrap; gap: 6px; }
.file-chip { display: flex; align-items: center; gap: 6px; padding: 5px 10px; background: var(--primary-light); border: 1px solid #c7d2fe; border-radius: 15px; font-size: 12px; color: var(--primary); }
.file-chip .remove-file { cursor: pointer; font-weight: bold; opacity: .6; }
.file-chip .remove-file:hover { opacity: 1; }

/* 输入 */
.input-area { padding: 12px 20px 16px; background: #fff; border-top: 1px solid var(--border); }
.input-wrapper { max-width: 850px; margin: 0 auto; }
.input-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.tool-btn { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; cursor: pointer; color: var(--text); }
.tool-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.tool-info { font-size: 11px; color: var(--text-lighter); }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
#messageInput { flex: 1; padding: 12px 14px; border: 2px solid var(--border); border-radius: 10px; font-size: 13px; font-family: inherit; resize: none; max-height: 150px; min-height: 42px; transition: border-color .2s; }
#messageInput:focus { outline: none; border-color: var(--primary); }
.send-btn { width: 42px; height: 42px; background: var(--primary); color: #fff; border: none; border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.send-btn:hover { background: var(--primary-hover); }
.send-btn:disabled { background: var(--text-lighter); cursor: not-allowed; }

/* 模态框 */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,.5); z-index: 1000; align-items: center; justify-content: center; }
.modal.active { display: flex; }
.modal-content { background: #fff; border-radius: 10px; width: 90%; max-width: 750px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-title { font-weight: 600; font-size: 14px; }
.modal-actions { display: flex; gap: 6px; }
.modal-btn { padding: 5px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; cursor: pointer; }
.modal-btn:hover { background: var(--primary-light); border-color: var(--primary); }
.modal-btn.close:hover { background: #fee2e2; border-color: var(--error); color: var(--error); }
.modal-body { flex: 1; overflow: auto; padding: 18px; }
.code-display { background: #1e293b; color: #e2e8f0; padding: 14px; border-radius: 7px; font-family: Consolas, monospace; font-size: 12px; line-height: 1.55; white-space: pre-wrap; word-break: break-all; margin: 0; }

/* Toast */
.toast { position: fixed; top: 16px; right: 16px; padding: 10px 16px; background: var(--text); color: #fff; border-radius: 7px; font-size: 13px; z-index: 2000; opacity: 0; transform: translateY(-15px); transition: all .3s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }

@media (max-width: 768px) {
    .sidebar { display: none; }
    .message { max-width: 95%; }
    .topbar { padding: 10px 14px; }
    .chat-container { padding: 14px; }
    .input-area { padding: 10px 14px 14px; }
}
