:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --border: #e5e7eb;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.header {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: white;
  padding: 20px 24px;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.header h1 { margin: 0 0 4px; font-size: 24px; }
.subtitle { margin: 0; opacity: 0.9; font-size: 14px; }
.status-badge {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.tabs {
  max-width: 1200px;
  margin: 16px auto 0;
  padding: 0 24px;
  display: flex;
  gap: 8px;
}
.tab {
  border: 1px solid var(--border);
  background: var(--card);
  padding: 10px 16px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  font-size: 14px;
}
.tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 40px;
}
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-top: 16px;
}
.card h2 { margin: 0 0 16px; font-size: 18px; }
.hint { color: var(--muted); font-size: 13px; margin-top: -8px; margin-bottom: 16px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}
.actions { display: flex; justify-content: flex-end; }

.btn {
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { background: #f9fafb; }
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn.primary:hover { background: var(--primary-dark); }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.tag-group { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.tag {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tag button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: #1d4ed8;
  font-size: 14px;
  line-height: 1;
}

.checkbox-group { display: flex; flex-wrap: wrap; gap: 12px; }
.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text);
  font-weight: 400;
}

.summary {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  font-size: 14px;
}
.hidden { display: none !important; }

.results { display: grid; gap: 12px; margin-top: 16px; }
.lead-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: grid;
  gap: 8px;
}
.lead-card h3 { margin: 0; font-size: 16px; }
.meta { color: var(--muted); font-size: 13px; }
.match-reason { font-size: 13px; line-height: 1.5; }
.lead-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge.high { background: #dcfce7; color: #166534; }
.badge.medium { background: #fef3c7; color: #92400e; }
.badge.low { background: #fee2e2; color: #991b1b; }
.badge.status-pending { background: #f3f4f6; color: #374151; }
.badge.status-analyzed { background: #dbeafe; color: #1e40af; }
.badge.status-drafted { background: #ede9fe; color: #5b21b6; }
.badge.status-sent { background: #dcfce7; color: #166534; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; background: #f9fafb; }
tr:hover td { background: #fafafa; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(520px, 100%);
  height: 100%;
  background: white;
  box-shadow: -8px 0 30px rgba(0,0,0,0.12);
  z-index: 30;
  display: flex;
  flex-direction: column;
}
.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-body {
  padding: 16px 20px 24px;
  overflow-y: auto;
  flex: 1;
}
.icon-btn {
  border: none;
  background: transparent;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 20;
}

.section-block {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
}
.section-block h4 { margin: 0 0 8px; font-size: 14px; }
.section-block p, .section-block li, .section-block pre {
  font-size: 13px;
  line-height: 1.6;
}
.section-block ul { margin: 0; padding-left: 18px; }
.email-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  white-space: pre-wrap;
  font-size: 13px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #111827;
  color: white;
  padding: 12px 16px;
  border-radius: 10px;
  z-index: 50;
  font-size: 14px;
}

@media (max-width: 768px) {
  .form-grid { grid-template-columns: 1fr; }
  .header-inner { flex-direction: column; align-items: flex-start; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
}
.login-card {
  background: white;
  border-radius: 16px;
  padding: 32px;
  width: min(400px, 92vw);
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-form { display: grid; gap: 14px; margin-top: 20px; }
.login-hint { font-size: 12px; color: var(--muted); margin-top: 16px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.btn.full { width: 100%; }
.btn.light { background: rgba(255,255,255,0.15); color: white; border-color: rgba(255,255,255,0.3); }

.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-badge {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: white;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 16px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card.highlight { border-color: #93c5fd; background: #eff6ff; }
.stat-num { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }

.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.keyword-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.country-panel {
  margin-bottom: 16px;
  padding: 16px 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.country-panel h3 { margin: 0 0 8px; font-size: 16px; }
.country-panel .strategy-text {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.5;
}
.country-panel .dialect-note {
  font-size: 13px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
}
.risk-list { display: flex; flex-direction: column; gap: 8px; }
.risk-item {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 4px solid var(--border);
  background: #f8fafc;
}
.risk-item.info { border-left-color: var(--primary); background: #eff6ff; }
.risk-item.warning { border-left-color: var(--warning); background: #fffbeb; }
.risk-item.danger { border-left-color: var(--danger); background: #fef2f2; }
.risk-item strong { display: block; margin-bottom: 2px; }
.risk-item span { color: var(--muted); }

.builtin-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.builtin-kw {
  font-size: 12px;
  padding: 4px 8px;
  background: #f3f4f6;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid var(--border);
}
.builtin-kw:hover { background: #e5e7eb; }

.draft-input, .draft-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  margin-bottom: 8px;
}
.btn.danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }

.suggest-box {
  margin-top: 12px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
}

.badge.score-high { background: #dcfce7; color: #166534; }
.badge.score-mid { background: #fef3c7; color: #92400e; }
.badge.score-low { background: #f3f4f6; color: #6b7280; }

.checkbox-inline { font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.action-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.ai-chat-card { min-height: 420px; display: flex; flex-direction: column; }
.chat-messages {
  flex: 1;
  min-height: 260px;
  max-height: 420px;
  overflow-y: auto;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.chat-bubble {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.5;
}
.chat-bubble.user { background: #dbeafe; margin-left: auto; }
.chat-bubble.assistant { background: white; border: 1px solid var(--border); }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row input { flex: 1; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.email-history { margin: 0; padding-left: 18px; font-size: 13px; }
.email-history li { margin-bottom: 8px; }
.ai-reply {
  margin-top: 8px;
  padding: 10px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
}
