:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7785;
  --line: #e3e8ee;
  --empty: #dfe4ea;
  --up: #2fb36d;
  --warn: #f0a020;
  --down: #e5484d;
  --ack: #8b7cf6;
  --paused: #9aa5b1;
  --accent: #2f80ed;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --card: #161b22;
    --text: #e6edf3;
    --muted: #8b949e;
    --line: #262d36;
    --empty: #2b323b;
    --accent: #58a6ff;
    color-scheme: dark;
  }
}

* { 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;
}
header, main, footer { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

header {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  padding-top: 28px; padding-bottom: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.logo {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--up); box-shadow: 0 0 0 4px color-mix(in srgb, var(--up) 25%, transparent);
}
.tag {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.summary { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px; background: var(--card);
  border: 1px solid var(--line); font-size: 13px; font-variant-numeric: tabular-nums;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
/* The pills filter the list: pressed, tinted in their colour; empty, faint. */
button.pill { cursor: pointer; color: var(--text); font: inherit; font-size: 13px; }
button.pill:hover { border-color: var(--c); }
button.pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pill[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--card)); }
.pill.zero { color: var(--muted); }
.pill.zero::before { opacity: 0.35; }
.pill.health { font-weight: 600; }
.pill-sep { width: 1px; align-self: stretch; margin: 2px 2px; background: var(--line); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; margin-bottom: 14px; }
#find, #sort, #order {
  padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
#find { flex: 1 1 220px; }
.order { display: inline-flex; gap: 4px; }
#order { cursor: pointer; min-width: 36px; }
:is(#find, #sort, #order):hover { border-color: var(--accent); }
.tagbar { display: flex; flex-wrap: wrap; gap: 6px; flex-basis: 100%; }
.tagbar[hidden] { display: none; }
.chip {
  padding: 2px 10px; border-radius: 999px; cursor: pointer; font-size: 13px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.link { all: unset; cursor: pointer; color: var(--accent); text-decoration: underline; }
.link:focus-visible { outline: 2px solid var(--accent); }

.targets { display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--muted); }
.target {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden;
}
/* The head expands the row on a click anywhere; for the keyboard, a button
   covers it, under the edit controls (later siblings, positioned). */
.head {
  position: relative; cursor: pointer;
  display: grid; grid-template-columns: auto minmax(120px, 220px) 1fr auto;
  align-items: center; gap: 16px; padding: 14px 18px;
}
.head > :not(.expand) { position: relative; }
.expand { all: unset; position: absolute; inset: 0; border-radius: 12px; cursor: pointer; }
.expand:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.head.editing { cursor: default; grid-template-columns: auto 1fr auto; }
.head.editing .beats { display: none; }
.badge {
  min-width: 64px; text-align: center; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: #fff; background: var(--c);
}
.who { display: flex; flex-direction: column; min-width: 0; }
.line { display: flex; align-items: center; gap: 4px; min-width: 0; }
.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.host { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tagline { margin-top: 3px; }
.tags { display: flex; gap: 4px; overflow: hidden; }
.tags[hidden] { display: none; }
.rtag {
  font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 999px; white-space: nowrap;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
}
.rtag.on { border-color: var(--accent); color: var(--accent); }

/* Edit buttons: shown on hover or focus where there is a mouse, always
   (faintly) on touch screens. */
.edit-btn {
  all: unset; cursor: pointer; flex: none; font-size: 12px; line-height: 16px;
  padding: 1px 5px; border-radius: 6px; color: var(--muted); opacity: 0;
}
.head:hover .edit-btn, .head:focus-within .edit-btn, .edit-btn[aria-expanded="true"] { opacity: 1; }
@media (hover: none) { .edit-btn { opacity: 0.7; } }
.edit-btn:hover, .edit-btn[aria-expanded="true"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.edit-btn:focus-visible { opacity: 1; outline: 2px solid var(--accent); }
.edit-tags.empty { border: 1px dashed var(--line); }
.row-note { font-size: 12px; color: var(--muted); margin-top: 3px; white-space: normal; }
.row-note:empty { display: none; }
.row-note.error { color: var(--down); }
.who-editor { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.who-editor .row-note { flex-basis: 100%; }
/* Every editing field alike: filled, with the accent while focused. */
.who-editor input, .tag-popover .tag-input {
  flex: 1 1 160px; min-width: 0; padding: 5px 9px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.who-editor input:focus, .tag-popover .tag-input:focus {
  outline: none; border-color: var(--accent); background: var(--card);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* The add form's tags: a box like its inputs, the picker under it. */
.add-tags {
  flex: 1 1 180px; position: relative; cursor: pointer; min-height: 36px;
  display: flex; align-items: center; padding: 4px 8px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card);
}
.add-tags:hover { border-color: var(--accent); }
.add-tags .tagline { margin-top: 0; position: static; flex-wrap: wrap; }
.add-tags .tags { flex-wrap: wrap; }
.add-tags .edit-btn { opacity: 1; }
.add-tags .tag-popover { top: calc(100% + 4px); }

.beats { display: flex; gap: 3px; justify-content: flex-end; min-width: 0; overflow: hidden; height: 26px; }
.beat { flex: 0 0 6px; border-radius: 3px; background: var(--c, var(--empty)); }
.beat:hover { transform: scaleY(1.15); }

.figures { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; min-width: 92px; }
.uptime { font-weight: 600; }
.latency { color: var(--muted); font-size: 13px; }

.detail { border-top: 1px solid var(--line); padding: 16px 18px 18px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 180px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .area { fill: color-mix(in srgb, var(--accent) 15%, transparent); }
.chart .sample { fill: var(--muted); opacity: 0.08; }
.chart .band { fill: color-mix(in srgb, var(--accent) 22%, transparent); }
.chart .rtt { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; }
.chart .loss { fill: var(--down); opacity: 0.7; }
.chart .partial { fill: var(--warn); opacity: 0.7; }
.chart .cursor { stroke: var(--muted); stroke-dasharray: 3 3; }
.tip {
  position: absolute; top: 4px; pointer-events: none; white-space: nowrap;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 8px; font-size: 12px; box-shadow: 0 4px 12px rgb(0 0 0 / 0.12);
}
.stats { display: flex; flex-wrap: wrap; gap: 24px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.stats b { display: block; color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }
/* A thin rule sets the trace apart from the statistics above it. */
.trace { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.trace-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-size: 14px; }
.trace-head button {
  font: inherit; font-size: 13px; padding: 3px 10px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.trace-head button:hover { border-color: var(--accent); }
.trace-head button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.trace-head button.copied { border-color: var(--accent); color: var(--accent); }
.hops-wrap { overflow-x: auto; margin-top: 8px; }
.hops { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hops th { text-align: right; font-weight: 500; color: var(--muted); padding: 3px 8px; border-bottom: 1px solid var(--line); cursor: help; }
.hops th:nth-child(2), .hops td.hop-host { text-align: left; }
.hops td { padding: 3px 8px; text-align: right; border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent); }
/* One responder per line: the address whole (an IPv6 one is up to 39
   characters), then its name, cut on the right past 64 characters. */
.hops td.hop-host .hop-addr { display: flex; gap: 0.5em; max-width: 64ch; }
.hops td.hop-host .ip { flex: none; cursor: copy; border-radius: 4px; }
.hops td.hop-host .ip:hover { color: var(--accent); }
.hops td.hop-host .ip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hops td.hop-host .ip.copied { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.hops td.hop-host .name { color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.hops td.hop-host .hop-addr + .hop-addr { color: var(--muted); font-size: 12px; }
.hops .muted { color: var(--muted); }
.hops .bad { color: var(--down); }
.hops .limited { color: var(--muted); text-decoration: underline dotted; cursor: help; }
.hops td.shared { text-decoration: underline dotted; text-underline-offset: 3px; cursor: help; }
.hops td.spark { padding-top: 2px; padding-bottom: 0; }
.hops .spark rect.ok { fill: var(--accent); }
.hops .spark rect.lost { fill: var(--down); opacity: 0.6; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions:empty { display: none; }

button, input { font: inherit; }
.actions button, .add > button {
  padding: 6px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.actions button:hover, .add > button:hover { border-color: var(--accent); }
.actions .danger { color: var(--down); }
.note { color: var(--muted); font-size: 13px; align-self: center; }

/* Tag picker, after GitHub's label picker. */
.tagline { position: relative; }
.target:has(.tag-popover) { overflow: visible; position: relative; z-index: 2; }
.tag-popover {
  /* Above the open detail, whose chart is positioned and comes later. */
  position: absolute; z-index: 10; top: calc(100% + 6px); left: 0; width: min(300px, calc(100vw - 24px)); cursor: default;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18); overflow: hidden;
}
.pop-title { font-size: 12px; font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tag-popover .tag-input { display: block; width: calc(100% - 16px); margin: 8px; }
.pop-list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; border-top: 1px solid var(--line); }
.pop-item {
  all: unset; box-sizing: border-box; cursor: pointer; display: flex; gap: 8px; align-items: center;
  width: 100%; padding: 7px 10px; font-size: 14px; border-bottom: 1px solid var(--line);
}
.pop-item:hover, .pop-item:focus-visible { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.pop-item:disabled { cursor: default; opacity: 0.45; background: none; }
.pop-item .check { width: 14px; color: var(--accent); font-weight: 700; text-align: center; }
.pop-item.create { color: var(--accent); }
.pop-empty { padding: 8px 10px; font-size: 13px; color: var(--muted); }
.pop-note { font-size: 12px; color: var(--muted); padding: 6px 10px; }
.pop-note:empty { display: none; }
.add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 18px; }
.add input {
  flex: 1 1 180px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.add > button { background: var(--accent); border-color: var(--accent); color: #fff; }
.error { color: var(--down); font-size: 13px; flex-basis: 100%; }
.error:empty { display: none; }
.error.demo { color: var(--muted); }

footer { color: var(--muted); font-size: 13px; padding-top: 24px; padding-bottom: 32px; }
footer a { color: inherit; }

@media (max-width: 720px) {
  .head { grid-template-columns: auto 1fr auto; gap: 10px 12px; padding: 12px 14px; }
  .beats { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; }
  /* Phone: the name goes under the address, both cut to fit, so the
     minigraph and the loss stay on screen without scrolling. */
  .hops td.hop-host .hop-addr { flex-direction: column; gap: 0; max-width: 38vw; }
  .hops td.hop-host .ip { overflow: hidden; text-overflow: ellipsis; }
  .hops td.hop-host .name { font-size: 12px; }
  .hops td.hop-host .hop-addr + .hop-addr { margin-top: 2px; }
  .hops th, .hops td { padding-left: 5px; padding-right: 5px; }
  .hops .spark svg { width: 80px; }
}
