/**
 * CTA Cards widget.
 *
 * Every tunable is a custom property set by the widget's controls, so this file
 * holds structure and the defaults, and Elementor only ever writes variables.
 *
 * @package GEMTech_Elementor_AddOns
 */

.gemtech-cta-cards {
	--gtea-cta-cols: 3;
	--gtea-cta-gap: 20px;
	--gtea-cta-ratio: 4 / 3;

	--gtea-cta-img-scale: 1.1;
	--gtea-cta-img-duration: 500ms;

	--gtea-cta-arrow-size: 28px;
	--gtea-cta-arrow-x: 18px;
	--gtea-cta-arrow-y: 14px;
	--gtea-cta-arrow-gap: 24px;
	--gtea-cta-arrow-travel: 10px;
	--gtea-cta-arrow-duration: 500ms;

	--gtea-cta-anim-duration: 500ms;
	--gtea-cta-anim-distance: 50px;
	--gtea-cta-anim-easing: ease;
	--gtea-cta-from-opacity: 0;
	--gtea-cta-from-transform: translateY(var(--gtea-cta-anim-distance));

	--gtea-cta-card-lift: 0px;
}

/* -------------------------------------------------------------------------
   Grid
   ---------------------------------------------------------------------- */

.gemtech-cta-cards__grid {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: var(--gtea-cta-gap);
}

/*
 * Flex rather than grid so a partly-filled last row can centre under the rest.
 * The width subtracts each card's share of the gaps between them — (n-1) gaps
 * spread across n cards — which is what makes any column count divide exactly.
 */
.gemtech-cta-cards__item {
	display: flex;
	flex: 0 0 auto;
	width: calc(
		100% / var(--gtea-cta-cols) -
		var(--gtea-cta-gap) * (var(--gtea-cta-cols) - 1) / var(--gtea-cta-cols)
	);
	min-width: 0;
}

/* -------------------------------------------------------------------------
   Card
   ---------------------------------------------------------------------- */

.gemtech-cta-cards__card {
	display: flex;
	flex-direction: column;
	width: 100%;
	background: #fff;
	color: inherit;
	text-decoration: none;
	overflow: hidden;
	transition: transform var(--gtea-cta-img-duration) ease,
		box-shadow var(--gtea-cta-img-duration) ease,
		background-color var(--gtea-cta-img-duration) ease;
}

.gemtech-cta-cards__card:hover,
.gemtech-cta-cards__card:focus-visible {
	transform: translateY(var(--gtea-cta-card-lift));
}

.gemtech-cta-cards__card:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 3px;
}

/* -------------------------------------------------------------------------
   Media
   ---------------------------------------------------------------------- */

/*
 * aspect-ratio governs the height until the widget's Fixed Height control
 * writes an explicit one. A box with both width and height definite ignores
 * aspect-ratio, so the override wins without needing extra specificity.
 */
.gemtech-cta-cards__media {
	position: relative;
	width: 100%;
	aspect-ratio: var(--gtea-cta-ratio);
	overflow: hidden;
	flex: 0 0 auto;
}

.gemtech-cta-cards__image {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform var(--gtea-cta-img-duration) ease;
}

.gemtech-cta-cards__card:hover .gemtech-cta-cards__image,
.gemtech-cta-cards__card:focus-visible .gemtech-cta-cards__image {
	transform: scale(var(--gtea-cta-img-scale));
}

/* -------------------------------------------------------------------------
   Body
   ---------------------------------------------------------------------- */

/*
 * The body grows to fill whatever height the tallest card sets, which is what
 * keeps every arrow on the same line across the row.
 */
.gemtech-cta-cards__body {
	/* Published by the Body Padding control; the arrow offsets use them. */
	--gtea-cta-body-pr: 24px;
	--gtea-cta-body-pb: 24px;
	position: relative;
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	padding: 24px;
}

.gemtech-cta-cards__title {
	margin: 0 0 10px;
	max-width: 75%;
	transition: color var(--gtea-cta-arrow-duration) ease;
}

.gemtech-cta-cards__desc {
	margin: 0;
}

/*
 * The description is rich text. Themes and the Elementor kit often style p and
 * li directly, which would override the widget's own typography and colour
 * controls (they target the wrapper), so the inner blocks inherit instead.
 */
.gemtech-cta-cards__desc :is(p, ul, ol, li, blockquote) {
	color: inherit;
	font-family: inherit;
	font-size: inherit;
	line-height: inherit;
	letter-spacing: inherit;
}

.gemtech-cta-cards__desc :is(p, ul, ol, blockquote) {
	margin: 0 0 0.75em;
}

.gemtech-cta-cards__desc :is(ul, ol) {
	padding-left: 1.25em;
}

.gemtech-cta-cards__desc > :last-child {
	margin-bottom: 0;
}

/* -------------------------------------------------------------------------
   Arrow
   ---------------------------------------------------------------------- */

/*
 * The arrow (and its optional text) sits in the flow, last in the body, so the
 * text can never run into it and Top Spacing is an exact gap whatever the
 * icon's proportions. The positioning lives on the __cta wrapper so the arrow
 * and its text move as one unit.
 *
 * (It used to be absolutely positioned, which meant guessing its height to
 * reserve a lane — and the Body Padding control overrode that lane anyway,
 * leaving the arrow beside the last line of text.)
 *
 * margin-top: auto drops it to the bottom of a card stretched by a taller
 * neighbour, keeping arrows level across the row; padding-top is the minimum
 * gap above it. The margins turn Offset Right / Offset Bottom back into
 * distances from the body's outer edges, as they were when absolute, by
 * cancelling out the body's own padding.
 */
.gemtech-cta-cards__cta {
	align-self: flex-end;
	margin-top: auto;
	margin-right: calc(var(--gtea-cta-arrow-x) - var(--gtea-cta-body-pr));
	margin-bottom: calc(var(--gtea-cta-arrow-y) - var(--gtea-cta-body-pb));
	padding-top: var(--gtea-cta-arrow-gap);
	display: flex;
	align-items: center;
	gap: var(--gtea-cta-arrow-text-gap, 10px);
	transition: transform var(--gtea-cta-arrow-duration) ease;
}

.gemtech-cta-cards__cta-text {
	font-weight: 600;
	line-height: 1.2;
	color: #78767a;
	transition: color var(--gtea-cta-arrow-duration) ease;
}

.gemtech-cta-cards__arrow {
	display: block;
	line-height: 0;
	color: #78767a;
	transition: transform var(--gtea-cta-arrow-duration) ease,
		color var(--gtea-cta-arrow-duration) ease;
}

.gemtech-cta-cards__card:hover .gemtech-cta-cards__arrow,
.gemtech-cta-cards__card:focus-visible .gemtech-cta-cards__arrow {
	transform: translateX(var(--gtea-cta-arrow-travel));
}

/*
 * With the text after the arrow, moving only the arrow would push it into the
 * text, so the pair travels together instead.
 */
.gemtech-cta-cards__card:hover .gemtech-cta-cards__cta--text-after,
.gemtech-cta-cards__card:focus-visible .gemtech-cta-cards__cta--text-after {
	transform: translateX(var(--gtea-cta-arrow-travel));
}

.gemtech-cta-cards__card:hover .gemtech-cta-cards__cta--text-after .gemtech-cta-cards__arrow,
.gemtech-cta-cards__card:focus-visible .gemtech-cta-cards__cta--text-after .gemtech-cta-cards__arrow {
	transform: none;
}

.gemtech-cta-cards__arrow svg {
	display: inline-block;
	width: var(--gtea-cta-arrow-size);
	height: auto;
	fill: none;
}

/* An Elementor icon font renders as <i>, which is sized by font-size. */
.gemtech-cta-cards__arrow i {
	font-size: var(--gtea-cta-arrow-size);
	line-height: 1;
}

/* -------------------------------------------------------------------------
   Scroll animation
   ---------------------------------------------------------------------- */

/*
 * One keyframe pair serves every effect: the Effect control sets the opacity
 * and transform the card starts from, and the resting state is always the same.
 */
@keyframes gtea-cta-in {
	from {
		opacity: var(--gtea-cta-from-opacity);
		transform: var(--gtea-cta-from-transform);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

.gemtech-cta-cards--animated .gemtech-cta-cards__item {
	opacity: var(--gtea-cta-from-opacity);
	transform: var(--gtea-cta-from-transform);
	will-change: opacity, transform;
}

.gemtech-cta-cards--animated .gemtech-cta-cards__item.is-visible {
	animation: gtea-cta-in var(--gtea-cta-anim-duration) var(--gtea-cta-anim-easing) both;
}

/*
 * If the script never runs — an old browser, a JS error elsewhere on the page,
 * a blocked bundle — cards must not stay invisible. The class is set as soon as
 * the script initialises, so its absence means nothing will ever reveal them.
 */
.gemtech-cta-cards--animated:not(.gemtech-cta-cards--observing) .gemtech-cta-cards__item {
	opacity: 1;
	transform: none;
}

/* -------------------------------------------------------------------------
   Reduced motion
   ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.gemtech-cta-cards--animated .gemtech-cta-cards__item,
	.gemtech-cta-cards--animated .gemtech-cta-cards__item.is-visible {
		opacity: 1;
		transform: none;
		animation: none;
	}

	.gemtech-cta-cards__card,
	.gemtech-cta-cards__image,
	.gemtech-cta-cards__cta,
	.gemtech-cta-cards__cta-text,
	.gemtech-cta-cards__arrow,
	.gemtech-cta-cards__title {
		transition: none;
	}

	.gemtech-cta-cards__card:hover .gemtech-cta-cards__image,
	.gemtech-cta-cards__card:focus-visible .gemtech-cta-cards__image,
	.gemtech-cta-cards__card:hover .gemtech-cta-cards__arrow,
	.gemtech-cta-cards__card:focus-visible .gemtech-cta-cards__arrow,
	.gemtech-cta-cards__card:hover .gemtech-cta-cards__cta,
	.gemtech-cta-cards__card:focus-visible .gemtech-cta-cards__cta,
	.gemtech-cta-cards__card:hover,
	.gemtech-cta-cards__card:focus-visible {
		transform: none;
	}
}
