/* TennMesh Live — dark theme, brand orange accent */
:root {
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --border: rgba(255,255,255,0.10);
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --accent: #f7710f;           /* TennMesh orange */
  --good: #0ca30c;
  --critical: #d03b3b;
  --warning: #fab219;
  /* map marker roles (validated dark categorical slots) */
  --c-repeater: #d95926;
  --c-companion: #3987e5;
  --c-room: #9085e9;
  --c-sensor: #c98500;
  --c-observer: #199e70;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand { height: 26px; }
.tabs { display: flex; gap: 2px; margin-left: 18px; }
.tab {
  background: none; border: none; color: var(--ink-2); font: inherit;
  padding: 8px 14px; cursor: pointer; border-radius: 6px 6px 0 0;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
/* Dashboard nav link — styled like a tab but navigates to a separate page.
   Kept off the .tab class so the app's tab-switching JS ignores it. */
.tab-link {
  background: none; border: none; color: var(--ink-2); font: inherit;
  padding: 8px 14px; cursor: pointer; border-radius: 6px 6px 0 0;
  border-bottom: 2px solid transparent; text-decoration: none;
  display: inline-flex; align-items: center;
}
.tab-link:hover { color: var(--ink); background: var(--surface-2); }
.meshstats { margin-left: auto; display: flex; gap: 18px; align-items: center; }
.mstat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.mstat b { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.mstat span { color: var(--muted); font-size: 10px; text-transform: uppercase;
  letter-spacing: .05em; }
.clocks { display: flex; flex-direction: column; gap: 1px; padding-left: 16px;
  border-left: 1px solid var(--border); line-height: 1.25; }
.clockrow { display: flex; gap: 8px; align-items: baseline; justify-content: flex-end; }
.clk-label { color: var(--muted); font-size: 10px; text-transform: uppercase;
  letter-spacing: .05em; width: 34px; }
.clk { color: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- panels ---------- */
.panel { display: none; flex: 1 1 auto; position: relative; min-height: 0; }
.panel.active { display: flex; }
.panel.scrollable { overflow-y: auto; display: none; flex-direction: column;
  padding: 16px; gap: 16px; }
.panel.scrollable.active { display: flex; }
.mapbox { flex: 1 1 auto; background: #111; }

/* ---------- map controls ---------- */
.map-controls {
  /* Sits below the Leaflet layer control, which Leaflet renders top-right
     (~top:10px). Offset down so the two don't overlap in the same corner. */
  position: absolute; top: 58px; right: 12px; z-index: 1000;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5); font-size: 13px;
}
.map-controls label { display: flex; align-items: center; gap: 8px; cursor: pointer;
  color: var(--ink-2); }
.map-controls label em { color: var(--muted); font-style: normal; margin-left: auto;
  font-variant-numeric: tabular-nums; padding-left: 10px; }
.map-controls .sep { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.ring { background: transparent; border: 2.5px solid; width: 8px; height: 8px; }
.line { width: 14px; height: 0; border-top: 2px solid var(--accent); display: inline-block; }

/* leaflet dark chrome */
.leaflet-container { background: #0a0a0a; font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface); color: var(--ink);
  box-shadow: 0 4px 16px rgba(0,0,0,.6);
}
.leaflet-popup-content { margin: 12px 14px; font: 13px/1.5 system-ui, sans-serif; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.popup h4 { margin: 0 0 2px; font-size: 14px; }
.popup .role { color: var(--accent); font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; }
.popup dl { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr;
  gap: 2px 12px; }
.popup dt { color: var(--muted); }
.popup dd { margin: 0; }
.popup .nbrs { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 6px; }
.popup-alert { margin: 6px 0; padding: 4px 8px; border-radius: 6px;
  background: rgba(208,59,59,.15); color: #ff6b6b; font-size: 12px; font-weight: 600; }
.popup-alert a { color: #ff6b6b; text-decoration: underline; }

/* Leaflet layer control (basemap selector, upper-right) — dark theme.
   Raise the top-right control corner above the custom .map-controls legend
   (also z-index:1000) so the expanded basemap list is never hidden behind it. */
.leaflet-top.leaflet-right { z-index: 1100; }
.leaflet-control-layers {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5); color: var(--ink-2);
}
.leaflet-control-layers-toggle {
  /* The vendored leaflet.css points at images/layers.png, which isn't shipped
     (the app draws all markers as SVG, so Leaflet's PNGs were never added).
     Supply the "layers" glyph inline as a themed SVG so the toggle isn't blank. */
  width: 34px; height: 34px; background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23c3c2b7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='12 2 2 7 12 12 22 7 12 2'/%3E%3Cpolyline points='2 17 12 22 22 17'/%3E%3Cpolyline points='2 12 12 17 22 12'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: center; background-size: 20px 20px;
}
/* When the control is expanded Leaflet hides the toggle; no icon needed then. */
.leaflet-control-layers-expanded .leaflet-control-layers-toggle { display: none; }
.leaflet-control-layers-expanded { padding: 8px 10px; font-size: 13px; }
.leaflet-control-layers-list label { display: flex; align-items: center; gap: 6px;
  cursor: pointer; margin: 2px 0; }
.leaflet-control-layers-selector { margin: 0 2px 0 0; }
.leaflet-control-layers-separator { border-top: 1px solid var(--border); }

/* Floating map settings panel (bottom-right, Live Map only). Matches the
   existing .map-controls surface so it reads as the same UI system. */
.map-settings {
  position: absolute; bottom: 16px; right: 12px; z-index: 1000; width: 190px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.5); font-size: 13px;
}
.map-settings .ms-row { display: flex; align-items: baseline; justify-content: space-between; }
.map-settings .ms-label { color: var(--ink-2); }
.map-settings .ms-value { color: var(--accent); font-weight: 600; font-size: 12px; }
.map-settings input[type=range] { width: 100%; margin: 8px 0 10px; accent-color: var(--accent); cursor: pointer; }
.map-settings .ms-reset {
  width: 100%; padding: 6px 8px; font: inherit; font-size: 12px; cursor: pointer;
  color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px;
}
.map-settings .ms-reset:hover { color: var(--ink); border-color: var(--accent); }

/* Alerts: pulsing red map markers + the tab badge and table pills. */
@keyframes advertPulse {
  0%   { stroke-opacity: 1;   stroke-width: 2; }
  50%  { stroke-opacity: .25; stroke-width: 17; }
  100% { stroke-opacity: 1;   stroke-width: 2; }
}
.advert-pulse { animation: advertPulse 1.4s ease-in-out infinite; stroke: #d03b3b; }
/* Red hover label for pulsing (high-advert) map markers. */
.leaflet-tooltip.advert-tip { background: #d03b3b; color: #fff; border: none; font-weight: 700; }
.leaflet-tooltip.advert-tip.leaflet-tooltip-top:before { border-top-color: #d03b3b; }
.leaflet-tooltip.advert-tip.leaflet-tooltip-bottom:before { border-bottom-color: #d03b3b; }
.leaflet-tooltip.advert-tip.leaflet-tooltip-left:before { border-left-color: #d03b3b; }
.leaflet-tooltip.advert-tip.leaflet-tooltip-right:before { border-right-color: #d03b3b; }
.alert-badge { display: inline-block; min-width: 16px; padding: 0 5px; margin-left: 4px;
  font-size: 10px; font-weight: 700; font-style: normal; line-height: 16px; text-align: center;
  border-radius: 99px; background: var(--offline, #d03b3b); color: #fff; }
.alert-pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px;
  font-weight: 700; background: var(--offline, #d03b3b); color: #fff; white-space: nowrap; }
.popup .nbrs div { display: flex; justify-content: space-between; gap: 12px; }
.popup .nbrs span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- live map ---------- */
.live-side {
  flex: 0 0 340px; background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.live-head { padding: 12px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 13px; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.pulse.live { background: var(--good); box-shadow: 0 0 0 0 rgba(12,163,12,.6);
  animation: pulse 2s infinite; }
.pulse.replay { background: var(--warning); }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(12,163,12,0); } }
.feed { flex: 1; overflow-y: auto; padding: 8px; display: flex;
  flex-direction: column-reverse; gap: 6px; }
.pkt {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; font-size: 12px; animation: slidein .25s ease;
}
@keyframes slidein { from { opacity: 0; transform: translateY(6px); } }
.pkt .row1 { display: flex; gap: 8px; align-items: baseline; }
.pkt .ptype { font-weight: 600; color: var(--accent); }
.pkt .ptype.ADVERT { color: var(--c-companion); }
.pkt .ptype.GRP_TXT { color: var(--c-observer); }
.pkt .ptype.TRACE, .pkt .ptype.PATH { color: var(--c-room); }
.pkt .time { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.pkt .meta { color: var(--ink-2); margin-top: 2px; }
.pkt .txt { color: var(--ink-2); margin-top: 2px; font-style: italic;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pkt .hops { color: var(--muted); margin-top: 2px; }

/* ---------- chat ---------- */
.chan-list {
  flex: 0 0 280px; background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 8px;
}
.chan {
  padding: 9px 12px; border-radius: 6px; cursor: pointer; display: flex;
  align-items: center; gap: 8px; color: var(--ink-2);
}
.chan:hover { background: var(--surface-2); }
.chan.active { background: var(--surface-2); color: var(--ink);
  box-shadow: inset 3px 0 0 var(--accent); }
.chan .cname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan .lock { font-size: 11px; }
.chan .ccount { margin-left: auto; color: var(--muted); font-size: 12px;
  font-variant-numeric: tabular-nums; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-title { padding: 12px 18px; border-bottom: 1px solid var(--border);
  font-weight: 600; background: var(--surface); }
.chat-msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 18px;
  display: flex; flex-direction: column; gap: 10px; }
.hint { color: var(--muted); max-width: 480px; }
.msg { max-width: 720px; }
.msg .mhead { display: flex; gap: 10px; align-items: baseline; }
.msg .sender { font-weight: 600; color: var(--accent); font-size: 13px; }
.msg .mtime { color: var(--muted); font-size: 11px; }
.msg .mtext { background: var(--surface); border: 1px solid var(--border);
  border-radius: 0 10px 10px 10px; padding: 8px 12px; margin-top: 3px;
  color: var(--ink-2); word-wrap: break-word; }
.msg.enc .mtext { color: var(--muted); font-style: italic; }

/* ---------- observers table ---------- */
.obs-toolbar { display: flex; gap: 14px; align-items: center; }
#obs-search {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  border-radius: 6px; padding: 8px 12px; width: 260px; font: inherit;
}
#obs-search:focus { outline: none; border-color: var(--accent); }
.chips { color: var(--muted); font-size: 13px; }
.chips b { color: var(--ink); }
.table { width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.table th {
  text-align: left; padding: 9px 12px; color: var(--muted); font-weight: 500;
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
  position: sticky; top: 0;
}
.table td { padding: 8px 12px; border-bottom: 1px solid var(--grid);
  color: var(--ink-2); }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.name { color: var(--ink); font-weight: 500; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; }
.status.online { color: var(--good); } .status.online::before { background: var(--good); }
.status.stale { color: var(--warning); } .status.stale::before { background: var(--warning); }
.status.offline { color: var(--muted); } .status.offline::before { background: var(--muted); }
.small { color: var(--muted); font-size: 12px; }

/* ---------- nodes table ---------- */
.filterbtns { display: flex; gap: 4px; flex-wrap: wrap; }
.fbtn {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink-2);
  padding: 7px 12px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px;
  white-space: nowrap;
}
.fbtn:hover { background: var(--surface-2); color: var(--ink); }
.fbtn.active { border-color: var(--accent); color: var(--ink); background: var(--surface-2); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.sortable .arr { color: var(--accent); margin-left: 3px; }
.rolebadge { display: inline-flex; align-items: center; gap: 7px; text-transform: capitalize; }
.rdot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.obs-mark { color: var(--c-observer); font-size: 11px; border: 1px solid var(--c-observer);
  border-radius: 4px; padding: 0 5px; margin-left: 7px; }
tr.locatable { cursor: pointer; }
tr.locatable:hover td { background: var(--surface-2); }
.mono { font-family: ui-monospace, "Cascadia Mono", monospace; font-size: 12px;
  color: var(--muted); }

/* ---------- reports ---------- */
.rsel {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  border-radius: 6px; padding: 8px 10px; font: inherit; max-width: 320px;
}
.rsel:focus { outline: none; border-color: var(--accent); }
.delta { font-size: 12px; margin-left: 6px; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--good); }
.delta.down { color: var(--critical); }
.delta.flat { color: var(--muted); }
.issue-tag { font-size: 11px; border: 1px solid; border-radius: 4px; padding: 1px 6px;
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.issue-tag.offline { color: var(--muted); border-color: var(--muted); }
.issue-tag.battery { color: var(--critical); border-color: var(--critical); }
.issue-tag.noise { color: var(--warning); border-color: var(--warning); }
.issue-tag.clock { color: var(--c-companion); border-color: var(--c-companion); }
.report-section-note { color: var(--muted); font-size: 12px; margin: -4px 0 8px; }
.allgood { color: var(--good); }
.rdesc { color: var(--ink-2); font-size: 13px; margin: 0 0 10px; max-width: 68em; }
.rdesc b { color: var(--ink); }
.scrollbox { max-height: 340px; overflow-y: auto; }
tr.redflag { background: rgba(208, 59, 59, 0.10); }
tr.redflag td, tr.redflag td.name { color: var(--critical); }

/* ---------- scopes ---------- */
/* A named scope is a cryptographically validated match; an unknown one is
   scoped traffic we cannot name. The two must never look alike. */
.scope-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 14px; }
.scope-pill { font-size: 12px; border-radius: 4px; padding: 1px 7px;
  border: 1px solid; white-space: nowrap; font-weight: 600; }
.scope-pill.known { color: var(--accent); border-color: var(--accent); }
.scope-pill.unknown { color: var(--muted); border-color: var(--muted);
  font-style: italic; font-weight: 500; }
.issue-tag.conf-exact { color: var(--good); border-color: var(--good); }
.issue-tag.conf-candidate { color: var(--warning); border-color: var(--warning); }
.issue-tag.conf-unverified { color: var(--c-companion); border-color: var(--c-companion); }
.issue-tag.conf-unattributed { color: var(--muted); border-color: var(--muted); }
#scope-search { background: var(--surface-2); border: 1px solid var(--border);
  color: var(--ink); border-radius: 6px; padding: 7px 10px; min-width: 260px; }

/* ---------- analyze ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 16px; }
.tile .v { font-size: 26px; font-weight: 650; }
.tile .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile.accent .v { color: var(--accent); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 16px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.card h3 .units { color: var(--muted); font-weight: 400; font-size: 12px;
  margin-left: 6px; }
.chartbox { position: relative; height: 240px; }
.chartbox.tall { height: 300px; }
.table.mini { border: none; background: none; }
.table.mini td { padding: 6px 8px; }
/* section divider inside a panel (e.g. path hash analysis on Stats) */
.section-head { margin: 26px 0 4px; font-size: 16px; font-weight: 650;
  padding-top: 18px; border-top: 1px solid var(--border); }
.section-note { color: var(--muted); font-size: 12.5px; margin: 0 0 14px;
  max-width: 780px; line-height: 1.5; }
#coll-table td.name a { margin-right: 2px; }
.table-wrap { overflow-x: auto; border-radius: 8px; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; padding: 8px 10px; gap: 10px; row-gap: 2px; }
  .brand { height: 20px; }
  .clocks { margin-left: auto; flex-direction: row; gap: 10px; padding-left: 0;
    border-left: none; }
  .clk { font-size: 12px; }
  .meshstats {
    order: 4; width: 100%; margin-left: 0; justify-content: space-between;
    gap: 8px; padding: 4px 2px 2px; border-top: 1px solid var(--border);
  }
  .mstat { align-items: center; }
  .mstat b { font-size: 13px; }
  .tabs {
    order: 3; width: 100%; margin-left: 0; overflow-x: auto;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 8px 12px; white-space: nowrap; flex: 0 0 auto; }

  /* live map: stack map above the feed */
  #panel-live { flex-direction: column; }
  .live-side { flex: 0 0 38%; border-left: none; border-top: 1px solid var(--border); }

  /* chat: channel list becomes a horizontal chip strip */
  #panel-chat { flex-direction: column; }
  .chan-list {
    flex: 0 0 auto; display: flex; overflow-x: auto; gap: 4px; padding: 6px;
    border-right: none; border-bottom: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
  }
  .chan { flex: 0 0 auto; padding: 7px 10px; }
  .chan.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .chan .ccount { margin-left: 6px; }
  .chat-msgs { padding: 10px 12px; }
  .msg .mtext { max-width: 100%; }

  /* compact map legend */
  .map-controls { padding: 8px 10px; font-size: 12px; gap: 4px; max-width: 180px; }

  /* scrollable panels & tables */
  .panel.scrollable { padding: 10px; gap: 10px; }
  .obs-toolbar { flex-wrap: wrap; gap: 8px; }
  #obs-search, #scope-search { flex: 1 1 100%; width: auto; min-width: 0; }
  .table th, .table td { padding: 7px 8px; }
  .tile { padding: 10px 12px; }
  .tile .v { font-size: 21px; }
  .chartbox { height: 210px; }
  .chartbox.tall { height: 250px; }

  /* Wide tables squeeze every column into an unreadable sliver on a phone.
     Drop the columns that carry the least meaning at a glance (see .opt-md /
     .opt-sm in the markup) so the ones that matter keep usable width. The data
     is still in the DOM on tablet widths and in full on desktop. */
  .opt-md { display: none; }

  /* Scope filter chips scroll rather than wrapping into a tall stack. */
  #scope-filters {
    display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 4px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
    max-width: 100%; padding-bottom: 2px;
  }
  #scope-filters::-webkit-scrollbar { display: none; }
  #scope-filters .fbtn { flex: 0 0 auto; }
  .scope-tiles { grid-template-columns: repeat(auto-fit, minmax(108px, 1fr)); gap: 8px; }
  .scope-pill { font-size: 11px; padding: 1px 5px; }
}

/* Phones proper: shed the second tier of optional columns too. */
@media (max-width: 560px) {
  .opt-sm { display: none; }
  .scope-tiles { grid-template-columns: repeat(2, 1fr); }
  .table th, .table td { padding: 6px 7px; }
  /* Confidence tags sit under the scope pill rather than beside it. */
  .table td .issue-tag { display: inline-block; margin-top: 3px; }
}
