/*
 * PB Forms front end.
 *
 * Everything visual is driven by the custom properties on .pbf, so a theme (or the style
 * options planned for a later version) only has to override these variables.
 */
.pbf {
	--pbf-gap: 1em;
	--pbf-radius: 4px;
	--pbf-border: #8c8f94;
	--pbf-bg: #fff;
	--pbf-text: inherit;
	--pbf-accent: #2271b1;
	--pbf-accent-text: #fff;
	--pbf-error: #b32d2e;
	--pbf-success: #1a7f37;
	--pbf-label-weight: 600;
	--pbf-input-pad: 0.5em 0.7em;

	/* One size drives everything (padding, gaps and controls are all in em). The "Text size"
	   setting writes --pbf-scale; 0.9 is the default. */
	font-size: calc(1em * var(--pbf-scale, 0.9));
	line-height: 1.4;
	color: var(--pbf-text);
}

.pbf *,
.pbf *::before,
.pbf *::after {
	box-sizing: border-box;
}

.pbf-fields {
	display: grid;
	grid-template-columns: repeat(6, minmax(0, 1fr));
	gap: var(--pbf-gap);
}

.pbf-field {
	grid-column: 1 / -1;
	min-width: 0;
}

/* Conditionally shown fields that are currently hidden. */
.pbf .pbf-field[hidden] {
	display: none !important;
}

/* Widths are fractions of a 6-column grid. */
.pbf-width-two-thirds {
	grid-column: span 4;
}

.pbf-width-half {
	grid-column: span 3;
}

.pbf-width-third {
	grid-column: span 2;
}

/*
 * Spacer: a blank cell that fills the rest of its row. The span is worked out on the server for
 * each breakpoint (d = desktop, t = tablet) from the widths of the fields before it.
 */
.pbf-field--spacer {
	grid-column: span 6;
}

.pbf-sp-d1 { grid-column: span 1; }
.pbf-sp-d2 { grid-column: span 2; }
.pbf-sp-d3 { grid-column: span 3; }
.pbf-sp-d4 { grid-column: span 4; }
.pbf-sp-d5 { grid-column: span 5; }
.pbf-sp-d6 { grid-column: span 6; }

/* Tablets: thirds become halves so inputs stay usable. */
@media (max-width: 800px) {
	.pbf-width-third,
	.pbf-width-two-thirds {
		grid-column: span 3;
	}

	.pbf-sp-t3 { grid-column: span 3; }
	.pbf-sp-t6 { grid-column: span 6; }
}

/* Phones: everything full width, and blank spacer cells disappear (they only make sense beside other fields). */
@media (max-width: 600px) {
	.pbf-field--spacer {
		display: none;
	}

	.pbf-width-third,
	.pbf-width-two-thirds,
	.pbf-width-half {
		grid-column: 1 / -1;
	}
}

.pbf-label {
	display: block;
	margin: 0 0 0.3em;
	padding: 0;
	font-size: 0.95em;
	font-weight: var(--pbf-label-weight);
}

.pbf-req {
	color: var(--pbf-error);
}

/*
 * Fields follow the theme. Layout (display, width, font size) is fixed so the grid and the
 * "Text size" setting work, but the look (border, background, padding, radius, colour) sits inside
 * :where(), which has zero specificity: any rule your theme or global styles set for
 * input / select / textarea wins, and these values only fill in where the theme says nothing.
 */
.pbf-input {
	display: block;
	width: 100%;
	max-width: 100%;
	margin: 0;
	font-size: inherit;
	vertical-align: top;
}

/*
 * Alignment guard. Themes often style inputs and selects with margins, offsets or transforms
 * (sometimes with selectors more specific than ours), which pushes one control off its row.
 * Layout-affecting properties are therefore pinned on form controls. Colours, borders, radius,
 * padding and fonts are left for the theme.
 */
.pbf .pbf-input,
.pbf .pbf-submit {
	margin: 0 !important;
	position: static !important;
	inset: auto !important;
	transform: none !important;
	translate: none !important;
	float: none !important;
	box-sizing: border-box !important;
	vertical-align: top !important;
}

.pbf .pbf-phone > .pbf-input {
	align-self: stretch !important;
}

:where(.pbf-input) {
	padding: var(--pbf-input-pad);
	border: 1px solid var(--pbf-border);
	border-radius: var(--pbf-radius);
	background-color: var(--pbf-bg);
	color: inherit;
	font-family: inherit;
	line-height: 1.4;
}

/* Native date/time controls ship with extra internal height; keep them level with their neighbours. */
.pbf-input[type="date"] {
	height: calc(1.4em + 1em + 2px);
	line-height: 1.4;
}

.pbf-input[type="date"]::-webkit-datetime-edit,
.pbf-input[type="date"]::-webkit-date-and-time-value {
	padding: 0;
	margin: 0;
	min-height: 1.4em;
	line-height: 1.4;
}

/* Dropdowns: draw our own arrow so a select looks like the text fields beside it. */
:where(select.pbf-input) {
	appearance: none;
	padding-right: 2em;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23646970' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.75em center;
	background-size: 0.7em auto;
}

.pbf-input:focus-visible,
.pbf-submit:focus-visible {
	outline: 2px solid var(--pbf-accent);
	outline-offset: 2px;
}

textarea.pbf-input {
	resize: vertical;
}

/*
 * Phone: a narrow country select and the number on one row. The select's options start with the
 * dial code followed by a run of non-breaking spaces and then the country name. Closed, the
 * narrow box only has room for the code (+44); open, the list shows the full names.
 */
.pbf-phone {
	display: flex;
	align-items: stretch;
	gap: 0.4em;
}

.pbf-phone__country {
	flex: 0 0 auto;
	width: 5.6em;
	min-width: 0;
	text-overflow: clip;
}

.pbf-phone__number {
	flex: 1 1 0;
	width: auto;
	min-width: 0;
}

/* Radios, checkboxes and consent. */
.pbf-group {
	margin: 0;
	padding: 0;
	border: 0;
	min-width: 0;
}

.pbf-choices {
	display: flex;
	flex-direction: column;
	gap: 0.4em;
}

.pbf-choice {
	display: flex;
	align-items: flex-start;
	gap: 0.55em;
	cursor: pointer;
}

.pbf-choice {
	line-height: 1.4;
}

/* Fixed box, no theme margins: centred on the first line of text (line box 1.4em, box 1em). */
.pbf-choice input {
	flex: none;
	width: 1em;
	height: 1em;
	margin: 0.2em 0 0;
	padding: 0;
	font-size: inherit;
}

.pbf-help {
	margin: 0.35em 0 0;
	font-size: 0.875em;
	opacity: 0.75;
}

.pbf-error {
	margin: 0.35em 0 0;
	font-size: 0.875em;
	color: var(--pbf-error);
}

.pbf-has-error .pbf-input {
	border-color: var(--pbf-error) !important;
}

.pbf-heading {
	margin: 0;
	font-size: 1.25em;
	line-height: 1.3;
}

.pbf-divider {
	height: 0;
	margin: 0.25em 0;
	border: 0;
	border-top: 1px solid currentColor;
	opacity: 0.2;
}

.pbf-paragraph {
	margin: 0;
}

.pbf-turnstile {
	margin-top: var(--pbf-gap);
}

.pbf-actions {
	margin-top: var(--pbf-gap);
}

:where(.pbf-submit) {
	padding: 0.55em 1.4em;
	border: 0;
	border-radius: var(--pbf-radius);
	background: var(--pbf-accent);
	color: var(--pbf-accent-text);
	font-family: inherit;
	font-weight: 600;
	cursor: pointer;
}

.pbf-submit {
	font-size: inherit;
}

.pbf-submit:hover {
	filter: brightness(1.1);
}

.pbf-submit:disabled {
	opacity: 0.6;
	cursor: wait;
}

.pbf-status:empty {
	display: none;
}

.pbf-status {
	margin-top: var(--pbf-gap);
}

.pbf-status--error {
	color: var(--pbf-error);
}

.pbf-status--ok {
	color: var(--pbf-success);
	font-weight: 600;
}

.pbf-status:focus {
	outline: none;
}

.pbf-notice {
	padding: 0.75em 1em;
	border-left: 4px solid var(--pbf-accent);
	background: rgba(0, 0, 0, 0.04);
}

/* Honeypot: off-screen rather than display:none, which some bots skip. */
.pbf-hp {
	position: absolute !important;
	left: -9999px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

@media (prefers-reduced-motion: no-preference) {
	.pbf-submit {
		transition: filter 0.15s ease;
	}
}
