/* ============================================================
   reader-ap-body.css — Administrative Procedure BODY typography
   in the portal reader (/view/{id}).
   ============================================================
   WHY THIS FILE EXISTS
   View.cshtml emits @Html.Raw(Model.Html) as a bare fragment
   directly inside <main class="reader-main">. There is no
   .gov-page / .gov-content / .tier-ap wrapper on the reader
   page, so every body rule in themes/ap.css (the H1 rule, the
   28px content indent) is dead code there. The AP body falls
   through to base.css alone: 11pt / 1.55, 10px paragraph gaps,
   4px list-item gaps, at the full ~880px reader column — about
   130 characters per line. That is the "crowded" complaint.

   This file styles the AP body where it actually lives.
   It does NOT touch .gov-header.ap (the title bar) or the
   reader chrome, and it carries its own @media print block so
   the Print button keeps producing a Word-parity page.

   INSTALL (two edits, both in Pages/View.cshtml)

   1. In @section Head, after the reader.css link:
        @if (docClass == "ap")
        {
            <link rel="stylesheet" href="~/css/reader-ap-body.css" asp-append-version="true" />
        }

   2. On the reader main element (~line 124):
        <main class="reader-main @(docClass == "ap" ? "doc-ap" : "")" id="reader-main">

   No renderer, Markdig, or markdown-source changes required.
   ============================================================ */

.reader-main.doc-ap {
  /* One indent step, one measure, one rhythm — everything below derives
     from these four. --ap-measure caps the prose column short of the
     reader's right edge; print drops the cap because the 6.5in page box
     already supplies it. */
  --ap-measure: 860px;
  --ap-fs: 16px;
  --ap-lh: 1.72;
  --ap-step: 1.9em;
  --ap-ink: #262320;
  --ap-accent: #2F6315;
  --ap-accent-soft: #DCE9CE;
  --ap-rail: rgba(47, 99, 21, .18);

  font-size: var(--ap-fs);
  line-height: var(--ap-lh);
  color: var(--ap-ink);
  font-variant-numeric: tabular-nums;
  text-wrap: pretty;
}

/* ---------- Measure -----------------------------------------
   Prose, headings and clause lists stop at the printed text
   width. Tables, SVG diagrams and .wide-page content keep the
   full reader column (reader.css already governs those). */
.reader-main.doc-ap > :is(p, ol, ul, h1, h2, h3, h4, h5, h6, blockquote) {
  max-width: var(--ap-measure);
}

.reader-main.doc-ap > p { margin: 0 0 .95em; }

/* ---------- Section headings --------------------------------
   H1 is the AP's section marker (Background, Procedures,
   Definitions…). It gets the air that the run-together body
   was stealing, plus the hairline that ap.css intended. */
.reader-main.doc-ap > h1 {
  font-size: 1.28em;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.005em;
  color: var(--ap-accent);
  margin: 2.5em 0 .75em;
  padding-bottom: .3em;
  border-bottom: 1px solid var(--ap-accent-soft);
}
.reader-main.doc-ap > h1:first-of-type { margin-top: 0; }

.reader-main.doc-ap > h2 {
  font-size: 1.09em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ap-accent);
  margin: 1.9em 0 .5em;
  border-bottom: 0;
}

.reader-main.doc-ap > h3 {
  font-size: 1em;
  font-weight: 700;
  color: #3A362E;
  margin: 1.5em 0 .4em;
}

.reader-main.doc-ap > h4,
.reader-main.doc-ap > h5,
.reader-main.doc-ap > h6 {
  font-size: 1em;
  font-weight: 600;
  font-style: italic;
  color: #3A362E;
  margin: 1.3em 0 .35em;
}

/* ---------- Clause lists ------------------------------------
   The real density problem: 60-word clauses separated by 4px.
   Items get a full line of air and nested clause groups a
   deeper step. The design's hairline rail on nested groups was
   removed 2026-08-12 — it fragmented in places (e.g. a clause
   whose sub-list is followed by continuation paragraphs, and
   across print page breaks); to bring it back, re-add
   `border-left: 1px solid var(--ap-rail)` on the nested-group
   rule below and restore the --ap-rail print repoint. */
.reader-main.doc-ap :is(ol, ul) {
  margin: 0 0 1.15em;
  padding-left: var(--ap-step);
}

.reader-main.doc-ap li {
  margin: 0 0 .95em;
}
.reader-main.doc-ap li:last-child { margin-bottom: 0; }

/* Lead-in paragraph then sub-clauses, inside one <li>. */
.reader-main.doc-ap li > p { margin: 0 0 .55em; }
.reader-main.doc-ap li > p:last-child { margin-bottom: 0; }

/* Nested clause group: step in. */
.reader-main.doc-ap li > :is(ol, ul) {
  margin: .8em 0 .2em;
  padding-left: 1.55em;
}
.reader-main.doc-ap li > :is(ol, ul) > li { margin-bottom: .75em; }

/* Deepest level (bullets under a lettered clause). */
.reader-main.doc-ap li > :is(ol, ul) li > :is(ol, ul) {
  margin: .65em 0 .2em;
  padding-left: 1.6em;
}
.reader-main.doc-ap li > :is(ol, ul) li > :is(ol, ul) > li { margin-bottom: .5em; }

/* Marker kinds are set by RomanAlphaListExtension (ol.alpha-list /
   ol.roman-list) and by base.css; restated so a nested plain <ol>
   emitted natively by Markdig still steps a) rather than repeating 1). */
.reader-main.doc-ap ol.alpha-list { list-style-type: lower-alpha; }
.reader-main.doc-ap ol.roman-list { list-style-type: lower-roman; }
.reader-main.doc-ap li > :is(ol, ul) ul { list-style-type: circle; }

/* ---------- Tables ------------------------------------------
   Left as base.css owns them; only the body-copy size is
   re-pinned so a table doesn't jump against the new body size. */
.reader-main.doc-ap table { font-size: .92em; }

/* ---------- Reference lists ---------------------------------
   The Cross reference / Legal reference sections that close an
   AP are link indexes, not clauses — the clause rhythm (.95em of
   air per item) reads as gaps there, so those lists tighten to a
   directory rhythm. Matched via the stable S_* ids that
   HeadingAnchorExtension emits for the five heading variants in
   the corpus; the list is the heading's next sibling. The id
   selector outranks the print block's li rule, so references
   stay tight on paper too. */
.reader-main.doc-ap > :is(#S_cross_reference, #S_legal_reference,
    #S_legal_references, #S_references, #S_reference) + ul > li {
  margin-bottom: .35em;
}

/* ============================================================
   PRINT — Word parity. Same structure, print metrics.
   The screen measure IS the printed measure, so nothing
   re-flows unexpectedly; only the scale tightens to 11pt.
   ============================================================ */
@media print {
  .reader-main.doc-ap {
    --ap-fs: 11pt;
    --ap-lh: 1.5;
    --ap-measure: 100%;
    --ap-step: 1.75em;
    color: #1F1F1F;
  }

  .reader-main.doc-ap > h1 {
    font-size: 14pt;
    margin: 1.7em 0 .55em;
    break-after: avoid;
    page-break-after: avoid;
  }
  .reader-main.doc-ap > h1:first-of-type { margin-top: 0; }

  .reader-main.doc-ap > h2 {
    font-size: 12pt;
    margin: 1.35em 0 .4em;
    break-after: avoid;
    page-break-after: avoid;
  }
  .reader-main.doc-ap > h3 { font-size: 11pt; margin: 1.1em 0 .3em; }

  .reader-main.doc-ap > p { margin-bottom: .7em; }
  .reader-main.doc-ap li { margin-bottom: .55em; }
  .reader-main.doc-ap li > :is(ol, ul) { margin-top: .55em; }

  /* A heading must not be the last thing on a page. */
  .reader-main.doc-ap :is(h1, h2, h3) + :is(p, ol, ul) {
    break-before: avoid;
    page-break-before: avoid;
  }

  /* Deliberately NOT `li { break-inside: avoid }` — long clauses
     (AP-925 item 2b is 100+ words) would push half-empty pages.
     Matches the reasoning already recorded in reader-print.css. */
  .reader-main.doc-ap li { break-inside: auto; }

  .reader-main.doc-ap p, .reader-main.doc-ap li { orphans: 3; widows: 3; }
}
