/* =====================================================================
   Axona Peer — Phase 2

   Per-row indicators replace the Phase 1 single light.  Every
   connection (bridge + each WebRTC peer) gets its own row with its
   own indicator dot:
     .indicator-red     — solid red, not connected / failed / closed
     .indicator-orange  — dim orange, connecting / signaling / stale;
                          pulses bright on real ping/pong traffic
     .indicator-green   — dim green, open;
                          pulses bright on real ping/pong traffic
   A peer with no actual data-channel traffic looks dim and steady;
   the blink rate now reflects bytes-on-the-wire, not a CSS clock.
   ===================================================================== */

:root {
  --bg:       #0f1419;
  --panel:    #1a2028;
  --panel-2:  #232b35;
  --border:   #2c3540;
  --text:     #d7dde5;
  --muted:    #7a8593;
  --muted-2:  #5a6370;
  --accent:   #5fbfd0;
  --red:      #d05050;
  --orange:   #e88c20;
  --green:    #50c060;
  --shadow-red:    rgba(208,  80,  80, 0.55);
  --shadow-orange: rgba(232, 140,  32, 0.65);
  --shadow-green:  rgba( 80, 192,  96, 0.65);
  /* Orange (not yellow) for the intermediate state.  Yellow sits
     uncomfortably close to green for deuteranopic / protanopic
     viewers (the most common red-green color blindness, ~8% of
     men).  Orange shifts toward red on the hue wheel, giving real
     separation from green at the cost of a less-traditional traffic
     light metaphor — worth it. */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

header {
  margin-bottom: 24px;
}
header h1 {
  font-size: 28px;
  margin: 0 0 4px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
header .subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ── "me" header panel ─────────────────────────────────────────── */

.me {
  background: var(--panel);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
.me-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 13px;
}
.me-label {
  color: var(--muted);
  flex-shrink: 0;
  min-width: 200px;
}
.me-value {
  color: var(--text);
  overflow-wrap: anywhere;
}
.me-value.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}
/* Routing-truth warning: data channels open but unbound (no auth'd
   routing).  Amber + bold so it can't be mistaken for a healthy count. */
.me-value.mesh-degraded {
  color: var(--orange);
  font-weight: 600;
}

/* ── Share QR — floating launcher + modal overlay ──────────────── */

/* Tiny QR in the top-right viewport corner.  Fixed so it stays put
   while the page scrolls.  Background is white because QR codes need
   a light quiet zone around the modules; the rounded corners are
   purely cosmetic and don't intrude on the scannable area. */
.qr-launcher {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  width: 60px;
  height: 60px;
  padding: 5px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.qr-launcher:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}
.qr-launcher:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.qr-launcher svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Full-viewport modal.  Click anywhere on this element dismisses
   (including the card itself), per spec.  The blur is a touch of
   depth so the underlying mesh state stays vaguely visible. */
.qr-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.78);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* hidden attribute does the actual hiding; this is the visible state. */
}
.qr-overlay[hidden] { display: none; }

.qr-overlay-card {
  position: relative;
  background: #ffffff;
  border-radius: 12px;
  padding: 24px;
  max-width: min(90vw, 90vh, 480px);
  width: 100%;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

.qr-overlay-image {
  width: 100%;
  /* Force a 1:1 aspect via padding-bottom trick so the card stays
     square as the viewport changes. */
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-overlay-image svg {
  width: 100%;
  height: 100%;
  display: block;
}

.qr-overlay-url {
  display: block;
  margin-top: 14px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  color: #222;
  text-align: center;
  overflow-wrap: anywhere;
  user-select: all;
}

.qr-overlay-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  color: #333;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.qr-overlay-close:hover {
  background: rgba(0, 0, 0, 0.12);
}
.qr-overlay-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* On phones, shrink the launcher so it doesn't dominate the corner. */
@media (max-width: 480px) {
  .qr-launcher { width: 52px; height: 52px; top: 12px; right: 12px; }
}

/* ── Peer table ────────────────────────────────────────────────── */

.peers {
  margin-bottom: 24px;
}

.peer-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: 8px;
  overflow: hidden;
}
.peer-table thead th {
  text-align: left;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.peer-table thead .col-ind  { width: 50px; }
.peer-table thead .col-rtt,
.peer-table thead .col-traf { text-align: right; width: 130px; }
.peer-table thead .col-up   { text-align: right; width: 90px; }

.peer-table tbody tr {
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.peer-table tbody tr:last-child {
  border-bottom: none;
}

.peer-table td {
  padding: 12px 14px;
  vertical-align: middle;
}

.peer-row-bridge {
  background: rgba(95, 191, 208, 0.04);   /* subtle accent for bridge row */
}

/* ── Indicator (per-row) ───────────────────────────────────────── */

.indicator {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  /* Resting state for orange / green is dim; pulses brighten on
     actual ping/pong traffic.  Red is full-bright and steady so
     a dead row is visually distinct from a stuck-but-quiet one. */
  opacity: 0.32;
  transition: background-color 0.15s ease, opacity 320ms ease-out;
}
.indicator-red {
  background: var(--red);
  box-shadow: 0 0 10px var(--shadow-red);
  /* Red is the only steady-bright state.  No pulse — a failed peer
     should look obviously different from an active one. */
  opacity: 1;
}
.indicator-orange {
  background: var(--orange);
  box-shadow: 0 0 10px var(--shadow-orange);
}
.indicator-green {
  background: var(--green);
  box-shadow: 0 0 10px var(--shadow-green);
}

/* Single-shot pulse: client.js adds this class on every observed
   ping-out / pong-in, then removes it ~80 ms later.  The opacity
   snaps to 1 on apply (transition: opacity 0ms) and fades back
   over 320 ms when the class is removed (default transition).  The
   net visual is a discrete flash per real frame of traffic — a
   healthy peer pulses ~2 Hz (ping out + pong back), a stale peer
   pulses ~1 Hz (ping out only, no pong back), a stuck-in-signaling
   peer doesn't pulse at all. */
.indicator-orange.indicator--pulse,
.indicator-green.indicator--pulse {
  opacity: 1;
  transition: opacity 0ms;
}

/* ── Peer / cell content ───────────────────────────────────────── */

.peer-label {
  font-weight: 500;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
}
.peer-sub {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 2px;
  white-space: nowrap;
}

/* Orange "via TURN" hint, appended to .peer-sub when the nominated
   candidate pair is relayed.  Empty text node when path is direct
   so it takes no space.  Inherits the uppercase + letter-spacing from
   the parent. */
.path-badge {
  color: var(--orange);
}

.cell-num {
  text-align: right;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}
.cell-sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}

/* ── Event log ─────────────────────────────────────────────────── */

.log {
  margin-bottom: 16px;
}
.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.log h2 {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0;
  font-weight: 600;
}
.log-clear {
  background: none;
  border: 1px solid var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.log-clear:hover {
  color: var(--text);
  border-color: var(--muted);
}
.log-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--panel);
  border-radius: 6px;
  max-height: 320px;
  overflow-y: auto;
}
.log-list li {
  padding: 5px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--muted);
  display: flex;
  gap: 10px;
}
.log-list li:last-child { border-bottom: none; }
.log-list .ts {
  color: var(--muted-2);
  flex-shrink: 0;
}
.log-list .ev          { color: var(--text); }
.log-list .ev-error    { color: var(--red); }
.log-list .ev-ok       { color: var(--green); }

/* ── Footer ────────────────────────────────────────────────────── */

footer {
  margin-top: 32px;
  font-size: 12px;
  color: var(--muted);
}
footer code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--panel);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--text);
}
footer a {
  color: var(--accent);
  text-decoration: none;
}
footer a:hover { text-decoration: underline; }

/* ── Region picker (Phase 3) ────────────────────────────────────── */

.region-picker {
  background: var(--bg-sub);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 14px 18px;
  margin: 0 0 16px;
}
.region-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.region-select {
  flex: 1 1 auto;
  min-width: 220px;
  padding: 6px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
}
.region-save {
  padding: 6px 14px;
  background: var(--accent);
  color: var(--bg);
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}
.region-save:hover { filter: brightness(1.1); }
.region-help {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

/* ── DHT lookup harness (Phase 3) ───────────────────────────────── */

.lookup {
  margin: 0 0 16px;
}
.lookup h2 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.lookup-row {
  display: flex;
  gap: 8px;
}
.lookup-input {
  flex: 1 1 auto;
  padding: 6px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
}
.lookup-input:focus {
  outline: none;
  border-color: var(--accent);
}
.lookup-go {
  padding: 6px 14px;
  background: var(--accent);
  color: var(--bg);
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}
.lookup-go:disabled {
  background: var(--border);
  cursor: not-allowed;
}
.lookup-result {
  margin: 8px 0 0;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: pre-wrap;
  min-height: 1.4em;
}

/* ── Upgrade-required banner ─────────────────────────────────────
   Shown when the bridge closes our connection with code 4426
   (client below MIN_PEER_VERSION).  Sticks to the top of the page
   and stays put until the user reloads. */

.upgrade-banner {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #4a1f1f;
  color: #ffd9d9;
  border-bottom: 2px solid #ff6b6b;
  padding: 14px 20px;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}
.upgrade-banner strong { color: #ff6b6b; font-size: 16px; }
.upgrade-banner code {
  background: rgba(0,0,0,0.3);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 12px;
}

/* ── Pub/Sub harness (Phase 3) ──────────────────────────────────── */

.pubsub {
  margin: 0 0 16px;
}
.pubsub h2 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.pubsub h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.pubsub-publish-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 0 10px;
}
.pubsub-publish-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 14px;
}
.pubsub-publish {
  background: var(--bg-sub);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  position: relative;
}
.pubsub-publish .pubsub-sub-remove {
  position: absolute;
  top: 6px;
  right: 8px;
}
.pubsub-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.pubsub-row + .pubsub-row {
  margin-top: 8px;
}
.pubsub-region {
  flex: 1 1 auto;
  min-width: 200px;
  padding: 6px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
}
.pubsub-input {
  flex: 1 1 auto;
  padding: 6px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
}
.pubsub-input:focus {
  outline: none;
  border-color: var(--accent);
}
.pubsub-send,
.pubsub-add,
.pubsub-cancel {
  padding: 6px 14px;
  background: var(--accent);
  color: var(--bg);
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.pubsub-send:hover,
.pubsub-add:hover { filter: brightness(1.1); }
.pubsub-send:disabled,
.pubsub-add:disabled {
  background: var(--border);
  cursor: not-allowed;
}
.pubsub-cancel {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.pubsub-cancel:hover { color: var(--text); border-color: var(--text); }
.pubsub-key {
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  word-break: break-all;
}
.pubsub-subs-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 0 10px;
}
.pubsub-sub-form {
  background: var(--bg-sub);
  border: 1px dashed var(--accent);
  border-radius: 6px;
  padding: 10px 14px;
  margin: 0 0 12px;
}
.pubsub-sub-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pubsub-sub {
  background: var(--bg-sub);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
}
.pubsub-sub-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.pubsub-sub-title {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}
.pubsub-sub-title .region-tag {
  color: var(--accent);
  font-size: 11px;
  margin-right: 6px;
  text-transform: uppercase;
}
.pubsub-sub-key {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}
.pubsub-sub-remove {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}
.pubsub-sub-remove:hover { color: #ff6b6b; }
.pubsub-sub-msgs {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}
.pubsub-sub-msgs li {
  background: var(--bg);
  border-left: 2px solid var(--accent);
  padding: 4px 8px;
  font-size: 13px;
  color: var(--text);
}
.pubsub-sub-msgs .msg-meta {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.pubsub-sub-empty {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}
