:root {
  --bg: #f4f5f1;
  --panel: #ffffff;
  --ink: #171a17;
  --text: #343832;
  --muted: #8a8f86;
  --line: #e7e9e3;
  --soft: #f7f8f5;
  --accent: #c8f169;
  --accent-dark: #5e7d23;
  --accent-soft: #f1f9df;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 35px rgba(28, 35, 24, .045);
  --shadow-card: 0 6px 20px rgba(28, 35, 24, .05);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
img { display: block; width: 100%; }
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.hidden { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(148, 196, 59, .35); outline-offset: 2px; }

/* ============ 通用按钮 ============ */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 42px; padding: 0 18px;
  color: #f9fbf5; background: var(--ink);
  border-radius: 11px; font-size: 12px; font-weight: 650;
  box-shadow: 0 6px 15px rgba(28, 34, 24, .12); transition: .18s;
}
.btn-primary:hover { background: #2c3327; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .6; cursor: progress; transform: none; }
.btn-primary.sm { height: 34px; padding: 0 13px; font-size: 11px; border-radius: 9px; }
.btn-primary svg { width: 15px; height: 15px; }
.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  height: 33px; padding: 0 13px;
  color: #5d6357; background: #fff; border: 1px solid var(--line); border-radius: 9px; font-size: 11px; font-weight: 550;
  transition: .18s;
}
.btn-ghost:hover { color: var(--ink); border-color: #cfd4cb; }
.btn-ghost svg { width: 14px; height: 14px; }
.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center;
  color: #93998f; background: var(--soft); border: 1px solid var(--line); border-radius: 9px; transition: .18s;
}
.icon-btn:hover { color: var(--ink); background: #eef0ea; }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
.icon-btn svg { width: 15px; height: 15px; }

.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], select {
  height: 36px; padding: 0 11px;
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  font-size: 12px; color: var(--text); transition: .15s; min-width: 0;
}
input:focus, select:focus { border-color: #a9c46f; background: #fcfef8; }
input::placeholder { color: #b3b8ae; }
.chk, .filepick { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: #6c7268; white-space: nowrap; cursor: pointer; }
.chk input { width: 15px; height: 15px; accent-color: var(--accent-dark); }
.filepick { padding: 0 11px; height: 34px; background: var(--soft); border: 1px dashed #cdd2c8; border-radius: 9px; }
.filepick input { display: none; }

/* ============ 登录 / 无权限 ============ */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(200, 241, 105, .18), transparent 60%),
    var(--bg);
}
.auth-card {
  width: min(380px, 100%); padding: 34px 30px 30px; text-align: center;
  background: var(--panel); border: 1px solid rgba(226, 229, 221, .85);
  border-radius: 20px; box-shadow: var(--shadow);
}
.auth-brand { display: inline-flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-mark {
  width: 37px; height: 37px; display: grid; place-items: center; flex: 0 0 auto;
  background: var(--ink); color: var(--accent); border-radius: 11px; transform: rotate(-3deg);
}
.brand-mark.small { width: 30px; height: 30px; border-radius: 9px; }
.brand-mark svg { width: 21px; height: 21px; stroke-width: 1.6; }
.brand-mark.small svg { width: 17px; height: 17px; }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: 2px; line-height: 1.05; text-align: left; }
.brand-name > span { display: block; margin-top: 4px; color: #7b8077; font-size: 8px; font-weight: 700; letter-spacing: 3.5px; }
.auth-eyebrow { margin-bottom: 7px; color: #95a083; font-size: 9px; font-weight: 700; letter-spacing: 2.5px; }
.auth-card h1 { margin: 0 0 8px; font-size: 23px; font-weight: 750; letter-spacing: -.4px; }
.auth-sub { margin: 0 0 22px; color: #8d9388; font-size: 11px; line-height: 1.7; }
.auth-form { display: flex; flex-direction: column; gap: 13px; text-align: left; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 11px; font-weight: 600; color: #515749; }
.auth-form input { height: 42px; border-radius: 11px; }
.auth-form .btn-primary { margin-top: 4px; width: 100%; }
.auth-back { display: inline-flex; align-items: center; gap: 5px; margin-top: 20px; color: #7f8678; font-size: 11px; }
.auth-back:hover { color: var(--ink); }
.auth-back svg { width: 14px; height: 14px; }
.auth-denied { padding-top: 38px; }
.denied-icon { width: 56px; height: 56px; margin: 0 auto 18px; display: grid; place-items: center; color: #35421f; background: var(--accent); border-radius: 16px; }
.denied-icon svg { width: 27px; height: 27px; }

/* ============ 后台布局 ============ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: 64px; padding: 0 30px; display: flex; align-items: center; justify-content: space-between;
  background: rgba(251, 252, 249, .82); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px);
}
.topbar-left { display: flex; align-items: center; gap: 11px; }
.topbar-left strong { font-size: 16px; font-weight: 750; letter-spacing: .3px; }
.top-back { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; color: #7f8678; font-size: 11px; }
.top-back:hover { color: var(--ink); }
.top-back svg { width: 13px; height: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 11px; }
.admin-email { font-size: 11px; color: #6c7268; background: var(--soft); border: 1px solid var(--line); padding: 6px 11px; border-radius: 9px; }

.admin-content { max-width: 1280px; margin: 0 auto; padding: 26px 30px 50px; }
.block { background: var(--panel); border: 1px solid rgba(226, 229, 221, .85); border-radius: var(--radius); box-shadow: var(--shadow-card); padding: 20px 22px; margin-bottom: 18px; }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.block-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.block-sub { display: block; margin-top: 3px; color: #9aa093; font-size: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ============ 统计卡片 ============ */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat-card {
  position: relative; overflow: hidden;
  padding: 16px 16px 15px; background: var(--soft); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.stat-card.wide { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }
.stat-card.wide strong { font-size: 16px; }
.stat-card strong { display: block; font-size: 24px; font-weight: 750; letter-spacing: -.5px; line-height: 1.1; }
.stat-card span { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.stat-ico { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; margin-bottom: 11px; }
.wide .stat-ico { margin-bottom: 0; flex: 0 0 auto; }
.stat-ico svg { width: 16px; height: 16px; }
.s-users { color: #3f4c31; background: #e9f1da; }
.s-tasks { color: #2f5a63; background: #dceef1; }
.s-ok { color: #2f6b3a; background: #def0e1; }
.s-fail { color: #8a3b3b; background: #f6e2e2; }
.s-queue { color: #7a5a1f; background: #f6ecd6; }
.s-credit { color: #5e7d23; background: var(--accent-soft); }
.s-chip { color: #4a4a2f; background: #ecefdb; }

/* ============ 新增表单 ============ */
.add-form { padding: 13px; margin-bottom: 14px; background: var(--soft); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.add-row + .add-row { margin-top: 9px; }
.add-row input, .add-row select { flex: 1 1 120px; min-width: 0; }
.add-row .chk, .add-row .filepick { flex: 0 0 auto; }

/* ============ Provider 列表 ============ */
.provider-list { display: flex; flex-direction: column; gap: 10px; }
.provider-card { padding: 13px 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.provider-top { display: flex; align-items: center; gap: 9px; margin-bottom: 11px; }
.provider-name { font-size: 13px; font-weight: 700; }
.provider-tag { padding: 2px 8px; font-size: 9px; font-weight: 600; color: #4f6430; background: var(--accent-soft); border-radius: 20px; }
.pill-active { margin-left: auto; padding: 3px 9px; font-size: 9px; font-weight: 600; border-radius: 20px; }
.pill-active.on { color: #2f6b3a; background: #def0e1; }
.pill-active.off { color: #93998f; background: #eef0ea; }
.provider-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.provider-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 9px; color: #8d9388; font-weight: 600; }
.provider-fields input { width: 100%; }
.provider-key { margin: 9px 0 4px; font-size: 10px; color: #93998f; }
.provider-key b { color: #6c7268; font-weight: 600; }
.provider-actions { display: flex; gap: 8px; margin-top: 11px; }

/* ============ 模板列表 ============ */
.template-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; }
.template-card { padding: 11px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.template-thumb { height: 110px; overflow: hidden; background: #ebece7; border-radius: 9px; margin-bottom: 10px; }
.template-thumb img { height: 100%; object-fit: cover; object-position: center 30%; }
.template-thumb.empty { display: grid; place-items: center; color: #b3b8ae; }
.template-thumb.empty svg { width: 26px; height: 26px; }
.template-name { width: 100%; height: 32px; font-weight: 600; font-size: 12px; margin-bottom: 8px; }
.template-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 9px; }
.template-meta input { flex: 1; }
.template-foot { display: flex; align-items: center; gap: 10px; }
.switch { width: 36px; height: 20px; padding: 2px; flex: 0 0 auto; background: #dfe3db; border-radius: 20px; transition: .2s; }
.switch i { display: block; width: 16px; height: 16px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.12); transition: .2s; }
.switch.on { background: #8ba452; }
.switch.on i { transform: translateX(16px); }
.switch-label { font-size: 10px; color: #6c7268; }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.admin-table th { text-align: left; padding: 9px 10px; color: #9aa093; font-size: 10px; font-weight: 700; border-bottom: 1px solid var(--line); white-space: nowrap; }
.admin-table td { padding: 10px; border-bottom: 1px solid #f0f1ec; color: var(--text); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tr:hover td { background: #fafbf7; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 10px; font-weight: 600; }
.tag-ok { color: #2f6b3a; background: #def0e1; }
.tag-fail { color: #8a3b3b; background: #f6e2e2; }
.tag-wait { color: #7a5a1f; background: #f6ecd6; }
.tag-run { color: #2f5a63; background: #dceef1; }
.tag-mute { color: #8a8f86; background: #eef0ea; }
.role-tag { padding: 2px 8px; border-radius: 6px; font-size: 10px; font-weight: 600; background: #eef0ea; color: #6c7268; }
.role-tag.admin { background: var(--accent-soft); color: #5e7d23; }
.cell-err { max-width: 200px; color: #b15a5a; font-size: 11px; }
.cell-img { display: inline-flex; align-items: center; gap: 7px; }
.cell-img img { width: 40px; height: 46px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.cell-img a { color: #5e7d23; font-weight: 600; font-size: 11px; }
.user-adjust { display: flex; gap: 6px; align-items: center; }
.user-adjust input { width: 64px; }
.user-adjust .note-i { width: 90px; }
.mini-btn { height: 30px; padding: 0 10px; font-size: 11px; border-radius: 8px; background: var(--ink); color: #f9fbf5; font-weight: 600; white-space: nowrap; }
.mini-btn:hover { background: #2c3327; }
.mini-btn:disabled { opacity: .5; cursor: not-allowed; }
.mini-btn.approve { background: var(--accent); color: #283317; }
.mini-btn.approve:hover { background: #bdec55; }

/* ============ Toast ============ */
.toast {
  position: fixed; z-index: 100; left: 50%; bottom: 30px; min-width: 230px; max-width: calc(100vw - 30px);
  padding: 12px 17px; display: flex; align-items: center; gap: 10px;
  color: #f7faf2; background: rgba(28, 33, 25, .94); border: 1px solid rgba(255,255,255,.09);
  border-radius: 11px; box-shadow: 0 12px 35px rgba(0,0,0,.18);
  opacity: 0; pointer-events: none; transform: translate(-50%, 15px); transition: .25s; backdrop-filter: blur(10px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast > span { width: 22px; height: 22px; display: grid; place-items: center; flex: 0 0 auto; color: #283317; background: var(--accent); border-radius: 50%; }
.toast svg { width: 12px; height: 12px; stroke-width: 2.3; }
.toast.err > span { background: #f0a3a3; color: #5a1f1f; }
.toast p { margin: 0; font-size: 11px; }

/* ============ 确认弹窗 ============ */
.modal-backdrop { position: fixed; inset: 0; z-index: 80; padding: 24px; display: grid; place-items: center; background: rgba(17, 21, 15, .6); backdrop-filter: blur(8px); animation: fadeIn .2s; }
.dialog { width: min(420px, 100%); padding: 30px; background: #fbfcf9; border-radius: 20px; box-shadow: 0 25px 80px rgba(0,0,0,.25); text-align: center; }
.dialog-icon { width: 42px; height: 42px; margin: 0 auto 13px; display: grid; place-items: center; color: #35421f; background: var(--accent); border-radius: 12px; }
.dialog-icon svg { width: 21px; height: 21px; }
.confirm-dialog h2 { margin: 0; font-size: 19px; letter-spacing: -.3px; }
.dialog-desc { margin: 9px 0 22px; color: #8e9587; font-size: 12px; line-height: 1.7; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn-ghost, .confirm-actions .btn-primary { flex: 1; height: 40px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ============ 窄屏适配 ============ */
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .topbar { padding: 0 16px; }
  .topbar-left strong { font-size: 15px; }
  .admin-email { display: none; }
  .admin-content { padding: 20px 16px 40px; }
  .block { padding: 16px 14px; border-radius: 16px; }
  .stat-grid { grid-template-columns: 1fr; }
  .stat-card.wide { grid-column: auto; }
  .template-list { grid-template-columns: 1fr; }
  .provider-fields { grid-template-columns: 1fr; }
  .add-row input, .add-row select { flex: 1 1 100%; }
}
@media (max-width: 520px) {
  .top-back span, .top-back { font-size: 10px; }
  .user-adjust { flex-wrap: wrap; }
  .admin-table th, .admin-table td { padding: 8px 7px; }
}
