/*
 * Section: write to us (the "jl-write" group), with the contact form.
 *
 * Split five to seven: on the left a small label, a heading, a short line and
 * label and value rows with the ways to reach you; on the right the contact
 * form. Each row is a Group holding two Paragraphs. A row with the class
 * "jl-row--hide-sm" is left out on phones.
 *
 * The form ("jl-form") is ordinary blocks in the editor and a real form on
 * the site (inc/contact.php marks it "is-live"). Fields are plain: a small
 * label above, a single hairline below, no boxes. A field left wrong gets a
 * darker line, a small dot and a written line, never colour alone. Once the
 * message has gone, the form gives way to the "sent" message.
 *
 * Colours, fonts and edge spacing come from the theme. The reveal only runs
 * once the script is running (html.jl-js).
 */

.jl-write.jl-write {
	--wr-pad: 48px;
	--wr-gap: 24px;
	--wr-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
	display: grid;
	grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
	gap: 72px var(--wr-gap);
	align-items: start;
	margin-block: 0;
	padding: 56px var(--wr-pad) 120px;
	background-color: var(--wp--preset--color--base);
	color: var(--wp--preset--color--contrast);
	scroll-margin-top: var(--jl-header-h);
}

/* WordPress spaces out a Group's children; every part here sets its own spacing. */
.jl-write.jl-write > *,
.jl-write .jl-write__intro > *,
.jl-write .jl-write__details > *,
.jl-write .jl-write__row > *,
.jl-write .jl-form > *,
.jl-write .jl-field > *,
.jl-write .jl-form__sent > *,
.jl-write .jl-form__done > *,
.jl-write .jl-form__done .jl-form__sent > * {
	margin-block: 0;
}

/* ---------- Heading and details ---------- */

.jl-write .jl-write__intro h2 {
	margin-top: 22px;
	font-size: clamp(2.5rem, 4.6vw, 4.25rem);
	letter-spacing: -0.03em;
	line-height: 1;
	text-wrap: balance;
}

.jl-write .jl-write__lead {
	max-width: 400px;
	margin-top: 28px;
	font-size: 1.1875rem;
	letter-spacing: -0.01em;
	line-height: 1.35;
}

.jl-write .jl-write__details {
	display: grid;
	column-gap: var(--wr-gap);
	max-width: 520px;
	margin-top: 72px;
	border-bottom: 1px solid var(--jl-line);
}

.jl-write .jl-write__row {
	display: flex;
	flex-wrap: wrap;
	gap: 4px 24px;
	padding: 18px 0;
	border-top: 1px solid var(--jl-line);
	font-size: 1rem;
	line-height: 1.5;
}

.jl-write .jl-write__row > :first-child {
	flex: 0 0 140px;
	color: var(--wp--preset--color--accent-4);
}

.jl-write .jl-write__row > :nth-child(2) {
	flex: 1 1 0;
	min-width: 0;
	overflow-wrap: anywhere;
}

.jl-write .jl-write__row a {
	color: inherit;
	text-decoration: none;
	transition: color 0.3s;
}

.jl-write .jl-write__row a:hover {
	color: var(--wp--preset--color--accent-3);
}

/* ---------- The form, on the site ---------- */

.jl-write .jl-form {
	min-width: 0;
	padding-top: 6px;
}

.jl-write .jl-form__form {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 56px var(--wr-gap);
}

.jl-write .jl-form__field {
	display: flex;
	flex-direction: column;
	gap: 6px;
	min-width: 0;
}

.jl-write .jl-form__field--message,
.jl-write .jl-form__field--consent,
.jl-write .jl-form__failed,
.jl-write .jl-form__actions {
	grid-column: 1 / -1;
}

/* Small labels above the fields. */
.jl-write .jl-form__label,
.jl-write .jl-field__label {
	color: var(--wp--preset--color--accent-4);
	font-size: 0.72rem;
	font-weight: 600;
	letter-spacing: 0.1em;
	line-height: 1.4;
	text-transform: uppercase;
}

.jl-write .jl-form__input {
	box-sizing: border-box;
	width: 100%;
	padding: 12px 0 14px;
	border: 0;
	border-bottom: 1px solid var(--jl-line);
	border-radius: 0;
	background: transparent;
	color: var(--wp--preset--color--contrast);
	font-family: inherit;
	font-size: 1.125rem;
	line-height: 1.4;
	-webkit-appearance: none;
	appearance: none;
	transition: border-color 0.3s;
}

.jl-write textarea.jl-form__input {
	min-height: 120px;
	line-height: 1.5;
	resize: vertical;
}

/*
 * Focus: the line under the field darkens and thickens, instead of the ring
 * the theme draws around other controls. The padding gives back the extra
 * pixel, so the text does not move.
 */
.jl-write .jl-form__input:focus,
.jl-write .jl-form__input:focus-visible {
	padding-bottom: 13px;
	border-bottom: 2px solid var(--wp--preset--color--contrast);
	outline: none;
}

/*
 * Browser autofill paints its own fill over a field (blue in Chrome, yellow
 * in Safari and Firefox) and cannot simply be told to be transparent. An
 * inset shadow in the page colour covers it, and the text keeps the theme's
 * colour, in light and dark mode. The two selectors stay in separate rules:
 * a browser that does not know one of them would drop the whole rule.
 */
.jl-write .jl-form__input:-webkit-autofill,
.jl-write .jl-form__input:-webkit-autofill:hover,
.jl-write .jl-form__input:-webkit-autofill:focus {
	-webkit-box-shadow: inset 0 0 0 100px var(--wp--preset--color--base);
	box-shadow: inset 0 0 0 100px var(--wp--preset--color--base);
	-webkit-text-fill-color: var(--wp--preset--color--contrast);
	caret-color: var(--wp--preset--color--contrast);
	transition: border-color 0.3s, background-color 0s 600000s;
}

.jl-write .jl-form__input:autofill {
	box-shadow: inset 0 0 0 100px var(--wp--preset--color--base);
	filter: none;
}

.jl-write .jl-form__field.is-error .jl-form__input {
	border-bottom-color: var(--wp--preset--color--contrast);
}

/* The line under a field left wrong, and the one shown if sending fails: a small dot, then the words. */
.jl-write .jl-form__error,
.jl-write .jl-field__error,
.jl-write .jl-form > .jl-form__failed {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-top: 6px;
	font-size: 0.875rem;
	line-height: 1.4;
}

.jl-write .jl-form__error::before,
.jl-write .jl-field__error::before,
.jl-write .jl-form > .jl-form__failed::before {
	content: "";
	flex: none;
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--wp--preset--color--accent-2);
}

.jl-write .jl-form__error[hidden],
.jl-write .jl-form__form[hidden],
.jl-write .jl-form__done[hidden] {
	display: none;
}

.jl-write .jl-form__field--consent .jl-form__error {
	margin-left: 32px;
}

/* The consent tick box: a small square, filled when ticked. */
.jl-write .jl-form__consent {
	display: flex;
	align-items: flex-start;
	gap: 14px;
	max-width: 520px;
	padding: 4px 0;
}

.jl-write .jl-form__consent input {
	display: grid;
	flex: none;
	place-content: center;
	width: 18px;
	height: 18px;
	margin: 1px 0 0;
	border: 1px solid var(--wp--preset--color--contrast);
	border-radius: 0;
	background: transparent;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}

.jl-write .jl-form__consent input:checked {
	background: var(--wp--preset--color--contrast);
}

.jl-write .jl-form__consent input:checked::after {
	content: "";
	width: 9px;
	height: 5px;
	border-bottom: 1.4px solid var(--wp--preset--color--base);
	border-left: 1.4px solid var(--wp--preset--color--base);
	transform: translate(0, -1px) rotate(-45deg);
}

.jl-write .jl-form__consent label,
.jl-write .jl-field--consent .jl-field__label {
	color: var(--wp--preset--color--accent-4);
	font-size: 0.875rem;
	font-weight: 400;
	letter-spacing: 0;
	line-height: 1.4;
	text-transform: none;
	cursor: pointer;
}

.jl-write .jl-form__consent label a,
.jl-write .jl-field--consent a {
	color: var(--wp--preset--color--contrast);
	text-decoration: underline;
	text-underline-offset: 3px;
}

.jl-write .jl-form__actions {
	margin-top: -8px;
}

/* The send button is the shared arrow pill, drawn on a real button. */
.jl-write .jl-form__actions .jl-pill .wp-block-button__link {
	font-family: inherit;
	line-height: 1;
	cursor: pointer;
}

.jl-write .jl-form__actions .jl-pill .wp-block-button__link:disabled {
	opacity: 0.6;
	cursor: progress;
}

/* ---------- Sent ---------- */

.jl-write .jl-form__done {
	max-width: 560px;
	padding-top: 36px;
	border-top: 1px solid var(--jl-line);
	outline: none;
}

.jl-write .jl-form__sent > .jl-tag {
	margin-bottom: 22px;
}

.jl-write .jl-form__statement {
	font-family: var(--wp--preset--font-family--fraunces);
	font-size: clamp(1.75rem, 3vw, 2.25rem);
	letter-spacing: -0.02em;
	line-height: 1.12;
}

.jl-write .jl-form__sent > p:not(.jl-tag):not(.jl-form__statement):not(.jl-arrow) {
	max-width: 440px;
	margin: 20px 0 32px;
	color: var(--wp--preset--color--accent-4);
	font-size: 1.0625rem;
	line-height: 1.6;
}

/* ---------- The form's blocks, as they appear in the editor ---------- */

.jl-write .jl-form:not(.is-live) {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 40px var(--wr-gap);
}

.jl-write .jl-form:not(.is-live) > :not(.jl-field--name):not(.jl-field--email) {
	grid-column: 1 / -1;
}

/* Each field: its label, a hairline where the typing goes, and the line shown when it is wrong. */
.jl-write .jl-field .jl-field__label {
	padding-bottom: 40px;
	border-bottom: 1px solid var(--jl-line);
}

.jl-write .jl-field--message .jl-field__label {
	padding-bottom: 110px;
}

.jl-write .jl-field--consent .jl-field__label {
	padding: 0 0 0 32px;
	border-bottom: 0;
}

.jl-write .jl-field .jl-field__error {
	margin-top: 10px;
}

.jl-write .jl-form:not(.is-live) .jl-form__sent {
	padding-top: 36px;
	border-top: 1px solid var(--jl-line);
}

/* ---------- Motion (front only, once the script is running) ---------- */

.jl-js .jl-write .jl-write__intro > *,
.jl-js .jl-write .jl-form {
	opacity: 0;
	transform: translateY(24px);
	transition: opacity 0.9s var(--wr-ease) var(--d, 0ms), transform 0.9s var(--wr-ease) var(--d, 0ms);
}

.jl-js .jl-write .jl-write__intro.is-in > *,
.jl-js .jl-write .jl-form.is-in {
	opacity: 1;
	transform: none;
}

.jl-write .jl-write__intro > :nth-child(2) {
	--d: 100ms;
}

.jl-write .jl-write__intro > :nth-child(3) {
	--d: 200ms;
}

.jl-write .jl-write__intro > :nth-child(n + 4) {
	--d: 300ms;
}

/* ---------- Tablet: the details above the form, in a grid of two ---------- */
@media (max-width: 1099px) {
	.jl-write.jl-write {
		--wr-pad: 40px;
		--wr-gap: 20px;
		grid-template-columns: minmax(0, 1fr);
		gap: 64px;
	}

	.jl-write .jl-write__details {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		max-width: none;
		margin-top: 56px;
		border-bottom: 0;
	}

	.jl-write .jl-write__row {
		padding: 16px 0 20px;
	}

	.jl-write .jl-write__row > :first-child {
		flex-basis: 100%;
	}

	.jl-write .jl-form {
		padding-top: 0;
	}

	.jl-write .jl-form__form {
		gap: 48px var(--wr-gap);
	}
}

/* ---------- Mobile: one column, the button across ---------- */
@media (max-width: 699px) {
	.jl-write.jl-write {
		--wr-pad: 24px;
		--wr-gap: 12px;
		gap: 56px;
		padding-top: 32px;
		padding-bottom: 72px;
	}

	.jl-write .jl-write__intro h2 {
		margin-top: 18px;
	}

	/* The short line, and any row marked "jl-row--hide-sm", are left out on phones. */
	.jl-write .jl-write__lead,
	.jl-write .jl-write__details .jl-row--hide-sm {
		display: none;
	}

	.jl-write .jl-write__details {
		grid-template-columns: minmax(0, 1fr);
		margin-top: 36px;
		border-bottom: 1px solid var(--jl-line);
	}

	.jl-write .jl-write__row {
		padding: 14px 0;
	}

	.jl-write .jl-write__row > :first-child {
		flex-basis: 88px;
	}

	.jl-write .jl-form__form,
	.jl-write .jl-form:not(.is-live) {
		grid-template-columns: minmax(0, 1fr);
		gap: 36px var(--wr-gap);
	}

	.jl-write .jl-form__actions .wp-block-button,
	.jl-write .jl-form__actions .jl-pill.jl-pill .wp-block-button__link {
		width: 100%;
	}

	.jl-write .jl-form__actions .jl-pill.jl-pill .wp-block-button__link {
		justify-content: space-between;
	}
}

/* Set by the script if it could not prepare the section: everything shows at rest. */
.jl-write.is-plain .jl-write__intro > *,
.jl-write.is-plain .jl-form {
	opacity: 1 !important;
	transform: none !important;
}

@media (prefers-reduced-motion: reduce) {
	.jl-js .jl-write .jl-write__intro > *,
	.jl-js .jl-write .jl-form {
		opacity: 1;
		transform: none;
	}

	.jl-write.jl-write * {
		transition: none !important;
	}
}
