:root {
  --bg: #f2ede3;
  --card: #fbf7ee;
  --line: #ddd2bf;
  --line-soft: #e9e1d3;
  --text: #23304a;
  --muted: #7d7768;
  --dim: #a39a88;
  --ok: #6b8f6e;
  --warn: #c08a2f;
  --crit: #a93b2f;
  --unknown: #b3aa99;
  --indigo: #23304a;
  --vermilion: #b23a2e;
  --radius: 3px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100svh;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='48' viewBox='0 0 96 48'%3E%3Cg fill='none' stroke='%2323304a' stroke-opacity='.05' stroke-width='1'%3E%3Ccircle cx='0' cy='48' r='16'/%3E%3Ccircle cx='0' cy='48' r='24'/%3E%3Ccircle cx='0' cy='48' r='32'/%3E%3Ccircle cx='48' cy='48' r='16'/%3E%3Ccircle cx='48' cy='48' r='24'/%3E%3Ccircle cx='48' cy='48' r='32'/%3E%3Ccircle cx='96' cy='48' r='16'/%3E%3Ccircle cx='96' cy='48' r='24'/%3E%3Ccircle cx='96' cy='48' r='32'/%3E%3Ccircle cx='24' cy='32' r='16'/%3E%3Ccircle cx='24' cy='32' r='24'/%3E%3Ccircle cx='72' cy='32' r='16'/%3E%3Ccircle cx='72' cy='32' r='24'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 96px 48px;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}

.wave {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 210px;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.wave svg { width: 100%; height: 100%; display: block; }

main, footer { position: relative; z-index: 1; max-width: 720px; margin: 0 auto; }
.top { position: relative; z-index: 1; max-width: 720px; margin: 0 auto; }

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: "Hiragino Mincho ProN", "Songti SC", serif;
  font-weight: 600;
  letter-spacing: 0.22em;
  font-size: 14px;
  color: var(--indigo);
}

.brand-mark {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--vermilion);
}

.top-right { display: flex; align-items: center; gap: 8px; }

.summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(251, 247, 238, 0.75);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* ---------- status dots ---------- */
.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
  background: var(--unknown);
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.crit { background: var(--crit); }
.dot.unknown { background: var(--unknown); }

/* ---------- host cards ---------- */
.hosts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 4px;
}

.host {
  min-width: 0;
  background: rgba(251, 247, 238, 0.93);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 13px 12px;
}

.host-top {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 2px;
}

.host-name {
  font-family: "Hiragino Mincho ProN", "Songti SC", serif;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.06em;
}

.host-up { margin-left: auto; font-size: 9px; color: var(--dim); font-variant-numeric: tabular-nums; }

.metrics {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 9px;
  font-variant-numeric: tabular-nums;
}

.metric { display: flex; flex-direction: column; gap: 1px; }
.metric b { font-size: 15px; font-weight: 600; }
.metric span { font-size: 8px; color: var(--dim); letter-spacing: 0.14em; text-transform: uppercase; }

.bars { margin-top: 9px; display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 30px 1fr 34px; align-items: center; gap: 7px; }
.bar-row em { font-style: normal; font-size: 9px; color: var(--dim); letter-spacing: 0.06em; }
.bar-row i { font-style: normal; font-size: 9px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 3px; border-radius: 2px; background: #e7dfd0; overflow: hidden; }
.bar > s { display: block; height: 100%; border-radius: 2px; background: var(--indigo); }
.bar.warn > s { background: var(--warn); }
.bar.crit > s { background: var(--crit); }

/* ---------- panels ---------- */
.panel {
  min-width: 0;
  background: rgba(251, 247, 238, 0.93);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 14px;
  margin-bottom: 2px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 16px 0 0;
}

.panel-head h2 {
  margin: 0 0 8px;
  font-family: "Hiragino Mincho ProN", "Songti SC", serif;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.22em;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.panel-head h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.source { font-size: 10px; color: var(--dim); letter-spacing: 0.04em; white-space: nowrap; margin-left: 10px; }

/* ---------- nodes ---------- */
.nodes { display: grid; }

.node {
  display: grid;
  grid-template-columns: 38px 80px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.node:last-child { border-bottom: 0; }

.node-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: "Hiragino Mincho ProN", "Songti SC", serif;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.node-delay { font-variant-numeric: tabular-nums; }
.node-delay b { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.node-delay span { font-size: 9px; color: var(--dim); margin-left: 2px; }

.node-spark { min-width: 0; }
.spark { width: 100%; min-width: 0; height: 38px; display: block; }
.axis {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.axis span { white-space: nowrap; }
.axis .now { color: var(--text); }

/* ---------- services ---------- */
.services { display: grid; }

.svc {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line-soft);
}
.svc:last-child { border-bottom: 0; }

.svc-name {
  font-family: "Hiragino Mincho ProN", "Songti SC", serif;
  font-size: 13px;
  letter-spacing: 0.03em;
}

.svc-checks { margin-left: auto; display: flex; gap: 5px; }
.svc-checks i { width: 5px; height: 5px; border-radius: 50%; background: var(--unknown); }
.svc-checks i.ok { background: var(--ok); }
.svc-checks i.warn { background: var(--warn); }
.svc-checks i.crit { background: var(--crit); }

.svc-state { font-size: 10px; color: var(--muted); min-width: 28px; text-align: right; }

/* ---------- auth ---------- */
.auth {
  min-height: 80vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 300px;
  text-align: center;
  background: rgba(251, 247, 238, 0.95);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 26px 22px;
}
.auth-card h1 {
  font-family: "Hiragino Mincho ProN", "Songti SC", serif;
  font-size: 13px;
  letter-spacing: 0.22em;
  margin: 0 0 6px;
}
.auth-card p { font-size: 12px; color: var(--muted); margin: 0 0 16px; }
.auth-card input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #fffdf8;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.auth-card button {
  margin-top: 12px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--indigo);
  border-radius: 2px;
  background: var(--indigo);
  color: #f7f4ed;
  font-size: 13px;
  letter-spacing: 0.1em;
  cursor: pointer;
}
.auth-err { margin-top: 10px; font-size: 12px; color: var(--crit); min-height: 16px; }

/* ---------- footer ---------- */
footer {
  margin-top: 20px;
  text-align: center;
  color: var(--dim);
  font-size: 9px;
  letter-spacing: 0.12em;
}
footer .sep { margin: 0 6px; }

/* ---------- refresh ---------- */
.refresh {
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 auto;
  width: 32px; height: 32px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(251, 247, 238, 0.75);
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, color 0.2s ease;
}
.refresh:active { transform: scale(0.92); }
.refresh svg { width: 15px; height: 15px; }
.refresh.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  position: fixed;
  top: 0;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  height: 3px;
  border-radius: 0 0 3px 3px;
  width: 0;
  background: linear-gradient(90deg, var(--indigo), var(--ok));
  opacity: 0;
  transition: width 0.5s ease, opacity 0.25s ease;
  z-index: 10;
  pointer-events: none;
}
body.refreshing .progress { opacity: 1; width: 88%; }
body.refreshing-done .progress { width: 100%; opacity: 0; }

/* ---------- motion ---------- */
.spark path {
  stroke-dasharray: 1200;
  stroke-dashoffset: 0; /* 若动画未执行也保持可见 */
  animation: draw 0.9s ease-out;
}
@keyframes draw {
  from { stroke-dashoffset: 1200; }
  to { stroke-dashoffset: 0; }
}

.node-delay b, .metrics b { animation: pop 0.45s ease; }
@keyframes pop {
  from { opacity: 0.45; transform: translateY(1px) scale(1.04); }
  to { opacity: 1; transform: none; }
}

.host, .svc, .node { transition: background 0.4s ease; }
body.refreshing .host, body.refreshing .svc, body.refreshing .node { background: #f6f0e2; }

@media (prefers-reduced-motion: reduce) {
  .spark path, .node-delay b, .metrics b { animation: none; }
}

@media (max-width: 360px) {
  .hosts { grid-template-columns: 1fr; }
  .node { grid-template-columns: 34px 72px minmax(0, 1fr); }
}

/* ---------- detail sheet ---------- */
.host, .node { cursor: pointer; }

.overlay { position: fixed; inset: 0; z-index: 60; }
.overlay[hidden] { display: none; }
.overlay-bg {
  position: absolute; inset: 0;
  background: rgba(22, 27, 36, 0.42);
  backdrop-filter: blur(3px);
}

.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: #fbf7ee;
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -10px 34px rgba(35, 48, 74, 0.14);
  padding-bottom: env(safe-area-inset-bottom);
  animation: sheet-up 0.24s ease;
}
@keyframes sheet-up {
  from { transform: translateY(26px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

.sheet-grab {
  width: 34px; height: 4px;
  border-radius: 99px;
  background: var(--line);
  margin: 8px auto 0;
}

.sheet-head {
  max-width: none;
  margin: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 18px 4px;
}
.sheet-head h3 {
  margin: 0;
  font-family: "Hiragino Mincho ProN", "Songti SC", serif;
  font-size: 15px;
  letter-spacing: 0.08em;
}

.icon-btn {
  -webkit-appearance: none; appearance: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 18px 22px;
}

.detail-sec { margin-top: 14px; }
.detail-sec h4 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 8px;
  font-family: "Hiragino Mincho ProN", "Songti SC", serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: var(--muted);
}
.detail-sec h4::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.drow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px;
  align-items: center;
  gap: 8px;
  padding: 5px 0 1px;
}
.drow .nm {
  font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.drow .vl {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.dbar {
  grid-column: 1 / 3;
  height: 3px;
  border-radius: 2px;
  background: #e7dfd0;
  overflow: hidden;
}
.dbar s { display: block; height: 100%; border-radius: 2px; background: var(--indigo); }

.dmeta {
  margin-top: 12px;
  text-align: right;
  font-size: 10px;
  color: var(--dim);
}
.empty { padding: 26px 0; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- full chart ---------- */
.chart-panel {
  position: absolute; inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 14px calc(8px + env(safe-area-inset-bottom));
}
.chart-head { max-width: none; margin: 0; display: flex; align-items: center; justify-content: space-between; }
.chart-head h3 {
  margin: 0;
  font-family: "Hiragino Mincho ProN", "Songti SC", serif;
  font-size: 16px;
  letter-spacing: 0.08em;
}
.chart-tools {
  display: flex; align-items: center; justify-content: space-between;
  margin: 10px 0 2px;
}
.ranges { display: flex; gap: 6px; }
.ranges button {
  -webkit-appearance: none; appearance: none;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.ranges button.on { background: var(--indigo); border-color: var(--indigo); color: #f7f4ed; }
.chart-stat { font-size: 10px; color: var(--dim); font-variant-numeric: tabular-nums; }

.chart-wrap { position: relative; flex: 1; min-height: 0; margin-top: 4px; }
#chart-svg { width: 100%; height: 100%; display: block; touch-action: none; }
.chart-hint { padding-top: 6px; text-align: center; font-size: 10px; color: var(--dim); letter-spacing: 0.06em; }

.chart-tip {
  position: absolute;
  pointer-events: none;
  padding: 4px 7px;
  border-radius: 3px;
  background: #23304a;
  color: #f7f4ed;
  font-size: 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transform: translate(-50%, -130%);
}
.chart-tip[hidden] { display: none; }
