/* ===== Agent 工具条 ===== */
.agent-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--card-bg-soft);
  font-size: 13px;
  color: var(--text-muted);
}

.agent-bar.is-on {
  color: var(--text-main);
}

/* 放在输入框内部上方：去掉独立的底色，和输入区融为一体，用细分隔线和文本框隔开 */
.composer-box .agent-bar {
  padding: 6px 12px;
  background: transparent;
  border-bottom: 1px solid var(--border-soft);
}

.composer-box .agent-bar.is-on {
  background: var(--card-bg-soft);
}

.agent-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
}

/* 同一行的开关、按钮、下拉框、复选框统一字体和字号（按钮和下拉框默认不继承页面字体） */
.agent-bar .agent-switch,
.agent-bar .agent-chip,
.agent-bar .agent-select,
.agent-bar .agent-check,
.agent-bar .agent-stop {
  font-family: inherit;
  font-size: 13px;
  line-height: 1.2;
}

.agent-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.agent-switch-track {
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: #d1d5db;
  transition: background 0.15s ease;
}

.agent-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease;
}

.agent-switch input:checked + .agent-switch-track {
  background: var(--accent);
}

.agent-switch input:checked + .agent-switch-track .agent-switch-thumb {
  transform: translateX(14px);
}

.agent-switch input:focus-visible + .agent-switch-track {
  outline: 2px solid rgba(17, 24, 39, 0.35);
  outline-offset: 2px;
}

.agent-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.agent-controls[hidden] {
  display: none;
}

.agent-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
}

.agent-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-chip:hover:not(:disabled) {
  border-color: rgba(17, 24, 39, 0.3);
}

.agent-chip:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.agent-chip.needs-grant {
  border-color: #f59e0b;
  color: #92400e;
  background: #fffbeb;
}

.agent-chip-x {
  width: 22px;
  height: 22px;
  margin-left: -4px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.agent-chip-x:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-main);
}

.agent-select {
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-main);
  font-size: 13px;
}

.agent-check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.agent-status {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.agent-stop {
  height: 26px;
  padding: 0 12px;
  border: 1px solid var(--danger-border);
  border-radius: 8px;
  background: var(--danger-bg);
  color: #b91c1c;
  font-size: 12px;
  cursor: pointer;
}

.agent-stop[hidden] {
  display: none;
}

/* 执行中补充说明（纠偏）：复用 /agent/steer，下一步开始前注入给模型 */
.agent-steer {
  height: 26px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-main);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.agent-steer[hidden] {
  display: none;
}

.agent-steer:disabled {
  opacity: 0.6;
  cursor: default;
}

/* 子 agent 实时进度：每个子任务一行，显示它最近在做什么 */
.agent-subs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px;
  border: 1px dashed var(--border-soft);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.agent-sub-row {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-sub-row b {
  font-weight: 500;
  color: var(--text-main);
}

.agent-sub-row.done {
  opacity: 0.7;
}

.agent-stop:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ===== Agent 消息内容 ===== */
.agent-msg {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.agent-text.draft {
  opacity: 0.55;
}

.agent-note {
  font-size: 12px;
  color: var(--text-muted);
  padding: 2px 0;
}

.agent-note.warn {
  color: #92400e;
}

.agent-note.error {
  color: #b91c1c;
}

/* 运行指示条：转圈 + 当前阶段 + 已运行时长；等待操作时停转，疑似断线时变黄 */
.agent-activity {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.agent-activity-spin {
  flex: none;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: agent-spin 0.9s linear infinite;
}

.agent-activity-text {
  min-width: 0;
}

.agent-activity-time {
  flex: none;
  margin-left: auto;
  opacity: 0.8;
}

.agent-activity.waiting .agent-activity-spin {
  animation: none;
  border-right-color: currentColor;
  opacity: 0.5;
}

.agent-activity.stale {
  color: #92400e;
}

.agent-activity.stale .agent-activity-spin {
  animation: none;
  border-radius: 2px;
}

@keyframes agent-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .agent-activity-spin { animation-duration: 2.4s; }
}

/* 工具调用卡片 */
.agent-tool {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--card-bg-soft);
  font-size: 13px;
}

/* 子 agent 发起的文件操作：缩进显示，与主 agent 的操作区分 */
.agent-tool.sub {
  margin-left: 18px;
  border-style: dashed;
}

.agent-tool > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  list-style: none;
  min-width: 0;
}

.agent-tool > summary::-webkit-details-marker {
  display: none;
}

.agent-tool > summary:hover {
  background: rgba(0, 0, 0, 0.035);
  border-radius: var(--radius-sm);
}

.agent-tool > summary:focus-visible {
  outline: 2px solid rgba(17, 24, 39, 0.35);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

/* 右侧「详情 ▾」：提示可以点击展开，展开后箭头朝上 */
.agent-tool-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.agent-tool-chevron {
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease, margin-top 0.15s ease;
}

.agent-tool[open] .agent-tool-chevron {
  margin-top: 3px;
  transform: rotate(-135deg);
}

.agent-tool > summary:hover .agent-tool-toggle {
  color: var(--text-main);
}

.agent-tool-toggle-text::before {
  content: "详情";
}

.agent-tool[open] .agent-tool-toggle-text::before {
  content: "收起";
}

/* 展开后的两段内容加上小标题 */
.agent-tool-args::before,
.agent-tool-result:not(:empty)::before {
  display: block;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-family: system-ui, sans-serif;
  font-weight: 600;
}

.agent-tool-args::before {
  content: "参数";
}

.agent-tool-result:not(:empty)::before {
  content: "结果";
}

.agent-tool[open] > summary {
  border-bottom: 1px dashed var(--border-soft);
}

.agent-tool-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
}

.agent-tool[data-state="running"] .agent-tool-dot {
  background: #3b82f6;
  animation: agent-pulse 1s ease-in-out infinite;
}

.agent-tool[data-state="ok"] .agent-tool-dot {
  background: #10b981;
}

.agent-tool[data-state="error"] .agent-tool-dot {
  background: #ef4444;
}

@keyframes agent-pulse {
  50% {
    opacity: 0.35;
  }
}

.agent-tool-name {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.agent-tool-arg {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.agent-tool-state {
  flex: none;
  color: var(--text-muted);
  font-size: 12px;
}

.agent-tool-body {
  padding: 0 10px 8px;
}

.agent-tool-body pre,
.agent-diff {
  margin: 6px 0 0;
  max-height: 260px;
  overflow: auto;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.agent-tool-result:empty {
  display: none;
}

/* 任务清单 */
.agent-todos {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: var(--card-bg-soft);
  font-size: 13px;
}

.agent-todos-h {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 4px;
}

.agent-todos-h span {
  color: var(--text-muted);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.agent-todo {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 2px 0;
}

.agent-todo-box {
  flex: none;
  width: 12px;
  height: 12px;
  margin-top: 4px;
  border: 1.5px solid #9ca3af;
  border-radius: 3px;
}

.agent-todo.in_progress {
  font-weight: 600;
}

.agent-todo.in_progress .agent-todo-box {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.2);
}

.agent-todo.completed {
  color: var(--text-muted);
  text-decoration: line-through;
}

.agent-todo.completed .agent-todo-box {
  border-color: #10b981;
  background: #10b981;
}

/* 审批 / 提问 / 计划卡片 */
.agent-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--card-bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  font-size: 13px;
}

.agent-card.approval {
  border-color: #f59e0b;
}

.agent-card.question,
.agent-card.plan {
  border-color: #3b82f6;
}

.agent-card.decided {
  box-shadow: none;
  border-color: var(--border-soft);
}

.agent-card.decided .agent-input {
  display: none;
}

.agent-card-h {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 6px;
}

.agent-badge {
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #fef3c7;
  color: #92400e;
}

.agent-badge.destructive {
  background: #fee2e2;
  color: #b91c1c;
}

.agent-diff-h {
  margin-top: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.agent-diff-h.danger {
  color: #b91c1c;
}

.agent-diff.add {
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.agent-diff.del {
  background: #fef2f2;
  border-color: #fecaca;
  text-decoration: line-through;
  text-decoration-color: rgba(185, 28, 28, 0.35);
}

.agent-q {
  margin-bottom: 8px;
  line-height: 1.6;
}

.agent-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.agent-plan {
  max-height: 360px;
  overflow: auto;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--card-bg-soft);
  font-size: 13px;
}

.agent-input {
  width: 100%;
  margin-top: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  resize: vertical;
}

.agent-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.agent-actions .agent-input {
  flex: 1;
  min-width: 160px;
  margin-top: 0;
}

.agent-btn {
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
}

.agent-btn:hover {
  border-color: rgba(17, 24, 39, 0.35);
}

.agent-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.agent-decided {
  color: var(--text-muted);
  font-size: 12px;
}

/* 底部统计与 trace */
.agent-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.agent-footer-status {
  padding: 1px 8px;
  border-radius: 999px;
  background: #fee2e2;
  color: #b91c1c;
}

.agent-footer-status.interrupted {
  background: #f3f4f6;
  color: var(--text-muted);
}

.agent-link {
  border: none;
  background: none;
  padding: 0;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
  font-size: 12px;
}

.agent-feedback {
  display: inline-flex;
  gap: 2px;
}

.agent-fb {
  border: none;
  background: none;
  padding: 0 2px;
  cursor: pointer;
  font-size: 12px;
  opacity: 0.45;
  filter: grayscale(1);
}

.agent-fb:hover,
.agent-fb.active {
  opacity: 1;
  filter: none;
}

.agent-trace {
  font-size: 12px;
  color: var(--text-muted);
}

.agent-trace table {
  margin-top: 6px;
  border-collapse: collapse;
  width: 100%;
}

.agent-trace th,
.agent-trace td {
  padding: 3px 8px;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  white-space: nowrap;
}

@media (max-width: 640px) {
  /* 手机上 Agent 选项保持一行，放不下时左右滑动，不挤占对话区的高度 */
  .composer-box .agent-bar {
    flex-wrap: nowrap;
    gap: 8px;
    padding: 6px 10px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .composer-box .agent-bar::-webkit-scrollbar {
    display: none;
  }

  /* 右侧渐隐：提示这一行还能往左滑。执行中「停止」按钮固定在右侧，不做渐隐 */
  .composer-box .agent-bar.is-on:not(.is-running) {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  }

  .agent-switch,
  .agent-controls {
    flex: none;
  }

  .agent-controls {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .agent-chip {
    max-width: 128px;
    height: 30px;
  }

  .agent-select {
    height: 30px;
    padding: 0 4px;
  }

  /* 执行中：权限和计划模式只在发送时生效，先收起，给「停止」按钮腾出位置 */
  .agent-bar.is-running .agent-select,
  .agent-bar.is-running .agent-check {
    display: none;
  }

  .agent-stop {
    height: 30px;
  }

  .agent-status {
    display: none;
  }

  /* 审批 / 提问卡片的按钮在手机上更好点 */
  .agent-btn {
    height: 34px;
  }

  /* 窄屏只留箭头 */
  .agent-tool-toggle-text {
    display: none;
  }
}
