/* ==========================================================================
   ICSV PDF Flipbook - styles (partials/builder/inner/pdf_flipbook)
   Adapted from Aztec's Flipbook Kit. Themed via the custom properties on
   .flipbook below, which map to the site's Tailwind colour tokens.
   ========================================================================== */

.flipbook {
  --fb-stage: #192b4e;         /* blue-dark: surround the book sits on */
  --fb-accent: #2aa0d8;        /* blue-light: spinner, button hover    */
  --fb-control: #00305f;       /* blue: toolbar buttons                */
  --fb-paper: #ffffff;         /* page background, toolbar text        */
  --fb-font-body: "Open Sans", sans-serif;
  --fb-text-xs: 0.8125rem;
  --fb-text-sm: 0.9375rem;
}

.flipbook {
  width: 100%;
  position: relative;
}

/* PDF (StPageFlip) variant */
.flipbook--pdf {
  max-width: 72rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.flipbook__stage {
  position: relative;
  width: 100%;
  min-height: var(--flipbook-h, 700px);
  background:
    radial-gradient(ellipse at center top, rgba(42, 160, 216, 0.14), transparent 60%),
    var(--fb-stage);
  border-radius: 0.4rem;
  overflow: hidden;
  padding: 1.5rem 0.75rem;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (min-width: 768px) {
  .flipbook__stage { padding: 2rem 1.5rem; }
}

.flipbook__book {
  width: 100%;
  height: 100%;
  visibility: hidden;
  /* Cap the spread so it fits the viewport height. --fb-spread (two pages'
     width / height) is set by flipbook.js from the PDF. !important because
     StPageFlip writes its own inline max-width onto this element. */
  max-width: min(1200px, calc(var(--fb-spread, 1.4142) * min(76vh, 720px))) !important;
}

/* The min-height only reserves space while loading; afterwards the stage
   hugs the book, so a single portrait page on a phone isn't lost in padding. */
.flipbook--pdf.is-ready .flipbook__stage {
  min-height: 0;
}

.flipbook--pdf.is-ready .flipbook__book {
  visibility: visible;
}

/* Centre a lone cover. StPageFlip pins the front cover to the right half of
   the spread and a lone back cover to the left, which leaves a page-width of
   empty stage beside it. The book is exactly two pages wide, so 25% of it is
   half a page -- exactly the offset needed to bring a single cover back to the
   middle. Inner spreads fill the width and stay at zero. Driven by
   updateCoverOffset() in flipbook.js. */
.flipbook__book {
  transition: transform 0.4s ease;
}

.flipbook.is-cover-right .flipbook__book {
  transform: translateX(-25%);
}

.flipbook.is-cover-left .flipbook__book {
  transform: translateX(25%);
}

@media (prefers-reduced-motion: reduce) {
  .flipbook__book { transition: none; }
}

.flipbook__page {
  background: var(--fb-paper);
  overflow: hidden;
}

.flipbook__page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

/* Loader */
.flipbook__loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  color: rgba(255, 255, 255, 0.85);
  font-size: var(--fb-text-sm);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 400;
  font-family: var(--fb-font-body);
}

.flipbook__loader__status {
  font-size: var(--fb-text-xs);
  letter-spacing: 0.12em;
  opacity: 0.7;
  min-height: 1.2em;
}

/* Shown instead of the spinner when PDF.js / StPageFlip never load (filtered
   network, CDN outage) -- see showFailure() in flipbook.js. */
.flipbook__loader--failed {
  gap: 0.75rem;
  padding: 0 1.5rem;
  text-align: center;
  text-transform: none;
  letter-spacing: 0.02em;
}

.flipbook__fallback-link {
  color: var(--fb-paper);
  text-decoration: underline;
  text-underline-offset: 0.25em;
  font-weight: 600;
}

.flipbook__fallback-link:hover,
.flipbook__fallback-link:focus-visible {
  color: var(--fb-accent);
}

.flipbook__spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--fb-accent);
  border-radius: 50%;
  animation: flipbook-spin 0.9s linear infinite;
}

@keyframes flipbook-spin {
  to { transform: rotate(360deg); }
}

/* Toolbar */
.flipbook__toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.25rem 0;
}

.flipbook__btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--fb-control);
  color: var(--fb-paper);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: background 0.25s ease, transform 0.25s ease;
}

.flipbook__btn:hover:not(:disabled),
.flipbook__btn:focus-visible {
  background: var(--fb-accent);
  transform: translateY(-1px);
}

.flipbook__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.flipbook__btn--download {
  background: transparent;
  color: var(--fb-control);
  border: 1px solid var(--fb-control);
}

.flipbook__btn--download:hover,
.flipbook__btn--download:focus-visible {
  background: var(--fb-control);
  color: var(--fb-paper);
}

.flipbook__count {
  font-family: var(--fb-font-body);
  font-size: var(--fb-text-xs);
  font-weight: 500;
  letter-spacing: 0.18em;
  color: var(--fb-control);
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 4rem;
  justify-content: center;
}

.flipbook__count__sep { opacity: 0.4; }

.flipbook__toolbar__sep {
  width: 1px;
  height: 1.5rem;
  background: rgba(25, 43, 78, 0.2);
  margin: 0 0.4rem;
}

.flipbook__btn:focus-visible {
  outline: 2px solid var(--fb-accent);
  outline-offset: 2px;
}

/* Fullscreen icons swap */
.flipbook__icon-collapse { display: none; }
.flipbook.is-fullscreen .flipbook__icon-expand { display: none; }
.flipbook.is-fullscreen .flipbook__icon-collapse { display: block; }

/* Fullscreen layout. Flattened out of native CSS nesting so the kit works in
   older browsers too. :is() parses forgivingly, so a browser that doesn't know
   :fullscreen simply ignores that half rather than dropping the whole rule. */
.flipbook:fullscreen,
.flipbook.is-fullscreen {
  background: var(--fb-stage);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

:is(.flipbook:fullscreen, .flipbook.is-fullscreen) .flipbook__stage {
  flex: 1;
  min-height: 0;
  border-radius: 0;
}

:is(.flipbook:fullscreen, .flipbook.is-fullscreen) .flipbook__book {
  max-width: calc(var(--fb-spread, 1.4142) * (100vh - 10rem)) !important;
}

:is(.flipbook:fullscreen, .flipbook.is-fullscreen) .flipbook__toolbar {
  background: rgba(0, 0, 0, 0.35);
  padding: 0.75rem;
  border-radius: 999px;
  align-self: center;
}

:is(.flipbook:fullscreen, .flipbook.is-fullscreen) .flipbook__count {
  color: var(--fb-paper);
}

:is(.flipbook:fullscreen, .flipbook.is-fullscreen) .flipbook__btn--download {
  color: var(--fb-paper);
  border-color: rgba(255, 255, 255, 0.4);
}

:is(.flipbook:fullscreen, .flipbook.is-fullscreen) .flipbook__btn--download:hover,
.flipbook__btn--download:focus-visible {
  background: var(--fb-paper);
  color: var(--fb-stage);
}

:is(.flipbook:fullscreen, .flipbook.is-fullscreen) .flipbook__toolbar__sep {
  background: rgba(255, 255, 255, 0.25);
}

/* ==========================================================================
   Standalone page (/flipbook/<file>) - the whole viewport is the book, so a
   document can be linked to directly without going via the page it sits on.
   ========================================================================== */

.flipbook-standalone {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #f0f1f8;
  font-family: "Open Sans", sans-serif;
  color: #192b4e;
}

.flipbook-standalone__bar {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.75rem 1.25rem;
  background: #ffffff;
  border-bottom: 1px solid rgba(25, 43, 78, 0.12);
}

.flipbook-standalone__brand {
  display: block;
  flex: none;
  line-height: 0;
}

.flipbook-standalone__brand img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.flipbook-standalone__title {
  font-family: "Lora", serif;
  font-weight: 700;
  font-size: clamp(1rem, 2.5vw, 1.375rem);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flipbook--standalone {
  flex: 1;
  min-height: 0;
  max-width: none;
  padding: 1rem 1rem 1.25rem;
  box-sizing: border-box;
}

.flipbook--standalone .flipbook__stage {
  flex: 1;
  min-height: 0;
}

/* Bar + toolbar + padding measure ~15rem at this font size; the rest is the
   book, so the whole viewer fits the viewport with no page scroll. */
.flipbook--standalone .flipbook__book {
  max-width: min(100%, calc(var(--fb-spread, 1.4142) * (100dvh - 15rem))) !important;
}
