/* Facility Signing — components this app needs on top of style.css.
 *
 * Every colour comes from tokens.css, which was measured from relentlessdc.com.
 * Nothing here hardcodes one, so the app follows the brand and the AV-booth dark
 * mode for free.
 */

/* The `hidden` attribute must actually hide things.
 *
 * A browser's built-in rule is roughly `[hidden] { display: none }`, which any
 * class selector setting `display` outranks. `.guide { display: flex }` therefore
 * beat `hidden`, so the guide bar sat on screen next to the real Submit button
 * while its .hidden property read true — the JS was right and the page was wrong.
 * One rule, at the top, so no component can reintroduce it. */
[hidden] { display: none !important; }

/* --- status pills ------------------------------------------------------- */

.pill {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.15em 0.6em;
  border: 1px solid var(--rdc-border);
  border-radius: 999px;
  white-space: nowrap;
  color: var(--rdc-body);
}
/* Hue carries state, so "blocked" never relies on brightness alone. */
.pill[data-status="Uploaded"] { border-color: var(--rdc-border); }
.pill[data-status="Sent to Renter"] { border-color: var(--rdc-warn); color: var(--rdc-warn); }
.pill[data-status="Renter Signed"] { border-color: var(--rdc-warn); color: var(--rdc-warn); }
.pill[data-status="RDC Signed"] { border-color: var(--rdc-warn); color: var(--rdc-warn); }
.pill[data-status="Fully Executed"] { border-color: var(--rdc-ok); color: var(--rdc-ok); }
.pill[data-status="Declined"],
.pill[data-status="Expired"],
.pill[data-status="Voided"] { border-color: var(--rdc-error); color: var(--rdc-error); }

/* --- agreement list ----------------------------------------------------- */

.agreements { display: grid; gap: 0.75rem; margin: 1.5rem 0 0; padding: 0; list-style: none; }

.agreement-card {
  display: block;
  border: 1px solid var(--rdc-border);
  border-radius: var(--rdc-radius);
  padding: 1rem 1.125rem;
  text-decoration: none;
  color: inherit;
  background: var(--rdc-bg);
}
.agreement-card:hover,
.agreement-card:focus-visible { background: var(--rdc-surface); }

.agreement-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.agreement-title { font-weight: 600; color: var(--rdc-ink); }
.agreement-meta {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
  font-size: 0.875rem;
  color: var(--rdc-muted);
}

/* --- forms -------------------------------------------------------------- */

.field-grid { display: grid; gap: 1rem; }
@media (min-width: 40rem) { .field-grid.two { grid-template-columns: 1fr 1fr; } }

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-size: 0.8125rem; font-weight: 500; color: var(--rdc-ink); }
.field input[type="text"],
.field input[type="email"],
.field input[type="file"],
.field textarea {
  font: inherit;
  font-size: 0.9375rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--rdc-border);
  border-radius: var(--rdc-radius);
  background: var(--rdc-bg);
  color: var(--rdc-ink);
  width: 100%;
}
.field input:focus-visible,
.field textarea:focus-visible { outline: 2px solid var(--rdc-ink); outline-offset: 1px; }
.field .hint { font-size: 0.8125rem; color: var(--rdc-muted); }
/* Marks a value the system read out of the Word file rather than one a person typed. */
.field .from-doc { font-size: 0.75rem; color: var(--rdc-ok); }

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.9375rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--rdc-radius);
  border: 1px solid var(--rdc-accent);
  background: var(--rdc-accent);
  color: var(--rdc-accent-ink);
  cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--rdc-ink); border-color: var(--rdc-border); }
.btn.danger { background: transparent; color: var(--rdc-error); border-color: var(--rdc-error); }
.btn-row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1.25rem; }

/* --- the PDF and its field overlay -------------------------------------- */

.pdf-scroll {
  border: 1px solid var(--rdc-border);
  border-radius: var(--rdc-radius);
  background: var(--rdc-surface);
  padding: 1rem;
  overflow: auto;
  max-height: 78vh;
}
.pdf-page {
  position: relative;
  margin: 0 auto 1rem;
  background: #ffffff; /* paper is white in both themes; it is paper */
  box-shadow: 0 1px 4px rgb(0 0 0 / 18%);
}
.pdf-page canvas { display: block; }
.pdf-layer { position: absolute; inset: 0; }
.pdf-page-number {
  position: absolute;
  right: 0.35rem;
  bottom: 0.2rem;
  font-size: 0.6875rem;
  color: #767676;
  background: rgb(255 255 255 / 80%);
  padding: 0 0.25rem;
  border-radius: 2px;
}

/* A field box drawn over the page. */
.fieldbox {
  position: absolute;
  box-sizing: border-box;
  border: 1.5px solid var(--rdc-warn);
  background: rgb(217 166 64 / 14%);
  border-radius: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.625rem;
  color: #202020;
  overflow: hidden;
}
.fieldbox[data-role="rdc"] { border-color: #2f6fb3; background: rgb(47 111 179 / 12%); }
.fieldbox[data-filled="true"] { border-style: solid; background: rgb(28 124 74 / 12%); border-color: var(--rdc-ok); }
.fieldbox.selected { outline: 2px solid var(--rdc-ink); outline-offset: 1px; }
.fieldbox canvas { width: 100%; height: 100%; display: block; color: #202020; }
.fieldbox input {
  font: inherit;
  font-size: 0.75rem;
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  padding: 0 2px;
  color: #202020;
}
.fieldbox .tick { font-size: 1rem; line-height: 1; color: #202020; }

/* Required-but-empty, once the renter has tried to submit. */
.fieldbox[data-invalid="true"] {
  border-color: var(--rdc-error);
  background: rgb(163 34 34 / 14%);
}

/* --- signature pad ------------------------------------------------------ */

.sigpad-wrap { display: flex; flex-direction: column; gap: 0.5rem; }
.sigpad {
  width: 100%;
  height: 10rem;
  border: 1px dashed var(--rdc-border);
  border-radius: var(--rdc-radius);
  background: var(--rdc-bg);
  color: var(--rdc-ink);
  touch-action: none;
}
.sigpad-hint { font-size: 0.8125rem; color: var(--rdc-muted); }

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

dialog.sheet {
  border: 1px solid var(--rdc-border);
  border-radius: var(--rdc-radius);
  background: var(--rdc-bg);
  color: var(--rdc-body);
  padding: 1.25rem;
  max-width: 34rem;
  width: calc(100vw - 2rem);
}
dialog.sheet::backdrop { background: rgb(0 0 0 / 45%); }
dialog.sheet h2 { margin-top: 0; }

/* --- history ------------------------------------------------------------ */

.history { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: 0; }
.history li {
  display: grid;
  grid-template-columns: 11rem 1fr;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--rdc-border);
  font-size: 0.875rem;
}
.history li:last-child { border-bottom: 1px solid var(--rdc-border); }
.history .when { color: var(--rdc-muted); font-variant-numeric: tabular-nums; }
.history .what { color: var(--rdc-ink); }
.history .who-detail { color: var(--rdc-muted); }
@media (max-width: 34rem) {
  .history li { grid-template-columns: 1fr; gap: 0.1rem; }
}

/* --- misc --------------------------------------------------------------- */

.toolbar {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin: 1.25rem 0;
  padding: 0.75rem;
  border: 1px solid var(--rdc-border);
  border-radius: var(--rdc-radius);
  background: var(--rdc-surface);
}
.toolbar .spacer { flex: 1; }
.toolbar select {
  font: inherit;
  font-size: 0.875rem;
  padding: 0.4rem;
  border: 1px solid var(--rdc-border);
  border-radius: var(--rdc-radius);
  background: var(--rdc-bg);
  color: var(--rdc-ink);
}

.notice {
  border-left: 3px solid var(--rdc-warn);
  background: var(--rdc-surface);
  padding: 0.9rem 1.1rem;
  border-radius: 0 var(--rdc-radius) var(--rdc-radius) 0;
  margin: 1.25rem 0;
}
.notice.error { border-left-color: var(--rdc-error); }
.notice.ok { border-left-color: var(--rdc-ok); }
.notice p { margin: 0; }
.notice p + p { margin-top: 0.5rem; }
/* Preserves the newlines in a server message that carries a link to paste. */
.notice pre {
  margin: 0.5rem 0 0;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 0.8125rem;
  color: var(--rdc-ink);
}

.consent {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin: 1.5rem 0;
  padding: 1rem;
  border: 1px solid var(--rdc-border);
  border-radius: var(--rdc-radius);
  background: var(--rdc-surface);
}
.consent input { margin-top: 0.25rem; width: 1.1rem; height: 1.1rem; }
.consent label { font-size: 0.9375rem; }

.checklist { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: 0.5rem; }
.checklist li { display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.9375rem; }
.checklist input { margin-top: 0.2rem; width: 1.05rem; height: 1.05rem; flex: none; }
.checklist li[data-invalid="true"] { color: var(--rdc-error); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- mobile: the agreement has to be readable and the next step obvious ----
 *
 * Two things ruin a contract on a phone. One is a nested scroller: the document
 * gets its own scrollbox inside a scrolling page, so a thumb-swipe fights over
 * which one moves. The other is a full US Letter page fitted to a 390px screen,
 * which puts 11pt body text at roughly 5px. Both are fixed here.
 */
@media (max-width: 48rem) {
  /* One scroller, not two. The document flows in the page. */
  .pdf-scroll {
    max-height: none;
    overflow-x: auto;
    overflow-y: visible;
    padding: 0.4rem;
    border-radius: 0;
    margin-left: calc(-1 * clamp(1rem, 4vw, 2.5rem));
    margin-right: calc(-1 * clamp(1rem, 4vw, 2.5rem));
  }
  .pdf-page { margin-bottom: 0.5rem; }
  /* Room for the sticky guide bar so it never covers the last field. */
  main.wrap { padding-bottom: 7rem; }
}

/* --- the guide bar ------------------------------------------------------- */

.guide {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem clamp(0.75rem, 3vw, 1.25rem);
  background: var(--rdc-bg);
  border-top: 1px solid var(--rdc-border);
  /* Sits above the iPhone home indicator rather than under it. */
  padding-bottom: max(0.7rem, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 14px rgb(0 0 0 / 12%);
}
.guide-progress {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.guide-label {
  font-size: 0.8125rem;
  color: var(--rdc-ink);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.guide-count { font-size: 0.75rem; color: var(--rdc-muted); }
.guide-bar {
  height: 4px;
  border-radius: 999px;
  background: var(--rdc-border);
  overflow: hidden;
}
.guide-bar span {
  display: block;
  height: 100%;
  background: var(--rdc-ok);
  transition: width 0.25s ease;
}
@media (prefers-reduced-motion: reduce) { .guide-bar span { transition: none; } }
.guide .btn { flex: none; }

/* The field the guide just jumped to. Pulsed rather than merely outlined,
 * because on a phone a 11pt box is easy to lose among fourteen others. */
.fieldbox.pointed {
  outline: 3px solid var(--rdc-ink);
  outline-offset: 2px;
  animation: point 1.1s ease-out 2;
}
@keyframes point {
  0%   { box-shadow: 0 0 0 0 rgb(217 166 64 / 70%); }
  100% { box-shadow: 0 0 0 14px rgb(217 166 64 / 0%); }
}
@media (prefers-reduced-motion: reduce) {
  .fieldbox.pointed { animation: none; }
}

/* --- zoom control -------------------------------------------------------- */

.zoombar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0 0.25rem;
  font-size: 0.8125rem;
  color: var(--rdc-muted);
}
.zoombar button {
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--rdc-border);
  background: var(--rdc-bg);
  color: var(--rdc-ink);
  border-radius: var(--rdc-radius);
  cursor: pointer;
}
.zoombar button:disabled { opacity: 0.4; cursor: not-allowed; }
.zoombar .level { min-width: 3.5rem; font-variant-numeric: tabular-nums; }

/* --- readable acknowledgements ------------------------------------------
 * The boxes on the page are 11pt. Nobody should have to read a legal
 * acknowledgement at 11pt on a phone to know what they are agreeing to, so the
 * same items appear here at body size and stay in sync with the page. */
.acks { margin-top: 1.5rem; }
.acks ol { list-style: none; padding: 0; margin: 0.75rem 0 0; display: grid; gap: 0.6rem; }
.acks li {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--rdc-border);
  border-radius: var(--rdc-radius);
  background: var(--rdc-bg);
}
.acks li[data-checked="true"] { border-color: var(--rdc-ok); background: var(--rdc-surface); }
.acks li[data-invalid="true"] { border-color: var(--rdc-error); }
.acks input { margin-top: 0.15rem; width: 1.2rem; height: 1.2rem; flex: none; }
.acks label { font-size: 0.9375rem; line-height: 1.45; }

/* --- signing from the summary as well as the document -------------------- */

.sigblock { margin-top: 1.5rem; }
.sigblock h3 { margin-bottom: 0.5rem; }

.sigrow {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.8rem;
  border: 1px solid var(--rdc-border);
  border-radius: var(--rdc-radius);
  background: var(--rdc-bg);
}
.sigrow[data-signed="true"] { border-color: var(--rdc-ok); background: var(--rdc-surface); }
.sigrow[data-invalid="true"] { border-color: var(--rdc-error); }

.sigrow-preview {
  flex: 1;
  min-width: 0;
  height: 3.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--rdc-border);
  border-radius: var(--rdc-radius);
  color: var(--rdc-muted);
  font-size: 0.8125rem;
}
.sigrow[data-signed="true"] .sigrow-preview { border-style: solid; border-color: var(--rdc-border); }
/* The preview canvas inherits `color`, which is what renderStrokes draws with, so
 * the signature follows the theme instead of vanishing on a dark background. */
.sigrow-preview canvas { width: 100%; height: 100%; color: var(--rdc-ink); }
.sigrow .btn { flex: none; }
.sigrow-label { font-size: 0.8125rem; color: var(--rdc-muted); margin-bottom: 0.35rem; }
