/*
 * The signing page's stylesheet, served as written from /s/assets/ (style-src 'self': no inline
 * style, and the script sets styles only through element.style). Plain CSS, no framework.
 * Phone first: one column, 44px touch targets, text at least 16px so a phone does not zoom in.
 */

:root {
  --ink: #1b1f24;
  --muted: #4a5560;
  --paper: #ffffff;
  --ground: #eef1f4;
  --line: #c3cad2;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --needed: #92400e;
  --needed-fill: rgba(251, 191, 36, 0.28);
  --done: #166534;
  --done-fill: rgba(34, 197, 94, 0.14);
  --danger: #b91c1c;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  /* Anything scrolled into view (a focused field, a jump to the next one) clears the bar. */
  scroll-padding-bottom: 9rem;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font:
    1rem/1.5 system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
}

main {
  max-width: 60rem;
  margin: 0 auto;
  padding: 1rem;
  outline: none;
  /* Tenant text (organisation, title, signer name, a file-name style title with no spaces) must wrap
     inside the screen, never widen it. */
  overflow-wrap: anywhere;
}

h1,
h2 {
  line-height: 1.25;
  margin: 0 0 0.5rem;
}

h1 {
  font-size: 1.5rem;
}

h2 {
  font-size: 1.25rem;
}

/* One clear focus ring for everything that can take focus. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

h1:focus,
h2:focus {
  outline: none;
}

.banner {
  margin-bottom: 1rem;
}

.org {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.signer {
  margin: 0;
  color: var(--muted);
}

.status,
.consent {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 1.25rem;
}

.consent-text {
  border-left: 4px solid var(--line);
  margin: 1rem 0;
  padding: 0.25rem 0 0.25rem 1rem;
}

.check {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.check input {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  margin: 0.15rem 0 0;
}

/* Buttons and button-like links. */
button,
a.button {
  display: inline-block;
  min-height: 2.75rem;
  padding: 0.5rem 1.1rem;
  border: 2px solid var(--accent);
  border-radius: 0.4rem;
  background: var(--paper);
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: var(--accent-ink);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.error {
  margin: 0.5rem 0 0;
  color: var(--danger);
  font-weight: 600;
}

.error:empty {
  display: none;
}

.hint,
.intro,
.doc-note,
.progress {
  color: var(--muted);
}

label {
  display: block;
  font-weight: 600;
}

/* The text boxes of the dialogs. A field laid over the document is sized by the sender (below). */
.dialog input[type='text'],
textarea {
  width: 100%;
  min-height: 2.75rem;
  margin-top: 0.25rem;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--line);
  border-radius: 0.4rem;
  background: var(--paper);
  color: inherit;
  font: inherit;
}

.check label {
  font-weight: 400;
}

/* The document: one canvas per page, the signer's fields laid over it. */
.pages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 1rem 0 6rem;
}

.page {
  position: relative;
  width: 100%;
  background: var(--paper);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
}

.page-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.field {
  /* Scrolled to, a field must clear the bar stuck to the bottom of the screen. */
  scroll-margin: 8rem 0;
  position: absolute;
  margin: 0;
  padding: 0;
  min-height: 0;
  overflow: hidden;
  border: 2px dashed var(--line);
  border-radius: 0.2rem;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: max(0.7rem, calc(var(--page-width, 800px) * 0.018));
  font-weight: 400;
  line-height: 1.1;
}

.field.needed {
  border-color: var(--needed);
  background: var(--needed-fill);
}

.field.done {
  border-color: var(--done);
  background: var(--done-fill);
}

.field-sign {
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  cursor: pointer;
}

.field-text {
  /* 16px at least, or iOS Safari zooms the page when the box takes focus. The box keeps the size
     the sender gave it: a field is never stretched to a touch size over the field below. */
  font-size: max(16px, calc(var(--page-width, 800px) * 0.018));
  line-height: 1;
  padding: 0 0.3em;
  border-width: 1px;
}

.field-check {
  accent-color: var(--accent);
}

.field-fixed {
  display: flex;
  align-items: center;
  padding: 0 0.3em;
  border-style: dotted;
  color: var(--muted);
}

.placeholder {
  color: var(--needed);
  font-weight: 700;
}

.typed-signature,
.typed-preview {
  font-family: 'Snell Roundhand', 'Segoe Script', 'Brush Script MT', 'Lucida Handwriting', cursive;
  font-style: italic;
  color: #0b2a6f;
}

.typed-signature {
  font-size: 1.6em;
  white-space: nowrap;
}

.typed-preview {
  min-height: 3rem;
  margin: 0.25rem 0;
  font-size: 2rem;
  overflow-wrap: anywhere;
}

.drawn-signature {
  max-width: 100%;
  max-height: 100%;
}

/* What is left to do, kept in reach at the bottom of the screen. */
.bar {
  position: sticky;
  bottom: 0;
  margin: 0 -1rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.bar p {
  margin: 0;
}

.bar .actions {
  margin-top: 0.5rem;
}

/* Dialogs: the signature and the decline confirmation. */
.dialog {
  width: min(100% - 2rem, 40rem);
  max-height: calc(100% - 2rem);
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--paper);
  color: var(--ink);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.choice {
  margin: 0 0 1rem;
  padding: 0;
  border: 0;
}

.choice legend {
  padding: 0;
  font-weight: 600;
}

.choice p {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.25rem 0;
}

.choice input {
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
}

.choice label {
  font-weight: 400;
}

.pad-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 1;
  border: 2px solid var(--line);
  border-radius: 0.4rem;
  background: var(--paper);
  /* A finger drawing must not scroll the page. */
  touch-action: none;
  cursor: crosshair;
}

@media (min-width: 40rem) {
  main {
    padding: 1.5rem;
  }

  .bar {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 0.5rem 0.5rem 0 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  button {
    transition: opacity 0.15s;
  }
}

/* The verify page (verify.<host>): one card with a file input and its answer. Text on these
   backgrounds is the ink-on-fill pair the contrast test already covers. */
input[type='file'] {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  margin-top: 0.25rem;
  font: inherit;
}

.verify-result {
  margin-top: 1rem;
}

.verify-result.match,
.verify-result.nomatch {
  padding: 0.25rem 1rem;
  border: 2px solid var(--line);
  border-radius: 0.4rem;
}

.verify-result.match {
  border-color: var(--done);
  background: var(--done-fill);
}

.verify-result.nomatch {
  border-color: var(--needed);
  background: var(--needed-fill);
}

.verify-result code {
  font-size: 0.9rem;
}
