:root {
  --bg: #0e1117;
  --bg-soft: #131822;
  --panel: #171d29;
  --panel-2: #1c2331;
  --border: #262e3d;
  --text: #e7ebf3;
  --text-dim: #8f9bb0;
  --text-faint: #64708a;
  --primary: #4c8dff;
  --success: #2ecc71;
  --warning: #f5a623;
  --danger: #f4556a;
  --purple: #a78bfa;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }

.layout { display: flex; min-height: 100vh; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.brand-title { font-size: 15px; font-weight: 600; letter-spacing: .5px; }
.brand-sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin-bottom: 2px;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all .15s;
  user-select: none;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: rgba(76,141,255,.14); color: var(--primary); font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; }
.nav-item .badge {
  margin-left: auto; background: var(--danger); color: #fff;
  border-radius: 10px; padding: 0 6px; font-size: 11px; line-height: 17px; min-width: 18px; text-align: center;
}
.nav-section {
  padding: 12px 12px 6px; font-size: 11px; color: var(--text-faint); letter-spacing: 1px;
}

/* ---------- 主区 ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .meta { font-size: 12px; color: var(--text-faint); }
.content { padding: 22px 24px 60px; }

/* ---------- 通用组件 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
  cursor: pointer; font-size: 13px; transition: all .15s;
  font-family: inherit;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #3a7ce8; color: #fff; }
.btn-danger { color: var(--danger); border-color: rgba(244,85,106,.4); }
.btn-danger:hover { background: rgba(244,85,106,.12); color: var(--danger); border-color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: transparent; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card-title { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-title .spacer { flex: 1; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 1200px) { .grid-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 820px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .value { font-size: 26px; font-weight: 600; line-height: 1.2; }
.stat .label { font-size: 12px; color: var(--text-faint); }
.stat .hint { font-size: 11px; color: var(--text-dim); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; padding: 9px 10px;
  color: var(--text-faint); font-weight: 500; font-size: 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid rgba(38,46,61,.6); vertical-align: middle; }
.tbl tbody tr:hover { background: rgba(76,141,255,.05); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; margin: -4px; }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 20px;
  font-size: 11px; line-height: 18px; border: 1px solid transparent;
}
.tag-run { background: rgba(46,204,113,.14); color: var(--success); border-color: rgba(46,204,113,.3); }
.tag-stop { background: rgba(143,155,176,.14); color: var(--text-dim); border-color: rgba(143,155,176,.3); }
.tag-warn { background: rgba(245,166,35,.14); color: var(--warning); border-color: rgba(245,166,35,.3); }
.tag-crit { background: rgba(244,85,106,.14); color: var(--danger); border-color: rgba(244,85,106,.3); }
.tag-info { background: rgba(76,141,255,.14); color: var(--primary); border-color: rgba(76,141,255,.3); }
.tag-purple { background: rgba(167,139,250,.14); color: var(--purple); border-color: rgba(167,139,250,.3); }

.bar { height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; transition: width .4s; }
.bar-info > i { background: linear-gradient(90deg, #4c8dff, #6aa5ff); }
.bar-warn > i { background: linear-gradient(90deg, #f5a623, #ffc257); }
.bar-crit > i { background: linear-gradient(90deg, #f4556a, #ff7b8c); }

.empty { padding: 40px; text-align: center; color: var(--text-faint); font-size: 13px; }
.spinner { padding: 40px; text-align: center; color: var(--text-dim); }
.mono { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
input.inp, select.inp {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 10px; border-radius: 8px; font-size: 13px; font-family: inherit; outline: none;
}
input.inp:focus, select.inp:focus { border-color: var(--primary); }
input.inp::placeholder { color: var(--text-faint); }
label.flabel { font-size: 12px; color: var(--text-faint); }

/* ---------- 弹窗 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(5,8,14,.72);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  width: 560px; max-width: 100%; max-height: 88vh; overflow-y: auto;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
.form-row input.inp, .form-row select.inp { width: 100%; }
.form-row .tip { font-size: 11px; color: var(--text-faint); margin-top: 4px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: 8px; padding: 12px 16px; min-width: 260px; max-width: 460px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); font-size: 13px;
  animation: slidein .2s ease;
}
.toast.ok { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warning); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 登录 ---------- */
.login-wrap { position: relative; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { width: 340px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.login-box h2 { margin: 0 0 18px; font-size: 18px; }
.login-foot {
  position: absolute; left: 16px; right: 16px; bottom: 16px;
  text-align: center; color: var(--text-faint); font-size: 12px; line-height: 1.8;
}
.login-foot a { color: var(--text-faint); }
.login-foot a:hover { color: var(--text); }

/* ---------- 图表 ---------- */
.chart-box { position: relative; height: 300px; }
.legend-inline { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-dim); margin-top: 8px; }
.legend-inline span { display: inline-flex; align-items: center; gap: 5px; }
.legend-inline i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.pkg-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; background: var(--panel); }
.pkg-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.pkg-name { font-weight: 600; font-size: 14px; }
.pkg-pct { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pkg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; font-size: 12px; }
.pkg-grid div span { display: block; color: var(--text-faint); }

.alert-line { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid rgba(38,46,61,.6); }
.alert-line:last-child { border-bottom: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: 0 0 8px; }
.dot-crit { background: var(--danger); box-shadow: 0 0 0 3px rgba(244,85,106,.18); }
.dot-warn { background: var(--warning); box-shadow: 0 0 0 3px rgba(245,166,35,.18); }
.dot-ok { background: var(--success); }

/* ---------- 实例控制 ---------- */
.ctrl-col { white-space: nowrap; }
.btn.block { display: block; width: 100%; margin-bottom: 8px; text-align: left; }
.ctrl-menu { display: flex; flex-direction: column; }
.big-num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }

/* ---------- 账单/费用概览 ---------- */
.bill-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.bill-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.bill-stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.bill-stat .k { font-size: 12px; color: var(--text-faint); }
.bill-stat .v { margin-top: 6px; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .2px; }
.bill-split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr); gap: 14px; align-items: start; }
.bill-row { display: grid; grid-template-columns: 132px minmax(0, 1fr) 92px; gap: 12px; align-items: center; padding: 9px 0; border-bottom: 1px solid rgba(38,46,61,.65); }
.bill-row:last-child { border-bottom: none; }
.bill-row .name { font-size: 13px; }
.bill-track { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bill-track i { display: block; height: 100%; border-radius: 99px; }
.bill-row .amt { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.bill-row .amt.neg { color: #23c6a0; }
.bill-row .pct { font-size: 11px; font-weight: 400; color: var(--text-faint); }
.chart { width: 100%; height: auto; display: block; }
.chart .c-val { fill: var(--text); font-size: 11px; }
.chart .c-lab { fill: var(--text-faint); font-size: 10.5px; }
.chart .c-axis { stroke: var(--border); stroke-width: 1; }
.up { color: #ff5d5d; }
.down { color: #23c6a0; }
@media (max-width: 900px) {
  .bill-stats, .bill-split { grid-template-columns: 1fr; }
  .bill-row { grid-template-columns: 108px minmax(0, 1fr) 84px; }
}
