:root {
  --bg: #f4f6fa; --card: #ffffff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #0284c7; --on: #16a34a; --idle: #d97706; --off: #94a3b8; --bad: #dc2626;
  --chip: #e8edf4; --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --card: #131c31; --text: #e5eaf3; --muted: #8a97ad; --line: #243049;
    --accent: #38bdf8; --on: #4ade80; --idle: #fbbf24; --off: #64748b; --bad: #f87171;
    --chip: #1b2742; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
body.noscroll { overflow: hidden; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
h1 { font-size: 19px; margin: 0; }
.muted { color: var(--muted); }
.small-text { font-size: 12.5px; }
.err { color: var(--bad); margin: 8px 0 0; }
button, input, select { font: inherit; color: inherit; }

/* 通用 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.btn { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }
.btn:active { opacity: .7; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
input[type=text], input[type=password], input:not([type]), input[type=search], select {
  width: 100%; min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}

/* 登录 */
#login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; padding: 24px; }
.login-card label { display: block; margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.login-card input { margin-top: 6px; color: var(--text); }
.login-card .btn { width: 100%; margin-top: 20px; }

/* 顶栏 */
.top { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 6px; }
.title { display: flex; align-items: center; gap: 10px; }
.top-r { display: flex; align-items: center; gap: 10px; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--off); }
.conn.ok { background: var(--on); box-shadow: 0 0 0 4px rgba(74, 222, 128, .2); }
.banner { margin: 6px 16px; padding: 10px 12px; border-radius: 10px; background: rgba(217, 119, 6, .14); color: var(--idle); font-size: 13.5px; }
.banner.bad { background: rgba(220, 38, 38, .12); color: var(--bad); }
.summary { padding: 4px 16px 12px; }
.big { font-size: 34px; font-weight: 700; line-height: 1; white-space: nowrap; }
.big small { font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.summary .small-text { margin-top: 6px; }
.proxy-node { margin-top: 6px; font-size: 14px; font-weight: 600; color: var(--accent); }

/* 标签页 / 筛选 */
.tabs { display: flex; gap: 6px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.filters { padding: 12px 16px 0; display: grid; gap: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; }
.chips button { border: 0; background: var(--chip); color: var(--text); padding: 7px 14px; border-radius: 999px; white-space: nowrap; cursor: pointer; }
.chips button.on { background: var(--accent); color: #fff; }

/* 设备列表 */
.list { padding: 12px 16px 40px; display: grid; gap: 10px; }
.dev { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; }
.dev:active { opacity: .75; }
.dev.off .name { color: var(--muted); }
.dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--off); }
.dot.on { background: var(--on); }
.dot.idle { background: var(--idle); }
.dot.bad { background: var(--bad); }
.dev .main { flex: 1; min-width: 0; }
.name { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.name .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; word-break: keep-all; overflow-wrap: anywhere; }
.rate { text-align: right; font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tag { font-size: 11px; font-weight: 500; padding: 1px 7px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.tag.bad { background: rgba(220, 38, 38, .14); color: var(--bad); }
.tag.acc { background: rgba(2, 132, 199, .14); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.logrow { display: flex; gap: 12px; padding: 10px 14px; align-items: baseline; }
.logrow time { flex: none; width: 92px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.logrow .ev-online { color: var(--on); }
.logrow .ev-offline { color: var(--muted); }
.logrow .ev-new { color: var(--accent); }
.logrow.fail { color: var(--bad); }

/* 底部抽屉 */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; }
.sheet-bg { position: absolute; inset: 0; background: rgba(2, 6, 23, .55); }
.panel { position: relative; width: 100%; max-height: 90vh; overflow-y: auto; background: var(--card); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 12px; }
.sh-title { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.kv { display: grid; grid-template-columns: 88px 1fr; gap: 6px 10px; margin: 14px 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.sec { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.sec h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.row { display: flex; gap: 8px; margin-top: 8px; }
.row > * { flex: 1; min-width: 0; }
.row .btn { flex: none; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.switch input { width: 20px; height: 20px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  max-width: 90vw; padding: 11px 16px; border-radius: 12px; background: #0f172a; color: #fff; font-size: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .3); }
.toast.bad { background: var(--bad); }
@media (min-width: 700px) {
  #app { max-width: 720px; margin: 0 auto; }
  .sheet { align-items: center; }
  .panel { border-radius: 18px; }
}
