:root {
  --bg: #f0f4fb;
  --card: #ffffff;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --ok: #059669;
  --err: #dc2626;
  --warn: #d97706;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.12);
  --radius: 14px;
  --input-h: 46px;
  --topbar-h: 58px;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: linear-gradient(180deg, #e8eefc 0%, var(--bg) 220px);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, video { max-width: 100%; height: auto; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #0b1b3a;
  color: #fff;
  min-height: var(--topbar-h);
  padding: 10px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
}
.topbar .brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(52vw, 360px);
}
.topbar-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 4px 6px;
}
.topbar-nav a {
  color: #dbe7ff;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
}
.topbar-nav a:hover {
  color: #fff;
  background: rgba(255,255,255,.08);
  text-decoration: none;
}
.nav-toggle {
  display: none;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.08);
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}
@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; align-items: center; }
  .topbar-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #0f274f;
    flex-direction: column;
    align-items: stretch;
    padding: 10px;
    gap: 4px;
    box-shadow: 0 12px 24px rgba(0,0,0,.2);
  }
  .topbar-nav.open { display: flex; }
  .topbar-nav a {
    padding: 12px 14px;
    border-radius: 10px;
  }
  .topbar { position: relative; flex-wrap: wrap; }
}

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 16px 48px;
}
.container.wide,
.container:has(.admin-layout) {
  max-width: 1320px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h2, .card h3 { margin: 0 0 12px; }
.card h2 { font-size: 1.25rem; }
.card h3 { font-size: 1.05rem; color: #111827; }

.muted { color: var(--muted); font-size: 13px; line-height: 1.6; }
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
}
@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 16px; border-radius: 12px; }
  .container { margin-top: 14px; padding-left: 12px; padding-right: 12px; }
}

/* ---------- Forms ---------- */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 7px;
  color: #334155;
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="file"],
input[type="search"],
input[type="tel"],
input[type="url"],
select,
textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14px;
  line-height: 1.4;
  background: #fff;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="search"],
input[type="tel"],
input[type="url"],
select {
  min-height: var(--input-h);
}
textarea {
  min-height: 96px;
  resize: vertical;
}
input:hover, select:hover, textarea:hover {
  border-color: #cbd5e1;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  background: #fff;
}
input::placeholder, textarea::placeholder {
  color: #94a3b8;
}
input[type="file"] {
  padding: 10px 12px;
  background: #f8fafc;
  min-height: auto;
}
input[type="checkbox"], input[type="radio"] {
  width: auto;
  min-height: auto;
  accent-color: var(--primary);
}
.field { margin-bottom: 14px; }
.field-hint { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* 带图标的输入框 */
.input-shell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--input-h);
  padding: 0 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.input-shell:hover { border-color: #cbd5e1; background: #fff; }
.input-shell:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  background: #fff;
}
.input-shell .ico {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: #64748b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.input-shell:focus-within .ico { color: var(--primary); }
.input-shell input,
.input-shell input[type="text"],
.input-shell input[type="email"],
.input-shell input[type="password"],
.input-shell input[type="number"] {
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
  padding: 10px 0 !important;
  min-height: 44px;
  border-radius: 0;
  width: 100%;
}
.input-shell .shell-action {
  flex-shrink: 0;
}

/* 验证码行 */
.code-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.code-row .input-shell,
.code-row > input {
  flex: 1;
  min-width: 0;
}
.code-row .btn {
  white-space: nowrap;
  flex-shrink: 0;
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--input-h);
}
@media (max-width: 480px) {
  .code-row { flex-direction: column; }
  .code-row .btn { width: 100%; }
}

.row-inline {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.row-inline label.chk,
label.chk {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  margin: 0;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 11px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  transition: background .15s, transform .05s;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .65; cursor: not-allowed; }
.btn.secondary { background: #e8eefc; color: #1e3a8a; }
.btn.secondary:hover { background: #dbe6ff; color: #1e3a8a; }
.btn.danger { background: #fee2e2; color: #991b1b; }
.btn.danger:hover { background: #fecaca; color: #7f1d1d; }
.btn.ghost { background: transparent; color: var(--primary); border: 1px solid #bfdbfe; }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn-lg { min-height: 48px; font-size: 15px; border-radius: 12px; }

.flash-wrap { margin-bottom: 14px; }
.flash {
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 14px;
}
.flash.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ---------- Tables ---------- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.table-scroll table { margin: 0; border: none; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  border-bottom: 1px solid var(--border);
  padding: 10px 10px;
  text-align: left;
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-weight: 600;
  background: #f8fafc;
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
@media (max-width: 700px) {
  th, td { padding: 8px 6px; font-size: 12px; }
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.done { background: #d1fae5; color: #065f46; }
.badge.failed { background: #fee2e2; color: #991b1b; }
.badge.running { background: #ffedd5; color: #9a3412; }
.badge.pending { background: #e5e7eb; color: #374151; }

/* ---------- Auth pages ---------- */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 14px;
  background:
    radial-gradient(ellipse 80% 60% at 10% 0%, rgba(37,99,235,.18), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 100%, rgba(14,165,233,.12), transparent 50%),
    linear-gradient(160deg, #eef2ff 0%, #f8fafc 45%, #eef6ff 100%);
}
.login-stack {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card,
.auth-card {
  width: 100%;
  background: rgba(255,255,255,.96);
  border-radius: 20px;
  padding: 32px 28px 28px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(226,232,240,.9);
  backdrop-filter: blur(8px);
}
.login-card h1,
.auth-card h1 {
  margin: 0 0 6px;
  font-size: 1.45rem;
  letter-spacing: -.02em;
}
.auth-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #1d4ed8;
  background: var(--primary-soft);
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 4px 10px;
  margin-bottom: 12px;
}
.auth-subtitle {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
}
.auth-footer {
  margin-top: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.auth-section-label {
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 4px 0 12px;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
}
.auth-section-label:first-of-type {
  border-top: none;
  padding-top: 0;
}
.login-notice {
  width: 100%;
  background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 100%);
  border: 1px solid #bfdbfe;
  border-left: 4px solid var(--primary);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.login-notice-title {
  font-weight: 700;
  font-size: 15px;
  color: #1e3a8a;
  margin-bottom: 8px;
}
.login-notice-body {
  font-size: 13px;
  line-height: 1.7;
  color: #334155;
  white-space: pre-wrap;
  word-break: break-word;
}
@media (max-width: 480px) {
  .login-card, .auth-card { padding: 24px 18px 20px; border-radius: 16px; }
  .login-card h1, .auth-card h1 { font-size: 1.25rem; }
}

/* ---------- Dashboard bits ---------- */
.stat-box {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 12px 0 4px;
}
.stat {
  background: #f8faff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.stat .n { font-size: 20px; font-weight: 700; color: #0f3fba; }
.stat .t { font-size: 12px; color: var(--muted); margin-top: 4px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; }
.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 10px 0 18px;
}
.step {
  background: #f8faff;
  border: 1px dashed #c7d2fe;
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
}
.step b { display: block; margin-bottom: 4px; color: #1e3a8a; }
@media (max-width: 800px) {
  .steps, .stat-box { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .steps, .stat-box { grid-template-columns: 1fr; }
}

/* ---------- Admin layout ---------- */
.admin-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.admin-sidebar {
  position: sticky;
  top: calc(var(--topbar-h) + 14px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 12px;
  max-height: calc(100vh - var(--topbar-h) - 28px);
  overflow-y: auto;
}
.admin-sidebar .side-title {
  font-size: 12px;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 4px 10px 10px;
}
.admin-sidebar a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #334155;
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 2px;
}
.admin-sidebar a:hover {
  background: var(--primary-soft);
  color: #1d4ed8;
  text-decoration: none;
}
.admin-sidebar a.active {
  background: linear-gradient(90deg, #dbeafe, #eff6ff);
  color: #1d4ed8;
  box-shadow: inset 3px 0 0 var(--primary);
}
.admin-main { min-width: 0; }
.admin-main > .card:target,
.admin-section:target {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}
.admin-hero {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.admin-hero h2 { margin-bottom: 4px; }
.admin-mobile-nav {
  display: none;
  margin-bottom: 14px;
}
.admin-mobile-nav select {
  width: 100%;
  font-weight: 600;
}
.batch-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: #f8faff;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.ops-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.ops-inline input[type="text"] {
  width: 100px;
  min-height: 34px;
  padding: 6px 8px;
  font-size: 12px;
  display: inline-block;
}
.form-panel {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}
.form-panel h4 {
  margin: 0 0 12px;
  font-size: 14px;
  color: #1e3a8a;
}
.smtp-grid {
  display: grid;
  grid-template-columns: 1.4fr 0.6fr;
  gap: 14px;
}
@media (max-width: 700px) {
  .smtp-grid { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar {
    display: none;
  }
  .admin-mobile-nav { display: block; }
}

/* AI pool */
.ai-batch-bar {
  gap: 8px;
  margin-bottom: 10px;
  padding: 10px 12px;
  background: #f8faff;
  border: 1px solid var(--border);
  border-radius: 10px;
  flex-wrap: wrap;
}
.ai-edit-table input[type="text"],
.ai-edit-table input[type="number"] {
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 8px;
  min-width: 0;
  min-height: 34px;
}
.ai-edit-table .inp-sm { width: 64px; }
.ai-edit-table .inp-md { width: 140px; min-width: 100px; }
.ai-edit-table .inp-lg { width: 100%; min-width: 160px; }
.ai-edit-table tr.row-warn { background: #fff7ed; }
.ai-edit-table tr.row-muted { background: #f9fafb; opacity: 0.92; }
.ai-edit-table .err-cell { max-width: 160px; color: var(--err); font-size: 11px; }
code {
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* ---------- 项目勾选确认 ---------- */
.project-pick {
  border: 1px solid #bfdbfe;
  background: #f8fbff;
  border-radius: 10px;
  padding: 10px 12px;
}
.project-pick-hd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 8px;
  font-size: 13px;
}
.project-pick-actions { margin-left: auto; display: flex; gap: 10px; }
.btn-link {
  border: none;
  background: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  text-decoration: underline;
}
.project-pick-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}
.project-pick-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  line-height: 1.4;
  padding: 6px 8px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  cursor: pointer;
}
.project-pick-item:hover { border-color: #93c5fd; }
.project-pick-item input { margin-top: 3px; }
.project-pick-code {
  font-weight: 700;
  color: #1e3a8a;
  white-space: nowrap;
}
.project-pick-name { flex: 1; min-width: 0; word-break: break-all; }

/* ---------- 全站水印（清晰可读，不挡操作） ---------- */
.site-watermark {
  position: fixed;
  inset: 0;
  z-index: 9990;
  pointer-events: none;
  overflow: hidden;
  user-select: none;
}
.site-watermark-inner {
  position: absolute;
  left: -20%;
  top: -20%;
  width: 140%;
  height: 140%;
  display: flex;
  flex-wrap: wrap;
  align-content: space-around;
  justify-content: space-around;
  gap: 48px 36px;
  transform: rotate(-28deg);
  opacity: 0.14;
}
.site-watermark-inner span {
  flex: 0 0 auto;
  color: #0f172a;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  line-height: 1.4;
  text-shadow: 0 0 1px rgba(15, 23, 42, 0.15);
}
/* 登录等深色页略提亮可读性 */
body.auth-page .site-watermark-inner {
  opacity: 0.18;
}
body.auth-page .site-watermark-inner span {
  color: #e2e8f0;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.35);
}
@media (max-width: 640px) {
  .site-watermark-inner span {
    font-size: 13px;
  }
  .site-watermark-inner {
    gap: 36px 20px;
    opacity: 0.16;
  }
}

/* Utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.text-ok { color: var(--ok); font-weight: 600; }
.text-warn { color: var(--warn); }
.text-err { color: var(--err); }
