:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --sidebar: #f6f6f7;
  --muted: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #3f3f46;
  --text-muted: #71717a;
  --text-faint: #a1a1aa;
  --primary: #18181b;
  --primary-fg: #fafafa;
  --accent: #10b981;
  --chip-bg: #f4f4f5;
  --danger: #dc2626;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.ic { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ── 口令页 ── */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--bg-soft); }
.gate-card {
  width: 100%; max-width: 360px; background: var(--bg); border: 1px solid var(--border); border-radius: 16px;
  padding: 32px 28px; display: flex; flex-direction: column; align-items: center; gap: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.05);
}
.gate-logo { width: 56px; height: 56px; }
.gate-title { margin: 4px 0 0; font-size: 20px; font-weight: 600; }
.gate-sub { margin: 0 0 8px; color: var(--text-muted); }
.gate-card input {
  width: 100%; height: 40px; border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; outline: none;
}
.gate-card input:focus { border-color: var(--text-faint); }
.gate-error { margin: 0; color: var(--danger); font-size: 13px; align-self: flex-start; }
.btn-primary {
  width: 100%; height: 40px; border-radius: 10px; background: var(--primary); color: var(--primary-fg); font-weight: 500;
}
.btn-primary:disabled { opacity: .5; cursor: default; }

/* ── 布局 ── */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 280px; flex: none; display: flex; flex-direction: column; background: var(--sidebar);
  border-right: 1px solid var(--border); min-height: 0;
}
.app.collapsed .sidebar { display: none; }

.sb-toolbar { display: flex; align-items: center; gap: 6px; height: 44px; padding: 6px 8px 0; }
.sb-search { position: relative; flex: 1; min-width: 0; }
.sb-search .ic { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-faint); }
.sb-search input {
  width: 100%; height: 30px; border: 1px solid var(--border); background: rgba(255,255,255,.7); border-radius: 8px;
  padding: 0 8px 0 28px; outline: none; font-size: 13px;
}
.sb-search input::placeholder { color: var(--text-faint); }
.icon-btn {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--text-muted); flex: none;
}
.icon-btn:hover { background: var(--muted); color: var(--text); }

.sb-nav { padding: 8px 8px 4px; display: flex; flex-direction: column; gap: 2px; }
.sb-item {
  display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: 8px; font-weight: 500; text-align: left;
}
.sb-item:hover { background: rgba(0,0,0,.045); }
.kbd-group { margin-left: auto; display: flex; gap: 3px; }
kbd {
  font-family: var(--font); font-size: 11px; color: var(--text-muted); background: var(--bg); border: 1px solid var(--border);
  border-radius: 5px; padding: 0 5px; line-height: 18px;
}

.sb-sessions { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 8px 12px; }
.sb-label { font-size: 12px; color: var(--text-muted); padding: 6px 10px; }
.sb-sublabel { font-size: 12px; color: var(--text-faint); padding: 2px 10px 6px; }
.session-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.session-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; cursor: pointer; position: relative;
}
.session-item:hover { background: rgba(0,0,0,.045); }
.session-item.active { background: rgba(0,0,0,.07); }
.session-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-faint); flex: none; }
.session-item.active .session-dot { background: var(--accent); }
.session-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; color: var(--text-2); }
.session-time { font-size: 11px; color: var(--text-faint); flex: none; }
.session-del { display: none; width: 20px; height: 20px; place-items: center; border-radius: 5px; color: var(--text-muted); flex: none; }
.session-del .ic { width: 13px; height: 13px; }
.session-item:hover .session-time { display: none; }
.session-item:hover .session-del { display: grid; }
.session-del:hover { background: rgba(0,0,0,.08); color: var(--danger); }
.session-empty { color: var(--text-faint); font-size: 12px; padding: 4px 10px; margin: 0; }

.agent-card {
  margin: 8px 12px 12px; padding: 10px; border: 1px solid var(--border); border-radius: 14px;
  background: linear-gradient(135deg, #fff 0%, #fff 55%, rgba(24,24,27,.04) 100%);
  display: flex; align-items: center; gap: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.avatar {
  position: relative; width: 44px; height: 44px; border-radius: 12px; background: #1f1f23; color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 18px; flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.status-dot {
  position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 2px #fff, 0 0 6px rgba(16,185,129,.55);
}
.agent-meta { min-width: 0; }
.agent-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-role { color: var(--text-muted); font-size: 13px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--bg); }
.main-header { height: 44px; flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 16px 0; }
.chat-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.thread { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.empty-state {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 24px; text-align: center;
}
.empty-state .wave {
  width: 52px; height: 52px; border-radius: 14px; border: 1px solid var(--border); display: grid; place-items: center; font-size: 26px;
  background: var(--bg); box-shadow: 0 2px 8px rgba(0,0,0,.05); margin-bottom: 10px;
}
.empty-state h2 { margin: 0; font-size: 17px; font-weight: 600; }
.empty-state p { margin: 0; color: var(--text-muted); }

.messages { max-width: 860px; margin: 0 auto; padding: 8px 24px 24px; display: flex; flex-direction: column; gap: 24px; }

/* 用户消息 */
.msg-user { align-self: flex-end; max-width: 85%; }
.msg-user .bubble {
  background: var(--muted); border-radius: 16px; padding: 10px 14px; font-size: 16px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}
.skill-chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-family: var(--mono); color: var(--text-2);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; margin-right: 6px; vertical-align: 2px;
}
.skill-chip .ic { width: 12px; height: 12px; }

/* 助手消息 */
.msg-assistant { align-self: stretch; min-width: 0; }
.steps { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.step { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 13px; }
.step .ic { width: 14px; height: 14px; }
.step .dur { color: var(--text-faint); font-size: 12px; }
.step.live .label { background: linear-gradient(90deg, var(--text-muted) 0%, var(--text-faint) 50%, var(--text-muted) 100%);
  background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--text-muted); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.md { font-size: 16px; line-height: 1.75; color: var(--text); word-break: break-word; }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.4; margin: 28px 0 8px; font-weight: 600; }
.md h1 { font-size: 20px; } .md h2 { font-size: 18px; } .md h3, .md h4 { font-size: 16px; }
.md > h1:first-child, .md > h2:first-child, .md > h3:first-child { margin-top: 0; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 1.4em; }
.md li { margin: 4px 0; }
.md strong { font-weight: 600; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--muted); border-radius: 4px; padding: 1px 5px; }
.md pre { background: #f7f7f8; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: 13px; }
.md blockquote { margin: 0 0 12px; padding: 8px 14px; border-left: 3px solid var(--border-strong); background: var(--bg-soft); color: var(--text-2); border-radius: 0 8px 8px 0; }
.md blockquote p:last-child { margin-bottom: 0; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.md a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.table-wrap { overflow-x: auto; margin: 0 0 14px; border: 1px solid var(--border); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 15px; }
.md th, .md td { padding: 8px 14px; border-bottom: 1px solid var(--border); text-align: left; line-height: 1.5; white-space: nowrap; }
.md th { background: var(--bg-soft); font-weight: 600; font-size: 14px; color: var(--text-2); }
.md tr:last-child td { border-bottom: 0; }
.md td + td, .md th + th { border-left: 1px solid var(--border); }

.chart {
  margin: 4px 0 16px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg);
  overflow-x: auto; text-align: center; min-height: 60px;
}
.chart svg { max-width: 100%; height: auto; }
.chart-pending { color: var(--text-faint); font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 60px; }

.msg-foot { display: flex; align-items: center; gap: 10px; margin-top: 6px; color: var(--text-faint); font-size: 12px; }
.msg-foot button { display: inline-flex; align-items: center; gap: 4px; color: var(--text-muted); padding: 3px 6px; border-radius: 6px; }
.msg-foot button:hover { background: var(--muted); color: var(--text); }
.msg-foot .ic { width: 13px; height: 13px; }
.msg-error { color: var(--danger); font-size: 14px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 10px; padding: 8px 12px; }

/* ── 输入区 ── */
.composer-wrap { flex: none; width: 100%; max-width: 860px; margin: 0 auto; padding: 0 24px 10px; }
.quick-bar { display: flex; gap: 8px; padding: 6px 0 10px; flex-wrap: wrap; }
.qc { position: relative; }
.qc-btn {
  display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); font-size: 13px; color: var(--text-2); white-space: nowrap;
}
.qc-btn:hover { border-color: var(--border-strong); background: var(--bg-soft); color: var(--text); }
.qc-btn .ic { width: 12px; height: 12px; color: var(--text-faint); }
.qc-menu { bottom: calc(100% + 6px); left: 0; min-width: 220px; }

.popover {
  position: absolute; z-index: 30; background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,.12); padding: 6px;
}
.menu-item {
  width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 10px; border-radius: 8px; text-align: left;
}
.menu-item:hover, .menu-item.hl { background: var(--muted); }
.menu-item .t { font-size: 13px; font-weight: 500; }
.menu-item .d { font-size: 12px; color: var(--text-muted); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.composer {
  border: 1px solid var(--border); border-radius: 16px; background: var(--bg); padding: 10px 10px 8px 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,.04); transition: border-color .15s;
}
.composer:focus-within { border-color: var(--border-strong); }
.composer-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.composer-chips:not(:empty) { margin-bottom: 6px; }
.composer-chips .skill-chip { margin: 0; padding: 2px 4px 2px 8px; }
.chip-x { display: grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; color: var(--text-muted); }
.chip-x:hover { background: var(--muted); color: var(--text); }
.chip-x .ic { width: 11px; height: 11px; }
#input {
  width: 100%; border: 0; outline: none; resize: none; font-size: 16px; line-height: 1.6; max-height: 200px; padding: 2px 0; background: transparent;
}
#input::placeholder { color: var(--text-faint); }
.composer-row { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.skill-anchor { position: relative; }
.ghost-btn { display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 9px; border-radius: 8px; color: var(--text-muted); font-size: 13px; }
.ghost-btn:hover, .ghost-btn.on { background: var(--muted); color: var(--text); }
.ghost-btn .ic { width: 14px; height: 14px; }
.skill-popover { bottom: calc(100% + 8px); left: 0; width: 320px; max-width: calc(100vw - 32px); }
.pop-tabs { display: flex; gap: 4px; padding: 2px 4px 6px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.pop-tab { font-size: 12px; color: var(--text-muted); padding: 4px 6px; border-radius: 6px; }
.pop-tab.active { color: var(--text); font-weight: 600; }
.pop-tab b { font-weight: 500; color: var(--text-faint); margin-left: 2px; }
.pop-search { position: relative; margin: 0 2px 6px; }
.pop-search .ic { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); width: 13px; height: 13px; color: var(--text-faint); }
.pop-search input { width: 100%; height: 30px; border: 1px solid var(--border); border-radius: 8px; outline: none; padding: 0 8px 0 27px; font-size: 13px; }
.pop-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.pop-empty { padding: 10px; color: var(--text-faint); font-size: 12px; }

.send-btn {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: var(--primary-fg); display: grid; place-items: center;
  transition: opacity .15s;
}
.send-btn:disabled { opacity: .25; cursor: default; }
.send-btn .ic-stop { display: none; fill: currentColor; stroke: none; }
.send-btn.busy .ic-send { display: none; }
.send-btn.busy .ic-stop { display: block; }
.composer-note { margin: 6px 0 0; text-align: center; color: var(--text-faint); font-size: 11px; }

/* ── 弹窗 ── */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.28); display: grid; place-items: center; padding: 16px; }
.modal-card { width: 100%; max-width: 640px; max-height: 85vh; background: var(--bg); border-radius: 16px; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 20px 20px; overflow-y: auto; }
.skill-card { border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.skill-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.skill-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--muted); display: grid; place-items: center; }
.skill-card-name { font-family: var(--mono); font-weight: 600; }
.skill-card-ver { font-size: 12px; color: var(--text-faint); }
.badge { margin-left: auto; font-size: 12px; color: #047857; background: #ecfdf5; border-radius: 999px; padding: 2px 8px; }
.skill-card p { margin: 0 0 12px; color: var(--text-2); line-height: 1.6; }
.scene-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.scene-table th, .scene-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); }
.scene-table th { color: var(--text-muted); font-weight: 500; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 60; background: var(--primary); color: var(--primary-fg);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

.sidebar-backdrop { display: none; }

/* ── 手机 ── */
@media (max-width: 767px) {
  .sidebar {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); transform: translateX(-100%);
    transition: transform .2s ease, visibility .2s; visibility: hidden;
  }
  .app.mobile-open .sidebar { transform: none; visibility: visible; box-shadow: 0 0 30px rgba(0,0,0,.15); }
  .app.collapsed .sidebar { display: flex; }
  .app.mobile-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.25); }
  .kbd-group { display: none; }
  .main-header { padding: 6px 12px 0; }
  .messages { padding: 8px 16px 20px; }
  .composer-wrap { padding: 0 12px calc(8px + env(safe-area-inset-bottom)); }
  .quick-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .quick-bar::-webkit-scrollbar { display: none; }
  .qc-menu { position: fixed; left: 12px; right: 12px; bottom: auto; min-width: 0; }
  .md { font-size: 15px; }
  .md table { font-size: 14px; }
  .msg-user { max-width: 92%; }
}
