/* Landing page polish for sphinx-book-theme */
.bd-main .bd-content .bd-article-container h1 {
  letter-spacing: -0.01em;
}

.sd-btn {
  border-radius: 999px;
  font-weight: 600;
}

.bd-footer-content p.component-author {
  display: none;
}

.navbar-brand .title.logo__title {
  display: none;
}

.bd-sidebar-primary .navbar-brand.logo {
  display: block;
  text-align: center;
}

.bd-sidebar-primary .navbar-brand.logo img.logo__image {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: none;
  height: auto;
  margin: 0 auto;
}

.article-header-buttons .btn-source-made-with-github {
  background: transparent;
  border: 0;
  box-shadow: none;
  color: inherit;
  cursor: default;
  padding: 0;
  pointer-events: none;
}

.landing-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1.25rem;
  padding: 2rem 0 1rem;
}

.landing-page img {
  width: min(100%, 1000px);
  height: auto;
}

.landing-page__image {
  width: min(100%, 1000px);
  height: auto;
}

.landing-page__title {
  margin: 0;
  font-size: clamp(1.6rem, 2vw + 1rem, 2.6rem);
  font-weight: 700;
  line-height: 1.2;
}

/* SimplePDF: use landing image as a clean front cover */
#cover .cover-footer {
  display: none;
}

#cover {
  background-position: center 200px;
  background-repeat: no-repeat;
  /* A4 width is ~794px at CSS 96dpi; 80% ~= 635px */
  background-size: 635px auto;
}

@page:first {
  /* Prevent double-rendering of cover image (page + #cover) */
  background: none !important;
}

/* SimplePDF: title and author under cover image */
#cover .container {
  position: relative;
  height: 100%;
  background: transparent;
}

/* SimplePDF: place NMBU logo at bottom center of front cover */
#cover .container .logo {
  position: absolute;
  top: auto !important;
  left: 50% !important;
  right: auto !important;
  bottom: 100pt;
  transform: translateX(-50%) !important;
  width: 180pt;
  max-width: 42%;
  height: auto;
  z-index: 6;
}

#cover .container .logo img {
  display: block;
  width: 100%;
  height: auto;
}

#cover .container .logo p {
  display: none;
}

#cover .container .cover-middle {
  position: absolute;
  top: auto !important;
  bottom: 320px !important;
  left: 0 !important;
  right: 0 !important;
  width: 100%;
  z-index: 5;
  text-align: center !important;
}

#cover .container .cover-middle .title {
  position: static !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  height: auto;
  margin: 0 auto !important;
  text-align: center !important;
  display: inline-block;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 8px;
}

#cover .container .cover-middle .title .title-cover {
  margin: 0;
  text-align: center !important;
  white-space: pre-line;
  color: #000000 !important;
  font-size: 24pt;
}

#cover .container .cover-middle .title .subtitle-cover {
  display: none;
}

#cover .container .cover-middle .title .meta {
  display: block;
  margin-top: 8pt;
  text-align: center !important;
  color: #000000 !important;
  font-size: 14pt;
}

/* SimplePDF: remove logo on TOC page */
.sphinxsidebarwrapper p.logo {
  display: none;
}

/* SimplePDF: back cover should be NMBU green, not front image */
@page back_cover {
  background: #008571 !important;
  color: #ffffff;
}

#back-cover {
  background: #008571 !important;
}

#back-cover .back-cover-footer,
#back-cover .back-cover-footer p,
#back-cover .back-cover-footer a {
  color: #ffffff !important;
}

/* SimplePDF: hide the built-in Sphinx line on back cover */
#back-cover .back-cover-footer p:nth-of-type(2) {
  display: none;
}

/* SimplePDF: hide only landing header/hero in body, keep chapter content */
.sphinxsidebar ~ .document #forside > h1,
.sphinxsidebar ~ .document #forside > .landing-page {
  display: none;
}

/* Additional PDF-only safety selector for hiding duplicated landing figure */
.document #forside > h1,
.document #forside > .landing-page {
  display: none !important;
}

/* SimplePDF: avoid blank page before first chapter (Forord) */
.sphinxsidebar ~ .document .toctree-wrapper > section:first-of-type > h2 {
  break-before: auto !important;
  page-break-before: auto !important;
}

/* SimplePDF: chapter headings start new page without forcing extra blank pages */
.sphinxsidebar ~ .document .toctree-wrapper > section > h2 {
  break-before: page !important;
  page-break-before: always !important;
}

/* Keep first chapter directly after TOC/front matter */
.sphinxsidebar ~ .document .toctree-wrapper > section:first-of-type > h2 {
  break-before: auto !important;
  page-break-before: auto !important;
}

/* Hard override for simplepdf theme default (html body h2 page-break-before: always). */
html body h2 {
  break-before: page !important;
  page-break-before: always !important;
}

/* Keep figure image and caption together in PDF pagination */
figure,
figure > figcaption {
  break-inside: avoid;
  page-break-inside: avoid;
}

/* Keep table and caption together in PDF pagination */
table,
table > caption {
  break-inside: avoid;
  page-break-inside: avoid;
}

/* Citation refs in PDF can be unresolved; render them as plain text */
a.reference.internal[href*="litteraturliste#"],
a.reference.internal[href*="document-14-litteraturliste#"],
a.reference.internal[href*="references#"],
a.reference.internal[href*="document-references#"] {
  color: #000000 !important;
  text-decoration: none !important;
}

/* SimplePDF math layout */
.sphinxsidebar ~ .document .body div.math {
  margin: 0 0 0.65em;
}

.sphinxsidebar ~ .document .body p + div.math {
  margin-top: -0.35em;
}

.sphinxsidebar ~ .document .body div.math p {
  position: relative;
  margin: 0;
  padding: 0 4.5rem;
  text-align: center;
}

.sphinxsidebar ~ .document .body div.math span.eqno {
  float: none;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: auto;
  margin: 0;
  white-space: nowrap;
}

.sphinxsidebar ~ .document .body div.math span.eqno a.headerlink {
  position: static;
}

.sphinxsidebar ~ .document .body div.math p > img {
  display: inline-block;
  vertical-align: middle;
  width: auto !important;
  max-width: none !important;
  height: 1.2em;
}

.sphinxsidebar ~ .document .body div.math p > img[alt*="overbrace"],
.sphinxsidebar ~ .document .body div.math p > img[alt*="frac"] {
  height: 2.4em;
}

.sphinxsidebar ~ .document .body span.math img.math,
.sphinxsidebar ~ .document .body p img.math {
  width: auto !important;
  max-width: none !important;
  height: 1em;
  vertical-align: -0.15em;
}

/* SimplePDF: compact table spacing and slightly smaller table text */
.sphinxsidebar ~ .document .body table.docutils {
  border-collapse: collapse;
  border-spacing: 0;
  font-size: 0.92em;
}

.sphinxsidebar ~ .document .body table.docutils td,
.sphinxsidebar ~ .document .body table.docutils th {
  padding: 0.2rem 0.4rem;
  line-height: 1.2;
  vertical-align: middle;
  text-align: left !important;
}

.sphinxsidebar ~ .document .body table.docutils td p,
.sphinxsidebar ~ .document .body table.docutils th p {
  margin: 0;
  text-align: left !important;
}

.sphinxsidebar ~ .document .body table.docutils td ul,
.sphinxsidebar ~ .document .body table.docutils td ol,
.sphinxsidebar ~ .document .body table.docutils td li,
.sphinxsidebar ~ .document .body table.docutils th ul,
.sphinxsidebar ~ .document .body table.docutils th ol,
.sphinxsidebar ~ .document .body table.docutils th li {
  text-align: left !important;
}

.tight-table table,
.tight-table td,
.tight-table th {
  border: none !important;
}

.tight-table table {
  box-shadow: none !important;
}

.tight-table td,
.tight-table th {
  padding: 0.1rem 0.6rem 0.1rem 0 !important;
}
