/* N V16 — Calm Intelligence / Premium Minimalism */
/* 设计语言：深色石墨黑+深灰+柔和白；浅色暖白+浅灰+低饱和辅助色；N橙 #ff7500 仅小面积点缀 */
/* 主题契约：:root 为浅色默认；html 无 .light 时匹配 app.js 默认深色；.light 为浅色；.contrast 为高对比 */
/* 兼容扩展：body.dark / body.light / [data-theme=dark] / [data-theme=light] / [data-theme=contrast] */

:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'ss01';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  --bg: #f7f5f1;
  --bg-deep: #f0eee9;
  --panel: #fffdfa;
  --panel-2: #f2f0ec;
  --hover: #ebe8e2;
  --border: #ded9d1;
  --border-soft: #e8e4dc;
  --border-strong: #cbc5bb;
  --text: #1e2024;
  --text-2: #545a63;
  --muted: #777e88;
  --faint: #9aa0a8;
  --accent: #ff7500;
  --accent-hover: #e96b00;
  --accent-ink: #fff8f2;
  --accent-soft: rgba(255, 117, 0, .09);
  --accent-softer: rgba(255, 117, 0, .045);
  --accent-border: rgba(255, 117, 0, .28);
  --ok: #3f8f66;
  --danger: #b84c48;
  --warn: #9a6b1f;
  --code-bg: #f1efe9;
  --scrim: rgba(18, 20, 24, .42);
  --r-xs: 5px;
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-pill: 999px;
  --ease: cubic-bezier(.22, .61, .36, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --t-fast: 140ms var(--ease);
  --t: 200ms var(--ease);
  --t-slow: 320ms var(--ease-out);
  --shadow: 0 1px 2px rgba(28, 25, 20, .06), 0 1px 1px rgba(28, 25, 20, .04);
  --shadow-raise: 0 10px 30px rgba(28, 25, 20, .12), 0 2px 6px rgba(28, 25, 20, .08);
  --shadow-focus: 0 0 0 3px var(--accent-soft);
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  --sidebar-w: 268px;
  --content-max: 760px;
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* app.js applyTheme: documentElement.classList.toggle('light', !dark) */
/* 无 .light 即深色默认，与 state.settings.dark=true 保持一致 */
:root:not(.light):not([data-theme=light]), body.dark, [data-theme=dark] {
  color-scheme: dark;
  --bg: #14161a;
  --bg-deep: #101216;
  --panel: #191c22;
  --panel-2: #20242b;
  --hover: #252a32;
  --border: #2a2f38;
  --border-soft: #23272f;
  --border-strong: #363c47;
  --text: #eceef2;
  --text-2: #aeb4bf;
  --muted: #7d8490;
  --faint: #565d68;
  --accent: #ff7500;
  --accent-hover: #ff8a26;
  --accent-ink: #1b0d02;
  --accent-soft: rgba(255, 117, 0, .10);
  --accent-softer: rgba(255, 117, 0, .055);
  --accent-border: rgba(255, 117, 0, .34);
  --ok: #6fbf8b;
  --danger: #e0736f;
  --warn: #d8a24a;
  --code-bg: #111419;
  --scrim: rgba(4, 5, 7, .58);
  --shadow: 0 1px 2px rgba(0, 0, 0, .28), 0 1px 1px rgba(0, 0, 0, .12);
  --shadow-raise: 0 10px 30px rgba(0, 0, 0, .34), 0 2px 6px rgba(0, 0, 0, .20);
  --shadow-focus: 0 0 0 3px var(--accent-soft);
}

.light, :root.light, body.light, [data-theme=light] {
  color-scheme: light;
  --bg: #f7f5f1;
  --bg-deep: #f0eee9;
  --panel: #fffdfa;
  --panel-2: #f2f0ec;
  --hover: #ebe8e2;
  --border: #ded9d1;
  --border-soft: #e8e4dc;
  --border-strong: #cbc5bb;
  --text: #1e2024;
  --text-2: #545a63;
  --muted: #777e88;
  --faint: #9aa0a8;
  --accent: #ff7500;
  --accent-hover: #e96b00;
  --accent-ink: #fff8f2;
  --accent-soft: rgba(255, 117, 0, .09);
  --accent-softer: rgba(255, 117, 0, .045);
  --accent-border: rgba(255, 117, 0, .28);
  --ok: #3f8f66;
  --danger: #b84c48;
  --warn: #9a6b1f;
  --code-bg: #f1efe9;
  --scrim: rgba(18, 20, 24, .42);
  --shadow: 0 1px 2px rgba(28, 25, 20, .06), 0 1px 1px rgba(28, 25, 20, .04);
  --shadow-raise: 0 10px 30px rgba(28, 25, 20, .12), 0 2px 6px rgba(28, 25, 20, .08);
  --shadow-focus: 0 0 0 3px var(--accent-soft);
}

.contrast, body.contrast, [data-theme=contrast], .contrast.light {
  color-scheme: dark;
  --bg: #000;
  --bg-deep: #000;
  --panel: #101010;
  --panel-2: #181818;
  --hover: #222;
  --border: #555;
  --border-soft: #3a3a3a;
  --border-strong: #777;
  --text: #fff;
  --text-2: #f2f2f2;
  --muted: #ddd;
  --faint: #c4c4c4;
  --accent: #ffd43b;
  --accent-hover: #ffe066;
  --accent-ink: #000;
  --accent-soft: rgba(255, 212, 59, .16);
  --accent-softer: rgba(255, 212, 59, .08);
  --accent-border: #ffd43b;
  --ok: #6ee7a2;
  --danger: #ff8f8a;
  --warn: #ffd43b;
  --code-bg: #080808;
  --scrim: rgba(0, 0, 0, .78);
  --shadow: none;
  --shadow-raise: none;
  --shadow-focus: 0 0 0 3px var(--accent-soft);
}

* { box-sizing: border-box; }
*::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; width: 100%; max-width: 100%; background: var(--bg); color: var(--text); }
html { height: 100%; overflow: hidden; scroll-behavior: smooth; }
body { height: 100dvh; min-height: 100dvh; overflow: hidden; overscroll-behavior: none; font-size: 15px; line-height: 1.6; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
svg { display: block; flex: none; }
a { color: var(--text-2); text-decoration-color: var(--accent-border); text-underline-offset: 3px; transition: color var(--t-fast), text-decoration-color var(--t-fast); }
a:hover { color: var(--text); text-decoration-color: var(--accent); }
::selection { background: var(--accent-soft); color: var(--text); }
:where(button, a, input, select, textarea, [tabindex]):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: var(--shadow-focus); }
button:not(:disabled):active { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: .45; }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border: 2px solid transparent; background-clip: padding-box; border-radius: var(--r-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); border: 2px solid transparent; background-clip: padding-box; }

/* ID 兼容锚点：保留 index.html 与 app.js 使用的 id 名称，不改变 DOM 行为 */
#drawerScrim, #sidebar, #drawerClose, #newChat, #memoryBtn, #darkMode, #darkMode2, #themeLabel, #drawerOpen, #status, #statusDesktop, #modelPicker, #chatScroll, #welcome, #messages, #composerZone, #imagePreview, #searchModeHint, #pickImage, #fileInput, #promptInput, #sendBtn, #cardsList, #inviteCode, #pairDevice, #familyStatus, #deviceInfo, #settingsForm, #serverUrl, #testConnection, #settingsStatus, #contrastMode, #exportDataBtn, #importDataBtn, #importDataFile, #dataSyncStatus, #toast, #updateBanner, #updateNow { min-width: 0; max-width: 100%; }

/* ---------- 布局骨架 ---------- */
.layout { display: flex; height: 100dvh; min-height: 100dvh; width: 100%; max-width: 100%; overflow: hidden; background: var(--bg); padding-left: var(--safe-left); padding-right: var(--safe-right); }
.sidebar { width: var(--sidebar-w); flex: none; display: flex; flex-direction: column; background: var(--bg-deep); border-right: 1px solid var(--border); transition: transform var(--t-slow), box-shadow var(--t-slow), background var(--t-slow); z-index: 40; min-height: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 14px 12px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 17px; font-weight: 800; letter-spacing: -.04em; box-shadow: var(--shadow); flex: none; }
.brand-mark.sm { width: 26px; height: 26px; font-size: 15px; border-radius: 8px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-name { font-size: 15px; font-weight: 720; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-close { display: none; }
.new-chat-btn { display: flex; align-items: center; justify-content: flex-start; gap: 8px; margin: 4px 12px 16px; min-width: calc(var(--sidebar-w) - 24px); width: calc(var(--sidebar-w) - 24px); padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--panel); color: var(--text); font-size: 14px; font-weight: 650; cursor: pointer; box-shadow: var(--shadow); transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast); }
.new-chat-btn svg { color: var(--accent); }
.new-chat-btn:hover { background: var(--hover); border-color: var(--accent-border); box-shadow: var(--shadow-raise); }
.new-chat-btn:active { transform: translateY(1px); box-shadow: var(--shadow); }
.side-nav { flex: 1; display: flex; flex-direction: column; gap: 3px; padding: 0 8px; min-width: 0; overflow-y: auto; overscroll-behavior: contain; }
.side-item { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 8px 10px; border: 1px solid transparent; border-radius: var(--r-md); background: transparent; color: var(--text-2); font-size: 14px; text-align: left; cursor: pointer; transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast); }
.side-item:hover { background: var(--panel); color: var(--text); border-color: var(--border-soft); }
.side-item.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }
.side-item.active svg { color: var(--accent); }
.sidebar-foot { padding: 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.theme-switch { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 8px 10px; border-radius: var(--r-md); cursor: pointer; color: var(--text-2); font-size: 14px; user-select: none; transition: background var(--t-fast), color var(--t-fast); }
.theme-switch:hover { background: var(--panel); color: var(--text); }
.theme-switch input { position: absolute; opacity: 0; pointer-events: none; }
.theme-track { width: 34px; height: 20px; border-radius: var(--r-pill); background: var(--panel-2); border: 1px solid var(--border); position: relative; flex: none; transition: background var(--t), border-color var(--t), box-shadow var(--t); }
.theme-thumb { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); box-shadow: var(--shadow); transition: transform var(--t), background var(--t); }
.theme-switch input:checked + .theme-track { background: var(--accent-soft); border-color: var(--accent-border); box-shadow: inset 0 0 0 1px var(--accent-softer); }
.theme-switch input:checked + .theme-track .theme-thumb { transform: translateX(14px); background: var(--accent); }
.theme-label { font-size: 13px; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.desktop-topbar { display: flex; align-items: center; gap: 12px; min-height: calc(50px + var(--safe-top)); padding: calc(9px + var(--safe-top)) 18px 9px; border-bottom: 1px solid var(--border); background: var(--bg); position: relative; z-index: 10; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.mobile-topbar, .mobile-nav, .drawer-scrim { display: none; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 3px var(--accent-softer); transition: background var(--t), box-shadow var(--t); }
.status-pill.connected { color: var(--text-2); }
.status-pill.connected::before { background: var(--ok); box-shadow: 0 0 0 3px rgba(111, 191, 139, .12); }
.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; min-width: 34px; border: 1px solid var(--border); border-radius: var(--r-md); background: transparent; color: var(--text-2); cursor: pointer; transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast); }
.icon-btn:hover { background: var(--panel); color: var(--text); border-color: var(--border-strong); }
.icon-btn:active { transform: translateY(1px); }
.model-picker { height: 34px; padding: 0 28px 0 10px; border: 1px solid var(--border); border-radius: var(--r-md); background-color: var(--panel); color: var(--text-2); font-size: 12.5px; font-family: var(--mono); cursor: pointer; appearance: none; -webkit-appearance: none; background-image: url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2210%22 height=%226%22%3E%3Cpath d=%22M0 0l5 6 5-6z%22 fill=%22%237d8490%22/%3E%3C/svg%3E'); background-repeat: no-repeat; background-position: right 10px center; max-width: 190px; text-overflow: ellipsis; transition: border-color var(--t-fast), color var(--t-fast), background-color var(--t-fast), box-shadow var(--t-fast); }
.model-picker:hover { border-color: var(--accent-border); color: var(--text); }
.model-picker:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; box-shadow: var(--shadow-focus); }
.hidden { display: none !important; }

/* ---------- 视图与聊天滚动 ---------- */
.views { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.view { display: none; flex: 1; min-height: 0; min-width: 0; }
.view.active { display: flex; flex-direction: column; animation: fadeIn 220ms var(--ease-out); }
#cardsView, #familyView, #settingsView { overflow-y: auto; overflow-x: hidden; padding: 28px 22px calc(40px + var(--safe-bottom)); overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
#cardsView > *, #familyView > *, #settingsView > * { max-width: 680px; margin-left: auto; margin-right: auto; width: 100%; min-width: 0; }
#chatView { overflow: hidden; position: relative; }
.chat-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; min-width: 0; width: 100%; padding: 26px 20px 12px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.chat-scroll > * { min-width: 0; max-width: 100%; }
.chat-scroll::-webkit-scrollbar { width: 6px; }
.chat-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
#chatView.is-home { justify-content: center; }
#chatView.is-home .chat-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; justify-content: center; align-items: center; padding-bottom: 12px; }

/* ---------- 欢迎区 ---------- */
.welcome { max-width: 640px; margin: auto; width: 100%; min-width: 0; padding: 8px 0 18px; }
.welcome.hidden { display: none; }
.welcome-mark { width: 44px; height: 44px; border-radius: 13px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 23px; font-weight: 800; letter-spacing: -.05em; margin-bottom: 22px; box-shadow: 0 8px 22px rgba(0, 0, 0, .18); }
.welcome-title { font-size: clamp(21px, 5.2vw, 26px); font-weight: 720; letter-spacing: -.035em; line-height: 1.25; margin: 0 0 8px; color: var(--text); }
.welcome-sub { color: var(--muted); font-size: 14px; line-height: 1.7; margin: 0 0 24px; max-width: 52ch; }
.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.quick { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; min-height: 52px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--panel); color: var(--text-2); font-size: 13.5px; text-align: left; cursor: pointer; box-shadow: var(--shadow); transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast); }
.quick:hover { border-color: var(--accent-border); background: var(--hover); color: var(--text); box-shadow: var(--shadow-raise); }
.quick:active { transform: translateY(1px); box-shadow: var(--shadow); }
.quick-a { color: var(--faint); transition: color var(--t-fast), transform var(--t-fast); flex: none; }
.quick:hover .quick-a { color: var(--accent); transform: translate(1px, -1px); }

/* ---------- 消息流 ---------- */
.messages { max-width: var(--content-max); margin: 0 auto; width: 100%; min-width: 0; display: flex; flex-direction: column; gap: 18px; padding-bottom: 12px; }
.msg { overflow-wrap: anywhere; min-width: 0; max-width: 100%; animation: riseIn 220ms var(--ease-out); margin-bottom: 0; }
.msg.user { align-self: flex-end; max-width: 78%; background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: var(--r-lg) var(--r-lg) var(--r-xs) var(--r-lg); padding: 10px 14px; box-shadow: var(--shadow); }
.msg.user .role { display: none; }
.msg.assistant { align-self: stretch; max-width: 100%; padding-left: 14px; border-left: 2px solid var(--border-soft); }
.role { font-size: 11px; font-weight: 700; letter-spacing: .10em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }
.msg-text { font-size: 15px; line-height: 1.76; color: var(--text); white-space: normal; min-width: 0; max-width: 100%; }
.msg-text p { margin: 0 0 10px; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text a { color: var(--text-2); text-decoration: underline; text-decoration-color: var(--accent-border); text-underline-offset: 3px; }
.msg-text a:hover { color: var(--accent); text-decoration-color: var(--accent); }
.msg img { max-width: 100%; max-height: 320px; width: auto; height: auto; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--panel); display: block; margin: 10px 0; box-shadow: var(--shadow); object-fit: contain; }

/* Markdown：行内代码、代码块、标题、列表、引用、表格 */
.md-inline { font-family: var(--mono); font-size: .86em; line-height: 1.5; background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: var(--r-xs); padding: 1px 5px; color: var(--text-2); }
.md-code { position: relative; font-family: var(--mono); font-size: 13px; line-height: 1.65; tab-size: 2; background: var(--code-bg); border: 1px solid var(--border-soft); border-left: 2px solid var(--accent-border); border-radius: var(--r-md); padding: 14px 16px; overflow-x: auto; overflow-y: hidden; margin: 12px 0; white-space: pre; max-width: 100%; box-shadow: inset 0 1px 0 rgba(128, 128, 128, .06); }
.md-code code { font-family: inherit; font-size: inherit; color: var(--text); background: transparent; border: 0; padding: 0; }
.md-code::selection, .md-code code::selection { background: var(--accent-soft); color: var(--text); }
.md-h { font-weight: 720; letter-spacing: -.025em; line-height: 1.35; margin: 18px 0 8px; color: var(--text); }
.md-h1 { font-size: 20px; }
.md-h2 { font-size: 18px; }
.md-h3 { font-size: 16px; }
.md-h1, .md-h2 { padding-bottom: 6px; border-bottom: 1px solid var(--border-soft); }
.md-list { margin: 8px 0 12px; padding-left: 22px; color: var(--text); }
.md-list li { margin: 5px 0; padding-left: 2px; }
.md-list li::marker { color: var(--accent); }
.md-quote { margin: 12px 0; padding: 4px 0 4px 14px; border-left: 2px solid var(--accent-border); color: var(--text-2); background: var(--accent-softer); border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.md-table { display: block; width: 100%; max-width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); border-spacing: 0; margin: 12px 0; font-size: 13.5px; background: var(--panel); box-shadow: var(--shadow); }
.md-table thead, .md-table tbody { display: table; width: 100%; min-width: 520px; }
.md-table tr { display: table-row; }
.md-table th, .md-table td { border: 0; border-bottom: 1px solid var(--border-soft); border-right: 1px solid var(--border-soft); padding: 9px 11px; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.md-table th:last-child, .md-table td:last-child { border-right: 0; }
.md-table tbody tr:last-child td { border-bottom: 0; }
.md-table th { background: var(--panel-2); font-weight: 680; color: var(--text); }
.md-table tr:nth-child(even) td { background: var(--accent-softer); }
.md-table tr:hover td { background: var(--hover); }
.md-hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* 消息操作、建议、来源引用 */
.msg-actions, .suggestions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.mini-btn, .suggestion { border: 1px solid var(--border); border-radius: var(--r-pill); padding: 6px 12px; background: transparent; color: var(--muted); font-size: 12px; line-height: 1.3; cursor: pointer; transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast); }
.mini-btn:hover { border-color: var(--accent-border); color: var(--text); background: var(--panel); }
.mini-btn:active, .suggestion:active { transform: translateY(1px); }
.suggestion { color: var(--text-2); background: var(--panel); }
.suggestion:hover { border-color: var(--accent-border); color: var(--accent); background: var(--accent-soft); box-shadow: var(--shadow-focus); }
.sources { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border-soft); display: flex; flex-direction: column; gap: 3px; }
.sources-head { font-size: 11.5px; font-weight: 700; letter-spacing: .04em; color: var(--text-2); margin-bottom: 6px; }
.source-item { display: flex; flex-direction: column; gap: 3px; padding: 8px 10px; border-radius: var(--r-sm); text-decoration: none; color: inherit; border-left: 2px solid transparent; transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast); }
a.source-item:hover { background: var(--panel); border-left-color: var(--accent-border); }
.source-title { font-size: 12.5px; line-height: 1.5; color: var(--text); }
.source-meta { font-size: 10.5px; line-height: 1.45; color: var(--faint); }
.search-error { margin-top: 8px; font-size: 11.5px; line-height: 1.55; color: var(--danger); }
.loading { display: inline-flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.loading::before { content: ''; width: 10px; height: 10px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 760ms linear infinite; }
.thinking, .thinking-state, .status-thinking, .msg.thinking { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 12.5px; letter-spacing: .01em; }
.thinking::before, .thinking-state::before, .status-thinking::before, .msg.thinking::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); animation: thinkingPulse 1.6s var(--ease) infinite; }
.thinking-dots { display: inline-flex; align-items: center; gap: 4px; color: var(--faint); letter-spacing: .12em; }
.thinking-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); display: inline-block; animation: thinkingPulse 1.2s var(--ease) infinite; }
.thinking-dots i:nth-child(2) { animation-delay: 140ms; }
.thinking-dots i:nth-child(3) { animation-delay: 280ms; }
.stream-cursor, .typing-cursor, .cursor, .caret { display: inline-block; width: 2px; height: 1.05em; margin-left: 3px; vertical-align: -.14em; border-radius: 2px; background: var(--accent); animation: caretBlink 1s steps(2, start) infinite; }
.msg.streaming .msg-text::after { content: ''; display: inline-block; width: 2px; height: 1.05em; margin-left: 3px; vertical-align: -.14em; border-radius: 2px; background: var(--accent); animation: caretBlink 1s steps(2, start) infinite; }
.msg.streaming .msg-text { caret-color: var(--accent); }

/* ---------- 输入区 ---------- */
.composer-zone { flex: none; position: relative; z-index: 4; padding: 10px 20px calc(14px + var(--safe-bottom)); max-width: calc(var(--content-max) + 40px); margin: 0 auto; width: 100%; min-width: 0; background: var(--bg); }
#chatView.is-home .composer-zone { padding-bottom: calc(14px + var(--safe-bottom)); }
.image-preview { display: flex; align-items: center; gap: 10px; margin: 0 0 9px; min-width: 0; }
.image-preview img { width: 54px; height: 54px; object-fit: cover; border-radius: var(--r-sm); border: 1px solid var(--border); box-shadow: var(--shadow); }
.image-preview button { border: 1px solid var(--border); background: var(--panel); color: var(--accent); cursor: pointer; font-size: 13px; padding: 6px 10px; border-radius: var(--r-sm); transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast); }
.image-preview button:hover { border-color: var(--accent-border); background: var(--hover); }
.search-mode-row { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; padding: 0 2px 9px; }
.search-mode-chip { border: 1px solid var(--border); background: transparent; color: var(--muted); border-radius: var(--r-pill); padding: 5px 12px; font-size: 11.5px; font-weight: 620; cursor: pointer; transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast); }
.search-mode-chip:hover { color: var(--text-2); border-color: var(--border-strong); background: var(--panel); }
.search-mode-chip:active { transform: translateY(1px); }
.search-mode-chip.on { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent-softer); }
.search-mode-hint { font-size: 10.5px; color: var(--faint); flex: 1 1 100%; line-height: 1.5; }
.composer { display: flex; align-items: flex-end; gap: 6px; min-width: 0; background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-xl); padding: 7px 8px; box-shadow: var(--shadow-raise); transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast), transform var(--t-fast); }
.composer:focus-within { border-color: var(--accent-border); box-shadow: var(--shadow-raise), var(--shadow-focus); }
.tool-btn { display: grid; place-items: center; width: 36px; height: 38px; min-width: 36px; border: 1px solid transparent; border-radius: var(--r-md); background: transparent; color: var(--muted); cursor: pointer; transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast), transform var(--t-fast); }
.tool-btn:hover { color: var(--text); background: var(--hover); border-color: var(--border-soft); }
.tool-btn:active { transform: translateY(1px); }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 140px; min-height: 38px; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 15px; line-height: 1.55; padding: 8px 4px; -webkit-overflow-scrolling: touch; }
.composer textarea::placeholder { color: var(--faint); }
.composer textarea:focus-visible { outline: 0; box-shadow: none; }
.send-btn { display: grid; place-items: center; width: 38px; height: 38px; min-width: 38px; border: 1px solid transparent; border-radius: var(--r-md); background: var(--accent); color: var(--accent-ink); cursor: pointer; box-shadow: var(--shadow); transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast), opacity var(--t-fast), box-shadow var(--t-fast); }
.send-btn:hover { background: var(--accent-hover); box-shadow: var(--shadow-raise); }
.send-btn:active { transform: translateY(1px); box-shadow: var(--shadow); }
.send-btn:disabled { opacity: .35; cursor: default; transform: none; box-shadow: var(--shadow); }

/* ---------- 页面头、表单、卡片 ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin: 0 0 20px; min-width: 0; }
.page-head h2 { font-size: 21px; font-weight: 720; letter-spacing: -.03em; margin: 0 0 5px; }
.page-head p { color: var(--muted); font-size: 13px; margin: 0; }
.text-btn { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 6px 4px; cursor: pointer; border-radius: var(--r-xs); transition: color var(--t-fast), background var(--t-fast); }
.text-btn:hover { color: var(--accent); background: var(--accent-soft); }
.settings-card, .flashcard { background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.settings-card h3 { margin: 0 0 12px; font-size: 14.5px; font-weight: 700; letter-spacing: -.01em; }
.settings-card label { display: block; color: var(--muted); font-size: 12.5px; margin: 12px 0 6px; }
.settings-card input[type=url], .settings-card input[type=password], .settings-card input[type=text] { width: 100%; min-width: 0; padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; font-size: 14px; transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast); }
.settings-card input[type=url] { direction: ltr; }
.settings-card input[type=password] { letter-spacing: .02em; }
.settings-card input[type=text] { direction: ltr; }
.settings-card input:focus { border-color: var(--accent-border); outline: 0; box-shadow: var(--shadow-focus); }
.hint { font-size: 12px; color: var(--muted); line-height: 1.65; }
.primary, .secondary { position: relative; width: 100%; border: 0; border-radius: var(--r-md); padding: 11px 14px; font-size: 14px; font-weight: 680; margin-top: 12px; cursor: pointer; overflow: hidden; transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast); }
.primary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow); }
.primary::after { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 3px; height: 18px; border-radius: 0 3px 3px 0; background: var(--accent); }
.primary:hover { background: var(--hover); border-color: var(--accent-border); color: var(--text); box-shadow: var(--shadow-raise); }
.primary:active { transform: translateY(1px); box-shadow: var(--shadow); }
.secondary { background: transparent; border: 1px solid var(--border); color: var(--text-2); }
.secondary:hover { border-color: var(--accent-border); color: var(--text); background: var(--panel); }
.link-btn { display: block; text-align: center; text-decoration: none; }
.toggle-row { display: flex !important; justify-content: space-between; align-items: center; gap: 14px; padding: 8px 0; }
.toggle-row input { width: 20px; height: 20px; min-width: 20px; accent-color: var(--accent); }
.cards-list { display: flex; flex-direction: column; gap: 12px; }
.flashcard { min-height: 120px; cursor: pointer; user-select: none; transition: border-color var(--t-fast), transform var(--t-fast), background var(--t-fast), box-shadow var(--t-fast); }
.flashcard:hover { border-color: var(--accent-border); transform: translateY(-1px); background: var(--hover); box-shadow: var(--shadow-raise); }
.flashcard .eyebrow { font-size: 11px; letter-spacing: .08em; color: var(--accent); margin-bottom: 8px; font-weight: 700; }
.flashcard .answer { white-space: pre-wrap; line-height: 1.7; font-size: 14px; color: var(--text-2); }
.delete-card { float: right; background: transparent; border: 0; color: var(--faint); cursor: pointer; font-size: 14px; padding: 4px 7px; border-radius: var(--r-xs); transition: color var(--t-fast), background var(--t-fast), transform var(--t-fast); }
.delete-card:hover { color: var(--danger); background: var(--hover); }
.empty { color: var(--muted); text-align: center; padding: 44px 16px; font-size: 13.5px; }

/* ---------- Toast 与更新提示 ---------- */
.toast { position: fixed; left: 50%; bottom: calc(94px + var(--safe-bottom)); transform: translateX(-50%) translateY(8px); background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: var(--r-md); padding: 10px 16px; font-size: 13px; line-height: 1.45; box-shadow: var(--shadow-raise); z-index: 90; opacity: 0; pointer-events: none; transition: opacity var(--t), transform var(--t), background var(--t); max-width: min(88vw, 520px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.update-banner { position: fixed; top: calc(var(--safe-top) + 10px); left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--accent-border); color: var(--text); border-radius: var(--r-pill); padding: 8px 8px 8px 16px; font-size: 13px; display: flex; align-items: center; gap: 12px; z-index: 95; box-shadow: var(--shadow-raise); animation: dropIn 260ms var(--ease-out); max-width: calc(100vw - 24px); }
.update-banner button { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--r-pill); padding: 7px 14px; font-size: 12.5px; font-weight: 700; cursor: pointer; white-space: nowrap; transition: background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast); }
.update-banner button:hover { background: var(--accent-hover); box-shadow: var(--shadow); }
.update-banner button:active { transform: translateY(1px); }

/* ---------- 移动端：保留原断点 ---------- */
@media (max-width: 859.5px) {
  .layout { height: 100dvh; min-height: 100dvh; }
  .sidebar { position: fixed; inset: 0 auto 0 var(--safe-left); width: min(280px, calc(100vw - 44px)); height: 100dvh; transform: translateX(calc(-100% - 12px)); border-right: 1px solid var(--border); box-shadow: none; }
  .sidebar.open { transform: none; box-shadow: 0 0 48px rgba(0, 0, 0, .5); }
  .sidebar-head { min-width: 0; padding-top: calc(16px + var(--safe-top)); }
  .sidebar-close { display: grid; }
  .new-chat-btn { min-width: 0; width: calc(100% - 24px); }
  .side-nav { min-width: 0; }
  .sidebar-foot { min-width: 0; padding-bottom: calc(8px + var(--safe-bottom)); }
  .drawer-scrim { display: block; position: fixed; inset: 0; z-index: 30; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity var(--t-slow); }
  .drawer-scrim:not([hidden]) { opacity: 1; pointer-events: auto; }
  .drawer-scrim[hidden] { display: none !important; }
  .desktop-topbar { display: none; }
  .mobile-topbar { display: flex; align-items: center; gap: 12px; min-width: 0; min-height: calc(52px + var(--safe-top)); padding: calc(8px + var(--safe-top)) 14px 8px; border-bottom: 1px solid var(--border); background: var(--bg); position: relative; z-index: 8; }
  .mobile-topbar .status-pill { margin-left: auto; max-width: 42vw; }
  .mobile-nav { display: flex; flex: none; align-items: stretch; border-top: 1px solid var(--border); background: var(--bg-deep); padding: 4px 4px calc(4px + var(--safe-bottom)); position: relative; z-index: 7; }
  .m-nav-item { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 48px; padding: 6px 0 5px; border: 1px solid transparent; background: transparent; color: var(--faint); font-size: 10.5px; line-height: 1.2; cursor: pointer; border-radius: var(--r-md); transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast), transform var(--t-fast); }
  .m-nav-item:hover { color: var(--text-2); background: var(--panel); }
  .m-nav-item.active { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-softer); }
  .chat-scroll { padding: 18px 14px 8px; }
  #chatView.is-home .chat-scroll { padding-top: 18px; }
  .composer-zone { padding: 8px 12px 10px; max-width: 100%; }
  #chatView.is-home .composer-zone { padding-bottom: 10px; }
  .composer { border-radius: var(--r-lg); }
  .composer textarea { font-size: 16px; max-height: min(140px, 28dvh); }
  .msg.user { max-width: 88%; }
  .msg.assistant { padding-left: 10px; }
  .messages { gap: 16px; }
  .welcome-title { font-size: 22px; }
  .welcome-sub { margin-bottom: 20px; }
  .model-picker { max-width: 130px; font-size: 11.5px; }
  #cardsView, #familyView, #settingsView { padding: 22px 14px 32px; }
  .settings-card, .flashcard { padding: 16px; }
  .toast { bottom: calc(78px + var(--safe-bottom)); max-width: calc(100vw - 28px); }
}

/* ---------- 桌面端：保留原断点 ---------- */
@media (min-width: 860px) {
  #cardsView, #familyView, #settingsView { padding: 32px 32px calc(48px + var(--safe-bottom)); }
  .sidebar-close { display: none; }
  .desktop-topbar { display: flex; }
  .mobile-topbar, .mobile-nav, .drawer-scrim { display: none; }
  .chat-scroll { padding-left: 28px; padding-right: 28px; }
  .chat-scroll::-webkit-scrollbar { width: 7px; }
}

/* ---------- 390 / 430 / 768 细节：无横向溢出、单列快捷项、底部导航不遮挡 ---------- */
@media (max-width: 430px) {
  .quick-grid { grid-template-columns: 1fr; }
  .quick { min-height: 48px; }
  .welcome { padding-bottom: 10px; }
  .welcome-mark { width: 40px; height: 40px; margin-bottom: 18px; }
  .welcome-title { font-size: 21px; }
  .welcome-sub { font-size: 13.5px; }
  .mobile-topbar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .mobile-topbar .status-pill { max-width: 38vw; font-size: 11.5px; }
  .search-mode-hint { font-size: 10px; }
  .msg.user { max-width: 92%; }
  .msg.assistant { padding-left: 0; border-left: 0; }
  .md-code { padding: 12px; font-size: 12.5px; }
  .composer-zone { padding-left: 10px; padding-right: 10px; }
  .composer { gap: 4px; padding: 6px; }
  .tool-btn, .send-btn { width: 36px; height: 36px; min-width: 36px; }
}
@media (max-width: 390px) {
  .brand-sub { display: none; }
  .mobile-topbar .brand-mark.sm { width: 24px; height: 24px; }
  .status-pill { gap: 6px; }
  .quick { padding: 10px 12px; font-size: 13px; }
  .search-mode-chip { padding: 5px 10px; }
  .composer textarea { padding-left: 2px; padding-right: 2px; }
  .page-head { gap: 10px; }
  .toast { font-size: 12.5px; padding: 9px 13px; }
}
@media (min-width: 768px) and (max-width: 859.5px) {
  .chat-scroll, #chatView.is-home .chat-scroll { padding-left: 24px; padding-right: 24px; }
  .composer-zone { max-width: calc(var(--content-max) + 40px); padding-left: 20px; padding-right: 20px; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .msg.user { max-width: 82%; }
}
@media (max-width: 859.5px) and (max-height: 560px) {
  .mobile-nav { display: none; }
  .mobile-topbar { padding-top: 8px; min-height: 48px; }
  .chat-scroll { padding-top: 12px; }
  #chatView.is-home .chat-scroll { justify-content: flex-start; align-items: stretch; }
  #chatView.is-home .welcome { margin: 12px auto; padding-top: 0; padding-bottom: 8px; }
  .welcome-mark { display: none; }
  .welcome-sub { margin-bottom: 14px; }
  .composer-zone, #chatView.is-home .composer-zone { padding-bottom: calc(8px + var(--safe-bottom)); }
  .composer textarea { max-height: min(96px, 22dvh); }
  .toast { bottom: calc(18px + var(--safe-bottom)); }
}

/* ---------- 1366 / 1440 桌面适配 ---------- */
@media (min-width: 1366px) {
  :root { --content-max: 800px; }
  .chat-scroll { padding-left: 32px; padding-right: 32px; }
  .composer-zone { max-width: calc(var(--content-max) + 48px); }
}
@media (min-width: 1440px) {
  :root { --sidebar-w: 280px; --content-max: 820px; }
  .sidebar-head { padding-left: 16px; padding-right: 16px; }
  .new-chat-btn { width: calc(var(--sidebar-w) - 28px); min-width: calc(var(--sidebar-w) - 28px); margin-left: 14px; margin-right: 14px; }
}

/* ---------- 浅色主题专用微调，保持与 app.js .light 一致 ---------- */
.light .md-code { background: var(--code-bg); border-color: var(--border-soft); }
.light .send-btn, .light .new-chat-btn, .light .primary { color: var(--text); }
.light .send-btn { color: var(--accent-ink); }
.light .welcome-mark, .light .brand-mark { color: #fff; }
.light .new-chat-btn:hover, .light .primary:hover, .light .send-btn:hover { background: var(--hover); border-color: var(--accent-border); color: var(--text); }
.light .send-btn:hover { background: var(--accent-hover); border-color: transparent; color: var(--accent-ink); }

/* ---------- 高对比主题微调 ---------- */
.contrast .composer, .contrast .settings-card, .contrast .flashcard, .contrast .quick, .contrast .toast, .contrast .update-banner { box-shadow: none; }
.contrast .side-item.active, .contrast .m-nav-item.active { text-decoration: underline; text-underline-offset: 3px; }
.contrast.light .welcome-mark, .contrast.light .brand-mark { color: #000; }

/* ---------- 动画 ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes riseIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes dropIn { from { opacity: 0; transform: translateX(-50%) translateY(-8px); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes caretBlink { 0%, 45% { opacity: 1; } 46%, 100% { opacity: 0; } }
@keyframes thinkingPulse { 0%, 100% { opacity: .45; transform: scale(.86); } 50% { opacity: 1; transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .view.active, .msg, .update-banner { animation: none !important; }
  .msg.streaming .msg-text::after, .stream-cursor, .typing-cursor, .cursor, .caret, .thinking::before, .thinking-state::before, .status-thinking::before, .msg.thinking::before { animation: none !important; opacity: 1; }
  html { scroll-behavior: auto; }
}
