/**
 * Hibot PDF — in-site viewer.
 *
 * Theme colors: navy #37414F (header), orange #FF521C (accent). Text and
 * icons use a darker orange (#C93A0C) to reach WCAG AA contrast.
 * The theme's reset gives every element a viewport-based font-size, so the
 * toolbar sets its own sizes in px.
 */

:root {
	/* Real value measured from the theme header by viewer.js. */
	--hibot-pdf-offset: 70px;
}

.hibot-pdf-page {
	padding-top: var(--hibot-pdf-offset);
	background: #e8eaed;
}

.hibot-pdf {
	--hibot-pdf-navy: #37414f;
	--hibot-pdf-orange: #ff521c;
	--hibot-pdf-orange-text: #c93a0c;
	--hibot-pdf-line: #d5d9df;
	--hibot-pdf-hover: #eef0f3;
	--hibot-pdf-stage: #e8eaed;

	position: relative;
	display: flex;
	flex-direction: column;
	/* The WordPress admin bar (logged-in users) takes room too. */
	height: calc(100vh - var(--hibot-pdf-offset) - var(--wp-admin--admin-bar--height, 0px));
	height: calc(100svh - var(--hibot-pdf-offset) - var(--wp-admin--admin-bar--height, 0px));
	min-height: 420px;
	background: var(--hibot-pdf-stage);
	color: var(--hibot-pdf-navy);
	font-size: 14px;
	line-height: 1.4;
}

.hibot-pdf__bar,
.hibot-pdf__bar :is(div, span, p, a, button, label, input, select, option, h1),
.hibot-pdf__status,
.hibot-pdf__status :is(div, span, p, a) {
	font-size: inherit;
	line-height: inherit;
}

.hibot-pdf__sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

/* Toolbar ------------------------------------------------------------- */

.hibot-pdf__bar {
	position: relative;
	z-index: 2;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 16px;
	padding: 8px 24px;
	background: #fff;
	border-bottom: 1px solid var(--hibot-pdf-line);
	box-shadow: 0 1px 4px rgb(0 0 0 / 0.06);
}

.hibot-pdf__title {
	flex: 1 1 200px;
	min-width: 0;
	margin: 0;
	overflow: hidden;
	font-size: 16px !important;
	font-weight: 700;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.hibot-pdf__controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 4px 12px;
}

.hibot-pdf__group {
	display: flex;
	align-items: center;
	gap: 2px;
}

.hibot-pdf__group + .hibot-pdf__group {
	padding-left: 12px;
	border-left: 1px solid var(--hibot-pdf-line);
}

.hibot-pdf__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	padding: 0;
	border: 0;
	border-radius: 6px;
	background: transparent;
	color: var(--hibot-pdf-navy);
	cursor: pointer;
	transition: background-color 0.15s, color 0.15s;
}

.hibot-pdf__btn[hidden] {
	display: none;
}

.hibot-pdf__btn:hover:not(:disabled),
.hibot-pdf__btn.is-active,
.hibot-pdf__btn[aria-expanded="true"] {
	background: var(--hibot-pdf-hover);
	color: var(--hibot-pdf-orange-text);
}

.hibot-pdf__btn:disabled {
	opacity: 0.35;
	cursor: default;
}

.hibot-pdf__btn:focus-visible,
.hibot-pdf__page-input:focus-visible,
.hibot-pdf__scale:focus-visible,
.hibot-pdf__find-input:focus-visible,
.hibot-pdf__container:focus-visible {
	outline: 2px solid var(--hibot-pdf-orange);
	outline-offset: 1px;
}

.hibot-pdf__icon {
	display: block;
	width: 20px;
	height: 20px;
}

.hibot-pdf__btn .hibot-pdf__icon--exit,
.hibot-pdf__btn.is-active .hibot-pdf__icon--enter {
	display: none;
}

.hibot-pdf__btn.is-active .hibot-pdf__icon--exit {
	display: block;
}

.hibot-pdf__pagenum {
	display: inline-flex;
}

.hibot-pdf__page-input,
.hibot-pdf__scale,
.hibot-pdf__find-input {
	box-sizing: border-box;
	height: 32px;
	border: 1px solid var(--hibot-pdf-line);
	border-radius: 4px;
	background: #fff;
	color: var(--hibot-pdf-navy);
	font-family: inherit;
}

.hibot-pdf__page-input {
	width: 48px;
	padding: 0 4px;
	text-align: center;
}

.hibot-pdf__pagecount {
	min-width: 40px;
	padding: 0 4px;
	white-space: nowrap;
}

.hibot-pdf__scale {
	max-width: 170px;
	padding: 0 8px;
	cursor: pointer;
}

/* Search bar --------------------------------------------------------- */

.hibot-pdf__find {
	display: flex;
	flex: 1 0 100%;
	align-items: center;
	justify-content: flex-end;
	gap: 4px;
}

.hibot-pdf__find[hidden] {
	display: none;
}

.hibot-pdf__find-input {
	flex: 0 1 320px;
	min-width: 0;
	padding: 0 10px;
}

.hibot-pdf__find-input.is-not-found {
	border-color: var(--hibot-pdf-orange);
	background: #fff1ec;
}

.hibot-pdf__find-result {
	min-width: 72px;
	padding: 0 6px;
	color: #6b7480;
	font-size: 13px !important;
	white-space: nowrap;
}

/* Pages -------------------------------------------------------------- */

.hibot-pdf__stage {
	position: relative;
	flex: 1 1 auto;
	min-height: 0;
}

/* PDF.js requires an absolutely positioned scroll container. */
.hibot-pdf__container {
	position: absolute;
	inset: 0;
	overflow: auto;
	background: var(--hibot-pdf-stage);
	/* The browser keeps one-finger scrolling; two-finger pinch is ours. */
	touch-action: pan-x pan-y;
	outline: none;
}

/* The theme makes every element border-box; PDF.js sizes pages as
   content-box (page size + 9px border). Restored with zero specificity, so
   pdf_viewer.css keeps its own exceptions. Without this the canvas shrinks
   while the text layer does not, and selection/search highlights drift. */
:where(.hibot-pdf .pdfViewer),
:where(.hibot-pdf .pdfViewer) *,
:where(.hibot-pdf .pdfViewer) *::before,
:where(.hibot-pdf .pdfViewer) *::after {
	box-sizing: content-box;
}

.hibot-pdf .pdfViewer {
	padding: 12px 0 24px;
}

/* Pages keep PDF.js' own shadow (drawn in their transparent border). */

.hibot-pdf .textLayer .highlight.selected {
	background-color: rgb(255 82 28 / 0.35);
}

/* Loading / error ---------------------------------------------------- */

.hibot-pdf__status {
	position: absolute;
	top: 40%;
	left: 50%;
	z-index: 3;
	width: min(360px, calc(100% - 32px));
	padding: 20px 24px;
	border-radius: 8px;
	background: #fff;
	box-shadow: 0 4px 24px rgb(0 0 0 / 0.12);
	text-align: center;
	transform: translate(-50%, -50%);
}

.hibot-pdf__status[hidden] {
	display: none;
}

.hibot-pdf__status p {
	margin: 0 0 12px;
}

.hibot-pdf__progress {
	display: block;
	height: 4px;
	overflow: hidden;
	border-radius: 2px;
	background: var(--hibot-pdf-hover);
}

.hibot-pdf__progress[hidden] {
	display: none;
}

.hibot-pdf__progress > span {
	display: block;
	width: 0;
	height: 100%;
	background: var(--hibot-pdf-orange);
	transition: width 0.2s;
}

.hibot-pdf__direct,
.hibot-pdf__noscript a,
.hibot-pdf__action {
	display: inline-block;
	padding: 8px 20px;
	border: 0;
	border-radius: 4px;
	background: var(--hibot-pdf-orange-text);
	color: #fff;
	font-weight: 700;
	cursor: pointer;
}

.hibot-pdf__direct:hover,
.hibot-pdf__noscript a:hover,
.hibot-pdf__action:hover {
	background: #a8320a;
}

.hibot-pdf__action--secondary {
	background: #fff;
	color: var(--hibot-pdf-navy);
	box-shadow: inset 0 0 0 1px var(--hibot-pdf-line);
}

.hibot-pdf__action--secondary:hover {
	background: var(--hibot-pdf-hover);
}

/* Password form */
.hibot-pdf__password {
	display: grid;
	gap: 10px;
	text-align: left;
}

.hibot-pdf__password[hidden],
.hibot-pdf__status p[hidden] {
	display: none;
}

.hibot-pdf__password :is(label, input, button, span) {
	font-size: 14px;
	line-height: 1.4;
}

.hibot-pdf__password input {
	box-sizing: border-box;
	width: 100%;
	height: 36px;
	padding: 0 10px;
	border: 1px solid var(--hibot-pdf-line);
	border-radius: 4px;
}

.hibot-pdf__password input:focus-visible,
.hibot-pdf__action:focus-visible,
.hibot-pdf__direct:focus-visible {
	outline: 2px solid var(--hibot-pdf-orange);
	outline-offset: 2px;
}

.hibot-pdf__password-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

.hibot-pdf__direct[hidden] {
	display: none;
}

.hibot-pdf__noscript {
	position: absolute;
	top: 40%;
	width: 100%;
	text-align: center;
}

/* Full screen -------------------------------------------------------- */

.hibot-pdf:fullscreen {
	height: 100vh;
	min-height: 0;
}

.hibot-pdf.is-fullscreen {
	height: 100vh;
	min-height: 0;
}

/* Small screens ------------------------------------------------------ */

@media (max-width: 767px) {
	.hibot-pdf {
		min-height: 360px;
	}

	.hibot-pdf__bar {
		gap: 4px 8px;
		padding: 6px 8px;
	}

	.hibot-pdf__title {
		flex-basis: 100%;
		font-size: 14px !important;
	}

	/* One row of controls: no separators, no zoom menu (+/- and pinch). */
	.hibot-pdf__controls {
		flex: 1 1 100%;
		flex-wrap: nowrap;
		justify-content: space-between;
		gap: 0;
	}

	.hibot-pdf__group + .hibot-pdf__group {
		padding-left: 0;
		border-left: 0;
	}

	.hibot-pdf__scale {
		display: none;
	}

	.hibot-pdf__btn {
		width: 32px;
		height: 32px;
	}

	.hibot-pdf__page-input {
		width: 40px;
	}

	.hibot-pdf__pagecount {
		min-width: 0;
	}

	.hibot-pdf__find-input {
		flex: 1 1 auto;
	}
}

/* Very narrow phones: zoom with two fingers, no full screen button. */
@media (max-width: 379px) {
	.hibot-pdf__group--zoom,
	.hibot-pdf__btn[data-action="fullscreen"] {
		display: none;
	}
}

/* Print: only the rendered PDF pages (see print() in viewer.js) ---------- */

.hibot-pdf-print,
.hibot-pdf__print-hint {
	display: none;
}

/* Printed from the browser menu (not the Print button): the pages are a
   canvas the browser cannot print reliably, so print a pointer instead. */
@media print {
	html:not(.hibot-pdf-printing) body > *:not(main),
	html:not(.hibot-pdf-printing) .hibot-pdf-page > *:not(.hibot-pdf),
	html:not(.hibot-pdf-printing) .hibot-pdf > *:not(.hibot-pdf__print-hint),
	html:not(.hibot-pdf-printing) #wpadminbar {
		display: none !important;
	}

	html:not(.hibot-pdf-printing) .hibot-pdf-page {
		padding: 0;
		background: #fff;
	}

	html:not(.hibot-pdf-printing) .hibot-pdf {
		height: auto;
		min-height: 0;
		background: #fff;
	}

	html:not(.hibot-pdf-printing) .hibot-pdf__print-hint {
		display: block;
		margin: 2cm;
		color: #000;
		font-size: 14pt;
		line-height: 1.6;
	}
}

@media print {
	html.hibot-pdf-printing,
	html.hibot-pdf-printing body {
		width: 100% !important;
		height: 100% !important;
		margin: 0 !important;
		padding: 0 !important;
		background: #fff !important;
	}

	html.hibot-pdf-printing body > *:not(.hibot-pdf-print) {
		display: none !important;
	}

	html.hibot-pdf-printing .hibot-pdf-print {
		display: block;
		width: 100%;
		height: 100%;
	}

	.hibot-pdf-print__page {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 100%;
		overflow: hidden;
		break-after: page;
		page-break-after: always;
		break-inside: avoid;
		page-break-inside: avoid;
	}

	.hibot-pdf-print__page:last-child {
		break-after: auto;
		page-break-after: auto;
	}

	.hibot-pdf-print__page img {
		display: block;
		max-width: 100%;
		max-height: 100%;
	}

	/* Each sheet on paper of its own size (CSS named pages): viewer.js sets
	   the sheet's width and height inline from the PDF page. */
	.hibot-pdf-print.is-sized .hibot-pdf-print__page img {
		width: 100%;
		height: 100%;
		object-fit: contain;
	}
}
