<?php
/**
 * File Path: includes/compat/compat-flatsome.php
 * Flatsome Theme (UX-themes) Compatibility -- loaded when get_template() === 'flatsome'.
 * Findings reference: PATCHES/COMPAT-WORKLOG.md -- FL-001 through FL-004.
 * @package My_Book_Showroom
 * @since   1.0.0
 */

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

/**
 * FL-001 + FL-002 -- Flatsome load-order safety bump.
 * Flatsome uses class-only selectors (max 0,2,1); mbs-compat.css wins on specificity.
 * This inline block re-asserts those rules to defeat any inline <style> blocks
 * Flatsome injects via wp_head before our linked stylesheet resolves.
 */
add_action( 'wp_enqueue_scripts', static function () {

	if ( ! wp_style_is( 'mbs-front', 'enqueued' ) ) {
		return;
	}

	$css = '
		/* FL-001 / FL-002: load-order safety bump — mbs-compat.css rules re-asserted */
		/* No !important needed: Flatsome uses class-only selectors (max 0,2,1)        */

		/* Paragraph cascade */
		.entry-content .mbs-wrapper p {
			margin: 0 0 0.75em;
			line-height: 1.6;
		}
		.entry-content .mbs-wrapper p:last-child {
			margin-bottom: 0;
		}

		/* Heading cascade */
		.entry-content .mbs-wrapper h1,
		.entry-content .mbs-wrapper h2,
		.entry-content .mbs-wrapper h3,
		.entry-content .mbs-wrapper h4,
		.entry-content .mbs-wrapper h5,
		.entry-content .mbs-wrapper h6 {
			margin: 0 0 0.5em;
			line-height: 1.3;
		}

		/* List cascade */
		.entry-content .mbs-wrapper ul,
		.entry-content .mbs-wrapper ol {
			padding: 0 0 0 1.25em;
			margin: 0 0 0.75em;
		}
		.entry-content .mbs-wrapper li {
			margin-bottom: 0.25em;
		}
		.entry-content .mbs-wrapper .mbs-per-format-meta {
			padding: 0;
			margin: 0;
			list-style: none;
		}

		/* Link color isolation */
		.entry-content .mbs-wrapper a {
			color: var(--mbs-link, #4AABB8);
		}
		.entry-content .mbs-wrapper a:hover,
		.entry-content .mbs-wrapper a:focus {
			color: var(--mbs-accent, #4AABB8);
		}

		/* Retailer buy button color restoration */
		.entry-content .mbs-wrapper a.mbs-retailer-btn {
			color: var(--mbs-button-text, #FFFFFF);
			background-color: var(--mbs-button-bg, #2C3E6B);
			text-decoration: none;
		}

		/* Format tabs */
		.entry-content .mbs-wrapper a.mbs-format-tab {
			text-decoration: none;
		}

		/* Image containment */
		.entry-content .mbs-wrapper img {
			border: 0 none;
			box-shadow: none;
			float: none;
			margin: 0;
			vertical-align: middle;
		}
	';

	wp_add_inline_style( 'mbs-front', $css );

}, 99 );

/**
 * FL-004 note -- UX Builder text elements and .entry-content parent. [AI]
 * If MBS shortcodes in a UX Builder text element lose styling, verify whether
 * .entry-content is absent and add a parallel scope per compat-divi.php pattern.
 * Full analysis in PATCHES/COMPAT-WORKLOG.md -- FL-004.
 */
