/* QHT VPN panel
 *
 * The subject is presence: whether a tunnel is alive, and for how long. So the
 * page is built around a roster of who is on the network, and the one piece of
 * visual weight in it is the handshake trail -- a strip per device showing the
 * last twenty-four minutes. A solid strip is a healthy link; a gappy one is a
 * device on bad wifi, visible before anyone files a complaint about it.
 *
 * Monospace appears only where alignment carries meaning: addresses, keys,
 * durations, byte counts. It is never used to style a label.
 */

:root {
  --ink:    #0E1821;
  --ink-2:  #13202B;
  --panel:  #16222D;
  --line:   #233543;
  --line-2: #2E4455;
  --text:   #DCE7EE;
  --mute:   #7D95A6;
  --faint:  #4E6676;

  --live:   #4FD8A5;
  --warn:   #F0B24A;
  --stop:   #E8657A;
  --focus:  #6FB7FF;

  --rail:   184px;
  --r-sm:   3px;
  --r-md:   6px;

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

a { color: var(--focus); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.hidden { display: none !important; }

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

/* ------------------------------------------------------------- sign in */

.signin {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.signin-card {
  width: 100%;
  max-width: 380px;
}

.signin h1 {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 6px;
}

.signin p.lede {
  color: var(--mute);
  margin: 0 0 28px;
  font-size: 14px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 13px;
  color: var(--mute);
  margin-bottom: 5px;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="search"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--ink-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
}

input::placeholder { color: var(--faint); }

/* Chrome paints autofilled fields with its own near-white background, which on
 * a dark form looks like a rendering fault. There is no property that disables
 * it; an inset shadow the size of the field is the only way to cover it. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--ink-2) inset;
  caret-color: var(--text);
  transition: background-color 9999s ease-in-out 0s;
}

textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }

button {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--faint); }
button:disabled { opacity: .5; cursor: default; }

button.primary {
  background: var(--live);
  border-color: var(--live);
  color: #06241A;
  font-weight: 600;
}

button.primary:hover:not(:disabled) { filter: brightness(1.08); }

button.danger { color: var(--stop); border-color: #4A2531; }
button.danger:hover:not(:disabled) { border-color: var(--stop); }

button.wide { width: 100%; }

.msg {
  margin-top: 14px;
  padding: 9px 12px;
  border-radius: var(--r-md);
  font-size: 14px;
  background: #2B1A20;
  border: 1px solid #4A2531;
  color: #F3A9B6;
}

/* ---------------------------------------------------------------- shell */

.shell { display: none; }
.shell.on { display: block; }

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  height: 52px;
  border-bottom: 1px solid var(--line);
  background: var(--ink-2);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 15px;
}

.hubstate {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--mute);
}

.pip {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--stop);
  flex: none;
}

.pip.up { background: var(--live); }

.topbar .spacer { flex: 1; }

.who {
  font-size: 13px;
  color: var(--mute);
}

.who strong { color: var(--text); font-weight: 500; }

.layout {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: 28px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

nav.rail { position: sticky; top: 76px; align-self: start; }

nav.rail button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-left: 2px solid transparent;
  border-radius: 0;
  padding: 7px 12px;
  color: var(--mute);
  font-size: 14px;
}

nav.rail button:hover { color: var(--text); border-color: var(--line-2); }

nav.rail button.on {
  color: var(--text);
  border-left-color: var(--live);
  font-weight: 500;
}

nav.rail .count {
  float: right;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
}

/* --------------------------------------------------------------- views */

.view { display: none; }
.view.on { display: block; }

.head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 4px;
}

.head h2 {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.head .of {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--mute);
}

.head .spacer { flex: 1; }

.figures {
  display: flex;
  flex-wrap: wrap;
  gap: 26px;
  margin: 0 0 22px;
  padding: 0;
  list-style: none;
}

.figures div { display: flex; align-items: baseline; gap: 7px; }

.figures b {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.figures span { color: var(--mute); font-size: 13px; }

.figures .hot b { color: var(--warn); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}

.panel + .sectiongap { margin-top: 34px; }

/* ---------------------------------------------------------- roster rows */

.roster { display: flex; flex-direction: column; }

/* Every column but the last is a fixed width, so the columns line up down the
 * roster. With fr units each row is its own grid and sizes itself, which leaves
 * the addresses stepping in and out by a few pixels per row -- unreadable in a
 * list you are meant to scan. */
.rrow {
  display: grid;
  grid-template-columns: 116px 228px 86px 108px 186px 1fr;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.rrow:last-child { border-bottom: none; }

.rrow .name { font-weight: 500; }
.rrow .sub { color: var(--mute); font-size: 13px; }
.rrow .mono { font-family: var(--mono); font-size: 13px; color: var(--mute); }
.rrow .dur {
  font-family: var(--mono);
  font-size: 14px;
  text-align: right;
  white-space: nowrap;
}

/* The one piece of visual weight on the page. */
.trail {
  display: flex;
  gap: 1px;
  height: 16px;
  align-items: stretch;
}

.trail i {
  width: 3px;
  background: var(--line-2);
  border-radius: 1px;
}

.trail i.on { background: var(--live); }
.trail i.on:last-child { box-shadow: 0 0 6px rgba(79, 216, 165, .55); }

.tag {
  display: inline-block;
  font-size: 12px;
  padding: 1px 7px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  color: var(--mute);
  white-space: nowrap;
}

.tag.suspended { color: var(--stop); border-color: #4A2531; }
.tag.full { color: var(--warn); border-color: #4A3A20; }

/* ------------------------------------------------------------- tiers */

.tiers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  border-top: 1px solid var(--line);
}

.tier {
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.tier:last-child { border-right: none; }
.tier h4 { margin: 0 0 2px; font-size: 14px; font-weight: 600; }
.tier .range { font-family: var(--mono); font-size: 12px; color: var(--faint); }

.tier .bar {
  height: 3px;
  background: var(--line-2);
  border-radius: 2px;
  margin: 9px 0 6px;
  overflow: hidden;
}

.tier .bar i { display: block; height: 100%; background: var(--live); }
.tier .n { font-size: 13px; color: var(--mute); }

/* -------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; }

/* No sticky header: inside a rounded panel with overflow hidden it leaves a
 * phantom band above the row, and the tables here are short enough to scan. */
th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--faint);
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--ink-2);
  white-space: nowrap;
}

td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: middle;
  white-space: nowrap;
}

/* The one column allowed to wrap, because a long note is better wrapped than
 * cut off. Everything else stays on one line so rows keep a constant height. */
td.wrap { white-space: normal; }

td .sub { color: var(--mute); font-size: 12px; }
td .name { font-weight: 500; }

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--ink-2); }

td.mono, th.mono { font-family: var(--mono); font-size: 13px; }
td.num { text-align: right; font-family: var(--mono); font-size: 13px; }
td.acts { text-align: right; }
td.acts button { padding: 3px 9px; font-size: 12px; margin-left: 5px; }

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.toolbar input[type="search"] { max-width: 280px; }
.toolbar select { width: auto; }
.toolbar .spacer { flex: 1; }

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--mute);
}

.empty p { margin: 0 0 14px; }

/* --------------------------------------------------------------- note */

.note {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-left: 2px solid var(--line-2);
  color: var(--mute);
  font-size: 13px;
  line-height: 1.55;
  max-width: 68ch;
}

/* --------------------------------------------------------------- bars */

.days { display: flex; flex-direction: column; gap: 7px; padding: 16px; }

.day { display: grid; grid-template-columns: 92px 1fr 64px; align-items: center; gap: 12px; }
.day .d { font-family: var(--mono); font-size: 12px; color: var(--mute); }
.day .track { height: 9px; background: var(--ink-2); border-radius: 2px; overflow: hidden; }
.day .track i { display: block; height: 100%; background: var(--live); opacity: .8; }
.day .v { font-family: var(--mono); font-size: 13px; text-align: right; }

/* -------------------------------------------------------------- alerts */

.alert {
  display: grid;
  grid-template-columns: 4px 1fr auto;
  gap: 14px;
  padding: 12px 16px 12px 0;
  border-bottom: 1px solid var(--line);
}

.alert:last-child { border-bottom: none; }
.alert .sev { background: var(--mute); }
.alert.critical .sev { background: var(--stop); }
.alert.warning .sev { background: var(--warn); }
.alert.info .sev { background: var(--faint); }
.alert h5 { margin: 0 0 2px; font-size: 14px; font-weight: 500; }
.alert p { margin: 0; color: var(--mute); font-size: 13px; }
.alert time { font-family: var(--mono); font-size: 12px; color: var(--faint); white-space: nowrap; }

/* --------------------------------------------------------------- modal */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(5, 11, 16, .72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 60;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow: auto;
}

.modal header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
}

.modal header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal header .spacer { flex: 1; }
.modal .body { padding: 18px 20px; }
.modal footer {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.hint { font-size: 12px; color: var(--faint); margin-top: 4px; line-height: 1.45; }

.qr {
  display: block;
  margin: 0 auto 14px;
  image-rendering: pixelated;
  border-radius: var(--r-sm);
  background: #fff;
  padding: 8px;
  max-width: 236px;
}

.once {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid #4A3A20;
  background: #241D10;
  color: var(--warn);
  border-radius: var(--r-md);
  font-size: 13px;
  line-height: 1.5;
}

/* --------------------------------------------------------------- small */

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; gap: 18px; padding: 16px 16px 48px; }
  nav.rail {
    position: static;
    display: flex;
    gap: 2px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
  }
  nav.rail button {
    border-left: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    width: auto;
  }
  nav.rail button.on { border-left-color: transparent; border-bottom-color: var(--live); }
  nav.rail .count { display: none; }
  .rrow { grid-template-columns: 116px 1fr auto; row-gap: 6px; }
  .rrow .mono.ip, .rrow .mono.from, .rrow .tag.grp { grid-column: 2 / -1; }
  th { position: static; }
  .grid2 { grid-template-columns: 1fr; }
}

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