/*
 * Print-first. The document is read on paper or as a PDF, so the layout is
 * built for a page rather than a scroll: fixed A4 measure, figures that do
 * not split across a break, and headings that do not end a page alone.
 */
@page {
  size: A4;
  margin: 20mm 18mm 18mm;
}

:root {
  --ink: #16202c;
  --muted: #5c6879;
  --line: #d7dee7;
  /* The app's own blue (client/src/styles/_tokens.scss). */
  --accent: #146db3;
  --tint: #f3f6fa;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 10.5pt;
  line-height: 1.55;
  color: var(--ink);
}

h1,
h2,
h3 {
  line-height: 1.25;
  break-after: avoid;
}

h2 {
  font-size: 17pt;
  margin: 0 0 2mm;
  padding-bottom: 2mm;
  border-bottom: 2px solid var(--accent);
  break-before: page;
}

h3 {
  font-size: 12.5pt;
  margin: 7mm 0 1mm;
}

p {
  margin: 0 0 3mm;
  orphans: 2;
  widows: 2;
}

/* ---------------------------------------------------------------- Cover */

.cover {
  height: 247mm;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* The cover is a page of its own: the contents' heading was left at its
     foot, the list it heads on the page after. */
  break-after: page;
}

/* The product's mark above every cover, from client/public/brand/logo.svg;
   written in, so the PDF and the help pages need no file beside them. */
.cover::before {
  content: '';
  width: 15mm;
  height: 15mm;
  margin-bottom: 7mm;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 154 154'%3E%3Cdefs%3E%3ClinearGradient id='fastomr-outer' gradientUnits='userSpaceOnUse' x1='16.36' y1='32.5' x2='60.04' y2='118.21'%3E%3Cstop offset='0' stop-color='%232288ce'/%3E%3Cstop offset='0.25' stop-color='%23258bca'/%3E%3Cstop offset='0.5' stop-color='%232c94b6'/%3E%3Cstop offset='0.75' stop-color='%2344a390'/%3E%3Cstop offset='1' stop-color='%2354a880'/%3E%3C/linearGradient%3E%3ClinearGradient id='fastomr-inner' gradientUnits='userSpaceOnUse' x1='60.06' y1='135.37' x2='22.31' y2='50.59'%3E%3Cstop offset='0' stop-color='%2354a877'/%3E%3Cstop offset='0.25' stop-color='%2349a283'/%3E%3Cstop offset='0.5' stop-color='%23389899'/%3E%3Cstop offset='0.75' stop-color='%23237ea6'/%3E%3Cstop offset='1' stop-color='%231868aa'/%3E%3C/linearGradient%3E%3ClinearGradient id='fastomr-lower' gradientUnits='userSpaceOnUse' x1='32.6' y1='122.57' x2='41.6' y2='156.18'%3E%3Cstop offset='0' stop-color='%2356aa64'/%3E%3Cstop offset='0.25' stop-color='%2362b163'/%3E%3Cstop offset='0.5' stop-color='%2372b85c'/%3E%3Cstop offset='0.75' stop-color='%237ebc52'/%3E%3Cstop offset='1' stop-color='%2386be50'/%3E%3C/linearGradient%3E%3C/defs%3E%3Cpath fill='url(%23fastomr-outer)' d='M145.61 76.76A68.61 68.61 0 1 0 11 95.74L24.15 92.01A54.94 54.94 0 1 1 131.94 76.81Z'/%3E%3Cpath fill='url(%23fastomr-lower)' d='M32.35 129.09A68.61 68.61 0 0 0 137.86 108.68L125.73 102.37A54.94 54.94 0 0 1 41.25 118.71Z'/%3E%3Cpath fill='url(%23fastomr-inner)' d='M79.88 29.37A47.72 47.72 0 1 0 105.44 38.68L97.63 50.39A33.67 33.67 0 1 1 79.85 43.45Z'/%3E%3C/svg%3E")
    center / contain no-repeat;
}

.cover h1 {
  font-size: 34pt;
  margin: 0 0 3mm;
  letter-spacing: -0.5pt;
}

.cover .lead {
  font-size: 13pt;
  color: var(--muted);
  max-width: 130mm;
}

.cover .meta {
  margin-top: 14mm;
  padding-top: 4mm;
  border-top: 1px solid var(--line);
  font-size: 9.5pt;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 1mm 3mm;
  border-radius: 10mm;
  background: var(--accent);
  color: #fff;
  font-size: 9pt;
  font-weight: 600;
  letter-spacing: 0.3pt;
}

/* ----------------------------------------------------------------- Flow */

.flow {
  display: flex;
  gap: 3mm;
  margin: 5mm 0 0;
}

.flow div {
  flex: 1;
  padding: 3mm;
  border: 1px solid var(--line);
  border-radius: 2mm;
  background: var(--tint);
  font-size: 9.5pt;
}

.flow strong {
  display: block;
  font-size: 10.5pt;
  margin-bottom: 1mm;
}

/* --------------------------------------------------------------- Figures */

figure {
  margin: 4mm 0 6mm;
  break-inside: avoid;
}

figure img {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 1.5mm;
  display: block;
}

figcaption {
  margin-top: 1.5mm;
  font-size: 9pt;
  color: var(--muted);
}

figcaption b {
  color: var(--ink);
}

/* ---------------------------------------------------------------- Blocks */

.note {
  margin: 4mm 0;
  padding: 3mm 4mm;
  border-left: 3px solid var(--accent);
  background: var(--tint);
  font-size: 9.5pt;
  break-inside: avoid;
}

/* The note's title is its first bold run; a bold word mid-sentence stays in the sentence. */
.note > b:first-child {
  display: block;
  margin-bottom: 1mm;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 3mm 0 5mm;
  font-size: 9.5pt;
  break-inside: avoid;
}

th,
td {
  text-align: left;
  padding: 2mm 3mm;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  background: var(--tint);
  font-weight: 600;
}

ol,
ul {
  margin: 0 0 3mm;
  padding-left: 6mm;
}

li {
  margin-bottom: 1.5mm;
}

code {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 9.5pt;
  background: var(--tint);
  padding: 0.5mm 1.5mm;
  border-radius: 1mm;
}

pre {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 9.5pt;
  line-height: 1.6;
  background: var(--tint);
  padding: 3mm 4mm;
  border-radius: 1.5mm;
  margin: 3mm 0;
  white-space: pre-wrap;
  break-inside: avoid;
}

/* ------------------------------------------------------------------ TOC */

.toc {
  break-after: page;
}

.toc h2 {
  break-before: avoid;
}

.toc ol {
  list-style: none;
  padding: 0;
  margin-top: 4mm;
  font-size: 10.5pt;
}

.toc li {
  padding: 1.5mm 0;
  border-bottom: 1px dotted var(--line);
}

.toc span {
  color: var(--muted);
  font-size: 9.5pt;
}

/* Links on screen and in the PDF; on paper they read as the plain entry they replace. */
.toc a {
  color: inherit;
  text-decoration: none;
}

/* ----------------------------------------------------- Permission matrix */

/*
 * Written into each document by `permissions.mjs` from the contracts' own
 * role table, so the page never says a role can do what the code refuses.
 * The reader's own role, in a role guide, is the tinted column.
 */
.matrix {
  font-size: 9pt;
  break-inside: auto;
}

.matrix tr {
  break-inside: avoid;
}

.matrix th,
.matrix td {
  padding: 1.6mm 2.5mm;
}

.matrix th.role,
.matrix td.mark {
  text-align: center;
  width: 19mm;
}

/* Six columns in the feature table: "System administrator" has to fit its own. */
.matrix th.role {
  font-size: 8pt;
  overflow-wrap: anywhere;
}

/* The line under a table that explains its marks (the † of the feature table). */
.legend {
  margin-top: 2mm;
  color: var(--muted);
  font-size: 8.5pt;
}

.matrix tr.group th {
  background: none;
  color: var(--accent);
  font-size: 9.5pt;
  padding-top: 4mm;
  break-after: avoid;
}

.matrix td.mark {
  color: var(--accent);
  font-weight: 600;
}

.matrix td.mark.no {
  color: var(--line);
}

.matrix .me {
  background: var(--tint);
}

.matrix td code {
  display: block;
  padding: 0;
  background: none;
  color: var(--muted);
  font-size: 8.5pt;
}

/* ------------------------------------------------------------ Role guides */

/* "You can" / "you cannot" lists: the mark says which without reading the sentence. */
ul.can,
ul.cannot {
  list-style: none;
  padding-left: 0;
}

ul.can li,
ul.cannot li {
  padding-left: 6mm;
  position: relative;
}

ul.can li::before,
ul.cannot li::before {
  position: absolute;
  left: 0;
  font-weight: 700;
}

ul.can li::before {
  content: '✓';
  color: var(--accent);
}

ul.cannot li::before {
  content: '✕';
  color: var(--muted);
}

/*
 * A role guide is a short document: its sections run on, and only its cover
 * and its permission table take a page of their own.
 */
body.guide h2 {
  break-before: auto;
  margin-top: 9mm;
}

body.guide h2.page {
  break-before: page;
  margin-top: 0;
}

body.guide .cover {
  height: 247mm;
}

/* A guide's tables are long lists of situations; they run across pages, one row at a time. */
body.guide table {
  break-inside: auto;
}

body.guide tr {
  break-inside: avoid;
}

body.guide thead {
  display: table-header-group;
}

/* ---------------------------------------------------------------- Screen */

/*
 * The same document is the installation's help page:
 * client/scripts/copy-manual.mjs serves it at /help/<edition>/. A screen has
 * no page to fill, so the page measures above give way to one readable
 * column, the cover to a heading, and the contents to links. The PDF is
 * printed with print media, which none of this touches.
 */
@media screen {
  html {
    background: var(--tint);
    scroll-behavior: smooth;
  }

  body {
    max-width: 54rem;
    margin: 0 auto;
    padding: 3rem clamp(1rem, 5vw, 3.5rem) 5rem;
    background: #fff;
    font-size: 1rem;
    line-height: 1.65;
    min-height: 100vh;
  }

  h2 {
    margin-top: 3.5rem;
    font-size: 1.625rem;
    scroll-margin-top: 1.5rem;
  }

  h3 {
    margin-top: 2rem;
    font-size: 1.1875rem;
  }

  p {
    margin-bottom: 0.875rem;
  }

  .cover {
    height: auto;
    padding: 1rem 0 2rem;
  }

  .cover h1 {
    font-size: clamp(2.25rem, 6vw, 3rem);
  }

  .cover .lead {
    font-size: 1.1875rem;
    max-width: 38rem;
  }

  .cover .meta {
    margin-top: 2rem;
    font-size: 0.875rem;
  }

  .toc {
    margin-top: 1rem;
    padding: 1.5rem 1.75rem;
    border: 1px solid var(--line);
    border-radius: 0.75rem;
  }

  .toc h2 {
    margin-top: 0;
    font-size: 1.25rem;
  }

  .toc ol {
    font-size: 1rem;
  }

  .toc a {
    color: var(--accent);
    font-weight: 600;
  }

  .toc a:hover,
  .toc a:focus-visible {
    text-decoration: underline;
  }

  .toc span,
  figcaption,
  .note,
  table,
  pre,
  .flow div {
    font-size: 0.9375rem;
  }

  code {
    font-size: 0.875em;
  }

  figure img {
    height: auto;
    border-radius: 0.5rem;
  }

  .matrix {
    font-size: 0.875rem;
  }
}

/*
 * On a screen set to dark, the help page is dark too: opened from the app in
 * its dark theme it was the brightest thing on the screen. The app's own dark
 * colours (client/src/styles/_tokens.scss); the screenshots keep their light,
 * and print keeps the paper.
 */
@media screen and (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #e8eaee;
    --muted: #98a1af;
    --line: #2c333d;
    --accent: #58b4e8;
    --tint: #0f1216;
  }

  body {
    background: #14171b;
  }

  /* White type on the dark theme's lighter blue would not read. */
  .badge {
    background: #146db3;
  }
}

/* A phone: the four steps stack, and a wide table scrolls inside itself rather than the page. */
@media screen and (max-width: 40rem) {
  body {
    padding-top: 1.5rem;
  }

  .flow {
    flex-direction: column;
  }

  table {
    display: block;
    overflow-x: auto;
  }
}
