/* ==========================================================================
   LAI Chat — 设计系统
   深/浅双主题 · CSS 变量驱动 · 零依赖
   ========================================================================== */

/* ------------------------------ 主题变量 ------------------------------ */
:root {
  --accent: #6c8cff;
  --accent-2: #8aa2ff;
  --accent-soft: rgba(108, 140, 255, .16);
  --accent-ring: rgba(108, 140, 255, .40);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --fs: 15px;
  --content-w: 880px;
  --sidebar-w: 288px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "SF Mono", ui-monospace, Menlo, Consolas,
    "Liberation Mono", monospace;

  --dur-fast: .13s;
  --dur: .22s;
  --ease: cubic-bezier(.32, .72, 0, 1);
}

/* 现代浏览器使用 color-mix 让强调色自动派生。
   注意：--accent-2 必须完全由 --accent 推导。历史上这里掺了固定的 #a06bff（58%），
   导致任何强调色都会被拉回紫色系，用户换色后界面看着「还是紫的」。 */
@supports (color: color-mix(in srgb, red, blue)) {
  :root {
    --accent-2: color-mix(in srgb, var(--accent) 78%, #ffffff);
    --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
    --accent-ring: color-mix(in srgb, var(--accent) 40%, transparent);
  }
}
@supports not (color: color-mix(in srgb, red, blue)) {
  :root {
    --accent-2: #8aa2ff;
    --accent-soft: rgba(108, 140, 255, .16);
    --accent-ring: rgba(108, 140, 255, .40);
  }
}

html[data-theme="dark"] {
  --bg: #0a0c10;
  --bg-grad-1: color-mix(in srgb, var(--accent) 9%, transparent);
  --bg-grad-2: color-mix(in srgb, var(--accent-2) 8%, transparent);
  --panel: #101319;
  --panel-2: #161a21;
  --panel-3: #1c212a;
  --elev: #1b2028;
  --border: rgba(255, 255, 255, .075);
  --border-strong: rgba(255, 255, 255, .14);
  --text: #e8ebf1;
  --text-dim: #aab3c2;
  --text-mute: #737f92;
  --user-bubble: color-mix(in srgb, var(--accent) 17%, #171b22);
  --code-bg: #0d1015;
  --code-head: #14181f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -12px rgba(0, 0, 0, .7);
  --shadow-lg: 0 24px 64px -16px rgba(0, 0, 0, .8);
  --ok: #3ddc97;
  --warn: #f5b544;
  --err: #ff6b6b;

  --tok-key: #ff7bac;
  --tok-str: #9ee493;
  --tok-num: #ffcb6b;
  --tok-com: #5d6b7f;
  --tok-fn: #79c0ff;
  --tok-type: #7ee0d0;
  --tok-tag: #ff9d7a;
  --tok-attr: #d2b3ff;
  --tok-punc: #8b98ab;
}

html[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-grad-1: color-mix(in srgb, var(--accent) 14%, transparent);
  --bg-grad-2: color-mix(in srgb, var(--accent-2) 12%, transparent);
  --panel: #ffffff;
  --panel-2: #f8f9fc;
  --panel-3: #eef1f7;
  --elev: #ffffff;
  --border: rgba(16, 24, 40, .09);
  --border-strong: rgba(16, 24, 40, .18);
  --text: #131722;
  --text-dim: #51596b;
  --text-mute: #7d879b;
  --user-bubble: color-mix(in srgb, var(--accent) 12%, #ffffff);
  --code-bg: #f7f8fb;
  --code-head: #eef1f7;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 10px 28px -16px rgba(16, 24, 40, .3);
  --shadow-lg: 0 28px 70px -22px rgba(16, 24, 40, .35);
  --ok: #0f9d62;
  --warn: #b8730a;
  --err: #d93a3a;

  --tok-key: #c2185b;
  --tok-str: #0a7d4b;
  --tok-num: #a15c00;
  --tok-com: #8a93a5;
  --tok-fn: #0550ae;
  --tok-type: #0b7285;
  --tok-tag: #b8460f;
  --tok-attr: #6f42c1;
  --tok-punc: #6b7280;
}

/* 浅色主题下渐变该往深色走，否则强调色在白底上会「发白」看不出色相 */
@supports (color: color-mix(in srgb, red, blue)) {
  html[data-theme="light"] {
    --accent-2: color-mix(in srgb, var(--accent) 72%, #000000);
  }
}

/* ------------------------------ 基础重置 ------------------------------ */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: var(--fs)/1.62 var(--font-sans);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(680px 420px at 12% -8%, var(--bg-grad-1), transparent 70%),
    radial-gradient(720px 500px at 92% 4%, var(--bg-grad-2), transparent 72%);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
h1, h2, h3, h4, h5 { margin: 0; font-weight: 650; line-height: 1.3; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border: 3px solid transparent; background-clip: content-box; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); background-clip: content-box; }
kbd {
  font: 600 11px/1 var(--font-mono); padding: 4px 6px; border-radius: 5px;
  background: var(--panel-3); border: 1px solid var(--border); color: var(--text-dim);
  box-shadow: 0 1px 0 var(--border-strong); display: inline-block; min-width: 20px; text-align: center;
}
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.85; stroke-linecap: round; stroke-linejoin: round; }
.icon--xs { width: 14px; height: 14px; }
[hidden] { display: none !important; }

/* ------------------------------ 布局 ------------------------------ */
.app {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100vh; height: 100dvh;
  overflow: hidden;
}
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; position: relative; }
.app.sb-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.app.sb-collapsed .sidebar { display: none; }

/* ------------------------------ 按钮 ------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-weight: 550; font-size: .93em;
  transition: background var(--dur-fast), border-color var(--dur-fast), transform var(--dur-fast), box-shadow var(--dur-fast);
  white-space: nowrap;
}
.btn:hover { background: var(--panel-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent-2) 70%, var(--accent)));
  border-color: transparent; color: #fff; box-shadow: 0 6px 18px -8px var(--accent-ring);
}
.btn--primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent-2) 70%, var(--accent))); }
.btn--sm { padding: 7px 11px; font-size: .87em; }
.btn--block { width: 100%; }
.btn--danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 35%, transparent); background: color-mix(in srgb, var(--err) 10%, var(--panel-2)); }
.btn--danger:hover { background: color-mix(in srgb, var(--err) 18%, var(--panel-2)); }
.btn--warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 32%, transparent); background: color-mix(in srgb, var(--warn) 10%, var(--panel-2)); }
.btn[disabled] { opacity: .5; pointer-events: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; color: var(--text-dim);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }
.icon-btn--sm { width: 26px; height: 26px; border-radius: 7px; }
.icon-btn--sm .icon { width: 14px; height: 14px; }

/* ------------------------------ 侧栏 ------------------------------ */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(14px);
}
.sb-top { padding: 16px 14px 10px; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.brand-logo {
  width: 36px; height: 36px; flex: none; border-radius: 11px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px -10px var(--accent-ring);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; overflow: hidden; }
.brand-text strong { font-size: .98em; letter-spacing: .2px; }
.brand-text small { color: var(--text-mute); font-size: .74em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sb-search { position: relative; margin: 0 14px; display: flex; align-items: center; }
.sb-search .icon { position: absolute; left: 10px; width: 15px; height: 15px; color: var(--text-mute); pointer-events: none; }
.sb-search input {
  width: 100%; padding: 9px 32px 9px 32px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel-2); font-size: .9em;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.sb-search input:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.sb-search .icon-btn { position: absolute; right: 4px; }

.sb-list { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 8px 8px; }
.sb-group { margin-bottom: 14px; }
.sb-group-title {
  font-size: .72em; font-weight: 650; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-mute); padding: 4px 10px 6px;
}
.sb-item {
  position: relative; display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 10px; color: var(--text-dim);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.sb-item:hover { background: var(--panel-2); color: var(--text); }
.sb-item.is-active { background: var(--accent-soft); color: var(--text); box-shadow: inset 0 0 0 1px var(--accent-ring); }
.sb-item-body { min-width: 0; flex: 1; }
.sb-item-main { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; text-align: left; color: inherit; font: inherit; }
.sb-item-title { font-size: .9em; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-item-meta { display: flex; gap: 6px; align-items: center; font-size: .74em; color: var(--text-mute); margin-top: 2px; }
.sb-item-meta .tag { padding: 1px 5px; border-radius: 5px; background: var(--panel-3); }
.sb-item-del { opacity: 0; color: var(--text-mute); }
.sb-item:hover .sb-item-del, .sb-item:focus-within .sb-item-del { opacity: 1; }
.sb-item-del:hover { color: var(--err); background: color-mix(in srgb, var(--err) 14%, transparent); }
@media (hover: none) { .sb-item-del { opacity: 1; } }

.sb-empty { padding: 28px 16px; text-align: center; color: var(--text-mute); font-size: .85em; line-height: 1.7; }
.sb-empty .icon { width: 26px; height: 26px; margin-bottom: 8px; opacity: .6; }

.sb-foot { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.sb-status { display: flex; align-items: center; gap: 7px; font-size: .78em; color: var(--text-mute); padding: 0 4px; }
.sb-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-mute); flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-mute) 18%, transparent); }
.sb-status.is-ok .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.sb-status.is-err .dot { background: var(--err); box-shadow: 0 0 0 3px color-mix(in srgb, var(--err) 18%, transparent); }
.sb-status-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-actions { display: flex; gap: 4px; justify-content: space-between; }
.sidebar-scrim { display: none; }

/* ------------------------------ 顶栏 ------------------------------ */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 76%, transparent);
  backdrop-filter: blur(14px); z-index: 5;
}
.topbar-menu { display: none; }
.topbar-title { min-width: 0; flex: 1; }
.topbar-title h1 { font-size: 1.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title p { font-size: .78em; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 3px; }

/* ------------------------------ 消息区 ------------------------------ */
.scroll-area { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
.thread { max-width: var(--content-w); margin: 0 auto; padding: 26px 22px 18px; display: flex; flex-direction: column; gap: 6px; }
.thread:empty { display: none; }

.msg { display: flex; gap: 13px; padding: 12px 0; animation: msg-in .28s var(--ease) both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg-avatar {
  width: 32px; height: 32px; flex: none; border-radius: 10px; display: grid; place-items: center;
  background: var(--panel-3); color: var(--text-dim); border: 1px solid var(--border);
}
.msg-avatar .icon { width: 17px; height: 17px; }
.msg--assistant .msg-avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.msg-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; min-height: 20px; }
.msg-name { font-size: .8em; font-weight: 650; color: var(--text-dim); }
.msg-meta { font-size: .72em; color: var(--text-mute); display: flex; gap: 8px; flex-wrap: wrap; }
.msg-content { word-wrap: break-word; overflow-wrap: anywhere; }

.msg--user .msg-content {
  background: var(--user-bubble); border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  padding: 11px 14px; border-radius: var(--radius-lg); border-top-left-radius: 6px;
  line-height: 1.72;
}
.msg--user .msg-content > *:last-child { margin-bottom: 0; }
.msg--assistant .msg-content { padding: 2px 0; }
.msg-content.msg--error,
.msg--error .msg-content {
  background: color-mix(in srgb, var(--err) 10%, transparent); border: 1px solid color-mix(in srgb, var(--err) 34%, transparent);
  color: var(--text); padding: 12px 14px; border-radius: var(--radius); display: flex; gap: 10px; align-items: flex-start;
}
.msg-content.msg--error .icon,
.msg--error .icon { color: var(--err); margin-top: 2px; }
.err-title { font-weight: 650; margin-bottom: 3px; }
.err-detail { font: .82em/1.6 var(--font-mono); color: var(--text-dim); white-space: pre-wrap; word-break: break-word; }

/* 消息编辑 */
.edit-wrap { display: flex; flex-direction: column; gap: 8px; }
.edit-wrap textarea { width: 100%; font-family: var(--font-sans); min-height: 72px; }
.edit-holder { margin-bottom: 4px; }

.msg-images { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 9px; }
.msg-image {
  width: 132px; height: 132px; object-fit: cover; border-radius: var(--radius); cursor: zoom-in;
  border: 1px solid var(--border); background: var(--panel-2); transition: transform var(--dur-fast), box-shadow var(--dur-fast);
}
.msg-image:hover { transform: scale(1.02); box-shadow: var(--shadow); }

.msg-actions { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 7px; opacity: 0; transition: opacity var(--dur); }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
@media (hover: none) { .msg-actions { opacity: 1; } }
.msg-actions .icon-btn { width: 30px; height: 30px; border-radius: 8px; }
.msg-actions .icon-btn .icon { width: 15px; height: 15px; }
.msg-actions .icon-btn.act-label {
  width: auto; min-width: 30px; padding: 0 9px; gap: 5px;
  white-space: nowrap; flex: 0 0 auto;
}

/* 思维链 */
.reasoning { margin-bottom: 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--panel-2); overflow: hidden; }
.reasoning-head {
  display: flex; align-items: center; gap: 7px; padding: 8px 12px; font-size: .8em; font-weight: 600;
  color: var(--text-dim); cursor: pointer; user-select: none;
}
.reasoning-head .icon { width: 15px; height: 15px; }
.reasoning-head .chev { margin-left: auto; transition: transform var(--dur); }
.reasoning.is-open .chev { transform: rotate(90deg); }
.reasoning-body { display: none; padding: 4px 14px 12px; font-size: .87em; color: var(--text-dim); border-top: 1px dashed var(--border); white-space: pre-wrap; max-height: 380px; overflow: auto; }
.reasoning.is-open .reasoning-body { display: block; }

/* ------------------------------ 联网检索状态与来源 ------------------------------ */
.msg-search {
  margin: 0 0 10px; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--panel-2); font-size: .82em;
}
.msg-search-head { display: flex; align-items: center; gap: 7px; color: var(--text-dim); }
.msg-search-head .icon { width: 15px; height: 15px; flex: 0 0 auto; color: var(--accent); }
.msg-search.is-err { border-color: color-mix(in srgb, var(--err) 45%, var(--border)); }
.msg-search.is-err .msg-search-head { color: var(--err); }
.msg-search.is-err .msg-search-head .icon { color: var(--err); }
.msg-search.is-done .msg-search-head { color: var(--text-mute); }
/* 检索中：图标持续旋转，明确告诉用户「正在联网」而不是卡住 */
.msg-search-head.is-loading .icon { animation: ws-spin 1.1s linear infinite; }
@keyframes ws-spin { to { transform: rotate(360deg); } }

.msg-sources { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.msg-sources.is-capped .src-card:nth-child(n+5) { display: none; }
.src-card {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 9px;
  text-decoration: none; color: inherit; border: 1px solid transparent; transition: background var(--dur), border-color var(--dur);
}
.src-card:hover { background: var(--panel-3); border-color: var(--border); }
.src-idx { color: var(--accent); font-weight: 650; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.src-body { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.src-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.src-site { font-size: .88em; color: var(--text-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-card > .icon { width: 13px; height: 13px; margin-left: auto; flex: 0 0 auto; color: var(--text-mute); }
.src-more {
  align-self: flex-start; margin-top: 5px; background: none; border: 0; padding: 2px 0;
  color: var(--accent); font-size: .95em; cursor: pointer; font-family: inherit;
}
.src-more:hover { text-decoration: underline; }

/* 设置里的「测试搜索」结果列表 */
.ws-test-list { margin: 8px 0 0; padding-left: 18px; line-height: 1.8; }
.ws-test-list a { color: var(--accent); text-decoration: none; }
.ws-test-list a:hover { text-decoration: underline; }
.hint--inline-warn { color: var(--err); }
.input.is-invalid { border-color: color-mix(in srgb, var(--err) 55%, var(--border)); }

/* ------------------------------ 侧栏账号区 ------------------------------ */
.sb-account { padding: 0 10px 10px; }
.sb-account[hidden] { display: none; }

.account-card {
  padding: 10px 11px; border-radius: var(--radius);
  background: var(--panel-2); border: 1px solid var(--border);
}
.account-line { display: flex; align-items: center; gap: 9px; }
.account-avatar {
  width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-size: .78em; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.account-meta { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; }
.account-meta b { font-size: .84em; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-meta span { font-size: .74em; color: var(--text-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-links { display: flex; gap: 10px; margin-top: 8px; }
.link-btn {
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit;
  font-size: .78em; color: var(--accent); text-decoration: none;
}
.link-btn:hover { text-decoration: underline; }
.link-btn[hidden] { display: none; }

/* 免费额度 */
.quota-box {
  margin-top: 8px; padding: 9px 11px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--border); font-size: .78em;
}
.quota-box[hidden] { display: none; }
.quota-head {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; color: var(--text-dim); margin-bottom: 7px;
}
.quota-head .icon { width: 13px; height: 13px; }
.quota-list { display: flex; flex-direction: column; gap: 7px; }
.quota-row-head {
  display: flex; justify-content: space-between; gap: 8px;
  color: var(--text-mute); margin-bottom: 4px;
}
.quota-row-head b { color: var(--text); font-variant-numeric: tabular-nums; }
.quota-box .bar { height: 4px; }
.quota-total { margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--border); color: var(--text-mute); }
.quota-alert {
  padding: 7px 9px; border-radius: var(--radius-sm); margin-bottom: 7px;
  background: color-mix(in srgb, var(--err) 12%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--err) 38%, transparent);
  color: var(--text);
}

/* 流式光标 / 打字指示 */
.caret { display: inline-block; width: 8px; height: 1.05em; vertical-align: -2px; margin-left: 2px; border-radius: 2px; background: var(--accent); animation: blink 1.05s steps(2, start) infinite; }@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }
.typing { display: inline-flex; gap: 4px; align-items: center; height: 1.3em; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-mute); animation: bounce 1.3s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .16s; }
.typing i:nth-child(3) { animation-delay: .32s; }
@keyframes bounce { 0%, 60%, 100% { transform: none; opacity: .45; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ------------------------------ 空状态 ------------------------------ */
.welcome { max-width: var(--content-w); margin: 0 auto; padding: 34px 22px 40px; animation: msg-in .4s var(--ease) both; }
.welcome-hero { text-align: center; margin-bottom: 28px; }
.welcome-logo {
  width: 62px; height: 62px; margin: 0 auto 16px; border-radius: 20px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 18px 40px -18px var(--accent-ring);
}
.welcome-logo .icon { width: 30px; height: 30px; }
.welcome-hero h2 { font-size: 1.62em; margin-bottom: 9px; letter-spacing: -.01em; }
.welcome-hero > p { color: var(--text-dim); font-size: .93em; line-height: 1.75; }
.welcome-cta { display: flex; gap: 10px; justify-content: center; margin: 20px 0 12px; flex-wrap: wrap; }
.welcome-hint { font-size: .8em; color: var(--text-mute); }
.welcome-hint b { color: var(--text-dim); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 12px; margin-bottom: 26px; }
.card {
  text-align: left; padding: 15px 16px; border-radius: var(--radius-lg); border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 82%, transparent); transition: border-color var(--dur), transform var(--dur), box-shadow var(--dur);
}
.card:hover { border-color: var(--accent-ring); transform: translateY(-2px); box-shadow: var(--shadow); }
.card-top { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.card-ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.card-ico .icon { width: 16px; height: 16px; }
.card b { font-size: .92em; font-weight: 620; }
.card p { font-size: .82em; color: var(--text-mute); line-height: 1.62; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-kbd { margin-top: 10px; font-size: .72em; color: var(--text-mute); display: flex; align-items: center; gap: 5px; }

.feature-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; padding-top: 22px; border-top: 1px solid var(--border); }
.feature { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: center; padding: 8px 10px; border-radius: var(--radius); }
.feature .icon { grid-row: span 2; color: var(--accent); }
.feature b { font-size: .85em; font-weight: 600; }
.feature span { font-size: .76em; color: var(--text-mute); }

/* ------------------------------ 输入区 ------------------------------ */
.composer-wrap { padding: 8px 22px 12px; background: linear-gradient(to top, var(--bg) 55%, transparent); }
.setup-banner {
  max-width: var(--content-w); margin: 0 auto 8px;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--warn) 42%, transparent);
  background: color-mix(in srgb, var(--warn) 12%, var(--panel));
  font-size: .85em; animation: msg-in .24s var(--ease) both;
}
.setup-banner .icon { color: var(--warn); flex: none; }
.setup-banner span { flex: 1; min-width: 0; line-height: 1.5; }
.setup-banner b { color: var(--text); }
.composer {
  max-width: var(--content-w); margin: 0 auto; border: 1px solid var(--border-strong); border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--panel) 94%, transparent); box-shadow: var(--shadow);
  backdrop-filter: blur(12px); transition: border-color var(--dur), box-shadow var(--dur);
}
.composer:focus-within { border-color: var(--accent-ring); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }
.composer.is-drag { border-color: var(--accent); border-style: dashed; }
.composer-main { display: flex; align-items: flex-end; gap: 4px; padding: 8px 8px 4px; }
.composer-attach { margin-bottom: 2px; }
#input {
  flex: 1; min-height: 40px; max-height: 260px; resize: none; border: 0; background: none;
  padding: 9px 4px; line-height: 1.65; overflow-y: auto; font-size: 1em;
}
#input:focus { outline: none; }
#input::placeholder { color: var(--text-mute); }
.composer-send {
  width: 38px; height: 38px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; margin-bottom: 2px;
  transition: transform var(--dur-fast), filter var(--dur-fast), opacity var(--dur-fast);
}
.composer-send:hover { filter: brightness(1.1); }
.composer-send:active { transform: scale(.94); }
.composer-send[disabled] { opacity: .45; cursor: not-allowed; }
.composer-send.is-stop { background: linear-gradient(135deg, var(--err), color-mix(in srgb, var(--err) 60%, var(--accent-2))); }

.composer-bar { display: flex; align-items: center; gap: 8px; padding: 4px 10px 9px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 300px;
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text-dim); font-size: .78em; font-weight: 550;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.chip:hover { background: var(--panel-3); color: var(--text); }
.chip .icon { width: 14px; height: 14px; }
.chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip--ghost { border-style: dashed; }
.chip.is-on { border-style: solid; border-color: var(--accent-ring); background: var(--accent-soft); color: var(--accent); }
.composer-tools { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.composer-count { font-size: .74em; color: var(--text-mute); font-variant-numeric: tabular-nums; padding-right: 2px; }
.composer-foot {
  max-width: var(--content-w); margin: 7px auto 0; display: flex; justify-content: space-between; gap: 10px;
  font-size: .73em; color: var(--text-mute); padding: 0 6px;
}
.composer-foot .foot-right { text-align: right; }

/* 附件 */
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 12px 0; }
.attachment { position: relative; width: 76px; height: 76px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--panel-2); }
.attachment img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment button {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center;
  background: rgba(0, 0, 0, .6); color: #fff; backdrop-filter: blur(4px);
}
.attachment button .icon { width: 12px; height: 12px; }
.attachment .att-size {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: .66em; text-align: center; color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, .72)); padding: 8px 2px 2px; font-variant-numeric: tabular-nums;
}

.scroll-bottom {
  position: absolute; right: 26px; bottom: 148px; z-index: 4;
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--elev); border: 1px solid var(--border-strong); color: var(--text-dim); box-shadow: var(--shadow);
  animation: msg-in .2s var(--ease) both;
}
.scroll-bottom:hover { color: var(--text); }

/* ------------------------------ Markdown 渲染 ------------------------------ */
.md { line-height: 1.78; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 .85em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.5em 0 .6em; line-height: 1.35; letter-spacing: -.01em; }
.md h1 { font-size: 1.5em; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.md h2 { font-size: 1.28em; padding-bottom: .25em; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 1.1em; }
.md h4 { font-size: 1em; color: var(--text-dim); }
.md ul, .md ol { margin: 0 0 .85em; padding-left: 1.5em; }
.md li { margin: .28em 0; }
.md li > ul, .md li > ol { margin: .3em 0; }
.md li::marker { color: var(--text-mute); }
.md blockquote {
  margin: 0 0 .85em; padding: .5em 1em; border-left: 3px solid var(--accent-ring);
  background: var(--panel-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-dim);
}
.md blockquote p:last-child { margin-bottom: 0; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.md :not(pre) > code {
  font: .87em/1.5 var(--font-mono); padding: .16em .4em; border-radius: 5px;
  background: var(--panel-3); border: 1px solid var(--border); color: color-mix(in srgb, var(--accent) 72%, var(--text));
  word-break: break-word;
}
.md table { width: 100%; border-collapse: collapse; margin: 0 0 1em; font-size: .88em; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; }
.md thead th { background: var(--panel-2); font-weight: 620; white-space: nowrap; }
.md tbody tr:nth-child(even) { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.md img { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.md a { text-decoration: none; border-bottom: 1px solid var(--accent-ring); }
.md a:hover { border-bottom-color: var(--accent); }
.md a .icon { width: 12px; height: 12px; margin-left: 2px; opacity: .7; vertical-align: -1px; }
.md input[type="checkbox"] { margin-right: 7px; accent-color: var(--accent); }
.md .task-item { list-style: none; margin-left: -1.2em; }
.md .task-item input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; width: 14px; height: 14px; border-radius: 4px;
  border: 1.5px solid var(--border-strong); background: var(--panel-2);
  vertical-align: -2px; position: relative; margin-right: 7px; cursor: default;
}
.md .task-item input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.md .task-item input[type="checkbox"]:checked::after {
  content: ""; position: absolute; left: 3.5px; top: 0.5px; width: 4px; height: 8px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.md mark { background: color-mix(in srgb, var(--warn) 32%, transparent); color: inherit; padding: 0 .2em; border-radius: 3px; }

/* 代码块 */
.code-block { margin: 0 0 1em; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--code-bg); }
.code-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; background: var(--code-head);
  border-bottom: 1px solid var(--border); font-size: .76em; color: var(--text-mute);
}
.code-lang { font-family: var(--font-mono); text-transform: lowercase; letter-spacing: .04em; }
.code-head .spacer { flex: 1; }
.code-head button {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 7px;
  color: var(--text-dim); font-size: .95em; transition: background var(--dur-fast), color var(--dur-fast);
}
.code-head button:hover { background: var(--panel-3); color: var(--text); }
.code-head button .icon { width: 13px; height: 13px; }
.code-block pre { margin: 0; overflow-x: auto; }
.code-block code { display: block; padding: 12px 14px; font: .84em/1.65 var(--font-mono); tab-size: 2; }
.code-block.is-collapsed pre { max-height: 320px; overflow: hidden; position: relative; }
.code-block.is-collapsed pre::after { content: ""; position: absolute; inset: auto 0 0 0; height: 60px; background: linear-gradient(transparent, var(--code-bg)); }
.tok-key { color: var(--tok-key); }
.tok-str { color: var(--tok-str); }
.tok-num { color: var(--tok-num); }
.tok-com { color: var(--tok-com); font-style: italic; }
.tok-fn { color: var(--tok-fn); }
.tok-type { color: var(--tok-type); }
.tok-tag { color: var(--tok-tag); }
.tok-attr { color: var(--tok-attr); }
.tok-punc { color: var(--tok-punc); }
.tok-del { color: var(--err); }
.tok-add { color: var(--tok-str); }
.md .math { font-family: var(--font-mono); font-size: .9em; padding: .1em .35em; border-radius: 5px; background: var(--panel-3); }

/* ------------------------------ 自动补全 ------------------------------ */
.ac {
  position: fixed; z-index: 88; width: 380px; max-width: calc(100vw - 24px);
  background: var(--elev); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); overflow: hidden; animation: ac-in .14s var(--ease) both;
}
@keyframes ac-in { from { opacity: 0; transform: translateY(6px) scale(.985); } to { opacity: 1; transform: none; } }
.ac-head { padding: 8px 12px; font-size: .72em; letter-spacing: .06em; text-transform: uppercase; color: var(--text-mute); border-bottom: 1px solid var(--border); }
.ac-list { max-height: 306px; overflow-y: auto; padding: 5px; }
.ac-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 10px;
  border-radius: 9px; color: var(--text-dim); transition: background var(--dur-fast);
}
.ac-item.is-active, .ac-item:hover { background: var(--accent-soft); color: var(--text); }
.ac-ico { width: 26px; height: 26px; flex: none; border-radius: 8px; display: grid; place-items: center; background: var(--panel-3); color: var(--text-dim); }
.ac-item.is-active .ac-ico { background: color-mix(in srgb, var(--accent) 24%, transparent); color: var(--accent); }
.ac-ico .icon { width: 14px; height: 14px; }
.ac-text { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.ac-name { display: block; font-size: .88em; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-desc { display: block; font-size: .75em; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-name mark, .ac-desc mark { background: none; color: var(--accent); font-weight: 700; }
.ac-badge { font-size: .68em; padding: 2px 6px; border-radius: 999px; background: var(--panel-3); color: var(--text-mute); flex: none; }
.ac-foot { display: flex; gap: 6px; align-items: center; padding: 7px 12px; border-top: 1px solid var(--border); font-size: .72em; color: var(--text-mute); background: var(--panel-2); }
.ac-foot kbd { padding: 2px 5px; font-size: 10px; }

/* ------------------------------ 弹窗 ------------------------------ */
.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 6, 10, .58); backdrop-filter: blur(6px); animation: fade .18s both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-panel {
  position: relative; width: 100%; max-height: min(88vh, 900px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); overflow: hidden; animation: panel-in .24s var(--ease) both;
}
@keyframes panel-in { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-panel--sm { max-width: 470px; }
.modal-panel--lg { max-width: 940px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 1.02em; display: flex; align-items: center; gap: 9px; flex: 1; }
.modal-head h2 .icon { color: var(--accent); }
.modal-body { padding: 18px; overflow-y: auto; min-height: 0; }
.modal-body--split { display: grid; grid-template-columns: 186px minmax(0, 1fr); gap: 0; padding: 0; min-height: 0; flex: 1 1 auto; overflow: hidden; }
.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 18px; border-top: 1px solid var(--border); background: var(--panel-2); }
.modal-foot-note { font-size: .78em; color: var(--text-mute); }
.confirm-text { color: var(--text-dim); line-height: 1.7; }

.tabs { display: flex; flex-direction: column; gap: 3px; padding: 12px 10px; border-right: 1px solid var(--border); background: var(--panel-2); overflow-y: auto; }
.tab {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 10px;
  color: var(--text-dim); font-size: .88em; font-weight: 550; text-align: left; transition: background var(--dur-fast), color var(--dur-fast);
}
.tab:hover { background: var(--panel-3); color: var(--text); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent-ring); }
.panes { overflow-y: auto; min-height: 0; padding: 18px 20px; }
.pane { display: none; animation: msg-in .22s var(--ease) both; }
.pane.is-active { display: block; }

/* ------------------------------ 表单 ------------------------------ */
.field { margin-bottom: 18px; }
.field > label { display: flex; align-items: center; gap: 6px; font-size: .84em; font-weight: 600; color: var(--text-dim); margin-bottom: 7px; }
.field > label output { margin-left: auto; font: 600 .95em var(--font-mono); color: var(--accent); }
.req { font-size: .72em; color: var(--err); font-weight: 500; }
.input {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); transition: border-color var(--dur-fast), background var(--dur-fast), box-shadow var(--dur-fast);
}
.input:hover { border-color: var(--border-strong); }
.input:focus { outline: none; border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; line-height: 1.62; }
.input--mono { font-family: var(--font-mono); font-size: .85em; }
.input--sm { padding: 7px 10px; font-size: .85em; }
select.input { cursor: pointer; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-mute) 50%), linear-gradient(135deg, var(--text-mute) 50%, transparent 50%); background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.input-group { display: flex; align-items: center; gap: 6px; }
.input-group .input { flex: 1 1 auto; width: auto; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row--gap { gap: 10px; margin-top: 8px; }
.row--wrap { flex-wrap: wrap; }
.hint { font-size: .78em; color: var(--text-mute); margin-top: 6px; line-height: 1.65; }
.hint--inline { margin: 0; }
.hint code, .md code { font-family: var(--font-mono); font-size: .92em; }
.field--slider input[type="range"] { width: 100%; -webkit-appearance: none; appearance: none; height: 5px; border-radius: 999px; background: var(--panel-3); margin: 8px 0 0; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 17px; height: 17px; border-radius: 50%; background: var(--accent); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--border-strong); cursor: grab; }
input[type="range"]::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: var(--accent); border: 3px solid var(--panel); cursor: grab; }

.switch-list { display: flex; flex-direction: column; gap: 3px; margin-bottom: 18px; }
.switch { display: flex; align-items: flex-start; gap: 11px; padding: 9px 10px; border-radius: 10px; cursor: pointer; transition: background var(--dur-fast); }
.switch:hover { background: var(--panel-2); }
.switch input { display: none; }
.switch .track { width: 38px; height: 22px; flex: none; border-radius: 999px; background: var(--panel-3); border: 1px solid var(--border); position: relative; transition: background var(--dur), border-color var(--dur); margin-top: 1px; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-mute); transition: transform var(--dur) var(--ease), background var(--dur); }
.switch input:checked + .track { background: var(--accent-soft); border-color: var(--accent-ring); }
.switch input:checked + .track::after { transform: translateX(16px); background: var(--accent); }
.switch-label { display: flex; flex-direction: column; font-size: .88em; font-weight: 550; }
.switch-label small { font-weight: 400; font-size: .86em; color: var(--text-mute); margin-top: 2px; }

.seg { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--panel-2); border: 1px solid var(--border); gap: 3px; }
.seg-item { padding: 7px 14px; border-radius: 8px; font-size: .85em; font-weight: 550; color: var(--text-dim); transition: background var(--dur-fast), color var(--dur-fast); }
.seg-item:hover { color: var(--text); }
.seg-item.is-active { background: var(--accent); color: #fff; box-shadow: 0 4px 12px -6px var(--accent-ring); }
.swatches { display: flex; gap: 9px; flex-wrap: wrap; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; background: var(--c); border: 2px solid transparent; box-shadow: 0 0 0 1px var(--border-strong); transition: transform var(--dur-fast); }
.swatches button:hover { transform: scale(1.1); }
.swatches button.is-active { border-color: var(--panel); box-shadow: 0 0 0 2px var(--c); transform: scale(1.06); }

/* 自定义取色器：抹平各浏览器原生 color input 的默认外观差异 */
.color-input {
  width: 46px; height: 36px; padding: 3px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--panel-2); cursor: pointer;
}
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: 0; border-radius: 6px; }
.color-input::-moz-color-swatch { border: 0; border-radius: 6px; }
.input--sm { max-width: 150px; }

details.adv { border: 1px solid var(--border); border-radius: var(--radius); padding: 0; margin-bottom: 12px; background: var(--panel-2); overflow: hidden; }
details.adv > summary { padding: 10px 13px; cursor: pointer; font-size: .85em; font-weight: 600; color: var(--text-dim); list-style: none; display: flex; align-items: center; gap: 7px; }
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::before { content: "▸"; transition: transform var(--dur); display: inline-block; color: var(--text-mute); }
details.adv[open] > summary::before { transform: rotate(90deg); }
details.adv[open] > summary { border-bottom: 1px solid var(--border); }
details.adv > *:not(summary) { margin: 12px 13px; }
details.adv .field:last-child { margin-bottom: 12px; }

.conn-result { margin-top: 14px; padding: 12px 14px; border-radius: var(--radius); font-size: .85em; line-height: 1.7; border: 1px solid var(--border); background: var(--panel-2); white-space: pre-wrap; word-break: break-word; }
.conn-result.is-ok { border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 9%, var(--panel-2)); }
.conn-result.is-err { border-color: color-mix(in srgb, var(--err) 40%, transparent); background: color-mix(in srgb, var(--err) 9%, var(--panel-2)); }
.conn-result.is-busy { border-color: var(--accent-ring); background: var(--accent-soft); }
.conn-result b { font-weight: 650; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 20px; }
.stat { padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel-2); }
.stat b { display: block; font-size: 1.3em; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat span { font-size: .78em; color: var(--text-mute); }
.meter { height: 8px; border-radius: 999px; background: var(--panel-3); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width var(--dur); }
.steps { margin: 0; padding-left: 1.3em; font-size: .88em; color: var(--text-dim); line-height: 1.85; }
.steps li { margin-bottom: 6px; }
.kbd-table { display: flex; flex-direction: column; gap: 2px; }
.kbd-row { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 9px; font-size: .86em; color: var(--text-dim); }
.kbd-row:nth-child(odd) { background: var(--panel-2); }
.kbd-row .keys { margin-left: auto; display: flex; gap: 5px; align-items: center; color: var(--text-mute); font-size: .9em; }

/* ------------------------------ 右键菜单 / 灯箱 / Toast ------------------------------ */
.ctx-menu {
  position: fixed; z-index: 90; min-width: 178px; padding: 5px;
  background: var(--elev); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); animation: ac-in .12s var(--ease) both;
}
.ctx-item { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; padding: 8px 10px; border-radius: 8px; font-size: .86em; color: var(--text-dim); transition: background var(--dur-fast), color var(--dur-fast); }
.ctx-item:hover { background: var(--accent-soft); color: var(--text); }
.ctx-item .icon { width: 15px; height: 15px; }
.ctx-item.is-danger { color: var(--err); }
.ctx-item.is-danger:hover { background: color-mix(in srgb, var(--err) 14%, transparent); }
.ctx-sep { height: 1px; margin: 4px 6px; background: var(--border); }

.lightbox { position: fixed; inset: 0; z-index: 95; display: grid; place-items: center; padding: 40px; background: rgba(3, 5, 9, .9); backdrop-filter: blur(8px); animation: fade .16s both; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.lightbox-close { position: absolute; top: 20px; right: 22px; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .1); color: #fff; }
.lightbox-close:hover { background: rgba(255, 255, 255, .2); }

.toasts { position: fixed; z-index: 100; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 9px; padding: 10px 15px; border-radius: 999px;
  background: var(--elev); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
  font-size: .85em; animation: toast-in .24s var(--ease) both; max-width: min(560px, 90vw);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
.toast.is-out { animation: toast-out .2s var(--ease) both; }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.97); } }
.toast .icon { width: 16px; height: 16px; flex: none; }
.toast--ok .icon { color: var(--ok); }
.toast--err .icon { color: var(--err); }
.toast--info .icon { color: var(--accent); }
.toast span { overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------ 紧凑模式 ------------------------------ */
html[data-density="compact"] .msg { padding: 7px 0; }
html[data-density="compact"] .thread { padding-top: 16px; }
html[data-density="compact"] .md p { margin-bottom: .6em; }
html[data-density="compact"] .msg-avatar { width: 28px; height: 28px; }

/* ------------------------------ 响应式 ------------------------------ */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 310px); z-index: 70;
    transform: translateX(-102%); transition: transform var(--dur) var(--ease);
    background: var(--panel); box-shadow: var(--shadow-lg);
  }
  .app.sb-open .sidebar { transform: none; }
  .app.sb-open .sidebar-scrim { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(0, 0, 0, .5); backdrop-filter: blur(3px); }
  .topbar-menu { display: inline-flex; }
  .thread, .welcome, .composer { padding-left: 14px; padding-right: 14px; }
  .thread { padding-left: 16px; padding-right: 16px; }
  .composer-wrap { padding: 8px 12px 10px; }
  .modal { padding: 0; }
  .modal-panel { max-width: 100%; max-height: 100dvh; border-radius: 0; height: 100%; }
  .modal-body--split { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .tabs { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 8px; }
  .tabs .tab { white-space: nowrap; padding: 8px 12px; }
  .tabs .tab .icon { display: none; }
  .scroll-bottom { right: 16px; bottom: 160px; }
  .ac { width: calc(100vw - 24px); }
  .msg-actions { opacity: 1; }
}
@media (max-width: 560px) {
  .composer-foot { display: none; }
  .composer-tools .chip--ghost span { display: none; }
  .welcome-hero h2 { font-size: 1.35em; }
  .cards { grid-template-columns: 1fr; }
  .feature-strip { grid-template-columns: 1fr 1fr; }
  .modal-foot { flex-direction: column-reverse; align-items: stretch; }
  .modal-foot .row { justify-content: stretch; }
  .modal-foot .row .btn { flex: 1; }
}
@media print {
  .sidebar, .topbar, .composer-wrap, .msg-actions, .scroll-bottom, .toasts { display: none !important; }
  body { overflow: visible; }
  .scroll-area { overflow: visible; }
  .app { display: block; height: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .scroll-area { scroll-behavior: auto; }
}
