/*
 * mod/pdfAssembler - scoped under .pdfAssembler, custom properties --pdfAsm-* declared on the root (never :root).
 * The host page decides the theme: html.darkTheme switches the palette, the module never writes it.
 * A host may override any --pdfAsm-* property to match its own design (the PDF24 Toolbox does).
 */
.pdfAssembler {
	--pdfAsm-bg: #f1f3f5;
	--pdfAsm-surface: #ffffff;
	--pdfAsm-surface-2: #f6f7f9;
	--pdfAsm-text: #1f2937;
	--pdfAsm-muted: #6b7280;
	--pdfAsm-border: #d4d8dd;
	--pdfAsm-accent: #0078d5;
	--pdfAsm-accent-text: #ffffff;
	--pdfAsm-accent-soft: rgba(0, 120, 213, .12);
	--pdfAsm-primary: #0078d5;
	--pdfAsm-primary-text: #ffffff;
	--pdfAsm-hover: rgba(0, 0, 0, .06);
	--pdfAsm-radius: 8px;
	--pdfAsm-shadow: 0 1px 3px rgba(0, 0, 0, .12);
	--pdfAsm-page-shadow: 0 1px 4px rgba(0, 0, 0, .25);

	position: relative;
	display: flex;
	flex-direction: column;
	min-height: 320px;
	height: 100%;
	box-sizing: border-box;
	background: var(--pdfAsm-bg);
	color: var(--pdfAsm-text);
	font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	outline: none;
	user-select: none;
}
html.darkTheme .pdfAssembler {
	--pdfAsm-bg: #17191c;
	--pdfAsm-surface: #22252a;
	--pdfAsm-surface-2: #2b2f35;
	--pdfAsm-text: #e5e7eb;
	--pdfAsm-muted: #9ca3af;
	--pdfAsm-border: #3a3f46;
	--pdfAsm-accent: #4aa3ff;
	--pdfAsm-accent-soft: rgba(74, 163, 255, .16);
	--pdfAsm-hover: rgba(255, 255, 255, .07);
	--pdfAsm-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}

/* ---- toolbar ---- */
.pdfAssembler .pdfAsm-toolbar {
	flex: none;
	container-type: inline-size;
	display: flex;
	align-items: center;
	flex-wrap: nowrap;
	overflow: hidden;
	gap: 4px;
	padding: 8px 12px;
	background: var(--pdfAsm-surface);
	border-bottom: 1px solid var(--pdfAsm-border);
}
.pdfAssembler .pdfAsm-sep {
	width: 1px;
	height: 24px;
	margin: 0 6px;
	background: var(--pdfAsm-border);
}
.pdfAssembler .pdfAsm-spacer {
	flex: 1 1 auto;
}
.pdfAssembler .pdfAsm-btn {
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: 34px;
	min-width: 34px;
	padding: 0 10px;
	border: 1px solid transparent;
	border-radius: var(--pdfAsm-radius);
	background: transparent;
	color: inherit;
	font: inherit;
	cursor: pointer;
	justify-content: center;
	white-space: nowrap;
}
.pdfAssembler .pdfAsm-btn:hover:not(:disabled) {
	background: var(--pdfAsm-hover);
}
.pdfAssembler .pdfAsm-btn[aria-pressed="true"] {
	background: var(--pdfAsm-accent-soft);
	color: var(--pdfAsm-accent);
}
.pdfAssembler .pdfAsm-btn:focus-visible {
	outline: 2px solid var(--pdfAsm-accent);
	outline-offset: 1px;
}
.pdfAssembler .pdfAsm-btn:disabled,
.pdfAssembler .pdfAsm-btn.off {
	opacity: .35;
	cursor: default;
	pointer-events: none;
}
.pdfAssembler .pdfAsm-btn.primary,
.pdfAssembler .pdfAsm-btn.primaryEmpty {
	background: var(--pdfAsm-primary);
	color: var(--pdfAsm-primary-text);
	font-weight: 600;
	padding: 0 16px;
}
.pdfAssembler .pdfAsm-btn.primary:hover:not(:disabled),
.pdfAssembler .pdfAsm-btn.primaryEmpty:hover {
	background: var(--pdfAsm-primary);
	filter: brightness(1.08);
}
.pdfAssembler .pdfAsm-btn svg {
	flex: none;
}
/* one row: the buttons never shrink below their content (else their words run over the next ones); when they don't
   fit, _fitToolbar() sets pdfAsm-compact and they keep only their icon (the tooltip still names them), Save keeps its
   word. Below 1050px that without measuring (before the script runs). */
.pdfAssembler .pdfAsm-toolbar > :not(.pdfAsm-spacer) {
	flex-shrink: 0;
}
.pdfAssembler .pdfAsm-toolbar.pdfAsm-compact .pdfAsm-btn:not(.primary) span {
	display: none;
}
@container (max-width: 1050px) {
	.pdfAssembler .pdfAsm-toolbar .pdfAsm-btn:not(.primary) span {
		display: none;
	}
}

/* ---- narrow (a phone, a small embedding): the toolbar one row to swipe sideways, "Save" in view at its end; a
   document's head in two lines (name and count, then its buttons) ---- */
.pdfAssembler {
	container: pdfAsm / inline-size;
}
@container pdfAsm (max-width: 720px) {
	.pdfAssembler .pdfAsm-toolbar {
		overflow-x: auto;
		overscroll-behavior-x: contain;
		scrollbar-width: thin;
	}
	.pdfAssembler .pdfAsm-toolbar > * {
		flex: none;
	}
	.pdfAssembler .pdfAsm-toolbar > .pdfAsm-spacer {
		flex: 1 0 8px;
	}
	.pdfAssembler .pdfAsm-toolbar > [data-act="save"] {
		position: sticky;
		inset-inline-end: -12px;
		box-shadow: -10px 0 10px -6px var(--pdfAsm-surface);
	}
	.pdfAssembler .pdfAsm-toolbar > [data-act="save"] span {
		display: none;
	}
	.pdfAssembler .pdfAsm-docHeader {
		flex-wrap: wrap;
		row-gap: 4px;
	}
	.pdfAssembler .pdfAsm-docName {
		flex: 1 1 120px;
		width: auto;
		max-width: none;
		min-width: 0;
	}
	/* the buttons on a line of their own, at its end */
	.pdfAssembler .pdfAsm-docHeader > .pdfAsm-spacer {
		flex: 1 0 100%;
		height: 0;
	}
	.pdfAssembler .pdfAsm-docHeader > .pdfAsm-spacer ~ .pdfAsm-btn:first-of-type {
		margin-inline-start: auto;
	}
}

/* ---- flow: no height of its own, the page scrolls (config flow) ---- */
.pdfAssembler.pdfAsm-flow {
	height: auto;
}
.pdfAssembler.pdfAsm-flow .pdfAsm-toolbar {
	position: sticky;
	top: 0;
	z-index: 8;
}
.pdfAssembler.pdfAsm-flow .pdfAsm-docs {
	overflow: visible;
}

/* ---- maximized: over the whole window (config maximizable), the documents scroll inside again ---- */
.pdfAssembler.pdfAsm-max {
	position: fixed;
	inset: 0;
	margin: 0;
	z-index: 9990;
	height: auto;
}
.pdfAssembler.pdfAsm-max .pdfAsm-docs {
	overflow: auto;
}

/* ---- documents ---- */
.pdfAssembler .pdfAsm-docs {
	flex: 1 1 auto;
	overflow: auto;
	padding: 14px;
	display: flex;
	flex-direction: column;
	gap: 14px;
}
.pdfAssembler .pdfAsm-doc {
	background: var(--pdfAsm-surface);
	border: 1px solid var(--pdfAsm-border);
	border-radius: var(--pdfAsm-radius);
	box-shadow: var(--pdfAsm-shadow);
}
/* pinned: stays in view while scrolling - at the top when it was above, at the bottom when below; one row of pages */
.pdfAssembler .pdfAsm-doc.pinned {
	position: sticky;
	top: var(--pdfAsm-pinTop, 0px);
	bottom: 0;
	z-index: 5;
	box-shadow: 0 2px 12px rgba(0, 0, 0, .28);
}
.pdfAssembler .pdfAsm-doc.pinned .pdfAsm-pages {
	flex-wrap: nowrap;
	overflow-x: auto;
}
.pdfAssembler .pdfAsm-doc.pinned .pdfAsm-page {
	flex: none;
}
.pdfAssembler .pdfAsm-doc.dropInto {
	border-color: var(--pdfAsm-accent);
	box-shadow: 0 0 0 2px var(--pdfAsm-accent-soft);
}
.pdfAssembler .pdfAsm-docHeader {
	display: flex;
	align-items: center;
	gap: 6px;
	padding-block: 6px; padding-inline: 12px 8px;
	border-bottom: 1px solid var(--pdfAsm-border);
}
.pdfAssembler .pdfAsm-docHeader .pdfAsm-btn {
	height: 30px;
	min-width: 30px;
	padding: 0 6px;
}
.pdfAssembler .pdfAsm-docCheck {
	width: 16px;
	height: 16px;
	margin-block: 0; margin-inline: 0 4px;
	accent-color: var(--pdfAsm-accent);
	cursor: pointer;
}
.pdfAssembler .pdfAsm-docName {
	box-sizing: border-box;
	min-width: 120px;
	width: 32ch;
	max-width: 50%;
	height: 30px;
	padding: 0 8px;
	border: 1px solid transparent;
	border-radius: 6px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-weight: 600;
	user-select: text;
}
.pdfAssembler .pdfAsm-docName:hover {
	border-color: var(--pdfAsm-border);
}
.pdfAssembler .pdfAsm-docName:focus {
	outline: none;
	border-color: var(--pdfAsm-accent);
	background: var(--pdfAsm-surface-2);
}
.pdfAssembler .pdfAsm-docCount {
	color: var(--pdfAsm-muted);
	white-space: nowrap;
}
.pdfAssembler .pdfAsm-pages {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 18px 14px;
	padding: 14px;
	min-height: 90px;
}
/* between two pages (the gap before a page, not the first): hovered, a line with two buttons in its middle - the
   scissors (split: this page and the ones after it become a new document) and a blank page (inserted right there);
   after the last page only the blank page */
.pdfAssembler .pdfAsm-gap {
	position: absolute;
	top: 8px;
	bottom: 0;
	inset-inline-start: -14px;
	z-index: 2;
	width: 14px;
	opacity: 0;
}
.pdfAssembler .pdfAsm-gap.end {
	inset-inline-start: auto;
	inset-inline-end: -14px;
}
/* the line down to the bottom of the page's picture (above it the page number: 6px padding + 12px number + 6px gap) */
.pdfAssembler .pdfAsm-gap::before {
	content: "";
	position: absolute;
	top: 0;
	bottom: 24px;
	left: 50%;
	pointer-events: none;
	border-left: 2px dashed var(--pdfAsm-accent);
	transform: translateX(-1px);
}
/* the buttons one above the other in the middle of the line */
.pdfAssembler .pdfAsm-gapBtns {
	position: absolute;
	top: calc(50% - 14px);
	left: 50%;
	display: flex;
	flex-direction: column;
	gap: 4px;
	transform: translate(-50%, -50%);
}
.pdfAssembler .pdfAsm-gapBtn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	padding: 3px;
	border: 0;
	border-radius: 50%;
	background: var(--pdfAsm-surface);
	box-shadow: var(--pdfAsm-shadow);
	color: var(--pdfAsm-accent);
	cursor: pointer;
}
.pdfAssembler .pdfAsm-gapBtn svg {
	width: 16px;
	height: 16px;
}
.pdfAssembler .pdfAsm-gapBtn[data-act="pSplit"] svg {
	transform: rotate(-90deg);
}
.pdfAssembler .pdfAsm-gapBtn:hover,
.pdfAssembler .pdfAsm-gapBtn:focus-visible {
	background: var(--pdfAsm-accent);
	color: var(--pdfAsm-accent-text);
	outline: none;
}
.pdfAssembler .pdfAsm-gap:hover,
.pdfAssembler .pdfAsm-gap:focus-within {
	opacity: 1;
}
/* the gap hovered: the page's own tools stay away, so it is clear what happens */
.pdfAssembler .pdfAsm-page:has(.pdfAsm-gap:hover) .pdfAsm-pageTools {
	visibility: hidden;
}
.pdfAssembler.pdfAsm-dragging .pdfAsm-gap,
.pdfAssembler .pdfAsm-docs.dragging .pdfAsm-gap {
	display: none;
}

/* without wrapping: each document one row, scrolling sideways */
.pdfAssembler.pdfAsm-noWrap .pdfAsm-pages {
	flex-wrap: nowrap;
	overflow-x: auto;
}
.pdfAssembler.pdfAsm-noWrap .pdfAsm-page {
	flex: none;
}
.pdfAssembler .pdfAsm-emptyDoc {
	box-sizing: border-box;
	flex: 1 1 auto;
	align-self: stretch;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 70px;
	border: 2px dashed var(--pdfAsm-border);
	border-radius: var(--pdfAsm-radius);
	color: var(--pdfAsm-muted);
}

/* ---- pages ---- */
.pdfAssembler .pdfAsm-page {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	padding: 6px;
	border-radius: var(--pdfAsm-radius);
	cursor: grab;
	touch-action: pan-y;
}
.pdfAssembler .pdfAsm-page:hover {
	background: var(--pdfAsm-hover);
}
.pdfAssembler .pdfAsm-page.selected {
	background: var(--pdfAsm-accent-soft);
	box-shadow: inset 0 0 0 2px var(--pdfAsm-accent);
}
.pdfAssembler .pdfAsm-page.dragging {
	opacity: .45;
	cursor: grabbing;
}
.pdfAssembler .pdfAsm-page.dragging[data-count]::after {
	content: attr(data-count);
	position: absolute;
	top: -6px;
	inset-inline-end: -6px;
	min-width: 22px;
	height: 22px;
	padding: 0 6px;
	border-radius: 11px;
	background: var(--pdfAsm-accent);
	color: var(--pdfAsm-accent-text);
	font-size: 12px;
	font-weight: 700;
	line-height: 22px;
	text-align: center;
}
.pdfAssembler .pdfAsm-page.dropBefore::before,
.pdfAssembler .pdfAsm-page.dropAfter::before {
	content: "";
	position: absolute;
	top: 4px;
	bottom: 24px;
	width: 4px;
	border-radius: 2px;
	background: var(--pdfAsm-accent);
}
.pdfAssembler .pdfAsm-page.dropBefore::before {
	inset-inline-start: -10px;
}
.pdfAssembler .pdfAsm-page.dropAfter::before {
	inset-inline-end: -10px;
}
.pdfAssembler .pdfAsm-thumb {
	position: relative;
	overflow: hidden;
	background: #fff;
	box-shadow: var(--pdfAsm-page-shadow);
}
.pdfAssembler .pdfAsm-thumb img {
	position: absolute;
	left: 50%; /* centred by the script's translate(-50%, -50%) - physical in any direction */
	top: 50%;
	max-width: none;
	pointer-events: none;
}
.pdfAssembler .pdfAsm-thumb img:not([src]) {
	visibility: hidden;
}
.pdfAssembler .pdfAsm-pageNo {
	color: var(--pdfAsm-muted);
	font-size: 12px;
	line-height: 1;
}
/* over the gap before the page (z-index 2): on a small page the tools reach into it */
.pdfAssembler .pdfAsm-pageTools {
	position: absolute;
	z-index: 3;
	top: 10px;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	gap: 2px;
	padding: 2px;
	border-radius: var(--pdfAsm-radius);
	background: var(--pdfAsm-surface);
	box-shadow: var(--pdfAsm-shadow);
	visibility: hidden;
}
.pdfAssembler .pdfAsm-page:hover .pdfAsm-pageTools {
	visibility: visible;
}
/* its tools are wider than a small page: over the next page, not under it */
.pdfAssembler .pdfAsm-page:hover {
	z-index: 3;
}
.pdfAssembler.pdfAsm-dragging .pdfAsm-pageTools,
.pdfAssembler .pdfAsm-docs.dragging .pdfAsm-pageTools {
	visibility: hidden;
}
.pdfAssembler .pdfAsm-pageTools .pdfAsm-btn {
	height: 28px;
	min-width: 28px;
	padding: 0 4px;
}

/* ---- empty workspace, busy, toast ---- */
.pdfAssembler .pdfAsm-empty {
	margin: auto;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	max-width: 520px;
	padding: 48px 24px;
	text-align: center;
}
.pdfAssembler .pdfAsm-emptyTitle {
	font-size: 18px;
	font-weight: 600;
}
.pdfAssembler .pdfAsm-emptyInfo {
	color: var(--pdfAsm-muted);
}
.pdfAssembler.pdfAsm-fileOver .pdfAsm-docs {
	outline: 3px dashed var(--pdfAsm-accent);
	outline-offset: -8px;
}
.pdfAssembler .pdfAsm-busy {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(0, 0, 0, .12);
	z-index: 5;
}
.pdfAssembler .pdfAsm-busy[hidden],
.pdfAssembler .pdfAsm-toast[hidden] {
	display: none;
}
.pdfAssembler .pdfAsm-spinner {
	width: 36px;
	height: 36px;
	border: 4px solid var(--pdfAsm-accent-soft);
	border-top-color: var(--pdfAsm-accent);
	border-radius: 50%;
	animation: pdfAsm-spin .8s linear infinite;
}
@keyframes pdfAsm-spin {
	to { transform: rotate(360deg); }
}
.pdfAssembler .pdfAsm-toast {
	position: absolute;
	left: 50%;
	bottom: 20px;
	transform: translateX(-50%);
	max-width: 80%;
	padding: 10px 16px;
	border-radius: var(--pdfAsm-radius);
	background: #333;
	color: #fff;
	box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
	z-index: 6;
}

/* right to left (Arabic, Hebrew pages): undo/redo point the other way */
[dir="rtl"] .pdfAsm-btn[data-act="undo"] svg,
[dir="rtl"] .pdfAsm-btn[data-act="redo"] svg {
	transform: scaleX(-1);
}
