/* The infrastructure dashboard. Colour says state (well, to look at, wrong,
   asleep) and tells clusters apart; it never says anything a word or a
   shape next to it does not say too. No font or image comes from elsewhere. */

:root {
  color-scheme: light dark;
  --bg: #eef1f4;
  --surface: #ffffff;
  --sunk: #e3e8ed;
  --ink: #16202b;
  --muted: #566473;
  --line: #cfd7df;
  --ok: #1a7448;
  --warn: #8a5000;
  --bad: #b3261e;
  --bad-wash: #fbeceb;
  --warn-wash: #fbf2e1;
  --asleep: #5d6b7a;
  --link: #0b5cad;
  /* Clusters, told apart. */
  --c0: #2f6fb5;
  --c1: #c2571a;
  --c2: #23856a;
  --c3: #a23b8f;
  --c4: #7a6a12;
  --c5: #5a58c9;
  --c6: #8a5a3c;
  --c7: #3d7f96;
  --sans: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "DejaVu Sans Mono", "Liberation Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --surface: #19212a;
    --sunk: #26313d;
    --ink: #e3e8ee;
    --muted: #97a5b3;
    --line: #313d4a;
    --ok: #58c08a;
    --warn: #e0a445;
    --bad: #f27d72;
    --bad-wash: #33201f;
    --warn-wash: #30281a;
    --asleep: #8d9aa8;
    --link: #7db7f0;
    --c0: #6ea8e6;
    --c1: #e8935a;
    --c2: #5cc4a0;
    --c3: #d77fc6;
    --c4: #c8b545;
    --c5: #9d9bf2;
    --c6: #c99a78;
    --c7: #74bdd4;
  }
}

.hue-0 { --hue: var(--c0); }
.hue-1 { --hue: var(--c1); }
.hue-2 { --hue: var(--c2); }
.hue-3 { --hue: var(--c3); }
.hue-4 { --hue: var(--c4); }
.hue-5 { --hue: var(--c5); }
.hue-6 { --hue: var(--c6); }
.hue-7 { --hue: var(--c7); }

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

body {
  margin: 0;
  padding: 0 20px 48px;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}

.top, main, .token, .stale, .acted { max-width: 1240px; margin-inline: auto; }

h1, h2, h3, h4, p, ul, dl, dd { margin: 0; }
ul { padding: 0; list-style: none; }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
h4 { font-size: 13px; font-weight: 650; }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 2px; }
strong { font-weight: 650; }

.quiet, .none { color: var(--muted); }
.id { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; }
.grow { margin-left: auto; text-align: right; }
.sep { color: var(--muted); padding: 0 1px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 8px; background: var(--surface); padding: 6px 10px; z-index: 2; }

/* The top: what this is, and whether it is current. */
.top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 20px; padding: 18px 0 14px; }
.title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.where { color: var(--muted); }
.status { margin-left: auto; display: flex; align-items: center; gap: 14px; }
button { font: inherit; color: inherit; cursor: pointer; }
button.plain { background: none; border: 0; padding: 2px 0; color: var(--link); text-decoration: underline; text-underline-offset: 2px; }

/* States: a mark whose shape goes with the word. */
.chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 550; }
.chip .mark { width: 9px; height: 9px; flex: none; background: currentColor; border-radius: 50%; }
.chip.ok { color: var(--ok); }
.chip.warn { color: var(--warn); }
.chip.warn .mark { border-radius: 0; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.chip.bad { color: var(--bad); }
.chip.bad .mark { border-radius: 1px; }
.chip.asleep { color: var(--asleep); }
.chip.asleep .mark { background: none; border: 2px solid currentColor; }
.chip.busy { color: var(--link); }
.chip.busy .mark { border-radius: 0; transform: rotate(45deg) scale(0.85); }
.chip.quiet { color: var(--muted); font-weight: 400; }
.chip.quiet .mark { height: 2px; border-radius: 0; }

/* Asking for the token. */
.token { display: none; margin-top: 8vh; max-width: 520px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 22px 24px 24px; }
.needs-token .token { display: block; }
.needs-token main, .needs-token .stale, .needs-token #forget, .needs-token #live { display: none; }
body:not(.has-data) main { display: none; }
.token p { color: var(--muted); margin: 8px 0 16px; max-width: 60ch; }
.token label { display: block; font-weight: 600; margin-bottom: 6px; }
.token-row { display: flex; flex-wrap: wrap; gap: 8px; }
.token input { flex: 1 1 220px; font: 14px var(--mono); padding: 8px 10px; color: var(--ink); background: var(--bg); border: 1px solid var(--muted); border-radius: 4px; }
.token button { padding: 8px 14px; background: var(--ink); color: var(--bg); border: 0; border-radius: 4px; font-weight: 600; }
.token .signin { margin: 16px 0 0; padding-top: 16px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; }
.token .signin a { padding: 8px 14px; border: 1px solid var(--muted); border-radius: 4px; font-weight: 600; text-decoration: none; color: inherit; }
.token .signin a:hover, .token .signin a:focus-visible { border-color: currentColor; }

/* The control plane does not answer: said plainly, above everything. */
.stale { margin-bottom: 14px; padding: 10px 14px; background: var(--bad-wash); border: 1px solid var(--bad); border-left-width: 4px; border-radius: 4px; font-weight: 550; }

/* What an operator asks from here: a small button where the thing is, a dialog that says what will happen, a strip that says how it went. */
.acts { display: inline-flex; gap: 8px; }
button.act { padding: 2px 10px; background: var(--surface); border: 1px solid var(--muted); border-radius: 4px; font-size: 13px; font-weight: 550; white-space: nowrap; }
button.act:hover:not(:disabled) { border-color: var(--ink); background: var(--sunk); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
td button.act { padding: 0 8px; }
dialog { width: min(92vw, 600px); max-height: 86vh; overflow-y: auto; padding: 20px 22px 18px; color: var(--ink); background: var(--surface); border: 1px solid var(--muted); border-radius: 8px; box-shadow: 0 12px 40px rgb(0 0 0 / 0.28); }
dialog::backdrop { background: rgb(10 16 22 / 0.5); }
.act-lines { margin: 12px 0 14px; }
.act-lines li { padding: 3px 0 3px 16px; position: relative; overflow-wrap: anywhere; }
.act-lines li::before { content: ""; position: absolute; left: 2px; top: 0.72em; width: 6px; height: 2px; background: var(--muted); }
.act-choice { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin-bottom: 14px; }
.act-choice label { font-weight: 600; }
.act-choice select { flex: 1 1 260px; min-width: 0; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--muted); border-radius: 4px; padding: 5px 8px; }
.act-row { display: flex; justify-content: flex-end; align-items: center; gap: 18px; margin-top: 4px; }
button.go { padding: 8px 14px; background: var(--ink); color: var(--bg); border: 0; border-radius: 4px; font-weight: 600; }
.note .line { display: block; }
.note.ok { color: var(--ok); font-weight: 550; }
.note.busy { color: var(--link); font-weight: 550; }
p.acted.note { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin: 0 auto 14px; border: 1px solid currentColor; border-left-width: 4px; }
.acted > span { flex: 1 1 320px; color: var(--ink); font-weight: 400; }
.acted .line { display: inline; }
.acted .line + .line { margin-left: 0.4em; }

/* At a glance. */
.summary { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px 12px; }
.headline { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 24px; margin-bottom: 14px; }
.stat dt { color: var(--muted); font-size: 12.5px; }
.stat dd { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.stat dd > .num { font-size: 21px; font-weight: 650; letter-spacing: -0.01em; }
.stat-note { color: var(--muted); font-size: 12.5px; }
.stat.tone-bad .stat-note { color: var(--bad); font-weight: 600; }
.stat.tone-warn .stat-note { color: var(--warn); font-weight: 600; }
.yard .bar { height: 16px; }
.yard .meter-text { margin-top: 6px; }

/* A capacity bar: parts in proportion, with a gap between them. */
.bar { display: flex; gap: 2px; height: 12px; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.bar.thin { height: 6px; }
.bar.over { outline: 2px dashed var(--bad); outline-offset: 2px; }
.seg { min-width: 3px; flex: 0 1 0; }
.seg.machine { background: var(--hue, var(--muted)); }
.seg.machine.stopped { background: repeating-linear-gradient(90deg, var(--bad) 0 3px, transparent 3px 6px); }
.seg.other { background: var(--muted); }
.seg.asleep { background: repeating-linear-gradient(135deg, var(--asleep) 0 2px, transparent 2px 5px); box-shadow: inset 0 0 0 1px var(--asleep); }
.seg.free { background: transparent; min-width: 0; }
.meter-text { color: var(--muted); font-size: 13px; }
.meter-text .num { color: var(--ink); font-weight: 600; }
.asleep-text { color: var(--asleep); }

/* What is wrong, before anything else. */
.problems { margin-top: 14px; background: var(--bad-wash); border: 1px solid var(--bad); border-left-width: 4px; border-radius: 4px; padding: 12px 16px; }
.problems h2 { color: var(--bad); font-size: 15px; }
.problems ul { margin: 6px 0 8px; }
.problems li { padding: 3px 0 3px 18px; position: relative; overflow-wrap: anywhere; }
.problems li::before { content: ""; position: absolute; left: 2px; top: 0.62em; width: 8px; height: 8px; background: var(--bad); border-radius: 1px; }
.problems .quiet { font-size: 12.5px; }
.notes { margin-top: 14px; background: var(--surface); border: 1px solid var(--line); border-left-width: 4px; border-radius: 4px; padding: 12px 16px; }
.notes h2 { font-size: 15px; }
.notes ul { margin: 6px 0 8px; padding-left: 18px; }
.notes li { padding: 3px 0; overflow-wrap: anywhere; }
.notes .quiet { font-size: 12.5px; }

/* Views. */
.tabs { display: flex; gap: 4px 22px; margin: 20px 0 16px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; }
.tabs a { flex: none; padding: 8px 0 9px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 550; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current] { color: var(--ink); border-bottom-color: var(--ink); }
.count { font-weight: 400; color: var(--muted); font-size: 12.5px; margin-left: 2px; }
.lede { color: var(--muted); max-width: 78ch; margin: 4px 0 14px; }
main section > h2 { margin-top: 2px; }
#stored-list > h3, #operations-list > h3 { margin: 18px 0 8px; }
#stored-list > h3:first-child, #operations-list > h3:first-child { margin-top: 0; }
.none { padding: 6px 0; }

.cards { display: grid; gap: 12px; }
#hosts-list { grid-template-columns: repeat(auto-fit, minmax(min(100%, 560px), 1fr)); align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; min-width: 0; }
.card > header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-bottom: 10px; }
.card.tone-bad { border-left: 4px solid var(--bad); }
.card.tone-warn { border-left: 4px solid var(--warn); }
.card.tone-quiet { opacity: 0.75; }
.card.cluster { border-left: 4px solid var(--hue); }
.env { color: var(--muted); }
.note { margin: 0 0 10px; padding: 6px 10px; border-radius: 4px; background: var(--sunk); overflow-wrap: anywhere; }
.note.bad { background: var(--bad-wash); color: var(--bad); font-weight: 550; }
.note.warn { background: var(--warn-wash); color: var(--warn); }
.note.asleep { color: var(--ink); background: repeating-linear-gradient(135deg, var(--sunk) 0 6px, transparent 6px 12px); border: 1px solid var(--line); }

.meters { display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; align-items: start; margin-bottom: 12px; }
.meters dt { color: var(--muted); font-size: 13px; }
.meters dd { display: grid; gap: 4px; min-width: 0; }
.meters dd .bar { margin-top: 4px; }

.cluster-name { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 9px; height: 9px; border-radius: 2px; background: var(--hue); flex: none; }
.flag { display: block; color: var(--bad); font-weight: 600; font-size: 12.5px; white-space: normal; }
.tags { display: flex; flex-wrap: wrap; gap: 2px 18px; margin-top: 10px; color: var(--muted); font-size: 13px; }
.tags strong { color: var(--ink); }
.reaches { display: inline-flex; flex-wrap: wrap; gap: 4px 6px; }
.reach { display: inline-flex; align-items: center; padding: 0 7px; border: 1px solid var(--line); border-radius: 10px; font-size: 12.5px; white-space: nowrap; }
.lets-in { margin-top: 12px; }
.lets-in li { padding: 2px 0; overflow-wrap: anywhere; }

/* Tables. */
.table-wrap { overflow-x: auto; }
#services-list > .table-wrap, #stored-list > .table-wrap, #operations-list > .table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 4px 16px 6px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; vertical-align: baseline; padding: 6px 14px 6px 0; border-bottom: 1px solid var(--line); }
th:last-child, td:last-child { padding-right: 0; }
thead th { font-size: 12.5px; font-weight: 500; color: var(--muted); white-space: nowrap; }
tbody th { font-weight: 600; white-space: nowrap; }
tbody tr:last-child > * { border-bottom: 0; }
th.num, td.num { text-align: right; white-space: nowrap; }
td { overflow-wrap: anywhere; }
td .id { overflow-wrap: normal; white-space: nowrap; }
/* Every cluster's table in the same columns, so the eye runs down them. */
@media (min-width: 900px) {
  .cluster table { table-layout: fixed; }
  .cluster thead th:nth-child(1) { width: 13%; }
  .cluster thead th:nth-child(2) { width: 10%; }
  .cluster thead th:nth-child(3) { width: 12%; }
  .cluster thead th:nth-child(4) { width: 12%; }
  .cluster thead th:nth-child(5) { width: 9%; }
  .cluster thead th:nth-child(6) { width: 12%; }
  .cluster thead th:nth-child(7) { width: 15%; }
}

/* The drawing. */
.legend { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-bottom: 10px; color: var(--muted); }
.legend .cluster-name { color: var(--ink); font-weight: 600; }
.frame { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow-x: auto; }
.topology { display: block; max-width: none; font-family: var(--sans); }
.topology text { fill: var(--ink); font-variant-numeric: tabular-nums; }
.topology .t-name { font-size: 14px; font-weight: 650; }
.topology .t-label { font-size: 12.5px; }
.topology .t-small { font-size: 11.5px; fill: var(--muted); }
.topology .state-bad { fill: var(--bad); font-weight: 600; }
.topology .state-warn { fill: var(--warn); font-weight: 600; }
.topology .state-ok { fill: var(--ok); }
.host-box { fill: var(--bg); stroke: var(--muted); stroke-width: 1.2; }
.tone-bad > .host-box { stroke: var(--bad); stroke-width: 2; stroke-dasharray: 6 4; }
.tone-warn > .host-box { stroke: var(--warn); stroke-width: 2; }
.machine-box { fill: var(--surface); stroke: var(--line); }
.machine-mark { fill: var(--hue); }
.t-machine.stopped .machine-box { stroke: var(--bad); stroke-width: 2; }
.t-machine.asleep .machine-box { stroke: var(--asleep); stroke-dasharray: 4 3; }
.hatch { fill: var(--asleep); opacity: 0.28; }
.service-box { fill: var(--surface); stroke: var(--ink); stroke-width: 1.2; }
.t-service.silent .service-box { stroke: var(--bad); stroke-dasharray: 6 4; }
.outside-box { fill: var(--surface); stroke: var(--muted); }
.link { fill: none; stroke: var(--hue, var(--muted)); stroke-width: 2; stroke-linejoin: round; }
.link.uses { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.link.outside { stroke: var(--muted); stroke-width: 1.5; }
.topology .link-label { font-size: 11.5px; font-weight: 600; fill: var(--hue); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.words { margin-top: 12px; }
.words summary { cursor: pointer; color: var(--link); width: fit-content; }
.words ul { margin-top: 8px; max-width: 90ch; }
.words li { padding: 2px 0; }

/* A narrow window: a table's row becomes a short list of its own. */
@media (max-width: 680px) {
  body { padding: 0 12px 40px; }
  .grow { margin-left: 0; text-align: left; flex-basis: 100%; }
  .status { margin-left: 0; }
  table, tbody, tr, td, tbody th { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  tbody tr { padding: 8px 0; border-bottom: 1px solid var(--line); }
  tbody tr:last-child { border-bottom: 0; }
  tbody th, td, th.num, td.num { border: 0; padding: 1px 0; text-align: left; white-space: normal; }
  td:empty { display: none; }
  td::before { content: attr(data-label) ": "; color: var(--muted); }
  .meters { grid-template-columns: 1fr; gap: 2px; }
  .meters dd { margin-bottom: 8px; }
}

@media print {
  body { background: #fff; }
  .tabs, #forget, .skip, .acts, button.act, .acted { display: none; }
  main section[hidden] { display: block !important; }
}
