/* Hiterra — legal documents, the consent tick, and the sheet they open in.

   The documents are set as documents: black on white, serif throughout,
   numbered clauses with the number in the margin, lettered sub-clauses
   where the drafting already has them, a contents list on the long ones.
   No teal, no accent colour. A contract that carries brand colour reads
   as marketing, and the house rule for legal documents is plain black on
   white.

   One set of rules serves both places a document appears: its own page,
   and the sheet that opens over a form. Nothing is styled twice.

   Logical properties throughout, so Arabic mirrors without a second rule.
   The only exception is noted where it occurs. */

/* ── the document ─────────────────────────────────────────────────── */

.legal-doc {
  font-family: var(--font-head, Georgia, serif);
  color: #111;
  max-width: 66ch;
  margin-inline: auto;
  font-size: 1rem;
  line-height: 1.75;
}

.legal-doc h1 {
  font-family: inherit;
  font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2rem);
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: #000;
  margin: 0 0 1.25rem;
}

/* the issuing block: who, which version, from when */
.legal-meta {
  margin: 0 0 2rem;
  padding-block-end: 1.25rem;
  border-block-end: 1.5px solid #111;
  font-size: 0.8125rem;
  line-height: 1.7;
  color: #333;
}

.legal-meta b { font-weight: 600; color: #000 }
.legal-meta span { display: block }

/* ── contents, on the longer documents ───────────────────────────── */

.legal-toc {
  margin: 0 0 2.5rem;
  padding: 0;
  counter-reset: toc;
  font-size: 0.875rem;
  line-height: 1.9;
  columns: 2;
  column-gap: 2.5rem;
}

.legal-toc > li {
  counter-increment: toc;
  list-style: none;
  break-inside: avoid;
  padding-inline-start: 2rem;
  position: relative;
  color: #333;
}

.legal-toc > li::before {
  content: counter(toc) ".";
  position: absolute;
  inset-inline-start: 0;
  font-variant-numeric: tabular-nums;
  color: #000;
}

.legal-toc a { color: inherit; text-decoration: none }
.legal-toc a:hover { text-decoration: underline }

@media (max-width: 560px) { .legal-toc { columns: 1 } }

/* ── clauses ──────────────────────────────────────────────────────── */

.legal-body { counter-reset: cl; margin: 0; padding: 0 }

.legal-body > li {
  counter-increment: cl;
  list-style: none;
  margin-block-end: 1.75rem;
  padding-inline-start: 2.75rem;
  position: relative;
}

.legal-body > li::before {
  content: counter(cl) ".";
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: 0;
  width: 2rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #000;
}

.legal-h {
  display: block;
  font-weight: 600;
  color: #000;
  margin-block-end: 0.35rem;
}

.legal-body p { margin: 0 0 0.75rem }
.legal-body p:last-child { margin-block-end: 0 }

/* lettered sub-clauses, only where the drafting already had (a), (b) ... */
.legal-sub { margin: 0.625rem 0 0; padding: 0 }

.legal-sub > li {
  list-style: none;
  position: relative;
  padding-inline-start: 2rem;
  margin-block-end: 0.4rem;
}

.legal-sub > li:last-child { margin-block-end: 0 }

.legal-sub > li > .legal-l {
  position: absolute;
  inset-inline-start: 0;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 480px) {
  .legal-doc { font-size: 0.9375rem }
  .legal-body > li { padding-inline-start: 2rem }
  .legal-body > li::before { width: 1.5rem }
  .legal-sub > li { padding-inline-start: 1.5rem }
}

/* ── the consent tick on a form ──────────────────────────────────── */

.cns { margin-block: 1.25rem 1.5rem }

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

.cns-row input[type="checkbox"] {
  flex: 0 0 auto;
  width: 1.125rem;
  height: 1.125rem;
  margin-block-start: 0.24rem;
  accent-color: var(--teal-text, #007a78);
}

.cns-row label {
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--text, #1f2937);
}

.cns-row a {
  color: var(--ink, #0f1720);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--teal, #009c9a);
  cursor: pointer;
}

.cns-row a:hover { text-decoration-color: var(--ink, #0f1720) }

.cns-row a:focus-visible {
  outline: 2px solid var(--teal, #009c9a);
  outline-offset: 2px;
}

.cns-hint {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text, #1f2937);
}

/* ── the sheet the document opens in ─────────────────────────────── */

dialog.paper {
  padding: 0;
  border: 0;
  max-width: none;
  max-height: none;
  width: 100%;
  height: 100%;
  overflow: hidden;
  /* The scrim sits on the dialog, not on ::backdrop. The dialog already
     fills the viewport, so the two are equivalent, and this one renders
     predictably everywhere rather than depending on backdrop support. */
  background: rgba(15, 23, 32, 0.55);
}

dialog.paper::backdrop { background: transparent }

.paper-sheet {
  position: relative;
  background: #fff;
  width: min(760px, calc(100vw - 2rem));
  max-height: min(88vh, 100% - 2rem);
  margin: auto;
  display: flex;
  flex-direction: column;
  box-shadow: 0 18px 60px rgba(15, 23, 32, 0.22);
}

.paper-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(2rem, 5vw, 3.5rem) clamp(1.5rem, 5vw, 3.5rem);
}

.paper-body:focus { outline: none }

/* the close control: two strokes, drawn here so nothing is fetched */
.paper-x {
  position: absolute;
  inset-block-start: 0.75rem;
  inset-inline-end: 0.75rem;
  z-index: 2;
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  background: #fff;
  cursor: pointer;
  padding: 0;
}

.paper-x::before,
.paper-x::after {
  content: "";
  position: absolute;
  /* physical centring: a cross has no reading direction */
  left: 50%;
  top: 50%;
  width: 1rem;
  height: 1.5px;
  background: #111;
  transform-origin: center;
}

.paper-x::before { transform: translate(-50%, -50%) rotate(45deg) }
.paper-x::after { transform: translate(-50%, -50%) rotate(-45deg) }

.paper-x:hover::before,
.paper-x:hover::after { background: #000 }

.paper-x:focus-visible {
  outline: 2px solid var(--teal, #009c9a);
  outline-offset: -2px;
}

@media (max-width: 560px) {
  .paper-sheet { width: 100vw; max-height: 100vh; height: 100vh }
}
