/* The one stylesheet of every page (ticket 29). Sober: one system font stack, no third-party
   request, colour kept for compliance states and errors, each also written as a word and a
   symbol. Selectors are elements and the data attributes the pages already carry. */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1d2125;
  --muted: #5a636b;
  --line: #c9ced3;
  --panel: #f4f5f6;
  --accent: #1f4e8c;
  --focus: #1f4e8c;
  --pass: #17692e;
  --pass-bg: #e8f4ec;
  --fail: #a4161a;
  --fail-bg: #fbeaea;
  --warn: #7a4a00;
  --warn-bg: #fdf3dc;
  --ack: #4b3a8c;
  --ack-bg: #eeebf8;
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 1rem;
  --s4: 1.5rem;
  --s5: 2.5rem;
}

/* Screen only: on paper the print rules set the text black, which a dark tint would hide. */
@media screen and (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --fg: #e6e8ea;
    --muted: #a3acb4;
    --line: #3a4046;
    --panel: #1d2226;
    --accent: #8db8f0;
    --focus: #8db8f0;
    --pass: #7fd193;
    --pass-bg: #16301f;
    --fail: #ff9a9d;
    --fail-bg: #3a1a1c;
    --warn: #f0c36b;
    --warn-bg: #36290e;
    --ack: #c3b6f5;
    --ack-bg: #261f40;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-wrap: break-word;
}

main {
  max-width: 70rem;
  margin: 0 auto;
  padding: var(--s4) var(--s3) var(--s5);
}

h1 {
  font-size: 1.6rem;
  line-height: 1.25;
  margin: 0 0 var(--s4);
}

h2 {
  font-size: 1.2rem;
  margin: var(--s4) 0 var(--s2);
}

h3 {
  font-size: 1.05rem;
  margin: var(--s3) 0 var(--s2);
}

p,
ul,
ol {
  margin: 0 0 var(--s3);
  max-width: 44rem;
}

ul,
ol {
  padding-left: 1.4rem;
}

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

dt {
  color: var(--muted);
  font-size: 0.9rem;
}

dd {
  margin: 0 0 var(--s2);
  padding-left: var(--s3);
}

/* One signed logbook entry is one box: without it the entries run into each other. */
article[data-logbook-entry] {
  margin: 0 0 var(--s4);
  padding: var(--s3);
  border: 1px solid var(--line);
  border-radius: 4px;
  max-width: 44rem;
}

article[data-logbook-entry] > :last-child {
  margin-bottom: 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95em;
  padding: 0 var(--s1);
  background: var(--panel);
  overflow-wrap: anywhere;
}

/* Two links in one paragraph ("Add a pilot", "Add a crew member") must not touch. */
p > a + a {
  margin-left: var(--s3);
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
}

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

/* Forms */

form {
  margin: 0 0 var(--s4);
  max-width: 32rem;
}

label {
  display: block;
  margin: 0 0 var(--s3);
  font-weight: 600;
}

input,
select,
textarea {
  display: block;
  width: 100%;
  margin-top: var(--s1);
  padding: var(--s2);
  font: inherit;
  font-weight: 400;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--muted);
  border-radius: 4px;
}

input[type="checkbox"],
input[type="radio"] {
  display: inline-block;
  width: 1.1rem;
  height: 1.1rem;
  margin: 0 var(--s2) 0 var(--s1);
  vertical-align: middle;
  accent-color: var(--accent);
}

fieldset {
  min-width: 0;
  margin: 0 0 var(--s3);
  padding: var(--s2) var(--s3) var(--s3);
  border: 1px solid var(--line);
  border-radius: 4px;
}

legend {
  padding: 0 var(--s1);
  font-weight: 600;
}

input[type="hidden"] {
  display: none;
}

button {
  font: inherit;
  font-weight: 600;
  padding: var(--s2) var(--s3);
  color: var(--bg);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.1);
}

/* Tables keep their table semantics (Safari/VoiceOver drop them under `display: block`); on a
   narrow screen they scroll inside themselves, see the media query below. */

table {
  max-width: 100%;
  border-collapse: collapse;
  margin: 0 0 var(--s3);
}

[data-verdict] table:not(:has(tr)) {
  display: none;
}

[data-verdict] table,
[data-decision] table {
  background: none;
}

/* The row buttons sit in a form of their own: no margin there, and no full-width button. */
td form {
  margin: 0;
}

td button {
  width: auto;
  white-space: nowrap;
}

/* A value and its unit ("253.5 kg") stay together in the evidence tables. */
[data-verdict] td:last-child {
  white-space: nowrap;
}

caption {
  text-align: left;
  font-weight: 600;
  padding: var(--s1) 0;
}

th,
td {
  overflow-wrap: normal;
  padding: var(--s1) var(--s2);
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--panel);
}

/* Compliance states and errors. The word is in the markup; the symbol below repeats it. */

[data-verdict],
[data-decision],
[role="alert"] {
  position: relative;
  border-left: 4px solid var(--line);
  padding: var(--s2) var(--s3) var(--s2) 2.25rem;
  margin-bottom: var(--s2);
}

/* The symbol sits in the left gutter: the boxes hold block children, and an inline symbol would
   stand alone on the first line. */
[data-verdict]::before,
[data-decision]::before,
[role="alert"]::before {
  position: absolute;
  left: var(--s2);
  top: var(--s2);
}

/* A list of boxes has no bullet gutter of its own. */
ul:has(> [data-verdict]),
ul:has(> [data-decision]) {
  padding-left: 0;
}

[data-verdict] p,
[data-decision] p {
  margin-bottom: var(--s1);
}

[data-verdict] > :last-child,
[data-decision] > :last-child {
  margin-bottom: 0;
}

li[data-verdict],
li[data-decision] {
  list-style: none;
}

[data-verdict="pass"] {
  border-left-color: var(--pass);
  background: var(--pass-bg);
}

[data-verdict="pass"]::before {
  content: "\2713  ";
  color: var(--pass);
  font-weight: 700;
}

[data-verdict="fail"][data-severity="blocking"] {
  border-left-color: var(--fail);
  background: var(--fail-bg);
}

[data-verdict="fail"][data-severity="blocking"]::before {
  content: "\2717  ";
  color: var(--fail);
  font-weight: 700;
}

[data-verdict="fail"][data-severity="warning"] {
  border-left-color: var(--warn);
  background: var(--warn-bg);
}

[data-verdict="fail"][data-severity="warning"]::before {
  content: "\26A0  ";
  color: var(--warn);
  font-weight: 700;
}

[data-decision="GO"] {
  border-left-color: var(--pass);
  background: var(--pass-bg);
}

[data-decision="GO"]::before {
  content: "\2713  ";
  color: var(--pass);
  font-weight: 700;
}

[data-decision="NO_GO"] {
  border-left-color: var(--fail);
  background: var(--fail-bg);
}

[data-decision="NO_GO"]::before {
  content: "\2717  ";
  color: var(--fail);
  font-weight: 700;
}

[data-decision="OVERRIDE"] {
  border-left-color: var(--ack);
  background: var(--ack-bg);
}

[data-decision="OVERRIDE"]::before {
  content: "\2691  ";
  color: var(--ack);
  font-weight: 700;
}

[data-decision="pending"] {
  border-left-color: var(--warn);
  background: var(--warn-bg);
}

[data-decision="pending"]::before {
  content: "\25CB  ";
  color: var(--warn);
  font-weight: 700;
}

[role="alert"] {
  border-left-color: var(--fail);
  background: var(--fail-bg);
  max-width: 44rem;
  margin-bottom: var(--s3);
}

[role="alert"]::before {
  content: "\2717  ";
  color: var(--fail);
  font-weight: 700;
}

/* A table row that carries a state needs no box of its own. */
tr[data-check],
tr[data-kind] {
  border: 0;
  background: none;
}

/* Narrow screens (375 px): one column, comfortable targets. */

@media (max-width: 40rem) {
  /* A wide table scrolls inside itself, never the page. */
  table {
    display: block;
    overflow-x: auto;
    /* A shadow on the edge that has more to scroll (pure CSS, no script). */
    background:
      linear-gradient(to right, var(--bg) 30%, transparent) 0 0 / 2rem 100% no-repeat local,
      linear-gradient(to left, var(--bg) 30%, transparent) 100% 0 / 2rem 100% no-repeat local,
      linear-gradient(to right, var(--line), transparent) 0 0 / 0.6rem 100% no-repeat scroll,
      linear-gradient(to left, var(--line), transparent) 100% 0 / 0.6rem 100% no-repeat scroll;
  }

  /* A table with a caption and no row stays a plain table; inside a check it says nothing, so
     it is left out (an empty "Evidence" heading under a failing warning). */
  table:not(:has(tr)) {
    display: table;
  }

  main {
    padding: var(--s3) var(--s3) var(--s4);
  }

  h1 {
    font-size: 1.35rem;
  }

  button {
    width: 100%;
    padding: 0.75rem var(--s3);
  }

  th,
  td {
    padding: var(--s1);
  }
}

/* The flight sheet is printed from its own page; its own print rules stay in force. */

@media print {
  :root {
    --bg: #ffffff;
    --fg: #000000;
  }

  main {
    max-width: none;
    padding: 0;
  }

  table {
    display: table;
    overflow: visible;
    background: none;
  }

  /* A check is read as one block: never cut between two printed pages. */
  [data-verdict],
  [data-decision],
  [role="alert"] {
    break-inside: avoid;
  }

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

  a {
    color: inherit;
  }
}
