:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --line: #e3e8f0;
  --text: #16202e;
  --muted: #6b7a90;
  --brand: #1f5eff;
  --ok: #14a06b;
  --warn: #d98a00;
  --bad: #d64545;
  --shadow: 0 2px 10px rgba(20, 32, 54, .06);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 20px; }

.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: linear-gradient(150deg, #eef3ff, #f7f9fc 60%);
}
.login-card {
  width: 340px; background: var(--card); padding: 32px; border-radius: 16px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 24px; letter-spacing: .5px; }
.login-card p { margin: 0 0 8px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

#app { display: flex; min-height: 100vh; }
.side {
  width: 200px; background: #101826; color: #c8d2e2;
  display: flex; flex-direction: column; padding: 20px 14px; gap: 18px;
}
.brand { font-size: 20px; font-weight: 700; color: #fff; letter-spacing: .5px; }
.brand span { display: block; font-size: 12px; font-weight: 400; color: #7d8ba3; letter-spacing: 2px; }
#nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; }
.nav-title {
  font-size: 11px; letter-spacing: 2px; color: #5c6b83;
  padding: 8px 12px 2px;
}
#nav button {
  text-align: left; background: transparent; border: 0; color: #a9b6ca;
  padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
#nav .nav-group button { padding-left: 22px; font-size: 13px; position: relative; }
#nav .nav-group button::before {
  content: ""; position: absolute; left: 12px; top: 50%; width: 3px; height: 3px;
  margin-top: -1.5px; border-radius: 50%; background: #4b5a72;
}
#nav button:hover { background: #1a2436; color: #fff; }
#nav button.active { background: var(--brand); color: #fff; }
#nav .nav-group button.active::before { background: #fff; }

.main { flex: 1; padding: 22px 26px 40px; min-width: 0; }
.main header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.main h2 { margin: 0; font-size: 20px; }
.actions { display: flex; align-items: center; gap: 12px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr; } }

button {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
button:hover { border-color: #b9c6dc; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.ghost { background: #101826; color: #c8d2e2; border-color: #243149; }
.main button.ghost { background: #fff; color: var(--text); border-color: var(--line); }
button.danger { color: var(--bad); border-color: #f0c9c9; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
  font-size: 13px; background: #fff; color: var(--text); min-width: 90px;
}
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.check { flex-direction: row; align-items: center; gap: 6px; }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 10px; }
.kv .k { color: var(--muted); }
.kv .v { font-variant-numeric: tabular-nums; }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 6px 20px; }
.kv-grid .item { display: flex; align-items: baseline; gap: 8px; padding: 1px 0; min-width: 0; }
.kv-grid .item .k { color: var(--muted); font-size: 12px; flex: 0 0 auto; min-width: 86px; }
.kv-grid .item .v { font-variant-numeric: tabular-nums; word-break: break-all; min-width: 0; }

.mini-tabs { display: inline-flex; gap: 4px; background: #eef1f6; padding: 3px; border-radius: 9px; }
.mini-tabs button { border: 0; background: transparent; padding: 5px 16px; border-radius: 7px; font-size: 13px; color: var(--muted); }
.mini-tabs button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(20, 32, 54, .12); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; }
.badge.ok { background: #e6f7ef; color: var(--ok); }
.badge.warn { background: #fdf3e0; color: var(--warn); }
.badge.bad { background: #fdecec; color: var(--bad); }
.badge.idle { background: #eef1f6; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip { background: #eef3ff; color: #2a4fa8; padding: 3px 10px; border-radius: 99px; font-size: 12px; }

.pager { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.pager button { padding: 4px 12px; font-size: 13px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; background: #fafbfe; position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); background: #f1f4fa; }
tbody tr:hover { background: #fafcff; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.comment { white-space: normal; max-width: 320px; line-height: 1.45; }
.ds-more { display: inline; }
.ds-more summary { display: inline; cursor: pointer; color: var(--muted); font-size: 12px; }

/* 数据集表格：操作列固定在右侧，其余列可左右滑动 */
#datasets-table td:last-child {
  position: sticky; right: 0; z-index: 2;
  background: var(--card);
  box-shadow: -8px 0 8px -8px rgba(20, 32, 54, .18);
}
#datasets-table th:last-child {
  position: sticky; top: 0; right: 0; z-index: 3;
  background: #fafbfe;
  box-shadow: -8px 0 8px -8px rgba(20, 32, 54, .18);
}
#datasets-table tbody tr:hover td:last-child { background: #fafcff; }

.gauge { margin: 6px 0 10px; }
.gauge-bar { height: 12px; background: #edf1f7; border-radius: 99px; overflow: hidden; }
.gauge-fill { height: 100%; background: linear-gradient(90deg, #3f7bff, #6ea0ff); }
.gauge-fill.warn { background: linear-gradient(90deg, #d98a00, #f0b64a); }
.gauge-fill.bad { background: linear-gradient(90deg, #d64545, #ef7a7a); }
.gauge-text { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }

.trend { display: flex; align-items: flex-end; gap: 6px; height: 90px; margin-top: 12px; }
.trend .bar { flex: 1; background: #dbe6ff; border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.trend .bar span { position: absolute; bottom: -20px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--muted); }

.notice {
  margin-top: 10px; padding: 10px 12px; border-radius: 8px;
  background: #eef3ff; color: #223a6b; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}
.link { color: var(--brand); text-decoration: none; }
.link:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: #33415c;
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.modal {
  position: fixed; inset: 0; background: rgba(16, 24, 38, .45);
  display: grid; place-items: center; z-index: 98;
}
.modal-card {
  width: 440px; max-width: calc(100vw - 32px); background: #fff; border-radius: 12px;
  padding: 20px 22px; box-shadow: 0 12px 32px rgba(16, 24, 38, .18);
  display: flex; flex-direction: column; gap: 14px;
}
.modal-card h3 { margin: 0; font-size: 15px; }
.warn-text {
  grid-column: 1 / -1; margin: 4px 0 0; padding: 6px 10px; border-radius: 6px;
  background: #fdf3e0; color: #8a5a00; font-size: 12px;
}
.toast {
  position: fixed; right: 24px; bottom: 24px; background: #101826; color: #fff;
  padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 99;
}

/* 在线 API 文档 */
.api-item { padding: 12px 0; border-top: 1px dashed var(--line); }
.api-item:first-of-type { border-top: 0; padding-top: 4px; }
.api-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.api-method {
  font-size: 11px; font-weight: 700; letter-spacing: .5px;
  padding: 1px 8px; border-radius: 6px; background: #eef1f6; color: var(--muted);
}
.api-method.get { background: #e6f0ff; color: var(--brand); }
.api-method.post { background: #e6f7ef; color: var(--ok); }
.api-path { font-size: 13px; font-weight: 600; color: var(--text); }
.api-summary { font-size: 13px; color: var(--muted); }
.api-params { width: auto; margin-top: 8px; }
.api-params th, .api-params td { position: static; background: transparent; padding: 3px 18px 3px 0; border-bottom: 0; }
.api-params th { color: var(--muted); font-weight: 500; }
.api-params td { white-space: normal; }
.api-links { margin-top: 8px; font-size: 13px; }
.api-example {
  margin-top: 8px; padding: 8px 10px; border-radius: 8px;
  background: #f6f8fc; border: 1px solid var(--line);
  overflow-x: auto;
}
.api-example code { white-space: pre; font-size: 12px; }
