/**
 * AIGROW forms layer.
 *
 * Scope: Contact Form 7 (.wpcf7): fields, select chevron, acceptance
 * checkbox, visible error summary, response output, submit spinner.
 * Load order: base, components, patterns, chrome, forms.
 * Use theme.json tokens only: var(--wp--preset--*), var(--wp--custom--*).
 *
 * Markup: CF7 forms created by aigrow-core (includes/cf7.php) and embedded by
 * the aigrow/form block (.aigrow-form). Generic .wpcf7 rules also cover any
 * other CF7 form. Design: design.md §4.12; UX: uiux.md §3.7, PLAN §3.8.
 */

/* ---------- Container ---------- */

.aigrow-form,
.wpcf7 {
	max-width: 640px;
}

.wpcf7 form {
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--50);
}

/* CF7 wraps the form's hidden inputs in a fieldset. */
.wpcf7 form .hidden-fields-container {
	display: none;
}

.aigrow-form__note {
	order: -1;
	margin: 0;
	color: var(--wp--preset--color--muted);
	font-size: var(--wp--preset--font-size--small);
}

.aigrow-form__row {
	display: grid;
	gap: var(--wp--preset--spacing--50);
}

@media (min-width: 600px) {

	.aigrow-form__row--split {
		grid-template-columns: 1fr 1fr;
	}
}

/* ---------- Labels and fields ---------- */

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

.aigrow-form__field > label,
.wpcf7 label {
	color: var(--wp--preset--color--ink);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 600;
	line-height: var(--wp--custom--line-height--snug);
}

.aigrow-form__req {
	color: var(--wp--preset--color--muted);
	font-weight: 400;
}

.wpcf7 .wpcf7-form-control-wrap {
	display: block;
	position: relative;
}

.wpcf7 input[type="text"],
.wpcf7 input[type="email"],
.wpcf7 input[type="tel"],
.wpcf7 input[type="url"],
.wpcf7 input[type="number"],
.wpcf7 select,
.wpcf7 textarea {
	box-sizing: border-box;
	width: 100%;
	min-height: 48px;
	margin: 0;
	padding: 12px 14px;
	border: 1px solid var(--wp--preset--color--line-strong);
	border-radius: var(--wp--custom--radius--sm);
	background-color: var(--wp--preset--color--base);
	color: var(--wp--preset--color--text);
	font-family: var(--wp--preset--font-family--body);
	font-size: max(16px, 1rem);
	line-height: var(--wp--custom--line-height--snug);
	transition: border-color var(--wp--custom--motion--fast) var(--wp--custom--motion--ease-out);
}

.wpcf7 textarea {
	min-height: 160px;
	resize: vertical;
}

.wpcf7 ::placeholder {
	color: var(--wp--preset--color--muted);
	opacity: 1;
}

.wpcf7 input:hover,
.wpcf7 select:hover,
.wpcf7 textarea:hover {
	border-color: var(--wp--preset--color--ink);
}

.wpcf7 input:focus,
.wpcf7 select:focus,
.wpcf7 textarea:focus {
	border-color: var(--wp--preset--color--primary);
}

.wpcf7 input:focus-visible,
.wpcf7 select:focus-visible,
.wpcf7 textarea:focus-visible {
	outline: 2px solid var(--aigrow-focus-color, var(--wp--preset--color--primary));
	outline-offset: 2px;
}

/* Select: native control, custom chevron (keeps platform accessibility). */
.wpcf7 select {
	padding-right: 44px;
	appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2318363E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
	background-position: right 14px center;
	background-repeat: no-repeat;
	background-size: 20px 20px;
	cursor: pointer;
}

/* ---------- Invalid fields ---------- */

.wpcf7 .wpcf7-not-valid {
	border-width: 1.5px;
	border-color: var(--wp--preset--color--error);
}

.wpcf7 .wpcf7-not-valid-tip {
	display: flex;
	gap: 6px;
	align-items: flex-start;
	margin-top: 6px;
	color: var(--wp--preset--color--error);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 500;
	line-height: var(--wp--custom--line-height--snug);
}

.wpcf7 .wpcf7-not-valid-tip::before {
	content: "";
	flex: none;
	width: 16px;
	height: 16px;
	margin-top: 0.15em;
	background-color: currentcolor;
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4M12 16h.01'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4M12 16h.01'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---------- Acceptance (privacy acknowledgement) ---------- */

.aigrow-form__field--acceptance,
.wpcf7 .wpcf7-acceptance {
	font-size: var(--wp--preset--font-size--small);
	line-height: var(--wp--custom--line-height--snug);
}

.wpcf7 .wpcf7-acceptance .wpcf7-list-item {
	display: block;
	margin: 0;
}

.wpcf7 .wpcf7-acceptance label {
	display: flex;
	gap: var(--wp--preset--spacing--30);
	align-items: flex-start;
	min-height: 44px;
	font-weight: 400;
	cursor: pointer;
}

.wpcf7 input[type="checkbox"] {
	flex: none;
	display: grid;
	place-content: center;
	width: 20px;
	height: 20px;
	margin: 0.1em 0 0;
	border: 1px solid var(--wp--preset--color--line-strong);
	border-radius: var(--wp--custom--radius--xs);
	background: var(--wp--preset--color--base);
	appearance: none;
	cursor: pointer;
}

.wpcf7 input[type="checkbox"]::before {
	content: "";
	width: 12px;
	height: 12px;
	background-color: var(--wp--preset--color--base);
	transform: scale(0);
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
}

.wpcf7 input[type="checkbox"]:checked {
	border-color: var(--wp--preset--color--primary);
	background: var(--wp--preset--color--primary);
}

.wpcf7 input[type="checkbox"]:checked::before {
	transform: scale(1);
}

.wpcf7 .wpcf7-acceptance a {
	color: var(--wp--preset--color--primary);
	text-decoration: underline;
}

/* ---------- Honeypot: visually hidden, never display:none alone ---------- */

.wpcf7 .aigrow-hp-wrap,
.wpcf7 [data-name="aigrow-hp"] {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	margin: -1px !important;
	padding: 0 !important;
	overflow: hidden !important;
	clip-path: inset(50%) !important;
	border: 0 !important;
	white-space: nowrap !important;
}

/* ---------- Submit ---------- */

.aigrow-form__actions {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--30);
	align-items: center;
}

.wpcf7 input[type="submit"],
.wpcf7 .wpcf7-submit {
	min-height: 48px;
	padding: 12px 22px;
	border: 0;
	border-radius: var(--wp--custom--radius--sm);
	background: var(--wp--preset--color--primary);
	color: var(--wp--preset--color--base);
	font-family: var(--wp--preset--font-family--heading);
	font-size: 1rem;
	font-weight: 700;
	line-height: 1.2;
	cursor: pointer;
	transition: background-color var(--wp--custom--motion--fast) var(--wp--custom--motion--ease-out);
}

.wpcf7 input[type="submit"]:hover,
.wpcf7 .wpcf7-submit:hover {
	background: var(--wp--preset--color--primary-dark);
	box-shadow: var(--wp--preset--shadow--sm);
}

.wpcf7 input[type="submit"]:active {
	transform: translateY(1px);
}

.wpcf7 input[type="submit"]:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

@media (max-width: 599px) {

	.aigrow-form__actions {
		flex-direction: column;
		align-items: stretch;
	}

	.wpcf7 input[type="submit"] {
		width: 100%;
		min-height: 56px;
	}
}

/* Spinner: only while submitting; the label text stays. */
.wpcf7 .wpcf7-spinner {
	display: none;
	width: 16px;
	height: 16px;
	margin: 0;
	border: 2px solid var(--wp--preset--color--line);
	border-top-color: var(--wp--preset--color--primary);
	border-radius: 50%;
	background: none;
	opacity: 1;
	visibility: visible;
	animation: aigrow-spin 0.8s linear infinite;
}

.wpcf7 .wpcf7-spinner::before {
	content: none;
}

.wpcf7 form.submitting .wpcf7-spinner {
	display: inline-block;
}

@keyframes aigrow-spin {

	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {

	.wpcf7 .wpcf7-spinner {
		animation-duration: 2.4s;
	}
}

/* ---------- Response output ---------- */

.wpcf7 form .wpcf7-response-output {
	margin: 0;
	padding: var(--wp--preset--spacing--40);
	border: 1px solid var(--wp--preset--color--error);
	border-radius: var(--wp--custom--radius--md);
	background: var(--wp--custom--color--error-soft);
	color: var(--wp--preset--color--error);
	font-size: var(--wp--preset--font-size--small);
}

.wpcf7 form.init .wpcf7-response-output,
.wpcf7 form.resetting .wpcf7-response-output,
.wpcf7 form.submitting .wpcf7-response-output {
	display: none;
}

.wpcf7 form.sent .wpcf7-response-output {
	border-color: var(--wp--preset--color--success);
	background: var(--wp--custom--color--success-soft);
	color: var(--wp--preset--color--success);
}

/* ---------- Error / status summary (aigrow/form view script) ----------
 * CF7 keeps its result in the visually hidden .screen-reader-response. When the
 * view script marks the wrapper (.aigrow-has-summary) the region is shown above
 * the fields, focused, and the duplicate response output is hidden.
 */
.wpcf7.aigrow-has-summary .screen-reader-response {
	position: static;
	width: auto;
	height: auto;
	margin: 0 0 var(--wp--preset--spacing--50);
	padding: var(--wp--preset--spacing--40);
	overflow: visible;
	clip-path: none;
	border: 1px solid var(--wp--preset--color--error);
	border-radius: var(--wp--custom--radius--md);
	background: var(--wp--custom--color--error-soft);
	color: var(--wp--preset--color--error);
	font-size: var(--wp--preset--font-size--small);
	white-space: normal;
	overflow-wrap: normal;
}

.wpcf7.aigrow-has-summary .screen-reader-response:focus {
	outline: 2px solid var(--aigrow-focus-color, var(--wp--preset--color--primary));
	outline-offset: 2px;
}

.wpcf7.aigrow-has-summary .screen-reader-response p {
	margin: 0;
	font-weight: 600;
}

.wpcf7.aigrow-has-summary .screen-reader-response ul {
	margin: var(--wp--preset--spacing--20) 0 0;
	padding-left: 1.25em;
}

.wpcf7.aigrow-has-summary .screen-reader-response ul:empty {
	display: none;
}

.wpcf7.aigrow-has-summary .screen-reader-response a {
	color: inherit;
	text-decoration: underline;
}

.wpcf7.aigrow-has-summary[data-aigrow-status="mailsent"] .screen-reader-response {
	border-color: var(--wp--preset--color--success);
	background: var(--wp--custom--color--success-soft);
	color: var(--wp--preset--color--success);
}

.wpcf7.aigrow-has-summary form .wpcf7-response-output {
	display: none;
}
