/**
 * Niramay Admin Dashboard - frontend PDF viewer (newsletter pages).
 *
 * Scoped to .niramay-pdf, which also carries .niramay-front, so every colour, radius, shadow and
 * font comes from the --nrm-* tokens (Settings > Branding) instead of a hard-coded value. Loaded
 * only by Niramay_Newsletter_Viewer, never on a page that merely lists newsletters.
 */

.niramay-pdf-body {
	margin: 0;
	background: var(--nrm-surface-2, #f7f6fb);
	color: var(--nrm-text, #171c26);
	font-family: var(--nrm-font-sans, system-ui, sans-serif);
	font-size: var(--nrm-font-base, 14px);
	-webkit-text-size-adjust: 100%;
}

.niramay-pdf,
.niramay-pdf * {
	box-sizing: border-box;
}

.niramay-pdf {
	display: flex;
	flex-direction: column;
	height: 100vh;
	height: 100dvh;
	overflow: hidden;
}

/* ------------------------------------------------------------------ top bar */

.niramay-pdf-bar {
	display: flex;
	align-items: center;
	gap: var(--nrm-space-4, 16px);
	padding: 10px var(--nrm-space-5, 20px);
	background: var(--nrm-surface, #fff);
	border-bottom: 1px solid var(--nrm-border, #ebeaf1);
}

.niramay-pdf-bar-title {
	display: flex;
	align-items: baseline;
	gap: var(--nrm-space-3, 12px);
	min-width: 0;
	flex: 1;
}

.niramay-pdf-back {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	flex: 0 0 auto;
	padding: 6px 10px;
	border-radius: var(--nrm-radius, 7px);
	color: var(--nrm-text-secondary, #3f4757);
	text-decoration: none;
	font-size: var(--nrm-font-sm, 13px);
}

.niramay-pdf-back:hover {
	background: var(--nrm-brand-soft, #f2ebe1);
	color: var(--nrm-brand-ink, #9a4614);
}

.niramay-pdf-title {
	font-family: var(--nrm-font-display, inherit);
	font-size: var(--nrm-font-md, 16px);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.niramay-pdf-meta {
	color: var(--nrm-text-muted, #5c6474);
	font-size: var(--nrm-font-xs, 12px);
	white-space: nowrap;
}

.niramay-pdf-bar-actions {
	flex: 0 0 auto;
}

/* The download button reuses .nrm-btn from frontend.css; only the size is tightened here. */
.niramay-pdf-download.nrm-btn {
	padding: 9px 16px;
	font-size: var(--nrm-font-sm, 13px);
	text-decoration: none;
}

/* ------------------------------------------------------------------ toolbar */

.niramay-pdf-toolbar {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 6px;
	padding: 8px var(--nrm-space-4, 16px);
	background: var(--nrm-surface, #fff);
	border-bottom: 1px solid var(--nrm-border, #ebeaf1);
}

.niramay-pdf-group {
	display: inline-flex;
	align-items: center;
	gap: 3px;
	padding-right: 6px;
	border-right: 1px solid var(--nrm-divider, #f0eef5);
}

.niramay-pdf-group:last-child {
	border-right: 0;
	padding-right: 0;
}

.niramay-pdf-group-end {
	margin-left: auto;
}

.niramay-pdf-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 1px solid transparent;
	border-radius: var(--nrm-radius, 7px);
	background: transparent;
	color: var(--nrm-text-secondary, #3f4757);
	cursor: pointer;
	text-decoration: none;
	transition: background var(--nrm-transition, 160ms ease), color var(--nrm-transition, 160ms ease);
}

.niramay-pdf-btn svg {
	width: 18px;
	height: 18px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.7;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.niramay-pdf-btn:hover:not([disabled]) {
	background: var(--nrm-brand-soft, #f2ebe1);
	color: var(--nrm-brand-ink, #9a4614);
}

.niramay-pdf-btn[aria-pressed="true"] {
	background: var(--nrm-brand-strong, #ac4d1c);
	border-color: var(--nrm-brand-strong, #ac4d1c);
	color: var(--nrm-text-on-brand, #fff);
}

.niramay-pdf-btn[disabled] {
	opacity: .38;
	cursor: default;
}

.niramay-pdf-btn:focus-visible,
.niramay-pdf-back:focus-visible,
.niramay-pdf-page-input:focus-visible,
.niramay-pdf-search input:focus-visible,
.niramay-pdf-thumb:focus-visible {
	outline: 2px solid var(--nrm-brand, #d17839);
	outline-offset: 2px;
}

.niramay-pdf-counter {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 0 6px;
	color: var(--nrm-text-muted, #5c6474);
	font-size: var(--nrm-font-sm, 13px);
}

.niramay-pdf-page-input {
	width: 46px;
	height: 32px;
	padding: 0 4px;
	border: 1px solid var(--nrm-border-strong, #dddbe7);
	border-radius: var(--nrm-radius-sm, 5px);
	background: var(--nrm-surface, #fff);
	color: var(--nrm-text, #171c26);
	font: inherit;
	font-size: var(--nrm-font-sm, 13px);
	text-align: center;
}

.niramay-pdf-zoom {
	min-width: 46px;
	text-align: center;
	color: var(--nrm-text-muted, #5c6474);
	font-size: var(--nrm-font-xs, 12px);
	font-variant-numeric: tabular-nums;
}

.niramay-pdf-find {
	gap: 4px;
	padding-left: 4px;
}

.niramay-pdf-search {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: 34px;
	padding: 0 10px;
	border: 1px solid var(--nrm-border-strong, #dddbe7);
	border-radius: var(--nrm-radius, 7px);
	background: var(--nrm-surface, #fff);
}

.niramay-pdf-search svg {
	width: 15px;
	height: 15px;
	fill: none;
	stroke: var(--nrm-text-muted, #5c6474);
	stroke-width: 1.7;
	stroke-linecap: round;
}

.niramay-pdf-search input {
	width: 132px;
	border: 0;
	outline: 0;
	background: transparent;
	color: var(--nrm-text, #171c26);
	font: inherit;
	font-size: var(--nrm-font-sm, 13px);
}

.niramay-pdf-find-hits {
	min-width: 54px;
	color: var(--nrm-text-muted, #5c6474);
	font-size: var(--nrm-font-xs, 12px);
	text-align: center;
}

/* -------------------------------------------------------------------- stage */

.niramay-pdf-stage {
	position: relative;
	display: flex;
	flex: 1;
	min-height: 0;
	background: var(--nrm-surface-3, #efedf5);
}

.niramay-pdf-thumbs {
	width: 172px;
	flex: 0 0 auto;
	overflow-y: auto;
	padding: 12px 10px;
	background: var(--nrm-surface, #fff);
	border-right: 1px solid var(--nrm-border, #ebeaf1);
}

.niramay-pdf-thumbs-inner {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.niramay-pdf-thumb {
	display: block;
	width: 100%;
	padding: 3px;
	border: 1px solid var(--nrm-border, #ebeaf1);
	border-radius: var(--nrm-radius-sm, 5px);
	background: var(--nrm-surface, #fff);
	cursor: pointer;
	line-height: 0;
	transition: border-color var(--nrm-transition, 160ms ease), box-shadow var(--nrm-transition, 160ms ease);
}

.niramay-pdf-thumb canvas {
	width: 100%;
	height: auto;
	border-radius: 3px;
}

.niramay-pdf-thumb:hover {
	border-color: var(--nrm-border-strong, #dddbe7);
}

.niramay-pdf-thumb[aria-current="true"] {
	border-color: var(--nrm-brand-strong, #ac4d1c);
	box-shadow: var(--nrm-shadow-focus, 0 0 0 3px rgba(209, 120, 57, .24));
}

.niramay-pdf-thumb-num {
	display: block;
	padding-top: 4px;
	color: var(--nrm-text-muted, #5c6474);
	font-size: 11px;
	line-height: 1;
	text-align: center;
}

.niramay-pdf-viewport {
	position: relative;
	flex: 1;
	min-width: 0;
	overflow: auto;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: var(--nrm-space-5, 20px);
	-webkit-overflow-scrolling: touch;
}

.niramay-pdf-viewport:focus {
	outline: none;
}

/* The page (or spread). The turn classes are applied for one transition, so the new page slides in
   from the side it was turned from — the "page turn" the viewer is built around. */
.niramay-pdf-page {
	display: flex;
	gap: 12px;
	align-items: center;
	justify-content: center;
	transition: transform 220ms ease, opacity 220ms ease;
	will-change: transform, opacity;
}

.niramay-pdf-page.is-turn-next {
	transform: translateX(-7%);
	opacity: .1;
}

.niramay-pdf-page.is-turn-prev {
	transform: translateX(7%);
	opacity: .1;
}

.niramay-pdf-page.is-enter-next {
	transform: translateX(7%);
	opacity: .1;
}

.niramay-pdf-page.is-enter-prev {
	transform: translateX(-7%);
	opacity: .1;
}

.niramay-pdf-canvas canvas {
	display: block;
	max-width: 100%;
	height: auto;
	background: #fff;
	border-radius: 3px;
	box-shadow: var(--nrm-shadow, 0 5px 14px rgba(72, 72, 110, .10));
}

.niramay-pdf-empty {
	padding: var(--nrm-space-7, 32px);
	border-radius: var(--nrm-radius-lg, 11px);
	background: var(--nrm-surface, #fff);
	color: var(--nrm-text-muted, #5c6474);
	text-align: center;
}

/* Page-turn arrows sitting on the stage edges. */
.niramay-pdf-edge {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 56px;
	border: 1px solid var(--nrm-border, #ebeaf1);
	border-radius: var(--nrm-radius, 7px);
	background: rgba(255, 255, 255, .92);
	color: var(--nrm-text-secondary, #3f4757);
	cursor: pointer;
	opacity: 0;
	transition: opacity var(--nrm-transition, 160ms ease), background var(--nrm-transition, 160ms ease);
}

.niramay-pdf-stage:hover .niramay-pdf-edge,
.niramay-pdf-edge:focus-visible {
	opacity: 1;
}

.niramay-pdf-edge svg {
	width: 20px;
	height: 20px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.niramay-pdf-edge:hover {
	background: var(--nrm-brand-soft, #f2ebe1);
	color: var(--nrm-brand-ink, #9a4614);
}

.niramay-pdf-edge[disabled] {
	opacity: 0;
	pointer-events: none;
}

.niramay-pdf-edge-prev {
	left: 10px;
}

.niramay-pdf-edge-next {
	right: 10px;
}

/* ------------------------------------------------------------------ overlays */

.niramay-pdf-status {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 12px 18px;
	border-radius: var(--nrm-radius-full, 999px);
	background: var(--nrm-surface, #fff);
	box-shadow: var(--nrm-shadow, 0 5px 14px rgba(72, 72, 110, .10));
	color: var(--nrm-text-secondary, #3f4757);
	font-size: var(--nrm-font-sm, 13px);
}

.niramay-pdf-status[hidden] {
	display: none;
}

.niramay-pdf-spinner {
	width: 15px;
	height: 15px;
	border: 2px solid var(--nrm-border-strong, #dddbe7);
	border-top-color: var(--nrm-brand-strong, #ac4d1c);
	border-radius: 50%;
	animation: nrm-pdf-spin 700ms linear infinite;
}

@keyframes nrm-pdf-spin {
	to { transform: rotate(360deg); }
}

.niramay-pdf-error {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	max-width: 420px;
	padding: var(--nrm-space-6, 24px);
	border: 1px solid var(--nrm-error, #c65a5a);
	border-radius: var(--nrm-radius-lg, 11px);
	background: var(--nrm-surface, #fff);
	box-shadow: var(--nrm-shadow-lg, 0 14px 30px rgba(72, 72, 110, .14));
	color: var(--nrm-error-ink, #a43636);
	text-align: center;
}

.niramay-pdf-error[hidden] {
	display: none;
}

/* The machine-readable reason (e.g. `InvalidPDFException: Invalid PDF structure.`), kept small so
   the human-readable line above stays the headline. */
.niramay-pdf-error-detail {
	margin: var(--nrm-space-2, 8px) 0 0;
	color: var(--nrm-text-muted, #6a6a7a);
	font-size: 12px;
	line-height: 1.5;
	word-break: break-word;
}

.niramay-pdf-error-detail[hidden] {
	display: none;
}

.niramay-pdf-noscript {
	display: block;
	padding: var(--nrm-space-6, 24px);
	border-radius: var(--nrm-radius-lg, 11px);
	background: var(--nrm-surface, #fff);
	box-shadow: var(--nrm-shadow-sm, 0 2px 7px rgba(72, 72, 110, .07));
	text-align: center;
}

/* ------------------------------------------------------------------- printing */

.niramay-pdf-print-stack {
	display: none;
}

@media print {
	.niramay-pdf-bar,
	.niramay-pdf-toolbar,
	.niramay-pdf-thumbs,
	.niramay-pdf-edge,
	.niramay-pdf-status,
	.niramay-pdf-error,
	.niramay-pdf-viewport {
		display: none !important;
	}

	.niramay-pdf-body,
	.niramay-pdf,
	.niramay-pdf-stage {
		display: block !important;
		height: auto !important;
		overflow: visible !important;
		background: #fff !important;
		padding: 0 !important;
	}

	.niramay-pdf-print-stack {
		display: block !important;
	}

	.niramay-pdf-print-stack canvas {
		display: block;
		width: 100%;
		height: auto;
		break-after: page;
		page-break-after: always;
	}

	.niramay-pdf-print-stack canvas:last-child {
		break-after: auto;
		page-break-after: auto;
	}
}

/* ----------------------------------------------------------------- responsive */

@media (max-width: 900px) {
	.niramay-pdf-bar {
		flex-wrap: wrap;
		gap: var(--nrm-space-2, 8px);
	}

	.niramay-pdf-meta {
		display: none;
	}

	.niramay-pdf-search input {
		width: 96px;
	}
}

@media (max-width: 720px) {
	.niramay-pdf-thumbs {
		position: absolute;
		top: 0;
		left: 0;
		bottom: 0;
		z-index: 5;
		width: 132px;
		box-shadow: var(--nrm-shadow, 0 5px 14px rgba(72, 72, 110, .10));
	}

	.niramay-pdf-viewport {
		padding: 10px;
	}

	.niramay-pdf-back-text {
		display: none;
	}

	.niramay-pdf-group-end {
		margin-left: 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	.niramay-pdf-page,
	.niramay-pdf-edge,
	.niramay-pdf-btn,
	.niramay-pdf-thumb {
		transition: none !important;
	}

	.niramay-pdf-spinner {
		animation-duration: 1600ms;
	}
}
