/* ===== DeepSeek 风格 - CSS 变量（浅/深主题） ===== */
:root {
  --bg: #ffffff;
  --bg-elevated: #ffffff;
  --bg-sidebar: #f9fbff;
  --bg-hover: #f2f4f8;
  --bg-input: #f4f6fa;
  --bg-bubble-user: #e8f0fe;
  --text: #1a1a1a;
  --text-secondary: #666;
  --text-tertiary: #999;
  --border: #e5e7eb;
  --accent: #4d6bfe;
  --accent-hover: #3b5bff;
  --code-bg: #f6f8fa;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
  --font-size: 16px;
}
[data-theme="dark"] {
  --bg: #1a1a1a;
  --bg-elevated: #252525;
  --bg-sidebar: #171717;
  --bg-hover: #2a2a2a;
  --bg-input: #2a2a2a;
  --bg-bubble-user: #2c3a5c;
  --text: #e8e8e8;
  --text-secondary: #aaa;
  --text-tertiary: #777;
  --border: #333;
  --accent: #5b7cfa;
  --accent-hover: #7090ff;
  --code-bg: #1e1e1e;
  --shadow: 0 2px 12px rgba(0,0,0,.3);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: var(--font-size);
  line-height: 1.6; transition: background .2s, color .2s;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { outline: none; border: none; }

/* ===== 登录页 ===== */
.login-page { display: flex; align-items: center; justify-content: center; background: var(--bg-sidebar); padding: 20px; }
.login-wrap { width: 100%; max-width: 400px; }
.login-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 16px; padding: 40px 32px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 32px; }
.brand-logo { color: var(--accent); }
.brand h1 { font-size: 24px; margin: 0; font-weight: 600; }
#loginForm h2, #changeForm h2 { margin: 0 0 6px; font-size: 20px; }
.sub { color: var(--text-secondary); margin: 0 0 24px; font-size: 14px; }
.login-card label { display: block; font-size: 13px; color: var(--text-secondary); margin: 14px 0 6px; }
.login-card input { width: 100%; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text); }
.login-card input:focus { border-color: var(--accent); }
.primary { width: 100%; padding: 12px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 500; margin-top: 22px; }
.primary:hover { background: var(--accent-hover); }
.primary:disabled { opacity: .6; }
.err { color: #e53; font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ===== 应用骨架 ===== */
.app-shell { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar { width: 260px; flex-shrink: 0; background: var(--bg-sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; transition: transform .25s; z-index: 30; }
.side-head { padding: 16px; display: flex; align-items: center; gap: 8px; }
.new-chat-btn { flex: 1; display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 500; }
.new-chat-btn:hover { background: var(--accent-hover); }
.side-close { display: none; }
.side-search { margin: 0 16px 8px; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 8px; background: var(--bg-input); color: var(--text-tertiary); }
.side-search input { background: none; flex: 1; color: var(--text); font-size: 14px; }
.session-list { flex: 1; overflow-y: auto; padding: 8px; }
.session-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 2px; position: relative; }
.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: var(--bg-hover); }
.session-item .s-icon { color: var(--text-tertiary); flex-shrink: 0; }
.session-item .s-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.session-item .s-del { display: none; color: var(--text-tertiary); padding: 2px; }
.session-item:hover .s-del { display: block; }
.session-item .s-del:hover { color: #e53; }
.side-foot { border-top: 1px solid var(--border); padding: 8px; }
.side-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.side-item:hover { background: var(--bg-hover); }
.avatar-small { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.topbar { height: 56px; flex-shrink: 0; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.icon-btn { padding: 8px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--bg-hover); }
#openSidebar { display: none; }
.top-title { flex: 1; font-weight: 500; text-align: center; }
.top-actions { display: flex; gap: 4px; }

/* 欢迎页 */
.welcome { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; text-align: center; }
.welcome-logo { color: var(--accent); margin-bottom: 20px; }
.welcome h1 { font-size: 26px; margin: 0 0 12px; font-weight: 600; }
.welcome p { color: var(--text-secondary); margin: 0; max-width: 500px; }

/* 消息区 */
.messages { flex: 1; overflow-y: auto; padding: 24px 0; scroll-behavior: smooth; }
.msg-row { max-width: 800px; margin: 0 auto; padding: 12px 24px; display: flex; gap: 16px; }
.msg-row.user { flex-direction: row-reverse; }
.msg-avatar { width: 32px; height: 32px; flex-shrink: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; }
.msg-avatar.ai { background: var(--accent); color: #fff; }
.msg-avatar.user { background: var(--bg-hover); color: var(--text); }
.msg-content { flex: 1; min-width: 0; }
.msg-row.user .msg-content { display: flex; justify-content: flex-end; }
.bubble { display: inline-block; max-width: 100%; }
.msg-row.user .bubble { background: var(--bg-bubble-user); padding: 10px 16px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; word-break: break-word; }
.msg-row.assistant .bubble { padding: 0; }

/* 思考链 */
.reasoning { border-left: 2px solid var(--border); padding: 4px 0 4px 14px; margin-bottom: 12px; color: var(--text-secondary); font-size: .9em; }
.reasoning-head { display: flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 500; color: var(--text-secondary); user-select: none; }
.reasoning-body { white-space: pre-wrap; word-break: break-word; margin-top: 8px; }
.reasoning.collapsed .reasoning-body { display: none; }

/* Markdown 内容 */
.md { word-break: break-word; line-height: 1.75; }
.md p { margin: 0 0 12px; }
.md p:last-child { margin-bottom: 0; }
.md h1,.md h2,.md h3 { margin: 20px 0 10px; line-height: 1.4; }
.md ul,.md ol { padding-left: 24px; margin: 0 0 12px; }
.md li { margin: 4px 0; }
.md a { color: var(--accent); }
.md blockquote { border-left: 3px solid var(--border); margin: 12px 0; padding: 4px 16px; color: var(--text-secondary); }
.md code { background: var(--code-bg); padding: 2px 6px; border-radius: 4px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; }
.md pre { background: var(--code-bg); border-radius: 8px; padding: 16px; overflow-x: auto; margin: 12px 0; position: relative; }
.md pre code { background: none; padding: 0; }
.copy-code { position: absolute; top: 8px; right: 8px; padding: 4px 8px; border-radius: 6px; background: var(--bg-elevated); border: 1px solid var(--border); font-size: 12px; color: var(--text-secondary); }
.md table { border-collapse: collapse; margin: 12px 0; width: 100%; }
.md th,.md td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.md th { background: var(--bg-hover); }
.msg-actions { display: flex; gap: 4px; margin-top: 8px; }
.msg-actions button { padding: 4px 8px; border-radius: 6px; color: var(--text-tertiary); }
.msg-actions button:hover { background: var(--bg-hover); color: var(--text); }

.typing-cursor { display: inline-block; width: 8px; height: 18px; background: var(--accent); vertical-align: middle; animation: blink 1s infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }

/* 输入区 */
.composer-wrap { flex-shrink: 0; padding: 0 24px 12px; max-width: 848px; width: 100%; margin: 0 auto; }
.composer { border: 1px solid var(--border); border-radius: 18px; background: var(--bg-elevated); box-shadow: var(--shadow); padding: 12px; }
.composer:focus-within { border-color: var(--accent); }
.composer textarea { width: 100%; resize: none; background: none; color: var(--text); max-height: 160px; min-height: 28px; padding: 4px 4px 8px; line-height: 1.5; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.composer-left, .composer-right { display: flex; align-items: center; gap: 4px; }
.chip { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 10px; color: var(--text-secondary); font-size: 13px; }
.chip:hover { background: var(--bg-hover); }
.chip.active { background: var(--bg-bubble-user); color: var(--accent); }
.send-btn { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: var(--border); color: var(--text-tertiary); cursor: not-allowed; }
.send-btn.stop { background: var(--text); }
.attachment-preview { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.attachment-preview img { height: 60px; border-radius: 8px; }
.disclaimer { text-align: center; color: var(--text-tertiary); font-size: 12px; padding: 8px 0 2px; }

/* 抽屉/弹窗 */
.overlay { position: absolute; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
.drawer { position: absolute; top: 0; right: 0; bottom: 0; width: 340px; max-width: 90vw; background: var(--bg-elevated); z-index: 50; box-shadow: -2px 0 20px rgba(0,0,0,.15); display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 8px 20px 32px; }
.set-group { padding: 16px 0; border-bottom: 1px solid var(--border); }
.set-label { font-weight: 500; margin-bottom: 12px; display: flex; justify-content: space-between; }
.set-value { color: var(--text-tertiary); font-weight: 400; }
.seg { display: flex; background: var(--bg-input); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; padding: 8px; border-radius: 8px; color: var(--text-secondary); }
.seg button.active { background: var(--bg-elevated); color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.1); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.set-group select, .set-group textarea { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text); }
.switch-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; font-size: 14px; }
.switch-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { color: var(--text-tertiary); font-size: 12px; margin-top: 8px; }
.secondary { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text); margin-top: 8px; }
.secondary:hover { background: var(--bg-hover); }
.secondary.danger { color: #e53; }
.secondary.small { width: auto; padding: 6px 12px; margin-top: 8px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: var(--bg-elevated); border-radius: 16px; padding: 28px; width: 100%; max-width: 360px; }
.modal-card h2 { margin: 0 0 20px; font-size: 20px; }
.modal-card label { display: block; font-size: 13px; color: var(--text-secondary); margin: 12px 0 6px; }
.modal-card input { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions button { flex: 1; margin: 0; }

.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 20px; border-radius: 8px; z-index: 100; font-size: 14px; }

/* 移动端 */
@media (max-width: 768px) {
  .sidebar { position: absolute; left: 0; top: 0; bottom: 0; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .side-close { display: flex; }
  #openSidebar { display: flex; }
  .msg-row { padding: 12px 16px; gap: 10px; }
  .composer-wrap { padding: 0 12px 8px; }
  .chip span { display: inline; font-size: 12px; }
  .chip-think span, #webBtn span { display: inline; }
  .welcome h1 { font-size: 20px; }
  .welcome p { font-size: 14px; padding: 0 12px; }
}
