/******************************************************************************/
/*                                                                            */
/* book.css - LaTeX book class for paged.js                                   */
/* =========================================                                  */
/*                                                                            */
/* This program is part of the Rexx Parser package                            */
/* [See https://rexx.epbcn.com/rexx-parser/]                                  */
/*                                                                            */
/* Copyright (c) 2024-2026 Josep Maria Blasco <josep.maria.blasco@epbcn.com>  */
/*                                                                            */
/* License: Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0)  */
/*                                                                            */
/* Load AFTER rexxpub-base.css.  Optional size variants:                      */
/*   book-<size>pt.css (load AFTER this file).                                */
/*                                                                            */
/* This is the most complete document class in RexxPub, designed for          */
/* long-form documents with chapters, parts, running headers, facing          */
/* pages, and a table of contents.                                            */
/*                                                                            */
/* Markdown structure:                                                        */
/*                                                                            */
/*   ::::: title-page          Title page (same convention as article)        */
/*   ::: {#toc}                Table of Contents placeholder (filled by       */
/*   :::                       createToc.js at render time)                   */
/*   h1 {.part}                Part divider (optional, centred, recto)        */
/*   h1 {.chapter}             Chapter (always starts on recto)               */
/*   h2, h3, h4                Section, subsection, subsubsection             */
/*                                                                            */
/* Page layout:                                                               */
/*   - DIN A4 portrait, facing pages (asymmetric margins)                     */
/*   - Inner margin wider for binding (3.5cm inner, 2.5cm outer)              */
/*   - Running headers: book title on verso, chapter on recto                 */
/*   - Page numbers: outer bottom corner                                      */
/*   - Chapters always start on recto (right-hand page)                       */
/*   - Part dividers: full page, centred, no headers/numbers                  */
/*                                                                            */
/* Requires: createToc.js (paged.js hook for TOC generation)                  */
/*                                                                            */
/* Version history:                                                           */
/*                                                                            */
/* Date     Version Details                                                   */
/* -------- ------- --------------------------------------------------------- */
/* 20260304    0.5  First version                                             */
/* 20260306         Refactored: common styles moved to rexxpub-base.css       */
/*                                                                            */
/******************************************************************************/

/******************************************************************************/
/******************************************************************************/
/* Book content                                                               */
/******************************************************************************/
/******************************************************************************/

div.content {
  font-family: "Times New Roman", Times, serif;
  font-size: var(--doc-font-size);
  line-height: var(--doc-line-height);
  text-align: justify;
  text-align-last: left;
  hyphens: auto;
  widows: 2;
  orphans: 2;
}

/******************************************************************************/
/* Running headers — captured via string-set, displayed in @page margins      */
/* The book title is captured from the title-page h1.                         */
/* The chapter title is captured from each h1.chapter.                        */
/******************************************************************************/

.title-page .book-title {
  string-set: bookTitle content(text);
}

.title-page h1.book-title {
  margin-bottom: 0 !important;
}

h1.chapter {
  string-set: chapterTitle content(text);
}

/******************************************************************************/
/* Paragraphs — LaTeX convention: first-line indent, no vertical space        */
/******************************************************************************/

div.content p {
  margin: 0;
  text-indent: 1.5em;
}

div.content h1 + p, div.content h2 + p,
div.content h3 + p, div.content h4 + p {
  text-indent: 0 !important;
}

div.content header + p { text-indent: 0; }

div.content blockquote + p { text-indent: 0; }

div.content pre + p { text-indent: 0; }

div.content [class*="highlight-rexx-"] + p {
  text-indent: 0;
}

div.content table + p { text-indent: 0; }
div.content figure + p { text-indent: 0; }

div.content .noindent p { text-indent: 0; }

div.content li p { text-indent: 0; }
div.content dd p { text-indent: 0; }

/******************************************************************************/
/* Title page                                                                 */
/* Same ::::: title-page structure as article.                                */
/******************************************************************************/

.title-page {
  text-align: center;
  text-align-last: center;
}

.title-page h1 {
  font-size: 2em;
  font-weight: normal;
  margin-top: 3em;
  margin-bottom: 0.3em;
  break-after: auto;
}

.title-page h1 small {
  display: block;
  font-size: 0.75em;
  margin-top: 0.5em;
  font-weight: normal;
  color: inherit;
}

.title-page .author       { font-size: 1.2em; margin-top: 2em; }
.title-page .author a     { color: inherit; text-decoration: none; }
.title-page .affiliation  { font-size: 1em;  font-style: italic; margin-top: 0.3em; }
.title-page .address      { font-size: 0.9em; margin-top: 0.2em; }
.title-page .email        { font-size: 0.9em; font-family: monospace; margin-top: 0.3em; }
.title-page .phone        { font-size: 0.9em; font-style: italic; margin-top: 0.1em; }
.title-page .date         { font-size: 1em;  margin-top: 2em; }

div.content .title-page p { text-indent: 0; text-align: center; text-align-last: center; }

/******************************************************************************/
/* Table of contents                                                          */
/* The #toc div is populated by createToc.js before paged.js renders.         */
/******************************************************************************/

#toc {
  page: toc-page;
  break-before: recto;
}

#toc .toc-nav {
  font-family: "Times New Roman", Times, serif;
  font-size: var(--doc-font-size);
  line-height: 1.8;
}

.toc-entry {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.toc-entry a {
  color: inherit;
  text-decoration: none;
  flex: 1;
  overflow: hidden;
}

/* Dot leaders between title and page number                                  */
.toc-entry a::after {
  content: target-counter(attr(href url), page);
  float: right;
  font-variant-numeric: tabular-nums;
}

.toc-entry.toc-level-1 {
  font-weight: bold;
  margin-top: 0.4em;
}

.toc-entry.toc-level-2 {
  font-weight: normal;
  padding-left: 1.5em;
}

.toc-entry.toc-level-3 {
  padding-left: 3em;
  font-weight: normal;
  font-size: 0.95em;
}

#toc h2 {
  font-size: 1.8em;
  font-weight: bold;
  margin-top: 3em;
  margin-bottom: 1em;
  text-align: left;
}

.toc-entry.toc-part {
  font-size: 1.15em;
  font-weight: bold;
  margin-top: 0.8em;
  text-transform: uppercase;
}

.toc-entry.toc-chapter {
  font-weight: bold;
  margin-top: 0.6em;
}

/******************************************************************************/
/* Part divider                                                               */
/* Full page, vertically centred, no running headers.                         */
/*                                                                            */
/* Emulates the LaTeX book.cls \part layout:                                  */
/*                                                                            */
/*   \null\vfil                          ← elastic space above                */
/*   \huge\bfseries  Part N              ← "Part I" in \huge bold             */
/*   \vskip 20pt                         ← 20pt gap                           */
/*   \Huge\bfseries  Title               ← title in \Huge bold                */
/*   \vfil\newpage                       ← elastic space below                */
/*                                                                            */
/* The \vfil…\vfil pair centres the block vertically on the page.             */
/* We approximate this with a large top margin (~40% of the text area).       */
/*                                                                            */
/* LaTeX font sizes at 12pt base:                                             */
/*   \huge  = 24.88pt    \Huge = 24.88pt (capped at \huge in 12pt)           */
/* At 10pt base:                                                              */
/*   \huge  = 20.74pt    \Huge = 24.88pt   (ratio ≈ 0.83)                   */
/*                                                                            */
/******************************************************************************/

h1.part {
  page: part-page;
  text-align: center;
  text-align-last: center;
  font-size: 2.4em;                    /* \Huge — title size                  */
  font-weight: bold;
  margin-top: 0;                       /* @page part-page handles position    */
  break-before: recto;
  page-break-before: recto;
}

h1.part .section-number {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 0.75em;                   /* \huge relative to \Huge ≈ 0.83     */
  font-weight: bold;                   /* LaTeX: \huge\bfseries               */
  margin-bottom: 0.7em;               /* \vskip 20pt                         */
}

h1.part .section-number-sep {
  display: none;                       /* Hidden on part page; TOC picks it   */
}                                      /* up via heading.textContent           */

/******************************************************************************/
/* Chapter heading                                                            */
/* Always starts on recto (right-hand page).  Prominent styling.              */
/******************************************************************************/

h1.chapter {
  break-before: recto;
  page-break-before: recto;
  font-size: 1.8em;
  font-weight: bold;
  margin-top: 3em;
  margin-bottom: 1em;
  padding-bottom: 0.3em;
  border-bottom: 1pt solid #333;
  string-set: chapterTitle content(text);
}

h1.chapter + p { text-indent: 0; }

/******************************************************************************/
/* h1 (generic, without .chapter or .part) — same as article h1              */
/******************************************************************************/

div.content h1 {
  font-size: 1.4em;
  font-weight: bold;
  line-height: 1.2;
  margin-top: 1.5em;
  margin-bottom: 0.6em;
  break-after: avoid;
  page-break-after: avoid;
}

/******************************************************************************/
/* h2 — section                                                               */
/******************************************************************************/

h2 {
  font-size: 1.2em;
  font-weight: bold;
  line-height: 1.2;
  margin-top: 1.2em;
  margin-bottom: 0.5em;
  break-after: avoid;
  page-break-after: avoid;
}

h1 + h2 { margin-top: 0; }

/******************************************************************************/
/* h3 — subsection                                                            */
/******************************************************************************/

h3 {
  font-size: 1em;
  font-weight: bold;
  line-height: 1.2;
  margin-top: 1em;
  margin-bottom: 0.4em;
  break-after: avoid;
  page-break-after: avoid;
}

h2 + h3 { margin-top: 0; }

/******************************************************************************/
/* h4 — paragraph                                                             */
/******************************************************************************/

h4 {
  font-size: 1em;
  font-weight: bold;
  font-style: italic;
  line-height: 1.2;
  margin-top: 0.8em;
  margin-bottom: 0.3em;
  break-after: avoid;
  page-break-after: avoid;
}

h3 + h4 { margin-top: 0; }

/******************************************************************************/
/* Tables — override base: smaller font, tighter padding                      */
/******************************************************************************/

div.content table {
  font-size: 0.95em;
}

div.content table th,
div.content table td {
  padding: 0.2em 0.5em;
}

/******************************************************************************/
/* Page break overrides                                                       */
/******************************************************************************/

@media print {
  h1.newpage, h1.chapter {
    margin-top: 3em;
  }
}

/******************************************************************************/
/******************************************************************************/
/* Pagination — Facing pages                                                  */
/******************************************************************************/
/******************************************************************************/

/* Default page: A4 portrait, asymmetric margins for binding                  */

@page {
  size: A4 portrait;
  margin-top: 2.5cm;
  margin-bottom: 2.5cm;
  margin-inside: 3.5cm;                /* Binding edge — wider                */
  margin-outside: 2.5cm;               /* Outer edge — narrower               */

  @bottom-center {
    content: none;
  }
}

/* Recto (right / odd) pages: page number bottom-right,                        */
/*                             chapter title top-right                         */

@page :right {

  @top-right {
    font-family: 'Times New Roman', Times, serif;
    content: string(chapterTitle, first-except);
    font-size: 11pt;
    font-style: italic;
    color: black;
  }

  @top-left {
    content: none;
  }

  @bottom-right {
    font-family: 'Times New Roman', Times, serif;
    content: counter(page);
    font-size: 12pt;
  }

  @bottom-left {
    content: none;
  }

}

/* Verso (left / even) pages: page number bottom-left,                        */
/*                              book title top-left                            */

@page :left {

  @top-left {
    font-family: 'Times New Roman', Times, serif;
    content: string(bookTitle);
    font-size: 11pt;
    font-style: italic;
    color: black;
  }

  @top-right {
    content: none;
  }

  @bottom-left {
    font-family: 'Times New Roman', Times, serif;
    content: counter(page);
    font-size: 12pt;
  }

  @bottom-right {
    content: none;
  }

}

/* Title page: no headers, no page number                                     */

@page title-page {
  @top-left    { content: none; }
  @top-right   { content: none; }
  @bottom-left { content: none; }
  @bottom-right{ content: none; }
}

/* TOC pages: no running chapter header                                       */

@page toc-page {
  @top-left  { content: none; }
  @top-right { content: none; }
}

/* Part divider: no headers, no page number, centred                          */
/* Extra top margin pushes content to vertical centre of the page             */

@page part-page {
  margin-top: 10cm;
  @top-left    { content: none; }
  @top-right   { content: none; }
  @bottom-left { content: none; }
  @bottom-right{ content: none; }
}

/* First page of each chapter: no running header (chapter title is visible)   */

@page:first {
  @top-left    { content: none; }
  @top-right   { content: none; }
  @bottom-left { content: none; }
  @bottom-right{ content: none; }
}

@page :blank {
  @top-left    { content: none; }
  @top-right   { content: none; }
  @bottom-left { content: none; }
  @bottom-right{ content: none; }
}