/*
 * amina brand hub 0.10: the document viewer (assets/viewer.js). Loaded on asset pages of PDF files only.
 * 0.12: the text layer over each page (select and copy) and the find bar.
 * The viewer sits outside .abh (it is appended to <body>), so it carries its own variables.
 */

.abh .abh-btn[hidden] {
	display: none;
}

.abh .abh-tile.is-viewable {
	cursor: zoom-in;
}

html.abh-viewer-open {
	overflow: hidden;
}

.abh-viewer {
	--v-ink: #222020;
	--v-deep: #100f0f;
	--v-line: #4a4645;
	--v-orange: #ffad6c;
	--v-font: "ABC-Repro-Regular", "Helvetica Neue", Helvetica, Arial, sans-serif;

	position: fixed;
	inset: 0;
	z-index: 100000; /* above the WordPress toolbar (99999) */
	display: flex;
	flex-direction: column;
	background: #100f0f;
	color: #fff;
	font-family: var(--v-font);
	font-size: 15px;
	line-height: 1.25;
	letter-spacing: -0.02em;
}

.abh-viewer[hidden] {
	display: none;
}

.abh-viewer *,
.abh-viewer *::before,
.abh-viewer *::after {
	box-sizing: border-box;
}

.abh-viewer__bar {
	display: flex;
	flex: 0 0 auto;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 16px;
	padding: 10px 16px;
	background: var(--v-ink);
	border-bottom: 1px solid var(--v-line);
}

.abh-viewer__title {
	flex: 1 1 12em;
	min-width: 0;
	overflow: hidden;
	font-family: var(--v-font);
	font-size: 15px;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.abh-viewer__tools {
	display: contents; /* on a phone it becomes the second row (see below) */
}

.abh-viewer__group {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

.abh-viewer__of {
	min-width: 3.5em;
	color: #cfcac7;
	white-space: nowrap;
}

.abh-viewer__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 36px;
	height: 36px;
	padding: 0 10px;
	border: 1px solid var(--v-line);
	border-radius: 18px;
	background: transparent;
	color: #fff;
	font-family: var(--v-font);
	font-size: 20px;
	line-height: 1;
	cursor: pointer;
}

.abh-viewer__btn--text {
	font-size: 14px;
}

.abh-viewer__btn:hover {
	border-color: #fff;
}

.abh-viewer__btn:focus-visible,
.abh-viewer__download:focus-visible,
.abh-viewer__field:focus-visible,
.abh-viewer__retry:focus-visible,
.abh-viewer__body:focus-visible {
	outline: 2px solid var(--v-orange);
	outline-offset: 2px;
}

.abh-viewer__field {
	width: 3.6em;
	height: 36px;
	padding: 0 6px;
	border: 1px solid var(--v-line);
	border-radius: 18px;
	background: var(--v-deep);
	color: #fff;
	font-family: var(--v-font);
	font-size: 16px; /* 16px or more: iOS Safari zooms the page when a smaller field is focused */
	text-align: center;
}

.abh-viewer__download {
	display: inline-flex;
	align-items: center;
	height: 36px;
	padding: 0 18px;
	border-radius: 18px;
	background: var(--v-orange);
	color: var(--v-ink);
	font-size: 15px;
	text-decoration: none;
}

.abh-viewer__download:hover {
	background: #ffc789;
}

.abh-viewer__body {
	position: relative;
	flex: 1 1 auto;
	padding: 16px;
	overflow: auto;
	overscroll-behavior: contain;
	overflow-anchor: none; /* the script keeps the place itself when a page changes size */
	touch-action: pan-x pan-y pinch-zoom;
}

.abh-viewer:focus {
	outline: none;
}

.abh-viewer__pages {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	width: max-content;
	min-width: 100%;
}

.abh-viewer__sheet {
	position: relative;
	flex: 0 0 auto;
	margin: 0 auto 16px;
	background: #fff;
	box-shadow: 0 2px 14px rgba(0, 0, 0, 0.5);
}

.abh-viewer__num {
	position: absolute;
	top: 50%;
	left: 50%;
	color: #cfcac7;
	font-size: 28px;
	transform: translate(-50%, -50%);
}

.abh-viewer__sheet.is-drawn .abh-viewer__num {
	display: none;
}

.abh-viewer__canvas {
	display: block;
	width: 100%;
	height: 100%;
}

.abh-viewer__status {
	margin: 40px auto;
	max-width: 32em;
	color: #fff;
	font-size: 16px;
	text-align: center;
}

.abh-viewer__status[hidden] {
	display: none;
}

.abh-viewer__retry {
	padding: 6px 14px;
	border: 1px solid #fff;
	border-radius: 18px;
	background: transparent;
	color: #fff;
	font-family: var(--v-font);
	font-size: 15px;
	cursor: pointer;
}

.abh-viewer__fail {
	position: absolute;
	top: 50%;
	left: 50%;
	padding: 8px 14px;
	border: 1px solid var(--v-ink);
	border-radius: 18px;
	background: #fff;
	color: var(--v-ink);
	font-family: var(--v-font);
	font-size: 14px;
	cursor: pointer;
	transform: translate(-50%, -50%);
}

.abh-viewer__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

/* ---- 0.12: the text of a page, laid over it (pdf.js text layer): invisible, but it can be selected and copied ---- */

.abh-viewer__text {
	position: absolute;
	inset: 0;
	z-index: 1;
	overflow: clip;
	line-height: 1;
	text-align: initial;
	-webkit-text-size-adjust: none;
	text-size-adjust: none;
	forced-color-adjust: none;
	transform-origin: 0 0;
	caret-color: CanvasText;
	mix-blend-mode: multiply; /* a highlight or a selection tints the page; the black text under it stays black */
}

.abh-viewer__text :is(span, br) {
	position: absolute;
	color: transparent;
	white-space: pre;
	cursor: text;
	transform-origin: 0% 0%;
}

/* What pdf.js sets on each piece of text (its size in --font-height, a squeeze in --scale-x, a turn in --rotate): scaled to the page. */
.abh-viewer__text {
	--min-font-size: 1; /* the script sets the measured value on the layer itself */
	--text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
	--min-font-size-inv: calc(1 / var(--min-font-size));
}

.abh-viewer__text > :not(.markedContent),
.abh-viewer__text .markedContent span:not(.markedContent) {
	z-index: 1;
	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));
}

.abh-viewer__text .markedContent {
	display: contents;
}

.abh-viewer__text span[role='img'] {
	cursor: default;
	user-select: none;
}

.abh-viewer__text span.markedContent {
	top: 0;
	height: 0;
}

.abh-viewer__text br::selection {
	background: transparent;
}

.abh-viewer__text ::selection {
	background: rgba(60, 130, 255, 0.4);
}

.abh-viewer__text .endOfContent {
	position: absolute;
	inset: 100% 0 0;
	z-index: 0;
	display: block;
	cursor: default;
	user-select: none;
}

.abh-viewer__text.selecting .endOfContent {
	top: 0;
}

/* ---- the find bar and the matches ---- */

.abh-viewer__find {
	display: flex;
	flex: 0 0 auto;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	padding: 8px 16px;
	background: var(--v-ink);
	border-bottom: 1px solid var(--v-line);
}

.abh-viewer__find[hidden] {
	display: none;
}

.abh-viewer__findfield {
	flex: 1 1 12em;
	width: auto;
	max-width: 26em;
	padding: 0 14px;
	text-align: left;
}

.abh-viewer__count {
	min-width: 6em;
	color: #cfcac7;
	font-size: 14px;
}

.abh-viewer__findbtn {
	font-size: 14px;
}

::highlight(abh-find) {
	background-color: rgba(255, 173, 108, 0.5);
	color: transparent;
}

::highlight(abh-find-now) {
	background-color: #ff8a30;
	color: transparent;
}

.abh-viewer__text .is-hit {
	background: rgba(255, 173, 108, 0.5);
}

.abh-viewer__text .is-hit-now {
	background: #ff8a30;
}

.abh-viewer__find:focus-within,
.abh-viewer__findfield:focus-visible {
	outline: none;
}

.abh-viewer__findfield:focus-visible {
	outline: 2px solid var(--v-orange);
	outline-offset: 2px;
}

@media (max-width: 640px) {
	/* Phone: title, Download and Close on the first row; page controls and zoom on the second. */
	.abh-viewer__bar {
		display: grid;
		grid-template-columns: minmax(0, 1fr) auto auto auto;
		align-items: center;
		padding: 8px 10px;
		gap: 8px 10px;
	}

	.abh-viewer__title {
		grid-column: 1;
		grid-row: 1;
	}

	.abh-viewer__findbtn {
		grid-column: 2;
		grid-row: 1;
	}

	.abh-viewer__download {
		grid-column: 3;
		grid-row: 1;
		padding: 0 14px;
	}

	.abh-viewer__close {
		grid-column: 4;
		grid-row: 1;
	}

	.abh-viewer__tools {
		display: flex;
		grid-column: 1 / -1;
		grid-row: 2;
		align-items: center;
		justify-content: space-between;
		gap: 8px;
	}

	.abh-viewer__of {
		min-width: 0;
	}

	.abh-viewer__find {
		padding: 8px 10px;
	}

	.abh-viewer__body {
		padding: 8px 8px calc(72px + env(safe-area-inset-bottom)); /* room under the last page for the browser's own toolbar */
	}
}
