/* ================= 聊天主界面样式 ================= */

#app {
  display: flex;
  height: 100vh;
  background: var(--ground, #fefefe);
}

/* ---- 侧栏 ---- */
#sidebar {
  position: relative;
  width: 240px;
  min-width: 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 0 8px;
  overflow: hidden;
  visibility: visible;
  opacity: 1;
  transform: translateX(0);
  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1), padding 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.18s ease, transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s;
}
#sidebar > * {
  min-width: 224px;
}
#app.sidebar-collapsed #sidebar {
  width: 0;
  padding: 0;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-12px);
  transition-delay: 0s, 0s, 0s, 0s, 0.28s;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 0 0 6px;
}

.brand-logo {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.sb-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
}
.sb-icon-btn:hover {
  background: var(--icon-hover-bg, rgba(0, 0, 0, 0.03));
  color: var(--text, rgba(0, 0, 0, 0.9));
}
.sb-icon-btn svg {
  width: 20px;
  height: 20px;
}

.sidebar-top {
  padding: 2px 0 6px;
}

.new-session-btn {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  background: #fff;
  font-size: 14px;
  color: var(--text, rgba(0, 0, 0, 0.9));
  cursor: pointer;
}
.new-session-btn:hover {
  background: #fff;
  border-color: rgba(0, 0, 0, 0.14);
}
.new-session-btn .icon {
  width: 18px;
  height: 18px;
}
.new-session-btn .nb-plus {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.3s;
}
.new-session-btn:hover .nb-plus {
  transform: rotate(90deg);
}
.new-session-btn .kbd {
  margin-left: auto;
  display: inline-flex;
  gap: 3px;
}
.new-session-btn kbd {
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.04);
  font-family: inherit;
  font-size: 12px;
  line-height: 20px;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
  text-align: center;
}

/* 项目 + 对话滚动区 */
#sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -8px;
  padding: 0 8px 28px;
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 40px), transparent);
}
.sb-section-title {
  padding: 16px 8px 4px;
  font-size: 13px;
  line-height: 20px;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
  user-select: none;
}

.sb-item, .work-item, .session-item {
  box-sizing: border-box;
  width: 100%;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-size: 14px;
  color: var(--text, rgba(0, 0, 0, 0.9));
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s;
}
.sb-item:hover, .work-item:hover, .session-item:hover {
  background: var(--sb-hover, rgba(0, 0, 0, 0.04));
}
.work-item.active, .session-item.active {
  background: var(--sb-active, rgba(0, 0, 0, 0.06));
}
.sb-ic {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: rgba(0, 0, 0, 0.75);
}

#new-work-btn {
  margin-bottom: 2px;
}

#works {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.work-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.work-badge {
  flex-shrink: 0;
  height: 18px;
  padding: 0 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.045);
  font-size: 11px;
  line-height: 18px;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
}
.work-size {
  display: none;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
}
.work-item:hover .work-size {
  display: inline;
}
.work-del {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-right: -4px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
}
.work-item:hover .work-del,
.work-item:focus-within .work-del,
.session-item:hover .work-del,
.session-item:focus-within .work-del {
  display: inline-flex;
}
.session-del {
  display: inline-flex;
  opacity: 0;
}
.session-item:hover .session-del,
.session-item:focus-within .session-del {
  opacity: 1;
}
@media (hover: none) {
  .session-del { opacity: 1; }
}
.work-del:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--danger, #FF3849);
}
.work-del svg {
  width: 14px;
  height: 14px;
}

#session-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.session-item .session-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item .session-time {
  display: none;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
}
.session-item:hover .session-time {
  display: inline;
}
.session-status {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  gap: 6px;
}
.session-running {
  width: 12px;
  height: 12px;
  border: 1.5px solid rgba(0, 0, 0, 0.12);
  border-top-color: var(--text-dim);
  border-radius: 50%;
}
.session-attention {
  padding: 0 6px;
  border-radius: 4px;
  background: var(--notice-bg);
  color: var(--warn);
  font-size: 12px;
  line-height: 20px;
}
.session-unread {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
}
@keyframes session-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: no-preference) {
  .session-running { animation: session-spin 1s linear infinite; }
}

/* ---- 侧栏底部：积分卡 + 用户行 ---- */
.sidebar-footer {
  position: relative;
  padding: 6px 0 10px;
}

.points-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  padding: 8px 8px 8px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.04);
  color: var(--text, rgba(0, 0, 0, 0.9));
  text-decoration: none;
  transition: background-color 0.15s;
}

.points-card:hover {
  background: rgba(0, 0, 0, 0.06);
}
.pc-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: rgba(0, 0, 0, 0.75);
}
.pc-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.pc-title {
  font-size: 14px;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pc-sub {
  font-size: 12px;
  line-height: 16px;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
}
.pc-arrow {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
}
.points-card.negative .pc-title {
  color: var(--danger, #FF3849);
}

/* ---- 版本更新入口 ---- */
.update-card .pc-icon {
  color: var(--admin-green, #2fb36d);
}
.update-card .pc-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 8px;
  border-radius: 12px;
  font-size: 14px;
  color: var(--text, rgba(0, 0, 0, 0.9));
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s;
}
.user-chip:hover, .user-chip.open {
  background: rgba(0, 0, 0, 0.05);
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
}
.user-chip #user-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-badge {
  flex-shrink: 0;
  padding: 0 5px;
  border-radius: 4px;
  background: #111;
  color: #fff;
  font-size: 12px;
  line-height: 19px;
}
.user-badge:empty {
  display: none;
}
.uc-caret {
  width: 16px;
  height: 16px;
  margin-left: auto;
  flex-shrink: 0;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
}

.user-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 58px;
  z-index: 60;
  padding: 6px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 16px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.04);
  transform-origin: bottom center;
  animation: pop-in 0.14s ease-out;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.um-item {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-size: 14px;
  color: var(--text, rgba(0, 0, 0, 0.9));
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.um-item:hover {
  background: rgba(0, 0, 0, 0.04);
}
.um-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.um-item .um-caret {
  width: 16px;
  height: 16px;
  margin-left: auto;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
}

/* ---- 主区域 ---- */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background: var(--bg, #ffffff);
  margin: 8px 8px 8px 0;
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 12px;
  overflow: hidden;
  transition: margin 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
#app.sidebar-collapsed #main {
  margin-left: 8px;
}
@media (prefers-reduced-motion: reduce) {
  #sidebar, #main { transition: none; }
}

#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  flex-shrink: 0;
  padding: 0 16px;
  background: var(--bg, #ffffff);
}
#expand-sidebar {
  display: none;
  margin-left: -6px;
}
#app.sidebar-collapsed #expand-sidebar {
  display: inline-flex;
}

#breadcrumb {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#session-title {
  color: var(--text, rgba(0, 0, 0, 0.9));
}

.conn-dot {
  display: none;
}

#messages {
  flex: 1;
  overflow-y: auto;
  /* 滚动条槽位常驻：折叠/展开改变内容高度时正文列宽不变，避免重新换行 */
  scrollbar-gutter: stable;
  padding: 20px max(24px, calc((100% - var(--content-max, 780px)) / 2)) calc(64px + var(--plan-h, 0px));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* 空会话首页 */
#hero {
  display: none;
}
#main.is-empty #breadcrumb {
  visibility: hidden;
}
#main:has(.msg-skeleton) #breadcrumb {
  visibility: hidden;
}
#main.is-empty #messages {
  flex: 1 1 0;
  min-height: 0;
  padding-bottom: 12px;
  justify-content: flex-end;
}
#main.is-empty #input-area {
  flex: 2.2 1 0;
  padding-top: 0;
}
#main.is-empty #input-area::before,
#main.is-empty #plan-dock {
  display: none;
}
#main.is-empty #hero {
  display: block;
}

#hero {
  margin: 0 0 30px;
  text-align: center;
  font: 600 40px/1.1 "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0.14em;
  margin-right: -0.14em;
  color: #111;
  user-select: none;
}

.load-more {
  flex-shrink: 0;
  align-self: center;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  background: var(--panel, #ffffff);
  border-radius: 999px;
  padding: 4px 14px;
  cursor: pointer;
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
  font-size: var(--fs-sm, 16px);
}
.load-more:hover {
  color: var(--text, rgba(0, 0, 0, 0.9));
}

/* ---- 消息流节点 ---- */
.msg {
  flex-shrink: 0;
  word-break: break-word;
  line-height: 1.7;
}

.msg-skeleton {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-spinner {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    rgba(0, 0, 0, 0) 0deg,
    rgba(0, 0, 0, 0.06) 90deg,
    rgba(0, 0, 0, 0.14) 175deg,
    rgba(0, 0, 0, 0.26) 240deg,
    rgba(0, 0, 0, 0.40) 290deg,
    rgba(0, 0, 0, 0.48) 320deg,
    rgba(0, 0, 0, 0.36) 338deg,
    rgba(0, 0, 0, 0.16) 351deg,
    rgba(0, 0, 0, 0) 360deg
  );
  -webkit-mask-image: radial-gradient(farthest-side, transparent calc(100% - 4.2px), #000 calc(100% - 3.4px));
  mask-image: radial-gradient(farthest-side, transparent calc(100% - 4.2px), #000 calc(100% - 3.4px));
  position: relative;
  /* 位于消息区可视中线偏下 */
  top: 64px;
  animation: spin 0.9s linear infinite;
}

.msg.user {
  align-self: flex-end;
  max-width: 82%;
  padding: 10px 16px;
  background: var(--active-bg, #f5f5f5);
  border-radius: 18px;
  white-space: pre-wrap;
}

.msg.assistant {
  align-self: stretch;
  width: 100%;
}
.msg.assistant .answer {
  font-size: var(--fs-md, 16px);
  line-height: 1.75;
}

.msg.system {
  align-self: center;
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
  font-size: var(--fs-sm, 16px);
  text-align: center;
  white-space: pre-wrap;
}
.msg.system.error {
  color: var(--danger, #FF3849);
}

.pending-indicator {
  flex-shrink: 0;
  align-self: flex-start;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
  font-size: var(--fs-sm, 16px);
  animation: pending-breathe 1.2s ease-in-out infinite;
}
@keyframes pending-breathe {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

/* ---- 代码块卡片 ---- */
.markdown-body .code-block,
.code-block {
  position: relative;
  margin: 12px 0;
  background: var(--bg, #ffffff);
  border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  border-radius: 12px;
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 38px;
  padding: 0 14px 0 16px;
  background: var(--surface, #f5f5f5);
  user-select: none;
}

.code-lang {
  font-size: 14px;
  font-weight: 500;
  color: var(--text, rgba(0, 0, 0, 0.9));
}

.code-copy {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
  cursor: pointer;
  opacity: 1;
  position: static;
  transition: background-color 0.15s, color 0.15s;
}

.code-copy:hover {
  background: var(--icon-hover-bg, rgba(0, 0, 0, 0.03));
  color: var(--text, rgba(0, 0, 0, 0.9));
}

.code-copy .icon {
  grid-area: 1 / 1;
  width: 20px;
  height: 20px;
  pointer-events: none;
}

.code-copy .icon-copy {
  opacity: 1;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1) 0.25s;
}

.code-copy .icon-tick {
  opacity: 0;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1) 0s;
}

.code-copy.copied .icon {
  transition: none;
}

.code-copy.copied .icon-copy {
  opacity: 0;
}

.code-copy.copied .icon-tick {
  opacity: 1;
}

.markdown-body .code-block pre,
.code-block pre,
#messages .code-block pre {
  margin: 0;
  padding: 14px 18px 24px;
  background: var(--bg, #ffffff);
  border: none;
  border-radius: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

.markdown-body .code-block pre::-webkit-scrollbar,
.code-block pre::-webkit-scrollbar,
#messages .code-block pre::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  background: transparent !important;
}

.markdown-body .code-block pre::-webkit-scrollbar-track,
.code-block pre::-webkit-scrollbar-track,
#messages .code-block pre::-webkit-scrollbar-track {
  display: none !important;
  background: transparent !important;
}

.markdown-body .code-block pre::-webkit-scrollbar-thumb,
.code-block pre::-webkit-scrollbar-thumb,
#messages .code-block pre::-webkit-scrollbar-thumb,
.markdown-body .code-block pre::-webkit-scrollbar-thumb:hover,
.code-block pre::-webkit-scrollbar-thumb:hover,
#messages .code-block pre::-webkit-scrollbar-thumb:hover {
  display: none !important;
  background: transparent !important;
}

.code-scrollbar {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 5px;
  height: 14px;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  transition: opacity 0.15s ease;
}

.code-block.has-scroll .code-scrollbar {
  opacity: 1;
  pointer-events: auto;
}

.code-scrollbar-thumb {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 4px;
  background-color: rgba(0, 0, 0, 0.18);
  border-radius: 5px;
  pointer-events: auto;
  cursor: pointer;
  transition: height 0.16s ease-out, background-color 0.16s ease-out;
}

.code-scrollbar:hover .code-scrollbar-thumb,
.code-scrollbar-thumb:hover,
.code-scrollbar-thumb.is-dragging {
  height: 10px;
  background-color: rgba(0, 0, 0, 0.55);
}

.markdown-body .code-block pre code,
.code-block pre code,
.code-block pre code.hljs {
  display: block;
  overflow: visible !important;
  font-family: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "PingFang SC", "Microsoft YaHei", monospace;
  font-size: var(--markdown-code-font-size, 14px);
  line-height: var(--markdown-code-line-height, 22px);
  background: transparent !important;
  padding: 0 !important;
  color: var(--text, rgba(0, 0, 0, 0.9));
  white-space: pre;
}

.code-block pre code::-webkit-scrollbar,
.code-block pre code::-webkit-scrollbar-track,
.code-block pre code::-webkit-scrollbar-thumb,
.code-block pre code::-webkit-scrollbar-thumb:hover {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  background: transparent !important;
}

/* 图标样式 */
.icon {
  display: inline-flex;
  width: var(--ic-md, 20px);
  height: var(--ic-md, 20px);
  flex-shrink: 0;
}
.icon svg {
  width: 100%;
  height: 100%;
}
.icon.caret {
  width: var(--ic-sm, 16px);
  height: var(--ic-sm, 16px);
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
  transition: transform 0.15s;
}

/* ---- 折叠动效：grid 行高过渡 + 内容渐显 ---- */
.fold-clip { overflow: hidden; min-height: 0; }

/* 工作分组与回合折叠：时长随内容高度自适应（--fold-duration 由 JS 写入） */
.work-body, .turn-fold-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--fold-duration, 300ms) cubic-bezier(0.2, 0.8, 0.25, 1);
}
.work-group.expanded > .work-body,
.work-group.live > .work-body,
.turn-fold.expanded > .turn-fold-wrap { grid-template-rows: 1fr; }

.work-items, .turn-fold-content {
  opacity: 0;
  transition: opacity calc(var(--fold-duration, 300ms) * 0.45) ease;
}
.work-group.expanded > .work-body .work-items,
.work-group.live > .work-body .work-items,
.turn-fold.expanded .turn-fold-content { opacity: 1; }

.work-group .caret, .turn-fold-head .caret {
  transition: transform var(--fold-duration, 300ms) cubic-bezier(0.2, 0.8, 0.25, 1), color 0.15s;
}
.work-group.no-anim .work-body,
.work-group.no-anim .work-items { transition: none; }

/* 思考区与工具卡片：高度过渡 + 淡出微位移，不带模糊 */
.thinking-body, .tool-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s cubic-bezier(0.2, 0.8, 0.25, 1);
}
.thinking.expanded .thinking-body,
.tool-card.expanded .tool-body { grid-template-rows: 1fr; }
.thinking-text, .tool-content {
  transition:
    opacity 0.26s cubic-bezier(0.2, 0.8, 0.25, 1),
    transform 0.32s cubic-bezier(0.2, 0.8, 0.25, 1);
}
.thinking:not(.expanded) .thinking-text,
.tool-card:not(.expanded) .tool-content {
  opacity: 0;
  transform: translateY(-4px);
}

/* ---- 工作过程分组 ---- */
.work-group {
  flex-shrink: 0;
  align-self: stretch;
}
.work-header {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  min-height: 30px;
  padding: 4px 0;
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-sm, 16px);
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
}
.work-header:hover { color: var(--text, rgba(0, 0, 0, 0.9)); }
.work-header:hover .caret { color: var(--text-dim, rgba(0, 0, 0, 0.6)); }
.work-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.work-group.has-error .work-summary { color: var(--danger, #FF3849); }
.work-group.expanded > .work-header .caret { transform: rotate(90deg); }
.work-group.live .work-icon { animation: spin 2.4s linear infinite; color: var(--text, rgba(0, 0, 0, 0.9)); }
@keyframes spin { to { transform: rotate(360deg); } }

.work-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0 0;
}
.work-group.live > .work-header { display: none; }
.work-group.live .work-items { margin: 0; }

/* ---- 思考区 ---- */
.thinking { font-size: var(--fs-sm, 16px); }
.thinking-header {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 4px 0;
  cursor: pointer;
  user-select: none;
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
}
.thinking-header:hover { color: var(--text, rgba(0, 0, 0, 0.9)); }
.thinking-header:hover .caret { color: var(--text-dim, rgba(0, 0, 0, 0.6)); }
.thinking-icon { color: var(--text-dim, rgba(0, 0, 0, 0.6)); }
.thinking.expanded .thinking-header .caret { transform: rotate(90deg); }
.thinking-text {
  margin: 2px 0 6px 7.5px;
  padding: 2px 0 2px 14px;
  border-left: 1px dashed rgba(0, 0, 0, 0.18);
  font-size: var(--fs-sm, 16px);
  line-height: calc(22 / 14);
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 360px;
  overflow-y: auto;
}

/* ---- 工具卡片 ---- */
.tool-card { flex-shrink: 0; align-self: stretch; }
.tool-header {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 7px;
  min-width: 0;
  min-height: 30px;
  padding: 4px 0;
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-sm, 16px);
  line-height: 1.5;
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
}
.tool-header:hover { color: var(--text, rgba(0, 0, 0, 0.9)); }
.tool-header:hover .caret { color: var(--text-dim, rgba(0, 0, 0, 0.6)); }
.tool-icon { color: var(--text-faint, rgba(0, 0, 0, 0.45)); }
.tool-header:hover .tool-icon { color: var(--text-dim, rgba(0, 0, 0, 0.6)); }
.tool-verb { flex-shrink: 0; }
.tool-target {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: inherit;
}
.tool-stats {
  display: inline-flex;
  gap: 5px;
  flex-shrink: 0;
  font-family: ui-monospace, Consolas, monospace;
  font-size: var(--fs-sm, 16px);
}
.tool-stats:empty { display: none; }
.stat-add { color: var(--diff-add-text, #0e7a38); }
.stat-del { color: var(--diff-del-text, #FF3849); }
.tool-card .caret { opacity: 0; }
.tool-header:hover .caret, .tool-card.expanded .caret { opacity: 1; }
.tool-card.expanded .caret { transform: rotate(90deg); }

.tool-status { flex-shrink: 0; font-size: var(--fs-sm, 16px); }
.tool-status.running {
  width: var(--ic-sm, 16px);
  height: var(--ic-sm, 16px);
  border: 1.5px solid rgba(0, 0, 0, 0.12);
  border-top-color: var(--text-dim, rgba(0, 0, 0, 0.6));
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.tool-status.error { color: var(--danger, #FF3849); }
.tool-card.error .tool-icon { color: var(--danger, #FF3849); }
.tool-pending-label {
  flex-shrink: 0;
  font-size: var(--fs-sm, 16px);
  color: var(--warn, #a9610a);
  background: rgba(169, 97, 10, 0.1);
  border-radius: 999px;
  padding: 1px 8px;
}
.tool-content { padding: 4px 0 8px; }

pre.tool-args, pre.tool-result, pre.tool-diff {
  margin: 4px 0;
  padding: 8px 10px;
  background: var(--code-bg, #f5f5f5);
  border-radius: 8px;
  font-family: ui-monospace, Consolas, "PingFang SC", "Microsoft YaHei", monospace;
  font-size: var(--fs-sm, 16px);
  line-height: calc(22 / 14);
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}
pre.tool-args:empty { display: none; }
pre.tool-result.error { background: var(--diff-del-bg, rgba(192, 57, 43, 0.07)); color: var(--danger, #FF3849); }

.diff .diff-add { background: var(--diff-add-bg, rgba(14, 122, 56, 0.08)); color: var(--diff-add-text, #0e7a38); display: block; }
.diff .diff-del { background: var(--diff-del-bg, rgba(192, 57, 43, 0.07)); color: var(--diff-del-text, #FF3849); display: block; }

.tool-card.has-file pre.tool-args,
.tool-card.has-file pre.tool-diff,
.tool-card.has-file pre.tool-result:not(.error) { display: none; }

.tool-target.file { display: inline-flex; gap: 6px; font-family: inherit; }
.tt-name { color: var(--text, rgba(0, 0, 0, 0.9)); }
.tt-meta { color: var(--text-faint, rgba(0, 0, 0, 0.45)); }
.tt-name, .tt-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- 回合折叠：只留最终回答 ---- */
.turn-fold {
  flex-shrink: 0;
  align-self: stretch;
  border-bottom: 1px solid var(--border-soft, rgba(0, 0, 0, 0.05));
}
.turn-fold-head {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  min-height: 30px;
  padding: 4px 0 14px;
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-sm, 16px);
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
}
.turn-fold-head:hover { color: var(--text, rgba(0, 0, 0, 0.9)); }
.turn-fold-head:hover .caret { color: var(--text-dim, rgba(0, 0, 0, 0.6)); }
.turn-fold-summary {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.turn-fold > .turn-fold-head .caret { opacity: 0; }
.turn-fold-head:hover .caret, .turn-fold.expanded > .turn-fold-head .caret { opacity: 1; }
.turn-fold.expanded > .turn-fold-head .caret { transform: rotate(90deg); }
.turn-fold-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 2px 0 10px;
}

/* 文件卡片视图 */
.file-view {
  margin-top: 2px;
  background: var(--color-surface, #f5f5f5);
  border-radius: 12px;
  overflow: hidden;
}
.fv-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 40px;
  padding: 0 8px 0 16px;
  font-size: var(--fs-sm, 16px);
}
.fv-dir { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-faint, rgba(0, 0, 0, 0.45)); }
.fv-name { flex-shrink: 0; white-space: nowrap; color: var(--text, rgba(0, 0, 0, 0.9)); }
.fv-dir + .fv-name { margin-left: -8px; }
.fv-copy {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.fv-copy:hover {
  background: var(--icon-hover-bg, rgba(0, 0, 0, 0.03));
  color: var(--text, rgba(0, 0, 0, 0.9));
}
.fv-copy .icon {
  grid-area: 1 / 1;
  width: var(--ic-sm, 16px);
  height: var(--ic-sm, 16px);
  pointer-events: none;
}
.fv-copy .icon-copy {
  opacity: 1;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1) 0.25s;
}
.fv-copy .icon-tick {
  opacity: 0;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1) 0s;
}
.fv-copy.copied .icon {
  transition: none;
}
.fv-copy.copied .icon-copy { opacity: 0; }
.fv-copy.copied .icon-tick { opacity: 1; }

.fv-body {
  max-height: 320px;
  overflow: auto;
}
.fv-lines {
  display: table;
  min-width: 100%;
  padding: 0 0 10px;
  font-family: ui-monospace, "JetBrains Mono", Consolas, "PingFang SC", "Microsoft YaHei", monospace;
  font-size: var(--fs-sm, 16px);
  line-height: calc(22 / 14);
}
.fv-row { display: table-row; }
.fv-row > span { display: table-cell; white-space: pre; }
.fv-no, .fv-sign {
  width: 1%;
  text-align: right;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
  user-select: none;
}
.fv-no { padding: 0 16px 0 16px; min-width: 2ch; }
.fv-sign { padding: 0 12px 0 14px; }
.fv-text { padding-right: 16px; color: var(--text, rgba(0, 0, 0, 0.9)); }
.fv-row.add { background: rgba(22, 196, 86, 0.1); }
.fv-row.add .fv-sign { color: var(--success, #0e7a38); }
.fv-row.del { background: rgba(255, 77, 77, 0.1); }
.fv-row.del .fv-sign { color: var(--danger, #FF3849); }
.fv-row.gap > span { color: var(--text-faint, rgba(0, 0, 0, 0.45)); }
.fv-note { padding: 0 16px 10px; font-size: var(--fs-sm, 16px); color: var(--text-faint, rgba(0, 0, 0, 0.45)); }


/* ---- 计划区 ---- */
#input-area { position: relative; }
#input-area::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 80px;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.02) 25%,
    rgba(255, 255, 255, 0.08) 45%,
    rgba(255, 255, 255, 0.20) 65%,
    rgba(255, 255, 255, 0.42) 80%,
    rgba(255, 255, 255, 0.70) 92%,
    rgba(255, 255, 255, 0.90) 97%,
    var(--bg, #ffffff) 100%
  );
  pointer-events: none;
  z-index: 1;
}
#plan-dock {
  position: absolute;
  left: max(24px, calc((100% - var(--content-max, 780px)) / 2));
  right: max(24px, calc((100% - var(--content-max, 780px)) / 2));
  bottom: calc(100% + 8px);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}
#plan-panel, #plan-pill {
  pointer-events: auto;
}
#plan-panel {
  width: 100%;
  background: rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  backdrop-filter: blur(24px) saturate(1.8);
  border: 0.5px solid rgba(0, 0, 0, 0.13);
  border-radius: 20px;
  padding: 18px 6px 20px 20px;
  max-height: min(300px, 50vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}
#plan-header {
  flex-shrink: 0;
  padding-right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: var(--fs-md, 16px);
  font-weight: 500;
  color: var(--text, rgba(0, 0, 0, 0.9));
}
.plan-head-icon { display: block; width: var(--ic-md, 20px); height: var(--ic-md, 20px); flex-shrink: 0; }
#plan-progress {
  margin-left: 2px;
  font-size: var(--fs-sm, 16px);
  font-weight: 400;
  color: rgba(0, 0, 0, 0.5);
  font-variant-numeric: tabular-nums;
}
#plan-panel.all-done #plan-progress { color: var(--success, #0e7a38); }
.plan-caret {
  display: inline-flex;
  width: var(--ic-sm, 16px);
  height: var(--ic-sm, 16px);
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
  opacity: 0;
  transform: rotate(90deg);
  transition: transform 0.15s, opacity 0.15s;
}
#plan-header:hover .plan-caret { opacity: 1; }
.plan-caret svg { width: 100%; height: 100%; }

#plan-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 18px;
  padding: 4px 8px;
  border: none;
  border-radius: 10px;
  background: #f7f7f7;
  color: var(--text, rgba(0, 0, 0, 0.9));
  font-size: var(--fs-sm, 16px);
  line-height: 20px;
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  transition: background 0.16s cubic-bezier(0.16, 1, 0.3, 1);
}
#plan-pill:hover { background: #f0f0f0; }
#plan-pill:active { background: #e8e8e8; }
#plan-pill:focus-visible { box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08); }
#plan-pill .plan-head-icon { color: rgba(0, 0, 0, 0.65); }
#plan-pill-count {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.55);
}

#plan-items {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
  margin: 16px 0 0;
  padding: 0 14px 0 0;
  list-style: none;
  overflow-y: auto;
}
#plan-items li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: var(--fs-sm, 16px);
  line-height: 1.4;
  color: var(--text, rgba(0, 0, 0, 0.9));
}
.plan-text { min-width: 0; }

.plan-mark {
  flex-shrink: 0;
  box-sizing: border-box;
  width: 16px;
  height: 16px;
  border: 1.5px solid rgba(0, 0, 0, 0.18);
  border-radius: 50%;
}
#plan-items li.in_progress .plan-mark {
  border-color: rgba(0, 0, 0, 0.18);
  border-top-color: rgba(0, 0, 0, 0.6);
  animation: spin 1s linear infinite;
}
#plan-items li.completed .plan-mark { border: none; border-radius: 0; color: var(--success, #0e7a38); }
.plan-mark svg { display: block; width: 100%; height: 100%; }

/* ---- 输入区 ---- */
#input-area {
  padding: 0 24px 20px;
  background: var(--bg, #ffffff);
}

#context-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: var(--content-max, 780px);
  margin: 0 auto 8px;
  min-height: 20px;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
  font-size: 13px;
  line-height: 20px;
}
#context-status.hidden { display: none; }
#context-status .spinner {
  width: 14px;
  height: 14px;
}
#context-status.done .spinner { display: none; }

#input-card {
  max-width: var(--content-max, 780px);
  margin: 0 auto;
  background: var(--panel, #ffffff);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 24px;
  padding: 14px 14px 10px 18px;
  box-shadow: rgba(0, 0, 0, 0.07) 0px 5px 16px -4px;
  transition: 0.3s;
  position: relative;
  z-index: 1;
}
#input-card:focus-within {
  border-color: rgba(0, 0, 0, 0.16);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
}

#input {
  width: 100%;
  min-height: 48px;
  border: none;
  background: transparent;
  padding: 2px 0;
  font: inherit;
  font-size: var(--fs-md, 16px);
  line-height: 1.6;
  color: var(--text, rgba(0, 0, 0, 0.9));
  max-height: 180px;
  overflow-y: auto;
  outline: none;
  cursor: text;
  white-space: pre-wrap;
  word-break: break-word;
}
#input.is-empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
  pointer-events: none;
  position: absolute;
}

#input-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 6px;
}

#input-tray {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(var(--content-max, 780px) - 36px);
  margin: -18px auto 0;
  padding: 24px 16px 8px;
  border-radius: 0 0 18px 18px;
  background: var(--surface, #f5f5f5);
  font-size: 13px;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
}
#input-card.hidden ~ #input-tray { display: none; }
.tray-item { display: inline-flex; align-items: center; gap: 6px; min-width: 0; line-height: 20px; }
.tray-item svg { width: 15px; height: 15px; flex-shrink: 0; }
#input-ws-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#input-ws-name:empty::before, #model-name:empty::before {
  content: "";
  display: inline-block;
  width: 64px;
  height: 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.05);
  vertical-align: middle;
  animation: sk-pulse 1.6s ease-in-out infinite;
}
#model-name:empty::before { width: 72px; }
.tray-conn { flex-shrink: 0; }
.tray-conn:has(.conn-dot.disconnected) { color: var(--text-dim, rgba(0, 0, 0, 0.6)); }
#reconnect-btn {
  padding: 0 4px;
  background: transparent;
  color: var(--link);
  font: inherit;
  text-decoration: none;
}
#reconnect-btn:hover { color: var(--text); }

/* 上下文用量 */
#usage {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 32px;
  cursor: default;
}
#usage svg { width: 16px; height: 16px; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: rgba(0, 0, 0, 0.08); stroke-width: 3; }
.ring-prog {
  fill: none;
  stroke: var(--text-dim, rgba(0, 0, 0, 0.6));
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 56.5;
  stroke-dashoffset: 56.5;
  transition: stroke-dashoffset 0.3s;
}
#usage-tip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
#usage:hover #usage-tip { opacity: 1; }
#input-toolbar:has(#model-pill.open) #usage-tip { display: none; }

#model-pill { position: relative; min-width: 0; }
#model-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(320px, calc(100vw - 132px));
  height: 32px;
  border: none;
  border-radius: 999px;
  padding: 0 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.15s;
}
#model-btn:hover:not(:disabled), #model-btn[aria-expanded="true"]:not(:disabled) { background: var(--surface, #f5f5f5); }
#model-effort { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.model-separator { color: var(--text-faint); }
#effort-name { color: var(--text-faint); white-space: nowrap; }
.model-caret {
  display: inline-flex;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--text-faint);
  pointer-events: none;
  transition: transform 0.15s;
}
.model-caret svg { width: 100%; height: 100%; }
#model-pill.open .model-caret { transform: rotate(180deg); }
#model-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#model-menu, #effort-menu {
  position: fixed;
  z-index: 20;
  width: 224px;
  max-width: calc(100vw - 16px);
  box-sizing: border-box;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
  animation: ui-pop 0.14s ease both;
}
@media (prefers-reduced-motion: reduce) {
  #model-menu, #effort-menu { animation: none; }
}
#effort-menu {
  z-index: 21;
  width: 136px;
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.model-menu-list {
  max-height: min(288px, calc(100dvh - 144px));
  overflow-y: auto;
  overscroll-behavior: contain;
}
.model-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 36px;
  box-sizing: border-box;
  padding: 6px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.model-item:hover, #effort-btn[aria-expanded="true"] { background: var(--hover-bg); }
#model-btn:focus-visible, .model-item:focus-visible { outline: 2px solid rgba(23, 131, 255, 0.4); outline-offset: -2px; }
#model-btn:disabled, .model-item:disabled { cursor: default; opacity: 0.5; }
.model-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-check { width: 16px; flex-shrink: 0; display: inline-flex; color: var(--text-dim); }
.model-check .icon { width: 16px; height: 16px; }
#effort-section { margin: 6px 2px 0; padding-top: 6px; border-top: 1px solid var(--border); }
.model-menu-value { color: var(--text-faint); white-space: nowrap; }
.model-arrow { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-faint); }

.round-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--accent, #1f1f1f);
  color: rgba(245, 245, 245, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  cursor: pointer;
  transition: background-color 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}
.round-btn:hover { background: var(--accent-hover, #000000); }
.round-btn:disabled { background: rgba(0, 0, 0, 0.12); color: #fff; cursor: not-allowed; opacity: 1; }
.round-btn svg { width: 100%; height: 100%; display: block; }

.tool-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  cursor: pointer;
  transition: background-color 0.15s cubic-bezier(0.4, 0, 0.2, 1), color 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}
.tool-btn:hover { background: var(--surface, #f5f5f5); color: var(--text, #1f1f1f); }
.tool-btn:disabled { opacity: 0.4; cursor: not-allowed; background: transparent; }
.tool-btn svg { width: 100%; height: 100%; display: block; }

.attach-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 240px;
  height: 24px;
  box-sizing: border-box;
  padding: 0 8px 0 6px;
  border-radius: 999px;
  background: var(--surface, #f5f5f5);
  font-size: 12px;
  line-height: 24px;
  color: var(--text, #1f1f1f);
  user-select: none;
  vertical-align: -2px;
}
.attach-icon {
  width: 15px;
  height: 15px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}
.attach-icon .icon,
.attach-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
.attach-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}
.attach-remove {
  display: none;
  width: 15px;
  height: 15px;
  flex: none;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background-color 0.15s;
}
.attach-remove:hover {
  color: var(--text, #111);
  background: rgba(0, 0, 0, 0.06);
}
.attach-remove .icon,
.attach-remove svg {
  width: 100%;
  height: 100%;
  display: block;
}
.attach-chip:hover .attach-remove { display: inline-flex; }
.attach-chip:hover .attach-remove ~ .attach-icon { display: none; }
.attach-preview {
  position: fixed;
  z-index: 60;
  padding: 8px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
  animation: ui-pop 0.14s ease both;
}
.attach-preview img {
  max-width: 320px;
  max-height: 220px;
  border-radius: 8px;
  display: block;
  object-fit: contain;
}

/* 输入框内嵌 chip */
.editor-chip {
  margin: 0 2px;
  cursor: default;
  font-size: 13px;
  white-space: nowrap;
}

.msg.user .attach-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.msg.user .attach-chip { background: rgba(0, 0, 0, 0.06); }
.msg-text { white-space: pre-wrap; }

#scroll-bottom {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 12px;
  z-index: 5;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  color: var(--text, rgba(0, 0, 0, 0.85));
  cursor: pointer;
  user-select: none;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  will-change: transform, opacity;
  backface-visibility: hidden;
  transition:
    opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
    color 0.15s ease,
    box-shadow 0.15s ease;
}
#scroll-bottom:hover {
  color: #000000;
  box-shadow: 0 12px 36px rgba(19, 41, 61, 0.2), 0 3px 8px rgba(19, 41, 61, 0.08);
}
#scroll-bottom.hidden {
  display: inline-flex !important;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  visibility: hidden;
  transition:
    opacity 0.18s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.18s cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0s linear 0.18s;
}
#scroll-bottom .sb-arrow {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: block;
}

/* ---- Agent 提问卡 / 工具审批卡 ---- */
#question-card, #approval-card {
  max-width: var(--content-max, 780px);
  margin: 0 auto;
  background: var(--panel, #ffffff);
  border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.06);
}
#approval-card:focus { outline: none; }
#question-head, #approval-head { display: flex; align-items: center; gap: 8px; }
#question-head .icon, #approval-head .icon { width: 18px; height: 18px; color: var(--text-dim, rgba(0, 0, 0, 0.6)); flex-shrink: 0; }
#question-text, #approval-tool { font-size: var(--fs-md, 16px); font-weight: 500; color: var(--text, rgba(0, 0, 0, 0.9)); min-width: 0; }
#approval-tool { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#question-close, #approval-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
  cursor: pointer;
}
#question-close:hover, #approval-close:hover { color: var(--text, rgba(0, 0, 0, 0.9)); }
#question-close svg, #approval-close svg { width: 14px; height: 14px; }

#question-options { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.q-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  border-radius: 10px;
  background: var(--panel, #ffffff);
  text-align: left;
  font-size: var(--fs-sm, 16px);
  color: var(--text, rgba(0, 0, 0, 0.9));
  cursor: pointer;
}
.q-option:hover { background: var(--hover-bg, rgba(0, 0, 0, 0.04)); border-color: rgba(0, 0, 0, 0.16); }
.q-num {
  flex-shrink: 0;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  border-radius: 5px;
  font-size: 12px;
  color: var(--text-faint, rgba(0, 0, 0, 0.45));
  background: var(--code-bg, #f5f5f5);
}

#question-custom-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
#question-custom {
  flex: 1;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  border-radius: 10px;
  padding: 8px 12px;
  font: inherit;
  font-size: var(--fs-sm, 16px);
  color: var(--text, rgba(0, 0, 0, 0.9));
  outline: none;
}
#question-custom:focus { border-color: rgba(0, 0, 0, 0.16); }

#question-actions, #approval-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
#question-actions .q-kbd, #approval-actions .q-kbd { margin-left: 6px; font-size: 12px; opacity: 0.55; }

#approval-args, #approval-diff {
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--code-bg, #f5f5f5);
  border-radius: 8px;
  font-family: ui-monospace, Consolas, "PingFang SC", "Microsoft YaHei", monospace;
  font-size: var(--fs-sm, 16px);
  line-height: calc(22 / 14);
  color: var(--text-dim, rgba(0, 0, 0, 0.6));
  white-space: pre-wrap;
  word-break: break-word;
  max-height: min(180px, 22vh);
  overflow-y: auto;
}
#approval-args:empty { display: none; }

/* 窄屏响应式 */
@media (max-width: 760px) {
  #sidebar { position: absolute; z-index: 50; height: 100%; background: var(--ground, #fefefe); box-shadow: var(--shadow); }
  #main, #app.sidebar-collapsed #main { margin: 0; border: none; border-radius: 0; }
  #messages { padding: 14px 12px; }
  #input-area { padding: 0 12px 14px; }
  #plan-dock { left: 12px; right: 12px; }
  #plan-panel { padding: 14px 16px 16px; }
  #usage { display: none; }
  #hero { font-size: 26px; margin-bottom: 22px; }
  .new-session-btn .kbd { display: none; }
  .msg.user { max-width: 96%; }
}

/* ---- 滚动条：默认隐藏，悬停或滚动中浮现 ---- */
:is(#messages, #sidebar-scroll, #input, .thinking-text, .fv-body)::-webkit-scrollbar { width: 8px; height: 8px; }
:is(#messages, #sidebar-scroll, #input, .thinking-text, .fv-body)::-webkit-scrollbar-track { background: transparent; }
:is(#messages, #sidebar-scroll, #input, .thinking-text, .fv-body)::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 999px;
}
:is(#messages, #sidebar-scroll, #input, .thinking-text, .fv-body):is(:hover, .is-scrolling)::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb, #c8c8c8); }
:is(#messages, #sidebar-scroll, #input, .thinking-text, .fv-body)::-webkit-scrollbar-thumb:hover { background-color: var(--scrollbar-thumb-hover, #a8a8a8); }

#model-menu::-webkit-scrollbar { width: 8px; }
#model-menu::-webkit-scrollbar-track { background: transparent; }
#model-menu::-webkit-scrollbar-thumb { background: transparent; border-radius: 999px; }
#model-menu:is(:hover, .is-scrolling)::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb, #c8c8c8); }

/* 计划列表：3px 细滑块，上下内缩避开圆角，最短 24px */
#plan-items::-webkit-scrollbar { width: 3px; }
#plan-items::-webkit-scrollbar-track { background: transparent; margin: 6px 0; }
#plan-items::-webkit-scrollbar-thumb {
  min-height: 24px;
  background: transparent;
  border-radius: 999px;
}
#plan-items:is(:hover, .is-scrolling)::-webkit-scrollbar-thumb { background: var(--scrollbar-menu-thumb, #d0d0d0); }
#plan-items::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-menu-thumb-hover, #b8b8b8); }

/* 不支持 ::-webkit-scrollbar 的浏览器（Firefox）退回标准属性 */
@supports not selector(::-webkit-scrollbar) {
  #messages, #sidebar-scroll, #input, pre, .thinking-text, .fv-body, #plan-items {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
  }
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] { -moz-appearance: textfield; }
