/* ========== 欢迎语 ========== */
.welcome {
  text-align: center;
  padding: 80px 20px;
  color: rgba(255, 255, 255, 0.4);
}
.welcome-avatar {
  font-size: 56px;
  margin-bottom: 16px;
}
.welcome h2 {
  font-size: 24px;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 12px;
}
.welcome p {
  font-size: 14px;
  line-height: 1.8;
}
.welcome-hint {
  margin-top: 8px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.3);
}

/* ========== 消息气泡 ========== */
.msg.selected {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
  background: rgba(37, 99, 235, 0.06);
  border-radius: 4px;
}
.msg {
  padding: 8px 14px 4px;
  border-radius: 12px;
  margin-bottom: 6px;
  line-height: 1.6;
  word-break: break-word;
  font-size: 14px;
  animation: msgIn 0.2s ease;
}

/* 消息气泡内代码块/引用内容强制换行（pre 默认 white-space:pre 不换行） */
.msg pre,
.msg-content pre {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}
.msg code {
  word-break: break-word;
  overflow-wrap: break-word;
}
@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 用户消息 — 常驻外框 */
.msg-user {
  background: var(--user-bg, #253244);
  color: #e0e0e0;
  font-family: var(--user-font, var(--global-font, system-ui, sans-serif));
  border: 2px solid rgba(255, 255, 255, 0.25);
}

/* AI 消息 */
.msg-ai {
  background: var(--ai-bg, #1e293b);
  color: #e0e0e0;
  font-family: var(--ai-font, var(--global-font, system-ui, sans-serif));
}

/* 归纳消息（归纳师） */
.msg-summary {
  background: linear-gradient(135deg, #1a2332 0%, #1e2d3d 100%);
  color: #d4dce8;
  font-family: var(--ai-font, var(--global-font, system-ui, sans-serif));
  border: 1px solid rgba(147, 197, 253, 0.15);
  border-left: 3px solid #60a5fa;
  position: relative;
}
.msg-summary .summary-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  color: #93c5fd;
  background: rgba(96, 165, 250, 0.12);
  padding: 2px 8px;
  border-radius: 10px;
  margin-bottom: 6px;
  font-weight: 500;
}
.msg-summary .summary-status {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 6px;
  font-weight: 400;
}
.msg-summary .summary-status.status-pending {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
}
.msg-summary .summary-status.status-ready {
  color: #34d399;
  background: rgba(52, 211, 153, 0.12);
}
.msg-summary .summary-status.status-archived {
  color: #818cf8;
  background: rgba(129, 140, 248, 0.12);
}
.msg-summary .summary-status.status-rejected {
  color: #f87171;
  background: rgba(248, 113, 113, 0.12);
}
.msg-summary .summary-collapse-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  color: #93c5fd;
  background: rgba(96, 165, 250, 0.08);
  border: 1px solid rgba(96, 165, 250, 0.2);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
  margin-top: 4px;
  transition: background 0.2s;
}
.msg-summary .summary-collapse-btn:hover {
  background: rgba(96, 165, 250, 0.18);
}
.msg-summary .summary-content-collapsed {
  max-height: 3.2em;
  overflow: hidden;
  position: relative;
}
.msg-summary .summary-content-collapsed::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1.2em;
  background: linear-gradient(transparent, #1a2332);
  pointer-events: none;
}
.msg-summary .summary-content-expanded {
  max-height: none;
}
.msg-summary .summary-actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.msg-summary .summary-actions .action-btn {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: all 0.15s;
}
.msg-summary .summary-actions .action-btn:hover {
  background: rgba(96, 165, 250, 0.15);
  border-color: rgba(96, 165, 250, 0.3);
  color: #93c5fd;
}
.msg-summary .summary-actions .action-btn.btn-archive {
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.25);
}
.msg-summary .summary-actions .action-btn.btn-archive:hover {
  background: rgba(52, 211, 153, 0.15);
  border-color: rgba(52, 211, 153, 0.4);
}
.msg-summary .summary-actions .action-btn.btn-delete {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.25);
}
.msg-summary .summary-actions .action-btn.btn-delete:hover {
  background: rgba(248, 113, 113, 0.15);
  border-color: rgba(248, 113, 113, 0.4);
}
.msg-summary .summary-actions .action-btn.btn-edit {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.25);
}
.msg-summary .summary-actions .action-btn.btn-edit:hover {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.4);
}
.msg-summary .summary-edit-textarea {
  width: 100%;
  min-height: 60px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(96, 165, 250, 0.3);
  border-radius: 6px;
  color: #d4dce8;
  font-size: 0.85rem;
  padding: 6px 8px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.5;
  margin-top: 4px;
}
.msg-summary .summary-edit-textarea:focus {
  outline: none;
  border-color: #60a5fa;
}
.msg-summary .summary-edit-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.msg-summary .summary-edit-actions button {
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.msg-summary .summary-edit-actions .btn-save-local {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}
.msg-summary .summary-edit-actions .btn-save-local:hover {
  background: #1d4ed8;
}
.msg-summary .summary-edit-actions .btn-save-remember {
  background: #059669;
  color: #fff;
  border-color: #059669;
}
.msg-summary .summary-edit-actions .btn-save-remember:hover {
  background: #047857;
}
.msg-summary .summary-edit-actions .btn-separator {
  color: rgba(255, 255, 255, 0.2);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  padding: 0 2px;
  user-select: none;
}
.msg-summary .summary-edit-actions .btn-cancel {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.6);
  border-color: rgba(255, 255, 255, 0.1);
}
.msg-summary .summary-edit-actions .btn-cancel:hover {
  background: rgba(255, 255, 255, 0.1);
}
.msg-summary .summary-confidence {
  font-size: 0.6rem;
  color: rgba(255, 255, 255, 0.3);
  margin-left: 6px;
}

/* 浅色主题归纳消息 */
[data-theme="light"] .msg-summary {
  background: linear-gradient(135deg, #f0f4ff 0%, #e8eef8 100%);
  color: #1a2332;
  border: 1px solid rgba(96, 165, 250, 0.25);
  border-left: 3px solid #3b82f6;
}
[data-theme="light"] .msg-summary .summary-badge {
  color: #3b82f6;
  background: rgba(59, 130, 246, 0.1);
}
[data-theme="light"] .msg-summary .summary-status.status-pending {
  color: #d97706;
  background: rgba(217, 119, 6, 0.1);
}
[data-theme="light"] .msg-summary .summary-status.status-ready {
  color: #059669;
  background: rgba(5, 150, 105, 0.1);
}
[data-theme="light"] .msg-summary .summary-status.status-archived {
  color: #6366f1;
  background: rgba(99, 102, 241, 0.1);
}
[data-theme="light"] .msg-summary .summary-status.status-rejected {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.1);
}
[data-theme="light"] .msg-summary .summary-collapse-btn {
  color: #3b82f6;
  background: rgba(59, 130, 246, 0.06);
  border-color: rgba(59, 130, 246, 0.2);
}
[data-theme="light"] .msg-summary .summary-collapse-btn:hover {
  background: rgba(59, 130, 246, 0.12);
}
[data-theme="light"] .msg-summary .summary-content-collapsed::after {
  background: linear-gradient(transparent, #f0f4ff);
}
[data-theme="light"] .msg-summary .summary-actions .action-btn {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.1);
  color: rgba(0, 0, 0, 0.5);
}
[data-theme="light"] .msg-summary .summary-actions .action-btn:hover {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.25);
  color: #3b82f6;
}
[data-theme="light"] .msg-summary .summary-edit-textarea {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(59, 130, 246, 0.3);
  color: #1a2332;
}
[data-theme="light"] .msg-summary .summary-edit-actions .btn-save-local {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}
[data-theme="light"] .msg-summary .summary-edit-actions .btn-save-local:hover {
  background: #1d4ed8;
}
[data-theme="light"] .msg-summary .summary-edit-actions .btn-save-remember {
  background: #059669;
  color: #fff;
  border-color: #059669;
}
[data-theme="light"]
  .msg-summary
  .summary-edit-actions
  .btn-save-remember:hover {
  background: #047857;
}
[data-theme="light"] .msg-summary .summary-edit-actions .btn-cancel {
  background: rgba(0, 0, 0, 0.05);
  color: rgba(0, 0, 0, 0.5);
  border-color: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .msg-summary .summary-edit-actions .btn-cancel:hover {
  background: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .msg-summary .summary-confidence {
  color: rgba(0, 0, 0, 0.25);
}

/* ========== 消息功能图标行 ========== */
.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 2px;
  opacity: 0.3;
  transition: opacity 0.2s;
}
.msg:hover .message-actions,
.msg.selected .message-actions {
  opacity: 1;
}
.action-btn {
  background: transparent;
  border: none;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}
.action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* 消息时间与按钮同行 */
.msg-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2px;
}
.msg-footer .msg-meta-text {
  font-size: 10px;
  color: inherit;
  opacity: 0.4;
}
.msg-footer .message-actions {
  margin-top: 0;
}

/* 整理菜单 */
.organize-menu {
  position: absolute;
  background: #1e1e2e;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 4px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 100;
  min-width: 160px;
}
.organize-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.organize-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* 批量工具条 */
.batch-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: rgba(37, 99, 235, 0.1);
  border-bottom: 1px solid rgba(37, 99, 235, 0.2);
}
.batch-toolbar.has-recall {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px 20px;
}
.batch-toolbar.has-recall .batch-left {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-self: start;
}
.batch-toolbar.has-recall .batch-center {
  justify-self: center;
}
.batch-toolbar.has-recall .batch-right {
  justify-self: end;
}
.batch-count {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  margin: 0 8px;
  min-width: 30px;
}

/* 整理编辑器弹窗 */
.organize-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.organize-editor {
  background: #1a1a2e;
  border-radius: 12px;
  padding: 20px;
  width: 90%;
  max-width: 480px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.organize-editor textarea {
  width: 100%;
  min-height: 100px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 12px;
  color: #fff;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}
.organize-editor textarea:focus {
  border-color: #2563eb;
}
.organize-editor-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  justify-content: flex-end;
}
.organize-editor-actions button {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: none;
}
.organize-editor-actions .btn-save {
  background: #2563eb;
  color: #fff;
}
.organize-editor-actions .btn-cancel {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
}

/* 选择模式 — 消息可点击切换 */
.messages.selecting .msg {
  cursor: pointer;
}
.messages.selecting .msg:hover {
  background: rgba(37, 99, 235, 0.08);
}

@media (max-width: 768px) {
  .action-btn {
    font-size: 0.75rem;
  }
  .message-actions {
    gap: 2px;
  }
  .batch-toolbar {
    padding: 6px 12px;
    gap: 4px;
  }
}

/* 消息元信息 */
.msg-meta {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.25);
  margin-bottom: 12px;
  text-align: right;
}
.msg-ai + .msg-meta {
  text-align: left;
}

/* 消息错误 */
.msg-error {
  background: rgba(248, 113, 113, 0.15);
  color: #fca5a5;
  font-size: 13px;
}

/* ========== 思考中动画 ========== */
.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  color: rgba(255, 255, 255, 0.4);
  font-size: 13px;
}
.thinking-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  animation: bounce 1.2s infinite;
}
.thinking-dot:nth-child(2) {
  animation-delay: 0.15s;
}
.thinking-dot:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-6px);
  }
}

/* --- 文档预览（对话区） --- */
.doc-preview-wrapper {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin-top: 8px;
  padding-top: 8px;
}

.doc-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(37, 99, 235, 0.1);
  border-radius: 8px 8px 0 0;
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-bottom: none;
}

.doc-preview-title {
  font-size: 12px;
  color: #60a5fa;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.doc-preview-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.15s;
  flex-shrink: 0;
}

.doc-preview-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.doc-preview-content {
  padding: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0 0 8px 8px;
  font-size: 14px;
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.85);
  max-height: 60vh;
  overflow-y: auto;
}

.doc-preview-content pre {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  padding: 12px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
  margin: 8px 0;
}

.doc-preview-content code {
  font-family: "Cascadia Code", "Fira Code", monospace;
  font-size: 13px;
}

.doc-preview-content p {
  margin: 8px 0;
}

.doc-preview-content h1,
.doc-preview-content h2,
.doc-preview-content h3,
.doc-preview-content h4 {
  margin: 16px 0 8px;
  color: #e0e0e0;
}

.doc-preview-content ul,
.doc-preview-content ol {
  padding-left: 24px;
  margin: 8px 0;
}

.doc-preview-content blockquote {
  border-left: 3px solid #2563eb;
  padding-left: 12px;
  margin: 8px 0;
  color: rgba(255, 255, 255, 0.6);
}

.doc-preview-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
}

.doc-preview-content th,
.doc-preview-content td {
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 6px 10px;
  text-align: left;
}

.doc-preview-content th {
  background: rgba(255, 255, 255, 0.05);
}

/* ========== 审计师诊断卡片 ========== */
.diagnosis-card {
  background: linear-gradient(
    135deg,
    rgba(15, 15, 35, 0.95),
    rgba(25, 20, 40, 0.95)
  );
  border: 1px solid rgba(255, 200, 50, 0.3);
  border-radius: 12px;
  padding: 16px;
  margin: 8px 0;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.diagnosis-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 200, 50, 0.15);
}

.diagnosis-icon {
  font-size: 20px;
}

.diagnosis-title {
  font-size: 15px;
  font-weight: 600;
  color: #f0d060;
  flex: 1;
}

.diagnosis-timestamp {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
}

.diagnosis-summary {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(255, 200, 50, 0.06);
  border-radius: 8px;
  line-height: 1.5;
}

.diagnosis-issues {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 单条问题卡片 */
.issue-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 12px;
  transition: border-color 0.2s;
}

.issue-card:hover {
  border-color: rgba(255, 200, 50, 0.25);
}

.issue-risk-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 4px;
  margin-bottom: 8px;
}

.risk-high {
  background: rgba(255, 50, 50, 0.15);
  color: #ff6b6b;
  border: 1px solid rgba(255, 50, 50, 0.3);
}

.risk-medium {
  background: rgba(255, 200, 50, 0.12);
  color: #f0c040;
  border: 1px solid rgba(255, 200, 50, 0.2);
}

.issue-code {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 8px;
  font-family: monospace;
  word-break: break-all;
}

.issue-root-cause,
.issue-impact,
.issue-suggestion {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  margin-bottom: 6px;
  line-height: 1.6;
}

.issue-root-cause strong,
.issue-impact strong,
.issue-suggestion strong {
  color: rgba(255, 255, 255, 0.9);
}

.issue-retry-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 14px;
  font-size: 12px;
  border: 1px solid rgba(255, 200, 50, 0.3);
  border-radius: 6px;
  background: rgba(255, 200, 50, 0.08);
  color: #f0c040;
  cursor: pointer;
  transition: all 0.2s;
}

.issue-retry-btn:hover {
  background: rgba(255, 200, 50, 0.18);
  border-color: rgba(255, 200, 50, 0.5);
}

/* 文件差异方向指示 */
.file-diff-direction {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 6px;
  padding: 4px 8px;
  background: rgba(100, 200, 255, 0.08);
  border-radius: 6px;
  line-height: 1.6;
}
