/* messages.css - 主内容区、聊天加载、欢迎页、消息、Markdown样式、工具调用、操作事件、错误 */

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  min-height: 100%;
  padding: 0 24px;
}

.messages-wrapper {
  flex: 1;
  padding: 24px 0;
  position: relative;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  --message-panel-gap: 16px;
  --message-inner-gap: 8px;
}

/* Chat Loading */
.chat-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(253, 248, 240, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.chat-loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.chat-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px dashed var(--border-sketch);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 1.2s linear infinite;
}

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

.chat-loading-text {
  font-family: var(--font-hand);
  font-size: 18px;
  color: var(--text-secondary);
  margin: 0;
}

/* Thinking Indicator */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  margin: 10px 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-primary);
  animation: thinking-bounce 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes thinking-bounce {

  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }

  40% {
    opacity: 1;
    transform: scale(1);
  }
}

.thinking-text {
  font-family: var(--font-hand);
}

/* Welcome */
.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 20px;
}

.welcome-icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-light);
  border: 2px solid var(--accent-primary);
  border-radius: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sketch);
  transform: rotate(-2deg);
}

.welcome-icon img {
  width: 54px;
  height: 54px;
  object-fit: contain;
}

.welcome-message h2 {
  font-family: var(--font-hand);
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}

.welcome-message p {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 400px;
}

.welcome-tips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
  justify-content: center;
}

.welcome-tip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--bg-secondary);
  border: 2px dashed var(--border-color);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.welcome-tip:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sketch);
}

.welcome-tip code {
  font-family: "SF Mono", Monaco, Consolas, monospace;
  background: rgba(107, 127, 198, 0.1);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--accent-primary);
}

/* Messages */
.message {
  display: flex;
  gap: 0;
  animation: sketchFadeIn 0.3s ease;
  min-width: 0;
  max-width: 100%;
}

@keyframes sketchFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px) rotate(-0.3deg);
  }

  to {
    opacity: 1;
    transform: translateY(0) rotate(0);
  }
}

.message-content {
  flex: 1;
  min-width: 0;
  max-width: 100%;
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.message-name {
  font-family: var(--font-hand);
  font-size: 16px;
  font-weight: 600;
}

.message-time {
  font-size: 12px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.message-body {
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

/* Markdown */
.markdown-body {
  word-break: break-word;
  overflow-wrap: anywhere;
  min-width: 0;
  max-width: 100%;
}

.markdown-body p {
  margin: 0 0 12px 0;
}

.markdown-body p:last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 16px 0 8px 0;
  font-weight: 600;
  line-height: 1.4;
}

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child {
  margin-top: 0;
}

.markdown-body ul,
.markdown-body ol {
  margin: 8px 0;
  padding-left: 20px;
}

.markdown-body li {
  margin: 4px 0;
}

.markdown-body code {
  font-family: "SF Mono", Monaco, Consolas, monospace;
  font-size: 13px;
  background: rgba(107, 127, 198, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(107, 127, 198, 0.15);
}

.markdown-body pre {
  margin: 12px 0;
  padding: 14px 16px;
  background: #f8f6f2;
  border: 2px solid var(--border-color);
  border-radius: 10px;
  overflow-x: auto;
  box-shadow: inset 1px 1px 4px rgba(0, 0, 0, 0.04);
  max-width: 100%;
}

.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
  border: none;
  overflow-wrap: normal;
  word-break: normal;
}

.markdown-body blockquote {
  margin: 12px 0;
  padding: 10px 18px;
  border-left: 4px solid var(--accent-primary);
  background: var(--accent-light);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.markdown-body strong {
  font-weight: 600;
}

.markdown-body a {
  color: var(--accent-primary);
  text-decoration: none;
  border-bottom: 1px dashed var(--accent-primary);
}

.markdown-body a:hover {
  border-bottom-style: solid;
}

.markdown-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 12px 0;
  border: 2px solid var(--border-color);
  border-radius: 8px;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
}

.markdown-table-wrap table {
  min-width: max-content;
}

.markdown-body th,
.markdown-body td {
  padding: 8px 12px;
  text-align: left;
  border: 1px solid var(--border-color);
  vertical-align: top;
  overflow-wrap: normal;
  word-break: normal;
}

.markdown-body th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

.markdown-body-compact {
  font-size: 13px;
  line-height: 1.6;
}

.markdown-body-compact p {
  margin-bottom: 8px;
}

.markdown-body-compact h1,
.markdown-body-compact h2,
.markdown-body-compact h3,
.markdown-body-compact h4,
.markdown-body-compact h5,
.markdown-body-compact h6 {
  margin: 12px 0 6px;
}

.markdown-body-compact ul,
.markdown-body-compact ol {
  margin: 6px 0;
}

.markdown-body-compact pre {
  margin: 8px 0;
  padding: 10px 12px;
  border-width: 1px;
  border-radius: 8px;
}

.markdown-body-compact code {
  font-size: 12px;
  padding: 1px 5px;
}

.markdown-body-compact table {
  font-size: 12px;
}

.markdown-body-compact .markdown-table-wrap {
  margin: 8px 0;
  border-width: 1px;
  border-radius: 6px;
}

.markdown-body-compact th,
.markdown-body-compact td {
  padding: 6px 8px;
}

/* Footnotes */

/* 行内脚注引用 - 小圆标 */
.markdown-body .footnote-cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  font-size: 9px;
  font-weight: 600;
  line-height: 1;
  color: var(--accent-primary);
  background: var(--accent-light);
  border: 1.5px solid var(--accent-primary);
  border-radius: 7px;
  text-decoration: none;
  cursor: pointer;
  vertical-align: super;
  margin: 0 1px;
  transition: all var(--transition);
  position: relative;
  box-sizing: border-box;
}

a.footnote-cite:hover {
  background: var(--accent-primary);
  color: white;
  box-shadow: 0 1px 4px rgba(107, 127, 198, 0.35);
  border-bottom: none;
}

/* 自定义快速 tooltip（替代原生 title 的延迟） */
a.footnote-cite::after {
  content: attr(data-url);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 400;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
  z-index: 100;
  line-height: 1.4;
}

a.footnote-cite:hover::after {
  opacity: 1;
}

/* 来源卡片 */
.sources-card {
  margin-top: 16px;
  border: 2px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-tertiary);
  animation: sources-fade-in 0.3s ease;
}

@keyframes sources-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.sources-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.sources-header:hover {
  background: var(--bg-hover);
}

.sources-icons {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.source-favicon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--bg-tertiary);
  background: var(--bg-secondary);
  object-fit: contain;
}

.source-icon-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--text-tertiary);
}

.source-icon-fallback svg {
  width: 16px;
  height: 16px;
}

.sources-count {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.sources-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  transition: transform var(--transition);
  flex-shrink: 0;
}

.sources-card.expanded .sources-chevron {
  transform: rotate(180deg);
}

.sources-list {
  display: none;
  border-top: 1px solid var(--border-color);
  padding: 6px 0;
  max-height: 240px;
  overflow-y: auto;
}

.sources-card.expanded .sources-list {
  display: block;
}

.source-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background var(--transition);
  cursor: pointer;
}

a.source-item:hover {
  background: var(--bg-hover);
  color: var(--accent-primary);
}

.source-item-favicon {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
}

.source-item-icon {
  display: flex;
  align-items: center;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.source-item-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* User Message */
.message.user {
  justify-content: flex-end;
}

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

.message.user .message-body {
  background: var(--accent-primary);
  color: white;
  border-radius: 14px 14px 4px 14px;
  max-width: 85%;
  margin-left: auto;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sketch);
  border: 2px solid rgba(107, 127, 198, 0.8);
}

.message.user .message-body code {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

/* Assistant Message */
.message.assistant .message-body {
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: 14px 14px 14px 4px;
  box-shadow: var(--shadow-sketch);
  position: relative;
}

/* Agent Tag */
.agent-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  background: var(--accent-light);
  color: var(--accent-primary);
  border: 1px solid var(--accent-primary);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
}

/* Streaming */
.streaming-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 2px 0;
}

.streaming-indicator span {
  width: 6px;
  height: 6px;
  background: var(--accent-primary);
  border-radius: 50%;
  animation: sketchBounce 1.4s infinite ease-in-out both;
}

.streaming-indicator span:nth-child(1) {
  animation-delay: -0.32s;
}

.streaming-indicator span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes sketchBounce {

  0%,
  80%,
  100% {
    transform: scale(0);
  }

  40% {
    transform: scale(1);
  }
}

/* Tool Calls & Results */
.tool-call,
.tool-result {
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  animation: fadeIn 0.2s ease;
}

.tool-call {
  background: var(--info-light);
  border: 2px solid var(--info);
  box-shadow: var(--shadow-sketch);
}

.agent-tool-call {
  background: rgba(123, 180, 140, 0.12);
  border-color: var(--success);
}

.tool-result {
  background: var(--bg-tertiary);
  border: 2px dashed var(--border-color);
}

.tool-call-header,
.tool-result-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-weight: 500;
}

.tool-call-header {
  color: var(--info);
  font-family: var(--font-hand);
  font-size: 15px;
  cursor: pointer;
}

.agent-tool-call .tool-call-header {
  color: var(--success);
}

.tool-call-header svg,
.tool-result-header svg {
  width: 14px;
  height: 14px;
}

.tool-result-header {
  color: var(--success);
  font-family: var(--font-hand);
  font-size: 15px;
}

/* Parallel Members */
.parallel-members-panel {
  margin: 0;
  animation: fadeIn 0.2s ease;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.dispatch-header.parallel-members-header {
  margin: 0 0 8px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  box-shadow: none;
  font-family: inherit;
}

.parallel-members-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--text-secondary);
}

.parallel-member-head {
  flex-wrap: nowrap;
}

.parallel-member-detail {
  cursor: text;
}

.parallel-member-head .parallel-member-name {
  font-weight: 700;
  flex: 0 0 auto;
  max-width: 160px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: normal;
  word-break: normal;
}

.parallel-member-head .parallel-member-status {
  flex: 0 0 auto;
  white-space: nowrap;
}

.parallel-members-count {
  color: var(--text-tertiary);
}

.parallel-member-head .parallel-member-task-content {
  display: block;
  flex: 1 1 0;
  min-width: 0;
  padding-left: 9px;
  border-left: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.parallel-member-head .parallel-member-task-text {
  color: var(--text-secondary);
}

.parallel-member-head .parallel-member-activity {
  flex: 0 1 auto;
  min-width: 72px;
  max-width: 150px;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.parallel-member-task-detail {
  margin-bottom: 8px;
  padding: 7px 9px;
  border-radius: 6px;
  background: rgba(107, 165, 198, 0.06);
  color: var(--text-primary);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.parallel-member-timeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}

.parallel-member-event {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}

.parallel-member-event-title {
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  background: rgba(107, 127, 198, 0.06);
  border-bottom: 1px dashed var(--border-color);
  overflow-wrap: anywhere;
}

.parallel-member-event-tool .parallel-member-event-title,
.parallel-member-event-task .parallel-member-event-title,
.parallel-member-event-result .parallel-member-event-title {
  color: var(--info);
  background: rgba(107, 165, 198, 0.08);
}

.parallel-member-event-reasoning .parallel-member-event-title {
  color: var(--warning);
  background: rgba(212, 165, 74, 0.08);
}

.parallel-member-event-output .parallel-member-event-title {
  color: var(--success);
  background: rgba(125, 184, 127, 0.08);
}

.parallel-member-event-body {
  padding: 8px 10px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
  overflow-x: hidden;
  overflow-y: visible;
  white-space: pre-wrap;
  word-break: break-word;
  min-width: 0;
  max-width: 100%;
}

.parallel-member-event-tool .parallel-member-event-body,
.parallel-member-event-task .parallel-member-event-body,
.parallel-member-event-result .parallel-member-event-body {
  font-family: var(--font-mono, "SF Mono", Monaco, Consolas, monospace);
  font-size: 12px;
}

.parallel-member-tool-flow details {
  display: block;
}

.parallel-member-tool-flow summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  list-style: none;
  color: var(--info);
  background: rgba(107, 165, 198, 0.08);
  border-bottom: 1px dashed var(--border-color);
  min-width: 0;
}

.parallel-member-tool-flow summary::-webkit-details-marker {
  display: none;
}

.parallel-member-tool-flow summary::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.parallel-member-tool-flow details[open] summary::before {
  transform: rotate(45deg);
}

.parallel-member-tool-title {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.parallel-member-tool-status {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  border-radius: 999px;
  padding: 1px 7px;
}

.parallel-member-tool-section {
  padding: 8px 10px;
  min-width: 0;
  max-width: 100%;
}

.parallel-member-tool-section + .parallel-member-tool-section {
  border-top: 1px dashed var(--border-color);
}

.parallel-member-tool-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-tertiary);
  margin-bottom: 5px;
}

.parallel-member-tool-section pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow-x: auto;
  overflow-y: auto;
  font-family: var(--font-mono, "SF Mono", Monaco, Consolas, monospace);
  font-size: 12px;
  max-width: 100%;
}

.parallel-member-markdown {
  white-space: normal;
  word-break: break-word;
  min-width: 0;
  max-width: 100%;
}

.parallel-member-markdown[data-streaming="1"] {
  white-space: pre-wrap;
}

.tool-call-name {
  font-family: "SF Mono", Monaco, monospace;
  background: rgba(107, 165, 198, 0.15);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  border: 1px solid rgba(107, 165, 198, 0.3);
}

.tool-call-status {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  border-radius: 999px;
  padding: 1px 8px;
}

.tool-call-detail {
  margin-top: 8px;
}

.tool-call-args,
.tool-result-content {
  font-family: "SF Mono", Monaco, monospace;
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.03);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 160px;
  overflow-y: auto;
  margin: 0;
  border: 1px solid var(--border-color);
}

.tool-call-result {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-color);
}

.tool-call-result-header {
  color: var(--success);
  font-family: var(--font-hand);
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
}

/* Action Events */
.action-event {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--warning-light);
  border: 2px dashed var(--warning);
  border-radius: 10px;
  font-size: 13px;
  color: var(--warning);
  margin: 0;
  animation: fadeIn 0.2s ease;
  box-shadow: var(--shadow-sketch);
}

/* Dispatch Task Results */
.dispatch-result {
  margin: 0;
  animation: fadeIn 0.2s ease;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.dispatch-progress-live .dispatch-progress-title::after {
  content: "";
  display: inline-block;
  width: 3px;
  height: 13px;
  margin-left: 4px;
  background: currentColor;
  animation: blink 1s step-end infinite;
  vertical-align: middle;
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

.dispatch-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-hand);
  margin-bottom: var(--message-inner-gap);
  min-width: 0;
}

.dispatch-progress-counter {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

.dispatch-status-ok {
  background: var(--success-light);
  color: var(--success);
  border: 2px solid var(--success);
}

.dispatch-status-partial {
  background: var(--warning-light);
  color: var(--warning);
  border: 2px solid var(--warning);
}

.dispatch-cards {
  display: flex;
  flex-direction: column;
  gap: var(--message-inner-gap);
  min-width: 0;
  max-width: 100%;
}

.dispatch-card {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  font-size: 13px;
  transition:
    background 0.15s,
    border-color 0.2s;
  overflow: hidden;
  box-shadow: none;
  min-width: 0;
  max-width: 100%;
}

.dispatch-card[style*="cursor: pointer"]:hover,
.dispatch-card.dispatch-card-done:hover,
.dispatch-card.dispatch-card-fail:hover {
  background: var(--bg-tertiary);
}

.dispatch-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}

/* Status dot */
.dispatch-card-status-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  transition: background 0.2s;
}

.dispatch-card-waiting .dispatch-card-status-dot {
  background: var(--text-tertiary);
}

.dispatch-card-running .dispatch-card-status-dot {
  background: var(--warning);
  box-shadow: 0 0 6px var(--warning);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

.dispatch-card-done .dispatch-card-status-dot {
  background: var(--success);
}

.dispatch-card-fail .dispatch-card-status-dot {
  background: var(--error);
}

.dispatch-card-fail {
  border-color: var(--error);
}

.dispatch-card-cancelled .dispatch-card-status-dot {
  background: var(--text-tertiary);
  box-shadow: none;
  animation: none;
}

.dispatch-card-cancelled {
  border-color: var(--border-color);
  background: var(--bg-tertiary);
}

.dispatch-card-desc {
  flex: 1;
  color: var(--text-primary);
  line-height: 1.4;
  min-width: 0;
  overflow-wrap: anywhere;
}

.dispatch-card-ops-count {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 1px 6px;
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.dispatch-card-toggle {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  position: relative;
  opacity: 0.4;
  transition:
    transform 0.2s,
    opacity 0.2s;
}

.dispatch-card-toggle::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 3px;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
}

.dispatch-card-expanded .dispatch-card-toggle {
  transform: rotate(180deg);
  opacity: 0.7;
}

/* Detail panel */
.dispatch-card-detail {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-color);
  min-width: 0;
  max-width: 100%;
}

.dispatch-card-error {
  padding: 6px 10px;
  font-size: 12px;
  color: var(--error);
  background: rgba(220, 100, 100, 0.06);
  border-radius: 6px;
  margin-bottom: 8px;
}

.dispatch-card-ops-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.dispatch-card-op-item {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 2px 0;
  font-family: var(--font-mono, monospace);
  line-height: 1.4;
}

.dispatch-card-op-item::before {
  content: "\25b8 ";
  color: var(--text-tertiary);
}

.dispatch-card-result {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  max-height: 300px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 10px 12px;
  background: var(--bg-primary);
  border-radius: 6px;
  border: 1px solid var(--border-color);
  word-break: break-word;
  min-width: 0;
  max-width: 100%;
}

.action-event svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.action-event.transfer {
  background: var(--info-light);
  border-color: var(--info);
  color: var(--info);
}

.action-event.exit {
  background: var(--success-light);
  border-color: var(--success);
  color: var(--success);
}

.action-event.cancelled {
  background: var(--error-light);
  border-color: var(--error);
  color: var(--error);
}

.action-event.approval-request {
  background: var(--warning-light, rgba(255, 193, 7, 0.08));
  border-color: var(--warning, #ffc107);
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.action-event.approval-result.approved {
  background: var(--success-light);
  border-color: var(--success);
  color: var(--success);
}

.action-event.approval-result.rejected {
  background: var(--error-light);
  border-color: var(--error);
  color: var(--error);
}

.action-event.ask-request {
  background: var(--accent-light, rgba(99, 102, 241, 0.08));
  border-color: var(--accent-primary);
  color: var(--text-secondary);
}

.action-event.ask-response.approved {
  background: var(--success-light);
  border-color: var(--success);
  color: var(--success);
}

.action-event.context-compress {
  background: var(--accent-light);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.action-event.steering-message {
  background: var(--info-light);
  border-color: var(--info);
  color: var(--info);
}

.action-event.agent-switch {
  background: var(--accent-light);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  border-style: solid;
}

.action-event strong {
  font-weight: 600;
}

.action-event .reset-mode-btn {
  margin-left: auto;
  padding: 4px 12px;
  background: var(--bg-secondary);
  border: 2px solid var(--accent-primary);
  border-radius: 8px;
  color: var(--accent-primary);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all var(--transition);
}

.action-event .reset-mode-btn:hover {
  background: var(--accent-primary);
  color: white;
  box-shadow: var(--shadow-sketch);
}

.action-event .reset-mode-btn svg {
  width: 12px;
  height: 12px;
}

/* Error */
.error-message {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--error-light);
  border: 2px solid var(--error);
  border-radius: 10px;
  color: var(--error);
  font-size: 13px;
  margin: 0;
  box-shadow: var(--shadow-sketch);
}

.error-message.error-continuable {
  flex-wrap: wrap;
  justify-content: space-between;
}

.error-continuable-content {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.continue-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 14px;
  background: var(--accent-primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.continue-btn:hover {
  background: var(--accent-secondary);
}

.continue-btn svg {
  width: 14px;
  height: 14px;
}

.error-message svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Reasoning / Thinking Block */
.reasoning-block {
  border: 2px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
  background: var(--bg-secondary);
}

.reasoning-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  user-select: none;
}

.reasoning-header:hover {
  background: var(--bg-hover, rgba(0, 0, 0, 0.03));
}

.reasoning-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  stroke: currentColor;
}

.reasoning-title {
  flex: 1;
  font-weight: 500;
}

.reasoning-chevron {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
  transform: rotate(-90deg);
}

.reasoning-block.expanded .reasoning-chevron {
  transform: rotate(0deg);
}

.reasoning-content {
  overflow: hidden;
  display: none;
  padding: 0 12px;
  font-size: 13px;
  color: var(--text-secondary);
  border-top: none;
}

.reasoning-block.expanded .reasoning-content {
  display: block;
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border);
}

/* Message Attachments (user message image previews) */
.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.attachment-preview-img {
  max-width: 200px;
  max-height: 150px;
  border-radius: 8px;
  border: 2px solid var(--border);
  object-fit: cover;
  cursor: pointer;
}

.attachment-preview-img:hover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-sketch);
}

/* Upload Button */
.upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.upload-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--bg-secondary);
}

.upload-btn svg {
  width: 18px;
  height: 18px;
}

/* Attachments Preview (input area) */
.attachments-preview {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.attachment-item {
  position: relative;
  display: inline-block;
}

.attachment-item img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid var(--border);
}

.attachment-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--error);
  color: white;
  border: none;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.attachment-remove:hover {
  background: #c53030;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
  .chat-container {
    padding: 0 10px;
  }

  .messages-wrapper {
    padding: 16px 0;
  }

  .messages {
    gap: 12px;
  }

  /* 消息气泡 */
  .message-body {
    padding: 10px 12px;
    font-size: 14px;
  }

  .message.user .message-body {
    max-width: 92%;
  }

  /* 代码块 */
  .markdown-body pre {
    margin: 8px 0;
    padding: 10px 12px;
    border-radius: 8px;
  }

  .markdown-body pre code {
    font-size: 12px;
  }

  /* 工具调用卡片更紧凑 */
  .tool-call,
  .tool-result {
    padding: 8px 10px;
    font-size: 12px;
  }

  .tool-call-header,
  .tool-result-header {
    font-size: 13px;
    margin-bottom: 6px;
  }

  .tool-call-name {
    font-size: 11px;
    padding: 1px 6px;
  }

  .tool-call-args,
  .tool-result-content {
    font-size: 11px;
    padding: 8px 10px;
    max-height: 120px;
  }

  .parallel-members-panel {
    margin: 0;
  }

  .dispatch-header.parallel-members-header {
    padding: 0 2px;
    font-size: 12px;
  }

  .parallel-member-card {
    padding: 8px 10px;
    font-size: 12px;
  }

  .parallel-member-head {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 7px;
  }

  .parallel-member-dot {
    align-self: center;
  }

  .parallel-member-head .parallel-member-name {
    flex: 0 0 auto;
    max-width: 88px;
    white-space: nowrap;
    overflow-wrap: normal;
  }

  .parallel-member-head .parallel-member-status {
    flex: 0 0 auto;
    font-size: 10px;
    padding: 1px 5px;
    align-self: center;
  }

  .parallel-member-toggle {
    flex: 0 0 16px;
  }

  .parallel-member-head .parallel-member-task-content {
    flex: 1 1 0;
    min-width: 0;
    padding-left: 7px;
    border-left: 1px solid var(--border-color);
  }

  .parallel-member-head .parallel-member-activity {
    flex: 0 1 auto;
    min-width: 54px;
    max-width: 92px;
    font-size: 11px;
  }

  .parallel-member-detail {
    margin-top: 8px;
    padding-top: 8px;
    min-width: 0;
  }

  .parallel-member-event-body {
    max-height: none;
    overflow-x: hidden;
  }

  .parallel-member-tool-flow summary {
    align-items: center;
    gap: 6px;
    padding: 7px 8px;
  }

  .parallel-member-tool-status {
    font-size: 10px;
    padding: 1px 5px;
  }

  .parallel-member-tool-section {
    padding: 8px;
  }

  .parallel-member-tool-section pre {
    max-height: 220px;
  }

  /* 操作事件 */
  .action-event {
    padding: 8px 10px;
    font-size: 12px;
  }

  /* 隐藏桌面端的快速导航 */
  .quick-nav-wrapper {
    display: none;
  }

  /* 欢迎页 */
  .welcome-message {
    padding: 40px 16px;
  }

  .welcome-message h2 {
    font-size: 24px;
  }

  .welcome-message p {
    font-size: 13px;
  }

  .welcome-tips {
    gap: 8px;
    margin-top: 16px;
  }

  .welcome-tip {
    font-size: 12px;
    padding: 5px 10px;
  }
}

/* ===== Inline Ask Form (embedded in chat) ===== */
.inline-ask-form {
  margin: 0;
  padding: 16px;
  background: var(--bg-secondary);
  border: 2px solid var(--accent-primary);
  border-radius: 14px;
  box-shadow: var(--shadow-sketch);
  animation: sketchSlideUp 0.3s ease;
}

.inline-ask-form.submitted {
  opacity: 0.7;
  border-style: dashed;
}

.inline-ask-question {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  margin-bottom: 12px;
  font-weight: 500;
  white-space: pre-wrap;
  word-break: break-word;
}

.inline-ask-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.inline-ask-option-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  transition: all var(--transition);
}

.inline-ask-option-label:hover {
  border-color: var(--accent-primary);
  background: var(--accent-light);
}

.inline-ask-option-label:has(input:checked) {
  border-color: var(--accent-primary);
  background: var(--accent-light);
  font-weight: 500;
}

.inline-ask-option-input {
  accent-color: var(--accent-primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.inline-ask-option-custom {
  border-style: dashed;
}

.inline-ask-free-text {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-body);
  resize: vertical;
  min-height: 48px;
  box-sizing: border-box;
  transition: border-color var(--transition);
}

.inline-ask-free-text:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.inline-ask-free-text::placeholder {
  color: var(--text-muted);
}

.inline-ask-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.inline-ask-submit-btn {
  padding: 7px 22px;
  background: var(--accent-primary);
  color: white;
  border: 1.5px solid var(--accent-primary);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.inline-ask-submit-btn:hover {
  background: var(--accent-secondary);
  border-color: var(--accent-secondary);
}

.inline-ask-submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.inline-ask-result {
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--success-light);
  border: 1.5px solid var(--success);
  border-radius: 8px;
  color: var(--success);
  font-size: 13px;
}
