/* ---------------------------------------------------------------
   MeshPest — design tokens (light default, dark via prefers-color-scheme
   or [data-theme]). Status hues are fixed per the dataviz palette and
   never themed; everything else swaps per mode.
   --------------------------------------------------------------- */
:root {
  color-scheme: light;
  --surface-page:   #f9f9f7;
  --surface-card:   #fcfcfb;
  --surface-raised: #ffffff;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --border:         rgba(11, 11, 11, 0.10);
  --gridline:       #e1e0d9;

  --accent:       #2a78d6;
  --accent-ink:   #ffffff;
  --accent-hover: #1c5cab;

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;
  --status-offline:  #898781;
  --status-online:   var(--accent); /* repeaters only -- see deviceStatus() in shared.js */

  /* Species (categorical) — dataviz palette slots 2-7, deliberately
     starting past slot 1 (blue) since blue is already this app's --accent
     and shouldn't double as a data identity color. Fixed order, never
     cycled or reassigned per filter. "other" is its own fixed slot, not a
     new hue per typed-in name -- see SPECIES_META/speciesBadgeHtml in
     shared.js for how a custom name still gets shown on the badge itself. */
  --species-rat:      #eb6834;
  --species-possum:   #1baf7a;
  --species-stoat:    #eda100;
  --species-hedgehog: #e87ba4;
  --species-cat:      #008300;
  --species-other:    #4a3aa7;

  /* Public (signed-out) map markers only -- fixed per device TYPE, not
     real-time status/health. Deliberately its own tokens rather than
     reusing --status-good/--species-rat: those mean "condition" or
     "species identity", this means "this dot is a trap" and nothing else
     -- the whole point is that it must NOT vary with real trap state. */
  --map-public-trap:     #0ca30c;
  --map-public-repeater: #eb6834;

  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.06);
  --shadow-md: 0 4px 16px rgba(11, 11, 11, 0.10);
  --radius: 12px;
  --ease: 150ms ease;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-page:   #0d0d0d;
    --surface-card:   #1a1a19;
    --surface-raised: #222220;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --border:         rgba(255, 255, 255, 0.12);
    --gridline:       #2c2c2a;
    --accent:       #3987e5;
    --accent-hover: #86b6ef;
    --species-rat:      #d95926;
    --species-possum:   #199e70;
    --species-stoat:    #c98500;
    --species-hedgehog: #d55181;
    --species-cat:      #008300;
    --species-other:    #9085e9;
    --map-public-repeater: #d95926;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-page:   #0d0d0d;
  --surface-card:   #1a1a19;
  --surface-raised: #222220;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --border:         rgba(255, 255, 255, 0.12);
  --gridline:       #2c2c2a;
  --accent:       #3987e5;
  --accent-hover: #86b6ef;
  --species-rat:      #d95926;
  --species-possum:   #199e70;
  --species-stoat:    #c98500;
  --species-hedgehog: #d55181;
  --species-cat:      #008300;
  --species-other:    #9085e9;
  --map-public-repeater: #d95926;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

* { scrollbar-width: thin; scrollbar-color: var(--text-muted) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--gridline); border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

h1, h2, h3 { margin: 0 0 4px; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }

a { color: var(--accent); }

button {
  font-family: inherit;
  cursor: pointer;
}

/* Smooth, consistent motion on every interactive element -- this one rule
   covers buttons, links, table/list rows, and form controls sitewide, so
   individual component blocks below don't need to repeat it. */
a, button, input, select,
tbody tr, .stat-tile, .leaderboard-row, .node-list li, .catch-row,
.mp-layer-row, .basemap-toggle button {
  transition: background-color var(--ease), border-color var(--ease),
    color var(--ease), box-shadow var(--ease), transform 100ms ease, opacity var(--ease);
}

button:active, .btn:active, .icon-btn:active, .chat-send-btn:active {
  transform: scale(0.96);
}

/* Visible keyboard focus everywhere -- mouse/touch users never see this
   (:focus-visible skips pointer-triggered focus), keyboard users always do. */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------
   Topbar
   --------------------------------------------------------------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 24px;
  background: var(--surface-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1500; /* above Leaflet's own panes/controls (max ~1000), below .modal-backdrop (4000) */
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
}

.topbar nav a {
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.topbar nav a:hover { background: var(--surface-page); color: var(--text-primary); }
.topbar nav a.active { background: var(--surface-page); color: var(--text-primary); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { color: var(--text-primary); border-color: var(--text-muted); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---------------------------------------------------------------
   Layout
   --------------------------------------------------------------- */
main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-tile {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
}

.stat-tile .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.stat-tile .value {
  font-size: 28px;
  font-weight: 600;
  line-height: 1;
}

.stat-tile.accent-good .value   { color: var(--status-good); }
.stat-tile.accent-critical .value { color: var(--status-critical); }
.stat-tile.accent-warning .value  { color: var(--status-warning); }

.content-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 900px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .content-grid { grid-template-columns: 1fr; }
}

/* Phone-sized screens. The public map view (index.html signed out) is the
   main thing this targets -- it's the one URL a community member is likely
   to open on a phone -- but everything here is generic enough to help the
   signed-in pages too. */
@media (max-width: 600px) {
  main { padding: 12px 12px 28px; }
  .topbar { padding: 10px 14px; }
  .topbar nav a { padding: 7px 9px; font-size: 13px; }

  /* On a phone the map IS the page -- give it most of the viewport rather
     than a fixed desktop-ish height, but keep a floor so it's never a
     useless sliver. */
  #map { height: 62vh; min-height: 300px; }

  .stat-tile { padding: 13px 14px; }
  .stat-tile .value { font-size: 24px; }

  .about-body { padding: 16px 16px; }
  .about-steps { padding: 12px; gap: 10px; }

  .legend { padding: 10px 12px; gap: 10px 12px; font-size: 12px; }

  .public-banner { flex-wrap: wrap; padding: 10px 12px; }
  .public-banner .btn { width: 100%; text-align: center; }

  /* Any wide table (the ranking tables when signed in) scrolls sideways
     inside its panel instead of blowing out the page width. */
  .side-panel { overflow-x: auto; }
}

/* ---------------------------------------------------------------
   Map panel
   --------------------------------------------------------------- */
.map-panel {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

#map {
  height: 480px;
  width: 100%;
  background: var(--surface-page);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--surface-raised);
  box-shadow: 0 0 0 1px rgba(11,11,11,0.25);
  flex: none;
}

/* Dashed-line swatch for the public map's "Signal path" legend entry --
   matches buildRouteLayer()'s public polyline style (dashed,
   --map-public-repeater). */
.legend-line {
  width: 18px;
  height: 0;
  border-top: 2px dashed var(--map-public-repeater);
  flex: none;
}

/* Leaflet marker */
.mp-marker {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(11, 11, 11, 0.35), var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
}
.mp-marker svg { width: 14px; height: 14px; }
.mp-marker.selected { box-shadow: 0 0 0 3px rgba(42, 120, 214, 0.55), 0 0 0 1px rgba(11,11,11,0.35); }

.mp-popup { font-size: 13px; }
.mp-popup h3 { font-size: 14px; margin-bottom: 4px; }
.mp-popup .badge { margin-top: 6px; }

/* ---------------------------------------------------------------
   Side panel / table
   --------------------------------------------------------------- */
.side-panel {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-primary);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
}
.btn:hover { border-color: var(--text-muted); box-shadow: var(--shadow-sm); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-block { width: 100%; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid var(--gridline);
  padding: 6px 8px;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
thead th.sortable .sort-arrow { display: inline-block; width: 0.9em; opacity: 0.4; }
thead th.sortable.sort-active { color: var(--text); }
thead th.sortable.sort-active .sort-arrow { opacity: 1; }
tbody td {
  padding: 8px;
  border-bottom: 1px solid var(--gridline);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
tbody tr.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); }

tbody tr.empty-row { cursor: default; }
tbody tr.empty-row:hover { background: none; }
tbody tr.empty-row td {
  text-align: center;
  padding: 28px 8px;
  color: var(--text-muted);
}
tbody tr.empty-row a { color: var(--accent); text-decoration: none; font-weight: 500; }
tbody tr.empty-row a:hover { text-decoration: underline; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------
   Status badges — icon + tinted background + ink text, never color alone
   --------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; flex: none; }

.badge-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.badge--good     { background: color-mix(in srgb, var(--status-good) 16%, var(--surface-card)); }
.badge--good svg { color: var(--status-good); }

.badge--warning     { background: color-mix(in srgb, var(--status-warning) 22%, var(--surface-card)); }
.badge--warning svg { color: color-mix(in srgb, var(--status-warning) 70%, black); }

.badge--serious     { background: color-mix(in srgb, var(--status-serious) 18%, var(--surface-card)); }
.badge--serious svg { color: var(--status-serious); }

.badge--critical     { background: color-mix(in srgb, var(--status-critical) 16%, var(--surface-card)); }
.badge--critical svg { color: var(--status-critical); }

.badge--offline     { background: color-mix(in srgb, var(--status-offline) 18%, var(--surface-card)); }
.badge--offline svg { color: var(--status-offline); }

.badge--online     { background: color-mix(in srgb, var(--status-online) 16%, var(--surface-card)); }
.badge--online svg { color: var(--status-online); }

/* Species badges — same icon+tint+label shape as status badges above, but a
   categorical (identity) palette rather than status (state). Light-mode
   possum/stoat/hedgehog land below 3:1 text contrast per the dataviz
   palette's own documented relief rule -- mitigated by always shipping the
   visible text label alongside (never color/icon alone). */
.badge--rat         { background: color-mix(in srgb, var(--species-rat) 16%, var(--surface-card)); }
.badge--rat svg      { color: var(--species-rat); }

.badge--possum       { background: color-mix(in srgb, var(--species-possum) 18%, var(--surface-card)); }
.badge--possum svg    { color: var(--species-possum); }

.badge--stoat        { background: color-mix(in srgb, var(--species-stoat) 20%, var(--surface-card)); }
.badge--stoat svg     { color: var(--species-stoat); }

.badge--hedgehog     { background: color-mix(in srgb, var(--species-hedgehog) 18%, var(--surface-card)); }
.badge--hedgehog svg  { color: var(--species-hedgehog); }

.badge--cat          { background: color-mix(in srgb, var(--species-cat) 16%, var(--surface-card)); }
.badge--cat svg       { color: var(--species-cat); }

.badge--other        { background: color-mix(in srgb, var(--species-other) 16%, var(--surface-card)); }
.badge--other svg     { color: var(--species-other); }

.badge--unclassified { background: color-mix(in srgb, var(--text-muted) 16%, var(--surface-card)); }
.badge--unclassified svg { color: var(--text-muted); }

/* ---------------------------------------------------------------
   Detail panel
   --------------------------------------------------------------- */
.detail-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--gridline);
}
.detail-panel.hidden { display: none; }
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 13px;
}
.detail-row .k { color: var(--text-secondary); }
.detail-row .v { font-weight: 500; }

/* ---------------------------------------------------------------
   Modal
   --------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 11, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 4000; /* Leaflet's own control/popup panes sit up to z-index 1000 */
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--surface-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
  padding: 20px;
}
.modal.modal--wide { max-width: 480px; }
.modal h2 { font-size: 16px; margin-bottom: 4px; }
.modal .modal-sub { color: var(--text-secondary); font-size: 13px; margin-bottom: 16px; }

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
}
.field textarea { resize: vertical; min-height: 68px; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Numbered setup steps -- the ntfy app install guide on notifications.html. */
.setup-steps { counter-reset: step; margin: 4px 0 0; padding: 0; list-style: none; }
.setup-steps li {
  position: relative;
  padding: 4px 0 14px 34px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
}
.setup-steps li:last-child { padding-bottom: 0; }
.setup-steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.setup-steps code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--surface-page);
  border-radius: 4px;
  padding: 1px 5px;
}

.topic-line { display: flex; gap: 8px; align-items: stretch; }
.topic-line .kv-mono { flex: 1; display: flex; align-items: center; }
.topic-line .btn { flex: none; }

.pin-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}
.pin-picker.armed { border-color: var(--accent); color: var(--accent); }
.pin-picker .coords { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-primary); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.otp-reveal {
  background: var(--surface-page);
  border: 1px solid var(--gridline);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  margin: 14px 0;
}
.otp-reveal .otp-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
  margin: 6px 0;
}
.otp-reveal .otp-warn {
  font-size: 12px;
  color: var(--status-critical);
}

/* ---------------------------------------------------------------
   Login page
   --------------------------------------------------------------- */
.login-shell {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px 26px;
}
.login-card .brand { justify-content: center; margin-bottom: 18px; }
.login-card h1 { font-size: 17px; text-align: center; margin-bottom: 2px; }
.login-card .modal-sub { text-align: center; margin-bottom: 20px; }
.login-foot {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}
.demo-toggle {
  display: block;
  text-align: center;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  background: none;
  border: none;
  text-decoration: underline;
}

.error-text {
  color: var(--status-critical);
  font-size: 12px;
  margin-top: -4px;
  margin-bottom: 10px;
  display: none;
}
.error-text.visible { display: block; }

/* ---------------------------------------------------------------
   Map layer control (hamburger menu)
   --------------------------------------------------------------- */
.mp-layer-control {
  background: var(--surface-raised);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.mp-layer-toggle {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  background: none;
  border: none;
}
.mp-layer-toggle svg { width: 18px; height: 18px; }
.mp-layer-toggle:hover { color: var(--text-primary); }

.mp-layer-panel {
  position: absolute;
  top: 38px;
  right: 0;
  width: 190px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 10px;
  font-size: 13px;
}
.mp-layer-panel.hidden { display: none; }

.mp-layer-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 4px 6px 2px;
}

.mp-layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-primary);
}
.mp-layer-row:hover { background: var(--surface-page); }
.mp-layer-row input { margin: 0; }

.mp-layer-divider {
  height: 1px;
  background: var(--gridline);
  margin: 6px 2px;
}

/* Basemap toggle pill, used on the small Add Device picker map */
.basemap-toggle {
  position: absolute;
  z-index: 500;
  top: 10px;
  right: 10px;
  display: flex;
  background: var(--surface-raised);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  padding: 2px;
  font-size: 12px;
}
.basemap-toggle button {
  border: none;
  background: none;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--text-secondary);
}
.basemap-toggle button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ---------------------------------------------------------------
   Recent activity / leaderboard (dashboard side panel)
   --------------------------------------------------------------- */
.panel-block + .panel-block {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--gridline);
}

.panel-block-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.panel-block-header h3 { font-size: 14px; }
.panel-block-header a { font-size: 12px; color: var(--accent); text-decoration: none; }
.panel-block-header a:hover { text-decoration: underline; }

.activity-list, .leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.activity-row-link {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 7px 4px;
  font-size: 13px;
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
}
.activity-row-link:hover { background: var(--surface-page); }
.activity-row-link .dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--status-critical);
}
.activity-name-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.activity-row-link .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-row-link .badge { flex: none; }
.activity-row-link .time { color: var(--text-muted); font-size: 12px; flex: none; margin-left: auto; }

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  font-size: 13px;
  border-radius: 6px;
}
.leaderboard-row:hover { background: var(--surface-page); }
.leaderboard-row .rank {
  width: 20px; height: 20px;
  border-radius: 6px;
  background: var(--surface-page);
  color: var(--text-secondary);
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.leaderboard-row .rank.r1 { background: color-mix(in srgb, var(--status-warning) 35%, var(--surface-page)); color: var(--text-primary); }
.leaderboard-row .name { flex: 1; font-weight: 500; }
.leaderboard-row .count { font-variant-numeric: tabular-nums; color: var(--text-secondary); font-size: 12px; }

/* ---------------------------------------------------------------
   Ranking page
   --------------------------------------------------------------- */
.rank-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--surface-page);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 12px;
}
.rank-cell.r1 { background: color-mix(in srgb, var(--status-warning) 35%, var(--surface-page)); color: var(--text-primary); }
.rank-cell.r2 { background: color-mix(in srgb, var(--text-muted) 25%, var(--surface-page)); color: var(--text-primary); }
.rank-cell.r3 { background: color-mix(in srgb, var(--status-serious) 22%, var(--surface-page)); color: var(--text-primary); }

/* ---------------------------------------------------------------
   Ranking bar chart — one shared status-color legend covers both;
   bar length = the ranked measure, bar color = current status (a
   secondary encoding, not decorative — same status language as the
   badges right below each chart).
   --------------------------------------------------------------- */
.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0 18px;
}
.bar-row {
  display: grid;
  grid-template-columns: 170px 1fr 44px;
  align-items: center;
  gap: 10px;
}
.bar-label {
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  height: 18px;
  background: var(--surface-page);
  border-radius: 0 4px 4px 0;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 0 4px 4px 0;
  min-width: 3px;
  transition: width 0.4s ease;
}
.bar-value {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  text-align: right;
}

.page-heading {
  margin-bottom: 16px;
}
.page-heading h1 { font-size: 20px; }
.page-heading p { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }

/* ---------------------------------------------------------------
   Auth chrome (mock sign-in/role-switch, see js/auth.js)
   --------------------------------------------------------------- */
#authSlot {
  display: flex;
  align-items: center;
  gap: 8px;
}
.role-switch {
  font-family: inherit;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-primary);
}

.public-view .stat-row,
.public-view .dashboard-ranking,
.public-view #activityBlock,
.public-view #leaderboardBlock,
.public-view #devicesBlock {
  display: none;
}

/* Map legend: full status legend when signed in, a plain type legend (no
   status/health info) for the public map -- matches the marker colors,
   which are fixed-per-type in public view rather than real status. */
.legend--public { display: none; }
.public-view .legend--full { display: none; }
.public-view .legend--public { display: flex; }
.public-banner {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface-card));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.public-banner a { font-weight: 500; }

.about-card {
  margin-top: 16px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.about-body { padding: 22px 24px; }
.about-card h2 { font-size: 17px; margin-bottom: 10px; }
.about-card p {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 720px;
}
.about-card p + p { margin-top: 10px; }
.about-card strong { color: var(--text-primary); }
.about-access {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-page));
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 720px;
}
.about-access svg { width: 15px; height: 15px; color: var(--accent); flex: none; }

.about-steps {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin: 18px 0;
  padding: 16px;
  background: var(--surface-page);
  border-radius: 10px;
}
.about-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}
.about-step-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.about-step-icon svg { width: 15px; height: 15px; }
.about-step-arrow { color: var(--text-muted); font-size: 14px; }

/* ---------------------------------------------------------------
   Devices page — filter bar
   --------------------------------------------------------------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 14px;
  padding: 12px;
  margin-bottom: 14px;
  background: var(--surface-page);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-field label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.filter-field input, .filter-field select {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-primary);
}
.filter-field input:focus, .filter-field select:focus { outline: none; border-color: var(--accent); }
.filter-field input[type="number"] { width: 68px; }
.filter-range {
  display: flex;
  align-items: center;
  gap: 6px;
}
.filter-range span { color: var(--text-muted); font-size: 12px; }
.filter-count {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

/* ---------------------------------------------------------------
   Settings page
   --------------------------------------------------------------- */
.node-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.node-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.node-list li:hover { background: var(--surface-page); }
.node-list li.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.node-list .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.node-list .type { margin-left: auto; color: var(--text-muted); font-size: 11px; }

.settings-section + .settings-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--gridline);
}
.settings-section h3 { font-size: 14px; margin-bottom: 2px; }
.settings-section .modal-sub { margin-bottom: 14px; }

.kv-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-page);
  border-radius: 6px;
  padding: 8px 10px;
  word-break: break-all;
}

.save-confirm {
  font-size: 12px;
  color: var(--status-good);
  margin-left: 10px;
  opacity: 0;
  transition: opacity 0.2s;
}
.save-confirm.visible { opacity: 1; }

/* ---------------------------------------------------------------
   Messages page
   --------------------------------------------------------------- */
.chat-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 560px;
}
.chat-contacts {
  border-right: 1px solid var(--gridline);
  padding: 8px;
  overflow-y: auto;
}
.chat-contacts .node-list li { gap: 10px; }

.chat-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-thread-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--gridline);
  font-weight: 600;
  font-size: 14px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg-row { display: flex; flex-direction: column; max-width: 70%; }
.msg-you { align-self: flex-end; align-items: flex-end; }
.msg-them { align-self: flex-start; align-items: flex-start; }
.msg-bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.4;
}
.msg-you .msg-bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg-them .msg-bubble { background: var(--surface-page); color: var(--text-primary); border-bottom-left-radius: 4px; }
.msg-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; padding: 0 2px; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--gridline);
}
.chat-input-row input {
  flex: 1;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
}
.chat-input-row input:focus { outline: none; border-color: var(--accent); }
.chat-send-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.chat-send-btn svg { width: 16px; height: 16px; }
.chat-send-btn:hover { background: var(--accent-hover); }

/* ---------------------------------------------------------------
   Logs page
   --------------------------------------------------------------- */
.log-type {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface-page);
  color: var(--text-secondary);
}
.log-type.trigger { background: color-mix(in srgb, var(--status-critical) 16%, var(--surface-page)); color: var(--status-critical); }
.log-type.message { background: color-mix(in srgb, var(--accent) 14%, var(--surface-page)); color: var(--accent); }
.inline-select {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-primary);
}
.inline-select:focus { outline: none; border-color: var(--accent); }
.log-detail {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ---------------------------------------------------------------
   Catches page — every trigger event with a species picker per row
   --------------------------------------------------------------- */
.catch-list { list-style: none; margin: 0; padding: 0; }

.catch-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 6px;
  border-bottom: 1px solid var(--gridline);
  border-radius: 6px;
}
.catch-row:last-child { border-bottom: none; }

/* Needs-logging cue -- a tint, never the only signal: the row still says
   "Log" (vs "Update") and the select still defaults to its placeholder,
   so nothing here depends on color alone. Same red as "Triggered"
   elsewhere (--status-critical), not --status-warning -- an unlogged
   trigger is the thing this whole page exists to chase down. */
.catch-row--pending { background: color-mix(in srgb, var(--status-critical) 8%, transparent); }

.catch-row--highlight { background: color-mix(in srgb, var(--accent) 14%, transparent); }

.catch-row-info { display: flex; flex-direction: column; gap: 2px; min-width: 140px; }
.catch-row-info .name { font-weight: 500; font-size: 13px; }
.catch-row-info .time { font-size: 12px; color: var(--text-muted); }

.catch-row-action { display: flex; align-items: center; gap: 8px; }

.catch-species-select {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-primary);
}
.catch-species-select:focus { outline: none; border-color: var(--accent); }

.catch-other-input {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-primary);
  width: 140px;
}
.catch-other-input:focus { outline: none; border-color: var(--accent); }

/* ---------------------------------------------------------------
   Row action menu -- a per-row "⋮" hamburger on the Admin > Users table
   (web/js/admin.js), tidying up what used to be 3-4 buttons + a visible
   "Notify topic" column crammed into every row. Same open/close pattern as
   the map's .mp-layer-panel hamburger: a button toggles a hidden absolute
   panel, closed by clicking elsewhere.
   --------------------------------------------------------------- */
.row-menu-wrap { position: relative; display: inline-block; }
.row-menu-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-secondary);
}
.row-menu-btn:hover { color: var(--text-primary); border-color: var(--text-muted); }
.row-menu-btn svg { width: 16px; height: 16px; }

.row-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 220px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 8px;
  font-size: 13px;
  z-index: 30;
}
.row-menu.hidden { display: none; }
.row-menu-topic {
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 6px 8px;
  border-bottom: 1px solid var(--gridline);
  margin-bottom: 6px;
  word-break: break-all;
}
.row-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 8px;
  border-radius: 6px;
  border: none;
  background: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.row-menu button:hover { background: var(--surface-page); }

/* ---------------------------------------------------------------
   Signal bars -- Device Details' "Link freshness" indicator
   (web/js/devices.js). Deliberately NOT labelled "signal quality": the
   companion protocol exposes no real RSSI/SNR for a cached contact, only
   how recently its advert was last heard (see gateway-listener.js's
   adventRecencyScore()) -- these bars are that recency, decayed over
   ~6h, not real signal strength.
   --------------------------------------------------------------- */
.signal-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 13px; vertical-align: middle; }
.signal-bars .bar { width: 3px; background: var(--gridline); border-radius: 1px; }
.signal-bars .bar:nth-child(1) { height: 30%; }
.signal-bars .bar:nth-child(2) { height: 45%; }
.signal-bars .bar:nth-child(3) { height: 62%; }
.signal-bars .bar:nth-child(4) { height: 80%; }
.signal-bars .bar:nth-child(5) { height: 100%; }
.signal-bars .bar.filled { background: var(--accent); }
