:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e5e7ef;
  --line-strong: #cbd5e1;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --green: #047857;
  --green-soft: #ecfdf5;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --red: #b91c1c;
  --red-soft: #fef2f2;
  --blue: #1d4ed8;
  --blue-soft: #eff6ff;
  --purple: #7e22ce;
  --purple-soft: #faf5ff;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 30px -18px rgba(15, 23, 42, 0.18);
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; line-height: 1.3; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 24px; height: 60px;
  display: flex; align-items: center; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff; display: grid; place-items: center; font-size: 15px; font-weight: 800;
  box-shadow: 0 4px 12px -4px rgba(79, 70, 229, 0.6);
}
.brand small { display: block; font-size: 11px; font-weight: 500; color: var(--faint); letter-spacing: 0.04em; }
.topnav { display: flex; align-items: center; gap: 4px; margin-left: 8px; }
.topnav a {
  color: var(--muted); padding: 7px 12px; border-radius: 8px; font-weight: 500;
}
.topnav a:hover { background: #f8fafc; color: var(--text); text-decoration: none; }
.topnav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.token-status { color: var(--faint); font-size: 12px; }

.page { max-width: 1280px; margin: 0 auto; padding: 26px 24px 64px; }

.page-head {
  display: flex; align-items: flex-start; gap: 20px; justify-content: space-between;
  margin-bottom: 20px;
}
.page-head .sub { color: var(--muted); margin-top: 6px; font-size: 13px; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.crumbs { display: flex; gap: 6px; color: var(--faint); font-size: 12.5px; margin-bottom: 10px; }
.crumbs a { color: var(--muted); }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.card-head {
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-head .hint { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 20px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; margin: 4px 0 2px; }
.stat-sub { color: var(--faint); font-size: 12px; }
.stat::after {
  content: ""; position: absolute; right: -20px; top: -20px; width: 70px; height: 70px;
  background: var(--accent-soft); border-radius: 50%; opacity: .7;
}

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 26px 0 12px;
}
.section-title h2 { font-size: 16px; }
.section-title .hint { color: var(--faint); font-size: 12.5px; }

.project-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.project-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
  transition: border-color .15s, transform .15s;
}
.project-card:hover { border-color: #c7d2fe; }
.project-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.project-card h3 { font-size: 17px; }
.project-card .product { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.project-meta { color: var(--faint); font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.project-stats { display: flex; gap: 22px; flex-wrap: wrap; }
.project-stats div { min-width: 54px; }
.project-stats strong { display: block; font-size: 18px; letter-spacing: -0.02em; }
.project-stats span { color: var(--faint); font-size: 11.5px; }
.project-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; }

.progress { height: 8px; background: #eef1f7; border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, #6366f1, #8b5cf6); border-radius: 999px; }
.progress-label { display: flex; justify-content: space-between; color: var(--faint); font-size: 11.5px; margin-top: 5px; }

.project-shell-head {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.project-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.project-title-row h1 { display: flex; align-items: center; gap: 10px; font-size: 22px; }
.project-facts { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.project-facts code { font-family: var(--mono); font-size: 12px; background: #f1f5f9; padding: 1px 5px; border-radius: 5px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 20px 0 18px; overflow-x: auto; }
.tabs a {
  padding: 10px 14px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap; font-size: 13.5px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 5px; border-radius: 999px; background: #eef1f7; color: var(--muted); font-size: 11px; text-align: center; }
.tabs a.active .count { background: var(--accent-soft); color: var(--accent); }

.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 12px;
}
.toolbar .spacer { flex: 1; }
.toolbar .selection-info { color: var(--muted); font-size: 12.5px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 5px 11px; font-size: 12.5px; cursor: pointer; font-weight: 500;
}
.chip:hover { border-color: var(--line-strong); color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .n { opacity: .75; margin-left: 4px; font-size: 11px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--text);
  padding: 8px 13px; border-radius: 9px; font-size: 13px; font-weight: 550;
  cursor: pointer; white-space: nowrap; transition: all .12s;
  font-family: inherit;
}
.btn:hover { background: #f8fafc; border-color: #b6c2d4; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 4px 10px -5px rgba(79,70,229,.6); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--red); border-color: #fecaca; background: #fff; }
.btn-danger:hover { background: var(--red-soft); border-color: #fca5a5; }
.btn-success { color: var(--green); border-color: #a7f3d0; background: #fff; }
.btn-success:hover { background: var(--green-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }
.btn-sm { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; }

.input, .select, .textarea {
  width: 100%; border: 1px solid var(--line-strong); background: #fff; color: var(--text);
  border-radius: 9px; padding: 8px 10px; font-size: 13px; font-family: inherit; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: #a5b4fc; box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.14);
}
.input::placeholder, .textarea::placeholder { color: #b6c0cf; }
.textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.input-sm { padding: 6px 9px; font-size: 12.5px; }
.search { width: 220px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 12.5px; font-weight: 600; color: #334155; }
.field .help { color: var(--faint); font-size: 11.5px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.span-2 { grid-column: span 2; }
.checkbox-row { display: flex; align-items: center; gap: 8px; color: #334155; font-size: 13px; }
.checkbox-row input { width: 15px; height: 15px; accent-color: var(--accent); }
.form-section { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 18px; }
.form-section:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.form-section h3 { margin-bottom: 12px; font-size: 14px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--faint); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap; background: #fbfcfe;
}
td { padding: 12px; border-bottom: 1px solid #eef1f6; vertical-align: middle; font-size: 13px; }
tbody tr:hover { background: #fafbff; }
tbody tr:last-child td { border-bottom: 0; }
.cell-email { font-weight: 600; color: var(--text); }
.cell-sub { color: var(--faint); font-size: 11.5px; margin-top: 2px; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; }
.cell-muted { color: var(--muted); }
.cell-mono { font-family: var(--mono); font-size: 12px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px;
  padding: 2px 8px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: #f1f5f9; color: #475569;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge-plain::before { display: none; }
.badge-draft, .badge-drafted, .badge-pending { background: var(--amber-soft); color: var(--amber); }
.badge-queued, .badge-approved, .badge-imported { background: var(--blue-soft); color: var(--blue); }
.badge-sent, .badge-validated { background: #eef2ff; color: #4338ca; }
.badge-replied, .badge-interested { background: var(--green-soft); color: var(--green); }
.badge-bounced, .badge-blocked, .badge-unsubscribed, .badge-declined { background: var(--red-soft); color: var(--red); }
.badge-closed, .badge-skipped, .badge-unknown, .badge-ooo { background: #f1f5f9; color: #64748b; }
.badge-price, .badge-question { background: var(--purple-soft); color: var(--purple); }
.badge-unsubscribe { background: var(--red-soft); color: var(--red); }
.badge-bounce { background: var(--red-soft); color: var(--red); }
.badge-global { background: #fef3c7; color: #92400e; }
.badge-scope { background: #e0e7ff; color: #3730a3; }

.empty {
  text-align: center; padding: 46px 20px; color: var(--muted);
}
.empty .icon { font-size: 30px; margin-bottom: 10px; opacity: .65; }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.empty p { font-size: 13px; color: var(--faint); }
.empty .btn { margin-top: 14px; }

.notice {
  border: 1px solid #fde68a; background: #fffbeb; color: #92400e;
  border-radius: 10px; padding: 10px 13px; font-size: 12.5px; margin-bottom: 14px;
}
.notice-blue { border-color: #bfdbfe; background: #eff6ff; color: #1e40af; }
.notice-red { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.notice-green { border-color: #a7f3d0; background: #ecfdf5; color: #065f46; }

.issue-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 5px; }
.issue-list li { color: var(--red); font-size: 12.5px; display: flex; gap: 6px; }
.issue-list li::before { content: "•"; }
.warning-list li { color: var(--amber); }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--faint); }
.kv dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }

.thread-layout { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 18px; align-items: start; }
.conversation { display: flex; flex-direction: column; gap: 12px; }
.msg { border: 1px solid var(--line); border-radius: 13px; background: #fff; padding: 14px 16px; box-shadow: 0 1px 1px rgba(15,23,42,.03); }
.msg-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--faint); font-size: 11.5px; margin-bottom: 8px; }
.msg-head strong { color: var(--muted); font-weight: 600; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13.5px; line-height: 1.7; }
.msg.out { background: #f5f6ff; border-color: #dfe3ff; }
.msg.in { background: #fff; }
.msg-summary { margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 12.5px; }
.msg-unread { border-left: 3px solid var(--accent); }
.bubble-tools { display: flex; gap: 6px; margin-top: 8px; }

.side-panel { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 76px; }
.side-panel .card-head { padding: 13px 16px; }
.side-panel .card-body { padding: 16px; }
.editor-subject { font-weight: 600; }
.editor-body { min-height: 360px; font-family: var(--mono); font-size: 12.5px; line-height: 1.65; }
.composer { min-height: 150px; }
.count-hint { color: var(--faint); font-size: 11.5px; text-align: right; }

.dropzone {
  border: 1.5px dashed var(--line-strong); border-radius: 12px; background: #fbfcff;
  padding: 26px; text-align: center; color: var(--muted); cursor: pointer; transition: .12s;
}
.dropzone:hover, .dropzone.drag { border-color: #a5b4fc; background: #f5f7ff; }
.dropzone strong { color: var(--text); display: block; margin-bottom: 3px; }
.dropzone small { color: var(--faint); }

.mapping-grid { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; align-items: center; }
.mapping-grid label { font-size: 12.5px; color: #334155; font-weight: 600; }
.preview-table { font-size: 12px; }
.preview-table td, .preview-table th { padding: 7px 9px; }

.import-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0; }
.import-summary div { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; }
.import-summary strong { display: block; font-size: 20px; }
.import-summary span { color: var(--faint); font-size: 11.5px; }
.reason-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 80; background: rgba(15, 23, 42, 0.48);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fade .12s ease-out;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 560px; max-height: 90vh;
  overflow: auto; box-shadow: 0 30px 80px -20px rgba(15, 23, 42, .45);
  animation: pop .14s ease-out;
}
.modal.wide { max-width: 880px; }
.modal.xwide { max-width: 1080px; }
.modal-head {
  position: sticky; top: 0; background: #fff; z-index: 2;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px;
  border-top: 1px solid var(--line); background: #fcfdff;
}
.icon-btn {
  border: 0; background: transparent; color: var(--faint); font-size: 20px; cursor: pointer;
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
}
.icon-btn:hover { background: #f1f5f9; color: var(--text); }

.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast {
  background: #111827; color: #fff; padding: 11px 14px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 16px 40px -12px rgba(15, 23, 42, .5); animation: slide .15s ease-out;
  display: flex; gap: 8px; align-items: flex-start;
}
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }
.toast.info { background: #1e3a8a; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid #e2e8f0;
  border-top-color: var(--accent); animation: spin .7s linear infinite;
}
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 70px 20px; color: var(--faint); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(900px 500px at 50% -10%, #e0e7ff 0%, transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 32px; box-shadow: 0 30px 70px -30px rgba(15,23,42,.3); }
.login-card .brand { justify-content: center; margin-bottom: 22px; }
.login-card h1 { font-size: 20px; text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin: 6px 0 22px; }
.login-card .field { margin-bottom: 14px; }
.login-note { color: var(--faint); font-size: 11.5px; margin-top: 14px; text-align: center; }

.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 14px; } .mt-4 { margin-top: 22px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 14px; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hidden { display: none !important; }

.stat-inline { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; }
.stat-inline strong { color: var(--text); }

.timeline-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--faint); font-size: 11.5px; }

@media (max-width: 1020px) {
  .thread-layout { grid-template-columns: 1fr; }
  .side-panel { position: static; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .topbar-inner { padding: 0 14px; gap: 12px; }
  .topnav a { padding: 6px 8px; font-size: 13px; }
  .token-status { display: none; }
  .page { padding: 18px 14px 50px; }
  .project-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .page-head { flex-direction: column; }
  .search { width: 100%; }
  .toolbar { align-items: stretch; }
  .import-summary { grid-template-columns: repeat(2, 1fr); }
  .mapping-grid { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 10px; }
  .modal { max-height: 94vh; border-radius: 13px; }
  .project-stats { gap: 16px; }
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.99); } }
@keyframes slide { from { opacity: 0; transform: translateY(6px); } }
