/* 成交助手 · 全局样式
   橙红色主题(8 步成交的"成交"感) + 简洁 */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --t: #DC2626;        /* 主色:橙红(成交) */
  --ts: #F87171;       /* 主色浅 */
  --te: #B91C1C;       /* 主色深 */
  --bg: #F9FAFB;
  --card: #FFFFFF;
  --border: #E5E7EB;
  --text: #1F2937;
  --text-2: #6B7280;
  --text-3: #9CA3AF;
  --ok: #10B981;
  --warn: #F59E0B;
  --err: #EF4444;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  padding-bottom: 60px;
  font-size: 14px;
}

/* ===== 顶栏 ===== */
.topbar { position: sticky; top: 0; z-index: 10; background: rgba(255,255,255,0.95); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 920px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; }
.brand { font-weight: 700; font-size: 16px; text-decoration: none; color: var(--text); }
.user { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.user-name { color: var(--text-2); }
.logout-btn { padding: 4px 10px; background: #fff; color: var(--err); border: 1px solid #FCA5A5; border-radius: 16px; text-decoration: none; font-size: 12px; }
.nav-link { padding: 4px 12px; color: var(--text-2); text-decoration: none; font-size: 14px; border-radius: 6px; }
.nav-link:hover { background: #F3F4F6; color: var(--t); }
.subnav { max-width: 920px; margin: 0 auto; display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 20px 0; }
.subnav a { padding: 6px 12px; background: #fff; border: 1px solid var(--border); border-radius: 16px; text-decoration: none; color: var(--text-2); font-size: 13px; }
.subnav a.active, .subnav a:hover { background: var(--t); color: #fff; border-color: var(--t); }
.subnav a.disabled { opacity: 0.5; cursor: not-allowed; }
.subnav a.disabled:hover { background: #fff; color: var(--text-2); border-color: var(--border); }

/* ===== 主体 ===== */
main { max-width: 920px; margin: 0 auto; padding: 20px; }
h1 { font-size: 22px; margin-bottom: 12px; color: #111827; }
h2 { font-size: 18px; margin: 0 0 8px; color: #111827; }
.muted { color: var(--text-3); font-size: 13px; margin-bottom: 12px; }

.card { background: var(--card); border-radius: 12px; padding: 20px 24px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); margin-bottom: 16px; border: 1px solid var(--border); }

/* ===== 登录/注册页 ===== */
.auth-page { min-height: calc(100vh - 60px); display: flex; align-items: center; justify-content: center; padding: 40px 20px; background: linear-gradient(135deg, #FECACA 0%, #FCA5A5 100%); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 20px; padding: 40px 36px; box-shadow: 0 20px 60px rgba(220,38,38,0.2), 0 0 0 1px rgba(255,255,255,0.5); }
.auth-logo { width: 64px; height: 64px; margin: 0 auto 16px; background: linear-gradient(135deg, #DC2626, #B91C1C); border-radius: 18px; display: flex; align-items: center; justify-content: center; font-size: 32px; color: #fff; box-shadow: 0 8px 20px rgba(220,38,38,0.35); }
.auth-card h1 { text-align: center; font-size: 24px; font-weight: 700; color: #111827; }
.auth-card .muted { text-align: center; color: var(--text-3); font-size: 13px; margin: 6px 0 28px; }
.auth-form { display: flex; flex-direction: column; gap: 18px; }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.form-row input, .form-row select, .form-row textarea { width: 100%; padding: 12px 14px; font-size: 14px; color: var(--text); background: #F9FAFB; border: 1.5px solid var(--border); border-radius: 10px; outline: none; transition: all 0.15s; font-family: inherit; }
.form-row input:hover, .form-row select:hover, .form-row textarea:hover { border-color: #D1D5DB; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { background: #fff; border-color: var(--t); box-shadow: 0 0 0 3px rgba(220,38,38,0.12); }
.form-row textarea { resize: vertical; }
.btn-primary { display: block; width: 100%; padding: 13px; margin-top: 8px; font-size: 15px; font-weight: 600; letter-spacing: 2px; color: #fff; background: linear-gradient(135deg, #DC2626 0%, #B91C1C 100%); border: 0; border-radius: 10px; cursor: pointer; transition: transform 0.1s, box-shadow 0.15s; font-family: inherit; box-shadow: 0 4px 12px rgba(220,38,38,0.35); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(220,38,38,0.45); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.auth-foot { text-align: center; color: var(--text-3); font-size: 13px; margin-top: 12px; }
.auth-foot a { color: var(--t); text-decoration: none; font-weight: 600; }
.auth-foot a:hover { text-decoration: underline; }

/* ===== Flash 提示条 ===== */
.flash { padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash-err { background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; }
.flash-ok  { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }

/* ===== 诊断页: AI 模型选择 ===== */
.ai-model-row { display: flex; gap: 8px; }
.ai-model-row select { flex: 1; }
.char-count { text-align: right; font-size: 12px; color: var(--text-3); margin-top: 4px; }
.char-count.warn { color: var(--warn); }
.char-count.err { color: var(--err); }

/* ===== 诊断结果 ===== */
.result-meta { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; padding: 14px; background: #F9FAFB; border-radius: 10px; }
.meta-item { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--text-3); }
.meta-item b { color: var(--text); font-size: 11px; }
.total-score { font-size: 22px; font-weight: 700; color: var(--t); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-warn { background: #FEF3C7; color: #92400E; }

.steps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.step-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.step-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.step-badge { color: #fff; padding: 2px 8px; border-radius: 8px; font-size: 11px; font-weight: 600; }
.step-card-head b { flex: 1; font-size: 14px; }
.step-score { font-size: 16px; font-weight: 700; color: var(--text); }
.score-bar { height: 6px; background: #F3F4F6; border-radius: 3px; overflow: hidden; margin-bottom: 10px; }
.score-bar-fill { height: 100%; transition: width 0.3s; }
.step-row { font-size: 13px; line-height: 1.5; margin-top: 6px; color: var(--text-2); }
.step-row b { color: var(--text); }
.step-quote { background: #FEF3C7; padding: 6px 10px; border-radius: 6px; border-left: 3px solid #F59E0B; font-style: italic; }
.step-suggestion { color: #047857; }
.step-suggestion b { color: #047857; }

.summary-box { background: #EFF6FF; border-left: 4px solid #3B82F6; padding: 14px 18px; border-radius: 8px; margin-top: 16px; line-height: 1.7; }
.action-box { background: #F0FDF4; border-left: 4px solid var(--ok); padding: 14px 18px; border-radius: 8px; margin-top: 12px; font-weight: 500; }

/* ===== 历史表格 ===== */
.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.history-table th, .history-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.history-table th { color: var(--text-3); font-weight: 600; font-size: 12px; }
.history-table tr:hover { background: #F9FAFB; }
.history-table a { color: var(--t); text-decoration: none; }
.history-table a:hover { text-decoration: underline; }
.history-table tr.parse-error { opacity: 0.6; }

@media (max-width: 640px) {
  .topbar-inner, main, .subnav { padding-left: 16px; padding-right: 16px; }
  .ai-model-row { flex-direction: column; }
  .steps-grid { grid-template-columns: 1fr; }
  .result-meta { font-size: 12px; gap: 8px; }
  .total-score { font-size: 18px; }
}

/* ============================================
   M2 客户模拟器
   ============================================ */

/* persona 选卡 */
.quota-bar { background: #FFF7ED; border: 1px solid #FED7AA; padding: 8px 14px; border-radius: 8px; margin: 12px 0; font-size: 13px; color: #9A3412; }
.model-pick { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.model-pick select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }

.persona-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 16px; }
.persona-card { background: #fff; border: 2px solid var(--border); border-radius: 10px; padding: 16px; cursor: pointer; transition: all 0.15s; }
.persona-card:hover { border-color: var(--t); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(220, 38, 38, 0.1); }
.persona-icon { font-size: 32px; margin-bottom: 6px; }
.persona-name { font-weight: 600; color: var(--text); margin-bottom: 4px; font-size: 14px; }
.persona-surface { color: var(--text-3); font-size: 12px; line-height: 1.5; margin-bottom: 8px; min-height: 36px; }
.persona-meta { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--text-3); padding-top: 8px; border-top: 1px solid var(--border); }

/* 对话主壳 */
.chat-shell { background: #fff; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.04); overflow: hidden; display: flex; flex-direction: column; min-height: calc(100vh - 180px); }

/* 头部 */
.chat-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); background: #FAFAFA; flex-wrap: wrap; gap: 12px; }
.chat-persona { display: flex; align-items: center; gap: 12px; }
.chat-persona .persona-icon { font-size: 28px; margin: 0; }
.chat-persona .persona-name { font-size: 15px; }
.chat-actions { display: flex; gap: 6px; }
.btn-ghost { background: #fff; border: 1px solid var(--border); padding: 6px 12px; border-radius: 6px; font-size: 13px; cursor: pointer; color: var(--text); transition: all 0.15s; }
.btn-ghost:hover { background: #F3F4F6; }
.btn-ghost.danger { color: #DC2626; border-color: #FCA5A5; }
.btn-ghost.danger:hover { background: #FEF2F2; }

/* 进度条 */
.progress-shell { padding: 16px 20px 8px; background: #fff; border-bottom: 1px solid var(--border); }
.progress-shell { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.step-pill { --c: #E5E7EB; background: var(--c); color: #fff; padding: 4px 10px; border-radius: 14px; font-size: 12px; display: flex; align-items: center; gap: 5px; opacity: 0.4; transition: all 0.2s; }
.step-pill.active { opacity: 1; transform: scale(1.05); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15); }
.step-pill.done { opacity: 0.7; }
.step-pill .step-num { background: rgba(255,255,255,0.35); border-radius: 50%; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 11px; }
.step-pill .step-name { font-weight: 500; }
.step-meta { width: 100%; margin-top: 8px; font-size: 13px; color: var(--text); padding: 6px 0 0; }
.step-meta b { color: var(--t); }

/* 消息流 */
.chat-stream { flex: 1; overflow-y: auto; padding: 20px; background: #F9FAFB; display: flex; flex-direction: column; gap: 14px; max-height: 60vh; }
.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg-user { flex-direction: row-reverse; }
.msg-avatar { width: 36px; height: 36px; border-radius: 50%; background: #fff; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.msg-bubble { max-width: 75%; padding: 10px 14px; border-radius: 12px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.msg-user .msg-bubble { background: var(--t); color: #fff; }
.msg-user .msg-role { color: rgba(255,255,255,0.7); }
.msg-system .msg-bubble { background: #FEF3C7; border-left: 4px solid #F59E0B; max-width: 90%; }
.msg-role { font-size: 11px; color: var(--text-3); margin-bottom: 4px; font-weight: 600; }
.msg-text { line-height: 1.6; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.replay-body h4 { margin: 8px 0 4px; font-size: 14px; color: #92400E; }
.replay-body h4:first-child { margin-top: 0; }
.replay-body ul { margin: 4px 0; padding-left: 20px; }
.replay-body li { margin: 3px 0; line-height: 1.6; }
.replay-body p { margin: 4px 0; line-height: 1.7; }
.replay-body code { background: rgba(146, 64, 14, 0.1); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.replay-body b { color: #B45309; }

/* 输入区 */
.chat-input-bar { padding: 14px 20px; background: #fff; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
#user-input { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; font-size: 14px; font-family: inherit; resize: vertical; min-height: 44px; max-height: 120px; }
#user-input:focus { outline: none; border-color: var(--t); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1); }
.input-bar-actions { display: flex; justify-content: space-between; align-items: center; }
.char-count { color: var(--text-3); font-size: 12px; }
.char-count.warn { color: #F59E0B; }
.chat-status { padding: 0 20px 10px; font-size: 12px; color: var(--text-3); min-height: 18px; }

/* typing 动画 */
.dot { display: inline-block; width: 6px; height: 6px; background: var(--text-3); border-radius: 50%; margin: 0 2px; animation: bounce 1.2s infinite; }
.dot:nth-child(2) { animation-delay: 0.15s; }
.dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

@media (max-width: 768px) {
  .persona-grid { grid-template-columns: 1fr; }
  .chat-header { flex-direction: column; align-items: stretch; }
  .chat-actions { width: 100%; justify-content: space-between; }
  .msg-bubble { max-width: 88%; }
  .chat-stream { max-height: 50vh; }
}

/* ============================== */
/* M3 · 知识库(stages/objections/formulas) */
/* ============================== */
.stages-grid { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.stage-card { background: #fff; border-radius: 8px; padding: 16px 18px; cursor: pointer; transition: box-shadow .15s; }
.stage-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.stage-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.stage-badge { color: #fff; font-size: 12px; padding: 3px 10px; border-radius: 12px; font-weight: 600; }
.stage-name { font-size: 18px; }
.stage-one { color: #333; line-height: 1.6; font-size: 14px; }
.stage-next { font-size: 13px; margin-top: 6px; }
.stage-detail { margin-top: 14px; padding-top: 14px; border-top: 1px dashed #e5e7eb; }
.stage-detail-inner { display: flex; flex-direction: column; gap: 16px; }
.kb-section h4 { margin: 0 0 8px 0; color: #ff6b35; font-size: 15px; }
.kb-list { padding-left: 22px; line-height: 1.8; color: #333; }
.kb-list li { margin-bottom: 4px; }
.formula-mini, .mistake-mini { background: #f8f9fa; border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; }
.formula-name, .mistake-title { font-weight: 600; margin-bottom: 4px; color: #1f2937; }
.formula-structure code, .formula-card-structure code { background: #fef3c7; padding: 2px 6px; border-radius: 4px; font-size: 13px; color: #92400e; }
.formula-example, .mistake-content { font-size: 13px; line-height: 1.6; }
.quote-list { list-style: none; padding-left: 0; }
.quote-item { padding: 8px 12px; background: #f0f9ff; border-left: 3px solid #3b82f6; margin-bottom: 6px; border-radius: 4px; color: #1e3a8a; font-size: 14px; }

/* 异议库 */
#obj-q { width: 100%; padding: 12px 14px; font-size: 15px; border: 2px solid #e5e7eb; border-radius: 8px; outline: none; }
#obj-q:focus { border-color: #ff6b35; }
.obj-categories { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.cat-chip { padding: 6px 14px; background: #f3f4f6; border-radius: 16px; cursor: pointer; font-size: 13px; user-select: none; transition: all .15s; }
.cat-chip:hover { background: #e5e7eb; }
.cat-chip.active { background: #ff6b35; color: #fff; }
.obj-list { display: flex; flex-direction: column; gap: 10px; }
.obj-item { background: #fff; border-radius: 8px; padding: 12px 16px; border: 1px solid #e5e7eb; }
.obj-pattern { font-size: 16px; color: #dc2626; font-weight: 500; margin-bottom: 6px; }
.obj-meta { font-size: 12px; margin-bottom: 8px; }
.cat-tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.cat-价格 { background: #fef3c7; color: #92400e; }
.cat-效果 { background: #dbeafe; color: #1e40af; }
.cat-时间 { background: #fce7f3; color: #9f1239; }
.cat-家人 { background: #e0e7ff; color: #3730a3; }
.cat-竞品 { background: #d1fae5; color: #065f46; }
.cat-其他 { background: #f3f4f6; color: #4b5563; }
.obj-response { color: #1f2937; line-height: 1.6; font-size: 14px; padding-top: 8px; border-top: 1px dashed #e5e7eb; }

/* 话术库 */
.formula-group { margin-bottom: 24px; }
.formula-group-head { padding-left: 12px; border-left: 4px solid #ff6b35; margin-bottom: 12px; font-size: 16px; }
.formula-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 14px 18px; margin-bottom: 10px; }
.formula-card-name { font-size: 15px; font-weight: 600; color: #1f2937; margin-bottom: 8px; }
.formula-card-structure { margin-bottom: 8px; }
.formula-card-example { background: #f8f9fa; padding: 10px 12px; border-radius: 6px; font-size: 13px; color: #4b5563; line-height: 1.6; white-space: pre-wrap; }

#formula-step { padding: 8px 12px; border: 1px solid #e5e7eb; border-radius: 6px; font-size: 14px; }

/* ============================== */
/* M4 · 设置页 + admin */
/* ============================== */
.user-provider { border: 1px solid #e5e7eb; border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; background: #f9fafb; }
.user-provider.inactive { opacity: 0.55; }
.up-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.up-head b { font-size: 15px; color: #1f2937; }
.up-meta { font-size: 13px; line-height: 1.8; margin-bottom: 10px; }
.up-meta code { background: #fff; padding: 1px 6px; border-radius: 4px; font-size: 12px; color: #1f2937; }
.up-actions { display: flex; gap: 8px; }
.up-actions button { padding: 4px 10px; font-size: 13px; }
.danger { color: #dc2626; }

#admin-providers, #ic-list { margin-top: 12px; }
.admin-form-row { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.admin-form-row .form-row { flex: 1; min-width: 160px; }
