/* 幕间 v0.1 —— 皮肤：灰色极简（低调、优雅、不花哨） */

:root {
  --bg: #161619;
  --panel: #1c1c20;
  --panel-2: #232329;
  --line: #2b2b33;
  --text: #e7e7ea;
  --muted: #8b8b95;
  --faint: #5d5d66;
  --user: #30333d;
  --accent: #cfd4de;
  --danger: #c9706f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC",
    "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
textarea, input, select { font: inherit; color: var(--text); }

#app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* 手机浏览器地址栏收缩时也能占满 */
}

/* ---------- 侧栏（v0.3：两层结构） ---------- */
#sidebar {
  width: 276px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
#charPane, #sessionPane { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#charPane.hidden, #sessionPane.hidden { display: none; }
#charList, #sessionList { flex: 1; overflow-y: auto; padding: 4px 10px; }
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 18px 14px 8px;
}
.side-head .logo { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { font-size: 17px; letter-spacing: 5px; color: var(--accent); font-weight: 600; }
#sessionPaneTitle { letter-spacing: 1px; font-size: 15px; }
#btnCloseSide { display: none; }
.side-new { padding: 6px 12px 10px; }
.session-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
  min-width: 0;
}
.session-item:hover { background: var(--panel-2); color: var(--text); }
.session-item.active {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--accent);
}
.session-item .st { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .sx {
  opacity: 0;
  color: var(--faint);
  font-size: 12px;
  padding: 2px 5px;
  border-radius: 6px;
  flex-shrink: 0;
}
.session-item:hover .sx, .session-item.active .sx { opacity: 1; }
.session-item .sx:hover { color: var(--danger); }

/* 角色行（v0.3.2：放大到36px，头像清晰可见） */
.char-item { padding: 12px 10px; }
.char-avatar {
  width: 36px; height: 36px;
  flex-shrink: 0;
  border-radius: 9px;
  overflow: hidden;
}
.char-avatar .avatar-blk { font-size: 15px; }
.char-item .st { font-size: 14px; }
.char-meta { font-size: 11px; color: var(--faint); flex-shrink: 0; }

/* 头像上传槽位（弹窗内） */
.avatar-slot {
  width: 56px; height: 56px;
  flex-shrink: 0;
  border-radius: 10px;
  border: 1px dashed var(--line);
  background: var(--panel-2);
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-slot:hover { border-color: var(--muted); }
.avatar-slot .avatar-img { width: 100%; height: 100%; object-fit: cover; }
.avatar-slot-hint {
  font-size: 10px;
  color: var(--faint);
  text-align: center;
  line-height: 1.4;
  user-select: none;
}
.profile-row { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.profile-row #myName { flex: 1; }

/* 角色卡弹窗的名字行 */
.role-name-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.role-name-row #roleName { flex: 1; }
.flex-sp { flex: 1; }

/* 幕后：更新历史 */
.history-list { max-height: 56vh; overflow-y: auto; }
.history-item { padding: 14px 2px; border-bottom: 1px solid var(--line); }
.history-item:last-child { border-bottom: none; }
.history-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.history-v { font-size: 13.5px; font-weight: 600; color: var(--accent); }
.history-date { font-size: 11.5px; color: var(--faint); }
.history-title { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.history-li {
  font-size: 12.5px; color: var(--muted);
  padding: 2.5px 0 2.5px 14px;
  position: relative;
}
.history-li::before {
  content: '·';
  position: absolute; left: 4px;
  color: var(--faint);
}
#btnHistory { cursor: pointer; }
#btnHistory:hover { color: var(--accent); text-decoration: underline; }
.side-foot {
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  align-items: center;
}
.side-foot button {
  flex: 1;
  font-size: 12.5px;
  color: var(--muted);
  padding: 8px 4px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.side-foot button:hover { color: var(--text); }
.version { font-size: 11px; color: var(--faint); flex-shrink: 0; }

/* 手机：侧栏变抽屉 */
#scrim { display: none; }
@media (max-width: 860px) {
  #sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  #sidebar.open { transform: none; }
  #scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .52);
    z-index: 25;
  }
  #scrim.show { display: block; }
  #btnCloseSide { display: block; }
}

/* ---------- 主区 ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
#btnMenu { display: none; }
@media (max-width: 860px) { #btnMenu { display: block; } }
.tb-title {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.tb-sub {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
select.ctl {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  min-width: 0;
}
#selProvider { flex: 0 0 118px; }
#selModel { flex: 1; }

/* ---------- 聊天区（v0.3.2：消息带头像） ---------- */
#chat { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.chat-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 22px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.msg {
  white-space: pre-wrap;
  word-break: break-word;
  min-width: 0;
  display: flex;
  gap: 10px;
}
/* 消息头像 */
.msg-avatar {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
  margin-top: 2px;
}
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-blk {
  width: 100%; height: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  border-radius: 8px;
}
.msg-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.msg.user {
  align-self: flex-end;
  max-width: 84%;
  flex-direction: row-reverse;
}
.msg.user .msg-body {
  background: var(--user);
  padding: 9px 14px;
  border-radius: 14px 14px 4px 14px;
}
.msg.assistant { align-self: stretch; }

/* 思维链收展（v0.3.2） */
.think-head {
  font-size: 12px;
  color: var(--faint);
  cursor: pointer;
  user-select: none;
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}
.think-head::before { content: '▸ '; }
.think-head.open::before { content: '▾ '; }
.think-head:hover { color: var(--muted); }
.msg .reasoning {
  display: none;
  font-size: 12.5px;
  color: var(--faint);
  font-style: italic;
  border-left: 2px solid var(--line);
  padding-left: 10px;
  margin-bottom: 10px;
  overflow-y: auto;
}
.msg .reasoning.open { display: block; }
/* v0.3.3 流式取景框：固定窗口大小，思考只露最近几行，滚着走 */
.msg .reasoning.streaming {
  max-height: 76px;           /* 约3行半的取景框 */
  mask-image: linear-gradient(to bottom, transparent 0, #000 18px);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 18px);
}
.msg .reasoning.open:not(.streaming) { max-height: 260px; } /* 展开看全量 */

/* token 用量 */
.msg-usage {
  display: none;
  font-size: 11px;
  color: var(--faint);
  margin-top: 6px;
  letter-spacing: 0.3px;
}

/* 消息操作条：hover 才现身 */
.msg-ops {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity .12s ease;
}
.msg:hover .msg-ops { opacity: 1; }
.msg-ops .op {
  font-size: 11.5px;
  color: var(--faint);
  background: none;
  border: none;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.msg-ops .op:hover { color: var(--danger); background: var(--panel-2); }

.msg .error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--accent);
  vertical-align: -2px;
  margin-left: 2px;
  border-radius: 1px;
  animation: blink 1s step-start infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.empty {
  min-height: 60%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--faint);
  text-align: center;
  padding: 40px 20px;
}
.empty .glyph { font-size: 20px; letter-spacing: 10px; color: var(--accent); }
.empty .hint { font-size: 13px; line-height: 1.9; white-space: pre-line; }

/* ---------- 输入区 ---------- */
#composer {
  border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.composer-inner {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
#input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  resize: none;
  max-height: 40vh;
  outline: none;
  font-size: 15px;
  line-height: 1.55;
}
#input:focus { border-color: #3d3d47; }
#btnSend {
  flex-shrink: 0;
  padding: 0 18px;
  height: 42px;
  border-radius: 12px;
}
#btnSend.stop {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 18px;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 500px;
  max-height: 86vh;
  max-height: 86dvh;
  overflow-y: auto;
}
.modal-card h3 { font-size: 15px; font-weight: 600; letter-spacing: 1px; margin-bottom: 10px; }
.modal-card .hint { margin-bottom: 6px; }
.modal-card label { display: block; font-size: 12.5px; color: var(--muted); margin: 14px 0 6px; }
.modal-card input, .modal-card textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
}
.modal-card textarea { resize: vertical; line-height: 1.6; }
.modal-card input:focus, .modal-card textarea:focus { border-color: #3d3d47; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.btn-primary {
  background: var(--accent);
  color: #1a1a1e;
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 18px;
  border-radius: 10px;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary.wide { width: 100%; padding: 10px; }
.btn-ghost { color: var(--muted); font-size: 13.5px; padding: 9px 14px; border-radius: 10px; }
.btn-ghost:hover { background: var(--panel-2); }
.hint { font-size: 12px; color: var(--faint); line-height: 1.75; }

/* ---------- 参数面板 ---------- */
.params-btn { color: var(--muted); }
.params-btn.active { color: var(--text); border-color: #3d3d47; }

.p-label { display: block; font-size: 13px; color: var(--text); font-weight: 600; margin: 18px 0 8px; }

/* 思维链三档分段选择器 */
.seg {
  display: flex;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  padding: 7px 0;
  border-radius: 8px;
}
.seg button.on { background: var(--accent); color: #1a1a1e; font-weight: 600; }

/* 超参行：勾选框 + 滑条 */
.param-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}
.chk {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px !important;
  color: var(--muted) !important;
  margin: 0 !important;
  flex: 0 0 auto;
  cursor: pointer;
  user-select: none;
}
.chk input[type="checkbox"] { width: auto; accent-color: var(--accent); }
.chk.checked, .param-row.enabled .chk { color: var(--text) !important; }

.p-range {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.p-range input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
  height: 3px;
  background: var(--line);
  border: none;
  border-radius: 2px;
  padding: 0;
}
.p-range output {
  font-size: 12.5px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  flex: 0 0 42px;
  text-align: right;
}
/* 未勾选时整行压暗 */
.param-row.disabled { opacity: .38; }
.param-row.disabled .p-range input[type="range"] { pointer-events: none; }

/* ---------- 轻提示 ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  max-width: 86vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2e2e36; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
