:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #17202a;
  --muted: #66727f;
  --line: #e2e6ea;
  --up: #16a34a;
  --degraded: #d97706;
  --down: #dc2626;
  --unknown: #94a3b8;
  --none: #e5e7eb;
  --accent: #2563eb;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --card: #171e26;
    --text: #e6ebf0;
    --muted: #8a96a3;
    --line: #26303b;
    --none: #2a333d;
    --accent: #60a5fa;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand .site { font-weight: 500; color: var(--muted); }

nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
nav form { margin: 0; }

main { max-width: 1100px; margin: 0 auto; padding: 1rem; }

h1 { font-size: 1.35rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.6rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.4rem; }

.card, .host {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.9rem;
}

.narrow { max-width: 26rem; margin: 3rem auto; text-align: center; }

.summary { display: flex; gap: 0.5rem; margin-bottom: 0.9rem; flex-wrap: wrap; }
.pill { padding: 0.2rem 0.7rem; border-radius: 999px; font-size: 0.85rem; font-weight: 600; color: #fff; }
.pill.up { background: var(--up); }
.pill.degraded { background: var(--degraded); }
.pill.down { background: var(--down); }

.host { border-left: 4px solid var(--unknown); }
.host.up { border-left-color: var(--up); }
.host.degraded { border-left-color: var(--degraded); }
.host.down { border-left-color: var(--down); }

.host-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.host-head .name { font-weight: 650; font-size: 1.05rem; color: var(--text); }
.host-head .peer { margin-left: auto; }

.dot { display: inline-block; width: 0.65rem; height: 0.65rem; border-radius: 50%; background: var(--unknown); }
.dot.up { background: var(--up); }
.dot.degraded { background: var(--degraded); }
.dot.down { background: var(--down); }

.badge {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.5rem;
  border-radius: 4px;
  color: #fff;
  background: var(--unknown);
}
.badge.up { background: var(--up); }
.badge.degraded { background: var(--degraded); }
.badge.down { background: var(--down); }

/* Heartbeat bars, one pill per half hour over the last day. */
.beats { display: flex; gap: 3px; margin: 0.7rem 0 0.5rem; height: 26px; }
.beat { flex: 1 1 0; min-width: 2px; border-radius: 4px; background: var(--none); }
.beat.up { background: var(--up); }
.beat.degraded { background: var(--degraded); }
.beat.down { background: var(--down); }
.beat.unknown { background: var(--unknown); }
.beat:hover { opacity: 0.75; }

.host-foot { display: flex; gap: 0.3rem 1.1rem; flex-wrap: wrap; font-size: 0.88rem; }
.host-foot strong { font-weight: 650; }

.reasons { margin: 0.6rem 0 0; padding-left: 1.1rem; font-size: 0.9rem; }
.reasons li { margin: 0.15rem 0; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0.9rem; margin-bottom: 0.9rem; }

.chart { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0.8rem; }
.chart figcaption { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.4rem; }
.chart figcaption .muted { font-weight: 400; }
.chart svg { width: 100%; height: 90px; display: block; }
.chart polyline { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart circle { fill: var(--accent); }
.chart .axis { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
td, th { text-align: left; padding: 0.35rem 0.5rem 0.35rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); }
thead th { position: sticky; top: 0; background: var(--card); }
.kv th { width: 11rem; font-weight: 400; }
.table-wrap { overflow-x: auto; }

.events { list-style: none; margin: 0; padding: 0; }
.events li { padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
.events time { display: inline-block; min-width: 11.5rem; color: var(--muted); font-size: 0.85rem; }
.events pre {
  margin: 0.3rem 0 0;
  white-space: pre-wrap;
  font: 0.85rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
}

button { font: inherit; cursor: pointer; }
button.primary {
  /* Fixed blue: white text keeps its contrast in both themes. */
  background: #2563eb;
  color: #fff;
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  padding: 0.65rem 1.2rem;
  font-weight: 600;
  margin-top: 0.5rem;
}
button.primary:disabled { opacity: 0.6; cursor: progress; }
button.link { background: none; border: 0; color: var(--accent); padding: 0; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.message { min-height: 1.4em; margin-top: 0.9rem; }
.message.error { color: var(--down); }

code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }

/* Touch screens: links and buttons get finger-sized hit areas. */
@media (pointer: coarse) {
  nav a, nav button.link, .brand { display: inline-flex; align-items: center; min-height: 44px; }
  .host-head .name, .events a { display: inline-flex; align-items: center; min-height: 44px; }
  .top { padding-top: 0.25rem; padding-bottom: 0.25rem; }
}

@media (max-width: 600px) {
  .host-head .peer { margin-left: 0; width: 100%; }
  .beats { gap: 2px; height: 22px; }
  .events time { display: block; }
}
