/*
 * One page, one stylesheet, with the tokens of the Domino and Engelmann benches.
 * A machine-produced fact (a DevEUI, a payload, a topic) is set in the
 * mono face. This file is downloaded by whoever opens the page, comments included.
 */

:root {
  --ink: #17191c;
  --ink-quiet: #4a4f57;
  --ink-faint: #767c86;
  --page: #f7f8fa;
  --card: #ffffff;
  --edge: #dfe3e8;
  --accent: #1a5fb4;
  --bad: #b3261e;
  --good: #1c7c48;
  --waiting: #8a5a00;

  --text-caption: 0.75rem;
  --text-small: 0.85rem;
  --text-body: 0.95rem;
  --text-lead: 1.1rem;
  --text-title: 1.5rem;

  --control: 34px;

  --gap-xs: 4px;
  --gap-s: 8px;
  --gap-m: 12px;
  --gap-l: 20px;
  --gap-xl: 32px;

  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: var(--gap-xl) var(--gap-l);
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-body);
  line-height: 1.5;
}

main, .masthead { max-width: 1400px; margin: 0 auto; }
.masthead h1 { font-size: var(--text-title); margin: 0 0 var(--gap-xs); font-weight: 600; }
.lede { margin: 0 0 var(--gap-l); color: var(--ink-quiet); max-width: 70ch; }

h2 { font-size: var(--text-lead); margin: 0; font-weight: 600; }
h3 { font-size: var(--text-body); margin: 0 0 var(--gap-s); font-weight: 600; }

.panel {
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: var(--gap-l);
  margin-bottom: var(--gap-l);
  min-width: 0;
}
.narrow-panel { max-width: 420px; }
.table-panel { padding: 0; overflow-x: auto; }

.field { display: block; margin-bottom: var(--gap-m); }
.label { display: block; font-size: var(--text-small); color: var(--ink-quiet); margin-bottom: var(--gap-xs); }
.hint { color: var(--ink-faint); font-weight: 400; }

input[type=text], input[type=password], input[type=search] {
  width: 100%;
  font-family: var(--font-mono);
  font-size: var(--text-small);
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: var(--gap-s) var(--gap-m);
  height: var(--control);
}
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit;
  font-size: var(--text-small);
  height: var(--control);
  padding: 0 var(--gap-m);
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { filter: brightness(1.08); }
button[disabled] { opacity: 0.6; cursor: default; }
button.quiet { background: var(--card); color: var(--ink); border-color: var(--edge); }
button.quiet:hover { filter: none; border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.wide { width: 100%; }

.row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--gap-m); }
.row .grow { flex: 1 1 240px; margin-bottom: 0; }
.row.end { justify-content: flex-end; }
.row.head { align-items: center; margin-bottom: var(--gap-s); }
.spacer { flex: 1 1 auto; }
.check { display: flex; align-items: center; gap: var(--gap-xs); height: var(--control); font-size: var(--text-small); }

.privacy, .note { color: var(--ink-faint); font-size: var(--text-small); margin: var(--gap-s) 0 0; }
.refusal { color: var(--bad); }
.warning { color: var(--waiting); margin: var(--gap-s) 0 0; }

code { font-family: var(--font-mono); font-size: var(--text-small); overflow-wrap: anywhere; }

table { width: 100%; border-collapse: collapse; font-size: var(--text-small); }
th, td { text-align: left; padding: var(--gap-s) var(--gap-m); border-bottom: 1px solid var(--edge); vertical-align: top; }
th { color: var(--ink-quiet); font-weight: 500; }

.facts { display: flex; flex-wrap: wrap; gap: var(--gap-s) var(--gap-xl); color: var(--ink-quiet); margin: 0 0 var(--gap-l); }



dialog { border: 1px solid var(--edge); border-radius: 8px; padding: var(--gap-l); max-width: min(520px, 92vw); }
dialog::backdrop { background: rgb(0 0 0 / 30%); }
dialog p { margin: var(--gap-s) 0; }

@media (max-width: 600px) {
  body { padding: var(--gap-l) var(--gap-m); }
  .panel { padding: var(--gap-m); }
}

/* The title's row: who is signed in, and their buttons. */
.row.top { align-items: center; margin-bottom: var(--gap-xs); }
.row.top h1 { margin: 0; }
.who { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-s); font-size: var(--text-small); }
.who .role { color: var(--ink-faint); margin-right: var(--gap-s); }

select {
  font: inherit;
  font-size: var(--text-small);
  height: var(--control);
  padding: 0 var(--gap-s);
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
}
.row .narrow { flex: 0 0 auto; margin-bottom: 0; }
.actions { display: flex; flex-wrap: wrap; gap: var(--gap-s); justify-content: flex-end; }
.link { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-s); margin: var(--gap-m) 0 0; }
.link code { background: var(--page); border: 1px solid var(--edge); border-radius: 6px; padding: var(--gap-xs) var(--gap-s); }
#users td { vertical-align: middle; }


textarea {
  width: 100%;
  font: inherit;
  font-size: var(--text-small);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: var(--gap-s) var(--gap-m);
  resize: vertical;
}

/* The tabs of a signed-in administrator. */
.tabs { display: flex; flex-wrap: wrap; gap: var(--gap-xs); margin-left: var(--gap-l); }
.tabs a {
  color: var(--ink-quiet);
  text-decoration: none;
  font-size: var(--text-small);
  padding: var(--gap-xs) var(--gap-m);
  border-radius: 6px;
}
.tabs a:hover { background: var(--card); }
.tabs a.current { background: var(--card); color: var(--ink); border: 1px solid var(--edge); }

.wide-panel { max-width: 640px; }
input.short { width: 7ch; }
.inline { margin-bottom: 0; }
.pad { padding: var(--gap-m) var(--gap-m) 0; }
.table-panel .row.head.pad { margin-bottom: var(--gap-s); }
.table-scroll { max-height: 50vh; overflow: auto; border: 1px solid var(--edge); border-radius: 6px; margin: var(--gap-m) 0; }

.state { font-size: var(--text-small); padding: 2px var(--gap-s); border-radius: 999px; border: 1px solid var(--edge); }
.state-connected, .state-running { color: var(--good); border-color: var(--good); }
.state-connecting, .state-reconnecting { color: var(--waiting); border-color: var(--waiting); }
.state-failed { color: var(--bad); border-color: var(--bad); }
.state-stopped { color: var(--ink-faint); }

td.mono, .mono { font-family: var(--font-mono); }
td.payload code { display: block; max-width: 40ch; }
.devices tbody tr, #monitor-devices tr { cursor: pointer; }
.devices tbody tr:hover { background: var(--page); }
.devices .values { margin: 0; padding: 0; list-style: none; }
.devices .values li, .messages .values li { white-space: nowrap; }
.values { margin: 0; padding: 0; list-style: none; }
.values .number { font-family: var(--font-mono); }
.faint { color: var(--ink-faint); }
.bad { color: var(--bad); }
.good { color: var(--good); }
.kind { font-size: var(--text-caption); text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-quiet); }
.kind-uplink { color: var(--accent); }
.kind-downlink { color: var(--waiting); }

.segmented { display: flex; gap: var(--gap-m); margin: var(--gap-s) 0 var(--gap-m); font-size: var(--text-small); }
.segmented label { display: flex; align-items: center; gap: var(--gap-xs); }
.wide-dialog { max-width: min(860px, 94vw); width: 100%; }

.logger { margin-bottom: var(--gap-l); }
.logger .facts { margin-bottom: var(--gap-s); }
.logger table { margin-top: var(--gap-s); }
.destination { border: 1px solid var(--edge); border-radius: 6px; padding: var(--gap-m); margin-bottom: var(--gap-m); }
.destination .row { align-items: flex-end; }
.download { display: flex; flex-wrap: wrap; gap: var(--gap-s); align-items: flex-end; }
.download input[type=date] { height: var(--control); border: 1px solid var(--edge); border-radius: 6px; padding: 0 var(--gap-s); font: inherit; font-size: var(--text-small); }

@media (max-width: 760px) {
  .tabs { margin-left: 0; order: 3; width: 100%; }
}

/* The logo is the page's title. The picture is twice its drawn size, for a sharp screen. */
.home { display: block; line-height: 0; }
.logo { display: block; height: 60px; width: auto; }
@media (max-width: 600px) {
  .logo { height: 44px; }
}

/* What a field of a command form is for, under its box. */
.field .about { display: block; margin-top: var(--gap-xs); font-size: var(--text-small); }

/* A device opens its quantities on a click, as a meter does on the gateway
   bench; one with none does not invite the click. */
.devices tbody tr { cursor: default; }
.devices tbody tr.opens { cursor: pointer; }
.devices tbody tr.opens:hover > td { background: var(--page); }
.devices tr.is-open > td { border-bottom-color: transparent; }
.devices .fold { display: inline-block; width: 1.2em; color: var(--ink-faint); }
.devices tr.detail > td { padding: 0; background: var(--page); }
.devices .number { font-family: var(--font-mono); }

/* The quantities under a device: a name, what it reads, when the meter measured
   it, how many values were heard, and how far it moved. */
table.quantities { border-collapse: collapse; font-size: var(--text-small); width: 100%; }
table.quantities td { padding: 2px var(--gap-l) 2px 0; border-bottom: none; white-space: nowrap; vertical-align: top; }
table.quantities td:first-child { padding-left: calc(var(--gap-m) + 1.2em); }
table.quantities tr:last-child td { padding-bottom: var(--gap-s); }
table.quantities td.amount { font-family: var(--font-mono); }
table.quantities td.change { width: 100%; }
.quantities .subunit { color: var(--ink-faint); font-size: var(--text-caption); }
.rises { color: var(--good); font-family: var(--font-mono); font-weight: 600; }
.falls { color: var(--waiting); font-family: var(--font-mono); font-weight: 600; }
.moved { display: inline-block; vertical-align: middle; font-size: 1.5em; line-height: 0; color: var(--good); }
.devices tbody tr > td:first-child { white-space: nowrap; }
.devices .actions { flex-wrap: nowrap; }

/* A device's row is one line: nothing in it wraps, and what does not fit a
   line is under the fold. */
.devices > tbody > tr:not(.detail) > td { white-space: nowrap; vertical-align: middle; }
.devices td.count { font-variant-numeric: tabular-nums; }
.devices .device-facts { margin: var(--gap-s) var(--gap-m) var(--gap-s) calc(var(--gap-m) + 1.2em); gap: var(--gap-xs) var(--gap-l); font-size: var(--text-small); }
.devices .device-refusal { margin: 0 var(--gap-m) var(--gap-s) calc(var(--gap-m) + 1.2em); font-size: var(--text-small); }

/* A message is one line too; a long payload or sentence ends in an ellipsis,
   and the whole of it is under the fold. The monitor's list of a device's
   messages keeps its payload to one line the same way. */
.messages > tbody > tr:not(.detail) > td { white-space: nowrap; vertical-align: middle; }
.messages tbody tr.opens { cursor: pointer; }
.messages tbody tr.opens:hover > td { background: var(--page); }
.messages tr.is-open > td { border-bottom-color: transparent; }
.messages tr.detail > td { padding: 0 0 var(--gap-s); background: var(--page); }
.messages .fold { display: inline-block; width: 1.2em; color: var(--ink-faint); }
.messages td.payload code { display: inline-block; max-width: 24ch; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.messages td.says { max-width: 46ch; overflow: hidden; text-overflow: ellipsis; }
.messages td.says > span { white-space: nowrap; }
.messages .device-facts, .messages .device-refusal { margin: var(--gap-s) var(--gap-m) 0 calc(var(--gap-m) + 1.2em); font-size: var(--text-small); }
.messages code.hex { overflow-wrap: anywhere; }
