/* Page viewer (viewer.html) */

:root {
	/* Article colours, as on item pages (Vega's tableau10) */
	--part-0: #4c78a8;
	--part-1: #f58518;
	--part-2: #e45756;
	--part-3: #72b7b2;
	--part-4: #54a24b;
	--part-5: #eeca3b;
	--part-6: #b279a2;
	--part-7: #ff9da6;
	--part-8: #9d755d;
	--part-9: #bab0ac;

	--viewer-current: #2563eb;
	--viewer-bg: #e8e8e8;
	--viewer-bar-bg: #ffffff;
	--viewer-bar-text: #222222;
	--viewer-bar-border: #d0d0d0;
	--viewer-page-bg: #f6f6f6;
	--viewer-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
	--viewer-mark: #fde68a;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--viewer-bg: #1b1b1b;
		--viewer-bar-bg: #262626;
		--viewer-bar-text: #e6e6e6;
		--viewer-bar-border: #3a3a3a;
		--viewer-page-bg: #333333;
		--viewer-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
		--viewer-current: #60a5fa;
		--viewer-mark: #854d0e;
	}
}

:root[data-theme="dark"] {
	--viewer-bg: #1b1b1b;
	--viewer-bar-bg: #262626;
	--viewer-bar-text: #e6e6e6;
	--viewer-bar-border: #3a3a3a;
	--viewer-page-bg: #333333;
	--viewer-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
	--viewer-current: #60a5fa;
	--viewer-mark: #854d0e;
}

html, body {
	margin: 0;
	height: 100%;
}

body {
	background-color: var(--viewer-bg);
	color: var(--viewer-bar-text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 14px;
	display: flex;
	flex-direction: column;
}

.viewer-bar {
	flex: none;
	display: flex;
	align-items: center;
	gap: 0.75em;
	padding: 0.4em 1em;
	background-color: var(--viewer-bar-bg);
	border-bottom: 1px solid var(--viewer-bar-border);
	min-width: 0;
}

.viewer-title {
	flex: 1 1 auto;
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	min-width: 0;
}

.viewer-bar select {
	font: inherit;
	color: inherit;
	background-color: var(--viewer-bar-bg);
	border: 1px solid var(--viewer-bar-border);
	border-radius: 4px;
	padding: 0.15em 0.3em;
	min-width: 0;
}

.viewer-articles {
	flex: 0 1 20em;
	max-width: 20em;
}

.viewer-pages {
	flex: none;
}

/* Thumbnails and search toggles */
.viewer-toggle {
	flex: none;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2em;
	height: 2em;
	padding: 0;
	color: inherit;
	background: none;
	border: 1px solid var(--viewer-bar-border);
	border-radius: 4px;
	cursor: pointer;
	box-sizing: border-box;
	text-decoration: none;
}

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

.viewer-toggle svg {
	fill: currentColor;
}

.viewer-toggle[aria-expanded="true"] {
	color: var(--viewer-bar-bg);
	background-color: var(--viewer-bar-text);
	border-color: var(--viewer-bar-text);
}

/* Thumbnails beside the pages */
.viewer-body {
	flex: 1 1 auto;
	display: flex;
	min-height: 0;
	position: relative;
}

/* The pages scroll inside this, so the bar stays put */
.viewer-scroll {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 1em 0;
}

.viewer-thumbs {
	flex: none;
	width: 15em;
	overflow-y: auto;
	padding: 0.75em;
	box-sizing: border-box;
	background-color: var(--viewer-bar-bg);
	border-right: 1px solid var(--viewer-bar-border);
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(5.5em, 1fr));
	gap: 0.75em 0.5em;
	align-content: start;
	align-items: end;
}

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

.viewer-thumb {
	display: block;
	color: inherit;
	text-decoration: none;
	text-align: center;
	font-size: 0.8em;
	line-height: 1.3;
	border-radius: 3px;
	padding: 3px;
}

/* The scan, with a bar below in its article's colour, as on item pages */
.viewer-thumb img {
	display: block;
	width: 100%;
	height: auto;
	background-color: var(--viewer-page-bg);
	box-shadow: var(--viewer-shadow);
	border-bottom: 4px solid transparent;
	box-sizing: border-box;
}

.viewer-thumb span {
	display: block;
	margin-top: 0.2em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.viewer-thumb:hover {
	background-color: var(--viewer-bg);
}

.viewer-thumb.current {
	outline: 2px solid var(--viewer-current);
	outline-offset: 0;
}

.viewer-thumb.current span {
	font-weight: 600;
}

.viewer-message {
	max-width: 40em;
	margin: 2em auto;
	padding: 0 1em;
	line-height: 1.5;
}

/* Each page keeps its shape (aspect-ratio, set from the canvas) before its image loads,
   so the scroll position never jumps. */
.viewer-page {
	position: relative;
	width: min(90%, 60em);
	margin: 0 auto 1em auto;
	background-color: var(--viewer-page-bg);
	background-size: 100% 100%;
	box-shadow: var(--viewer-shadow);
	scroll-margin-top: 1em;
	user-select: none;
	-webkit-user-select: none;
}

/* Fills the page box exactly, so a scan whose shape differs slightly from its canvas
   does not change the page's height */
.viewer-page img {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	-webkit-user-drag: none;
}

/* Text laid over the image (see draw_text() in viewer.js): invisible, but it can be
   selected, which shows each word's box */
.viewer-page {
	container-type: inline-size;
}

.viewer-text {
	position: absolute;
	inset: 0;
	user-select: text;
	-webkit-user-select: text;
}

.viewer-text span {
	position: absolute;
	white-space: pre;
	line-height: 1;
	font-family: sans-serif;
	color: transparent;
	transform-origin: 0 0;
	cursor: text;
}

.viewer-text span::selection {
	color: transparent;
	background-color: rgba(37, 99, 235, 0.3);
}

/* Search inside and the page's text, beside the pages on the right, one above the
   other if both are open */
.viewer-side {
	flex: none;
	width: 20em;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	background-color: var(--viewer-bar-bg);
	border-left: 1px solid var(--viewer-bar-border);
	min-height: 0;
}

.viewer-side[hidden],
.viewer-search[hidden],
.viewer-text-panel[hidden] {
	display: none;
}

.viewer-search,
.viewer-text-panel {
	flex: 1 1 0;
	display: flex;
	flex-direction: column;
	min-height: 0;
}

.viewer-search + .viewer-text-panel:not([hidden]) {
	border-top: 1px solid var(--viewer-bar-border);
}

.viewer-search-form {
	flex: none;
	padding: 0.75em 0.75em 0 0.75em;
}

.viewer-search-form input {
	width: 100%;
	box-sizing: border-box;
	font: inherit;
	color: inherit;
	background-color: var(--viewer-bar-bg);
	border: 1px solid var(--viewer-bar-border);
	border-radius: 4px;
	padding: 0.35em 0.5em;
}

.viewer-search-status {
	flex: none;
	margin: 0.5em 0.75em;
	font-size: 0.9em;
	opacity: 0.75;
}

.viewer-search-status:empty {
	display: none;
}

.viewer-search-results {
	flex: 1 1 auto;
	overflow-y: auto;
	list-style: none;
	margin: 0;
	padding: 0 0.75em 0.75em 0.75em;
}

/* A page with hits: its label, then each hit in its context */
.viewer-search-page {
	margin-top: 0.75em;
}

.viewer-search-page h3 {
	margin: 0 0 0.25em 0;
	font-size: 0.85em;
	font-weight: 600;
}

.viewer-search-hit {
	display: block;
	width: 100%;
	text-align: left;
	font: inherit;
	font-size: 0.9em;
	line-height: 1.4;
	color: inherit;
	background: none;
	border: none;
	border-radius: 3px;
	padding: 0.25em 0.35em;
	margin: 0 0 0.15em 0;
	cursor: pointer;
}

.viewer-search-hit:hover {
	background-color: var(--viewer-bg);
}

.viewer-search-hit.current {
	outline: 2px solid var(--viewer-current);
}

.viewer-search-hit mark {
	color: inherit;
	background-color: var(--viewer-mark);
	border-radius: 2px;
}

/* The page's text: as the OCR gives it, so line breaks are kept */
.viewer-text-label {
	flex: none;
	margin: 0;
	padding: 0.75em 0.75em 0.25em 0.75em;
	font-size: 0.85em;
	font-weight: 600;
}

.viewer-text-body {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 0.25em 0.75em 0.75em 0.75em;
	font-family: Georgia, "Times New Roman", serif;
	font-size: 0.95em;
	line-height: 1.5;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	user-select: text;
	-webkit-user-select: text;
}

.viewer-text-body.viewer-text-none {
	font-family: inherit;
	font-style: italic;
	opacity: 0.75;
}

.viewer-text-body mark {
	color: inherit;
	background-color: var(--viewer-mark);
	border-radius: 2px;
}

.viewer-text-body mark.current {
	outline: 2px solid rgb(234, 88, 12);
}

/* Search hits marked on the page (see draw_hits() in viewer.js), under its text */
.viewer-hits {
	position: absolute;
	inset: 0;
	pointer-events: none;
}

.viewer-hits div {
	position: absolute;
	box-sizing: content-box;
	margin: -2px 0 0 -2px;
	padding: 2px;
	border-radius: 2px;
	background-color: rgba(250, 204, 21, 0.4);
	mix-blend-mode: multiply;
}

.viewer-hits div.current {
	background-color: rgba(249, 115, 22, 0.5);
	outline: 2px solid rgb(234, 88, 12);
}

@media (max-width: 700px) {
	.viewer-page {
		width: 100%;
	}
	.viewer-scroll {
		padding: 0.5em 0;
	}
	.viewer-title {
		display: none;
	}
	/* Thumbnails cover the pages, and close when one is chosen */
	.viewer-thumbs {
		position: absolute;
		inset: 0;
		width: auto;
		z-index: 10;
		border-right: none;
	}
	/* Search and text cover the pages too */
	.viewer-side {
		position: absolute;
		inset: 0;
		width: auto;
		z-index: 10;
		border-left: none;
	}
	/* A long article title must not widen the bar */
	.viewer-articles {
		flex: 1 1 0;
		width: 0;
		max-width: none;
	}
}
