/* ============ 主题变量 ============ */
:root {
  --bg: #f4f6fb;
  --bg-accent-a: rgba(99, 102, 241, .13);
  --bg-accent-b: rgba(6, 182, 212, .11);
  --card: #ffffff;
  --card-soft: #f8fafd;
  --text: #0f172a;
  --text-dim: #64748b;
  --border: #e6eaf2;
  --down: #6366f1;
  --down-2: #06b6d4;
  --up: #a855f7;
  --up-2: #ec4899;
  --lat: #f59e0b;
  --ok: #22c55e;
  --err: #ef4444;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 30px rgba(15, 23, 42, .06);
  --shadow-lg: 0 2px 6px rgba(15, 23, 42, .06), 0 24px 60px rgba(15, 23, 42, .10);
  --radius: 18px;
}

[data-theme="dark"] {
  --bg: #0a0f1c;
  --bg-accent-a: rgba(99, 102, 241, .18);
  --bg-accent-b: rgba(6, 182, 212, .14);
  --card: #121a2c;
  --card-soft: #0f1728;
  --text: #e8eefb;
  --text-dim: #8ea0bd;
  --border: #1f2b45;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 14px 36px rgba(0, 0, 0, .35);
  --shadow-lg: 0 2px 8px rgba(0, 0, 0, .4), 0 28px 70px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(1100px 560px at 15% -12%, var(--bg-accent-a), transparent 62%),
    radial-gradient(900px 520px at 100% -5%, var(--bg-accent-b), transparent 58%);
}

.app { position: relative; z-index: 1; max-width: 1120px; margin: 0 auto; padding: 22px 20px 56px; }

/* ============ 顶栏 ============ */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  box-shadow: 0 6px 18px rgba(99, 102, 241, .32);
}
.brand-text { display: flex; flex-direction: column; gap: 4px; }
.brand-text strong { font-size: 17px; letter-spacing: .2px; }
.tag {
  font-size: 11.5px; color: var(--text-dim); background: var(--card); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 999px; width: fit-content;
}
.tag.ok { color: var(--ok); border-color: rgba(34, 197, 94, .35); }
.tag.warn { color: var(--lat); border-color: rgba(245, 158, 11, .35); }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.node {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim);
  background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 7px 13px;
  max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.node .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); flex: none; }
.node .dot.on { background: var(--ok); box-shadow: 0 0 0 4px rgba(34, 197, 94, .16); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; cursor: pointer;
  background: var(--card); color: var(--text-dim); border: 1px solid var(--border); transition: .18s;
}
.icon-btn:hover { color: var(--text); transform: translateY(-1px); }

/* ============ 卡片通用 ============ */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { font-size: 14px; font-weight: 650; margin: 0; letter-spacing: .3px; color: var(--text); }

.main { display: flex; flex-direction: column; gap: 18px; }

/* ============ 舞台 / 仪表盘 ============ */
.stage { display: flex; flex-direction: column; align-items: center; padding: 26px 22px 24px; box-shadow: var(--shadow-lg); }
.gauge-wrap { position: relative; width: min(300px, 78vw); aspect-ratio: 1; }
.gauge { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge-track { fill: none; stroke: var(--border); stroke-width: 14; opacity: .85; }
.gauge-bar {
  fill: none; stroke: url(#gaugeGrad); stroke-width: 14; stroke-linecap: round;
  stroke-dasharray: 678.58; stroke-dashoffset: 678.58;
  transition: stroke-dashoffset .18s linear;
}
.gauge-center {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.gauge-center .phase { font-size: 12.5px; color: var(--text-dim); letter-spacing: .5px; }
.gauge-center .value { font-size: clamp(38px, 9vw, 54px); font-weight: 700; line-height: 1.05; letter-spacing: -1px; }
.gauge-center .unit { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.gauge-center .sub { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; text-align: center; padding: 0 18px; }
.num { font-feature-settings: "tnum" 1; }

.progress { width: min(420px, 90%); height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; margin: 14px 0 18px; }
.progress-bar { height: 100%; width: 0%; border-radius: 999px; background: linear-gradient(90deg, var(--down), var(--down-2)); transition: width .2s linear; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; font-weight: 600;
  padding: 11px 20px; border-radius: 12px; border: 1px solid var(--border); background: var(--card); color: var(--text);
  transition: .18s ease; font-family: inherit;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: linear-gradient(135deg, #6366f1, #06b6d4); color: #fff; border: none; box-shadow: 0 8px 22px rgba(99, 102, 241, .3); }
.btn.primary.stop { background: linear-gradient(135deg, #ef4444, #f97316); box-shadow: 0 8px 22px rgba(239, 68, 68, .28); }
.btn.ghost { color: var(--text-dim); }
.btn.tiny { padding: 6px 12px; font-size: 12px; border-radius: 9px; color: var(--text-dim); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.err {
  margin: 14px 0 0; font-size: 12.5px; color: var(--err); background: rgba(239, 68, 68, .08);
  border: 1px solid rgba(239, 68, 68, .22); padding: 9px 13px; border-radius: 10px; max-width: 520px; text-align: center;
}

/* ============ 指标卡 ============ */
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.metric { display: flex; flex-direction: column; gap: 8px; padding: 18px 20px; }
.metric-head { display: flex; align-items: center; gap: 9px; }
.chip { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; color: #fff; flex: none; }
.chip-down { background: linear-gradient(135deg, var(--down), var(--down-2)); }
.chip-up { background: linear-gradient(135deg, var(--up), var(--up-2)); }
.chip-lat { background: linear-gradient(135deg, #f59e0b, #f97316); }
.metric-label { font-size: 12.5px; color: var(--text-dim); font-weight: 600; }
.metric-value { font-size: clamp(24px, 4.4vw, 32px); font-weight: 700; letter-spacing: -.6px; line-height: 1.1; }
.metric-sub { font-size: 11.5px; color: var(--text-dim); }
.metric-value .u { font-size: .48em; font-weight: 600; color: var(--text-dim); margin-left: 4px; letter-spacing: 0; }
.metric.active { border-color: rgba(99, 102, 241, .4); box-shadow: 0 0 0 3px rgba(99, 102, 241, .10), var(--shadow); }

/* ============ 设置 ============ */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px 20px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 12.5px; color: var(--text-dim); font-weight: 600; }
.field-label b { color: var(--text); font-weight: 700; }
.field select, .field input[type="text"] {
  font-family: inherit; font-size: 13px; color: var(--text); background: var(--card-soft);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; outline: none; transition: .15s;
}
.field select:focus, .field input[type="text"]:focus { border-color: var(--down); box-shadow: 0 0 0 3px rgba(99, 102, 241, .14); }
.field input[type="range"] { width: 100%; accent-color: var(--down); }
.check-field { justify-content: space-between; }
.switch { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 42px; height: 24px; border-radius: 999px; background: var(--border); position: relative; transition: .2s; display: inline-block;
}
.switch-dot {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: .2s;
}
.switch input:checked + .switch-track { background: linear-gradient(135deg, #6366f1, #06b6d4); }
.switch input:checked + .switch-track .switch-dot { left: 21px; }
.switch-text { font-size: 12.5px; color: var(--text-dim); }
.advanced { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.advanced summary { font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.advanced .settings-grid { margin-top: 14px; }
.hint { font-size: 12px; color: var(--text-dim); margin: 14px 0 0; line-height: 1.6; }
.hint code { background: var(--card-soft); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font-size: 11.5px; }

/* ============ 曲线 ============ */
.legend { display: flex; gap: 14px; }
.lg { font-size: 12px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 6px; }
.lg::before { content: ""; width: 10px; height: 3px; border-radius: 2px; }
.lg-down::before { background: linear-gradient(90deg, var(--down), var(--down-2)); }
.lg-up::before { background: linear-gradient(90deg, var(--up), var(--up-2)); }
.canvas-box { width: 100%; height: 240px; }
#chart { width: 100%; height: 100%; display: block; }

/* ============ 历史 ============ */
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history-list li {
  display: grid; grid-template-columns: 92px 1fr 1fr 1fr; gap: 10px; align-items: center;
  font-size: 12.5px; padding: 10px 12px; border-radius: 11px; background: var(--card-soft); border: 1px solid var(--border);
}
.history-list .h-time { color: var(--text-dim); }
.history-list .h-item { display: flex; flex-direction: column; gap: 3px; }
.history-list .h-k { font-size: 10.5px; color: var(--text-dim); }
.history-list .h-v { font-weight: 650; }
.empty { font-size: 12.5px; color: var(--text-dim); margin: 6px 0 0; }

/* ============ 页脚 ============ */
.footer { margin-top: 26px; text-align: center; color: var(--text-dim); font-size: 12px; line-height: 1.8; }
.footer p { margin: 0; }
.footer .dim { opacity: .75; }
.footer b { color: var(--text); }

/* ============ 响应式 ============ */
@media (max-width: 760px) {
  .metrics { grid-template-columns: 1fr; }
  .node { max-width: 60vw; }
  .history-list li { grid-template-columns: 1fr 1fr; }
  .history-list .h-time { grid-column: 1 / -1; }
  .app { padding: 16px 14px 40px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
