:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e3e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); font-weight: normal; }
.right { text-align: right; }

/* ---------- 登录 ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 340px;
  box-shadow: 0 10px 30px rgba(0,0,0,.06);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-sub { color: var(--muted); margin: 0 0 20px; }
.login-card label { display: block; margin-bottom: 12px; font-weight: 600; }
.login-card input {
  width: 100%; margin-top: 6px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 12px 24px; position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #9ca3af; display: inline-block; }
.dot.idle { background: var(--ok); }
.dot.running { background: var(--primary); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.topbar-actions { display: flex; gap: 8px; }

.container { max-width: 1200px; margin: 20px auto; padding: 0 20px; }

/* ---------- 卡片 ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px;
}
.card-label { color: var(--muted); font-size: 12px; }
.card-value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.card-value.small { font-size: 14px; font-weight: 600; }

/* ---------- 面板 ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; margin-bottom: 16px;
}
.panel h2 { font-size: 16px; margin: 0 0 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.add-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.add-row input, .add-row select {
  flex: 1; min-width: 160px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
td.title { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* ---------- 分页 / 账号 ---------- */
.pager {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; font-size: 13px;
}
.account-box {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 14px; background: #fafbfe;
}
.account-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kv-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; margin: 0 2px; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 开关 ---------- */
.switch { position: relative; display: inline-block; width: 38px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; cursor: pointer; inset: 0; background: #cbd5e1;
  border-radius: 20px; transition: .2s;
}
.switch span:before {
  content: ""; position: absolute; height: 14px; width: 14px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span:before { transform: translateX(18px); }

/* ---------- 日志 ---------- */
.log-box {
  height: 320px; overflow-y: auto; background: #0f172a; color: #e2e8f0;
  border-radius: 8px; padding: 10px 12px; font-family: ui-monospace, Consolas, monospace;
  font-size: 12px; line-height: 1.6;
}
.log { white-space: pre-wrap; word-break: break-all; }
.log.warn { color: #fbbf24; }
.log.error { color: #f87171; }

/* ---------- 设置 ---------- */
.settings-form label { display: block; margin-bottom: 10px; font-weight: 600; font-size: 13px; }
.settings-form input {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}

/* ---------- 弹窗 ---------- */
/* hidden 属性必须压过 display:flex（否则弹窗会一直显示、无法关闭） */
.modal-backdrop[hidden] { display: none !important; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: #fff; border-radius: 12px; width: min(720px, 92vw);
  max-height: 86vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 14px 18px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }

.comment { border-bottom: 1px solid var(--border); padding: 10px 0; }
.comment:last-child { border-bottom: none; }
.comment-meta { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.comment-content { margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.badge { background: #eef2ff; color: var(--primary); border-radius: 6px; padding: 1px 7px; font-size: 11px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px;
  z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 80vw;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert.error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
