/**
 * Tecology Print & Membership Helper
 *
 * A "Download" control that reveals on hover inside any `.tec-printable`
 * container. Colours map to the active FSE theme palette
 * (--wp--preset--color--*) with sensible fallbacks.
 */

.tec-has-download {
	position: relative;
}

.tec-download {
	position: absolute;
	top: 12px;
	right: 12px;
	z-index: 5;
	display: inline-flex;
	align-items: center;
	gap: 0.4em;
	margin: 0;
	padding: 0.5em 0.85em;
	font-size: 0.85rem;
	font-weight: 600;
	line-height: 1.1;
	border: 1px solid transparent;
	border-radius: 8px;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	/* --tec-dl-* are set per-container by the block; fall back to the theme
	   palette, then to hard-coded neutrals. */
	color: var(--tec-dl-color, var(--wp--preset--color--base, #ffffff));
	background-color: var(--tec-dl-bg, var(--wp--preset--color--contrast, #1d2939));
	box-shadow: 0 2px 10px rgba(16, 24, 40, 0.18);

	/* Hidden until the container is hovered/focused. */
	opacity: 0;
	transform: translateY(-4px);
	pointer-events: none;
	transition: opacity 0.15s ease, transform 0.15s ease, background-color 0.15s ease;
}

.tec-download svg {
	width: 1.05em;
	height: 1.05em;
	flex: 0 0 auto;
	fill: currentColor;
}

/* Corner placement (default is top-right, set above). */
.tec-printable[data-dl-position='top-left'] .tec-download {
	right: auto;
	left: 12px;
}

.tec-printable[data-dl-position='bottom-right'] .tec-download {
	top: auto;
	bottom: 12px;
}

.tec-printable[data-dl-position='bottom-left'] .tec-download {
	top: auto;
	bottom: 12px;
	right: auto;
	left: 12px;
}

/* Busy / processing state. */
.tec-download.is-busy {
	cursor: progress;
	opacity: 0.9;
}

.tec-download .tec-spinner {
	fill: none;
	transform-origin: center;
	animation: tec-spin 0.7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
	.tec-download .tec-spinner {
		animation-duration: 1.6s;
	}
}

.tec-has-download:hover .tec-download,
.tec-has-download:focus-within .tec-download,
.tec-has-download .tec-download.is-busy,
.tec-printable.tec-dl-always .tec-download {
	opacity: 1;
	transform: none;
	pointer-events: auto;
}

/* Hover/focus works with any custom colour without needing a second value. */
.tec-download:hover,
.tec-download:focus-visible {
	filter: brightness(1.08);
}

.tec-download:focus-visible {
	outline: none;
	box-shadow: 0 0 0 3px rgba(16, 24, 40, 0.25);
}

/* Touch devices have no hover - keep the control visible and usable. */
@media (hover: none) {
	.tec-has-download .tec-download {
		opacity: 1;
		transform: none;
		pointer-events: auto;
	}
}

/* Never include the control in the printout. */
@media print {
	.tec-download {
		display: none !important;
	}
}

/* Hide the control while the container is being captured to PDF. */
.tec-capturing .tec-download {
	display: none !important;
}
