/* ===== Design Tokens ===== */
:root {
  --bg: #ffffff;
  --bg-soft: #f9f9f9;
  --bg-hover: #ececec;
  --bg-bubble-user: #f4f4f4;
  --border: #e5e5e5;
  --border-soft: #f0f0f0;
  --text: #0d0d0d;
  --text-soft: #6b7280;
  --text-mute: #9ca3af;
  --accent: #10a37f;
  --danger: #dc2626;
  --success: #16a34a;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== Reset ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button { cursor: pointer; font: inherit; touch-action: manipulation; }
input, textarea { font: inherit; -webkit-appearance: none; appearance: none; }
.hidden { display: none !important; }
.view {
  height: 100vh;
  height: 100dvh;
}

/* ===== 登录页 ===== */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
  padding-top: calc(var(--safe-top) + 24px);
  padding-bottom: calc(var(--safe-bottom) + 24px);
}
.login-box {
  width: 100%;
  max-width: 360px;
}
.login-box h1 {
  font-size: 24px;
  text-align: center;
  font-weight: 600;
  color: var(--text);
}
.login-box .subtitle {
  text-align: center;
  color: var(--text-mute);
  font-size: 14px;
  margin: 6px 0 32px;
}

/* ===== 表单 ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 6px;
}
.form-group input,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  min-height: 44px;
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--text);
}

/* ===== 按钮 ===== */
.btn-primary {
  width: 100%;
  padding: 12px 16px;
  background: var(--text);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 15px;
  min-height: 44px;
  transition: background .15s ease;
}
.btn-primary:hover { background: #1f1f1f; }
.btn-primary:active { background: #404040; }

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  min-height: 18px;
}
.hint-msg {
  color: var(--success);
  font-size: 13px;
  margin-top: 8px;
  text-align: center;
}

/* ===== 主界面布局 ===== */
#main-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ===== 顶部栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  padding: calc(var(--safe-top) + 6px) 4px 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 11;
  flex-shrink: 0;
}
.topbar h2 {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text);
  min-width: 44px;
  min-height: 44px;
  padding: 10px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-btn:active { background: var(--bg-hover); }

.text-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  padding: 8px 10px;
  min-height: 36px;
  border-radius: var(--radius-sm);
}
.text-btn:hover { color: var(--accent); }

.reset-btn {
  color: var(--danger);
  display: block;
  margin-top: 8px;
}
.reset-btn:hover { color: #991b1b; }

/* ===== 侧边栏（抽屉式） ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: -85%;
  width: 85%;
  max-width: 320px;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-soft);
  border-right: 1px solid var(--border-soft);
  padding: calc(var(--safe-top) + 16px) 0 calc(var(--safe-bottom) + 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition: left .25s ease, box-shadow .25s ease;
  z-index: 20;
}
.sidebar.open {
  left: 0;
  box-shadow: 2px 0 24px rgba(0, 0, 0, .15);
}
.sidebar-section {
  padding: 12px 16px;
}
.sidebar-section + .sidebar-section {
  border-top: 1px solid var(--border-soft);
}
.sidebar-section h3 {
  font-size: 11px;
  color: var(--text-mute);
  margin-bottom: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.agent-list, .conv-list { list-style: none; }
.agent-list li, .conv-list li {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 2px;
  min-height: 40px;
  display: flex;
  align-items: center;
  color: var(--text);
  line-height: 1.4;
}
.agent-list li:hover, .conv-list li:hover { background: var(--bg-hover); }
.agent-list li.active, .conv-list li.active {
  background: #e3e3e3;
  color: var(--text);
  font-weight: 600;
}

/* ===== 对话区 ===== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 用户消息：浅灰圆角气泡，右对齐 */
.msg {
  max-width: 85%;
  line-height: 1.6;
  font-size: 15px;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.user {
  align-self: flex-end;
  background: var(--bg-bubble-user);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-md);
}
/* AI 消息：无气泡纯文本，左对齐铺满 */
.msg.assistant {
  align-self: stretch;
  background: transparent;
  color: var(--text);
  padding: 0;
  max-width: 100%;
}
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-mute);
  font-size: 12px;
  padding: 4px 12px;
  max-width: 90%;
  text-align: center;
}

/* ===== 输入区 ===== */
.chat-input {
  display: flex;
  gap: 8px;
  padding: 12px 12px calc(var(--safe-bottom) + 12px);
  background: var(--bg);
  border-top: 1px solid var(--border-soft);
  align-items: center;
  flex-shrink: 0;
}
.chat-input input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 22px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  min-height: 44px;
}
.chat-input input:focus { border-color: var(--text); }
.chat-input .btn-primary {
  width: auto;
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 14px;
  min-width: 64px;
  min-height: 44px;
  font-weight: 600;
}
.chat-input .icon-btn {
  font-size: 20px;
  padding: 10px;
  min-width: 44px;
  min-height: 44px;
}
.chat-input .icon-btn.recording {
  color: var(--danger);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== 弹层（手机端从底部出来） ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
  padding: 0;
}
.modal-content {
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--safe-bottom) + 16px);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.modal-body { padding: 20px; }
.extra-data-wrap { margin-bottom: 16px; }
.extra-data-wrap summary {
  font-size: 13px;
  color: var(--text-mute);
  cursor: pointer;
  padding: 6px 0;
}
.extra-data-wrap textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

/* ===== AI 回复内的三层卡片（业务必需） ===== */
.msg.assistant .card-hook,
.msg.assistant .card-reason,
.msg.assistant .card-warning {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin: 10px 0;
  line-height: 1.6;
  border-left: 3px solid;
}
.msg.assistant .card-hook {
  background: #f0f7ff;
  border-left-color: #3b82f6;
}
.msg.assistant .card-reason {
  background: var(--bg-soft);
  border-left-color: var(--text-soft);
}
.msg.assistant .card-warning {
  background: #fffbf0;
  border-left-color: #f59e0b;
}
.msg.assistant .card-intro {
  color: var(--text-soft);
  font-size: 14px;
  margin-bottom: 8px;
  line-height: 1.6;
}
.msg.assistant .card-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 6px;
}
.msg.assistant .card-body {
  font-size: 15px;
  color: var(--text);
  word-wrap: break-word;
  white-space: normal;
  line-height: 1.6;
}
.msg.assistant .card-body strong {
  color: var(--text);
  font-weight: 600;
}

/* 常发圈专用：3 版文案独立卡片（v1 视觉重做） */
.msg.assistant .card-copy {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-left: 4px solid #6366f1;
  border-radius: 10px;
  padding: 16px 18px;
  margin: 14px 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  position: relative;
}
.msg.assistant .card-copy .card-title {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.msg.assistant .card-copy .card-body {
  font-size: 16px;
  line-height: 1.75;
  color: #1f2937;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.assistant .card-copy .card-body strong {
  color: #1f2937;
  font-weight: 600;
}

/* 复制按钮（每张文案卡右上角） */
.copy-btn {
  background: #eff6ff;
  color: #2563eb;
  border: 1px solid #bfdbfe;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.copy-btn:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}
.copy-btn:active {
  transform: scale(0.97);
}
.copy-btn.copied {
  background: #dcfce7;
  color: #16a34a;
  border-color: #86efac;
}

/* ===== 评分按钮 ===== */
.score-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  font-size: 13px;
  flex-wrap: wrap;
}
.score-bar-label {
  color: var(--text-soft);
  margin-right: 4px;
}
.score-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
}
.score-btn:hover {
  background: var(--bg-soft);
  border-color: var(--text-soft);
}
.score-btn:active { background: var(--bg-hover); }

/* ===== 4 象限优先级按钮（hotfix13）===== */
.priority-bar {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.prio-customer { font-weight: 600; color: var(--text); }
.prio-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
}
.prio-btn:hover { background: var(--bg-soft); border-color: var(--text-soft); }
.prio-btn:active { background: var(--bg-hover); }
.prio-btn.selected { background: var(--bg-soft); border-color: var(--primary); color: var(--primary); }

/* ===== Onboarding 确认气泡 ===== */
.onboarding-confirm {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft) !important;
  font-size: 14px !important;
  padding: 14px !important;
  border-radius: var(--radius-sm);
  margin: 4px 0;
  flex-wrap: wrap;
}
.onboarding-confirm .btn-primary {
  width: auto;
  padding: 10px 20px;
  min-height: 40px;
}
.onboarding-confirm .text-btn { color: var(--text-mute); }

/* ===== 大屏适配（桌面/平板调试用） ===== */
@media (min-width: 768px) {
  .msg.user { max-width: 70%; }
  .messages { padding: 20px max(20px, calc((100% - 760px) / 2)); }
  .chat-input {
    padding-left: max(16px, calc((100% - 760px) / 2));
    padding-right: max(16px, calc((100% - 760px) / 2));
  }
  .modal { align-items: center; padding: 20px; }
  .modal-content { border-radius: 16px; max-height: 80vh; }
}

/* ===== 表单 hint（label 下的小提示） ===== */
.form-hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-mute);
  line-height: 1.5;
}

/* ===== 密码框 + 显示按钮 复合输入 ===== */
.password-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
}
.password-wrap input {
  flex: 1;
  padding-right: 60px;
}
.pwd-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-soft);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  min-height: 32px;
}
.pwd-toggle:hover { color: var(--text); background: var(--bg-soft); }
.pwd-toggle:active { background: var(--bg-hover); }

/* ===== 主按钮禁用态（登录中 / 保存中） ===== */
.btn-primary:disabled {
  background: var(--text-mute);
  color: #ffffff;
  cursor: not-allowed;
  opacity: 0.7;
}
.btn-primary:disabled:hover { background: var(--text-mute); }

/* ===== 改密弹层提示行 ===== */
#password-modal-tip {
  margin-top: -4px;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: #fffbf0;
  border-left: 3px solid #f59e0b;
  border-radius: var(--radius-sm);
  color: #92400e;
  font-size: 13px;
}

/* ===== 丁客户 Dashboard ===== */
#dingkehu-dashboard {
  padding: 12px;
  background: var(--bg-soft, #f5f7fa);
  border-bottom: 1px solid var(--border, #e0e0e0);
}
#dingkehu-dashboard.hidden { display: none; }
.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.dash-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.dash-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dash-card {
  background: #ffffff;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.dash-card h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: #666;
  font-weight: 600;
}
/* v1.8.0-dk-step4: 卡片可点击折叠（标题整行可点，右侧 chevron） */
.dash-card.collapsible .dash-card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  margin: -4px -8px 8px -8px;  /* 扩展点击区到卡片边 */
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  color: #666;
  font-weight: 600;
  outline: none;
  transition: background 0.15s;
}
.dash-card.collapsible .dash-card-title:hover {
  background: #f5f7fa;
  color: #333;
}
.dash-card.collapsible .dash-card-title:focus {
  background: #e8f0fe;
  color: #4a90e2;
}
.dash-card-chevron {
  font-size: 14px;
  color: #999;
  display: inline-block;
  transition: transform 0.2s;
}
.dash-card.collapsed .dash-card-body {
  display: none;
}
.dash-card.collapsed .dash-card-chevron {
  transform: rotate(-90deg);
}
.dash-card.collapsed .dash-card-title {
  margin-bottom: 0;
}
.dash-card-body {
  font-size: 13px;
}
.stage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}
.stage-name {
  width: 72px;
  font-size: 12px;
  color: #555;
  flex-shrink: 0;
}
.stage-bar {
  flex: 1;
  height: 16px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
}
.stage-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #4a90e2, #6cb6ff);
  border-radius: 4px;
  transition: width 0.3s;
}
.stage-count {
  width: 24px;
  text-align: right;
  font-weight: 600;
  color: #333;
  font-size: 13px;
}
.followup-item {
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
}
.followup-item:last-child { border-bottom: none; }
/* v1.8.0-dk-step4: 跟进项头部 = 客户名 + 4 象限 chip */
.followup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.followup-name {
  font-weight: 600;
  color: #333;
  font-size: 13px;
}
.followup-stage {
  font-weight: normal;
  color: #888;
  font-size: 12px;
}
.followup-days {
  color: #e67e22;
  font-size: 12px;
  margin: 2px 0;
}
.followup-days .overdue {
  color: #d63031;
  font-weight: bold;
}
.followup-days .newly-added {
  color: #27ae60;
  font-weight: 600;
}
.followup-suggestion {
  color: #666;
  font-size: 12px;
}

/* v1.8.0-dk-step4-hotfix4: 4 象限 priority 标签 — 纯文字 + 前导圆点（无底纹/无文本框） */
.prio-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  color: #333;
  /* 显式去底纹/边框/背景 — 不像 chip */
  background: none;
  border: none;
  padding: 0;
  border-radius: 0;
}
.prio-chip::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.prio-chip.prio-empty {
  color: #999;
  font-weight: normal;
}
.prio-chip.prio-empty::before { display: none; }
/* 4 象限圆点颜色（红/黄/蓝/绿） */
.prio-chip.prio-crit::before { background: #e74c3c; }
.prio-chip.prio-high::before { background: #f1c40f; }
.prio-chip.prio-mid::before { background: #3498db; }
.prio-chip.prio-low::before { background: #27ae60; }
.prio-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}
.prio-count {
  font-weight: 600;
  color: #333;
  font-size: 13px;
}
/* v1.8.0-dk-step4: 数据概览内分块（8 阶段） */
.data-section {
  margin-bottom: 12px;
}
.data-section:last-child { margin-bottom: 0; }
.data-section-title {
  font-size: 11px;
  color: #999;
  margin-bottom: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.trend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.trend-cell {
  text-align: center;
  padding: 8px 4px;
  background: #f5f7fa;
  border-radius: 6px;
}
.trend-num {
  font-size: 20px;
  font-weight: 700;
  color: #4a90e2;
  line-height: 1.2;
}
.trend-label {
  font-size: 12px;
  color: #888;
  margin-top: 2px;
}
.empty-hint {
  color: #27ae60;
  text-align: center;
  padding: 12px;
  font-size: 13px;
}

/* ===== 丁客户「提醒」消息样式 ===== */
.msg.reminder {
  background: #fff8e1;
  border-left: 4px solid #f39c12;
  padding: 12px 14px;
}
.msg.reminder .card-intro,
.msg.reminder p {
  margin: 0;
}
