/* tui.css — black ink on white, dense monospace TUI. */
:root {
  --ink: #000;
  --paper: #fff;
  --dim: #777;
  --line: #000;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); }
body { font-family: var(--mono); font-size: 13px; line-height: 1.35; }
a { color: inherit; }

.tui {
  min-height: calc(100dvh - 20px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  border: 1px solid var(--line);
  margin: 10px;
}
/* On a real screen, fit exactly so the footer never scrolls off. */
@media (min-width: 761px) { .tui { height: calc(100dvh - 20px); } }

/* ── top + bottom bars ───────────────────────────────── */
.bar {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 10px; border-bottom: 1px solid var(--line);
  text-transform: uppercase; letter-spacing: .04em;
}
.bar--foot { border-bottom: 0; border-top: 1px solid var(--line); color: var(--dim); }
.bar__title { font-weight: 700; white-space: nowrap; }
.bar__title::before { content: "┌─ "; color: var(--dim); }
.bar__title::after  { content: " ─"; color: var(--dim); }
.bar__line { color: var(--dim); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.copyable { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-transform: inherit; letter-spacing: inherit; }
.copyable:hover { text-decoration: underline; }
.copyable.copied { color: var(--ink); text-decoration: none; }
.bar__status { font-weight: 700; white-space: nowrap; }
.bar__status .dot { display: inline-block; transform: translateY(-1px); }
.bar__status[data-state="online"]  { color: var(--ink); }
.bar__status[data-state="demo"]    { color: var(--dim); }
.bar__status[data-state="loading"] { color: var(--dim); }
.bar__status[data-state="error"]   { color: var(--ink); text-decoration: line-through; }
.bar__sp { flex: 1; }
.foot__tag { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.foot__mail { text-decoration: none; white-space: nowrap; }
.foot__mail:hover { text-decoration: underline; }
.foot__dot { color: var(--dim); }
#foot-ts { white-space: nowrap; }

/* ── pane grid ───────────────────────────────────────── */
/* Main panel = stats/chart (left, tall). Map = top-right. */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr) minmax(0, auto) minmax(0, auto);
  grid-template-areas:
    "traffic map"
    "traffic snr"
    "recent  mesh"
    "recent  connect";
  min-height: 0;
}
.pane { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pane--map, .pane--snr, .pane--mesh, .pane--connect { border-right: 0; }
.pane--traffic{ grid-area: traffic; }
.pane--map    { grid-area: map; }
.pane--snr    { grid-area: snr; }
.pane--recent { grid-area: recent; }
.pane--mesh   { grid-area: mesh; }
.pane--connect{ grid-area: connect; }
.pane--recent, .pane--connect { border-bottom: 0; }

.pane__h {
  margin: 0; padding: 5px 10px; font-size: 11px; font-weight: 700;
  letter-spacing: .08em; border-bottom: 1px solid var(--line); background: var(--ink); color: var(--paper);
  flex: 0 0 auto;
}

/* ── map ─────────────────────────────────────────────── */
.map { flex: 1 1 auto; min-height: 0; background: var(--paper); }
/* Force the raster basemap to monochrome, very high-contrast: dark water + bold
   street lines against pale land. */
.leaflet-tile-pane { filter: grayscale(1) brightness(.74) contrast(2.4); }
.leaflet-container { background: var(--paper); font-family: var(--mono); }
.leaflet-control-attribution { font-size: 9px; background: rgba(255,255,255,.7); }

/* ── traffic table + full-width bar chart ────────────── */
.ttable { width: 100%; border-collapse: collapse; padding: 0; flex: 0 0 auto; }
.ttable th, .ttable td { padding: 4px 10px; text-align: right; }
.ttable th:first-child, .ttable td:first-child { text-align: left; font-weight: 700; }
.ttable thead th { color: var(--dim); font-weight: 400; border-bottom: 1px solid var(--line); }
.ttable td { font-variant-numeric: tabular-nums; }

.chart-wrap { position: relative; flex: 1 1 auto; min-height: 140px; display: flex; flex-direction: column; border-top: 1px dashed var(--dim); }
.chart-block { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
.chart-block + .chart-block { border-top: 1px dashed var(--dim); }
.chart__cap { padding: 4px 10px 0; color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
/* Grid (not flex) so N equal columns shrink to fit any width without overflow. */
.chart { flex: 1 1 auto; min-height: 38px; min-width: 0; overflow: hidden;
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  align-items: end; gap: 2px; padding: 4px 10px 8px; }
.chart .bar { min-width: 0; min-height: 1px; background: var(--ink); }
.chart .bar:hover { background: var(--dim); }
.chart .bar--zero { background: var(--dim); opacity: .35; min-height: 1px; }
.chart-tip {
  position: absolute; top: 6px; z-index: 5; pointer-events: none;
  background: var(--ink); color: var(--paper); font-size: 11px; padding: 2px 6px;
  white-space: nowrap; text-transform: none; letter-spacing: 0;
}
.chart-tip[hidden] { display: none; }

/* ── inline term definition (HEARD / RELAYED) ────────── */
.term { position: relative; cursor: help; border-bottom: 1px dotted var(--dim); outline: none; }
.term__i { font-size: 8px; color: var(--dim); vertical-align: super; margin-left: 1px; }
.term__tip {
  position: absolute; left: 0; top: calc(100% + 5px); z-index: 6;
  width: max-content; max-width: min(240px, 60vw);
  background: var(--ink); color: var(--paper);
  font-weight: 400; font-size: 11px; line-height: 1.4; text-align: left;
  text-transform: none; letter-spacing: 0; padding: 6px 8px;
  opacity: 0; visibility: hidden; transition: opacity .12s;
}
.term:hover .term__tip, .term:focus .term__tip { opacity: 1; visibility: visible; }

/* ── top SNR ─────────────────────────────────────────── */
.snr { list-style: none; margin: 0; padding: 6px 10px; overflow: auto; }
.snr li { display: grid; grid-template-columns: 1.2em 1fr auto 84px; gap: 8px; align-items: center; padding: 3px 0; }
.snr .rank { color: var(--dim); }
.snr .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.snr a.name { text-decoration: none; }
.snr a.name:hover { text-decoration: underline; }
.snr .val  { font-variant-numeric: tabular-nums; }
.snrbars { display: flex; align-items: flex-end; gap: 1px; height: 20px; }
.snrbars i { flex: 1 1 0; min-width: 1px; min-height: 1px; background: var(--ink); }

/* ── recent ──────────────────────────────────────────── */
.recent { list-style: none; margin: 0; padding: 6px 10px; flex: 1 1 auto; min-height: 0; overflow: auto; }
.recent li { display: flex; gap: 8px; padding: 1px 0; white-space: nowrap; }
.recent .t { color: var(--dim); }
.recent .ch { color: var(--dim); }
.recent .rel { font-weight: 700; }
.recent .txt { overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* ── mesh stats ──────────────────────────────────────── */
.stats { margin: 0; padding: 8px 10px; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-content: start; }
.stats dt { color: var(--dim); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }

/* ── connect / contact QR ────────────────────────────── */
.connect { flex: 1 1 auto; min-height: 0; display: flex; gap: 12px; padding: 8px 10px; align-items: center; }
.connect__qr { flex: 0 0 auto; width: 100px; height: 100px; background: var(--paper); }
.connect__qr svg { display: block; width: 100%; height: 100%; }
.connect__info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.connect__lead { margin: 0; color: var(--dim); font-size: 11px; line-height: 1.45; }
.connect__lead b { color: var(--ink); }
.connect__link { align-self: flex-start; border: 1px solid var(--line); padding: 4px 8px; font-size: 11px; }
.connect__link:hover { text-decoration: none; background: var(--ink); color: var(--paper); }

/* ── responsive: stack ───────────────────────────────── */
@media (max-width: 760px) {
  .grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "map" "traffic" "snr" "recent" "mesh" "connect";
  }
  .pane { border-right: 0; }
  .pane--map { min-height: 240px; }
  .chart-wrap { min-height: 180px; }
  /* Footer: let it wrap so the refresh time never overflows the screen. */
  .bar--foot { flex-wrap: wrap; gap: 2px 8px; }
  .bar--foot .bar__sp { display: none; }
  .foot__tag { flex: 1 1 100%; }
}

/* ── hop + direct-SNR tags on recent rows ────────────── */
.recent .meta { margin-left: auto; display: flex; gap: 8px; padding-left: 10px; align-items: baseline; }
.recent .hop { color: var(--dim); }
.recent .hop--0 { color: var(--ink); font-weight: 700; }
.recent .rx { font-variant-numeric: tabular-nums; font-weight: 700; }
.recent .rx small { color: var(--dim); font-weight: 400; font-size: 10px; }

/* ── map: header extras, expand overlay, node labels ─── */
.pane--map { position: relative; }
.pane__hr { float: right; font-weight: 400; color: rgba(255,255,255,.75); letter-spacing: .06em; }
.map-expand { float: right; margin-left: 10px; background: none; border: 1px solid var(--paper); color: var(--paper); font: inherit; font-size: 9px; letter-spacing: .1em; padding: 0 6px; cursor: pointer; }
.map-expand:hover { background: var(--paper); color: var(--ink); }
.pane--map.expanded { position: fixed; inset: 10px; z-index: 1000; background: var(--paper); border: 1px solid var(--line); }
body.map-open { overflow: hidden; }
.map-note { position: absolute; right: 8px; bottom: 20px; z-index: 800; background: rgba(255,255,255,.85); color: var(--dim); font-size: 9px; padding: 2px 6px; pointer-events: none; }
.ntip { background: var(--paper); border: 1px solid var(--line); border-radius: 0; color: var(--ink); font-family: var(--mono); font-size: 9.5px; padding: 1px 5px; box-shadow: none; }
.ntip::before { display: none; }
@media (max-width: 760px) { .ntip { display: none; } }
.leaflet-control-zoom a { border-radius: 0 !important; color: var(--ink) !important; font-family: var(--mono); }

/* ── galaxy star marker ──────────────────────────────── */
.gstar-wrap { background: none; border: 0; }
.gstar { display: block; }
.gstar svg { overflow: visible; display: block; }
.gstar__spikes path { fill: var(--ink); }
.gstar__core { fill: var(--ink); }
.gstar__ring { fill: none; stroke: var(--ink); stroke-width: .6; opacity: .28; }
.gstar { animation: gstar-pulse 3.2s ease-in-out infinite; transform-origin: 50% 50%; }
@keyframes gstar-pulse {
  0%, 100% { opacity: .82; transform: scale(.96); }
  50%      { opacity: 1;   transform: scale(1.06); }
}
@media (prefers-reduced-motion: reduce) { .gstar { animation: none; } }
