:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2433;
  --muted: #6b7486;
  --line: #e4e8ef;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eaf1ff;
  --good: #15803d;
  --good-soft: #e7f6ec;
  --bad: #c2410c;
  --bad-soft: #fdeee6;
  --warn: #b45309;
  --warn-soft: #fdf3e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  font-size: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.loc { color: var(--muted); }
.bad-text { color: var(--bad); }

h1, h2, h3 { margin: 0; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 16px; margin-bottom: 14px; }

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: #cbd2de; background: #f8f9fc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0, 0, 0, 0.04); }
.btn.block { width: 100%; height: 40px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.loading::after {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.link {
  border: 0;
  background: none;
  padding: 2px 4px;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--bad); }
.link:disabled { color: #b6bcc8; cursor: default; text-decoration: none; }

/* 表单 */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; margin-bottom: 12px; }
input[type=text], input:not([type]), input[type=password], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: #fff;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; }
label.check input { margin-top: 3px; }
.form-error { color: var(--bad); min-height: 1em; margin: 4px 0 8px; font-size: 13px; }

/* 登录 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand.small { margin: 0; gap: 10px; }
.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.brand.small .logo { width: 30px; height: 30px; border-radius: 8px; font-size: 12px; }
.brand p { margin: 2px 0 0; }

/* 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-actions { display: flex; gap: 4px; }

.container { max-width: 1180px; margin: 0 auto; padding: 20px 24px 48px; }

/* 状态卡片 */
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 2fr;
  gap: 14px;
  margin-bottom: 16px;
}
.stat {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.stat-value.good { color: var(--good); }
.stat-value.bad { color: var(--bad); }
.stat-value.warn { color: var(--warn); }
.stat-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

/* 卡片 */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-head p { margin: 4px 0 0; }
.card-head.inner { align-items: center; margin: 12px 0; }
.card-foot { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 12px; }
.card-foot .muted { margin-right: auto; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

details.card > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform 0.15s;
}
details.card[open] > summary::before { transform: rotate(90deg); }
details.card[open] > summary { margin-bottom: 12px; }

/* 表格 */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; min-width: 860px; }
.table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.row-active { background: #f5f9ff; }
.table tr.row-disabled td { opacity: 0.55; }
.table tr.row-disabled td.col-switch, .table tr.row-disabled td.col-ops { opacity: 1; }
.table tr.direct td { background: #fbfbfd; }
.table td.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.col-use { width: 92px; white-space: nowrap; }
.col-switch { width: 64px; }
.col-ops { width: 170px; white-space: nowrap; }
.ops { display: flex; flex-wrap: wrap; gap: 2px; }
.name { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tag {
  font-weight: 500;
  font-size: 11px;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 4px;
  padding: 0 6px;
}
.order { font-weight: 600; color: var(--muted); margin-right: 6px; }
.badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border-radius: 10px;
  padding: 1px 8px;
  vertical-align: middle;
}
.badge.warn { background: var(--warn); }

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.good-pill { color: var(--good); background: var(--good-soft); }
.bad-pill { color: var(--bad); background: var(--bad-soft); }
.muted-pill { color: var(--muted); background: #eef0f4; }

/* 开关 */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  background: #cdd3dd;
  cursor: pointer;
  transition: background 0.15s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary-soft); }

/* 策略 */
.mode-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 10px; }
.mode {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  cursor: pointer;
  font-weight: 400;
  margin: 0;
}
.mode:has(input:checked) { border-color: var(--primary); background: #f5f9ff; }
.mode input { margin-top: 3px; }
.mode strong { display: block; margin-bottom: 4px; }
.mode span { color: var(--muted); font-size: 13px; }

/* 弹窗 */
dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 20px 50px rgba(16, 24, 40, 0.25);
  width: min(560px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
.dialog { padding: 22px 24px; }
.dialog.narrow { max-width: 420px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.spacer { flex: 1; }
.formats {
  background: #f6f7fa;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  margin: 6px 0 12px;
  white-space: pre-wrap;
}
.test-result {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #f6f7fa;
  font-size: 13px;
}
.test-result.ok { background: var(--good-soft); color: var(--good); }
.test-result.ok strong { color: var(--text); }
.test-result.fail { background: var(--bad-soft); color: var(--bad); }
#import-error div { font-size: 13px; }

/* 提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  max-width: min(640px, calc(100vw - 32px));
  padding: 10px 18px;
  border-radius: 10px;
  color: #fff;
  background: #1f2937;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  z-index: 50;
}
.toast.ok { background: #166534; }
.toast.error { background: #b91c1c; }
.toast.warn { background: #92400e; }

@media (max-width: 760px) {
  .topbar { padding: 10px 14px; }
  .container { padding: 14px 12px 40px; }
  .status-grid { grid-template-columns: 1fr 1fr; }
  .stat.wide { grid-column: 1 / -1; }
  .mode-options, .grid2 { grid-template-columns: 1fr; }
  .card { padding: 16px 14px; }
}
