/**
 * Front-end forms: fields, labels, checkbox, errors, and the search form
 * (inc/search.php). Loaded on the front end only. See "Forms" and
 * "Sidebar" in docs/design-system.md (contact-01.jpg, fields only).
 *
 * Markup for forms built in the theme:
 * <p class="bst-field [bst-field--invalid]">
 *   <label class="bst-field__label" for="…">Label<span class="bst-field__required" aria-hidden="true">*</span><span class="screen-reader-text"> bắt buộc</span></label>
 *   <input … aria-invalid="true" aria-describedby="…-error">
 *   <span class="bst-field__error" id="…-error">Message</span>
 * </p>
 * <p class="bst-check"><input type="checkbox" id="…"><label for="…">Label</label></p>
 * Optional: <span class="bst-field__hint" id="…-hint"> after the label;
 * an error summary (.bst-error-summary) above the form.
 * The submit button is the primary button (.bst-button).
 */

/* Label above the field: heading font italic at --text-link. */
.bst-field {
	margin: 0 0 1.5em;
}

.bst-field__label {
	display: block;
	margin-bottom: 0.15em;
	color: var(--color-text);
	font-family: var(--font-heading);
	font-size: var(--text-link);
	font-style: italic;
	line-height: 1.4;
}

.bst-field__required {
	margin-left: 0.15em;
	color: var(--color-accent);
	font-style: normal;
}

/*
 * Text inputs, textareas, selects: no box, transparent background, a 1px
 * bottom border; typed text in the body font in forest. Same specificity
 * as the GeneratePress field rules (input[type="text"] …), loaded later.
 */
input:is([type="text"], [type="email"], [type="tel"], [type="url"], [type="search"], [type="number"], [type="password"], [type="date"]),
textarea,
select {
	box-sizing: border-box;
	width: 100%;
	min-height: 44px;
	padding: 0.5em 0;
	border: 0;
	border-bottom: 1px solid var(--color-border);
	border-radius: 0;
	background-color: transparent;
	color: var(--color-forest);
	font-family: var(--font-body);
	font-size: var(--text-body);
	line-height: 1.5;
	transition: border-color var(--motion-fast) ease;
}

/* Focus: the bottom border turns forest (plus the site focus outline). */
input:is([type="text"], [type="email"], [type="tel"], [type="url"], [type="search"], [type="number"], [type="password"], [type="date"]):focus,
textarea:focus,
select:focus {
	border-color: var(--color-forest);
	background-color: transparent;
	color: var(--color-forest);
}

::placeholder {
	color: var(--color-text);
	font-family: var(--font-heading);
	font-size: var(--text-link);
	font-style: italic;
	opacity: 1;
}

textarea {
	min-height: 8em;
	resize: vertical;
}

/*
 * Select: the accent chevron, drawn with two thin gradient lines
 * ("\" and "/") so it takes the token color.
 */
select {
	padding-right: 2em;
	background-image:
		linear-gradient(45deg, transparent calc(50% - 0.75px), var(--color-accent) calc(50% - 0.75px), var(--color-accent) calc(50% + 0.75px), transparent calc(50% + 0.75px)),
		linear-gradient(-45deg, transparent calc(50% - 0.75px), var(--color-accent) calc(50% - 0.75px), var(--color-accent) calc(50% + 0.75px), transparent calc(50% + 0.75px));
	background-position: right calc(0.25em + 0.4em) center, right 0.25em center;
	background-repeat: no-repeat;
	background-size: 0.4em 0.4em;
	cursor: pointer;
	appearance: none;
}

/* Invalid field: --color-error bottom border and a short message below. */
.bst-field--invalid :is(input, textarea, select),
:is(input, textarea, select)[aria-invalid="true"] {
	border-color: var(--color-error);
}

.bst-field__error {
	display: block;
	margin-top: 0.4em;
	color: var(--color-error);
	font-size: var(--text-body);
	line-height: 1.5;
}

/* Hint between the label and the field, linked with aria-describedby. */
.bst-field__hint {
	display: block;
	color: var(--color-text);
	font-size: var(--text-body);
	line-height: 1.5;
}

/*
 * Error summary above a form: a 1px border in the error color, a short
 * title and a list of the errors, each linking to its field. Focused on
 * load (tabindex="-1", autofocus); not a control, so no focus outline.
 */
.bst-error-summary {
	margin: 0 0 2em;
	padding: 1em 1.25em;
	border: 1px solid var(--color-error);
}

.bst-error-summary:focus {
	outline: none;
}

.bst-error-summary__title {
	margin: 0 0 0.5em;
	font-size: var(--text-h3);
}

.bst-error-summary__list {
	margin: 0;
	padding-left: 1.25em;
}

.bst-error-summary__list li + li {
	margin-top: 0.25em;
}

.bst-error-summary__list a,
.bst-error-summary__list a:hover,
.bst-error-summary__list a:focus {
	color: var(--color-error);
}

/*
 * Checkbox: a square 1px forest box, filled forest with an ivory check
 * when checked; its label in body text beside it; the row at least 44px.
 */
.bst-check {
	display: flex;
	align-items: center;
	gap: 0.75em;
	min-height: 44px;
	margin: 0 0 1.5em;
}

input[type="checkbox"] {
	display: inline-grid;
	flex-shrink: 0;
	place-content: center;
	width: 1.25em;
	height: 1.25em;
	margin: 0;
	border: 1px solid var(--color-forest);
	border-radius: 0;
	background-color: transparent;
	cursor: pointer;
	appearance: none;
}

input[type="checkbox"]::before {
	width: 0.35em;
	height: 0.65em;
	border: solid var(--color-ivory);
	border-width: 0 2px 2px 0;
	opacity: 0;
	transform: translateY(-0.08em) rotate(45deg);
	content: "";
}

input[type="checkbox"]:checked {
	background-color: var(--color-forest);
}

input[type="checkbox"]:checked::before {
	opacity: 1;
}

/*
 * Search form: the field and, at its right end, a 44x44 submit button
 * with an accent magnifier icon; the bottom border runs under both.
 */
.bst-search-form {
	display: flex;
	align-items: stretch;
	margin: 0;
}

.bst-search-form__field {
	flex: 1;
	min-width: 0;
	appearance: none;
}

button.bst-search-form__submit,
button.bst-search-form__submit:hover,
button.bst-search-form__submit:focus {
	background-color: transparent;
	color: var(--color-accent);
}

button.bst-search-form__submit {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 44px;
	min-height: 44px;
	padding: 0;
	border: 0;
	border-bottom: 1px solid var(--color-border);
	border-radius: 0;
	cursor: pointer;
}

button.bst-search-form__submit:hover,
button.bst-search-form__submit:focus {
	color: var(--color-forest);
}

.bst-search-form__icon {
	display: block;
	width: 20px;
	height: 20px;
}
