/* EPUB Stylesheet for MAIDR */
/* Ensures consistent figure alignment across EPUB readers */

/* Reset and base styles */
body {
  margin: 1em;
  padding: 0;
  line-height: 1.6;
}

/* Force block-level display for figures */
figure, .figure, div.figure {
  display: block !important;
  width: 100% !important;
  margin: 1.5em auto !important;
  padding: 0 !important;
  text-align: center !important;
  page-break-inside: avoid;
}

/* Center images within figures */
figure img, .figure img, div.figure img,
p img, img {
  display: block !important;
  margin: 0 auto !important;
  max-width: 100% !important;
  height: auto !important;
}

/* Figure captions */
figcaption, .caption, p.caption {
  display: block !important;
  text-align: center !important;
  font-style: italic;
  margin-top: 0.5em;
  font-size: 0.9em;
}

/* Code blocks - prevent side-by-side layout */
pre, code {
  display: block !important;
  width: 100% !important;
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 1em 0 !important;
  padding: 0.5em;
  background-color: #f5f5f5;
  font-size: 0.85em;
}

/* Inline code */
code:not(pre code) {
  display: inline !important;
  width: auto !important;
  margin: 0 !important;
  padding: 0.1em 0.3em;
}

/* Ensure paragraphs containing images are block-level */
p:has(img) {
  display: block !important;
  width: 100% !important;
  text-align: center !important;
  margin: 1.5em 0 !important;
}

/* Tables */
table {
  width: 100%;
  margin: 1em auto;
  border-collapse: collapse;
}

th, td {
  padding: 0.5em;
  border: 1px solid #ddd;
  text-align: left;
}

th {
  background-color: #f0f0f0;
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
  page-break-after: avoid;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

/* Horizontal rules - clear any floats */
hr {
  clear: both !important;
  margin: 2em 0;
  border: none;
  border-top: 1px solid #ccc;
}

/* Prevent floating elements */
* {
  float: none !important;
}

/* Source code chunks from knitr */
div.sourceCode, pre.sourceCode {
  display: block !important;
  width: 100% !important;
  margin: 1em 0 !important;
  clear: both !important;
}
