HEX
Server: nginx/1.24.0
System: Linux 0c1023d6c65e 6.8.0-137-generic #137-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 17 20:28:23 UTC 2026 x86_64
User: root (0)
PHP: 8.3.33
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/mu-plugins/ethnic-request-proposal-page.php
<?php
/**
 * Plugin Name: Ethnic Request a Proposal Page
 * Description: Creates and renders the Request a Proposal page with a structured project inquiry form.
 * Version: 1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! defined( 'ETHNIC_PROPOSAL_REQUEST_POST_TYPE' ) ) {
	define( 'ETHNIC_PROPOSAL_REQUEST_POST_TYPE', 'ethnic_proposal_req' );
}

if ( ! defined( 'ETHNIC_PROPOSAL_REQUEST_META_KEY' ) ) {
	define( 'ETHNIC_PROPOSAL_REQUEST_META_KEY', '_ethnic_proposal_request' );
}

if ( ! function_exists( 'ethnic_request_proposal_page_get_target_page' ) ) {
	function ethnic_request_proposal_page_get_target_page() {
		return get_page_by_path( 'request-a-proposal' );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_ensure_page' ) ) {
	function ethnic_request_proposal_page_ensure_page() {
		$page = ethnic_request_proposal_page_get_target_page();

		if ( $page instanceof WP_Post ) {
			return;
		}

		$page_id = wp_insert_post(
			array(
				'post_title'     => 'Request a Proposal',
				'post_name'      => 'request-a-proposal',
				'post_status'    => 'publish',
				'post_type'      => 'page',
				'post_content'   => '',
				'post_parent'    => 0,
				'comment_status' => 'closed',
			)
		);

		if ( $page_id && ! is_wp_error( $page_id ) ) {
			update_post_meta( $page_id, '_wp_page_template', 'default' );
		}
	}

	add_action( 'init', 'ethnic_request_proposal_page_ensure_page', 5 );
}

if ( ! function_exists( 'ethnic_request_proposal_page_is_target' ) ) {
	function ethnic_request_proposal_page_is_target() {
		if ( is_admin() ) {
			return false;
		}

		$page = ethnic_request_proposal_page_get_target_page();

		if ( ! ( $page instanceof WP_Post ) ) {
			return false;
		}

		return (int) get_queried_object_id() === (int) $page->ID || is_page( (int) $page->ID );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_url' ) ) {
	function ethnic_request_proposal_page_url( $path = '' ) {
		$path = trim( (string) $path, '/' );

		if ( '' === $path ) {
			return home_url( '/request-a-proposal/' );
		}

		return home_url( '/' . $path . '/' );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_contact_url' ) ) {
	function ethnic_request_proposal_page_contact_url( $args = array() ) {
		return ethnic_consultation_route_contact_url( $args, ethnic_request_proposal_page_url( 'contact-us' ) );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_admin_post_url' ) ) {
	function ethnic_request_proposal_page_admin_post_url( $action ) {
		return add_query_arg(
			array(
				'action' => sanitize_key( (string) $action ),
			),
			admin_url( 'admin-post.php' )
		);
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_body_class' ) ) {
	function ethnic_request_proposal_page_body_class( $classes ) {
		if ( ethnic_request_proposal_page_is_target() ) {
			$classes[] = 'ethnic-proposal-active';
		}

		return $classes;
	}

	add_filter( 'body_class', 'ethnic_request_proposal_page_body_class' );
}

if ( ! function_exists( 'ethnic_request_proposal_page_submission_meta_key' ) ) {
	function ethnic_request_proposal_page_submission_meta_key() {
		return ETHNIC_PROPOSAL_REQUEST_META_KEY;
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_data' ) ) {
	function ethnic_request_proposal_page_data() {
		static $data = null;

		if ( null !== $data ) {
			return $data;
		}

		$data = array(
			'metaTitle'       => 'Request a Proposal | Submit Your Project Inquiry',
			'metaDescription' => 'Request a proposal by sharing your project goals, timeline, budget, required services, and supporting documents. Submit a detailed inquiry for a better-fit response.',
			'heroTitle'       => 'Request a Proposal',
			'heroCopy'        => 'Share your requirements through a structured project inquiry so our team can review your goals, scope, timeline, and service mix with enough context to respond with a stronger business proposal request. This page is built for serious inquiries that need clearer planning and a more relevant response.',
			'heroPoints'      => array(
				'Structured project inquiry process',
				'Better-fit proposals for serious requirements',
				'Support across strategy, design, development, and delivery',
			),
			'introTitle'      => 'A more detailed project form for better proposal alignment.',
			'introCopy'       => array(
				'This request a proposal page is best used for qualified project conversations where the business already has an initial requirement, a working scope direction, or a defined internal need. The more clearly the request is framed, the better we can review service fit, effort, and the right next step.',
				'Use the form below to outline goals, services, timing, and any supporting material that can help us understand the opportunity faster. You can also upload project briefs, decks, wireframes, or reference documents if they are already available.',
			),
			'introCards'      => array(
				array(
					'icon'  => 'goal',
					'title' => 'Share Project Goals',
					'copy'  => 'Clarify the outcome, business objective, and delivery direction behind the inquiry.',
				),
				array(
					'icon'  => 'timeline',
					'title' => 'Define Scope and Timeline',
					'copy'  => 'Help us understand urgency, expected milestones, and the practical shape of the work.',
				),
				array(
					'icon'  => 'proposal',
					'title' => 'Get a Better-Fit Proposal',
					'copy'  => 'Detailed project information helps improve relevance before we respond with the next step.',
				),
			),
			'projectTypes'    => array(
				''                     => 'Select project type',
				'ecommerce-website'    => 'eCommerce Website',
				'web-app'              => 'Web App',
				'mobile-app'           => 'Mobile App',
				'ai-ml-solution'       => 'AI / ML Solution',
				'devops-infrastructure'=> 'DevOps / Infrastructure',
				'game-development'     => 'Game Development',
				'blockchain-project'   => 'Blockchain Project',
				'other'                => 'Other',
			),
			'serviceOptions'  => array(
				array(
					'value' => 'strategy-consulting',
					'label' => 'Strategy / Consulting',
				),
				array(
					'value' => 'ui-ux-design',
					'label' => 'UI/UX Design',
				),
				array(
					'value' => 'ecommerce-development',
					'label' => 'eCommerce Development',
				),
				array(
					'value' => 'app-development',
					'label' => 'App Development',
				),
				array(
					'value' => 'ai-ml-development',
					'label' => 'AI / ML Development',
				),
				array(
					'value' => 'devops-services',
					'label' => 'DevOps Services',
				),
				array(
					'value' => 'game-development',
					'label' => 'Game Development',
				),
				array(
					'value' => 'blockchain-development',
					'label' => 'Blockchain Development',
				),
				array(
					'value' => 'integrations',
					'label' => 'Integrations',
				),
				array(
					'value' => 'support-maintenance',
					'label' => 'Support & Maintenance',
				),
				array(
					'value' => 'performance-optimization',
					'label' => 'Performance Optimization',
				),
				array(
					'value' => 'migration-replatforming',
					'label' => 'Migration / Replatforming',
				),
				array(
					'value' => 'other',
					'label' => 'Other',
				),
			),
			'startOptions'    => array(
				''               => 'Select desired start time',
				'asap'           => 'ASAP',
				'within-2-weeks' => 'Within 2 weeks',
				'within-1-month' => 'Within 1 month',
				'within-1-3-months' => '1–3 months',
				'flexible'       => 'Flexible',
			),
			'targetOptions'   => array(
				''               => 'Select target launch / delivery',
				'within-30-days' => 'Within 30 days',
				'within-60-days' => 'Within 60 days',
				'within-90-days' => 'Within 90 days',
				'3-6-months'     => '3–6 months',
				'6-plus-months'  => '6+ months',
				'not-defined'    => 'Not defined yet',
			),
			'budgetOptions'   => array(
				array(
					'value' => 'under-5000',
					'label' => 'Under $5,000',
					'copy'  => 'Best for small focused scopes, audits, or initial delivery phases.',
				),
				array(
					'value' => '5000-10000',
					'label' => '$5,000 – $10,000',
					'copy'  => 'Suitable for lean builds, specific delivery modules, or tactical support work.',
				),
				array(
					'value' => '10000-25000',
					'label' => '$10,000 – $25,000',
					'copy'  => 'Often used for broader implementation, redesign, integration, or scoped product work.',
				),
				array(
					'value' => '25000-50000',
					'label' => '$25,000 – $50,000',
					'copy'  => 'A better fit for larger builds, structured multi-phase delivery, or higher-complexity projects.',
				),
				array(
					'value' => '50000-plus',
					'label' => '$50,000+',
					'copy'  => 'For larger product, platform, transformation, or long-term engagement planning.',
				),
				array(
					'value' => 'discuss',
					'label' => 'Prefer to discuss',
					'copy'  => 'Use this if internal approvals or budget planning are still being shaped.',
				),
			),
			'formSteps'       => array(
				'Contact',
				'Project',
				'Services',
				'Timeline',
				'Budget',
				'Upload',
				'Submit',
			),
			'responseSteps'   => array(
				array(
					'title' => 'Requirement review',
					'copy'  => 'We read the project inquiry, service mix, budget band, and attached material before replying.',
				),
				array(
					'title' => 'Clarifying follow-up',
					'copy'  => 'If needed, we may return with targeted questions to reduce gaps before scoping the response.',
				),
				array(
					'title' => 'Proposal direction',
					'copy'  => 'Qualified requests can move into a recommendation, proposal discussion, or consultation step.',
				),
			),
			'trustTitle'      => 'A structured proposal process designed for serious project conversations.',
			'trustCopy'       => 'Detailed project requests help our team review opportunities with better context, respond more accurately, and identify when a proposal, follow-up workshop, or scoped consultation is the right next step.',
			'trustCards'      => array(
				array(
					'icon'  => 'review',
					'title' => 'Clear Requirement Review',
					'copy'  => 'Each inquiry is assessed against scope, business objective, service fit, and delivery complexity.',
				),
				array(
					'icon'  => 'message',
					'title' => 'Structured Follow-Up',
					'copy'  => 'Where details are incomplete, we can respond with focused questions rather than generic back-and-forth.',
				),
				array(
					'icon'  => 'layers',
					'title' => 'Service-Aligned Proposals',
					'copy'  => 'The form is designed to map inquiry details across strategy, design, development, integration, and support needs.',
				),
				array(
					'icon'  => 'shield',
					'title' => 'Support for Complex Projects',
					'copy'  => 'Requests can range from focused delivery scopes to broader long-term engagements with multiple service tracks.',
				),
			),
			'faqs'            => array(
				array(
					'question' => 'What kind of projects should use the Request a Proposal page?',
					'answer'   => 'Use this page for serious project inquiries where you already have a business need, initial scope direction, or a clear intent to evaluate delivery support in more detail.',
				),
				array(
					'question' => 'How detailed should my project brief be?',
					'answer'   => 'Share as much detail as you reasonably can. Clear goals, business context, timing, and service needs help us respond with a more relevant proposal or next-step recommendation.',
				),
				array(
					'question' => 'Can I upload documents or wireframes with my inquiry?',
					'answer'   => 'Yes. Supporting files like briefs, wireframes, decks, scope notes, or reference documents can help improve context and reduce follow-up questions.',
				),
				array(
					'question' => 'What budget information should I provide?',
					'answer'   => 'A realistic budget band helps frame service fit and response direction. If the budget is still being shaped, you can choose the discuss option instead.',
				),
				array(
					'question' => 'What happens after I submit the form?',
					'answer'   => 'Our team reviews the inquiry, checks service alignment, and may return with clarifying questions before moving into a proposal or consultation step.',
				),
				array(
					'question' => 'Can I request multiple services in one proposal?',
					'answer'   => 'Yes. The form supports multi-service requests so you can combine strategy, design, engineering, DevOps, integration, or support needs in one inquiry.',
				),
				array(
					'question' => 'What if I am not sure about the exact timeline yet?',
					'answer'   => 'That is fine. Share the best available estimate or choose a flexible option so we can understand urgency without forcing a fixed date too early.',
				),
				array(
					'question' => 'Is this better than using the general contact form?',
					'answer'   => 'For broader or more serious business proposal requests, yes. This page gives our team better project context and usually supports a stronger first response.',
				),
			),
			'finalTitle'      => 'Need Help Defining the Right Scope Before Requesting a Proposal?',
			'finalCopy'       => 'If your project is still being shaped, we can help you think through scope, service mix, delivery direction, timeline expectations, or the right next planning step before you submit a full proposal request.',
		);

		return $data;
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_form_feedback' ) ) {
	function ethnic_request_proposal_page_form_feedback() {
		$status = isset( $_GET['proposal_request_status'] ) ? sanitize_key( wp_unslash( $_GET['proposal_request_status'] ) ) : '';

		$messages = array(
			'success' => array(
				'type'  => 'success',
				'title' => 'Proposal request submitted successfully.',
				'copy'  => 'Your project inquiry is now saved in our system and ready for internal review. Our team can follow up with clarifying questions if needed.',
			),
			'partial' => array(
				'type'  => 'success',
				'title' => 'Proposal request submitted with partial file upload.',
				'copy'  => 'We saved the request details successfully. One or more uploaded files could not be attached, but the inquiry itself is safely recorded.',
			),
			'invalid' => array(
				'type'  => 'error',
				'title' => 'Please review the required fields.',
				'copy'  => 'Some required information was missing or invalid. Update the form details and submit the proposal request again.',
			),
			'blocked_email' => array(
				'type'  => 'error',
				'title' => 'Please use a different email address.',
				'copy'  => function_exists( 'ethnic_email_domain_block_message' ) ? ethnic_email_domain_block_message() : 'This email domain is not allowed for proposal requests.',
			),
			'security' => array(
				'type'  => 'error',
				'title' => 'We could not verify the security check.',
				'copy'  => 'Please refresh the page and submit the proposal request again so we can confirm this is a real visitor submission.',
			),
			'error' => array(
				'type'  => 'error',
				'title' => 'We could not save the proposal request.',
				'copy'  => 'Something went wrong while storing the request. Please try again or use the team conversation route if the issue continues.',
			),
		);

		return isset( $messages[ $status ] ) ? $messages[ $status ] : array();
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_option_map' ) ) {
	function ethnic_request_proposal_page_option_map( $options ) {
		$map = array();

		foreach ( (array) $options as $key => $value ) {
			if ( is_array( $value ) ) {
				if ( ! empty( $value['value'] ) ) {
					$map[ (string) $value['value'] ] = isset( $value['label'] ) ? (string) $value['label'] : (string) $value['value'];
				}
				continue;
			}

			$map[ (string) $key ] = (string) $value;
		}

		return $map;
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_project_type_label' ) ) {
	function ethnic_request_proposal_page_project_type_label( $value ) {
		$data = ethnic_request_proposal_page_data();
		$map  = ethnic_request_proposal_page_option_map( isset( $data['projectTypes'] ) ? $data['projectTypes'] : array() );

		return isset( $map[ $value ] ) ? $map[ $value ] : ( $value ? ucwords( str_replace( '-', ' ', $value ) ) : '' );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_start_time_label' ) ) {
	function ethnic_request_proposal_page_start_time_label( $value ) {
		$data = ethnic_request_proposal_page_data();
		$map  = ethnic_request_proposal_page_option_map( isset( $data['startOptions'] ) ? $data['startOptions'] : array() );

		return isset( $map[ $value ] ) ? $map[ $value ] : ( $value ? ucwords( str_replace( '-', ' ', $value ) ) : '' );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_target_timeline_label' ) ) {
	function ethnic_request_proposal_page_target_timeline_label( $value ) {
		$data = ethnic_request_proposal_page_data();
		$map  = ethnic_request_proposal_page_option_map( isset( $data['targetOptions'] ) ? $data['targetOptions'] : array() );

		return isset( $map[ $value ] ) ? $map[ $value ] : ( $value ? ucwords( str_replace( '-', ' ', $value ) ) : '' );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_budget_label' ) ) {
	function ethnic_request_proposal_page_budget_label( $value ) {
		$data = ethnic_request_proposal_page_data();
		$map  = ethnic_request_proposal_page_option_map( isset( $data['budgetOptions'] ) ? $data['budgetOptions'] : array() );

		return isset( $map[ $value ] ) ? $map[ $value ] : ( $value ? ucwords( str_replace( '-', ' ', $value ) ) : '' );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_service_labels' ) ) {
	function ethnic_request_proposal_page_service_labels( $values ) {
		$data = ethnic_request_proposal_page_data();
		$map  = ethnic_request_proposal_page_option_map( isset( $data['serviceOptions'] ) ? $data['serviceOptions'] : array() );

		$labels = array();

		foreach ( (array) $values as $value ) {
			$value = sanitize_key( (string) $value );

			if ( '' === $value ) {
				continue;
			}

			$labels[] = isset( $map[ $value ] ) ? $map[ $value ] : ucwords( str_replace( '-', ' ', $value ) );
		}

		return $labels;
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_icon' ) ) {
	function ethnic_request_proposal_page_icon( $icon ) {
		ob_start();

		switch ( $icon ) {
			case 'goal':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<circle cx="12" cy="12" r="8.5" />
					<circle cx="12" cy="12" r="4.2" />
					<circle cx="12" cy="12" r="1.4" />
				</svg>
				<?php
				break;

			case 'timeline':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<circle cx="12" cy="12" r="8.5" />
					<path d="M12 7.5v4.8l3 1.8" />
				</svg>
				<?php
				break;

			case 'proposal':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<path d="M7 3.8h7.8L19 8v12.2H7z" />
					<path d="M14.8 3.8V8H19" />
					<path d="M10 11.5h6" />
					<path d="M10 15h6" />
				</svg>
				<?php
				break;

			case 'review':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<path d="M6.5 4.5h11v15h-11z" />
					<path d="M9 9h6" />
					<path d="M9 12h6" />
					<path d="M9 15l1.6 1.6L15 12.2" />
				</svg>
				<?php
				break;

			case 'message':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<path d="M5 6.5h14v9H9.5L6 18.5v-3H5z" />
					<path d="M8.5 10.2h7" />
					<path d="M8.5 12.9h5.2" />
				</svg>
				<?php
				break;

			case 'layers':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<path d="M12 4l8 4-8 4-8-4 8-4z" />
					<path d="M4 11.5l8 4 8-4" />
					<path d="M4 15.5l8 4 8-4" />
				</svg>
				<?php
				break;

			case 'shield':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<path d="M12 3.5l6 2.4v5.2c0 4-2.4 7.6-6 9.5-3.6-1.9-6-5.5-6-9.5V5.9L12 3.5z" />
					<path d="M9.4 12.2l1.7 1.7 3.6-4" />
				</svg>
				<?php
				break;

			case 'upload':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<path d="M12 5v9" />
					<path d="M8.8 8.4L12 5l3.2 3.4" />
					<path d="M5 16.5h14" />
					<path d="M6.5 19.2h11" />
				</svg>
				<?php
				break;

			case 'brief':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<rect x="4" y="5" width="16" height="14" rx="2.2" />
					<path d="M9 5V3.8h6V5" />
					<path d="M4 9h16" />
				</svg>
				<?php
				break;

			case 'budget':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<rect x="3.5" y="6" width="17" height="12" rx="2.3" />
					<path d="M8 12h8" />
					<path d="M12 9v6" />
				</svg>
				<?php
				break;

			case 'form':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<path d="M7 4.2h10l3 3v12.6H7z" />
					<path d="M17 4.2v3h3" />
					<path d="M10 10.2h7" />
					<path d="M10 13.6h7" />
					<path d="M10 17h4.6" />
				</svg>
				<?php
				break;

			case 'stack':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<rect x="4.5" y="5" width="15" height="4.2" rx="1.2" />
					<rect x="4.5" y="10" width="15" height="4.2" rx="1.2" />
					<rect x="4.5" y="15" width="15" height="4.2" rx="1.2" />
				</svg>
				<?php
				break;

			case 'check':
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<path d="M5.5 12.5l4 4 9-9" />
				</svg>
				<?php
				break;

			default:
				?>
				<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
					<circle cx="12" cy="12" r="8.5" />
				</svg>
				<?php
				break;
		}

		return ob_get_clean();
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_section_heading' ) ) {
	function ethnic_request_proposal_page_section_heading( $eyebrow, $title, $copy = '' ) {
		ob_start();
		?>
		<div class="ethnic-proposal-heading">
			<?php if ( $eyebrow ) : ?>
				<p class="ethnic-proposal-heading__eyebrow"><?php echo esc_html( $eyebrow ); ?></p>
			<?php endif; ?>
			<h2 class="ethnic-proposal-heading__title"><?php echo esc_html( $title ); ?></h2>
			<?php if ( $copy ) : ?>
				<p class="ethnic-proposal-heading__copy"><?php echo esc_html( $copy ); ?></p>
			<?php endif; ?>
		</div>
		<?php

		return ob_get_clean();
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_render_input' ) ) {
	function ethnic_request_proposal_page_render_input( $args ) {
		$args = wp_parse_args(
			(array) $args,
			array(
				'id'          => '',
				'name'        => '',
				'label'       => '',
				'type'        => 'text',
				'placeholder' => '',
				'help'        => '',
				'required'    => false,
				'full'        => false,
			)
		);

		$class = 'ethnic-proposal-field' . ( ! empty( $args['full'] ) ? ' ethnic-proposal-field--full' : '' );
		?>
		<label class="<?php echo esc_attr( $class ); ?>" for="<?php echo esc_attr( $args['id'] ); ?>">
			<span class="ethnic-proposal-field__label"><?php echo esc_html( $args['label'] ); ?><?php if ( ! empty( $args['required'] ) ) : ?><em>*</em><?php endif; ?></span>
			<input
				id="<?php echo esc_attr( $args['id'] ); ?>"
				name="<?php echo esc_attr( $args['name'] ); ?>"
				type="<?php echo esc_attr( $args['type'] ); ?>"
				placeholder="<?php echo esc_attr( $args['placeholder'] ); ?>"
				<?php echo ! empty( $args['required'] ) ? 'required' : ''; ?>
			/>
			<?php if ( ! empty( $args['help'] ) ) : ?>
				<span class="ethnic-proposal-field__help"><?php echo esc_html( $args['help'] ); ?></span>
			<?php endif; ?>
		</label>
		<?php
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_render_select' ) ) {
	function ethnic_request_proposal_page_render_select( $args ) {
		$args = wp_parse_args(
			(array) $args,
			array(
				'id'       => '',
				'name'     => '',
				'label'    => '',
				'options'  => array(),
				'help'     => '',
				'required' => false,
				'full'     => false,
			)
		);

		$class = 'ethnic-proposal-field' . ( ! empty( $args['full'] ) ? ' ethnic-proposal-field--full' : '' );
		?>
		<label class="<?php echo esc_attr( $class ); ?>" for="<?php echo esc_attr( $args['id'] ); ?>">
			<span class="ethnic-proposal-field__label"><?php echo esc_html( $args['label'] ); ?><?php if ( ! empty( $args['required'] ) ) : ?><em>*</em><?php endif; ?></span>
			<select id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" <?php echo ! empty( $args['required'] ) ? 'required' : ''; ?>>
				<?php foreach ( (array) $args['options'] as $value => $label ) : ?>
					<option value="<?php echo esc_attr( $value ); ?>" <?php selected( '', $value ); ?>><?php echo esc_html( $label ); ?></option>
				<?php endforeach; ?>
			</select>
			<?php if ( ! empty( $args['help'] ) ) : ?>
				<span class="ethnic-proposal-field__help"><?php echo esc_html( $args['help'] ); ?></span>
			<?php endif; ?>
		</label>
		<?php
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_render_textarea' ) ) {
	function ethnic_request_proposal_page_render_textarea( $args ) {
		$args = wp_parse_args(
			(array) $args,
			array(
				'id'          => '',
				'name'        => '',
				'label'       => '',
				'placeholder' => '',
				'help'        => '',
				'rows'        => 5,
				'required'    => false,
				'full'        => true,
			)
		);

		$class = 'ethnic-proposal-field' . ( ! empty( $args['full'] ) ? ' ethnic-proposal-field--full' : '' );
		?>
		<label class="<?php echo esc_attr( $class ); ?>" for="<?php echo esc_attr( $args['id'] ); ?>">
			<span class="ethnic-proposal-field__label"><?php echo esc_html( $args['label'] ); ?><?php if ( ! empty( $args['required'] ) ) : ?><em>*</em><?php endif; ?></span>
			<textarea
				id="<?php echo esc_attr( $args['id'] ); ?>"
				name="<?php echo esc_attr( $args['name'] ); ?>"
				rows="<?php echo esc_attr( (int) $args['rows'] ); ?>"
				placeholder="<?php echo esc_attr( $args['placeholder'] ); ?>"
				<?php echo ! empty( $args['required'] ) ? 'required' : ''; ?>
			></textarea>
			<?php if ( ! empty( $args['help'] ) ) : ?>
				<span class="ethnic-proposal-field__help"><?php echo esc_html( $args['help'] ); ?></span>
			<?php endif; ?>
		</label>
		<?php
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_render' ) ) {
	function ethnic_request_proposal_page_render() {
		$data               = ethnic_request_proposal_page_data();
		$feedback           = ethnic_request_proposal_page_form_feedback();
		$consultation_url   = ethnic_request_proposal_page_contact_url(
			array(
				'intent' => 'consultation',
				'source' => 'request-a-proposal',
			)
		);
		$conversation_url   = ethnic_request_proposal_page_contact_url(
			array(
				'intent' => 'proposal-conversation',
				'source' => 'request-a-proposal',
			)
		);
		$progress_count     = count( $data['formSteps'] );
		$faq_schema_entries = array();

		foreach ( (array) $data['faqs'] as $faq ) {
			$faq_schema_entries[] = array(
				'@type'          => 'Question',
				'name'           => $faq['question'],
				'acceptedAnswer' => array(
					'@type' => 'Answer',
					'text'  => $faq['answer'],
				),
			);
		}

		ob_start();
		?>
		<div class="ethnic-request-proposal-page">
			<section class="ethnic-proposal-hero">
				<div class="ethnic-proposal-shell ethnic-proposal-hero__layout">
					<div class="ethnic-proposal-hero__content">
						<p class="ethnic-proposal-hero__eyebrow">Proposal Request</p>
						<h1 class="ethnic-proposal-hero__title"><?php echo esc_html( $data['heroTitle'] ); ?></h1>
						<p class="ethnic-proposal-hero__copy"><?php echo esc_html( $data['heroCopy'] ); ?></p>
						<div class="ethnic-proposal-hero__actions">
							<a class="ethnic-proposal-button ethnic-proposal-button--primary" href="#proposal-request-form">Start Your Request</a>
							<a class="ethnic-proposal-button ethnic-proposal-button--secondary" href="<?php echo esc_url( $conversation_url ); ?>">Talk to Our Team</a>
						</div>
						<ul class="ethnic-proposal-hero__points">
							<?php foreach ( (array) $data['heroPoints'] as $point ) : ?>
								<li>
									<span class="ethnic-proposal-hero__point-marker" aria-hidden="true"></span>
									<span><?php echo esc_html( $point ); ?></span>
								</li>
							<?php endforeach; ?>
						</ul>
					</div>
					<div class="ethnic-proposal-hero__visual" aria-hidden="true">
						<div class="ethnic-proposal-visual__frame">
							<div class="ethnic-proposal-visual__toolbar">
								<span></span><span></span><span></span>
							</div>
							<div class="ethnic-proposal-visual__stack">
								<div class="ethnic-proposal-visual__card ethnic-proposal-visual__card--brief">
									<p class="ethnic-proposal-visual__eyebrow">Project Brief</p>
									<h2>Structured project details for a stronger proposal path.</h2>
									<ul>
										<li>Goals and business outcomes</li>
										<li>Scope, timeline, and services</li>
										<li>Budget band and supporting files</li>
									</ul>
								</div>
								<div class="ethnic-proposal-visual__card ethnic-proposal-visual__card--upload">
									<div class="ethnic-proposal-visual__icon"><?php echo ethnic_request_proposal_page_icon( 'upload' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
									<p class="ethnic-proposal-visual__eyebrow">Upload Panel</p>
									<h2>Briefs, wireframes, decks, or reference files</h2>
									<div class="ethnic-proposal-visual__upload-lines">
										<span></span><span></span><span></span>
									</div>
								</div>
								<div class="ethnic-proposal-visual__card ethnic-proposal-visual__card--support">
									<p class="ethnic-proposal-visual__eyebrow">Response Support</p>
									<h2>Better-fit proposals for qualified business requirements</h2>
									<div class="ethnic-proposal-visual__badge-row">
										<span>Strategy</span>
										<span>Delivery</span>
										<span>Scoping</span>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</section>

			<section class="ethnic-proposal-section">
				<div class="ethnic-proposal-shell">
					<?php echo ethnic_request_proposal_page_section_heading( 'Qualified Inquiries', $data['introTitle'], 'Use the detailed project form below to support a stronger, more relevant proposal response.' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
					<div class="ethnic-proposal-intro">
						<div class="ethnic-proposal-prose">
							<?php foreach ( (array) $data['introCopy'] as $paragraph ) : ?>
								<p><?php echo esc_html( $paragraph ); ?></p>
							<?php endforeach; ?>
						</div>
						<div class="ethnic-proposal-intro__cards">
							<?php foreach ( (array) $data['introCards'] as $card ) : ?>
								<article class="ethnic-proposal-mini-card">
									<div class="ethnic-proposal-mini-card__icon"><?php echo ethnic_request_proposal_page_icon( $card['icon'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
									<h3><?php echo esc_html( $card['title'] ); ?></h3>
									<p><?php echo esc_html( $card['copy'] ); ?></p>
								</article>
							<?php endforeach; ?>
						</div>
					</div>
				</div>
			</section>

			<section class="ethnic-proposal-section ethnic-proposal-section--form" id="proposal-request-form">
				<div class="ethnic-proposal-shell">
					<?php echo ethnic_request_proposal_page_section_heading( 'Proposal Request Form', 'Share the details that help us review scope, timing, service needs, and proposal fit.', 'The more useful context you provide here, the easier it becomes to review your business proposal request against delivery reality.' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
					<div class="ethnic-proposal-request">
						<form class="ethnic-proposal-form" id="ethnicProposalForm" method="post" action="<?php echo esc_url( ethnic_request_proposal_page_admin_post_url( 'ethnic_submit_proposal_request' ) ); ?>" enctype="multipart/form-data" novalidate>
							<?php wp_nonce_field( 'ethnic_submit_proposal_request', 'ethnic_request_proposal_nonce' ); ?>
							<input type="hidden" name="action" value="ethnic_submit_proposal_request" />
							<input type="hidden" name="proposal_source" value="request-a-proposal-page" />
							<input type="hidden" name="proposal_progress_total" value="<?php echo esc_attr( (string) $progress_count ); ?>" />
							<input type="hidden" name="return_url" value="<?php echo esc_url( ethnic_request_proposal_page_url() ); ?>" />

							<div class="ethnic-proposal-form__states" aria-live="polite">
								<div class="ethnic-proposal-form__alert ethnic-proposal-form__alert--error" data-form-alert="error" <?php echo ( ! empty( $feedback['type'] ) && 'error' === $feedback['type'] ) ? '' : 'hidden'; ?>>
									<strong><?php echo esc_html( ! empty( $feedback['type'] ) && 'error' === $feedback['type'] ? $feedback['title'] : 'Please review the required fields.' ); ?></strong>
									<p><?php echo esc_html( ! empty( $feedback['type'] ) && 'error' === $feedback['type'] ? $feedback['copy'] : 'Complete the missing sections so the proposal request can be captured with enough project context.' ); ?></p>
								</div>
								<div class="ethnic-proposal-form__alert ethnic-proposal-form__alert--success" data-form-alert="success" <?php echo ( ! empty( $feedback['type'] ) && 'success' === $feedback['type'] ) ? '' : 'hidden'; ?>>
									<strong><?php echo esc_html( ! empty( $feedback['type'] ) && 'success' === $feedback['type'] ? $feedback['title'] : 'Proposal request submitted successfully.' ); ?></strong>
									<p><?php echo esc_html( ! empty( $feedback['type'] ) && 'success' === $feedback['type'] ? $feedback['copy'] : 'Your request has been saved and is ready for internal review.' ); ?></p>
								</div>
							</div>

							<section class="ethnic-proposal-form__section" data-step="contact">
								<div class="ethnic-proposal-form__section-header">
									<span class="ethnic-proposal-form__step">A</span>
									<div>
										<h3>Contact Information</h3>
										<p>Tell us who is making the request and how your team should be reached.</p>
									</div>
								</div>
								<div class="ethnic-proposal-form__grid">
									<?php ethnic_request_proposal_page_render_input( array( 'id' => 'proposal-full-name', 'name' => 'full_name', 'label' => 'Full Name', 'placeholder' => 'Your full name', 'required' => true ) ); ?>
									<?php ethnic_request_proposal_page_render_input( array( 'id' => 'proposal-company-name', 'name' => 'company_name', 'label' => 'Company Name', 'placeholder' => 'Company or organization', 'required' => true ) ); ?>
									<?php ethnic_request_proposal_page_render_input( array( 'id' => 'proposal-work-email', 'name' => 'work_email', 'label' => 'Work Email', 'type' => 'email', 'placeholder' => 'name@company.com', 'required' => true ) ); ?>
									<?php ethnic_request_proposal_page_render_input( array( 'id' => 'proposal-phone-number', 'name' => 'phone_number', 'label' => 'Phone Number', 'type' => 'tel', 'placeholder' => '+1 000 000 0000' ) ); ?>
									<?php ethnic_request_proposal_page_render_input( array( 'id' => 'proposal-company-url', 'name' => 'company_url', 'label' => 'Website / Company URL', 'type' => 'url', 'placeholder' => 'https://yourcompany.com', 'help' => 'Optional, but useful when reviewing your current business presence.', 'full' => true ) ); ?>
								</div>
							</section>

							<section class="ethnic-proposal-form__section" data-step="project">
								<div class="ethnic-proposal-form__section-header">
									<span class="ethnic-proposal-form__step">B</span>
									<div>
										<h3>Project Information</h3>
										<p>Share the working context, initiative type, and what the project is trying to achieve.</p>
									</div>
								</div>
								<div class="ethnic-proposal-form__grid">
									<?php ethnic_request_proposal_page_render_input( array( 'id' => 'proposal-project-title', 'name' => 'project_title', 'label' => 'Project Title / Working Name', 'placeholder' => 'Internal project name or short working label', 'required' => true, 'full' => true ) ); ?>
									<?php ethnic_request_proposal_page_render_select( array( 'id' => 'proposal-project-type', 'name' => 'project_type', 'label' => 'Project Type', 'options' => $data['projectTypes'], 'required' => true ) ); ?>
									<?php ethnic_request_proposal_page_render_input( array( 'id' => 'proposal-current-platform', 'name' => 'current_platform', 'label' => 'Current Situation / Existing Platform', 'placeholder' => 'Magento store, internal app, legacy platform, no existing system', 'help' => 'This can also be your current operational challenge or technology baseline.' ) ); ?>
									<?php ethnic_request_proposal_page_render_textarea( array( 'id' => 'proposal-overview', 'name' => 'project_overview', 'label' => 'Project Overview', 'placeholder' => 'Describe the project, product, platform, or initiative in practical terms.', 'required' => true ) ); ?>
									<?php ethnic_request_proposal_page_render_textarea( array( 'id' => 'proposal-goals', 'name' => 'project_goals', 'label' => 'Project Goals', 'placeholder' => 'Explain the business outcomes, performance targets, launch intent, or problem to solve.', 'required' => true ) ); ?>
								</div>
							</section>

							<section class="ethnic-proposal-form__section" data-step="services">
								<div class="ethnic-proposal-form__section-header">
									<span class="ethnic-proposal-form__step">C</span>
									<div>
										<h3>Required Services</h3>
										<p>Select the service areas you expect the proposal to cover.</p>
									</div>
								</div>
								<div class="ethnic-proposal-services" data-service-group>
									<?php foreach ( (array) $data['serviceOptions'] as $index => $service ) : ?>
										<label class="ethnic-proposal-chip" for="proposal-service-<?php echo esc_attr( (string) $index ); ?>">
											<input id="proposal-service-<?php echo esc_attr( (string) $index ); ?>" type="checkbox" name="required_services[]" value="<?php echo esc_attr( $service['value'] ); ?>" />
											<span><?php echo esc_html( $service['label'] ); ?></span>
										</label>
									<?php endforeach; ?>
								</div>
								<p class="ethnic-proposal-form__group-note">Choose one or multiple services. This helps us align the response to the real delivery mix.</p>
							</section>

							<section class="ethnic-proposal-form__section" data-step="timeline">
								<div class="ethnic-proposal-form__section-header">
									<span class="ethnic-proposal-form__step">D</span>
									<div>
										<h3>Desired Timeline</h3>
										<p>Outline urgency, expected start timing, and any delivery expectation already in view.</p>
									</div>
								</div>
								<div class="ethnic-proposal-form__grid">
									<?php ethnic_request_proposal_page_render_select( array( 'id' => 'proposal-start-time', 'name' => 'desired_start_time', 'label' => 'Desired Start Time', 'options' => $data['startOptions'], 'required' => true ) ); ?>
									<?php ethnic_request_proposal_page_render_select( array( 'id' => 'proposal-target-delivery', 'name' => 'target_delivery_timeline', 'label' => 'Target Launch / Delivery Timeline', 'options' => $data['targetOptions'], 'required' => true ) ); ?>
									<?php ethnic_request_proposal_page_render_textarea( array( 'id' => 'proposal-timeline-notes', 'name' => 'timeline_notes', 'label' => 'Timeline Notes', 'placeholder' => 'Include internal deadlines, funding windows, launch dates, stakeholder dependencies, or anything timing-related.', 'rows' => 4 ) ); ?>
								</div>
							</section>

							<section class="ethnic-proposal-form__section" data-step="budget">
								<div class="ethnic-proposal-form__section-header">
									<span class="ethnic-proposal-form__step">E</span>
									<div>
										<h3>Budget Band</h3>
										<p>Choose the budget range that best reflects the current planning view.</p>
									</div>
								</div>
								<div class="ethnic-proposal-budget" data-budget-group>
									<?php foreach ( (array) $data['budgetOptions'] as $index => $option ) : ?>
										<label class="ethnic-proposal-budget__card" for="proposal-budget-<?php echo esc_attr( (string) $index ); ?>">
											<input id="proposal-budget-<?php echo esc_attr( (string) $index ); ?>" type="radio" name="budget_band" value="<?php echo esc_attr( $option['value'] ); ?>" />
											<span class="ethnic-proposal-budget__title"><?php echo esc_html( $option['label'] ); ?></span>
											<span class="ethnic-proposal-budget__copy"><?php echo esc_html( $option['copy'] ); ?></span>
										</label>
									<?php endforeach; ?>
								</div>
							</section>

							<section class="ethnic-proposal-form__section" data-step="upload">
								<div class="ethnic-proposal-form__section-header">
									<span class="ethnic-proposal-form__step">F</span>
									<div>
										<h3>Upload Supporting Files</h3>
										<p>Attach project briefs, scope notes, decks, wireframes, or reference material if available.</p>
									</div>
								</div>
								<div class="ethnic-proposal-upload">
									<label class="ethnic-proposal-upload__dropzone" for="proposal-files">
										<span class="ethnic-proposal-upload__icon"><?php echo ethnic_request_proposal_page_icon( 'upload' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span>
										<strong>Drag and drop files here or click to upload</strong>
										<span>Project briefs, RFPs, wireframes, scope documents, decks, or reference files.</span>
										<input id="proposal-files" type="file" name="supporting_files[]" multiple accept=".pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.png,.jpg,.jpeg,.zip" />
									</label>
									<div class="ethnic-proposal-upload__meta">
										<p>Accepted formats placeholder: PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, PNG, JPG, ZIP</p>
										<p>File upload UI is ready for future backend handling, validation, and storage rules.</p>
									</div>
									<div class="ethnic-proposal-upload__state" data-upload-state>
										<div class="ethnic-proposal-upload__empty">
											<span class="ethnic-proposal-upload__empty-icon"><?php echo ethnic_request_proposal_page_icon( 'brief' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span>
											<div>
												<strong>No supporting files selected yet</strong>
												<p>This file upload state will update as soon as documents are chosen.</p>
											</div>
										</div>
										<ul class="ethnic-proposal-upload__files" data-upload-list hidden></ul>
									</div>
								</div>
							</section>

							<section class="ethnic-proposal-form__section" data-step="notes">
								<div class="ethnic-proposal-form__section-header">
									<span class="ethnic-proposal-form__step">G</span>
									<div>
										<h3>Additional Notes</h3>
										<p>Use this space for context that can help shape a better project response.</p>
									</div>
								</div>
								<div class="ethnic-proposal-form__grid">
									<?php ethnic_request_proposal_page_render_textarea( array( 'id' => 'proposal-additional-requirements', 'name' => 'additional_requirements', 'label' => 'Additional Requirements', 'placeholder' => 'Compliance, internal approval, stakeholder needs, market constraints, or other important project conditions.', 'rows' => 4 ) ); ?>
									<?php ethnic_request_proposal_page_render_textarea( array( 'id' => 'proposal-references', 'name' => 'reference_links', 'label' => 'References / Inspiration Links', 'placeholder' => 'Share product references, competitor links, brand inspiration, or benchmark examples.', 'rows' => 4 ) ); ?>
									<?php ethnic_request_proposal_page_render_textarea( array( 'id' => 'proposal-anything-else', 'name' => 'anything_else', 'label' => 'Anything Else We Should Know?', 'placeholder' => 'Add anything not covered above that could improve the proposal fit or review process.', 'rows' => 5 ) ); ?>
								</div>
							</section>

							<section class="ethnic-proposal-form__section ethnic-proposal-form__section--submit" data-step="submit">
								<div class="ethnic-proposal-form__section-header">
									<span class="ethnic-proposal-form__step">H</span>
									<div>
										<h3>Submission</h3>
										<p>Confirm the information and send the request through the frontend-ready proposal capture flow.</p>
									</div>
								</div>
								<div class="ethnic-proposal-submit">
									<label class="ethnic-proposal-consent" for="proposal-consent">
										<input id="proposal-consent" type="checkbox" name="proposal_consent" value="1" required />
										<span>I understand this request is intended for serious project inquiries and I consent to being contacted about this proposal request.</span>
									</label>
									<?php
									if ( function_exists( 'ethnic_recaptcha_render_widget' ) ) {
										ethnic_recaptcha_render_widget(
											'proposal_request',
											array(
												'wrapper_class' => 'ethnic-proposal-submit__recaptcha',
											)
										);
									}
									?>
									<div class="ethnic-proposal-submit__actions">
										<button class="ethnic-proposal-button ethnic-proposal-button--primary" type="submit" data-submit-button>Submit Proposal Request</button>
										<a class="ethnic-proposal-button ethnic-proposal-button--secondary" href="<?php echo esc_url( $conversation_url ); ?>">Talk to Our Team</a>
									</div>
									<p class="ethnic-proposal-submit__note">Each valid request is now saved in WordPress so your team can review project details, uploaded files, and scope notes before we connect CRM or email routing.</p>
								</div>
							</section>
						</form>

						<aside class="ethnic-proposal-sidebar">
							<div class="ethnic-proposal-sidebar__card ethnic-proposal-sidebar__card--progress">
								<p class="ethnic-proposal-sidebar__eyebrow">Progress</p>
								<h3>Complete the form in structured steps.</h3>
								<div class="ethnic-proposal-progress">
									<div class="ethnic-proposal-progress__bar">
										<span data-progress-fill></span>
									</div>
									<div class="ethnic-proposal-progress__meta">
										<strong data-progress-percent>0%</strong>
										<span data-progress-label>Form not started yet</span>
									</div>
								</div>
								<ol class="ethnic-proposal-progress__steps">
									<?php foreach ( (array) $data['formSteps'] as $index => $step ) : ?>
										<li data-progress-step="<?php echo esc_attr( sanitize_title( $step ) ); ?>">
											<span><?php echo esc_html( sprintf( '%02d', $index + 1 ) ); ?></span>
											<strong><?php echo esc_html( $step ); ?></strong>
										</li>
									<?php endforeach; ?>
								</ol>
							</div>

							<div class="ethnic-proposal-sidebar__card ethnic-proposal-sidebar__card--support">
								<p class="ethnic-proposal-sidebar__eyebrow">What Helps</p>
								<h3>Better details usually lead to a stronger first response.</h3>
								<ul class="ethnic-proposal-checklist">
									<li><?php echo ethnic_request_proposal_page_icon( 'check' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><span>Clear project goals and practical business outcomes</span></li>
									<li><?php echo ethnic_request_proposal_page_icon( 'check' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><span>Expected services, existing platform context, and timing</span></li>
									<li><?php echo ethnic_request_proposal_page_icon( 'check' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><span>Useful documents, decks, or early scope notes if available</span></li>
								</ul>
							</div>

							<div class="ethnic-proposal-sidebar__card ethnic-proposal-sidebar__card--process">
								<p class="ethnic-proposal-sidebar__eyebrow">What Happens Next</p>
								<h3>Proposal support follows a structured review path.</h3>
								<div class="ethnic-proposal-sidebar__timeline">
									<?php foreach ( (array) $data['responseSteps'] as $index => $item ) : ?>
										<div class="ethnic-proposal-sidebar__timeline-item">
											<span class="ethnic-proposal-sidebar__timeline-index"><?php echo esc_html( sprintf( '%02d', $index + 1 ) ); ?></span>
											<div>
												<strong><?php echo esc_html( $item['title'] ); ?></strong>
												<p><?php echo esc_html( $item['copy'] ); ?></p>
											</div>
										</div>
									<?php endforeach; ?>
								</div>
								<div class="ethnic-proposal-sidebar__panel-note">
									<strong>Need help before filling the form?</strong>
									<p>Use the team conversation route if you want to discuss the right scope before submitting a detailed request.</p>
									<a class="ethnic-proposal-inline-link" href="<?php echo esc_url( $consultation_url ); ?>">Book a Free Consultation</a>
								</div>
							</div>
						</aside>
					</div>
				</div>
			</section>

			<section class="ethnic-proposal-section ethnic-proposal-section--soft">
				<div class="ethnic-proposal-shell">
					<?php echo ethnic_request_proposal_page_section_heading( 'Proposal Confidence', $data['trustTitle'], $data['trustCopy'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
					<div class="ethnic-proposal-trust-grid">
						<?php foreach ( (array) $data['trustCards'] as $card ) : ?>
							<article class="ethnic-proposal-trust-card">
								<div class="ethnic-proposal-trust-card__icon"><?php echo ethnic_request_proposal_page_icon( $card['icon'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
								<h3><?php echo esc_html( $card['title'] ); ?></h3>
								<p><?php echo esc_html( $card['copy'] ); ?></p>
							</article>
						<?php endforeach; ?>
					</div>
				</div>
			</section>

			<section class="ethnic-proposal-section ethnic-proposal-section--faq" id="proposal-faq">
				<div class="ethnic-proposal-shell">
					<?php echo ethnic_request_proposal_page_section_heading( 'Proposal FAQs', 'Common questions before submitting a proposal request.', 'These answers are written to help clarify when to use the detailed project form and what to expect after submission.' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
					<div class="ethnic-proposal-faq">
						<?php foreach ( (array) $data['faqs'] as $index => $faq ) : ?>
							<details class="ethnic-proposal-faq__item" <?php echo 0 === $index ? 'open' : ''; ?>>
								<summary>
									<span><?php echo esc_html( $faq['question'] ); ?></span>
									<span class="ethnic-proposal-faq__marker" aria-hidden="true"></span>
								</summary>
								<div class="ethnic-proposal-faq__answer">
									<p><?php echo esc_html( $faq['answer'] ); ?></p>
								</div>
							</details>
						<?php endforeach; ?>
					</div>
				</div>
			</section>

			<section class="ethnic-proposal-section ethnic-proposal-section--cta">
				<div class="ethnic-proposal-shell">
					<div class="ethnic-proposal-cta">
						<div class="ethnic-proposal-cta__content">
							<p class="ethnic-proposal-cta__eyebrow">Need Support First?</p>
							<h2><?php echo esc_html( $data['finalTitle'] ); ?></h2>
							<p><?php echo esc_html( $data['finalCopy'] ); ?></p>
							<div class="ethnic-proposal-cta__actions">
								<a class="ethnic-proposal-button ethnic-proposal-button--primary" href="<?php echo esc_url( $conversation_url ); ?>">Talk to Our Team</a>
								<a class="ethnic-proposal-button ethnic-proposal-button--secondary" href="<?php echo esc_url( $consultation_url ); ?>">Book a Free Consultation</a>
							</div>
						</div>
						<div class="ethnic-proposal-cta__panel">
							<div class="ethnic-proposal-cta__panel-icon"><?php echo ethnic_request_proposal_page_icon( 'stack' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
							<h3>Still shaping scope, service mix, or delivery expectations?</h3>
							<p>Use a consultation path if the project still needs direction before a formal proposal request makes sense.</p>
							<ul class="ethnic-proposal-checklist ethnic-proposal-checklist--light">
								<li><?php echo ethnic_request_proposal_page_icon( 'check' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><span>Scope and service alignment</span></li>
								<li><?php echo ethnic_request_proposal_page_icon( 'check' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><span>Timeline and proposal readiness</span></li>
								<li><?php echo ethnic_request_proposal_page_icon( 'check' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><span>Next-step planning for qualified leads</span></li>
							</ul>
						</div>
					</div>
				</div>
			</section>
		</div>
		<script type="application/ld+json">
			<?php
			echo wp_json_encode(
				array(
					'@context' => 'https://schema.org',
					'@graph'   => array(
						array(
							'@type'       => 'WebPage',
							'name'        => $data['metaTitle'],
							'description' => $data['metaDescription'],
							'url'         => ethnic_request_proposal_page_url(),
						),
						array(
							'@type'      => 'FAQPage',
							'mainEntity' => $faq_schema_entries,
						),
					),
				),
				JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
			);
			?>
		</script>
		<?php

		return ob_get_clean();
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_register_submission_post_type' ) ) {
	function ethnic_request_proposal_page_register_submission_post_type() {
		register_post_type(
			ETHNIC_PROPOSAL_REQUEST_POST_TYPE,
			array(
				'labels' => array(
					'name'               => 'Proposal Requests',
					'singular_name'      => 'Proposal Request',
					'menu_name'          => 'Proposal Requests',
					'name_admin_bar'     => 'Proposal Request',
					'all_items'          => 'All Proposal Requests',
					'view_item'          => 'View Proposal Request',
					'edit_item'          => 'View Proposal Request',
					'search_items'       => 'Search Proposal Requests',
					'not_found'          => 'No proposal requests found.',
					'not_found_in_trash' => 'No proposal requests found in Trash.',
				),
				'public'             => false,
				'publicly_queryable' => false,
				'show_ui'            => true,
				'show_in_menu'       => false,
				'show_in_rest'       => false,
				'rewrite'            => false,
				'query_var'          => false,
				'capability_type'    => 'page',
				'map_meta_cap'       => true,
				'capabilities'       => array(
					'create_posts' => 'do_not_allow',
				),
				'menu_icon'          => 'dashicons-media-document',
				'supports'           => array( 'title' ),
			)
		);
	}

	add_action( 'init', 'ethnic_request_proposal_page_register_submission_post_type', 22 );
}

if ( ! function_exists( 'ethnic_request_proposal_page_add_submission_submenu' ) ) {
	function ethnic_request_proposal_page_add_submission_submenu() {
		add_submenu_page(
			'edit.php?post_type=page',
			'Proposal Requests',
			'Proposal Requests',
			'edit_pages',
			'edit.php?post_type=' . ETHNIC_PROPOSAL_REQUEST_POST_TYPE
		);
	}

	add_action( 'admin_menu', 'ethnic_request_proposal_page_add_submission_submenu', 40 );
}

if ( ! function_exists( 'ethnic_request_proposal_page_submission_data' ) ) {
	function ethnic_request_proposal_page_submission_data( $post_id ) {
		$data = get_post_meta( (int) $post_id, ethnic_request_proposal_page_submission_meta_key(), true );

		return is_array( $data ) ? $data : array();
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_update_submission_data' ) ) {
	function ethnic_request_proposal_page_update_submission_data( $post_id, $changes ) {
		$post_id = absint( $post_id );
		$data    = ethnic_request_proposal_page_submission_data( $post_id );
		$data    = array_merge( $data, (array) $changes );

		update_post_meta( $post_id, ethnic_request_proposal_page_submission_meta_key(), $data );

		return $data;
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_submission_sync_url' ) ) {
	function ethnic_request_proposal_page_submission_sync_url( $post_id, $redirect_to = '' ) {
		$post_id     = absint( $post_id );
		$redirect_to = $redirect_to ? $redirect_to : admin_url( 'post.php?post=' . $post_id . '&action=edit' );

		return wp_nonce_url(
			add_query_arg(
				array(
					'action'      => 'ethnic_proposal_sync_submission',
					'submission'  => $post_id,
					'redirect_to' => rawurlencode( $redirect_to ),
				),
				admin_url( 'admin-post.php' )
			),
			'ethnic_proposal_sync_submission_' . $post_id
		);
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_odoo_text_lines' ) ) {
	function ethnic_request_proposal_page_odoo_text_lines( $value ) {
		if ( is_array( $value ) ) {
			$raw_lines = $value;
		} elseif ( is_scalar( $value ) ) {
			$raw_lines = preg_split( '/\r\n|\r|\n/', (string) $value );
		} else {
			return array();
		}

		$lines          = array();
		$previous_blank = false;

		foreach ( (array) $raw_lines as $raw_line ) {
			$line = is_scalar( $raw_line ) ? trim( (string) $raw_line ) : '';

			if ( '' === $line ) {
				if ( $previous_blank || empty( $lines ) ) {
					continue;
				}

				$lines[]        = '';
				$previous_blank = true;
				continue;
			}

			$lines[]        = $line;
			$previous_blank = false;
		}

		while ( ! empty( $lines ) && '' === end( $lines ) ) {
			array_pop( $lines );
		}

		return $lines;
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_odoo_line' ) ) {
	function ethnic_request_proposal_page_odoo_line( $label, $value ) {
		$lines = ethnic_request_proposal_page_odoo_text_lines( $value );

		if ( empty( $lines ) ) {
			return '';
		}

		return trim( (string) $label ) . ': ' . implode( ' ', $lines );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_odoo_block' ) ) {
	function ethnic_request_proposal_page_odoo_block( $label, $value ) {
		$lines = ethnic_request_proposal_page_odoo_text_lines( $value );

		if ( empty( $lines ) ) {
			return '';
		}

		$body = array_values(
			array_filter(
				array_map(
					'trim',
					$lines
				)
			)
		);

		if ( empty( $body ) ) {
			return '';
		}

		return trim( (string) $label ) . ': ' . implode( ' / ', $body );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_odoo_list_block' ) ) {
	function ethnic_request_proposal_page_odoo_list_block( $label, $items ) {
		if ( ! is_array( $items ) ) {
			return '';
		}

		$lines = array();

		foreach ( $items as $item ) {
			$item_lines = ethnic_request_proposal_page_odoo_text_lines( $item );

			if ( empty( $item_lines ) ) {
				continue;
			}

			$lines[] = implode( ' / ', array_filter( array_map( 'trim', $item_lines ) ) );
		}

		if ( empty( $lines ) ) {
			return '';
		}

		return trim( (string) $label ) . ': ' . implode( ' | ', $lines );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_odoo_section' ) ) {
	function ethnic_request_proposal_page_odoo_section( $title, $entries ) {
		$entries = array_values(
			array_filter(
				array_map(
					static function ( $entry ) {
						return is_scalar( $entry ) ? trim( (string) $entry ) : '';
					},
					(array) $entries
				)
			)
		);

		if ( empty( $entries ) ) {
			return '';
		}

		$title = strtoupper( trim( (string) $title ) );

		return '[' . $title . ']' . "\n" . implode( "\n", $entries );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_build_odoo_lead_description' ) ) {
	function ethnic_request_proposal_page_build_odoo_lead_description( $submission_data, $settings ) {
		$services = ! empty( $submission_data['required_service_labels'] ) && is_array( $submission_data['required_service_labels'] )
			? array_values( array_filter( array_map( 'trim', $submission_data['required_service_labels'] ) ) )
			: array();
		$files    = ! empty( $submission_data['attachment_urls'] ) && is_array( $submission_data['attachment_urls'] )
			? array_values( array_filter( array_map( 'trim', $submission_data['attachment_urls'] ) ) )
			: array();
		$sections = array(
			ethnic_request_proposal_page_odoo_section(
				'Lead details',
				array(
					ethnic_request_proposal_page_odoo_line( 'Lead source', ! empty( $settings['source_label'] ) ? $settings['source_label'] : 'Website Proposal Requests' ),
					ethnic_request_proposal_page_odoo_line( 'Submitted at', ! empty( $submission_data['submitted_at'] ) ? $submission_data['submitted_at'] : '' ),
					ethnic_request_proposal_page_odoo_line( 'Page URL', ! empty( $submission_data['page_url'] ) ? $submission_data['page_url'] : '' ),
					ethnic_request_proposal_page_odoo_line( 'Proposal source', ! empty( $submission_data['proposal_source'] ) ? $submission_data['proposal_source'] : '' ),
				)
			),
			ethnic_request_proposal_page_odoo_section(
				'Contact',
				array(
					ethnic_request_proposal_page_odoo_line( 'Contact name', ! empty( $submission_data['full_name'] ) ? $submission_data['full_name'] : '' ),
					ethnic_request_proposal_page_odoo_line( 'Company', ! empty( $submission_data['company_name'] ) ? $submission_data['company_name'] : '' ),
					ethnic_request_proposal_page_odoo_line( 'Email', ! empty( $submission_data['work_email'] ) ? $submission_data['work_email'] : '' ),
					ethnic_request_proposal_page_odoo_line( 'Phone', ! empty( $submission_data['phone_number'] ) ? $submission_data['phone_number'] : '' ),
					ethnic_request_proposal_page_odoo_line( 'Website', ! empty( $submission_data['company_url'] ) ? $submission_data['company_url'] : '' ),
				)
			),
			ethnic_request_proposal_page_odoo_section(
				'Project summary',
				array(
					ethnic_request_proposal_page_odoo_line( 'Project title', ! empty( $submission_data['project_title'] ) ? $submission_data['project_title'] : '' ),
					ethnic_request_proposal_page_odoo_line( 'Project type', ! empty( $submission_data['project_type_label'] ) ? $submission_data['project_type_label'] : '' ),
					ethnic_request_proposal_page_odoo_list_block( 'Required services', $services ),
					ethnic_request_proposal_page_odoo_line( 'Desired start', ! empty( $submission_data['desired_start_time_label'] ) ? $submission_data['desired_start_time_label'] : '' ),
					ethnic_request_proposal_page_odoo_line( 'Target delivery timeline', ! empty( $submission_data['target_timeline_label'] ) ? $submission_data['target_timeline_label'] : '' ),
					ethnic_request_proposal_page_odoo_line( 'Budget band', ! empty( $submission_data['budget_band_label'] ) ? $submission_data['budget_band_label'] : '' ),
				)
			),
			ethnic_request_proposal_page_odoo_section(
				'Project details',
				array(
					ethnic_request_proposal_page_odoo_block( 'Project overview', ! empty( $submission_data['project_overview'] ) ? $submission_data['project_overview'] : '' ),
					ethnic_request_proposal_page_odoo_block( 'Project goals', ! empty( $submission_data['project_goals'] ) ? $submission_data['project_goals'] : '' ),
					ethnic_request_proposal_page_odoo_block( 'Current situation', ! empty( $submission_data['current_platform'] ) ? $submission_data['current_platform'] : '' ),
					ethnic_request_proposal_page_odoo_block( 'Timeline notes', ! empty( $submission_data['timeline_notes'] ) ? $submission_data['timeline_notes'] : '' ),
					ethnic_request_proposal_page_odoo_block( 'Additional requirements', ! empty( $submission_data['additional_requirements'] ) ? $submission_data['additional_requirements'] : '' ),
					ethnic_request_proposal_page_odoo_block( 'References / inspiration', ! empty( $submission_data['reference_links'] ) ? $submission_data['reference_links'] : '' ),
					ethnic_request_proposal_page_odoo_block( 'Anything else', ! empty( $submission_data['anything_else'] ) ? $submission_data['anything_else'] : '' ),
				)
			),
			ethnic_request_proposal_page_odoo_section(
				'Files',
				array(
					ethnic_request_proposal_page_odoo_list_block( 'Uploaded files', $files ),
				)
			),
			ethnic_request_proposal_page_odoo_section(
				'Technical context',
				array(
					ethnic_request_proposal_page_odoo_line( 'Referrer', ! empty( $submission_data['referrer'] ) ? $submission_data['referrer'] : '' ),
					ethnic_request_proposal_page_odoo_line( 'IP address', ! empty( $submission_data['ip'] ) ? $submission_data['ip'] : '' ),
					ethnic_request_proposal_page_odoo_block( 'User agent', ! empty( $submission_data['user_agent'] ) ? $submission_data['user_agent'] : '' ),
				)
			),
		);

		$sections = array_filter(
			array_map(
				'trim',
				$sections
			)
		);

		return implode( "\n\n", $sections );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_build_odoo_lead_payload' ) ) {
	function ethnic_request_proposal_page_build_odoo_lead_payload( $submission_data, $settings ) {
		$project_title = ! empty( $submission_data['project_title'] ) ? (string) $submission_data['project_title'] : 'Proposal Request';
		$lead_prefix   = ! empty( $settings['lead_prefix'] ) ? trim( (string) $settings['lead_prefix'] ) : 'Proposal Request';
		$lead_name     = $lead_prefix ? $lead_prefix . ': ' . $project_title : $project_title;
		$payload       = array(
			'name'         => $lead_name,
			'type'         => ! empty( $settings['lead_type'] ) ? (string) $settings['lead_type'] : 'lead',
			'contact_name' => ! empty( $submission_data['full_name'] ) ? (string) $submission_data['full_name'] : '',
			'partner_name' => ! empty( $submission_data['company_name'] ) ? (string) $submission_data['company_name'] : '',
			'email_from'   => ! empty( $submission_data['work_email'] ) ? (string) $submission_data['work_email'] : '',
			'phone'        => ! empty( $submission_data['phone_number'] ) ? (string) $submission_data['phone_number'] : '',
			'website'      => ! empty( $submission_data['company_url'] ) ? (string) $submission_data['company_url'] : '',
			'description'  => ethnic_request_proposal_page_build_odoo_lead_description( $submission_data, $settings ),
		);

		if ( ! empty( $settings['team_id'] ) ) {
			$payload['team_id'] = absint( $settings['team_id'] );
		}

		if ( ! empty( $settings['user_id'] ) ) {
			$payload['user_id'] = absint( $settings['user_id'] );
		}

		return $payload;
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_sync_submission_to_odoo' ) ) {
	function ethnic_request_proposal_page_sync_submission_to_odoo( $post_id, $force = false ) {
		$post_id = absint( $post_id );
		$data    = ethnic_request_proposal_page_submission_data( $post_id );

		if ( $post_id <= 0 || empty( $data ) ) {
			return new WP_Error( 'ethnic_proposal_submission_missing', 'The proposal request could not be found.' );
		}

		if ( ! function_exists( 'ethnic_odoo_crm_channel_settings' ) || ! function_exists( 'ethnic_odoo_crm_create_lead' ) ) {
			return new WP_Error( 'ethnic_proposal_odoo_unavailable', 'The shared Odoo CRM module is not available.' );
		}

		$settings      = ethnic_odoo_crm_channel_settings( 'proposal' );
		$status        = ! empty( $data['odoo_sync_status'] ) ? sanitize_key( (string) $data['odoo_sync_status'] ) : 'pending';
		$existing_lead = ! empty( $data['odoo_lead_id'] ) ? absint( $data['odoo_lead_id'] ) : 0;

		if ( $existing_lead > 0 && 'synced' === $status && ! $force ) {
			return $existing_lead;
		}

		if ( empty( $settings['enabled'] ) ) {
			ethnic_request_proposal_page_update_submission_data(
				$post_id,
				array(
					'odoo_sync_status'  => 'disabled',
					'odoo_sync_message' => 'Odoo CRM sync is currently disabled in settings.',
					'odoo_last_attempt' => current_time( 'mysql' ),
				)
			);

			return new WP_Error( 'ethnic_proposal_odoo_disabled', 'Odoo CRM sync is currently disabled in settings.' );
		}

		if ( ! function_exists( 'ethnic_odoo_crm_credentials_present' ) || ! ethnic_odoo_crm_credentials_present( $settings ) ) {
			ethnic_request_proposal_page_update_submission_data(
				$post_id,
				array(
					'odoo_sync_status'  => 'not-configured',
					'odoo_sync_message' => 'Complete the Odoo CRM settings before syncing proposal requests.',
					'odoo_last_attempt' => current_time( 'mysql' ),
				)
			);

			return new WP_Error( 'ethnic_proposal_odoo_not_configured', 'Complete the Odoo CRM settings before syncing proposal requests.' );
		}

		ethnic_request_proposal_page_update_submission_data(
			$post_id,
			array(
				'odoo_sync_status'  => 'syncing',
				'odoo_sync_message' => 'Syncing proposal request to Odoo CRM.',
				'odoo_last_attempt' => current_time( 'mysql' ),
			)
		);

		$payload     = ethnic_request_proposal_page_build_odoo_lead_payload( $data, $settings );
		$sync_result = false;
		$lead_id     = $existing_lead;
		$message     = 'Proposal request synced to Odoo CRM successfully.';

		if ( $existing_lead > 0 && function_exists( 'ethnic_odoo_crm_update_lead' ) ) {
			$sync_result = ethnic_odoo_crm_update_lead( $existing_lead, $payload, $settings );
			$message     = 'Proposal request updated in Odoo CRM successfully.';
		} else {
			$sync_result = ethnic_odoo_crm_create_lead( $payload, $settings );
		}

		if ( is_wp_error( $sync_result ) ) {
			ethnic_request_proposal_page_update_submission_data(
				$post_id,
				array(
					'odoo_sync_status'  => 'failed',
					'odoo_sync_message' => $sync_result->get_error_message(),
					'odoo_last_attempt' => current_time( 'mysql' ),
				)
			);

			return $sync_result;
		}

		if ( $existing_lead <= 0 ) {
			$lead_id = absint( $sync_result );
		}

		if ( $lead_id <= 0 ) {
			$error = new WP_Error( 'ethnic_proposal_odoo_invalid_lead', 'Odoo did not return a valid CRM lead ID for this proposal request.' );

			ethnic_request_proposal_page_update_submission_data(
				$post_id,
				array(
					'odoo_sync_status'  => 'failed',
					'odoo_sync_message' => $error->get_error_message(),
					'odoo_last_attempt' => current_time( 'mysql' ),
				)
			);

			return $error;
		}

		ethnic_request_proposal_page_update_submission_data(
			$post_id,
			array(
				'odoo_sync_status'  => 'synced',
				'odoo_sync_message' => $message,
				'odoo_lead_id'      => $lead_id,
				'odoo_synced_at'    => current_time( 'mysql' ),
				'odoo_last_attempt' => current_time( 'mysql' ),
			)
		);

		return $lead_id;
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_maybe_sync_submission_to_odoo' ) ) {
	function ethnic_request_proposal_page_maybe_sync_submission_to_odoo( $post_id ) {
		$result = ethnic_request_proposal_page_sync_submission_to_odoo( $post_id );

		return is_wp_error( $result ) ? 0 : absint( $result );
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_sync_existing_submissions_to_odoo' ) ) {
	function ethnic_request_proposal_page_sync_existing_submissions_to_odoo() {
		if ( ! function_exists( 'ethnic_odoo_crm_channel_settings' ) ) {
			return new WP_Error( 'ethnic_proposal_odoo_unavailable', 'The shared Odoo CRM module is not available.' );
		}

		$settings = ethnic_odoo_crm_channel_settings( 'proposal' );

		if ( empty( $settings['enabled'] ) ) {
			return new WP_Error( 'ethnic_proposal_odoo_disabled', 'Enable Proposal Request sync before syncing existing proposal requests.' );
		}

		if ( ! function_exists( 'ethnic_odoo_crm_credentials_present' ) || ! ethnic_odoo_crm_credentials_present( $settings ) ) {
			return new WP_Error( 'ethnic_proposal_odoo_not_configured', 'Complete the Odoo CRM settings before syncing existing proposal requests.' );
		}

		$ids = get_posts(
			array(
				'post_type'      => ETHNIC_PROPOSAL_REQUEST_POST_TYPE,
				'post_status'    => 'publish',
				'posts_per_page' => -1,
				'fields'         => 'ids',
				'orderby'        => 'date',
				'order'          => 'ASC',
			)
		);

		$totals = array(
			'processed' => 0,
			'synced'    => 0,
			'failed'    => 0,
			'skipped'   => 0,
		);

		foreach ( $ids as $post_id ) {
			$data   = ethnic_request_proposal_page_submission_data( $post_id );
			$status = ! empty( $data['odoo_sync_status'] ) ? sanitize_key( (string) $data['odoo_sync_status'] ) : 'pending';

			if ( ! empty( $data['odoo_lead_id'] ) && 'synced' === $status ) {
				++$totals['skipped'];
				continue;
			}

			++$totals['processed'];

			$result = ethnic_request_proposal_page_sync_submission_to_odoo( $post_id, false );

			if ( is_wp_error( $result ) ) {
				++$totals['failed'];
			} else {
				++$totals['synced'];
			}
		}

		return $totals;
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_submission_redirect_url' ) ) {
	function ethnic_request_proposal_page_submission_redirect_url( $status, $base_url = '' ) {
		$base_url = $base_url ? $base_url : ethnic_request_proposal_page_url();
		$target   = add_query_arg(
			array(
				'proposal_request_status' => sanitize_key( (string) $status ),
			),
			$base_url
		);

		return $target . '#proposal-request-form';
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_require_media_dependencies' ) ) {
	function ethnic_request_proposal_page_require_media_dependencies() {
		require_once ABSPATH . 'wp-admin/includes/file.php';
		require_once ABSPATH . 'wp-admin/includes/media.php';
		require_once ABSPATH . 'wp-admin/includes/image.php';
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_upload_error_message' ) ) {
	function ethnic_request_proposal_page_upload_error_message( $code ) {
		$messages = array(
			UPLOAD_ERR_INI_SIZE   => 'The uploaded file exceeds the server upload limit.',
			UPLOAD_ERR_FORM_SIZE  => 'The uploaded file exceeds the allowed form size.',
			UPLOAD_ERR_PARTIAL    => 'The uploaded file was only partially uploaded.',
			UPLOAD_ERR_NO_FILE    => 'No file was uploaded.',
			UPLOAD_ERR_NO_TMP_DIR => 'The server is missing a temporary upload folder.',
			UPLOAD_ERR_CANT_WRITE => 'The server could not write the uploaded file.',
			UPLOAD_ERR_EXTENSION  => 'The upload was stopped by a server extension.',
		);

		return isset( $messages[ $code ] ) ? $messages[ $code ] : 'The uploaded file could not be processed.';
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_normalize_uploaded_files' ) ) {
	function ethnic_request_proposal_page_normalize_uploaded_files( $files ) {
		$normalized = array();

		if ( ! is_array( $files ) || empty( $files['name'] ) ) {
			return $normalized;
		}

		if ( ! is_array( $files['name'] ) ) {
			return array( $files );
		}

		foreach ( $files['name'] as $index => $name ) {
			if ( '' === (string) $name ) {
				continue;
			}

			$normalized[] = array(
				'name'     => isset( $files['name'][ $index ] ) ? $files['name'][ $index ] : '',
				'type'     => isset( $files['type'][ $index ] ) ? $files['type'][ $index ] : '',
				'tmp_name' => isset( $files['tmp_name'][ $index ] ) ? $files['tmp_name'][ $index ] : '',
				'error'    => isset( $files['error'][ $index ] ) ? $files['error'][ $index ] : UPLOAD_ERR_NO_FILE,
				'size'     => isset( $files['size'][ $index ] ) ? $files['size'][ $index ] : 0,
			);
		}

		return $normalized;
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_handle_uploaded_files' ) ) {
	function ethnic_request_proposal_page_handle_uploaded_files( $files, $parent_post_id = 0 ) {
		$attachments = array();
		$errors      = array();
		$items       = ethnic_request_proposal_page_normalize_uploaded_files( $files );

		if ( empty( $items ) ) {
			return array(
				'attachments' => array(),
				'errors'      => array(),
			);
		}

		ethnic_request_proposal_page_require_media_dependencies();

		foreach ( $items as $item ) {
			$error_code = isset( $item['error'] ) ? (int) $item['error'] : UPLOAD_ERR_NO_FILE;

			if ( UPLOAD_ERR_NO_FILE === $error_code ) {
				continue;
			}

			if ( UPLOAD_ERR_OK !== $error_code ) {
				$errors[] = ethnic_request_proposal_page_upload_error_message( $error_code );
				continue;
			}

			$uploaded = wp_handle_upload(
				$item,
				array(
					'test_form' => false,
				)
			);

			if ( ! empty( $uploaded['error'] ) ) {
				$errors[] = sanitize_text_field( (string) $uploaded['error'] );
				continue;
			}

			$file_path = isset( $uploaded['file'] ) ? (string) $uploaded['file'] : '';
			$file_type = wp_check_filetype( wp_basename( $file_path ) );
			$title     = sanitize_text_field( preg_replace( '/\.[^.]+$/', '', wp_basename( (string) $item['name'] ) ) );

			$attachment_id = wp_insert_attachment(
				array(
					'post_mime_type' => ! empty( $uploaded['type'] ) ? (string) $uploaded['type'] : ( ! empty( $file_type['type'] ) ? (string) $file_type['type'] : '' ),
					'post_title'     => $title ? $title : 'Proposal Attachment',
					'post_content'   => '',
					'post_status'    => 'inherit',
					'post_parent'    => absint( $parent_post_id ),
				),
				$file_path,
				absint( $parent_post_id ),
				true
			);

			if ( is_wp_error( $attachment_id ) ) {
				$errors[] = $attachment_id->get_error_message();
				continue;
			}

			$metadata = wp_generate_attachment_metadata( $attachment_id, $file_path );

			if ( ! is_wp_error( $metadata ) && ! empty( $metadata ) ) {
				wp_update_attachment_metadata( $attachment_id, $metadata );
			}

			$attachments[] = (int) $attachment_id;
		}

		return array(
			'attachments' => $attachments,
			'errors'      => $errors,
		);
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_store_submission' ) ) {
	function ethnic_request_proposal_page_store_submission( $submission, $files = array() ) {
		$name          = isset( $submission['full_name'] ) ? sanitize_text_field( (string) $submission['full_name'] ) : '';
		$company       = isset( $submission['company_name'] ) ? sanitize_text_field( (string) $submission['company_name'] ) : '';
		$email         = isset( $submission['work_email'] ) ? sanitize_email( (string) $submission['work_email'] ) : '';
		$project_title = isset( $submission['project_title'] ) ? sanitize_text_field( (string) $submission['project_title'] ) : '';
		$post_title    = $project_title ? $project_title : ( $company ? $company : ( $name ? $name : 'Proposal Request' ) );

		if ( $email && function_exists( 'ethnic_email_domain_is_allowed' ) && ! ethnic_email_domain_is_allowed( $email ) ) {
			return new WP_Error( 'ethnic_proposal_blocked_email', function_exists( 'ethnic_email_domain_block_message' ) ? ethnic_email_domain_block_message() : 'This email domain is not allowed.' );
		}

		$post_id = wp_insert_post(
			array(
				'post_type'      => ETHNIC_PROPOSAL_REQUEST_POST_TYPE,
				'post_status'    => 'publish',
				'post_title'     => $post_title,
				'post_content'   => '',
				'comment_status' => 'closed',
				'ping_status'    => 'closed',
			)
		);

		if ( ! $post_id || is_wp_error( $post_id ) ) {
			return new WP_Error( 'ethnic_proposal_save_failed', 'The proposal request could not be stored.' );
		}

		$upload_result = array(
			'attachments' => array(),
			'errors'      => array(),
		);

		if ( ! empty( $files['supporting_files'] ) ) {
			$upload_result = ethnic_request_proposal_page_handle_uploaded_files( $files['supporting_files'], $post_id );
		}

		$service_values = isset( $submission['required_services'] ) && is_array( $submission['required_services'] ) ? $submission['required_services'] : array();
		$service_values = array_values(
			array_filter(
				array_map(
					'sanitize_key',
					$service_values
				)
			)
		);

		$service_labels  = ethnic_request_proposal_page_service_labels( $service_values );
		$attachment_ids  = array_values( array_filter( array_map( 'absint', (array) $upload_result['attachments'] ) ) );
		$attachment_urls = array();

		foreach ( $attachment_ids as $attachment_id ) {
			$url = wp_get_attachment_url( $attachment_id );

			if ( $url ) {
				$attachment_urls[] = esc_url_raw( $url );
			}
		}

		update_post_meta(
			$post_id,
			ethnic_request_proposal_page_submission_meta_key(),
			array(
				'full_name'                => $name,
				'company_name'             => $company,
				'work_email'               => $email,
				'phone_number'             => isset( $submission['phone_number'] ) ? sanitize_text_field( (string) $submission['phone_number'] ) : '',
				'company_url'              => isset( $submission['company_url'] ) ? esc_url_raw( (string) $submission['company_url'] ) : '',
				'project_title'            => $project_title,
				'project_type'             => isset( $submission['project_type'] ) ? sanitize_key( (string) $submission['project_type'] ) : '',
				'project_type_label'       => ethnic_request_proposal_page_project_type_label( isset( $submission['project_type'] ) ? sanitize_key( (string) $submission['project_type'] ) : '' ),
				'project_overview'         => isset( $submission['project_overview'] ) ? sanitize_textarea_field( (string) $submission['project_overview'] ) : '',
				'project_goals'            => isset( $submission['project_goals'] ) ? sanitize_textarea_field( (string) $submission['project_goals'] ) : '',
				'current_platform'         => isset( $submission['current_platform'] ) ? sanitize_textarea_field( (string) $submission['current_platform'] ) : '',
				'required_services'        => $service_values,
				'required_service_labels'  => $service_labels,
				'desired_start_time'       => isset( $submission['desired_start_time'] ) ? sanitize_key( (string) $submission['desired_start_time'] ) : '',
				'desired_start_time_label' => ethnic_request_proposal_page_start_time_label( isset( $submission['desired_start_time'] ) ? sanitize_key( (string) $submission['desired_start_time'] ) : '' ),
				'target_delivery_timeline' => isset( $submission['target_delivery_timeline'] ) ? sanitize_key( (string) $submission['target_delivery_timeline'] ) : '',
				'target_timeline_label'    => ethnic_request_proposal_page_target_timeline_label( isset( $submission['target_delivery_timeline'] ) ? sanitize_key( (string) $submission['target_delivery_timeline'] ) : '' ),
				'timeline_notes'           => isset( $submission['timeline_notes'] ) ? sanitize_textarea_field( (string) $submission['timeline_notes'] ) : '',
				'budget_band'              => isset( $submission['budget_band'] ) ? sanitize_key( (string) $submission['budget_band'] ) : '',
				'budget_band_label'        => ethnic_request_proposal_page_budget_label( isset( $submission['budget_band'] ) ? sanitize_key( (string) $submission['budget_band'] ) : '' ),
				'additional_requirements'  => isset( $submission['additional_requirements'] ) ? sanitize_textarea_field( (string) $submission['additional_requirements'] ) : '',
				'reference_links'          => isset( $submission['reference_links'] ) ? sanitize_textarea_field( (string) $submission['reference_links'] ) : '',
				'anything_else'            => isset( $submission['anything_else'] ) ? sanitize_textarea_field( (string) $submission['anything_else'] ) : '',
				'proposal_source'          => isset( $submission['proposal_source'] ) ? sanitize_text_field( (string) $submission['proposal_source'] ) : '',
				'consent'                  => ! empty( $submission['proposal_consent'] ) ? 1 : 0,
				'submitted_at'             => current_time( 'mysql' ),
				'ip'                       => isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '',
				'user_agent'               => isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '',
				'referrer'                 => isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
				'page_url'                 => ethnic_request_proposal_page_url(),
				'attachment_ids'           => $attachment_ids,
				'attachment_urls'          => $attachment_urls,
				'upload_error_messages'    => array_values( array_map( 'sanitize_text_field', (array) $upload_result['errors'] ) ),
				'odoo_sync_status'         => 'pending',
				'odoo_sync_message'        => '',
				'odoo_lead_id'             => 0,
				'odoo_synced_at'           => '',
				'odoo_last_attempt'        => '',
			)
		);

		ethnic_request_proposal_page_maybe_sync_submission_to_odoo( $post_id );

		return array(
			'post_id'         => (int) $post_id,
			'attachment_ids'  => $attachment_ids,
			'upload_errors'   => (array) $upload_result['errors'],
			'status'          => empty( $upload_result['errors'] ) ? 'success' : 'partial',
		);
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_handle_submission' ) ) {
	function ethnic_request_proposal_page_handle_submission() {
		$is_submission = false;

		if ( isset( $_POST['action'] ) ) {
			$is_submission = 'ethnic_submit_proposal_request' === sanitize_key( wp_unslash( $_POST['action'] ) );
		}

		if ( ! $is_submission ) {
			return;
		}

		$return_url = ethnic_request_proposal_page_url();

		if ( ! empty( $_POST['return_url'] ) ) {
			$validated_return = wp_validate_redirect( wp_unslash( (string) $_POST['return_url'] ), ethnic_request_proposal_page_url() );

			if ( $validated_return ) {
				$return_url = $validated_return;
			}
		}

		if ( empty( $_POST['ethnic_request_proposal_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['ethnic_request_proposal_nonce'] ) ), 'ethnic_submit_proposal_request' ) ) {
			wp_safe_redirect( ethnic_request_proposal_page_submission_redirect_url( 'error', $return_url ) );
			exit;
		}

		$raw_services = isset( $_POST['required_services'] ) && is_array( $_POST['required_services'] ) ? wp_unslash( $_POST['required_services'] ) : array();
		$services     = array_values(
			array_filter(
				array_map(
					'sanitize_key',
					(array) $raw_services
				)
			)
		);

		$submission = array(
			'full_name'                => isset( $_POST['full_name'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['full_name'] ) ) : '',
			'company_name'             => isset( $_POST['company_name'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['company_name'] ) ) : '',
			'work_email'               => isset( $_POST['work_email'] ) ? sanitize_email( wp_unslash( (string) $_POST['work_email'] ) ) : '',
			'phone_number'             => isset( $_POST['phone_number'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['phone_number'] ) ) : '',
			'company_url'              => isset( $_POST['company_url'] ) ? esc_url_raw( wp_unslash( (string) $_POST['company_url'] ) ) : '',
			'project_title'            => isset( $_POST['project_title'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['project_title'] ) ) : '',
			'project_type'             => isset( $_POST['project_type'] ) ? sanitize_key( wp_unslash( (string) $_POST['project_type'] ) ) : '',
			'project_overview'         => isset( $_POST['project_overview'] ) ? sanitize_textarea_field( wp_unslash( (string) $_POST['project_overview'] ) ) : '',
			'project_goals'            => isset( $_POST['project_goals'] ) ? sanitize_textarea_field( wp_unslash( (string) $_POST['project_goals'] ) ) : '',
			'current_platform'         => isset( $_POST['current_platform'] ) ? sanitize_textarea_field( wp_unslash( (string) $_POST['current_platform'] ) ) : '',
			'required_services'        => $services,
			'desired_start_time'       => isset( $_POST['desired_start_time'] ) ? sanitize_key( wp_unslash( (string) $_POST['desired_start_time'] ) ) : '',
			'target_delivery_timeline' => isset( $_POST['target_delivery_timeline'] ) ? sanitize_key( wp_unslash( (string) $_POST['target_delivery_timeline'] ) ) : '',
			'timeline_notes'           => isset( $_POST['timeline_notes'] ) ? sanitize_textarea_field( wp_unslash( (string) $_POST['timeline_notes'] ) ) : '',
			'budget_band'              => isset( $_POST['budget_band'] ) ? sanitize_key( wp_unslash( (string) $_POST['budget_band'] ) ) : '',
			'additional_requirements'  => isset( $_POST['additional_requirements'] ) ? sanitize_textarea_field( wp_unslash( (string) $_POST['additional_requirements'] ) ) : '',
			'reference_links'          => isset( $_POST['reference_links'] ) ? sanitize_textarea_field( wp_unslash( (string) $_POST['reference_links'] ) ) : '',
			'anything_else'            => isset( $_POST['anything_else'] ) ? sanitize_textarea_field( wp_unslash( (string) $_POST['anything_else'] ) ) : '',
			'proposal_source'          => isset( $_POST['proposal_source'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['proposal_source'] ) ) : 'request-a-proposal-page',
			'proposal_consent'         => ! empty( $_POST['proposal_consent'] ) ? 1 : 0,
		);

		$required_fields = array(
			$submission['full_name'],
			$submission['company_name'],
			$submission['work_email'],
			$submission['project_title'],
			$submission['project_type'],
			$submission['project_overview'],
			$submission['project_goals'],
			$submission['desired_start_time'],
			$submission['target_delivery_timeline'],
			$submission['budget_band'],
		);

		$is_valid = true;

		foreach ( $required_fields as $field_value ) {
			if ( '' === trim( (string) $field_value ) ) {
				$is_valid = false;
				break;
			}
		}

		if ( ! is_email( $submission['work_email'] ) || empty( $submission['required_services'] ) || empty( $submission['proposal_consent'] ) ) {
			$is_valid = false;
		}

		if ( ! empty( $submission['work_email'] ) && function_exists( 'ethnic_email_domain_is_allowed' ) && ! ethnic_email_domain_is_allowed( $submission['work_email'] ) ) {
			wp_safe_redirect( ethnic_request_proposal_page_submission_redirect_url( 'blocked_email', $return_url ) );
			exit;
		}

		if ( ! $is_valid ) {
			wp_safe_redirect( ethnic_request_proposal_page_submission_redirect_url( 'invalid', $return_url ) );
			exit;
		}

		if ( function_exists( 'ethnic_recaptcha_verify_submission' ) ) {
			$recaptcha_result = ethnic_recaptcha_verify_submission( 'proposal_request' );

			if ( is_wp_error( $recaptcha_result ) ) {
				wp_safe_redirect( ethnic_request_proposal_page_submission_redirect_url( 'security', $return_url ) );
				exit;
			}
		}

		$result = ethnic_request_proposal_page_store_submission( $submission, $_FILES );

		if ( is_wp_error( $result ) ) {
			if ( 'ethnic_proposal_blocked_email' === $result->get_error_code() ) {
				wp_safe_redirect( ethnic_request_proposal_page_submission_redirect_url( 'blocked_email', $return_url ) );
				exit;
			}

			wp_safe_redirect( ethnic_request_proposal_page_submission_redirect_url( 'error', $return_url ) );
			exit;
		}

		wp_safe_redirect( ethnic_request_proposal_page_submission_redirect_url( isset( $result['status'] ) ? $result['status'] : 'success', $return_url ) );
		exit;
	}

	add_action( 'admin_post_nopriv_ethnic_submit_proposal_request', 'ethnic_request_proposal_page_handle_submission' );
	add_action( 'admin_post_ethnic_submit_proposal_request', 'ethnic_request_proposal_page_handle_submission' );
}

if ( ! function_exists( 'ethnic_request_proposal_page_submission_columns' ) ) {
	function ethnic_request_proposal_page_submission_columns( $columns ) {
		$ordered = array();

		foreach ( $columns as $key => $label ) {
			if ( 'title' === $key ) {
				$ordered['title']                           = 'Project';
				$ordered['ethnic_proposal_company']         = 'Company';
				$ordered['ethnic_proposal_contact']         = 'Contact';
				$ordered['ethnic_proposal_services']        = 'Services';
				$ordered['ethnic_proposal_budget']          = 'Budget';
				$ordered['ethnic_proposal_files']           = 'Files';
				$ordered['ethnic_proposal_crm']             = 'Odoo CRM';
				continue;
			}

			if ( 'date' === $key ) {
				$ordered['date'] = 'Submitted';
				continue;
			}

			$ordered[ $key ] = $label;
		}

		return $ordered;
	}

	add_filter( 'manage_' . ETHNIC_PROPOSAL_REQUEST_POST_TYPE . '_posts_columns', 'ethnic_request_proposal_page_submission_columns' );
}

if ( ! function_exists( 'ethnic_request_proposal_page_render_submission_column' ) ) {
	function ethnic_request_proposal_page_render_submission_column( $column, $post_id ) {
		$data = ethnic_request_proposal_page_submission_data( $post_id );

		switch ( $column ) {
			case 'ethnic_proposal_company':
				echo ! empty( $data['company_name'] ) ? esc_html( $data['company_name'] ) : '<span style="color:#6a7691;">—</span>';
				break;

			case 'ethnic_proposal_contact':
				if ( ! empty( $data['full_name'] ) ) {
					echo esc_html( $data['full_name'] );
				}

				if ( ! empty( $data['work_email'] ) ) {
					echo ! empty( $data['full_name'] ) ? '<br />' : '';
					printf(
						'<a href="mailto:%1$s">%2$s</a>',
						esc_attr( $data['work_email'] ),
						esc_html( $data['work_email'] )
					);
				}
				break;

			case 'ethnic_proposal_services':
				$labels = ! empty( $data['required_service_labels'] ) && is_array( $data['required_service_labels'] ) ? $data['required_service_labels'] : array();
				echo ! empty( $labels ) ? esc_html( implode( ', ', $labels ) ) : '<span style="color:#6a7691;">—</span>';
				break;

			case 'ethnic_proposal_budget':
				echo ! empty( $data['budget_band_label'] ) ? esc_html( $data['budget_band_label'] ) : '<span style="color:#6a7691;">—</span>';
				break;

			case 'ethnic_proposal_files':
				$attachment_ids = ! empty( $data['attachment_ids'] ) && is_array( $data['attachment_ids'] ) ? array_filter( array_map( 'absint', $data['attachment_ids'] ) ) : array();
				$count          = count( $attachment_ids );

				if ( $count > 0 ) {
					echo esc_html( sprintf( '%d file%s', $count, 1 === $count ? '' : 's' ) );
				} else {
					echo '<span style="color:#6a7691;">No files</span>';
				}
				break;

			case 'ethnic_proposal_crm':
				$status          = ! empty( $data['odoo_sync_status'] ) ? sanitize_key( (string) $data['odoo_sync_status'] ) : 'pending';
				$settings        = function_exists( 'ethnic_odoo_crm_channel_settings' ) ? ethnic_odoo_crm_channel_settings( 'proposal' ) : array();
				$can_manual_sync = ! empty( $settings['enabled'] ) && function_exists( 'ethnic_odoo_crm_credentials_present' ) && ethnic_odoo_crm_credentials_present( $settings );
				$lead_url        = ! empty( $data['odoo_lead_id'] ) && function_exists( 'ethnic_odoo_crm_lead_admin_url' ) ? ethnic_odoo_crm_lead_admin_url( (int) $data['odoo_lead_id'], $settings ) : '';

				if ( function_exists( 'ethnic_odoo_crm_sync_badge_html' ) ) {
					echo wp_kses_post( ethnic_odoo_crm_sync_badge_html( $status ) );
				} else {
					echo esc_html( ucfirst( $status ) );
				}

				if ( ! empty( $data['odoo_lead_id'] ) ) {
					echo '<br /><span style="color:#6a7691;font-size:12px;">Lead #' . esc_html( (string) $data['odoo_lead_id'] ) . '</span>';
				}

				if ( $lead_url ) {
					echo '<br /><a href="' . esc_url( $lead_url ) . '" target="_blank" rel="noopener">Open lead</a>';
				}

				if ( $can_manual_sync ) {
					$sync_label = $lead_url ? 'Refresh lead' : 'Sync now';
					echo '<br /><a href="' . esc_url( ethnic_request_proposal_page_submission_sync_url( $post_id, admin_url( 'edit.php?post_type=' . ETHNIC_PROPOSAL_REQUEST_POST_TYPE ) ) ) . '">' . esc_html( $sync_label ) . '</a>';
				}
				break;
		}
	}

	add_action( 'manage_' . ETHNIC_PROPOSAL_REQUEST_POST_TYPE . '_posts_custom_column', 'ethnic_request_proposal_page_render_submission_column', 10, 2 );
}

if ( ! function_exists( 'ethnic_request_proposal_page_add_submission_meta_boxes' ) ) {
	function ethnic_request_proposal_page_add_submission_meta_boxes() {
		add_meta_box(
			'ethnic-proposal-request-details',
			'Proposal Request Details',
			'ethnic_request_proposal_page_render_submission_meta_box',
			ETHNIC_PROPOSAL_REQUEST_POST_TYPE,
			'normal',
			'high'
		);
	}

	add_action( 'add_meta_boxes_' . ETHNIC_PROPOSAL_REQUEST_POST_TYPE, 'ethnic_request_proposal_page_add_submission_meta_boxes' );
}

if ( ! function_exists( 'ethnic_request_proposal_page_render_submission_meta_box' ) ) {
	function ethnic_request_proposal_page_render_submission_meta_box( $post ) {
		$data           = ethnic_request_proposal_page_submission_data( $post->ID );
		$attachment_ids = ! empty( $data['attachment_ids'] ) && is_array( $data['attachment_ids'] ) ? array_filter( array_map( 'absint', $data['attachment_ids'] ) ) : array();
		$services       = ! empty( $data['required_service_labels'] ) && is_array( $data['required_service_labels'] ) ? implode( ', ', $data['required_service_labels'] ) : '';
		$odoo_settings  = function_exists( 'ethnic_odoo_crm_channel_settings' ) ? ethnic_odoo_crm_channel_settings( 'proposal' ) : array();
		$can_manual_sync = ! empty( $odoo_settings['enabled'] ) && function_exists( 'ethnic_odoo_crm_credentials_present' ) && ethnic_odoo_crm_credentials_present( $odoo_settings );
		$odoo_lead_admin = ! empty( $data['odoo_lead_id'] ) && function_exists( 'ethnic_odoo_crm_lead_admin_url' ) ? ethnic_odoo_crm_lead_admin_url( (int) $data['odoo_lead_id'], $odoo_settings ) : '';
		$rows           = array(
			'Full Name'                 => isset( $data['full_name'] ) ? $data['full_name'] : '',
			'Company Name'              => isset( $data['company_name'] ) ? $data['company_name'] : '',
			'Work Email'                => isset( $data['work_email'] ) ? $data['work_email'] : '',
			'Phone Number'              => isset( $data['phone_number'] ) ? $data['phone_number'] : '',
			'Company URL'               => isset( $data['company_url'] ) ? $data['company_url'] : '',
			'Project Title'             => isset( $data['project_title'] ) ? $data['project_title'] : '',
			'Project Type'              => isset( $data['project_type_label'] ) ? $data['project_type_label'] : '',
			'Project Overview'          => isset( $data['project_overview'] ) ? $data['project_overview'] : '',
			'Project Goals'             => isset( $data['project_goals'] ) ? $data['project_goals'] : '',
			'Current Situation'         => isset( $data['current_platform'] ) ? $data['current_platform'] : '',
			'Required Services'         => $services,
			'Desired Start Time'        => isset( $data['desired_start_time_label'] ) ? $data['desired_start_time_label'] : '',
			'Target Delivery Timeline'  => isset( $data['target_timeline_label'] ) ? $data['target_timeline_label'] : '',
			'Timeline Notes'            => isset( $data['timeline_notes'] ) ? $data['timeline_notes'] : '',
			'Budget Band'               => isset( $data['budget_band_label'] ) ? $data['budget_band_label'] : '',
			'Additional Requirements'   => isset( $data['additional_requirements'] ) ? $data['additional_requirements'] : '',
			'References / Inspiration'  => isset( $data['reference_links'] ) ? $data['reference_links'] : '',
			'Anything Else'             => isset( $data['anything_else'] ) ? $data['anything_else'] : '',
			'Odoo Sync'                 => isset( $data['odoo_sync_status'] ) ? $data['odoo_sync_status'] : 'pending',
			'Odoo Lead ID'              => isset( $data['odoo_lead_id'] ) ? $data['odoo_lead_id'] : '',
			'Odoo Synced'               => isset( $data['odoo_synced_at'] ) ? $data['odoo_synced_at'] : '',
			'Last Attempt'              => isset( $data['odoo_last_attempt'] ) ? $data['odoo_last_attempt'] : '',
			'Odoo Error'                => isset( $data['odoo_sync_message'] ) && 'failed' === ( isset( $data['odoo_sync_status'] ) ? $data['odoo_sync_status'] : '' ) ? $data['odoo_sync_message'] : '',
			'Submitted At'              => isset( $data['submitted_at'] ) ? $data['submitted_at'] : '',
			'IP Address'                => isset( $data['ip'] ) ? $data['ip'] : '',
			'User Agent'                => isset( $data['user_agent'] ) ? $data['user_agent'] : '',
			'Referrer'                  => isset( $data['referrer'] ) ? $data['referrer'] : '',
		);
		?>
		<style>
			.ethnic-proposal-request__grid {
				display: grid;
				grid-template-columns: 210px minmax(0, 1fr);
				gap: 12px 18px;
				align-items: start;
			}
			.ethnic-proposal-request__label {
				font-weight: 600;
				color: #22314f;
			}
			.ethnic-proposal-request__value {
				min-width: 0;
				word-break: break-word;
				white-space: pre-wrap;
			}
			.ethnic-proposal-request__files,
			.ethnic-proposal-request__notes {
				margin-top: 20px;
			}
			.ethnic-proposal-request__files ul,
			.ethnic-proposal-request__notes ul {
				margin: 8px 0 0 18px;
			}
		</style>
		<div class="ethnic-proposal-request__grid">
			<?php foreach ( $rows as $label => $value ) : ?>
				<div class="ethnic-proposal-request__label"><?php echo esc_html( $label ); ?></div>
				<div class="ethnic-proposal-request__value">
					<?php if ( 'Work Email' === $label && $value ) : ?>
						<a href="mailto:<?php echo esc_attr( $value ); ?>"><?php echo esc_html( $value ); ?></a>
					<?php elseif ( 'Odoo Sync' === $label && function_exists( 'ethnic_odoo_crm_sync_badge_html' ) ) : ?>
						<?php echo wp_kses_post( ethnic_odoo_crm_sync_badge_html( (string) $value ) ); ?>
					<?php elseif ( in_array( $label, array( 'Company URL', 'Referrer' ), true ) && $value ) : ?>
						<a href="<?php echo esc_url( $value ); ?>" target="_blank" rel="noopener"><?php echo esc_html( $value ); ?></a>
					<?php else : ?>
						<?php echo '' !== (string) $value ? esc_html( $value ) : '—'; ?>
					<?php endif; ?>
				</div>
			<?php endforeach; ?>
		</div>

		<div class="ethnic-proposal-request__files">
			<strong>Uploaded Files</strong>
			<?php if ( ! empty( $attachment_ids ) ) : ?>
				<ul>
					<?php foreach ( $attachment_ids as $attachment_id ) : ?>
						<li>
							<a href="<?php echo esc_url( wp_get_attachment_url( $attachment_id ) ); ?>" target="_blank" rel="noopener">
								<?php echo esc_html( get_the_title( $attachment_id ) ? get_the_title( $attachment_id ) : wp_basename( (string) get_attached_file( $attachment_id ) ) ); ?>
							</a>
						</li>
					<?php endforeach; ?>
				</ul>
			<?php else : ?>
				<p>No supporting files were uploaded with this request.</p>
			<?php endif; ?>
		</div>

		<?php if ( ! empty( $data['upload_error_messages'] ) && is_array( $data['upload_error_messages'] ) ) : ?>
			<div class="ethnic-proposal-request__notes">
				<strong>Upload Notes</strong>
				<ul>
					<?php foreach ( $data['upload_error_messages'] as $message ) : ?>
						<li><?php echo esc_html( $message ); ?></li>
					<?php endforeach; ?>
				</ul>
			</div>
		<?php endif; ?>

		<div class="ethnic-proposal-request__notes">
			<strong>CRM Actions</strong>
			<p style="margin:8px 0 0;">
				<?php if ( $odoo_lead_admin ) : ?>
					<a class="button button-secondary" href="<?php echo esc_url( $odoo_lead_admin ); ?>" target="_blank" rel="noopener">Open Odoo Lead</a>
					<?php if ( $can_manual_sync ) : ?>
						<a class="button button-primary" href="<?php echo esc_url( ethnic_request_proposal_page_submission_sync_url( $post->ID ) ); ?>">Refresh Odoo Lead</a>
					<?php endif; ?>
				<?php elseif ( $can_manual_sync ) : ?>
					<a class="button button-primary" href="<?php echo esc_url( ethnic_request_proposal_page_submission_sync_url( $post->ID ) ); ?>">Send to Odoo Now</a>
				<?php else : ?>
					<span style="color:#6a7691;">Proposal request sync follows the shared Odoo CRM settings.</span>
				<?php endif; ?>
			</p>
		</div>
		<?php
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_handle_manual_submission_sync' ) ) {
	function ethnic_request_proposal_page_handle_manual_submission_sync() {
		if ( ! current_user_can( 'edit_pages' ) ) {
			wp_die( 'You do not have permission to sync proposal requests.', 403 );
		}

		$post_id = isset( $_GET['submission'] ) ? absint( wp_unslash( $_GET['submission'] ) ) : 0;

		check_admin_referer( 'ethnic_proposal_sync_submission_' . $post_id );

		$redirect_to = isset( $_GET['redirect_to'] ) ? rawurldecode( (string) wp_unslash( $_GET['redirect_to'] ) ) : '';
		$redirect_to = wp_validate_redirect( $redirect_to, admin_url( 'post.php?post=' . $post_id . '&action=edit' ) );
		$result      = ethnic_request_proposal_page_sync_submission_to_odoo( $post_id, true );

		if ( function_exists( 'ethnic_odoo_crm_set_admin_notice' ) ) {
			if ( is_wp_error( $result ) ) {
				ethnic_odoo_crm_set_admin_notice( 'error', 'Odoo CRM sync failed: ' . $result->get_error_message() );
			} else {
				ethnic_odoo_crm_set_admin_notice( 'success', 'Proposal request synced to Odoo CRM successfully.' );
			}
		}

		wp_safe_redirect( $redirect_to );
		exit;
	}
	add_action( 'admin_post_ethnic_proposal_sync_submission', 'ethnic_request_proposal_page_handle_manual_submission_sync' );
}

if ( ! function_exists( 'ethnic_request_proposal_page_styles' ) ) {
	function ethnic_request_proposal_page_styles() {
		return <<<'CSS'
body.ethnic-proposal-active #page-title.page-title-block.custom-page-title {
	display: none;
}

body.ethnic-proposal-active .fullwidth-content > .ethnic-request-proposal-page {
	padding-bottom: clamp(72px, 8vw, 120px);
}

body.ethnic-proposal-active .block-content > .container {
	width: 100%;
	max-width: none;
	padding-left: 0;
	padding-right: 0;
}

body.ethnic-proposal-active .block-content > .container > .panel.row {
	margin-left: 0;
	margin-right: 0;
}

body.ethnic-proposal-active .block-content > .container > .panel > .panel-center {
	width: 100%;
	padding-left: 0;
	padding-right: 0;
}

body.ethnic-proposal-active .entry-content.post-content {
	margin-bottom: 0;
}

.ethnic-request-proposal-page {
	--ethnic-proposal-bg: #f5f8ff;
	--ethnic-proposal-surface: #ffffff;
	--ethnic-proposal-surface-soft: rgba(255, 255, 255, 0.82);
	--ethnic-proposal-border: rgba(15, 23, 42, 0.08);
	--ethnic-proposal-border-strong: rgba(148, 163, 184, 0.2);
	--ethnic-proposal-text: #10192f;
	--ethnic-proposal-text-soft: #556b8b;
	--ethnic-proposal-text-muted: #7a8ba7;
	--ethnic-proposal-dark: #0d1b3a;
	--ethnic-proposal-dark-soft: #132850;
	--ethnic-proposal-accent: #ebff56;
	--ethnic-proposal-accent-strong: #d7ff23;
	--ethnic-proposal-blue: #4d7cff;
	--ethnic-proposal-green: #5dbd74;
	--ethnic-proposal-shadow: 0 24px 54px rgba(9, 22, 48, 0.08);
	--ethnic-proposal-radius: 30px;
	background:
		radial-gradient(circle at top left, rgba(235, 255, 86, 0.1), transparent 20%),
		radial-gradient(circle at top right, rgba(77, 124, 255, 0.11), transparent 24%),
		linear-gradient(180deg, #f7faff, #f2f6ff 100%);
	color: var(--ethnic-proposal-text);
	font-family: "Plus Jakarta Sans", "Figtree", sans-serif;
}

.ethnic-request-proposal-page *,
.ethnic-request-proposal-page *::before,
.ethnic-request-proposal-page *::after {
	box-sizing: border-box;
}

.ethnic-proposal-shell {
	width: min(1280px, calc(100% - 40px));
	margin: 0 auto;
}

.ethnic-proposal-section {
	padding: clamp(72px, 8vw, 112px) 0;
}

.ethnic-proposal-section--soft {
	background:
		radial-gradient(circle at top left, rgba(235, 255, 86, 0.08), transparent 22%),
		linear-gradient(180deg, rgba(247, 250, 255, 0.86), rgba(239, 244, 255, 0.94));
}

.ethnic-proposal-heading {
	display: grid;
	gap: 14px;
	max-width: 760px;
	margin-bottom: 38px;
}

.ethnic-proposal-heading__eyebrow,
.ethnic-proposal-hero__eyebrow,
.ethnic-proposal-cta__eyebrow,
.ethnic-proposal-sidebar__eyebrow {
	display: inline-flex;
	align-items: center;
	width: fit-content;
	min-height: 42px;
	padding: 10px 18px;
	margin: 0;
	border-radius: 999px;
	border: 1px solid rgba(255, 255, 255, 0.14);
	background: rgba(255, 255, 255, 0.12);
	color: rgba(255, 255, 255, 0.9);
	font-size: 12px;
	font-weight: 800;
	letter-spacing: 0.14em;
	line-height: 1;
	text-transform: uppercase;
}

.ethnic-proposal-hero__eyebrow,
.ethnic-proposal-cta__panel h3,
.ethnic-proposal-cta__panel p,
.ethnic-proposal-checklist--light li,
.ethnic-proposal-checklist--light li span {
	-webkit-text-fill-color: currentColor;
}

.ethnic-proposal-heading__eyebrow {
	border-color: rgba(77, 124, 255, 0.12);
	background: rgba(77, 124, 255, 0.08);
	color: #50698f;
}

.ethnic-proposal-heading__title {
	margin: 0;
	color: var(--ethnic-proposal-text);
	font-size: clamp(34px, 4.4vw, 56px);
	font-weight: 700;
	line-height: 1.02;
	letter-spacing: -0.06em;
	text-wrap: balance;
}

.ethnic-proposal-heading__copy,
.ethnic-proposal-hero__copy,
.ethnic-proposal-prose p,
.ethnic-proposal-mini-card p,
.ethnic-proposal-form__section-header p,
.ethnic-proposal-field__help,
.ethnic-proposal-form__group-note,
.ethnic-proposal-sidebar__timeline-item p,
.ethnic-proposal-sidebar__panel-note p,
.ethnic-proposal-upload__meta p,
.ethnic-proposal-submit__note,
.ethnic-proposal-trust-card p,
.ethnic-proposal-faq__answer p,
.ethnic-proposal-cta p,
.ethnic-proposal-form__alert p {
	margin: 0;
	color: var(--ethnic-proposal-text-soft);
	font-size: 18px;
	line-height: 1.78;
}

.ethnic-proposal-hero {
	position: relative;
	overflow: clip;
	padding: clamp(74px, 9vw, 124px) 0 clamp(76px, 8vw, 112px);
	background:
		radial-gradient(circle at top right, rgba(235, 255, 86, 0.14), transparent 22%),
		radial-gradient(circle at top left, rgba(77, 124, 255, 0.16), transparent 24%),
		linear-gradient(135deg, #07162f 0%, #0d1e43 50%, #153953 100%);
}

.ethnic-proposal-hero::before {
	content: "";
	position: absolute;
	inset: 0;
	background:
		linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
		linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
	background-size: 42px 42px;
	opacity: 0.38;
	pointer-events: none;
}

.ethnic-proposal-hero__layout {
	position: relative;
	z-index: 1;
	display: grid;
	grid-template-columns: minmax(0, 0.95fr) minmax(420px, 1.05fr);
	gap: clamp(34px, 4vw, 54px);
	align-items: center;
}

.ethnic-proposal-hero__content {
	display: grid;
	gap: 24px;
}

.ethnic-proposal-hero__title {
	margin: 0;
	color: #ffffff !important;
	-webkit-text-fill-color: #ffffff;
	font-size: clamp(50px, 6vw, 88px);
	font-weight: 700;
	line-height: 0.94;
	letter-spacing: -0.08em;
	text-wrap: balance;
}

.ethnic-proposal-hero__copy {
	max-width: 700px;
	color: rgba(236, 242, 255, 0.94) !important;
	-webkit-text-fill-color: rgba(236, 242, 255, 0.94);
}

.ethnic-proposal-hero__actions,
.ethnic-proposal-submit__actions,
.ethnic-proposal-cta__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 14px;
}

.ethnic-proposal-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 56px;
	padding: 16px 28px;
	border-radius: 999px;
	border: 1px solid transparent;
	font-size: 17px;
	font-weight: 700;
	line-height: 1;
	text-align: center;
	text-decoration: none;
	transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.ethnic-proposal-button:hover,
.ethnic-proposal-button:focus-visible {
	transform: translateY(-1px);
	box-shadow: 0 16px 34px rgba(8, 19, 40, 0.16);
}

.ethnic-proposal-button:disabled {
	opacity: 0.72;
	cursor: wait;
	transform: none;
	box-shadow: none;
}

.ethnic-proposal-button--primary {
	background: var(--ethnic-proposal-accent);
	color: #091225;
}

.ethnic-proposal-button--secondary {
	background: rgba(255, 255, 255, 0.12);
	border-color: rgba(255, 255, 255, 0.16);
	color: #ffffff !important;
	-webkit-text-fill-color: #ffffff;
	backdrop-filter: blur(12px);
}

.ethnic-proposal-inline-link {
	color: var(--ethnic-proposal-accent);
	font-size: 15px;
	font-weight: 700;
	text-decoration: none;
}

.ethnic-proposal-hero__points,
.ethnic-proposal-checklist {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 14px;
	padding: 0;
	margin: 0;
	list-style: none;
}

.ethnic-proposal-hero__points li {
	display: flex;
	align-items: flex-start;
	gap: 12px;
	min-height: 100%;
	padding: 18px 18px 18px 16px;
	border-radius: 24px;
	background:
		linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.06)),
		rgba(255, 255, 255, 0.04);
	border: 1px solid rgba(255, 255, 255, 0.12);
	color: rgba(245, 248, 255, 0.94) !important;
	-webkit-text-fill-color: rgba(245, 248, 255, 0.94);
	font-size: 14px;
	font-weight: 600;
	line-height: 1.6;
}

.ethnic-proposal-hero__point-marker {
	display: inline-flex;
	width: 10px;
	height: 10px;
	flex: 0 0 auto;
	margin-top: 5px;
	border-radius: 50%;
	background: var(--ethnic-proposal-accent);
	box-shadow: 0 0 0 5px rgba(235, 255, 86, 0.12);
}

.ethnic-proposal-hero__visual {
	position: relative;
	min-width: 0;
}

.ethnic-proposal-visual__frame {
	position: relative;
	min-height: 560px;
	padding: 28px;
	border-radius: 36px;
	background:
		linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04)),
		linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
	border: 1px solid rgba(255, 255, 255, 0.14);
	box-shadow: 0 34px 70px rgba(3, 10, 24, 0.28);
}

.ethnic-proposal-visual__toolbar {
	display: flex;
	gap: 8px;
	margin-bottom: 18px;
}

.ethnic-proposal-visual__toolbar span {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.54);
}

.ethnic-proposal-visual__stack {
	position: relative;
	min-height: 460px;
}

.ethnic-proposal-visual__card {
	position: absolute;
	padding: 24px;
	border-radius: 28px;
	box-shadow: 0 24px 60px rgba(5, 14, 28, 0.22);
}

.ethnic-proposal-visual__card--brief {
	inset: 26px 92px 138px 18px;
	background: linear-gradient(180deg, #f8fbff, #eef4ff);
}

.ethnic-proposal-visual__card--upload {
	top: 148px;
	left: 0;
	width: 300px;
	background: linear-gradient(180deg, #234d39, #17372a);
	color: #ffffff;
}

.ethnic-proposal-visual__card--support {
	right: 0;
	bottom: 10px;
	width: 320px;
	background: linear-gradient(180deg, #ffffff, #eef5ff);
}

.ethnic-proposal-visual__card h2 {
	margin: 0;
	font-size: clamp(22px, 2.5vw, 28px);
	font-weight: 700;
	line-height: 1.12;
	letter-spacing: -0.04em;
}

.ethnic-proposal-visual__card--brief h2,
.ethnic-proposal-visual__card--support h2 {
	color: #16233e !important;
	-webkit-text-fill-color: #16233e;
}

.ethnic-proposal-visual__card--upload h2 {
	color: #ffffff !important;
	-webkit-text-fill-color: #ffffff;
}

.ethnic-proposal-visual__eyebrow {
	margin: 0 0 14px;
	color: #5b6f93 !important;
	-webkit-text-fill-color: #5b6f93;
	font-size: 12px;
	font-weight: 800;
	letter-spacing: 0.14em;
	line-height: 1;
	text-transform: uppercase;
}

.ethnic-proposal-visual__card--upload .ethnic-proposal-visual__eyebrow {
	color: rgba(255, 255, 255, 0.9) !important;
	-webkit-text-fill-color: rgba(255, 255, 255, 0.9);
}

.ethnic-proposal-visual__card ul {
	display: grid;
	gap: 12px;
	padding: 0;
	margin: 20px 0 0;
	list-style: none;
}

.ethnic-proposal-visual__card ul li {
	display: flex;
	align-items: center;
	gap: 10px;
	color: #4c617f !important;
	-webkit-text-fill-color: #4c617f;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.55;
}

.ethnic-proposal-visual__card ul li::before {
	content: "";
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--ethnic-proposal-accent);
	box-shadow: 0 0 0 4px rgba(235, 255, 86, 0.18);
}

.ethnic-proposal-visual__icon {
	width: 54px;
	height: 54px;
	display: inline-grid;
	place-items: center;
	margin-bottom: 14px;
	border-radius: 18px;
	background: rgba(255, 255, 255, 0.12);
	border: 1px solid rgba(255, 255, 255, 0.14);
}

.ethnic-proposal-visual__icon svg {
	width: 22px;
	height: 22px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
	color: #ffffff;
}

.ethnic-proposal-visual__upload-lines {
	display: grid;
	gap: 10px;
	margin-top: 18px;
}

.ethnic-proposal-visual__upload-lines span {
	display: block;
	height: 10px;
	border-radius: 999px;
	background: linear-gradient(90deg, #d6ff4b, #7ca4ff);
}

.ethnic-proposal-visual__upload-lines span:nth-child(1) {
	width: 90%;
}

.ethnic-proposal-visual__upload-lines span:nth-child(2) {
	width: 74%;
}

.ethnic-proposal-visual__upload-lines span:nth-child(3) {
	width: 58%;
}

.ethnic-proposal-visual__badge-row {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin-top: 18px;
}

.ethnic-proposal-visual__badge-row span {
	display: inline-flex;
	align-items: center;
	min-height: 36px;
	padding: 10px 14px;
	border-radius: 999px;
	background: rgba(77, 124, 255, 0.08);
	color: #3f5888 !important;
	-webkit-text-fill-color: #3f5888;
	font-size: 12px;
	font-weight: 800;
	letter-spacing: 0.12em;
	line-height: 1;
	text-transform: uppercase;
}

.ethnic-proposal-hero__eyebrow,
.ethnic-proposal-hero__points li span,
.ethnic-proposal-button--secondary span,
.ethnic-proposal-visual__card h2,
.ethnic-proposal-visual__card p,
.ethnic-proposal-visual__card li,
.ethnic-proposal-visual__badge-row span {
	text-shadow: none;
}

.ethnic-proposal-intro {
	display: grid;
	grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
	gap: 28px;
	align-items: start;
}

.ethnic-proposal-prose {
	display: grid;
	gap: 18px;
}

.ethnic-proposal-intro__cards,
.ethnic-proposal-trust-grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 18px;
}

.ethnic-proposal-mini-card,
.ethnic-proposal-trust-card,
.ethnic-proposal-form__section,
.ethnic-proposal-sidebar__card,
.ethnic-proposal-faq__item {
	border-radius: 28px;
	border: 1px solid var(--ethnic-proposal-border);
	background:
		linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 250, 255, 0.92)),
		var(--ethnic-proposal-surface);
	box-shadow: var(--ethnic-proposal-shadow);
}

.ethnic-proposal-mini-card,
.ethnic-proposal-trust-card {
	padding: 24px;
}

.ethnic-proposal-mini-card__icon,
.ethnic-proposal-trust-card__icon,
.ethnic-proposal-cta__panel-icon {
	width: 52px;
	height: 52px;
	display: inline-grid;
	place-items: center;
	border-radius: 18px;
	background: rgba(77, 124, 255, 0.08);
	border: 1px solid rgba(77, 124, 255, 0.14);
	color: #4162b4;
}

.ethnic-proposal-mini-card__icon svg,
.ethnic-proposal-trust-card__icon svg,
.ethnic-proposal-cta__panel-icon svg,
.ethnic-proposal-checklist svg,
.ethnic-proposal-upload__empty-icon svg {
	width: 22px;
	height: 22px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.ethnic-proposal-mini-card h3,
.ethnic-proposal-trust-card h3,
.ethnic-proposal-cta__panel h3 {
	margin: 18px 0 12px;
	color: var(--ethnic-proposal-text);
	font-size: 24px;
	font-weight: 700;
	line-height: 1.14;
	letter-spacing: -0.04em;
}

.ethnic-proposal-request {
	display: grid;
	grid-template-columns: minmax(0, 1.24fr) minmax(320px, 0.76fr);
	gap: 22px;
	align-items: start;
}

.ethnic-proposal-form {
	display: grid;
	gap: 22px;
}

.ethnic-proposal-form__states {
	display: grid;
	gap: 14px;
}

.ethnic-proposal-form__alert {
	padding: 18px 20px;
	border-radius: 22px;
	border: 1px solid transparent;
}

.ethnic-proposal-form__alert strong {
	display: block;
	margin: 0 0 6px;
	font-size: 18px;
	font-weight: 700;
}

.ethnic-proposal-form__alert--error {
	background: rgba(255, 233, 233, 0.92);
	border-color: rgba(214, 78, 78, 0.16);
}

.ethnic-proposal-form__alert--error strong,
.ethnic-proposal-form__alert--error p {
	color: #8f2121;
}

.ethnic-proposal-form__alert--success {
	background: rgba(230, 255, 238, 0.92);
	border-color: rgba(78, 156, 104, 0.18);
}

.ethnic-proposal-form__alert--success strong,
.ethnic-proposal-form__alert--success p {
	color: #1e6c3b;
}

.ethnic-proposal-form__section {
	padding: 28px;
}

.ethnic-proposal-form__section-header {
	display: grid;
	grid-template-columns: 54px minmax(0, 1fr);
	gap: 18px;
	align-items: start;
	margin-bottom: 22px;
}

.ethnic-proposal-form__step {
	display: inline-grid;
	place-items: center;
	width: 54px;
	height: 54px;
	border-radius: 18px;
	background: linear-gradient(180deg, #eff4ff, #e3ebff);
	color: #3559b8;
	font-size: 14px;
	font-weight: 800;
	letter-spacing: 0.12em;
	line-height: 1;
	text-transform: uppercase;
}

.ethnic-proposal-form__section-header h3 {
	margin: 0 0 6px;
	color: var(--ethnic-proposal-text);
	font-size: clamp(24px, 2.2vw, 30px);
	font-weight: 700;
	line-height: 1.1;
	letter-spacing: -0.04em;
}

.ethnic-proposal-form__section-header p,
.ethnic-proposal-field__help,
.ethnic-proposal-form__group-note,
.ethnic-proposal-upload__meta p,
.ethnic-proposal-submit__note,
.ethnic-proposal-sidebar__panel-note p,
.ethnic-proposal-sidebar__timeline-item p,
.ethnic-proposal-progress__meta span {
	font-size: 14px;
	line-height: 1.72;
}

.ethnic-proposal-form__grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 18px;
}

.ethnic-proposal-field {
	display: grid;
	gap: 8px;
}

.ethnic-proposal-field--full {
	grid-column: 1 / -1;
}

.ethnic-proposal-field__label,
.ethnic-proposal-upload__meta strong,
.ethnic-proposal-submit__note strong,
.ethnic-proposal-progress__meta strong {
	color: var(--ethnic-proposal-text);
	font-size: 13px;
	font-weight: 800;
	letter-spacing: 0.12em;
	line-height: 1.1;
	text-transform: uppercase;
}

.ethnic-proposal-field__label em {
	margin-left: 6px;
	color: #d45454;
	font-style: normal;
}

.ethnic-proposal-field input,
.ethnic-proposal-field select,
.ethnic-proposal-field textarea {
	width: 100%;
	min-height: 58px;
	padding: 16px 18px;
	border: 1px solid var(--ethnic-proposal-border-strong);
	border-radius: 18px;
	background: #fbfcff;
	color: var(--ethnic-proposal-text);
	font-size: 16px;
	font-weight: 500;
	line-height: 1.5;
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.64);
	transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.ethnic-proposal-field textarea {
	min-height: 142px;
	resize: vertical;
}

.ethnic-proposal-field input::placeholder,
.ethnic-proposal-field textarea::placeholder {
	color: #8a98b1;
}

.ethnic-proposal-field input:focus,
.ethnic-proposal-field select:focus,
.ethnic-proposal-field textarea:focus {
	outline: none;
	border-color: rgba(77, 124, 255, 0.36);
	box-shadow: 0 0 0 4px rgba(77, 124, 255, 0.12);
	background: #ffffff;
}

.ethnic-proposal-services {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 14px;
}

.ethnic-proposal-chip {
	position: relative;
	display: flex;
	align-items: center;
	min-height: 62px;
	padding: 16px 18px;
	border-radius: 18px;
	border: 1px solid var(--ethnic-proposal-border);
	background: #fbfcff;
	color: var(--ethnic-proposal-text);
	cursor: pointer;
	transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, background-color 0.2s ease;
}

.ethnic-proposal-chip:hover,
.ethnic-proposal-budget__card:hover {
	transform: translateY(-1px);
	box-shadow: 0 18px 34px rgba(10, 22, 45, 0.08);
}

.ethnic-proposal-chip input,
.ethnic-proposal-budget__card input {
	position: absolute;
	inset: 0;
	opacity: 0;
	pointer-events: none;
}

.ethnic-proposal-chip span {
	display: block;
	color: var(--ethnic-proposal-text);
	font-size: 15px;
	font-weight: 700;
	line-height: 1.5;
}

.ethnic-proposal-chip.is-selected,
.ethnic-proposal-chip input:checked + span,
.ethnic-proposal-budget__card.is-selected {
	border-color: rgba(77, 124, 255, 0.28);
	background: linear-gradient(180deg, rgba(77, 124, 255, 0.08), rgba(77, 124, 255, 0.04));
}

.ethnic-proposal-chip.is-selected::before,
.ethnic-proposal-budget__card.is-selected::before {
	content: "";
	position: absolute;
	top: 12px;
	right: 12px;
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--ethnic-proposal-accent);
	box-shadow: 0 0 0 5px rgba(235, 255, 86, 0.18);
}

.ethnic-proposal-budget {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 16px;
}

.ethnic-proposal-budget__card {
	position: relative;
	display: grid;
	gap: 12px;
	padding: 22px;
	border-radius: 22px;
	border: 1px solid var(--ethnic-proposal-border);
	background: #fbfcff;
	cursor: pointer;
	transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, background-color 0.2s ease;
}

.ethnic-proposal-budget__title {
	display: block;
	color: var(--ethnic-proposal-text);
	font-size: 20px;
	font-weight: 700;
	line-height: 1.18;
	letter-spacing: -0.04em;
}

.ethnic-proposal-budget__copy {
	display: block;
	color: var(--ethnic-proposal-text-soft);
	font-size: 14px;
	line-height: 1.72;
}

.ethnic-proposal-upload {
	display: grid;
	gap: 16px;
}

.ethnic-proposal-upload__dropzone {
	position: relative;
	display: grid;
	place-items: center;
	gap: 12px;
	min-height: 220px;
	padding: 28px;
	border-radius: 28px;
	border: 1px dashed rgba(77, 124, 255, 0.28);
	background:
		radial-gradient(circle at top left, rgba(235, 255, 86, 0.14), transparent 22%),
		linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(244, 248, 255, 0.96));
	text-align: center;
	cursor: pointer;
	transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.ethnic-proposal-upload__dropzone.is-dragover {
	border-color: rgba(77, 124, 255, 0.46);
	box-shadow: 0 18px 34px rgba(10, 22, 45, 0.08);
}

.ethnic-proposal-upload__dropzone input {
	position: absolute;
	inset: 0;
	opacity: 0;
	cursor: pointer;
}

.ethnic-proposal-upload__icon {
	width: 66px;
	height: 66px;
	display: inline-grid;
	place-items: center;
	border-radius: 22px;
	background: rgba(77, 124, 255, 0.08);
	border: 1px solid rgba(77, 124, 255, 0.14);
	color: #4265b9;
}

.ethnic-proposal-upload__icon svg,
.ethnic-proposal-upload__empty-icon svg {
	width: 26px;
	height: 26px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.ethnic-proposal-upload__dropzone strong,
.ethnic-proposal-upload__empty strong,
.ethnic-proposal-sidebar__timeline-item strong,
.ethnic-proposal-sidebar__panel-note strong {
	color: var(--ethnic-proposal-text);
	font-size: 18px;
	font-weight: 700;
	line-height: 1.4;
}

.ethnic-proposal-upload__dropzone span,
.ethnic-proposal-upload__empty p {
	color: var(--ethnic-proposal-text-soft);
	font-size: 15px;
	line-height: 1.7;
}

.ethnic-proposal-upload__meta {
	display: grid;
	gap: 6px;
	padding: 0 4px;
}

.ethnic-proposal-upload__state {
	padding: 20px;
	border-radius: 24px;
	border: 1px solid var(--ethnic-proposal-border);
	background: rgba(250, 252, 255, 0.84);
}

.ethnic-proposal-upload__empty {
	display: grid;
	grid-template-columns: 54px minmax(0, 1fr);
	gap: 16px;
	align-items: start;
}

.ethnic-proposal-upload__empty-icon {
	width: 54px;
	height: 54px;
	display: inline-grid;
	place-items: center;
	border-radius: 18px;
	background: rgba(77, 124, 255, 0.08);
	border: 1px solid rgba(77, 124, 255, 0.14);
	color: #4162b4;
}

.ethnic-proposal-upload__files {
	display: grid;
	gap: 12px;
	padding: 0;
	margin: 0;
	list-style: none;
}

.ethnic-proposal-upload__files li {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 16px;
	border-radius: 18px;
	background: #ffffff;
	border: 1px solid rgba(77, 124, 255, 0.08);
	color: var(--ethnic-proposal-text);
	font-size: 14px;
	font-weight: 600;
	line-height: 1.5;
}

.ethnic-proposal-upload__files li span:last-child {
	color: var(--ethnic-proposal-text-muted);
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
}

.ethnic-proposal-submit {
	display: grid;
	gap: 18px;
}

.ethnic-proposal-consent {
	display: flex;
	align-items: flex-start;
	gap: 12px;
	color: var(--ethnic-proposal-text-soft);
	font-size: 15px;
	font-weight: 500;
	line-height: 1.7;
}

.ethnic-proposal-consent input {
	width: 18px;
	height: 18px;
	margin-top: 4px;
	accent-color: #375ed1;
}

.ethnic-proposal-submit__note {
	padding: 16px 18px;
	border-radius: 18px;
	background: rgba(77, 124, 255, 0.06);
	border: 1px solid rgba(77, 124, 255, 0.08);
}

.ethnic-proposal-sidebar {
	display: grid;
	gap: 18px;
	position: sticky;
	top: 40px;
}

.ethnic-proposal-sidebar__card {
	padding: 24px;
}

.ethnic-proposal-sidebar__eyebrow {
	margin-bottom: 14px;
	border-color: rgba(77, 124, 255, 0.12);
	background: rgba(77, 124, 255, 0.08);
	color: #50698f;
}

.ethnic-proposal-sidebar__card h3 {
	margin: 0;
	color: var(--ethnic-proposal-text);
	font-size: 24px;
	font-weight: 700;
	line-height: 1.16;
	letter-spacing: -0.04em;
}

.ethnic-proposal-progress {
	display: grid;
	gap: 12px;
	margin-top: 18px;
}

.ethnic-proposal-progress__bar {
	position: relative;
	height: 12px;
	border-radius: 999px;
	background: rgba(77, 124, 255, 0.12);
	overflow: hidden;
}

.ethnic-proposal-progress__bar span {
	position: absolute;
	inset: 0 auto 0 0;
	width: 0;
	border-radius: inherit;
	background: linear-gradient(90deg, #ebff56, #7ca4ff);
	transition: width 0.25s ease;
}

.ethnic-proposal-progress__meta {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
}

.ethnic-proposal-progress__meta strong {
	font-size: 26px;
	letter-spacing: -0.04em;
}

.ethnic-proposal-progress__steps,
.ethnic-proposal-sidebar__timeline {
	display: grid;
	gap: 12px;
	padding: 0;
	margin: 18px 0 0;
}

.ethnic-proposal-progress__steps {
	list-style: none;
}

.ethnic-proposal-progress__steps li,
.ethnic-proposal-sidebar__timeline-item {
	display: grid;
	grid-template-columns: 42px minmax(0, 1fr);
	gap: 14px;
	align-items: start;
	padding: 14px 0;
	border-top: 1px solid rgba(15, 23, 42, 0.07);
}

.ethnic-proposal-progress__steps li:first-child,
.ethnic-proposal-sidebar__timeline-item:first-child {
	border-top: 0;
	padding-top: 0;
}

.ethnic-proposal-progress__steps li span,
.ethnic-proposal-sidebar__timeline-index {
	display: inline-grid;
	place-items: center;
	width: 42px;
	height: 42px;
	border-radius: 14px;
	background: rgba(77, 124, 255, 0.08);
	color: #4766a1;
	font-size: 12px;
	font-weight: 800;
	letter-spacing: 0.12em;
	line-height: 1;
	text-transform: uppercase;
}

.ethnic-proposal-progress__steps li strong {
	display: block;
	color: var(--ethnic-proposal-text);
	font-size: 16px;
	font-weight: 700;
	line-height: 1.4;
	padding-top: 10px;
}

.ethnic-proposal-progress__steps li.is-complete span {
	background: rgba(235, 255, 86, 0.2);
	color: #223314;
}

.ethnic-proposal-progress__steps li.is-complete strong {
	color: #23324c;
}

.ethnic-proposal-checklist {
	grid-template-columns: 1fr;
	gap: 12px;
	margin-top: 18px;
}

.ethnic-proposal-checklist li {
	display: grid;
	grid-template-columns: 22px minmax(0, 1fr);
	gap: 12px;
	align-items: start;
	color: var(--ethnic-proposal-text-soft);
	font-size: 15px;
	font-weight: 600;
	line-height: 1.68;
}

.ethnic-proposal-checklist li svg {
	color: #4766bf;
	margin-top: 4px;
}

.ethnic-proposal-sidebar__timeline-item strong {
	display: block;
	margin-bottom: 6px;
}

.ethnic-proposal-sidebar__panel-note {
	margin-top: 18px;
	padding: 18px;
	border-radius: 22px;
	background: rgba(77, 124, 255, 0.06);
	border: 1px solid rgba(77, 124, 255, 0.08);
}

.ethnic-proposal-trust-grid {
	grid-template-columns: repeat(4, minmax(0, 1fr));
}

.ethnic-proposal-faq {
	display: grid;
	gap: 14px;
}

.ethnic-proposal-faq__item summary {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 24px 28px;
	cursor: pointer;
	list-style: none;
	color: var(--ethnic-proposal-text);
	font-size: 22px;
	font-weight: 700;
	line-height: 1.3;
	letter-spacing: -0.04em;
}

.ethnic-proposal-faq__item summary::-webkit-details-marker {
	display: none;
}

.ethnic-proposal-faq__marker {
	position: relative;
	width: 24px;
	height: 24px;
	flex: 0 0 auto;
}

.ethnic-proposal-faq__marker::before,
.ethnic-proposal-faq__marker::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 16px;
	height: 2px;
	border-radius: 999px;
	background: #355ac2;
	transform: translate(-50%, -50%);
	transition: transform 0.2s ease, opacity 0.2s ease;
}

.ethnic-proposal-faq__marker::after {
	transform: translate(-50%, -50%) rotate(90deg);
}

.ethnic-proposal-faq__item[open] .ethnic-proposal-faq__marker::after {
	opacity: 0;
	transform: translate(-50%, -50%) rotate(90deg) scaleX(0.4);
}

.ethnic-proposal-faq__answer {
	padding: 0 28px 24px;
}

.ethnic-proposal-cta {
	display: grid;
	grid-template-columns: minmax(0, 1.04fr) minmax(320px, 0.96fr);
	gap: 24px;
	align-items: stretch;
	padding: 34px;
	border-radius: 34px;
	background:
		radial-gradient(circle at top left, rgba(235, 255, 86, 0.12), transparent 24%),
		radial-gradient(circle at top right, rgba(77, 124, 255, 0.12), transparent 26%),
		linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(246, 250, 255, 0.94));
	border: 1px solid var(--ethnic-proposal-border);
	box-shadow: var(--ethnic-proposal-shadow);
}

.ethnic-proposal-cta h2 {
	margin: 16px 0 16px;
	color: var(--ethnic-proposal-text);
	font-size: clamp(36px, 4.8vw, 62px);
	font-weight: 700;
	line-height: 0.98;
	letter-spacing: -0.06em;
	max-width: 12ch;
}

.ethnic-proposal-cta__panel {
	padding: 28px;
	border-radius: 28px;
	background:
		linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04)),
		linear-gradient(180deg, #102240, #0d1d37 58%, #0a162d);
	border: 1px solid rgba(255, 255, 255, 0.12);
	box-shadow: 0 26px 60px rgba(15, 23, 42, 0.24);
}

.ethnic-proposal-cta__panel h3 {
	color: #ffffff !important;
	-webkit-text-fill-color: #ffffff;
	margin-top: 18px;
}

.ethnic-proposal-cta__panel p,
.ethnic-proposal-checklist--light li {
	color: rgba(255, 255, 255, 0.9) !important;
	-webkit-text-fill-color: rgba(255, 255, 255, 0.9);
}

.ethnic-proposal-checklist--light li svg {
	color: var(--ethnic-proposal-accent);
}

.ethnic-proposal-cta__panel .ethnic-proposal-checklist--light li,
.ethnic-proposal-cta__panel .ethnic-proposal-checklist--light li span,
.ethnic-proposal-cta__panel .ethnic-proposal-checklist--light svg {
	text-shadow: none;
}

@media (max-width: 1200px) {
	.ethnic-proposal-hero__layout,
	.ethnic-proposal-intro,
	.ethnic-proposal-request,
	.ethnic-proposal-cta {
		grid-template-columns: 1fr;
	}

	.ethnic-proposal-hero__points,
	.ethnic-proposal-intro__cards,
	.ethnic-proposal-trust-grid,
	.ethnic-proposal-services,
	.ethnic-proposal-budget {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.ethnic-proposal-sidebar {
		position: relative;
		top: auto;
	}

	.ethnic-proposal-hero__visual {
		max-width: 760px;
	}
}

@media (max-width: 900px) {
	.ethnic-proposal-form__grid,
	.ethnic-proposal-intro__cards,
	.ethnic-proposal-trust-grid,
	.ethnic-proposal-services,
	.ethnic-proposal-budget,
	.ethnic-proposal-hero__points {
		grid-template-columns: 1fr;
	}

	.ethnic-proposal-form__section,
	.ethnic-proposal-sidebar__card,
	.ethnic-proposal-faq__item,
	.ethnic-proposal-cta,
	.ethnic-proposal-cta__panel,
	.ethnic-proposal-visual__frame {
		border-radius: 24px;
	}

	.ethnic-proposal-visual__frame {
		min-height: auto;
	}

	.ethnic-proposal-visual__stack {
		min-height: auto;
		display: grid;
		gap: 16px;
	}

	.ethnic-proposal-visual__card {
		position: relative;
		inset: auto;
		width: 100%;
	}
}

@media (max-width: 767px) {
	.ethnic-proposal-shell {
		width: min(100%, calc(100% - 24px));
	}

	.ethnic-proposal-section {
		padding: 60px 0;
	}

	.ethnic-proposal-hero {
		padding: 72px 0 64px;
	}

	.ethnic-proposal-hero__title {
		font-size: clamp(36px, 12vw, 50px);
	}

	.ethnic-proposal-heading__title,
	.ethnic-proposal-cta h2 {
		font-size: clamp(30px, 9vw, 38px);
	}

	.ethnic-proposal-button {
		width: 100%;
	}

	.ethnic-proposal-faq__item summary {
		padding: 20px 22px;
		font-size: 18px;
	}

	.ethnic-proposal-faq__answer {
		padding: 0 22px 20px;
	}

	.ethnic-proposal-form__section,
	.ethnic-proposal-sidebar__card,
	.ethnic-proposal-mini-card,
	.ethnic-proposal-trust-card {
		padding: 22px;
	}

	.ethnic-proposal-form__section-header {
		grid-template-columns: 46px 1fr;
		gap: 14px;
	}

	.ethnic-proposal-form__step {
		width: 46px;
		height: 46px;
		border-radius: 16px;
	}

	.ethnic-proposal-progress__steps li,
	.ethnic-proposal-sidebar__timeline-item,
	.ethnic-proposal-upload__empty {
		grid-template-columns: 38px 1fr;
	}

	.ethnic-proposal-progress__steps li span,
	.ethnic-proposal-sidebar__timeline-index {
		width: 38px;
		height: 38px;
		border-radius: 13px;
	}

	.ethnic-proposal-upload__empty-icon {
		width: 38px;
		height: 38px;
		border-radius: 13px;
	}
}
CSS;
	}
}

if ( ! function_exists( 'ethnic_request_proposal_page_enqueue_assets' ) ) {
	function ethnic_request_proposal_page_enqueue_assets() {
		if ( ! ethnic_request_proposal_page_is_target() ) {
			return;
		}

		$page = ethnic_request_proposal_page_get_target_page();

		if ( $page instanceof WP_Post ) {
			$handle = 'elementor-post-' . (int) $page->ID;
			wp_dequeue_style( $handle );
			wp_deregister_style( $handle );
		}
	}

	add_action( 'wp_enqueue_scripts', 'ethnic_request_proposal_page_enqueue_assets', 120 );
}

if ( ! function_exists( 'ethnic_request_proposal_page_print_head_assets' ) ) {
	function ethnic_request_proposal_page_print_head_assets() {
		if ( ! ethnic_request_proposal_page_is_target() ) {
			return;
		}

		$data = ethnic_request_proposal_page_data();
		?>
		<style id="ethnic-request-proposal-page-inline-css" type="text/css">
			<?php echo ethnic_request_proposal_page_styles(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
		</style>
		<meta name="description" content="<?php echo esc_attr( $data['metaDescription'] ); ?>" />
		<?php
	}

	add_action( 'wp_head', 'ethnic_request_proposal_page_print_head_assets', 120 );
}

if ( ! function_exists( 'ethnic_request_proposal_page_document_title' ) ) {
	function ethnic_request_proposal_page_document_title( $title ) {
		if ( ethnic_request_proposal_page_is_target() ) {
			$data = ethnic_request_proposal_page_data();

			return $data['metaTitle'];
		}

		return $title;
	}

	add_filter( 'pre_get_document_title', 'ethnic_request_proposal_page_document_title', 50 );
}

if ( ! function_exists( 'ethnic_request_proposal_page_print_footer_assets' ) ) {
	function ethnic_request_proposal_page_print_footer_assets() {
		if ( ! ethnic_request_proposal_page_is_target() ) {
			return;
		}
		?>
		<script id="ethnic-request-proposal-page-script">
			(function () {
				var form = document.getElementById('ethnicProposalForm');

				if (!form) {
					return;
				}

				var progressFill = document.querySelector('[data-progress-fill]');
				var progressPercent = document.querySelector('[data-progress-percent]');
				var progressLabel = document.querySelector('[data-progress-label]');
				var progressSteps = Array.prototype.slice.call(document.querySelectorAll('[data-progress-step]'));
				var uploadInput = document.getElementById('proposal-files');
				var uploadList = document.querySelector('[data-upload-list]');
				var uploadState = document.querySelector('[data-upload-state]');
				var uploadEmpty = uploadState ? uploadState.querySelector('.ethnic-proposal-upload__empty') : null;
				var dropzone = document.querySelector('.ethnic-proposal-upload__dropzone');
				var errorAlert = document.querySelector('[data-form-alert="error"]');
				var successAlert = document.querySelector('[data-form-alert="success"]');
				var chipInputs = Array.prototype.slice.call(form.querySelectorAll('.ethnic-proposal-chip input'));
				var budgetInputs = Array.prototype.slice.call(form.querySelectorAll('.ethnic-proposal-budget__card input'));
				var submitButton = form.querySelector('[data-submit-button]');
				var defaultSubmitLabel = submitButton ? submitButton.textContent : '';
				var errorAlertTitle = errorAlert ? errorAlert.querySelector('strong') : null;
				var errorAlertCopy = errorAlert ? errorAlert.querySelector('p') : null;
				var defaultErrorTitle = 'Please review the required fields.';
				var defaultErrorCopy = 'Complete the missing sections so the proposal request can be captured with enough project context.';

				var groupChecks = [
					{
						key: 'contact',
						fields: ['full_name', 'company_name', 'work_email']
					},
					{
						key: 'project',
						fields: ['project_title', 'project_type', 'project_overview', 'project_goals']
					},
					{
						key: 'services',
						custom: function () {
							return !!form.querySelector('input[name="required_services[]"]:checked');
						}
					},
					{
						key: 'timeline',
						fields: ['desired_start_time', 'target_delivery_timeline']
					},
					{
						key: 'budget',
						custom: function () {
							return !!form.querySelector('input[name="budget_band"]:checked');
						}
					},
					{
						key: 'upload',
						custom: function () {
							return !!(uploadInput && uploadInput.files && uploadInput.files.length);
						}
					},
					{
						key: 'submit',
						fields: ['proposal_consent']
					}
				];

				function normalizeStepKey(label) {
					return label.toLowerCase().replace(/[^a-z0-9]+/g, '-');
				}

				function fieldIsComplete(name) {
					var field = form.elements[name];

					if (!field) {
						return false;
					}

					if (field.type === 'checkbox') {
						return field.checked;
					}

					return String(field.value || '').trim() !== '';
				}

				function groupIsComplete(definition) {
					if (typeof definition.custom === 'function') {
						return definition.custom();
					}

					return definition.fields.every(fieldIsComplete);
				}

				function updateProgress() {
					var completeCount = groupChecks.filter(groupIsComplete).length;
					var total = groupChecks.length;
					var percent = Math.round((completeCount / total) * 100);

					if (progressFill) {
						progressFill.style.width = percent + '%';
					}

					if (progressPercent) {
						progressPercent.textContent = percent + '%';
					}

					if (progressLabel) {
						progressLabel.textContent = completeCount === 0 ? 'Form not started yet' : completeCount + ' of ' + total + ' key groups complete';
					}

					progressSteps.forEach(function (item, index) {
						var key = normalizeStepKey(item.getAttribute('data-progress-step') || '');
						var matching = groupChecks.find(function (group) {
							return normalizeStepKey(group.key) === key;
						});

						if (matching && groupIsComplete(matching)) {
							item.classList.add('is-complete');
						} else {
							item.classList.remove('is-complete');
						}
					});
				}

				function updateSelectionState(inputs, cardSelector) {
					inputs.forEach(function (input) {
						var card = input.closest(cardSelector);
						if (!card) {
							return;
						}

						if (input.checked) {
							card.classList.add('is-selected');
						} else {
							card.classList.remove('is-selected');
						}
					});
				}

				function humanFileSize(bytes) {
					if (!bytes) {
						return '0 KB';
					}

					var units = ['B', 'KB', 'MB', 'GB'];
					var index = 0;
					var size = bytes;

					while (size >= 1024 && index < units.length - 1) {
						size = size / 1024;
						index++;
					}

					return (index === 0 ? size : size.toFixed(size >= 10 ? 0 : 1)) + ' ' + units[index];
				}

				function updateUploadState(files) {
					if (!uploadList || !uploadState) {
						return;
					}

					if (!files || !files.length) {
						uploadList.innerHTML = '';
						uploadList.hidden = true;
						if (uploadEmpty) {
							uploadEmpty.hidden = false;
						}
						updateProgress();
						return;
					}

					uploadList.innerHTML = '';

					Array.prototype.slice.call(files).forEach(function (file) {
						var item = document.createElement('li');
						var name = document.createElement('span');
						var meta = document.createElement('span');

						name.textContent = file.name;
						meta.textContent = humanFileSize(file.size);

						item.appendChild(name);
						item.appendChild(meta);
						uploadList.appendChild(item);
					});

					uploadList.hidden = false;
					if (uploadEmpty) {
						uploadEmpty.hidden = true;
					}
					updateProgress();
				}

				function hideAlerts() {
					if (errorAlert) {
						errorAlert.hidden = true;
					}

					if (successAlert) {
						successAlert.hidden = true;
					}
				}

				function showAlert(type) {
					hideAlerts();

					if (type === 'error') {
						if (errorAlertTitle) {
							errorAlertTitle.textContent = defaultErrorTitle;
						}

						if (errorAlertCopy) {
							errorAlertCopy.textContent = defaultErrorCopy;
						}
					}

					if (type === 'error' && errorAlert) {
						errorAlert.hidden = false;
						errorAlert.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
					}

					if (type === 'success' && successAlert) {
						successAlert.hidden = false;
						successAlert.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
					}
				}

				form.addEventListener('input', updateProgress);
				form.addEventListener('change', updateProgress);

				chipInputs.forEach(function (input) {
					input.addEventListener('change', function () {
						updateSelectionState(chipInputs, '.ethnic-proposal-chip');
						updateProgress();
					});
				});

				budgetInputs.forEach(function (input) {
					input.addEventListener('change', function () {
						updateSelectionState(budgetInputs, '.ethnic-proposal-budget__card');
						updateProgress();
					});
				});

				if (uploadInput) {
					uploadInput.addEventListener('change', function () {
						updateUploadState(uploadInput.files);
					});
				}

				if (dropzone) {
					['dragenter', 'dragover'].forEach(function (eventName) {
						dropzone.addEventListener(eventName, function (event) {
							event.preventDefault();
							dropzone.classList.add('is-dragover');
						});
					});

					['dragleave', 'drop'].forEach(function (eventName) {
						dropzone.addEventListener(eventName, function (event) {
							event.preventDefault();
							dropzone.classList.remove('is-dragover');
						});
					});

					dropzone.addEventListener('drop', function (event) {
						if (!uploadInput || !event.dataTransfer || !event.dataTransfer.files) {
							return;
						}

						try {
							uploadInput.files = event.dataTransfer.files;
						} catch (error) {
							return;
						}

						updateUploadState(uploadInput.files);
					});
				}

				form.addEventListener('submit', function (event) {
					hideAlerts();

					var hasService = !!form.querySelector('input[name="required_services[]"]:checked');
					var hasBudget = !!form.querySelector('input[name="budget_band"]:checked');

					if (!form.checkValidity() || !hasService || !hasBudget) {
						event.preventDefault();
						showAlert('error');
						form.reportValidity();
						return;
					}

					if (window.ethnicRecaptcha && window.ethnicRecaptcha.enabled && !window.ethnicRecaptcha.validateForm(form)) {
						event.preventDefault();

						if (errorAlertTitle) {
							errorAlertTitle.textContent = 'Please complete the reCAPTCHA checkbox.';
						}

						if (errorAlertCopy) {
							errorAlertCopy.textContent = 'Confirm the security checkbox before submitting this proposal request.';
						}

						showAlert('error');
						return;
					}

					if (submitButton) {
						submitButton.disabled = true;
						submitButton.textContent = 'Submitting...';
					}
				});

				updateSelectionState(chipInputs, '.ethnic-proposal-chip');
				updateSelectionState(budgetInputs, '.ethnic-proposal-budget__card');
				updateUploadState(uploadInput ? uploadInput.files : null);
				updateProgress();
			})();
		</script>
		<?php
	}

	add_action( 'wp_footer', 'ethnic_request_proposal_page_print_footer_assets', 120 );
}

if ( ! function_exists( 'ethnic_request_proposal_page_replace_content' ) ) {
	function ethnic_request_proposal_page_replace_content( $content ) {
		if ( ! ethnic_request_proposal_page_is_target() || ! in_the_loop() || ! is_main_query() ) {
			return $content;
		}

		static $rendered = false;

		if ( $rendered ) {
			return $content;
		}

		$rendered = true;

		return ethnic_request_proposal_page_render();
	}

	add_filter( 'the_content', 'ethnic_request_proposal_page_replace_content', 1000 );
}