/* goqbot WebUI
   参照 Telegram 的样子：白色会话列表、蓝色强调色、带底纹的聊天背景、带小尾巴的气泡（自己发的是浅绿色）。
   深色模式参照 Telegram 的夜间蓝主题 */

:root {
    --canvas: #f1f2f5; --surface: #ffffff; --surface-2: #f4f4f6; --line: #e3e5ea; --ink: #111418; --muted: #707579;
    --accent: #3390ec; --accent-ink: #ffffff; --accent-soft: #e6f1fd;
    --select: #3390ec; --select-ink: #ffffff;
    --rail: #ffffff; --rail-ink: #707579; --rail-hover: #f4f4f6; --rail-active: #e6f1fd; --rail-active-ink: #3390ec; --rail-line: #e3e5ea;
    --bubble-in: #ffffff; --bubble-out: #effedd; --bubble-in-meta: #8a9097; --bubble-out-meta: #4fae4e; --bubble-shadow: rgba(16, 35, 47, .15);
    --chat-bg:
      radial-gradient(at 12% 18%, #e2e4bc 0, transparent 55%),
      radial-gradient(at 88% 12%, #96c08d 0, transparent 50%),
      radial-gradient(at 78% 86%, #d7dc92 0, transparent 55%),
      radial-gradient(at 18% 90%, #8fbf95 0, transparent 55%),
      #c4d6a4;
    --chat-dots: rgba(40, 70, 30, .07);
    --pill: rgba(36, 64, 30, .32); --pill-ink: #ffffff;
    --ok: #2f9e52; --ok-soft: #e3f5e8; --wait: #b26a00; --wait-soft: #fdf1dd; --bad: #e53935; --bad-soft: #fde8e7;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Cascadia Mono", Consolas, "Noto Sans Mono CJK SC", monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --canvas: #0e1621; --surface: #17212b; --surface-2: #1e2c3a; --line: #253241; --ink: #f2f4f6; --muted: #7f91a4;
    --accent: #5aa7f0; --accent-ink: #ffffff; --accent-soft: #1d3346;
    --select: #2b5278; --select-ink: #ffffff;
    --rail: #17212b; --rail-ink: #7f91a4; --rail-hover: #1e2c3a; --rail-active: #22364b; --rail-active-ink: #6ab2f2; --rail-line: #0f1923;
    --bubble-in: #182533; --bubble-out: #2b5278; --bubble-in-meta: #6d8297; --bubble-out-meta: #8fb6dc; --bubble-shadow: rgba(0, 0, 0, .35);
    --chat-bg:
      radial-gradient(at 15% 20%, #1a2a3a 0, transparent 55%),
      radial-gradient(at 85% 80%, #132232 0, transparent 55%),
      #0e1621;
    --chat-dots: rgba(255, 255, 255, .035);
    --pill: rgba(0, 0, 0, .38); --pill-ink: #e8edf2;
    --ok: #5ccf86; --ok-soft: #173326; --wait: #e6b34f; --wait-soft: #3a2f16; --bad: #f2786c; --bad-soft: #3d1d1a;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --canvas: #0e1621; --surface: #17212b; --surface-2: #1e2c3a; --line: #253241; --ink: #f2f4f6; --muted: #7f91a4;
    --accent: #5aa7f0; --accent-ink: #ffffff; --accent-soft: #1d3346;
    --select: #2b5278; --select-ink: #ffffff;
    --rail: #17212b; --rail-ink: #7f91a4; --rail-hover: #1e2c3a; --rail-active: #22364b; --rail-active-ink: #6ab2f2; --rail-line: #0f1923;
    --bubble-in: #182533; --bubble-out: #2b5278; --bubble-in-meta: #6d8297; --bubble-out-meta: #8fb6dc; --bubble-shadow: rgba(0, 0, 0, .35);
    --chat-bg:
      radial-gradient(at 15% 20%, #1a2a3a 0, transparent 55%),
      radial-gradient(at 85% 80%, #132232 0, transparent 55%),
      #0e1621;
    --chat-dots: rgba(255, 255, 255, .035);
    --pill: rgba(0, 0, 0, .38); --pill-ink: #e8edf2;
    --ok: #5ccf86; --ok-soft: #173326; --wait: #e6b34f; --wait-soft: #3a2f16; --bad: #f2786c; --bad-soft: #3d1d1a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.55 var(--font); color: var(--ink); background: var(--canvas); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .code { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: var(--wait); }
.form-error { color: var(--bad); margin: 0; padding: 0; list-style: none; }
.form-error:empty { display: none; }

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

/* ---------- 按钮与表单 ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; height: 40px; }
.btn .icon { width: 16px; height: 16px; }
.btn.icon-only { width: 34px; padding: 0; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
input[type="text"], input[type="password"], input[type="search"], input[type="url"], input[type="number"], input[type="date"], select {
  height: 34px; padding: 0 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.field { display: grid; gap: 5px; min-width: 0; align-content: start; }
.field > span { font-weight: 600; font-size: 13px; }
.field small { color: var(--muted); font-size: 12px; }
.field input { width: 100%; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input[type="password"], .inline input[type="text"], .inline input[type="url"] { flex: 1; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- 登录 ---------- */

.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--chat-bg); }
.login-box { width: min(380px, 100%); display: grid; gap: 16px; padding: 32px; background: var(--surface); border-radius: 18px; box-shadow: 0 10px 40px rgba(16, 35, 47, .18); }
.login-brand { display: flex; align-items: center; gap: 10px; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.login-box code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.pw-rules { list-style: none; margin: -6px 0 0; padding: 0; display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.pw-rules li { display: flex; align-items: center; gap: 8px; }
.pw-rules li.ok { color: var(--ok); }
.pw-mark { width: 16px; height: 16px; display: inline-grid; place-items: center; border-radius: 50%; background: var(--surface-2); font-size: 11px; font-weight: 700; }
.pw-rules li.ok .pw-mark { background: var(--ok-soft); }
.pw-show { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: -6px; }
.btn.ghost.wide { margin-top: -8px; }

.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font: 700 20px/1 var(--font); letter-spacing: 0;
}

/* ---------- 布局：左侧导航 + 内容 ---------- */

.app { display: grid; grid-template-columns: 76px 1fr; height: 100%; }
.rail {
  display: flex; flex-direction: column; gap: 6px; padding: 12px 8px; background: var(--rail); color: var(--rail-ink); border-right: 1px solid var(--rail-line);
  overflow-y: auto; scrollbar-width: none;
}
.brand { display: grid; justify-items: center; gap: 4px; padding: 4px 0 10px; color: var(--ink); font-size: 11px; font-weight: 600; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.nav-group { display: grid; gap: 2px; padding-top: 8px; }
.nav-group + .nav-group { border-top: 1px solid var(--line); margin-top: 4px; }
.nav {
  position: relative; display: grid; justify-items: center; gap: 2px; padding: 8px 0 6px; border-radius: 10px;
  color: var(--rail-ink); font: 12px/1.3 var(--font); background: none; border: 0; cursor: pointer; width: 100%;
}
.nav .icon { width: 22px; height: 22px; stroke-width: 1.6; }
.nav:hover { background: var(--rail-hover); color: var(--ink); text-decoration: none; }
.nav.active { background: var(--rail-active); color: var(--rail-active-ink); font-weight: 600; }
.nav-badge {
  position: absolute; top: 3px; left: 50%; margin-left: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600;
  box-shadow: 0 0 0 2px var(--rail);
}
.rail-foot { margin-top: auto; display: grid; gap: 2px; padding-top: 8px; }
.live { justify-self: center; font-size: 11px; padding: 1px 8px; border-radius: 10px; color: var(--wait); background: var(--wait-soft); }
.live.on { color: var(--ok); background: var(--ok-soft); }
.live:empty { display: none; }

.view { overflow-y: auto; min-width: 0; }
.view:focus { outline: none; }
.view-chat { overflow: hidden; }

/* ---------- 管理页 ---------- */

.page { max-width: 940px; margin: 0 auto; padding: 32px 32px 64px; display: grid; gap: 16px; }
.page-head { display: grid; gap: 4px; margin-bottom: 4px; }
.page-head h1 { font-size: 22px; letter-spacing: -.01em; }
.page-head p { color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: grid; gap: 12px; }
.panel h2 { font-size: 15px; }
.panel-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.status-line {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px;
  padding: 18px 20px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
}
.status-line h2 { font-size: 18px; }
.status-line p { color: var(--muted); }
.status-line .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 5px var(--bad-soft); }
.status-line.ok .dot { background: var(--ok); box-shadow: 0 0 0 5px var(--ok-soft); }

.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 24px; margin: 0; }
.facts div { display: grid; gap: 2px; min-width: 0; }
.facts dt { margin: 0; color: var(--muted); font-size: 12px; }
.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.rows { list-style: none; margin: 0; padding: 0; display: grid; }
.rows li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.rows li:first-child { border-top: 0; }
.rows code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); background: var(--ok-soft); }
.pill.wait { color: var(--wait); background: var(--wait-soft); }
.pill.bad { color: var(--bad); background: var(--bad-soft); }
.pill.muted { color: var(--muted); background: var(--surface-2); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.save-result { display: grid; gap: 6px; }
.save-result:empty { display: none; }

.search { position: relative; display: flex; align-items: center; }
.search .icon { position: absolute; left: 9px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 30px; width: 100%; }

.overview { display: grid; gap: 16px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
label.btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* 连接：参照 NapCat 的网络配置，类型标签页 + 卡片，新建 / 编辑用弹窗 */
.conn-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tabs { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border: 0; border-radius: 7px; background: none; font: inherit; color: var(--muted); cursor: pointer; }
.tab span { font-size: 11px; min-width: 18px; padding: 0 5px; border-radius: 8px; background: var(--line); color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.tab.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(10, 30, 40, .1); }
.tab.active span { background: var(--accent-soft); color: var(--accent); }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; width: 300px; padding: 6px; display: grid; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(10, 30, 40, .16);
}
.menu-pop button { display: grid; gap: 2px; padding: 10px 12px; border: 0; border-radius: 8px; background: none; font: inherit; color: var(--ink); text-align: left; cursor: pointer; }
.menu-pop button:hover { background: var(--surface-2); }
.menu-pop small { color: var(--muted); font-size: 12px; }

.ncards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.ncards-empty { grid-column: 1 / -1; display: grid; gap: 6px; padding: 40px 20px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.ncard { display: flex; flex-direction: column; gap: 12px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; min-width: 0; }
.ncard.off { background: var(--surface-2); }
.ncard header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ncard h2 { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ncard-state { display: flex; align-items: center; gap: 8px; min-height: 22px; }
.ncard-state small { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { display: grid; gap: 2px; min-width: 0; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; }
.ncard.off .tile { background: var(--surface); }
.tile.full { grid-column: 1 / -1; }
.tile span { font-size: 12px; color: var(--muted); }
.tile b { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ncard footer { display: flex; gap: 8px; margin-top: auto; }
.ncard footer .btn { flex: 1; border-radius: 999px; }

.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.switch input { appearance: none; -webkit-appearance: none; margin: 0; width: 36px; height: 20px; border-radius: 10px; background: var(--line); position: relative; cursor: pointer; transition: background .15s; flex: none; }
.switch input::before { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::before { transform: translateX(16px); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .switch input, .switch input::before { transition: none; } }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.form-grid > .full { grid-column: 1 / -1; }
.switch-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.switch-card > span:first-child { display: grid; gap: 2px; }
.switch-card small { color: var(--muted); font-size: 12px; }
.conn-edit { display: grid; gap: 14px; }
.conn-edit .actions { display: flex; justify-content: flex-end; gap: 8px; }
.conn-edit .warn:empty { display: none; }
.preview small { color: var(--muted); font-size: 12px; }
.more summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.dialog.mid { width: min(580px, calc(100vw - 32px)); }

/* 配置（图形化） */
.settings { display: grid; gap: 16px; padding-bottom: 8px; }
.settings .panel > div:first-child h2 + p { margin-top: 2px; }
.field.placeholder { visibility: hidden; }
.intents { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px 14px; }
.intent { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.intent:hover { background: var(--surface-2); }
.intent input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.intent span { display: grid; gap: 1px; min-width: 0; }
.intent b { font-weight: 500; }
.intent small { color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; }
.intent.required { cursor: default; opacity: .75; }
.cmd-demo { display: grid; gap: 6px; justify-items: start; }
.cmd-preview { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 22%, transparent); border-radius: 14px 4px 14px 14px; }
.save-bar {
  position: sticky; bottom: 16px; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(10, 30, 40, .16);
}
.restart-note { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-radius: var(--radius); background: var(--wait-soft); color: var(--wait); }
.restart-note p { flex: 1; min-width: 200px; }

.grants { display: grid; gap: 12px; }
.grant-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 8px; }
.grant-card header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grant-card h3 { font-size: 15px; }
.grant-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 2px 16px; }
.grant-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; }
.grant-list li:hover { background: var(--surface-2); }
.grant-list li.off .grant-name { opacity: .55; }
.grant-sub { margin: 4px 0 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.grant-list.provided li { cursor: default; }
.grant-name { flex: 1; min-width: 0; display: grid; gap: 1px; }
.grant-name code { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grant-name small { color: var(--muted); font-size: 12px; }
.tag.danger { color: var(--bad); background: var(--bad-soft); border-color: transparent; font-weight: 600; }

/* 插件 */
.plugin-list { display: grid; gap: 10px; }
.plugin { display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; }
.plugin-top { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; }
.perm { display: grid; gap: 8px; padding-top: 12px; border-top: 1px dashed var(--line); }
.perm-row { display: grid; grid-template-columns: 72px 1fr; gap: 10px; align-items: baseline; }
.perm-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.perm-value { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.perm-foot { display: flex; justify-content: flex-end; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); cursor: default; }
.chip b { font-size: 11px; font-weight: 600; color: var(--bad); }
.chip.sensitive { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.chip.off { text-decoration: line-through; opacity: .6; }
.grant-card { transition: box-shadow .3s; }
.grant-card.focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }
.plugin-main { display: grid; gap: 6px; min-width: 0; }
.plugin-main h2 { font-size: 15px; display: flex; gap: 8px; align-items: baseline; }
.plugin-main h2 small { color: var(--muted); font-weight: 400; font-size: 12px; }
.plugin-main > p { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.plugin-actions { display: flex; gap: 6px; align-items: center; flex: none; }

/* 日志与配置 */
.logbox {
  margin: 0; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  height: 60vh; overflow: auto; white-space: pre-wrap; word-break: break-all; line-height: 1.6;
}
.log-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.log-file { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.log-file select { font-weight: 400; min-width: 230px; }
.log-search { flex: 1; min-width: 180px; }
.log-auto span { font-size: 13px; color: var(--muted); }
.log-auto input:disabled { opacity: .45; cursor: not-allowed; }
.log-meta { color: var(--muted); font-size: 12px; margin-top: -4px; }
.logview {
  height: calc(100vh - 250px); min-height: 320px; overflow: auto; padding: 6px 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
}
.log-entry { display: grid; grid-template-columns: 64px 40px 1fr; gap: 10px; padding: 1px 14px; }
.log-entry:hover { background: var(--surface-2); }
.log-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.log-level { font-family: var(--font); font-size: 11.5px; font-weight: 600; color: var(--muted); padding-top: 1px; }
.log-msg { white-space: pre-wrap; word-break: break-all; min-width: 0; }
.lv-Warning { background: color-mix(in srgb, var(--wait-soft) 55%, transparent); }
.lv-Warning .log-level, .lv-Warning .log-msg { color: var(--wait); }
.lv-Error { background: color-mix(in srgb, var(--bad-soft) 60%, transparent); }
.lv-Error .log-level, .lv-Error .log-msg { color: var(--bad); }
.lv-Debug .log-level { color: var(--accent); }
.log-empty { padding: 40px 20px; text-align: center; color: var(--muted); font-family: var(--font); }
.line.l-err { color: var(--bad); }
.line.l-warn { color: var(--wait); }
textarea.code { width: 100%; min-height: calc(100vh - 290px); padding: 12px 14px; line-height: 1.6; resize: vertical; tab-size: 2; white-space: pre; }
.notes { margin: 0; padding: 12px 14px; background: var(--surface-2); border-radius: 8px; white-space: pre-wrap; max-height: 320px; overflow: auto; font-family: var(--font); font-size: 13px; }
.release { display: grid; gap: 10px; }

/* ---------- 聊天 ---------- */

.chat { display: grid; grid-template-columns: 340px 1fr; height: 100%; }
.chat-side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--surface); }
.chat-side-head { display: grid; gap: 10px; padding: 14px 12px 8px; }
.chat-side-head .search input { height: 40px; border-radius: 999px; border-color: transparent; background: var(--surface-2); padding-left: 40px; }
.chat-side-head .search input:focus { background: var(--surface); border-color: var(--accent); box-shadow: none; }
.chat-side-head .search .icon { left: 14px; }
.chat-side-head h1 { font-size: 18px; }
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.list-empty { padding: 28px 14px; color: var(--muted); line-height: 1.7; }

.chat-item { display: flex; gap: 12px; align-items: center; padding: 8px 10px; border-radius: 12px; color: inherit; }
.chat-item:hover { background: var(--surface-2); text-decoration: none; }
.chat-item .avatar.md { width: 54px; height: 54px; font-size: 21px; }
.chat-item.active { background: var(--select); color: var(--select-ink); }
.chat-item.active .chat-item-text, .chat-item.active .chat-item-top time { color: color-mix(in srgb, var(--select-ink) 80%, transparent); }
.chat-item.active .badge { background: var(--select-ink); color: var(--select); }
.chat-item-main { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.chat-item-top, .chat-item-bottom { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.chat-item-top b { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-top time { flex: none; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chat-item-text { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--accent); color: #fff; font-size: 12px; line-height: 22px; text-align: center; font-weight: 600; }

.avatar { flex: none; display: inline-grid; place-items: center; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.avatar.md { width: 44px; height: 44px; font-size: 18px; }
.avatar.sm { width: 36px; height: 36px; font-size: 15px; }
.avatar.square, .avatar.sm.square { border-radius: 50%; }
.avatar.mono { --h: 190; background: linear-gradient(hsl(var(--h) 75% 66%), hsl(var(--h) 62% 52%)); color: #fff; font-weight: 600; }
.avatar.digits { font-size: 15px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.avatar.md.digits { font-size: 16px; }
.avatar.bot { background: linear-gradient(#5fb1f5, var(--accent)); color: #fff; }

/* 聊天背景：渐变底色加一层很淡的圆点底纹 */
.chat-panel {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: radial-gradient(var(--chat-dots) 1.2px, transparent 1.6px) 0 0 / 22px 22px, var(--chat-bg);
}
.panel-empty { margin: auto; display: grid; justify-items: center; gap: 10px; padding: 18px 24px; border-radius: 16px; background: var(--pill); color: var(--pill-ink); }
.panel-head { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.panel-head .back { display: none; }
.panel-title { flex: 1; min-width: 0; }
.panel-title h2 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-title p { display: flex; gap: 12px; color: var(--muted); font-size: 13px; }
.title-btn { max-width: 100%; padding: 0; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: 4px; }
.title-btn:hover { color: var(--accent); }
.title-btn:focus-visible, .avatar-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.avatar-btn { flex: none; padding: 0; border: 0; background: none; border-radius: 50%; cursor: pointer; line-height: 0; }
.avatar-btn:hover .avatar { box-shadow: 0 0 0 2px var(--accent-soft); }

/* 会话列表的右键菜单 */
.ctx-menu {
  position: fixed; z-index: 30; min-width: 180px; padding: 6px; border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 86%, transparent); border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.6); backdrop-filter: blur(16px) saturate(1.6);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}
.ctx-item { display: block; width: 100%; padding: 8px 12px; border: 0; border-radius: 8px; background: none; color: var(--ink); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.ctx-item:hover, .ctx-item:focus-visible { background: color-mix(in srgb, var(--ink) 8%, transparent); outline: none; }
.ctx-item:disabled { color: var(--muted); cursor: not-allowed; background: none; }
.ctx-item:disabled { opacity: .7; }
.ctx-item small { display: block; max-width: 220px; margin-top: 1px; font-size: 11.5px; line-height: 1.4; color: var(--muted); white-space: normal; }
.ctx-item.danger { color: var(--bad); }
.ctx-item.danger:hover, .ctx-item.danger:focus-visible { background: var(--bad-soft); }
.ctx-item.danger:disabled { color: var(--muted); background: none; }
.ctx-sep { height: 1px; margin: 4px 6px; background: var(--line); }

/* 群资料、用户资料 */
.profile { display: grid; gap: 14px; }
.profile-head { display: flex; align-items: center; gap: 14px; }
.profile-head > div { display: grid; gap: 2px; min-width: 0; }
.profile-head b { font-size: 16px; overflow-wrap: anywhere; }
.profile-head small { color: var(--muted); font-size: 12.5px; }
.avatar.lg { width: 56px; height: 56px; font-size: 22px; }
.avatar.lg.square { border-radius: 50%; }
.avatar.lg.digits { font-size: 18px; }
.profile-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0; font-size: 13.5px; }
.profile-list dt { color: var(--muted); }
.profile-list dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.profile-sub { margin: 4px 0 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); font-weight: 600; }
.profile-loading, .profile-empty { margin: 0; color: var(--muted); font-size: 13px; }
.profile-error { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--wait-soft); color: var(--wait); font-size: 13px; line-height: 1.6; }

.msgs { --msgs-pad: 24px; flex: 1; overflow-y: auto; padding: 8px var(--msgs-pad) 20px; display: flex; flex-direction: column; }
/* 日期和提示：背景上的半透明小胶囊 */
.msgs-hint { align-self: center; margin: 10px 0 2px; padding: 2px 10px; border-radius: 999px; background: var(--pill); color: var(--pill-ink); font-size: 12.5px; }
.msgs-hint.error { background: var(--bad); color: #fff; }
.day { position: sticky; top: 8px; z-index: 2; align-self: center; margin: 14px 0 4px; }
.day span { font-size: 13px; font-weight: 500; color: var(--pill-ink); background: var(--pill); padding: 3px 10px; border-radius: 999px; }

.msg { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; max-width: 100%; }
.msg-main { position: relative; display: grid; gap: 4px; min-width: 0; max-width: min(620px, 78%); justify-items: start; }
/* 名字和时间在气泡上方，放在背景上的半透明小胶囊里，换了聊天背景也看得清 */
.msg-meta {
  display: inline-flex; flex-wrap: wrap; gap: 2px 6px; align-items: center; max-width: 100%;
  padding: 1px 8px; border-radius: 999px; background: var(--pill); color: var(--pill-ink); font-size: 12px; line-height: 19px;
}
.msg-meta b { font-weight: 600; color: inherit; }
.msg-meta .role { color: var(--wait); background: var(--wait-soft); padding: 0 6px; border-radius: 4px; font-size: 11px; line-height: 16px; }
/* 消息时间：点击查看这条消息的原始数据 */
.msg-meta .msg-stamp { padding: 0; border: 0; background: none; font: inherit; color: inherit; opacity: .85; cursor: pointer; font-variant-numeric: tabular-nums; border-radius: 3px; }
.msg-meta .msg-stamp:hover { opacity: 1; text-decoration: underline; text-underline-offset: 2px; }
.msg-meta .msg-stamp:focus-visible { outline: 2px solid var(--pill-ink); outline-offset: 1px; }
.msg-meta .recalled-tag { color: #ffd2cc; }
/* 气泡：左上角带小尾巴，指向头像 */
.bubble {
  position: relative; max-width: 100%; padding: 7px 11px; border-radius: 4px 14px 14px 14px;
  background: var(--bubble-in); box-shadow: 0 1px 2px var(--bubble-shadow);
  overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.45;
}
.bubble::before {
  content: ""; position: absolute; top: 0; left: -8px; width: 9px; height: 14px; background: var(--bubble-in);
  -webkit-mask: radial-gradient(circle at 0 100%, transparent 9px, #000 9.5px); mask: radial-gradient(circle at 0 100%, transparent 9px, #000 9.5px);
}

.msg.self { flex-direction: row-reverse; }
.msg.self .msg-main { justify-items: end; }
.msg.self .msg-meta { flex-direction: row-reverse; }
.msg.self .bubble { background: var(--bubble-out); border-radius: 14px 4px 14px 14px; }
.msg.self .bubble::before {
  left: auto; right: -8px; background: var(--bubble-out);
  -webkit-mask: radial-gradient(circle at 100% 100%, transparent 9px, #000 9.5px); mask: radial-gradient(circle at 100% 100%, transparent 9px, #000 9.5px);
}

/* 灰字提示（发消息失败等）：像 QQ 的系统提示一样居中显示在对应消息下面 */
.sys-tip { align-self: center; display: flex; justify-content: center; max-width: min(560px, 92%); margin: 6px 0 2px; }
.sys-tip button {
  max-width: 100%; padding: 3px 12px; border: 0; border-radius: 999px; background: var(--pill); color: var(--pill-ink);
  font: inherit; font-size: 12.5px; line-height: 1.5; text-align: center; cursor: pointer; overflow-wrap: anywhere;
}
.sys-tip button:hover { background: color-mix(in srgb, var(--pill) 80%, #000); }
.sys-tip button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sys-tip-time { margin-right: 6px; opacity: .75; font-variant-numeric: tabular-nums; }
.sys-tip.failed button::before { content: ""; display: inline-block; width: 6px; height: 6px; margin: 0 6px 1px 0; border-radius: 50%; background: #ff6b6b; vertical-align: middle; }

/* 一条新消息到来时淡入，只有这一处动效 */
.msg.arrive { animation: arrive .28s ease-out; }
@keyframes arrive { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .msg.arrive { animation: none; } }

/* bubble 里的内容按行排列：文字和 @ 连在一起，图片等单独成块 */
.bubble { display: block; }
.bubble > .seg-image, .bubble > .seg-audio, .bubble > .seg-video, .bubble > .seg-file, .bubble > .seg-card, .bubble > .seg-forward,
.bubble > .md, .bubble > .kb, .bubble > .seg-reply { display: block; margin: 4px 0; }
.bubble > :first-child { margin-top: 0; }
/* 只有图片、聊天记录卡片的消息：不要气泡，直接放在名字下面 */
.bubble.bare, .msg.self .bubble.bare { padding: 0; background: none; box-shadow: none; border-radius: 0; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.bubble.bare::before { display: none; }
.msg.self .bubble.bare { align-items: flex-end; }
.bubble.bare > .seg-image, .bubble.bare > .seg-forward, .bubble.bare > .seg-ark { margin: 0; }
.bubble.bare > .seg-forward, .bubble.bare > .seg-ark { background: var(--surface); }

/* 卡片消息：机器人发的卡片照常显示；QQ 小程序只写一行说明 */
.seg-ark { display: grid !important; width: 280px; max-width: 100%; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: inherit; text-decoration: none; overflow: hidden; white-space: normal; }
a.seg-ark:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
a.seg-ark:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg-ark img { width: 100%; max-height: 160px; object-fit: cover; display: block; }
.ark-body { display: grid; gap: 4px; padding: 10px 12px; }
.ark-body b { font-size: 14px; line-height: 1.4; }
.ark-body span { font-size: 12.5px; color: var(--muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ark-body small { margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.seg-ark-brief { white-space: normal; }
.ark-label { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-size: 12px; line-height: 20px; vertical-align: 1px; }
.bubble.bare .seg-image img { border-radius: 14px; box-shadow: 0 1px 2px var(--bubble-shadow); }
.bubble > :last-child { margin-bottom: 0; }
.seg-at { color: var(--accent); font-weight: 500; }
.seg-tag { color: var(--muted); }
.seg-face { color: var(--wait); }
.seg-image { padding: 0; border: 0; background: none; cursor: zoom-in; line-height: 0; }
/* 图片按长宽比缩放（显示尺寸由脚本按真实尺寸算好），窄屏时整体等比缩小 */
.seg-image { position: relative; }
.seg-image img { display: block; max-width: 100%; height: auto; border-radius: 8px; }
.seg-image img:not([width]) { width: auto; max-width: min(320px, 100%); max-height: 360px; }
.seg-image.long::after { content: "长图"; position: absolute; right: 6px; bottom: 6px; padding: 1px 6px; border-radius: 4px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 11px; line-height: 18px; }
.seg-audio { width: 260px; max-width: 100%; height: 36px; }
.seg-video { max-width: min(360px, 100%); max-height: 320px; border-radius: 8px; background: #000; }
.seg-file { display: grid !important; gap: 2px; padding: 8px 12px; border-radius: 8px; background: color-mix(in srgb, var(--ink) 5%, transparent); border: 0; color: inherit; white-space: normal; }
.seg-file small { color: var(--muted); }
.seg-card { display: flex !important; gap: 10px; padding: 8px; border-radius: 8px; background: color-mix(in srgb, var(--ink) 5%, transparent); border: 0; color: inherit; white-space: normal; max-width: 320px; }
.seg-card img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; flex: none; }
.seg-card div { display: grid; gap: 2px; min-width: 0; }
.seg-card small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.seg-reply { padding: 4px 8px; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 6px; font-size: 12.5px; color: var(--muted); white-space: normal; }
.seg-reply b { color: var(--accent); font-weight: 600; }
/* 引用：发送者一行，正文最多三行，图片缩略 */
.seg-reply.quote { display: grid !important; gap: 2px; justify-items: start; width: fit-content; max-width: 100%; text-align: left; font: inherit; font-size: 12.5px; border-top: 0; border-right: 0; border-bottom: 0; }
.seg-reply.quote.jump { cursor: pointer; }
.seg-reply.quote.jump:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.seg-reply.quote:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.quote-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; }
.quote-imgs { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.quote-img { padding: 0; border: 0; background: none; cursor: zoom-in; line-height: 0; }
.quote-img img { height: 56px; max-width: 96px; object-fit: cover; border-radius: 4px; display: block; }
/* 跳到被引用的消息：整行底色闪一下（左右铺满消息区，内容位置不变） */
.msg.flash {
  max-width: none; margin-inline: calc(-1 * var(--msgs-pad)); padding: 6px var(--msgs-pad); margin-top: 6px; margin-bottom: -6px;
  animation: row-flash 1.8s ease-out;
}
@keyframes row-flash {
  0%, 20% { background: color-mix(in srgb, var(--accent) 26%, transparent); }
  40% { background: color-mix(in srgb, var(--accent) 12%, transparent); }
  55% { background: color-mix(in srgb, var(--accent) 24%, transparent); }
  100% { background: transparent; }
}
@media (prefers-reduced-motion: reduce) { .msg.flash { animation: none; background: color-mix(in srgb, var(--accent) 18%, transparent); } }

/* 聊天记录卡片 */
.seg-forward { display: grid !important; gap: 3px; width: 260px; max-width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: inherit; font: inherit; text-align: left; white-space: normal; cursor: pointer; }
.seg-forward:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.seg-forward:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg-forward b { font-size: 13.5px; margin-bottom: 2px; }
.seg-forward span { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg-forward small { margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.fwd-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; max-height: 64vh; overflow: auto; }
.fwd-meta { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.fwd-meta b { color: var(--ink); font-weight: 600; }
.fwd-body { display: block; width: fit-content; max-width: 100%; padding: 8px 12px; border-radius: 4px 12px 12px 12px; background: var(--surface-2); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.fwd-body.bare { padding: 0; background: none; border: 0; }
.fwd-body > .seg-image, .fwd-body > .seg-reply, .fwd-body > .seg-forward, .fwd-body > .md { display: block; margin: 4px 0; }

.md { white-space: normal; display: grid !important; gap: 6px; }
.md p, .md ul, .md ol, .md blockquote, .md pre { margin: 0; }
.md ul, .md ol { padding-left: 20px; }
.md h3, .md h4, .md h5, .md h6 { font-size: 15px; margin: 0; }
.md h3 { font-size: 17px; }
.md blockquote { padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.md code { background: color-mix(in srgb, var(--ink) 7%, transparent); padding: 1px 4px; border-radius: 4px; }
.md pre { padding: 8px 10px; background: color-mix(in srgb, var(--ink) 6%, transparent); border-radius: 6px; overflow-x: auto; white-space: pre; }
.md pre code { background: none; padding: 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 2px 0; width: 100%; }
.md img { max-width: 100%; height: auto; }
.md .md-cmd { color: var(--accent); }

.kb { display: grid !important; gap: 6px; }
.kb-row { display: flex; gap: 6px; }
.kb { min-width: 220px; }
.kb-btn { flex: 1 0 auto; text-align: center; padding: 6px 8px; border-radius: 8px; border: 0; color: var(--accent); font-size: 13px; font-weight: 500; background: color-mix(in srgb, var(--accent) 12%, transparent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 消息区和右上角的消息额度卡片 */
.msgs-wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.msgs-wrap > .msgs { flex: 1; min-height: 0; }
.quota-card {
  position: absolute; top: 12px; right: 18px; z-index: 5; width: 248px; padding: 10px 12px;
  border-radius: 14px; border: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.5); backdrop-filter: blur(14px) saturate(1.5);
  box-shadow: 0 8px 28px rgba(10, 30, 40, .12); font-size: 12.5px;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .quota-card { background: var(--surface); } }
.quota-head { display: flex; align-items: center; gap: 8px; }
.quota-head b { font-size: 13px; }
.quota-mini { flex: 1; min-width: 0; color: var(--muted); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: none; }
.quota-card.collapsed .quota-mini { display: block; }
.quota-card:not(.collapsed) .quota-head { justify-content: space-between; }
.quota-toggle { padding: 2px 8px; border: 0; border-radius: 6px; background: none; color: var(--accent); font: inherit; font-size: 12px; cursor: pointer; }
.quota-toggle:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.quota-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.quota-body { display: grid; gap: 10px; margin-top: 8px; }
.quota-card.collapsed { width: auto; max-width: 248px; padding: 6px 10px; }
.quota-card.collapsed .quota-body { display: none; }
.quota-row { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: baseline; }
.quota-label { grid-row: span 3; color: var(--muted); }
.quota-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.quota-value.ok { color: var(--ok); }
.quota-value.warn { color: var(--wait); }
.quota-value.muted { color: var(--muted); font-weight: 500; }
.quota-sub { color: var(--ink); opacity: .8; font-variant-numeric: tabular-nums; }
.quota-rule { color: var(--muted); font-size: 11.5px; line-height: 1.45; }
.quota-note { margin: 0; color: var(--muted); }
.quota-note.warn { color: var(--wait); }

/* 输入框上方的快捷按钮 */
.composer-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.tool-chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 0; border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; cursor: pointer; box-shadow: 0 1px 2px var(--bubble-shadow); }
.tool-chip .icon { width: 16px; height: 16px; color: var(--accent); }
.tool-chip:hover:not(:disabled) { color: var(--accent); }
.tool-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tool-chip:disabled { opacity: .55; cursor: not-allowed; }

/* Markdown 消息弹窗 */
.md-modal { width: min(1040px, calc(100vw - 32px)); height: min(640px, calc(100vh - 48px)); padding: 0; border: 0; border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 64px rgba(10, 30, 40, .28); }
.md-modal[open] { display: flex; flex-direction: column; }
.md-modal::backdrop { background: rgba(0, 0, 0, .4); }
.md-head { display: flex; align-items: baseline; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.md-head h2 { font-size: 15px; }
.md-head span { color: var(--muted); font-size: 12.5px; }
.md-main { flex: 1; min-height: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr); }
.md-tools { display: flex; flex-direction: column; gap: 4px; padding: 10px 8px; border-right: 1px solid var(--line); background: var(--surface-2); }
.md-tool { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 64px; padding: 8px 4px; border: 0; border-radius: 8px; background: none; color: var(--ink); font: inherit; font-size: 12px; cursor: pointer; }
.md-tool .icon { width: 20px; height: 20px; color: var(--accent); }
.md-tool:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.md-tool:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.md-edit { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.md-input { flex: 1; min-height: 0; resize: none; padding: 14px 16px; border: 0; background: var(--surface); color: var(--ink); font-family: var(--mono); font-size: 13px; line-height: 1.65; }
.md-input:focus { outline: none; box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.md-ask { display: grid; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.md-ask[hidden] { display: none; }
.md-ask label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.md-ask input { height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; font-family: var(--mono); font-size: 12.5px; }
.md-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.md-chip { padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; font-size: 12px; cursor: pointer; }
.md-chip:hover { border-color: var(--accent); color: var(--accent); }
.md-ask-actions { display: flex; justify-content: flex-end; gap: 6px; }
.md-preview-wrap { position: relative; min-height: 0; overflow: auto; padding: 30px 16px 16px; background: radial-gradient(var(--chat-dots) 1.2px, transparent 1.6px) 0 0 / 22px 22px, var(--chat-bg); }
.md-preview-label { position: absolute; top: 8px; left: 16px; padding: 0 8px; border-radius: 999px; background: var(--pill); color: var(--pill-ink); font-size: 11.5px; }
.md-preview { width: fit-content; max-width: 100%; padding: 8px 12px; border-radius: 14px 14px 14px 4px; background: var(--bubble-in); box-shadow: 0 1px 2px var(--bubble-shadow); overflow-wrap: anywhere; }
.md-preview .md img { max-width: 100%; height: auto; }
.md-empty { margin: 0; color: var(--muted); font-size: 13px; }
.md-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.md-foot small { flex: 1; color: var(--muted); font-size: 12px; }
@media (max-width: 760px) {
  .md-modal { height: calc(100vh - 24px); width: calc(100vw - 16px); }
  .md-main { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) minmax(0, .8fr); }
  .md-tools { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .md-tool { width: auto; min-width: 56px; }
  .md-edit { border-right: 0; border-bottom: 1px solid var(--line); }
  .md-foot small { display: none; }
}

/* 输入框 */
.composer { display: grid; gap: 8px; padding: 6px 24px 16px; background: none; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; min-height: 48px; max-height: 180px; padding: 13px 16px; border: 0; border-radius: 16px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 15px; line-height: 1.45; box-shadow: 0 1px 2px var(--bubble-shadow);
}
.composer textarea:focus { outline: none; box-shadow: 0 1px 2px var(--bubble-shadow), 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent); }
.composer textarea:disabled { opacity: .7; cursor: not-allowed; }
.composer .btn { height: 48px; min-width: 48px; padding: 0 18px; border-radius: 999px; box-shadow: 0 1px 2px var(--bubble-shadow); }
.composer-reply { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-left: 3px solid var(--accent); border-radius: 12px; background: var(--surface); box-shadow: 0 1px 2px var(--bubble-shadow); font-size: 12.5px; color: var(--muted); }
.composer-reply[hidden] { display: none; }
.composer-reply > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-reply b { color: var(--ink); font-weight: 600; }
.composer-reply-x { flex: none; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; }
.composer-reply-x:hover { background: var(--line); color: var(--ink); }
.msg.recalled .bubble { opacity: .55; }
.recalled-tag { color: var(--bad); font-size: 11px; line-height: 1.4; }
.ban-pick { display: grid; gap: 14px; justify-items: start; }
.ban-pick p { margin: 0; color: var(--muted); font-size: 13px; }
.ban-choices { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- 弹窗、遮罩、提示 ---------- */

.dialog { border: 0; padding: 0; border-radius: 16px; width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 24px 64px rgba(10, 30, 40, .28); }
.dialog.wide { width: min(880px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 6px; }
.dialog-head h2 { font-size: 17px; }
.dialog-head form { margin: 0; }
.dialog-body { padding: 18px; }
.confirm { display: grid; gap: 18px; }
.confirm .actions { display: flex; justify-content: flex-end; gap: 8px; }
/* 消息原始数据 */
.raw-view { display: grid; gap: 12px; }
.raw-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; font-size: 13px; color: var(--muted); }
.raw-head b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.raw-head .btn { margin-left: auto; }
.raw-note { margin: 0; padding: 8px 12px; border-radius: 8px; background: var(--wait-soft); color: var(--wait); font-size: 13px; }
.raw-json { margin: 0; padding: 12px 14px; max-height: 64vh; overflow: auto; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.raw-json .j-key { color: var(--accent); }
.raw-json .j-str { color: var(--ok); }
.raw-json .j-num { color: var(--wait); }
.raw-json .j-lit { color: var(--bad); }

/* 查看大图 */
.lightbox { position: fixed; inset: 0; width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: none; overflow: auto; color: #fff; }
.lightbox::backdrop { background: rgba(4, 12, 15, .88); }
.lightbox-stage { min-width: 100%; min-height: 100%; width: max-content; display: grid; place-items: center; padding: 60px 24px 24px; box-sizing: border-box; }
.lightbox img { display: block; max-width: calc(100vw - 48px); max-height: calc(100vh - 84px); border-radius: 6px; box-shadow: 0 12px 48px rgba(0, 0, 0, .45); }
.lightbox.can-zoom img { cursor: zoom-in; }
.lightbox.zoomed img { max-width: none; max-height: none; cursor: zoom-out; }
.lightbox-bar { position: fixed; top: 14px; right: 16px; display: flex; gap: 8px; }
.lightbox-btn { padding: 6px 14px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .22); background: rgba(255, 255, 255, .1); color: #fff; font: inherit; font-size: 13px; text-decoration: none; cursor: pointer; }
.lightbox-btn:hover { background: rgba(255, 255, 255, .2); }
.lightbox-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.lightbox-error { color: rgba(255, 255, 255, .8); }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .45); z-index: 20; }
.overlay-box { display: grid; justify-items: center; gap: 14px; padding: 28px 36px; border-radius: 14px; background: var(--surface); max-width: 360px; text-align: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 30; }
.toast { padding: 10px 16px; border-radius: 12px; background: rgba(20, 24, 28, .88); color: #fff; font-size: 13px; max-width: 360px; transition: opacity .3s; }
.toast.error { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; }

/* ---------- 窄屏 ---------- */

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .rail { order: 2; flex-direction: row; padding: 4px 6px; gap: 0; overflow-x: auto; }
  .brand, .live { display: none; }
  .nav-group, .rail-foot { display: flex; padding: 0; margin: 0; border: 0 !important; gap: 0; }
  .rail-foot { margin-left: auto; }
  .nav { width: 58px; padding: 6px 0 4px; }
  .nav.active::before { display: none; }
  .page { padding: 20px 16px 48px; }
  .facts { grid-template-columns: 1fr 1fr; }
  .two, .form-grid { grid-template-columns: 1fr; }
  .log-file select, .log-search { min-width: 0; width: 100%; }
  .log-file, .log-search { flex: 1 1 100%; }
  .log-entry { grid-template-columns: 58px 1fr; }
  .log-entry .log-level { display: none; }
  .field.placeholder { display: none; }
  .status-line { grid-template-columns: auto 1fr; }
  .status-line .btn { grid-column: 1 / -1; }
  .plugin-top { flex-direction: column; }
  .perm-row { grid-template-columns: 1fr; gap: 4px; }
  .chat { grid-template-columns: 1fr; }
  .chat.has-current .chat-side { display: none; }
  .chat:not(.has-current) .chat-panel { display: none; }
  .panel-head { padding: 10px 12px; }
  .panel-head .back { display: inline-flex; }
  .msgs { --msgs-pad: 10px; padding: 8px var(--msgs-pad) 16px; }
  .composer { padding: 6px 10px 10px; }
  .rail { border-right: 0; border-top: 1px solid var(--rail-line); }
  .panel-title p { overflow: hidden; }
  .panel-title p > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .composer textarea { padding: 13px 12px; font-size: 14px; }
  .composer .btn { padding: 0 14px; }
  .quota-card { right: 10px; top: 8px; width: 220px; }
  .msg-main { max-width: 86%; }
}

/* 群消息私聊回复弹窗 */
.private-reply { gap: 12px; }
.private-reply textarea { width: 100%; min-height: 96px; resize: vertical; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
.private-reply-quote { margin: 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 6px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.private-reply-quote b { color: var(--ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
