/* =========================================================
   闪电 Agent · 控制台样式（只给 agent.html 用，不影响清单 App）
   设计：左侧 Agent 导航 + 居中对话流 + 右侧滑出面板
   ========================================================= */

:root {
  --bg: #F6F4ED;
  --surface: #FFFFFF;
  --surface-2: #FBFAF6;
  --surface-3: #F1EEE5;
  --line: #E7E2D5;
  --line-strong: #D8D1BF;
  --ink: #1B1A16;
  --ink-2: #46423A;
  --ink-3: #6B6557;
  --ink-4: #6E6858;
  --brand: #0F9D7A;
  --brand-2: #14B98F;
  --brand-ink: #0A6E56;
  --brand-wash: #E7F6F1;
  --danger: #C0392B;
  --danger-wash: #FDEDEB;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(30, 26, 15, .05);
  --shadow: 0 12px 32px rgba(30, 26, 15, .10);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink-2); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--brand); color: var(--brand-ink); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  border-color: var(--brand); color: #fff; box-shadow: 0 2px 6px rgba(15, 157, 122, .25);
}
.btn.primary:hover { filter: brightness(1.04); color: #fff; }
.btn.ghost,
.btn.danger { background: transparent; }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); border-color: #E9C4BF; }
.btn.danger:hover { background: var(--danger-wash); border-color: var(--danger); color: var(--danger); }

/* ============ 线性图标（Lucide，MIT） ============
   规范见 _ai/TASKS.md T1：24×24 viewBox、stroke-width 1.75、圆头圆角、fill:none、
   颜色一律继承 currentColor。**色值与线宽只在这里给一次** —— 图标符号体内不许写颜色。
   `.ico` 基础规则的正文必须与 index.html 内联样式里的那一份逐字相同
   （`check_website_served.py` 的 I3 段比对两处，防止「一处改、另一处忘」）。 */
.icon-sprite { display: none; }
.ico {
  width: 16px; height: 16px; flex: none; vertical-align: -2px;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}
.ico--14 { width: 14px; height: 14px; }
.ico--18 { width: 18px; height: 18px; }
.ico--22 { width: 22px; height: 22px; }
.ico--28 { width: 28px; height: 28px; }

.icon-btn {
  width: 34px; height: 34px; flex: none; display: inline-grid; place-items: center;
  border-radius: 10px; border: 1px solid transparent; background: transparent;
  color: var(--ink-3); font-size: 16px; cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn.subtle { width: 28px; height: 28px; font-size: 15px; }
.ghost-btn {
  padding: 7px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: transparent; color: var(--ink-3); font-size: 12.5px; cursor: pointer;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--line-strong); background: var(--surface-2); }
.ghost-btn.danger { color: var(--danger); border-color: #E9C4BF; }
.link-btn { border: none; background: none; color: var(--ink-3); font-size: 12.5px; cursor: pointer; padding: 0; }
.link-btn:hover { color: var(--brand-ink); }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--ink-3); margin-bottom: 6px; }
.field input, .field select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 13px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15, 157, 122, .12);
}
.hint { font-size: 11.5px; color: var(--ink-4); line-height: 1.6; margin: 6px 0 0; }
.error-text { color: var(--danger); font-size: 12.5px; min-height: 18px; margin: 2px 0 8px; }

/* 键盘焦点可见（鼠标点击不显示） */
button:focus-visible, a:focus-visible, .field input:focus-visible,
.field select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}

/* ---------- 登录页 ---------- */
.login-view {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, #E4F6F0 0%, transparent 55%),
    radial-gradient(900px 500px at 110% 110%, #F3EFE2 0%, transparent 60%),
    var(--bg);
}
.login-shell {
  width: min(880px, 100%); display: grid; grid-template-columns: 1.05fr 1fr;
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px;
  box-shadow: var(--shadow); overflow: hidden;
}
.login-brand {
  padding: 44px 38px; color: #fff;
  background: linear-gradient(150deg, #12B98F 0%, #0F9D7A 55%, #0B7A5E 100%);
  display: flex; flex-direction: column; justify-content: center;
}
.lb-logo {
  width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .16); font-size: 28px; margin-bottom: 20px;
  border: 1px solid rgba(255, 255, 255, .25);
}
.login-brand h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: .5px; }
.login-brand p { margin: 0 0 22px; font-size: 13px; opacity: .82; }
.login-brand ul { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 2; opacity: .9; }
.login-brand li::marker { color: rgba(255, 255, 255, .7); }

.login-card { padding: 44px 40px; display: flex; flex-direction: column; justify-content: center; }
.login-card h2 { margin: 0 0 4px; font-size: 20px; }
.login-sub { margin: 0 0 20px; color: var(--ink-4); font-size: 12.5px; }
.login-actions { display: grid; gap: 8px; margin-top: 4px; }
.login-links { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }
.login-links a { color: var(--ink-4); font-size: 12.5px; text-decoration: none; }
.login-links a:hover { color: var(--brand-ink); }

/* ---------- 主框架 ---------- */
.app-shell {
  height: 100vh; display: flex; overflow: hidden; position: relative;
  background: var(--bg);
}

/* 侧栏 */
.sidebar {
  width: 288px; flex: none; display: flex; flex-direction: column;
  background: var(--surface-2); border-right: 1px solid var(--line);
  transition: margin-left .22s ease, transform .22s ease;
}
.app-shell.sidebar-collapsed .sidebar { margin-left: -288px; }
.brand {
  display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px;
  border-bottom: 1px solid var(--line);
}
.brand-logo {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center;
  border-radius: 11px; background: linear-gradient(180deg, var(--brand-2), var(--brand));
  color: #fff; font-size: 20px; box-shadow: 0 3px 10px rgba(15, 157, 122, .28);
}
.brand-text { min-width: 0; }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: .2px; }
.brand-tag {
  font-size: 10px; padding: 1px 5px; border-radius: 5px; margin-left: 4px;
  background: var(--brand-wash); color: var(--brand-ink); vertical-align: 1px;
}
.brand-sub { font-size: 11px; color: var(--ink-4); margin-top: 2px; }
.side-close { margin-left: auto; display: none; }

.side-scroll { flex: 1; overflow-y: auto; padding: 14px 12px; }
.side-section + .side-section { margin-top: 18px; }
.side-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 6px 8px; font-size: 11px; font-weight: 600; letter-spacing: .08em;
  color: var(--ink-4); text-transform: uppercase;
}
.agent-list { display: flex; flex-direction: column; gap: 4px; }
.agent-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: 11px; cursor: pointer; border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.agent-item:hover { background: var(--surface); border-color: var(--line); }
.agent-item.active { background: var(--surface); border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.agent-avatar {
  width: 32px; height: 32px; flex: none; display: grid; place-items: center;
  border-radius: 10px; background: var(--brand-wash); font-size: 16px;
}
.agent-info { min-width: 0; flex: 1; }
.agent-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-code { font-size: 10.5px; color: var(--ink-4); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: #C9C2B1; }
.agent-dot.idle { background: #35C08A; }
.agent-dot.running { background: #F2A93B; animation: pulse 1.1s ease-in-out infinite; }
/* 设备在线点（app.js 按 presence 结果给 online/offline）：不再是 🟢/⚪ 两个 emoji，
   一是 emoji 在不同系统上颜色观感不一致，二是图标位禁止用 emoji（T1 已拍板）。
   色值沿用上面 .agent-dot 的两档（在线 = 绿、离线 = 灰），换主题时两处一起改。 */
.device-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  flex: none; margin-right: 6px; vertical-align: 1px; background: #C9C2B1;
}
.device-dot.online { background: #35C08A; }
.agent-empty { padding: 14px 10px; font-size: 12px; color: var(--ink-4); line-height: 1.6; }
/* 有 Agent 时隐藏侧栏占位；游客模式下由 showGuest() 注入的占位在列表内部，正常显示 */
#agentList:not(:empty) + .agent-empty { display: none; }

.side-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; margin-bottom: 2px; border-radius: 10px; border: none;
  background: transparent; color: var(--ink-2); font-size: 13px; text-align: left;
  cursor: pointer; text-decoration: none;
}
.side-item:hover { background: var(--surface); color: var(--ink); }
/* 管理入口：标题 + 一行说明；比纯文字列表更容易扫读 */
.side-item-rich {
  align-items: flex-start; gap: 9px; padding: 9px 10px;
  border: 1px solid transparent; background: transparent;
}
.side-item-rich:hover { border-color: var(--line); background: var(--surface-2); }
.side-item-rich .si-icon { margin-top: 1px; opacity: .9; }
.si-copy { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.si-title { color: var(--ink-2); font-size: 12.5px; font-weight: 500; line-height: 1.45; }
.si-desc { color: var(--ink-4); font-size: 10.5px; line-height: 1.45; }
/* 图标位容器：emoji 自带字宽与基线，`<svg>` 不会 —— 必须显式居中，否则图标贴着文字、各行高不一致 */
.si-icon { width: 22px; display: inline-flex; align-items: center; justify-content: center; opacity: .85; }

.sidebar-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-top: 1px solid var(--line);
}
.user-box { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1; cursor: pointer; }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.user-meta { min-width: 0; }
.user-name { display: block; font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { display: block; font-size: 10.5px; color: var(--ink-4); }

/* 套餐卡：侧栏窄，只放「是什么 / 还剩多少 / 去哪儿升级」三件事 */
.plan-box { margin: 2px 0 10px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.plan-badge { font-size: 10px; font-weight: 600; color: var(--brand-ink); background: var(--brand-wash); border-radius: 999px; padding: 2px 7px; white-space: nowrap; }
.plan-usage { font-size: 12px; line-height: 1.55; color: var(--ink-2); }
.plan-points, .plan-expiry { margin-top: 4px; font-size: 10.5px; line-height: 1.5; color: var(--ink-4); }
.plan-action { margin-top: 6px; color: var(--brand-ink); font-weight: 600; }
.chat-plan {
  font-size: 10px; font-weight: 600; color: var(--brand-ink);
  background: var(--brand-wash); border-radius: 999px; padding: 2px 7px;
  white-space: nowrap;
}

/* 对话区 */
.chat-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; background: rgba(246, 244, 237, .86);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.chat-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; font-weight: 600; }
.chat-logo { display: inline-flex; align-items: center; }
.chat-status {
  font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--ink-3);
}
.chat-status::before {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: #35C08A; margin-right: 5px; vertical-align: 1px;
}
.ctx-usage { font-size: 11px; color: var(--ink-4); }
.ctx-usage.warn { color: #B7791F; }
.ctx-usage.danger { color: var(--danger); }
.chat-header-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }

.messages {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  padding: 26px 22px 8px; scroll-behavior: smooth;
}
.messages > * { width: 100%; max-width: 820px; margin-left: auto; margin-right: auto; }

/* 消息气泡 */
.msg { display: flex; margin-bottom: 18px; }
.msg.user { justify-content: flex-end; }
.msg .msg-text {
  max-width: 86%; padding: 11px 15px; border-radius: 16px;
  font-size: 13.5px; line-height: 1.75; word-break: break-word;
}
.msg.user .msg-text {
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  color: #fff; border-bottom-right-radius: 6px;
  box-shadow: 0 2px 10px rgba(15, 157, 122, .18);
}
.msg.assistant .msg-text {
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  border-bottom-left-radius: 6px; box-shadow: var(--shadow-sm);
}
.msg.assistant.error .msg-text {
  background: var(--danger-wash); border-color: #E9C4BF; color: #8E2F24;
}

/* 助手 markdown */
.msg-text > :first-child { margin-top: 0; }
.msg-text > :last-child { margin-bottom: 0; }
.msg-text p { margin: 0 0 10px; }
.msg-text h1, .msg-text h2, .msg-text h3 { font-size: 15px; margin: 14px 0 8px; }
.msg-text ul, .msg-text ol { margin: 6px 0 10px; padding-left: 22px; }
.msg-text li { margin: 3px 0; }
.msg-text code {
  font-family: var(--mono); font-size: 12px; padding: 1px 5px; border-radius: 5px;
  background: var(--surface-3); color: var(--brand-ink);
}
.msg-text pre {
  background: #1E211D; color: #E8E6DC; border-radius: 12px; padding: 14px 16px;
  overflow-x: auto; margin: 10px 0; border: 1px solid #2C302A;
}
.msg-text pre code { background: none; color: inherit; padding: 0; font-size: 12px; line-height: 1.6; }
.msg-text blockquote {
  margin: 10px 0; padding: 6px 12px; border-left: 3px solid var(--brand);
  background: var(--brand-wash); color: var(--ink-2); border-radius: 0 8px 8px 0;
}
.msg-text table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 12.5px; }
.msg-text th, .msg-text td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; }
.msg-text th { background: var(--surface-2); }
.msg-text a { color: var(--brand-ink); }

/* 助手消息复制按钮（悬停显示，移动端常显） */
.msg.assistant { align-items: flex-start; }
.msg-copy {
  margin: 4px 0 0 8px; padding: 3px 9px; flex: none;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); color: var(--ink-3); font-size: 11px; box-shadow: var(--shadow-sm);
  cursor: pointer; opacity: 0; transition: opacity .15s, color .15s, border-color .15s;
}
.msg.assistant .msg-copy { display: none; }
.msg.assistant.done .msg-copy { display: inline-flex; }
.msg.assistant.done:hover .msg-copy { opacity: 1; }
.msg-copy:hover { color: var(--brand-ink); border-color: var(--brand); }
.msg-copy.ok { color: var(--brand-ink); border-color: var(--brand); }
@media (hover: none) { .msg-copy { opacity: 1; } }

/* 空会话：示例指令 */
.empty-state {
  max-width: 560px; margin: 8vh auto 0; padding: 0 8px; text-align: center;
}
.es-seal {
  width: 56px; height: 56px; margin: 0 auto 16px; display: grid; place-items: center;
  border-radius: 18px; background: linear-gradient(180deg, var(--brand-2), var(--brand));
  color: #fff; font-size: 26px; box-shadow: 0 8px 22px rgba(15, 157, 122, .22);
}
.empty-state h3 { margin: 0 0 8px; font-size: 19px; }
.empty-state p { margin: 0 0 16px; font-size: 13px; color: var(--ink-3); line-height: 1.7; }
.es-chips { display: flex; flex-direction: column; gap: 8px; margin: 0 auto 14px; max-width: 440px; }
.es-chip {
  text-align: left; padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  font-size: 13px; cursor: pointer; transition: border-color .15s, background .15s, transform .05s;
}
.es-chip::before { content: "✦ "; color: var(--brand); }
.es-chip:hover { border-color: var(--brand); background: var(--brand-wash); color: var(--brand-ink); }
.es-chip:active { transform: translateY(1px); }
.es-hint { font-size: 11.5px; color: var(--ink-4); }

/* 工具卡片 */
.tool-card {
  max-width: 86%; margin: -8px 0 16px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--surface-2); overflow: hidden;
}
.tool-card summary {
  cursor: pointer; padding: 8px 12px; font-size: 12px; color: var(--ink-3);
  list-style: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tool-card summary::-webkit-details-marker { display: none; }
.tool-card summary:hover { color: var(--ink); }
.tool-result {
  margin: 0; padding: 10px 12px; border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 11.5px; line-height: 1.6; color: var(--ink-2);
  white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto;
}
.tool-result.error { color: var(--danger); background: var(--danger-wash); }
.tool-toggle { margin-top: 6px; padding: 0; border: none; background: none; color: var(--brand-ink); font-size: 11.5px; cursor: pointer; }
.tool-toggle:hover { text-decoration: underline; }
.diff-view { margin: 8px 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.diff-line { font-family: var(--mono); font-size: 11.5px; padding: 2px 10px; white-space: pre-wrap; }
.diff-line.add { background: #EAF7F0; color: #1F6B4A; }
.diff-line.del { background: #FDEDEB; color: #8E2F24; }

/* 空状态 / 游客欢迎 */
.guest-welcome {
  max-width: 620px; margin: 6vh auto 0; padding: 0 8px; text-align: left;
}
.gw-seal {
  width: 58px; height: 58px; display: grid; place-items: center; border-radius: 18px;
  background: linear-gradient(180deg, var(--brand-2), var(--brand)); color: #fff;
  font-size: 28px; margin-bottom: 20px; box-shadow: 0 8px 22px rgba(15, 157, 122, .25);
}
.guest-welcome h2 { margin: 0 0 10px; font-size: 23px; letter-spacing: .2px; }
.guest-welcome p { margin: 0 0 14px; font-size: 13.5px; line-height: 1.8; color: var(--ink-3); }
.guest-welcome ul { margin: 0 0 18px; padding-left: 18px; font-size: 13px; line-height: 2; color: var(--ink-3); }
.guest-welcome li::marker { color: var(--brand); }
.gw-hint { font-size: 12px; color: var(--ink-4); }

/* 输入区 */
.composer { padding: 10px 22px 18px; background: linear-gradient(180deg, transparent, var(--bg) 40%); }
.composer-box {
  max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 8px 8px 14px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 18px; box-shadow: 0 6px 22px rgba(30, 26, 15, .07);
  transition: border-color .15s, box-shadow .15s;
}
.composer-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15, 157, 122, .12), 0 6px 22px rgba(30, 26, 15, .07); }
.composer textarea {
  flex: 1; border: none; background: transparent; box-shadow: none; resize: none;
  padding: 7px 0; max-height: 180px; min-height: 22px; line-height: 1.6; font-size: 13.5px;
}
.composer textarea:focus { box-shadow: none; }
.composer-actions { display: flex; align-items: center; gap: 4px; }
.btn.send { padding: 8px 18px; border-radius: 12px; }
.composer-hint {
  max-width: 820px; margin: 7px auto 0; text-align: center;
  font-size: 10.5px; color: var(--ink-4);
}

/* ---------- 右侧滑出面板 ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -18px 0 40px rgba(30, 26, 15, .12);
  display: flex; flex-direction: column; z-index: 40;
  animation: slideIn .22s ease;
}
.drawer.wide { width: 520px; }
@keyframes slideIn { from { transform: translateX(24px); } to { transform: none; } }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.drawer-title { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
.drawer-sub {
  margin: 0; padding: 10px 16px 0; color: var(--ink-4);
  font-size: 11.5px; line-height: 1.55;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }
.drawer-foot { padding: 14px 16px; border-top: 1px solid var(--line); background: var(--surface-2); }

.cfg-section {
  margin-bottom: 14px; padding: 13px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
}
.cfg-section:last-child { margin-bottom: 0; }
.cfg-section-title {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; color: var(--ink-4);
  text-transform: uppercase; margin-bottom: 10px;
}
.agent-ops { display: flex; gap: 8px; margin-top: 10px; }
.agent-ops .ghost-btn { flex: 1; text-align: center; }

/* 项目 / 文件 / 工作区 */
.project-list { display: flex; flex-direction: column; gap: 8px; }
.project-item {
  padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
}
.project-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.project-meta { font-size: 11px; color: var(--ink-4); line-height: 1.6; }
.project-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.upload-row { display: flex; gap: 8px; margin-bottom: 8px; }
.upload-row input[type=file] { flex: 1; font-size: 11.5px; }
.file-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.file-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
}
.file-name { flex: 1; font-size: 12.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-actions { display: flex; gap: 4px; }
/* 文件列表里的小图标按钮：原来是 emoji，换成 SVG 后必须给它一个明确的盒子和居中——
   默认按钮会把 <svg> 贴着基线摆，三个按钮上下错位（r456 换图标时踩过同一个坑）。 */
.file-actions button {
  display: inline-grid; place-items: center; width: 26px; height: 26px; padding: 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); color: var(--ink-3); cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.file-actions button:hover { color: var(--brand-ink); border-color: var(--brand); background: var(--brand-wash); }
.file-viewer { margin-top: 12px; }
.file-md, .file-content {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; font-size: 12.5px; line-height: 1.7; max-height: 60vh; overflow: auto;
}
.file-content { font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; }

.ws-tree { flex: 1; overflow: auto; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.ws-dir { font-size: 12.5px; font-weight: 600; color: var(--ink-2); padding: 6px 0; }
.ws-file { flex: 1; overflow: auto; padding: 12px 16px; font-family: var(--mono); font-size: 11.5px; line-height: 1.7; white-space: pre-wrap; }
.ws-resize-handle {
  position: absolute; left: 0; top: 0; bottom: 0; width: 6px; cursor: col-resize;
  background: transparent;
}
.ws-resize-handle:hover { background: var(--brand-wash); }
.ws-tree a, .ws-tree .file-link { cursor: pointer; color: var(--ink-2); text-decoration: none; }
.ws-tree .file-link:hover { color: var(--brand-ink); }

/* 用户信息弹窗 */
.user-modal-name { font-size: 16px; font-weight: 600; }
.user-modal-meta { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.user-avatar-big { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }

/* 表单 / 选择器 / 用户弹窗（app.js 动态生成） */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: block; font-size: 12px; color: var(--ink-3); margin-bottom: 5px; }
.form input, .form textarea, .form select { width: 100%; }
.user-modal { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px 0 2px; text-align: center; }
.select-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.select-item {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); font-size: 13px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.select-item:hover { border-color: var(--brand); background: var(--brand-wash); }
.select-item small { color: var(--ink-4); margin-left: 6px; }
.file-link { color: var(--brand-ink); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.file-link:hover { color: var(--brand); }

/* ---------- 弹窗 ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(27, 26, 22, .35);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.modal {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 50;
  background: rgba(27, 26, 22, .38); padding: 18px;
}
.modal-card {
  width: min(560px, 100%); max-height: 82vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-title { font-size: 14px; font-weight: 600; }
.modal-body { padding: 16px; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ---------- 新建 / 编辑 Agent ---------- */
.agent-form { display: flex; flex-direction: column; gap: 16px; }
.agent-form-intro { display: flex; align-items: flex-start; gap: 12px; padding: 2px 0 2px; }
.agent-form-icon {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center;
  border-radius: 13px; color: var(--brand-ink); background: var(--brand-wash);
}
.agent-form-intro h3 { margin: 1px 0 4px; font-size: 18px; letter-spacing: .1px; }
.agent-form-intro p { margin: 0; color: var(--ink-3); font-size: 12.5px; line-height: 1.65; }
.agent-form-section {
  padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-2);
}
.agent-section-title {
  display: flex; align-items: center; gap: 7px; margin-bottom: 10px;
  color: var(--ink-2); font-size: 12px; font-weight: 600;
}
.agent-optional { color: var(--ink-4); font-size: 10.5px; font-weight: 400; }
.agent-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.agent-field { display: block; min-width: 0; }
.agent-field > span { display: block; margin-bottom: 5px; color: var(--ink-3); font-size: 11.5px; }
.agent-field input {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line-strong); border-radius: 9px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; outline: none;
}
.agent-field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,157,122,.12); }
.agent-field input::placeholder { color: var(--ink-4); }
.agent-field small, .agent-hint { display: block; margin-top: 5px; color: var(--ink-4); font-size: 10.5px; line-height: 1.5; }
.agent-plan-note {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink-3); font-size: 11.5px; line-height: 1.6;
}
.agent-plan-note.ok { border-color: #C9E8DE; background: var(--brand-wash); }
.agent-plan-note.locked { border-color: #E7D8B5; background: #FFFBF1; }
.agent-plan-icon { flex: none; color: var(--brand-ink); }
.agent-plan-note b { display: block; margin-bottom: 2px; color: var(--ink-2); font-size: 12px; }
.agent-plan-note p { margin: 0; }
.agent-plan-note a { display: inline-block; margin-top: 4px; color: var(--brand-ink); font-weight: 600; text-decoration: none; }
.agent-plan-note a:hover { text-decoration: underline; }
.agent-advanced { border-top: 1px dashed var(--line); padding-top: 10px; }
.agent-advanced summary { cursor: pointer; color: var(--ink-3); font-size: 12px; }
.agent-advanced summary:hover { color: var(--brand-ink); }
.agent-advanced[open] summary { margin-bottom: 10px; }
.agent-form-msg { min-height: 18px; margin: -4px 0 0; font-size: 12px; color: var(--ink-4); }
.agent-form-msg.err { color: var(--danger); }
.agent-form-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding-top: 4px; border-top: 1px solid var(--line); margin-top: 2px;
}
@media (max-width: 560px) {
  .agent-grid { grid-template-columns: 1fr; }
  .agent-form-section { padding: 12px; }
}

/* ---------- 可见性 ---------- */
body:not(.guest-mode) .guest-only { display: none !important; }
body.guest-mode .auth-only { display: none !important; }
body:not(.admin-mode) .admin-only { display: none !important; }

/* ---------- 响应式 ---------- */
.scrim { display: none; }
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 35;
    transform: translateX(-100%); margin-left: 0 !important;
    box-shadow: 18px 0 40px rgba(30, 26, 15, .16);
  }
  .sidebar.open { transform: none; }
  .side-close { display: inline-grid; }
  .scrim {
    display: block; position: fixed; inset: 0; background: rgba(27, 26, 22, .35);
    opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 34;
  }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .messages { padding: 18px 12px 6px; }
  .msg .msg-text, .tool-card { max-width: 94%; }
  .composer { padding: 8px 12px 14px; }
  .chat-header { padding: 10px 12px; }
  .chat-header-actions .ghost-btn { display: none; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { padding: 28px 24px; }
  .login-brand ul { display: none; }
  .login-card { padding: 26px 22px 30px; }
  .drawer { width: 100vw; max-width: 100vw; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
