:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --border: #e6e8ef;
  --text: #1b2030;
  --text-soft: #5b6479;
  --muted: #8b93a7;
  --primary: #3b5bfd;
  --primary-dark: #2f49d9;
  --green: #0f9d68;
  --green-soft: #e7f7ef;
  --red: #dc4c4c;
  --red-soft: #fdecec;
  --amber: #c47a10;
  --amber-soft: #fff4e2;
  --blue-soft: #eaf0ff;
  --shadow: 0 1px 2px rgba(20, 28, 60, .04), 0 8px 24px rgba(20, 28, 60, .05);
  --radius: 14px;
}

* { 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", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { width: 18px; height: 18px; flex: none; }

.app-shell { min-height: 100vh; }

/* 顶栏 */
.topbar {
  height: 72px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 40px; height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, #3b5bfd, #6f8bff);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 14px rgba(59, 91, 253, .25);
}
.brand-mark svg { width: 22px; height: 22px; }

.brand h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.brand p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }

.topbar-actions { display: flex; align-items: center; gap: 16px; }

.engine-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-soft);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
}
.pulse-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 157, 104, .15);
  animation: pulse 2s infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(15, 157, 104, 0); } }

/* 主体 */
.main { max-width: 1180px; margin: 0 auto; padding: 28px 32px 64px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow);
}
.stat-icon { width: 42px; height: 42px; border-radius: 11px; display: flex; align-items: center; justify-content: center; }
.stat-icon svg { width: 20px; height: 20px; }
.icon-blue { background: var(--blue-soft); color: var(--primary); }
.icon-green { background: var(--green-soft); color: var(--green); }
.icon-gray { background: #f0f1f5; color: #64748b; }
.icon-amber { background: var(--amber-soft); color: var(--amber); }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; margin-top: 2px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px 24px;
  margin-bottom: 24px;
}

.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.muted { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.panel-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.search-input {
  height: 36px; width: 180px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0 12px;
  background: var(--surface-soft);
  outline: none;
  font-size: 13px;
}
.search-input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(59,91,253,.1); }

/* 按钮 */
.btn {
  height: 36px;
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 13px; font-weight: 600;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-soft); border-color: #d3d7e3; }
.btn-ghost { background: transparent; color: var(--text-soft); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-soft); color: var(--text); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.icon-btn {
  border: none; background: transparent; color: var(--muted);
  font-size: 24px; line-height: 1; width: 30px; height: 30px; border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-soft); color: var(--text); }

/* 商品卡片 */
.product-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }

.product-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.product-card:hover { border-color: #cfd5e6; box-shadow: 0 4px 14px rgba(20,28,60,.05); }
.product-card.disabled { opacity: .62; }

.product-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.product-name { font-size: 15px; font-weight: 700; margin: 0; line-height: 1.4; word-break: break-word; }
.product-url {
  display: block; font-size: 12px; color: var(--muted); margin-top: 4px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.product-url:hover { color: var(--primary); }

.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 999px;
  white-space: nowrap; flex: none;
}
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-in { background: var(--green-soft); color: var(--green); }
.status-out { background: #f0f1f5; color: #64748b; }
.status-unknown { background: var(--amber-soft); color: var(--amber); }
.status-error { background: var(--red-soft); color: var(--red); }

.product-reason {
  margin: 12px 0 0; font-size: 12px; color: var(--text-soft);
  background: var(--surface-soft); border-radius: 8px; padding: 8px 10px;
  min-height: 34px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

.product-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; font-size: 11px; color: var(--muted); }
.product-meta span { display: inline-flex; align-items: center; gap: 4px; }
.product-meta svg { width: 13px; height: 13px; }

.product-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.product-actions .btn { height: 30px; font-size: 12px; padding: 0 10px; }
.product-actions .spacer { flex: 1; }

.switch-row { display: inline-flex; align-items: center; gap: 9px; font-size: 12px; color: var(--text-soft); cursor: pointer; user-select: none; }
.switch-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch { width: 32px; height: 18px; border-radius: 999px; background: #cbd2e0; position: relative; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch-row input:checked + .switch { background: var(--primary); }
.switch-row input:checked + .switch::after { transform: translateX(14px); }

/* 空状态 */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-soft); }
.empty-illustration {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 20px;
  background: var(--blue-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
}
.empty-illustration svg { width: 34px; height: 34px; }
.empty-state h3 { margin: 0 0 6px; font-size: 16px; color: var(--text); }
.empty-state p { margin: 0 auto 20px; max-width: 380px; font-size: 13px; color: var(--muted); }

/* 记录 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.tab {
  border: none; background: transparent; padding: 8px 14px; font-size: 13px;
  color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.log-list { max-height: 320px; overflow-y: auto; }
.log-item { display: flex; align-items: flex-start; gap: 12px; padding: 11px 4px; border-bottom: 1px solid #f0f1f5; font-size: 12px; }
.log-item:last-child { border-bottom: none; }
.log-time { color: var(--muted); width: 130px; flex: none; font-variant-numeric: tabular-nums; }
.log-body { flex: 1; min-width: 0; }
.log-title { font-weight: 600; color: var(--text); }
.log-detail { color: var(--muted); margin-top: 2px; word-break: break-word; }
.log-empty { text-align: center; color: var(--muted); padding: 28px; font-size: 13px; }
.log-status { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; flex: none; }
.log-sent { background: var(--green-soft); color: var(--green); }
.log-failed { background: var(--red-soft); color: var(--red); }

/* 弹窗 */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 26, 45, .42);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px;
  max-height: 92vh; overflow-y: auto; box-shadow: 0 24px 60px rgba(15, 23, 42, .22);
}
.modal-wide { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 14px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal form { padding: 0 24px 22px; }

.form-row { margin-bottom: 16px; }
.form-row label, .form-row-grid label, .settings-section label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 6px;
}
.form-row input, .form-row-grid input, .settings-section input {
  width: 100%; height: 38px; border: 1px solid var(--border); border-radius: 9px;
  padding: 0 12px; outline: none; background: #fff; color: var(--text); font-size: 13px;
}
.form-row input:focus, .form-row-grid input:focus, .settings-section input:focus,
.select-input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,91,253,.1);
}
.select-input {
  width: 100%; height: 38px; border: 1px solid var(--border); border-radius: 9px;
  padding: 0 12px; outline: none; background: #fff; color: var(--text); font-size: 13px;
}
.form-row-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.hint { display: block; font-size: 11px; color: var(--muted); margin-top: 5px; }
.hint-inline { font-weight: 400; color: var(--muted); }
.required { color: var(--red); }
.modal .switch-row { margin: 4px 0 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 6px; }

.settings-section { border-bottom: 1px solid var(--border); padding-bottom: 18px; margin-bottom: 18px; }
.settings-section:last-of-type { border-bottom: none; }
.settings-section h4 { margin: 0 0 14px; font-size: 13px; color: var(--primary); }
.settings-section .switch-row { margin: 2px 0 12px; }
.test-mail-row { display: flex; gap: 10px; margin-top: 12px; }
.test-mail-row input { flex: 1; }

/* 提示 */
.toast-container { position: fixed; right: 24px; bottom: 24px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 240px; max-width: 380px; padding: 12px 16px; border-radius: 10px;
  background: #1f2739; color: #fff; font-size: 13px; box-shadow: 0 12px 30px rgba(0,0,0,.2);
  animation: slideIn .2s ease;
}
.toast.success { background: #107a53; }
.toast.error { background: #c23939; }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 860px) {
  .topbar { padding: 0 18px; }
  .main { padding: 20px 18px 48px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .product-grid { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; }
  .panel-tools { width: 100%; justify-content: flex-start; }
  .search-input { flex: 1; }
  .form-row-grid { grid-template-columns: 1fr; }
  .log-time { width: 100px; }
}
