/* ===== CSS 变量（党政红 + 党徽金）===== */
:root {
  --primary: #c8102e;
  --primary-light: #e85667;
  --primary-dark: #9a0d22;
  --primary-soft: #fff1f2;
  --accent: #d4a017;
  --accent-light: #f0b429;
  --red: #c8102e;
  --red-soft: #fff1f2;
  --green: #10b981;
  --green-soft: #ecfdf5;
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface-alt: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.05);
  --shadow-glow: 0 8px 24px -4px rgba(200,16,46,0.25);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --font-sans: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Courier New', monospace;
  --transition: 0.2s ease;
  --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header（浅色现代风）===== */
.header {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
}
.logo-link {
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.2s;
}
.logo-link:hover { transform: scale(1.02); }
.logo-icon {
  font-size: 24px;
  display: inline-block;
  filter: drop-shadow(0 2px 4px rgba(200,16,46,0.2));
}
.logo-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-sub {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-top: 1px;
}
.nav-links {
  display: flex;
  gap: 2px;
}
.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  transition: all var(--transition);
}
.nav-link:hover {
  color: var(--primary);
  background: var(--primary-soft);
}
.nav-link.active {
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 600;
}

/* ===== Main Layout ===== */
.main {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: 20px 20px;
}
/* chat tab 突破 1400 限制，铺满视口（对话/成果区需要更宽空间） */
.main:has(#tab-chat.active) {
  max-width: none;
  padding: 20px 24px;
}
@media (max-width: 1280px) {
  .main:has(#tab-chat.active) { padding: 18px 16px; }
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Workspace ===== */
.workspace {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 20px;
  height: calc(100vh - 100px);
}

/* ===== Panel Shared ===== */
.panel-left, .panel-right, .polish-input-panel, .polish-output-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, var(--surface-alt), var(--surface));
}
.panel-header h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}
.panel-header p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ===== Left Panel ===== */
.panel-left {
  overflow-y: auto;
}
.panel-left::-webkit-scrollbar { width: 5px; }
.panel-left::-webkit-scrollbar-track { background: transparent; }
.panel-left::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }

/* ===== Doc Type Selection ===== */
.doc-type-section {
  padding: 18px 20px 0;
}
.doc-type-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  margin-top: 8px;
}
.doc-type-btn {
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  text-align: center;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}
.doc-type-btn:hover {
  border-color: var(--primary-light);
  color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
}
.doc-type-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(200,16,46,0.3);
  transform: translateY(-1px);
}

/* ===== Divider ===== */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 20px;
}

/* ===== Form ===== */
.doc-form {
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.form-row {
  display: flex;
  gap: 12px;
}
.form-group.half { flex: 1; }
.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}
.required {
  color: var(--red);
  margin-left: 2px;
}
.form-input, .form-textarea {
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
  resize: none;
}
.form-input:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(200,16,46,0.12);
  background: var(--surface);
}
.form-input::placeholder, .form-textarea::placeholder {
  color: var(--text-muted);
  font-size: 12px;
}
.form-textarea { line-height: 1.6; }

/* ===== Generate Button ===== */
.btn-generate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 13px 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 3px 10px rgba(200,16,46,0.25);
  margin-top: 4px;
  letter-spacing: 0.03em;
}
.btn-generate:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(200,16,46,0.3);
}
.btn-generate:active { transform: translateY(0); }
.btn-generate:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}
.btn-icon { font-size: 16px; }
.btn-text { letter-spacing: 0.04em; }

/* ===== Result Panel ===== */
.panel-right {
  display: flex;
  flex-direction: column;
}
.result-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, var(--surface-alt), var(--surface));
}
.result-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.result-title-row h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}
.result-actions {
  display: flex;
  gap: 8px;
}
.btn-action {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all var(--transition);
}
.btn-action:hover {
  border-color: var(--primary-light);
  color: var(--primary);
  background: var(--primary-soft);
}
.btn-polish-quick {
  border-color: #f0b429;
  color: #8a6300;
  background: #fffbeb;
}
.btn-polish-quick:hover {
  background: #fef3c7;
  border-color: var(--accent);
}
.result-meta {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.result-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.result-body::-webkit-scrollbar { width: 5px; }
.result-body::-webkit-scrollbar-track { background: transparent; }
.result-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  gap: 12px;
}
.empty-icon { font-size: 52px; opacity: 0.25; }
.empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
}
.empty-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.7;
}

/* ===== Document Output Styling ===== */
.doc-output {
  font-family: 'SimSun', 'FangSong', 'STSong', serif;
  font-size: 14.5px;
  line-height: 1.9;
  color: #1a1a1a;
  background: white;
  border-radius: var(--radius);
  padding: 40px 48px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  min-height: 400px;
  white-space: pre-wrap;
  word-break: break-all;
}
.doc-section-label {
  display: inline-block;
  background: var(--primary);
  color: white;
  font-size: 10px;
  font-family: var(--font-sans);
  padding: 1px 6px;
  border-radius: 3px;
  margin-bottom: 6px;
  margin-right: 6px;
  vertical-align: middle;
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* ===== Streaming cursor（升级版：发光呼吸光标）===== */
.cursor-blink {
  display: inline-block;
  width: 3px;
  height: 1.1em;
  background: linear-gradient(180deg, var(--primary), var(--primary-light));
  border-radius: 2px;
  margin-left: 3px;
  vertical-align: text-bottom;
  animation: cursor-pulse 1s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(200,16,46,0.4);
}
@keyframes cursor-pulse {
  0%, 100% { opacity: 1; transform: scaleY(1); }
  50% { opacity: 0.4; transform: scaleY(0.85); }
}
@keyframes blink {
  50% { opacity: 0; }
}

/* ===== Loading State ===== */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  gap: 16px;
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.loading-dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

/* ===== Polish Workspace ===== */
.polish-workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  height: calc(100vh - 100px);
}
.polish-input-panel {
  padding: 0;
}
.polish-input-panel .panel-header {
  flex-shrink: 0;
}
.polish-input-panel form,
.polish-input-panel > .form-group,
.polish-input-panel > .btn-generate {
  margin: 0 20px;
}
.polish-input-panel > * + * {
  margin-top: 14px;
}
.polish-input-panel > .form-group:last-of-type {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.polish-textarea {
  flex: 1;
  resize: none;
  min-height: 200px;
}
.polish-input-panel > .btn-generate {
  margin-bottom: 20px;
}

/* ===== Guide ===== */
.guide-container {
  max-width: 1100px;
  margin: 0 auto;
}
.guide-header {
  text-align: center;
  padding: 32px 0 28px;
}
.guide-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}
.guide-header p {
  font-size: 13px;
  color: var(--text-muted);
}
.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  padding-bottom: 32px;
}
.guide-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.guide-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-light);
}
.guide-card-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.guide-badge {
  background: rgba(255,255,255,0.18);
  color: white;
  font-size: 14px;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.25);
}
.guide-use {
  font-size: 11.5px;
  color: rgba(255,255,255,0.72);
}
.guide-card-body {
  padding: 16px 18px;
}
.guide-format {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.format-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 12.5px;
}
.fi-label {
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 1px;
}
.fi-val {
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1a1f2e;
  color: white;
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s ease;
  z-index: 999;
  pointer-events: none;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ===== Chat Workspace ===== */
.chat-workspace {
  display: grid;
  /* 侧栏固定 | 对话区限定阅读宽度 | 成果区吃掉剩余空间 */
  grid-template-columns: 260px minmax(380px, 540px) 1fr;
  gap: 18px;
  height: calc(100vh - 100px);
}
@media (max-width: 1440px) {
  .chat-workspace {
    grid-template-columns: 240px minmax(360px, 480px) 1fr;
    gap: 14px;
  }
}
@media (max-width: 1080px) {
  .chat-workspace {
    grid-template-columns: 220px minmax(320px, 440px) 1fr;
    gap: 12px;
  }
}
@media (max-width: 880px) {
  /* 窄屏：成果区落到对话下方占满宽度 */
  .chat-workspace {
    grid-template-columns: 200px 1fr;
    height: auto;
  }
  .result-panel { grid-column: 1 / -1; min-height: 600px; }
}

.chat-sidebar {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.chat-sidebar::-webkit-scrollbar { width: 5px; }
.chat-sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }

/* ===== 历史对话侧边栏 ===== */
.chat-sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.chat-sidebar-header h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}
.btn-new-chat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all var(--transition);
}
.btn-new-chat:hover {
  background: var(--primary-dark, #3651b3);
  transform: translateY(-1px);
}

.chat-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.chat-history-empty {
  padding: 30px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
}
.chat-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: all var(--transition);
  border: 1px solid transparent;
}
.chat-history-item:hover {
  background: var(--surface-alt);
}
.chat-history-item.active {
  background: var(--primary-soft);
  border-color: var(--primary-light);
}
.chat-history-info {
  flex: 1;
  min-width: 0;
}
.chat-history-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.chat-history-time {
  font-size: 11px;
  color: var(--text-muted);
}
.chat-history-del {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: all var(--transition);
}
.chat-history-item:hover .chat-history-del {
  opacity: 1;
}
.chat-history-del:hover {
  background: #fef2f2;
  color: var(--red);
}

/* ===== 欢迎页示例 ===== */
.chat-welcome-examples {
  margin-top: 28px;
  width: 100%;
  max-width: 720px;
}
.chat-welcome-examples-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-align: center;
}
.chat-welcome-examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.chat-welcome-example {
  display: block;
  text-align: left;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all var(--transition);
}
.chat-welcome-example:hover {
  background: var(--primary-soft);
  border-color: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.chat-welcome-example-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 4px;
}
.chat-welcome-example-prompt {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.chat-main {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }

.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  margin: auto;
}
.chat-welcome-icon {
  font-size: 56px;
  margin-bottom: 14px;
  opacity: 0.85;
}
.chat-welcome-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}
.chat-welcome-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.7;
}

/* 新用户引导 tips 卡 */
.chat-welcome-tips {
  margin: 20px auto 0;
  max-width: 720px;
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.04), rgba(59, 130, 246, 0.01));
  border: 1px solid rgba(59, 130, 246, 0.15);
  border-radius: 10px;
  padding: 14px 18px;
}
.chat-welcome-tip {
  font-size: 13px;
  color: var(--text-primary);
  margin-bottom: 10px;
  text-align: left;
}
.chat-welcome-tip strong { color: var(--primary); }
.chat-welcome-tip-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 18px;
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: left;
}
@media (max-width: 720px) {
  .chat-welcome-tip-grid { grid-template-columns: 1fr; }
}

/* 文风档位 + 金句开关 工具栏 */
.style-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 22px;
  padding: 8px 14px;
  margin-bottom: 8px;
  background: rgba(0, 0, 0, 0.015);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  font-size: 12.5px;
}
.style-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.style-group-label {
  color: var(--text-muted);
  margin-right: 4px;
  user-select: none;
}
.style-pill {
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 14px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}
.style-pill:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.style-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
/* 联网开关「开」高亮成绿色，强化"在线"感 */
.style-pill[data-web-search="on"].active {
  background: #10b981;
  border-color: #10b981;
}

/* 联网搜索：参考资料徽章 */
.msg-sources {
  margin-top: 10px;
  border: 1px solid rgba(59, 130, 246, 0.18);
  background: rgba(59, 130, 246, 0.04);
  border-radius: 8px;
  font-size: 12.5px;
  overflow: hidden;
}
.msg-sources > summary {
  cursor: pointer;
  padding: 8px 12px;
  color: var(--primary);
  font-weight: 500;
  user-select: none;
  list-style: none;
}
.msg-sources > summary::-webkit-details-marker { display: none; }
.msg-sources > summary::before { content: '▸ '; margin-right: 2px; transition: transform 0.15s; display: inline-block; }
.msg-sources[open] > summary::before { transform: rotate(90deg); }
.msg-sources > summary:hover { background: rgba(59, 130, 246, 0.06); }
.src-list { padding: 4px 12px 10px; display: flex; flex-direction: column; gap: 6px; }
.src-item {
  display: flex;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 5px;
  text-decoration: none;
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.5;
  transition: background 0.12s;
}
.src-item:hover { background: rgba(59, 130, 246, 0.08); }
.src-idx { color: var(--primary); font-weight: 600; flex-shrink: 0; }
.src-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-meta { color: var(--text-muted); font-size: 11px; flex-shrink: 0; }

.chat-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: msg-slide-in 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.chat-msg.user {
  flex-direction: row-reverse;
}
@keyframes msg-slide-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* 气泡的外层容器（包住气泡 + 操作按钮）*/
.chat-msg > div:not(.chat-avatar) {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: calc(100% - 50px);
  min-width: 0;
}
.chat-msg.user > div:not(.chat-avatar) {
  align-items: flex-end;
}
.chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
}
.chat-msg.user .chat-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #2a1c00;
}
.chat-msg.assistant .chat-avatar {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
}

.chat-bubble {
  display: inline-block;
  max-width: 100%;
  width: fit-content;
  padding: 11px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.chat-msg.user .chat-bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  border-top-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(200,16,46,0.18);
  /* 限制用户气泡宽度，避免长文本时延伸到助手 avatar 列。
     chat-main 在 A4 预览开启时仅 ~480px 宽，
     wrapper(366px) × 70% = 256px 即长文本最大宽度，
     可保留 80px+ 间隙与助手 avatar 分列清晰。 */
  max-width: 70%;
}
.chat-msg.assistant .chat-bubble {
  background: white;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  width: auto;
  min-width: 420px;
  max-width: 760px;
  box-shadow: var(--shadow-sm);
}
/* 当气泡内有公文卡时，气泡自身退让（让卡片接管视觉） */
.chat-msg.assistant .chat-bubble.has-doc {
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  white-space: normal;
  min-width: 480px;
  max-width: 760px;
}
.chat-msg.assistant .chat-bubble.has-doc .thinking-card {
  margin: 8px 4px;
}

/* 纯思考阶段：只有 thinking-card 没有正文时，气泡同样退让，避免框中框 */
.chat-msg.assistant .chat-bubble.is-thinking-only {
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  min-width: 0;
}
.chat-msg.assistant .chat-bubble.is-thinking-only .thinking-card {
  margin: 0;
}

/* Markdown 渲染样式（生成内容里的标题/列表/加粗等）*/
.chat-bubble .md-h {
  font-family: var(--font-sans);
  margin: 8px 0 4px;
  color: var(--primary);
  font-weight: 700;
  line-height: 1.4;
}
.chat-bubble h1.md-h { font-size: 16px; }
.chat-bubble h2.md-h { font-size: 15px; }
.chat-bubble h3.md-h { font-size: 14px; }
.chat-bubble h4.md-h { font-size: 13.5px; }
.chat-bubble .md-li {
  margin: 2px 0 2px 8px;
  line-height: 1.6;
}
.chat-bubble .md-hr {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 10px 0;
}
.chat-bubble strong { font-weight: 700; color: #1a1a1a; }
.chat-bubble em { font-style: italic; color: var(--text-secondary); }
.chat-bubble code {
  background: var(--surface-alt);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12.5px;
  font-family: ui-monospace, monospace;
}

.chat-msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.2s;
}
.chat-msg.assistant:hover .chat-msg-actions {
  opacity: 1;
}
.chat-msg-action {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all var(--transition);
}
.chat-msg-action:hover {
  background: var(--surface-alt);
  color: var(--primary);
  border-color: var(--primary-light);
}

/* ===== AI 正在思考（升级版：动态文字 + 三跳点 + 闪光）===== */
.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 4px 0;
  color: var(--primary);
  font-size: 13.5px;
  font-weight: 500;
}
.chat-typing-text {
  background: linear-gradient(90deg, var(--text-secondary) 0%, var(--primary) 50%, var(--text-secondary) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: text-shimmer 2s ease-in-out infinite;
}
@keyframes text-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.chat-typing-dots {
  display: inline-flex;
  gap: 4px;
}
.chat-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
  box-shadow: 0 0 6px rgba(200,16,46,0.4);
}
.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* AI 流式输出时气泡的微光效果 */
.chat-msg.assistant .chat-bubble.streaming {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(200,16,46,0.06), 0 2px 12px rgba(200,16,46,0.08);
  animation: streaming-glow 2.5s ease-in-out infinite;
}
@keyframes streaming-glow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(200,16,46,0.06), 0 2px 12px rgba(200,16,46,0.08); }
  50%      { box-shadow: 0 0 0 4px rgba(200,16,46,0.12), 0 2px 20px rgba(200,16,46,0.15); }
}
/* override：thinking-only / has-doc 与 streaming 并存时，光环 + 边框应消失，
   否则会看到一个"白块"（边框 + 光晕外环） */
.chat-msg.assistant .chat-bubble.streaming.is-thinking-only,
.chat-msg.assistant .chat-bubble.streaming.has-doc {
  border-color: transparent;
  box-shadow: none;
  animation: none;
}

/* 完成时的高亮一次 */
@keyframes msg-done-flash {
  0% { background: rgba(200,16,46,0.05); }
  100% { background: transparent; }
}
.chat-msg.just-finished .chat-bubble {
  animation: msg-done-flash 1.2s ease-out;
}

/* AI 状态标签（"政笔AI 正在书写..."）*/
.chat-status-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--primary);
  font-weight: 500;
  margin-top: 4px;
  margin-left: 2px;
  opacity: 0.85;
}
.chat-status-label::before {
  content: "✒️";
  font-size: 12px;
}

/* 输入区 */
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 14px 20px 16px;
  background: var(--surface-alt);
  position: relative; /* cfg-popover 绝对定位锚点 */
}
.chat-input-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.chat-input-wrap:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(200,16,46,0.1);
}
.chat-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  line-height: 1.6;
  padding: 6px 8px;
  max-height: 150px;
  background: transparent;
}
.chat-input::placeholder {
  color: var(--text-muted);
  font-size: 13px;
}
.btn-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(200,16,46,0.25);
}
.btn-send:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(200,16,46,0.35);
}
.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.chat-input-hint {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 4px;
}

/* ===== User Area ===== */
.user-area {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-guest {
  display: flex;
  gap: 8px;
}
.btn-auth {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all var(--transition);
}
.btn-auth:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}
.btn-auth-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  font-weight: 600;
}
.btn-auth-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(200,16,46,0.3);
}

.user-logged {
  display: flex;
  align-items: center;
  gap: 10px;
}
.credit-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  color: #4a3500;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(212,160,23,0.35);
  border: none;
}
.credit-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(212,160,23,0.5);
}
.credit-icon { font-size: 13px; }
.credit-count { font-size: 14px; }
.credit-unit { font-size: 11px; opacity: 0.75; }

.user-menu {
  position: relative;
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(200,16,46,0.25);
  transition: all var(--transition);
}
.user-avatar:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(200,16,46,0.4);
}
.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  overflow: hidden;
  display: none;
  border: 1px solid var(--border);
}
.user-dropdown.show { display: block; }
.dropdown-header {
  padding: 12px 16px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}
.dropdown-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.dropdown-credits {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
}
.dropdown-credits span {
  color: var(--accent);
  font-weight: 700;
}
.dropdown-item {
  display: block;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-primary);
  text-decoration: none;
  transition: background var(--transition);
}
.dropdown-item:hover {
  background: var(--surface-alt);
  color: var(--primary);
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 25, 45, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: white;
  border-radius: 18px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  position: relative;
  animation: slideUp 0.25s ease;
}
.modal-recharge { max-width: 560px; }
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  z-index: 2;
}
.modal-close:hover {
  background: var(--surface-alt);
  color: var(--text-primary);
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 18px 18px 0 0;
}
.modal-tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 16px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.modal-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: white;
}

.modal-body { padding: 28px 28px 24px; }
.auth-pane { display: none; }
.auth-pane.active { display: block; }
.auth-pane h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}
.auth-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}
.auth-pane .form-group {
  margin-bottom: 14px;
}
.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}
.auth-pane .btn-generate {
  width: 100%;
  margin-top: 8px;
}
.auth-switch {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 16px;
}
.auth-switch a {
  color: var(--primary-light);
  text-decoration: none;
  font-weight: 500;
}
.auth-switch a:hover { text-decoration: underline; }

/* ===== 登录/注册方式切换（邮箱 / 手机号）===== */
.auth-method {
  display: flex;
  gap: 6px;
  padding: 4px;
  margin-bottom: 18px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.auth-method-btn {
  flex: 1;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: calc(var(--radius-sm) - 3px);
  font-family: var(--font-sans);
  transition: all var(--transition);
}
.auth-method-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}
.reg-method-pane,
.login-method-pane { display: none; }
.reg-method-pane.active,
.login-method-pane.active { display: block; }

/* ===== Recharge ===== */
.recharge-header {
  padding: 26px 28px 18px;
  text-align: center;
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  border-radius: 18px 18px 0 0;
  border-bottom: 1px solid var(--border);
}
.recharge-header h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}
.recharge-header p {
  font-size: 12.5px;
  color: var(--text-secondary);
}
.recharge-current {
  padding: 12px 28px;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}
.recharge-current span {
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
}
.recharge-packages {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 12px 24px 16px;
}

/* ── 会员档位卡 ── */
.recharge-section-title {
  padding: 14px 24px 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary, #1f2328);
}
.recharge-section-title .rst-sub {
  font-weight: 400;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-left: 6px;
}
.member-plans {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px 24px 4px;
}
.member-card {
  position: relative;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
}
.member-card:hover {
  border-color: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.member-card.selected {
  border-color: var(--primary);
  background: #fdf3f4;
  box-shadow: 0 4px 12px rgba(200,16,46,0.18);
}
.member-hot { border-color: var(--primary-light); }
.member-tag {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.member-title {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.member-price {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 2px;
}
.member-price .mp-unit { font-size: 12px; font-weight: 400; color: var(--text-muted); }
.member-price .mp-was { font-size: 12px; font-weight: 400; color: var(--text-muted); margin-left: 2px; }
.member-desc { font-size: 11px; color: var(--text-muted); }

/* ── 头部会员徽标 / 下拉会员态 / 签到 ── */
.member-badge {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #8f6d24;
  background: linear-gradient(135deg, #fdf6e3, #faecc8);
  border: 1px solid #ecd9a0;
  border-radius: 99px;
  padding: 3px 10px;
  margin-right: 8px;
  white-space: nowrap;
}
.dropdown-member {
  margin-top: 4px;
  font-size: 12px;
  color: #8f6d24;
  font-weight: 600;
}
.dropdown-item-done { opacity: 0.55; pointer-events: none; }

/* ── 开票申请 ── */
.invoice-link-row {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
}
.invoice-link-row a { color: var(--primary); }
.invoice-form {
  margin-top: 10px;
  padding: 14px;
  border: 1px dashed var(--border-strong, #d1d5db);
  border-radius: var(--radius);
  background: var(--surface-alt, #f9fafb);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.invoice-form-title { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.invoice-form-row { display: flex; gap: 8px; }
.invoice-form-row .form-input { flex: 1; min-width: 0; }
.invoice-submit { align-self: flex-end; }

@media (max-width: 560px) {
  .member-plans { grid-template-columns: repeat(3, 1fr); padding: 12px 16px 4px; }
  .invoice-form-row { flex-direction: column; }
}
.package-card {
  position: relative;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
}
.package-card:hover {
  border-color: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.package-card.selected {
  border-color: var(--accent);
  background: #fffbeb;
  box-shadow: 0 4px 12px rgba(240,180,41,0.3);
}
.package-hot {
  border-color: var(--accent);
}
.package-tag {
  position: absolute;
  top: -8px;
  right: -6px;
  background: var(--red);
  color: white;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}
.package-title {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.package-price {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 2px;
}
.package-credits {
  font-size: 11.5px;
  color: var(--accent);
  font-weight: 600;
}
.recharge-custom {
  padding: 16px 28px 24px;
  border-top: 1px dashed var(--border);
}
.recharge-custom .field-label {
  margin-bottom: 8px;
  display: block;
}
.recharge-custom-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.recharge-custom-row .form-input {
  flex: 1;
}
.recharge-custom-row .btn-generate {
  margin-top: 0;
  white-space: nowrap;
  padding: 10px 18px;
}
.recharge-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 10px;
  text-align: center;
}

.btn-wxpay {
  background: linear-gradient(135deg, #07c160 0%, #06a854 100%) !important;
  box-shadow: 0 3px 10px rgba(7,193,96,0.35) !important;
}
.btn-wxpay:hover {
  box-shadow: 0 6px 16px rgba(7,193,96,0.45) !important;
}

/* ===== QR Code Payment View ===== */
.qr-header {
  text-align: center;
  padding: 26px 28px 18px;
  background: linear-gradient(135deg, #e6fff0 0%, #d4f4dd 100%);
  border-radius: 18px 18px 0 0;
  border-bottom: 1px solid var(--border);
}
.wxpay-logo {
  display: inline-block;
  background: #07c160;
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
  letter-spacing: 0.04em;
}
.qr-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
}
.qr-amount {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  color: #07c160;
}
.qr-currency {
  font-size: 20px;
  font-weight: 600;
}
.qr-amount-num {
  font-size: 36px;
  font-weight: 700;
  font-family: 'Helvetica Neue', sans-serif;
  letter-spacing: -0.02em;
}
.qr-suffix {
  font-size: 13px;
  color: var(--text-secondary);
  margin-left: 8px;
  align-self: center;
}
.qr-suffix b {
  color: var(--accent);
  font-weight: 700;
}

.qr-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  padding: 24px 28px 28px;
}
.qr-code-wrap {
  position: relative;
  background: white;
  padding: 12px;
  border: 2px solid #07c160;
  border-radius: 12px;
  width: 260px;
  height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(7,193,96,0.2);
}
.qr-code-img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 6px;
}
.qr-code-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  animation: fadeIn 0.3s ease;
}
.qr-overlay-icon {
  font-size: 64px;
  margin-bottom: 10px;
  animation: successPop 0.4s ease;
}
.qr-overlay-text {
  font-size: 18px;
  font-weight: 700;
  color: #07c160;
}
@keyframes successPop {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.qr-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.qr-step {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.qr-step b {
  color: #07c160;
  margin-right: 4px;
}
.qr-order {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 8px;
  word-break: break-all;
  padding: 6px 10px;
  background: var(--surface-alt);
  border-radius: 6px;
}
.qr-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #fff8e7;
  border: 1px solid #f0d080;
  border-radius: 8px;
  font-size: 12.5px;
  color: #8a6300;
  margin-top: 4px;
}
.qr-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f0b429;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.5); }
}
.qr-status.paid {
  background: #e6fff0;
  border-color: #07c160;
  color: #067b3e;
}
.qr-status.paid .qr-status-dot {
  background: #07c160;
  animation: none;
}
.qr-status.failed {
  background: #fef2f2;
  border-color: #f5b5b5;
  color: #c0392b;
}
.qr-status.failed .qr-status-dot {
  background: #c0392b;
  animation: none;
}

.qr-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.btn-simulate {
  background: #fffbeb !important;
  border-color: #f0b429 !important;
  color: #8a6300 !important;
}
.btn-simulate:hover {
  background: #fef3c7 !important;
}

@media (max-width: 560px) {
  .qr-body { grid-template-columns: 1fr; }
  .qr-code-wrap { margin: 0 auto; }
}

/* ===== Responsive ===== */
@media (max-width: 960px) {
  .workspace, .polish-workspace {
    grid-template-columns: 1fr;
    height: auto;
  }
  .panel-left {
    max-height: none;
    overflow: visible;
  }
  .doc-type-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
@media (max-width: 600px) {
  .header-inner { padding: 0 16px; }
  .logo-title { font-size: 15px; }
  .nav-link { padding: 5px 10px; font-size: 12px; }
  .main { padding: 12px; }
  .doc-type-grid { grid-template-columns: repeat(4, 1fr); }
  .doc-output { padding: 24px 20px; }
}

/* ===== 我的样本 / 写作风格 ===== */
.refs-container {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px;
  max-width: 960px;
  margin: 0 auto;
}
.refs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 12px;
}
.refs-header h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.refs-header p { color: var(--text-secondary); font-size: 13px; }
.refs-stats {
  background: var(--surface-alt);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
}

.refs-intro {
  display: flex;
  gap: 14px;
  padding: 16px 18px;
  background: linear-gradient(135deg, rgba(79,70,229,.06), rgba(245,158,11,.04));
  border: 1px solid var(--primary-light);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-secondary);
}
.refs-intro-icon { font-size: 22px; flex-shrink: 0; }
.refs-intro strong { color: var(--text-primary); margin-right: 4px; }
.refs-intro em { color: var(--primary); font-style: normal; font-weight: 600; }

.refs-upload {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 24px;
}
.refs-upload:hover, .refs-upload.dragover {
  border-color: var(--primary);
  background: rgba(79,70,229,.04);
}
.refs-upload-icon { font-size: 36px; margin-bottom: 10px; opacity: 0.8; }
.refs-upload-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.refs-upload-sub { font-size: 12px; color: var(--text-muted); }

.refs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.refs-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.refs-empty-icon { font-size: 48px; margin-bottom: 10px; opacity: 0.6; }
.refs-empty-sub { font-size: 12.5px; margin-top: 6px; color: var(--text-muted); }

.refs-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: all 0.2s;
}
.refs-item:hover { border-color: var(--primary-light); transform: translateX(2px); }
.refs-item-icon { font-size: 28px; }
.refs-item-info { flex: 1; min-width: 0; }
.refs-item-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.refs-item-meta { font-size: 12px; color: var(--text-muted); }
.refs-item-actions { display: flex; gap: 6px; }
.refs-item-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}
.refs-item-btn:hover { background: white; border-color: var(--primary); }
.refs-item-btn-del:hover { border-color: var(--red); color: var(--red); background: #fef2f2; }

.refs-preview {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.refs-preview-card {
  background: white;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 760px;
  max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 25px 60px rgba(0,0,0,.3);
}
.refs-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.refs-preview-header h3 { font-size: 16px; font-weight: 600; margin: 0; }
.refs-preview-close {
  background: none; border: none; font-size: 26px;
  cursor: pointer; color: var(--text-muted);
  width: 32px; height: 32px; line-height: 1;
  border-radius: 6px;
}
.refs-preview-close:hover { background: var(--surface-alt); color: var(--red); }
.refs-preview-body {
  flex: 1; overflow: auto;
  padding: 20px;
  font-family: "FangSong", "STSong", "SimSun", serif;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0;
}

/* ===== 应用我的写作风格 toggle ===== */
.use-refs-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 12.5px;
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: all 0.2s;
}
.use-refs-toggle:hover:not(.disabled) {
  background: rgba(79,70,229,.06);
  border-color: var(--primary-light);
  color: var(--primary);
}
.use-refs-toggle input { cursor: pointer; }
.use-refs-toggle.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.use-refs-toggle.disabled input { cursor: not-allowed; }
.use-refs-toggle-block {
  display: flex;
  width: 100%;
  justify-content: center;
  margin-bottom: 10px;
  padding: 8px 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}
.use-refs-toggle-block:hover:not(.disabled) {
  background: rgba(79,70,229,.04);
}

/* ===== 涉密警示 ===== */
.refs-warning {
  display: flex;
  gap: 14px;
  padding: 18px 20px;
  background: #fff5f5;
  border: 2px solid #fcc;
  border-left: 5px solid var(--red);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
}
.refs-warning-icon {
  font-size: 28px;
  flex-shrink: 0;
  line-height: 1;
}
.refs-warning-text {
  flex: 1;
  font-size: 13px;
  color: #5d1a14;
  line-height: 1.7;
}
.refs-warning-text strong {
  display: block;
  font-size: 14.5px;
  color: var(--red);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}
.refs-warning-text ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.refs-warning-text ul li {
  padding: 3px 0;
}
.refs-warning-text ul li strong {
  display: inline;
  font-size: inherit;
  margin: 0;
  color: var(--red);
}

/* ===== 邮箱验证码输入行 ===== */
.code-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.code-input-row .form-input.code-input {
  flex: 1;
  letter-spacing: 4px;
  font-size: 14px;
  font-family: var(--font-mono);
  text-align: center;
}
.btn-send-code {
  flex-shrink: 0;
  padding: 0 14px;
  border: 1.5px solid var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all var(--transition);
  white-space: nowrap;
  min-width: 96px;
}
.btn-send-code:hover:not(:disabled) {
  background: var(--primary);
  color: white;
}
.btn-send-code:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--surface-alt);
  color: var(--text-muted);
  border-color: var(--border);
}

/* ===== 思考过程区块 ===== */
.thinking-block {
  margin-bottom: 14px;
  border: none;
  border-left: 2px solid #e5e7eb;
  border-radius: 0;
  background: transparent;
  overflow: hidden;
  transition: border-color 0.3s;
}
.thinking-block.is-active {
  border-left-color: #a78bfa;
  animation: think-pulse 2s ease-in-out infinite;
}
@keyframes think-pulse {
  0%, 100% { border-left-color: #a78bfa; }
  50% { border-left-color: #ddd6fe; }
}
/* summary 行 */
.thinking-summary {
  padding: 3px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: #b0b7c3;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s;
  letter-spacing: 0.01em;
}
.thinking-summary:hover { color: #6b7280; }
.thinking-summary::-webkit-details-marker { display: none; }
.thinking-icon {
  display: inline-block;
  width: 0; height: 0;
  border-left: 4px solid currentColor;
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.thinking-block[open] .thinking-icon {
  transform: rotate(90deg);
}
/* 正文区 */
.thinking-content {
  padding: 4px 10px 8px;
  color: #b0b7c3;
  font-size: 12px;
  font-style: italic;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 280px;
  overflow-y: auto;
}
.thinking-content::-webkit-scrollbar { width: 3px; }
.thinking-content::-webkit-scrollbar-thumb {
  background: #e5e7eb;
  border-radius: 2px;
}
/* 聊天气泡里的思考块 */
.chat-bubble .thinking-block {
  margin-bottom: 10px;
}
.chat-bubble .thinking-content {
  max-height: 220px;
}

/* ===== 终止按钮 ===== */
.btn-send.is-stop {
  background: linear-gradient(135deg, #6b7280, #4b5563);
  box-shadow: 0 2px 8px rgba(75, 85, 99, 0.3);
  animation: stop-pulse 1.5s ease-in-out infinite;
}
.btn-send.is-stop:hover {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
}
@keyframes stop-pulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(75, 85, 99, 0.3); }
  50% { box-shadow: 0 2px 12px rgba(75, 85, 99, 0.5); }
}

/* ═══════════════════════════════════════════════════════════════
 *  公文卡片 v2  (.doc-card)
 *  统一供 chat 气泡内、表单结果区、润色结果区
 * ═══════════════════════════════════════════════════════════════ */
.doc-card {
  position: relative;
  display: block;
  background: #fdfcf7;                              /* 极淡米色，仿公文用纸 */
  border: 1px solid #e8e4d8;
  border-radius: 10px;
  padding: 44px 56px 56px;                          /* 公文版式留白，更接近 A4 */
  max-width: 780px;                                 /* A4 阅读宽度，超宽屏不撑满 */
  margin: 0 auto;                                   /* 在成果区里居中 */
  box-shadow:
    0 1px 2px rgba(0,0,0,0.04),
    0 8px 24px rgba(120, 80, 30, 0.06);
  overflow: hidden;
}
.doc-card.is-final {
  animation: doc-card-in 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes doc-card-in {
  from { opacity: 0.4; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 顶部装饰条（仿公文红头） */
.doc-card-band {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary) 0%, #d4a017 100%);
}

/* 右下角水印 */
.doc-card-watermark {
  position: absolute;
  bottom: 10px; right: 14px;
  font-size: 10.5px;
  color: rgba(140, 120, 80, 0.32);
  letter-spacing: 0.5px;
  font-family: var(--font-sans);
  pointer-events: none;
  user-select: none;
}

/* ──────────────────────────────────────────────────────────
 * 公文卡片排版规格（严格对齐 Word 导出 / GB/T 9704-2012）
 *
 *   字号：用 pt 单位（与 docx 完全同度量）
 *     - 标题 22pt（二号），正文/主送/落款/附件 16pt（三号）
 *   行距：固定 28pt（与 docx WD_LINE_SPACING.EXACTLY / Pt(28) 完全一致）
 *   字体：从 :root 变量统一定义，与 server.py FONT_FALLBACK 严格对照
 * ────────────────────────────────────────────────────────── */
/* ──────────────────────────────────────────────────────────
 * 思源宋体（Noto Serif SC）—— Web Font 兜底
 * macOS 没装"仿宋_GB2312"，正文 fallback 会落到"华文宋体"，与其他段差距大
 * 加载思源宋体 Light(300) 作为正文兜底，最接近仿宋的开源衬线字体
 * 单字重 ~1.5MB，3 个权重共 ~4.5MB，font-display: swap 不阻塞首屏
 * ────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'GongwenFangSongFallback';
  src: url('/fonts/noto-serif-sc-300.woff2') format('woff2');
  font-display: swap;
  font-weight: 300 400;          /* 涵盖 normal 和 light 范围 */
  font-style: normal;
}
@font-face {
  font-family: 'GongwenFangSongFallback';
  src: url('/fonts/noto-serif-sc-700.woff2') format('woff2');
  font-display: swap;
  font-weight: 600 900;          /* 加粗时用 700 文件 */
  font-style: normal;
}

:root {
  /* 4 类字体栈 — Windows 命中前段（真公文字体），macOS 命中后段（华文系列 + Web Font 兜底）
     关键修复（GB/T 9704-2012）：
     1) 一级标题 fallback 加 Hiragino Sans GB（冬青黑体），mac 上不再落到苹方
     2) 正文/标题 fallback 末尾加 GongwenFangSongFallback（思源宋体 Light）
        mac 上没"仿宋"字体时不再直接落到华文宋体，而是先用思源宋体细体（更接近仿宋视觉）
     3) 与 server.py FONT_FALLBACK 严格对照，确保渲染端 / Word 端视觉一致 */
  --doc-font-title:    "方正小标宋_GBK", "方正小标宋简体", "FZXiaoBiaoSong-B07S",
                       "STZhongsong", "华文中宋", "Songti SC",
                       "GongwenFangSongFallback",
                       "SimSun", "宋体", serif;
  --doc-font-fangsong: "仿宋_GB2312", "仿宋", "FangSong", "STFangsong", "华文仿宋",
                       "FangSong_GB2312",
                       "GongwenFangSongFallback",
                       "Songti SC", serif;
  --doc-font-hei:      "黑体", "SimHei",
                       "Hiragino Sans GB", "Hiragino Sans GB W3", "冬青黑体简体中文",
                       "STHeiti", "华文黑体", "Heiti SC", "PingFang SC", sans-serif;
  --doc-font-kai:      "楷体_GB2312", "楷体", "KaiTi", "STKaiti", "华文楷体", "Kaiti SC", serif;
  /* 行距：与 docx Pt(28) 完全一致 */
  --doc-line-height:   28pt;
}

/* ── 红头版头：发文机关标志（红色小标宋）+ 发文字号 + 红色反线 ── */
.doc-card .doc-org-banner {
  font-family: var(--doc-font-title);
  font-size: 26pt;                       /* ≈ 一号，GB 发文机关标志 */
  font-weight: 700;
  color: #e60000;
  text-align: center;
  line-height: 1.4;
  letter-spacing: 0.06em;
  margin: 4px 0 0;
}
.doc-card .doc-issue-no {
  font-family: var(--doc-font-fangsong);
  font-size: 16pt;
  color: #000;
  text-align: center;
  margin: 12px 0 0;
}
.doc-card .doc-red-rule {
  height: 3px;
  background: #e60000;
  margin: 14px 0 6px;
}

/* 标题：方正小标宋 二号 22pt，居中加粗 */
.doc-card .doc-title {
  font-family: var(--doc-font-title);
  font-size: 22pt;
  font-weight: 800;
  text-align: center;
  margin: 12px 0 8px;
  color: #000;
  letter-spacing: 0.08em;
  line-height: 1.4;
  white-space: normal;
  /* 微伪粗体补无方正小标宋时的厚度（macOS 上回退到 STSong 较细） */
  text-shadow: 0 0.4px 0 currentColor;
}
@media (max-width: 720px) {
  .doc-card { padding: 28px 22px 36px; }
  .doc-card .doc-title { font-size: 18pt; letter-spacing: 0.06em; }
}

/* 标题下短装饰横线 */
.doc-card .doc-title-rule {
  width: 56px;
  height: 2px;
  margin: 18px auto 30px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  opacity: 0.55;
}

/* 主送：仿宋 三号 16pt，顶格 */
.doc-card .doc-recipient {
  font-family: var(--doc-font-fangsong);
  font-size: 16pt;
  font-weight: 400;
  color: #000;
  line-height: var(--doc-line-height);
  margin: 0 0 10px;
}

/* 段内小标题（会议概况/讨论内容/决定事项）—— 黑体 三号 16pt */
.doc-card .doc-subhead {
  font-family: var(--doc-font-hei);
  font-size: 16pt;
  font-weight: 700;
  color: #000;
  margin: 22px 0 8px;
  text-indent: 2em;
  letter-spacing: 0.02em;
}

/* 正文：仿宋 三号 16pt，固定行距 28pt，首行缩进 2 字 */
.doc-card .doc-body {
  font-family: var(--doc-font-fangsong);
  font-size: 16pt;
  line-height: var(--doc-line-height);
  color: #000;
  margin: 6px 0;
}
.doc-card .doc-body p {
  margin: 0;
  text-indent: 2em;
  text-align: justify;
}
.doc-card .doc-body p:empty { display: none; }
.doc-card .doc-body strong { font-weight: 700; color: #000; }

/* 一级小标题（一、二、三、）—— 黑体 三号 加粗 */
.doc-card .doc-body p.doc-h1 {
  font-family: var(--doc-font-hei);
  font-weight: 700;
  text-align: left;
  margin: 12px 0 2px;
  letter-spacing: 0.02em;
}
/* 二级小标题（（一）（二）（三））—— 楷体 三号 */
.doc-card .doc-body p.doc-h2 {
  font-family: var(--doc-font-kai);
  font-weight: 700;
  text-align: left;
  margin: 8px 0 2px;
}
/* 三级小标题（1. 2. 3.）—— 仿宋 三号 加粗 */
.doc-card .doc-body p.doc-h3 {
  font-weight: 700;
  text-align: left;
  margin: 4px 0 2px;
}

/* 结尾语：仿宋 三号 16pt 首行缩进 */
.doc-card .doc-closing {
  font-family: var(--doc-font-fangsong);
  font-size: 16pt;
  line-height: var(--doc-line-height);
  color: #000;
  text-indent: 2em;
  margin-top: 6px;
}

/* 落款：仿宋 三号 16pt，居右；机关名右空 4 字、日期右空 2 字 */
.doc-card .doc-signoff {
  margin-top: 36pt;                       /* 与 docx _add_para space_before 类比 */
  font-family: var(--doc-font-fangsong);
  font-size: 16pt;
  line-height: var(--doc-line-height);
  color: #000;
  text-align: right;
}
.doc-card .doc-signoff > div { font-weight: 400; }
/* 右空字数由 app.js 按 GB/T 9704 落款算法内联（日期右空四字、署名以日期为中心居中） */

/* 附件：仿宋 三号 16pt 左空 2 字 */
.doc-card .doc-attachment {
  margin-top: 22px;
  padding: 6px 12px;
  font-family: var(--doc-font-fangsong);
  font-size: 16pt;
  color: #000;
  line-height: var(--doc-line-height);
  border-left: 3px solid #d4a017;
  text-indent: 2em;
}
.doc-card .doc-attachment-label {
  display: inline;
  font-weight: 700;
  margin-right: 2px;
}
.doc-card .doc-attachment-extra {
  margin-top: 4px;
  font-size: 21px;
  color: #000;
  text-indent: 2em;
}

/* 令号 / 签发人（命令文种） */
.doc-card .doc-meta-line {
  text-align: center;
  font-family: var(--font-sans);
  font-size: 14px;
  color: #555;
  margin: 8px 0;
}
.doc-card .doc-meta-label {
  display: inline-block;
  color: var(--primary);
  font-weight: 600;
  margin-right: 8px;
}

/* 版记：抄送 / 印发机关 —— 仿宋四号 14pt，抄送上方细分隔线（与 docx 一致） */
.doc-card .doc-copyline {
  margin-top: 24px;
  padding-top: 8px;
  border-top: 1px solid #333;
  font-family: var(--doc-font-fangsong);
  font-size: 14pt;
  line-height: 1.6;
  color: #000;
}
.doc-card .doc-copyline + .doc-copyline {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
.doc-card .doc-printline {
  margin-top: 4px;
  font-family: var(--doc-font-fangsong);
  font-size: 14pt;
  line-height: 1.6;
  color: #000;
}

/* hover 显示右上角操作按钮 */
.doc-card:hover ~ .chat-msg-actions,
.doc-card:hover + .chat-msg-actions { opacity: 1 !important; }

/* ═══════════════════════════════════════════════════════════════
 *  流式中：pre 节点，仅 textContent 增量更新，绝不重建
 *  .stream-doc 嵌在 .doc-card-streaming 外壳里，跟 .doc-card 共享视觉
 * ═══════════════════════════════════════════════════════════════ */
.stream-doc {
  display: block;
  font-family: var(--doc-font-fangsong);
  font-size: 16pt;
  line-height: var(--doc-line-height);
  color: #000;
  padding: 0;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: transparent;
  border: none;
  font-variant-ligatures: none;
}

/* 流式版 doc-card：和最终态共享 .doc-card 主样式，但不带入场动画、文风稍异 */
.doc-card-streaming { /* 继承 .doc-card 的所有样式（class 共存） */ }
.doc-card-streaming .doc-card-watermark {
  color: rgba(140, 120, 80, 0.42);   /* 起草中：水印稍明显，提示用户"还没完成" */
}

/* 思考块和下方公文卡之间留视觉间距，避免紧贴 */
.thinking-card + .doc-card,
.thinking-card + .doc-card-streaming {
  margin-top: 16px;
}
/* 折叠胶囊态时再多一点缓冲 */
.thinking-card:not([open]) + .doc-card,
.thinking-card:not([open]) + .doc-card-streaming {
  margin-top: 20px;
}

/* ══════════════════════════════════════════════════════════════
 *  成果区 A4 等比缩放（容器查询）
 *  之前的问题：doc-card 里全部是固定 pt 字号，右栏 400~500px 宽时
 *  22pt 标题折成三行、每行只排十几个字，看起来"格式坏了"。
 *  方案：以 A4 版面宽 595pt 为基准，把字号/行距/页边距换算成容器
 *  宽度百分比（cqw），面板多宽都是一张等比缩小的 A4——
 *  与 Word 打开 docx 的换行、比例一致。
 *  旧的 pt 值保留作为不支持容器查询浏览器的兜底。
 *  换算：1pt = 100/595 cqw ≈ 0.168cqw
 * ══════════════════════════════════════════════════════════════ */
@supports (container-type: inline-size) {
  .result-panel-body { container-type: inline-size; }

  .result-panel-body .doc-card {
    /* 纸张宽高/页边距的等比覆盖在下方"A4 纸张感预览"段落里；这里只管排版度量 */
    --doc-line-height: max(4.7cqw, 18px);
  }
  .result-panel-body .doc-card .doc-title {
    font-size: max(3.7cqw, 14px);          /* 二号 22pt */
  }
  .result-panel-body .doc-card .doc-recipient,
  .result-panel-body .doc-card .doc-subhead,
  .result-panel-body .doc-card .doc-body,
  .result-panel-body .doc-card .doc-closing,
  .result-panel-body .doc-card .doc-signoff,
  .result-panel-body .doc-card .doc-attachment,
  .result-panel-body .doc-card .doc-attachment-extra,
  .result-panel-body .doc-card .stream-doc {
    font-size: max(2.69cqw, 10px);         /* 三号 16pt */
  }
  .result-panel-body .doc-card .doc-copyline,
  .result-panel-body .doc-card .doc-printline {
    font-size: max(2.35cqw, 9px);          /* 四号 14pt */
  }
  .result-panel-body .doc-card .doc-org-banner {
    font-size: max(4.37cqw, 15px);         /* 一号 26pt */
  }
  .result-panel-body .doc-card .doc-issue-no {
    font-size: max(2.69cqw, 10px);
  }
  .result-panel-body .doc-card .doc-red-rule {
    height: max(0.5cqw, 2px);
  }
  .result-panel-body .doc-card .doc-signoff {
    margin-top: 6cqw;                       /* ≈ 36pt */
  }
}

/* 表单/润色结果区：外层 .doc-output 在含 doc-card / stream-doc / thinking 时全部退让，
   由内部内容自行管理边框背景，避免"框中框" */
.doc-output .doc-card { margin: 0; }
.doc-output:has(.doc-card),
.doc-output:has(.stream-doc),
.doc-output:has(.thinking-card) {
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  min-height: 0;
}
/* 兜底：streamOutput 一旦出现（任何流式状态），都退让 */
#streamOutput { padding: 0; background: transparent; border: none; box-shadow: none; min-height: 0; }

/* ═══════════════════════════════════════════════════════════════
 *  思考便签 v3  (.thinking-card)  暖米灰色调 / 与公文纸色呼应
 * ═══════════════════════════════════════════════════════════════ */
.thinking-card {
  margin: 10px 0 14px;
  background: #fafaf6;
  border: 1px solid #ebe7dc;
  border-left: 2px solid #a8a297;
  border-radius: 6px;
  overflow: hidden;
  transition: all 0.25s;
  /* is-thinking-only 让外层 chat-bubble 收缩到 fit-content(~116px)，
     summary 的 think-time 会被压窄导致 "57 秒" 逐字换行 3 行 → summary 73px 高。
     给思考框定最小宽度，避免内容被压缩。 */
  min-width: 320px;
  max-width: 100%;
}
.thinking-card.is-active {
  animation: think-glow 2.4s ease-in-out infinite;
}
@keyframes think-glow {
  0%, 100% {
    border-left-color: #a8a297;
    box-shadow: 0 0 0 0 rgba(168, 162, 151, 0);
  }
  50% {
    border-left-color: #8a8478;
    box-shadow: 0 0 0 3px rgba(168, 162, 151, 0.10);
  }
}

.thinking-card .think-summary {
  list-style: none;
  cursor: pointer;
  padding: 7px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: #6b6862;
  font-weight: 500;
  user-select: none;
  transition: background 0.15s;
}
.thinking-card .think-summary::-webkit-details-marker { display: none; }
.thinking-card .think-summary:hover { background: rgba(168, 162, 151, 0.06); }

.thinking-card .think-icon { font-size: 13px; line-height: 1; opacity: 0.85; flex: 0 0 auto; }
.thinking-card .think-state { flex: 0 0 auto; white-space: nowrap; }
.thinking-card .think-time {
  font-size: 11px;
  background: rgba(168, 162, 151, 0.18);
  color: #6b6862;
  padding: 1px 8px;
  border-radius: 8px;
  font-weight: 500;
  flex: 0 0 auto;          /* 防止 flex 容器收缩时被压窄导致换行 */
  white-space: nowrap;     /* "57 秒" 不可换行 */
  letter-spacing: 0.5px;
}
.thinking-card .think-toggle {
  margin-left: auto;
  color: #a8a297;
  font-size: 10px;
  transition: transform 0.2s;
}
.thinking-card[open] .think-toggle { transform: rotate(90deg); }

.thinking-card .think-body {
  padding: 6px 16px 12px;
  font-family: "FangSong", "STFangsong", "KaiTi", serif;
  font-size: 12.5px;
  line-height: 1.7;
  color: #6b6862;
  /* pre-line：保留换行但折叠所有连续空白，杜绝模型输出"\n\n\n"产生的多行空白 */
  white-space: pre-line;
  word-break: break-word;
  max-height: 280px;
  overflow-y: auto;
  border-top: 1px dashed rgba(168, 162, 151, 0.28);
  letter-spacing: 0.01em;
}
.thinking-card .think-body:empty {
  display: none;                                /* 内容真为空时不要占位 */
}
.thinking-card .think-body::-webkit-scrollbar { width: 4px; }
.thinking-card .think-body::-webkit-scrollbar-thumb {
  background: #d8d3c4;
  border-radius: 2px;
}

/* 折叠态：变成紧凑胶囊 */
.thinking-card:not([open]) {
  display: inline-flex;
  background: #f3f1ea;
  border: 1px solid #e3dfd1;
  border-left: 2px solid #a8a297;
  border-radius: 14px;
}
.thinking-card:not([open]) .think-summary {
  padding: 4px 12px;
}

/* ═══════════════════════════════════════════════════════════════
 *  流式状态指示 v3  (.stream-status)  同步暖米灰
 * ═══════════════════════════════════════════════════════════════ */
.stream-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  padding: 4px 12px;
  font-size: 12px;
  color: #6b6862;
  background: #f3f1ea;
  border: 1px solid #e3dfd1;
  border-radius: 12px;
  font-weight: 500;
  position: relative;
  overflow: hidden;
}
.stream-status .ss-icon { font-size: 13px; opacity: 0.85; }
.stream-status .ss-text { letter-spacing: 0.3px; }
.stream-status .ss-glow {
  position: absolute;
  top: 0; left: -30%;
  width: 40%; height: 100%;
  background: linear-gradient(90deg,
    transparent,
    rgba(168, 162, 151, 0.32),
    transparent);
  animation: ss-sweep 1.8s linear infinite;
}
@keyframes ss-sweep {
  to { left: 130%; }
}

/* ═══════════════════════════════════════════════════════════════
 *  成果区 (.result-panel)  右侧公文呈现 + 编辑 + 评论
 * ═══════════════════════════════════════════════════════════════ */
.result-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.result-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface-alt), var(--surface));
  flex-shrink: 0;
}
.result-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.result-panel-title h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-primary);
}
.rp-icon { font-size: 16px; }
.rp-version {
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 1px 8px;
  border-radius: 8px;
  letter-spacing: 0.5px;
}
.result-panel-actions {
  display: flex;
  gap: 6px;
}
.rp-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 12.5px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.rp-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(200, 16, 46, 0.04);
}
.rp-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.rp-btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.rp-btn-primary:hover:not(:disabled) {
  background: var(--primary-dark, #9a0d22);
  color: white;
}

.result-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  background: var(--surface-alt);
}
.result-panel-body::-webkit-scrollbar { width: 6px; }
.result-panel-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

/* ── 范文库 ── */
.fanwen-page { max-width: 900px; margin: 0 auto; padding: 32px 20px 80px; }
.fanwen-head h2 { font-size: 22px; margin: 0 0 6px; }
.fanwen-sub { color: var(--text-muted); font-size: 13.5px; line-height: 1.7; margin: 0 0 16px; max-width: 70ch; }
.fanwen-count { color: var(--primary); font-weight: 600; margin-left: 6px; }
.fanwen-search { max-width: 420px; }
.fanwen-cats { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 20px; }
.fanwen-cat-chip {
  font-size: 13px; padding: 5px 14px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; transition: all var(--transition);
}
.fanwen-cat-chip:hover { border-color: var(--primary-light); color: var(--primary); }
.fanwen-cat-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.fanwen-cat-chip .fcc-n { opacity: 0.7; font-size: 11.5px; margin-left: 2px; }
.fanwen-list { display: flex; flex-direction: column; gap: 8px; }
.fanwen-loading { color: var(--text-muted); text-align: center; padding: 40px 0; font-size: 14px; }
.fanwen-card {
  display: flex; align-items: center; gap: 12px; width: 100%;
  text-align: left; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 16px; cursor: pointer; font-family: inherit;
  transition: all var(--transition);
}
.fanwen-card:hover { border-color: var(--primary-light); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.fanwen-card-type {
  flex: none; font-size: 11.5px; font-weight: 600; color: var(--primary);
  background: #fdf3f4; border-radius: 4px; padding: 3px 8px; white-space: nowrap;
}
.fanwen-card-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.fanwen-card-title {
  font-size: 14.5px; color: var(--text-primary, #1f2328); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.fanwen-card-meta { font-size: 12px; color: var(--text-muted); }
.fanwen-card-arrow { flex: none; color: var(--text-muted); font-size: 20px; line-height: 1; }

/* 范文详情弹窗 */
.modal-fanwen {
  max-width: 860px; width: 92vw; max-height: 88vh;
  display: flex; flex-direction: column; padding: 0;
}
.fanwen-detail-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 24px 12px; border-bottom: 1px solid var(--border);
}
.fanwen-detail-type {
  font-size: 12px; font-weight: 600; color: #fff;
  background: var(--primary); border-radius: 4px; padding: 3px 10px;
}
.fanwen-detail-src { font-size: 12.5px; color: var(--primary); }
.fanwen-detail-body {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  background: linear-gradient(180deg, #e5e7eb 0%, #d6d8db 100%);
  container-type: inline-size;
}
.fanwen-detail-body .doc-card { max-width: none; margin: 0 auto; }
.fanwen-detail-body .doc-card-band,
.fanwen-detail-body .doc-card-watermark { display: none; }
.fanwen-detail-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 24px; border-top: 1px solid var(--border);
}
.btn-action-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-action-primary:hover { background: var(--primary-dark, #9a0d22); }
@media (max-width: 720px) {
  .fanwen-card { flex-wrap: wrap; }
  .fanwen-detail-body { padding: 12px; }
}

/* ── 金句素材库 ── */
.quotes-page {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}
.quotes-head h2 { font-size: 22px; margin: 0 0 6px; }
.quotes-sub { color: var(--text-muted); font-size: 13.5px; margin: 0 0 16px; }
.quotes-search { max-width: 420px; }
.quotes-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 20px;
}
.quotes-cat-chip {
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all var(--transition);
}
.quotes-cat-chip:hover { border-color: var(--primary-light); color: var(--primary); }
.quotes-cat-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.quotes-group { margin-bottom: 26px; }
.quotes-group-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
  padding-left: 10px;
  border-left: 3px solid var(--primary);
}
.quote-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.7;
}
.quote-text { flex: 1; min-width: 0; }
.quote-src {
  display: inline-block;
  margin-left: 8px;
  font-size: 11px;
  color: var(--gold, #8f6d24);
  background: #fdf6e3;
  border-radius: 4px;
  padding: 1px 6px;
  white-space: nowrap;
  vertical-align: 1px;
}
.quote-actions { flex: none; display: flex; gap: 6px; opacity: 0; transition: opacity var(--transition); }
.quote-card:hover .quote-actions { opacity: 1; }
.quote-btn {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-strong, #d1d5db);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}
.quote-btn:hover { border-color: var(--primary); color: var(--primary); }
.quotes-empty { color: var(--text-muted); text-align: center; padding: 40px 0; }
@media (max-width: 720px) {
  .quote-actions { opacity: 1; }
  .quote-card { flex-direction: column; align-items: stretch; gap: 8px; }
}

/* ── AI 审校结果面板 ── */
.rp-review-panel {
  border-top: 1px solid var(--border);
  background: var(--surface);
  max-height: 42%;
  display: flex;
  flex-direction: column;
}
.rp-review-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.rp-review-title { font-size: 13px; font-weight: 700; flex: 1; }
.rp-review-applyall {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 99px;
  border: 1px solid var(--primary);
  color: var(--primary);
  background: transparent;
  cursor: pointer;
}
.rp-review-applyall:hover { background: var(--primary); color: #fff; }
.rp-review-close {
  border: none; background: transparent; cursor: pointer;
  font-size: 18px; line-height: 1; color: var(--text-muted); padding: 2px 6px;
}
.rp-review-list { overflow-y: auto; padding: 8px 12px; }
.rp-review-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
}
.rp-review-item:last-child { border-bottom: none; }
.rp-review-item.is-done { opacity: 0.5; }
.rri-type {
  flex: none;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary, #4b5563);
  background: var(--surface-alt, #f3f4f6);
  border-radius: 4px;
  padding: 2px 6px;
  margin-top: 1px;
}
/* 政治性差错：红色置顶高亮（对标新华妙笔"政务性差错"分级） */
.rri-type-political {
  color: #fff;
  background: var(--primary);
}
.rp-review-item.is-political {
  background: #fdf3f4;
  border-radius: 6px;
  border-bottom-style: solid;
}
.rri-body { flex: 1; min-width: 0; }
.rri-diff { line-height: 1.6; word-break: break-all; }
.rri-diff s { color: var(--text-muted); }
.rri-diff b { color: var(--primary); }
.rri-reason { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.rri-apply {
  flex: none;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-strong, #d1d5db);
  background: var(--surface);
  cursor: pointer;
}
.rri-apply:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.rri-apply:disabled { cursor: default; color: var(--text-muted); }

/* 空状态 */
.rp-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
}
.rp-empty-icon { font-size: 48px; opacity: 0.5; margin-bottom: 16px; }
.rp-empty-title { font-size: 15px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.rp-empty-desc { font-size: 13px; line-height: 1.7; }

/* 评论区 */
.result-panel-comment {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 18px 14px;
  flex-shrink: 0;
}
.rp-comment-target {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.rp-comment-target strong { color: var(--primary); font-weight: 600; }
.rp-comment-input {
  width: 100%;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--surface-alt);
  color: var(--text-primary);
  transition: border-color 0.15s;
  box-sizing: border-box;
}
.rp-comment-input:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
}
.rp-comment-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 12px;
}
.rp-comment-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* 编辑模式样式 */
.result-panel-body .doc-card.is-editing {
  outline: 2px dashed var(--primary);
  outline-offset: 4px;
  cursor: text;
  user-select: text;
}
.result-panel-body .doc-card[contenteditable="true"] {
  /* contenteditable 单元素时的样式（备用） */
}

/* 段落选中评论目标提示 */
.rp-selected-anchor {
  background: rgba(212, 160, 23, 0.18);
  border-radius: 2px;
}

/* ═══════════════════════════════════════════════════════════════
 *  Chat 气泡内的公文回执 (chat-doc-receipt)
 *  左侧只显示一行简短"已起草 → 查看"，正文在右侧成果区
 * ═══════════════════════════════════════════════════════════════ */
.chat-doc-receipt {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin-top: 4px;
  background: linear-gradient(135deg, #fdfcf7, #fbf8ee);
  border: 1px solid #e8e4d8;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-primary);
}
.chat-doc-receipt.streaming {
  background: #f7f5ee;
  border-color: #ddd6bf;
}
.cdr-icon { font-size: 15px; line-height: 1; }
.cdr-svg {
  width: 14px; height: 14px;
  flex-shrink: 0;
  color: var(--primary);
}
.chat-doc-receipt.streaming .cdr-svg { color: #b87f0a; }
.cdr-text { color: var(--text-primary); font-weight: 500; }
.cdr-arrow {
  margin-left: 4px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
.cdr-arrow:hover { border-bottom-color: var(--primary); }

/* 流式打字三点 */
.cdr-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: 2px;
}
.cdr-dots span {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: #a8a297;
  animation: cdr-dot-pulse 1.2s infinite ease-in-out;
}
.cdr-dots span:nth-child(2) { animation-delay: 0.15s; }
.cdr-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cdr-dot-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* chat-bubble 含回执时：气泡退让（不要 chat-bubble 的白底边框） */
.chat-msg.assistant .chat-bubble.has-receipt {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  min-width: 0;
}

/* 普通对话回复 wrapper（容器，便于增量更新） */
.chat-plain {
  /* 不设样式，直接交给内部 markdown 元素 */
}

/* 选段评论目标 — 显示 "针对：选段「xxx」 ×" */
.rp-target-preview {
  color: var(--text-primary);
  background: rgba(212, 160, 23, 0.15);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11.5px;
  margin: 0 4px;
}
.rp-target-clear {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  line-height: 1;
  border-radius: 50%;
  transition: all 0.15s;
  vertical-align: middle;
}
.rp-target-clear:hover {
  background: rgba(0,0,0,0.06);
  color: var(--primary);
}

/* 文字选中时的临时高亮（浏览器原生选区，鼠标按下时显示）*/
.result-panel-body .doc-card *::selection {
  background: rgba(212, 160, 23, 0.32);
}

/* CSS Highlight API：选段确定后持久化的高亮（焦点离开也不消失）*/
::highlight(rp-selected) {
  background-color: rgba(212, 160, 23, 0.42);
  color: #000;
  text-shadow: 0 0 0 #000;     /* 防止某些字体在高亮上变模糊 */
}

/* 编辑模式样式 */
.result-panel-body .doc-card.is-editing {
  outline: 2px dashed var(--primary);
  outline-offset: 6px;
  background: #ffffff;
  cursor: text;
}
.result-panel-body .doc-card.is-editing [contenteditable] {
  outline: none;
}
.result-panel-body .doc-card.is-editing:focus { outline-color: var(--primary); }

/* ═══════════════════════════════════════════════════════════════
 *  Chat 输入区改版：选段提示 + 配置行 + 高级弹层
 * ═══════════════════════════════════════════════════════════════ */

/* 选段评论目标条（紧贴 input 上方，仅在选段时出现） */
.comment-target-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: linear-gradient(90deg, rgba(212, 160, 23, 0.10), rgba(212, 160, 23, 0.04));
  border: 1px solid rgba(212, 160, 23, 0.32);
  border-radius: 8px;
  font-size: 12.5px;
  animation: ctb-slide-in 0.2s ease-out;
}
@keyframes ctb-slide-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ctb-label {
  flex-shrink: 0;
  color: #b87f0a;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.ctb-preview {
  flex: 1;
  min-width: 0;
  color: var(--text-primary);
  font-family: "FangSong", "STFangsong", serif;
  background: rgba(255,255,255,0.6);
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ctb-clear {
  background: transparent;
  border: none;
  color: #b87f0a;
  cursor: pointer;
  font-size: 16px;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.ctb-clear:hover {
  background: rgba(212, 160, 23, 0.2);
  color: #8a5d05;
}

/* 配置行 */
.chat-config-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12.5px;
  flex-wrap: wrap;
}
.chat-config-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-secondary);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.chat-config-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.chat-config-btn.is-open {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.chat-config-btn .cab-icon {
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  transition: transform 0.2s;
}
.chat-config-btn.is-open .cab-icon { transform: rotate(45deg); }

.chat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.chat-toggle:hover { border-color: var(--primary); }
.chat-toggle input { display: none; }
.chat-toggle .ct-icon { font-size: 13px; line-height: 1; }
.chat-toggle .ct-text { font-size: 12.5px; }
.chat-toggle:has(input:checked) {
  background: rgba(200, 16, 46, 0.08);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.chat-config-spacer { flex: 1; }
.chat-config-hint {
  color: var(--text-muted);
  font-size: 11.5px;
}
.cch-sep { margin: 0 4px; opacity: 0.5; }

/* 高级弹层 */
.chat-adv-popover {
  margin-top: 8px;
  padding: 12px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.06);
  animation: cap-slide-in 0.2s ease-out;
}
@keyframes cap-slide-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cap-section + .cap-section { margin-top: 10px; }
.cap-section-title {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.cap-options {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.cap-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 3px 12px;
  font-size: 12.5px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s;
}
.cap-pill:hover { border-color: var(--primary); color: var(--primary); }
.cap-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  font-weight: 600;
}

/* 隐藏旧的 style-toolbar，及它的相关样式（不再使用） */
.style-toolbar { display: none !important; }

/* 调整 chat-input-hint 的旧规则（被 chat-config-row 取代，但保留 use-refs-toggle 兼容） */
.chat-input-hint { display: none; }

/* ═══════════════════════════════════════════════════════════════
 *  SVG 图标按钮统一样式（替代 emoji）
 * ═══════════════════════════════════════════════════════════════ */

/* 成果区头部 */
.rp-icon svg {
  width: 16px; height: 16px;
  color: var(--primary);
  display: block;
}
/* 成果区操作按钮 */
.rp-btn {
  display: inline-flex !important;
  align-items: center;
  gap: 5px;
}
.rp-btn-icon {
  width: 13px; height: 13px;
  flex-shrink: 0;
}

/* chat 配置行 SVG */
.chat-config-btn .cab-svg {
  width: 12px; height: 12px;
  transition: transform 0.2s;
}
.chat-config-btn.is-open .cab-svg { transform: rotate(45deg); }
.chat-toggle .ct-svg {
  width: 14px; height: 14px;
  opacity: 0.85;
}
.chat-toggle:has(input:checked) .ct-svg { opacity: 1; }

/* 选段提示条 */
.ctb-svg {
  width: 14px; height: 14px;
  color: #b87f0a;
  flex-shrink: 0;
}
.ctb-clear svg { display: block; }

/* 弹层 cap-section 标题不再带 emoji，弱化样式 */
.cap-section-title {
  font-size: 11.5px;
  letter-spacing: 1px;
  text-transform: none;
  color: var(--text-muted);
}

/* 意图分类等待 spinner */
.btn-spin {
  animation: btn-spin-rot 0.9s linear infinite;
}
@keyframes btn-spin-rot {
  to { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════════════════
 *  充值弹窗：支付通道按钮
 * ═══════════════════════════════════════════════════════════════ */
.pay-channels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.pay-channel-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.18s;
  text-align: left;
  font-family: inherit;
}
.pay-channel-btn:hover {
  border-color: var(--primary);
  background: rgba(200, 16, 46, 0.02);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.pay-channel-wx:hover { border-color: #07c160; background: rgba(7, 193, 96, 0.04); }
.pay-channel-ali:hover { border-color: #1677ff; background: rgba(22, 119, 255, 0.04); }
.pcb-logo {
  flex-shrink: 0;
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-alt);
  border-radius: 8px;
}
.pcb-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.3;
}
.pcb-text strong {
  font-size: 14px;
  color: var(--text-primary);
}
.pcb-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}
@media (max-width: 480px) {
  .pay-channels { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════════
 *  表单 tab：文种选择器按分组展示（法定公文 / 常用文稿）
 * ═══════════════════════════════════════════════════════════════ */
.doc-type-group + .doc-type-group { margin-top: 14px; }
.doc-type-group-title {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 1.2px;
  font-weight: 500;
  margin-bottom: 8px;
  padding-left: 2px;
}
.dtg-count {
  margin-left: 6px;
  background: var(--surface-alt);
  color: var(--text-secondary);
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10.5px;
  font-weight: 500;
}
.doc-type-group-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* URL chip：所有用户可见 URL 都中立化为不可点击的样式 chip
 * 防止浏览器扩展（IDM、UU 远程、Smart URL Detection 等）自动开新 tab */
.url-chip {
  display: inline-block;
  font-size: 0.85em;
  background: rgba(59, 130, 246, 0.10);
  color: #2563eb;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid rgba(59, 130, 246, 0.18);
  margin: 0 2px;
  cursor: default;
  user-select: text;
  font-family: var(--font-sans);
  vertical-align: baseline;
  /* 关键：不是 a 标签，没有 href，浏览器扩展不会识别 */
}
.url-chip:hover {
  background: rgba(59, 130, 246, 0.16);
}

/* Chat 输入区下方的下拉选择器（公文类型 / 字数）
   样式与 .chat-toggle 协调，但用 <select> 让用户能下拉选择 */
.chat-select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-alt, #f7f7f5);
  border: 1px solid var(--border, #e6e6df);
  border-radius: 14px;
  padding: 3px 4px 3px 10px;
  font-size: 12.5px;
  color: var(--text-secondary, #555);
  cursor: pointer;
  transition: all 0.15s;
}
.chat-select:hover {
  border-color: var(--primary, #c8102e);
  color: var(--text-primary, #222);
}
.chat-select .ct-svg {
  width: 14px; height: 14px;
  opacity: 0.7;
  flex-shrink: 0;
}
.chat-select select {
  border: none;
  background: transparent;
  font-size: 12.5px;
  color: inherit;
  cursor: pointer;
  padding: 2px 18px 2px 0;
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
}
.chat-select select:focus { outline: none; }
.chat-select select option { color: #222; background: #fff; }
.chat-select:has(select:not([value=""]):checked) {
  background: rgba(200, 16, 46, 0.04);
  border-color: var(--primary, #c8102e);
}

/* ═══════════════════════════════════════════════════════════════
 *  对话配置 v3 —— 单胶囊 + 分组浮层（替代 chat-config-row v1/v2）
 * ═══════════════════════════════════════════════════════════════ */

.chat-config-row-v2 {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px 0;
  min-height: 30px;
}

/* —— 单胶囊（汇总当前配置） —— */
.chat-cfg-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 999px;
  padding: 5px 12px 5px 9px;
  font-size: 12.5px;
  line-height: 1.2;
  color: var(--text-primary, #1f2937);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  font-family: inherit;
  max-width: 70%;
}
.chat-cfg-chip:hover {
  border-color: var(--primary, #c8102e);
  background: rgba(200, 16, 46, 0.03);
}
.chat-cfg-chip[aria-expanded="true"] {
  border-color: var(--primary, #c8102e);
  background: rgba(200, 16, 46, 0.06);
  box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.08);
}
.cfg-chip-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  color: var(--text-muted, #6b7280);
}
.chat-cfg-chip[aria-expanded="true"] .cfg-chip-icon { color: var(--primary, #c8102e); }
.cfg-chip-summary {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.1px;
}
.cfg-chip-summary .cfg-sum-sep {
  color: var(--text-muted, #9ca3af);
  margin: 0 4px;
}
.cfg-chip-summary .cfg-sum-on {
  color: var(--primary, #c8102e);
  font-weight: 600;
}
.cfg-chip-caret {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  color: var(--text-muted, #9ca3af);
  transition: transform 0.2s;
}
.chat-cfg-chip[aria-expanded="true"] .cfg-chip-caret { transform: rotate(180deg); }

/* —— 首次引导高亮（chat 第一次进入时让胶囊"呼吸"提示用户点开） —— */
.chat-cfg-chip.is-onboarding {
  animation: cfg-chip-pulse 1.6s ease-in-out 2;
  border-color: var(--primary, #c8102e);
}
@keyframes cfg-chip-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(200, 16, 46, 0.0); }
  50%      { box-shadow: 0 0 0 6px rgba(200, 16, 46, 0.18); }
}

/* —— 浮层：从胶囊下方弹出 —— */
.chat-cfg-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 4px;
  width: 380px;
  max-width: calc(100vw - 32px);
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.04);
  z-index: 50;
  padding: 16px 18px 12px;
  animation: cfg-pop-in 0.16s ease-out;
}
@keyframes cfg-pop-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cfg-pop-arrow {
  position: absolute;
  bottom: -7px;
  left: 22px;
  width: 14px;
  height: 14px;
  background: var(--surface, #fff);
  border-right: 1px solid var(--border, #e5e7eb);
  border-bottom: 1px solid var(--border, #e5e7eb);
  transform: rotate(45deg);
}

/* —— 分组 —— */
.cfg-sec {
  padding: 10px 0 12px;
  border-top: 1px solid var(--border, #f0f0f0);
}
.cfg-sec:first-child { border-top: none; padding-top: 4px; }
.cfg-sec-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted, #6b7280);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.cfg-sec-icon {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  color: var(--text-muted, #9ca3af);
}

/* —— 行：label + 控件 —— */
.cfg-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
  min-height: 28px;
}
.cfg-label {
  font-size: 13px;
  color: var(--text-primary, #1f2937);
  flex: 0 0 64px;
  font-weight: 500;
}
.cfg-select {
  flex: 1;
  border: 1px solid var(--border, #e5e7eb);
  background: var(--surface, #fff);
  border-radius: 8px;
  padding: 5px 26px 5px 10px;
  font-size: 13px;
  color: var(--text-primary, #1f2937);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  font-family: inherit;
}
.cfg-select:focus {
  outline: none;
  border-color: var(--primary, #c8102e);
}
.cfg-select:not([data-default="true"]) {
  border-color: rgba(200, 16, 46, 0.4);
}

/* —— 行：胶囊组（pill 风格） —— */
.cfg-row-pill {
  align-items: flex-start;
  padding-top: 6px;
}
.cfg-row-pill .cfg-label { padding-top: 5px; }
.cfg-pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
}
.cfg-pill {
  background: var(--surface-alt, #f7f8fa);
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 5px 12px;
  font-size: 12.5px;
  color: var(--text-primary, #1f2937);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.cfg-pill:hover { background: rgba(200, 16, 46, 0.06); }
.cfg-pill.active,
.cfg-pill.is-active {
  background: var(--primary, #c8102e);
  color: white;
  border-color: var(--primary, #c8102e);
  font-weight: 600;
}

/* —— 切换开关（联网/范本） —— */
.cfg-toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 0;
  cursor: pointer;
}
.cfg-toggle input[type="checkbox"] {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  accent-color: var(--primary, #c8102e);
  cursor: pointer;
}
.cfg-toggle-text { display: flex; flex-direction: column; gap: 1px; }
.cfg-toggle-label {
  font-size: 13px;
  color: var(--text-primary, #1f2937);
  font-weight: 500;
}
.cfg-toggle-hint {
  font-size: 11.5px;
  color: var(--text-muted, #6b7280);
}

/* —— 浮层底部：操作按钮 —— */
.cfg-pop-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0 2px;
  border-top: 1px solid var(--border, #f0f0f0);
  margin-top: 6px;
}
.cfg-pop-reset, .cfg-pop-done {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 5px 14px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: inherit;
}
.cfg-pop-reset {
  background: transparent;
  color: var(--text-muted, #6b7280);
}
.cfg-pop-reset:hover { color: var(--primary, #c8102e); }
.cfg-pop-done {
  background: var(--primary, #c8102e);
  color: white;
  font-weight: 600;
}
.cfg-pop-done:hover { background: var(--primary-dark, #9a0d22); }

/* —— 窄屏 —— */
@media (max-width: 720px) {
  .chat-cfg-chip { max-width: 100%; }
  .chat-cfg-popover {
    width: calc(100vw - 24px);
    left: 12px;
    right: 12px;
  }
}

/* ═══════════════════════════════════════════════════════════════
 *  右侧成果区：Word A4 纸张感预览
 *  GB/T 9704-2012 页边距：上 3.7 / 下 3.5 / 左 2.8 / 右 2.6 cm
 *  纸张：A4 21 × 29.7 cm，白底，灰色背景上漂浮，带阴影
 * ═══════════════════════════════════════════════════════════════ */

/* 成果区 body 改为"桌面感"灰色底，A4 纸张漂浮其上 */
.result-panel-body {
  background: linear-gradient(180deg, #e5e7eb 0%, #d6d8db 100%);
  padding: 28px 16px;
}

/* doc-card 在 result-panel-body 内时，退化为标准 A4 纸张 */
.result-panel-body .doc-card {
  /* 纸张尺寸：A4 */
  width: 21cm;
  min-height: 29.7cm;
  max-width: 100%;
  /* GB/T 9704-2012 标准页边距：上 3.7 / 右 2.6 / 下 3.5 / 左 2.8 */
  padding: 3.7cm 2.6cm 3.5cm 2.8cm;
  /* 取消原有米色与圆角，换成纯白方形（Word 默认） */
  background: #ffffff;
  border: none;
  border-radius: 2px;
  /* 漂浮纸张感 */
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.12),
    0 12px 32px rgba(0, 0, 0, 0.10),
    0 0 0 1px rgba(0, 0, 0, 0.03);
  margin: 0 auto 24px;
  box-sizing: border-box;
  overflow: visible;
}

/* 隐藏旧装饰：红头横条 + 右下水印（A4 视图下不应出现） */
.result-panel-body .doc-card .doc-card-band,
.result-panel-body .doc-card .doc-card-watermark {
  display: none;
}

/* —— 响应式：当容器窄于 21cm（≈ 794px @ 96dpi）时整体等比缩放 —— */
@media (max-width: 900px) {
  .result-panel-body { padding: 20px 8px; }
  .result-panel-body .doc-card {
    /* 等比缩放：保留视觉比例，让窄屏下也能"看见整张纸"
       21cm × 0.74 ≈ 15.5cm；padding 同步缩小 */
    width: calc(21cm * 0.78);
    min-height: calc(29.7cm * 0.78);
    padding: calc(3.7cm * 0.78) calc(2.6cm * 0.78) calc(3.5cm * 0.78) calc(2.8cm * 0.78);
  }
}
@media (max-width: 640px) {
  .result-panel-body .doc-card {
    width: calc(21cm * 0.58);
    min-height: calc(29.7cm * 0.58);
    padding: calc(3.7cm * 0.58) calc(2.6cm * 0.58) calc(3.5cm * 0.58) calc(2.8cm * 0.58);
  }
}

/* 支持容器查询的浏览器（Chrome 105+ / Safari 16+）：纸张严格按"面板宽度"
   等比缩放成一张 A4，取代上面按"视口宽度"猜面板宽的两档 media query。
   之前的问题：桌面端右栏只有 500~700px 时视口仍 >900px，走的是固定
   21cm 纸 + 固定 3.7/2.8cm 边距 + max-width:100% 压扁 —— 边距不缩、
   字号不缩，一行只排得下十几个字，看起来"格式全乱"。
   这里的比例全部来自 A4 实纸：21cm 宽为 100cqw。 */
@supports (container-type: inline-size) {
  .result-panel-body .doc-card {
    width: 100%;
    min-height: 141.4cqw;                             /* 29.7cm / 21cm */
    padding: 17.62cqw 12.38cqw 16.67cqw 13.33cqw;     /* 3.7 / 2.6 / 3.5 / 2.8 cm ÷ 21cm */
  }
}

/* —— 编辑态：保持 A4 外形，去掉外层蓝边框样式覆盖 —— */
.result-panel-body .doc-card.is-editing {
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.12),
    0 12px 32px rgba(0, 0, 0, 0.10),
    0 0 0 2px var(--primary, #c8102e);
}

/* 期望字数：手动数字输入（复用 .cfg-select 的边框/红边，去掉下拉箭头与原生步进器）*/
.cfg-num {
  background-image: none !important;
  padding: 5px 10px;
  cursor: text;
  -moz-appearance: textfield;
}
.cfg-num::-webkit-outer-spin-button,
.cfg-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cfg-unit { font-size: 12px; color: var(--text-muted, #9ca3af); flex: none; }

/* ============================================================
 *  手机端适配（≤720px）—— 抽屉式侧栏/成果区 + 紧凑顶栏
 *  追加在文件末尾，覆盖上方 880px 等旧断点
 * ============================================================ */
.mobile-ws-bar { display: none; }
.drawer-backdrop { display: none; }
.rp-mobile-close { display: none; }

@media (max-width: 720px) {
  /* —— 顶栏紧凑 —— */
  .header-inner { padding: 0 12px; height: 52px; gap: 10px; }
  .logo-sub { display: none; }
  .logo-icon { font-size: 20px; }
  .logo-title { font-size: 15px; }
  .nav-links { gap: 0; }
  .nav-link { padding: 6px 8px; font-size: 12px; }
  .credit-unit { display: none; }
  .credit-badge { padding: 4px 8px; }

  .main, .main:has(#tab-chat.active) { padding: 8px; }

  /* —— workspace 单列 —— */
  .chat-workspace { display: block; height: auto; }
  .chat-main {
    width: 100%;
    height: calc(100vh - 60px);
    height: calc(100dvh - 60px);
  }
  .chat-messages { padding: 14px 14px 8px; }

  /* —— 手机工具条：唤出抽屉 —— */
  .mobile-ws-bar { display: flex; gap: 8px; padding: 0 14px 8px; }
  .mws-btn {
    flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 10px; font-size: 13px; font-weight: 600;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text-secondary); cursor: pointer;
  }
  .mws-btn svg { width: 16px; height: 16px; flex: none; }
  .mws-btn:active { background: var(--surface-alt); color: var(--primary); }

  /* —— 历史侧栏 → 左抽屉 —— */
  .chat-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 82%; max-width: 320px; z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s ease;
    border-radius: 0;
  }
  .chat-sidebar.drawer-open { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.25); }

  /* —— 成果区(A4) → 右抽屉，近满屏便于阅读 —— */
  .result-panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 100%; max-width: 480px; z-index: 200;
    grid-column: auto; min-height: 0;
    transform: translateX(100%);
    transition: transform .25s ease;
    border-radius: 0;
  }
  .result-panel.drawer-open { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.25); }
  .result-panel-head { flex-wrap: wrap; }
  .result-panel-actions { flex-wrap: wrap; }
  .rp-mobile-close {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; flex: none; margin-left: auto;
    border: none; background: transparent; color: var(--text-secondary);
    border-radius: 8px; cursor: pointer;
  }
  .rp-mobile-close svg { width: 20px; height: 20px; }
  .rp-mobile-close:active { background: var(--surface-alt); }

  /* —— 抽屉遮罩 —— */
  .drawer-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    z-index: 150; display: none;
  }
  .drawer-backdrop.show { display: block; }

  /* —— 弹窗自适应 —— */
  .modal-overlay { padding: 12px; }
  .modal { max-width: 100%; }
  .modal-recharge { max-width: 100%; }
  .modal-body { padding: 22px 18px 20px; }
}

/* 更窄屏（≤420px）：logo 仅图标，导航更紧 */
@media (max-width: 420px) {
  .logo-title { display: none; }
  .nav-link { padding: 6px 6px; font-size: 11.5px; }
  .header-inner { gap: 6px; }
}
