:root {
  --bg: #131316;
  --bg2: #1a1b1e;
  --bg3: #242629;
  --border: #2e2f33;        /* 发丝线：约文字色 10% */
  --text: #e8e6e3;
  --text-dim: #9d9b96;
  --accent: #d9a03c;        /* 琥珀暖光：每屏只出现两三处 */
  --accent-ink: #1d1508;    /* accent 底上的深色文字 */
  --ok: #4fae7f;
  --err: #d95f5f;
  --radius: 10px;
  --mono: Consolas, "Cascadia Mono", ui-monospace, monospace;
  font-size: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  font-variant-numeric: tabular-nums;
}
#app { display: flex; height: 100vh; }

button { font-family: inherit; cursor: pointer; }
input, textarea {
  font-family: inherit; color: var(--text);
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; outline: none; width: 100%;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217,160,60,.14);
}
label { display: block; font-size: 12px; color: var(--text-dim); margin: 8px 0 4px; }

/* 内联 SVG 线性图标（sprite 见 index.html）：16px·1.5 描边，随文字色 */
.ic { width: 16px; height: 16px; flex: none; }

.btn {
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 16px; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: color .15s ease, background-color .15s ease, border-color .15s ease;
}
.btn:hover { border-color: var(--text-dim); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border: none; color: var(--accent-ink); font-weight: 500; }
.btn.primary:hover { background: #e2ab48; }
.btn.danger { color: var(--err); }
.btn.full { width: 100%; }
.btn.icon { padding: 8px 10px; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
/* ============ 左栏 ============ */
#sidebar {
  width: 220px; min-width: 220px; background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 12px;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; padding: 2px 4px 4px; }
.logo .ic { color: var(--accent); }  /* 品牌图标是 accent 的少数落点之一 */
#session-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.session-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  color: var(--text-dim); font-size: 13px;
  white-space: nowrap; overflow: hidden;
  transition: background-color .15s ease, color .15s ease;
}
/* 签名细节：活动会话的 4px 状态点（所有行保留点位，对齐不跳动） */
.session-item::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: transparent; flex: none; }
.session-item:hover { background: var(--bg3); color: var(--text); }
.session-item.active { background: var(--bg3); color: var(--text); font-weight: 500; }
.session-item.active::before { background: var(--accent); }
.session-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.session-item .del { visibility: hidden; border: none; background: none; color: var(--text-dim); font-size: 14px; }
.session-item:hover .del { visibility: visible; }
.session-item .del:hover { color: var(--err); }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; }
.model-switch {
  display: block; width: 100%; padding: 8px 10px; font-size: 12px;
  font-family: inherit; color: var(--text); background: var(--bg3);
  border: 1px solid var(--border); border-radius: 8px; outline: none;
  color-scheme: dark; cursor: pointer;
  transition: border-color .15s ease;
}
.model-switch:hover, .model-switch:focus { border-color: var(--text-dim); }
.model-switch:disabled { cursor: default; color: var(--text-dim); }

/* ============ 中部 ============ */
#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--bg2);
}
#chat-title { font-weight: 500; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-status { font-size: 12px; color: var(--accent); font-family: var(--mono); }

#messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 82%; display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; }
.bubble {
  padding: 12px 16px; border-radius: var(--radius); line-height: 1.65;
  word-break: break-word; overflow-wrap: anywhere;
}
/* 用户/助手气泡同为安静的拾升面，靠对齐方向区分；生成内容自己带色彩 */
.msg.user .bubble { background: var(--bg3); border: 1px solid var(--border); }
.msg.assistant .bubble { background: var(--bg2); border: 1px solid var(--border); }
.bubble p { margin: 6px 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 10px 0 6px; font-weight: 500; }
.bubble h1 { font-size: 1.25em; } .bubble h2 { font-size: 1.15em; } .bubble h3 { font-size: 1.05em; }
.bubble ul, .bubble ol { margin: 6px 0 6px 22px; }
.bubble code { background: rgba(110,118,129,.22); padding: 1px 5px; border-radius: 4px; font-size: .92em; font-family: var(--mono); }
.bubble pre {
  background: #0e0f11; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; margin: 8px 0;
}
.bubble pre code { background: none; padding: 0; }

/* 代码块（带复制按钮） */
.code-block { margin: 8px 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg3); padding: 6px 12px; font-size: 12px; color: var(--text-dim);
}
.code-head .lang { font-family: var(--mono); text-transform: lowercase; }
.code-copy {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 6px; padding: 2px 10px; font-size: 12px;
  transition: color .15s ease, border-color .15s ease;
}
.code-copy:hover { border-color: var(--text-dim); color: var(--text); }
.code-copy.copied { border-color: var(--ok); color: var(--ok); }
.code-block pre { margin: 0; border: none; border-radius: 0; }
.bubble a { color: #e3b25e; }
/* 生成图在气泡内最大 620×620（min() 保证窄气泡不被撑破），灯箱里不受限 */
.bubble img.gen { max-width: min(620px, 100%); max-height: 620px; border-radius: 8px; margin: 6px 0; display: block; cursor: zoom-in; }
.msg .meta { font-size: 11px; color: var(--text-dim); display: flex; gap: 8px; align-items: center; font-family: var(--mono); }

.tool-card {
  align-self: flex-start; width: 100%; max-width: 82%;
  background: var(--bg2); border: 1px solid var(--border); border-left: 2px solid var(--text-dim);
  border-radius: 8px; padding: 8px 12px; font-size: 13px;
}
.tool-card.err { border-left-color: var(--err); }
.tool-card .head { display: flex; align-items: center; gap: 8px; cursor: default; }
.tool-card .head .ic { width: 14px; height: 14px; color: var(--text-dim); }
.tool-card .label { font-weight: 500; }
.tool-card .status { color: var(--text-dim); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-card .status.ok { color: var(--ok); }
.tool-card .status.err { color: var(--err); }
.tool-card .args { color: var(--text-dim); font-size: 12px; margin-top: 4px; font-family: var(--mono);
  white-space: pre-wrap; word-break: break-all; display: none; }
.tool-card.open .args { display: block; }

.attachment-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; color: var(--text-dim);
}
.attachment-chip .ic { width: 12px; height: 12px; }

#drop-overlay {
  position: absolute; inset: 0; z-index: 10; display: none;
  align-items: center; justify-content: center;
  background: rgba(217,160,60,.08); border: 2px dashed var(--accent);
  font-size: 16px; color: var(--accent); pointer-events: none;
}
#drop-overlay.show { display: flex; }

#composer { border-top: 1px solid var(--border); background: var(--bg2); padding: 12px 16px; }
#attachments { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
#attachments:empty { margin: 0; }
.attachment-chip .x { cursor: pointer; color: var(--err); }
.chip-thumb { width: 18px; height: 18px; border-radius: 4px; object-fit: cover; vertical-align: -4px; }
.attachment-thumb {
  max-height: 120px; max-width: 160px; border-radius: 8px; cursor: zoom-in;
  border: 1px solid var(--border); display: block;
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#input { resize: none; max-height: 160px; line-height: 1.5; }
#btn-send { min-width: 44px; min-height: 38px; }

/* 欢迎页 */
.welcome { align-self: center; margin: auto; text-align: center; max-width: 560px; }
.welcome h2 { font-size: 20px; font-weight: 500; margin-bottom: 8px; }
.welcome p { color: var(--text-dim); margin-bottom: 20px; }
.welcome .examples { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.welcome .ex {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; cursor: pointer; text-align: left; font-size: 13px; color: var(--text-dim);
  transition: color .15s ease, border-color .15s ease;
}
.welcome .ex:hover { border-color: var(--text-dim); color: var(--text); }
.welcome .ex b { display: flex; align-items: center; gap: 8px; color: var(--text); margin-bottom: 4px; font-size: 14px; font-weight: 500; }
.welcome .ex b .ic { color: var(--text-dim); }

/* ============ 右栏 ============ */
#panel {
  width: 320px; min-width: 320px; background: var(--bg2);
  border-left: 1px solid var(--border); display: flex; flex-direction: column;
}
#panel-tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; padding: 12px 4px; background: none; border: none;
  color: var(--text-dim); font-size: 13px; border-bottom: 2px solid transparent;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: color .15s ease, border-color .15s ease;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
#panel-body { flex: 1; overflow-y: auto; padding: 16px; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.pane-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.hint { font-size: 12px; color: var(--text-dim); line-height: 1.5; }

.card-list { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px;
}
.card .row { display: flex; align-items: center; gap: 8px; }
.card .name { font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: flex; align-items: center; gap: 8px; }
.card .name .ic { color: var(--text-dim); }
.card .desc { font-size: 12px; color: var(--text-dim); margin-top: 4px; line-height: 1.5; }
.card .actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.card .actions .btn { padding: 4px 10px; font-size: 12px; }
.card .sub { font-size: 11px; color: var(--text-dim); margin-top: 4px; font-family: var(--mono); }
/* 状态：安静的单色文本 + 4px 指示点（签名细节），不再是彩色药丸 */
.tag {
  font-size: 11px; font-family: var(--mono); color: var(--text-dim);
  display: inline-flex; align-items: center; gap: 6px;
}
.tag::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: var(--text-dim); }
.tag.on { color: var(--ok); }
.tag.on::before { background: var(--ok); }
.docs-list { font-size: 12px; color: var(--text-dim); margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.docs-list div { padding: 2px 0; display: flex; justify-content: space-between; gap: 8px; }

.settings-block { margin-bottom: 24px; }
.settings-block h4 { margin-bottom: 10px; font-size: 13px; color: var(--text-dim); font-weight: 500; }
.provider-card { display: flex; flex-direction: column; gap: 6px; }
.provider-card .head { display: flex; align-items: center; gap: 6px; }
.provider-card .name { font-weight: 500; flex: 1; }
.provider-card .fields { display: none; flex-direction: column; gap: 4px; }
.provider-card.open .fields { display: flex; }
.provider-card label { margin: 4px 0 2px; }

/* ============ 弹窗 ============ */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; width: 560px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
}
.modal-box h3 { margin-bottom: 6px; font-weight: 500; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3a3b3e; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ 图片/视频灯箱 ============ */
.lightbox {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.78); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
}
.lightbox.hidden { display: none; }
.lightbox video.hidden { display: none; }  /* 项目无全局 .hidden，灯箱内 img/video 互斥显示 */
.lightbox img {
  max-width: 92vw; max-height: 92vh;
  border-radius: 8px; box-shadow: 0 8px 48px rgba(0,0,0,.6);
  cursor: default;
}
.lightbox video {
  max-width: 92vw; max-height: 92vh;
  border-radius: 8px; box-shadow: 0 8px 48px rgba(0,0,0,.6);
  cursor: default;
}

/* 气泡内生成视频：角标按钮触发灯箱放大（视频本体保留原生控件）；同图最大 620×620。
   wrap 自身 max-width 先夹住尺寸（fit-content 参与计算的是未约束固有宽，须由 wrap 上限兜住），
   视频在 wrap 内再自适应，横竖版都精确贴边无黑边 */
.bubble .gen-video-wrap { position: relative; display: block; margin: 6px 0;
  width: fit-content; max-width: min(620px, 100%); }
.bubble video.gen-video {
  width: auto; max-width: 100%; max-height: 620px;
  border-radius: 8px; display: block; background: #000;
}
.bubble .gen-video-zoom {
  position: absolute; top: 8px; right: 8px;
  padding: 2px 8px; font-size: 12px; line-height: 1.4;
  background: rgba(0,0,0,.55); color: #fff;
  border: 1px solid rgba(255,255,255,.35); border-radius: 6px;
  cursor: zoom-in;
}
.bubble .gen-video-zoom:hover { background: rgba(0,0,0,.75); }

/* 气泡内生成音频：原生控件已含播放/进度/音量，宽度统一占满文本列 */
.bubble audio.gen-audio { display: block; width: min(620px, 100%); height: 40px;
  margin: 6px 0; accent-color: var(--accent); }

/* 打字点：真实生成状态的循环动效，保留 */
.typing-dots::after {
  content: "●●●"; letter-spacing: 2px; font-size: 10px; color: var(--accent);
  animation: blink 1.2s infinite;
}
@keyframes blink { 0%,100% { opacity: .25; } 50% { opacity: 1; } }
