/* PDF viewer widget (common\widgets\PdfViewer, js/pdf-viewer.js). */

html.pdf-viewer-open,
html.pdf-viewer-open body {
  overflow: hidden;
}

.pdf-viewer {
  /* holds the loading message (js/pdf-viewer.js); fixed instead while full screen */
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid #d5dceb;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.pdf-viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  padding: 4px 6px 4px 12px;
  border-bottom: 1px solid #d5dceb;
  background: #f6f8fb;
}

.pdf-viewer-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #1d2f49;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
}

.pdf-viewer-toggle {
  --pv-accent: var(--clr-primary, #245f8f);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  margin-left: auto;
  padding: 4px 12px;
  border: 1px solid var(--pv-accent);
  border-radius: 6px;
  background: #fff;
  color: var(--pv-accent);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.pdf-viewer-toggle .fa {
  font-size: 13px;
}

/* filled while the viewer covers the page: it is then the way back */
.pdf-viewer-toggle:hover,
.pdf-viewer-toggle:focus-visible,
.pdf-viewer.is-expanded .pdf-viewer-toggle {
  background: var(--pv-accent);
  color: #fff;
}

.pdf-viewer-toggle:focus-visible {
  outline: 2px solid #6db3ff;
  outline-offset: 1px;
}

.pdf-viewer > iframe {
  display: block;
}

/* the viewer opens in the system's colours (black in dark mode) until js/pdf-viewer.js turns
   it light: it is kept out of sight until then, so it never shows dark first. Should the script
   not run, it shows after a few seconds all the same. */
iframe[name^="pdfjs-iframe-"]:not(.pv-light),
iframe[name^="fp-frame-"]:not(.pv-light) {
  visibility: hidden;
  animation: pdf-viewer-reveal 0s 6s forwards;
}

/* "Loading document..." over the whole viewer, toolbar too, until its first page is drawn
   (js/pdf-viewer.js): one wait, then the finished viewer */
.pv-loading {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* near the top: a tall viewer's middle can be below the screen */
  justify-content: flex-start;
  padding-top: min(140px, 30%);
  gap: 10px;
  background: #f6f8fb;
  color: #475569;
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
}

.pv-loading.is-done {
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* the file did not open (js/pdf-viewer.js showError) */
.pv-loading.is-error {
  pointer-events: auto;
  padding-left: 16px;
  padding-right: 16px;
  text-align: center;
  color: #334155;
}

.pv-loading.is-error strong {
  color: #1d2f49;
  font-size: 15px;
}

.pv-error-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #fdecea;
  color: #b42318;
  font-weight: 700;
}

.pv-error-hint {
  max-width: 26rem;
  color: #64748b;
  font-size: 13px;
}

.pv-error-retry {
  margin-top: 4px;
  padding: 6px 16px;
  border: 1px solid var(--clr-primary, #245f8f);
  border-radius: 6px;
  background: #fff;
  color: var(--clr-primary, #245f8f);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.pv-error-retry:hover,
.pv-error-retry:focus-visible {
  background: var(--clr-primary, #245f8f);
  color: #fff;
}

.pv-loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #cbd5e1;
  border-top-color: var(--clr-primary, #2563eb);
  border-radius: 50%;
  animation: pdf-viewer-spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .pv-loading-spinner {
    animation-duration: 2.4s;
  }
}

/* while it covers the whole window the viewer has no room for the message */
.pdf-viewer.is-expanded .pv-loading {
  display: none;
}

@keyframes pdf-viewer-reveal {
  to {
    visibility: visible;
  }
}

/* the button goes into the viewer's own toolbar (js/pdf-viewer.js): the bar above stays only for a title */
.pdf-viewer > .pdf-viewer-bar:not(.has-title),
.pdf-viewer-toggle {
  display: none;
}

/* a viewer the script cannot reach keeps its button in the bar above it */
.pdf-viewer.no-frame-toggle > .pdf-viewer-bar {
  display: flex;
}

.pdf-viewer.no-frame-toggle .pdf-viewer-toggle {
  display: inline-flex;
}

/* drawn with the page (PdfViewer), over the viewer until the script places it; gives up with the
   script, should it not run */
.pdf-viewer > .pv-loading {
  inset: 0;
  animation: pdf-viewer-give-up 0s 30s forwards;
}

/* a message that the file did not open stays */
.pdf-viewer > .pv-loading.is-error {
  animation: none;
}

@keyframes pdf-viewer-give-up {
  to {
    visibility: hidden;
  }
}

.pdf-viewer.is-expanded {
  position: fixed;
  inset: 0;
  /* above the page's own bars and an open bootstrap modal (1055) */
  z-index: 1060;
  border: 0;
  border-radius: 0;
}

/* the height a view gave the viewer is set on the frame itself */
.pdf-viewer.is-expanded > iframe {
  flex: 1 1 auto;
  width: 100% !important;
  height: auto !important;
  min-height: 0;
}

@media (max-width: 575.98px) {
  .pdf-viewer-toggle-text {
    display: none;
  }
}

/* Beside a page's Print button while the copy is readied for the printer (js/pdf-viewer.js) */
.pdf-print-note {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.85rem;
  color: var(--ui-muted, #6c757d);
  vertical-align: middle;
}
.pdf-print-note[role="alert"] {
  color: var(--ui-danger, #b42318);
}
