:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #059669;
  --bad: #dc2626;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .04), 0 8px 24px rgba(17, 24, 39, .06);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

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

h1, h2, h3, p { margin: 0; }
h1 { font-size: 17px; letter-spacing: -.2px; }
h2 { font-size: 22px; letter-spacing: -.4px; }
h3 { font-size: 15px; margin-bottom: 14px; }
b { font-weight: 600; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #eef2ff; color: #3730a3; padding: 1px 5px; border-radius: 5px; font-size: 12px; }

.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.6; }

/* Auth */
.auth-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(1000px 500px at 15% -10%, #dbeafe 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 110%, #ede9fe 0%, transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff; font-weight: 800; font-size: 18px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, .25);
}
.brand h1 { line-height: 1.1; }
.brand p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.auth-card > .brand { padding: 22px 24px; border-bottom: 1px solid var(--line); }
.auth-body { padding: 24px; }
.auth-body h2 { font-size: 19px; margin-bottom: 6px; }
.auth-body > .muted { margin-bottom: 20px; }
.auth-error {
  background: #fef2f2; color: #991b1b; border: 1px solid #fecaca;
  padding: 9px 12px; border-radius: 9px; font-size: 13px; margin-bottom: 12px;
}
.auth-body .tiny { margin-top: 14px; text-align: center; }

/* Shell */
.topbar {
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  background: rgba(255, 255, 255, .85);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(180%) blur(12px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0;
  white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-muted { background: #f3f4f6; color: #4b5563; border-color: var(--line); }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: #fde68a; }

.layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 28px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.steps { position: sticky; top: 92px; align-self: start; display: flex; flex-direction: column; gap: 6px; }
.step {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 11px 12px;
  background: transparent; border: 1px solid transparent;
  border-radius: 12px; cursor: pointer; text-align: left;
  color: var(--text); font: inherit;
  transition: background .15s, border-color .15s;
}
.step:hover { background: #fff; border-color: var(--line); }
.step.active { background: #fff; border-color: var(--line); box-shadow: var(--shadow); }
.step-no {
  width: 28px; height: 28px; flex: 0 0 28px; border-radius: 9px;
  display: grid; place-items: center;
  background: #eef2ff; color: #4338ca; font-size: 12px; font-weight: 700;
}
.step.active .step-no { background: var(--primary); color: #fff; }
.step b { display: block; font-size: 13px; line-height: 1.3; }
.step small { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.steps-foot { margin-top: 14px; padding: 12px; border-top: 1px solid var(--line); }

.content { min-width: 0; }
.panel { display: none; }
.panel.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.panel-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 18px; margin-bottom: 20px;
}
.panel-head .muted { margin-top: 4px; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid-2.wide-right { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); }
.grid-2.tight { gap: 10px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* Forms */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.field input, .field select, .field textarea,
.input-inline {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 9px 11px;
  font: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus, .input-inline:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.field textarea { resize: vertical; }
.field .tiny { display: block; margin-top: 5px; }
.input-inline { width: 72px; padding: 6px 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line-strong);
  background: #fff; color: var(--text);
  border-radius: 10px; padding: 9px 14px;
  font: inherit; font-weight: 600; font-size: 13px;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #f9fafb; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(37, 99, 235, .2); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; }
.btn-danger-ghost { color: var(--bad); border-color: #fecaca; background: #fff; }
.btn-danger-ghost:hover { background: #fef2f2; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.row-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* Dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 22px 16px; border: 1.5px dashed var(--line-strong);
  border-radius: 12px; background: #fafafa; cursor: pointer; text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: #eff6ff; }
.dropzone b { font-size: 13px; }
.dropzone small { color: var(--muted); font-size: 11px; }
.drop-icon {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: #e0e7ff; color: #4338ca; font-size: 17px; margin-bottom: 4px;
}
.or { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted); font-size: 11px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 14px 0; }
.stat {
  background: #f9fafb; border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 10px;
}
.stat span { display: block; font-size: 11px; color: var(--muted); }
.stat b { font-size: 18px; line-height: 1.3; }
.stat.ok b { color: var(--ok); }
.stat.bad b { color: var(--bad); }
.stat.muted b { color: var(--muted); }
.stat.big b { font-size: 28px; }
.stat.big small { font-size: 13px; color: var(--muted); font-weight: 400; }

.job-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.job-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Table */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.table-wrap.small { max-height: 340px; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th {
  text-align: left; font-weight: 600; color: #4b5563; background: #f9fafb;
  padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1;
  white-space: nowrap;
}
.table td { padding: 8px 10px; border-bottom: 1px solid #f1f2f4; vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .email { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.table .other { color: var(--muted); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .err { color: var(--bad); font-size: 11.5px; }
.badge {
  display: inline-block; padding: 2px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; background: #f3f4f6; color: #4b5563; white-space: nowrap;
}
.badge.sent { background: #ecfdf5; color: #047857; }
.badge.failed { background: #fef2f2; color: #b91c1c; }
.badge.skipped { background: #f3f4f6; color: #6b7280; }
.badge.sending { background: #eff6ff; color: #1d4ed8; }
.badge.unknown { background: #fffbeb; color: #b45309; }

/* Preview */
.preview-card { position: sticky; top: 92px; }
.preview-controls { display: flex; align-items: center; gap: 6px; }
.preview-meta { font-size: 12px; color: var(--muted); border-bottom: 1px dashed var(--line); padding-bottom: 8px; margin-bottom: 10px; }
.preview-subject { font-weight: 700; margin-bottom: 10px; word-break: break-word; }
.preview-body {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; line-height: 1.7; color: #1f2937;
  background: #fbfbfc; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; max-height: 520px; overflow: auto;
}

/* Progress */
.progress-head { display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.progress { height: 12px; background: #eef0f3; border-radius: 999px; overflow: hidden; }
.progress-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, #2563eb, #7c3aed);
  border-radius: 999px; transition: width .35s ease;
}
.progress-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.checklist { margin: 0; padding-left: 18px; color: #374151; }
.checklist li { margin-bottom: 7px; font-size: 13px; }

/* History */
.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; cursor: pointer; font: inherit; text-align: left;
}
.history-item:hover { border-color: var(--line-strong); background: #fafafa; }
.history-item.active { border-color: var(--primary); background: #eff6ff; }
.history-item b { font-size: 12.5px; display: block; }
.history-item small { color: var(--muted); font-size: 11px; }

/* Content library */
.content-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.content-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff;
}
.content-item.active { border-color: var(--primary); background: #eff6ff; }
.content-main { min-width: 0; flex: 1; cursor: pointer; }
.content-main b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.content-main small { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.content-main:hover b { color: var(--primary); }
.content-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.content-actions .btn { padding: 4px 8px; font-size: 11px; border-radius: 7px; }
.content-empty { padding: 18px; text-align: center; color: var(--muted); }
.content-pill {
  display: block; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 10px; background: #f9fafb; font-size: 13px; min-height: 38px;
}

/* Empty / notices */
.empty { text-align: center; padding: 26px 10px; color: var(--muted); }
.notice { border-radius: 12px; padding: 14px 16px; margin-top: 4px; font-size: 13px; }
.notice.warn { background: var(--warn-bg); border: 1px solid #fde68a; color: #78350f; }
.notice p { margin-top: 5px; line-height: 1.6; }

/* Toast */
.toast {
  position: fixed; right: 22px; bottom: 22px; z-index: 100;
  max-width: 380px; padding: 11px 15px;
  background: #111827; color: #fff; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2); font-size: 13px;
  animation: toastIn .18s ease;
}
.toast.err { background: #b91c1c; }
.toast.ok { background: #047857; }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Responsive */
@media (max-width: 1050px) {
  .grid-2, .grid-2.wide-right { grid-template-columns: 1fr; }
  .preview-card { position: static; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; gap: 16px; padding: 16px 14px 48px; }
  .steps { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .step { min-width: 150px; }
  .steps-foot { display: none; }
  .topbar { padding: 0 14px; }
  .topbar .brand p { display: none; }
  .topbar-right .pill-muted { display: none; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .progress-head { grid-template-columns: repeat(3, 1fr); }
  .panel-head { flex-direction: column; align-items: flex-start; }
}
