/* ════════════════════════════════════════════════════════════
   18. 顶部主题切换器
   ────────────────────────────────────────────────────────────
   架构:T164 起每轮回复不再显示头像抬头,助手身份(头像 + 名字)在顶栏显示一次,
   主题名 + ⌄ 作为第二行放在名字下方。
   本文件管:.topbar-identity(身份)+ .topbar-title-wrap(主题切换触发点),
   下拉面板,独立"临时模式"按钮 + 分隔线。
   临时态:标题文字+⌄ 染金,临时按钮 is-active 金黄发光。
   P411:全量 token 化,所有金色/阴影走变量,不再写 [data-theme="light"] 浅色例外。
   ════════════════════════════════════════════════════════════ */

/* ─── 无对话语境隐藏(欢迎页/设置页等)─── */
.topbar-left.is-hidden > .topbar-identity { display: none !important; }
.topbar-right.is-hidden > .topbar-temp-toggle,
.topbar-right.is-hidden > .topbar-sep { display: none !important; }

/* ─── 助手身份:小头像 + 名字,主题名在名字下方 ─── */
.topbar-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 0 1 auto;
  max-width: min(52vw, 520px);
}
.topbar-agent-avatar { display: inline-flex; flex-shrink: 0; }
.topbar-agent-avatar:empty { display: none; }
/* 名字与主题两行都随身份区宽度伸缩,放不下时各自省略 */
.topbar-identity-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.topbar-agent-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-agent-name:empty { display: none; }

/* ─── 主题名(主题切换器触发点)─── */
.topbar-title-wrap {
  display: flex;
  align-items: center;
  gap: 3px;
  margin: 1px 0 0 -5px;
  padding: 1px 5px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
  transition: background var(--transit-fast), border-color var(--transit-fast), color var(--transit-fast);
  min-width: 0;
}
.topbar-title-wrap:hover {
  background: var(--bg-hover);
  border-color: var(--border-glass);
}
.topbar-title-wrap.open {
  background: var(--brand-bg-subtle);
  border-color: var(--brand-border);
}

.topbar-title-wrap .ts-topic-name {
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.topbar-title-wrap .ts-topic-name:empty::before {
  content: "新对话";
  color: var(--text-muted);
}

.topbar-title-wrap .ts-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: transform 0.18s ease, color 0.16s ease;
  flex-shrink: 0;
}
.topbar-title-wrap.open .ts-caret {
  transform: rotate(180deg);
  color: var(--brand-primary);
}

/* 模型名节点保留(chat.js 写入点)但视觉隐藏 */
#chat-agent-model { display: none; }

/* ─── 临时态:标题 + ⌄ 染金 ─── */
.topbar-title-wrap.ts-temp .ts-topic-name { color: var(--brand-primary); font-weight: 600; }
.topbar-title-wrap.ts-temp .ts-caret { color: var(--brand-primary); }

/* ─── 独立"临时模式"按钮 ─── */
.topbar-temp-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 16px;
  height: 40px;
  background: transparent;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  font-family: inherit;
  transition: background var(--transit-fast), border-color var(--transit-fast), color var(--transit-fast), box-shadow var(--transit-fast), transform 0.1s ease;
}
.topbar-temp-toggle svg { width: 15px; height: 15px; flex-shrink: 0; }
.topbar-temp-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--brand-border);
  color: var(--brand-primary);
}
.topbar-temp-toggle:active { transform: scale(0.97); }
.topbar-temp-toggle:disabled { opacity: 0.5; cursor: progress; }
.topbar-temp-toggle.is-active {
  background: var(--brand-bg);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
  /* P413 扁平化:删金色 glow,保留 inset 描边作为激活态识别(无装饰发光) */
  box-shadow: 0 0 0 1px var(--brand-primary) inset;
}
.topbar-temp-toggle.is-active:hover {
  background: var(--brand-bg-strong);
}

/* ─── 下拉面板 ─── */
.ts-panel {
  background: var(--bg-floating);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  padding: 10px;
  /* P413 扁平化:从 4 层(近距离锐利 + 远距离扩散 + 金色光环 + 顶部 inset 高光)→ 单层柔影 token */
  box-shadow: var(--shadow-ambient);
  max-height: 70vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: ts-panel-in 0.16s ease;
}
.ts-panel.hidden { display: none; }
@keyframes ts-panel-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.ts-panel-head {
  padding: 8px 12px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.2px;
}

.ts-new {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: transparent;
  border: 1px dashed var(--border-light);
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 14.5px;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  margin-bottom: 4px;
}
.ts-new:hover {
  background: var(--bg-hover);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

.ts-empty {
  padding: 16px 12px;
  font-size: 13.5px;
  color: var(--text-tertiary);
  text-align: center;
}

/* ─── 分组:特殊 / 今天 / 本周 / 更早 ─── */
.ts-section { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.ts-section:first-of-type { margin-top: 4px; }
.ts-section-head {
  padding: 6px 12px 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.ts-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 38px 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14.5px;
  color: var(--text-main);
  transition: background 0.15s ease, color 0.15s ease;
  min-width: 0;
}
.ts-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.ts-item-icon svg { width: 18px; height: 18px; display: block; }

.ts-item:hover {
  background: var(--bg-hover);
  color: var(--text-bright);
}
.ts-item:hover .ts-item-icon { color: var(--text-secondary); }

.ts-item.active {
  background: var(--brand-bg-light);
  color: var(--brand-primary);
  border: 1px solid var(--brand-border);
  padding: 10px 37px 10px 11px;
  font-weight: 500;
}
.ts-item.active .ts-item-icon { color: var(--brand-primary); }

.ts-item.pinned .ts-item-title::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brand-primary);
  margin-right: 7px;
  vertical-align: middle;
}

/* 特殊组 — 临时对话动作 item */
.ts-item.ts-item-temp { padding-right: 12px; }
.ts-item.ts-item-temp,
.ts-item.ts-item-temp .ts-item-icon {
  color: var(--brand-primary);
}
.ts-item.ts-item-temp:hover {
  background: var(--brand-bg-subtle);
  color: var(--brand-primary-hover);
}
.ts-item.ts-item-temp .ts-item-title { font-weight: 500; }
.ts-item.ts-item-temp .ts-item-time {
  color: var(--text-tertiary);
  font-size: 12.5px;
  font-variant-numeric: normal;
}
/* 创建中态:防双击视觉反馈(对 div/button 都生效)*/
.ts-item.is-pending,
.ts-new.is-pending {
  opacity: 0.55;
  pointer-events: none;
  cursor: progress;
}
.ts-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.ts-item-title-input {
  width: 100%;
  /* 黑底 25%:中性自适应,深色版叠 #141414 浮层得 ~#0F0F0F,浅色版叠 #FFF 浮层得 ~#BFBFBF,两侧都合适 */
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--brand-primary);
  border-radius: 5px;
  padding: 2px 6px;
  color: inherit;
  font: inherit;
  outline: none;
}
.ts-item-time {
  font-size: 12px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  transition: opacity 0.15s ease;
}
.ts-item:hover .ts-item-time,
.ts-item.editing .ts-item-time { opacity: 0; }

.ts-item-rename,
.ts-item-del {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.ts-item-rename { right: 32px; }
.ts-item-del { right: 4px; }
.ts-item:hover .ts-item-rename,
.ts-item:hover .ts-item-del,
.ts-item.editing .ts-item-rename,
.ts-item.editing .ts-item-del {
  opacity: 1;
  pointer-events: auto;
}
.ts-item-rename:hover {
  background: var(--brand-bg-light);
  color: var(--brand-primary);
}
.ts-item-del:hover {
  background: var(--error-bg);
  color: var(--error-color);
}

/* ─── 移动端 / 窄屏 ─── */
@media (max-width: 640px) {
  .topbar { padding-left: 12px; padding-right: 12px; gap: 8px; }
  .topbar-left { gap: 6px; }
  .topbar-right { gap: 6px; }
  .topbar-sep { height: 18px; }
  .topbar-identity { gap: 8px; max-width: none; }
  .topbar-temp-toggle {
    padding: 0 12px;
    height: 34px;
    font-size: 12.5px;
  }
  .ts-panel { padding: 8px; border-radius: 14px; }
  .ts-new { font-size: 14px; padding: 10px 12px; }
  .ts-section-head { padding: 5px 10px 3px; }
  .ts-item {
    font-size: 14px;
    gap: 10px;
    padding: 10px 36px 10px 10px;
  }
  .ts-item.active { padding: 9px 35px 9px 9px; }
  .ts-item-icon, .ts-item-icon svg { width: 17px; height: 17px; }
  .ts-item-time { font-size: 11.5px; }
}

/* ─── 触屏设备(无 hover 能力):重命名/删除常显 + 时间让位给按钮 ─── */
@media (hover: none) {
  .ts-item-rename,
  .ts-item-del {
    opacity: 0.55;
    pointer-events: auto;
  }
  .ts-item .ts-item-time { display: none; }
  .ts-item.ts-item-temp .ts-item-time { display: inline; }
}

@media (max-width: 480px) {
  .topbar-temp-toggle { display: none; }
  .topbar-right > .topbar-sep { display: none; }
}

/* P411:不再写 [data-theme="light"] 组件级例外。
   01-variables.css + theme-light.css 已统一覆盖 --brand-* / --shadow-* / --bg-floating / --border-* 等所有相关变量。
   本文件全走变量,浅色自动跟随。若浅色出现意外漂移,先核查变量值而非加 [data-theme="light"] 例外。 */
