/**
 * PDF viewer — branded RTL presentation around the BROWSER's native PDF
 * renderer (never a JS library — PDF.js mis-renders Hebrew).
 *
 *   • Desktop: a framed <object> (native renderer) + slim toolbar.
 *   • Phones:  a card that opens the file in the device's native viewer.
 *
 * Progressive enhancement: the native <object>/link render normally until
 * pdf-viewer.js adds `.is-enhanced`; the hide rules are gated on that class,
 * so there is no FOUC and the PDF stays correct even if the script never runs.
 *
 * NOTE: every selector targets JS-injected markup, so this file is safelisted
 * against WP Rocket "Remove Unused CSS" in inc/assets.php
 * (hm_rocket_rucss_exclusions), and pdf-viewer.js is excluded from WP Rocket
 * "Delay JavaScript" (hm_rocket_delay_js_exclusions) so it enhances on load.
 *
 * @package Hamechadesh
 */

/* Native fallback links — hidden only once JS has enhanced the block.
   (The <object> is REUSED as the renderer on desktop, so it is not hidden;
   on the card path the whole block is a launcher and the object, if any,
   is hidden too.) */
.wp-block-file.hm-pdf.is-enhanced > a {
	display: none;
}
.wp-block-file.hm-pdf--launcher.is-enhanced > object {
	display: none;
}

.hm-pdf {
	margin-block: var(--hm-space-lg);
	max-width: 100%;
}

/* ================= Reader shell (desktop) ================= */
.hm-pdf__reader {
	border: 1px solid var(--hm-color-border);
	border-radius: var(--hm-radius-lg);
	background: var(--hm-color-bg-alt);
	box-shadow: var(--hm-shadow-md);
	overflow: hidden;
	font-family: var(--hm-font-primary);
}

.hm-pdf__toolbar {
	display: flex;
	align-items: center;
	gap: var(--hm-space-sm);
	padding: 8px 12px;
	background: var(--hm-color-bg-alt);
	border-bottom: 1px solid var(--hm-color-border);
}

.hm-pdf__name {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	flex: 1 1 auto;
	min-width: 0;
	color: var(--hm-color-text);
	font-size: var(--hm-font-size-sm);
	font-weight: 700;
}

.hm-pdf__name svg {
	flex: 0 0 auto;
	width: 20px;
	height: 20px;
	color: var(--hm-color-accent);
}

.hm-pdf__name-text {
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	unicode-bidi: isolate;
}

.hm-pdf__tools {
	display: flex;
	align-items: center;
	gap: 2px;
	flex: 0 0 auto;
}

.hm-pdf__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 36px;
	height: 36px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--hm-color-text);
	cursor: pointer;
	text-decoration: none;
	-webkit-tap-highlight-color: transparent;
	transition: background-color var(--hm-transition-fast),
		color var(--hm-transition-fast),
		transform var(--hm-transition-fast);
}

.hm-pdf__btn svg {
	display: block;
	width: 20px;
	height: 20px;
}

.hm-pdf__btn:hover {
	background: rgba(33, 33, 33, 0.06);
}

.hm-pdf__btn:active {
	transform: scale(0.92);
}

.hm-pdf__btn:focus-visible {
	outline: 2px solid var(--hm-color-accent);
	outline-offset: 2px;
}

/* The native renderer. */
.hm-pdf__frame {
	background: var(--hm-color-bg);
}

.hm-pdf__object {
	display: block;
	width: 100%;
	height: min(78vh, 900px);
	border: 0;
}

/* ================= Launcher card (phones / no inline PDF) ================= */
.hm-pdf__card {
	display: flex;
	align-items: center;
	gap: var(--hm-space-md);
	flex-wrap: wrap;
	padding: var(--hm-space-md) var(--hm-space-lg);
	border: 1px solid var(--hm-color-border);
	border-radius: var(--hm-radius-lg);
	background: var(--hm-color-bg-alt);
	box-shadow: var(--hm-shadow-sm);
	font-family: var(--hm-font-primary);
}

.hm-pdf__card-icon svg {
	width: 34px;
	height: 34px;
	color: var(--hm-color-accent);
	display: block;
}

.hm-pdf__card-name {
	flex: 1 1 auto;
	min-width: 0;
	font-weight: 700;
	color: var(--hm-color-text);
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	unicode-bidi: isolate;
}

.hm-pdf__card-open {
	flex: 0 0 auto;
	padding: 9px 22px;
	border: 0;
	border-radius: 999px;
	background: var(--hm-color-accent);
	color: #fff;
	font-family: inherit;
	font-size: var(--hm-font-size-sm);
	font-weight: 700;
	text-decoration: none;
	cursor: pointer;
	transition: filter var(--hm-transition-fast);
}

.hm-pdf__card-open:hover {
	filter: brightness(1.08);
}

.hm-pdf__card-open:focus-visible {
	outline: 2px solid var(--hm-color-accent);
	outline-offset: 2px;
}

.hm-pdf__card-dl {
	flex: 0 0 auto;
	color: var(--hm-color-link);
	font-size: var(--hm-font-size-sm);
	font-weight: 700;
	text-decoration: none;
}

.hm-pdf__card-dl:hover {
	text-decoration: underline;
}

/* ================= Fullscreen overlay (native <iframe>) ================= *
 * position:fixed overlay. Registered in $unzoom (generate-fit-desktop-css.php)
 * so it renders at real size under the desktop scale-to-fit zoom.
 */
.hm-pdf-viewer__fullscreen {
	position: fixed;
	inset: 0;
	z-index: calc(var(--hm-z-modal) + 10);
	display: flex;
	flex-direction: column;
	background: rgba(18, 18, 18, 0.94);
	opacity: 0;
	visibility: hidden;
	transition: opacity var(--hm-transition-base), visibility var(--hm-transition-base);
}

.hm-pdf-viewer__fullscreen.is-open {
	opacity: 1;
	visibility: visible;
}

.hm-pdf-viewer__fullscreen .hm-pdf__toolbar {
	flex: 0 0 auto;
	background: rgba(0, 0, 0, 0.4);
	border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.hm-pdf-viewer__fullscreen .hm-pdf__name {
	color: #fff;
}

.hm-pdf-viewer__fullscreen .hm-pdf__btn {
	color: #f3f3f3;
}

.hm-pdf-viewer__fullscreen .hm-pdf__btn:hover {
	background: rgba(255, 255, 255, 0.14);
}

.hm-pdf__iframe {
	flex: 1 1 auto;
	width: 100%;
	border: 0;
	background: #fff;
}

.hm-pdf-noscroll {
	overflow: hidden;
}

/* ================= Responsive ================= */
@media (max-width: 600px) {
	.hm-pdf__toolbar {
		gap: 4px;
		padding: 6px 8px;
	}

	.hm-pdf__object {
		height: 70vh;
	}

	.hm-pdf__btn {
		width: 34px;
		height: 34px;
	}

	.hm-pdf__card {
		padding: var(--hm-space-md);
		row-gap: var(--hm-space-sm);
	}

	/* Icon + filename share the first row; the two actions wrap to their own
	   row and split the width. */
	.hm-pdf__card-name {
		flex: 1 1 auto;
	}

	.hm-pdf__card-open {
		flex: 1 1 auto;
		text-align: center;
		order: 1;
	}

	.hm-pdf__card-dl {
		order: 2;
	}
}

@media (prefers-reduced-motion: reduce) {
	.hm-pdf__btn,
	.hm-pdf-viewer__fullscreen {
		transition: none;
	}
}
