:root {
  color-scheme: dark;
  --bg: #07101d;
  --bg-soft: #0b1626;
  --panel: rgba(17, 31, 50, 0.92);
  --panel-strong: #101d30;
  --line: rgba(148, 163, 184, 0.16);
  --text: #f8fafc;
  --muted: #92a4ba;
  --accent: #2ea6ff;
  --accent-soft: rgba(46, 166, 255, 0.14);
  --good: #33d17a;
  --warning: #ffb84d;
  --danger: #ff6b6b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
  --radius-lg: 22px;
  --radius-md: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 86% -8%, rgba(46, 166, 255, 0.18), transparent 32%),
    linear-gradient(180deg, #081321 0%, var(--bg) 45%, #050b14 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }
.app-shell { width: min(100%, 1180px); margin: 0 auto; min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 18px 14px;
  background: rgba(7, 16, 29, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.eyebrow, .section-kicker {
  margin: 0 0 5px;
  color: #71c4ff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.15em;
}
.topbar h1 { margin: 0; font-size: 20px; line-height: 1.15; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 46%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(15, 27, 44, 0.9);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
}
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 4px rgba(255, 184, 77, 0.1); }
.status-pill[data-state="live"] .status-dot { background: var(--good); box-shadow: 0 0 0 4px rgba(51, 209, 122, 0.1); }
.status-pill[data-state="error"] .status-dot { background: var(--danger); }

main { padding: 18px 16px calc(92px + var(--safe-bottom)); }
.hero-card, .panel, .safety-note {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, rgba(18, 34, 55, 0.96), rgba(11, 23, 39, 0.94));
  box-shadow: var(--shadow);
}
.hero-card {
  display: grid;
  gap: 18px;
  padding: 20px;
}
.hero-card h2, .panel h2 { margin: 0; font-size: 21px; }
.muted { margin: 9px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.relay-state {
  display: flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
  padding: 12px 14px;
  border-radius: 15px;
  background: rgba(51, 209, 122, 0.08);
  border: 1px solid rgba(51, 209, 122, 0.18);
}
.relay-icon { color: var(--good); font-size: 16px; }
.relay-state div { display: grid; gap: 2px; }
.relay-state strong { font-size: 14px; }
.relay-state span:last-child { color: var(--muted); font-size: 11px; }
.relay-state[data-state="off"] { background: rgba(148, 163, 184, 0.07); border-color: var(--line); }
.relay-state[data-state="off"] .relay-icon { color: #7c8ca0; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.metric-card {
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(12, 25, 43, 0.92);
}
.metric-label { display: block; color: var(--muted); font-size: 11px; }
.metric-value { display: block; margin-top: 7px; font-size: 25px; font-weight: 800; letter-spacing: -0.03em; }
.metric-hint { display: block; margin-top: 3px; color: #7e91a9; font-size: 10px; }
.metric-card[data-tone="good"] .metric-value { color: #62e49c; }
.metric-card[data-tone="warning"] .metric-value { color: #ffc568; }
.metric-card[data-tone="danger"] .metric-value { color: #ff8989; }

.panel { margin-top: 14px; padding: 18px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-heading.compact { margin-bottom: 12px; }
.counter { min-width: 34px; padding: 6px 9px; text-align: center; border-radius: 999px; background: var(--accent-soft); color: #8bd1ff; font-size: 12px; font-weight: 700; }
.route-list, .activity-list { display: grid; gap: 10px; }
.route-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(6, 16, 29, 0.52);
}
.route-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.route-title { display: flex; align-items: center; gap: 8px; font-weight: 750; font-size: 14px; }
.route-badge { padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; background: rgba(51, 209, 122, 0.1); color: #70e7a7; }
.route-badge.off { background: rgba(148, 163, 184, 0.08); color: #94a3b8; }
.route-path { display: grid; grid-template-columns: minmax(0, 1fr) 24px minmax(0, 1fr); align-items: center; gap: 6px; }
.channel-chip { min-width: 0; padding: 9px 10px; border-radius: 11px; background: rgba(255,255,255,0.035); color: #cbd5e1; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-arrow { color: #5b7088; text-align: center; }
.route-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.meta-chip { padding: 5px 7px; border-radius: 8px; background: rgba(46,166,255,0.08); color: #91cfff; font-size: 9px; }
.meta-chip.health-healthy { color: #75e8aa; background: rgba(51,209,122,0.08); }
.meta-chip.health-error, .meta-chip.health-degraded { color: #ffb2a5; background: rgba(255,107,107,0.08); }
.empty-state { padding: 24px 12px; color: var(--muted); text-align: center; font-size: 13px; }

.split-panel { display: grid; gap: 22px; }
.reconcile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.reconcile-item { padding: 12px; border-radius: 13px; background: rgba(255,255,255,0.035); }
.reconcile-item strong { display: block; font-size: 19px; }
.reconcile-item span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.activity-item { display: grid; grid-template-columns: 8px 1fr; gap: 10px; align-items: start; padding: 11px 0; border-bottom: 1px solid rgba(148,163,184,0.1); }
.activity-item:last-child { border-bottom: 0; }
.activity-dot { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--accent); }
.activity-title { font-size: 12px; font-weight: 700; }
.activity-detail, .activity-time { margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.45; }

.safety-note { display: flex; gap: 12px; margin-top: 14px; padding: 15px 16px; background: rgba(20, 32, 49, 0.72); box-shadow: none; }
.safety-icon { font-size: 18px; }
.safety-note strong { font-size: 12px; }
.safety-note p { margin: 4px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(100%, 1180px);
  transform: translateX(-50%);
  padding: 9px 12px calc(9px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(7, 16, 29, 0.9);
  backdrop-filter: blur(18px);
}
.nav-item {
  appearance: none;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 9px 8px;
  background: transparent;
  color: #7f91a7;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.nav-item.active { background: var(--accent-soft); color: #84ccff; }

@media (min-width: 720px) {
  main { padding: 28px 28px 110px; }
  .topbar { padding-left: 30px; padding-right: 30px; }
  .hero-card { grid-template-columns: 1fr auto; align-items: center; padding: 26px; }
  .metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  .split-panel { grid-template-columns: 1fr 1.2fr; gap: 24px; }
  .route-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: no-preference) {
  .metric-card, .route-card { transition: transform 160ms ease, border-color 160ms ease; }
  .metric-card:hover, .route-card:hover { transform: translateY(-1px); border-color: rgba(94, 180, 255, 0.25); }
}
