/**
 * UX Enhancements - Ernesto Theme
 * Back to Top, Sticky Header, Infinite Scroll, Reading Time
 *
 * @package Ernesto
 * @since 1.0.0
 */

/* ============================================
   1. BACK TO TOP BUTTON
   ============================================ */

.back-to-top {
	position: fixed;
	bottom: var(--space-xl);
	right: var(--space-xl);
	z-index: 999;
	width: 48px;
	height: 48px;
	padding: 0;
	border-radius: 50%;
	background-color: var(--color-primary);
	color: var(--text-on-brand);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--shadow-md);
	transition: opacity 0.4s ease, visibility 0.4s ease,
	            background-color 0.2s ease, transform 0.2s ease;
	opacity: 0;
	visibility: hidden;
	transform: translateY(8px);
}

.back-to-top.visible {
	opacity: 0.72;
	visibility: visible;
	transform: translateY(0);
}

.back-to-top:hover,
.back-to-top:focus-visible {
	opacity: 1;
	background-color: var(--color-primary-hover);
	transform: scale(1.08);
}

.back-to-top:active {
	transform: scale(0.95);
	transition-duration: 0.1s;
}

.back-to-top:focus-visible {
	outline: 3px solid var(--text-on-brand);
	outline-offset: 4px;
}

.back-to-top svg {
	/* Override the global svg { height: auto; max-width: 100% } reset.
	   flex-shrink: 0 prevents the SVG collapsing to width: 0 inside the flex button. */
	width: 20px;
	min-width: 20px;
	height: 20px;
	flex-shrink: 0;
	pointer-events: none;
}

/* Mobile positioning */
@media (max-width: 768px) {
	.back-to-top {
		bottom: var(--space-lg);
		right: var(--space-lg);
		width: 44px;
		height: 44px;
	}

	.back-to-top svg {
		width: 20px;
		height: 20px;
	}
}

/* Hide on print */
@media print {
	.back-to-top {
		display: none;
	}
}

/* ============================================
   2. STICKY HEADER
   ============================================ */

.has-sticky-header .site-header {
	position: sticky;
	top: 0;
	z-index: 998;
	background-color: var(--bg-body);
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0);
	transition: box-shadow var(--transition-fast),
	            background-color var(--transition-fast);
}

.has-sticky-header .site-header.scrolled {
	box-shadow: var(--shadow-md);
	background-color: var(--bg-surface);
}

/* Compact header when scrolled */
.has-sticky-header .site-header.scrolled .site-branding {
	padding: var(--space-sm) 0;
}

.has-sticky-header .site-header.scrolled .custom-logo {
	max-height: 40px;
	transition: max-height var(--transition-fast);
}

/* ============================================
   3. INFINITE SCROLL
   ============================================ */

.infinite-scroll-container {
	position: relative;
}

.infinite-scroll-loading {
	display: none;
	text-align: center;
	padding: var(--space-xl) 0;
}

.infinite-scroll-loading.active {
	display: block;
}

.infinite-scroll-spinner {
	width: 40px;
	height: 40px;
	margin: 0 auto;
	border: 4px solid var(--border-color);
	border-top-color: var(--color-primary);
	border-radius: 50%;
	animation: spinner 0.8s linear infinite;
}

@keyframes spinner {
	to {
		transform: rotate(360deg);
	}
}

.infinite-scroll-message {
	text-align: center;
	padding: var(--space-lg) 0;
	color: var(--text-muted);
	font-size: var(--font-size-sm);
}

.infinite-scroll-error {
	text-align: center;
	padding: var(--space-lg);
	background-color: var(--color-error-bg);
	color: var(--color-error-text);
	border-radius: var(--border-radius-md);
	margin: var(--space-lg) 0;
}

/* Hide default pagination when infinite scroll is active */
.has-infinite-scroll .pagination,
.has-infinite-scroll .navigation {
	display: none;
}

/* ============================================
   4. READING TIME
   ============================================ */

.reading-time {
	display: inline-flex;
	align-items: center;
	gap: 0.25rem;
	font-size: var(--font-size-sm);
	color: var(--text-muted);
	font-weight: var(--font-weight-normal);
}

.reading-time svg {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
}

.entry-meta .reading-time {
	margin-left: var(--space-sm);
}

/* ============================================
   5. SOCIAL SHARING BUTTONS
   ============================================ */

.social-sharing {
	display: flex;
	gap: var(--space-xs, 0.25rem);
	align-items: center;
	flex-wrap: wrap;
	margin: var(--space-xl) 0;
	padding: var(--space-lg) 0;
	border-top: 1px solid var(--border-color);
	border-bottom: 1px solid var(--border-color);
	max-width: var(--container-width);
	margin-left: auto;
	margin-right: auto;
}

.social-sharing-label {
	font-size: var(--font-size-sm, 0.875rem);
	font-weight: var(--font-weight-semibold);
	margin-right: var(--space-xs, 0.25rem);
	color: var(--text-muted);
}

/* ── Base button ─────────────────────────────────────────────────────── */

.social-share-button {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	padding: 7px;
	background: transparent;
	border: none;
	border-radius: var(--border-radius-sm, 4px);
	cursor: pointer;
	color: var(--color-secondary, #64748B);
	transition: opacity 0.15s ease, transform 0.15s ease, color 0.15s ease;
	text-decoration: none;
}

/* JS-toggled buttons (share-native, share-copy) start hidden;
   JS adds .is-visible when the right one is chosen. */
.share-native,
.share-copy {
	display: none;
}

.social-share-button.is-visible {
	display: inline-flex;
}

.social-share-button:hover {
	opacity: 0.65;
	transform: scale(1.15);
}

.social-share-button:focus-visible {
	outline: 2px solid var(--color-primary);
	outline-offset: 3px;
	border-radius: var(--border-radius-sm, 4px);
}

.social-share-button svg {
	width: 100%;
	height: 100%;
	fill: currentColor;
	display: block;
	/* Bounding-box rect inside SVGs uses .cls-1 { fill:none } via inline style — untouched */
}

/* ── Tooltip ─────────────────────────────────────────────────────────── */

.social-share-button::after {
	content: attr(data-tooltip);
	position: absolute;
	bottom: calc(100% + 6px);
	left: 50%;
	transform: translateX(-50%) translateY(4px);
	background: var(--text-main, #1a1a1b);
	color: var(--bg-main, #fff);
	font-size: 0.68rem;
	white-space: nowrap;
	padding: 3px 8px;
	border-radius: 4px;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.15s ease, transform 0.15s ease;
	z-index: 10;
}

.social-share-button:hover::after {
	opacity: 1;
	transform: translateX(-50%) translateY(0);
}

/* ── State variants ──────────────────────────────────────────────────── */

/* Copy: flash success color when copied */
.share-copy--copied {
	color: var(--color-success, #28A745) !important;
}


/* ── QR Code modal ───────────────────────────────────────────────────── */

.ernesto-qr-modal {
	position: fixed;
	border: 1px solid var(--border-color, #dee2e6);
	border-radius: var(--border-radius-md, 6px);
	padding: 0;
	max-width: 260px;
	width: 90vw;
	background: var(--bg-main, #fff);
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.ernesto-qr-modal::backdrop {
	background: rgba(0, 0, 0, 0.45);
}

.ernesto-qr-modal__inner {
	padding: var(--space-lg, 1.5rem);
	text-align: center;
	position: relative;
}

.ernesto-qr-modal__close {
	position: absolute;
	top: 0.5rem;
	right: 0.5rem;
	background: none;
	border: none;
	cursor: pointer;
	font-size: 1rem;
	line-height: 1;
	padding: 4px 8px;
	color: var(--text-muted, #6c757d);
	border-radius: 4px;
	transition: opacity 0.15s;
}

.ernesto-qr-modal__close:hover {
	opacity: 0.6;
}

.ernesto-qr-modal__title {
	font-size: var(--font-size-sm, 0.875rem);
	font-weight: var(--font-weight-semibold);
	margin: 0 0 var(--space-md, 1rem) 0;
	color: var(--text-main);
}

.ernesto-qr-canvas {
	display: inline-block;
}

.ernesto-qr-canvas img,
.ernesto-qr-canvas canvas {
	display: block;
	max-width: 200px;
	height: auto;
	margin: 0 auto;
}

.ernesto-qr-modal__url {
	font-size: 0.65rem;
	word-break: break-all;
	color: var(--text-muted, #6c757d);
	margin: var(--space-sm, 0.5rem) 0 0 0;
}

.ernesto-qr-modal__fallback {
	font-size: 0.75rem;
	word-break: break-all;
	padding: var(--space-md, 1rem);
	border: 1px dashed var(--border-color);
	border-radius: var(--border-radius-sm, 4px);
	color: var(--text-muted);
	margin: 0;
}

/* ── Mobile ──────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
	.social-share-button {
		width: 40px;
		height: 40px;
		padding: 8px;
	}
}

/* ============================================
   6. LAZY LOAD VIDEOS (Placeholders)
   ============================================ */

.video-container {
	position: relative;
	padding-bottom: 56.25%; /* 16:9 */
	height: 0;
	overflow: hidden;
	background-color: #000000;
	border-radius: var(--border-radius-md);
	margin: var(--space-lg) 0;
}

.video-container iframe,
.video-container object,
.video-container embed {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	border: 0;
}

.video-placeholder {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-size: cover;
	background-position: center;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}

.video-placeholder::before {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, 0.3);
	transition: background-color var(--transition-fast);
}

.video-placeholder:hover::before {
	background-color: rgba(0, 0, 0, 0.5);
}

.video-play-button {
	position: relative;
	width: 80px;
	height: 80px;
	background-color: var(--color-primary);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all var(--transition-fast);
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.video-placeholder:hover .video-play-button {
	transform: scale(1.1);
	background-color: var(--color-primary-hover);
}

.video-play-button::after {
	content: '';
	width: 0;
	height: 0;
	border-style: solid;
	border-width: 15px 0 15px 26px;
	border-color: transparent transparent transparent #FFFFFF;
	margin-left: 4px;
}

/* ============================================
   7. REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
	.back-to-top,
	.social-share-button,
	.video-play-button {
		transition: none;
	}

	.infinite-scroll-spinner {
		animation: none;
		border-top-color: var(--color-primary);
		border-right-color: var(--color-primary);
	}
}

.reduced-motion .back-to-top,
.reduced-motion .social-share-button,
.reduced-motion .video-play-button {
	transition: none;
}

/* ============================================
   8. PRINT
   ============================================ */

@media print {
	.back-to-top,
	.social-sharing,
	.infinite-scroll-loading {
		display: none;
	}
}
