/* HTO2 Stack Monitor
   The content here is equipment tags, so the interface borrows from panel
   schedules and engraved nameplates: monospace for anything that is a code,
   a cool drawing-sheet ground, and saturated colour reserved entirely for
   device state. Okabe-Ito palette per the design spec -- red/green is the
   worst possible pairing for colour vision deficiency, and state is never
   carried by hue alone. */

:root {
  --ground: #e8ecf0;
  --sheet: #ffffff;
  --ink: #11161c;
  --muted: #5c6874;
  --rule: #ccd4dc;
  --rule-strong: #9aa7b4;

  --waiting: #0072b2;
  --up: #009e73;
  --down: #d55e00;
  --unknown: #8b949e;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --tick: 4px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

/* ---- masthead ---------------------------------------------------------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--ink);
  color: #eef2f6;
  position: sticky;
  top: 0;
  z-index: 10;
}

.mark { text-decoration: none; color: inherit; display: flex; gap: 10px; align-items: baseline; }
.mark-code {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.14em;
  border: 1px solid #4a5561;
  padding: 2px 7px;
}
.mark-name { font-size: 13px; color: #9fadbb; letter-spacing: 0.04em; }

.masthead nav { display: flex; gap: 18px; align-items: baseline; }
.masthead nav a, .linkish {
  color: #cfd8e2;
  text-decoration: none;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.masthead nav a:hover, .linkish:hover { color: #fff; }
.linkish { background: none; border: 0; padding: 0; cursor: pointer; font-family: inherit; }
.masthead form { display: inline; }

/* Hamburger. Hidden above the breakpoint, where the nav sits inline. */
.nav-button { display: none; }
.nav-toggle { display: none; }

/* ---- sheet ------------------------------------------------------------- */

main.sheet { max-width: 1080px; margin: 0 auto; padding: 24px 20px 64px; }
main.narrow { max-width: 420px; margin: 0 auto; padding: 56px 20px; }

h1 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 18px;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
}

/* ---- overall progress -------------------------------------------------- */

.tally {
  background: var(--sheet);
  border: 1px solid var(--rule);
  padding: 20px 22px;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  align-items: flex-end;
}
.tally .figure {
  font-family: var(--mono);
  font-size: 40px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
}
.tally .figure span { color: var(--rule-strong); }
.tally dl { margin: 0; display: flex; gap: 22px; }
.tally dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.tally dd { margin: 2px 0 0; font-family: var(--mono); font-size: 19px; font-weight: 600; }

/* ---- banner ------------------------------------------------------------ */

.banner {
  border-left: var(--tick) solid var(--unknown);
  background: var(--sheet);
  border-top: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 14px;
}
.banner strong { text-transform: uppercase; letter-spacing: 0.08em; font-size: 12px; }
.banner.warn { border-left-color: var(--down); }

/* ---- stack list -------------------------------------------------------- */
/* Vertical, in CRIT/MNR order. The alias is the identifier people actually
   speak, so it leads; the raw code sits under it for cross-referencing
   against the drawings. */

.stack-list { background: var(--sheet); border: 1px solid var(--rule); }

.stack-row {
  display: grid;
  grid-template-columns: var(--tick) 104px 1fr auto;
  grid-template-areas:
    "rail alias ticks fraction"
    "rail code  ticks fraction";
  align-items: center;
  gap: 0 16px;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  color: inherit;
}
.stack-row .rail { grid-area: rail; }
.stack-row .alias { grid-area: alias; padding-left: 16px; align-self: end; }
.stack-row .code { grid-area: code; padding-left: 16px; align-self: start; }
.stack-row .ticks { grid-area: ticks; }
.stack-row .fraction { grid-area: fraction; }
.stack-row:last-child { border-bottom: 0; }
.stack-row:hover { background: #f6f8fa; }

.stack-row .rail { align-self: stretch; background: var(--rule-strong); }
.stack-row.complete .rail { background: var(--up); }
.stack-row.started .rail { background: var(--waiting); }
.stack-row.faulted .rail { background: var(--down); }
.stack-row.blind .rail { background: var(--unknown); }

.stack-row .alias {
  display: block;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
  padding-top: 12px;
  white-space: nowrap;
}
.stack-row .code {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  padding-bottom: 12px;
}
.stack-row .fraction {
  font-family: var(--mono);
  font-size: 15px;
  color: var(--muted);
  padding: 12px 16px 12px 0;
  white-space: nowrap;
}
.stack-row .fraction b { color: var(--ink); font-weight: 600; font-size: 17px; }

/* one tick per device, in port order -- reads like a panel schedule */
.ticks { display: flex; gap: 2px; flex-wrap: wrap; padding: 12px 0; }
.ticks i { width: 6px; height: 15px; background: var(--rule); display: block; }
.ticks i.up { background: var(--up); }
.ticks i.down { background: var(--down); }
/* Waiting is a neutral empty slot, not a colour.
   Up and waiting were previously both saturated fills differing mainly by
   hue, which is the channel that fails first at 6px on a phone. Outlining
   them separated the two but read as harsh at that size -- a 1.5px border
   on a 6px tick is a quarter of its width.
   Draining the colour instead means anything coloured on the strip is
   something that happened: green turned up, vermillion went down. The rest
   is simply not done yet. */
.ticks i.waiting { background: #e6eaee; }
/* Unknown never appears alongside the others -- when the collector is
   blind, every tick is unknown -- so a slightly deeper grey distinguishes
   a stale board from an untouched one without competing. */
.ticks i.unknown { background: #d5dbe1; }

/* ---- device list ------------------------------------------------------- */

.stack-head {
  background: var(--sheet);
  border: 1px solid var(--rule);
  padding: 18px 20px;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
}
.stack-head .code { font-family: var(--mono); font-size: 28px; font-weight: 700; letter-spacing: 0.05em; }
.stack-head .fraction { font-family: var(--mono); font-size: 28px; font-weight: 600; }
.stack-head .fraction span { color: var(--rule-strong); }

select.stack-picker {
  font-family: var(--mono);
  font-size: 15px;
  padding: 9px 10px;
  border: 1px solid var(--rule-strong);
  background: var(--sheet);
  color: var(--ink);
  width: 100%;
  max-width: 320px;
}

.rows { background: var(--sheet); border: 1px solid var(--rule); }

.row {
  display: grid;
  grid-template-columns: var(--tick) 1fr auto;
  align-items: center;
  gap: 0 14px;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  color: inherit;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: #f6f8fa; }
.row .rail { align-self: stretch; background: var(--rule); }
.row.up .rail { background: var(--up); }
.row.down .rail { background: var(--down); }
.row.waiting .rail { background: var(--waiting); }
.row.unknown .rail { background: var(--unknown); }

.row .body { padding: 11px 0 11px 14px; min-width: 0; }
.row .tag {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}
.row .meta { font-size: 12px; color: var(--muted); font-family: var(--mono); margin-top: 2px; }
.row .state { padding: 11px 14px 11px 0; text-align: right; white-space: nowrap; }

/* Fixed-width state chips: filled with the state colour, white text.
   Same footprint whatever the state, so the right-hand column stays a clean
   vertical line down the list rather than ragging in and out.
   Colour never carries the meaning alone -- each chip keeps its glyph. */

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 104px;
  padding: 5px 0;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #fff;
  border: 1px solid transparent;
}
.chip.up { background: var(--up); }
.chip.down { background: var(--down); }
.chip.waiting { background: var(--waiting); }
.chip.unknown { background: var(--unknown); }
/* Asserted, not observed: hollow says the state was entered rather than
   measured. Solid on the tick strip, where it counts simply as progress. */
.chip.passive {
  background: transparent;
  color: #007052;
  border-color: var(--up);
}
.chip .glyph { font-size: 11px; }

.stamp { font-size: 11px; color: var(--muted); font-family: var(--mono); margin-top: 3px; }

/* ---- tables and diffs -------------------------------------------------- */

table { width: 100%; border-collapse: collapse; background: var(--sheet); border: 1px solid var(--rule); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--rule); font-size: 13px; vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); font-weight: 600; }
td.mono, th.mono { font-family: var(--mono); }
tr:last-child td { border-bottom: 0; }

.panel { background: var(--sheet); border: 1px solid var(--rule); padding: 20px 22px; margin-bottom: 18px; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.12em; margin: 0 0 14px; color: var(--muted); }

.count-line { font-family: var(--mono); font-size: 15px; margin: 0 0 6px; }
.count-line b { font-size: 19px; }
.risk { border-left: var(--tick) solid var(--down); padding-left: 14px; margin: 14px 0; }

/* ---- forms ------------------------------------------------------------- */

label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 14px 0 5px; }
input[type=text], input[type=email], input[type=password], input[type=file] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--rule-strong);
  background: var(--sheet);
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
}
button.primary {
  margin-top: 18px;
  padding: 11px 20px;
  border: 0;
  background: var(--ink);
  color: #fff;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}
button.primary:hover { background: #2a3541; }
button.ghost {
  margin-top: 18px;
  padding: 11px 20px;
  border: 1px solid var(--rule-strong);
  background: transparent;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { margin-top: 0; }
.inline-form button { margin-top: 0; }

.error { border-left: var(--tick) solid var(--down); padding: 10px 14px; background: var(--sheet); font-size: 14px; margin-top: 14px; }
.note { font-size: 13px; color: var(--muted); }
.secret { font-family: var(--mono); font-size: 13px; word-break: break-all; background: #f2f5f8; border: 1px dashed var(--rule-strong); padding: 12px; }

a.plain { color: var(--ink); }

:focus-visible { outline: 2px solid var(--waiting); outline-offset: 2px; }

@media (max-width: 760px) {
  .masthead { padding: 12px 14px; position: relative; }
  .mark-name { display: none; }

  .nav-button {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    margin: -10px -8px -10px 0;
    padding: 0 8px;
    cursor: pointer;
    align-items: flex-end;
  }
  .nav-button span {
    display: block;
    width: 22px;
    height: 2px;
    background: #cfd8e2;
  }

  /* Collapsed by default; the checkbox opens it. */
  .masthead nav {
    display: none;
    order: 3;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    margin-top: 12px;
    border-top: 1px solid #2f3a46;
  }
  .nav-toggle:checked ~ nav { display: flex; }
  .masthead nav a, .masthead nav .linkish {
    padding: 13px 2px;
    border-bottom: 1px solid #2f3a46;
    font-size: 14px;
    text-align: left;
  }
  .masthead nav form { display: block; width: 100%; }
  .masthead nav .linkish { display: block; width: 100%; }

  main.sheet { padding: 16px 14px 56px; }
  .tally { gap: 18px; padding: 16px; }
  .tally .figure { font-size: 32px; }
  .stack-head .code, .stack-head .fraction { font-size: 22px; }
  .chip { width: 92px; font-size: 10px; }
  /* Alias and tick strip share the top line; code and count share the
     second. The name column is auto-width so it cannot force a wrap. */
  .stack-row {
    grid-template-columns: var(--tick) auto 1fr;
    grid-template-areas:
      "rail alias ticks"
      "rail code  fraction";
    align-items: center;
    gap: 2px 10px;
  }
  .stack-row .alias { padding: 10px 0 0 12px; font-size: 14px; }
  .stack-row .code { padding: 0 0 10px 12px; }
  .stack-row .fraction {
    padding: 0 12px 10px 0;
    font-size: 13px;
    text-align: right;
    justify-self: end;
  }
  .stack-row .fraction b { font-size: 15px; }
  .stack-row .ticks {
    padding: 10px 12px 0 0;
    gap: 2px;
    justify-content: flex-end;
    flex-wrap: nowrap;
    overflow: hidden;
  }
  .ticks i { width: 6px; height: 14px; flex: 0 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- admin row actions ------------------------------------------------- */

/* A <td> must stay a table cell: making it a flex container detaches it
   from the row's height, which leaves the links floating and the borders
   misaligned. Flex goes on an inner wrapper instead. */
.row-actions { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.row-actions form { display: inline; margin: 0; }
.linkish.dark { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 13px; text-decoration: underline; }
.linkish.dark:hover { color: var(--waiting); }
.linkish.danger { color: #a34800; text-transform: none; letter-spacing: 0; font-size: 13px; text-decoration: underline; }
.linkish.danger:hover { color: var(--down); }

/* ---- day toggle -------------------------------------------------------- */

.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}
.panel-head h2 { text-transform: uppercase; letter-spacing: 0.12em; font-size: 13px; color: var(--muted); }

.toggle { display: inline-flex; border: 1px solid var(--rule-strong); }
.toggle a {
  padding: 7px 14px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--muted);
  border-right: 1px solid var(--rule-strong);
}
.toggle a:last-child { border-right: 0; }
.toggle a.on { background: var(--ink); color: #fff; }
.toggle a:hover:not(.on) { background: #f0f3f6; color: var(--ink); }

.role-form { display: inline; }
.role-select {
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid var(--rule-strong);
  background: var(--sheet);
  color: var(--ink);
}

.flag { color: #a34800; font-weight: 600; }

/* ---- view-as banner ---------------------------------------------------- */
/* Deliberately loud: the failure mode is forgetting it is on and concluding
   the export is broken. */

.view-as-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  background: var(--waiting);
  color: #fff;
  padding: 9px 20px;
  font-size: 13px;
}
.view-as-bar b { letter-spacing: 0.04em; }
.view-as-bar button {
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.55);
  color: #fff;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 5px 12px;
  cursor: pointer;
}
.view-as-bar button:hover { background: rgba(255, 255, 255, 0.28); }

@media (max-width: 760px) { .view-as-bar { padding: 9px 14px; } }

/* ---- switch state ------------------------------------------------------ */
/* A small circle, deliberately unlike the square device ticks and the left
   rail: it reports the switch, not the devices beneath it. */

.sw-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: baseline;
  background: var(--rule-strong);
}
.sw-dot.up { background: var(--up); }
.sw-dot.down { background: var(--down); }
.sw-dot.waiting { background: var(--waiting); }
.sw-dot.unknown { background: var(--unknown); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.switch-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 0; }
.ip-input {
  font-family: var(--mono);
  font-size: 13px;
  padding: 4px 7px;
  width: 130px;
  border: 1px solid var(--rule-strong);
  background: var(--sheet);
  color: var(--ink);
}
.poll-toggle {
  margin: 0;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.switch-status {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: 0.02em;
}
.switch-status b { color: var(--ink); text-transform: uppercase; }

/* ---- destructive actions ----------------------------------------------- */
/* Collapsed by default and visually separated: resetting a device destroys
   the record this system exists to produce. */

.danger-zone {
  border: 1px solid var(--rule);
  border-left: var(--tick) solid var(--down);
  background: var(--sheet);
  margin-top: 28px;
}
.danger-zone summary {
  cursor: pointer;
  padding: 12px 16px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #a34800;
  font-weight: 600;
}
.danger-body { padding: 0 16px 18px; max-width: 620px; }
.danger-body .note { margin: 0 0 8px; }
.danger-body input[type=text] { max-width: 240px; font-family: var(--mono); }

/* ---- Net plan view ------------------------------------------------------ */
/* The building in plan, north at the top: MDF at the north end, IDFs
   running north to south down each side. Two columns fit a 360px phone
   with room to spare once the H- prefix is dropped. */

.plan { max-width: 620px; }
/* The MDF sits at the north end of the building, so it is centred above the
   two columns rather than aligned to one side. Constrained to a single
   column's width so it reads as a closet rather than a banner. */
.plan-north {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.plan-north .closet {
  grid-column: 1 / -1;
  justify-self: center;
  width: calc(50% - 4px);
  border-left-width: var(--tick);
}

.plan-sides { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.plan-col { display: flex; flex-direction: column; gap: 8px; }
.plan-label {
  margin: 0 0 2px;
  min-height: 1em;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.closet {
  display: block;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-left: var(--tick) solid var(--rule-strong);
  padding: 10px;
  text-decoration: none;
  color: inherit;
}
.closet:hover { border-color: var(--rule-strong); }
.closet.up { border-left-color: var(--up); }
.closet.down { border-left-color: var(--down); }
.closet.waiting { border-left-color: var(--waiting); }
.closet.unknown { border-left-color: var(--unknown); }

.closet-name {
  display: block;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.closet-name .sw-dot { margin-right: 7px; }
.closet-meta {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

@media (max-width: 760px) {
  .plan-sides { gap: 6px; }
  .closet { padding: 9px 8px; }
  .closet-name { font-size: 13px; }
  .closet-meta { font-size: 11px; }
}

/* A details element styled as a panel: the summary carries the heading and
   the body is what unfolds. */
.detail-panel summary {
  cursor: pointer;
  list-style: revert;
}
.detail-panel summary h2 { margin: 0; }
.detail-panel[open] summary { margin-bottom: 4px; }
