/**
 * Method Steps widget — layout, connecting line and scroll animation.
 *
 * Tablet and phone: a vertical timeline (number circle on the start side,
 * title and text beside it, a line running down between the circles).
 * Desktop (above Elementor's 1024px tablet breakpoint): the steps sit in one
 * row and the line runs across between the circles.
 *
 * Colors and typography come from the widget's Style controls (Elementor
 * Global Colors / Fonts by default), which set the custom properties below.
 * Logical properties keep RTL working; the line draws right-to-left in Arabic.
 */

.dns-branches-steps {
	/* Fallback only; the Style controls set every color below from the kit. */
	--dns-branches-steps-accent: var(--e-global-color-primary, CanvasText);
	--dns-branches-steps-gap: 32px;
	--dns-branches-steps-content-gap: 20px;
	--dns-branches-steps-text-gap: 8px;
	--dns-branches-steps-marker-size: 56px;
	--dns-branches-steps-marker-border: 2px;
	--dns-branches-steps-line-width: 2px;
	--dns-branches-steps-line-gap: 10px;
	--dns-branches-steps-delay: 350ms;
	--dns-branches-steps-done-color: #fff;
	--dns-branches-steps-done-bg: var(--dns-branches-steps-accent);
	--dns-branches-steps-pending-color: var(--dns-branches-steps-accent);
	--dns-branches-steps-pending-bg: transparent;
	--dns-branches-steps-fill: var(--dns-branches-steps-accent);
	--dns-branches-steps-track: color-mix(in srgb, var(--dns-branches-steps-fill) 18%, transparent);
}

@media (max-width: 767px) {
	.dns-branches-steps {
		--dns-branches-steps-gap: 28px;
		--dns-branches-steps-content-gap: 16px;
		--dns-branches-steps-marker-size: 48px;
	}
}

/* Vertical timeline (tablet and phone) ------------------------------------- */

/* (0,2,0) so theme list rules (e.g. `.entry-content ol`) cannot add
 * bullets, indents or margins. */
.dns-branches-steps .dns-branches-steps__list {
	display: flex;
	flex-direction: column;
	gap: var(--dns-branches-steps-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

.dns-branches-steps .dns-branches-steps__item {
	position: relative;
	display: grid;
	grid-template-columns: var(--dns-branches-steps-marker-size) minmax(0, 1fr);
	grid-template-areas:
		"marker title"
		".      text";
	column-gap: var(--dns-branches-steps-content-gap);
	align-items: start;
	margin: 0;
	padding: 0;
	/* Not inherited from a centered section: text sits beside the circles. */
	text-align: start;
}

/* Final ("Completed") look. While the animation waits, the
 * "Before animation" colors replace these (see Animation below). */
.dns-branches-steps__marker {
	position: relative;
	z-index: 1;
	grid-area: marker;
	display: inline-flex;
	flex: none;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	inline-size: var(--dns-branches-steps-marker-size);
	block-size: var(--dns-branches-steps-marker-size);
	border: var(--dns-branches-steps-marker-border) solid var(--dns-branches-steps-done-bg);
	border-radius: 50%;
	background-color: var(--dns-branches-steps-done-bg);
	color: var(--dns-branches-steps-done-color);
	box-shadow: 0 0 0 6px color-mix(in srgb, var(--dns-branches-steps-done-bg) 14%, transparent);
}

/* (0,1,0): the Number typography control always wins. */
.dns-branches-steps__number {
	font-size: 1.125rem;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	line-height: 1;
}

/* Font defaults come from the kit's heading / paragraph styles; only the
 * spacing is reset here, at (0,2,0), so theme margins cannot break the rhythm. */
.dns-branches-steps .dns-branches-steps__title {
	grid-area: title;
	display: flex;
	align-items: center;
	min-block-size: var(--dns-branches-steps-marker-size);
	margin: 0;
	padding: 0;
	overflow-wrap: anywhere;
}

.dns-branches-steps .dns-branches-steps__text {
	grid-area: text;
	margin: 0;
	margin-block-start: var(--dns-branches-steps-text-gap);
	padding: 0;
	overflow-wrap: anywhere;
}

/* The line from this circle to the next one: a faint track with a colored
 * fill (::before) that the animation scales in. */
.dns-branches-steps__line {
	position: absolute;
	inset-block-start: calc(var(--dns-branches-steps-marker-size) + var(--dns-branches-steps-line-gap));
	inset-inline-start: calc((var(--dns-branches-steps-marker-size) - var(--dns-branches-steps-line-width)) / 2);
	inline-size: var(--dns-branches-steps-line-width);
	block-size: calc(100% + var(--dns-branches-steps-gap) - var(--dns-branches-steps-marker-size) - 2 * var(--dns-branches-steps-line-gap));
	overflow: hidden;
	border-radius: var(--dns-branches-steps-line-width);
	background-color: var(--dns-branches-steps-track);
	pointer-events: none;
}

.dns-branches-steps__line::before {
	content: "";
	position: absolute;
	inset: 0;
	background-color: var(--dns-branches-steps-fill);
	transform-origin: center top;
}

/* Horizontal row (desktop) ------------------------------------------------- */

@media (min-width: 1025px) {
	.dns-branches-steps {
		/* Where the circle's center sits inside its column. */
		--dns-branches-steps-center: 50%;
	}

	.dns-branches-steps-align--start .dns-branches-steps {
		--dns-branches-steps-center: calc(var(--dns-branches-steps-marker-size) / 2);
	}

	.dns-branches-steps .dns-branches-steps__list {
		display: grid;
		grid-auto-columns: minmax(0, 1fr);
		grid-auto-flow: column;
	}

	.dns-branches-steps .dns-branches-steps__item {
		display: flex;
		flex-direction: column;
		align-items: center;
		text-align: center;
	}

	.dns-branches-steps-align--start .dns-branches-steps .dns-branches-steps__item {
		align-items: flex-start;
		text-align: start;
	}

	.dns-branches-steps .dns-branches-steps__title {
		display: block;
		min-block-size: 0;
		margin-block-start: var(--dns-branches-steps-content-gap);
	}

	/* From this circle's edge, across the column gap, to the next circle's edge. */
	.dns-branches-steps__line {
		inset-block-start: calc((var(--dns-branches-steps-marker-size) - var(--dns-branches-steps-line-width)) / 2);
		inset-inline-start: calc(var(--dns-branches-steps-center) + var(--dns-branches-steps-marker-size) / 2 + var(--dns-branches-steps-line-gap));
		inline-size: calc(100% + var(--dns-branches-steps-gap) - var(--dns-branches-steps-marker-size) - 2 * var(--dns-branches-steps-line-gap));
		block-size: var(--dns-branches-steps-line-width);
	}

	.dns-branches-steps__line::before {
		transform-origin: left center;
	}

	.dns-branches-steps__line:dir(rtl)::before {
		transform-origin: right center;
	}
}

/* Animation ----------------------------------------------------------------
 * method-steps.js adds [data-dns-branches-steps-ready] (only when the widget
 * asks for animation), then the --revealed class when the steps scroll into
 * view. Without JS, or with "reduce motion" on, the steps are simply shown.
 *
 * Timing (d = time per step, i = step index):
 *   step i fades in at i × d;
 *   circle i turns "Completed" at (i + 1) × d;
 *   line i draws from (i + 1) × d for d, so it reaches circle i + 1 exactly
 *   when that circle turns "Completed".
 * Transitions are declared on the revealed state only, so hiding the steps
 * before they scroll into view is instant. */

@media (prefers-reduced-motion: no-preference) {
	.dns-branches-steps[data-dns-branches-steps-ready]:not(.dns-branches-steps--revealed) .dns-branches-steps__item {
		opacity: 0;
		transform: translateY(16px);
	}

	.dns-branches-steps[data-dns-branches-steps-ready]:not(.dns-branches-steps--revealed) .dns-branches-steps__marker {
		border-color: var(--dns-branches-steps-pending-color);
		background-color: var(--dns-branches-steps-pending-bg);
		color: var(--dns-branches-steps-pending-color);
		box-shadow: none;
	}

	.dns-branches-steps[data-dns-branches-steps-ready]:not(.dns-branches-steps--revealed) .dns-branches-steps__line::before {
		transform: scaleY(0);
	}

	.dns-branches-steps--revealed .dns-branches-steps__item {
		transition: opacity 0.5s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
		transition-delay: calc(var(--dns-branches-steps-index) * var(--dns-branches-steps-delay));
	}

	.dns-branches-steps--revealed .dns-branches-steps__marker {
		transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease, box-shadow 0.45s ease;
		transition-delay: calc((var(--dns-branches-steps-index) + 1) * var(--dns-branches-steps-delay));
	}

	.dns-branches-steps--revealed .dns-branches-steps__line::before {
		transition: transform var(--dns-branches-steps-delay) linear calc((var(--dns-branches-steps-index) + 1) * var(--dns-branches-steps-delay));
	}
}

@media (prefers-reduced-motion: no-preference) and (min-width: 1025px) {
	.dns-branches-steps[data-dns-branches-steps-ready]:not(.dns-branches-steps--revealed) .dns-branches-steps__line::before {
		transform: scaleX(0);
	}
}

/* Editor-only empty state ---------------------------------------------------- */

.dns-branches-steps-empty {
	padding: 24px;
	border: 1px dashed rgba(0, 0, 0, 0.25);
	border-radius: 16px;
	text-align: center;
}

.dns-branches-steps-empty__title,
.dns-branches-steps-empty__text {
	margin: 0;
}

.dns-branches-steps-empty__title {
	margin-block-end: 4px;
	font-weight: 600;
}
