/*
 * Fallback form styles, scoped under .sd-form. Themes restyle with the
 * custom properties below, or return false from sd_forms_load_styles.
 */
.sd-form {
	--sd-form-gap: 1.25rem;
	--sd-form-fg: inherit;
	--sd-form-muted: color-mix(in srgb, currentColor 70%, transparent);
	--sd-form-border: color-mix(in srgb, currentColor 55%, transparent);
	--sd-form-input-bg: transparent;
	--sd-form-radius: 4px;
	--sd-form-focus: currentColor;
	--sd-form-error: #b3261e;
	--sd-form-button-bg: currentColor;
	--sd-form-button-fg: Canvas;

	color: var(--sd-form-fg);
}

.sd-form__form {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sd-form-gap) calc(var(--sd-form-gap) * 0.8);
	margin: 0;
}

/* Text and layout blocks between fields take the full row. */
.sd-form__form > * {
	flex: 1 1 100%;
	min-width: 0;
	margin-block: 0;
}

.sd-form__field {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	margin: 0;
	padding: 0;
	border: 0;
}

@media (min-width: 40em) {
	.sd-form__form > .sd-form__field--half {
		flex: 1 1 calc(50% - var(--sd-form-gap));
	}
}

.sd-form__label {
	font-weight: 600;
	padding: 0;
}

/* A fieldset's gap does not reach its legend, so space it explicitly. */
fieldset.sd-form__field > legend {
	margin-bottom: 0.4rem;
}

/* Markers in another font must not make their label taller, or half-width
   fields beside each other lose alignment. */
.sd-form__label .sd-form__required,
.sd-form__label .sd-form__optional {
	line-height: 1;
}

.sd-form__required,
.sd-form__optional,
.sd-form__help {
	color: var(--sd-form-muted);
	font-size: 0.875em;
	font-weight: 400;
}

.sd-form .sd-form__help {
	margin: 0;
}

/* Fallbacks stay at one class of specificity (:where), so any theme rule for
   .sd-form overrides them. */
.sd-form :where(input:not([type="checkbox"], [type="radio"]), select, textarea) {
	box-sizing: border-box;
	width: 100%;
	min-height: 2.75rem;
	padding: 0.6rem 0.75rem;
	border: 1px solid var(--sd-form-border);
	border-radius: var(--sd-form-radius);
	background: var(--sd-form-input-bg);
	color: inherit;
	font: inherit;
}

.sd-form :where(textarea) {
	resize: vertical;
}

.sd-form :where(input[type="checkbox"], input[type="radio"]) {
	inline-size: 1.25rem;
	block-size: 1.25rem;
	margin: 0.15rem 0 0;
	flex: none;
	accent-color: var(--sd-form-focus);
}

.sd-form :where(:focus-visible) {
	outline: 3px solid var(--sd-form-focus);
	outline-offset: 2px;
}

.sd-form__options {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.sd-form__option {
	display: flex;
	align-items: flex-start;
	gap: 0.6rem;
}

.sd-form__option label {
	min-height: 1.5rem;
}

.sd-form .sd-form__error {
	margin: 0;
	color: var(--sd-form-error);
	font-weight: 600;
}

.sd-form__field--error :where(input:not([type="checkbox"], [type="radio"]), select, textarea) {
	border-color: var(--sd-form-error);
	border-width: 2px;
}

.sd-form__summary {
	padding: 1rem 1.25rem;
	border: 3px solid var(--sd-form-error);
	border-radius: var(--sd-form-radius);
}

.sd-form__summary[hidden],
.sd-form__error[hidden] {
	display: none;
}

.sd-form__summary-title {
	margin: 0 0 0.5rem;
	font-size: 1.125em;
}

.sd-form__summary ul {
	margin: 0;
	padding-left: 1.25rem;
}

.sd-form .sd-form__summary a {
	color: var(--sd-form-error);
	font-weight: 600;
}

.sd-form__actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
}

.sd-form .sd-form__note {
	margin: 0;
	color: var(--sd-form-muted);
	font-size: 0.9375em;
}

.sd-form__submit {
	min-height: 2.75rem;
	padding: 0.65rem 1.5rem;
	cursor: pointer;
}

/* Only when the theme has no button styles of its own (wp-element-button). */
.sd-form__submit:not(.wp-element-button) {
	border: 0;
	border-radius: var(--sd-form-radius);
	background: var(--sd-form-button-bg);
	color: var(--sd-form-button-fg);
	font: inherit;
	font-weight: 600;
}

.sd-form__submit:disabled {
	cursor: progress;
	opacity: 0.7;
}

.sd-form__status:empty {
	display: none;
}

.sd-form__confirmation {
	padding: 1rem 1.25rem;
	border-left: 4px solid currentColor;
}

.sd-form__confirmation > :first-child {
	margin-top: 0;
}

.sd-form__confirmation > :last-child {
	margin-bottom: 0;
}

/* The honeypot: off-screen for people, still in the markup for bots. */
.sd-form__hp {
	position: absolute !important;
	left: -10000px !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.sd-form .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.sd-form-problem {
	padding: 0.75rem 1rem;
	border: 2px dashed #b3261e;
}

@media (prefers-reduced-motion: no-preference) {
	.sd-form :where(input, select, textarea) {
		transition: border-color 0.15s ease;
	}
}
