:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #fff);
  --text: var(--tg-theme-text-color, #111);
  --muted: var(--tg-theme-hint-color, #888);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --section-bg: var(--tg-theme-secondary-bg-color, #f4f4f5);
  --ok: #2ecc71;
  --warn: #e67e22;
  --fail: #c0392b;
  --off: #95a5a6;
  --error: #c0392b;
}

* { box-sizing: border-box; }

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

header {
  padding: max(16px, env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) 16px 8px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

header h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 600;
  flex: 1;
}

.back-to-launcher {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--section-bg);
}
.back-to-launcher:active { opacity: 0.6; }

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

main { padding: 8px 16px 96px; }

section {
  background: var(--section-bg);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 8px 0;
}

section h2 {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 8px;
}

.kv {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(128,128,128,0.15);
}
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv strong { font-variant-numeric: tabular-nums; font-weight: 600; }

.error { color: var(--error); }

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 10px;
}
.pill {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  color: #fff;
}
.pill-ok { background: var(--ok); }
.pill-warn { background: var(--warn); }
.pill-fail { background: var(--fail); }
.pill-off { background: var(--off); }

.component-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.component-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(128,128,128,0.12);
}
.component-list li:last-child { border-bottom: 0; }
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-fail { background: var(--fail); }
.dot-off { background: var(--off); }
.comp-name { font-weight: 600; flex-shrink: 0; }
.comp-detail { color: var(--muted); font-size: 13px; flex: 1; text-align: right; }
.comp-off-tag { font-size: 11px; color: var(--off); text-transform: uppercase; letter-spacing: 0.04em; margin-left: 4px; }

.agent-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.agent-list li {
  display: grid;
  grid-template-columns: 1.6em 1fr auto;
  align-items: baseline;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(128,128,128,0.12);
}
.agent-list li:last-child { border-bottom: 0; }
.agent-glyph { font-size: 18px; }
.agent-label { font-weight: 600; }
.agent-meta { color: var(--muted); font-size: 13px; text-align: right; }
.agent-summary { grid-column: 2 / -1; color: var(--muted); font-size: 12px; margin-top: 2px; }

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid rgba(128,128,128,0.2);
  display: flex;
  align-items: center;
  gap: 12px;
}

button, .link-btn {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:disabled { opacity: 0.5; }

#staleness.warn { color: var(--warn); }
#staleness.alarm { color: var(--fail); }
