/**
 * Form design system.
 *
 * One set of rules for every customer-facing form on the site: contact, PCGS
 * grading, appointments, selling bullion and the wholesale application. The
 * forms differ in their fields, never in how they look or behave.
 *
 * Built on the theme's own tokens, so a change to spacing, colour or radius
 * elsewhere carries through here without this file being touched.
 */

.tcs-form {
	/* Long lines are hard to scan and a form is not a place to be reading
	   across the full width of a desktop screen. */
	max-width: 820px;
	margin-inline: 0;
}

/* --- layout ------------------------------------------------------------- */

.tcs-form__grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: var(--tcs-space-sm) var(--tcs-space-md);
	align-items: start;
}

.tcs-form__field {
	grid-column: 1 / -1;
	display: grid;
	gap: 0.3rem;
	min-width: 0;
}

/* Pairs that read naturally side by side: first/last name, email/phone. */
.tcs-form__field--half {
	grid-column: span 1;
}

.tcs-form__section {
	grid-column: 1 / -1;
	margin-block-start: var(--tcs-space-md);
	padding-block-start: var(--tcs-space-sm);
	border-block-start: var(--tcs-border-faint);
}

.tcs-form__section:first-child {
	margin-block-start: 0;
	padding-block-start: 0;
	border-block-start: 0;
}

.tcs-form__section-title {
	margin: 0;
	font-size: 0.78rem;
	font-weight: var(--tcs-weight-semibold);
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--tcs-ink-muted);
}

/* --- labels and help ---------------------------------------------------- */

.tcs-form__label {
	font-size: 0.88rem;
	font-weight: var(--tcs-weight-medium);
	color: var(--tcs-ink);
}

.tcs-form__req {
	color: var(--tcs-error);
	margin-inline-start: 0.15em;
}

.tcs-form__help {
	font-size: 0.8rem;
	line-height: 1.45;
	color: var(--tcs-ink-muted);
}

.tcs-form__error {
	font-size: 0.8rem;
	font-weight: var(--tcs-weight-medium);
	color: var(--tcs-error);
}

/* --- controls ----------------------------------------------------------- */

.tcs-form__input,
.tcs-form__select,
.tcs-form__textarea {
	width: 100%;
	box-sizing: border-box;
	padding: 0.6rem 0.75rem;
	font: inherit;
	font-size: 0.95rem;
	color: var(--tcs-ink);
	background: var(--tcs-surface);
	border: 1px solid var(--tcs-border-strong);
	border-radius: var(--tcs-radius-sm);
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
	-webkit-appearance: none;
	appearance: none;
}

.tcs-form__textarea {
	/* Big enough to write in, small enough not to swallow the page. */
	min-height: 140px;
	resize: vertical;
	line-height: 1.55;
}

/* A native select arrow varies wildly between browsers, so the control is
   drawn here and the chevron supplied as a background image. */
.tcs-form__select {
	padding-inline-end: 2.2rem;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%23666' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.8rem center;
	background-size: 0.7rem;
}

.tcs-form__input::placeholder,
.tcs-form__textarea::placeholder {
	color: var(--tcs-ink-faint);
}

.tcs-form__input:hover,
.tcs-form__select:hover,
.tcs-form__textarea:hover {
	border-color: var(--tcs-ink-muted);
}

/* Focus must be obvious for keyboard users, and must not rely on colour
   alone - hence a ring as well as a border change. */
.tcs-form__input:focus-visible,
.tcs-form__select:focus-visible,
.tcs-form__textarea:focus-visible,
.tcs-form__check input:focus-visible {
	outline: none;
	border-color: var(--tcs-accent);
	box-shadow: 0 0 0 3px var(--tcs-accent-tint);
}

.tcs-form__field.is-invalid .tcs-form__input,
.tcs-form__field.is-invalid .tcs-form__select,
.tcs-form__field.is-invalid .tcs-form__textarea {
	border-color: var(--tcs-error);
}

.tcs-form__field.is-invalid .tcs-form__input:focus-visible,
.tcs-form__field.is-invalid .tcs-form__select:focus-visible,
.tcs-form__field.is-invalid .tcs-form__textarea:focus-visible {
	box-shadow: 0 0 0 3px var(--tcs-error-bg);
}

/* --- checkboxes and radios ---------------------------------------------- */

.tcs-form__choices {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem var(--tcs-space-md);
	margin: 0.15rem 0 0;
	padding: 0;
	border: 0;
}

.tcs-form__check {
	display: flex;
	align-items: center;
	gap: 0.45rem;
	font-size: 0.92rem;
	cursor: pointer;
}

.tcs-form__check input {
	inline-size: 1rem;
	block-size: 1rem;
	margin: 0;
	accent-color: var(--tcs-accent);
	cursor: pointer;
}

/* --- file upload --------------------------------------------------------- */

.tcs-form__file {
	font-size: 0.9rem;
	padding: 0.55rem;
	border: 1px dashed var(--tcs-border-strong);
	border-radius: var(--tcs-radius-sm);
	background: var(--tcs-surface);
	width: 100%;
	box-sizing: border-box;
}

.tcs-form__file::file-selector-button {
	font: inherit;
	font-size: 0.85rem;
	margin-inline-end: 0.75rem;
	padding: 0.35rem 0.7rem;
	border: 1px solid var(--tcs-border-strong);
	border-radius: var(--tcs-radius-sm);
	background: var(--tcs-surface-raised);
	color: var(--tcs-ink);
	cursor: pointer;
}

/* --- actions ------------------------------------------------------------- */

.tcs-form__actions {
	grid-column: 1 / -1;
	display: flex;
	align-items: center;
	gap: var(--tcs-space-md);
	flex-wrap: wrap;
	margin-block-start: var(--tcs-space-md);
}

.tcs-form__privacy {
	margin: 0;
	font-size: 0.8rem;
	color: var(--tcs-ink-muted);
	max-width: 46ch;
}

/* --- notices ------------------------------------------------------------- */

.tcs-form-note {
	max-width: 820px;
	border: 1px solid var(--tcs-border);
	border-inline-start: 3px solid var(--tcs-border-strong);
	border-radius: var(--tcs-radius);
	padding: var(--tcs-space-md);
	margin-block-end: var(--tcs-space-md);
}

.tcs-form-note p { margin: 0; }
.tcs-form-note p + p,
.tcs-form-note ul { margin-block-start: 0.4rem; }
.tcs-form-note ul { margin-block-end: 0; padding-inline-start: 1.1rem; }

.tcs-form-note--ok {
	border-inline-start-color: var(--tcs-state-instock);
	background: var(--tcs-state-instock-bg);
}

.tcs-form-note--bad {
	border-inline-start-color: var(--tcs-error);
	background: var(--tcs-error-bg);
}

/* The honeypot is for robots, and must stay reachable to them while being
   genuinely invisible - display:none would be a giveaway. */
.tcs-form__hp {
	position: absolute !important;
	inline-size: 1px;
	block-size: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* --- mobile -------------------------------------------------------------- */

@media (max-width: 640px) {
	.tcs-form__grid {
		grid-template-columns: 1fr;
		gap: var(--tcs-space-sm);
	}

	.tcs-form__field--half {
		grid-column: 1 / -1;
	}

	.tcs-form__actions .tcs-button {
		width: 100%;
		justify-content: center;
	}

	/* 16px prevents iOS zooming the page when a field takes focus. */
	.tcs-form__input,
	.tcs-form__select,
	.tcs-form__textarea {
		font-size: 16px;
	}
}
