:root {
  --primary: #4f6bf7;
  --primary-dark: #3d55d6;
  --primary-light: #eef1fe;
  --violet: #7c5cf0;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #23262f;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --border: #e8eaf2;
  --sidebar: #171d2f;
  --sidebar-2: #1f2740;
  --green: #10b981;
  --red: #ef4444;
  --orange: #f59e0b;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(23, 29, 47, .05), 0 8px 24px rgba(23, 29, 47, .05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

.hidden { display: none !important; }

/* ============ 登录页 ============ */
.auth-bg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(800px 500px at 15% 10%, rgba(79,107,247,.18), transparent 60%),
    radial-gradient(700px 500px at 85% 90%, rgba(124,92,240,.16), transparent 60%),
    var(--bg);
  padding: 24px;
}

.auth-card {
  width: 400px;
  max-width: 100%;
  background: var(--card);
  border-radius: 20px;
  padding: 40px 36px 32px;
  box-shadow: 0 20px 60px rgba(23, 29, 47, .12);
  text-align: center;
}

.auth-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 24px rgba(79,107,247,.35);
}

.auth-card h1 { font-size: 22px; font-weight: 700; letter-spacing: 1px; }
.auth-sub { color: var(--text-3); font-size: 13px; margin: 6px 0 24px; }

.auth-tabs {
  display: flex;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 22px;
}

.auth-tabs span {
  flex: 1;
  padding: 8px 0;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  transition: all .2s;
}

.auth-tabs span.active {
  background: var(--card);
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.auth-card form { display: flex; flex-direction: column; gap: 14px; }

.auth-card input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  outline: none;
  transition: border .2s, box-shadow .2s;
  background: #fbfcfe;
}

.auth-card input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,107,247,.12);
  background: #fff;
}

.btn-primary {
  border: none;
  border-radius: 10px;
  padding: 12px 0;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  box-shadow: 0 6px 16px rgba(79,107,247,.3);
  transition: opacity .2s, transform .1s;
}

.btn-primary:hover { opacity: .92; }
.btn-primary:active { transform: scale(.98); }

.auth-tip { margin-top: 18px; font-size: 12px; color: var(--text-3); }

/* ============ 布局 ============ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: var(--sidebar);
  color: #aab1c5;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 10;
}

.sidebar .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 18px;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
}

.sidebar .logo .logo-ico {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.sidebar nav { flex: 1; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  color: #aab1c5;
  transition: all .15s;
}

.nav-item:hover { background: var(--sidebar-2); color: #fff; }

.nav-item.active {
  background: linear-gradient(135deg, var(--primary), var(--violet));
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(79,107,247,.35);
}

.nav-item svg { flex: none; opacity: .9; }

.sidebar-footer {
  padding: 16px 20px;
  font-size: 11px;
  color: #5b6478;
  border-top: 1px solid rgba(255,255,255,.06);
}

.main { flex: 1; margin-left: 232px; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 60px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.page-title { font-size: 17px; font-weight: 700; }

.user-box { display: flex; align-items: center; gap: 14px; color: var(--text-2); font-size: 13px; }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
}

.btn-link:hover { background: var(--bg); color: var(--red); }

.content { padding: 24px 28px 48px; max-width: 1200px; width: 100%; }

/* ============ 通用组件 ============ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title .sub { font-size: 12px; color: var(--text-3); font-weight: 400; margin-left: 10px; }

.btn {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 9px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text);
  transition: all .15s;
}

.btn:hover { border-color: var(--primary); color: var(--primary); }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }

.btn-primary-sm {
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  color: #fff;
  border-radius: 9px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(79,107,247,.25);
}

.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); color: var(--red); background: #fef2f2; }

.btn:disabled { opacity: .5; cursor: not-allowed; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th {
  text-align: left;
  color: var(--text-3);
  font-weight: 500;
  font-size: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td { padding: 13px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfe; }
tbody tr:last-child:hover { background: transparent; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
}

.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge.green { background: #ecfdf5; color: #059669; }
.badge.gray { background: #f3f4f6; color: #6b7280; }
.badge.red { background: #fef2f2; color: #dc2626; }
.badge.orange { background: #fffbeb; color: #d97706; }
.badge.blue { background: var(--primary-light); color: var(--primary-dark); }
.badge.violet { background: #f5f3ff; color: #7c3aed; }

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--primary-light);
  color: var(--primary-dark);
}

.empty {
  text-align: center;
  color: var(--text-3);
  padding: 48px 0;
  font-size: 13px;
}

.empty svg { margin-bottom: 10px; opacity: .4; }

/* 表单 */
.form-item { margin-bottom: 16px; }

.form-item label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 7px;
}

.form-item label .req { color: var(--red); margin-left: 2px; }

.form-item input[type="text"],
.form-item input[type="password"],
.form-item input[type="number"],
.form-item input[type="url"],
.form-item select,
.form-item textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 13.5px;
  outline: none;
  background: #fbfcfe;
  transition: border .2s, box-shadow .2s;
}

.form-item input:focus, .form-item select:focus, .form-item textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,107,247,.1);
  background: #fff;
}

.form-item .hint { font-size: 12px; color: var(--text-3); margin-top: 5px; line-height: 1.5; }

.form-row { display: flex; gap: 14px; }
.form-row .form-item { flex: 1; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }

.switch input { display: none; }

.switch .track {
  width: 38px;
  height: 22px;
  border-radius: 99px;
  background: #d6dae5;
  position: relative;
  transition: background .2s;
  flex: none;
}

.switch .track::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch .sw-label { font-size: 13px; color: var(--text-2); }

/* 模态框 */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 19, 33, .45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: 40px 16px;
  overflow-y: auto;
}

.modal {
  background: var(--card);
  border-radius: 16px;
  width: 640px;
  max-width: 100%;
  box-shadow: 0 24px 80px rgba(15, 19, 33, .25);
  animation: modalIn .18s ease;
}

.modal.wide { width: 860px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 { font-size: 16px; }

.modal-close {
  border: none;
  background: none;
  font-size: 20px;
  color: var(--text-3);
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 22px; max-height: calc(100vh - 220px); overflow-y: auto; }

.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-dark);
  margin: 20px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::before {
  content: '';
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--primary), var(--violet));
}

.section-title:first-child { margin-top: 0; }

/* 变体编辑器 */
.variant-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  background: #fbfcfe;
}

.variant-item .vi-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.variant-item .vi-head .vi-name { font-size: 12px; font-weight: 700; color: var(--text-2); }

.img-uploader { display: flex; gap: 8px; align-items: center; }

.img-uploader input[type="text"] { flex: 1; }

.thumb {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg);
  flex: none;
}

/* 抖音卡片预览 */
.preview-box {
  background: #ededed;
  border-radius: 14px;
  padding: 18px;
  display: flex;
  justify-content: flex-start;
}

.dy-card {
  background: #fff;
  border-radius: 10px;
  padding: 11px 12px;
  max-width: 300px;
  width: 100%;
  display: flex;
  gap: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}

.dy-card .dy-thumb {
  width: 46px;
  height: 46px;
  border-radius: 6px;
  object-fit: cover;
  background: linear-gradient(135deg, #c7d2fe, #a5b4fc);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 10px;
}

.dy-card .dy-body { min-width: 0; display: flex; flex-direction: column; justify-content: space-between; }

.dy-card .dy-title {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dy-card .dy-desc {
  font-size: 11px;
  color: #999;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 2px 0;
}

.dy-card .dy-host { font-size: 10px; color: #bbb; }

/* 统计卡片 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.stat-card .sc-icon {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.stat-card .sc-num { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.stat-card .sc-label { font-size: 12px; color: var(--text-3); margin-top: 3px; }

.chart-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; }

.chart-box .ch-title { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.chart-box .ch-sub { font-size: 12px; color: var(--text-3); margin-bottom: 12px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 6px; }

.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }

.legend i { width: 10px; height: 10px; border-radius: 3px; }

/* 漏斗归因 */
.funnel-body { padding: 8px 4px 2px; }

.funnel-step { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }

.funnel-step .fs-label { width: 82px; flex: none; font-size: 13px; font-weight: 600; color: var(--text-2); text-align: right; }

.funnel-step .fs-bar-area { flex: 1; min-width: 0; }

.funnel-step .fs-bar {
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
  min-width: 54px;
  transition: width .5s ease;
}

.funnel-step .fs-count { font-size: 14px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.15); }

.funnel-step .fs-rate { width: 128px; flex: none; font-size: 13px; font-weight: 700; color: var(--text-1); display: flex; flex-direction: column; gap: 2px; }

.funnel-step .fs-drop { font-size: 11.5px; font-weight: 500; color: var(--text-3); }

.fs-dim-link { color: var(--primary); font-weight: 600; }

.fs-dim-link:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .funnel-step .fs-label { width: 64px; font-size: 12px; }
  .funnel-step .fs-rate { width: 96px; }
}

/* 顶部操作条 */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }

.toolbar .toolbar-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

select.mini {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  background: #fff;
  outline: none;
}

.link-code {
  font-family: Consolas, Monaco, monospace;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.copy-btn { color: var(--primary); font-size: 12px; background: none; border: none; padding: 2px 4px; }
.copy-btn:hover { text-decoration: underline; }

/* toast */
#toast-box {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.toast {
  background: #1f2433;
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  animation: toastIn .2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.ok::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #34d399; }
.toast.err::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #f87171; }

@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* 分页 */
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 14px; font-size: 13px; color: var(--text-2); }

/* 域名池双栏 */
.domain-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.domain-note {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12.5px;
  color: #92400e;
  line-height: 1.7;
  margin-bottom: 16px;
}

.info-note {
  background: var(--primary-light);
  border: 1px solid #d5defc;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12.5px;
  color: #3d55d6;
  line-height: 1.7;
  margin-bottom: 16px;
}

@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .domain-grid { grid-template-columns: 1fr; }
}

.qr-thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg);
}

.mono { font-family: Consolas, Monaco, monospace; font-size: 12px; }

.muted { color: var(--text-3); font-size: 12px; }

.action-cell { display: flex; gap: 4px; flex-wrap: wrap; }

.result-box {
  margin-top: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 12.5px;
  font-family: Consolas, Monaco, monospace;
  word-break: break-all;
  color: #334155;
}

.result-box.err { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }

/* ---- 会话行为进度点 ---- */
.sdot-row { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.sdot {
  display: inline-block; padding: 1px 7px; border-radius: 99px;
  font-size: 11px; line-height: 17px; background: #f1f3f8; color: #9aa3b2;
}
.sdot.on { background: #e3f7ee; color: #059669; font-weight: 600; }
.sdot.blocked { background: #fef3e2; color: #d97706; font-weight: 600; }
.sarrow { color: #c3c9d4; font-size: 11px; margin: 0 1px; }

/* ---- 会话时间线 ---- */
.timeline { position: relative; padding-left: 6px; }
.tl-item { display: flex; gap: 12px; position: relative; padding-bottom: 16px; }
.tl-item::before {
  content: ''; position: absolute; left: 5px; top: 14px; bottom: 0;
  width: 2px; background: #edf0f6;
}
.tl-item:last-child::before { display: none; }
.tl-dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px #e3e7f0; }
.tl-dot.blue { background: #4f6bf7; } .tl-dot.violet { background: #7c5cf0; }
.tl-dot.green { background: #10b981; } .tl-dot.orange { background: #f59e0b; }
.tl-dot.red { background: #ef4444; } .tl-dot.gray { background: #9aa3b2; }
.tl-body { flex: 1; min-width: 0; }
.tl-head { display: flex; align-items: center; gap: 10px; }
.tl-note { font-size: 12.5px; color: #b45309; margin-top: 5px; word-break: break-all; }
.tl-meta { font-size: 12px; color: #9aa3b2; margin-top: 4px; }

/* ---- 漏斗下钻链接 ---- */
.fs-dim-link { color: var(--primary); text-decoration: none; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.fs-dim-link:hover { text-decoration: underline; }
