/* The console's look, see ../DESIGN.md. Every colour comes from the variables below, which
   theme.js sets from the customer's theme. These defaults are Serika Dark. */
:root {
  --bg: #323437;
  --main: #e2b714;
  --subAlt: #2c2e31;
  --text: #d1d0c5;
  --error: #ca4754;
  --ok: #6cc48a;
  --onMain: #323437;
  --mutedMix: 72%;
  --muted: color-mix(in srgb, var(--text) var(--mutedMix), var(--bg));
  --line: color-mix(in srgb, var(--text) 15%, var(--bg));
  --field-line: color-mix(in srgb, var(--text) 30%, var(--bg));
  --hover: color-mix(in srgb, var(--text) 7%, transparent);
  --problem: color-mix(in srgb, var(--error) 50%, var(--text));
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --rail: 56px;
  --panel: 232px;
  --top: 48px;
}

* {
  box-sizing: border-box;
}

/* hidden has to win over the display set on anything below */
[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration-color: var(--main);
  text-underline-offset: 2px;
}

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

/* Anything a customer might copy */
.address {
  font-family: var(--mono);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
}

.help {
  color: var(--muted);
  font-size: 13px;
}

/* The icons, all drawn from the symbols at the top of index.html */
.sprite {
  position: absolute;
  width: 0;
  height: 0;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The top bar */
#top {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  height: var(--top);
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 12px;
  background: var(--subAlt);
  border-bottom: 1px solid var(--line);
}

#brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding-left: 18px;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

/* The one image, inlined so it takes the theme's text colour. Drawn by fill, unlike the icons */
.logo {
  width: 40px;
  height: 18px;
  flex: none;
}

#brand .long {
  overflow: hidden;
  text-overflow: ellipsis;
}

.spacer {
  flex: 1;
}

.top-button {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 10px;
  background: none;
  border: 1px solid transparent;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.top-button:hover,
.top-button[aria-expanded="true"] {
  background: var(--hover);
}

.top-button .icon {
  width: 14px;
  height: 14px;
}

/* A long email shrinks with an ellipsis instead of pushing the bar wider than the screen */
#account-button {
  min-width: 0;
}

#username {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#menu-button {
  display: none;
}

/* Small squares showing a theme's colours */
.swatches {
  display: inline-flex;
}

.swatches span {
  width: 12px;
  height: 12px;
  margin-left: -1px;
  border: 1px solid var(--line);
}

/* The theme and account menus */
.menu {
  position: absolute;
  top: 44px;
  right: 12px;
  min-width: 220px;
  max-height: calc(100vh - 60px);
  overflow: auto;
  padding: 4px 0;
  background: var(--subAlt);
  border: 1px solid var(--line);
}

.menu h3 {
  padding: 8px 12px 4px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.menu button {
  position: relative;
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 12px;
  background: none;
  border: 0;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

/* A link in a menu, looking like its buttons */
.menu-link {
  display: block;
  padding: 6px 12px;
  color: var(--text);
  text-decoration: none;
}

.menu-link:hover {
  background: var(--hover);
}

/* The Stats link is for phones only, desktop has the top bar's button */
#stats-menu-link {
  display: none;
}

.menu button:hover {
  background: var(--hover);
}

.menu button[aria-checked="true"] {
  font-weight: 600;
}

.menu button[aria-checked="true"]::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--main);
}

/* The side panel: a rail of icons that slides out over the page on hover, or stays open when
   pinned. The icons don't move, so the pointer is still on the same item once it is open */
#side {
  position: fixed;
  top: var(--top);
  bottom: 0;
  left: 0;
  z-index: 20;
  width: var(--rail);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  white-space: nowrap;
  background: var(--subAlt);
  border-right: 1px solid var(--line);
  transition: width 0.11s ease-out;
}

#side:hover {
  width: var(--panel);
  transition-delay: 60ms;
}

#side:has(:focus-visible) {
  width: var(--panel);
}

.pinned #side {
  width: var(--panel);
  transition: none;
}

/* Until the first load settles the panel's items keep their space but don't show, so they appear together
   instead of one by one. showSidePanel() in app.js takes the class off. Appearing isn't motion, so DESIGN.md's
   rule that only the panel moves holds */
#side.waiting > * {
  visibility: hidden;
}

#side h2 {
  height: 26px;
  margin-top: 14px;
  padding-left: 18px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 26px;
  text-transform: uppercase;
  opacity: 0;
}

#side:hover h2,
.pinned #side h2 {
  opacity: 1;
}

#side:has(:focus-visible) h2 {
  opacity: 1;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 22px;
  width: 100%;
  height: 38px;
  padding: 0 0 0 18px;
  background: none;
  border: 0;
  color: var(--muted);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--hover);
  color: var(--text);
}

.nav-item[aria-current="page"] {
  background: var(--hover);
  color: var(--text);
  font-weight: 600;
}

.nav-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--main);
}

.nav-item:focus-visible {
  outline-offset: -2px;
}

/* Our network and Account sit at the bottom of the panel, just above the pin. Our network is always
   shown, Account only signed in */
#nav-network {
  margin-top: auto;
}

#pin {
  flex: none;
  height: 42px;
  border-top: 1px solid var(--line);
}

.pinned #pin .icon {
  fill: currentColor;
}

#scrim {
  display: none;
}

/* The page */
main {
  margin-left: var(--rail);
  padding: calc(var(--top) + 24px) 32px 48px;
}

.pinned main {
  margin-left: var(--panel);
}

/* join.html, account.html, terms.html and privacy.html have no side panel */
body.standalone main {
  margin-left: 0;
}

#page {
  max-width: 1240px;
  margin: 0 auto;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-head h1 {
  font-size: 20px;
  font-weight: 600;
  line-height: 32px;
}

.page-head h1.address-heading {
  font-family: var(--mono);
  overflow-wrap: anywhere;
}

/* terms.html and privacy.html: text to read, so lines are kept to the narrow panel's width */
.prose {
  max-width: 720px;
}

.prose .effective {
  margin-top: -8px;
  color: var(--muted);
  font-size: 13px;
}

.prose h2 {
  margin: 24px 0 8px;
  font-size: 14px;
  font-weight: 600;
}

.prose p,
.prose ul {
  margin: 0 0 8px;
}

.prose ul {
  padding-left: 24px;
}

.prose li + li {
  margin-top: 4px;
}

/* Table cells normally stay on one line, these hold sentences */
.prose td {
  white-space: normal;
  vertical-align: top;
}

.crumb {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Buttons and fields */
input,
select,
button {
  font: inherit;
  color: inherit;
  border: 1px solid var(--field-line);
  border-radius: 0;
}

.button {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 14px;
  background: none;
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.button:hover {
  background: var(--hover);
}

.button:disabled,
.button[aria-disabled="true"] {
  opacity: 0.55;
  cursor: default;
}

.button[aria-disabled="true"] {
  pointer-events: none;
}

.button.primary {
  background: var(--main);
  border-color: var(--main);
  color: var(--onMain);
}

.button.primary:hover {
  background: color-mix(in srgb, var(--main) 86%, var(--onMain));
}

.button.danger {
  border-color: color-mix(in srgb, var(--problem) 50%, var(--bg));
  color: var(--problem);
}

.button.small {
  height: 24px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 400;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
}

label input,
label select {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  font-weight: 400;
}

input,
select {
  height: 32px;
  max-width: 100%;
  min-width: 220px;
  padding: 0 8px;
  background: var(--bg);
}

input:focus,
select:focus {
  outline: 2px solid var(--text);
  outline-offset: -1px;
}

input.address {
  font-size: 13px;
}

td select {
  height: 28px;
  min-width: 200px;
  margin-right: 6px;
}

td .button {
  height: 28px;
}

/* The wrapper hint.js listens on, since a disabled select gets no mouse events of its own. Letting taps pass
   through the select means a phone that sends nothing from a disabled control still reaches the wrapper */
.route-hint-anchor {
  display: inline-block;
}

.route-hint-anchor select:disabled {
  pointer-events: none;
}

/* The hint above a greyed-out control (hint.js). Fixed, so a table's scroll box can't cut it off, and above
   the top bar. Flat like the rest of the site: a notice's background and a 1px line, no shadow */
.route-hint {
  position: fixed;
  z-index: 40;
  max-width: 280px;
  padding: 6px 10px;
  background: var(--subAlt);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
}

.form-stack {
  display: grid;
  justify-items: start;
  gap: 14px;
}

/* A box to tick, which sits on one line with its words */
label.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-weight: 400;
}

label.check input {
  width: auto;
  min-width: 0;
  height: auto;
  margin: 2px 0 0;
}

/* Tables */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
}

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

th {
  font-size: 13px;
  font-weight: 600;
  text-align: left;
}

thead th {
  padding: 9px 14px;
  background: var(--subAlt);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

td {
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  white-space: nowrap;
}

tbody tr:first-child td,
tbody tr:first-child th {
  border-top: 0;
}

td a {
  font-weight: 600;
}

td.right {
  text-align: right;
}

td a.plain-link {
  font-weight: 400;
}

/* A row that opens the thing it shows when clicked anywhere */
tr.row-link {
  cursor: pointer;
}

tr.row-link:hover td {
  background: var(--hover);
}

/* Status: always a dot and words, so colour isn't the only signal */
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.status::before {
  content: "";
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}

.status.ok::before {
  background: var(--ok);
}

.status.bad {
  color: var(--problem);
}

.status.bad::before {
  background: var(--problem);
}

.status.idle::before {
  background: none;
  border: 1px solid var(--muted);
}

.status.stale {
  color: var(--muted);
}

/* A titled box of details */
.panel {
  min-width: 0;
  border: 1px solid var(--line);
}

.panel > h2 {
  padding: 8px 14px;
  background: var(--subAlt);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
}

.panel tbody th {
  width: 1%;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  white-space: nowrap;
}

.panel td {
  overflow-wrap: anywhere;
  white-space: normal;
}

/* The panel already has the line around it */
.panel > .table-scroll {
  border: 0;
}

.panel-body {
  padding: 14px;
}

/* A panel that opens and closes, its summary looks like a panel's title bar */
.panel > summary {
  padding: 8px 14px;
  background: var(--subAlt);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.panel[open] > summary {
  border-bottom: 1px solid var(--line);
}

.panel.narrow {
  max-width: 720px;
}

.panel-gap {
  margin-bottom: 16px;
}

.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

/* One panel per plan, side by side for comparing them. Buttons line up along the bottom whatever
   length the description is */
.plans {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

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

.plan .panel-body {
  flex: 1;
  white-space: pre-line;
}

.plan table {
  flex: none;
}

.plan-action {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 52px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}

.spaced {
  margin-top: 10px;
}

.spaced-below {
  margin-bottom: 10px;
}

/* A box that needs noticing, like the new config or a problem */
.notice {
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--subAlt);
  border: 1px solid var(--line);
  border-left: 3px solid var(--main);
}

.notice.bad {
  border-left-color: var(--problem);
}

.notice h2 {
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 600;
}

.notice .actions {
  margin-top: 10px;
}

details {
  margin-top: 10px;
}

summary {
  color: var(--muted);
  cursor: pointer;
}

/* The new tunnel's config, and the IPv6 test's summary when it can't go on the clipboard */
#config-text,
#ipv6test-summary {
  margin: 8px 0 0;
  padding: 10px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  font: 13px/1.5 var(--mono);
}

.error-text {
  margin-bottom: 16px;
  color: var(--problem);
}

/* The Stats screen (stats.js), the one place with big numbers and charts, see DESIGN.md. The top bar's
   Stats button is marked while it shows */
#stats-link[aria-current="page"] {
  background: var(--hover);
}

/* The range buttons, joined into one row, with a bar in the accent under the picked one */
.stats-ranges {
  display: flex;
  flex-wrap: wrap;
}

.stats-ranges .button + .button {
  margin-left: -1px;
}

.stats-ranges .button[aria-pressed="true"] {
  position: relative;
  background: var(--hover);
}

.stats-ranges .button[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: var(--main);
}

/* The tables hold figures, which shouldn't break across lines the way a panel's text does. They scroll
   sideways on a phone instead */
#screen-stats .panel td {
  overflow-wrap: normal;
  white-space: nowrap;
}

/* Left-aligned, and as many to a row as fit (two on a phone), so a fifth doesn't stretch the others */
.stats-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  margin: 0 0 16px;
}

.stats-tile {
  padding: 10px 14px;
  border: 1px solid var(--line);
}

.stats-tile dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.stats-tile dd {
  margin: 0;
}

.stats-number {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.25;
}

/* A chart: tick labels down the left, the drawing, and the first and last dates under it. The labels are
   spread over the drawing's height, so each one's middle is on its line while their line height is twice
   STATS_PAD in stats.js */
.stats-chart {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  column-gap: 8px;
}

.stats-axis {
  display: flex;
  flex-direction: column-reverse;
  justify-content: space-between;
  align-items: flex-end;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
}

.stats-plot {
  display: block;
  width: 100%;
}

.stats-dates {
  grid-column: 2;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.stats-grid {
  stroke: var(--line);
  stroke-width: 1;
}

/* The first series solid in the accent, the second dashed in the secondary text colour. The round cap
   draws a point alone between gaps as a dot */
.stats-line {
  fill: none;
  stroke: var(--main);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stats-line.second {
  stroke-width: 2;
  stroke: var(--muted);
  stroke-dasharray: 4 6;
}

/* Self-signups filled in the accent, accounts staff made outlined, so a bar of either alone says which by
   more than colour */
.stats-bar {
  fill: var(--main);
}

.stats-bar.second {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.5;
}

/* The column over each point that holds its title */
.stats-hit {
  fill: transparent;
}

.stats-hit:hover {
  fill: var(--hover);
}

.stats-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 8px;
  font-size: 13px;
}

.stats-key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stats-sample {
  flex: none;
}

/* One small chart per box, side by side */
.stats-small {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

/* Touch screens have no hover, so the panel becomes a drawer behind a menu button */
@media (max-width: 760px) {
  #menu-button {
    display: flex;
    margin-left: 4px;
  }

  /* No room for it beside the account's email, so it is in the account menu instead */
  #stats-link {
    display: none;
  }

  #stats-menu-link:not([hidden]) {
    display: block;
  }

  #brand {
    padding-left: 4px;
  }

  /* The logo is VTT, so on phones it stands alone */
  #brand .long,
  #theme-name {
    display: none;
  }

  .logo {
    width: 44px;
    height: 20px;
  }

  #side,
  .pinned #side {
    width: var(--panel);
    transform: translateX(-100%);
    transition: transform 0.11s ease-out;
  }

  .drawer #side {
    transform: none;
  }

  .drawer #scrim {
    display: block;
    position: fixed;
    inset: var(--top) 0 0 0;
    z-index: 15;
    background: color-mix(in srgb, #000000 40%, transparent);
  }

  #side h2 {
    opacity: 1;
  }

  #pin {
    display: none;
  }

  main,
  .pinned main {
    margin-left: 0;
    padding: calc(var(--top) + 16px) 16px 32px;
  }

  .columns {
    grid-template-columns: minmax(0, 1fr);
  }

  /* size="40" would be wider than a phone */
  .form-row label,
  .form-stack label {
    width: 100%;
  }

  label input,
  label select {
    width: 100%;
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #side,
  .pinned #side {
    transition: none;
  }
}
