:root {
  --bg: #14171c;
  --panel: #1c2027;
  --panel-2: #232833;
  --line: #2f3542;
  --text: #e6e9ef;
  --muted: #8d97a8;
  --accent: #4aa3ff;
  --ok: #4ec46e;
  --warn: #e0a931;
  --danger: #e2564d;
  /* Chart series. Checked against the panel colour for contrast and for
     staying distinguishable with colour-blindness; do not swap casually. */
  --series-1: #3987e5;
  --series-2: #d95926;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
/* An author `display` rule beats the browser's [hidden]{display:none}, so
   el.hidden = true would set the property but leave the element on screen. */
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
h1, h2 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 20px; } h2 { font-size: 15px; letter-spacing: .02em; }
h1 strong, .brand strong { color: var(--accent); }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 20px; margin: 8px 0 0; font-size: 13px; }

/* ---- controls ---- */
button, input, select {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 11px;
}
button { cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #08131f; font-weight: 600; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 4px; margin: 0 0 12px; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; }
input:not([type=checkbox]), select { width: 100%; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 12px; padding: 10px 12px; min-width: 0; }
legend label { margin: 0; font-weight: 600; }

/* ---- login ---- */
.login-screen { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; width: min(360px, 100%); display: grid; gap: 4px;
}
.login-card h1 { text-align: center; }

/* ---- chrome ---- */
header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-size: 16px; }
.listeners { display: flex; gap: 14px; flex-wrap: wrap; }
.listener { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.off { background: var(--danger); }

nav {
  display: flex; gap: 2px; padding: 0 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); overflow-x: auto;
}
nav button {
  background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  color: var(--muted); padding: 10px 14px;
}
nav button:hover { color: var(--text); }
nav button.active { color: var(--text); border-bottom-color: var(--accent); }

main { max-width: 1240px; margin: 0 auto; padding: 20px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin: 0 0 16px; overflow-x: auto;
}
.panel.narrow { max-width: 420px; }
.panel.warn { border-color: var(--warn); }
.panel.warn p { margin: 0 0 6px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row h2 { margin: 0; flex: 1; }
.row input { flex: 1; min-width: 180px; width: auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.notice {
  position: sticky; top: 8px; z-index: 5; margin: 0 0 16px; padding: 10px 14px;
  border-radius: var(--radius); background: var(--panel-2); border: 1px solid var(--accent);
}
.notice.bad { border-color: var(--danger); white-space: pre-wrap; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; }
td.actions button { margin-left: 6px; padding: 4px 9px; font-size: 13px; }
.tag { display: inline-flex; align-items: center; gap: 6px; }
.tag.disabled { color: var(--warn); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
ul.plain { list-style: none; padding: 0; margin: 8px 0 0; color: var(--muted); }
details { margin-top: 12px; }
summary { cursor: pointer; }
pre {
  margin: 12px 0 0; padding: 12px; background: #0f1216; border: 1px solid var(--line);
  border-radius: 6px; max-height: 60vh; overflow: auto; font-size: 12px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
}

/* ---- overview: machine tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 0 0 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.tile-label { color: var(--muted); font-size: 12px; }
.tile-value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter { height: 6px; border-radius: 3px; background: var(--panel-2); margin: 6px 0; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 3px; background: var(--series-1); }

/* ---- overview: traffic chart ---- */
.chart { position: relative; margin-top: 10px; }
.chart svg { display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s1 { stroke: var(--series-1); }
.chart .line.s2 { stroke: var(--series-2); }
.chart .area { stroke: none; opacity: .1; }
.chart .area.s1 { fill: var(--series-1); }
.chart .area.s2 { fill: var(--series-2); }
.chart .cross line { stroke: var(--muted); stroke-width: 1; }
.chart .pt { stroke: var(--panel); stroke-width: 2; }
.chart .pt.s1 { fill: var(--series-1); }
.chart .pt.s2 { fill: var(--series-2); }
.tip {
  position: absolute; top: 6px; pointer-events: none; white-space: nowrap; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px;
}
.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend strong, .tip strong { color: var(--text); font-variant-numeric: tabular-nums; }
.key { display: inline-block; width: 14px; border-top: 2px solid; border-radius: 1px; vertical-align: middle; margin-right: 6px; }
.key.s1 { border-color: var(--series-1); }
.key.s2 { border-color: var(--series-2); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
#add-form .row { align-self: end; margin-bottom: 12px; }
#add-form label .row { margin: 0; }
.row label.check { margin: 0; }
.row label.check input { flex: none; min-width: 0; }

/* ---- dialogs ---- */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 22px; width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog ol { padding-left: 18px; margin: 10px 0; }
dialog a { color: var(--accent); word-break: break-all; }
/* The code is drawn dark-on-white whatever the theme: that is what cameras expect. */
.qr { background: #fff; padding: 12px; border-radius: 6px; width: max-content; margin: 4px auto 12px; }
.qr svg { display: block; }
.qr rect { fill: #000; }
.full { grid-column: 1 / -1; }
.tag.expired { color: var(--danger); }
.chart .bar.s1 { fill: var(--series-1); }
.chart .bar.s2 { fill: var(--series-2); }
.chart .hit { fill: transparent; }
.chart .hit.on { fill: var(--text); opacity: .06; }
input[type=file] { padding: 5px; }
input[type=date] { color-scheme: dark; }
.grid2 { align-items: start; }
h2.spaced { margin-top: 22px; }
pre.wrap { white-space: pre-wrap; word-break: break-all; max-height: none; margin: 0 0 12px; }
#alerts-events { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 16px; margin: 4px 0 8px; }
#s-full-extra p { margin: -6px 0 12px; }
td .tag.guest { color: var(--muted); }
#settings-form > .row { margin-bottom: 16px; }

/* A second line under a column heading, saying what the figure covers. */
th { vertical-align: bottom; }
th .sub { display: block; font-weight: 400; opacity: .8; }

/* ---- folder picker for a network share ---- */
#smb-dialog { width: min(580px, calc(100vw - 32px)); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; min-height: 28px; margin: 0 0 8px; font-size: 13px; }
.crumbs button { background: none; border: 0; padding: 3px 6px; border-radius: 4px; color: var(--accent); }
.crumbs button:hover { background: var(--panel-2); }
/* The last one is where you are, not somewhere to go. */
.crumbs button:disabled { color: var(--text); font-weight: 600; opacity: 1; }
.crumbs .sep { color: var(--muted); }
.browser {
  list-style: none; margin: 0 0 8px; padding: 4px; height: 260px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
}
.browser button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; white-space: normal;
  background: none; border: 0; border-radius: 4px; padding: 7px 9px;
}
.browser button:hover, .browser button:focus-visible { background: var(--panel-2); }
.browser svg { flex: none; width: 18px; height: 15px; fill: var(--accent); }
.browser .note { margin-left: auto; color: var(--muted); font-size: 12px; }
dialog .error:empty { display: none; }
dialog .error { margin: 0 0 10px; }
fieldset > legend { color: var(--muted); font-size: 12px; padding: 0 6px; }
fieldset > p:last-child { margin-bottom: 0; }
