:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --orange: #d97706;
  --orange-bg: #fffbeb;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --purple: #7c3aed;
  --purple-bg: #f5f3ff;
  --gray-bg: #f1f5f9;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.text-red { color: var(--danger); }
.text-blue { color: var(--primary); }
.text-orange { color: var(--orange); }
.text-green { color: var(--green); }

/* Toast */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  font-size: 13px;
  max-width: 380px;
}
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }

/* Login */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #0f172a 100%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.login-logo { font-size: 40px; text-align: center; margin-bottom: 6px; }
.login-card h1 { font-size: 20px; text-align: center; margin: 0 0 6px; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.login-hint {
  margin-top: 18px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* Header */
.topbar {
  background: #0f172a;
  color: #fff;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 20px; }
.brand { font-weight: 700; font-size: 16px; letter-spacing: 0.3px; }
.nav-tabs { display: flex; gap: 4px; }
.nav-tab {
  background: transparent;
  color: #cbd5e1;
  border: none;
  padding: 8px 14px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.nav-tab:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-tab.active { background: var(--primary); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-badge { font-size: 13px; color: #e2e8f0; }

/* Layout */
.container { max-width: 1520px; margin: 18px auto; padding: 0 18px 40px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 960px) { .two-col { grid-template-columns: 1fr; } }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}
@media (max-width: 900px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; }

/* Forms & Buttons */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 4px; }
.form-group.inline { display: flex; align-items: center; gap: 8px; margin-bottom: 0; }
.form-group.inline label { margin-bottom: 0; white-space: nowrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.btn {
  border: none;
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 10px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #0f766e; color: #fff; }
.btn-secondary:hover { background: #115e59; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: #e2e8f0; color: #334155; }
.btn-ghost:hover { background: #cbd5e1; }
.inline-form { display: flex; gap: 8px; align-items: center; }

/* Filters */
.filter-card { margin-bottom: 12px; padding: 14px 16px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search-input { flex: 1 1 280px; }
.filter-row select { width: auto; min-width: 120px; }
.num-input { width: 92px !important; }
.sm-input { width: 150px !important; padding: 5px 8px !important; }
.sep { color: var(--muted); }
.tag-filter-bar {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.bar-label { font-size: 12px; color: var(--muted); }

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.result-count { font-size: 13px; color: var(--muted); margin-left: 6px; }
#batch-actions-bar {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 5px 10px;
  border-radius: 8px;
}

/* Table */
.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  background: #f8fafc;
  color: #475569;
  text-align: left;
  padding: 10px 10px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr.row-risk { border-left: 4px solid var(--danger); background: #fffafa; }
.data-table.compact td, .data-table.compact th { padding: 7px 8px; font-size: 12px; }

.tg-main { font-weight: 700; color: #0f172a; word-break: break-all; }
.hist-chip {
  display: inline-block;
  margin-top: 3px;
  font-size: 11px;
  background: #fee2e2;
  color: #991b1b;
  padding: 1px 6px;
  border-radius: 4px;
}
.sub-text { font-size: 11px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.quote-num { font-weight: 700; color: #0f766e; }

/* Links */
.link-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  padding: 2px 7px;
  border-radius: 5px;
  text-decoration: none;
  margin: 0 4px 4px 0;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-pill:hover { background: #dbeafe; }

/* Tags */
.tag-pill-list { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
}
.tag-red { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.tag-orange { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.tag-blue { background: #dbeafe; color: #1d4ed8; border-color: #bfdbfe; }
.tag-green { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.tag-purple { background: #ede9fe; color: #6d28d9; border-color: #ddd6fe; }
.tag-gray { background: #e2e8f0; color: #475569; border-color: #cbd5e1; }
.tag-pill .tag-x { font-weight: 700; margin-left: 2px; opacity: 0.7; }
.tag-pill .tag-x:hover { opacity: 1; }
.tag-pill.filter-include { outline: 2px solid var(--primary); font-weight: 700; }
.tag-pill.filter-exclude { outline: 2px solid var(--danger); text-decoration: line-through; opacity: 0.85; }
.btn-add-tag-mini {
  border: 1px dashed #94a3b8;
  background: transparent;
  color: #64748b;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 12px;
  cursor: pointer;
}
.btn-add-tag-mini:hover { border-color: var(--primary); color: var(--primary); }

.inline-status {
  padding: 4px 6px !important;
  font-size: 12px !important;
  border-radius: 6px;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
}

/* Import */
.import-mode-tabs { display: flex; gap: 8px; margin: 12px 0; }
.import-options { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 14px; }
.dropzone {
  border: 2px dashed #94a3b8;
  border-radius: 12px;
  padding: 30px 20px;
  text-align: center;
  position: relative;
  background: #f8fafc;
  margin-bottom: 14px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: #eff6ff; }
.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.dropzone-icon { font-size: 32px; }
.dropzone-title { font-weight: 600; margin-top: 6px; }
.dropzone-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.selected-file { margin-top: 8px; font-weight: 700; color: var(--primary); }

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.summary-badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.sbadge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}
.sbadge-total { background: #e2e8f0; color: #1e293b; }
.sbadge-new { background: #dcfce7; color: #15803d; }
.sbadge-fraud { background: #fee2e2; color: #b91c1c; }
.sbadge-blacklist { background: #fef3c7; color: #b45309; }
.sbadge-dup { background: #dbeafe; color: #1d4ed8; }

.ocr-raw-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 12px;
}
.ocr-raw-box pre { white-space: pre-wrap; margin: 8px 0 0; max-height: 180px; overflow: auto; }

.risk-note {
  font-size: 11px;
  padding: 4px 6px;
  border-radius: 5px;
  margin-bottom: 5px;
  line-height: 1.4;
}
.risk-fraud_alert { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; font-weight: 600; }
.risk-blacklist_alert { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.risk-duplicate { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.risk-new { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* Anti-fraud cards */
.check-cards { display: flex; flex-direction: column; gap: 12px; }
.check-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 5px solid #94a3b8;
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.check-card.level-fraud_alert { border-left-color: var(--danger); background: #fff5f5; }
.check-card.level-blacklist_alert { border-left-color: var(--orange); background: #fffbeb; }
.check-card.level-duplicate { border-left-color: var(--primary); }
.check-card.level-new { border-left-color: var(--green); }
.check-card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.check-match-box {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}

/* Logs & Tag Manage */
.tags-manage-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.tag-manage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid #f1f5f9;
  border-radius: 7px;
}
.log-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.log-item {
  font-size: 12px;
  padding: 7px 10px;
  background: #f8fafc;
  border-radius: 6px;
  border-left: 3px solid #cbd5e1;
}
.log-meta { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.55); }
.modal-dialog {
  position: relative;
  background: var(--card);
  border-radius: 12px;
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
}
.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.btn-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-footer-inline { display: flex; gap: 10px; margin-top: 10px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.detail-section { margin-bottom: 14px; }
.detail-section h4 { margin: 0 0 8px; font-size: 13px; color: #334155; }
.link-list { display: flex; flex-direction: column; gap: 6px; }
.link-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
}
.mini-list { display: flex; flex-direction: column; gap: 5px; max-height: 150px; overflow-y: auto; font-size: 12px; }
.raw-line-box {
  display: block;
  background: #f1f5f9;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  word-break: break-all;
}
.checkbox-row { margin: 8px 0; font-size: 12px; color: #475569; }
.checkbox-row input { width: auto; margin-right: 6px; }
.alert-box { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* Quick Tag Popover */
.popover {
  position: fixed;
  z-index: 800;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.2);
  padding: 10px;
  width: 240px;
}
.popover-title { font-size: 12px; font-weight: 700; color: #475569; margin-bottom: 8px; }
.popover-choices { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; max-height: 160px; overflow-y: auto; }
.popover-custom input { font-size: 12px; padding: 6px 8px; }
