/**
 * Forms — front-end styles.
 *
 * A front-end form renders inside the user's THEME, where the BE admin design
 * system is not loaded — so this is a self-contained, theme-friendly stylesheet
 * using its own `.bef-` namespace (Blaminhor Essentials Forms). It does NOT
 * recreate any admin `.be-*` component. Tokens are used with sensible fallbacks
 * so it degrades gracefully if the tokens sheet is absent. Accessibility first:
 * visible focus, clear required/error affordances, never colour alone.
 */

.bef-form {
	--bef-gap: var(--be-space-3, 16px);
	display: flex;
	flex-wrap: wrap;
	gap: var(--bef-gap);
	max-width: 640px;
}

/* The JS hides steps, conditional fields and nav buttons via the `hidden`
   attribute. Author rules like `.bef-step { display: flex }` would otherwise
   beat the UA `[hidden] { display: none }`, leaving every step on screen —
   which silently breaks multi-step and conversational mode. Force it. */
.bef-form [hidden] {
	display: none !important;
}

.bef-form__field {
	flex: 1 1 100%;
	min-width: 0;
}

.bef-form__field--two_thirds {
	flex: 1 1 calc(66.666% - var(--bef-gap));
}

.bef-form__field--half {
	flex: 1 1 calc(50% - var(--bef-gap));
}

.bef-form__field--third {
	flex: 1 1 calc(33.333% - var(--bef-gap));
}

.bef-form__field--quarter {
	flex: 1 1 calc(25% - var(--bef-gap));
}

.bef-form__label,
.bef-form__group legend {
	display: block;
	margin-bottom: var(--be-space-1, 4px);
	font-weight: 600;
}

.bef-form__required {
	color: var(--be-color-danger, #d63638);
	margin-left: 2px;
}

.bef-form__control {
	width: 100%;
	box-sizing: border-box;
	padding: 8px 10px;
	border: 1px solid var(--be-surface-border, #c3c4c7);
	border-radius: var(--be-radius-sm, 4px);
	font: inherit;
	color: inherit;
	background: #fff;
}

.bef-form__control:focus,
.bef-form__choice input:focus,
.bef-form__consent input:focus,
.bef-form__submit:focus {
	outline: 2px solid var(--be-color-primary, #2271b1);
	outline-offset: 1px;
}

textarea.bef-form__control {
	resize: vertical;
	min-height: 120px;
}

.bef-form__group {
	border: 0;
	padding: 0;
	margin: 0;
}

/* Rating: a 1–5 radio scale laid out inline, each cued with a star glyph
   (the radios stay real + labelled for accessibility). */
.bef-form__group--rating {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
}

.bef-form__group--rating .bef-form__choice {
	margin: 0;
}

.bef-form__group--rating .bef-form__choice span::before {
	content: "\2605 ";
	color: var(--be-color-warning, #dba617);
}

/* Range slider: track stretches, value reads out alongside it. */
.bef-form__range {
	display: flex;
	align-items: center;
	gap: var(--be-space-2, 8px);
}

.bef-form__control--range {
	flex: 1 1 auto;
	width: auto;
	padding: 0;
	border: 0;
	background: none;
	accent-color: var(--be-color-primary, #2271b1);
}

.bef-form__range-output {
	flex: 0 0 auto;
	min-width: 2.5em;
	text-align: right;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	color: var(--be-text-default, #1d2327);
}

/* Repeatable group: each row lays its column inputs out in a responsive line,
   with a remove control; the Add row button sits below. */
.bef-form__repeater-row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--be-space-2, 8px);
	margin-bottom: var(--be-space-2, 8px);
}

.bef-form__repeater-cell {
	flex: 1 1 160px;
	margin: 0;
}

.bef-form__repeater-cell .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.bef-form__repeater-remove {
	flex: 0 0 auto;
	color: var(--be-color-danger, #d63638);
}

.bef-form__repeater-add {
	margin-top: var(--be-space-1, 4px);
}

/* Admin preview: a top banner + centered form. Scoped so it only affects the
   standalone preview document, never a real embedded form. */
.bef-form__preview-banner {
	position: sticky;
	top: 0;
	z-index: 10;
	padding: 10px 16px;
	background: var(--be-color-warning-soft, #fcf9e8);
	color: var(--be-color-warning, #8a6d00);
	border-bottom: 1px solid var(--be-color-warning, #dba617);
	text-align: center;
	font-weight: 600;
}

.bef-preview-page__inner {
	max-width: 680px;
	margin: 24px auto;
	padding: 0 16px;
}

/* Calculation: a read-only computed result, visually set apart from inputs. */
.bef-form__control--calc {
	background: var(--be-surface-bg, #f6f7f7);
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

/* Signature pad: a bordered drawing surface with a Clear action below. */
.bef-form__signature {
	display: block;
}

.bef-form__signature-pad {
	display: block;
	width: 100%;
	max-width: 500px;
	height: auto;
	aspect-ratio: 500 / 180;
	border: 1px solid var(--be-surface-border, #c3c4c7);
	border-radius: var(--be-radius-sm, 4px);
	background: #fff;
	touch-action: none;
	cursor: crosshair;
}

.bef-form__signature-clear {
	margin-top: var(--be-space-1, 4px);
}

/* Image choice: a responsive grid of selectable picture tiles (the radios
   stay real + labelled; the tile highlights when its radio is checked). */
.bef-form__group--image {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
	gap: var(--be-space-2, 8px);
}

.bef-form__choice--image {
	flex-direction: column;
	align-items: center;
	text-align: center;
	gap: var(--be-space-1, 4px);
	padding: var(--be-space-2, 8px);
	border: 1px solid var(--be-surface-border, #c3c4c7);
	border-radius: var(--be-radius-md, 6px);
	cursor: pointer;
}

.bef-form__choice--image:has( input:checked ) {
	border-color: var(--be-color-primary, #2271b1);
	box-shadow: 0 0 0 1px var(--be-color-primary, #2271b1);
}

.bef-form__choice-img {
	display: block;
	width: 100%;
	height: auto;
	border-radius: var(--be-radius-sm, 4px);
	object-fit: cover;
}

.bef-form__choice,
.bef-form__consent {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	margin-bottom: var(--be-space-1, 4px);
	font-weight: 400;
}

.bef-form__choice input,
.bef-form__consent input {
	margin-top: 3px;
	flex: 0 0 auto;
}

.bef-form__help {
	margin: var(--be-space-1, 4px) 0 0;
	font-size: 0.875em;
	color: var(--be-text-muted, #646970);
}

.bef-form__error {
	margin: var(--be-space-1, 4px) 0 0;
	font-size: 0.875em;
	font-weight: 600;
	color: var(--be-color-danger, #d63638);
}

.bef-form__field--has-error .bef-form__control {
	border-color: var(--be-color-danger, #d63638);
}

/* Self-contained notices (the admin .be-notice is not available on the front-end). */
.bef-notice {
	flex: 1 1 100%;
	margin: 0 0 var(--be-space-2, 8px);
	padding: var(--be-space-2, 12px) var(--be-space-3, 16px);
	border-left: 4px solid var(--be-color-info, #2271b1);
	background: var(--be-color-info-soft, #f0f6fc);
	border-radius: var(--be-radius-sm, 4px);
}

.bef-notice--danger {
	border-left-color: var(--be-color-danger, #d63638);
	background: var(--be-color-danger-soft, #fcf0f1);
}

.bef-notice--success {
	border-left-color: var(--be-color-success, #00a32a);
	background: var(--be-color-success-soft, #edfaef);
}

.bef-form__errors-title {
	margin: 0 0 var(--be-space-1, 4px);
	font-weight: 700;
}

.bef-form__errors ul {
	margin: 0;
	padding-left: 1.2em;
}

.bef-form__actions {
	flex: 1 1 100%;
}

.bef-form__submit {
	display: inline-flex;
	align-items: center;
	padding: 10px 20px;
	border: 0;
	border-radius: var(--be-radius-sm, 4px);
	background: var(--be-color-primary, #2271b1);
	color: #fff;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	transition: background var(--be-duration, 150ms) ease;
}

.bef-form__submit:hover {
	background: var(--be-color-primary-hover, #135e96);
}

.bef-form__submit[disabled] {
	opacity: 0.6;
	cursor: default;
}

/* Multi-step */
.bef-steps {
	flex: 1 1 100%;
	display: flex;
	flex-wrap: wrap;
	gap: var(--bef-gap);
}

.bef-step {
	flex: 1 1 100%;
	display: flex;
	flex-wrap: wrap;
	gap: var(--bef-gap);
}

.bef-steps__nav {
	flex: 1 1 100%;
	display: flex;
	gap: 8px;
}

.bef-form__nav-btn {
	background: var(--be-color-gray-600, #50575e);
}

.bef-progress {
	flex: 1 1 100%;
}

.bef-progress__track {
	height: 6px;
	border-radius: 999px;
	background: var(--be-surface-border, #dcdcde);
	overflow: hidden;
}

.bef-progress__fill {
	display: block;
	height: 100%;
	width: 0;
	background: var(--be-color-primary, #2271b1);
	transition: width var(--be-duration, 150ms) ease;
}

.bef-progress__label {
	margin: 4px 0 0;
	font-size: 0.875em;
	color: var(--be-text-muted, #646970);
}
