/* af-pdf-viewer.css — the inline pdf.js viewer that assets/js/af-pdf-viewer.js builds from an
   [af_pdf view="inline"] card. Enqueued only on pages that printed one (inc/shortcodes.php), so
   af.css stays the same size. Uses af.css's tokens; the fallbacks are the theme's values.

   ONE frame (.af-pdf--viewer, a two-column grid):
     header  .af-pdf__body (the title; caption if any)  |  .af-pdfv__bar (download, print, open, full screen)
     body    .af-pdfv__stage: the page well (.af-pdfv__scroll), its loading line + message, and
             .af-pdfv__pill (‹ [n] / N › · − Fit +) floating at the bottom of the well.
   The card's facts line and Open / Download buttons (af.css §10) are hidden while the viewer
   shows the document, and come back without JS, on failure (.af-pdf--failed) and on paper. */

.af-pdf.af-pdf--viewer {
	--pv-primary: var(--af-primary, #65001f);
	--pv-accent: var(--af-accent, #9b053f);
	--pv-border: #e3d6c4;          /* the card's border */
	--pv-line: #ebe2d6;            /* header / well divider */
	--pv-well: #ece6de;
	--pv-ink: #66584e;             /* header icons: 6.6:1 on white */
	--pv-hover: #f6f0e8;
	--pv-pill: rgba(38, 7, 20, .9);
	--pv-h: min(78vh, 1100px);     /* the well: grows with the document up to this, then scrolls */
	--pv-gap: 16px;                /* around and between pages */
	--pv-pill-h: 44px;
	--pv-pill-off: 14px;           /* the pill's distance from the bottom of the well */
	display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
	gap: 0; margin: 0 0 28px; padding: 0;
	border: 1px solid var(--pv-border); border-radius: 6px; background: #fff;
	box-shadow: 0 1px 2px rgba(80, 40, 20, .05), 0 12px 28px -20px rgba(80, 40, 20, .35);
}
.af-pdf [hidden] { display: none !important; } /* the script hides parts with the hidden attribute */

/* Header: title left, document actions right. The title wraps to two lines, then clamps (the
   script then puts the full title in a tooltip). */
.af-pdf--viewer .af-pdf__body { min-width: 0; padding: 12px 12px 12px 20px; }
.af-pdf--viewer .af-pdf__title {
	display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
	overflow: hidden; overflow-wrap: anywhere;
}
.af-pdf--viewer .af-pdf__desc { margin-top: 2px; color: #5f554e; font-size: 13.5px; line-height: 1.45; }
.af-pdf--viewer .af-pdf__facts, .af-pdf--viewer .af-pdf__actions { display: none; }

.af-pdfv__bar { display: flex; align-items: center; gap: 2px; padding: 8px 10px 8px 0; }
.af-pdf .af-pdfv__btn {
	display: inline-flex; flex: none; align-items: center; justify-content: center;
	min-width: 40px; height: 40px; padding: 0 8px; border: 0; border-radius: 6px;
	background: transparent; color: var(--pv-ink); font: 500 14px/1 var(--af-font, Roboto, sans-serif);
	text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
	transition: background-color .15s, color .15s;
}
.af-pdf .af-pdfv__btn:hover { background: var(--pv-hover); color: var(--pv-primary); }
.af-pdf .af-pdfv__btn:active { background: #efe5d8; }
.af-pdf .af-pdfv__btn:focus-visible { outline: 2px solid var(--pv-accent); outline-offset: 1px; }
.af-pdf .af-pdfv__btn:disabled { opacity: .35; cursor: default; background: transparent; }
.af-pdfv__btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Body: the page well. */
.af-pdf--viewer .af-pdfv__stage {
	grid-column: 1 / -1; align-self: stretch; /* fills its row in full screen */
	position: relative; display: flex; flex-direction: column; min-width: 0;
	border-top: 1px solid var(--pv-line); border-radius: 0 0 5px 5px; background: var(--pv-well);
}
.af-pdfv__scroll {
	position: relative; max-height: var(--pv-h); overflow: auto; overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch; border-radius: inherit; outline: none;
}
.af-pdfv__scroll:focus-visible { outline: 2px solid var(--pv-accent); outline-offset: -2px; }
/* Before the document arrives the well already has its height, so nothing below it jumps. */
.af-pdf--idle .af-pdfv__scroll, .af-pdf--loading .af-pdfv__scroll, .af-pdfv__scroll--fill { height: var(--pv-h); }
/* The page column is as wide as the widest page, so a zoomed page scrolls to both edges; the
   bottom padding keeps the last page clear of the pill (the script reads these paddings). */
.af-pdfv__pages {
	display: flex; flex-direction: column; align-items: flex-start; width: max-content; min-width: 100%;
	padding: var(--pv-gap) var(--pv-gap) calc(var(--pv-gap) + var(--pv-pill-h) + var(--pv-pill-off));
}
.af-pdfv__pg {
	position: relative; flex: none; margin: 0 auto var(--pv-gap); background: #fff;
	box-shadow: 0 1px 2px rgba(60, 30, 15, .16), 0 6px 20px -6px rgba(60, 30, 15, .18);
	contain: strict; /* size is set inline; children never affect layout */
}
.af-pdfv__pg:last-child { margin-bottom: 0; }
.af-pdfv__pg canvas { display: block; opacity: 0; transition: opacity .25s; }
.af-pdfv__pg--ready canvas { opacity: 1; }

/* Loading: a thin line along the top of the well (indeterminate while pdf.js loads, then the
   download percentage) and a quiet message in the middle. */
.af-pdfv__progress { position: absolute; top: -1px; left: 0; right: 0; z-index: 3; height: 2px; overflow: hidden; opacity: 0; transition: opacity .4s; }
.af-pdf--loading .af-pdfv__progress { opacity: 1; }
.af-pdfv__progress::before {
	content: ""; position: absolute; inset: 0; width: var(--p, 0%);
	background: linear-gradient(90deg, var(--pv-primary), var(--pv-accent)); transition: width .2s;
}
.af-pdfv__progress--busy::before { width: 35%; animation: af-pdfv-slide 1.1s ease-in-out infinite alternate; }
@keyframes af-pdfv-slide { from { transform: translateX(-100%); } to { transform: translateX(285%); } }
.af-pdf--viewer .af-pdfv__status {
	position: absolute; inset: 0 0 auto; z-index: 1; display: flex; justify-content: center; gap: 8px;
	padding: 18vh 24px 0; color: var(--pv-ink); font: 400 14px/1.4 var(--af-font, Roboto, sans-serif);
	text-align: center; pointer-events: none;
}
.af-pdfv__pct { color: #8b7c71; font-variant-numeric: tabular-nums; }

/* The pill: page navigation and zoom, floating over the bottom of the well. Sticky, so while
   the well runs below the window it sits at the bottom of the window instead. Hidden (not
   removed) until the pages are there; one-page documents show only the zoom. */
.af-pdfv__pill {
	position: sticky; bottom: var(--pv-pill-off); z-index: 2; align-self: center;
	display: flex; align-items: center; gap: 2px; max-width: calc(100% - 16px); height: var(--pv-pill-h);
	margin: calc(-1 * (var(--pv-pill-h) + var(--pv-pill-off))) 0 var(--pv-pill-off); padding: 0 4px;
	border-radius: 999px; background: var(--pv-pill); color: #fff;
	box-shadow: 0 10px 26px -8px rgba(38, 7, 20, .55), 0 1px 4px rgba(38, 7, 20, .25);
	-webkit-backdrop-filter: blur(10px) saturate(1.2); backdrop-filter: blur(10px) saturate(1.2);
	transition: opacity .25s ease, transform .25s ease, visibility .25s;
}
.af-pdf--idle .af-pdfv__pill, .af-pdf--loading .af-pdfv__pill { visibility: hidden; opacity: 0; transform: translateY(6px); }
.af-pdfv__group { display: flex; align-items: center; gap: 2px; }
.af-pdfv__sep { flex: none; width: 1px; height: 20px; margin: 0 4px; background: rgba(255, 255, 255, .22); }
.af-pdfv__pill--single .af-pdfv__group--nav, .af-pdfv__pill--single .af-pdfv__sep { display: none; }
.af-pdf .af-pdfv__pill .af-pdfv__btn { min-width: 36px; height: 36px; padding: 0 6px; border-radius: 999px; color: #fff; }
.af-pdf .af-pdfv__pill .af-pdfv__btn:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.af-pdf .af-pdfv__pill .af-pdfv__btn:active { background: rgba(255, 255, 255, .22); }
.af-pdf .af-pdfv__pill .af-pdfv__btn:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.af-pdf .af-pdfv__pill .af-pdfv__btn:disabled { opacity: .35; background: transparent; }
.af-pdf .af-pdfv__pill .af-pdfv__zoom { min-width: 50px; font-size: 13px; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.af-pdfv__page {
	width: calc(var(--digits, 1) * 1ch + 24px); height: 28px; margin: 0 2px; padding: 0 4px;
	border: 1px solid rgba(255, 255, 255, .3); border-radius: 6px; background: rgba(255, 255, 255, .1);
	color: #fff; font: 500 14px/1 var(--af-font, Roboto, sans-serif); text-align: center; font-variant-numeric: tabular-nums;
}
.af-pdfv__page:hover { border-color: rgba(255, 255, 255, .55); }
.af-pdfv__page:focus { outline: 2px solid #fff; outline-offset: 1px; background: rgba(255, 255, 255, .18); }
.af-pdfv__count { margin: 0 4px 0 3px; color: rgba(255, 255, 255, .8); font: 400 14px/1 var(--af-font, Roboto, sans-serif); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Text layer: the subset of pdf.js's viewer.css that its TextLayer class needs (selection, find). */
.af-pdf .textLayer {
	position: absolute; inset: 0; overflow: clip; line-height: 1; opacity: 1; text-align: initial;
	letter-spacing: normal; word-spacing: normal; text-size-adjust: none; -webkit-text-size-adjust: none;
	forced-color-adjust: none; transform-origin: 0 0; z-index: 0; color-scheme: only light;
	--min-font-size: 1; --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size)); --min-font-size-inv: calc(1 / var(--min-font-size));
}
.af-pdf .textLayer :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0 0; user-select: text; -webkit-user-select: text; }
.af-pdf .textLayer > :not(.markedContent), .af-pdf .textLayer .markedContent span:not(.markedContent) {
	z-index: 1; --font-height: 0; font-size: calc(var(--text-scale-factor) * var(--font-height));
	--scale-x: 1; --rotate: 0deg; transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}
.af-pdf .textLayer .markedContent { display: contents; }
.af-pdf .textLayer ::selection { background: rgba(155, 5, 63, .25); }
.af-pdf .textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: 0; cursor: default; user-select: none; }
.af-pdf .textLayer.selecting .endOfContent { top: 0; }

/* Full screen: the whole frame (Fullscreen API), or a fixed overlay where that is missing (iPhone). */
.af-pdf.af-pdf--fs, .af-pdf.af-pdf--overlay {
	grid-template-rows: auto minmax(0, 1fr); width: 100%; height: 100%; margin: 0;
	border: 0; border-radius: 0; box-shadow: none;
}
.af-pdf.af-pdf--overlay { position: fixed; inset: 0; z-index: 100000; height: 100vh; height: 100dvh; }
.af-pdf--fs .af-pdfv__stage, .af-pdf--overlay .af-pdfv__stage { min-height: 0; border-radius: 0; }
.af-pdf--fs .af-pdfv__scroll, .af-pdf--overlay .af-pdfv__scroll { flex: 1 1 auto; min-height: 0; height: auto; max-height: none; }
.af-pdfv-lock, .af-pdfv-lock body { overflow: hidden; }

.af-pdfv__printstatus { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 14px; background: #fff; color: var(--pv-ink); border-bottom: 1px solid var(--pv-border); font-size: 14px; }
.af-pdfv__printstatus > span { flex: 1 1 240px; }
.af-pdfv__printstatus button, .af-pdfv__printstatus a { padding: 10px 12px; border: 1px solid var(--pv-border); border-radius: 4px; background: #fff; color: var(--pv-primary); font: inherit; cursor: pointer; }
.af-pdfv__printstatus :focus-visible, .af-pdfv__printstatus:focus-visible { outline: 2px solid var(--pv-accent); outline-offset: 2px; }
.af-pdfv__printframe { position: fixed; right: 0; bottom: 0; width: 1px; height: 1px; border: 0; opacity: 0; pointer-events: none; }

/* The file could not be shown: the card again (af.css), with the reason under it. */
.af-pdf--failed .af-pdfv__stage { flex: 1 1 100%; }
.af-pdf--failed .af-pdfv__status { padding: 10px 14px; border-radius: 3px; background: #faf4ec; color: #5a3b2c; font-size: 14px; line-height: 1.5; }

/* Phones: a smaller header, the title may take three lines, a taller well, tighter gaps. */
@media (max-width: 600px) {
	.af-pdf.af-pdf--viewer { --pv-h: 72vh; --pv-gap: 10px; }
	.af-pdf--viewer .af-pdf__body { padding: 10px 4px 10px 14px; }
	.af-pdf--viewer .af-pdf__title { font-size: 15px; -webkit-line-clamp: 3; line-clamp: 3; }
	.af-pdf--viewer .af-pdf__desc { font-size: 13px; }
	.af-pdfv__bar { gap: 0; padding: 6px 6px 6px 0; }
	.af-pdf--viewer .af-pdfv__status { padding-top: 14vh; }
}
@supports (height: 1svh) {
	@media (max-width: 600px) { .af-pdf.af-pdf--viewer { --pv-h: 72svh; } } /* the well fits with the browser bars showing */
}
/* Touch screens: bigger targets in the pill; PDF printing uses the same document layout. */
@media (hover: none) and (pointer: coarse) {
	.af-pdf.af-pdf--viewer { --pv-pill-h: 48px; }
	.af-pdf .af-pdfv__pill .af-pdfv__btn { min-width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: no-preference) { .af-pdfv__scroll { scroll-behavior: smooth; } }
@media (prefers-reduced-motion: reduce) {
	.af-pdf .af-pdfv__btn, .af-pdfv__pg canvas, .af-pdfv__pill, .af-pdfv__progress, .af-pdfv__progress::before { transition: none; }
	.af-pdfv__progress--busy::before { animation: none; width: 100%; opacity: .5; }
}
@media (forced-colors: active) { .af-pdfv__pill { border: 1px solid CanvasText; } }

/* On paper: one plain box with the title and the facts (the card, without buttons). Print in
   the header prepares a separate document-only print frame. */
@media print {
	.af-pdf.af-pdf--viewer, .af-pdf.af-pdf--overlay {
		display: block; position: static; height: auto; margin: 0 0 20px; padding: 12px 16px;
		border: 1px solid #999; border-radius: 0; box-shadow: none; break-inside: avoid;
	}
	.af-pdf--viewer .af-pdfv__bar, .af-pdf--viewer .af-pdfv__stage, .af-pdf--viewer .af-pdf__actions { display: none !important; }
	.af-pdf--viewer .af-pdf__body { padding: 0; }
	.af-pdf--viewer .af-pdf__title { display: block; overflow: visible; -webkit-line-clamp: unset; line-clamp: none; }
	.af-pdf--viewer .af-pdf__facts { display: block; }
	.af-pdfv-lock, .af-pdfv-lock body { overflow: visible; }
}
