:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1f2329;
  --muted: #6b7380;
  --line: #e4e7ec;
  --primary: #1668dc;
  --primary-hover: #3c89e8;
  --danger: #d9363e;
  --ok: #1f9d55;
  --warn: #d48806;
  --chip-bg: #eef1f5;
  --hover: #f0f3f8;
  --shadow: 0 8px 28px rgba(0, 0, 0, .18);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --panel: #1d2026;
    --text: #e6e8eb;
    --muted: #98a1ad;
    --line: #2d323b;
    --primary: #3c89e8;
    --primary-hover: #5b9df0;
    --danger: #ef6b72;
    --ok: #4cc27f;
    --warn: #f0b84a;
    --chip-bg: #2a2f38;
    --hover: #262b33;
    --shadow: 0 8px 28px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14161a;
  --panel: #1d2026;
  --text: #e6e8eb;
  --muted: #98a1ad;
  --line: #2d323b;
  --primary: #3c89e8;
  --primary-hover: #5b9df0;
  --danger: #ef6b72;
  --ok: #4cc27f;
  --warn: #f0b84a;
  --chip-bg: #2a2f38;
  --hover: #262b33;
  --shadow: 0 8px 28px rgba(0, 0, 0, .6);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* 登录 */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 28px 24px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p { margin: 0 0 20px; }

/* 布局 */
.layout { display: grid; grid-template-columns: 200px 1fr; min-height: 100%; }
.side { overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 16px 10px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 18px; padding: 4px 10px 16px; }
.nav button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 9px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 2px;
}
.nav button:hover { background: var(--hover); }
.nav button.active { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); font-weight: 600; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.content { padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.page-title { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; flex-wrap: wrap; }
.page-title h2 { margin: 0; font-size: 18px; }

/* 统计卡片 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat .s { color: var(--muted); font-size: 12px; }

/* 按钮与表单 */
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 6px 14px; cursor: pointer; line-height: 1.5;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn.sm { padding: 2px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }
textarea { min-height: 120px; resize: vertical; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 600; margin-bottom: 4px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 3px; }
.row2 { display: grid; grid-template-columns: 1fr 120px; gap: 8px; }

/* 表格 */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: color-mix(in srgb, var(--chip-bg) 60%, transparent); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--hover); }
td.actions { white-space: nowrap; }
td.actions .btn { margin-right: 4px; }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }

/* 标签与开关 */
.chip { display: inline-block; padding: 0 8px; border-radius: 6px; font-size: 12px; line-height: 20px; background: var(--chip-bg); margin-right: 4px; }
.chip.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.chip.bad { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.chip.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); }
.switch { position: relative; width: 38px; height: 22px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 22px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(16px); }

/* 弹窗 */
dialog.modal { border: 0; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
dialog.modal.wide { width: min(760px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(0, 0, 0, .45); }
.modal-head { padding: 16px 20px 0; font-size: 17px; font-weight: 700; }
.modal-body { padding: 16px 20px; max-height: 70vh; overflow: auto; }
.modal-foot { padding: 0 20px 16px; display: flex; justify-content: flex-end; gap: 8px; }
.cmd { background: var(--chip-bg); border-radius: 8px; padding: 10px 12px; word-break: break-all; user-select: all; }
.result-line { padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.result-line.err { color: var(--danger); }

/* 提示 */
#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 99; display: grid; gap: 8px; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--ok); border-radius: 8px; padding: 9px 16px; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { border-left-color: var(--danger); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }

/* v0.4 */
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid2 .card { margin-bottom: 0; }
.grid2 + .card, .card + .grid2 { margin-top: 16px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }
.banner { background: color-mix(in srgb, var(--primary) 10%, transparent); border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; white-space: pre-wrap; }
.banner.bad { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.meter { position: relative; height: 18px; min-width: 120px; background: var(--chip-bg); border-radius: 9px; overflow: hidden; margin: 2px 0; }
.meter .bar { position: absolute; left: 0; top: 0; bottom: 0; background: color-mix(in srgb, var(--ok) 55%, transparent); }
.meter .bar.warm { background: color-mix(in srgb, var(--warn) 60%, transparent); }
.meter .bar.hot { background: color-mix(in srgb, var(--danger) 60%, transparent); }
.meter span { position: relative; display: block; font-size: 12px; line-height: 18px; padding: 0 8px; white-space: nowrap; }
td.meters { min-width: 150px; }
.usage { min-width: 160px; flex: 1; max-width: 280px; }
.plans { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.plan-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.plan-card.current { border-color: var(--primary); }
.plan-name { font-weight: 700; font-size: 16px; }
.plan-price { font-size: 24px; font-weight: 700; margin: 6px 0; }
.plan-card ul { margin: 6px 0; padding-left: 18px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.check { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; font-weight: 400 !important; }
.ann { padding: 10px 0; border-bottom: 1px dashed var(--line); }
.ann:last-child { border-bottom: 0; }
.ann-body { white-space: pre-wrap; margin-top: 4px; }
.ann-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }
.pos { color: var(--ok); }
.table-wrap.flat { border: 0; border-radius: 0; background: transparent; }
.diag-node { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.daybars { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-bottom: 16px; }
.daybar { flex: 1; height: 100%; position: relative; display: flex; align-items: flex-end; min-width: 6px; }
.daybar div { width: 100%; background: var(--primary); border-radius: 3px 3px 0 0; }
.daybar span { position: absolute; bottom: -16px; left: 50%; transform: translateX(-50%); font-size: 9px; color: var(--muted); white-space: nowrap; display: none; }
.daybar:nth-child(5n+1) span { display: block; }

@media (max-width: 760px) {
  .row3 { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .brand { padding: 0 8px; }
  .nav { display: flex; flex-wrap: wrap; }
  .nav button { width: auto; margin: 0; }
  .content { padding: 12px; }
}
.chip { white-space: nowrap; }

.row-inline{display:flex;align-items:center;gap:8px;margin:6px 0}
.row-inline select{flex:1}
.bars{display:flex;align-items:flex-end;gap:3px;height:140px;padding:8px 0;border-bottom:1px solid var(--line)}
.bar-col{flex:1;display:flex;flex-direction:column;justify-content:flex-end;align-items:center;height:100%;min-width:0}
.bar-fill{width:100%;background:var(--primary);border-radius:2px 2px 0 0;min-height:2px}
.bar-lab{font-size:9px;color:var(--muted);margin-top:3px;white-space:nowrap;overflow:hidden}
.layout.standalone { grid-template-columns: 1fr; }

.nav-head { color: var(--muted) !important; font-size: 12px; margin-top: 8px; }
.nav-sub { margin-left: 8px; padding-left: 6px; border-left: 2px solid var(--line); }
.nav-sub[hidden] { display: none; }

.qm { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border: 1px solid var(--muted); color: var(--muted); border-radius: 50%; font-size: 11px; cursor: help; vertical-align: 1px; }
details.adv { border: 1px solid var(--line, #e3e6ea); border-radius: 8px; padding: 0 12px 6px; margin-top: 8px; }
details.adv > summary { cursor: pointer; padding: 10px 0; font-weight: 600; list-style: none; }
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::before { content: '›'; display: inline-block; margin-right: 8px; transition: transform .15s; }
details.adv[open] > summary::before { transform: rotate(90deg); }
.conninfo { padding: 8px 12px; border: 1px solid var(--line, #e4e7ec); border-radius: 8px; font-size: 13px; background: var(--bg-soft, rgba(127,127,127,.06)); }
.logbox { height: 62vh; overflow: auto; background: var(--chip-bg, rgba(127,127,127,.08)); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; line-height: 1.6; }
.logl { white-space: pre-wrap; word-break: break-all; }

.demo-box{margin-top:16px;padding:12px 14px;border:1px dashed var(--border,#9aa);border-radius:10px;background:rgba(14,116,144,.08)}
.demo-box code{user-select:all}
.demo-bar{background:#b45309;color:#fff;padding:6px 14px;font-size:13px;text-align:center}
