/**
 * Agreements — shared document styles (July 2026). SINGLE SOURCE OF TRUTH.
 *
 * House clause numbering: literal decimal numbers ("2.1)") are typed into the
 * document text so citations are frozen into signed copies. Clause lists use
 * plain nested <ol>; these rules hide the browser's own markers (which would
 * double-number) and lay clauses out contract-style with a FIXED-WIDTH number
 * gutter, so "9.1)" and "10.1)" text starts at the same column and wrapped
 * lines align under the text:
 *
 *   6) Title
 *      6.1)   Clause text that wraps onto a
 *             second line aligned with the text
 *             6.3.1)  Sub-clause…
 *
 * Technique: each render surface wraps the leading clause number of every <li>
 * in <span class="ms-clause-num"> AT DISPLAY TIME (PHP:
 * ms_agreements_decorate_clause_numbers() in public-render.php; the view modal
 * mirrors it in agreements-list.js). The stored/frozen content keeps plain
 * text numbers — CKEditor would strip spans on edit, and the hashed signed
 * content must stay clean. The span is an inline-block of the level's gutter
 * width, pulled left by the li's padding, so all text — first line and
 * wrapped — starts at the padding edge. If the span is absent (e.g. the
 * CKEditor editing view), the number just renders inline — graceful.
 *
 * Lettered lists (ol[type=a] / ol[type=i] — legacy docs / old signed copies)
 * keep their native markers. Genuine bullets stay <ul> and are untouched.
 * Bare document <table>s (e.g. the DPA's Schedule 3) get the contract look.
 *
 * Consumed by EVERY document surface:
 *   - Admin editor (CKEditor content, #ms-agreement-editor .ck-content)
 *   - Preview page ([agreements_preview], .ms-agreements-preview-body)
 *   - Public signing page ([agreement_sign], .ms-agreement-doc)
 *   - Portal view modal (#ms-view-body)
 *   - Public website ([public_agreement], .ms-public-agreement-body —
 *     enqueued by public-site.php on the main-site theme)
 *   - Signed PDF (Dompdf inlines this file; .ms-agreement-pdf scope below —
 *     Dompdf-safe selectors only, no :not())
 *
 * Bump MS_Agreements_Shortcodes::DOC_CSS_VER (and the matching version in
 * public-site.php) whenever this file changes.
 */

/* ── Clause lists: base ────────────────────────────────────────────────── */

.ms-agreement-doc ol:not([type]),
.ms-agreements-preview-body ol:not([type]),
#ms-view-body ol:not([type]),
.ms-public-agreement-body ol:not([type]),
#ms-agreement-editor .ck-content ol:not([type]) {
  list-style: none;
  padding-left: 1.25em; /* clause block sits inset from its section heading */
  margin: 0 0 1rem;
}

/* Nested clause lists — alignment comes from the parent li's text column,
   so the list box itself needs no extra padding. */
.ms-agreement-doc ol:not([type]) ol:not([type]),
.ms-agreements-preview-body ol:not([type]) ol:not([type]),
#ms-view-body ol:not([type]) ol:not([type]),
.ms-public-agreement-body ol:not([type]) ol:not([type]),
#ms-agreement-editor .ck-content ol:not([type]) ol:not([type]) {
  padding-left: 0;
  margin: 0.5rem 0 0;
}

/* ── Fixed-width number gutter, per nesting level ────────────────────────
   li padding-left = the text column; the .ms-clause-num span (added at
   display time) is an inline-block of exactly that width pulled back into
   the gutter — so text starts at the same column whatever the number width
   ("9.1)" vs "10.1)"), and wrapped lines align under the text. Widths fit
   each level's numbers: "12.3)" / "12.3.1)" / "1.2.2.1)". */

.ms-agreement-doc ol:not([type]) > li,
.ms-agreements-preview-body ol:not([type]) > li,
#ms-view-body ol:not([type]) > li,
.ms-public-agreement-body ol:not([type]) > li,
#ms-agreement-editor .ck-content ol:not([type]) > li {
  padding-left: 3.4em;
  margin-bottom: 0.5rem;
}
.ms-agreement-doc ol:not([type]) > li > .ms-clause-num,
.ms-agreements-preview-body ol:not([type]) > li > .ms-clause-num,
#ms-view-body ol:not([type]) > li > .ms-clause-num,
.ms-public-agreement-body ol:not([type]) > li > .ms-clause-num {
  display: inline-block;
  width: 3.4em;
  margin-left: -3.4em;
}

.ms-agreement-doc ol:not([type]) ol:not([type]) > li,
.ms-agreements-preview-body ol:not([type]) ol:not([type]) > li,
#ms-view-body ol:not([type]) ol:not([type]) > li,
.ms-public-agreement-body ol:not([type]) ol:not([type]) > li,
#ms-agreement-editor .ck-content ol:not([type]) ol:not([type]) > li {
  padding-left: 4.2em;
}
.ms-agreement-doc ol:not([type]) ol:not([type]) > li > .ms-clause-num,
.ms-agreements-preview-body ol:not([type]) ol:not([type]) > li > .ms-clause-num,
#ms-view-body ol:not([type]) ol:not([type]) > li > .ms-clause-num,
.ms-public-agreement-body ol:not([type]) ol:not([type]) > li > .ms-clause-num {
  width: 4.2em;
  margin-left: -4.2em;
}

.ms-agreement-doc ol:not([type]) ol:not([type]) ol:not([type]) > li,
.ms-agreements-preview-body ol:not([type]) ol:not([type]) ol:not([type]) > li,
#ms-view-body ol:not([type]) ol:not([type]) ol:not([type]) > li,
.ms-public-agreement-body ol:not([type]) ol:not([type]) ol:not([type]) > li,
#ms-agreement-editor .ck-content ol:not([type]) ol:not([type]) ol:not([type]) > li {
  padding-left: 5em;
}
.ms-agreement-doc ol:not([type]) ol:not([type]) ol:not([type]) > li > .ms-clause-num,
.ms-agreements-preview-body ol:not([type]) ol:not([type]) ol:not([type]) > li > .ms-clause-num,
#ms-view-body ol:not([type]) ol:not([type]) ol:not([type]) > li > .ms-clause-num,
.ms-public-agreement-body ol:not([type]) ol:not([type]) ol:not([type]) > li > .ms-clause-num {
  width: 5em;
  margin-left: -5em;
}

/* Blocks inside a clause align with the clause text column. */
.ms-agreement-doc li p,
.ms-agreements-preview-body li p,
#ms-view-body li p,
.ms-public-agreement-body li p,
#ms-agreement-editor .ck-content li p {
  margin: 0.5rem 0 0;
}
.ms-agreement-doc li ul,
.ms-agreements-preview-body li ul,
#ms-view-body li ul,
.ms-public-agreement-body li ul,
#ms-agreement-editor .ck-content li ul {
  list-style: disc;
  padding-left: 1.5em;
  margin: 0.5rem 0 0;
}

/* ── Document tables (e.g. the DPA's Schedule 3 sub-processor list) ──────
   Content tables are bare <table> markup (no Bootstrap classes — content
   renders on non-Bootstrap surfaces too), so the shared sheet provides the
   contract-style table look. Neutral rgba greys keep it dark-mode safe on
   the portal and theme-agnostic on the public website. */
.ms-agreement-doc table,
.ms-agreements-preview-body table,
#ms-view-body table,
.ms-public-agreement-body table,
#ms-agreement-editor .ck-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}
.ms-agreement-doc th, .ms-agreement-doc td,
.ms-agreements-preview-body th, .ms-agreements-preview-body td,
#ms-view-body th, #ms-view-body td,
.ms-public-agreement-body th, .ms-public-agreement-body td,
#ms-agreement-editor .ck-content th, #ms-agreement-editor .ck-content td {
  border: 1px solid rgba(134, 142, 150, 0.4);
  padding: 0.5rem 0.65rem;
  text-align: left;
  vertical-align: top;
}
.ms-agreement-doc thead th,
.ms-agreements-preview-body thead th,
#ms-view-body thead th,
.ms-public-agreement-body thead th,
#ms-agreement-editor .ck-content thead th {
  background: rgba(134, 142, 150, 0.12);
}

/* ── PDF scope (Dompdf) ──────────────────────────────────────────────────
   Dompdf's :not() support is unreliable, so the PDF wrapper gets plain
   rules with explicit [type] overrides instead. Same fixed-gutter layout
   in px (body font is 12px). The PDF service wraps the frozen document in
   <div class="body ms-agreement-pdf"> and inlines this whole file into the
   PDF's <style> block. */
.ms-agreement-pdf ol { list-style: none; padding-left: 15px; margin: 0 0 10px; }
.ms-agreement-pdf ol ol { padding-left: 0; margin: 6px 0 0; }
.ms-agreement-pdf ol > li { padding-left: 42px; margin-bottom: 6px; }
.ms-agreement-pdf ol > li > .ms-clause-num { display: inline-block; width: 42px; margin-left: -42px; }
.ms-agreement-pdf ol ol > li { padding-left: 52px; }
.ms-agreement-pdf ol ol > li > .ms-clause-num { width: 52px; margin-left: -52px; }
.ms-agreement-pdf ol ol ol > li { padding-left: 62px; }
.ms-agreement-pdf ol ol ol > li > .ms-clause-num { width: 62px; margin-left: -62px; }
.ms-agreement-pdf li p { margin: 6px 0 0; }
.ms-agreement-pdf li ul { list-style: disc; padding-left: 18px; margin: 6px 0 0; }
/* Legacy lettered lists (old published versions / signed copies) keep their
   native markers and normal layout. */
.ms-agreement-pdf ol[type="a"] { list-style-type: lower-alpha; padding-left: 22px; }
.ms-agreement-pdf ol[type="i"] { list-style-type: lower-roman; padding-left: 22px; }
.ms-agreement-pdf ol[type] > li { padding-left: 0; }
.ms-agreement-pdf table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.ms-agreement-pdf th, .ms-agreement-pdf td { border: 1px solid #ddd; padding: 4px 6px; text-align: left; vertical-align: top; }
.ms-agreement-pdf thead th { background: #f3f3f3; }

/* ── Merge-tag values ─────────────────────────────────────────────────────
   Resolved merge-tag values are wrapped in .ms-tag-value at render time
   (render_document() on issue; render_preview() for real preview values) so
   the client-specific parts read as filled-in fields. Light grey, dark-mode
   safe on screen; fixed light grey in the PDF. */
.ms-agreement-doc .ms-tag-value,
.ms-agreements-preview-body .ms-tag-value,
#ms-view-body .ms-tag-value,
.ms-public-agreement-body .ms-tag-value {
  background: rgba(134, 142, 150, 0.18);
  border-radius: 0.2em;
  padding: 0 0.2em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.ms-agreement-pdf .ms-tag-value { background-color: #ececec; }
