/**
 * Listing edit form — restyled to match the supplied reference design
 * (chefcations-listing-form.html).
 *
 * Design tokens, spacing, radii, control sizing, focus rings and the
 * 12-column span system are ported from that file; selectors are mapped
 * onto HivePress's real markup (.hp-form__field / .hp-field__label /
 * .hp-field__description) and onto the section/grid wrappers built at
 * runtime by edit-form-groups.js in layout:'sections' mode.
 *
 * Everything is scoped under .ec-listing-form so the vendor edit form
 * (and every other HivePress form) is untouched, per "only update the
 * listing edit".
 */

/* Card shell. Applied to HivePress's own form-level class rather than the
 * inner fields container, so the submit footer (.hp-form__footer, a
 * sibling of the fields container) sits inside the card as the reference
 * design's actions bar. --hp-form--listing-update is already unique to
 * this one form, so this stays scoped without extra hooks. */
.hp-form--listing-update {
	background: #ffffff;
	border: 1px solid #dce3e5;
	border-radius: 16px;
	box-shadow: 0 8px 28px rgba( 24, 35, 38, .06 );
	overflow: hidden;
}

.ec-listing-form {
	--ecf-surface: #ffffff;
	--ecf-text: #182326;
	--ecf-muted: #667277;
	--ecf-line: #dce3e5;
	--ecf-accent: #087d78;
	--ecf-accent-dark: #05645f;
	--ecf-focus: rgba( 8, 125, 120, .18 );
	--ecf-danger: #b42318;

	color: var( --ecf-text );
}

/* ---------------------------------------------------------- sections */

.ec-listing-form .ec-form-section {
	padding: 30px;
}

.ec-listing-form .ec-form-section + .ec-form-section {
	border-top: 1px solid var( --ecf-line );
}

.ec-listing-form .ec-section-heading {
	margin-bottom: 22px;
}

.ec-listing-form .ec-section-heading h2 {
	margin: 0 0 4px;
	font-size: 1.15rem;
	line-height: 1.35;
	color: var( --ecf-text );
}

.ec-listing-form .ec-section-heading p {
	margin: 0;
	color: var( --ecf-muted );
	font-size: .9rem;
}

/* ------------------------------------------------------- 12-col grid */

.ec-listing-form .ec-field-grid {
	display: grid;
	grid-template-columns: repeat( 12, minmax( 0, 1fr ) );
	gap: 20px 18px;
	align-items: stretch;
}

/* Fields default to full width; explicit spans come from the JS config.
 * Span selectors repeat .ec-field-grid so they out-specify this default
 * rule — otherwise the 3-class default beats a 2-class span and every
 * field renders full width. */
.ec-listing-form .ec-field-grid > .hp-form__field {
	grid-column: span 12;
	min-width: 0;
}

.ec-listing-form .ec-field-grid > .ec-span-3 { grid-column: span 3; }
.ec-listing-form .ec-field-grid > .ec-span-4 { grid-column: span 4; }
.ec-listing-form .ec-field-grid > .ec-span-6 { grid-column: span 6; }
.ec-listing-form .ec-field-grid > .ec-span-8 { grid-column: span 8; }
.ec-listing-form .ec-field-grid > .ec-span-12 { grid-column: span 12; }

/* Each field is a flex column so label/control/description can be
 * reordered independent of HivePress's own markup order (see below). */
.ec-listing-form .ec-field-grid > .hp-form__field:not( .hp-form__field--checkbox ) {
	display: flex;
	flex-direction: column;
}

/* ------------------------------------------------------------ labels */

.ec-listing-form .hp-field__label {
	display: block;
	margin: 0 0 7px;
	padding: 0;
	background: none;
	border: 0;
	color: var( --ecf-text );
	font-size: .93rem;
	font-weight: 650;
	text-transform: none; /* reference uses sentence case, not the theme's uppercase */
	letter-spacing: normal;
}

/* order only matters inside the column-flex fields this reordering
 * scheme targets — the checkbox field's own row layout (see
 * .hp-form__field--checkbox below) has its own natural sequence, and
 * applying order:1 there reverses checkbox-then-label into label-then-
 * checkbox, which is exactly the bug this rule is scoped to avoid. */
.ec-listing-form .hp-form__field:not( .hp-form__field--checkbox ) > .hp-field__label {
	order: 1;
}

.ec-listing-form .hp-field__label .ec-required {
	color: var( --ecf-danger );
}

/* Only required fields get a marker (the red asterisk hp-forms.js adds
 * next to the label text) — the "(optional)" tag HivePress renders for
 * every non-required field (class-form.php: <small>(optional)</small>,
 * a sibling of the label's <span> text) is removed entirely rather than
 * hidden-but-still-taking-space, since it no longer carries information
 * once required fields are the only ones marked. */
.ec-listing-form .hp-field__label small {
	display: none;
}

/* Label → field box → help text. HivePress's own markup order is label,
 * then description, then the control (see class-form.php render()) —
 * description sitting between label and input was what caused uneven
 * row alignment: a field whose help text or (formerly) "(optional)" tag
 * wrapped to two lines pushed its input lower than shorter neighbors.
 * Moving help text below the control via flex order fixes this at the
 * source rather than compensating for it after the fact — the control
 * now sits directly under the label in every field, so a row only goes
 * uneven if the LABEL itself differs in height, which is rare now that
 * "(optional)" no longer inflates label length. */
.ec-listing-form .ec-field-grid > .hp-form__field:not( .hp-form__field--checkbox ) > *:last-child {
	order: 2;
}

.ec-listing-form .hp-field__description {
	display: block;
	margin-top: 6px;
	color: var( --ecf-muted );
	font-size: .82rem;
	line-height: 1.45;
	order: 3;
}

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

.ec-listing-form input[type="text"],
.ec-listing-form input[type="number"],
.ec-listing-form input[type="email"],
.ec-listing-form input[type="url"],
.ec-listing-form input[type="tel"],
.ec-listing-form input[type="time"],
.ec-listing-form select,
.ec-listing-form textarea,
.ec-listing-form .select2-container .select2-selection {
	width: 100%;
	max-width: none; /* overrides the width caps in hp-forms.css — spans size fields here */
	min-height: 44px;
	border: 1px solid #bfc9cc;
	border-radius: 8px;
	background: #fff;
	color: var( --ecf-text );
	font: inherit;
	padding: 10px 12px;
	transition: border-color .15s, box-shadow .15s;
}

.ec-listing-form input:focus,
.ec-listing-form select:focus,
.ec-listing-form textarea:focus {
	outline: 0;
	border-color: var( --ecf-accent );
	box-shadow: 0 0 0 4px var( --ecf-focus );
}

.ec-listing-form textarea {
	min-height: 130px;
	resize: vertical;
}

/* The long-form fields the reference marks as .tall */
.ec-listing-form [name="sample_menu"],
.ec-listing-form [name="description"] {
	min-height: 210px;
}

/* Select2 (HivePress renders category/tags through it) — match height
 * and border treatment so it doesn't read as a different control set.
 * Select2's own inner .select2-selection__rendered carries its own
 * default padding (7px 32px 7px 16px) on top of the 10px 12px already
 * set on the outer .select2-selection above — left un-zeroed, the two
 * stack and the box comes out noticeably taller/bulkier than a plain
 * input (81px vs the ~44px every other field box uses). */
.ec-listing-form .select2-container .select2-selection--multiple,
.ec-listing-form .select2-container .select2-selection--single {
	display: flex;
	align-items: center;
	height: auto;
}

.ec-listing-form .select2-container--default .select2-selection .select2-selection__rendered,
.ec-listing-form .select2-container--default .select2-selection--multiple .select2-selection__rendered {
	padding: 0;
}

.ec-listing-form .select2-container--focus .select2-selection,
.ec-listing-form .select2-container--open .select2-selection {
	border-color: var( --ecf-accent );
	box-shadow: 0 0 0 4px var( --ecf-focus );
}

/* File/attachment upload — dashed dropzone per the reference. Padding
 * matched to the standard input padding (10px 12px) below rather than
 * the reference's own 16px, which read noticeably bulkier than every
 * other field box once placed next to them. */
.ec-listing-form .hp-form__field--attachment-upload .hp-field__label + * {
	border: 1px dashed #aebbbf;
	border-radius: 10px;
	background: #fafcfc;
	padding: 10px 12px;
}

.ec-listing-form .hp-form__field--attachment-upload button,
.ec-listing-form .hp-form__field--attachment-upload .button {
	border: 0;
	border-radius: 6px;
	background: #e8f3f2;
	color: var( --ecf-accent-dark );
	font-weight: 650;
	padding: 7px 11px;
	min-height: 0;
	cursor: pointer;
}

/* Checkbox fields as bordered cards. */
.ec-listing-form .hp-form__field--checkbox {
	display: flex;
	gap: 11px;
	align-items: flex-start;
	border: 1px solid var( --ecf-line );
	border-radius: 9px;
	background: #fafcfc;
	padding: 14px;
}

.ec-listing-form .hp-form__field--checkbox input[type="checkbox"] {
	width: 18px;
	min-height: 18px;
	margin: 2px 0 0;
	accent-color: var( --ecf-accent );
}

.ec-listing-form .hp-form__field--checkbox .hp-field__label {
	margin: 0;
	font-weight: 600;
	cursor: pointer;
}

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

/* Reference's .form-actions: right-aligned button on a tinted footer
 * strip inside the card. HivePress renders the submit as an
 * <input type="submit"> inside .hp-form__footer. */
.hp-form--listing-update .hp-form__footer {
	display: flex;
	justify-content: flex-end;
	margin: 0;
	padding: 20px 30px;
	border-top: 1px solid #dce3e5;
	background: #fafcfc;
}

.hp-form--listing-update .hp-form__footer input[type="submit"],
.hp-form--listing-update .hp-form__footer button[type="submit"] {
	width: auto;
	min-height: 46px;
	border: 0;
	border-radius: 8px;
	background: #087d78;
	color: #fff;
	font: inherit;
	font-weight: 700;
	padding: 11px 24px;
	cursor: pointer;
	transition: background .15s;
}

.hp-form--listing-update .hp-form__footer input[type="submit"]:hover,
.hp-form--listing-update .hp-form__footer button[type="submit"]:hover {
	background: #05645f;
}

.hp-form--listing-update .hp-form__footer input[type="submit"]:focus-visible,
.hp-form--listing-update .hp-form__footer button[type="submit"]:focus-visible {
	outline: 4px solid rgba( 8, 125, 120, .18 );
	outline-offset: 2px;
}

/* -------------------------------------------------------- responsive */

@media ( max-width: 720px ) {
	.ec-listing-form .ec-form-section {
		padding: 24px 20px;
	}

	/* Must repeat .ec-field-grid to out-specify the desktop default
	 * (.ec-listing-form .ec-field-grid > .hp-form__field), otherwise the
	 * 3-class default beats these and nothing collapses on mobile. */
	.ec-listing-form .ec-field-grid > .ec-span-3,
	.ec-listing-form .ec-field-grid > .ec-span-4,
	.ec-listing-form .ec-field-grid > .ec-span-6,
	.ec-listing-form .ec-field-grid > .ec-span-8 {
		grid-column: span 12;
	}
}

@media ( min-width: 721px ) and ( max-width: 840px ) {
	.ec-listing-form .ec-field-grid > .ec-span-3 {
		grid-column: span 6;
	}
}
