/* alfviewer.css
   Core viewer styles and defensive overrides for PDF canvas layout.
   Place this at /pdfjs/alfviewer/alfviewer.css

   - Consolidates layout, controls, and debug overlay styles moved from flat.shtml
   - Defensive rules to override injected UI (Google Translate) and inline styles
   - DPR / responsive friendly: canvas scales to wrapper width
*/

/* -------------------- Layout: viewer blocks -------------------- */
.pdf-viewer-block {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 0;
  position: relative; /* anchors floating controls */
}

/* Viewer container and page wrapper */
#viewerContainer,
#pageWrapper {
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  overflow: visible !important;
  min-width: 0 !important;
}

/* Use flex to align the canvas; desktop centers, mobile aligns end for narrow UIs */
#pageWrapper {
  display: flex !important;
  justify-content: flex-end !important;
  align-items: center !important;
  padding: 0 8px !important;
}

/* Desktop: center pages; mobile keep responsive behavior */
@media (min-width: 900px) {
  #pageWrapper {
    justify-content: center !important; /* center pages on desktop */
  }
}

/* Reflow helper used by JS to trigger a harmless layout recalculation */
#pageWrapper.alf-reflow {
  transform: translateZ(0);
}

/* Vertical centering helper toggled by renderer when page is short */
#pageWrapper.vcenter {
  align-items: center !important;
  justify-content: center !important;
}

/* -------------------- Canvas rules -------------------- */
/* Default canvas behavior (responsive and DPR-friendly) */
#pdf-canvas {
  display: block !important;
  max-width: 100% !important;
  width: auto !important;
  height: auto !important;
  box-sizing: border-box !important;
  margin: 0 !important;
  vertical-align: middle;
}

/* Safety net: ensure canvas fills wrapper width when needed */
#pdf-canvas {
  width: 100% !important;
  height: auto !important;
  max-width: 100% !important;
}

/* If PDF.js wraps pages in .page elements */
#viewerContainer .page,
#pageWrapper .page {
  margin: 0 auto;
  display: block;
  box-sizing: border-box;
}

/* -------------------- Controls and indicators -------------------- */
/* Floating buttons styling (kept minimal and defensive) */
.floatBtn {
  position: absolute;
  right: 12px;
  top: 12px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: 0;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  z-index: 1000;
  line-height: 1;
}

/* If multiple float buttons exist, stack them vertically with small gap */
.floatBtn + .floatBtn {
  top: 48px; /* second button sits below the first */
}

/* Page indicator */
#pageIndicator {
  margin-top: 8px;
  font-size: 13px;
  color: #333;
  text-align: center;
}

/* Hero spacing */
.hero-card { margin-bottom: 15px; margin-top: 0; }

/* -------------------- Debug overlay (moved from flat.shtml) --------------------
   This overlay is visible only when ALF_VIEWER_CONFIG.debug is true or ?debug is set.
   Kept here so debug styling is versioned with the viewer.
-------------------------------------------------------------------------- */
#alfDebugOverlay {
  position: fixed;
  right: 12px;
  top: 12px;
  width: 320px;
  max-height: 60vh;
  overflow: auto;
  background: rgba(0,0,0,0.78);
  color: #e6f0ff;
  font: 12px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, Arial;
  padding: 10px;
  border-radius: 8px;
  z-index: 99999;
  display: none; /* toggled by JS when debug enabled */
}

/* Small helpers used by the debug overlay buttons */
#dbgRefreshBtn, #dbgHideBtn {
  width: 100%;
  border: 0;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: #fff;
}
#dbgRefreshBtn { background: #1f6feb; margin-top: 8px; }
#dbgHideBtn { background: #444; margin-top: 6px; }

/* -------------------- Defensive overrides --------------------
   These rules are intentionally scoped to viewer selectors and use !important
   only where necessary to override inline styles injected by third-party scripts.
-------------------------------------------------------------------------- */

/* Prevent Google Translate banner/spinner from visually affecting layout.
   This is a defensive rule; remove if you rely on the Google Translate banner.
*/
[class^="VIpgJd"],
[class*=" VIpgJd"],
.goog-te-banner-frame,
iframe.goog-te-banner-frame,
.goog-te-spinner,
.skiptranslate,
[data-alf-hidden="true"] {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  height: 0 !important;
  width: 0 !important;
  pointer-events: none !important;
  z-index: -99999 !important;
  overflow: hidden !important;
}

/* Final override to guarantee layout behavior for viewer elements */
#viewerContainer, #pageWrapper, .pdf-viewer-block {
  overflow: visible !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}

/* -------------------- Accessibility and small tweaks -------------------- */
/* Ensure focus outlines remain visible for keyboard users */
.floatBtn:focus, #pageIndicator:focus {
  outline: 2px solid rgba(31,111,235,0.9);
  outline-offset: 2px;
}

/* Reduce motion for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  #pageWrapper.alf-reflow { transform: none; transition: none !important; }
}
/* Small floating in-viewer debug status (inside the viewer) */
#debugOverlay {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0,0,0,0.72);
  color: #e6f0ff;
  font: 12px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, Arial;
  padding: 6px 8px;
  border-radius: 6px;
  z-index: 2000;
  display: none;               /* hidden by default */
  pointer-events: none;        /* non-interactive */
  white-space: nowrap;
}

/* Visible state for the small in-viewer debug status */
#debugOverlay.visible {
  display: block;
}

/* Keep the big overlay separate (already in CSS) but ensure it doesn't overlap viewer controls */
#alfDebugOverlay { z-index: 99999; }

/* Ensure float buttons remain above the small debug status if needed */
.floatBtn { z-index: 3000; }

/* End of alfviewer.css */
