:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2330;
  --muted: #677285;
  --accent: #2459d6;
  --accent-text: #ffffff;
  --ok: #17803d;
  --ok-bg: #e3f4e8;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #232834;
    --border: #2f3542;
    --text: #e5e8ee;
    --muted: #949cad;
    --accent: #5b8cff;
    --accent-text: #0d1220;
    --ok: #5fd08a;
    --ok-bg: #173323;
    --bad: #ff8a80;
    --bad-bg: #3a1c1a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

[hidden] { display: none !important; }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; margin: 0; }

input, select, button, .button {
  font: inherit;
  color: inherit;
  border-radius: 6px;
}

input[type=text], input[type=search], input[type=password], input[type=number], input:not([type]), select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  min-width: 0;
}

input:focus-visible, select:focus-visible, button:focus-visible, .button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--surface-2); }
button:disabled { opacity: 0.55; cursor: progress; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover, .button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.ghost { background: transparent; }
button.small { height: 28px; padding: 0 9px; font-size: 13px; }

label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
label input { color: var(--text); font-size: 14px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin: 10px 0; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.error { color: var(--bad); min-height: 1.5em; margin: 0; }
.offscreen { position: fixed; left: -9999px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card.empty { color: var(--muted); text-align: center; }

/* 登录 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 600; font-size: 15px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button { border: none; background: transparent; color: var(--muted); }
.tabs button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }

/* 统计 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 22px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat-value.ok { color: var(--ok); }
.stat-value.bad { color: var(--bad); }

/* 表单与工具栏 */
.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.inline-form label { width: 120px; }
.inline-form label.grow { flex: 1; min-width: 200px; }
.stack { display: flex; flex-direction: column; gap: 12px; max-width: 360px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { width: 260px; max-width: 100%; }
.toolbar .spacer { flex: 1; }

/* 表格 */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
th { background: var(--surface-2); color: var(--muted); font-weight: 500; font-size: 13px; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tr.disabled td { color: var(--muted); }
td.remark { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
td.empty { text-align: center; color: var(--muted); padding: 28px; }
td.actions { display: flex; gap: 6px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; }
.badge.on { background: var(--ok-bg); color: var(--ok); }
.badge.off { background: var(--surface-2); color: var(--muted); }
.test { font-size: 12px; margin-top: 3px; }
.test.ok { color: var(--ok); }
.test.bad { color: var(--bad); white-space: normal; max-width: 220px; }

/* 订阅 */
.pick-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.pick { flex-direction: row; align-items: center; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--border); color: var(--text); font-size: 14px; cursor: pointer; }
.pick:last-child { border-bottom: none; }
.pick:hover { background: var(--surface-2); }
.pick.disabled { color: var(--muted); }
.pick-id { width: 48px; color: var(--muted); }
.pick-remark { min-width: 80px; }
.pick-ip { color: var(--muted); }
.sub-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.sub-url input { width: 100%; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }

/* 设置 */
.info { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0 0 16px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; word-break: break-all; }

/* 提示条 */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
  z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--bad); color: #fff; }

@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .brand { display: none; }
  main { padding: 16px; }
  .info { grid-template-columns: 1fr; gap: 2px; }
  .info dd { margin-bottom: 8px; }
  .toolbar .spacer { display: none; }
}
