/* ============================================================
   Open sky  ·  MATRIXCHONG OF OPENSKY SDUDIO
   ============================================================ */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 264px;
  /* 全站统一走中性灰阶：所有强调色最终都落到"白天近黑 / 夜晚近白"两极，
     再由下面两个主题块分别给出具体取值，避免任何彩色残留。 */
  --shadow: 0 8px 30px rgba(0, 0, 0, .10);
  --maxw: 780px;
}

html[data-theme="light"] {
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --bg-elev: #ffffff;
  --sidebar: #f7f7f8;
  --sidebar-hover: #ececec;
  --border: #e5e5e5;
  --border-strong: #cfcfcf;
  --text: #151515;
  --text-dim: #5f6368;
  --text-faint: #9a9a9a;
  --accent: #151515;
  --accent-soft: rgba(0, 0, 0, .06);
  --accent-line: rgba(0, 0, 0, .16);
  --on-accent: #ffffff;
  --accent-hover: #3d3d3d;
  /* 状态色同样黑白化：轻危方式是反色块（黑底白字），而不是红字 */
  --danger: #151515;
  --danger-soft: rgba(0, 0, 0, .06);
  --ok: #151515;
  --warn: #5f6368;
  --bubble-user: #f4f4f4;
  --bubble-user-br: #e6e6e6;
  --code-bg: #f6f6f7;
  --overlay: rgba(0, 0, 0, .45);
  --hl-dim: #6b7280;
  --hl-strong: #d4d4d4;
  --hl-accent: #9a9a9a;
  --hl-str: #6b7280;
}

html[data-theme="dark"] {
  --bg: #171717;
  --bg-soft: #1e1e1e;
  --bg-elev: #212121;
  --sidebar: #101010;
  --sidebar-hover: #232323;
  --border: #2e2e2e;
  --border-strong: #3d3d3d;
  --text: #ececec;
  --text-dim: #a1a1a1;
  --text-faint: #777777;
  --accent: #f2f2f2;
  --accent-soft: rgba(255, 255, 255, .10);
  --accent-line: rgba(255, 255, 255, .22);
  --on-accent: #0b0b0c;
  --accent-hover: #cfcfcf;
  --danger: #f2f2f2;
  --danger-soft: rgba(255, 255, 255, .10);
  --ok: #f2f2f2;
  --warn: #a1a1a1;
  --bubble-user: #2a2a2a;
  --bubble-user-br: #363636;
  --code-bg: #202020;
  --overlay: rgba(0, 0, 0, .65);
  --hl-dim: #8a8a8a;
  --hl-strong: #dcdcdc;
  --hl-accent: #b5b5b5;
  --hl-str: #8a8a8a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }

/* ---------------- 登录页 ---------------- */
.login-page {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  padding: 24px calc(16px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  /* 登录页底色：中性柔光渐晕（原为蓝青两团，已改为灰阶） */
  background:
    radial-gradient(1100px 520px at 78% -8%, var(--accent-soft), transparent 60%),
    radial-gradient(760px 420px at 8% 108%, var(--danger-soft), transparent 62%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 20px; padding: 34px 30px 26px;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 6px; }
.login-brand .logo-mark { width: 42px; height: 42px; }
/* 品牌标识：星球 O（用户提供图），透明底 PNG。
   用背景图切换而不是 <img>，这样能跟 html[data-theme] 走，
   白天黑版 / 夜晚白版，与系统偏好无关、与站内主题开关一致。 */
.logo-img {
  display: inline-block; flex: none;
  background: url('/logo-light.png') no-repeat center / contain;
}
html[data-theme="dark"] .logo-img { background-image: url('/logo-dark.png'); }
.brand-row .logo-img { width: 30px; height: 30px; }
.admin-head .logo-img { width: 28px; height: 28px; }
/* hero 尺寸沿用下方既有 .hero-logo 规则 */
.login-title { font-size: 26px; font-weight: 700; letter-spacing: .5px; text-align: center; }
.login-slogan { text-align: center; color: var(--text-dim); font-size: 13px; margin-bottom: 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text);
  font-size: 14.5px; outline: none; transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text); cursor: pointer; font-size: 14px; font-weight: 500;
  transition: background .15s, border-color .15s, opacity .15s, transform .06s;
}
.btn:hover { background: var(--bg-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-block { width: 100%; }
.notice {
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; margin-bottom: 16px;
  background: var(--accent-soft); color: var(--text); border: 1px solid var(--border);
}
.notice.error { background: var(--danger-soft); border-color: var(--accent-line); }
/* 提醒类：比普通 notice 更醒目一点，但仍保持黑白灰配色 */
.notice.warn { border-color: var(--border-strong); border-style: dashed; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.notice.warn .btn { margin-left: auto; }
.login-foot { margin-top: 22px; text-align: center; font-size: 11.5px; color: var(--text-faint); }
/* 备案号（ICP / 公安联网备案）：低调但可点击，符合"首页底部标注并链接官方站"的要求 */
.login-foot .beian { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: center; align-items: center; }
.login-foot .beian a { color: var(--text-faint); text-decoration: none; border-bottom: 1px solid transparent; transition: color .15s, border-color .15s; }
.login-foot .beian a:hover { color: var(--text-dim); border-bottom-color: var(--border); }
.login-foot .beian a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------------- 应用布局 ---------------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; transition: margin-left .22s ease;
}
.sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }
.side-head { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.brand-row { display: flex; align-items: center; gap: 9px; }
.brand-name { font-weight: 700; font-size: 16.5px; letter-spacing: .3px; }
.brand-sub { font-size: 10.5px; color: var(--text-faint); letter-spacing: .6px; }
.new-chat {
  display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text); cursor: pointer;
  font-size: 14px; font-weight: 500; width: 100%;
}
.new-chat:hover { background: var(--bg-soft); }
.search-wrap { position: relative; }
.search-wrap .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.search-wrap .input { padding-left: 33px; font-size: 13.5px; }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 10px; }
.group-label { font-size: 11.5px; color: var(--text-faint); padding: 12px 10px 5px; font-weight: 600; letter-spacing: .4px; }
.conv-item {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 9px; cursor: pointer;
  color: var(--text); font-size: 13.5px; position: relative;
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item.active { background: var(--sidebar-hover); font-weight: 600; }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .pin { color: var(--accent); }
.conv-actions { display: none; gap: 2px; }
.conv-item:hover .conv-actions { display: flex; }
.icon-btn {
  width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 7px; border: none; background: transparent; color: var(--text-dim); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

.side-foot { border-top: 1px solid var(--border); padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.user-btn {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 9px; cursor: pointer;
  border: none; background: transparent; color: var(--text); width: 100%; text-align: left; font-size: 13.5px;
}
.user-btn:hover { background: var(--sidebar-hover); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font-size: 12.5px; font-weight: 700;
}
.side-menu { display: flex; flex-direction: column; gap: 1px; }
.side-menu button {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border: none; background: transparent;
  border-radius: 8px; cursor: pointer; color: var(--text-dim); font-size: 13px; text-align: left;
}
.side-menu button:hover { background: var(--sidebar-hover); color: var(--text); }

/* ---------------- 主区 ---------------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }
.topbar {
  height: 52px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 12px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.model-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--bg-elev); cursor: pointer; font-size: 13.5px; font-weight: 500;
}
.model-pill:hover { background: var(--bg-soft); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.dot.off { background: var(--text-faint); }
.topbar .spacer { flex: 1; }
.announce {
  padding: 7px 16px; font-size: 13px; background: var(--accent-soft); border-bottom: 1px solid var(--border);
  color: var(--text);
}

/* 居中欢迎 + 输入框 */
.scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }

/* ---- 右侧对话导航条：一问为一轮，直观展示本页对话次数，点击直达 ----
   挂在 .main 上、垂直居中，不随内容滚动；窄屏空间有限直接隐藏 */
.conv-rail {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  display: none; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 5px; border-radius: 12px; background: var(--bg-elev);
  border: 1px solid var(--border); box-shadow: var(--shadow); z-index: 6;
  max-height: 62vh; overflow-y: auto; scrollbar-width: none;
}
.conv-rail::-webkit-scrollbar { display: none; }
.rail-count {
  font-size: 10.5px; font-weight: 700; color: var(--on-accent); background: var(--accent);
  min-width: 20px; text-align: center; border-radius: 999px; padding: 2px 5px; margin-bottom: 3px;
}
.rail-dot { width: 20px; height: 16px; border: none; background: transparent; padding: 0; cursor: pointer; display: grid; place-items: center; border-radius: 6px; }
.rail-dot i { display: block; width: 5px; height: 5px; border-radius: 3px; background: var(--border-strong); transition: width .15s, background .15s; }
.rail-dot:hover { background: var(--bg-soft); }
.rail-dot:hover i { width: 10px; background: var(--text-dim); }
.rail-dot.on i { width: 12px; background: var(--accent); }
@media (max-width: 820px) { .conv-rail { display: none !important; } }

/* ---- 选段操作菜单：选中回复文本后弹出，小尺寸三个按钮；
   点翻译后展开成更大尺寸显示译文 ---- */
.sel-menu {
  position: fixed; z-index: 60; background: var(--bg-elev);
  border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: var(--shadow); padding: 4px; min-width: 128px;
  transition: min-width .2s ease, max-width .2s ease; max-width: 380px;
}
.sel-menu .sel-actions { display: flex; flex-direction: column; gap: 1px; }
.sel-menu .sel-btn {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px;
  border: none; background: transparent; border-radius: 8px; cursor: pointer;
  font-size: 13px; color: var(--text); text-align: left; white-space: nowrap; width: 100%;
}
.sel-menu .sel-btn:hover, .sel-menu .sel-btn.on { background: var(--bg-soft); }

/* 导出格式下拉菜单 */
.export-menu {
  position: fixed; z-index: 60; background: var(--bg-elev);
  border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: var(--shadow); padding: 4px; min-width: 150px;
}
.export-item {
  display: block; width: 100%; padding: 8px 12px; border: none;
  background: transparent; border-radius: 7px; cursor: pointer;
  font-size: 13px; color: var(--text); text-align: left;
}
.export-item:hover { background: var(--bg-soft); }
.sel-menu .sel-btn .icon { flex: none; }
.sel-menu .sel-result {
  display: none; margin-top: 4px; padding: 8px 10px; border-top: 1px solid var(--border);
  max-height: 240px; overflow-y: auto; font-size: 13px; line-height: 1.65; color: var(--text);
  white-space: pre-wrap; word-break: break-word; scrollbar-width: thin;
}
.sel-menu.expanded { min-width: 300px; max-width: 460px; }
.sel-menu.expanded .sel-result { display: block; }
.sel-menu .sel-loading { color: var(--text-faint); }
.hero {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 20px 0; gap: 18px;
}
.hero-logo { width: 54px; height: 54px; opacity: .95; }
.hero h1 { font-size: 24px; margin: 0; font-weight: 650; text-align: center; }
.hero p { margin: 0; color: var(--text-dim); font-size: 14px; text-align: center; }
.hero-samples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 640px; margin-top: 4px; }
.sample-chip {
  border: 1px solid var(--border-strong); background: var(--bg-elev); border-radius: 999px;
  padding: 7px 13px; font-size: 13px; color: var(--text-dim); cursor: pointer;
}
.sample-chip:hover { color: var(--text); border-color: var(--accent); }

/* 消息流 */
.thread { max-width: var(--maxw); margin: 0 auto; padding: 22px 20px 140px; }
.msg { display: flex; gap: 12px; margin-bottom: 26px; }
.msg .role-avatar {
  width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: var(--on-accent); background: var(--accent);
}
.msg.user .role-avatar { background: transparent; color: var(--text-dim); border: 1px solid var(--border-strong); }
.msg-body { flex: 1; min-width: 0; }
.msg-name { font-size: 12.5px; color: var(--text-faint); margin-bottom: 4px; }
.msg.user .bubble {
  background: var(--bubble-user); border: 1px solid var(--bubble-user-br);
  border-radius: var(--radius); padding: 10px 14px; display: inline-block; max-width: 100%;
  white-space: pre-wrap; word-break: break-word;
}
.md { word-break: break-word; overflow-wrap: anywhere; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 { margin: 20px 0 10px; line-height: 1.35; }
.md h1 { font-size: 20px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md blockquote { margin: 12px 0; padding: 2px 14px; border-left: 3px solid var(--accent); color: var(--text-dim); }
.md code { background: var(--code-bg); padding: 1.5px 5px; border-radius: 5px; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.md pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; overflow-x: auto; margin: 12px 0; position: relative;
}
.md pre code { background: none; padding: 0; font-size: 13px; line-height: 1.6; }
.md table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13.5px; }
.md th, .md td { border: 1px solid var(--border-strong); padding: 6px 10px; }
.md th { background: var(--bg-soft); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.md img { max-width: 100%; border-radius: 8px; }
/* 代码高亮配色（随主题切换） */
/* 代码高亮：同样走灰阶，用深浅和字重区分语义，不引入任何色相 */
html[data-theme="light"] {
  --hl-keyword: #151515; --hl-string: #5f6368; --hl-comment: #9a9a9a; --hl-number: #151515;
  --hl-title: #151515; --hl-attr: #5f6368; --hl-builtin: #151515; --hl-meta: #6b7280;
}
html[data-theme="dark"] {
  --hl-keyword: #f2f2f2; --hl-string: #a1a1a1; --hl-comment: #777777; --hl-number: #f2f2f2;
  --hl-title: #f2f2f2; --hl-attr: #b5b5b5; --hl-builtin: #dcdcdc; --hl-meta: #8a8a8a;
}
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute { color: var(--hl-string); }
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-number, .hljs-symbol, .hljs-bullet { color: var(--hl-number); }
.hljs-title, .hljs-title.function_, .hljs-section, .hljs-name, .hljs-selector-id { color: var(--hl-title); }
.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-selector-class, .hljs-property { color: var(--hl-attr); }
.hljs-built_in, .hljs-type, .hljs-class .hljs-title { color: var(--hl-builtin); }
.hljs-meta, .hljs-link { color: var(--hl-meta); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

.copy-code {
  position: absolute; right: 8px; top: 8px; font-size: 11.5px; padding: 3px 8px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text-dim); cursor: pointer;
}
.msg-actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
/* 朗读中：按钮常显且高亮，鼠标移开也能随时点停（黑白配色，只用底色/描边区分） */
.msg.speaking .msg-actions { opacity: 1; }
.icon-btn.speaking {
  background: var(--text); color: var(--bg); border-radius: 7px;
  box-shadow: 0 0 0 2px var(--bg) inset;
}
.icon-btn.speaking:hover { background: var(--text); color: var(--bg); opacity: .85; }
/* 触屏设备没有 hover：操作按钮常显，且放大点击区域 */
@media (hover: none) {
  .conv-actions { display: flex; }
  .msg-actions { opacity: 1; }
  .icon-btn { width: 34px; height: 34px; }
  .copy-code { opacity: 1; }
}
.reasoning { margin-bottom: 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.reasoning > summary { cursor: pointer; padding: 7px 12px; font-size: 12.5px; color: var(--text-dim); }
.reasoning .reason-body { padding: 0 12px 10px; font-size: 13px; color: var(--text-dim); white-space: pre-wrap; }
/* 生成中：只有字母 O 缓慢淡入淡出，方形底色保持不动。
   纯透明度动画，白天/夜间主题通用 */
.msg .role-avatar > .avatar-fade { animation: avatarFade 2.4s ease-in-out infinite; }
@keyframes avatarFade { 0%, 100% { opacity: 1; } 50% { opacity: .18; } }
@media (prefers-reduced-motion: reduce) {
  .msg .role-avatar > .avatar-fade { animation: none; }
}

.attach-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text-dim); max-width: 320px;
}
.chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip img { width: 22px; height: 22px; object-fit: cover; border-radius: 4px; }

/* 输入区 */
.composer-wrap { flex: none; padding: 0 20px 14px; background: var(--bg); }
.composer-wrap.centered { padding-bottom: 28px; }
.composer {
  max-width: var(--maxw); margin: 0 auto; background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: 18px; padding: 10px 12px 8px; box-shadow: var(--shadow); position: relative;
}
/* ---- @ 引用菜单：列出本次上传的图片/文件/网页，点击插入引用标记 ---- */
.mention-menu {
  position: absolute; left: 8px; right: 8px; bottom: calc(100% - 6px);
  background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: 14px;
  box-shadow: var(--shadow); padding: 6px; z-index: 40; max-height: 250px; overflow-y: auto;
}
.mention-tip { font-size: 11px; color: var(--text-faint); padding: 4px 9px 7px; }
.mention-item {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px;
  border: none; background: transparent; border-radius: 9px; cursor: pointer;
  font-size: 13px; color: var(--text); text-align: left;
}
.mention-item .icon { flex: none; }
.mention-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mention-kind { flex: none; font-size: 11px; color: var(--text-faint); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; }
.mention-item:hover, .mention-item.on { background: var(--bg-soft); }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.composer textarea {
  width: 100%; border: none; outline: none; resize: none; background: transparent; color: var(--text);
  font-family: inherit; font-size: 15px; line-height: 1.6; max-height: 200px; min-height: 26px; padding: 4px 4px 2px;
}
.composer-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text-dim); cursor: pointer; font-size: 12.5px;
}
.tool-btn:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.tool-btn:disabled { opacity: .45; cursor: not-allowed; }
.composer .spacer { flex: 1; }
/* 语音输入：聆听中图标脉冲呼吸 */
.tool-btn.voice-btn.on { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.tool-btn.voice-btn.on .icon { animation: voicePulse 1.5s ease-in-out infinite; }
@keyframes voicePulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .tool-btn.voice-btn.on .icon { animation: none; } }
.send-btn {
  width: 34px; height: 34px; border-radius: 10px; border: none; background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; cursor: pointer;
}
.send-btn:not(:disabled):hover { background: var(--accent-hover); }
/* 夜晚模式下发送键保持黑色（白箭头），与 ChatGPT 深色风格一致，
   不跟随 --accent 反相成白色 */
html[data-theme="dark"] .send-btn { background: #0b0b0c; color: #f2f2f2; }
html[data-theme="dark"] .send-btn:not(:disabled):hover { background: #262627; }
.send-btn:disabled { background: var(--border-strong); cursor: not-allowed; }
.hint { text-align: center; font-size: 11.5px; color: var(--text-faint); margin-top: 8px; }

/* ---------------- Modal / Toast ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 60; padding: 20px;
}
.modal {
  width: 100%; max-width: 520px; max-height: 86vh; overflow: auto; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 16px; padding: 22px; box-shadow: var(--shadow);
}
.modal.wide { max-width: 720px; }
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal .sub { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; }
.segmented button {
  padding: 8px 14px; border: none; background: var(--bg-elev); color: var(--text-dim); cursor: pointer; font-size: 13px;
}
.segmented button.on { background: var(--accent); color: #fff; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13.5px; padding: 5px 0; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border-strong); border-radius: 99px; cursor: pointer; transition: .18s; }
.slider:before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .18s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(16px); }

/* 语言切换菜单 */
.lang-menu {
  background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
.lang-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px 10px; border: none;
  border-radius: 8px; background: transparent; color: var(--text); cursor: pointer;
  font-size: 13.5px; text-align: left; font-family: inherit;
}
.lang-menu button:hover { background: var(--bg-soft); }
.lang-menu button.on { color: var(--accent); font-weight: 600; }
.lang-menu button span { flex: 1; }

#toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  padding: 10px 16px; border-radius: 10px; background: var(--bg-elev); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: 13.5px; animation: pop .18s ease; max-width: 90vw;
}
.toast.err { border-color: var(--accent-line); color: var(--danger); }
.toast.ok { border-color: var(--accent-line); }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

/* ---------------- 管理后台 ---------------- */
.admin { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.admin-head { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.admin-body { flex: 1; display: flex; overflow: hidden; }
.admin-nav { width: 190px; flex: none; border-right: 1px solid var(--border); padding: 12px 8px; overflow-y: auto; }
.admin-nav button {
  display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px 12px; border: none; border-radius: 9px;
  background: transparent; color: var(--text-dim); cursor: pointer; font-size: 13.5px; text-align: left;
}
.admin-nav button:hover { background: var(--bg-soft); color: var(--text); }
.admin-nav button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.admin-main { flex: 1; overflow-y: auto; padding: 20px 24px 60px; }
.admin-main h2 { margin: 0 0 14px; font-size: 19px; }
.card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); padding: 16px; margin-bottom: 16px; }
.card h4 { margin: 0 0 12px; font-size: 14.5px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 560px; }
table.grid th, table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.grid th { color: var(--text-dim); font-weight: 600; font-size: 12.5px; }
table.grid tr:last-child td { border-bottom: none; }
.tag { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--text-dim); }
.tag.on { color: var(--text); border-color: var(--border-strong); }
.tag.off { color: var(--text-faint); border-color: var(--border); }
.tag.role-admin, .tag.accent { color: var(--accent); border-color: var(--accent-line); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--bg-elev); }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--text-dim); }
.model-editor { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.model-editor > header { display: flex; align-items: center; gap: 10px; padding: 11px 14px; cursor: pointer; }
.model-editor > header:hover { background: var(--bg-soft); }
.model-editor .body { padding: 4px 14px 14px; border-top: 1px solid var(--border); display: none; }
.model-editor.open .body { display: block; }
.empty { text-align: center; color: var(--text-faint); padding: 40px 0; font-size: 14px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--text-dim); font-size: 12.5px; }

/* ============================================================
   响应式 / 手机端
   ============================================================ */
.mobile-only { display: none; }
.sidebar-mask {
  position: fixed; inset: 0; background: var(--overlay); z-index: 49; display: none;
  backdrop-filter: blur(1px);
}
.sidebar-mask.show { display: block; }

/* ---------- 平板 / 小窗口 ---------- */
@media (max-width: 900px) {
  :root { --maxw: 100%; }
  .thread { padding: 18px 14px 120px; }
}

/* ---------- 手机 ---------- */
@media (max-width: 820px) {
  /* 侧栏：抽屉 + 遮罩 */
  .sidebar {
    position: fixed; z-index: 50; top: 0; left: 0; height: 100vh; height: 100dvh;
    width: min(84vw, 300px); --sidebar-w: min(84vw, 300px);
    box-shadow: 0 0 40px rgba(0, 0, 0, .35);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar.collapsed { margin-left: calc(-1 * min(84vw, 300px)); }
  .mobile-only { display: inline-flex; }
  .side-head, .side-foot { padding-left: max(10px, env(safe-area-inset-left)); }

  /* 顶栏 */
  .topbar {
    height: 50px; padding: 0 8px; gap: 6px;
    padding-top: env(safe-area-inset-top);
    height: calc(50px + env(safe-area-inset-top));
  }
  .model-pill { max-width: 46vw; padding: 6px 10px; }
  .model-pill #modelLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #visionTag { display: none !important; }
  .announce { padding: 6px 12px; font-size: 12.5px; }

  /* 消息区 */
  .scroll { -webkit-overflow-scrolling: touch; }
  .thread { padding: 14px 12px 110px; }
  .msg { gap: 9px; margin-bottom: 20px; }
  .msg .role-avatar { width: 27px; height: 27px; font-size: 11px; }
  .msg.user .bubble { padding: 9px 12px; }
  .md { font-size: 14.8px; }
  .md pre { padding: 10px 12px; font-size: 12.3px; border-radius: 8px; }
  .md table { font-size: 13px; display: block; overflow-x: auto; }
  .hero { padding: 20px 16px 0; gap: 14px; }
  .hero-logo { width: 44px; height: 44px; }
  .hero h1 { font-size: 20px; padding: 0 8px; }
  .hero p { font-size: 13px; }
  .hero-samples { flex-wrap: nowrap; overflow-x: auto; padding: 2px 12px; margin: 0 -12px; justify-content: flex-start; scrollbar-width: none; }
  .hero-samples::-webkit-scrollbar { display: none; }
  .sample-chip { flex: none; }

  /* 输入区 */
  .composer-wrap {
    padding: 0 10px calc(8px + env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  .composer { border-radius: 16px; padding: 9px 10px 7px; }
  .composer textarea {
    font-size: 16px; /* iOS 聚焦时不自动放大页面 */
    max-height: 140px;
  }
  .composer-tools { flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding-bottom: 2px; scrollbar-width: none; }
  .composer-tools::-webkit-scrollbar { display: none; }
  .tool-btn { flex: none; padding: 7px 10px; font-size: 12px; }
  .send-btn { width: 38px; height: 38px; flex: none; }
  #hint { display: none; }
  .attach-chips { max-height: 92px; overflow-y: auto; }
  .chip { max-width: 78vw; }

  /* 弹窗：底部抽屉 */
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%; width: 100%; border-radius: 18px 18px 0 0; max-height: 92dvh;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    animation: sheet .22s ease;
  }
  @keyframes sheet { from { transform: translateY(24px); opacity: .6; } }
  .modal.wide { max-width: 100%; }
  .modal-foot { flex-direction: column-reverse; gap: 8px; }
  .modal-foot .btn { width: 100%; padding: 12px; }
  .grid2 { grid-template-columns: 1fr; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 10px 6px; }
  .checkline { padding: 7px 0; }
  .field { margin-bottom: 12px; }

  /* 管理后台 */
  .admin-head { padding: 10px 12px; gap: 8px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .admin-head > div { min-width: 0; }
  .admin-head .btn { padding: 8px 10px; font-size: 13px; }
  .admin-body { flex-direction: column; }
  .admin-nav {
    width: 100%; flex: none; border-right: none; border-bottom: 1px solid var(--border);
    display: flex; overflow-x: auto; gap: 4px; padding: 8px 10px; scrollbar-width: none;
  }
  .admin-nav::-webkit-scrollbar { display: none; }
  .admin-nav button { width: auto; flex: none; padding: 8px 12px; white-space: nowrap; border: 1px solid var(--border); }
  .admin-nav button span { display: inline; }
  .admin-main { padding: 14px 12px calc(40px + env(safe-area-inset-bottom)); }
  .card { padding: 13px; border-radius: 12px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 11px; }
  .stat .n { font-size: 20px; }
  .model-editor > header { flex-wrap: wrap; gap: 6px; padding: 10px 12px; font-size: 13.5px; }
  .model-editor .body { padding: 2px 12px 12px; }
  .row .btn { padding: 9px 12px; }
  .admin-head .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* 后台表格 → 卡片式布局 */
  .table-wrap { overflow-x: visible; }
  table.grid { min-width: 0; display: block; }
  table.grid thead { display: none; }
  table.grid tbody { display: block; }
  table.grid tr {
    display: block; border: 1px solid var(--border); border-radius: 12px;
    padding: 6px 12px; margin-bottom: 10px; background: var(--bg);
  }
  table.grid td {
    display: block; border-bottom: none; padding: 5px 0; text-align: left;
    white-space: normal; word-break: break-word;
  }
  table.grid td[data-label]::before {
    content: attr(data-label); display: inline-block; min-width: 78px; margin-right: 10px;
    color: var(--text-faint); font-size: 12px;
  }
  table.grid td:last-child { text-align: left; }
  table.grid td:last-child .btn { margin: 3px 4px 3px 0; }
  .login-card { padding: 26px 20px 22px; border-radius: 16px; }
  .login-title { font-size: 23px; }
}

/* ---------- 小屏手机 ---------- */
@media (max-width: 400px) {
  .tool-btn { padding: 6px 8px; font-size: 11.5px; gap: 4px; }
  .tool-btn .icon { width: 14px; height: 14px; }
  .thread { padding: 12px 10px 104px; }
  .brand-name { font-size: 15px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- 横屏矮屏 ---------- */
@media (max-height: 480px) and (max-width: 900px) {
  .hero-logo { display: none; }
  .hero { gap: 10px; padding-top: 12px; }
  .hero h1 { font-size: 18px; }
  .hero-samples { display: none; }
  .thread { padding-bottom: 90px; }
}

/* ---------- 远程模型选择器（拉取 Key 名下模型） ---------- */
.picker { margin-top: 14px; border-top: 1px dashed var(--border-strong); padding-top: 12px; }
.picker-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.picker-head .input { flex: 1 1 200px; min-width: 150px; margin: 0; }
.picker-head .muted { white-space: nowrap; }
.picker-list { max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px; background: var(--bg-soft); }
.pick-row { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 8px; cursor: pointer; user-select: none; }
.pick-row:hover { background: var(--sidebar-hover); }
.pick-row.added { opacity: .58; }
.pick-row input[type="checkbox"] { flex: 0 0 auto; width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.pick-row .pick-id { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.pick-row .pick-note { flex: 0 0 auto; font-size: 11.5px; color: var(--text-faint); }
.picker-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
@media (max-width: 560px) {
  .picker-list { max-height: 260px; }
  .picker-head .input { flex-basis: 100%; }
}

/* 深度思考开关：开启时高亮，关闭时呈普通描边，一眼看出当前状态 */
.think-btn { transition: all .15s; }
.think-btn.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.think-btn:not(.on) { opacity: .62; }
.think-btn:not(.on) span { text-decoration: line-through; text-decoration-thickness: 1px; }

/* 后台：拉取模型选择弹层的列表行 */
.pm-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); cursor: pointer; color: var(--text); text-align: left;
  font: inherit; font-size: 13px; transition: border-color .12s ease, background .12s ease;
}
.pm-item:hover { border-color: var(--border-strong); background: var(--bg-soft); }
