:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --fg: #e6edf3;
  --muted: #8b949e;
  --accent: #22c55e;
  --border: #30363d;
  --paid: #f59e0b;
  --auth: #3b82f6;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.1em; color: var(--fg); }
.brand span { color: var(--accent); }
header > a:not(.brand), header button {
  color: var(--fg);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font: inherit;
}
header button:hover, header > a:hover { border-color: var(--accent); text-decoration: none; }
header > a.current, header > a[aria-current='page'] { border-color: var(--accent); color: var(--accent); }

.searchwrap { position: relative; flex: 1 1 220px; max-width: 420px; }
#search {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
}
#searchResults {
  position: absolute;
  top: 110%;
  left: 0;
  right: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.search-hit {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: none;
  border: none;
  color: var(--fg);
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.search-hit:hover { background: var(--bg); }

#filterbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  align-items: center;
}
#filterbar[hidden] { display: none; }
#filterbar fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; display: flex; gap: 10px; flex-wrap: wrap; }
#filterbar legend { padding: 0 6px; color: var(--muted); font-size: 0.85em; }
#filterbar label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
#nipChips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-check { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; }
.sel { display: flex; flex-direction: column; gap: 2px; font-size: 0.85em; color: var(--muted); }
.sel select { padding: 5px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--fg); }

.btn {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { border-color: var(--accent); }
.btn.small { padding: 3px 8px; font-size: 0.85em; }
.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.4em;
  cursor: pointer;
  line-height: 1;
}
.icon-btn:hover { color: var(--fg); }

main { flex: 1; position: relative; min-height: 320px; }
#map { position: absolute; inset: 0; }

.stats-strip {
  position: absolute;
  left: 10px;
  bottom: 8px;
  z-index: 10;
  background: rgba(13, 17, 23, 0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.9em;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  max-width: min(92vw, 760px);
  backdrop-filter: blur(4px);
}
.stats-strip .dot { color: var(--muted); }
.stats-strip b { font-weight: 700; }
.stats-strip a { margin-left: 4px; }

.overlay-btn { position: absolute; right: 10px; bottom: 44px; z-index: 10; background: rgba(13,17,23,0.85); }

.pulse-rate {
  position: absolute;
  left: 10px;
  bottom: 46px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(13, 17, 23, 0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.8em;
  color: var(--fg);
  backdrop-filter: blur(4px);
}
.pulse-rate .live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: live-dot 2s ease-in-out infinite;
}
@keyframes live-dot { 50% { opacity: 0.25; } }

.nm-proj-ctrl { margin: 0; }
.nm-proj-btn {
  background: rgba(22, 27, 34, 0.9);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font: inherit;
  font-size: 0.85em;
}
.nm-proj-btn:hover { border-color: var(--accent); }
.nm-proj-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.says { font-style: italic; overflow-wrap: anywhere; }

.cards.records .card b { font-size: 1.25em; }
.cards.records .card { min-width: 200px; flex: 1 1 200px; }
.cards .card.hero b { color: var(--paid); font-size: 2.1em; }
.cards .card.hero { flex: 1 1 240px; }

.changes-list { display: flex; flex-direction: column; gap: 4px; margin: 16px 0; }
.change-row {
  display: flex;
  gap: 12px;
  align-items: baseline;
  flex-wrap: wrap;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg2);
}
.change-row time { color: var(--muted); font-size: 0.82em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.change-row .chg-relay { overflow-wrap: anywhere; min-width: 120px; }
.change-row .chg {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 0.8em;
  white-space: nowrap;
}
.change-row .chg.chg-pos { color: var(--accent); border-color: var(--accent); }
.change-row .chg.chg-neg { color: #ef4444; border-color: #ef4444; }
.change-row .chg.chg-info { color: var(--auth); border-color: var(--auth); }
.change-row .chg-detail { font-size: 0.85em; flex-basis: 100%; }

.nearby {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 15;
  width: 300px;
  max-width: calc(100vw - 20px);
  background: rgba(22, 27, 34, 0.96);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nearby h3 { margin: 0 0 6px; font-size: 0.95em; }
.nearby .nearby-close { position: absolute; top: 4px; right: 8px; }
.nearby .search-hit { border-radius: 6px; }

.chip.ach {
  border-color: var(--paid);
  color: var(--paid);
  background: rgba(245, 158, 11, 0.08);
}
.ach-chips { flex-wrap: wrap; }
.npub-full { overflow-wrap: anywhere; font-size: 0.85em; }
.stattable td.st.online { color: var(--accent); }
.stattable td.st.offline { color: var(--muted); }

.map-fallback { padding: 40px 16px; text-align: center; color: var(--muted); }
.map-fallback a { color: var(--fg); }
.locate-note {
  position: absolute;
  right: 10px;
  bottom: 82px;
  z-index: 10;
  max-width: 230px;
  font-size: 0.75em;
  background: rgba(13,17,23,0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}

#panel {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 20;
  width: 340px;
  max-width: calc(100vw - 20px);
  max-height: calc(100% - 20px);
  overflow-y: auto;
  background: rgba(22, 27, 34, 0.96);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.panel-head h2 { margin: 0; font-size: 1.05em; overflow-wrap: anywhere; }
.status-line { display: flex; gap: 10px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.st.online { color: var(--accent); }
.st.offline { color: var(--muted); }
.url-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.url-row code { overflow-wrap: anywhere; }
.panel-body .row { display: flex; gap: 10px; margin: 6px 0; align-items: baseline; }
.panel-body .label { color: var(--muted); min-width: 110px; flex-shrink: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.78em;
  color: var(--muted);
}
.npub { font-size: 0.85em; }
.desc { color: var(--muted); font-size: 0.9em; }

.spark { display: flex; align-items: flex-end; gap: 2px; height: 40px; flex: 1; min-width: 160px; }
.spark .bar { flex: 1; border-radius: 2px 2px 0 0; background: #30363d; min-height: 2px; }
.spark .bar.ok { background: var(--accent); }
.spark .bar.mid { background: var(--paid); }
.spark .bar.bad { background: #ef4444; }

footer {
  display: flex;
  gap: 14px;
  padding: 8px 16px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  font-size: 0.85em;
  align-items: center;
}

#drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(360px, 92vw);
  z-index: 40;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
}
#drawer[hidden] { display: none; }
#drawer h2 { margin-top: 0; }
.legend { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 10px; }
.legend .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.legend .dot.online { background: var(--accent); }
.legend .dot.offline { background: #6b7280; }
.legend .dot.paid { background: none; border: 3px solid var(--paid); }
.legend .dot.auth { background: none; border: 3px solid var(--auth); }

.listwrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; width: 100%; }
.listwrap table { border-collapse: collapse; width: 100%; font-size: 0.92em; }
.listwrap th, .listwrap td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.listwrap th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--bg); }
.listwrap td.st.online { color: var(--accent); }
.listwrap td.st.offline { color: var(--muted); }

article.page { max-width: 760px; margin: 0 auto; padding: 24px 16px 80px; }
article.page h1 { font-size: 1.5em; }
article.page pre {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}

/* relay detail page (/relay/<id>/) and stats page (/stats/) */
.relaywrap { overflow-y: auto; }
.relaycard h1 { margin-bottom: 4px; overflow-wrap: anywhere; }
.relaycard .url-line { margin-top: 0; }
.relaycard .url-line code { overflow-wrap: anywhere; }
.relayrows { border-top: 1px solid var(--border); margin-top: 12px; }
.relayrows .row { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); align-items: baseline; }
.relayrows .label { color: var(--muted); min-width: 140px; flex-shrink: 0; }
.relayrows .value { overflow-wrap: anywhere; }
.relay-spark { height: 56px; max-width: 420px; }
.badge-img { background: var(--bg2); border-radius: 3px; }
article.page h2 { font-size: 1.1em; margin-top: 28px; }
article.page h3 { font-size: 0.95em; color: var(--muted); }

.cards { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 20px;
  min-width: 140px;
  display: flex;
  flex-direction: column;
}
.card b { font-size: 1.6em; }
.card span { color: var(--muted); font-size: 0.85em; }

.stattable { border-collapse: collapse; width: 100%; font-size: 0.92em; }
.stattable th, .stattable td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.stattable th { color: var(--muted); font-weight: 600; }
.bar-wrap { background: var(--bg2); border-radius: 3px; height: 8px; min-width: 120px; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 3px; }

.trend svg { width: 100%; max-width: 720px; height: auto; display: block; }

@media (max-width: 700px) {
  #panel {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 55vh;
    border-radius: 12px 12px 0 0;
  }
  .stats-strip { font-size: 0.8em; max-width: calc(100vw - 20px); }
  .locate-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* /find/ wizard */
.find-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin: 16px 0; }
.find-results { display: flex; flex-direction: column; gap: 10px; margin-bottom: 28px; }
.find-card h3 { margin: 0 0 6px 0; font-size: 1.05em; }
.find-card .url-line { margin: 0 0 8px 0; }
.find-submit { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 8px 0; }
.find-submit input[type='text'] {
  flex: 1 1 260px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
