:root {
  --bg: #f5f6f8;
  --card: #fff;
  --line: #e3e6ea;
  --text: #1f2328;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* 必须放在所有布局规则之前：作者样式里的 display 会盖掉浏览器默认的 [hidden]{display:none}，
   导致 hidden=true 的元素依然占位显示（登录卡片就踩过这个坑） */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); margin: 10px 0 0; }

code {
  background: #eceff3;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* ---------- 登录 ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-card {
  width: 380px;
  max-width: 92vw;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, .06);
}

.login-card p { margin: 0; }

/* ---------- 滑块拼图验证码 ---------- */

.captcha { display: flex; flex-direction: column; gap: 8px; }

.captcha-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: #eef1f4;
  border: 1px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.captcha-bg { display: block; width: 100%; height: 100%; }

.captcha-piece {
  position: absolute;
  left: 0;
  top: 0;
  will-change: left;
  pointer-events: none;
}

.captcha-refresh {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.captcha-refresh:hover { background: rgba(0, 0, 0, .68); }

.captcha-badge {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(22, 163, 74, .85);
  color: #fff;
  font-size: 15px;
  letter-spacing: 1px;
}

.captcha-track {
  position: relative;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #eceff3;
  overflow: hidden;
}

.captcha-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0;
  background: rgba(37, 99, 235, .18);
}

.captcha-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

.captcha-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: 48px;
  height: 100%;
  display: grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 18px;
  cursor: grab;
  touch-action: none;
}

.captcha-handle:active { cursor: grabbing; }

.captcha.solved .captcha-handle { cursor: default; }

.captcha.solved .captcha-refresh { display: none; }

.captcha.shake { animation: captcha-shake .32s; }

@keyframes captcha-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ---------- 布局 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.hint, .toolbar {
  margin: 16px 24px;
}

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

.ads {
  width: calc(100% - 48px);
  margin: 0 24px 32px;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.ads th, .ads td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.ads th { background: #fafbfc; font-weight: 600; color: var(--muted); font-size: 13px; }
.ads tr:last-child td { border-bottom: none; }
.ads img { width: 132px; height: 74px; object-fit: cover; border-radius: 6px; background: #eef1f4; display: block; }

.empty {
  margin: 0 24px 32px;
  padding: 40px;
  text-align: center;
  color: var(--muted);
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 18px;
}
.badge.on { background: #e7f6ec; color: var(--ok); }
.badge.off { background: #f1f2f4; color: var(--muted); }
.badge.wait { background: #fff5e5; color: #b45309; }

.ops { display: flex; gap: 6px; }
.ops button { padding: 4px 9px; font-size: 13px; white-space: nowrap; }

/* ---------- 表单控件 ---------- */

label { display: block; font-size: 13px; color: var(--muted); }

label.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"], input:not([type]) {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--text);
}

label.inline-check input, input[type="checkbox"] { width: auto; margin: 0; }

input:focus { outline: 2px solid rgba(37, 99, 235, .35); border-color: var(--primary); }

button {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  background: #eceff3;
  color: var(--text);
}

button.primary { background: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.ghost { background: #fff; border-color: var(--line); }
button.ghost:hover { background: #f3f4f6; }
button[disabled] { opacity: .55; cursor: not-allowed; }
button.danger { color: var(--danger); background: #fdecec; }

/* ---------- 弹窗 ---------- */

dialog {
  border: none;
  border-radius: 12px;
  padding: 24px;
  width: min(880px, 92vw);
  box-shadow: 0 20px 50px rgba(15, 23, 42, .18);
}

dialog::backdrop { background: rgba(15, 23, 42, .45); }

.editor-grid { display: grid; grid-template-columns: 300px 1fr; gap: 24px; }

.editor-preview img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #eef1f4;
}

.editor-preview img:not([src]) { display: none; }

.editor-fields { display: flex; flex-direction: column; gap: 12px; }
.editor-fields .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.file { display: block; margin-top: 10px; }
.file input { display: none; }
.file span {
  display: block;
  text-align: center;
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  background: #fff;
  color: var(--text);
}
.file span:hover { border-color: var(--primary); color: var(--primary); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- 提示条 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: #1f2328;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  z-index: 99;
}
.toast.err { background: var(--danger); }

@media (max-width: 760px) {
  .editor-grid { grid-template-columns: 1fr; }
  .ads { display: block; overflow-x: auto; }
}
