/* 设计令牌（:root / [data-theme=dark] 变量）已统一至 css/tokens.css（在本文件之前加载）。
   本文件不再定义变量，仅消费 var()。间距/圆角/字号/层级/阴影/品牌色阶等分级标度见 tokens.css。 */

*{
  margin:0;
  padding:0;
  box-sizing:border-box;
}

body{
  font-family:var(--type-family-ui);
  font-size:var(--type-size-body);
  background-color:var(--bg-primary);
  color:var(--text-primary);
  line-height:var(--type-line-body);
}

button,
input,
textarea,
select{
  font-family:inherit;
  font-size:inherit;
  font-weight:inherit;
  line-height:inherit;
}

small {
  font-size: var(--type-size-meta);
}

/* rem 相对根元素 html：字体档位必须作用在 html 上，整站用 rem 的文案才会随档位缩放 */
html[data-font="small"]{font-size:var(--root-font-size-small);}
html[data-font="medium"]{font-size:var(--root-font-size-medium);}
html[data-font="large"]{font-size:var(--root-font-size-large);}

/* =========================
   Layout
========================= */
.app-container{
  display:flex;
  height:calc(100dvh - var(--icp-footer-height, 36px));
  min-height:calc(100dvh - var(--icp-footer-height, 36px));
  overflow:hidden;
}

/* =========================
   Sidebar
========================= */
.sidebar{
  width:var(--sidebar-width);
  background-color:var(--sidebar-bg);
  border-right:1px solid var(--sidebar-border);
  display:flex;
  flex-direction:column;
  flex-shrink:0;
  min-height:0;
  height:100%;
  transition:width .2s ease,border-color .2s ease;
}

@media (min-width:769px){
  .sidebar.is-collapsed{
    width:0;
    min-width:0;
    overflow:hidden;
    border-right-color:transparent;
  }

  body.chat-sidebar-collapsed #globalSiteFooter.site-footer{
    left:0;
  }
}

.sidebar-header{
  height:var(--header-height);
  min-height:var(--header-height);
  padding:0 14px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  border-bottom:1px solid var(--border-color);
  background-color:var(--sidebar-bg);
  box-sizing:border-box;
}

.sidebar-header-actions{
  display:flex;
  flex:0 0 auto;
  align-items:center;
  gap:2px;
}

.sidebar-header-icon-btn{
  width:34px;
  height:34px;
  flex:0 0 auto;
  padding:0;
  border:0;
  border-radius:9px;
  color:var(--app-text-secondary);
  background:transparent;
}

.sidebar-header-icon-btn:hover,
.sidebar-header-icon-btn:focus-visible{
  outline:none;
  color:var(--app-accent);
  background:var(--app-accent-soft);
}

.sidebar-header-icon-btn:focus-visible{
  box-shadow:0 0 0 3px var(--app-focus-ring);
}

.sidebar-collapsed-launcher{
  display:flex;
  flex:0 0 auto;
  align-items:center;
  gap:10px;
  margin-right:8px;
}

.sidebar-collapsed-launcher__logo{
  width:36px;
  height:36px;
  flex:0 0 auto;
  object-fit:contain;
}

.sidebar-collapsed-launcher__actions{
  display:flex;
  align-items:center;
  gap:3px;
  padding:5px 7px;
  border:1px solid var(--app-border);
  border-radius:999px;
  background:var(--app-surface);
  box-shadow:var(--shadow-sm);
}

.sidebar-collapsed-launcher__button,
.sidebar-collapsed-launcher__actions .sidebar-header-icon-btn{
  width:34px;
  height:34px;
  padding:0;
  border-radius:50%;
  color:var(--app-text);
}

.sidebar-collapsed-launcher__actions .sidebar-header-icon-btn:hover,
.sidebar-collapsed-launcher__actions .sidebar-header-icon-btn:focus-visible{
  color:var(--app-accent);
  background:var(--app-accent-soft);
}

/* Vue Teleport 挂载点：承载 .brand，与右侧新建按钮并排 */
.sidebar-brand-mount{
  display:flex;
  min-width:0;
  flex:1;
}

/* 左上角品牌区：logo + 标题 */ 
.sidebar-header .brand { 
  display: flex; 
  align-items: center; 
  gap: var(--brand-lockup-gap); 
  min-width: 0; 
  flex: 1; 
} 

.sidebar-header .brand .logo { 
  width: var(--brand-logo-md); 
  height: var(--brand-logo-md); 
  object-fit: contain; 
  flex-shrink: 0; 
} 

.sidebar-header .brand h1 { 
  margin: 0; 
  min-width: 0; 
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis; 
  font-size: var(--text-md);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  letter-spacing: var(--brand-title-tracking);
} 

.search-sort-row{
  padding: 10px 12px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-box{
  flex: 1;
  min-width: 0;
  padding: 0;
}

.search-box input{
  width:100%;
  padding:8px 12px;
  border:1px solid var(--sidebar-border);
  border-radius:10px;
  background-color:var(--chat-main-bg);
  color:var(--text-primary);
  font-size: var(--type-size-body);
}

.search-box input:focus{
  outline:none;
  border-color:var(--accent-color);
}

.chat-sort-box{
  padding: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sort-icon-btn{
  width: 32px;
  height: 32px;
  border: 1px solid var(--sidebar-border);
  border-radius: 10px;
  background-color: var(--chat-main-bg);
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: var(--type-size-body);
  font-weight: var(--font-weight-bold);
  line-height: var(--type-line-none);
}

.sort-icon-btn svg{
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sort-icon-btn:hover{
  color: var(--text-primary);
  border-color: var(--accent-color);
}

.sort-icon-btn.active{
  color: #fff;
  background-color: var(--accent-color);
  border-color: var(--accent-color);
}

.sort-icon-btn[data-dir="asc"]::after,
.sort-icon-btn[data-dir="desc"]::after{
  position: absolute;
  right: -2px;
  top: -4px;
  width: 14px;
  height: 14px;
  border-radius: 7px;
  background: var(--sidebar-bg);
  border: 1px solid var(--sidebar-border);
  color: var(--text-primary);
  font-size: var(--type-size-meta);
  line-height: 12px;
  text-align: center;
  content: '';
}

.sort-icon-btn[data-dir="asc"]::after{ content: '↑'; }
.sort-icon-btn[data-dir="desc"]::after{ content: '↓'; }

.chat-list{
  flex:1;
  overflow-y:auto;
  padding:6px 10px 12px;
}

.chat-item{
  padding:10px 12px;
  border-radius:var(--radius-lg);
  cursor:pointer;
  margin-bottom:2px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  transition:background-color 0.15s ease,color 0.15s ease;
  color:var(--text-primary);
}

/* 占位「暂无会话」等无 data-id 的项不参与悬停底 */
.chat-item:not([data-id]){
  cursor:default;
}
.chat-item:not([data-id]):hover{
  background-color:transparent;
}

.chat-item:hover{background-color:var(--sidebar-item-hover);}
.chat-item.active{
  background-color:var(--sidebar-item-active);
  color:var(--text-primary);
  box-shadow:inset 3px 0 0 var(--accent-color);
}

.chat-item-content{
  flex:1;
  min-width:0;
}

.chat-item-title{
  font-weight: var(--font-weight-medium);
  font-size: var(--type-size-body);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.chat-item-title-icon{
  display:inline-flex;
  vertical-align:-2px;
  margin-right:4px;
  color:var(--accent-color);
}

.chat-item.active .chat-item-title{
  font-weight: var(--font-weight-semibold);
}

/* 侧栏会话时间分组标题（今天/昨天/近7天/更早） */
.chat-list-group-label{
  padding:14px 12px 5px;
  font-size:var(--text-2xs,11px);
  font-weight: var(--font-weight-semibold);
  color:var(--text-muted);
  letter-spacing:0.03em;
  user-select:none;
}
.chat-list-group-label:first-child{padding-top:6px;}

.chat-item-date{
  font-size: var(--type-size-caption);
  opacity:0.72;
  color:var(--text-secondary);
}

.chat-item-snippet{
  font-size: var(--type-size-caption);
  opacity:0.88;
  color:var(--text-secondary);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  margin-top:2px;
}

.chat-item-snippet mark{
  background:rgba(255, 214, 102, 0.65);
  color:inherit;
  border-radius:3px;
  padding:0 2px;
}

.chat-item.active .chat-item-snippet{
  opacity:0.92;
  color:var(--text-secondary);
}

.chat-item.active .chat-item-date{
  opacity:0.85;
  color:var(--text-secondary);
}

.message-bubble mark.search-hit{
  background: rgba(255, 214, 102, 0.7);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.message.search-hit-target .message-bubble{
  box-shadow: 0 0 0 2px rgba(255, 214, 102, 0.45) inset;
}

.chat-item-delete{
  opacity:0;
  background:none;
  border:none;
  color:var(--text-muted);
  cursor:pointer;
  padding:4px;
  border-radius:8px;
}

.message.user .message-select-row{
  width:100%;
  align-self:stretch;
  text-align:left;
}

.message-select-row{
  margin-bottom: 8px;
  font-size: var(--type-size-caption);
  color: var(--text-secondary);
}

.message-select-row label{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.message-select-checkbox{
  width: 14px;
  height: 14px;
}

.share-select-backdrop{
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--icp-footer-height, 36px);
  height: 82px;
  background: transparent;
  backdrop-filter: none;
  z-index: 880;
  display: none;
  pointer-events: none;
}

.share-select-backdrop.active{
  display: block;
}

.share-select-bar{
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--icp-footer-height, 36px);
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-primary);
  z-index: 900;
  box-shadow: 0 -6px 18px rgba(0,0,0,0.08);
}

.share-select-bar.active{
  display: flex;
}

@media (min-width: 769px){
  .share-select-backdrop,
  .share-select-bar{
    left: var(--sidebar-width, 280px);
  }

  body.chat-sidebar-collapsed .share-select-backdrop,
  body.chat-sidebar-collapsed .share-select-bar{
    left: 0;
  }
}

.share-select-left{
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.share-select-all-label{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.share-select-count{
  color: var(--text-secondary);
  font-size: var(--type-size-card-title);
  white-space: nowrap;
}

.share-select-right{
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 滑动删除容器 */
.chat-item-swipe-container {
  position: relative;
  width: 100%;
  overflow: hidden;
}

/* 滑动删除按钮 */
.chat-item-delete-swipe {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 80px;
  background: var(--danger-color);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--type-size-body);
  font-weight: var(--font-weight-medium);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 1;
}

.chat-item.swiped .chat-item-delete-swipe {
  transform: translateX(0);
}

/* 滑动时的聊天项样式 */
.chat-item {
  transition: transform 0.3s ease;
  will-change: transform;
}

.chat-item.swiped {
  transform: translateX(-80px);
}

.chat-item.dragging{
  opacity: 0.7;
}

/* 确保内容不被遮挡 */
.chat-item.swiped .chat-item-content {
  opacity: 0.8;
}

.chat-item:hover .chat-item-delete{opacity:0.7;}
.chat-item-delete:hover{
  opacity:1 !important;
  background-color:rgba(220,38,38,0.2);
}

.sidebar-footer{
  padding: 12px;
  margin-top: auto;
  flex: 0 0 var(--chat-bottom-dock-height);
  min-height: var(--chat-bottom-dock-height);
  box-sizing: border-box;
  border-top: 1px solid var(--border-color);
  background-color: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  position: relative;
  z-index: 3100;
}

.footer-group {
  display: flex; /* 每行内部横向排列 */
  gap: 8px; /* 按钮之间的间距 */
  width: 100%;
}

.sidebar-auth-mount {
  width: 100%;
  flex-shrink: 0;
}

.sidebar-auth-group {
  width: 100%;
}

.footer-group--agent-kb {
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
}

.footer-group--agent-kb .agent-selector-wrapper {
  width: 100%;
  position: relative;
}

.footer-group--agent-kb .sidebar-footer-stack {
  width: 100%;
}

/* 侧栏底部旧版横排 btn-secondary（已改为 sidebar-footer-row-btn） */
.footer-group:not(.footer-group--agent-kb) .btn-secondary {
  flex: 1;
  min-width: 0;
  padding: 8px 4px;
  font-size: var(--type-size-control);
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

/* 针对带有图标的同步按钮微调 */
#syncBtn svg {
  flex-shrink: 0;
}

.sidebar-footer-row-link {
  color: var(--text-primary);
}

/* 侧栏弹出菜单（从 index.html 迁入，确保生产环境 style.css 单独更新时仍可用） */
.sidebar-footer-menu-wrap,
.auth-menu-wrap--sidebar {
  position: relative;
}
.sidebar-flyout-panel {
  display: none;
  position: absolute;
  left: calc(100% + 8px);
  right: auto;
  top: auto;
  bottom: 0;
  min-width: 200px;
  width: max-content;
  max-width: min(280px, calc(100vw - var(--sidebar-width, 280px) - 32px));
  max-height: min(320px, calc(100dvh - var(--icp-footer-height, 36px) - 12px));
  overflow-y: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 3200;
  padding: 6px;
}
.sidebar-flyout-panel.active,
.agent-selector-panel.active {
  display: block;
}
.auth-dropdown-menu.sidebar-flyout-panel {
  left: calc(100% + 8px);
  right: auto;
  top: auto;
  bottom: 0;
  min-width: 200px;
}
.auth-menu-wrap--sidebar .sidebar-flyout-panel {
  bottom: var(--icp-footer-height, 36px);
}
.agent-selector-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: var(--type-size-body);
}
.agent-selector-item:hover {
  background: var(--bg-secondary);
}
.agent-selector-item.active {
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent-color);
}
.agent-selector-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-selector-divider {
  height: 1px;
  background: var(--border-color);
  margin: 4px 0;
}
.auth-dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
  font-size: var(--type-size-body);
}
.auth-dropdown-item:hover {
  background: var(--bg-secondary);
}

/* 知识库未配置时禁用 */
.btn-disabled{
  opacity: 0.5;
  pointer-events: none;
}

/* =========================
   Main Chat
========================= */
.chat-main{
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* 关键：防止被内容撑开或压缩 */
  min-height: 0; /* 与侧栏并列 flex 时，允许子项正确收缩，避免主区挤出视口 */
  width: 100%;  /* 强制铺满 */
  background-color: var(--chat-main-bg);
}

.chat-header{
  height:var(--header-height);
  padding:0 var(--chat-inline-padding);
  display:flex;
  align-items:center;
  gap:8px;
  border-bottom:1px solid var(--border-color);
  background-color:var(--chat-main-bg);
  box-sizing:border-box;
}

.chat-header-left{
  display:flex;
  align-items:center;
  gap:8px;
  min-width:0;
  flex:1;
}

.chat-header-left h2{
  margin:0;
  font-size: var(--type-size-section-title);
  font-weight: var(--font-weight-medium);
}

.chat-title-cluster{
  display:flex;
  align-items:center;
  gap:4px;
  min-width:0;
  flex:1 1 0%;
  overflow:hidden;
}

.chat-title-text-wrap{
  flex:0 1 auto;
  min-width:0;
  max-width:100%;
  overflow:hidden;
}

.chat-title-text-wrap h2{
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

/* 头部左侧：汉堡、标题同一行（h2 省略号依赖 flex 子项 min-width:0） */
#chatHeaderLeftBridgeMount,
.chat-header-left{
  display:flex;
  flex-direction:row;
  align-items:center;
  gap:8px;
  min-width:0;
  flex:1;
}

#chatHeaderLeftBridgeMount .mobile-menu-btn,
.chat-header-left .mobile-menu-btn{
  flex-shrink:0;
}

.chat-header > .agent-badge,
#chatHeaderLeftBridgeMount .agent-badge{
  flex:0 1 auto;
  min-width:0;
  max-width:min(320px,42vw);
}

.chat-header > .agent-badge #agentBadgeName,
#chatHeaderLeftBridgeMount #agentBadgeName{
  overflow:hidden;
  text-overflow:ellipsis;
  min-width:0;
}

.chat-title-actions{
  display:flex;
  align-items:center;
  gap:2px;
  flex-shrink:0;
  box-sizing:border-box;
  /* 计数角标向按钮右上方外扩；在标题裁切区内为它保留完整显示空间。 */
  padding-block:4px;
  padding-inline:0 6px;
}

.chat-title-actions .btn-icon{
  flex-shrink:0;
}

.chat-project-btn.is-active{
  color:var(--accent-color);
  background-color:var(--bg-tertiary);
}

/* 桌面端：工具栏作为一行 flex 行内元素 */
.chat-header-toolbar{
  display:flex;
  align-items:center;
  gap:4px;
  flex-shrink:0;
}

/* 弹性间隔（桌面端不占空间） */
.toolbar-spacer{
  display:none;
}

/* 兼容旧的 chat-header-actions 类名引用（JS 可能用到） */
.chat-header-actions{
  display:flex;
  flex-direction:row;
  align-items:center;
  gap:4px;
  flex-shrink:0;
  flex-wrap:nowrap;
}

.messages-container{
  flex:1;
  display:flex;
  flex-direction:column;
  min-height:0;
  overflow:hidden;
  padding:0;
  position:relative;
}

/* Markdown 资源加载中：避免先展示备用渲染再整页重绘 */
.messages-container.messages-md-pending .messages-content{
  visibility:hidden;
}

.messages-container.messages-md-pending .messages-scroll-pane::after{
  content:'';
  position:absolute;
  inset:0;
  pointer-events:none;
}

/* 对话右侧：用户消息快捷导航 */
.chat-quick-nav{
  position:absolute;
  top:0;
  right:0;
  bottom:0;
  width:48px;
  z-index:12;
  pointer-events:none;
}

.chat-quick-nav-inner{
  position:absolute;
  top:50%;
  right:4px;
  transform:translateY(-50%);
  display:flex;
  flex-direction:row-reverse;
  align-items:stretch;
  max-height:min(60vh, 420px);
  pointer-events:auto;
}

.chat-quick-nav-rail{
  flex-shrink:0;
  width:16px;
  min-height:48px;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:default;
  border-radius:0 8px 8px 0;
  transition:background 0.15s ease;
}

.chat-quick-nav:hover .chat-quick-nav-rail{
  background:transparent;
}

.chat-quick-nav-ticks{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:5px;
  width:100%;
  padding:8px 0;
  max-height:100%;
  overflow:hidden;
}

.chat-quick-nav-tick{
  display:block;
  width:6px;
  height:2px;
  border-radius:2px;
  background:var(--border-color);
  flex-shrink:0;
  transition:background 0.15s ease, width 0.15s ease, height 0.15s ease;
}

.chat-quick-nav-tick.is-active{
  width:8px;
  height:3px;
  background:var(--accent-color);
}

.chat-quick-nav-panel{
  display:none;
  flex:0 1 auto;
  min-width:200px;
  max-width:min(320px, calc(100vw - 120px));
  max-height:min(60vh, 420px);
  overflow-y:auto;
  overflow-x:hidden;
  padding:8px 28px 8px 10px;
  background:var(--bg-primary);
  border:1px solid var(--border-color);
  border-right:none;
  border-radius:12px 0 0 12px;
  box-shadow:var(--shadow);
  box-sizing:border-box;
}

.chat-quick-nav:hover .chat-quick-nav-panel,
.chat-quick-nav.is-open .chat-quick-nav-panel,
.chat-quick-nav-inner:hover .chat-quick-nav-panel{
  display:block;
}

.chat-quick-nav:hover .chat-quick-nav-ticks,
.chat-quick-nav.is-open .chat-quick-nav-ticks{
  visibility:hidden;
}

.chat-quick-nav-item{
  display:flex;
  align-items:center;
  gap:10px;
  width:100%;
  padding:7px 8px;
  border:none;
  border-radius:8px;
  background:transparent;
  color:var(--text-secondary);
  font-size: var(--type-size-control);
  line-height: var(--type-line-snug);
  text-align:left;
  cursor:pointer;
  transition:background 0.12s ease, color 0.12s ease;
}

.chat-quick-nav-item:hover{
  background:var(--bg-secondary);
}

.chat-quick-nav-item.is-active{
  color:var(--accent-color);
}

.chat-quick-nav-item-text{
  flex:1;
  min-width:0;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.chat-quick-nav-item-line{
  flex-shrink:0;
  width:18px;
  height:2px;
  border-radius:2px;
  background:var(--border-color);
  transition:background 0.12s ease, height 0.12s ease;
}

.chat-quick-nav-item.is-active .chat-quick-nav-item-line{
  height:3px;
  background:var(--accent-color);
}

/* 全局自定义 tooltip（替代浏览器原生 title） */
.app-tooltip{
  position:fixed;
  /* 必须高于 Vue 全屏预览、设置弹窗和全局 Toast。 */
  z-index:2147483000;
  max-width:min(420px, calc(100vw - 24px));
  padding:6px 14px;
  font-size: var(--type-size-control);
  font-weight: var(--font-weight-medium);
  line-height: var(--type-line-compact);
  color:#fff;
  background:#1a1a1a;
  border-radius:999px;
  box-shadow:0 4px 16px rgba(0,0,0,0.28);
  pointer-events:none;
  white-space:nowrap;
  word-break:break-word;
}

.app-tooltip.app-tooltip--wrap{
  white-space:pre-line;
  border-radius:10px;
  padding:8px 14px;
  line-height: var(--type-line-compact);
}

[data-theme="dark"] .app-tooltip{
  background:#2d2d2d;
  box-shadow:0 4px 18px rgba(0,0,0,0.45);
}

@media (max-width:900px){
  .chat-quick-nav{
    display:none !important;
  }
}

/* 滚动条贴在主对话栏最右侧（全宽滚动，内容在内层限宽居中） */
.messages-scroll-pane{
  flex:1;
  min-height:0;
  overflow-y:auto;
  overflow-x:hidden;
  overflow-anchor:none;
  width:100%;
  padding:0 var(--chat-side-gutter);
  box-sizing:border-box;
}

.messages-inner{
  width:100%;
  max-width:var(--chat-max-width);
  margin:0 auto;
  padding:var(--chat-inline-padding) 0;
  box-sizing:border-box;
}

.messages-content{
  display:flex;
  flex-direction:column;
  align-items:stretch;
  width:100%;
  max-width:100%;
  margin:0;
  min-height:0;
  overflow:visible;
  flex:0 0 auto;
  position:relative;
}

.welcome-message{
  text-align:center;
  padding:52px 24px;
  color:var(--text-secondary);
  flex-shrink:0;
  width:100%;
  max-width:760px;
  margin:0 auto;
  box-sizing:border-box;
}
.welcome-examples{
  display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;
  width:100%;max-width:680px;
  margin:10px auto 0;text-align:left;
}
.welcome-example-card{
  min-height:50px;
  display:flex;align-items:center;gap:10px;
  padding:9px 14px;
  border:1px solid var(--border-color);
  border-radius:var(--radius-lg);
  background:var(--chat-main-bg);
  color:var(--text-primary);
  font-size:var(--type-size-control);
  font-weight:var(--font-weight-regular);
  line-height:var(--type-line-control);
  cursor:pointer;
  transition:border-color 0.15s ease,box-shadow 0.15s ease,transform 0.15s ease;
}
.welcome-example-card:hover{
  border-color:var(--accent-color);
  box-shadow:var(--shadow-sm);
  transform:translateY(-1px);
}
.welcome-example-icon{
  width:24px;height:24px;
  display:inline-flex;align-items:center;justify-content:center;
  flex:0 0 24px;
  color:var(--accent-color);
}
.welcome-example-text{
  min-width:0;
  color:var(--text-secondary);
  font-size:var(--type-size-control);
  line-height:var(--type-line-control);
}

/* ── Bridge mount 布局层 ────────────────────────────────────
   使用 display:flex 而非 display:contents，规避部分浏览器
   display:contents 下点击命中树异常导致按钮失效的 bug。
──────────────────────────────────────────────────────── */

/* 头部主工具栏 mount：flex:1 撑满剩余宽度，内部按钮左对齐 */
#chatHeaderToolbarPrimaryBridgeMount {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

/* 头部右侧各 mount：仅收紧包裹各自子元素 */
#chatHeaderShareBridgeMount,
#chatHeaderAuthBridgeMount,
#helpTriggerBridgeMount {
  display: flex;
  align-items: center;
}

/* 侧栏底部 mount：竖向堆叠 footer-group 行 */
#sidebarFooterBridgeMount,
#sidebarAgentKbBridgeMount {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  flex-shrink: 0;
}

/* =========================
   Messages
========================= */
.message{
  width:100%;
  max-width:100%;
  margin:0 0 20px;
  display:flex;
  gap:10px;
  align-items:flex-start;
}

.message.user{
  flex-direction:row-reverse;
}

/* 助手：顶栏头像 + 名称，正文在下方整块区域 */
.message.assistant {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.message-assistant-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.message-assistant-name {
  font-size: var(--type-size-card-title);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  letter-spacing: 0.01em;
}
.message.assistant .message-content {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.message-assistant-reasoning-host {
  width: 100%;
  max-width: 100%;
  margin: 0 0 8px;
}
.message-assistant-reasoning-host:empty {
  display: none;
}

.message-avatar{
  width:36px;
  height:36px;
  border-radius:50%;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight: var(--font-weight-semibold);
  font-size: var(--type-size-caption);
  flex-shrink:0;
  background-color:var(--bg-secondary);
  color:var(--text-primary);
  border:1px solid var(--border-color);
}

.message.user .message-avatar,
.message.assistant .message-avatar{
  background-color:var(--bg-secondary);
  color:var(--text-primary);
}
.message-avatar.is-emoji{
  background:var(--bg-secondary) !important;
  border:1px solid var(--border-color) !important;
  font-size: var(--type-size-page-title);
  line-height: var(--type-line-none);
}
.message-avatar.is-emoji span{display:flex;align-items:center;justify-content:center;width:100%;height:100%;}

.message-content{
  flex:1;
  min-width:0;
  display:flex;
  flex-direction:column;
  align-items:flex-start;
}

.message.user .message-content{
  align-items:flex-end;
  text-align:right;
}

.message-bubble{
  padding:4px 0 6px;
  border-radius:0;
  word-wrap:break-word;
  overflow-wrap:break-word;
  font-family:var(--chat-content-font-family);
  font-size:var(--chat-content-font-size);
  line-height: var(--type-line-body);
  color:var(--text-primary);
  background:transparent;
  border:none;
  /* overflow:hidden 会创建滚动容器，使 KaTeX vlist 用 position:relative top:-Nem 定位的
     公式内容（分子、上标、根号横线等）落入负坐标区域而不可见。
     改为 overflow:visible。clip-path 已移除——它会对 KaTeX 元素产生与 overflow:hidden
     相同的裁剪效果，在 PC 端导致矩阵、积分上下限等被截断。
     border-radius 本身已保证圆角外观，无需 clip-path。 */
  overflow:visible;
  max-width:100%;
  word-break:break-word;
}

/* 确保所有子元素都不会溢出。
   注意：不在此处设置 overflow-x:auto，否则 CSS 规范会将 overflow-y 同时计算为 auto，
   导致 p/li 等块级元素竖向裁剪 KaTeX 上下标。
   横向滚动在下方针对 pre/table/katex-block-wrapper 单独设置。 */
.message-bubble * {
  max-width: 100%;
  overflow-wrap: break-word;
}

/* 特殊处理代码块，允许横向滚动 */
.message-bubble pre {
  overflow-x: auto;
  max-width: 100%;
}

.message-bubble pre code {
  white-space: pre;
  overflow-x: auto;
}

/* 确保列表不会溢出 */
.message-bubble ul,
.message-bubble ol {
  max-width: 100%;
  overflow-wrap: break-word;
}

/* 确保引用块不会溢出 */
.message-bubble blockquote {
  max-width: 100%;
  overflow-wrap: break-word;
}

/* 确保所有行内元素不会溢出 */
.message-bubble p,
.message-bubble span,
.message-bubble strong,
.message-bubble em {
  max-width: 100%;
  overflow-wrap: break-word;
}

/* 确保链接不会溢出 */
.message-bubble a {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: normal;
}

.message.user .message-bubble{
  text-align:left;
  width:fit-content;
  max-width:min(720px,92%);
  background:var(--bg-secondary);
  color:var(--text-primary);
  border:none;
  padding:var(--space-3) var(--space-4);
  /* 非对称圆角：靠用户一侧（右下）收小，形成「从用户发出」的方向感；极淡阴影令气泡轻微浮起 */
  border-radius:var(--radius-2xl);
  border-bottom-right-radius:var(--radius-sm);
  box-shadow:var(--shadow-sm);
}

.message-text-content{
  width:100%;
  min-width:0;
}

.user-message-text{
  position:relative;
}

.user-message-text:not(.is-expanded){
  max-height:var(--chat-user-message-collapsed-height);
  overflow:hidden;
}

.user-message-text.is-collapsed::after{
  content:"";
  position:absolute;
  right:0;
  bottom:0;
  left:0;
  height:72px;
  background:linear-gradient(to bottom, transparent, var(--bg-secondary) 88%);
  pointer-events:none;
}

.user-message-toggle{
  display:flex;
  width:100%;
  min-height:var(--touch-target-min);
  align-items:center;
  justify-content:center;
  gap:4px;
  margin:6px 0 -6px;
  padding:6px 10px;
  border:0;
  border-top:1px solid color-mix(in srgb, var(--border-color) 72%, transparent);
  border-radius:0 0 var(--radius-lg) var(--radius-lg);
  color:var(--text-secondary);
  background:transparent;
  font:inherit;
  font-size:var(--type-size-caption);
  font-weight:var(--font-weight-medium);
  line-height:var(--type-line-none);
  cursor:pointer;
  transition:color .16s ease, background-color .16s ease;
}

.user-message-toggle:hover{
  color:var(--text-primary);
  background:color-mix(in srgb, var(--text-primary) 5%, transparent);
}

.user-message-toggle:focus-visible{
  outline:2px solid var(--accent-color);
  outline-offset:2px;
}

.user-message-toggle iconify-icon{
  transition:transform .18s ease;
}

.user-message-toggle[aria-expanded="true"] iconify-icon{
  transform:rotate(180deg);
}

.message.assistant .message-bubble{
  width:100%;
  background:transparent;
  color:var(--text-primary);
  border:none;
  font-size:var(--chat-content-font-size);
  line-height: var(--type-line-relaxed);
}

.message.assistant .message-bubble p{
  line-height: var(--type-line-relaxed);
}

.message.assistant .message-bubble li{
  line-height: var(--type-line-relaxed);
}

/* 长篇正文收窄行长；代码、表格、图片和可视化仍可使用完整消息宽度。 */
.message.assistant .message-markdown__segment > :is(
  p, h1, h2, h3, h4, h5, h6, ul, ol, blockquote, hr
) {
  max-width: min(100%, var(--chat-reading-width, 780px));
}

.message-meta-row{
  display:flex;
  flex-direction:row;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  width:100%;
  margin-top:4px;
  flex-wrap:nowrap;
}

.message.assistant.is-generating .message-meta-row{
  display: none;
}

.message.user .message-meta-row{
  justify-content:flex-end;
}

.message-meta-row .message-time{
  flex:0 0 auto;
  margin:0;
  font-size: var(--type-size-caption);
  color:var(--text-muted);
}

.message-meta-row .message-stats{
  flex:0 0 auto;
  margin:0;
  font-size: var(--type-size-caption);
  color:var(--text-secondary);
  opacity:0.88;
  text-align:right;
  white-space:nowrap;
  user-select:none;
}

/* 模型等待 / 生成中 */
.message-loading{
  display:flex;
  align-items:center;
  padding:8px 0;
}
.message-loading iconify-icon,
.message-loading-icon{
  color:var(--text-muted);
  animation:icon-spin 0.9s linear infinite;
}

@keyframes icon-spin{
  from{transform:rotate(0deg);}
  to{transform:rotate(360deg);}
}

/* attachments in message */
.message-attachments{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  margin-top:10px;
}
.message-attachment-preview{
  display:block;
  flex:0 0 auto;
  padding:0;
  border:0;
  border-radius:var(--radius-lg);
  background:transparent;
  line-height:0;
  cursor:pointer;
}
.message-attachment-preview:focus-visible{
  outline:2px solid var(--accent-color);
  outline-offset:2px;
}
.message-attachments img{
  display:block;
  max-width:260px;
  max-height:260px;
  object-fit:cover;
  border-radius:8px;
  border:1px solid rgba(0,0,0,.08);
  transition: opacity 0.3s ease, transform 0.2s ease;
  cursor: pointer;
}
.message-attachments--uploads{
  max-width:calc(var(--chat-upload-thumbnail-size) * 4 + 30px);
  justify-content:flex-end;
}
.message-attachments--uploads .message-attachment-preview,
.message-attachments--uploads img{
  width:var(--chat-upload-thumbnail-size);
  height:var(--chat-upload-thumbnail-size);
}
.message-attachments--uploads img{
  max-width:none;
  max-height:none;
  object-position:center;
}
.message-attachments img:hover {
  opacity: 0.9;
  transform: scale(1.01);
}

.message-videos {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.message-video-card {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px;
  background: var(--bg-secondary);
}

.message-inline-video {
  width: 100%;
  max-width: 420px;
  max-height: 320px;
  display: block;
  border-radius: 8px;
  background: #000;
}

.message-video-open-btn {
  margin-top: 8px;
}

.message-bubble img.chat-clickable-image {
  width: auto;
  max-width: min(100%, 300px);
  max-height: 300px;
  display: block;
  clear: both;
  margin: 10px 0;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,.08);
  background: var(--bg-secondary);
  object-fit: contain;
  cursor: zoom-in;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.message-bubble img.chat-clickable-image:hover {
  transform: scale(1.01);
  opacity: 0.92;
}

.generation-progress-box {
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
}

.generation-progress-title {
  font-size: var(--type-size-body);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

.generation-progress-hint {
  margin-top: 3px;
  font-size: var(--type-size-caption);
  color: var(--text-secondary);
}

.generation-progress-elapsed {
  margin-top: 4px;
  font-size: var(--type-size-caption);
  color: var(--text-muted);
}

.generation-thinking-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: var(--type-size-control);
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}
.generation-thinking-text {
  line-height: var(--type-line-compact);
}
.generation-thinking-line .generation-thinking-spinner,
.generation-thinking-line iconify-icon.generation-thinking-spinner {
  flex-shrink: 0;
  color: var(--text-muted);
}
/* 生图 loader：四方块轮转，用品牌色更醒目 */
.generation-thinking-line .image-gen-loader {
  flex-shrink: 0;
  color: var(--accent-color);
  vertical-align: middle;
}

.assistant-error-bubble {
  color: var(--danger-color);
  padding: 6px 0;
  font-size: var(--type-size-body);
  line-height: var(--type-line-compact);
  white-space: pre-wrap;
  word-break: break-word;
}

.message-attachment-expired {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--text-secondary, #667085) 25%, transparent);
  border-radius: 8px;
  color: var(--text-secondary, #667085);
  background: color-mix(in srgb, var(--bg-secondary, #f5f7fa) 80%, transparent);
  font-size: var(--type-size-caption);
  line-height: var(--type-line-control);
}

.message-bubble.assistant-stopped-bubble {
  border-left: 3px solid var(--text-muted);
  opacity: 0.95;
}


/* 图片懒加载样式 */
.message-attachments img.lazy-load {
  opacity: 0.3;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading-shimmer 1.5s infinite;
}

.message-attachments img.lazy-loaded {
  opacity: 1;
  animation: fade-in 0.5s ease;
}

@keyframes loading-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes fade-in {
  from { opacity: 0.3; }
  to { opacity: 1; }
}

/* =========================
   Input Area
========================= */
.input-area{
  width: 100%;
  padding: 12px var(--chat-side-gutter);
  flex: 0 0 auto;
  min-height: var(--chat-bottom-dock-height);
  box-sizing: border-box;
  border-top: 1px solid var(--border-color);
  background-color: var(--chat-main-bg);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  position: relative;
  z-index: 25;
  flex-shrink: 0;
}

.input-compose-stack {
  width: 100%;
  max-width: var(--chat-max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.input-wrapper{
  width: 100%;
  max-width: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--chat-main-bg);
  padding: var(--space-3);
  border-radius: var(--radius-2xl);
  border: 1px solid color-mix(in srgb,var(--dialog-table-border) 92%,transparent);
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: visible;
}

.input-wrapper textarea{
  width: 100%;
  min-height: 44px;
  border: none !important;
  background: transparent !important;
  padding: 8px;
  font-family: var(--chat-content-font-family);
  font-size: var(--chat-content-font-size);
  font-weight: var(--font-weight-regular);
  line-height: var(--type-line-control);
  box-sizing: border-box;
  max-height: 50vh;
  overflow-y: hidden;
  resize: none;
}

.input-wrapper textarea:focus{
  width: 100%;
  border: none !important;          /* 彻底移除边框 */
  outline: none !important;         /* 彻底移除点击时的蓝色轮廓线 */
  background: transparent !important;
  padding: 8px;
  font-family: var(--chat-content-font-family);
  font-size: var(--chat-content-font-size);
  font-weight: var(--font-weight-regular);
  line-height: var(--type-line-control);
  max-height: 50vh;
  overflow-y: hidden;
  resize: none;
  box-shadow: none !important;      /* 移除某些浏览器默认的阴影 */
}

/* 当鼠标移入或点击内部时，外层容器变色（模拟输入框聚焦效果） */
.input-wrapper:focus-within {
  border-color: var(--accent-color);
  /* 聚焦时品牌色光晕环，明确反馈输入态 */
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-color) 16%, transparent);
}

.workflow-params-trigger {
  display: inline-flex;
  flex: 0 0 auto;
  min-height: 34px;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border: 1px solid color-mix(in srgb, var(--accent-color, #4263eb) 34%, var(--border-color));
  border-radius: 9px;
  color: var(--accent-color, #4263eb);
  background: color-mix(in srgb, var(--accent-color, #4263eb) 7%, var(--bg-primary));
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.workflow-params-trigger:hover,
.workflow-params-trigger.is-open {
  border-color: var(--accent-color, #4263eb);
  background: color-mix(in srgb, var(--accent-color, #4263eb) 13%, var(--bg-primary));
}

.workflow-params-trigger.is-open {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-color, #4263eb) 14%, transparent);
}

.workflow-params-trigger b {
  min-width: 30px;
  padding: 2px 5px;
  border-radius: 999px;
  color: var(--text-secondary);
  background: var(--bg-primary);
  font-size: var(--type-size-meta);
  line-height: var(--type-line-snug);
  text-align: center;
}

.workflow-params-overlay {
  position: fixed;
  z-index: var(--z-modal, 10000);
  inset: 0;
  display: flex;
  box-sizing: border-box;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(5px);
}

.workflow-params-dialog {
  width: min(680px, 100%);
  max-height: min(760px, calc(100dvh - 48px));
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  color: var(--text-primary);
  background: var(--bg-primary);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}

.workflow-params-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--border-color);
}

.workflow-params-eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--accent-color, #4263eb);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-bold);
}

.workflow-params-dialog-head h2 {
  margin: 0;
  font-size: var(--type-size-page-title);
  line-height: var(--type-line-snug);
}

.workflow-params-dialog-head p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.workflow-params-close {
  display: inline-flex;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 9px;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
}

.workflow-params-close:hover {
  color: var(--text-primary);
  background: var(--bg-secondary);
}

.workflow-params-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 22px 24px 24px;
}

.workflow-params-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 7px;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
}

.workflow-params-field.is-wide { grid-column: 1 / -1; }
.workflow-params-field > span:first-child em { margin-left: 3px; color: #dc2626; font-style: normal; }

.workflow-params-field input:not([type="checkbox"]),
.workflow-params-field select,
.workflow-params-field textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 40px;
  margin: 0;
  padding: 9px 11px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  outline: none;
  color: var(--text-primary);
  background: var(--bg-secondary);
  font: inherit;
  font-weight: var(--font-weight-regular);
  resize: vertical;
}

.workflow-params-field textarea { min-height: 96px; }
.workflow-params-field input:focus,
.workflow-params-field select:focus,
.workflow-params-field textarea:focus {
  border-color: var(--accent-color, #4263eb);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-color, #4263eb) 12%, transparent);
}

.workflow-params-switch {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  gap: 9px;
  box-sizing: border-box;
  padding: 8px 11px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  background: var(--bg-secondary);
  font-weight: var(--font-weight-medium);
}

.workflow-params-switch input { accent-color: var(--accent-color, #4263eb); }

.workflow-params-dialog-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  background: color-mix(in srgb, var(--bg-secondary) 72%, var(--bg-primary));
}

.workflow-params-dialog-foot > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.workflow-params-done {
  min-height: 36px;
  padding: 0 18px;
  border: none;
  border-radius: 9px;
  color: #fff;
  background: var(--accent-color, #4263eb);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
}

[data-theme="dark"] .input-wrapper{
  box-shadow:none;
  border-color:var(--border-color);
  background:var(--bg-secondary);
}

[data-theme="dark"] .input-wrapper:focus-within{
  border-color:var(--accent-color);
  box-shadow:0 0 0 3px color-mix(in srgb, var(--accent-color) 24%, transparent);
}

/* 模型选择栏（移至输入区底部） */
.model-bar{
  width:100%;
  max-width:var(--chat-max-width);
  margin:6px auto 0;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
}

.model-bar--tokens-only{
  justify-content:flex-end;
}

.model-bar-left{
  display:flex;
  align-items:center;
  gap:10px;
  flex:1;
  min-width:0;
}

.model-bar .model-selector{
  display:flex;
  align-items:center;
  gap:6px;
}

.model-bar .model-selector select{
  padding:4px 24px 4px 8px;
  font-size: var(--type-size-control);
  min-width:160px;
  max-width:100%;
}

.model-bar-right{
  display:flex;
  align-items:center;
  gap:8px;
  flex-shrink:0;
}

.model-bar .token-count{
  font-size: var(--type-size-caption);
  color:var(--text-muted);
  white-space:nowrap;
}

.model-indicator-text{
  font-size: var(--type-size-caption);
  color:var(--text-muted);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  max-width:220px;
  display:inline-flex;
  align-items:center;
  gap:2px;
}

.model-indicator-prefix{
  color:var(--text-secondary);
  flex-shrink:0;
}

/* =========================
   Buttons
========================= */
.btn-primary{
  padding:10px 20px;
  background-color:var(--accent-color);
  color:#fff;
  border:none;
  border-radius:var(--radius);
  cursor:pointer;
  font-size:var(--type-size-body);
  font-weight:var(--font-weight-medium);
  line-height:var(--type-line-control);
  transition:background-color 0.2s;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:6px;
}

.btn-primary:hover{background-color:var(--accent-hover);}
.btn-primary:disabled{opacity:0.5;cursor:not-allowed;}

.btn-secondary{
  padding:8px 12px;
  background-color:var(--bg-tertiary);
  color:var(--text-primary);
  border:1px solid var(--border-color);
  border-radius:var(--radius);
  cursor:pointer;
  font-size:var(--type-size-control);
  font-weight:var(--font-weight-regular);
  line-height:var(--type-line-control);
  transition:background-color 0.2s;
}

.btn-secondary:hover{background-color:var(--border-color);}

.btn-danger{
  padding:8px 16px;
  background-color:var(--danger-color);
  color:#fff;
  border:none;
  border-radius:var(--radius);
  cursor:pointer;
  font-size:var(--type-size-body);
  font-weight:var(--font-weight-medium);
  line-height:var(--type-line-control);
}

.btn-icon{
  padding:8px;
  background:none;
  border:none;
  color:var(--text-secondary);
  cursor:pointer;
  border-radius:var(--radius);
  display:flex;
  align-items:center;
  justify-content:center;
  transition:background-color 0.2s,color 0.2s;
}

.btn-icon:hover{
  background-color:var(--bg-tertiary);
  color:var(--text-primary);
}

#shareMessagesBtn.active{
  background-color: rgba(37,99,235,0.12);
  color: var(--accent-color);
}

/* =========================
   Modal & Overlay
========================= */
.modal{
  display:none;
  position:fixed;
  top:0;left:0;right:0;bottom:0;
  z-index:1000;
  align-items:center;
  justify-content:center;
  padding:20px;
}

.modal.active{display:flex;}

.modal-content{
  background-color:var(--bg-primary);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  width:100%;
  max-width:560px;
  max-height:90vh;
  display:flex;
  flex-direction:column;
}

.modal-small {
  max-width: 400px;
  width: 90%; /* 移动端适配 */
}

.modal-large{
  max-width: min(1100px, 96vw);
  width: 96vw;
  height: 88vh;
}

.modal-header{
  padding:16px 20px;
  border-bottom:1px solid var(--border-color);
  display:flex;
  align-items:center;
  justify-content:space-between;
}

.modal-header h3{
  font-size:var(--type-size-section-title);
  font-weight:var(--font-weight-semibold);
  line-height:var(--type-line-tight);
}

.modal-body{
  padding:20px;
  overflow-y:auto;
  flex:1;
}

.modal-footer{
  padding:16px 20px;
  border-top:1px solid var(--border-color);
  display:flex;
  justify-content:flex-end;
  gap:12px;
}

/* overlay: 修复输入框被遮罩挡住的问题 */
.overlay{
  display:none;
  position:fixed;
  top:0;left:0;right:0;bottom:0;
  background-color:rgba(0,0,0,0.5);
  z-index:999;
  pointer-events:none; /* 非active时不拦截事件 */
}

.overlay.active{
  display:block;
  pointer-events:auto; /* active 时才拦截 */
}

/* =========================
   Settings Tabs / Forms
========================= */
.settings-tabs{
  display:flex;
  gap:8px;
  margin-bottom:20px;
  border-bottom:1px solid var(--border-color);
  padding-bottom:12px;
}

.tab-btn{
  padding:8px 16px;
  background:none;
  border:none;
  color:var(--text-secondary);
  cursor:pointer;
  font-size:var(--type-size-body);
  font-weight:var(--font-weight-regular);
  line-height:var(--type-line-control);
  border-radius:var(--radius);
  transition:background-color 0.2s,color 0.2s;
}

.tab-btn:hover{background-color:var(--bg-tertiary);}
.tab-btn.active{background-color:var(--accent-color);color:#fff;}

.tab-content{display:none;}
.tab-content.active{display:block;}

/* 旧个人资料弹窗保留兼容尺寸；设置已迁移为独立页面 */
#profileModal .modal-content {
  width: min(560px, 96vw);
  max-width: min(560px, 96vw);
  max-height: 88vh;
}
#profileModal .modal-content {
  height: auto;
  min-height: 0;
}
#profileModal .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.form-group{margin-bottom:16px;}

.form-group label{
  display:block;
  margin-bottom:6px;
  font-weight: var(--font-weight-medium);
  font-size: var(--type-size-body);
}

/* Iconify 图标 */
iconify-icon{
  display:inline-block;
  vertical-align:middle;
  color:currentColor;
}

iconify-icon.message-action-svg{
  display:block;
}

.btn-icon-action{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:36px;
  padding:0 10px;
}

.btn-icon.modal-close,
.btn-icon-action,
.input-with-btn > .btn-icon{
  display:inline-flex;
  align-items:center;
  justify-content:center;
}

.btn-icon.modal-close iconify-icon,
.btn-icon-action iconify-icon,
.input-with-btn > .btn-icon iconify-icon{
  display:block;
}

/* 头像选择器 */
.avatar-picker{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:4px;
}
.avatar-option{
  width:40px;
  height:40px;
  border-radius:50%;
  border:2px solid var(--border-color);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: var(--type-size-subpage-title);
  cursor:pointer;
  transition:border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  background:var(--bg-secondary);
  user-select:none;
}
.avatar-option:hover{
  border-color:var(--accent-color);
  transform:scale(1.1);
}
.avatar-option.selected{
  border-color:var(--accent-color);
  box-shadow:0 0 0 3px rgba(37,99,235,0.2);
  transform:scale(1.08);
}

.auth-avatar-option iconify-icon,
.profile-summary-avatar iconify-icon,
.avatar-option iconify-icon,
.avatar-preview-emoji iconify-icon,
.auth-profile-avatar iconify-icon,
.agent-selector-item iconify-icon,
.message-avatar iconify-icon{
  display:block;
  flex-shrink:0;
}

/* 设置-通用：头像预览 + 弹窗选择 */
.avatar-settings-preview-group{
  margin-bottom:12px;
}

.avatar-preview-trigger{
  display:inline-flex;
  align-items:center;
  gap:12px;
  margin-top:4px;
  padding:8px 14px 8px 8px;
  border:1px solid var(--border-color);
  border-radius:var(--radius);
  background:var(--bg-secondary);
  color:var(--text-primary);
  cursor:pointer;
  transition:border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.avatar-preview-trigger:hover{
  border-color:var(--accent-color);
  box-shadow:0 0 0 2px rgba(37,99,235,0.12);
}

.avatar-preview-emoji{
  width:48px;
  height:48px;
  border-radius:50%;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: var(--type-size-display);
  background:var(--bg-primary);
  border:2px solid var(--border-color);
  flex-shrink:0;
}

.avatar-preview-label{
  font-size: var(--type-size-control);
  color:var(--text-secondary);
}

.avatar-picker-overlay{
  position:fixed;
  inset:0;
  z-index:1100;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:20px;
  background:rgba(0,0,0,0.45);
}

.avatar-picker-dialog{
  width:min(420px, 92vw);
  max-height:min(70vh, 520px);
  display:flex;
  flex-direction:column;
  background:var(--bg-primary);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  overflow:hidden;
}

.avatar-picker-dialog-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 16px;
  border-bottom:1px solid var(--border-color);
}

.avatar-picker-dialog-header h3{
  margin:0;
  font-size: var(--type-size-compact-title);
  font-weight: var(--font-weight-semibold);
}

.avatar-picker-dialog-body{
  padding:16px;
  overflow-y:auto;
}

.avatar-picker-dialog-grid .avatar-option{
  padding:0;
  font-family:inherit;
  line-height: var(--type-line-none);
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group textarea,
.form-group select{
  width:100%;
  padding:10px 12px;
  border:1px solid var(--border-color);
  border-radius:var(--radius);
  background-color:var(--bg-secondary);
  color:var(--text-primary);
  font-size:var(--type-size-body);
  font-family:inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus{
  outline:none;
  border-color:var(--accent-color);
}

.form-group small{
  display:block;
  margin-top:4px;
  color:var(--text-muted);
  font-size:var(--type-size-caption);
}

.form-group input[type="checkbox"]{margin-right:8px;}
.form-group input[type="range"]{width:100%;}

.input-with-btn{
  display:flex;
  gap:8px;
}
.input-with-btn input{flex:1;}

.btn-group{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.danger-zone{
  margin-top:24px;
  padding-top:16px;
  border-top:1px solid var(--danger-color);
}

/* WebDAV status */
.sync-status{
  margin-top:12px;
  padding:8px 12px;
  border-radius:var(--radius);
  font-size: var(--type-size-body);
}
.sync-status.success{
  background-color:rgba(22,163,74,0.1);
  color:var(--success-color);
}
.sync-status.error{
  background-color:rgba(220,38,38,0.1);
  color:var(--danger-color);
}

/* 存储用量卡片 */
/* 存储方式单选卡片 */
.storage-mode-cards{
  display:flex;
  flex-direction:column;
  gap:0;
}
.storage-mode-card{
  display:block;
  cursor:pointer;
  border:2px solid var(--border-color);
  border-radius:10px;
  padding:12px 14px;
  margin-bottom:8px;
  transition:border-color 0.2s, background 0.2s;
  user-select:none;
}
.storage-mode-card:hover{
  border-color:var(--accent-color);
  background:var(--bg-secondary);
}
.storage-mode-card:has(input:checked){
  border-color:var(--accent-color);
  background:rgba(37,99,235,0.06);
}
.storage-mode-card-header{
  display:flex;
  align-items:center;
  gap:8px;
}
.storage-mode-card-header input[type="radio"]{
  accent-color:var(--accent-color);
  width:16px;
  height:16px;
  flex-shrink:0;
}
.storage-mode-card-title{
  font-weight: var(--font-weight-semibold);
  font-size: var(--type-size-body);
  flex:1;
}
.storage-mode-badge{
  font-size: var(--type-size-caption);
  background:rgba(37,99,235,0.12);
  color:var(--accent-color);
  padding:2px 8px;
  border-radius:20px;
}
.storage-mode-card-desc{
  font-size: var(--type-size-caption);
  color:var(--text-muted);
  margin-top:4px;
  padding-left:24px;
}
/* 各存储方式的展开内容区 */
.storage-mode-section{
  border:1px solid var(--border-color);
  border-radius:10px;
  padding:14px 16px;
  margin-bottom:14px;
  transition:opacity 0.2s;
}
.storage-mode-disabled{
  opacity:0.45;
  pointer-events:none;
}
.storage-mode-disabled input,
.storage-mode-disabled button,
.storage-mode-disabled select{
  cursor:not-allowed;
}

/* 服务器存储 — 未登录提示 */
.server-login-required{
  padding:14px 16px;
  border-radius:10px;
  background:var(--bg-secondary);
  border:1px solid var(--border-color);
  font-size: var(--type-size-body);
  color:var(--text-muted);
  text-align:center;
}
.server-login-required a{
  color:var(--accent-color);
  text-decoration:none;
  font-weight: var(--font-weight-medium);
}
.server-login-required a:hover{
  text-decoration:underline;
}

/* 存储用量卡片（嵌套在 section 内） */
.storage-info-card{
  background:var(--bg-secondary);
  border:1px solid var(--border-color);
  border-radius:10px;
  padding:14px 16px;
  margin-bottom:16px;
}
.storage-info-row{
  display:flex;
  justify-content:space-between;
  align-items:baseline;
  margin-bottom:4px;
}
.storage-info-label{
  font-size: var(--type-size-caption);
  font-weight: var(--font-weight-semibold);
  color:var(--text-secondary);
  white-space:nowrap;
  margin-right:8px;
}
.storage-bar-wrap{
  background:var(--bg-tertiary);
  border-radius:6px;
  height:7px;
  overflow:hidden;
  margin-bottom:4px;
}
.storage-bar{
  height:100%;
  border-radius:6px;
  background:#3498db;
  transition:width 0.4s ease;
}
.storage-info-text{
  font-size: var(--type-size-control);
  color:var(--text-secondary);
}
.storage-info-hint{
  font-size: var(--type-size-caption);
  color:var(--text-muted);
  line-height: var(--type-line-control);
}

/* =========================
   首屏加载遮罩（主页 / 智能体页共用）
========================= */
.app-page-boot {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary, #fafafa);
  transition: opacity 0.28s ease, visibility 0.28s ease;
}
.app-page-boot.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.app-page-boot-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.app-page-boot-spinner-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}
.app-page-boot-spinner-slot iconify-icon,
.app-page-boot-spinner-icon {
  color: var(--text-secondary, #6b7280);
}
.app-page-boot-brand {
  font-size: var(--type-size-display);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.06em;
  color: var(--text-primary, #1f2937);
  animation: app-page-boot-brand-fade 2.2s ease-in-out infinite;
}
@keyframes app-page-boot-brand-fade {
  0%, 100% { opacity: 0.38; }
  50% { opacity: 1; }
}
/* 仅隐藏主页对话布局，勿影响 SPA 子页（智能体/知识库）内的 .app-container */
body.app-page-boot-active #app .app-container {
  visibility: hidden;
}

/* =========================
   Toast
========================= */
.toast-container{
  position:fixed;
  bottom:20px;
  right:20px;
  z-index:2000;
  display:flex;
  flex-direction:column;
  gap:8px;
}

body.global-site-footer-visible .toast-container,
body.global-site-footer-visible .app-floating-feedback {
  bottom: calc(var(--icp-footer-height, 36px) + 12px);
}

.toast{
  padding:12px 20px;
  background-color:var(--bg-tertiary);
  color:var(--text-primary);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  animation:slideIn 0.3s ease;
  border: 1px solid var(--border-color);
  opacity: 1 !important;
}

.toast.success{background-color:var(--success-color);color:#fff;}
.toast.error{background-color:var(--danger-color);color:#fff;}
.toast.info{background-color:var(--accent-color);color:#fff;}
.toast.loading,.toast.progress{background-color:var(--accent-color);color:#fff;}

/* 右下角反馈：统一结构，使用语义色区分成功、警告、错误与进度。 */
.toast.toast--chat-download{
  display:flex;
  max-width:min(92vw, 420px);
  align-items:center;
  gap:8px;
  padding:8px 13px;
  font-size: var(--type-size-caption);
  line-height: var(--type-line-compact);
  font-weight: var(--font-weight-medium);
  background:var(--bg-primary);
  color:var(--text-primary);
  border:1px solid var(--border-color);
  border-radius:10px;
  box-shadow:0 8px 28px rgba(15,23,42,0.14);
}
.toast.toast--chat-download.info,
.toast.toast--chat-download.progress,
.toast.toast--chat-download.loading{
  color:var(--primary-color);
  border-color:color-mix(in srgb, var(--primary-color) 30%, var(--border-color));
  background:color-mix(in srgb, var(--primary-color) 8%, var(--bg-primary));
}
.toast.toast--chat-download.success{
  color:var(--success-color);
  border-color:color-mix(in srgb, var(--success-color) 32%, var(--border-color));
  background:var(--app-success-soft, color-mix(in srgb, var(--success-color) 10%, var(--bg-primary)));
}
.toast.toast--chat-download.warning{
  color:var(--warning-color, #b45309);
  border-color:color-mix(in srgb, var(--warning-color, #b45309) 32%, var(--border-color));
  background:var(--app-warning-soft, #fff7ed);
}
.toast.toast--chat-download.error{
  color:var(--danger-color);
  border-color:color-mix(in srgb, var(--danger-color) 32%, var(--border-color));
  background:var(--app-danger-soft, color-mix(in srgb, var(--danger-color) 10%, var(--bg-primary)));
}
.toast.toast--chat-download.toast--with-progress{
  display:grid;
  grid-template-columns:auto minmax(0,1fr);
  align-items:stretch;
  gap:6px;
  min-width:min(92vw, 280px);
  border-radius:12px;
  padding:8px 14px 10px;
}
.toast.toast--chat-download .toast-message{
  min-width:0;
  color:var(--text-primary);
  line-height: var(--type-line-compact);
  overflow-wrap:anywhere;
}
.toast.toast--chat-download .toast-progress-track{
  grid-column:1 / -1;
  height:4px;
  border-radius:999px;
  background:rgba(0,0,0,0.1);
  overflow:hidden;
}
.toast.toast--chat-download .toast-progress-bar{
  height:100%;
  border-radius:999px;
  background:var(--accent-color, #3b82f6);
  transition:width 0.22s ease;
}

/* 工作区持久反馈：与全局 Toast 共用位置、间距和语义色。 */
.app-floating-feedback {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--z-toast, 20000);
  display: flex;
  max-width: min(92vw, 420px);
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  background: var(--bg-primary);
  box-shadow: 0 8px 28px rgba(15, 23, 42, .14);
  font-size: var(--type-size-caption);
  line-height: var(--type-line-compact);
}
.app-floating-feedback > span { min-width: 0; overflow-wrap: anywhere; }
.app-floating-feedback.is-info { color: var(--app-accent); border-color: var(--app-accent-border); background: var(--app-accent-soft); }
.app-floating-feedback.is-error { color: var(--app-danger); border-color: var(--app-danger-border); background: var(--app-danger-soft); }

/* 表单与管理工作区的内联反馈使用同一语义结构。 */
.app-inline-feedback {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 11px;
  border: 1px solid var(--app-accent-border);
  border-radius: var(--radius-md, 8px);
  color: var(--app-accent);
  background: var(--app-accent-soft);
  font-size: var(--type-size-caption);
  line-height: var(--type-line-control);
}
.app-inline-feedback > iconify-icon { flex: 0 0 auto; margin-top: 1px; }
.app-inline-feedback.success { color: var(--app-success); border-color: var(--app-success-border); background: var(--app-success-soft); }
.app-inline-feedback.error { color: var(--app-danger); border-color: var(--app-danger-border); background: var(--app-danger-soft); }
.app-inline-feedback.warning { color: var(--app-warning); border-color: var(--app-warning-border); background: var(--app-warning-soft); }

@media (max-width: 600px) {
  .app-floating-feedback {
    right: 12px;
    bottom: 12px;
    max-width: calc(100vw - 24px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .toast-progress-bar { transition: none; }
}

@keyframes slideIn{
  from{transform:translateX(100%);opacity:0;}
  to{transform:translateX(0);opacity:1;}
}

/* =========================
   Mobile menu button
========================= */
.mobile-menu-btn{
  display:none;
  flex-shrink:0;
  align-items:center;
  justify-content:center;
  width:36px;
  height:36px;
  padding:0;
  background:transparent;
  border:none;
  border-radius:var(--radius);
  color:var(--text-primary);
  cursor:pointer;
  transition:background 0.15s;
}
.mobile-menu-btn:hover{
  background:var(--bg-tertiary);
}

/* =========================
   Model selector
========================= */
.model-selector{
  display:flex;
  align-items:center;
  gap:8px;
}

.model-selector label{
  font-size: var(--type-size-body);
  color:var(--text-muted);
  white-space:nowrap;
}

.model-selector select{
  padding:6px 28px 6px 12px;
  font-size: var(--type-size-body);
  color:var(--text-primary);
  background-color:var(--bg-secondary);
  border:1px solid var(--border-color);
  border-radius:var(--radius);
  cursor:pointer;
  appearance:none;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat:no-repeat;
  background-position:right 8px center;
  min-width:140px;
  max-width:200px;
}

.model-selector select:hover{border-color:var(--accent-color);}
.model-selector select:focus{
  outline:none;
  border-color:var(--accent-color);
  box-shadow:0 0 0 2px rgba(37,99,235,0.2);
}

[data-theme="dark"] .model-selector select{
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

/* =========================
   Attachment bar (input)
========================= */
.attach-bar{
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-sizing: border-box;
}

.attach-bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.attach-bar-left,
.attach-bar-right{
  display:inline-flex;
  align-items:center;
  gap:10px;
}

.attach-bar-right{float:none;}

.attach-count{
  color:var(--text-secondary);
  font-size: var(--type-size-body);
}

.attach-clear-btn{font-size: var(--type-size-control);}

.attach-list{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  justify-content:flex-start;
  align-items:flex-start;
}

/* 附件卡片样式 - 类似腾讯元宝 */
.attach-card {
  position: relative;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
}

.attach-card:hover {
  border-color: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* 图片卡片 */
.attach-image-card {
  position: relative;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

/* 输入区附件按上传顺序：附件1、附件2… */
.attach-slot-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  font-size: var(--type-size-meta);
  line-height: var(--type-line-dense);
  text-align: center;
  color: #fff;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.2));
  padding: 2px 1px 3px;
  border-radius: 0 0 6px 6px;
  pointer-events: none;
  user-select: none;
}

.attach-image-card .attach-thumb {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  object-fit: cover;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* 文件卡片 */
.attach-file-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  min-width: 120px;
  max-width: 200px;
  flex-shrink: 0;
}

.attach-pdf-card {
  max-width: 420px;
  min-width: min(360px, 100%);
  flex-wrap: nowrap;
}

.attach-file-copy {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 3px;
}

.attach-pdf-meta,
.attach-parse-hint {
  color: var(--text-muted);
  font-size: var(--type-size-caption);
  line-height: var(--type-line-snug);
}

.attach-visual-error {
  color: var(--danger-color);
  font-size: var(--type-size-caption);
  line-height: var(--type-line-snug);
  overflow-wrap: anywhere;
}

.attach-visual-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid color-mix(in srgb, var(--accent-color) 38%, var(--border-color));
  border-radius: 8px;
  color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 7%, var(--bg-primary));
  font-size: var(--type-size-caption);
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
  cursor: pointer;
}

.attach-visual-stop {
  color: var(--danger-color);
  border-color: color-mix(in srgb, var(--danger-color) 38%, var(--border-color));
  background: color-mix(in srgb, var(--danger-color) 7%, var(--bg-primary));
}

.attach-visual-btn-ready {
  color: var(--success-color, #15803d);
  border-color: color-mix(in srgb, var(--success-color, #16a34a) 38%, var(--border-color));
  background: color-mix(in srgb, var(--success-color, #16a34a) 7%, var(--bg-primary));
}

.attach-visual-btn-partial {
  color: var(--warning-color, #b45309);
  border-color: color-mix(in srgb, var(--warning-color, #d97706) 38%, var(--border-color));
  background: color-mix(in srgb, var(--warning-color, #d97706) 7%, var(--bg-primary));
}

.attach-visual-overlay {
  position: fixed;
  inset: 0;
  z-index: 10020;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.46);
  backdrop-filter: blur(3px);
}

.attach-visual-dialog {
  width: min(760px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  background: var(--bg-primary);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
  color: var(--text-primary);
}

.attach-visual-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.attach-visual-dialog-head h3 {
  margin: 0 0 5px;
  font-size: var(--type-size-page-title);
}

.attach-visual-dialog-head p {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--type-size-control);
  overflow-wrap: anywhere;
}

.attach-visual-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
}

.attach-visual-notice {
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--accent-color) 22%, var(--border-color));
  border-radius: 10px;
  color: var(--text-secondary);
  background: color-mix(in srgb, var(--accent-color) 6%, var(--bg-secondary));
  font-size: var(--type-size-body);
  line-height: var(--type-line-control);
}

.attach-visual-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-secondary);
}

.attach-visual-progress > div {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.attach-visual-progress strong {
  font-size: var(--type-size-body);
}

.attach-visual-progress span {
  color: var(--text-muted);
  font-size: var(--type-size-caption);
}

.attach-visual-progress .attach-visual-current {
  color: var(--accent-color);
  font-weight: var(--font-weight-semibold);
}

.attach-visual-progress .attach-visual-failed-count {
  color: var(--danger-color);
}

.attach-visual-selection-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.attach-visual-selection-toolbar > span {
  margin-right: auto;
  color: var(--text-secondary);
  font-size: var(--type-size-body);
  font-weight: var(--font-weight-semibold);
}

.attach-visual-selection-toolbar button {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  color: var(--text-secondary);
  background: var(--bg-primary);
  font-size: var(--type-size-caption);
  cursor: pointer;
}

.attach-visual-selection-toolbar button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.attach-visual-select-all,
.attach-visual-page {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
}

.attach-visual-select-all {
  font-size: var(--type-size-body);
  font-weight: var(--font-weight-semibold);
}

.attach-visual-pages {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  overflow: auto;
  padding-right: 3px;
}

.attach-visual-page {
  position: relative;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-secondary);
}

.attach-visual-page.is-analyzing {
  border-color: color-mix(in srgb, var(--accent-color) 58%, var(--border-color));
  background: color-mix(in srgb, var(--accent-color) 8%, var(--bg-secondary));
}

.attach-visual-page.is-ready {
  border-color: color-mix(in srgb, var(--success-color, #16a34a) 34%, var(--border-color));
}

.attach-visual-page.is-failed {
  border-color: color-mix(in srgb, var(--danger-color) 38%, var(--border-color));
}

.attach-visual-page-copy {
  display: grid;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.attach-visual-page-copy strong {
  font-size: var(--type-size-body);
}

.attach-visual-page-copy small {
  color: var(--text-muted);
  font-size: var(--type-size-caption);
  line-height: var(--type-line-snug);
  overflow-wrap: anywhere;
}

.attach-visual-page-copy .attach-visual-page-error {
  color: var(--danger-color);
}

.attach-visual-page em {
  flex: 0 0 auto;
  padding: 3px 6px;
  border-radius: 999px;
  color: var(--text-muted);
  background: var(--bg-primary);
  font-size: var(--type-size-caption);
  font-style: normal;
  white-space: nowrap;
}

.attach-visual-page.is-analyzing em {
  color: var(--accent-color);
}

.attach-visual-page.is-ready em {
  color: var(--success-color, #15803d);
}

.attach-visual-page.is-failed em {
  color: var(--danger-color);
}

.attach-visual-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.attach-visual-dialog-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding-inline: 16px;
  white-space: nowrap;
  cursor: pointer;
}

@media (max-width: 640px) {
  .attach-pdf-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .attach-visual-btn {
    padding-inline: 8px;
  }

  .attach-visual-overlay {
    align-items: end;
    padding: 0;
  }

  .attach-visual-dialog {
    width: 100%;
    max-height: 86vh;
    padding: 18px 16px;
    border-radius: 18px 18px 0 0;
  }

  .attach-visual-pages {
    grid-template-columns: 1fr;
  }

  .attach-visual-progress {
    align-items: flex-start;
    flex-direction: column;
  }

  .attach-visual-dialog-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

.attach-file-card .attach-icon-placeholder {
  width: 36px;
  height: 36px;
  min-width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  border-radius: 6px;
  font-size: var(--type-size-page-title);
}

.attach-file-name {
  font-size: var(--type-size-body);
  color: var(--text-primary);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.attach-file-slot {
  font-weight: var(--font-weight-semibold);
  color: var(--accent-color);
}

/* 卡片删除按钮 */
.attach-card-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--danger-color);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 10;
}

.attach-card:hover .attach-card-remove {
  opacity: 1;
}

.attach-card-remove:hover {
  transform: scale(1.1);
  background: #b91c1c;
}

.attach-card-remove svg {
  width: 12px;
  height: 12px;
}

.attach-item {
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 6px;
  gap: 10px;
  height: 44px; /* 固定高度确保整齐 */
  min-width: 0;
}

.attach-thumb {
  width: 32px !important;
  height: 32px !important;
  min-width: 32px; /* 防止压缩 */
  border-radius: 4px;
  border: 1px solid var(--border-color);
  object-fit: cover;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  flex-shrink: 0;
}

.attach-icon-placeholder {
  width: 32px !important;
  height: 32px !important;
  min-width: 32px; /* 防止压缩 */
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: 4px;
  font-size: var(--type-size-section-title);
  flex-shrink: 0;
}

.attach-item-clickable {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.attach-item-name {
  font-size: var(--type-size-body);
  color: var(--text-primary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: var(--type-line-dense);
}

.attach-item-remove {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.attach-item-remove:hover {
  color: var(--danger-color);
  background: rgba(220,38,38,0.08);
}

/* =========================
   Image Preview Modal
========================= */
.image-preview-modal {
  max-width: min(900px, 96vw);
  width: 96vw;
  height: 90vh;
  max-height: 90vh;
}

.image-preview-header {
  flex-shrink: 0;
  gap: 8px;
}

.image-preview-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  font-size: var(--type-size-card-title) !important;
}

.image-zoom-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.zoom-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.zoom-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.zoom-level-label {
  font-size: var(--type-size-caption);
  color: var(--text-muted);
  min-width: 38px;
  text-align: center;
  user-select: none;
}

/* 图片预览区域 */
.image-preview-body {
  padding: 0 !important;
  overflow: hidden !important;
  flex: 1;
  position: relative;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}

.image-preview-body.dragging {
  cursor: grabbing;
}

/* 图片容器（用于 transform） */
.image-preview-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: center center;
  transform: translate(-50%, -50%) scale(1);
  transition: transform 0.1s ease;
  will-change: transform;
  line-height: 0;
}

.image-preview-container.no-transition {
  transition: none;
}

.attach-preview-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.attach-preview-video {
  width: min(100%, 900px);
  max-height: calc(90vh - 180px);
  border-radius: 6px;
  background: #000;
}

/* 文本预览（非图片）时恢复正常滚动 */
.image-preview-body.text-mode {
  overflow-y: auto !important;
  cursor: default;
  padding: 20px !important;
}

.attach-preview-text {
  width: 100%;
  white-space: pre-wrap;
  font-family: var(--type-family-code);
  font-size: var(--type-size-control);
  line-height: var(--type-line-control);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
}

/* 底部状态栏 */
.image-preview-footer {
  flex-shrink: 0;
  padding: 10px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.image-preview-hint {
  font-size: var(--type-size-caption);
  color: var(--text-muted);
}

.btn-sm {
  padding: 6px 14px;
  font-size: var(--type-size-body);
}

/* 移动端适配 */
@media (max-width: 600px) {
  .image-preview-modal {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    margin: 0;
  }

  .modal:has(.image-preview-modal) {
    padding: 0;
  }

  #attachPreviewModal {
    padding: 0;
  }

  .image-preview-title {
    max-width: 100px;
  }

  .zoom-level-label {
    display: none;
  }

  .image-preview-hint {
    display: none;
  }
}

/* 附件项布局微调 */
.attach-item-clickable {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    cursor: pointer;
}

.attach-item-clickable:hover .attach-item-name {
    text-decoration: underline;
    color: var(--primary-color);
}


/* =========================
   Message actions / edit
========================= */
.message-actions{
  display:flex;
  gap:6px;
  margin-top:8px;
  opacity:0;
  transition:opacity 0.2s;
  flex-wrap:wrap;
}

.message.user .message-actions{
  justify-content:flex-end;
}

.message:hover .message-actions,
.message:focus-within .message-actions{opacity:1;}

.message-actions button{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:32px;
  height:32px;
  padding:0;
  font-size:0;
  color:var(--text-muted);
  background:transparent;
  border:1px solid transparent;
  border-radius:8px;
  cursor:pointer;
  transition:color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.message-actions button .message-action-svg{
  display:block;
  flex-shrink:0;
  pointer-events:none;
}

.message-actions button:hover{
  color:var(--text-primary);
  background:var(--bg-secondary);
  border-color:var(--border-color);
}

.message-actions button.danger:hover{
  color:var(--danger-color);
  border-color:color-mix(in srgb, var(--danger-color) 35%, transparent);
  background:rgba(220,38,38,0.08);
}

.message-actions button.action-feedback--copied{
  color:var(--success-color,#16a34a);
  border-color:color-mix(in srgb,var(--success-color,#16a34a) 35%,transparent);
  background:color-mix(in srgb,var(--success-color,#16a34a) 10%,var(--bg-secondary));
}

.message-actions button.action-feedback--copied .message-action-svg{
  color:var(--success-color,#16a34a);
}

.copy-feedback--success{
  color:var(--success-color,#16a34a) !important;
  border-color:color-mix(in srgb,var(--success-color,#16a34a) 40%,var(--border-color)) !important;
  background:color-mix(in srgb,var(--success-color,#16a34a) 10%,var(--bg-secondary)) !important;
}

.copy-feedback--success iconify-icon,
.copy-feedback--success svg{
  flex:0 0 auto;
  color:currentColor;
}

.copy-feedback-label{
  white-space:nowrap;
}

.btn--action-saved{
  background:color-mix(in srgb,var(--success-color,#16a34a) 14%,var(--bg-secondary)) !important;
  border-color:color-mix(in srgb,var(--success-color,#16a34a) 40%,var(--border-color)) !important;
  color:var(--success-color,#16a34a) !important;
}

.message-actions button.regenerate:hover{
  color:var(--accent-color);
  border-color:color-mix(in srgb, var(--accent-color) 35%, transparent);
  background:color-mix(in srgb, var(--accent-color) 8%, transparent);
}

.message-edit-area{
  width:100%;
  margin-top:8px;
}

.message-edit-area textarea{
  width:100%;
  min-height:80px;
  padding:10px 12px;
  font-size:inherit;
  font-family:inherit;
  line-height: var(--type-line-body);
  color:var(--text-primary);
  background:var(--bg-primary);
  border:1px solid var(--accent-color);
  border-radius:var(--radius);
  resize:vertical;
}

.message-edit-area textarea:focus{
  outline:none;
  box-shadow:0 0 0 2px rgba(37,99,235,0.2);
}

.message-edit-buttons{
  display:flex;
  gap:8px;
  margin-top:8px;
}

.message-edit-buttons button{
  padding:6px 14px;
  font-size: var(--type-size-control);
  border-radius:4px;
  cursor:pointer;
  transition:all 0.2s;
}

.message-edit-buttons .save-btn{
  color:#fff;
  background:var(--accent-color);
  border:none;
}

.message-edit-buttons .save-btn:hover{background:var(--accent-hover);}

.message-edit-buttons .cancel-btn{
  color:var(--text-primary);
  background:var(--bg-tertiary);
  border:1px solid var(--border-color);
}

.message-edit-buttons .cancel-btn:hover{background:var(--border-color);}

/* =========================
   Code copy / 可折叠代码块（浅灰底与引用块一致）
========================= */
.code-block-wrapper{position:relative;}

.code-copy-btn{
  position:static;
  flex-shrink:0;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:5px;
  background-color:var(--chat-main-bg);
  border:1px solid var(--border-color);
  border-radius:var(--radius-sm);
  color:var(--text-secondary);
  cursor:pointer;
  opacity:0.88;
  transition:opacity 0.2s,background 0.2s,color 0.2s,border-color 0.2s;
}

.code-block-wrapper:hover .code-copy-btn{opacity:1;}
.code-copy-btn:hover{background-color:var(--bg-secondary);color:var(--accent-color);border-color:var(--accent-color);}
.code-copy-btn--done{color:var(--success-color);border-color:var(--success-color);opacity:1;}

.streaming .code-copy-btn{display:none;}
.code-copy-placeholder {
  width: 27px;
  height: 27px;
  flex: 0 0 27px;
}

/* =========================
   Markdown render
========================= */

/* Markdown高亮样式 */
.message-bubble mark {
  background-color: #fef08a;
  color: #000;
  padding: 2px 4px;
  border-radius: 2px;
}

[data-theme="dark"] .message-bubble mark {
  background-color: #854d0e;
  color: #fef08a;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4,
.message-bubble h5,
.message-bubble h6{
  margin:16px 0 8px 0;
  font-weight: var(--font-weight-semibold);
  line-height: var(--type-line-compact);
}

.message-bubble h1{font-size:1.35em;}
.message-bubble h2{font-size:1.22em;}
.message-bubble h3{font-size:1.1em;}
.message-bubble h4{font-size:1.05em;}
.message-bubble h5,
.message-bubble h6{font-size:1em;}

.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child{margin-top:0;}

.message-bubble p{
  margin:0 0 12px 0;
  line-height: var(--type-line-body);
}
.message-bubble p:last-child{margin-bottom:0;}

.message-bubble ul,
.message-bubble ol{
  margin:10px 0;
  padding-left:1.5em;
  list-style-position:outside;
}

.message-bubble li{
  margin:6px 0;
  line-height: var(--type-line-body);
}

.message-bubble li > ul,
.message-bubble li > ol{margin:4px 0;}

.message-bubble ul{list-style-type:disc;}
.message-bubble ol{list-style-type:decimal;}
.message-bubble ul ul,
.message-bubble ol ul{list-style-type:circle;}
.message-bubble ul ul ul,
.message-bubble ol ul ul{list-style-type:square;}

.message-bubble li.task-list-item{
  margin-left:-1.4em;
  padding-left:0;
  list-style:none;
}

.message-bubble li.task-list-item input[type="checkbox"]{
  margin-right:.4em;
  vertical-align:middle;
  cursor:default;
}

.message-bubble blockquote{
  margin:14px 0;
  padding:10px 16px;
  border-left:3px solid color-mix(in srgb,var(--accent-color) 75%,var(--border-color));
  background-color:rgba(0,0,0,0.025);
  border-radius:0 10px 10px 0;
}
[data-theme="dark"] .message-bubble blockquote{
  background-color:rgba(255,255,255,0.04);
}
.message-bubble blockquote p{margin:0;}

.message-bubble hr{
  margin:16px 0;
  border:none;
  border-top:1px solid var(--border-color);
}

.message-bubble a{
  color:var(--accent-color);
  text-decoration:none;
}
.message-bubble a:hover{text-decoration:underline;}

.message-bubble code{
  font-family: var(--type-family-code);
  font-size:0.875em;
  padding:2px 7px;
  background-color:#eef1f6;
  border-radius:6px;
  border:1px solid color-mix(in srgb,var(--dialog-table-border) 70%,transparent);
}
[data-theme="dark"] .message-bubble code{
  background-color:rgba(255,255,255,0.08);
  border-color:rgba(255,255,255,0.12);
}

.message-bubble pre{
  margin:12px 0;
  padding:0;
  background:none;
  overflow:visible;
}

/* 无 code-block-wrapper 包裹的 pre（少见）；勿作用于 .code-block-body 内，避免双层边框 */
.message-bubble pre:not(.code-block-body pre) > code{
  display:block;
  padding:12px 14px;
  background-color:rgba(0,0,0,0.025);
  color:var(--text-primary);
  border-radius:10px;
  border:1px solid color-mix(in srgb,var(--border-color) 55%,transparent);
  overflow-x:auto;
  line-height: var(--type-line-control);
  font-size: var(--type-size-card-title);
}
[data-theme="dark"] .message-bubble pre:not(.code-block-body pre) > code{
  background-color:rgba(255,255,255,0.04);
}

/* 历史消息：markdown-it 曾把自定义代码块再包一层 pre>code，去掉外层框与背景 */
.message-bubble pre:has(> code > .code-block-wrapper),
.message-bubble pre:has(> code > .mermaid-wrapper){
  margin:0;
  padding:0;
  background:none !important;
  border:none;
  overflow:visible;
}
.message-bubble pre:has(> code > .code-block-wrapper) > code,
.message-bubble pre:has(> code > .mermaid-wrapper) > code{
  display:contents;
  padding:0;
  border:none !important;
  background:transparent !important;
  border-radius:0;
  font-size:inherit;
}

.message-bubble .code-block-wrapper{
  box-sizing:border-box;
  width:100%;
  min-width:0;
  margin:14px 0;
  border-radius:var(--radius-lg);
  border:1px solid var(--dialog-table-border);
  background-color:var(--dialog-code-frame-bg);
  overflow:hidden;
}

.message-bubble .code-block-header{
  display:flex;
  flex-direction:row;
  align-items:center;
  gap:8px;
  padding:8px 12px;
  cursor:pointer;
  user-select:none;
  font-size: var(--type-size-control);
  font-weight: var(--font-weight-medium);
  color:var(--text-secondary);
  background:var(--dialog-code-header-bg);
  border-bottom:1px solid var(--dialog-table-border);
}

.message-bubble .code-block-chevron{
  flex-shrink:0;
  width:1em;
  text-align:center;
  font-size: var(--type-size-meta);
  line-height: var(--type-line-none);
  color:var(--text-muted);
  transform:rotate(0deg);
  transform-origin:center;
  transition:transform 160ms ease;
}

.message-bubble .code-block-collapsed .code-block-chevron{
  transform:rotate(-90deg);
}

.message-bubble .code-block-lang{
  flex-shrink:0;
  font-family: var(--type-family-code);
}

.message-bubble .code-block-header-fill{
  flex:1;
  min-width:0;
}

.message-bubble .code-block-body{
  display:grid;
  grid-template-rows:minmax(0,1fr);
  overflow:hidden;
  opacity:1;
  transition:grid-template-rows 180ms ease,opacity 120ms ease;
}

.message-bubble .code-block-collapsed .code-block-body{
  grid-template-rows:0fr;
  opacity:0;
}

.message-bubble .code-block-collapsed .code-block-header{
  border-bottom-color:transparent;
}

.message-bubble .code-block-body pre{
  min-height:0;
  margin:0;
  padding:0;
  background:transparent;
  border:none;
  overflow-x:auto;
  max-width:100%;
}

.message-bubble .code-block-wrapper .code-block-body code{
  border:none;
  background:transparent !important;
  border-radius:0;
  box-shadow:none;
}

.message-bubble .code-block-body pre code{
  display:block;
  padding:10px 14px 12px;
  background:transparent !important;
  color:var(--text-primary);
  font-size: var(--type-size-control);
  line-height: var(--type-line-control);
  border-radius:0;
  /* 横向滚动只交给外层 pre，避免流式生成时滚动条随代码底部下移。 */
  overflow-x:visible;
}

.message-bubble .code-block-body .hljs,
.message-bubble .code-block-body pre.hljs{
  background:transparent !important;
  padding:0;
  border:none;
}

.message-bubble table{
  display:table;
  width:max-content;
  max-width:100%;
  margin:0;
  border-collapse:collapse;
  font-size:0.9em;
  box-shadow:0 0 0 1px var(--dialog-table-border);
  border-radius:10px;
  overflow:hidden;
}

.message-bubble th,
.message-bubble td{
  padding:10px 14px;
  border:1px solid var(--dialog-table-border);
  text-align:left;
  vertical-align:top;
}

.message-bubble th{
  background-color:var(--dialog-table-header-bg);
  font-weight: var(--font-weight-semibold);
  color:var(--text-primary);
}

.message-bubble tbody tr:nth-child(even) td{background-color:rgba(0,0,0,0.02);}
[data-theme="dark"] .message-bubble tbody tr:nth-child(even) td{background-color:rgba(255,255,255,0.03);}

.message-bubble strong{font-weight: var(--font-weight-bold);color:inherit;}
.message-bubble em{font-style:italic;}
.message-bubble del{text-decoration:line-through;opacity:0.7;}

/* user bubble tweaks：无蓝底后，行内码与链接恢复为正文可读配色 */
.message.user .message-bubble code{
  background-color:rgba(0,0,0,0.06);
  border-color:transparent;
}
[data-theme="dark"] .message.user .message-bubble code{
  background-color:rgba(255,255,255,0.1);
  border-color:transparent;
}
.message.user .message-bubble a{
  color:var(--accent-color);
  text-decoration:underline;
}

/* =========================
   Scrollbar
========================= */
::-webkit-scrollbar{width:6px;height:6px;}
::-webkit-scrollbar-track{background:transparent;}
::-webkit-scrollbar-thumb{background-color:var(--border-color);border-radius:3px;}
::-webkit-scrollbar-thumb:hover{background-color:var(--text-muted);}

/* =========================
   Responsive
========================= */
@media (max-width:768px){
  .site-footer {
    left: 0;
  }
  .sidebar{
    position:fixed;
    top:0;left:0;
    bottom:var(--icp-footer-height, 36px);
    z-index:200;
    transform:translateX(-100%);
    transition:transform 0.3s ease;
  }
  .sidebar.open{transform:translateX(0);}

  .sidebar-collapse-btn,
  .sidebar-collapsed-launcher{display:none;}

  .mobile-menu-btn{display:flex;}

  .messages-container{padding:0;}

  .welcome-message{padding:40px 16px;}

  .message{gap:8px;}
  .message-avatar{width:32px;height:32px;font-size: var(--type-size-caption);}

  .input-area{padding:12px var(--chat-side-gutter);}
  
  /* 优化移动端输入区域 */
  .input-wrapper{
    padding:8px;
    border-radius:12px;
    margin-bottom:8px;
  }
  
  .input-wrapper textarea{
    font-size: var(--type-size-compact-title); /* 防止iOS缩放 */
    padding:12px;
    min-height:44px; /* 符合触摸最小尺寸 */
  }
  
  .input-toolbar{
    padding:8px 0 0;
    gap:12px;
  }
  
  .toolbar-left .input-toolbar-icon-btn{
    width:44px !important;
    height:44px !important;
    min-width:44px !important;
  }
  
  #sendBtn.send-btn{
    min-width:44px;
    width:44px;
    height:44px;
    padding:0;
  }

  .modal-content{
    max-height:100vh;
    border-radius:0;
  }

  .settings-tabs{flex-wrap:wrap;}
  .tab-btn{padding:6px 12px;font-size: var(--type-size-control);}

  /* 移动端始终显示操作按钮 */
  .message-actions{opacity:1;}

  /* 移动端 header：默认单行；仅在存在智能体徽章时启用第二行。 */
  .chat-header{
    height:auto !important;
    display:grid;
    grid-template-columns:1fr auto;
    grid-template-areas:"left toolbar";
    align-items:center;
    padding:8px 12px;
    gap:4px 8px;
  }
  .chat-header:has(> .agent-badge){
    grid-template-areas:
      "left left"
      "agent toolbar";
  }
  .chat-header-left{
    grid-area:left;
    width:100%;
    flex-shrink:0;
    min-width:0;
    display:flex;
    align-items:center;
    gap:8px;
  }
  .chat-header-left h2{
    font-size: var(--type-size-compact-title);
  }
  .chat-title-text-wrap h2{
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
  #chatHeaderLeftBridgeMount,
  .chat-header-left{
    display:flex;
    flex-direction:row;
    align-items:center;
    gap:8px;
    min-width:0;
    width:100%;
  }
  #chatHeaderLeftBridgeMount .mobile-menu-btn,
  .chat-header-left .mobile-menu-btn,
  #chatHeaderLeftBridgeMount .chat-title-actions{
    flex-shrink:0;
  }
  .chat-header > .agent-badge{
    grid-area:agent;
    justify-self:start;
    flex:0 1 auto;
    min-width:0;
    max-width:min(260px,48vw);
  }
  #chatHeaderLeftBridgeMount .agent-badge{
    flex:0 1 auto;
    min-width:0;
    max-width:min(260px,48vw);
  }
  .chat-header-toolbar{
    grid-area:toolbar;
    width:auto;
    flex-shrink:0;
    justify-content:flex-end;
    justify-self:end;
  }
  #chatHeaderShareBridgeMount{
    margin-left:auto;
  }
  .toolbar-spacer{
    display:none;
    flex:0;
  }

  /* 移动端模型栏：左右各占 50%，防重叠 */
  .model-bar{gap:4px;}
  .model-bar-left{
    flex:1;
    min-width:0;
    overflow:hidden;
  }
  .model-bar-right{
    flex:0 0 auto;
    min-width:auto;
    overflow:visible;
    justify-content:flex-end;
  }
  .model-bar .model-selector{
    min-width:0;
    overflow:hidden;
  }
  .model-bar .model-selector label{
    display:inline;
    font-size: var(--type-size-caption);
    flex-shrink:0;
  }
  .model-bar .model-selector select{
    min-width:0;
    width:auto;
    max-width:none;
    font-size: var(--type-size-caption);
    flex:0 1 auto;
  }
  .model-indicator-text{
    max-width:100%;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
  }
}

@media (max-width:520px){
  .history-bar{
    grid-template-columns:1fr;
    align-items:start;
  }
  .history-tip{margin-top:2px;}
}


.compress-enable{
  display:inline-flex;
  align-items:center;
  gap:8px;
  color:var(--text-primary);
  font-size: var(--type-size-body);
  white-space:nowrap;
}

.compress-input{
  display:inline-flex;
  align-items:center;
  gap:6px;
  white-space:nowrap;
}

.compress-input input{
  width:120px;
  padding:6px 8px;
  border-radius:10px;
  border:1px solid var(--border-color);
  background:var(--bg-primary);
  color:var(--text-primary);
}

.compress-input input:disabled{ opacity:0.6; }

.compress-prefix,
.compress-suffix{
  color:var(--text-secondary);
  font-size: var(--type-size-body);
}

.compress-tip{
  color:var(--text-muted);
  font-size: var(--type-size-control);
  line-height: var(--type-line-snug);
}

@media (max-width:520px){
  .compress-bar{
    grid-template-columns:1fr;
    align-items:start;
  }
  .compress-tip{ margin-top:2px; }
}
.compress-sep{
  color: var(--text-muted);
  margin: 0 6px;
}
/* 会话标题与背景材料：统一入口图标和编辑弹窗 */
.chat-title-actions .chat-title-action {
  position: relative;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--app-text-muted);
  background: transparent;
}

.chat-title-actions .chat-title-action:hover,
.chat-title-actions .chat-title-action:focus-visible {
  outline: none;
  border-color: var(--app-accent-border);
  color: var(--app-accent);
  background: var(--app-accent-soft);
}

.chat-title-actions .chat-title-action:focus-visible {
  box-shadow: 0 0 0 3px var(--app-focus-ring);
}

.chat-title-actions .chat-title-action.is-active {
  border-color: var(--app-accent-border);
  color: var(--app-accent);
  background: var(--app-accent-soft);
}

.chat-title-action__status {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 6px;
  height: 6px;
  border: 1.5px solid var(--app-surface);
  border-radius: 50%;
  background: var(--app-accent);
}

.chat-title-action__status--count {
  top: -4px;
  right: -5px;
  display: grid;
  width: auto;
  min-width: 15px;
  height: 15px;
  place-items: center;
  padding: 0 3px;
  border-width: 1px;
  border-radius: 999px;
  color: #fff;
  font-size: var(--type-size-meta);
  font-weight: var(--font-weight-bold);
  line-height: var(--type-line-none);
}

.modal .chat-editor-dialog {
  width: min(680px, calc(100vw - 32px));
  max-width: none;
  max-height: min(88dvh, 760px);
  overflow: hidden;
  border: 1px solid var(--app-border);
  border-radius: 18px;
  color: var(--app-text-secondary);
  background: var(--app-surface);
  box-shadow: 0 24px 72px rgba(15, 23, 42, .22);
}

.modal .chat-editor-dialog--compact {
  width: min(460px, calc(100vw - 32px));
}

.chat-editor-dialog__header {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--app-border);
}

.chat-editor-dialog__heading {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  gap: 12px;
}

.chat-editor-dialog__icon,
.chat-editor-option__icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  color: var(--app-accent);
  background: var(--app-accent-soft);
}

.chat-editor-dialog__icon {
  width: 38px;
  height: 38px;
  border: 1px solid var(--app-accent-border);
  border-radius: 11px;
}

.chat-editor-dialog__kicker {
  display: block;
  margin-bottom: 2px;
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
  font-weight: var(--font-weight-bold);
  letter-spacing: .08em;
}

.chat-editor-dialog__heading h2,
.chat-editor-dialog__heading p {
  margin: 0;
}

.chat-editor-dialog__heading h2 {
  color: var(--app-text);
  font-size: var(--text-lg);
  line-height: var(--type-line-tight);
}

.chat-editor-dialog__heading p {
  margin-top: 5px;
  color: var(--app-text-muted);
  font-size: var(--text-xs);
  line-height: var(--type-line-control);
}

.chat-editor-dialog__close {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 9px;
  color: var(--app-text-muted);
  background: transparent;
  cursor: pointer;
}

.chat-editor-dialog__close:hover,
.chat-editor-dialog__close:focus-visible {
  outline: none;
  color: var(--app-text);
  background: var(--app-control-hover);
}

.chat-editor-dialog__close:focus-visible {
  box-shadow: 0 0 0 3px var(--app-focus-ring);
}

.chat-editor-dialog__body {
  min-height: 0;
  flex: 1;
  padding: 22px 24px 24px;
  overflow-y: auto;
}

.chat-editor-field {
  display: grid;
  gap: 8px;
}

.chat-editor-field > span {
  color: var(--app-text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
}

.chat-editor-field input,
.chat-editor-field textarea,
.chat-editor-threshold input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--app-border);
  border-radius: 10px;
  outline: none;
  color: var(--app-text);
  background: var(--app-surface);
  font: inherit;
  transition: border-color .16s ease, box-shadow .16s ease;
}

.chat-editor-field input {
  height: 42px;
  padding: 0 12px;
}

.chat-editor-field textarea {
  min-height: 210px;
  padding: 12px;
  resize: vertical;
  line-height: var(--type-line-body);
}

.chat-editor-field input:focus,
.chat-editor-field textarea:focus,
.chat-editor-threshold input:focus {
  border-color: var(--app-accent-border);
  box-shadow: 0 0 0 3px var(--app-focus-ring);
}

.chat-editor-field__meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
  line-height: var(--type-line-control);
}

.chat-editor-field__meta span:last-child {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.chat-editor-option {
  margin-top: 20px;
  margin-bottom: 4px;
  padding: 16px;
  border: 1px solid var(--app-border);
  border-radius: 12px;
  background: var(--app-surface);
}

.chat-editor-option__header {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.chat-editor-option__icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
}

.chat-editor-option__header h3,
.chat-editor-option__header p {
  margin: 0;
}

.chat-editor-option__header h3 {
  color: var(--app-text);
  font-size: var(--text-sm);
}

.chat-editor-option__header p {
  margin-top: 2px;
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
}

.chat-editor-switch {
  position: relative;
  display: inline-flex;
  width: 42px;
  height: 24px;
  cursor: pointer;
}

.chat-editor-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.chat-editor-switch > span {
  width: 100%;
  border-radius: 999px;
  background: color-mix(in srgb, var(--app-text-muted) 55%, var(--app-surface));
  transition: background .16s ease;
}

.chat-editor-switch > span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .2);
  content: '';
  transition: transform .16s ease;
}

.chat-editor-switch input:checked + span {
  background: var(--app-accent);
}

.chat-editor-switch input:checked + span::after {
  transform: translateX(18px);
}

.chat-editor-switch input:focus-visible + span {
  box-shadow: 0 0 0 3px var(--app-focus-ring);
}

.chat-editor-threshold {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--app-border);
  color: var(--app-text-secondary);
  font-size: var(--text-xs);
}

.chat-editor-threshold > div {
  display: flex;
  align-items: center;
  gap: 7px;
}

.chat-editor-threshold input {
  width: 92px;
  height: 34px;
  padding: 0 9px;
}

.chat-editor-threshold.is-disabled {
  opacity: .55;
}

.chat-editor-dialog__footer {
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--app-border);
  background: var(--app-control);
}

.chat-editor-dialog__button {
  display: inline-flex;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--app-border);
  border-radius: 9px;
  font: inherit;
  cursor: pointer;
}

.chat-editor-dialog__button.is-secondary {
  color: var(--app-text-secondary);
  background: var(--app-surface);
}

.chat-editor-dialog__button.is-secondary:hover {
  border-color: var(--app-accent-border);
  color: var(--app-text);
  background: var(--app-control-hover);
}

.chat-editor-dialog__button.is-primary {
  border-color: var(--app-accent);
  color: #fff;
  background: var(--app-accent);
}

.chat-editor-dialog__button.is-primary:hover {
  background: var(--accent-600);
}

.chat-editor-dialog__button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--app-focus-ring);
}

.chat-editor-dialog__button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.modal .context-memory-dialog {
  width: min(780px, calc(100vw - 32px));
  height: min(820px, calc(100dvh - 40px));
  max-height: min(820px, calc(100dvh - 40px));
}

.context-memory-tabs {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
  padding: 10px 24px 0;
  border-bottom: 1px solid var(--app-border);
  background: var(--app-surface);
}

.context-memory-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px 11px;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--app-text-muted);
  background: transparent;
  font: inherit;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
}

.context-memory-tabs button:hover,
.context-memory-tabs button.is-active {
  color: var(--app-text);
}

.context-memory-tabs button.is-active {
  border-bottom-color: var(--app-accent);
}

.context-memory-tabs b {
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 999px;
  color: var(--app-accent);
  background: var(--app-accent-soft);
  font-size: var(--type-size-meta);
  text-align: center;
}

.memory-create-row,
.memory-generate-panel,
.context-memory-select-field,
.memory-inline-editor__head {
  display: flex;
  align-items: center;
}

.memory-create-row {
  gap: 10px;
}

.memory-create-row input,
.memory-inline-editor input,
.memory-inline-editor textarea,
.context-memory-select-field select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--app-border);
  border-radius: 10px;
  outline: none;
  color: var(--app-text);
  background: var(--app-surface);
  font: inherit;
}

.memory-create-row input,
.memory-inline-editor input,
.context-memory-select-field select {
  height: 40px;
  padding: 0 11px;
}

.memory-create-row input:focus,
.memory-inline-editor input:focus,
.memory-inline-editor textarea:focus,
.context-memory-select-field select:focus {
  border-color: var(--app-accent-border);
  box-shadow: 0 0 0 3px var(--app-focus-ring);
}

.memory-create-row button,
.memory-generate-panel button,
.memory-inline-editor__save {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 14px;
  border: 1px solid var(--app-accent);
  border-radius: 9px;
  color: #fff;
  background: var(--app-accent);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
  cursor: pointer;
}

.memory-create-row button:disabled,
.memory-generate-panel button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.context-memory-help,
.context-memory-notice {
  margin: 10px 0 14px;
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
  line-height: var(--type-line-control);
}

.memory-access-settings {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--app-border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--app-text-muted) 4%, var(--app-surface));
}

.memory-access-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.memory-access-options > label {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--app-border);
  border-radius: 9px;
  background: var(--app-surface);
  cursor: pointer;
}

.memory-access-options > label.is-selected {
  border-color: var(--app-accent-border);
  box-shadow: 0 0 0 2px var(--app-focus-ring);
}

.memory-access-options input {
  margin-top: 2px;
  accent-color: var(--app-accent);
}

.memory-access-options span {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.memory-access-options strong {
  color: var(--app-text);
  font-size: var(--text-xs);
}

.memory-access-options small {
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
  line-height: var(--type-line-compact);
}

.memory-recommendations {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--app-accent-border);
  border-radius: 12px;
  background: var(--app-accent-soft);
}

.memory-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--app-accent);
}

.memory-section-heading > div {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.memory-section-heading strong {
  color: var(--app-text);
  font-size: var(--text-xs);
}

.memory-section-heading small {
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
}

.memory-recommendation-list {
  display: grid;
  gap: 6px;
}

.memory-recommendation-list article {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 9px;
  border-radius: 9px;
  background: var(--app-surface);
}

.memory-recommendation-list article > div {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.memory-recommendation-list strong,
.memory-recommendation-list small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-recommendation-list strong {
  color: var(--app-text);
  font-size: var(--text-xs);
}

.memory-recommendation-list small {
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
}

.memory-recommendation-list button {
  padding: 5px 10px;
  border: 1px solid var(--app-accent-border);
  border-radius: 8px;
  color: var(--app-accent);
  background: var(--app-accent-soft);
  font: inherit;
  font-size: var(--text-2xs);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
}

.memory-library-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 9px;
  margin-bottom: 10px;
}

.memory-search-field {
  display: flex;
  height: 38px;
  box-sizing: border-box;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--app-border);
  border-radius: 9px;
  color: var(--app-text-muted);
  background: var(--app-surface);
}

.memory-search-field:focus-within {
  border-color: var(--app-accent-border);
  box-shadow: 0 0 0 3px var(--app-focus-ring);
}

.memory-search-field input,
.memory-library-tools select {
  min-width: 0;
  border: 0;
  outline: none;
  color: var(--app-text);
  background: transparent;
  font: inherit;
  font-size: var(--text-xs);
}

.memory-search-field input {
  width: 100%;
}

.memory-library-tools select {
  padding: 0 9px;
  border: 1px solid var(--app-border);
  border-radius: 9px;
  background: var(--app-surface);
}

.memory-file-list {
  display: grid;
  gap: 9px;
}

.memory-file-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--app-border);
  border-radius: 11px;
  background: var(--app-surface);
}

.memory-file-card.is-selected {
  border-color: var(--app-accent-border);
  background: var(--app-accent-soft);
}

.memory-file-select {
  display: grid;
  min-width: 0;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.memory-file-select > span {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.memory-file-select strong {
  overflow: hidden;
  color: var(--app-text);
  font-size: var(--text-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-file-title-line {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
}

.memory-file-title-line strong {
  min-width: 0;
}

.memory-file-title-line em {
  flex: 0 0 auto;
  padding: 2px 6px;
  border-radius: 999px;
  color: var(--app-text-muted);
  background: var(--app-control);
  font-size: var(--type-size-meta);
  font-style: normal;
  font-weight: var(--font-weight-semibold);
}

.memory-file-title-line em.is-review {
  color: #b45309;
  background: #fffbeb;
}

.memory-file-title-line em.is-expired {
  color: var(--app-text-muted);
  background: var(--app-control-hover);
}

.memory-file-select input:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.memory-file-select small {
  overflow: hidden;
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
  line-height: var(--type-line-compact);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-tag-row {
  display: flex;
  gap: 5px;
  overflow: hidden;
}

.memory-tag-row i {
  color: var(--app-accent);
  font-size: var(--type-size-meta);
  font-style: normal;
  white-space: nowrap;
}

.memory-file-select .memory-usage-line {
  color: var(--app-text-muted);
  font-size: var(--type-size-meta);
}

.memory-file-actions {
  display: flex;
  gap: 4px;
}

.memory-file-actions button,
.memory-inline-editor__head button {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--app-text-muted);
  background: transparent;
  cursor: pointer;
}

.memory-file-actions button:hover,
.memory-inline-editor__head button:hover {
  color: var(--app-text);
  background: var(--app-control-hover);
}

.context-memory-empty {
  padding: 36px 18px;
  border: 1px dashed var(--app-border);
  border-radius: 11px;
  color: var(--app-text-muted);
  font-size: var(--text-xs);
  text-align: center;
}

.memory-inline-editor {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--app-accent-border);
  border-radius: 12px;
  background: var(--app-accent-soft);
}

.memory-inline-editor__head {
  justify-content: space-between;
  color: var(--app-text);
  font-size: var(--text-xs);
}

.memory-inline-editor textarea {
  min-height: 150px;
  padding: 11px;
  resize: vertical;
  line-height: var(--type-line-body);
}

.memory-editor-metadata {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 9px;
}

.memory-editor-metadata label {
  display: grid;
  gap: 5px;
  color: var(--app-text-secondary);
  font-size: var(--text-2xs);
}

.memory-editor-metadata select {
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--app-border);
  border-radius: 10px;
  outline: none;
  color: var(--app-text);
  background: var(--app-surface);
  font: inherit;
}

.memory-editor-metadata select:focus {
  border-color: var(--app-accent-border);
  box-shadow: 0 0 0 3px var(--app-focus-ring);
}

.memory-editor-lifecycle {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 11px;
  border: 1px solid var(--app-border);
  border-radius: 10px;
  background: var(--app-surface);
}

.memory-editor-lifecycle label,
.memory-editor-lifecycle > div {
  display: grid;
  gap: 5px;
}

.memory-editor-lifecycle label > span,
.memory-editor-lifecycle small {
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
}

.memory-editor-lifecycle input {
  width: 160px;
  height: 34px;
  padding: 0 8px;
}

.memory-editor-lifecycle > div {
  justify-items: end;
}

.memory-editor-lifecycle > div > span {
  padding: 3px 7px;
  border-radius: 999px;
  font-size: var(--type-size-meta);
  font-weight: var(--font-weight-semibold);
}

.memory-editor-lifecycle .is-pending {
  color: #b45309;
  background: #fffbeb;
}

.memory-editor-lifecycle .is-verified {
  color: #047857;
  background: #ecfdf5;
}

.memory-source-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding-top: 2px;
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
}

.memory-source-list strong {
  margin-right: 2px;
  color: var(--app-text-secondary);
}

.memory-source-list span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 7px;
  border-radius: 7px;
  background: var(--app-surface);
}

.memory-revision-list {
  color: var(--app-text-muted);
  font-size: var(--text-xs);
}

.memory-revision-list summary {
  width: max-content;
  cursor: pointer;
}

.memory-revision-list > div {
  display: grid;
  max-height: 210px;
  gap: 6px;
  margin-top: 8px;
  overflow-y: auto;
}

.memory-revision-list article {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 9px;
  border-radius: 8px;
  background: var(--app-surface);
}

.memory-revision-list article > div {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.memory-revision-list article strong,
.memory-revision-list article small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-revision-list article strong {
  color: var(--app-text-secondary);
  font-size: var(--text-2xs);
}

.memory-revision-list article small {
  font-size: var(--type-size-meta);
}

.memory-revision-list button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border: 0;
  border-radius: 7px;
  color: var(--app-accent);
  background: var(--app-accent-soft);
  font: inherit;
  font-size: var(--text-2xs);
  cursor: pointer;
}

.memory-inline-editor__save {
  width: max-content;
  justify-self: end;
}

.memory-archive-list {
  margin-top: 16px;
  color: var(--app-text-muted);
  font-size: var(--text-xs);
}

.memory-archive-list summary {
  width: max-content;
  cursor: pointer;
}

.memory-archive-list > div {
  display: grid;
  gap: 6px;
  margin-top: 9px;
}

.memory-archive-list article {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--app-control);
}

.memory-archive-list article > div {
  min-width: 0;
}

.memory-archive-list article p {
  display: -webkit-box;
  max-width: 560px;
  margin: 7px 0 2px 22px;
  overflow: hidden;
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
  line-height: var(--type-line-control);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.memory-archive-list button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 0;
  border-radius: 7px;
  color: var(--app-accent);
  background: var(--app-accent-soft);
  font: inherit;
  font-size: var(--text-2xs);
  cursor: pointer;
}

.memory-archive-list .memory-archive-preview {
  max-width: 520px;
  padding: 0;
  color: var(--app-text-secondary);
  background: transparent;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  text-align: left;
}

.context-memory-deposit {
  margin-top: 0;
}

.context-memory-select-field {
  align-items: flex-start;
  flex-direction: column;
  gap: 7px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--app-border);
  color: var(--app-text-secondary);
  font-size: var(--text-xs);
}

.memory-generate-panel {
  justify-content: space-between;
  gap: 18px;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--app-border);
  border-radius: 12px;
  background: var(--app-surface);
}

.memory-generate-panel strong {
  color: var(--app-text);
  font-size: var(--text-sm);
}

.memory-generate-panel p {
  margin: 4px 0 0;
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
  line-height: var(--type-line-control);
}

.memory-health-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.memory-health-summary > div {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 13px 10px;
  border: 1px solid var(--app-border);
  border-radius: 11px;
  background: var(--app-surface);
}

.memory-health-summary span {
  color: var(--app-text);
  font-size: var(--text-lg);
  font-weight: var(--font-weight-bold);
}

.memory-health-summary span.is-danger {
  color: #dc2626;
}

.memory-health-summary span.is-warning {
  color: #d97706;
}

.memory-health-summary small {
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
}

.memory-health-list {
  display: grid;
  gap: 9px;
}

.memory-health-list > article {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--app-border);
  border-left-width: 3px;
  border-radius: 11px;
  background: var(--app-surface);
}

.memory-health-list > article.is-danger {
  border-left-color: #dc2626;
}

.memory-health-list > article.is-warning {
  border-left-color: #d97706;
}

.memory-health-list > article.is-info {
  border-left-color: var(--app-accent);
}

.memory-health-list__icon {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 9px;
  color: var(--app-text-muted);
  background: var(--app-control);
}

.memory-health-list > article.is-danger .memory-health-list__icon {
  color: #dc2626;
  background: #fef2f2;
}

.memory-health-list > article.is-warning .memory-health-list__icon {
  color: #d97706;
  background: #fffbeb;
}

.memory-health-list > article > div:not(.memory-health-list__actions) {
  min-width: 0;
}

.memory-health-list strong {
  color: var(--app-text);
  font-size: var(--text-xs);
}

.memory-health-list p {
  margin: 3px 0 0;
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
  line-height: var(--type-line-control);
}

.memory-health-list__actions {
  display: flex;
  gap: 5px;
}

.memory-health-list__actions button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border: 1px solid var(--app-border);
  border-radius: 8px;
  color: var(--app-text-secondary);
  background: var(--app-surface);
  font: inherit;
  font-size: var(--text-2xs);
  cursor: pointer;
}

.memory-health-list__actions button:hover {
  border-color: var(--app-accent-border);
  color: var(--app-accent);
}

.memory-health-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #047857;
}

.memory-storage-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.memory-storage-summary > div {
  display: grid;
  min-width: 0;
  justify-items: center;
  gap: 3px;
  padding: 13px 8px;
  border: 1px solid var(--app-border);
  border-radius: 11px;
  background: var(--app-surface);
}

.memory-storage-summary strong {
  max-width: 100%;
  overflow: hidden;
  color: var(--app-text);
  font-size: var(--text-md);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-storage-summary small {
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
}

.memory-storage-section {
  display: grid;
  gap: 9px;
  margin-top: 16px;
}

.memory-storage-section > .memory-section-heading {
  padding: 0 2px;
}

.memory-storage-section > .memory-section-heading > span {
  min-width: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--app-text-muted);
  background: var(--app-control);
  font-size: var(--text-2xs);
  text-align: center;
}

.memory-storage-list {
  display: grid;
  gap: 7px;
}

.memory-storage-list article {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 11px;
  border: 1px solid var(--app-border);
  border-radius: 10px;
  background: var(--app-surface);
}

.memory-storage-list article > div:first-child {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.memory-storage-list article > div:first-child > strong {
  overflow: hidden;
  color: var(--app-text-secondary);
  font-size: var(--text-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-storage-list article small,
.memory-storage-list article p {
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
}

.memory-storage-list article p {
  display: -webkit-box;
  max-width: 480px;
  margin: 4px 0 0 22px;
  overflow: hidden;
  line-height: var(--type-line-control);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.memory-storage-list .memory-archive-preview {
  display: inline-flex;
  max-width: 500px;
  align-items: center;
  gap: 5px;
  padding: 0;
  overflow: hidden;
  border: 0;
  color: var(--app-text-secondary);
  background: transparent;
  font: inherit;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.memory-storage-list__actions {
  display: flex;
  flex: 0 0 auto;
  gap: 5px;
}

.memory-storage-list__actions button,
.memory-empty-trash,
.memory-version-cleanup button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px;
  border: 1px solid var(--app-border);
  border-radius: 8px;
  color: var(--app-text-secondary);
  background: var(--app-surface);
  font: inherit;
  font-size: var(--text-2xs);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
}

.memory-storage-list__actions button:hover,
.memory-version-cleanup button:hover {
  border-color: var(--app-accent-border);
  color: var(--app-accent);
}

.memory-storage-list__actions button.is-danger,
.memory-empty-trash {
  color: #dc2626;
}

.memory-trash-section {
  padding-top: 14px;
  border-top: 1px solid var(--app-border);
}

.memory-empty-trash {
  border-color: #fecaca;
  background: #fef2f2;
}

.memory-version-cleanup {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--app-border);
  border-radius: 11px;
  background: var(--app-control);
}

.memory-version-cleanup strong {
  color: var(--app-text);
  font-size: var(--text-xs);
}

.memory-version-cleanup p {
  margin: 3px 0 0;
  color: var(--app-text-muted);
  font-size: var(--text-2xs);
  line-height: var(--type-line-control);
}

.memory-version-cleanup button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .workflow-params-trigger span { display: none; }
  .workflow-params-overlay { align-items: flex-end; padding: 10px; }
  .workflow-params-dialog { max-height: calc(100dvh - 20px); border-radius: 18px 18px 12px 12px; }
  .workflow-params-dialog-head { padding: 18px 18px 15px; }
  .workflow-params-grid { grid-template-columns: 1fr; padding: 18px; }
  .workflow-params-field.is-wide { grid-column: auto; }
  .workflow-params-dialog-foot { align-items: stretch; flex-direction: column; padding: 14px 18px 18px; }
  .workflow-params-done { width: 100%; }
  .modal .chat-editor-dialog {
    width: min(100%, 680px);
    max-height: calc(100dvh - 24px);
    border-radius: 16px;
  }

  .chat-editor-dialog__header {
    padding: 18px 18px 16px;
  }

  .chat-editor-dialog__heading p {
    display: none;
  }

  .chat-editor-dialog__body {
    padding: 18px;
  }

  .chat-editor-dialog__footer {
    padding: 14px 18px;
  }
}

@media (max-width: 520px) {
  .chat-editor-dialog__icon {
    width: 34px;
    height: 34px;
  }

  .chat-editor-option__header {
    grid-template-columns: 34px minmax(0, 1fr) auto;
  }

  .chat-editor-threshold {
    align-items: flex-start;
    flex-direction: column;
  }

  .context-memory-tabs {
    padding-right: 12px;
    padding-left: 12px;
  }

  .context-memory-tabs button {
    flex: 1;
    justify-content: center;
    padding-right: 6px;
    padding-left: 6px;
  }

  .memory-generate-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .memory-generate-panel button {
    width: 100%;
  }

  .memory-library-tools,
  .memory-editor-metadata {
    grid-template-columns: 1fr;
  }

  .memory-access-options {
    grid-template-columns: 1fr;
  }

  .memory-library-tools select {
    height: 38px;
  }

  .memory-section-heading > div {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .context-memory-tabs {
    overflow-x: auto;
  }

  .context-memory-tabs button {
    min-width: max-content;
  }

  .memory-editor-lifecycle {
    align-items: stretch;
    flex-direction: column;
  }

  .memory-editor-lifecycle input {
    width: 100%;
  }

  .memory-editor-lifecycle > div {
    align-items: center;
    grid-auto-flow: column;
    justify-content: space-between;
    justify-items: initial;
  }

  .memory-health-list > article {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .memory-health-list__actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .memory-storage-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .memory-storage-list article,
  .memory-version-cleanup {
    align-items: stretch;
    flex-direction: column;
  }

  .memory-storage-list__actions {
    justify-content: flex-end;
  }

  .memory-version-cleanup button {
    width: 100%;
  }

}

/* =========================
   ICP Footer (fixed)
========================= */
:root{
  --icp-footer-height: 36px;
}

/* 子页全屏层 z-index 10050；内嵌版权栏为文档流布局，勿与侧栏争层 */
body.spa-subpage-active #globalSiteFooter {
  z-index: 10100 !important;
  left: 0;
}

/* SPA 子页内嵌版权栏：非 fixed，避免压住侧栏底部账号区 */
.site-footer.site-footer--subpage {
  position: relative !important;
  left: 0 !important;
  right: 0 !important;
  bottom: auto !important;
  width: 100%;
  z-index: 1 !important;
  flex: 0 0 auto;
  min-height: var(--icp-footer-height, 36px);
  height: auto;
  line-height: var(--type-line-snug);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.site-footer {
  position: fixed;
  left: var(--sidebar-width, 280px);
  right: 0;
  bottom: 0;
  z-index: 1200;

  height: var(--icp-footer-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;

  padding: 0 12px;
  font-size: var(--type-size-caption);
  font-family: var(--type-family-ui);
  font-weight: var(--font-weight-regular);
  line-height: var(--type-line-none);
  color: var(--text-muted);
  background-color: color-mix(in srgb, var(--bg-primary) 88%, transparent);
  border-top: 1px solid var(--border-color);
  backdrop-filter: blur(6px);
}

/* 针对声明与版权文字的微调 */
.site-footer .ai-disclaimer,
.site-footer .copyright {
  user-select: none;
}

.site-footer__sync-mount {
  position: absolute;
  right: 12px;
  top: 50%;
  display: inline-flex;
  align-items: center;
  transform: translateY(-50%);
}

/* 移动端适配：窄屏两行上下排列 */
@media (max-width: 600px) {
  .site-footer:not(.site-footer--subpage) {
    left: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: auto;
    min-height: var(--icp-footer-height);
    padding: 6px 42px 6px 10px;
    gap: 2px;
    line-height: var(--type-line-snug);
    font-size: var(--type-size-meta);
    text-align: center;
  }

  .site-footer__sync-mount { right: 8px; }

  .site-footer:not(.site-footer--subpage) .ai-disclaimer,
  .site-footer:not(.site-footer--subpage) .copyright,
  .site-footer:not(.site-footer--subpage) a {
    display: block;
    max-width: 100%;
    line-height: var(--type-line-snug);
  }

  .site-footer:not(.site-footer--subpage) a {
    white-space: nowrap;
  }

  /* html:root 的更高优先级避免 Vue 后加载的基础令牌把移动端值覆盖回 36px。 */
  html:root {
    /* 三行法务信息约需 61–66px；同时为 iPhone 底部安全区预留空间。 */
    --icp-footer-height: calc(68px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 600px) {
  .site-footer.site-footer--subpage {
    flex-direction: column;
    padding: 6px 10px;
    gap: 2px;
    font-size: var(--type-size-meta);
    text-align: center;
  }

  .site-footer.site-footer--subpage .ai-disclaimer,
  .site-footer.site-footer--subpage .copyright,
  .site-footer.site-footer--subpage a {
    display: block;
    line-height: var(--type-line-snug);
  }

  .site-footer.site-footer--subpage a {
    white-space: nowrap;
  }
}

/* 兼容不支持 color-mix 的浏览器（会用这条覆盖） */
@supports not (background-color: color-mix(in srgb, white 50%, transparent)){
  .site-footer{
    background-color: var(--bg-primary);
  }
}

.site-footer a{
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover{
  text-decoration: underline;
}

/* 主体高度已扣除备案栏，无需再 padding-bottom */
/* 流式代码块样式 */
.code-block-wrapper.streaming {
  border-color: color-mix(in srgb,var(--dialog-table-border) 78%,var(--accent-color));
  opacity: 1;
}

.code-block-wrapper.streaming .code-stream-status {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 1px 7px;
  color: var(--accent-color);
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-color) 9%, transparent);
  font-family: var(--font-sans);
  font-size: var(--type-size-meta);
  font-weight: var(--font-weight-medium);
  line-height: var(--type-line-none);
  vertical-align: middle;
}

.code-block-wrapper.streaming .typing-indicator {
  margin-left: 8px;
  animation: blink 1s infinite;
  font-size: var(--type-size-caption);
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0.3; }
}

/* 确保代码块内容正确换行 */
.code-block-wrapper pre {
  margin: 0;
  overflow-x: auto;
}

.code-block-wrapper code {
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

/* 表格主样式见上方「Markdown render」.message-bubble table */

/* =========================
   打字机光标效果
========================= */
.typewriter-cursor {
    display: inline;
    margin-left: 2px;
}

.typewriter-cursor::after {
    content: '▋';
    animation: blink 0.8s infinite;
    color: var(--accent-color);
    font-weight: normal;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* 流式正文：逐字打字下不做块/字淡入、也不用底部 mask——
   块淡入对已显示段落会"重闪"，mask 会让正在读的最新行发虚反而挡字。
   顺滑改靠细颗粒逐字（_streamSmoothFrameCharCap）+ 平滑速度曲线获得。 */
		/* =========================================
	   最新版：移动端适配 + 标题自动换行 + 隐藏摘要模型
	   ========================================= */
	/* -----------------------
	   第一步：修正层级顺序
	   ----------------------- */
	.site-footer:not(.site-footer--subpage) { z-index: 10 !important; }
	.overlay { z-index: 1000 !important; background-color: rgba(0, 0, 0, 0.5) !important; }
	.sidebar { z-index: 1050 !important; }
	.modal { z-index: 1100 !important; }
	/* -----------------------
	   第二步：移动端整体适配
	   ----------------------- */
	@media (max-width: 768px) {
	    /* 1. 侧边栏抽屉效果 */
	    .sidebar {
	        position: fixed !important;
	        top: 0; left: 0;
	        bottom: var(--icp-footer-height, 36px) !important;
	        width: 280px !important;
	        max-width: 85vw !important;
	        transform: translateX(-100%) !important;
	        transition: transform 0.3s ease-in-out !important;
	        box-shadow: 2px 0 15px rgba(0,0,0,0.5) !important;
	    }
	    .sidebar.open { transform: translateX(0) !important; }
	    .mobile-menu-btn { display: flex !important; }

	    /* 子页侧栏在 shell 内容区内全高展开，版权栏为独立 flex 子项，无需再留 bottom 空隙 */
	    body.spa-subpage-active .legacy-page-host .sidebar {
	        bottom: 0 !important;
	    }
	}
	/* -----------------------
	   第三步：移动端界面净化 (隐藏复杂配置栏)
	   ----------------------- */
	@media (max-width: 768px) {
	    /* 隐藏历史条数栏和自动压缩栏 */
	    .history-bar,
	    .compress-bar {
	        display: none !important;
	    }
	}
/* 厂商配置那一行的按钮组合 */
.input-with-btn {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-with-btn select {
  flex: 1;
}

/* 统一 + 和 - 按钮的尺寸，使其看起来完全对称 */
.input-with-btn #addProviderBtn, 
.input-with-btn #deleteProviderBtn {
  width: 38px;         /* 固定宽度 */
  height: 38px;        /* 固定高度 */
  padding: 0;          /* 清除内边距，靠 flex 居中 */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--type-size-subpage-title);   /* 放大符号 */
  font-weight: bold;   /* 加粗符号 */
  flex-shrink: 0;      /* 防止被挤压 */
  line-height: var(--type-line-none);
}

.input-with-btn #deleteProviderBtn {
  padding-bottom: 2px; 
}
/* 模型分组显示 */
optgroup {
  background: var(--bg-secondary);
  color: var(--accent-color);
  font-weight: bold;
  font-style: normal;
}
/* 打字机光标样式 */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background-color: var(--accent-color);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1.1s step-end infinite;
  flex-shrink: 0;
}

/* 流式输出：正文与光标分层，光标固定在底部锚点，避免每帧重绘时抖动 */
.message-stream-shell {
  display: block;
}

.message-stream-cursor {
  display: flex;
  align-items: center;
  min-height: 1.1em;
  margin-top: 2px;
  flex-shrink: 0;
  contain: layout style;
  pointer-events: none;
}

.message-stream-cursor--line {
  display: block;
  line-height: var(--type-line-none);
}

.message-stream-cursor .typing-cursor {
  margin-left: 0;
  vertical-align: baseline;
}

/* project 构建状态与光标分行，避免光标闪烁带动图标 */
.typing-cursor-line {
  display: block;
  margin-top: 2px;
  line-height: var(--type-line-none);
  min-height: 1.1em;
}
.typing-cursor-line .typing-cursor {
  margin-left: 0;
  vertical-align: baseline;
}

.message-bubble.is-streaming .message-stream-cursor .typing-cursor {
  animation: streamCursorBlink 1.15s step-end infinite;
}

@keyframes streamCursorBlink {
  0%, 100% { opacity: 0.92; }
  50% { opacity: 0.28; }
}

@media (prefers-reduced-motion: reduce) {
  .message-bubble.is-streaming .message-stream-cursor .typing-cursor {
    animation: none;
  }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* 模型思考过程折叠块：默认无底色，悬停整块时再显示背景与描边（触屏无精细 hover 时保留弱描边） */
.reasoning-block {
  margin: 0 0 12px 0;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  font-size: 0.9em;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
@media (hover: hover) and (pointer: fine) {
  .reasoning-block:hover {
    border-color: var(--border-color);
    background: var(--bg-secondary, rgba(0,0,0,0.03));
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
  }
  [data-theme="dark"] .reasoning-block:hover {
    background: var(--bg-secondary, rgba(255,255,255,0.06));
    box-shadow: none;
  }
}
@media (hover: none), (pointer: coarse) {
  .reasoning-block {
    border-color: color-mix(in srgb, var(--border-color) 40%, transparent);
  }
}
.reasoning-block summary {
  cursor: pointer;
  font-weight: var(--font-weight-semibold);
  color: var(--text-secondary, #666);
  user-select: none;
  padding: 2px 0;
}
.reasoning-block summary:hover {
  color: var(--accent-color);
}
.reasoning-content {
  margin-top: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary, #666);
  line-height: var(--type-line-body);
}

/* 助手思考条：药丸摘要 + 详情展开（与顶栏名称分行） */
.reasoning-block--pill {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}
.reasoning-block--pill > summary {
  list-style: none;
}
.reasoning-block--pill > summary::-webkit-details-marker {
  display: none;
}
.reasoning-block--pill .reasoning-summary-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-secondary);
  border: 1px solid color-mix(in srgb, var(--border-color) 65%, transparent);
  font-size: var(--type-size-body);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.reasoning-block--pill .reasoning-summary-pill:hover {
  border-color: var(--border-color);
  background: color-mix(in srgb, var(--bg-secondary) 85%, var(--text-primary));
}
.reasoning-block--pill .reasoning-pill-icon {
  font-size: var(--type-size-caption);
  opacity: 0.75;
  line-height: var(--type-line-none);
}
.reasoning-block--pill .reasoning-pill-chevron {
  font-size: var(--type-size-meta);
  opacity: 0.55;
  transition: transform 0.15s ease;
  margin-left: 2px;
}
.reasoning-block--pill[open] .reasoning-pill-chevron {
  transform: rotate(90deg);
}
.reasoning-block--pill .reasoning-content {
  margin-top: 10px;
}

/* 避免与普通 .reasoning-block 悬停外框叠加 */
.reasoning-block.reasoning-block--pill,
.reasoning-block.reasoning-block--pill:hover {
  border-color: transparent !important;
  background: transparent !important;
  box-shadow: none !important;
}

/* ── 分享链接弹窗 ─────────────────────────────────────────────────────────── */
.share-modal-content {
  border: 1px solid var(--app-border);
  border-radius: var(--radius-2xl);
  background: var(--app-surface);
  box-shadow: var(--shadow-lg);
}

.share-modal-title {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--app-text);
}

.share-modal-title iconify-icon {
  color: var(--app-accent);
}

.share-modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  padding: 20px;
}

.share-url-section {
  width: 100%;
}

.share-url-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--app-border);
  border-radius: var(--radius-lg);
  background: var(--app-canvas);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.share-url-box:hover {
  border-color: var(--app-accent-border);
  background: var(--app-accent-soft);
}

.share-url-box.copied {
  border-color: color-mix(in srgb, var(--app-success) 55%, var(--app-border));
  background: color-mix(in srgb, var(--app-success) 7%, var(--app-surface));
}

.share-url-text {
  flex: 1;
  font-size: var(--type-size-control);
  color: var(--app-accent);
  word-break: break-all;
  line-height: var(--type-line-control);
  min-width: 0;
}

.share-copy-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--app-text-secondary);
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  padding: 0;
}

.share-copy-btn:hover {
  color: var(--app-accent);
  background: var(--app-control);
}

.share-copy-btn.copied {
  color: var(--app-success);
  background: color-mix(in srgb, var(--app-success) 10%, transparent);
}

.share-url-hint {
  margin-top: 6px;
  font-size: var(--type-size-control);
  color: var(--app-text-muted);
  text-align: center;
}

.share-url-hint.is-success {
  color: var(--app-success);
  font-weight: var(--font-weight-medium);
}

.share-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--app-text-muted);
  font-size: var(--type-size-control);
}

.share-divider::before,
.share-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--app-border);
}

.share-qr-section {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.share-qr-container {
  padding: 10px;
  background: #fff;
  border: 1px solid var(--app-border);
  border-radius: var(--radius-md);
  display: inline-block;
  line-height: 0;
}

.share-qr-container img,
.share-qr-container canvas {
  display: block;
  border-radius: 4px;
}

/* 工具调用日志块 */
.tool-call-log {
  margin-bottom: 10px;
}
.tool-call-item {
  border: 1px solid var(--border-color);
  border-radius: 6px;
  margin-bottom: 6px;
  overflow: hidden;
  font-size: var(--type-size-body);
}
.tool-call-item > summary {
  padding: 6px 10px;
  cursor: pointer;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.tool-call-item > summary::-webkit-details-marker { display: none; }
.tool-call-item > summary::before {
  content: '▶';
  font-size: var(--type-size-meta);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.tool-call-item[open] > summary::before { transform: rotate(90deg); }
.tool-call-item > summary:hover { background: var(--bg-tertiary); }
.tool-call-summary-icon {
  flex: 0 0 auto;
  color: var(--text-muted);
}
.tool-call-detail {
  padding: 8px 10px;
  border-top: 1px solid var(--border-color);
  font-size: var(--type-size-control);
  background: var(--bg-primary);
}
.tool-call-args {
  margin-bottom: 5px;
  overflow-wrap: anywhere;
  word-break: normal;
  color: var(--text-secondary);
}
.tool-call-result {
  color: var(--text-secondary);
  overflow-wrap: anywhere;
  word-break: normal;
  white-space: pre-wrap;
}
.tool-call-pending {
  margin: 6px 0 10px;
}
.tool-call-running {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border-radius: 6px;
  font-size: var(--type-size-control);
  color: var(--text-secondary);
  margin-bottom: 4px;
  animation: tool-pulse 1.4s ease-in-out infinite;
}
@keyframes tool-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* 消息泡泡渐入效果 */
.message {
  animation: fadeIn 0.3s ease-out forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .message,
  .tool-call-running,
  .generation-thinking-spinner,
  .project-build-status-spinner,
  .code-block-wrapper.streaming .typing-indicator {
    animation: none !important;
  }
  .message-actions,
  .message-actions button,
  .code-block-chevron,
  .reasoning-pill-chevron,
  .message-bubble img.chat-clickable-image {
    transition: none !important;
  }
}

/* 思考中加载图标（见上方 .message-loading / .message-loading-icon） */
/* =========================
   简洁一行式配置栏样式 (修复版)
========================= */
.chat-config-bar {
  width: 100%;
  max-width: var(--chat-max-width);
  margin: 0 auto 12px;
  padding: 8px 0;
  
  display: flex;
  align-items: center;
  justify-content: flex-start; /* 靠左排列 */
  gap: 12px;            /* 适当缩减间距防止溢出 */
  
  font-size: var(--type-size-body);
  color: var(--text-secondary);
  flex-wrap: nowrap;    /* 电脑端禁止换行，保持一行 */
  overflow-x: auto;     /* 万一屏幕太窄，允许横向滚动而不是挤压布局 */
}

.config-item {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;       /* 防止文字被挤压换行 */
}

/* 复选框与文字组合 */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text-primary);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
}

/* 下划线输入框 */
.inline-input {
  border: none;
  border-bottom: 1px solid var(--border-color);
  background: transparent !important;
  text-align: center;
  padding: 0 2px;
  height: 22px;
  font-size: var(--type-size-body);
  color: var(--accent-color);
  transition: border-color 0.2s;
  font-family: inherit;
}

.inline-input:focus {
  outline: none;
  border-bottom-color: var(--accent-color);
}

.inline-input:disabled {
  color: var(--text-muted);
  border-bottom-style: dashed;
  cursor: not-allowed;
}

/* 分割竖线 */
.config-divider {
  width: 1px;
  height: 14px;
  background-color: var(--border-color);
  margin: 0 4px;
  flex-shrink: 0;
}

/* 移动端适配：仅在小屏幕允许换行 */
@media (max-width: 768px) {
  .chat-config-bar {
    max-width: 100%;
    padding: 8px 15px;
    flex-wrap: wrap; /* 手机端允许换行 */
    gap: 10px;
  }
  .config-divider {
    display: none; /* 手机端隐藏分割线 */
  }
}

/* 会话配置条：小屏仍可显示知识库选择（历史/压缩已迁至输入栏记忆菜单） */
@media (max-width: 768px) {
  .chat-config-bar--kb-only {
    display: flex !important;
    flex-wrap: wrap;
    padding: 6px 12px;
    gap: 8px;
  }
}

/* 设置页面：删除厂商按钮浅灰样式 */
#deleteProviderBtn {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color) !important;
  transition: background 0.15s ease, border-color 0.15s ease;
}

#deleteProviderBtn:hover {
  background-color: var(--border-color) !important;
}

/* 保持加号按钮为原色，但确保它们高度一致 */
#addProviderBtn {
  background-color: var(--accent-color);
  color: #ffffff;
  border: none;
}

#addProviderBtn:hover {
  background-color: var(--accent-hover);
}
/* 输入栏左侧：无方框底、图标灰 / 悬停主题色；附件与记忆为向上弹出层 */
.toolbar-left {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
}

.input-toolbar-icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  min-width: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.input-toolbar-icon-btn:hover {
  color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 12%, transparent);
}

.input-toolbar-icon-btn.search-toggle-btn.active,
.input-toolbar-icon-btn.kb-toggle-btn.active,
.input-toolbar-icon-btn.research-toggle-btn.active,
.input-toolbar-icon-btn.siheng-toggle-btn.active,
.input-toolbar-icon-btn.mcp-toggle-btn.active,
.input-toolbar-icon-btn.project-toggle-btn.active,
.input-toolbar-icon-btn.component-toggle-btn.active,
.input-toolbar-icon-btn.image-gen-toggle-btn.active {
  color: #fff !important;
  background: var(--accent-color) !important;
}

/* 组件生成模式提示：引用块样式，仅显示名称（显隐由 app.js 控制 currentChat.componentMode） */
.component-mode-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  margin: 0 0 8px;
  padding: 4px 6px 4px 10px;
  font-size: var(--text-xs);
  color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 8%, var(--chat-main-bg));
  border-left: 3px solid var(--accent-color);
  border-radius: var(--radius-sm);
}
.component-mode-hint-label { font-weight: var(--font-weight-semibold); }
.component-mode-hint-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  margin-left: 2px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.component-mode-hint-close:hover {
  color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 12%, transparent);
}

/* 生图模式参数面板：开启生图模式后显示在输入框上方，显式填写模型 / 张数 / 尺寸 / 质量 / 中间图 */
.image-gen-panel {
  align-self: stretch;
  margin: 0 0 8px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--accent-color) 6%, var(--chat-main-bg));
  border: 1px solid color-mix(in srgb, var(--accent-color) 22%, transparent);
  border-radius: var(--radius-md, 10px);
}
.image-gen-panel-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 14px;
}
.image-gen-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.image-gen-field--model { flex: 1 1 200px; min-width: 160px; }
.image-gen-field-label {
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--text-muted);
}
.image-gen-select,
.image-gen-input {
  height: 30px;
  padding: 0 8px;
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-sizing: border-box;
}
.image-gen-field--model .image-gen-select { width: 100%; }
.image-gen-input { width: 64px; }
.image-gen-select:focus,
.image-gen-input:focus {
  outline: none;
  border-color: var(--accent-color);
}
.image-gen-panel-note {
  margin-top: 8px;
  font-size: var(--text-xs);
  line-height: var(--type-line-control);
  color: var(--text-muted);
}

/* 组件类型菜单项（多选，选中显示 ✓ + 品牌色高亮） */
.input-tool-popover-panel--component {
  width: min(500px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
}
.component-type-item {
  min-width: 0;
  gap: 8px;
  padding: 8px 10px;
}
.component-type-copy {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}
.component-type-description {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-regular);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.component-type-name { white-space: nowrap; }
.component-type-check { margin-left: auto; color: var(--accent-color); font-weight: var(--font-weight-bold); visibility: hidden; }
.component-type-item.is-selected .component-type-name { color: var(--accent-color); font-weight: var(--font-weight-semibold); }
.component-type-item.is-selected .component-type-check { visibility: visible; }

.input-tool-popover-panel--mcp {
  width: min(88vw, 360px);
  max-height: 340px;
  overflow-y: auto;
}

.mcp-tool-menu-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mcp-tool-menu-server {
  padding: 8px 10px 4px;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-bold);
  color: var(--text-muted);
}

.mcp-tool-menu-tool {
  align-items: flex-start;
  gap: 8px;
  min-height: 42px;
}

.mcp-tool-menu-tool-main {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 2px;
}

.mcp-tool-menu-tool-name {
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mcp-tool-menu-tool-desc,
.mcp-tool-menu-empty {
  font-size: var(--text-xs);
  line-height: var(--type-line-compact);
  color: var(--text-muted);
}

.mcp-tool-menu-empty {
  padding: 10px 12px;
}

.input-toolbar-icon-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

.input-tool-popover {
  position: relative;
  display: inline-flex;
  align-items: center;
}

/* 填补按钮与向上菜单之间的空隙，避免鼠标经过时 :hover 闪烁关闭 */
.input-tool-popover--up::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 14px;
  z-index: 55;
}

.input-tool-popover--up .input-tool-popover-panel {
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  min-width: 176px;
  padding: 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.12);
  z-index: 60;
  visibility: hidden;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s;
  pointer-events: none;
}

[data-theme="dark"] .input-tool-popover--up .input-tool-popover-panel {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
}

.input-tool-popover--up .input-tool-popover-panel::after {
  content: '';
  position: absolute;
  bottom: -5px;
  /* 与触发按钮左对齐的面板：三角应落在按钮水平中心（38px 图标钮），勿用 right 以免宽面板时错位 */
  left: 19px;
  right: auto;
  width: 9px;
  height: 9px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  transform: translateX(-50%) rotate(45deg);
}

@media (hover: hover) and (pointer: fine) {
  .input-tool-popover--up:hover .input-tool-popover-panel,
  .input-tool-popover--up:focus-within .input-tool-popover-panel {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }
}

.input-tool-popover--up.is-open .input-tool-popover-panel {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.input-tool-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  font-size: var(--type-size-body);
  font-weight: var(--font-weight-regular);
  line-height: var(--type-line-control);
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

.input-tool-menu-item:hover {
  background: var(--bg-secondary);
}

.input-tool-menu-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.input-tool-popover-panel--memory {
  min-width: min(96vw, 300px);
  max-width: min(96vw, 360px);
  padding: 8px 14px 12px;
  font-size: var(--type-size-body);
  line-height: var(--type-line-control);
  color: var(--text-primary);
  text-align: left;
}

.input-tool-popover-panel--memory .checkbox-label {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
}

.input-tool-popover-panel--memory input[type='checkbox'] {
  width: 1em;
  height: 1em;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent-color);
  cursor: pointer;
}

.input-tool-popover-panel--memory input[type='checkbox']:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.memory-menu-blocks {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.memory-menu-block {
  padding: 14px 0 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--border-color) 75%, transparent);
}

.memory-menu-block:last-child {
  border-bottom: none;
  padding-bottom: 6px;
}

.memory-menu-block-title {
  margin: 0;
  padding: 0;
  font-size: inherit;
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  line-height: inherit;
  letter-spacing: 0.01em;
}

.memory-menu-block-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin-top: 10px;
}

.memory-menu-cb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.memory-menu-row-label {
  font-size: inherit;
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  white-space: nowrap;
}

.memory-underline-input {
  border: none !important;
  border-bottom: 1px solid var(--text-primary) !important;
  border-radius: 0 !important;
  background: transparent !important;
  padding: 2px 6px 4px;
  margin: 0;
  font: inherit;
  font-size: inherit;
  line-height: inherit;
  color: var(--text-primary);
  text-align: center;
  min-width: 2.25em;
  height: auto;
  box-sizing: content-box;
}

.memory-underline-input:focus {
  outline: none;
  border-bottom-color: var(--accent-color) !important;
}

.memory-underline-input:disabled {
  border-bottom-style: dashed !important;
  border-bottom-color: color-mix(in srgb, var(--text-muted) 55%, var(--border-color)) !important;
  color: var(--text-muted);
  cursor: not-allowed;
}

.memory-underline-input--narrow {
  width: 3.25rem !important;
  min-width: 3.25rem;
}

.memory-underline-input--mid {
  width: 4.5rem !important;
  min-width: 4.5rem;
}

.memory-menu-unit {
  font-size: inherit;
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  white-space: nowrap;
}

@media (max-width: 520px) {
  .input-tool-popover-panel--memory {
    min-width: min(94vw, 280px);
  }
}

.markdown-toggle-btn.active {
  background-color: var(--accent-color) !important;
  color: white !important;
  border-color: var(--accent-color) !important;
}

/* 工具栏布局 */
.input-toolbar {
  display: flex;
  justify-content: space-between; /* 左右分布 */
  align-items: center;
  padding-top: 4px;
  gap: 8px;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.reasoning-mode-trigger {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 8px;
  color: var(--text-muted);
  border: none;
  border-radius: 10px;
  background: transparent;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.reasoning-mode-trigger:hover,
.reasoning-mode-picker.is-open .reasoning-mode-trigger {
  color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 12%, transparent);
}

.input-tool-popover--up .reasoning-mode-panel {
  left: auto;
  right: 0;
  width: min(280px, calc(100vw - 24px));
  padding: 6px;
}

@media (hover: hover) and (pointer: fine) {
  .reasoning-mode-picker:not(.is-open) .reasoning-mode-panel {
    visibility: hidden;
    opacity: 0;
    transform: translateY(6px);
    pointer-events: none;
  }
}

.input-tool-popover--up .reasoning-mode-panel::after {
  left: auto;
  right: 30px;
  transform: translateX(50%) rotate(45deg);
}

.reasoning-mode-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  color: var(--text-primary);
  border: none;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.reasoning-mode-option:hover {
  background: var(--bg-secondary);
}

.reasoning-mode-option.is-selected {
  color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 10%, transparent);
}

.reasoning-mode-option-icon {
  flex: 0 0 auto;
  color: currentColor;
}

.reasoning-mode-option-copy {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reasoning-mode-option-copy strong {
  font-size: var(--text-sm);
  line-height: var(--type-line-snug);
}

.reasoning-mode-option-copy small,
.reasoning-mode-note {
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: var(--type-line-compact);
}

.reasoning-mode-note {
  margin: 5px 8px 3px;
  padding-top: 7px;
  border-top: 1px solid var(--border-color);
}

/* 模型选择弹出层 */
.input-tool-popover-panel--model {
  min-width: 280px;
  max-width: min(96vw, 380px);
  padding: 8px 0 6px;
  max-height: min(58vh, 480px);
  display: flex;
  flex-direction: column;
}

.chat-model-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 10px;
  margin: 0 4px 4px;
  border-bottom: 1px solid var(--border-color);
}

.chat-model-search-wrap input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: var(--type-size-body);
  color: var(--text-primary);
  padding: 6px 4px;
}

.chat-model-search-wrap input:focus {
  outline: none;
}

.chat-model-search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-model-picker-list {
  overflow-y: auto;
  flex: 1;
  min-height: 100px;
  max-height: min(50vh, 420px);
  padding: 4px 4px 8px;
}

.chat-model-provider-block--empty {
  display: none !important;
}

.chat-model-provider-label {
  padding: 10px 14px 4px;
  font-size: var(--type-size-caption);
  font-weight: var(--font-weight-semibold);
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.chat-model-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% - 8px);
  margin: 2px 4px;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: var(--type-size-body);
  color: var(--text-primary);
  transition: background 0.12s ease;
}

.chat-model-picker-row:hover {
  background: var(--bg-secondary);
}

.chat-model-picker-row.is-selected {
  background: color-mix(in srgb, var(--bg-secondary) 88%, var(--accent-color) 12%);
}

.chat-model-picker-row.is-hidden {
  display: none !important;
}

.chat-model-brand-icon {
  display: block;
  flex-shrink: 0;
  color: #6b7280;
}
.chat-model-brand-icon--asset {
  object-fit: contain;
}
.chat-model-brand-icon--bananarouter {
  filter: grayscale(1);
}
[data-theme="dark"] .chat-model-brand-icon--bananarouter {
  filter: grayscale(1) invert(1);
}

.chat-model-brand-icon--along {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #6b7280;
}

.chat-model-brand-icon--along svg {
  display: block;
  width: 100%;
  height: 100%;
}

.chat-model-picker-btn-glyph .chat-model-brand-icon {
  width: 22px;
  height: 22px;
}

.chat-model-picker-name {
  flex: 1;
  min-width: 0;
  font-weight: var(--font-weight-medium);
}

.chat-model-picker-empty {
  padding: 16px 14px;
  font-size: var(--type-size-body);
  color: var(--text-muted);
  text-align: center;
}

.input-toolbar-icon-btn--model .chat-model-picker-btn-glyph {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 知识库多选面板 */
.kb-selector-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.kb-dropdown-panel {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 220px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.15); /* 向上投影 */
  z-index: 10000; /* 确保在最顶层 */
  margin-bottom: 10px;
  padding: 8px;
  max-height: 300px;
  overflow-y: auto;
}

/* 关键修复：当面板激活时，允许父容器溢出显示 */
.chat-config-bar:has(.kb-dropdown-panel.active) {
  overflow: visible !important;
}

.kb-dropdown-panel.active {
  display: block;
}

.kb-picker-empty {
  padding: 8px;
  color: var(--text-muted);
}

.kb-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 4px;
}

.kb-option:hover {
  background: var(--bg-secondary);
}

.kb-option input {
  cursor: pointer;
}

#messagePreview {
  width: 100%;
  border: none !important;
  background: transparent !important;
  padding: 8px 4px;
  font-size: var(--type-size-compact-title);
  max-height: 200px;
  overflow-y: auto;
}

/* 发送按钮：仅图标；无内容灰、有内容蓝 */
#sendBtn.send-btn {
  min-width: 38px;
  width: 38px;
  height: 38px;
  padding: 0;
  gap: 0;
  border-radius: var(--radius-lg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

#sendBtn.send-btn svg,
#sendBtn.send-btn iconify-icon {
  display: block;
  width: 18px;
  height: 18px;
}

/* 生成中：主页与工作流共用的停止按钮（灰色底 + 脉冲动画图标） */
#sendBtn.send-btn.send-btn--generating,
.response-stop-button {
  min-width: 38px;
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  border-radius: var(--radius-lg);
  background-color: color-mix(in srgb, var(--border-color) 55%, var(--bg-secondary)) !important;
  border: 1px solid color-mix(in srgb, var(--border-color) 90%, transparent) !important;
  color: var(--text-secondary) !important;
  cursor: pointer !important;
}

#sendBtn.send-btn.send-btn--generating:hover,
.response-stop-button:hover {
  background-color: color-mix(in srgb, var(--text-muted) 12%, var(--bg-secondary)) !important;
  color: var(--text-primary) !important;
}

#sendBtn.send-btn.send-btn--generating iconify-icon,
.response-stop-button iconify-icon {
  width: 20px;
  height: 20px;
  color: currentColor;
  animation: stop-btn-pulse 1.1s ease-in-out infinite;
}

@keyframes stop-btn-pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(0.88);
    opacity: 0.82;
  }
}

#sendBtn.send-btn.send-btn--empty:not(:disabled) {
  background-color: color-mix(in srgb, var(--border-color) 55%, var(--bg-secondary)) !important;
  color: var(--text-muted) !important;
  border: 1px solid color-mix(in srgb, var(--border-color) 90%, transparent) !important;
}

#sendBtn.send-btn.send-btn--empty:not(:disabled):hover {
  background-color: color-mix(in srgb, var(--text-muted) 12%, var(--bg-secondary)) !important;
  color: var(--text-secondary) !important;
}

#sendBtn.send-btn.send-btn--ready:not(:disabled) {
  background-color: var(--accent-color) !important;
  color: #fff !important;
  border: 1px solid var(--accent-color) !important;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent-color) 32%, transparent);
}

#sendBtn.send-btn.send-btn--ready:not(:disabled):hover {
  background-color: var(--accent-hover) !important;
  border-color: var(--accent-hover) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent-color) 40%, transparent);
}

#sendBtn.send-btn.send-btn--ready:not(:disabled):active {
  transform: translateY(0);
  box-shadow: 0 1px 4px color-mix(in srgb, var(--accent-color) 32%, transparent);
}

#sendBtn.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed !important;
}

/* 停止按钮样式 */
.btn-stop {
  background-color: #dc2626 !important;
  color: #fff !important;
  border-color: #dc2626 !important;
  cursor: pointer !important;
}

.btn-stop:hover {
  background-color: #b91c1c !important;
  border-color: #b91c1c !important;
}

/* 停止按钮圆圈旋转动画 */
.btn-stop .stop-circle {
  animation: rotate 2s linear infinite;
  transform-origin: 12px 12px; /* 确保围绕圆心旋转 */
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* =========================
   移动端适配优化
========================= */
@media (max-width: 768px) {
  .input-area {
    padding: 10px var(--chat-side-gutter);
  }
  
  .input-wrapper {
    padding: 8px;
    border-radius: 12px; /* 手机端圆角大一点更好看 */
  }

  #sendBtn.send-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

  /* 移动端隐藏知识库切换按钮 */
  #kbToggleBtn {
    display: none !important;
  }
}
/* =========================
   右上角帮助按钮
========================= */
.info-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px; 
  padding: 0 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px; /* 与附件按钮圆角一致 */
  color: var(--text-primary);
  font-size: var(--type-size-body);
  cursor: pointer;
  transition: all 0.2s;
}

/* 确保图标颜色和粗细感一致 */
.info-btn svg {
  flex-shrink: 0;
  color: var(--text-secondary);
}

.info-btn:hover svg {
  color: var(--accent-color);
}

.info-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-color);
}

/* 移动端适配 */
@media (max-width: 768px) {
  .info-btn span { display: none; }
}
@media (max-width: 768px) {
  .share-select-bar{
    padding: 10px 12px;
    gap: 8px;
  }
  .share-select-left{
    gap: 10px;
  }
  .share-select-count{
    font-size: var(--type-size-control);
  }
  .share-select-right{
    gap: 8px;
  }
  .share-select-right .btn-secondary,
  .share-select-right .btn-primary{
    padding: 8px 10px;
    font-size: var(--type-size-control);
  }

}
#backgroundContent {
  width: 100%;
  min-height: 200px;
  padding: 12px;
  font-size: var(--type-size-card-title);
  line-height: var(--type-line-body);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: inherit;
  resize: vertical;
}

#backgroundContent:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}
/* 数学公式容器样式 */
.katex-block-wrapper {
  overflow-x: auto;
  overflow-y: visible;
  padding: 10px 0;
  margin: 10px 0;
  text-align: center;
}

/*
 * KaTeX 渲染修复
 * 问题：
 *   1. 旧规则 ".message-bubble * { overflow-x:auto }" 触发 CSS 规范中
 *      overflow-x≠visible 时 overflow-y 同时计算为 auto 的行为，
 *      使 p/li 等块级容器竖向裁剪 KaTeX vlist 上下标（积分上下限、矩阵行等）。
 *      → 已在上方 .message-bubble * 规则中移除 overflow-x:auto。
 *   2. 旧 clip-path: inset(0 round var(--radius)) 对 .message-bubble 整体裁剪，
 *      在 PC 端宽屏下截断 KaTeX 精确定位的公式元素。
 *      → 已从 .message-bubble 移除 clip-path。
 *   3. 保留以下规则：对 .katex-display 和所有 .katex 后代设置 overflow:visible +
 *      max-width:none，防止任何后续 CSS 意外裁剪公式内容。
 */

/* 确保包含行内公式的段落/列表项不会竖向裁剪 KaTeX 内容 */
.message-bubble p,
.message-bubble li,
.message-bubble blockquote {
  overflow: visible;
}

.message-bubble .katex-display,
.message-bubble .katex * {
  overflow: visible !important;
  max-width: none !important;
  /* 全局 * { box-sizing: border-box } 会影响 KaTeX 内部精确尺寸计算（如 frac-line 的 min-height）。
     KaTeX 假设 content-box 模型，必须在此恢复。 */
  box-sizing: content-box !important;
}

/*
 * 恢复 KaTeX 内部必须使用 overflow:hidden 的元素（共 9 类）：
 *
 *   .katex-mathml   — ⚠️ 最关键：MathML 无障碍层，必须隐藏。
 *                     若 overflow:visible，该层会溢出并叠在视觉公式上方，
 *                     导致用户只看到普通字母，所有数学符号和分式横线消失。
 *   .pstrut         — 定位辅助元素（width:0），不能让内容溢出
 *   .stretchy       — 根号横线、括号等可伸缩符号
 *   .hide-tail      — 箭头尾部裁剪
 *   .halfarrow-*    — 箭头两侧裁剪
 *   .brace-*        — 花括号各段裁剪
 */
.message-bubble .katex .katex-mathml,
.message-bubble .katex .pstrut,
.message-bubble .katex .stretchy,
.message-bubble .katex .hide-tail,
.message-bubble .katex .halfarrow-left,
.message-bubble .katex .halfarrow-right,
.message-bubble .katex .brace-left,
.message-bubble .katex .brace-center,
.message-bubble .katex .brace-right {
  overflow: hidden !important;
}

/* Mermaid：气泡内工具栏 + 预览/代码 + 缩放（.mermaid-wrapper.mermaid-artifact） */
.mermaid-wrapper.mermaid-artifact {
  margin: 12px 0;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-primary);
  overflow: hidden;
  max-width: 100%;
}

.mermaid-artifact-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-color);
  background: color-mix(in srgb, var(--bg-secondary) 65%, var(--bg-primary));
}

.mermaid-artifact-tabs {
  display: flex;
  gap: 4px;
}

.mermaid-artifact-tab {
  padding: 5px 12px;
  font-size: var(--type-size-control);
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.mermaid-artifact-tab.is-active {
  background: var(--bg-primary);
  border-color: var(--border-color);
  color: var(--text-primary);
  font-weight: var(--font-weight-semibold);
}

.mermaid-artifact-tab:hover:not(.is-active) {
  color: var(--accent-color);
}

.mermaid-artifact-zoom {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mermaid-artifact-zoom-btn,
.mermaid-artifact-copy-btn {
  padding: 4px 8px;
  font-size: var(--type-size-control);
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
}

.mermaid-artifact-zoom-btn:hover,
.mermaid-artifact-copy-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.mermaid-artifact-zoom-value {
  font-size: var(--type-size-caption);
  color: var(--text-muted);
  min-width: 2.6rem;
  text-align: center;
}

.mermaid-artifact-panel--preview {
  padding: 8px;
}

.mermaid-zoom-outer {
  overflow: auto;
  max-height: min(70vh, 520px);
  text-align: center;
  background: var(--bg-secondary);
  border-radius: 8px;
}

.mermaid-zoom-inner {
  display: inline-block;
  transition: transform 0.12s ease;
}

.mermaid-wrapper.mermaid-artifact .mermaid {
  display: inline-block;
  min-width: 100px;
  max-width: 100%;
  overflow-x: visible;
}

.mermaid-wrapper.mermaid-artifact svg {
  max-width: 100%;
  height: auto;
}

.mermaid-artifact-body {
  min-width: 0;
}

.mermaid-artifact-panel--code {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  max-height: min(70vh, 520px);
  max-width: 100%;
  overflow: auto;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  background: var(--chat-main-bg);
  border-radius: 0 0 8px 8px;
}

.mermaid-artifact-pre {
  margin: 0;
  padding: 10px 12px;
  overflow: visible;
  font-size: var(--type-size-control);
  line-height: var(--type-line-compact);
  background: transparent;
  color: var(--text-primary);
}

.mermaid-artifact-pre code {
  font-family: var(--type-family-code);
  white-space: pre;
  word-break: normal;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

/* 气泡内全局 * { max-width:100% } 影响代码区，用面板承担滚动 */
.message-bubble .mermaid-artifact-panel--code {
  max-width: 100%;
}

.message-bubble .mermaid-artifact-pre,
.message-bubble .mermaid-artifact-pre code {
  max-width: 100%;
}

.message-bubble .mermaid-artifact {
  max-width: 100%;
}

.katex-display {
  /* 覆盖 KaTeX 默认的 1em 上下外边距，保持紧凑 */
  margin: 6px 0 !important;
  /* 保留 KaTeX 自身的 display:block + text-align:center，不要覆盖为 inline-block
     (inline-block + min-width:100% 会导致居中公式从左边缘开始，右侧被截断) */
}

/* 错误公式显示样式 */
.katex-error {
  color: var(--danger-color);
  background: rgba(220, 38, 38, 0.1);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: var(--type-family-code);
}

/* ========================= 知识库引用标注 ========================= */

.kb-cite {
  display: inline-block;
  color: var(--accent-color);
  font-weight: var(--font-weight-bold);
  font-size: var(--type-size-meta);
  cursor: pointer;
  vertical-align: super;
  line-height: var(--type-line-none);
  padding: 0 2px;
  border-radius: 3px;
  transition: background 0.2s;
}
.kb-cite:hover {
  background: rgba(var(--accent-rgb), 0.15);
  text-decoration: underline;
}

.kb-references-block {
  margin-top: 16px;
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
}

.kb-references-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 0;
  background: transparent;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  font-size: var(--type-size-body);
  color: var(--text-muted);
  padding: 6px 0;
  user-select: none;
}
.kb-references-title:hover {
  color: var(--text-primary);
}

.kb-refs-toggle, .kb-ref-toggle {
  font-size: var(--type-size-caption);
  transition: transform 0.2s;
  color: var(--text-muted);
}

.kb-refs-title-icon {
  margin-right: 5px;
  vertical-align: middle;
  flex-shrink: 0;
}

.kb-references-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.kb-ref-item {
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  transition: box-shadow 0.3s, border-color 0.3s;
}
/* 图谱扩展来源的条目左侧加紫色细线 */
.kb-ref-item--graph {
  border-left: 3px solid rgba(124, 58, 237, 0.5);
}

.kb-ref-item.kb-ref-highlight {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.25);
}

.kb-ref-header {
  display: flex;
  align-items: center;
  width: 100%;
  border: 0;
  color: inherit;
  font-family: inherit;
  text-align: left;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  background: var(--bg-secondary);
  font-size: var(--type-size-control);
  transition: background 0.2s;
}
.kb-ref-header:hover {
  background: var(--bg-tertiary, rgba(0,0,0,0.04));
}

.kb-ref-num {
  font-weight: var(--font-weight-bold);
  color: var(--accent-color);
  min-width: 24px;
}

.kb-ref-source {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

.kb-ref-confidence {
  font-size: var(--type-size-caption);
  color: var(--text-muted);
  white-space: nowrap;
}

.kb-ref-content {
  border-top: 1px solid var(--border-color);
}

.kb-ref-text {
  padding: 10px 12px;
  font-size: var(--type-size-control);
  line-height: var(--type-line-body);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  color: var(--text-primary);
  background: var(--bg-primary);
}

/* 图谱关联关系区块 */
.kb-ref-graph-rels {
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border-color);
  background: rgba(124, 58, 237, 0.04);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
}
.kb-ref-graph-rels-label {
  font-size: var(--type-size-caption);
  font-weight: var(--font-weight-semibold);
  color: rgba(124, 58, 237, 0.8);
  white-space: nowrap;
  margin-right: 2px;
}
.kb-ref-rel-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.kb-ref-rel-tag {
  font-size: var(--type-size-caption);
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(124, 58, 237, 0.08);
  color: rgba(124, 58, 237, 0.85);
  border: 1px solid rgba(124, 58, 237, 0.18);
  white-space: nowrap;
}

/* ========================= 联网搜索引用（DeepSeek 风格） ========================= */

.web-cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15em;
  height: 1.15em;
  margin: 0 1px;
  padding: 0 3px;
  font-size: var(--type-size-meta);
  font-weight: var(--font-weight-semibold);
  line-height: var(--type-line-none);
  color: var(--text-muted);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  cursor: pointer;
  vertical-align: super;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.web-cite:hover {
  color: var(--accent-color);
  border-color: var(--accent-color);
  background: rgba(var(--accent-rgb), 0.08);
}

.web-sources-capsule {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 2px 10px 2px 4px;
  max-width: 100%;
  min-height: 0;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-primary);
  cursor: pointer;
  user-select: none;
  font: inherit;
  color: inherit;
  line-height: var(--type-line-none);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.web-sources-capsule:hover {
  background: var(--bg-secondary);
  border-color: var(--text-muted);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}
.web-sources-capsule:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.web-sources-favicons {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding-left: 1px;
}
.web-sources-favicon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border-radius: 50%;
  border: 1px solid var(--border-color, #e2e8f0);
  margin-left: 3px;
  background: var(--bg-secondary);
  box-sizing: border-box;
  overflow: hidden;
}
.web-sources-favicons .web-sources-favicon:first-child {
  margin-left: 0;
}
.web-sources-favicon--fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.web-sources-favicon-fallback-svg {
  width: 12px;
  height: 12px;
  display: block;
}
.web-sources-favicon--has-img .web-sources-favicon-fallback-svg {
  display: none;
}
.web-sources-favicon--wrap {
  position: relative;
  overflow: hidden;
}
.web-sources-favicon--wrap > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 2px;
  object-fit: contain;
  object-position: center;
  border-radius: 50%;
  background: #fff;
}

.web-sources-label {
  font-size: var(--type-size-caption);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  white-space: nowrap;
}

body.web-search-panel-open {
  overflow: hidden;
}

.web-search-panel {
  position: fixed;
  inset: 0;
  z-index: 12000;
  pointer-events: none;
}
.web-search-panel.is-open {
  pointer-events: auto;
}
.web-search-panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.2s;
}
.web-search-panel.is-open .web-search-panel-backdrop {
  opacity: 1;
}

.web-search-panel-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: min(420px, 92vw);
  height: 100%;
  background: var(--bg-primary);
  border-left: 1px solid var(--border-color);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.web-search-panel.is-open .web-search-panel-drawer {
  transform: translateX(0);
}

.web-search-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.web-search-panel-header h3 {
  margin: 0;
  font-size: var(--type-size-compact-title);
  font-weight: var(--font-weight-semibold);
}
.web-search-panel-close {
  border: none;
  background: transparent;
  font-size: var(--type-size-metric);
  line-height: var(--type-line-none);
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
}
.web-search-panel-close:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.web-search-panel-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.web-ref-item {
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-secondary);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.web-ref-item.web-ref-highlight {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.2);
}

.web-ref-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.web-ref-site-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}
.web-ref-favicon {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
  object-fit: contain;
}
.web-ref-favicon.is-hidden {
  display: none;
}
.web-ref-favicon--fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  color: var(--text-muted);
}
.web-ref-favicon-fallback-svg {
  width: 14px;
  height: 14px;
  display: block;
}
.web-ref-favicon--has-img .web-ref-favicon-fallback-svg {
  display: none;
}
.web-ref-favicon--wrap {
  position: relative;
  overflow: hidden;
}
.web-ref-favicon--wrap > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: inherit;
  background: #fff;
}
.web-ref-site {
  font-size: var(--type-size-control);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.web-ref-date {
  font-size: var(--type-size-caption);
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: auto;
}
.web-ref-num-badge {
  flex-shrink: 0;
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--type-size-caption);
  font-weight: var(--font-weight-bold);
  color: var(--text-muted);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 999px;
}

.web-ref-title {
  display: block;
  font-size: var(--type-size-card-title);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  text-decoration: none;
  line-height: var(--type-line-compact);
  margin-bottom: 6px;
}
.web-ref-title:hover {
  color: var(--accent-color);
  text-decoration: underline;
}

.web-ref-snippet {
  margin: 0;
  font-size: var(--type-size-control);
  line-height: var(--type-line-control);
  color: var(--text-secondary);
}

@media (max-width: 640px) {
  .web-search-panel-drawer {
    width: 100%;
  }
}

/* ========================= HTML/SVG 组件预览卡片 + 右侧面板 ========================= */

:root {
  --artifact-panel-width: 0px;
}

.assistant-truncation-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, #f59e0b 45%, var(--border-color));
  background: color-mix(in srgb, #f59e0b 8%, var(--bg-primary));
  font-size: var(--type-size-body);
  color: var(--text-primary);
}

.assistant-truncation-text {
  flex: 1;
  min-width: 180px;
}

.continue-project-btn {
  flex-shrink: 0;
}

.project-build-status,
.project-continuing-notice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 2px;
  padding: 0;
  font-size: var(--type-size-control);
  color: var(--text-muted);
  letter-spacing: 0.02em;
  background: none;
  border: none;
  border-radius: 0;
}

.project-build-status-text {
  line-height: var(--type-line-compact);
}

.project-build-status-spinner,
.project-build-status iconify-icon.project-build-status-spinner {
  flex-shrink: 0;
  color: var(--text-muted);
}

/* 对话内运行状态共用同一套轻量药丸，避免“生成/工具/项目”各自成体系。 */
.generation-thinking-line,
.project-build-status,
.tool-call-running {
  display: inline-flex;
  width: fit-content;
  min-height: 30px;
  align-items: center;
  gap: 7px;
  margin: 4px 0 6px;
  padding: 5px 10px;
  color: var(--text-secondary);
  border: 1px solid color-mix(in srgb, var(--border-color) 72%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-secondary) 90%, transparent);
  font-size: var(--type-size-control);
  letter-spacing: 0;
}

.message-bubble .artifact-chip {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 420px;
  margin: 8px 0;
  padding: 14px 16px;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  font: inherit;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.message-bubble .artifact-chip:hover {
  border-color: color-mix(in srgb, var(--accent-color) 45%, var(--border-color));
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

.message-bubble .artifact-chip.is-active {
  border-color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 6%, var(--bg-primary));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-color) 25%, transparent);
}

.message-bubble .artifact-chip:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* 含组件卡片(artifact-chip)的气泡撑满内容区：否则气泡按内容收缩，短标题卡片（如「演示文稿」）
   会比长标题卡片明显偏窄。撑满后所有卡片统一取 max-width:420px 对齐；窄屏随容器收缩、不溢出。 */
.message-bubble:has(.artifact-chip) {
  width: 100%;
}

.artifact-chip-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.artifact-chip-icon--html {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.1);
}

.artifact-chip-icon--mermaid {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
}

.artifact-chip-icon--flowchart {
  background: rgba(66, 99, 235, 0.12);
  color: #4263eb;
}

.artifact-chip-icon--svg {
  color: #7c3aed;
  background: rgba(124, 58, 237, 0.1);
}

.artifact-chip-icon--mindmap {
  color: #4f46e5;
  background: rgba(79, 70, 229, 0.1);
}

.artifact-chip-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.artifact-chip-type {
  font-size: var(--type-size-caption);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.artifact-chip-title {
  font-weight: var(--font-weight-semibold);
  font-size: var(--type-size-card-title);
  line-height: var(--type-line-snug);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html.artifact-panel-open .chat-main {
  flex: 1 1 0;
  min-width: min(280px, 28vw);
  width: 0;
}

.artifact-preview-portal {
  position: relative;
  flex: 0 0 var(--artifact-panel-width, 480px);
  display: flex;
  height: 100%;
  width: var(--artifact-panel-width, 480px);
  min-width: 0;
  max-width: var(--artifact-panel-width, 480px);
  z-index: 2;
  pointer-events: auto;
  overflow: hidden;
}

.artifact-preview-portal .artifact-preview-panel-host {
  flex: 1 1 auto;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0;
  height: 100%;
}

.artifact-preview-portal .artifact-preview-backdrop {
  display: none !important;
}

.artifact-preview-panel-host {
  overflow: hidden;
  transition: width 0.2s ease;
}

body.artifact-resizing .artifact-preview-panel-host,
body.artifact-resizing .artifact-preview-portal {
  transition: none !important;
}

body.artifact-resizing .artifact-preview-inner,
body.artifact-resizing .artifact-preview-panel-host iframe,
body.artifact-resizing .artifact-preview-panel-host video,
body.artifact-resizing .artifact-preview-panel-host .artifact-attach-preview {
  pointer-events: none !important;
}

.artifact-preview-panel {
  position: relative;
  height: 100%;
  width: 100%;
  max-width: 100%;
}

.artifact-preview-panel.is-open {
  border-left: 1px solid var(--border-color);
  background: var(--bg-primary);
}

.artifact-preview-resizer {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 10px;
  cursor: col-resize;
  z-index: 5;
  touch-action: none;
  user-select: none;
}

.artifact-preview-resizer:hover,
body.artifact-resizing .artifact-preview-resizer {
  background: color-mix(in srgb, var(--accent-color) 35%, transparent);
}

.artifact-preview-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  margin-left: 6px;
  min-width: 0;
}

.artifact-preview-header {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  min-height: 52px;
}

.artifact-preview-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.artifact-preview-back,
.artifact-preview-open-new,
.artifact-preview-close {
  flex-shrink: 0;
  color: var(--text-secondary);
}

.artifact-preview-back:hover,
.artifact-preview-open-new:hover,
.artifact-preview-close:hover {
  color: var(--text-primary);
}

.artifact-preview-title-group {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 4px;
}

.artifact-preview-title {
  flex: 0 1 auto;
  margin: 0;
  font-size: var(--type-size-card-title);
  font-weight: var(--font-weight-semibold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.artifact-preview-rename-title {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  color: var(--text-secondary);
}

.artifact-preview-rename-title:hover {
  color: var(--accent-color);
}

.artifact-preview-title-input {
  width: min(100%, 320px);
  min-width: 100px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--accent-color);
  border-radius: 7px;
  outline: none;
  color: var(--text-primary);
  font: inherit;
  font-size: var(--type-size-body);
  font-weight: var(--font-weight-semibold);
  background: var(--bg-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-color) 14%, transparent);
}

.artifact-preview-close {
  font-size: var(--type-size-subpage-title);
  line-height: var(--type-line-none);
}

.artifact-preview-tabs {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.artifact-preview-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--type-size-control);
  cursor: pointer;
  white-space: nowrap;
}

.artifact-preview-tab.is-active {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: var(--font-weight-semibold);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.artifact-preview-tab:hover:not(.is-active) {
  color: var(--text-primary);
}

.artifact-preview-tabs--single {
  pointer-events: none;
}

.artifact-preview-tabs--single .artifact-preview-tab {
  cursor: default;
}

.artifact-preview-zoom-btn {
  flex-shrink: 0;
  color: var(--text-secondary);
}

.artifact-preview-zoom-btn:hover {
  color: var(--text-primary);
}

.artifact-preview-zoom-label {
  font-size: var(--type-size-caption);
  color: var(--text-muted);
  min-width: 2.8rem;
  text-align: center;
  flex-shrink: 0;
}

.artifact-preview-panel-view--preview .artifact-attach-preview {
  height: 100%;
}

.artifact-preview-panel--attachment .artifact-preview-panel-view--preview {
  background: var(--bg-secondary);
}

.artifact-preview-code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.artifact-preview-code-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.artifact-preview-action-btn {
  padding: 5px 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--type-size-caption);
  cursor: pointer;
  white-space: nowrap;
}

.artifact-preview-action-btn:hover:not(:disabled) {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.artifact-preview-action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.artifact-preview-action-btn--primary {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: #fff;
  font-weight: var(--font-weight-semibold);
}

.artifact-preview-action-btn--primary:hover:not(:disabled) {
  filter: brightness(1.05);
  color: #fff;
}

.artifact-preview-action-btn--danger {
  border-color: color-mix(in srgb, var(--danger-color, #dc2626) 45%, var(--border-color));
  color: var(--danger-color, #dc2626);
  background: color-mix(in srgb, var(--danger-color, #dc2626) 8%, var(--bg-primary));
  font-weight: var(--font-weight-semibold);
}

.artifact-preview-action-btn--danger:hover:not(:disabled) {
  border-color: var(--danger-color, #dc2626);
  color: var(--danger-color, #dc2626);
  background: color-mix(in srgb, var(--danger-color, #dc2626) 13%, var(--bg-primary));
}

.artifact-preview-editor {
  flex: 1;
  min-height: 0;
  width: 100%;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: var(--type-family-code);
  font-size: var(--type-size-control);
  line-height: var(--type-line-control);
  resize: none;
  box-sizing: border-box;
  tab-size: 2;
}

.artifact-preview-editor:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-color) 25%, transparent);
}

.artifact-preview-code-lang {
  font-size: var(--type-size-caption);
  font-weight: var(--font-weight-semibold);
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.artifact-preview-copy-btn {
  padding: 5px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--type-size-control);
  cursor: pointer;
}

.artifact-preview-copy-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.artifact-preview-copy-btn.btn--action-saved {
  border-color: color-mix(in srgb, var(--success-color, #16a34a) 40%, var(--border-color));
  background: color-mix(in srgb, var(--success-color, #16a34a) 12%, var(--bg-primary));
  color: var(--success-color, #16a34a);
}

.artifact-preview-panel-view--visual {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.artifact-preview-visual-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-color);
  background: color-mix(in srgb, var(--accent-color) 8%, var(--bg-primary));
}

.artifact-preview-visual-badge {
  font-size: var(--type-size-control);
  font-weight: var(--font-weight-semibold);
  color: var(--accent-color);
}

.artifact-preview-visual-sync {
  margin-left: 6px;
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
}

.artifact-preview-visual-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.artifact-preview-iframe--visual {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: none;
  display: block;
}

html.artifact-visual-editing .artifact-preview-panel-view--preview {
  background: var(--bg-secondary);
}

/* 可视化编辑：全屏覆盖；普通预览：在 app-container 内分屏 */
.artifact-preview-portal--visual {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  top: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  max-width: none !important;
  z-index: 20000 !important;
  pointer-events: auto;
}

body.artifact-visual-portal-open {
  overflow: hidden !important;
}

body.artifact-visual-portal-open .site-footer {
  display: none !important;
}

.artifact-preview-portal--visual .artifact-preview-panel,
.artifact-preview-portal--visual .artifact-preview-panel-host {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  border-left: none;
}

.artifact-preview-portal--visual .artifact-preview-inner {
  margin-left: 0;
  height: 100%;
}

.artifact-preview-portal--visual .artifact-preview-resizer {
  display: none;
}

/* 可视化编辑：全屏覆盖，便于在页面上直接编辑 */
html.artifact-visual-fullscreen {
  --artifact-panel-width: 100vw !important;
  overflow: hidden;
}

/* 组件整屏放大（拓扑等大画布编辑）：portal 固定覆盖整个视口
   —— 同可视化全屏（--visual）的覆盖方式，但不进入可视化编辑态。
   注意：面板宽度由模板内联 :style 控制，故必须靠 position:fixed + !important 覆盖，
   单改 --artifact-panel-width 变量无效（会被内联宽度压死）。 */
html.artifact-panel-maximized {
  overflow: hidden;
}
.artifact-preview-portal--maximized {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  max-width: none !important;
  z-index: 20000 !important;
}
.artifact-preview-portal--maximized .artifact-preview-panel,
.artifact-preview-portal--maximized .artifact-preview-panel-host {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  border-left: none;
}
.artifact-preview-portal--maximized .artifact-preview-inner {
  margin-left: 0;
  height: 100%;
}
.artifact-preview-portal--maximized .artifact-preview-resizer {
  display: none;
}

html.artifact-visual-fullscreen .artifact-preview-inner {
  margin-left: 0;
  height: 100%;
}

html.artifact-visual-fullscreen .artifact-preview-resizer {
  display: none;
}

html.artifact-visual-fullscreen .artifact-preview-panel {
  position: relative;
  z-index: 1;
}

html.artifact-visual-fullscreen .artifact-preview-body {
  flex: 1;
  min-height: 0;
}

html.artifact-visual-fullscreen .artifact-preview-panel-view--visual {
  flex: 1;
  min-height: 0;
}

html.artifact-visual-fullscreen .artifact-preview-iframe,
html.artifact-visual-fullscreen .artifact-preview-iframe--visual {
  flex: 1;
  min-height: 0;
  height: auto;
}

.artifact-preview-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.artifact-preview-panel-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.artifact-preview-panel-view--preview {
  padding: 0;
  background: #f4f4f5;
}

.artifact-preview-iframe {
  flex: 1;
  width: 100%;
  min-height: 200px;
  border: none;
  border-radius: 0;
  background: #fff;
}

.artifact-preview-panel-view--code {
  display: flex;
  flex-direction: column;
  padding: 10px 14px 14px;
  overflow: hidden;
}

.artifact-preview-pre {
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--bg-secondary);
  font-size: var(--type-size-control);
  line-height: var(--type-line-control);
  overflow: auto;
  max-height: 100%;
}

.artifact-preview-pre--readonly {
  flex: 1;
  min-height: 0;
  max-height: none;
}

.artifact-preview-pre--readonly code {
  display: block;
}

.artifact-preview-pre code {
  white-space: pre-wrap;
  word-break: break-word;
}

.artifact-preview-backdrop {
  display: none;
}

body.artifact-resizing {
  cursor: col-resize;
  user-select: none;
}

@media (max-width: 900px) {
  .artifact-preview-portal {
    position: fixed;
    right: 0;
    top: 0;
    bottom: var(--icp-footer-height, 36px);
    left: 0;
    z-index: 200;
    width: 0 !important;
    max-width: none !important;
    flex: none !important;
    pointer-events: none;
  }

  html.artifact-panel-open .artifact-preview-portal {
    width: 100% !important;
    max-width: 100% !important;
    flex: none !important;
    pointer-events: auto;
  }

  html.artifact-panel-open .chat-main {
    visibility: hidden;
  }

  .artifact-preview-panel-host {
    position: relative;
    width: 100% !important;
    max-width: 100% !important;
    pointer-events: auto;
  }

  .artifact-preview-header {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    gap: 6px 8px;
    padding: 8px 10px;
  }

  .artifact-preview-title {
    font-size: var(--type-size-body);
  }

  /* 操作按钮固定在第一行最右（「在新窗口打开」靠右） */
  .artifact-preview-header-actions {
    grid-row: 1;
    grid-column: 3;
  }

  /* tabs 下沉到第二行、靠左铺开（不再与标题挤在第一行） */
  .artifact-preview-tabs {
    grid-row: 2;
    grid-column: 1 / -1;
    justify-self: start;
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .artifact-preview-tab {
    flex-shrink: 0;
    font-size: var(--type-size-caption);
    padding: 4px 8px;
  }

  /* 移动端隐藏「可视化」编辑 tab */
  .artifact-preview-tab--visual {
    display: none;
  }

  /* 第一行仅保留「在新窗口打开」；隐藏发布/列表，以及关闭按钮（左上返回箭头即等于关闭） */
  .artifact-preview-header-actions .artifact-preview-list,
  .artifact-preview-header-actions .artifact-preview-publish {
    display: none;
  }

  .artifact-preview-close {
    display: none;
  }

  html.artifact-panel-open .artifact-preview-panel {
    position: relative;
    z-index: 2;
    width: 100%;
    height: calc(100dvh - var(--icp-footer-height, 36px));
    min-height: calc(100dvh - var(--icp-footer-height, 36px));
    background: var(--bg-primary);
  }

  html.artifact-panel-open {
    --artifact-panel-width: 100% !important;
  }

  /* 移动端全屏预览：不显示蒙层，避免叠在预览内容上方发灰 */
  .artifact-preview-backdrop {
    display: none !important;
  }

  .artifact-preview-resizer {
    display: none;
  }

  .artifact-preview-inner {
    margin-left: 0;
    height: 100%;
  }

  .artifact-preview-body {
    flex: 1;
    min-height: 0;
  }
}

/* ── 多页面项目：文件树 + 已发布列表 ── */
.artifact-preview-panel-view--project {
  flex-direction: row !important;
  padding: 0 !important;
  gap: 0;
}
.artifact-preview-code-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 14px 14px;
  overflow: hidden;
}
html.artifact-project-mode .artifact-preview-panel-host {
  max-width: min(780px, calc(100vw - var(--sidebar-width, 280px) - 300px));
}

@media (max-width: 900px) {
  html.artifact-project-mode .artifact-preview-panel-host {
    max-width: 100% !important;
  }
}
.artifact-preview-panel-view--preview .project-overview {
  height: 100%;
}
.published-projects-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10050;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.published-projects-modal {
  width: min(520px, 100%);
  max-height: 80vh;
  background: var(--bg-primary, #fff);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.published-projects-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.published-projects-modal-header h2 {
  margin: 0;
  font-size: var(--type-size-compact-title);
}
.published-projects-body {
  padding: 12px 16px 16px;
  overflow-y: auto;
}
.published-projects-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.published-projects-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  background: var(--bg-secondary, #f9fafb);
}
.published-projects-item-main {
  min-width: 0;
  flex: 1;
}
.published-projects-item-main strong {
  display: block;
  font-size: var(--type-size-body);
}
.published-projects-meta {
  display: block;
  font-size: var(--type-size-caption);
  color: var(--text-secondary, #6b7280);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.published-projects-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 8px;
}
.published-projects-empty {
  margin: 0;
  color: var(--text-secondary, #6b7280);
  font-size: var(--type-size-body);
  text-align: center;
  padding: 24px 0;
}

.profile-center-footer {
  flex: 0 0 auto;
  min-height: 68px;
  align-items: center;
}

.profile-center-footer .btn-primary,
.profile-center-footer .btn-secondary {
  min-width: 76px;
  min-height: 38px;
  justify-content: center;
}

@media (max-width: 640px) {
  #profileModal {
    padding: 12px;
  }

  #profileModal .modal-content {
    width: 100%;
    max-width: 100%;
    min-height: 0;
    max-height: calc(100dvh - 24px);
  }

  .published-projects-item {
    align-items: stretch;
    flex-direction: column;
  }

  .published-projects-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

}
.agent-component-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 6px;
}
.agent-component-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--type-size-body);
  cursor: pointer;
}

/* ===== 自适应工具菜单 ===== */
/* 移动端使用 action sheet；桌面分栏被挤窄时使用输入框内的锚定菜单。 */
.mobile-tool-more-btn,
.mobile-attach-btn,
.compact-tool-menu { display: none; }

@media (min-width: 769px) {
  .input-wrapper--compact-toolbar .toolbar-left > .input-toolbar-desktop-tool {
    display: none !important;
  }

  .input-wrapper--compact-toolbar .toolbar-left {
    min-width: 0;
    flex: 1;
  }

  .input-wrapper--compact-toolbar .compact-tool-menu {
    position: relative;
    display: block;
    flex: 0 0 auto;
  }
}

.compact-tool-more-btn.active {
  color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 12%, transparent);
}

.compact-tool-popover {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  z-index: 80;
  width: min(320px, calc(100vw - 32px));
  max-height: min(480px, 62vh);
  overflow: auto;
  color: var(--text-primary);
  border: 1px solid color-mix(in srgb, var(--border-color) 92%, transparent);
  border-radius: 14px;
  outline: none;
  background: var(--bg-primary);
  box-shadow: var(--shadow-lg);
  transform-origin: left bottom;
}

.compact-tool-popover-header {
  position: sticky;
  top: 0;
  z-index: 1;
  min-height: 45px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 32px;
  align-items: center;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-color);
  background: color-mix(in srgb, var(--bg-primary) 94%, transparent);
  backdrop-filter: blur(12px);
}

.compact-tool-popover-header strong {
  grid-column: 2;
  overflow: hidden;
  font-size: var(--text-sm);
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-tool-popover-header > button {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: var(--text-muted);
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.compact-tool-popover-header > button:last-child { grid-column: 3; }
.compact-tool-popover-header > button:hover {
  color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 10%, transparent);
}

.compact-tool-popover-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 8px;
}

.compact-tool-item {
  min-width: 0;
  min-height: 42px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--bg-secondary);
  font: inherit;
  font-size: var(--text-xs);
  text-align: left;
  cursor: pointer;
}

.compact-tool-item > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-tool-item > small {
  color: var(--accent-color);
  font-size: var(--text-2xs);
  font-weight: var(--font-weight-bold);
}

.compact-tool-item:hover,
.compact-tool-item.active {
  color: var(--accent-color);
  border-color: color-mix(in srgb, var(--accent-color) 24%, transparent);
  background: color-mix(in srgb, var(--accent-color) 9%, var(--bg-primary));
}

.compact-tool-popover-list,
.compact-tool-memory {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px;
}

.compact-tool-list-item {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 20px;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  color: var(--text-secondary);
  border: 0;
  border-radius: 9px;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.compact-tool-list-item > span {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.compact-tool-list-item strong,
.compact-tool-list-item small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-tool-list-item strong { font-size: var(--text-sm); }
.compact-tool-list-item small { color: var(--text-muted); font-size: var(--text-xs); }
.compact-tool-list-item:hover { background: var(--bg-secondary); }
.compact-tool-list-item.active {
  color: var(--accent-color);
  background: color-mix(in srgb, var(--accent-color) 9%, transparent);
}

.compact-tool-empty {
  margin: 0;
  padding: 20px 12px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-align: center;
}

.compact-tool-memory { gap: 7px; padding: 10px; }
.compact-tool-setting,
.compact-tool-number {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  background: var(--bg-secondary);
}

.compact-tool-setting > span {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.compact-tool-setting strong { font-size: var(--text-sm); }
.compact-tool-setting small { color: var(--text-muted); font-size: var(--text-xs); }
.compact-tool-setting input { width: 16px; height: 16px; accent-color: var(--accent-color); }
.compact-tool-number { justify-content: flex-end; color: var(--text-muted); font-size: var(--text-xs); }
.compact-tool-number input {
  width: 72px;
  height: 30px;
  box-sizing: border-box;
  padding: 0 6px;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 7px;
  background: var(--bg-primary);
  font: inherit;
  text-align: center;
}

.compact-tool-popover-enter-active,
.compact-tool-popover-leave-active { transition: opacity 140ms ease, transform 140ms ease; }
.compact-tool-popover-enter-from,
.compact-tool-popover-leave-to { opacity: 0; transform: translateY(5px) scale(.98); }

@media (max-width: 768px) {
  /* 输入栏：除模型选择外的功能按钮收进 + 菜单，避免窄屏溢出 */
  .toolbar-left > .input-toolbar-desktop-tool,
  #attachMenuWrap,
  #searchToggleBtn,
  #kbToggleBtn,
  #researchToggleBtn,
  #sihengToggleBtn,
  #mcpMenuWrap,
  #componentMenuWrap,
  #memoryMenuWrap { display: none !important; }
  .mobile-tool-more-btn,
  .mobile-attach-btn { display: inline-flex; }
}

/* 底部弹出菜单（action sheet）：一级 / 二级共用，参考 iOS 风格 */
.mobile-sheet-mask {
  position: fixed;
  inset: 0;
  box-sizing: border-box;
  height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  z-index: var(--z-modal, 10000);
  background: rgba(15, 23, 42, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: mobileSheetFade 0.18s ease;
}
.mobile-sheet-wrap {
  width: 100%;
  min-height: 0;
  max-height: 100%;
  max-width: 480px;
  box-sizing: border-box;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: mobileSheetUp 0.24s cubic-bezier(0.2, 0.85, 0.25, 1);
}
.mobile-sheet-wrap > .mobile-sheet-card:not(.mobile-sheet-cancel) {
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}
.mobile-sheet-card {
  background: var(--chat-main-bg, #fff);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-2xl, 16px);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.mobile-sheet-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 15px 18px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-color);
  font-size: var(--type-size-compact-title);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
}
.mobile-sheet-item:last-child { border-bottom: none; }
.mobile-sheet-item:active { background: var(--sidebar-item-hover); }
.mobile-sheet-item--project {
  background: color-mix(in srgb, var(--accent-color) 6%, transparent);
}
.mobile-sheet-ico {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--text-secondary);
}
.mobile-sheet-label { flex: 1; }
.mobile-sheet-label--stacked {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}
.mobile-sheet-label--stacked small {
  color: var(--text-muted);
  font-size: var(--type-size-caption);
}
.mobile-sheet-tail {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--type-size-control);
  color: var(--text-muted);
}
.mobile-sheet-tail.on { color: var(--accent-color); }
.mobile-sheet-arrow { font-size: var(--type-size-page-title); line-height: var(--type-line-none); color: var(--text-muted); }
.mobile-sheet-check { color: var(--accent-color); font-weight: var(--font-weight-bold); font-size: var(--type-size-compact-title); }
.mobile-sheet-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent-color);
  color: #fff;
  font-size: var(--type-size-caption);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.mobile-sheet-back {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--chat-main-bg, #fff);
  color: var(--text-secondary);
  font-size: var(--type-size-body);
  gap: 6px;
  font-weight: var(--font-weight-semibold);
}
.mobile-sheet-cancel {
  display: block;
  width: 100%;
  flex: 0 0 auto;
  padding: 16px;
  text-align: center;
  font-size: var(--type-size-compact-title);
  font-weight: var(--font-weight-semibold);
  color: var(--accent-color);
  cursor: pointer;
}
.mobile-sheet-empty {
  justify-content: center;
  color: var(--text-muted);
  font-size: var(--type-size-body);
  cursor: default;
}
/* 记忆设置二级：开关行 + 数值行 */
.mobile-sheet-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-color);
  font-size: var(--type-size-card-title);
  color: var(--text-primary);
}
.mobile-sheet-row:last-child { border-bottom: none; }
.mobile-sheet-row .mobile-sheet-label { flex: 1; }
.mobile-sheet-row--sub {
  padding-left: 18px;
  background: var(--bg-secondary);
  font-size: var(--type-size-body);
}
.mobile-sheet-num {
  width: 76px;
  padding: 6px 10px;
  text-align: right;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: var(--type-size-card-title);
  background: var(--chat-main-bg);
  color: var(--text-primary);
}
.mobile-sheet-unit { color: var(--text-muted); font-size: var(--type-size-control); flex-shrink: 0; }
.mobile-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}
.mobile-switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}
.mobile-switch-track {
  position: absolute;
  inset: 0;
  border-radius: 13px;
  background: var(--bg-tertiary);
  transition: background 0.2s;
}
.mobile-switch-track::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: var(--shadow-sm);
}
.mobile-switch input:checked + .mobile-switch-track { background: var(--accent-color); }
.mobile-switch input:checked + .mobile-switch-track::before { transform: translateX(18px); }
@keyframes mobileSheetFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mobileSheetUp { from { transform: translateY(24px); } to { transform: translateY(0); } }
/* ──────────────────────────────────────────────────────────────────────────
   模型配置（原 API 设置）：带 logo 的厂商下拉 + 配置卡 + 模型 chips + 高级参数
   ────────────────────────────────────────────────────────────────────────── */
.model-vendor-select { position: relative; }
.model-vendor-select-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border: 1px solid var(--border-color); border-radius: var(--radius-md, 8px);
  background: var(--bg-primary); color: var(--text-primary); cursor: pointer; font-size: var(--type-size-body);
  font-weight: var(--font-weight-regular); line-height: var(--type-line-control);
}
.model-vendor-select-btn:hover { border-color: var(--accent-color); }
.model-vendor-caret { color: var(--text-muted); transition: transform 0.15s; flex-shrink: 0; }
.model-vendor-select.open .model-vendor-caret { transform: rotate(180deg); }
.model-vendor-current, .model-vendor-name { display: inline-flex; align-items: center; }
.model-vendor-current { gap: 9px; min-width: 0; }
.model-vendor-logo { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; flex-shrink: 0; color: var(--text-primary); }
.model-vendor-logo iconify-icon, .model-vendor-logo svg, .model-vendor-logo img {
  display: block;
  width: 20px;
  height: 20px;
}
.model-vendor-logo img { object-fit: contain; }
.model-vendor-logo img[data-brand="bananarouter"] { filter: grayscale(1); }
[data-theme="dark"] .model-vendor-logo img[data-brand="bananarouter"] {
  filter: grayscale(1) invert(1);
}
.model-vendor-name { font-weight: var(--font-weight-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-vendor-dropdown {
  display: none; position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 50;
  max-height: 320px; overflow-y: auto; padding: 6px; border: 1px solid var(--border-color);
  border-radius: var(--radius-md, 8px); background: var(--bg-primary);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.model-vendor-select.open .model-vendor-dropdown { display: block; }
.model-vendor-option {
  width: 100%; display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border: 0; border-radius: 7px; background: transparent; color: var(--text-primary);
  font-size: var(--type-size-body); text-align: left; cursor: pointer;
}
.model-vendor-option:hover { background: var(--bg-secondary); }
.model-vendor-option.is-active { background: var(--accent-color); color: #fff; }
.model-vendor-option.is-active .model-vendor-logo { color: #fff; }
.model-vendor-option--add { justify-content: center; color: var(--accent-color); font-weight: var(--font-weight-semibold); margin-top: 4px; border-top: 1px solid var(--border-color); border-radius: 0; }
.model-vendor-option--add:hover { background: var(--bg-secondary); }

.model-vendor-config { margin-top: 14px; }
.model-builtin-notice {
  margin-bottom: 14px;
  padding: 9px 11px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md, 8px);
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: var(--type-size-caption);
  line-height: var(--type-line-control);
}
.model-protocol-auth {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 9px 12px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md, 8px);
  font-size: var(--type-size-body);
  line-height: var(--type-line-compact);
}

/* 模型 chips */
.model-chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 20px; margin-bottom: 8px; }
.model-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 6px 3px 10px; border-radius: 14px; background: var(--bg-secondary); border: 1px solid var(--border-color); font-size: var(--type-size-control); }
.model-chip-text { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-chip-del { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin: -4px; border: 0; border-radius: 50%; background: transparent; color: var(--text-muted); cursor: pointer; font-size: var(--type-size-card-title); line-height: var(--type-line-none); }
.model-chip-del:hover { background: var(--danger-color, #dc2626); color: #fff; }
.model-chips-empty { font-size: var(--type-size-control); color: var(--text-muted); }
.model-chips-add { display: flex; gap: 8px; }
.model-chips-add input { flex: 1; min-width: 0; }
.model-chips-hint { display: block; margin-top: 6px; font-size: var(--type-size-caption); }

/* 连通性检查 */
.model-conn-check { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.model-conn-check-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.conn-check-status { font-size: var(--type-size-control); color: var(--text-muted); }
.conn-check-status.ok { color: var(--success-color, #16a34a); }
.conn-check-status.err { color: var(--danger-color, #dc2626); }

/* 高级设置（模型参数） */
.advanced-params { margin-top: 6px; border: 1px solid var(--border-color); border-radius: var(--radius-md, 8px); padding: 0 14px; }
.advanced-params > summary { cursor: pointer; padding: 12px 0; font-weight: var(--font-weight-semibold); font-size: var(--type-size-body); list-style: revert; }
.advanced-params[open] > summary { border-bottom: 1px solid var(--border-color); }
.param-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 16px; row-gap: 4px; align-items: center; padding: 12px 0; border-top: 1px solid var(--border-color); }
.advanced-params .param-row:first-of-type { border-top: 0; }
.param-row-head { grid-column: 1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.param-toggle { display: inline-flex; align-items: center; gap: 6px; font-weight: var(--font-weight-semibold); font-size: var(--type-size-body); cursor: pointer; }
.param-toggle input { cursor: pointer; }
.param-key { font-size: var(--type-size-caption); background: var(--bg-secondary); color: var(--text-muted); padding: 1px 6px; border-radius: 5px; font-family: var(--type-family-code); }
.param-desc { grid-column: 1; font-size: var(--type-size-caption); color: var(--text-muted); line-height: var(--type-line-compact); }
.param-controls { grid-column: 2; grid-row: 1 / span 2; display: flex; align-items: center; gap: 10px; }
.param-row--switch .param-controls { grid-row: 1; }
.param-range { width: 130px; max-width: 38vw; }
.param-val { width: 66px; text-align: center; }
.param-range:disabled, .param-val:disabled { opacity: 0.45; cursor: not-allowed; }

@media (max-width: 600px) {
  .param-row { grid-template-columns: minmax(0, 1fr); column-gap: 0; row-gap: 10px; }
  .param-row-head { min-width: 0; }
  .param-toggle { white-space: nowrap; }
  .param-controls,
  .param-row--switch .param-controls { grid-column: 1; grid-row: auto; width: 100%; }
  .param-range { min-width: 0; max-width: none; flex: 1; }
  .param-val { flex: 0 0 66px; }
}

/* 同步设置：自动同步说明（取消开关后，告知用户已实时同步） */
.sync-auto-note {
  margin: 8px 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--note-bg, #ecfdf5);
  border-left: 3px solid var(--success-color, #16a34a);
  color: var(--text-secondary, #475569);
  font-size: var(--type-size-control);
  line-height: var(--type-line-control);
}
