:root {
  --bg: #f5f6f8;
  --panel-bg: #ffffff;
  --border: #d8dce2;
  --text: #1c2128;
  --muted: #6b7280;
  --accent: #2563eb;
  --rx: #059669;
  --tx: #2563eb;
  --warn-bg: #fff7e6;
  --warn-border: #d97706;
  --error-bg: #fdecec;
  --error-border: #dc2626;
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel-bg: #171b21;
    --border: #2b313a;
    --text: #e6e8eb;
    --muted: #8b93a0;
    --accent: #60a5fa;
    --rx: #34d399;
    --tx: #60a5fa;
    --warn-bg: #2a2210;
    --warn-border: #d97706;
    --error-bg: #2a1414;
    --error-border: #ef4444;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
}

header h1 {
  font-size: 1.1rem;
  margin: 0;
}

#sidebar-toggle {
  align-self: center;
  font-size: 1rem;
  line-height: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text);
  cursor: pointer;
}
#sidebar-toggle:hover { border-color: var(--accent); }

body.sidebar-collapsed #sidebar {
  display: none;
}

.status {
  font-size: 0.8rem;
  color: var(--muted);
}
.status.ok { color: var(--rx); }
.status.down { color: var(--error-border); }
.status.warn { color: var(--warn-border); }

main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#sidebar {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--panel-bg);
  display: flex;
  flex-direction: column;
  min-height: 0; /* lets the inner scroller actually scroll instead of growing the column */
}

/* Everything above the docked Latest Command block scrolls on its own. */
#sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

#sidebar h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 8px;
}

#sidebar section + section {
  margin-top: 24px;
}

.hint {
  font-size: 0.76rem;
  color: var(--muted);
  margin: 0 0 10px;
  line-height: 1.4;
}

/* Launchers for the standalone archive-backed pages (Route (from DB), and more to come) - a
   simple stacked list so a second/third link is just another <a> here, no redesign needed. Same
   bordered-pill look as #clear-log/#export-open so it reads as an action, not a plain text link. */
.report-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.report-link {
  display: block;
  font-size: 0.8rem;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text);
  text-decoration: none;
  text-align: center;
}
.report-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#device-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#device-list li {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.82rem;
  cursor: pointer;
}

#device-list li:hover:not(.empty) {
  border-color: var(--accent);
}

#device-list li.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-bg));
}

#device-list li.empty {
  color: var(--muted);
  border-style: dashed;
  cursor: default;
}

#device-list .imei {
  font-family: var(--mono);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

#device-list .meta {
  color: var(--muted);
  margin-top: 2px;
}

.conn-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

.conn-line {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
}

.conn-line.closed {
  opacity: 0.6;
}

.conn-id {
  color: var(--muted);
}

.conn-addr {
  color: var(--text);
}

.conn-close-icon {
  margin: 0 2px;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.online { background: var(--rx); }
.dot.offline { background: var(--muted); }

/* Wrapper claims the auto margin once, regardless of how many badges it holds - avoids an
   adjacency override rule per badge pair as more badge kinds are added. */
.badges {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.queued-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--warn-border);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 10px;
  padding: 1px 8px;
}

.alarm-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--error-border);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 10px;
  padding: 1px 8px;
}

.device-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  line-height: 16px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--panel-bg);
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.1s ease;
}

#device-list li:hover .device-remove,
#device-list li:focus-within .device-remove,
.device-remove:focus {
  opacity: 1;
}

.device-remove:hover {
  border-color: var(--error-border);
  color: var(--error-border);
}

#send-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#send-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

#send-form input,
#send-form select {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

#send-form button {
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

#send-form button:hover { opacity: 0.9; }

#send-status {
  font-size: 0.8rem;
  min-height: 1.2em;
}
#send-status.ok { color: var(--rx); }
#send-status.err { color: var(--error-border); }

#log-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.autoscroll {
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

#clear-log,
#export-open {
  font-size: 0.8rem;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text);
  cursor: pointer;
}

.log-scope {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 20px;
  font-size: 0.78rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--accent) 8%, var(--panel-bg));
  border-bottom: 1px solid var(--border);
}

.log-scope strong {
  font-family: var(--mono);
  color: var(--text);
}

.log-scope-spacer {
  flex: 1;
}

.device-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.status-chips,
.alarm-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.strip-sep {
  color: var(--border);
  font-size: 0.85rem;
}

/* Rectangular, no dot - deliberately different from .alarm-icon's pill shape so status info and
   active alarms stay visually unmistakable at a glance in the shared strip. */
.status-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.76rem;
  cursor: default;
}

.status-chip.on {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-bg));
  color: var(--accent);
  font-weight: 600;
}

.overview {
  padding: 4px 4px 14px;
  background: var(--panel-bg);
}

.overview-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.overview-header h2 {
  font-size: 0.85rem;
  margin: 0;
}

#overview-meta {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--mono);
  flex: 1;
}

#overview-dialog {
  max-width: min(1100px, 92vw);
  max-height: 88vh;
  overflow: auto;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--text);
}

#overview-dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.dialog-close {
  align-self: flex-start;
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text);
  cursor: pointer;
}
.dialog-close:hover { border-color: var(--accent); }

#export-dialog {
  max-width: min(420px, 92vw);
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--text);
}

#export-dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.export-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.export-header h2 {
  font-size: 0.85rem;
  margin: 0;
  flex: 1;
}

#export-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#export-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* #export-form label/#export-custom-range above set display:flex, which out-specifies the
   [hidden] { display: none } the browser applies by default - without this rule, setting the
   .hidden property from JS on anything inside this form has no visible effect. */
#export-form [hidden] {
  display: none;
}

.control-disabled {
  opacity: 0.5;
}
.control-disabled select {
  cursor: not-allowed;
}

#export-form input,
#export-form select {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

#export-form button {
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

#export-form button:hover { opacity: 0.9; }
#export-form button:disabled { opacity: 0.5; cursor: not-allowed; }

#export-custom-range {
  display: flex;
  gap: 10px;
}
#export-custom-range label {
  flex: 1;
}

#export-status {
  font-size: 0.8rem;
  min-height: 1.2em;
}
#export-status.err { color: var(--error-border); }

#export-open:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Docked at the bottom of the sidebar, directly under the send form, so firing a command and
   seeing whether it landed happen in the same column. */
#latest-command {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  background: var(--bg); /* sits slightly apart from the --panel-bg sidebar above it */
}

#latest-command-body {
  max-height: 40vh; /* a long multi-config reply must not crowd the device list off-screen */
  overflow-y: auto;
}

.latest-command-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.latest-command-head h2 {
  margin: 0; /* the rest is inherited from the shared #sidebar h2 rule */
}

.cmd-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  font-family: var(--mono);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.cmd-status.waiting { border-color: var(--warn-border); color: var(--warn-border); }
.cmd-status.ok { border-color: var(--rx); color: var(--rx); }
.cmd-status.failed { border-color: var(--error-border); background: var(--error-bg); color: var(--error-border); }

.cmd-status .pending-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn-border);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn-border) 25%, transparent);
  flex-shrink: 0;
}

/* seq=0x05 · 2026-08-04 13:05:54 · 862596089245157 */
.cmd-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}

.cmd-block + .cmd-block {
  margin-top: 8px;
}

.cmd-block-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 2px;
}

.cmd-block-text {
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.45;
  white-space: pre-wrap; /* renders the '\n'-joined reply fields one per line */
  overflow-wrap: anywhere;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
}

.cmd-empty {
  font-size: 0.76rem;
  color: var(--muted);
}

.alarm-panel {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.alarm-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.alarm-panel-head h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0;
}

.alarm-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.alarm-grid:empty::after {
  content: "(no alarm types known)";
  color: var(--muted);
  font-size: 0.78rem;
}

.alarm-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-bg);
  color: var(--muted);
  font-size: 0.76rem;
  cursor: default;
}

.alarm-icon .alarm-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.alarm-icon.active {
  border-color: var(--error-border);
  background: var(--error-bg);
  color: var(--error-border);
  font-weight: 600;
  cursor: pointer;
}

.alarm-icon.active .alarm-dot {
  background: var(--error-border);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--error-border) 25%, transparent);
}

.alarm-icon.active:hover {
  opacity: 0.85;
}

@keyframes alarm-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.alarm-icon.blink {
  animation: alarm-blink 0.35s ease-in-out 4;
}

.overview-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.overview-empty {
  color: var(--muted);
  font-size: 0.82rem;
  grid-column: 1 / -1;
}

.overview-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel-bg);
}

.overview-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.overview-card-time {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
}

.overview-card-fields {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.82rem;
}

.overview-card-fields li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.overview-card-fields .field-label {
  color: var(--muted);
  flex-shrink: 0;
}

.overview-card-fields .field-value {
  font-family: var(--mono);
  text-align: right;
  overflow-wrap: anywhere;
}

.overview-card-fields li.subitem {
  justify-content: flex-start;
  padding-left: 10px;
  border-left: 2px solid var(--border);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
}

/* Explicit width/height (not just max-*) because a <dialog> defaults to width/height: fit-content -
   without a real size to fit, it shrinks to whatever's smallest instead of using available screen
   space, which is what made the map render as a sliver. */
#map-dialog {
  width: min(1400px, 96vw);
  height: min(900px, 92vh);
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--text);
}

/* <dialog>'s UA stylesheet sets display:block when open - overridden to flex so .map-view (and in
   turn #map) can actually fill the dialog's full height instead of sizing to its content. */
#map-dialog[open] {
  display: flex;
}

#map-dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.map-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.map-view-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.map-view-header h2 {
  font-size: 0.85rem;
  margin: 0;
}

#map-meta {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--mono);
  flex: 1;
}

.map-body {
  display: flex;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

#map {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Leaflet's div-icon UA styles (white background + border) are meant for plain content, not a
   pre-styled badge - stripped here so .map-pin's own background/shape shows through cleanly. */
.map-pin-icon {
  background: none;
  border: none;
}

.map-pin {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: system-ui, sans-serif;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.map-list {
  list-style: none;
  margin: 0;
  /* Right padding becomes part of the max-content calc below (box-sizing: border-box, set
     globally) - it's a deliberate buffer between the longest line and the scrollbar/edge, not
     just leftover space. */
  padding: 0 0 0 0;
  /* Sized to whatever the longest line actually needs, rather than a guessed fixed width - a
     device near the equator/prime meridian needs far less room than one with two negative,
     six-decimal coordinates plus a speed. max-width is just a safety net so one pathologically
     long line can't crowd out the map; ordinary content never gets close to it (it wraps, not
     truncates, if it ever did). */
  width: max-content;
  max-width: min(320px, 42%);
  flex-shrink: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.map-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 8px;
  row-gap: 1px;
  padding: 6px 16px 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
}
.map-list li:hover { border-color: var(--accent); }
.map-list li.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-bg));
}
.map-list li.empty {
  color: var(--muted);
  cursor: default;
  display: block;
}

/* Same colored/numbered badge as the map's own pins (see map.js's pinIcon), so a number means the
   same thing in both places - that's the whole point of numbering them. */
.map-list-pin {
  grid-row: 1 / 3;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: system-ui, sans-serif;
  flex-shrink: 0;
}

.map-list-line1 {
  grid-column: 2;
  font-weight: 600;
}

.map-list-line2 {
  grid-column: 2;
  font-family: var(--mono);
  color: var(--muted);
}

/* On a narrow screen the fixed-width side list (300px) left almost nothing for the map itself -
   below this breakpoint, drop the list entirely so #map's flex:1 has the whole .map-body to
   itself. Marker popups (type/time/coords) already carry the same info a tapped list row would,
   so nothing is lost - just reached by tapping a marker instead of a row. */
@media (max-width: 700px) {
  .map-list {
    display: none;
  }
}

/* -------------------------------------------------------------------------------------------
   archive-route.html and archive-log.html - the standalone "Route (from DB)" and "Packet Log
   (from DB)" pages. Reuses the map-view, map-body, map, and map-list/map-pin rule families above
   (route page), and the log, filters, chip, and entry rule families (log page), all as-is - none
   of it is dialog- or dashboard-panel-specific. This block only supplies what map-dialog and
   log-panel used to (a real height for each page's own content area), plus one shared filter-form
   toolbar, adapted from export-form into a horizontal layout since these are full pages, not a
   narrow dialog.
   ------------------------------------------------------------------------------------------- */
#route-page,
#log-page {
  /* Overrides the bare `main` rule's row default (used for the live dashboard's aside+section
     layout) - specific to these ids so it can't affect index.html, which loads the same
     stylesheet. */
  flex-direction: column;
  min-height: 0;
  gap: 14px;
  padding: 16px 20px;
}

.archive-filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  flex-shrink: 0;
}

.archive-filter-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.archive-filter-form input,
.archive-filter-form select {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.archive-filter-form button {
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.archive-filter-form button:hover { opacity: 0.9; }

/* Narrower than the shared .archive-filter-form input rule's default width - a row-count field
   doesn't need IMEI-textbox-sized room. */
.archive-filter-form input[type="number"] {
  width: 6rem;
}

.archive-status {
  font-size: 0.8rem;
  color: var(--muted);
}
.archive-status.err { color: var(--error-border); }

#route-page .map-view {
  min-height: 0;
}

#log-page .filters {
  flex-shrink: 0;
}

#log-page #log {
  flex: 1;
  min-height: 0;
}

.filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.78rem;
}

.filter-label {
  color: var(--muted);
  width: 90px;
  flex-shrink: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  background: var(--bg);
}

.chip input {
  margin: 0;
}

.chip:has(input:checked) {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#filter-types {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-row input[type="datetime-local"] {
  font: inherit;
  font-size: 0.76rem;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.link-btn {
  font-size: 0.76rem;
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

#log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#log.filtered-empty::after {
  content: "no events match the current filters";
  color: var(--muted);
  font-size: 0.85rem;
}

.entry {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--panel-bg);
  font-size: 0.85rem;
  /* Off-screen entries skip layout/paint entirely - without this, every appended event re-lays-out
     the whole (up to MAX_LIVE_ROWS) log, which is what made a long-running dashboard tab drag. */
  content-visibility: auto;
  contain-intrinsic-size: auto 90px;
}

.entry.rx { border-left-color: var(--rx); }
.entry.tx { border-left-color: var(--tx); }
.entry.warn { background: var(--warn-bg); border-left-color: var(--warn-border); }
.entry.error { background: var(--error-bg); border-left-color: var(--error-border); }

.entry-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
}

/* Only present on the "Packet Log (from DB)" page (options.packetNumber, see log-render.js) - the
   live dashboard's own rows never carry this. A filled accent pill rather than the muted bracket
   text used for connection id ([#0], right below) so the two aren't mistaken for each other at a
   glance - this number identifies the packet's position among the ones pulled, not a live
   connection. */
.entry-head .pkt-num {
  font-family: system-ui, sans-serif;
  font-weight: 700;
  font-size: 0.7rem;
  min-width: 1.6em;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  text-align: center;
}

.entry-head .dir {
  font-weight: 700;
}
.entry.rx .dir { color: var(--rx); }
.entry.tx .dir { color: var(--tx); }

.entry-head .pending-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn-border);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn-border) 25%, transparent);
  flex-shrink: 0;
}

.entry-head .type-badge {
  font-family: system-ui, sans-serif;
  font-weight: 600;
  font-size: 0.72rem;
  padding: 1px 8px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}

.entry-head .map-btn {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  filter: grayscale(1);
  opacity: 0.7;
}
.entry-head .map-btn:hover { filter: none; opacity: 1; }

.entry-lines {
  font-family: var(--mono);
  white-space: pre-wrap;
  margin-top: 4px;
  line-height: 1.4;
}

.entry details {
  margin-top: 4px;
}

.entry summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.75rem;
}

/* The collapsible detail toggle's summary line reuses .entry-lines' typography (not the smaller,
   muted "raw bytes" style above) since, collapsed, it's the primary line for this packet - not a
   secondary aside. Specificity over ".entry summary" comes from the extra class, not source order. */
.entry .detail-toggle > summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text);
  white-space: pre-wrap;
}

.msg-header {
  font-weight: 600;
}

.msg-summary {
  color: var(--muted);
  margin-left: 6px;
}

/* Expanded: the summary text disappears, leaving just the bare "  TypeName (0xID)" header above
   the full detail block below it - collapsing again brings the summary text back. */
/*
.detail-toggle[open] > summary .msg-summary {
  display: none;
}
*/
.detail-toggle .entry-lines {
  margin-top: 4px;
}

.entry .raw-hex {
  font-family: var(--mono);
  font-size: 0.72rem;
  word-break: break-all;
  color: var(--muted);
  margin-top: 4px;
}

/* --- "Packets" live view: one row per TCP packet, switchable with the Events view's .entry rows
   above. Same design language (colors, mono font, pill badges) - own classes because a packet row's
   internal structure (header line + wrapped sub-message chips) genuinely differs from an .entry's. */

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.view-toggle button {
  font: inherit;
  font-size: 0.78rem;
  background: var(--bg);
  border: none;
  padding: 4px 12px;
  cursor: pointer;
  color: var(--muted);
}

.view-toggle button.active {
  background: var(--accent);
  color: #fff;
}

.packet-row {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--panel-bg);
  font-size: 0.85rem;
  content-visibility: auto;
  contain-intrinsic-size: auto 90px;
}

.packet-row.rx { border-left-color: var(--rx); }
.packet-row.tx { border-left-color: var(--tx); }
.packet-row.warn { background: var(--warn-bg); border-left-color: var(--warn-border); }
.packet-row.error { background: var(--error-bg); border-left-color: var(--error-border); }

.packet-row-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
}

.packet-row-head .dir { font-weight: 700; }
.packet-row.rx .dir { color: var(--rx); }
.packet-row.tx .dir { color: var(--tx); }

.packet-row-head .type-badge {
  font-family: system-ui, sans-serif;
  font-weight: 600;
  font-size: 0.72rem;
  padding: 1px 8px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}

.packet-row-head .map-btn {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  filter: grayscale(1);
  opacity: 0.7;
}
.packet-row-head .map-btn:hover { filter: none; opacity: 1; }

/* display:contents removes the <details> element's own box, promoting its two children (the
   <summary> and the .raw-hex div) to be direct flex items of .packet-row-head instead - the native
   open/close hide-show behavior is a UA rule keyed on the DOM parent/child relationship, so it still
   applies. That's what lets "raw" stay pinned in place at the end of the header (never moving) while
   only .raw-hex itself claims the full row width and wraps onto its own line when opened, since
   .packet-row-head is flex-wrap:wrap - without this split, flex-basis:100% on the whole <details>
   would drag "raw" down onto that new line along with its content. */
.packet-row-head .raw-toggle {
  display: contents;
}
.packet-row-head .raw-toggle > summary {
  list-style: none;
  cursor: pointer;
  color: var(--accent);
  text-decoration: underline;
}
.packet-row-head .raw-toggle > summary::-webkit-details-marker { display: none; }
.packet-row-head .raw-toggle > summary:hover {
  opacity: 0.75;
}
.packet-row-head .raw-hex {
  flex-basis: 100%;
  font-family: var(--mono);
  font-size: 0.72rem;
  word-break: break-all;
  color: var(--muted);
  margin-top: 4px;
}

.packet-row-cmd {
  font-family: var(--mono);
  font-size: 0.8rem;
  margin-top: 4px;
  color: var(--text);
}

.col-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

/* One populated sub-message-type column - a native <details> so its full per-instance detail (the
   same LogFields.Build field list the Events view's own .detail-toggle expands) is a click away
   without leaving the row. */
.col-chip {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 0.78rem;
}

.col-chip > summary {
  list-style: none;
  cursor: pointer;
  padding: 3px 10px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}
.col-chip > summary::-webkit-details-marker { display: none; }

.col-chip-label {
  font-weight: 600;
  color: var(--text);
}

.col-chip-value {
  font-family: var(--mono);
  color: var(--muted);
}

.col-chip[open] > summary {
  white-space: normal;
}

/* Small warning glyph on a chip whose sub-message's own device timestamp differs from the row's
   shared sub_time - the live counterpart of the CSV export's inline "*[...]" marker. */
.col-chip-outlier {
  cursor: help;
  color: var(--warn-border);
}

.col-chip-body {
  padding: 0 10px 6px;
  font-size: 0.78rem;
}
