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

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

body{
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'PingFang SC','Microsoft YaHei',sans-serif;
  background-color:var(--bg-primary);
  color:var(--text-primary);
  line-height:1.55;
}

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

/* =========================
   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%;
}

.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;
}

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

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

.sidebar-header .brand .logo { 
  width: 32px; 
  height: 32px; 
  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: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
} 

.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:0.875rem;
}

.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: 0.9rem;
  font-weight: 700;
  line-height: 1;
}

.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: 10px;
  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:500;
  font-size:0.9rem;
  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:600;
}

/* 侧栏会话时间分组标题（今天/昨天/近7天/更早） */
.chat-list-group-label{
  padding:14px 12px 5px;
  font-size:var(--text-2xs,11px);
  font-weight:600;
  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:0.72rem;
  opacity:0.72;
  color:var(--text-secondary);
}

.chat-item-snippet{
  font-size:0.72rem;
  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: 0.78rem;
  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: 0;
  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: 0;
  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;
}

.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: 0.92rem;
  white-space: nowrap;
}

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

body.message-share-selecting .input-area{
  display: none;
}

/* 滑动删除容器 */
.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: 0.875rem;
  font-weight: 500;
  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: 0.8rem;
  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: 0.9rem;
}
.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: 0.9rem;
}
.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:1.125rem;
  font-weight:500;
}

.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;
}

.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:auto;
}

.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);
}

.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:0.82rem;
  line-height:1.35;
  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;
  z-index:10000;
  max-width:min(420px, calc(100vw - 24px));
  padding:6px 14px;
  font-size:0.8rem;
  font-weight:500;
  line-height:1.4;
  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:normal;
  border-radius:10px;
  padding:8px 14px;
  line-height:1.45;
}

[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;
  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;
  max-width:660px;
  margin:0 auto;
}
.welcome-logo{
  width:62px;height:62px;margin:0 auto 18px;
  display:flex;align-items:center;justify-content:center;
  border-radius:var(--radius-2xl);
  background:color-mix(in srgb,var(--accent-color) 12%,var(--chat-main-bg));
  color:var(--accent-color);
}
.welcome-message .welcome-title{
  font-size:var(--text-2xl);font-weight:700;color:var(--text-primary);margin:0 0 8px;
}
.welcome-subtitle{
  font-size:var(--text-base);color:var(--text-secondary);margin:0;
}
.welcome-examples{
  display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px;
  margin-top:28px;text-align:left;
}
.welcome-example-card{
  display:flex;align-items:center;gap:10px;
  padding:14px 16px;
  border:1px solid var(--border-color);
  border-radius:var(--radius-xl);
  background:var(--chat-main-bg);
  color:var(--text-primary);
  font-size:var(--text-sm);
  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{display:inline-flex;flex-shrink:0;color:var(--accent-color);}
.welcome-example-text{line-height:1.45;}

/* ── 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;
}

.welcome-message h2{
  margin-bottom:12px;
  color:var(--text-primary);
}

/* =========================
   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: 0.95rem;
  font-weight: 600;
  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:600;
  font-size:0.75rem;
  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:1.2rem;
  line-height:1;
}
.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-size:0.9rem;
  line-height:1.62;
  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: break-word;
  word-break: break-all;
}

.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.assistant .message-bubble{
  background:transparent;
  color:var(--text-primary);
  border:none;
  font-size:0.95rem;
  line-height:1.72;
}

.message.assistant .message-bubble p{
  line-height:1.72;
}

.message.assistant .message-bubble li{
  line-height:1.7;
}

.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:0.7rem;
  color:var(--text-muted);
}

.message-meta-row .message-stats{
  flex:0 0 auto;
  margin:0;
  font-size:0.7rem;
  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-attachments img{
  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 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 {
  max-width: min(100%, 360px);
  max-height: 360px;
  display: block;
  clear: both;
  margin: 10px 0;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,.08);
  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: 0.86rem;
  font-weight: 600;
  color: var(--text-primary);
}

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

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

.generation-thinking-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.84rem;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}
.generation-thinking-text {
  line-height: 1.4;
}
.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: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.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-size: 1rem;
  line-height: 1.5;
  max-height: 200px;
  resize: none;
}

.input-wrapper textarea:focus{
  width: 100%;
  border: none !important;          /* 彻底移除边框 */
  outline: none !important;         /* 彻底移除点击时的蓝色轮廓线 */
  background: transparent !important;
  padding: 8px;
  font-size: 1rem;
  line-height: 1.5;
  max-height: 200px;
  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);
}

[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:0.8rem;
  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:0.75rem;
  color:var(--text-muted);
  white-space:nowrap;
}

.model-indicator-text{
  font-size:0.75rem;
  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:0.875rem;
  font-weight:500;
  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:0.8rem;
  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:0.875rem;
}

.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;
}

.help-modal-search-mount{
  padding: 10px 16px 0;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.help-search-bar{
  display: flex;
  align-items: center;
}

.help-search-input{
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--bg-primary);
  color: var(--text-primary);
}

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

.help-modal-body{
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#helpFrame{
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg-primary);
}

/* 限制标题输入框样式 */
#newChatTitleInput {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 1rem;
}

#newChatTitleInput:focus {
  border-color: var(--accent-color);
  outline: none;
}

.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:1.125rem;
  font-weight:600;
}

.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:0.875rem;
  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;}

/* 设置 / 个人信息弹窗：统一宽度与最小高度 */
#settingsModal .modal-content,
#profileModal .modal-content {
  width: min(560px, 96vw);
  max-width: min(560px, 96vw);
  max-height: 88vh;
  min-height: min(480px, 72vh);
}
#settingsModal .modal-body,
#profileModal .modal-body {
  flex: 1 1 auto;
  min-height: 320px;
  overflow-x: hidden;
  overflow-y: auto;
}

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

.form-group label{
  display:block;
  margin-bottom:6px;
  font-weight:500;
  font-size:0.875rem;
}

/* 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:1.4rem;
  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);
}

/* 设置-通用：头像预览 + 弹窗选择 */
.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:1.75rem;
  background:var(--bg-primary);
  border:2px solid var(--border-color);
  flex-shrink:0;
}

.avatar-preview-label{
  font-size:0.8125rem;
  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:1rem;
  font-weight:600;
}

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

.avatar-picker-dialog-grid .avatar-option{
  padding:0;
  font-family:inherit;
  line-height:1;
}

.form-group input[type="text"],
.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:0.875rem;
  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:0.75rem;
}

.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:0.875rem;
}
.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:600;
  font-size:0.9rem;
  flex:1;
}
.storage-mode-badge{
  font-size:0.72rem;
  background:rgba(37,99,235,0.12);
  color:var(--accent-color);
  padding:2px 8px;
  border-radius:20px;
}
.storage-mode-card-desc{
  font-size:0.78rem;
  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:0.88rem;
  color:var(--text-muted);
  text-align:center;
}
.server-login-required a{
  color:var(--accent-color);
  text-decoration:none;
  font-weight:500;
}
.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:0.78rem;
  font-weight:600;
  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:0.8rem;
  color:var(--text-secondary);
}
.storage-info-hint{
  font-size:0.78rem;
  color:var(--text-muted);
  line-height:1.5;
}

/* =========================
   首屏加载遮罩（主页 / 智能体页共用）
========================= */
.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: 1.75rem;
  font-weight: 600;
  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;
}

.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{
  padding:6px 16px;
  font-size:12px;
  line-height:1.45;
  font-weight:500;
  background:#ececec;
  color:#111;
  border:none;
  border-radius:999px;
  box-shadow:0 2px 10px rgba(0,0,0,0.08);
}
.toast.toast--chat-download.progress,
.toast.toast--chat-download.loading,
.toast.toast--chat-download.success,
.toast.toast--chat-download.error,
.toast.toast--chat-download.info{
  background:#ececec;
  color:#111;
}
.toast.toast--chat-download.toast--with-progress{
  display:flex;
  flex-direction:column;
  align-items:stretch;
  gap:6px;
  min-width:min(92vw, 280px);
  border-radius:12px;
  padding:8px 14px 10px;
}
.toast.toast--chat-download .toast-message{
  line-height:1.45;
}
.toast.toast--chat-download .toast-progress-track{
  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;
}

@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:0.875rem;
  color:var(--text-muted);
  white-space:nowrap;
}

.model-selector select{
  padding:6px 28px 6px 12px;
  font-size:0.875rem;
  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:0.85rem;
}

.attach-clear-btn{font-size:0.8rem;}

.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: 0.65rem;
  line-height: 1.1;
  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-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: 20px;
}

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

.attach-file-slot {
  font-weight: 600;
  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: 18px;
  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: 0.85rem;
  color: var(--text-primary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.2;
}

.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: 0.95rem !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: 12px;
  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: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
  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: 12px;
  color: var(--text-muted);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.875rem;
}

/* 移动端适配 */
@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{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);
}

.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:1.6;
  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:0.8rem;
  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;}

/* =========================
   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:600;
  line-height:1.4;
}

.message-bubble h1{font-size:1.5em;}
.message-bubble h2{font-size:1.3em;}
.message-bubble h3{font-size:1.15em;}
.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:1.62;
}
.message-bubble p:last-child{margin-bottom:0;}

.message-bubble ul,
.message-bubble ol{
  margin:12px 0;
  padding-left:24px;
}

.message-bubble li{
  margin:6px 0;
  line-height:1.6;
}

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

.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:'SF Mono',Monaco,'Courier New',Consolas,monospace;
  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:1.55;
  font-size:0.9375rem;
}
[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{
  margin:12px 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:0.72rem;
  font-weight:500;
  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:0.62rem;
  line-height:1;
  color:var(--text-muted);
}

.message-bubble .code-block-lang{
  flex-shrink:0;
  font-family:ui-monospace,Menlo,Consolas,monospace;
}

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

.code-block-collapsed .code-block-body{
  display:none;
}

.message-bubble .code-block-body pre{
  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:0.72rem;
  line-height:1.55;
  border-radius:0;
  overflow-x:auto;
}

.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:14px 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:600;
  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:600;}
.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);}

  .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:0.75rem;}

  .input-area{padding:12px var(--chat-side-gutter);}
  
  /* 优化移动端输入区域 */
  .input-wrapper{
    padding:8px;
    border-radius:12px;
    margin-bottom:8px;
  }
  
  .input-wrapper textarea{
    font-size:16px; /* 防止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:0.8rem;}

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

  /* 移动端 header：标题独占第一行，智能体徽章与工具栏第二行 */
  .chat-header{
    height:auto !important;
    display:grid;
    grid-template-columns:1fr auto;
    grid-template-areas:
      "left left"
      "agent toolbar";
    align-items:center;
    padding:8px 12px;
    gap:4px 8px;
  }
  .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:1rem;
  }
  .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:0.78rem;
    flex-shrink:0;
  }
  .model-bar .model-selector select{
    min-width:0;
    width:auto;
    max-width:none;
    font-size:0.78rem;
    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:0.9rem;
  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:0.9rem;
}

.compress-tip{
  color:var(--text-muted);
  font-size:0.8rem;
  line-height:1.3;
}

@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;
}
/* 背景材料指示器样式 */
.background-indicator {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
  white-space: nowrap;
}

.background-indicator span {
  margin-left: 4px;
}

@media (max-width: 768px) {
  .background-indicator span {
    display: none; /* 移动端隐藏文字 */
  }
  .background-indicator {
    padding: 2px 4px;
    background: transparent; /* 移动端去掉背景色，只留图标更清爽 */
    font-size: 1rem;
  }
}

/* =========================
   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: 1.35;
}

.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: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-weight: 400;
  line-height: 1;
  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 .copyright {
  user-select: none; /* 禁止选中版权文字，防止误触 */
}

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

  .site-footer:not(.site-footer--subpage) .copyright,
  .site-footer:not(.site-footer--subpage) a {
    display: block;
    max-width: 100%;
    line-height: 1.35;
  }

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

  :root {
    --icp-footer-height: 54px;
  }
}

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

  .site-footer.site-footer--subpage .copyright,
  .site-footer.site-footer--subpage a {
    display: block;
    line-height: 1.35;
  }

  .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: 1px dashed color-mix(in srgb,var(--dialog-table-border) 80%,var(--accent-color));
  opacity: 0.92;
}

.code-block-wrapper.streaming .typing-indicator {
  margin-left: 8px;
  animation: blink 1s infinite;
  font-size: 12px;
}

@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 */

/* 列表样式 */
.message-bubble ul,
.message-bubble ol {
  margin: 0.5em 0;
  padding-left: 1.8em;
}

.message-bubble ul {
  list-style-type: disc;
  list-style-position: outside;
}

.message-bubble ol {
  list-style-type: decimal;
  list-style-position: outside;
}

.message-bubble li {
  margin: 0.25em 0;
  overflow-x: visible; /* 覆盖全局 * 规则，确保 marker 不被裁剪 */
}

/* 嵌套列表 */
.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 {
  list-style: none;
  margin-left: -1.4em;
  padding-left: 0;
}

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

/* 引用块 */
.message-bubble blockquote {
  margin: 1em 0;
  padding: 0.5em 1em;
  border-left: 4px solid var(--primary-color);
  background: var(--bg-secondary);
}
/* =========================
   打字机光标效果
========================= */
.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: 1.4rem;   /* 放大符号 */
  font-weight: bold;   /* 加粗符号 */
  flex-shrink: 0;      /* 防止被挤压 */
  line-height: 1;
}

.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: 1;
}

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

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

/* 流式输出：禁用正文淡入，避免每帧 innerHTML 更新时反复闪烁 */
.message-bubble.is-streaming .message-stream-body {
  animation: none;
}

/* 等待/思考提示：避免每帧 innerHTML 重绘时反复触发淡入动画 */
.message-bubble.is-streaming .message-stream-body.is-thinking-wait,
.message-bubble.is-streaming .message-stream-body:has(.generation-thinking-line) {
  animation: none;
}

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

.message-bubble.is-stream-ending .typing-cursor,
.message-bubble.is-stream-ending .typing-cursor-line,
.message-bubble.is-stream-ending .message-stream-cursor .typing-cursor {
  animation: streamCursorFadeOut 0.24s ease-out forwards;
}

@keyframes streamBodyFadeIn {
  from { opacity: 0.72; }
  to { opacity: 1; }
}

@keyframes streamCursorFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

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

@media (prefers-reduced-motion: reduce) {
  .message-bubble.is-streaming .message-stream-body,
  .message-bubble.is-streaming .message-stream-cursor .typing-cursor,
  .message-bubble.is-stream-ending .typing-cursor,
  .message-bubble.is-stream-ending .typing-cursor-line,
  .message-bubble.is-stream-ending .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: 600;
  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: 1.6;
  max-height: 400px;
  overflow-y: auto;
}

/* 助手思考条：药丸摘要 + 详情展开（与顶栏名称分行） */
.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: 0.85rem;
  font-weight: 500;
  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: 0.75rem;
  opacity: 0.75;
  line-height: 1;
}
.reasoning-block--pill .reasoning-pill-chevron {
  font-size: 0.65rem;
  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-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;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.share-url-box:hover {
  border-color: var(--accent-color);
  background: var(--bg-hover, rgba(99,102,241,0.05));
}

.share-url-box.copied {
  border-color: #22c55e;
  background: rgba(34,197,94,0.06);
}

.share-url-text {
  flex: 1;
  font-size: 0.82rem;
  color: var(--accent-color);
  word-break: break-all;
  line-height: 1.5;
  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(--text-secondary);
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  padding: 0;
}

.share-copy-btn:hover {
  color: var(--accent-color);
  background: var(--bg-tertiary, rgba(0,0,0,0.05));
}

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

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

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

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

.share-qr-container {
  padding: 10px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  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: 0.85rem;
}
.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: 0.65rem;
  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-detail {
  padding: 8px 10px;
  border-top: 1px solid var(--border-color);
  font-size: 0.82rem;
  background: var(--bg-primary);
}
.tool-call-args {
  margin-bottom: 5px;
  word-break: break-all;
  color: var(--text-secondary);
}
.tool-call-result {
  color: var(--text-secondary);
  word-break: break-all;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}
.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: 0.84rem;
  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; }
}

/* Markdown渲染器样式优化 */
.message-bubble strong {
  font-weight: 700;
  color: inherit;
}

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

.message-bubble li {
  margin-bottom: 6px;
  line-height: 1.62;
}

.message-bubble p {
  margin-bottom: 12px;
  line-height: 1.62;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

/* 确保代码块与文字有足够间距 */
.code-block-wrapper {
  margin: 16px 0 !important;
}

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

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

/* 正在生成的泡泡特殊效果 */
.message.generating .message-bubble {
  border-left: 3px solid var(--accent-color);
  transition: all 0.2s ease;
}
/* 思考中加载图标（见上方 .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: 0.85rem;
  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: 500;
  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: 0.85rem;
  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.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: 600; }
.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: 600;
  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: 1.5;
  color: var(--text-muted);
}

/* 组件类型菜单项（多选，选中显示 ✓ + 品牌色高亮） */
.input-tool-popover-panel--component { min-width: 150px; }
.component-type-item { gap: 8px; }
.component-type-check { margin-left: auto; color: var(--accent-color); font-weight: 700; visibility: hidden; }
.component-type-item.is-selected .component-type-name { color: var(--accent-color); font-weight: 600; }
.component-type-item.is-selected .component-type-check { visibility: visible; }

.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: 0.9rem;
  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: 0.9rem;
  line-height: 1.5;
  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: 600;
  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: 500;
  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: 500;
  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;
}

/* 隐藏但保留在 DOM 供 app 填充 option */
.chat-model-select-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.input-wrapper--expanded #messageInput {
  min-height: min(36vh, 280px);
  max-height: 50vh !important;
  overflow-y: auto;
}

/* 模型选择弹出层 */
.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: 0.9rem;
  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: 0.75rem;
  font-weight: 600;
  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: 0.9rem;
  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--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: 500;
}

.chat-model-picker-empty {
  padding: 16px 14px;
  font-size: 0.88rem;
  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-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: 1rem;
  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 {
  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 {
  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 {
  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: 0.85rem;
  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: 0.82rem;
  }
  .share-select-right{
    gap: 8px;
  }
  .share-select-right .btn-secondary,
  .share-select-right .btn-primary{
    padding: 8px 10px;
    font-size: 0.8rem;
  }

}
/*Markdown格式调整*/
  /* 确保列表有缩进和正确的符号 */
.message-bubble ul.markdown-list, 
.message-bubble ol.markdown-list {
    margin: 10px 0 10px 0 !important;
    padding-left: 1.2em !important; /* 减少缩进，主要由序号/符号决定层级 */
    list-style-position: outside !important; /* 序号显示在列表外部 */
    text-indent: 0 !important; /* 确保文本不缩进 */
}

.message-bubble ul.markdown-list {
    list-style-type: disc !important; /* 显示圆点 */
}

.message-bubble ol.markdown-list {
    list-style-type: decimal !important; /* 显示数字 1. 2. 3. */
    padding-left: 2.5em !important; /* 有序列表需要更多空间来显示多位数序号 */
    /* 移除 counter-reset，让浏览器自动处理有序列表编号 */
}

.message-bubble ol.markdown-list li {
    margin-bottom: 5px;
    line-height: 1.6;
    display: list-item !important; /* 确保它是列表项模式 */
    padding-left: 0 !important; /* 有序列表项不需要额外的左边距 */
}

.message-bubble ul.markdown-list li {
    margin-bottom: 5px;
    line-height: 1.6;
    display: list-item !important; /* 确保它是列表项模式 */
    padding-left: 0 !important; /* 无序列表项不需要额外的左边距 */
}
/* 聊天气泡内的分割线 */
.message-bubble hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 15px 0;
    opacity: 0.5;
}
.message-bubble {
    /* 允许通过 CSS 稍微美化引用标注，但不改变其内容 */
}
.message-bubble p {
    /* 这里保持默认，由 AI 生成内容 */
}


/* 暗色模式适配 */
[data-theme="dark"] .message-bubble hr {
    border-top: 1px solid #444;
}

#backgroundContent {
  width: 100%;
  min-height: 200px;
  padding: 12px;
  font-size: 0.95rem;
  line-height: 1.6;
  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: 0.82rem;
  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: 600;
}

.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: 0.8rem;
  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: 0.75rem;
  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: 0.82rem;
  line-height: 1.45;
  background: transparent;
  color: var(--text-primary);
}

.mermaid-artifact-pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  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: monospace;
}

/* ========================= 知识库引用标注 ========================= */

.kb-cite {
  display: inline-block;
  color: var(--accent-color);
  font-weight: 700;
  font-size: 0.8em;
  cursor: pointer;
  vertical-align: super;
  line-height: 1;
  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;
  cursor: pointer;
  font-size: 0.85rem;
  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: 0.7rem;
  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;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  background: var(--bg-secondary);
  font-size: 0.82rem;
  transition: background 0.2s;
}
.kb-ref-header:hover {
  background: var(--bg-tertiary, rgba(0,0,0,0.04));
}

.kb-ref-num {
  font-weight: 700;
  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: 0.75rem;
  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: 0.83rem;
  line-height: 1.6;
  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: 0.72rem;
  font-weight: 600;
  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: 0.75rem;
  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: 0.72em;
  font-weight: 600;
  line-height: 1;
  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: 1;
  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;
  border-radius: 50%;
  border: 1px solid var(--border-color, #e2e8f0);
  margin-left: 3px;
  object-fit: cover;
  background: var(--bg-secondary);
  box-sizing: content-box;
  overflow: hidden;
}
.web-sources-favicons .web-sources-favicon:first-child {
  margin-left: 0;
}
.web-sources-favicon--letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  font-weight: 700;
  color: var(--text-muted);
}
.web-sources-favicon--wrap {
  position: relative;
  overflow: hidden;
}
.web-sources-favicon--wrap > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
  background: #fff;
}

.web-sources-label {
  font-size: 0.78rem;
  font-weight: 500;
  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: 1rem;
  font-weight: 600;
}
.web-search-panel-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  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--letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--bg-primary);
  color: var(--text-muted);
}
.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: 0.8rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.web-ref-date {
  font-size: 0.75rem;
  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: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 999px;
}

.web-ref-title {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  line-height: 1.4;
  margin-bottom: 6px;
}
.web-ref-title:hover {
  color: var(--accent-color);
  text-decoration: underline;
}

.web-ref-snippet {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.55;
  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: 0.85rem;
  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: 0.84rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  background: none;
  border: none;
  border-radius: 0;
}

.project-build-status-text {
  line-height: 1.4;
}

.project-build-status-spinner,
.project-build-status iconify-icon.project-build-status-spinner {
  flex-shrink: 0;
  color: var(--text-muted);
}

.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--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: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.artifact-chip-title {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.35;
  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 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.artifact-preview-close {
  font-size: 1.35rem;
  line-height: 1;
}

.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: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}

.artifact-preview-tab.is-active {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: 600;
  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: 0.78rem;
  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: 0.78rem;
  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: 600;
}

.artifact-preview-action-btn--primary:hover:not(:disabled) {
  filter: brightness(1.05);
  color: #fff;
}

.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: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  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: 0.75rem;
  font-weight: 600;
  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: 0.8rem;
  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: 0.8rem;
  font-weight: 600;
  color: var(--accent-color);
}

.artifact-preview-visual-sync {
  margin-left: 6px;
  font-weight: 500;
  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;
}

/* Legacy 子页全屏布局（shell 内 flex 分配内容区 + 版权栏） */
.legacy-page-shell {
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

.legacy-page-view {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* SPA 子页：挂载层 → 侧栏纵向撑满，账号区贴底 */
body.kb-page .legacy-page-host,
body.agent-page .legacy-page-host {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

body.kb-page .legacy-page-host .legacy-page-content,
body.agent-page .legacy-page-host .legacy-page-content {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  width: 100%;
}

body.kb-page .legacy-page-host .app-container,
body.agent-page .legacy-page-host .app-container {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  display: flex;
  overflow: hidden;
  visibility: visible !important;
}

body.kb-page .legacy-page-host .sidebar,
body.agent-page .legacy-page-host .sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  align-self: stretch;
}

body.kb-page .legacy-page-host .sidebar-header,
body.agent-page .legacy-page-host .sidebar-header,
body.kb-page .legacy-page-host .search-sort-row,
body.agent-page .legacy-page-host .search-sort-row {
  flex: 0 0 auto;
}

/* 子页侧栏：列表撑满、账号贴底（覆盖 .sidebar-footer 174px 固定高度） */
body.kb-page .legacy-page-host .sidebar-footer,
body.agent-page .legacy-page-host .sidebar-footer {
  flex: 0 0 auto;
  min-height: unset;
  justify-content: flex-end;
  margin-top: auto;
}

body.kb-page .legacy-page-host #kbList.chat-list,
body.agent-page .legacy-page-host #agentList.chat-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 10px 12px;
}

/* 子页侧栏列表：与主页 #chatList 标题/副文案样式一致 */
body.kb-page .legacy-page-host .sidebar .chat-list .chat-item,
body.agent-page .legacy-page-host .sidebar .chat-list .chat-item {
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 2px;
  color: var(--text-primary);
  font-family: inherit;
  line-height: inherit;
}

body.kb-page .legacy-page-host .sidebar .chat-list .chat-item-title,
body.agent-page .legacy-page-host .sidebar .chat-list .chat-item-title {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: inherit;
}

body.kb-page .legacy-page-host .sidebar .chat-list .chat-item.active .chat-item-title,
body.agent-page .legacy-page-host .sidebar .chat-list .chat-item.active .chat-item-title {
  font-weight: 600;
}

body.kb-page .legacy-page-host .sidebar .chat-list .chat-item-date,
body.kb-page .legacy-page-host .sidebar .chat-list .chat-item-sub,
body.kb-page .legacy-page-host .sidebar .chat-list .chat-item-snippet,
body.agent-page .legacy-page-host .sidebar .chat-list .chat-item-date,
body.agent-page .legacy-page-host .sidebar .chat-list .chat-item-snippet {
  font-size: 0.72rem;
  font-weight: 400;
  opacity: 0.72;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.kb-page .legacy-page-host .sidebar .chat-list .chat-item.active .chat-item-date,
body.kb-page .legacy-page-host .sidebar .chat-list .chat-item.active .chat-item-snippet,
body.agent-page .legacy-page-host .sidebar .chat-list .chat-item.active .chat-item-date,
body.agent-page .legacy-page-host .sidebar .chat-list .chat-item.active .chat-item-snippet {
  opacity: 0.88;
  color: var(--text-secondary);
}

.legacy-page-host {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.legacy-page-host > .legacy-page-content,
.legacy-page-shell .legacy-page-host .legacy-page-content {
  min-height: 0;
  height: 100%;
}

.legacy-page-host > .app-container,
.legacy-page-shell .legacy-page-host .app-container {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.legacy-page-host .app-container {
  visibility: visible !important;
}

/* 可视化编辑：全屏覆盖，便于在页面上直接编辑 */
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: 0.8rem;
  line-height: 1.5;
  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: 0.88rem;
  }

  /* 操作按钮固定在第一行最右（「在新窗口打开」靠右） */
  .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: 0.72rem;
    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: 1rem;
}
.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: 0.9rem;
}
.published-projects-meta {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary, #6b7280);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.published-projects-actions {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
}
.published-projects-empty {
  margin: 0;
  color: var(--text-secondary, #6b7280);
  font-size: 0.9rem;
  text-align: center;
  padding: 24px 0;
}

.profile-center-tabs {
  display: flex;
  gap: 4px;
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--border-color);
}

.profile-center-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.profile-center-tab:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.profile-center-tab.active {
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent-color);
  font-weight: 500;
}

.profile-projects-body {
  max-height: min(50vh, 420px);
  overflow-y: auto;
}

.profile-projects-list {
  margin: 0;
}

.profile-projects-hint {
  margin: 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 24px 0;
}

.profile-projects-error {
  color: var(--danger-color);
}
.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: 0.88rem;
  cursor: pointer;
}

/* ===== 移动端工具菜单（+ 弹出 action sheet）===== */
/* + 按钮默认隐藏（桌面端原按钮照常平铺），仅移动端显示 */
.mobile-tool-more-btn { display: none; }

@media (max-width: 768px) {
  /* 输入栏：除模型选择外的功能按钮收进 + 菜单，避免窄屏溢出 */
  #attachMenuWrap,
  #searchToggleBtn,
  #kbToggleBtn,
  #componentMenuWrap,
  #memoryMenuWrap { display: none !important; }
  .mobile-tool-more-btn { display: inline-flex; }
}

/* 底部弹出菜单（action sheet）：一级 / 二级共用，参考 iOS 风格 */
.mobile-sheet-mask {
  position: fixed;
  inset: 0;
  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%;
  max-width: 480px;
  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-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: 16px;
  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-ico {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--text-secondary);
}
.mobile-sheet-label { flex: 1; }
.mobile-sheet-tail {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
.mobile-sheet-tail.on { color: var(--accent-color); }
.mobile-sheet-arrow { font-size: 20px; line-height: 1; color: var(--text-muted); }
.mobile-sheet-check { color: var(--accent-color); font-weight: 700; font-size: 16px; }
.mobile-sheet-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent-color);
  color: #fff;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.mobile-sheet-back {
  color: var(--text-secondary);
  font-size: 14px;
  gap: 6px;
  font-weight: 600;
}
.mobile-sheet-cancel {
  display: block;
  width: 100%;
  padding: 16px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-color);
  cursor: pointer;
}
.mobile-sheet-empty {
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  cursor: default;
}
/* 记忆设置二级：开关行 + 数值行 */
.mobile-sheet-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-color);
  font-size: 15px;
  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: 14px;
}
.mobile-sheet-num {
  width: 76px;
  padding: 6px 10px;
  text-align: right;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 15px;
  background: var(--chat-main-bg);
  color: var(--text-primary);
}
.mobile-sheet-unit { color: var(--text-muted); font-size: 13px; 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: 0.92rem;
}
.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 { width: 20px; height: 20px; }
.model-vendor-name { font-weight: 500; 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: 0.9rem; 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: 600; 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; }

/* 模型 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: 0.82rem; }
.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: 16px; height: 16px; border: 0; border-radius: 50%; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 0.95rem; line-height: 1; }
.model-chip-del:hover { background: var(--danger-color, #dc2626); color: #fff; }
.model-chips-empty { font-size: 0.82rem; 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: 0.78rem; }

/* 连通性检查 */
.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: 0.82rem; 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: 600; font-size: 0.9rem; 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: 600; font-size: 0.9rem; cursor: pointer; }
.param-toggle input { cursor: pointer; }
.param-key { font-size: 0.72rem; background: var(--bg-secondary); color: var(--text-muted); padding: 1px 6px; border-radius: 5px; font-family: ui-monospace, "SFMono-Regular", monospace; }
.param-desc { grid-column: 1; font-size: 0.78rem; color: var(--text-muted); line-height: 1.45; }
.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; }

/* 同步设置：自动同步说明（取消开关后，告知用户已实时同步） */
.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: 0.82rem;
  line-height: 1.5;
}
