:root {
  --bg: #0b0f14;
  --surface: #151b23;
  --surface-2: #1c242e;
  --border: #26303c;
  --fg: #e8eef6;
  --muted: #8b97a6;
  --accent: #4c9aff;
  --danger: #ff5f56;
  --ok: #34c759;
  --warn: #ffb020;
  --radius: 14px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(24px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h1 { font-size: 19px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }

.muted { color: var(--muted); font-size: 12.5px; }

.pill {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.pill.online { color: var(--ok); border-color: rgba(52, 199, 89, .35); }
.pill.offline { color: var(--danger); border-color: rgba(255, 95, 86, .35); }

.alarm {
  background: rgba(255, 95, 86, .14);
  border: 1px solid rgba(255, 95, 86, .45);
  color: #ffb4ae;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 650;
  margin-bottom: 12px;
}

.chips {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chip span { font-size: 17px; }
.chip b { font-size: 12.5px; font-weight: 600; }
.chip small { color: var(--muted); font-size: 10.5px; }
.chip.good b { color: var(--ok); }
.chip.bad b { color: var(--danger); }
.chip.warn b { color: var(--warn); }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg);
  border-radius: var(--radius);
  padding: 14px 12px;
  font-size: 14.5px;
  font-weight: 550;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: scale(.975); background: #232d39; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.metric .k { color: var(--muted); font-size: 11.5px; }
.metric .v { font-size: 15px; font-weight: 600; margin-top: 2px; }

.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 12px;
}
.tab {
  flex: 1;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px;
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.tab.active { background: var(--surface-2); color: var(--fg); font-weight: 600; }

.panel { margin-bottom: 16px; }
.row { display: flex; gap: 6px; margin-bottom: 10px; }
.small {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.small.active { color: var(--fg); border-color: var(--accent); }

.events { list-style: none; margin: 0; padding: 0; }
.events li {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(38, 48, 60, .6);
  font-size: 13.5px;
}
.events time { color: var(--muted); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.events li.alarm { color: #ffb4ae; }

canvas { width: 100%; height: auto; display: block; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  max-width: 88vw;
  text-align: center;
}
.toast.error { border-color: rgba(255, 95, 86, .5); color: #ffb4ae; }
.toast.ok { border-color: rgba(52, 199, 89, .5); color: #b8f5c8; }

.hidden { display: none !important; }

footer { margin-top: 18px; text-align: center; }
