:root {
  --accent: #4f8cff;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --up: #4f8cff;
  --down: #3fb950;
}
[data-theme="dark"] {
  --bg: #0b0e14;
  --bg2: #0d1117;
  --card: #151a23;
  --card-hover: #1b212c;
  --border: #232a36;
  --text: #e6e9ef;
  --muted: #8a93a3;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
}
[data-theme="light"] {
  --bg: #f4f6fa;
  --bg2: #eaeef5;
  --card: #ffffff;
  --card-hover: #ffffff;
  --border: #e2e7ef;
  --text: #1b2330;
  --muted: #6b7585;
  --shadow: 0 8px 30px rgba(20,40,80,.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
  transition: background .25s, color .25s;
}

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; letter-spacing: .5px; }
.logo-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .4 } }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.stats { display: flex; gap: 18px; font-size: 13px; color: var(--muted); }
.stat-num { color: var(--text); font-weight: 700; font-size: 15px; }
.stat.up { color: var(--up); } .stat.down { color: var(--down); }
.icon-btn {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  width: 36px; height: 36px; border-radius: 9px; cursor: pointer; font-size: 16px;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--card-hover); border-color: var(--accent); }

/* 卡片网格 */
.grid {
  max-width: 1480px; margin: 22px auto; padding: 0 26px;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
}
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 18px; cursor: pointer;
  transition: background .15s, transform .15s, border-color .15s, box-shadow .15s;
}
.card:hover { background: var(--card-hover); transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.card.offline { opacity: .5; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.name { font-size: 16px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.status { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.status.on { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status.off { background: var(--red); }
.badge { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; white-space: nowrap; }
.meta { font-size: 12px; color: var(--muted); margin-bottom: 14px; line-height: 1.7; }

.metric { margin-bottom: 11px; }
.metric-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.metric-top .label { color: var(--muted); }
.metric-top .val { font-variant-numeric: tabular-nums; }
.bar { height: 7px; background: var(--bg2); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 4px; transition: width .5s ease, background .5s; }

.spark { margin: 6px 0 10px; }
.spark canvas { width: 100%; height: 40px; display: block; }

.net { display: flex; gap: 18px; font-size: 13px; margin-top: 6px; flex-wrap: wrap; }
.net div { display: flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }
.net .up { color: var(--up); } .net .down { color: var(--down); }
.net .tot { color: var(--muted); }

.empty { grid-column: 1/-1; text-align: center; color: var(--muted); padding: 90px 0; font-size: 15px; }

.foot { max-width: 1480px; margin: 26px auto; padding: 0 26px 30px; text-align: center; color: var(--muted); font-size: 12px; }

/* 详情抽屉 */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 20;
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: 560px; max-width: 92vw;
  background: var(--bg); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.2,.7,.3,1);
  z-index: 21; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer.show { transform: translateX(0); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.drawer-actions { display: flex; gap: 8px; flex: none; }
.icon-btn.danger:hover { border-color: var(--red); color: var(--red); }
.drawer-title { font-size: 18px; font-weight: 700; }
.drawer-sub { font-size: 12px; color: var(--muted); margin-top: 5px; line-height: 1.6; }
.drawer-body { padding: 18px 22px 30px; overflow-y: auto; }

.ranges { display: flex; gap: 8px; margin-bottom: 16px; }
.range-btn {
  background: var(--card); border: 1px solid var(--border); color: var(--muted);
  padding: 6px 14px; border-radius: 8px; font-size: 13px; cursor: pointer;
  transition: all .15s;
}
.range-btn:hover { color: var(--text); border-color: var(--accent); }
.range-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.kpi .k { font-size: 11px; color: var(--muted); }
.kpi .v { font-size: 18px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

.chart-block { margin-bottom: 22px; }
.chart-block h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; display: flex; justify-content: space-between; }
.chart-block canvas { width: 100%; height: 140px; display: block; background: var(--card); border: 1px solid var(--border); border-radius: 12px; }

/* 添加服务器弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30;
}
.modal-mask.show { opacity: 1; pointer-events: auto; }
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -46%);
  width: 680px; max-width: 92vw; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 31;
}
.modal.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 17px; font-weight: 700; }
.modal-body { padding: 20px 22px 24px; }
.modal-tip { font-size: 13px; color: var(--muted); line-height: 1.7; margin-bottom: 12px; }
.modal-tip b { color: var(--text); }
.cmd-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 14px; max-height: 200px; overflow: auto;
}
.cmd-box code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px; line-height: 1.6; color: var(--text); white-space: pre-wrap; word-break: break-all;
}
.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: 9px;
  padding: 10px 18px; font-size: 14px; cursor: pointer; transition: opacity .15s;
}
.btn-primary:hover { opacity: .88; }
.btn-primary:disabled { opacity: .5; cursor: default; }
.modal-note { font-size: 12px; color: var(--muted); margin-top: 12px; line-height: 1.7; }
.modal-note.warn { color: var(--yellow); }

@media (max-width: 560px) {
  .stats { display: none; }
  .grid { grid-template-columns: 1fr; padding: 0 14px; }
}
