:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #7b8496;
  --line: #e6e9f0;
  --brand: #4f46e5;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 8px 24px rgba(31, 36, 48, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  padding: env(safe-area-inset-top) 14px env(safe-area-inset-bottom);
  max-width: 760px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 2px 12px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: 0.5px;
}

.brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.conn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 999px;
  background: #eef0f6;
  color: var(--muted);
  white-space: nowrap;
}

.conn .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9aa3b2;
}

.conn.online { background: #e8f7ee; color: var(--good); }
.conn.online .dot { background: var(--good); box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.12); }
.conn.retry { background: #fff7e6; color: var(--warn); }
.conn.retry .dot { background: var(--warn); }
.conn.offline { background: #fdecec; color: var(--bad); }
.conn.offline .dot { background: var(--bad); }

.alert-banner {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 12px 14px;
  border-radius: 14px;
  margin: 4px 0 12px;
  font-size: 13px;
}

.alert-banner strong { font-size: 14px; }
.alert-banner.hidden { display: none; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 1px;
}

.metric {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.metric small {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.metric.good { color: var(--good); }
.metric.warn { color: var(--warn); }
.metric.bad { color: var(--bad); }

.sub {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.sub span { color: var(--ink); font-weight: 600; }

.announce { margin-top: 12px; }

.announce p {
  margin: 2px 0 4px;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.5;
  min-height: 26px;
}

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

.events {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.events li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  background: #f8f9fc;
  font-size: 13px;
}

.events li.empty {
  justify-content: center;
  color: var(--muted);
  background: transparent;
}

.events .time {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 2px 24px;
  font-size: 12px;
  color: var(--muted);
  gap: 12px;
}

.actions { display: flex; gap: 8px; }

button {
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

button.primary { background: var(--brand); color: #fff; }
button.ghost { background: #eef0f6; color: var(--ink); }
button:active { transform: scale(0.98); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: rgba(31, 36, 48, 0.94);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  max-width: 86vw;
  z-index: 20;
  transition: opacity 0.2s;
}

.toast.hidden { opacity: 0; pointer-events: none; }

body.stale .card { opacity: 0.6; }

@media (max-width: 360px) {
  .grid { grid-template-columns: 1fr; }
  .metric { font-size: 26px; }
}
