/* ================= 主题变量（昼 = 参考图白色产品风；夜 = 深蓝大屏风） ================= */
body[data-theme="day"] {
  --page: #ffffff;
  --surface: #fcfcfb;
  --surface-2: #f4f4f1;
  --border: rgba(11, 11, 11, 0.10);
  --ink-1: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --c1: #2a78d6;
  --c2: #eb6834;
  --c3: #1baf7a;
  --good: #0ca30c;
  --warn: #fab219;
  --serious: #ec835a;
  --crit: #d03b3b;
  --up: #006300;
  --down: #d03b3b;
  --panel-shadow: 0 1px 3px rgba(11, 11, 11, 0.06);
  --font-ui: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color-scheme: light;
}

body[data-theme="night"] {
  --page: #070d1c;
  --surface: #131c33;
  --surface-2: #0f1628;
  --border: rgba(255, 255, 255, 0.10);
  --ink-1: #f2f6fc;
  --ink-2: #c3cad9;
  --muted: #8d97ad;
  --grid: #243049;
  --baseline: #383f52;
  --c1: #3987e5;
  --c2: #d95926;
  --c3: #199e70;
  --good: #0ca30c;
  --warn: #fab219;
  --serious: #ec835a;
  --crit: #d03b3b;
  --up: #0ca30c;
  --down: #e66767;
  --panel-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--page);
  color: var(--ink-1);
  overflow: hidden;
  transition: background 0.45s ease, color 0.45s ease;
}

.app {
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr) 26px;
  height: 100vh;
  height: 100dvh;
}

/* ================= 头部 ================= */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { flex: none; }
.brand h1 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.brand .sub {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.12em;
  white-space: nowrap;
}
.head-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.badge {
  font-size: 11px;
  color: var(--ink-2);
  border: 1px dashed var(--baseline);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}
#clock {
  font-size: 13px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#mode-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink-1);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.2s;
}
#mode-toggle:hover { background: var(--grid); }

/* ================= 主体三栏 ================= */
main {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 320px;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}
.col { display: flex; flex-direction: column; gap: 14px; min-height: 0; overflow-y: auto; scrollbar-width: thin; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--panel-shadow);
  flex: none;
  transition: background 0.45s ease, border-color 0.45s ease;
}
.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-2);
  margin-bottom: 10px;
}
.panel-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--grid);
}
.panel-note { font-size: 11px; color: var(--muted); margin-top: 8px; line-height: 1.5; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface);
}
.kpi-label { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.kpi-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.kpi-unit { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.kpi-delta { font-size: 11px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-delta.up { color: var(--up); }
.kpi-delta.down { color: var(--down); }
.kpi-delta.flat { color: var(--muted); }
.kpi-vs { color: var(--muted); margin-left: 2px; }

/* 图表画布 */
canvas.chart { display: block; width: 100%; }
#chart-region { height: 190px; }
.trend-sub { font-size: 11px; color: var(--muted); margin: 6px 0 2px; }
#chart-req { height: 104px; }
#chart-err { height: 84px; }

/* 当前节点 */
#panel-node .empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  padding: 18px 0;
  text-align: center;
}
#node-detail { display: grid; gap: 8px; }
.node-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
#node-name { font-size: 15px; font-weight: 650; }
#node-region { font-size: 11px; color: var(--muted); }
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--st);
  border: 1px color-mix(in srgb, var(--st) 45%, transparent);
  background: color-mix(in srgb, var(--st) 12%, transparent);
  padding: 2px 9px;
  border-radius: 999px;
}
.node-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  font-size: 12px;
  color: var(--ink-2);
}
.node-metrics b {
  color: var(--ink-1);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
#chart-spark { height: 56px; }
#spark-max { font-size: 11px; color: var(--muted); text-align: right; }

/* 环形图 + 图例 */
.donut-wrap { display: flex; align-items: center; gap: 12px; }
#chart-donut { width: 150px; height: 150px; flex: none; }
#donut-legend { flex: 1; display: grid; gap: 7px; }
.legend-row {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }
.legend-label { color: var(--ink-2); }
.legend-val { font-weight: 650; font-variant-numeric: tabular-nums; }
.legend-pct { color: var(--muted); font-variant-numeric: tabular-nums; width: 42px; text-align: right; }

/* 链路列表 */
#link-list { display: grid; gap: 6px; }
.link-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.link-row:hover { background: var(--surface-2); }
.link-latency { color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ================= 中央地球舞台 ================= */
.stage {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--page);
  min-height: 0;
}
.stage canvas { width: 100%; height: 100%; }
.stage-legend {
  position: absolute;
  top: 10px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--ink-2);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  backdrop-filter: blur(4px);
  pointer-events: none;
}
.stage-legend .row { display: flex; align-items: center; gap: 6px; }
.stage-legend .dot { width: 8px; height: 8px; border-radius: 50%; }
.stage-hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}
.stage-caption {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 12px;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(4px);
}
.globe-tip {
  position: absolute;
  z-index: 10;
  font-size: 12px;
  background: var(--ink-1);
  color: var(--page);
  padding: 4px 9px;
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
}
.chart-tip {
  position: fixed;
  z-index: 30;
  font-size: 12px;
  line-height: 1.55;
  background: var(--ink-1);
  color: var(--page);
  padding: 6px 10px;
  border-radius: 8px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* ================= 页脚 ================= */
footer {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0 10px;
  text-align: center;
}

/* ================= 窄屏（<1080px 单列堆叠） ================= */
@media (max-width: 1080px) {
  body { overflow: auto; }
  .app { height: auto; grid-template-rows: auto auto auto; }
  header { position: sticky; top: 0; z-index: 20; flex-wrap: wrap; height: auto; padding: 8px 12px; }
  .brand .sub { display: none; }
  main { grid-template-columns: 1fr; padding: 12px; }
  .stage { order: -1; height: 54vh; min-height: 400px; }
  .col { overflow: visible; }
  footer { position: static; }
}
@media (max-width: 560px) {
  .head-right { flex-wrap: wrap; }
  #clock { display: none; }
  .stage { height: 46vh; min-height: 340px; }
}
