/*
 * clickwrap — bundled default styles.
 *
 * Deliberately small and unopinionated. It sets the things that change whether
 * a person can USE the block — focus you can see, links that look like links,
 * targets big enough to press, errors that read as errors in words — and stops
 * well short of a design. Everything is scoped under `.clickwrap`, so dropping
 * this file into a host stylesheet cannot repaint anything else on the page.
 *
 * Self-contained on purpose: engine views can't lean on the host's CSS
 * framework (a Tailwind host never scans gem view files, so utility classes
 * used here would simply not exist in its build). Semantic clickwrap-* classes
 * plus plain modern CSS work in any host with zero build integration.
 *
 * Theme it with CSS variables from any host stylesheet:
 *
 *   :root {
 *     --clickwrap-link: #1d4ed8;
 *     --clickwrap-error: #b3261e;
 *   }
 *
 * Want something completely different? `bin/rails generate clickwrap:views`
 * ejects the templates into your app; restyle them and skip this file.
 *
 * What this file cannot do is make a page accessible. Placement, contrast
 * against YOUR background, surrounding clutter, reading order, and the words
 * themselves belong to the host page. These are defaults that try not to be the
 * problem.
 */

.clickwrap {
  --clickwrap-text: #111827;
  --clickwrap-muted: #4b5563;
  --clickwrap-link: #1d4ed8;
  --clickwrap-link-visited: #6b21a8;
  --clickwrap-error: #b3261e;
  --clickwrap-error-surface: #fdf2f2;
  --clickwrap-border: #6b7280;
  --clickwrap-focus: #111827;
  --clickwrap-radius: 0.375rem;

  color: var(--clickwrap-text);
  font: inherit;
  line-height: 1.5;
}

/* --- Focus ------------------------------------------------------------------
 * A visible focus ring on everything focusable, in both directions: the outline
 * is drawn, and it is offset so it stays visible on top of a control that has
 * its own border. Never `outline: none`.
 */

.clickwrap :is(a, button, input, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--clickwrap-focus);
  outline-offset: 2px;
  border-radius: 2px;
}

/* --- Screen-reader-only text -------------------------------------------------
 * The "(opens in a new tab)" truth without the clutter: announced, never drawn.
 * Not `display: none` and not `visibility: hidden` — both remove it from the
 * accessibility tree, which is the one place it needs to exist.
 */

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

/* --- Statements --------------------------------------------------------------
 * The default is one line: a checkbox and a sentence with links in it. Aligned
 * on the first line's baseline rather than the box's top edge, so the control
 * sits with the words instead of above them, and nothing wraps to a second row
 * that a person has to read as a second thing.
 */

.clickwrap-statements { display: flex; flex-direction: column; gap: 1rem; }

.clickwrap-statement__control { display: flex; align-items: flex-start; gap: 0.6rem; }

.clickwrap-statement__checkbox,
.clickwrap-statement__radio {
  /* Sized in em so the box matches the sentence it belongs to instead of
     towering over small text, and optically centered against the FIRST line
     of the label: (line-height minus box) halved. Flex `baseline` cannot do
     this — a checkbox aligns its bottom edge to the baseline and ends up
     floating high. The rem fallback covers engines without the lh unit. */
  width: 1em;
  height: 1em;
  margin: 0.2em 0 0;
  margin-top: calc((1lh - 1em) / 2);
  flex: 0 0 auto;
  accent-color: var(--clickwrap-focus);
}

.clickwrap-statement__label,
.clickwrap-statement__choice-label { cursor: pointer; }

.clickwrap-statement__choices {
  border: 1px solid var(--clickwrap-border);
  border-radius: var(--clickwrap-radius);
  padding: 0.75rem 1rem;
  margin: 0;
}

.clickwrap-statement__legend { font-weight: 600; padding: 0 0.25rem; }
.clickwrap-statement__choice { display: inline-flex; align-items: center; gap: 0.4rem; margin-right: 1rem; }

/* --- Documents ---------------------------------------------------------------
 * Links look like links: underlined, in a conventional link color, and distinct
 * from the surrounding text by more than color alone. In the composed line they
 * sit inside the sentence; on an itemized statement they sit under it.
 */

.clickwrap-documents { list-style: none; margin: 0.4rem 0 0; padding: 0 0 0 1.75rem; }
.clickwrap-documents__item { margin: 0.15rem 0; font-size: 0.9375rem; }

.clickwrap-documents__link,
.clickwrap-link {
  /* The links read AS PART of the sentence: same color as the words around
     them, distinguished by a subtle underline — still a non-color signal, so
     the distinction survives color-blindness and forced-colors modes. The
     underline firms up on hover/focus as the affordance. */
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
  text-underline-offset: 0.18em;
}

.clickwrap-documents__link:hover,
.clickwrap-documents__link:focus-visible,
.clickwrap-link:hover,
.clickwrap-link:focus-visible { text-decoration-color: currentColor; }

.clickwrap-documents__link:visited,
.clickwrap-link:visited { color: inherit; }

/* Versions belong on a receipt, where somebody is reading the record. Beside a
   checkbox they are noise nobody can act on. */
.clickwrap-documents__version { color: var(--clickwrap-muted); font-size: 0.8125rem; }

/* --- Errors ------------------------------------------------------------------
 * Never color alone. The message is words, it is prefixed by the word "Error",
 * and the block carries a heavy left rule — so it still reads as an error in
 * grayscale, in high-contrast mode, and to someone who cannot see red.
 */

.clickwrap-error-summary {
  border: 2px solid var(--clickwrap-error);
  border-left-width: 8px;
  background: var(--clickwrap-error-surface);
  border-radius: var(--clickwrap-radius);
  padding: 0.85rem 1rem;
  margin: 0 0 1rem;
}

.clickwrap-error-summary__heading { margin: 0 0 0.5rem; font-size: 1.0625rem; font-weight: 700; }
.clickwrap-error-summary__list { margin: 0; padding-left: 1.25rem; }
.clickwrap-error-summary__link { color: var(--clickwrap-error); text-decoration: underline; }

.clickwrap-statement--invalid {
  border-left: 4px solid var(--clickwrap-error);
  padding-left: 0.75rem;
}

.clickwrap-statement__error { color: var(--clickwrap-error); margin: 0.35rem 0 0; font-size: 0.9375rem; }
.clickwrap-statement__error-prefix { font-weight: 700; }

.clickwrap-flash { padding: 0.75rem 1rem; border-radius: var(--clickwrap-radius); }
.clickwrap-flash--alert {
  border: 2px solid var(--clickwrap-error);
  border-left-width: 8px;
  background: var(--clickwrap-error-surface);
}

/* --- Actions ------------------------------------------------------------------ */

.clickwrap-actions { margin-top: 1.25rem; }

.clickwrap-submit {
  font: inherit;
  padding: 0.6rem 1.1rem;
  border-radius: var(--clickwrap-radius);
  border: 1px solid var(--clickwrap-focus);
  background: var(--clickwrap-focus);
  color: #ffffff;
  cursor: pointer;
  min-height: 2.75rem;
}

/* --- Engine screens ------------------------------------------------------------
 * Only the four pages this gem ships. A host page that embeds the form helper
 * keeps its own layout entirely.
 */

.clickwrap-screen { max-width: 42rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.clickwrap-screen__title { font-size: 1.5rem; margin: 0 0 0.35rem; }
.clickwrap-screen__subtitle { font-size: 1.125rem; margin: 1.5rem 0 0.5rem; }
.clickwrap-screen__intro { color: var(--clickwrap-muted); margin: 0 0 1.25rem; }
.clickwrap-screen__actions { margin-top: 1.5rem; }

.clickwrap-facts { display: grid; grid-template-columns: minmax(10rem, auto) 1fr; gap: 0.35rem 1rem; margin: 0; }
.clickwrap-facts dt { color: var(--clickwrap-muted); }
.clickwrap-facts dd { margin: 0; }

.clickwrap-receipts, .clickwrap-acts { list-style: none; margin: 0; padding: 0; }

.clickwrap-receipts__item,
.clickwrap-acts__item {
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
}

.clickwrap-receipts__link { color: var(--clickwrap-link); text-decoration: underline; font-weight: 600; }
.clickwrap-receipts__meta, .clickwrap-acts__meta { display: block; color: var(--clickwrap-muted); font-size: 0.875rem; }
.clickwrap-acts__assertion { margin: 0; }

.clickwrap-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8125rem;
  word-break: break-all;
}

.clickwrap-code--digest { display: block; color: var(--clickwrap-muted); }
.clickwrap-empty, .clickwrap-note { color: var(--clickwrap-muted); }
.clickwrap-note { margin-top: 2rem; font-size: 0.875rem; }

/* Respect a reader's own contrast and motion settings rather than overriding
   them: in forced-colors mode the system palette wins outright. */
@media (forced-colors: active) {
  .clickwrap :is(a, button, input, [tabindex]):focus-visible { outline: 3px solid CanvasText; }
  .clickwrap-error-summary, .clickwrap-flash--alert { border-color: CanvasText; }
}
