/**
 * CF7 Multistep Wizard
 *
 * Deliberately low-specificity and colour-token driven so a theme can restyle
 * it by redefining the custom properties instead of fighting !important.
 */

.ms-form {
	--ms-accent: #2563eb;
	--ms-accent-contrast: #fff;
	--ms-line: #d4d8de;
	--ms-muted: #6b7280;
	--ms-error: #dc2626;
	--ms-num-bg: #fff;
	--ms-radius: 6px;
}

/* Hide steps 2..n before the JS runs, but only when JS is available, so a
   no-JS visitor still sees (and can submit) the whole form as one page. */
.cf7ms-js .ms-step:not(.is-active) {
	display: none;
}

.ms-step[hidden] {
	display: none !important;
}

.ms-step {
	border: 0;
	margin: 0;
	padding: 0;
	min-width: 0; /* fieldsets refuse to shrink inside flex/grid without this */
}

/* ---------- progress bar ---------- */

/*
 * Themes and page builders style bare <button> and <ol> elements heavily -
 * Elementor's kit CSS especially - and those rules repaint the progress track
 * into a row of filled blocks with invisible numbers. The !important run below
 * neutralises that. It is scoped to .ms-progress throughout, so none of it can
 * leak into the rest of the page.
 */

.ms-form .ms-progress {
	display: flex;
	list-style: none;
	margin: 0 0 2.5em;
	padding: 0;
	gap: 0;
	background: none;
	border: 0;
}

.ms-form .ms-progress__item {
	flex: 1 1 0;
	position: relative;
	margin: 0;
	padding: 0;
	min-width: 0;
	text-align: center;
	list-style: none;
	background: none;
	border: 0;
}

.ms-form .ms-progress__item::marker {
	content: "";
}

/* Connecting rule, drawn behind the number bubbles. */
.ms-form .ms-progress__item::before {
	content: "";
	position: absolute;
	top: 15px;
	left: -50%;
	width: 100%;
	height: 2px;
	background: var(--ms-line);
	z-index: 0;
}

.ms-form .ms-progress__item:first-child::before {
	display: none;
}

.ms-form .ms-progress__item.is-done::before,
.ms-form .ms-progress__item.is-current::before {
	background: var(--ms-accent);
}

.ms-form .ms-progress__btn,
.ms-form .ms-progress__btn:hover,
.ms-form .ms-progress__btn:focus,
.ms-form .ms-progress__btn:active {
	display: flex !important;
	flex-direction: column !important;
	align-items: center !important;
	gap: 6px !important;
	width: 100% !important;
	min-height: 0 !important;
	min-width: 0 !important;
	margin: 0 !important;
	padding: 0 !important;
	background: none !important;
	background-color: transparent !important;
	border: 0 !important;
	border-radius: 0 !important;
	box-shadow: none !important;
	font: inherit !important;
	line-height: 1.3 !important;
	letter-spacing: normal !important;
	text-transform: none !important;
	text-decoration: none !important;
	text-shadow: none !important;
	cursor: default !important;
	position: relative;
	z-index: 1;
}

.ms-form .ms-progress__item.is-reachable .ms-progress__btn {
	cursor: pointer !important;
}

.ms-form .ms-progress__num {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	/* Set explicitly, not inherited: the theme's button colour is often white,
	   which would put white digits on a white bubble. */
	border: 2px solid var(--ms-line);
	background: var(--ms-num-bg);
	color: var(--ms-muted);
	font-size: 14px;
	line-height: 1;
	font-weight: 600;
	transition: background-color .18s, border-color .18s, color .18s;
}

.ms-form .ms-progress__label {
	font-size: 13px;
	line-height: 1.3;
	font-weight: 400;
	color: var(--ms-muted);
	/* Long section titles wrap rather than blowing out the track. */
	overflow-wrap: anywhere;
}

.ms-form .ms-progress__item.is-done .ms-progress__num {
	border-color: var(--ms-accent);
	color: var(--ms-accent);
}

.ms-form .ms-progress__item.is-current .ms-progress__num {
	border-color: var(--ms-accent);
	background: var(--ms-accent);
	color: var(--ms-accent-contrast);
}

.ms-form .ms-progress__item.is-current .ms-progress__label {
	color: var(--ms-accent);
	font-weight: 600;
}

.ms-form .ms-progress__item.is-done .ms-progress__label {
	color: var(--ms-accent);
}

.ms-form .ms-progress__btn:focus-visible {
	outline: 2px solid var(--ms-accent) !important;
	outline-offset: 3px;
}

/* Below ~600px the labels stop fitting; keep the numbered track only. */
@media (max-width: 600px) {
	.ms-form .ms-progress__label {
		display: none;
	}
}

/* ---------- step navigation ---------- */

.ms-nav {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
	margin-top: 1.75em;
}

/* Push Next/Submit to the right when a Back button precedes it. */
.ms-btn--back {
	margin-right: auto;
}

.ms-form .ms-btn,
.ms-form .ms-btn:hover,
.ms-form .ms-btn:focus {
	font: inherit;
	line-height: 1;
	padding: 0.85em 1.6em;
	margin: 0;
	border-radius: var(--ms-radius);
	border: 2px solid var(--ms-accent);
	box-shadow: none;
	text-transform: none;
	letter-spacing: normal;
	text-decoration: none;
	cursor: pointer;
}

.ms-form .ms-btn--next,
.ms-form .ms-btn--next:hover,
.ms-form .ms-btn--next:focus {
	background: var(--ms-accent);
	color: var(--ms-accent-contrast);
}

.ms-form .ms-btn--back,
.ms-form .ms-btn--back:hover,
.ms-form .ms-btn--back:focus {
	background: transparent;
	color: var(--ms-accent);
}

.ms-form .ms-btn:focus-visible {
	outline: 2px solid var(--ms-accent);
	outline-offset: 2px;
}

/* ---------- validation ---------- */

.ms-form .wpcf7-not-valid {
	border-color: var(--ms-error);
}

.ms-form .wpcf7-not-valid-tip {
	display: block;
	margin-top: 4px;
	font-size: 0.875em;
	color: var(--ms-error);
}

/* Radio/checkbox groups are spans; a red border round them looks broken. */
.ms-form span.wpcf7-not-valid {
	border: 0;
}

/* Screen-reader-only step announcement, in case the theme lacks the class. */
.ms-live {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

@media (prefers-reduced-motion: reduce) {
	.ms-progress__num {
		transition: none;
	}
}

/* ---------- question scaffolding ---------- */

.ms-step__title {
	margin: 0 0 0.25em;
}

.ms-step__intro {
	margin: 0 0 2em;
	color: var(--ms-muted);
}

.ms-q {
	margin: 0 0 1.75em;
}

.ms-q > label,
.ms-q__label {
	display: block;
	margin-bottom: 0.4em;
	font-weight: 600;
}

.ms-req {
	color: var(--ms-error);
}

.ms-help {
	display: block;
	margin: 0.2em 0 0.5em;
	font-size: 0.875em;
	font-weight: 400;
	color: var(--ms-muted);
}

/* ---------- checkbox / radio lists ---------- */

/* CF7 lays choices out inline; stack them the way Google Forms does. */
.ms-form .ms-choices .wpcf7-list-item {
	display: block !important;
	margin: 0 0 0.4em !important;
}

.ms-form .ms-choices .wpcf7-list-item label {
	display: flex !important;
	align-items: baseline;
	gap: 0.55em;
	margin: 0;
	font-weight: 400;
	cursor: pointer;
}

/* ---------- linear scale (Google Forms "1..5" question) ---------- */

/*
 * The layout child here is CF7's own .wpcf7-form-control-wrap span, NOT the
 * .wpcf7-radio group inside it. Style the group and forget the wrapper, and
 * the scale collapses to the left with the end labels stranded above and
 * below it. A three-column grid also survives the wrapper being displayed
 * inline or block by the theme, which flex did not.
 *
 * Layout-critical rules carry !important for the same reason the progress bar
 * does: page builders style bare spans inside forms aggressively.
 */

.ms-form .ms-scale {
	margin: 0 0 2em;
}

.ms-form .ms-scale__row {
	display: grid !important;
	grid-template-columns: auto minmax(0, 1fr) auto;
	align-items: center;
	gap: 0.5em 1em;
}

/*
 * wpcf7_autop is switched off for multistep forms (see cf7-multistep.php), but
 * if it is ever re-enabled it wraps this row's contents in a <p>. Hand the
 * grid down to that <p> rather than letting the row collapse.
 */
.ms-form .ms-scale__row > p {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	align-items: center;
	gap: 0.5em 1em;
	grid-column: 1 / -1;
	margin: 0;
}

.ms-form .ms-scale__row br {
	display: none;
}

.ms-form .ms-scale__end {
	font-size: 0.875em;
	font-weight: 400;
	line-height: 1.3;
	color: var(--ms-muted);
}

.ms-form .ms-scale__row .wpcf7-form-control-wrap {
	display: block !important;
	width: 100%;
	margin: 0 !important;
	padding: 0 !important;
}

.ms-form .ms-scale .wpcf7-radio {
	display: flex !important;
	justify-content: space-between;
	align-items: flex-end;
	width: 100%;
	gap: 0.25em;
}

.ms-form .ms-scale .wpcf7-list-item {
	flex: 1 1 0;
	min-width: 0;
	margin: 0 !important;
	text-align: center;
}

/* column-reverse puts the number above its radio button. */
.ms-form .ms-scale .wpcf7-list-item label {
	display: flex !important;
	flex-direction: column-reverse;
	align-items: center;
	gap: 0.45em;
	margin: 0;
	font-weight: 400;
	cursor: pointer;
}

.ms-form .ms-scale .wpcf7-list-item-label {
	font-size: 0.9375em;
	line-height: 1;
}

.ms-form .ms-scale .wpcf7-list-item input[type="radio"] {
	margin: 0;
}

/* Side-by-side end labels stop fitting on a narrow column; stack instead. */
@media (max-width: 620px) {
	.ms-form .ms-scale__row,
	.ms-form .ms-scale__row > p {
		grid-template-columns: minmax(0, 1fr);
		gap: 0.4em;
	}

	.ms-form .ms-scale__end:last-child {
		text-align: right;
	}
}

/* ---------- file uploads ---------- */

.ms-q input[type="file"] {
	display: block;
	max-width: 100%;
}

/* ---------- browser-side image compression ---------- */

.ms-compress-status:not(:empty) {
	display: block;
	margin-top: 0.4em;
	font-size: 0.875em;
	color: var(--ms-muted);
}

.ms-compress-status.is-done {
	color: #15803d;
}

/* Next and Submit are held while an image is still encoding. */
.ms-form .ms-btn[disabled],
.ms-form .wpcf7-submit[disabled] {
	opacity: 0.55;
	cursor: progress;
}
