/**
 * Job sheet form — mobile first.
 *
 * Sized for a phone held in one hand, outdoors, possibly with a glove on:
 * large tap targets, 16px inputs (anything smaller triggers iOS zoom on
 * focus), generous spacing between fields.
 *
 * The form is a self-contained panel: it carries its own type, colour and
 * card styling instead of inheriting the client theme's form look. This page
 * is a field tool for jb_client users, not public content — consistency
 * across client sites beats theme deference. Everything hangs off tokens on
 * .jb-sheet; no fonts, icons or images are fetched (poor-signal rule), the
 * select chevron is an inline data URI.
 */

.jb-sheet {
	--jb-ink: #0f172a;
	--jb-muted: #5b6779;
	--jb-accent: #1d4ed8;
	--jb-accent-deep: #1e40af;
	--jb-accent-tint: rgba( 29, 78, 216, 0.08 );
	--jb-error: #b91c1c;
	--jb-ok: #15803d;
	--jb-line: #e2e8f0;
	--jb-line-strong: #c4cdd9;
	--jb-card: #ffffff;
	--jb-page-pad: 1.25rem;
	--jb-radius: 0.875rem;
	--jb-radius-sm: 0.5625rem;
	--jb-shadow: 0 1px 2px rgba( 15, 23, 42, 0.05 ), 0 6px 20px rgba( 15, 23, 42, 0.05 );

	max-width: 42rem;
	margin: 0 auto;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
	color: var( --jb-ink );
	line-height: 1.5;
	counter-reset: jb-step;
}

.jb-guidance {
	margin: 0 0 1.5rem;
	padding: 0.9375rem 1.125rem;
	border-left: 3px solid var( --jb-accent );
	border-radius: 0 var( --jb-radius-sm ) var( --jb-radius-sm ) 0;
	background: var( --jb-accent-tint );
	font-size: 0.9375rem;
}

/* --- Cards --------------------------------------------------------------- */

.jb-card {
	margin: 0 0 1.125rem;
	padding: var( --jb-page-pad );
	background: var( --jb-card );
	border: 1px solid var( --jb-line );
	border-radius: var( --jb-radius );
	box-shadow: var( --jb-shadow );
}

/* Fieldset cards (photos, consent): the .jb-card margin/padding already
   override the UA fieldset chrome; only the shrink-wrap sizing needs undoing. */
fieldset.jb-card {
	min-inline-size: 0;
}

.jb-card__title {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin: 0 0 1.25rem;
	padding: 0;
	font-size: 1.0625rem;
	font-weight: 700;
	line-height: 1.3;
	color: var( --jb-ink );
	counter-increment: jb-step;
}

/* Legends do not obey margin like headings; float keeps the title inside the
   card's padding box, and the clear puts the first field below it. */
legend.jb-card__title {
	float: left;
	width: 100%;
}

legend.jb-card__title + * {
	clear: both;
}

/* Step number: pure CSS counter, no markup and nothing fetched. */
.jb-card__title::before {
	content: counter( jb-step );
	flex: 0 0 auto;
	display: grid;
	place-items: center;
	width: 1.75rem;
	height: 1.75rem;
	border-radius: 50%;
	background: var( --jb-accent-tint );
	color: var( --jb-accent );
	font-size: 0.9375rem;
	font-weight: 700;
}

/* --- Fields -------------------------------------------------------------- */

.jb-field {
	margin-bottom: 1.375rem;
}

.jb-field:last-child {
	margin-bottom: 0;
}

.jb-field__label {
	display: block;
	margin-bottom: 0.4375rem;
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1.35;
}

.jb-field__required {
	color: var( --jb-accent );
	font-weight: 700;
}

/* The yes/no field is a fieldset with a legend; strip the browser chrome so
   it sits flush with the surrounding single-control fields. */
fieldset.jb-field {
	border: 0;
	padding: 0;
	margin-inline: 0;
	min-inline-size: 0;
}

legend.jb-field__label {
	padding: 0;
}

/* Failed validation: the field says it, so nothing has to be written under
   the button. Colour is not the only signal — aria-invalid carries it for
   screen readers, and the border weight changes as well as its hue. */
.jb-field--error .jb-field__label,
.jb-field--error .jb-field__helper {
	color: var( --jb-error );
}

.jb-field--error .jb-input,
.jb-field--error .jb-toggle__option {
	border-color: var( --jb-error );
	border-width: 2px;
	background: rgba( 185, 28, 28, 0.04 );
}

.jb-field--error .jb-input:focus {
	border-color: var( --jb-error );
	box-shadow: 0 0 0 3px rgba( 185, 28, 28, 0.15 );
}

/* Shown only when an answer is too short — a blank field needs no caption. */
.jb-field__hint {
	margin: 0.375rem 0 0;
	font-size: 0.875rem;
	font-weight: 600;
	line-height: 1.4;
	color: var( --jb-error );
}

.jb-field__hint[hidden] {
	display: none;
}

.jb-field__helper {
	margin: 0 0 0.5rem;
	font-size: 0.8125rem;
	line-height: 1.45;
	color: var( --jb-muted );
}

.jb-input {
	display: block;
	width: 100%;
	box-sizing: border-box;
	padding: 0.8125rem 1rem;
	font: inherit;
	font-size: 1rem; /* 16px minimum: smaller values zoom the viewport on iOS */
	line-height: 1.4;
	border: 1.5px solid var( --jb-line-strong );
	border-radius: var( --jb-radius-sm );
	background: #fff;
	color: var( --jb-ink );
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.jb-input:focus {
	outline: 2px solid transparent; /* keeps a ring in forced-colors mode */
	border-color: var( --jb-accent );
	box-shadow: 0 0 0 3px var( --jb-accent-tint );
}

textarea.jb-input {
	min-height: 7rem;
	resize: vertical;
}

/* Native select chrome replaced; the chevron is inline, nothing is fetched. */
select.jb-input {
	appearance: none;
	-webkit-appearance: none;
	padding-right: 2.75rem;
	background-image: url( "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%235b6779' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E" );
	background-repeat: no-repeat;
	background-position: right 1rem center;
}

.jb-field__conditional {
	margin-top: 0.75rem;
}

.jb-sheet input[type="checkbox"],
.jb-sheet input[type="radio"] {
	accent-color: var( --jb-accent );
}

/* --- Yes/no toggle ------------------------------------------------------- */

.jb-toggle {
	display: flex;
	gap: 0.625rem;
}

.jb-toggle__option {
	flex: 1 1 0;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	min-height: 3rem;
	padding: 0.5rem 1rem;
	border: 1.5px solid var( --jb-line-strong );
	border-radius: var( --jb-radius-sm );
	background: #fff;
	font-weight: 600;
	cursor: pointer;
	transition: border-color 0.15s ease, background-color 0.15s ease;
}

.jb-toggle__option:focus-within {
	outline: 2px solid transparent;
	border-color: var( --jb-accent );
	box-shadow: 0 0 0 3px var( --jb-accent-tint );
}

/* The segmented look — radio hidden, chosen option filled — only where :has()
   exists; elsewhere the visible radio dot keeps carrying the state. */
@supports selector( :has( * ) ) {
	.jb-toggle__option input[type="radio"] {
		position: absolute;
		opacity: 0;
		pointer-events: none;
	}

	.jb-toggle__option:has( input:checked ) {
		border-color: var( --jb-accent );
		background: var( --jb-accent-tint );
		color: var( --jb-accent-deep );
	}

	.jb-toggle__option:has( input:checked ) span::before {
		content: "✓ ";
	}
}

/* --- Photos -------------------------------------------------------------- */

.jb-photos__list {
	display: grid;
	grid-template-columns: repeat( auto-fill, minmax( 8.5rem, 1fr ) );
	gap: 1rem;
	margin: 0 0 1rem;
	padding: 0;
	list-style: none;
}

.jb-photo {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 0.375rem;
}

.jb-photo__frame {
	position: relative;
	aspect-ratio: 4 / 3;
	overflow: hidden;
	border-radius: var( --jb-radius-sm );
	border: 1px solid var( --jb-line );
	background: #f1f5f9;
}

.jb-photo__img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

/* Uploading and failed states dim the photo so the status reads on top. */
.jb-photo--uploading .jb-photo__img,
.jb-photo--failed .jb-photo__img,
.jb-photo--rejected .jb-photo__img {
	opacity: 0.55;
}

.jb-photo--failed .jb-photo__frame {
	border-color: var( --jb-error );
	cursor: pointer;
}

.jb-photo__progress {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	height: 0.375rem;
	background: rgba( 15, 23, 42, 0.35 );
}

.jb-photo__progress[hidden] {
	display: none;
}

.jb-photo__progress span {
	display: block;
	height: 100%;
	width: 0;
	background: var( --jb-accent );
	transition: width 0.2s ease;
}

.jb-photo__name {
	margin: 0;
	font-size: 0.75rem;
	line-height: 1.3;
	color: var( --jb-muted );
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.jb-photo__status {
	margin: 0;
	font-size: 0.8125rem;
	line-height: 1.35;
	min-height: 1em;
	color: var( --jb-muted );
}

.jb-photo__status--error {
	color: var( --jb-error );
	font-weight: 600;
}

.jb-photo__role {
	width: 100%;
	box-sizing: border-box;
	padding: 0.5rem;
	font: inherit;
	font-size: 0.875rem;
	border: 1px solid var( --jb-line-strong );
	border-radius: 0.4375rem;
	background: #fff;
	color: var( --jb-ink );
}

/* Sits on the photo corner: reachable with a thumb, clear of the role select. */
.jb-photo__remove {
	position: absolute;
	top: 0.375rem;
	right: 0.375rem;
	width: 2rem;
	height: 2rem;
	padding: 0;
	font-size: 1.25rem;
	line-height: 1;
	border: 0;
	border-radius: 50%;
	background: rgba( 15, 23, 42, 0.65 );
	color: #fff;
	cursor: pointer;
}

/* Mid-upload there is nothing sane to remove yet. */
.jb-photo--uploading .jb-photo__remove {
	display: none;
}

/* Add tile: sized like a photo so the grid reads "the next one goes here". */
.jb-photos__add {
	display: grid;
	place-items: center;
	align-content: center;
	gap: 0.25rem;
	width: 100%;
	max-width: 10.5rem;
	aspect-ratio: 4 / 3;
	box-sizing: border-box;
	padding: 0.5rem;
	background: transparent;
	border: 2px dashed var( --jb-line-strong );
	border-radius: var( --jb-radius-sm );
	color: var( --jb-muted );
	font-weight: 600;
	font-size: 0.9375rem;
	text-align: center;
	cursor: pointer;
	transition: border-color 0.15s ease, color 0.15s ease;
}

.jb-photos__add::before {
	content: "+";
	font-size: 1.625rem;
	line-height: 1;
	color: var( --jb-accent );
}

.jb-photos__add:hover,
.jb-photos__add:focus-within {
	border-color: var( --jb-accent );
	color: var( --jb-accent-deep );
}

.jb-photos__add[hidden] {
	display: none;
}

.jb-photos__input {
	display: none;
}

.jb-photos__count {
	margin: 0.5rem 0 0;
	font-size: 0.875rem;
	color: var( --jb-muted );
}

/* --- Consent ------------------------------------------------------------- */

.jb-consent__item {
	display: flex;
	gap: 0.75rem;
	align-items: flex-start;
	margin-bottom: 1rem;
	line-height: 1.4;
	cursor: pointer;
}

.jb-consent__item:last-child {
	margin-bottom: 0;
}

.jb-consent__item input[type="checkbox"] {
	flex: 0 0 auto;
	width: 1.375rem;
	height: 1.375rem;
	margin-top: 0.0625rem;
}

.jb-consent__helper {
	display: block;
	margin-top: 0.25rem;
	font-size: 0.8125rem;
	font-style: normal;
	color: var( --jb-muted );
}

/* --- Actions ------------------------------------------------------------- */

.jb-actions {
	margin-top: 1.75rem;
	text-align: center;
}

/* "6 of 7 required answered" — revealed by form.js, quiet until then. */
.jb-req-count {
	display: inline-flex;
	margin: 0 0 0.875rem;
	padding: 0.375rem 0.9375rem;
	border-radius: 999px;
	background: #eef2f7;
	color: var( --jb-muted );
	font-size: 0.875rem;
	font-weight: 600;
}

.jb-req-count--done {
	background: rgba( 22, 163, 74, 0.12 );
	color: var( --jb-ok );
}

.jb-req-count[hidden] {
	display: none;
}

/* "Draft saved ✓" — quiet reassurance under the counter, revealed by
   form.js after a successful server autosave. */
.jb-saved {
	margin: 0 0 0.875rem;
	color: var( --jb-ok );
	font-size: 0.8125rem;
	font-weight: 600;
}

.jb-saved[hidden] {
	display: none;
}

.jb-button {
	display: inline-block;
	min-height: 3.25rem;
	padding: 0.875rem 1.75rem;
	font: inherit;
	font-size: 1.0625rem;
	font-weight: 600;
	border: 1px solid transparent;
	border-radius: var( --jb-radius-sm );
	cursor: pointer;
	text-decoration: none;
	transition: background-color 0.15s ease;
}

.jb-button--primary {
	width: 100%;
	background: var( --jb-accent );
	color: #fff;
	box-shadow: 0 2px 8px rgba( 29, 78, 216, 0.3 );
}

.jb-button--primary:hover:not( :disabled ) {
	background: var( --jb-accent-deep );
}

.jb-button--primary:active:not( :disabled ) {
	transform: translateY( 1px );
}

.jb-button--primary:disabled {
	opacity: 0.6;
	cursor: default;
}

.jb-actions__note {
	margin: 0.75rem 0 0;
	font-size: 0.9375rem;
	line-height: 1.4;
	min-height: 1.4em;
}

.jb-actions__note--error {
	color: var( --jb-error );
	font-weight: 600;
}

/* --- In-progress chooser (s10) ------------------------------------------- */

.jb-drafts {
	list-style: none;
	margin: 0 0 1.25rem;
	padding: 0;
}

.jb-draft-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	flex-wrap: wrap;
}

.jb-draft-row__info {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	min-width: 0;
}

.jb-draft-row__title {
	font-size: 1.0625rem;
	overflow-wrap: anywhere;
}

.jb-draft-row__meta {
	color: var( --jb-muted );
	font-size: 0.875rem;
}

.jb-draft-row__actions {
	display: flex;
	align-items: center;
	gap: 0.625rem;
	flex-shrink: 0;
}

/* Continue is the primary action; sized down from the full-width submit. */
.jb-draft-row__continue {
	width: auto;
	min-height: 2.75rem;
	padding: 0.625rem 1.25rem;
}

/* Delete stays visually quiet: destructive, but never the eye-catcher. */
.jb-draft-row__delete {
	min-height: 2.75rem;
	padding: 0.625rem 1rem;
	background: transparent;
	border-color: currentColor;
	color: var( --jb-error );
}

.jb-drafts__new {
	margin: 0;
	text-align: center;
}

/* --- Notices ------------------------------------------------------------- */

.jb-notice {
	margin: 0 0 1.25rem;
	padding: 1rem 1.125rem;
	border-radius: var( --jb-radius );
	border: 1px solid var( --jb-line );
	background: var( --jb-card );
	box-shadow: var( --jb-shadow );
}

.jb-notice p {
	margin: 0;
}

.jb-notice--success {
	border-color: rgba( 22, 163, 74, 0.4 );
	background: #f2faf5;
	/* The success panel replaces the form entirely (Form::render), so it is
	   the whole page at that moment — center it and let it breathe. */
	text-align: center;
	padding: 2.75rem 1.5rem;
	font-size: 1.15rem;
	line-height: 1.6;
}

.jb-notice--success p + p {
	/* Air between the message and the start-another button. */
	margin-top: 1.75rem;
}

.jb-notice--error {
	border-color: rgba( 185, 28, 28, 0.45 );
	background: #fdf5f5;
}

@media ( min-width: 40rem ) {
	.jb-sheet {
		--jb-page-pad: 1.5rem;
	}

	.jb-button--primary {
		width: auto;
		min-width: 16rem;
	}
}
