package com.realnet.OpenAi.Services;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class HtmlBuilder4 {

	public static String buildHtml(Object node) {
		if (node instanceof Map) {
			Map<String, Object> map = (Map<String, Object>) node;

			// Handle raw section container
			if (!map.containsKey("type") && !map.containsKey("tag")) {
				StringBuilder html = new StringBuilder();
				for (Map.Entry<String, Object> entry : map.entrySet()) {
					String sectionName = entry.getKey();
					Object sectionContent = entry.getValue();

					if ("teamSlider".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderTeamSlider((Map<String, Object>) sectionContent));
						continue;
					}

					if ("teamSectionTemplate".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderTeamSectionTemplate((Map<String, Object>) sectionContent));
						continue;
					}

					if ("teamSection".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderTeamSection((Map<String, Object>) sectionContent));
						continue;
					}

					if ("logoGuidelines".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderLogoGuidelines((Map<String, Object>) sectionContent));
						continue;
					}

					if ("logoGrid".equalsIgnoreCase(sectionName) && sectionContent instanceof List) {
						html.append(renderLogoGrid((List<Map<String, Object>>) sectionContent));
						continue;
					}

					if ("brandGuideline".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderBrandGuideline((Map<String, Object>) sectionContent));
						continue;
					}

					if ("logoShowcase".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderLogoShowcase((Map<String, Object>) sectionContent));
						continue;
					}

					if ("logoCloud".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderLogoCloud((Map<String, Object>) sectionContent));
						continue;
					}

					if ("ecommerceFAQs".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderEcommerceFAQs((Map<String, Object>) sectionContent));
						continue;
					}

					if ("dashboardLayout".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderDashboardLayout((Map<String, Object>) sectionContent));
						continue;
					}

					if ("FAQIllustratedSection".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderFaqIllustrated((Map<String, Object>) sectionContent));
						continue;
					}

					if ("FAQSection".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderFaqSection((Map<String, Object>) sectionContent));
						continue;
					}
					if ("FAQTwoColumn".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderFaqTwoColumn((Map<String, Object>) sectionContent));
						continue;
					}

					if ("TestimonialLanding".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderTestimonialLanding((Map<String, Object>) sectionContent));
						continue;
					}

					if ("ClientTestimonialSection".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderClientTestimonial((Map<String, Object>) sectionContent));
						continue;
					}
					if ("TestimonialSection".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderSimpleTestimonial((Map<String, Object>) sectionContent));
						continue;
					}

					if ("SubSection".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderSubSectionCentered((Map<String, Object>) sectionContent));
						continue;
					}
					if ("HeroSection".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						Map<String, Object> heroMap = (Map<String, Object>) sectionContent;

						if ("centered".equalsIgnoreCase(getString(heroMap, "layout", ""))
								&& heroMap.containsKey("artwork")) {
							html.append(renderHeroCenteredWithArt(heroMap));
							continue;
						}
						if ("left-text-right-cards".equalsIgnoreCase(getString(heroMap, "layout", ""))) {
							html.append(renderHeroLeftCards(heroMap));
							continue;
						}
						// Smart internal layout-based routing to correct renderer
						String layout = getString(heroMap, "layout", "").toLowerCase();

						if (layout.equals("two-column") || heroMap.containsKey("leftColumn")) {
							html.append(renderTwoColumnHeroSection(heroMap));
						} else if (layout.equals("centered") || heroMap.containsKey("heading")) {
							html.append(renderCenteredHeroSection(heroMap));
						} else {
							// fallback to older generic renderHeroSection
							html.append(renderHeroSection(heroMap));
						}
						continue;
					}

					if ("Blog".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderBlogCardSection((Map<String, Object>) sectionContent));
						continue;
					}

					if ("blogPage".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderBlogPage((Map<String, Object>) sectionContent));
						continue;
					}

					if ("blogPreviewSection".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderBlogPreviewSection((Map<String, Object>) sectionContent));
						continue;
					}
					if ("blogHomePage".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderBlogHomePage((Map<String, Object>) sectionContent));
						continue;
					}

					if ("blogListSection".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderBlogListSection((Map<String, Object>) sectionContent));
						continue;
					}

					if ("ContactSection".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderContactSection((Map<String, Object>) sectionContent));
						continue;
					}

					if ("Navbar".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderNavbarBlock((Map<String, Object>) sectionContent));
						continue;
					}
					if ("Footer".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						Map<String, Object> footerMap = (Map<String, Object>) sectionContent;

						// Smart switch based on keys like 'columns', 'topBar', 'bottom'
						if (footerMap.containsKey("columns") || footerMap.containsKey("topBar")
								|| footerMap.containsKey("bottom")) {
							html.append(renderMdBootstrapFooter(footerMap));
						} else if (footerMap.containsKey("linkColumns") || footerMap.containsKey("socialIcons")) {
							html.append(renderCompactFooter(footerMap));
						} else {
							html.append(renderFooterBlock(footerMap));
						}
						continue;
					}
					if ("how-to-blog-post".equalsIgnoreCase(getString(map, "type", ""))) {
						html.append(renderHowToBlogPost(map));
						return html.toString();
					}

					if ("blogThumbnailGrid".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderBlogThumbnailGrid((Map<String, Object>) sectionContent));
						continue;
					}
					if ("blogSection".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderBlogSection((Map<String, Object>) sectionContent));
						continue;
					}
					if ("articlePage".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderArticlePage((Map<String, Object>) sectionContent));
						continue;
					}
					if ("templateLibrary".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderTemplateLibrary((Map<String, Object>) sectionContent));
						continue;
					}
					if ("blogHeader".equalsIgnoreCase(sectionName) && sectionContent instanceof Map) {
						html.append(renderBlogHeader((Map<String, Object>) sectionContent));
						continue;
					}

					// Wrap each section in a <section> tag with class derived from key
					html.append("<section class=\"").append(sectionName.toLowerCase().replace(" ", "-")).append("\">");

					html.append(buildHtml(sectionContent));

					html.append("</section>");
				}
				return html.toString();
			}
			// Check if a universal TYPE_RENDERER exists for this block
			String type = getString(map, "type", "");
			if (TYPE_RENDERERS.containsKey(type.toLowerCase())) {
				return TYPE_RENDERERS.get(type.toLowerCase()).apply(map);
			}
			// Normal map block
			return renderFromMap(map);
		} else if (node instanceof List) {
			return renderFromList((List<Object>) node);
		} else if (node != null) {
			return node.toString();
		} else {
			return "";
		}
	}

	private static final Map<String, String> TYPE_TAG_MAP = new HashMap<>();
	static {
		TYPE_TAG_MAP.put("navbar", "nav");
		TYPE_TAG_MAP.put("footer", "footer");
		TYPE_TAG_MAP.put("article", "article");
		TYPE_TAG_MAP.put("header", "header");
		TYPE_TAG_MAP.put("logo", "div");
		TYPE_TAG_MAP.put("nav", "nav");
		TYPE_TAG_MAP.put("link", "a");
		TYPE_TAG_MAP.put("button", "button");
		TYPE_TAG_MAP.put("span", "span");
		TYPE_TAG_MAP.put("img", "img"); // already supported as self-closing
		TYPE_TAG_MAP.put("social-icons", "div");
		TYPE_TAG_MAP.put("icon", "div");
		TYPE_TAG_MAP.put("text", "span"); // or "p" depending on your choice

		// add more if needed
	}
	private static final Map<String, Function<Map<String, Object>, String>> TYPE_RENDERERS = new HashMap<>();

	static {
		// Blog Related
		TYPE_RENDERERS.put("blog-list", HtmlBuilder4::renderBlogList);
		TYPE_RENDERERS.put("blog-featured", HtmlBuilder4::renderBlogFeatured);
		TYPE_RENDERERS.put("blog-author-bio", HtmlBuilder4::renderBlogAuthorBio);
		TYPE_RENDERERS.put("newsletter-signup", HtmlBuilder4::renderNewsletterSignup);
		TYPE_RENDERERS.put("blog-categories", HtmlBuilder4::renderBlogCategories);
		TYPE_RENDERERS.put("how-to-blog-post", HtmlBuilder4::renderHowToBlogPost);

		// Media
		TYPE_RENDERERS.put("video-section", HtmlBuilder4::renderVideoSection);
		TYPE_RENDERERS.put("image-gallery", HtmlBuilder4::renderImageGallery);
		TYPE_RENDERERS.put("testimonial-carousel", HtmlBuilder4::renderTestimonialCarousel);
		TYPE_RENDERERS.put("brand-logos", HtmlBuilder4::renderBrandLogos);

		// Features
		TYPE_RENDERERS.put("feature-grid", HtmlBuilder4::renderFeatureGrid);
		TYPE_RENDERERS.put("feature-carousel", HtmlBuilder4::renderFeatureCarousel);
		TYPE_RENDERERS.put("feature-with-image", HtmlBuilder4::renderFeatureWithImage);
		TYPE_RENDERERS.put("feature-numbered-steps", HtmlBuilder4::renderFeatureNumberedSteps);
		TYPE_RENDERERS.put("feature-section", HtmlBuilder4::renderFeatureAuto);
		TYPE_RENDERERS.put("section-centered-card-grid", HtmlBuilder4::renderCenteredCardGrid);
		TYPE_RENDERERS.put("feature-card-list", HtmlBuilder4::renderFeatureCardList);

		// Interactive
		TYPE_RENDERERS.put("faq-accordion", HtmlBuilder4::renderFaqAccordion);
		TYPE_RENDERERS.put("tabbed-section", HtmlBuilder4::renderTabbedSection);
		TYPE_RENDERERS.put("counter-stats", HtmlBuilder4::renderCounterStats);
		TYPE_RENDERERS.put("progress-bars", HtmlBuilder4::renderProgressBars);

		// Marketing
		TYPE_RENDERERS.put("call-to-action", HtmlBuilder4::renderCallToAction);
		TYPE_RENDERERS.put("download-app", HtmlBuilder4::renderDownloadApp);
		TYPE_RENDERERS.put("lead-magnet", HtmlBuilder4::renderLeadMagnet);
		TYPE_RENDERERS.put("promo-banner", HtmlBuilder4::renderPromoBanner);

		// Team
		TYPE_RENDERERS.put("team-grid", HtmlBuilder4::renderTeamGrid);
		TYPE_RENDERERS.put("team-profile-list", HtmlBuilder4::renderTeamProfileList);
		TYPE_RENDERERS.put("company-timeline", HtmlBuilder4::renderCompanyTimeline);
		TYPE_RENDERERS.put("values-section", HtmlBuilder4::renderValuesSection);

		// Pricing
		TYPE_RENDERERS.put("pricing-cards", HtmlBuilder4::renderPricingCards);
		TYPE_RENDERERS.put("pricing-comparison", HtmlBuilder4::renderPricingComparison);

		// Contact
		TYPE_RENDERERS.put("contact-form", HtmlBuilder4::renderContactForm);
		TYPE_RENDERERS.put("contact-map", HtmlBuilder4::renderContactMap);
		TYPE_RENDERERS.put("contact-grid", HtmlBuilder4::renderContactGrid);
		TYPE_RENDERERS.put("contactformsection", HtmlBuilder4::renderContactFormSection);
		TYPE_RENDERERS.put("contactinfosection", HtmlBuilder4::renderContactInfoSection);
		TYPE_RENDERERS.put("contactsplitsection", HtmlBuilder4::renderContactSplitSection);
		TYPE_RENDERERS.put("contactpage", HtmlBuilder4::renderContactPage);
		TYPE_RENDERERS.put("contactussection", HtmlBuilder4::renderContactUsSection);

		// Footer
		TYPE_RENDERERS.put("footer-minimal", HtmlBuilder4::renderFooterMinimal);
		TYPE_RENDERERS.put("footer-centered", HtmlBuilder4::renderFooterCentered);
		TYPE_RENDERERS.put("footer-columns", HtmlBuilder4::renderFooterColumns);

//		Subscription
		TYPE_RENDERERS.put("subscription-form", HtmlBuilder4::renderSubscriptionForm);
		TYPE_RENDERERS.put("cta-block", HtmlBuilder4::renderCtaBlock);
		TYPE_RENDERERS.put("cta-gradient", HtmlBuilder4::renderCtaGradientSection);
		TYPE_RENDERERS.put("contact-signup", HtmlBuilder4::renderContactSignupSection);
		TYPE_RENDERERS.put("hero-banner", HtmlBuilder4::renderHeroBanner);

//       Pricing

		TYPE_RENDERERS.put("pricing-section", HtmlBuilder4::renderPricingSection);
		TYPE_RENDERERS.put("pricingsectiondark", HtmlBuilder4::renderPricingSectionDark);
		TYPE_RENDERERS.put("pricingsection", HtmlBuilder4::renderPricingHubPlans);
		TYPE_RENDERERS.put("pricingsection", HtmlBuilder4::renderTogglePricingSection);
		TYPE_RENDERERS.put("singleplansection", HtmlBuilder4::renderSinglePlanSection);

		// Utility Elements
		TYPE_RENDERERS.put("icon-button", HtmlBuilder4::renderIconButton);
		TYPE_RENDERERS.put("label", HtmlBuilder4::renderLabel);
		TYPE_RENDERERS.put("badge", HtmlBuilder4::renderBadge);
		TYPE_RENDERERS.put("rating-stars", HtmlBuilder4::renderRatingStars);
		TYPE_RENDERERS.put("classic-list-post", HtmlBuilder4::renderClassicListPost);
		TYPE_RENDERERS.put("list-post", HtmlBuilder4::renderListPost);
		TYPE_RENDERERS.put("perfect-blog-post", HtmlBuilder4::renderPerfectBlogPost);
		TYPE_RENDERERS.put("blog-thumbnail-grid", HtmlBuilder4::renderBlogThumbnailGrid);
		TYPE_RENDERERS.put("teamShowcase", HtmlBuilder4::renderTeamShowcase);
		TYPE_RENDERERS.put("herosection", HtmlBuilder4::renderHeroCenteredHeadingSplit);

		TYPE_RENDERERS.put("header", HtmlBuilder4::renderSmartHeader);
		TYPE_RENDERERS.put("centered-section-with-image", HtmlBuilder4::renderCenteredSectionWithImage);

		TYPE_RENDERERS.put("Header Section", HtmlBuilder4::renderHeaderSection);
		TYPE_RENDERERS.put("herosection", HtmlBuilder4::renderSmartHeroSection);
		TYPE_RENDERERS.put("hero-section", HtmlBuilder4::renderSmartHeroSection);

		TYPE_RENDERERS.put("page", (node) -> buildHtml(node.get("children")));
		TYPE_RENDERERS.put("heading", (node) -> "<h1 class=\"hero-heading\" ref=\"" + get(node, "ref") + "\">"
				+ get(node, "content") + "</h1>");
		TYPE_RENDERERS.put("paragraph", (node) -> "<p class=\"hero-paragraph\" ref=\"" + get(node, "ref") + "\">"
				+ get(node, "content") + "</p>");
		TYPE_RENDERERS.put("button-group", (node) -> wrapTag("div", "button-group", node));
		TYPE_RENDERERS.put("image-grid", (node) -> wrapTag("div", "image-grid", node));
		TYPE_RENDERERS.put("image-tile", (node) -> "<div class=\"image-tile\" ref=\"" + get(node, "ref")
				+ "\"><img src=\"" + get(node, "content") + "\" alt=\"image\"/></div>");
		TYPE_RENDERERS.put("logo",
				(node) -> "<div class=\"logo-1\" ref=\"" + get(node, "ref") + "\">" + get(node, "content") + "</div>");

		TYPE_RENDERERS.put("nav", (node) -> {
			StringBuilder b = new StringBuilder();
			b.append("<ul class=\"nav-1\" ref=\"").append(get(node, "ref")).append("\">");
			for (Object link : (List<?>) node.get("children")) {
				Map<String, Object> l = (Map<String, Object>) link;
				b.append("<li><a href=\"#\">").append(get(l, "content")).append("</a></li>");
			}
			b.append("</ul>");
			return b.toString();
		});
		TYPE_RENDERERS.put("link", (node) -> ""); // handled above in nav
		TYPE_RENDERERS.put("button", (node) -> "<button class=\"join-btn\" ref=\"" + get(node, "ref") + "\">"
				+ get(node, "content") + "</button>");

	}

	private static String wrapTag(String tag, String className, Map<String, Object> node) {
		StringBuilder html = new StringBuilder();
		html.append("<").append(tag);
		if (className != null) {
			html.append(" class=\"").append(className).append("\"");
		}
		html.append(">");

		if (node.containsKey("children")) {
			List<Map<String, Object>> children = (List<Map<String, Object>>) node.get("children");
			for (Map<String, Object> child : children) {
				html.append(buildHtml(child)); // ✅ Use universal method
			}
		}

		html.append("</").append(tag).append(">");
		return html.toString();
	}

	private static String get(Map<String, Object> map, String key) {
		Object val = map.get(key);
		return val instanceof String ? (String) val : "";
	}

	public static String get(Map<String, Object> map, String key, String defaultValue) {
		Object value = map.get(key);
		return value != null ? value.toString() : defaultValue;
	}

	@SuppressWarnings("unchecked")
	public static List<Map<String, Object>> getList(Map<String, Object> map, String key) {
		Object value = map.get(key);
		if (value instanceof List) {
			return (List<Map<String, Object>>) value;
		}
		return Collections.emptyList();
	}

	@SuppressWarnings("unchecked")
	public static List<String> getStringList(Map<String, Object> map, String key) {
		Object value = map.get(key);
		if (value instanceof List<?>) {
			return ((List<?>) value).stream().filter(String.class::isInstance).map(String.class::cast)
					.collect(Collectors.toList());
		}
		return Collections.emptyList();
	}

	@SuppressWarnings("unchecked")
	public static Map<String, Object> getMap(Map<String, Object> map, String key) {
		Object value = map.get(key);
		if (value instanceof Map) {
			return (Map<String, Object>) value;
		}
		return Collections.emptyMap();
	}

	// ---------------- Placeholder Functions ----------------
	private static String renderBlogList(Map<String, Object> node) {
		return "<section class='blog-list'>Blog List Placeholder</section>";
	}

	private static String renderBlogFeatured(Map<String, Object> node) {
		return "<section class='blog-featured'>Featured Blog</section>";
	}

	private static String renderBlogAuthorBio(Map<String, Object> node) {
		return "<div class='blog-author'>Author Bio</div>";
	}

	private static String renderNewsletterSignup(Map<String, Object> node) {
		return "<div class='newsletter'>Newsletter Signup</div>";
	}

	private static String renderBlogCategories(Map<String, Object> node) {
		return "<div class='blog-categories'>Categories</div>";
	}

	private static String renderVideoSection(Map<String, Object> node) {
		return "<section class='video-section'>Video Section</section>";
	}

	private static String renderImageGallery(Map<String, Object> node) {
		return "<div class='gallery'>Image Gallery</div>";
	}

	private static String renderPricingSectionDark(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"pricing-section-dark\">");

		html.append("<div class=\"badge\">").append(get(data, "badge")).append("</div>");
		html.append("<h2 class=\"title\">").append(get(data, "title")).append("</h2>");
		html.append("<p class=\"description\">").append(get(data, "description")).append("</p>");

		html.append("<div class=\"card-grid\">");
		List<Map<String, Object>> cards = getList(data, "cards");
		for (Map<String, Object> card : cards) {
			String cardClass = "pricing-card" + (getBoolean(card, "highlight") ? " highlight" : "");
			html.append("<div class=\"").append(cardClass).append("\">");
			html.append("<div class=\"badge\">").append(get(card, "badge")).append("</div>");
			html.append("<h3 class=\"price\">").append(get(card, "price")).append("</h3>");
			html.append("<ul>");
			List<String> features = (List<String>) card.get("features");
			for (String feature : features) {
				html.append("<li>").append(feature).append("</li>");
			}
			html.append("</ul>");
			Map<String, Object> btn = getMap(card, "button");
			String btnClass = "filled";
			if ("outline".equals(btn.get("style")))
				btnClass = "outline";
			else if ("light".equals(btn.get("style")))
				btnClass = "light";

			html.append("<button class=\"").append(btnClass).append("\">").append(get(btn, "label"))
					.append("</button>");

			html.append("</div>");
		}
		html.append("</div></section>");
		return html.toString();
	}

	private static String renderSinglePlanSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"pricing-single-plan\">");

		// Header
		html.append("<div class=\"pricing-header\">").append("<h2 class=\"pricing-title\">")
				.append(getText(data, "title")).append("</h2>").append("<p class=\"pricing-subtitle\">")
				.append(getText(data, "subtitle")).append("</p>").append("</div>");

		// Features
		List<Map<String, Object>> features = getList(data, "features");
		html.append("<div class=\"features-grid\">");
		for (Map<String, Object> feature : features) {
			html.append("<div class=\"feature-item\">").append("<span class=\"feature-icon\">")
					.append(getText(feature, "icon")).append("</span>").append("<h3 class=\"feature-title\">")
					.append(getText(feature, "title")).append("</h3>").append("<p class=\"feature-description\">")
					.append(getText(feature, "description")).append("</p>").append("</div>");
		}
		html.append("</div>");

		// Plan Card
		Map<String, Object> planCard = getMap(data, "planCard");
		Map<String, Object> cta = getMap(planCard, "cta");
		html.append("<div class=\"plan-card\">").append("<h3 class=\"plan-title\">").append(getText(planCard, "title"))
				.append("</h3>").append("<p class=\"plan-price\">").append(getText(planCard, "price")).append(" / ")
				.append(getText(planCard, "frequency")).append("</p>").append("<p class=\"plan-description\">")
				.append(getText(planCard, "description")).append("</p>").append("<a href=\"#\" class=\"btn-filled\">")
				.append(getText(cta, "label")).append("</a>").append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderTogglePricingSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"pricing-section\">");

		html.append("<div class=\"pricing-header\">").append("<h2>").append(get(data, "title")).append("</h2>")
				.append("<p>").append(get(data, "subtitle")).append("</p>").append("</div>");

		Map<String, Object> toggle = getMap(data, "toggle");
		List<String> options = getStringList(toggle, "options");
		String def = get(toggle, "default");

		html.append("<div class=\"pricing-toggle\">");
		for (String option : options) {
			String active = option.equalsIgnoreCase(def) ? "active" : "";
			html.append("<button class=\"" + active + "\">").append(option).append("</button>");
		}
		html.append("</div>");

		html.append("<div class=\"pricing-cards\">");
		List<Map<String, Object>> plans = getList(data, "plans");
		for (Map<String, Object> plan : plans) {
			boolean highlight = getBoolean(plan, "highlight");
			html.append("<div class=\"pricing-card ").append(highlight ? "highlight" : "").append("\">").append("<h3>")
					.append(get(plan, "name")).append("</h3>").append("<div class=\"price\">")
					.append(get(plan, "price")).append("</div>").append("<div class=\"savings\">")
					.append(get(plan, "savings")).append("</div>").append("<div class=\"bonus\">")
					.append(get(plan, "bonus")).append("</div>").append("<ul>");
			List<String> features = getStringList(plan, "features");
			for (String feat : features) {
				html.append("<li>").append(feat).append("</li>");
			}
			html.append("</ul>").append("<button>").append(get(plan, "buttonLabel")).append("</button>")
					.append("</div>");
		}
		html.append("</div></section>");

		return html.toString();
	}

	private static String renderPricingHubPlans(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		Map<String, Object> header = getMap(data, "header");
		html.append("<section class=\"pricing-section\">");

		html.append("<div class=\"pricing-header\">").append("<h2>").append(get(header, "title")).append("</h2>")
				.append("<p>").append(get(header, "subtitle")).append("</p>").append("</div>");

		List<String> tabs = (List<String>) data.get("tabs");
		if (tabs != null && !tabs.isEmpty()) {
			html.append("<div class=\"pricing-tabs\">");
			for (String tab : tabs) {
				html.append("<div class=\"pricing-tab\">").append(tab).append("</div>");
			}
			html.append("</div>");
		}

		Map<String, Object> hub = getMap(data, "hub");
		html.append("<div class=\"pricing-hub\">").append("<h3>").append(get(hub, "name")).append("</h3>").append("<p>")
				.append(get(hub, "description")).append("</p>").append("<a href=\"#\">").append(get(hub, "link"))
				.append("</a>").append("</div>");

		html.append("<div class=\"pricing-plans\">");
		List<Map<String, Object>> plans = getList(data, "plans");
		for (Map<String, Object> plan : plans) {
			html.append("<div class=\"pricing-card\">").append("<h4>").append(get(plan, "name")).append("</h4>")
					.append("<p>").append(get(plan, "priceMonthly")).append(" / ").append(get(plan, "priceYearly"))
					.append("</p>").append("<p>Contacts: ").append(get(plan, "contacts")).append("</p>").append("<p>")
					.append(get(plan, "notes")).append("</p>").append("<button>").append(get(plan, "button"))
					.append("</button>").append("</div>");
		}
		html.append("</div></section>");

		return html.toString();
	}

	public static boolean getBoolean(Map<String, Object> data, String key) {
		Object value = data.get(key);
		return value instanceof Boolean ? (Boolean) value : false;
	}

	private static String renderPricingSection(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"pricing-section\">");

		sb.append("<p class=\"hero-label\">").append(getText(data, "tagline.text")).append("</p>");
		sb.append("<h2 class=\"hero-heading\">").append(getText(data, "title.text")).append("</h2>");
		sb.append("<p class=\"hero-description\">").append(getText(data, "description.text")).append("</p>");

		sb.append("<div class=\"pricing-cards\">");
		List<Map<String, Object>> cards = getList(data, "cards");
		for (Map<String, Object> card : cards) {
			sb.append("<div class=\"").append(card.get("class")).append("\">");

			sb.append("<h3>").append(card.get("plan")).append("</h3>");
			sb.append("<p class=\"price\">").append(card.get("monthly")).append(" / mo</p>");
			sb.append("<p class=\"price\">").append(card.get("yearly")).append(" / yr</p>");

			sb.append("<ul>");
			List<String> features = (List<String>) card.get("features");
			for (String feature : features) {
				sb.append("<li>").append(feature).append("</li>");
			}
			sb.append("</ul>");

			Map<String, Object> button = getMap(card, "button");
			sb.append("<a href=\"#\" class=\"").append(button.get("class")).append("\">").append(button.get("label"))
					.append("</a>");

			sb.append("</div>");
		}
		sb.append("</div></section>");
		return sb.toString();
	}

	@SuppressWarnings("unchecked")
	public static String getText(Map<String, Object> data, String path) {
		String[] keys = path.split("\\.");
		Object current = data;
		for (String key : keys) {
			if (current instanceof Map) {
				current = ((Map<String, Object>) current).get(key);
			} else {
				return ""; // return blank if path breaks
			}
		}
		return current != null ? current.toString() : "";
	}

	private static String renderHeroBanner(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"hero-banner\">");

		Map<String, Object> headline = getMap(data, "headline");
		Map<String, Object> subheading = getMap(data, "subheading");
		Map<String, Object> button = getMap(data, "ctaButton");
		List<Map<String, Object>> images = getList(data, "decorativeImages");

		sb.append("<h1 class=\"").append(headline.get("class")).append("\">").append(headline.get("text"))
				.append("</h1>");

		sb.append("<p class=\"").append(subheading.get("class")).append("\">").append(subheading.get("text"))
				.append("</p>");

		sb.append("<a class=\"").append(button.get("class")).append("\" href=\"#\">").append(button.get("text"))
				.append("</a>");

		for (Map<String, Object> img : images) {
			sb.append("<img class=\"").append(img.get("class")).append("\" src=\"").append(img.get("src"))
					.append("\" style=\"width:").append(img.get("size")).append(";\" alt=\"decorative\" />");
		}

		sb.append("</section>");
		return sb.toString();
	}

	private static String renderContactSignupSection(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"contact-signup-section\">");

		Map<String, Object> left = getMap(data, "left");
		Map<String, Object> heading = getMap(left, "heading");
		Map<String, Object> desc = getMap(left, "description");

		sb.append("<div>");
		sb.append("<h2 class=\"").append(heading.get("class")).append("\">").append(heading.get("text"))
				.append("</h2>");
		sb.append("<p class=\"").append(desc.get("class")).append("\">").append(desc.get("text")).append("</p>");
		sb.append("</div>");

		Map<String, Object> right = getMap(data, "right");
		Map<String, Object> form = getMap(right, "form");
		List<Map<String, Object>> fields = getList(form, "fields");
		Map<String, Object> button = getMap(form, "button");

		sb.append("<form class=\"contact-form\">");
		for (Map<String, Object> field : fields) {
			sb.append("<input type=\"").append(field.get("type")).append("\" name=\"").append(field.get("name"))
					.append("\" placeholder=\"").append(field.get("placeholder")).append("\" />");
		}
		sb.append("<button class=\"").append(button.get("class")).append("\">").append(button.get("label"))
				.append("</button>");
		sb.append("</form>");

		sb.append("</section>");
		return sb.toString();
	}

	private static String renderCtaGradientSection(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"cta-gradient-section\">");

		Map<String, Object> title = getMap(data, "title");
		sb.append("<h2 class=\"").append(title.get("class")).append("\">").append(title.get("text")).append("</h2>");

		Map<String, Object> desc = getMap(data, "description");
		sb.append("<p class=\"").append(desc.get("class")).append("\">").append(desc.get("text")).append("</p>");

		Map<String, Object> button = getMap(data, "button");
		sb.append("<a href=\"#\" class=\"").append(button.get("class")).append("\">").append(button.get("label"))
				.append("</a>");

		sb.append("</section>");
		return sb.toString();
	}

	private static String renderCtaBlock(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"cta-section\">");

		// Heading
		Map<String, Object> heading = getMap(data, "heading");
		sb.append("<h2 class=\"").append(heading.get("class")).append("\">").append(heading.get("text"))
				.append("</h2>");

		// Description
		Map<String, Object> description = getMap(data, "description");
		sb.append("<p class=\"").append(description.get("class")).append("\">").append(description.get("text"))
				.append("</p>");

		// Buttons
		List<Map<String, Object>> buttons = getList(data, "buttons");
		sb.append("<div class=\"cta-buttons\">");
		for (Map<String, Object> button : buttons) {
			sb.append("<a href=\"#\" class=\"").append(button.get("class")).append("\">").append(button.get("label"))
					.append("</a>");
		}
		sb.append("</div>");

		sb.append("</section>");
		return sb.toString();
	}

	private static String renderSubscriptionForm(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"subscription-section\">");

		// Left side: Heading + Description
		sb.append("<div>");
		sb.append("<h2 class=\"subscription-heading\">").append(getMap(data, "heading").get("text")).append("</h2>");
		sb.append("<p class=\"subscription-description\">").append(getMap(data, "description").get("text"))
				.append("</p>");
		sb.append("</div>");

		// Right side: Form
		sb.append("<form class=\"subscription-form\">");

		List<Map<String, Object>> fields = getList(getMap(data, "form"), "fields");
		for (Map<String, Object> field : fields) {
			sb.append("<input type=\"").append(field.get("type")).append("\" name=\"").append(field.get("name"))
					.append("\" placeholder=\"").append(field.get("placeholder")).append("\" class=\"form-input\"/>");
		}

		Map<String, Object> button = getMap(getMap(data, "form"), "button");
		sb.append("<button class=\"form-submit\">").append(button.get("label")).append("</button>");

		// Disclaimer
		Map<String, Object> disclaimer = getMap(getMap(data, "form"), "disclaimer");
		Map<String, Object> link = getMap(disclaimer, "link");
		sb.append("<p class=\"disclaimer\">").append(disclaimer.get("text")).append(" <a href=\"")
				.append(link.get("href")).append("\" class=\"link-text\">").append(link.get("label"))
				.append("</a></p>");

		sb.append("</form>");
		sb.append("</section>");
		return sb.toString();
	}

	private static String renderFeatureCardList(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();

		sb.append("<section class=\"feature-list-section\">");

		// Heading
		Map<String, Object> heading = getMap(data, "heading");
		sb.append("<h2 class=\"feature-heading\">").append(get(heading, "text")).append("</h2>");

		// Features grid
		List<Map<String, Object>> features = getList(data, "features");
		sb.append("<div class=\"feature-list-grid\">");

		for (Map<String, Object> feature : features) {
			sb.append("<div class=\"feature-card\">");

			// Icon
			Map<String, Object> icon = getMap(feature, "icon");
			sb.append("<img src=\"").append(get(icon, "src")).append("\" alt=\"").append(get(icon, "alt"))
					.append("\"/>");

			// Title
			sb.append("<h4>").append(get(feature, "title")).append("</h4>");

			// Description
			sb.append("<p>").append(get(feature, "description")).append("</p>");

			// Button
			Map<String, Object> button = getMap(feature, "button");
			String arrow = Boolean.TRUE.equals(button.get("arrow")) ? " →" : "";
			sb.append("<button class=\"text-button\">").append(get(button, "label")).append(arrow).append("</button>");

			sb.append("</div>");
		}

		sb.append("</div></section>");
		return sb.toString();
	}

	private static String renderTestimonialCarousel(Map<String, Object> node) {
		return "<div class='testimonial-carousel'>Testimonials</div>";
	}

	private static String renderBrandLogos(Map<String, Object> node) {
		return "<div class='brand-logos'>Brand Logos</div>";
	}

	private static String renderCenteredCardGrid(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"feature-grid-section\">");

		sb.append(p("hero-label", get(data, "tagline", "text")));
		sb.append(h("h2", "hero-heading", get(data, "heading", "text")));
		sb.append(p("hero-description", get(data, "description", "text")));

		List<Map<String, Object>> cards = getList(data, "cards");
		if (!cards.isEmpty()) {
			sb.append("<div class=\"feature-grid\">");
			for (Map<String, Object> card : cards) {
				sb.append("<div class=\"feature-card\">");
				Map<String, Object> image = getMap(card, "image");
				sb.append(img("card-img", image.get("src"), image.get("alt")));
				sb.append(h("h3", "card-title", card.get("title")));
				sb.append(p("card-description", card.get("description")));
				sb.append("</div>");
			}
			sb.append("</div>");
		}

		List<Map<String, Object>> buttons = getList(data, "buttons");
		if (!buttons.isEmpty()) {
			sb.append("<div class=\"cta-buttons\">");
			for (Map<String, Object> button : buttons) {
				String btnClass = getBtnClass(button);
				sb.append(a(btnClass, "#", button.get("label")));
			}
			sb.append("</div>");
		}

		sb.append("</section>");
		return sb.toString();
	}

	private static String p(String cls, Object content) {
		return "<p class=\"" + cls + "\">" + content + "</p>";
	}

	private static String h(String tag, String cls, Object content) {
		return "<" + tag + " class=\"" + cls + "\">" + content + "</" + tag + ">";
	}

	private static String img(String cls, Object src, Object alt) {
		return "<img class=\"" + cls + "\" src=\"" + src + "\" alt=\"" + alt + "\"/>";
	}

	private static String a(String cls, String href, Object content) {
		return "<a class=\"" + cls + "\" href=\"" + href + "\">" + content + "</a>";
	}

	private static String getBtnClass(Map<String, Object> btn) {
		String style = String.valueOf(btn.get("style"));
		return "filled".equals(style) ? "btn-filled" : "btn-outlined";
	}

	private static String renderFeatureAuto(Map<String, Object> data) {
		// Smart detection based on structure
		List<Map<String, Object>> children = getChildren(data);

		for (Map<String, Object> child : children) {
			String type = get(child, "type");
			String sclass = get(child, "class");
			String ref = get(child, "ref");

			String sectionclass = !sclass.isEmpty() ? sclass : ref;
			if ("img".equalsIgnoreCase(type) && "feature-image".equalsIgnoreCase(sectionclass)) {
				return renderFeatureWithImage(data); // This is the new one
			}
		}

		return renderFeatureSection(data); // This is the old one
	}

	private static String renderFeatureWithImage(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"feature-section\">");

		List<Map<String, Object>> children = getChildren(data);

		for (Map<String, Object> child : children) {
			String type = get(child, "type");
			String className = get(child, "class");

			if ("img".equalsIgnoreCase(type)) {
				String ref = getString(child, "ref", "");
				String classAttr = getString(child, "class", "");
				String src = getString(child, "src", "").trim();
				String alt = getString(child, "alt", "Image");

				if (src.isEmpty()) {
					src = "/assets/images/place.png";
				}

				if ("feature-image".equalsIgnoreCase(ref) || "feature-image".equalsIgnoreCase(classAttr)) {
					// ✅ Correct: render actual <img>
					sb.append("<img class=\"feature-image\" src=\"").append(src).append("\" alt=\"").append(alt)
							.append("\"");
					if (!classAttr.isEmpty()) {
						sb.append(" class=\"").append(classAttr).append("\"");
					}
					sb.append(" style=\"width: 100%; height: auto;\"/>");
				} else {
					// ✅ fallback icon
					sb.append(renderImageDiv(child));
				}
			}

			else if ("div".equals(type) && "placeholder-img".equals(className)) {
				sb.append(renderImageDiv(child));
			}

			else if ("div".equalsIgnoreCase(type)) {
				sb.append("<div class=\"feature-content\">");
				List<Map<String, Object>> contentChildren = getChildren(child);
				for (Map<String, Object> c : contentChildren) {
					String innerType = get(c, "type");
					String content = get(c, "content");

					switch (innerType) {
					case "p":
					case "h2":
						sb.append("<").append(innerType).append(" class=\"").append(get(c, "class")).append("\">")
								.append(content).append("</").append(innerType).append(">");
						break;
					case "div":
						sb.append("<div class=\"cta-buttons\">");
						List<Map<String, Object>> buttons = getChildren(c);
						for (Map<String, Object> b : buttons) {
							sb.append("<a href=\"").append(get(b, "href")).append("\" class=\"").append(get(b, "class"))
									.append("\">").append(get(b, "content")).append("</a>");
						}
						sb.append("</div>");
						break;
					}
				}
				sb.append("</div>");
			}
		}

		sb.append("</section>");
		return sb.toString();
	}

	private static String renderFeatureSection(Map<String, Object> node) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"feature-section\">");

		List<Map<String, Object>> children = getChildren(node);

		for (Map<String, Object> child : children) {
			String type = getString(child, "type", "");
			String className = get(child, "class");

			if ("img".equalsIgnoreCase(type)) {
				String ref = getString(child, "ref", "");
				String classAttr = getString(child, "class", "");
				String src = getString(child, "src", "").trim();
				String alt = getString(child, "alt", "Image");

				if (src.isEmpty()) {
					src = "/assets/images/place.png";
				}

				if ("feature-image".equalsIgnoreCase(ref) || "feature-image".equalsIgnoreCase(classAttr)) {
					// ✅ Correct: render actual <img>
					sb.append("<img src=\"").append(src).append("\" alt=\"").append(alt).append("\"");
					if (!classAttr.isEmpty()) {
						sb.append(" class=\"").append(classAttr).append("\"");
					}
					sb.append(" style=\"width: 100%; height: auto;\"/>");
				} else {
					// ✅ fallback icon
					sb.append(renderImageDiv(child));
				}
			}

			else if ("div".equals(type) && "placeholder-img".equals(className)) {
				sb.append(renderImageDiv(child));
			}

			else if ("div".equalsIgnoreCase(type)) {
				sb.append("<div class=\"feature-content\">");

				List<Map<String, Object>> divChildren = getChildren(child);
				for (Map<String, Object> inner : divChildren) {
					String innerType = getString(inner, "type", "");

					if ("h2".equalsIgnoreCase(innerType)) {
						sb.append("<h2 class=\"feature-title\">").append(getString(inner, "content", ""))
								.append("</h2>");
					} else if ("p".equalsIgnoreCase(innerType)) {
						sb.append("<p class=\"feature-description\">").append(getString(inner, "content", ""))
								.append("</p>");
					} else if ("ul".equalsIgnoreCase(innerType)) {
						sb.append("<ul class=\"feature-list\">");
						List<Map<String, Object>> items = getChildren(inner);
						for (Map<String, Object> li : items) {
							sb.append("<li>").append(getString(li, "content", "")).append("</li>");
						}
						sb.append("</ul>");
					}
				}

				sb.append("</div>");
			}
		}

		sb.append("</section>");
		return sb.toString();
	}

	private static String renderFeatureGrid(Map<String, Object> node) {
		return "<section class='feature-grid'>Features</section>";
	}

	private static String renderFeatureCarousel(Map<String, Object> node) {
		return "<div class='feature-carousel'>Carousel</div>";
	}

	private static String renderFeatureNumberedSteps(Map<String, Object> node) {
		return "<ol class='numbered-steps'><li>Step 1</li></ol>";
	}

	private static String renderFaqAccordion(Map<String, Object> node) {
		return "<div class='faq-accordion'>FAQs</div>";
	}

	private static String renderTabbedSection(Map<String, Object> node) {
		return "<div class='tabs'>Tabbed Section</div>";
	}

	private static String renderCounterStats(Map<String, Object> node) {
		return "<div class='counter-stats'>Stats</div>";
	}

	private static String renderProgressBars(Map<String, Object> node) {
		return "<div class='progress-bars'>Progress Bars</div>";
	}

	private static String renderCallToAction(Map<String, Object> node) {
		return "<section class='cta'>Call to Action</section>";
	}

	private static String renderDownloadApp(Map<String, Object> node) {
		return "<div class='download-app'>App Download</div>";
	}

	private static String renderLeadMagnet(Map<String, Object> node) {
		return "<div class='lead-magnet'>Lead Magnet</div>";
	}

	private static String renderPromoBanner(Map<String, Object> node) {
		return "<div class='promo-banner'>Promo</div>";
	}

	private static String renderTeamGrid(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<section id=\"team-grid\">");

		// Tag
		if (section.containsKey("tag")) {
			html.append("<div class=\"tag\">").append(section.get("tag")).append("</div>");
		}

		// Heading
		if (section.containsKey("title")) {
			html.append("<h2 class=\"heading\">").append(section.get("title")).append("</h2>");
		}

		// Description
		if (section.containsKey("description")) {
			html.append("<p class=\"description\">").append(section.get("description")).append("</p>");
		}

		// Grid
		List<Map<String, Object>> members = (List<Map<String, Object>>) section.get("members");
		html.append("<div id=\"team-member-grid\">");

		for (Map<String, Object> member : members) {
			html.append("<div class=\"team-member\">");

			html.append("<img src=\"").append(member.get("image")).append("\" alt=\"").append(member.get("name"))
					.append("\" />");

			html.append("<div class=\"name\">").append(member.get("name")).append("</div>");
			html.append("<div class=\"description\">").append(member.get("description")).append("</div>");

			html.append("</div>"); // .team-member
		}

		html.append("</div>"); // #team-member-grid
		html.append("</section>");

		return html.toString();
	}

	private static String renderTeamProfileList(Map<String, Object> node) {
		return "<ul class='team-list'><li>Team Member</li></ul>";
	}

	private static String renderCompanyTimeline(Map<String, Object> node) {
		return "<div class='timeline'>Timeline</div>";
	}

	private static String renderValuesSection(Map<String, Object> node) {
		return "<section class='values'>Company Values</section>";
	}

	private static String renderPricingCards(Map<String, Object> node) {
		return "<div class='pricing-cards'>Pricing</div>";
	}

	private static String renderPricingComparison(Map<String, Object> node) {
		return "<table class='pricing-table'><tr><td>Plan</td></tr></table>";
	}

	private static String renderContactForm(Map<String, Object> node) {
		return "<form class='contact-form'><input placeholder='Your name'/></form>";
	}

	private static String renderContactMap(Map<String, Object> node) {
		return "<div class='contact-map'>Map</div>";
	}

	private static String renderContactGrid(Map<String, Object> node) {
		return "<div class='contact-grid'>Grid</div>";
	}

	private static String renderContactPage(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"contact-page\">");

		// Hero
		Map<String, Object> hero = getMap(data, "hero");
		sb.append("<div class=\"hero-banner\" style=\"background-image: url(").append(getText(hero, "backgroundImage"))
				.append(");\">");
		sb.append("<div class=\"logo-1\">").append(getText(hero, "logo")).append("</div>");

		List<String> navLinks = getStringList(hero, "navLinks");
		sb.append("<ul class=\"nav-1\">");
		for (String link : navLinks) {
			sb.append("<li>").append(link).append("</li>");
		}
		sb.append("</ul>");

		sb.append("<h1 class=\"hero-heading\">").append(getText(hero, "title")).append("</h1>");
		sb.append("</div>");

		// Three-column layout
		sb.append("<div class=\"contact-three-column\">");
		List<Map<String, Object>> sections = getListMap(data, "sections");

		for (Map<String, Object> sec : sections) {
			String type = getText(sec, "type");

			if ("map".equalsIgnoreCase(type)) {
				sb.append("<iframe class=\"contact-map\" src=\"").append(getText(sec, "embedUrl"))
						.append("\" loading=\"lazy\"></iframe>");
			}

			else if ("info".equalsIgnoreCase(type)) {
				Map<String, Object> details = getMap(sec, "details");
				sb.append("<div class=\"contact-info\">").append("<h3 class=\"info-heading\">")
						.append(getText(sec, "heading")).append("</h3>").append("<p class=\"info-phone\">")
						.append(getText(details, "phone")).append("</p>").append("<p class=\"info-email\">")
						.append(getText(details, "email")).append("</p>").append("<p class=\"info-address\">")
						.append(getText(details, "address")).append("</p>").append("</div>");
			}

			else if ("form".equalsIgnoreCase(type)) {
				sb.append("<form class=\"contact-form\">").append("<h3 class=\"form-heading\">")
						.append(getText(sec, "heading")).append("</h3>");

				List<Map<String, Object>> fields = getListMap(sec, "fields");
				for (Map<String, Object> field : fields) {
					String inputType = getText(field, "type");
					if ("textarea".equalsIgnoreCase(inputType)) {
						sb.append("<textarea name=\"").append(getText(field, "name", "message"))
								.append("\" placeholder=\"").append(getText(field, "placeholder")).append("\" rows=\"")
								.append(get(field, "rows", "4")).append("\"></textarea>");
					} else {
						sb.append("<input type=\"").append(inputType).append("\" name=\"")
								.append(getText(field, "name", "input")).append("\" placeholder=\"")
								.append(getText(field, "placeholder")).append("\" />");
					}
				}

				Map<String, Object> button = getMap(sec, "button");
				sb.append("<button class=\"btn-filled\">").append(getText(button, "label")).append("</button>")
						.append("</form>");
			}
		}

		sb.append("</div></section>");
		return sb.toString();
	}

	public static String getText(Map<String, Object> map, String key, String defaultValue) {
		Object val = map.get(key);
		return (val instanceof String) ? (String) val : defaultValue;
	}

	private static String renderContactUsSection(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();

		Map<String, Object> getInTouch = getMap(data, "getInTouch");
		List<Map<String, Object>> columns = getListMap(getInTouch, "columns");

		sb.append("<section class=\"contact-getintouch\">");
		sb.append("<h2>").append(getText(getInTouch, "heading")).append("</h2>");
		sb.append("<div class=\"columns\">");
		for (Map<String, Object> col : columns) {
			sb.append("<div class=\"column\">");
			sb.append("<div>").append(getText(col, "icon")).append("</div>");
			sb.append("<h4>").append(getText(col, "title")).append("</h4>");
			List<String> lines = getStringList(col, "lines");
			for (String line : lines) {
				sb.append("<p>").append(line).append("</p>");
			}
			sb.append("</div>");
		}
		sb.append("</div></section>");

		Map<String, Object> messageUs = getMap(data, "messageUs");
		Map<String, Object> leftColumn = getMap(messageUs, "leftColumn");
		Map<String, Object> form = getMap(messageUs, "form");
		List<Map<String, Object>> fields = getListMap(form, "fields");
		Map<String, Object> submit = getMap(form, "submit");

		sb.append("<section class=\"contact-messageus\">");
		sb.append("<div class=\"left-column\">");
		sb.append("<h2>").append(getText(leftColumn, "heading")).append("</h2>");
		sb.append("<p>").append(getText(leftColumn, "description")).append("</p>");
		sb.append("<p><strong>").append(getText(leftColumn, "awardText")).append("</strong></p>");
		sb.append("</div>");

		sb.append("<div class=\"form\">");
		sb.append("<form>");
		for (Map<String, Object> field : fields) {
			String type = getText(field, "type");
			String name = getText(field, "name", type);
			String placeholder = getText(field, "placeholder");
			if ("textarea".equals(type)) {
				int rows = getInt(field, "rows", 4);
				sb.append("<textarea name=\"").append(name).append("\" placeholder=\"").append(placeholder)
						.append("\" rows=\"").append(rows).append("\"></textarea>");
			} else {
				sb.append("<input type=\"").append(type).append("\" name=\"").append(name).append("\" placeholder=\"")
						.append(placeholder).append("\"/>");
			}
		}
		sb.append("<button>").append(getText(submit, "label")).append("</button>");
		sb.append("</form></div></section>");

		return sb.toString();
	}

	@SuppressWarnings("unchecked")
	public static int getInt(Map<String, Object> map, String key, int defaultValue) {
		Object value = map.get(key);
		if (value instanceof Number) {
			return ((Number) value).intValue();
		}
		try {
			return Integer.parseInt(String.valueOf(value));
		} catch (Exception e) {
			return defaultValue;
		}
	}

	private static String renderContactSplitSection(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"contact-split-section\">");

		// LEFT PANEL
		Map<String, Object> left = getMap(data, "leftPanel");
		sb.append("<div class=\"contact-left-panel\" style=\"background-image:url(")
				.append(getText(left, "backgroundImage")).append(");\">");

		List<Map<String, Object>> sections = getListMap(left, "sections");
		for (Map<String, Object> sec : sections) {
			sb.append("<div class=\"contact-section\">");
			sb.append("<h3 class=\"section-heading\">").append(getText(sec, "heading")).append("</h3>");
			if (sec.containsKey("highlightColor")) {
				sb.append("<p class=\"section-highlight\">").append(getText(sec, "content")).append("</p>");
			} else {
				sb.append("<p class=\"section-content\">").append(getText(sec, "content")).append("</p>");
			}
			sb.append("</div>");
		}
		sb.append("</div>");

		// RIGHT PANEL
		Map<String, Object> right = getMap(data, "rightPanel");
		sb.append("<div class=\"contact-right-panel\">");
		sb.append("<h2 class=\"form-heading\">").append(getText(right, "heading")).append("</h2>");

		sb.append("<form class=\"contact-form\">");
		Map<String, Object> form = getMap(right, "form");
		List<Map<String, Object>> fields = getListMap(form, "fields");

		for (Map<String, Object> field : fields) {
			String type = getText(field, "type");
			if ("textarea".equalsIgnoreCase(type)) {
				sb.append("<textarea name=\"").append(getText(field, "name")).append("\" placeholder=\"")
						.append(getText(field, "placeholder")).append("\"></textarea>");
			} else {
				sb.append("<input type=\"").append(type).append("\" name=\"").append(getText(field, "name"))
						.append("\" placeholder=\"").append(getText(field, "placeholder")).append("\" />");
			}
		}

		Map<String, Object> btn = getMap(form, "button");
		sb.append("<button class=\"btn-filled\" type=\"submit\">").append(getText(btn, "label")).append("</button>");

		sb.append("</form></div>"); // end right panel
		sb.append("</section>");
		return sb.toString();
	}

	private static String renderContactInfoSection(Map<String, Object> data) {
		StringBuilder sb = new StringBuilder();
		sb.append("<section class=\"contact-info-section\">");

		// Profile Image
		Map<String, Object> image = getMap(data, "profileImage");
		if (!image.isEmpty()) {
			sb.append("<img class=\"contact-profile-image\" src=\"").append(getText(image, "src")).append("\" alt=\"")
					.append(getText(image, "alt")).append("\" />");
		}

		// Heading
		Map<String, Object> heading = getMap(data, "heading");
		sb.append("<h2 class=\"contact-heading\">").append(getText(heading, "text")).append("</h2>");

		// Description
		Map<String, Object> desc = getMap(data, "description");
		sb.append("<p class=\"contact-description\">").append(getText(desc, "text")).append("</p>");

		// Columns
		List<Map<String, Object>> columns = getListMap(data, "columns");
		if (!columns.isEmpty()) {
			sb.append("<div class=\"contact-columns\">");
			for (Map<String, Object> col : columns) {
				sb.append("<div class=\"contact-column\">");
				sb.append("<span class=\"contact-icon\">").append(getText(col, "icon")).append("</span>");
				sb.append("<h3 class=\"contact-title\">").append(getText(col, "title")).append("</h3>");
				sb.append("<p class=\"contact-text\">").append(getText(col, "text")).append("</p>");
				sb.append("</div>");
			}
			sb.append("</div>");
		}

		sb.append("</section>");
		return sb.toString();
	}

	private static String renderContactFormSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"contact-form-section\">");

		html.append("<div class=\"contact-header\">").append("<p class=\"hero-label\">")
				.append(getText(data, "tagline")).append("</p>").append("<h2 class=\"contact-title\">")
				.append(getTextMap(data, "heading", "text")).append("</h2>").append("<p class=\"contact-description\">")
				.append(getTextMap(data, "description", "text")).append("</p>").append("</div>");

		html.append("<form class=\"contact-form\">");
		List<Map<String, Object>> fields = getListMap(getMap(data, "form"), "fields");

		for (Map<String, Object> field : fields) {
			String type = getText(field, "type");
			String name = getText(field, "name");
			String label = getText(field, "label");
			String placeholder = getText(field, "placeholder");

			switch (type) {
			case "text":
			case "email":
				html.append("<input type=\"").append(type).append("\" name=\"").append(name).append("\" placeholder=\"")
						.append(placeholder).append("\" />");
				break;
			case "textarea":
				html.append("<textarea name=\"").append(name).append("\" placeholder=\"").append(placeholder)
						.append("\"></textarea>");
				break;
			case "checkbox":
				html.append("<label class=\"checkbox-label\">").append("<input type=\"checkbox\" name=\"").append(name)
						.append("\" />").append("<span>").append(label).append("</span>").append("</label>");
				break;
			}
		}

		Map<String, Object> button = getMap(getMap(data, "form"), "button");
		html.append("<button class=\"btn-filled\">").append(getText(button, "label")).append("</button>");
		html.append("</form>");

		html.append("</section>");
		return html.toString();
	}

	@SuppressWarnings("unchecked")
	public static String getTextMap(Map<String, Object> map, String key, String innerKey) {
		Object inner = map.get(key);
		if (inner instanceof Map) {
			Object value = ((Map<String, Object>) inner).get(innerKey);
			return value != null ? value.toString() : "";
		}
		return "";
	}

	@SuppressWarnings("unchecked")
	public static List<Map<String, Object>> getListMap(Map<String, Object> map, String key) {
		Object value = map.get(key);
		if (value instanceof List) {
			return (List<Map<String, Object>>) value;
		}
		return new ArrayList<>();
	}

	private static String renderFooterMinimal(Map<String, Object> node) {
		return "<footer class='footer-minimal'>Minimal Footer</footer>";
	}

	private static String renderFooterCentered(Map<String, Object> node) {
		return "<footer class='footer-centered'>Centered Footer</footer>";
	}

	private static String renderFooterColumns(Map<String, Object> node) {
		return "<footer class='footer-columns'>Footer Columns</footer>";
	}

	private static String renderIconButton(Map<String, Object> node) {
		return "<button class='icon-btn'>Icon Button</button>";
	}

	private static String renderLabel(Map<String, Object> node) {
		return "<span class='label'>Label</span>";
	}

	private static String renderBadge(Map<String, Object> node) {
		return "<span class='badge'>Badge</span>";
	}

	private static String renderRatingStars(Map<String, Object> node) {
		return "<div class='stars'>★★★★★</div>";
	}

	private static String renderClassicListPost(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		html.append("<article class=\"classic-list-post\" style=\"padding: 20px; font-family: sans-serif;\">");

		// Title
		html.append("<h1>").append(getString(data, "title", "List Post Title")).append("</h1>");

		// Hook/Intro
		html.append("<p class=\"hook\" style=\"font-style: italic; margin-top: 10px;\">")
				.append(getString(data, "hook", "")).append("</p>");

		// List Content
		if (data.containsKey("content")) {
			List<Map<String, Object>> items = (List<Map<String, Object>>) data.get("content");
			html.append("<div class=\"list-content\" style=\"margin-top: 20px;\">");
			for (Map<String, Object> item : items) {
				html.append("<div class=\"tactic\" style=\"margin-bottom: 20px;\">");
				html.append("<h3>").append(getString(item, "subheading", "")).append("</h3>");
				html.append("<p>").append(getString(item, "description", "")).append("</p>");

				if (item.containsKey("actionSteps")) {
					List<String> steps = (List<String>) item.get("actionSteps");
					html.append("<ul>");
					for (String step : steps) {
						html.append("<li>").append(step).append("</li>");
					}
					html.append("</ul>");
				}

				html.append("</div>");
			}
			html.append("</div>");
		}

		// Conclusion
		if (data.containsKey("conclusion")) {
			html.append("<div class=\"conclusion\" style=\"margin-top: 30px; font-weight: bold;\">")
					.append(data.get("conclusion")).append("</div>");
		}

		// Call to action
		if (data.containsKey("callToAction")) {
			html.append("<div class=\"cta\" style=\"margin-top: 10px; font-style: italic; color: #555;\">")
					.append(data.get("callToAction")).append("</div>");
		}

		html.append("</article>");
		return html.toString();
	}

	private static String renderListPost(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		html.append("<article class=\"list-post\" style=\"padding: 30px; font-family: sans-serif;\">");

		// Title
		html.append("<h1>").append(getString(data, "title", "List Post Title")).append("</h1>");

		// Intro
		if (data.containsKey("intro")) {
			Map<String, Object> intro = (Map<String, Object>) data.get("intro");
			html.append("<div class=\"intro\" style=\"margin-top: 15px;\">");
			html.append("<p class=\"hook\" style=\"font-weight: bold; color: #222;\">")
					.append(getString(intro, "hook", "")).append("</p>");
			html.append("<p>").append(getString(intro, "summary", "")).append("</p>");
			html.append("<p><em>").append(getString(intro, "benefitStatement", "")).append("</em></p>");
			html.append("</div>");
		}

		// List Items
		if (data.containsKey("listItems")) {
			List<Map<String, Object>> items = (List<Map<String, Object>>) data.get("listItems");
			html.append("<ol class=\"post-list\" style=\"margin-top: 20px;\">");
			for (Map<String, Object> item : items) {
				html.append("<li style=\"margin-bottom: 16px;\">").append("<strong>")
						.append(getString(item, "title", "")).append("</strong>").append("<p>")
						.append(getString(item, "description", "")).append("</p>").append("</li>");
			}
			html.append("</ol>");
		}

		// Conclusion
		if (data.containsKey("conclusion")) {
			Map<String, Object> conclusion = (Map<String, Object>) data.get("conclusion");
			html.append("<div class=\"conclusion\" style=\"margin-top: 30px;\">");
			html.append("<p style=\"font-weight: bold;\">").append(getString(conclusion, "summary", "")).append("</p>");
			html.append("<p style=\"font-style: italic;\">").append(getString(conclusion, "callToAction", ""))
					.append("</p>");
			html.append("</div>");
		}

		html.append("</article>");
		return html.toString();
	}

	private static String renderPerfectBlogPost(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		html.append("<article class=\"perfect-blog-post\" style=\"padding: 40px; font-family: sans-serif;\">");

		// Title
		html.append("<h1>").append(getString(data, "title", "Perfect Blog Post")).append("</h1>");

		// Sections
		if (data.containsKey("sections")) {
			List<Map<String, Object>> sections = (List<Map<String, Object>>) data.get("sections");
			html.append("<div class=\"sections\" style=\"margin-top: 20px;\">");
			for (Map<String, Object> section : sections) {
				html.append("<div class=\"section-block\" style=\"margin-bottom: 24px;\">");
				html.append("<h3 style=\"margin-bottom: 5px;\">").append(getString(section, "label", "Section"))
						.append("</h3>");
				html.append("<p>").append(getString(section, "description", "")).append("</p>");
				html.append("</div>");
			}
			html.append("</div>");
		}

		// Footer CTA
		if (data.containsKey("footer")) {
			html.append("<footer style=\"margin-top: 40px; font-style: italic; color: #666;\">")
					.append(getString(data, "footer", "")).append("</footer>");
		}

		html.append("</article>");
		return html.toString();
	}

	private static String renderHeroCenteredSection(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"hero-centered\">");

		// Tagline
		Map<String, Object> tagline = (Map<String, Object>) section.get("tagline");
		if (tagline != null) {
			html.append("<div class=\"hero-label\">").append(tagline.get("text")).append("</div>");
		}

		// Heading
		Map<String, Object> heading = (Map<String, Object>) section.get("heading");
		if (heading != null) {
			html.append("<h1 class=\"hero-heading\">").append(heading.get("text")).append("</h1>");
		}

		// Description
		Map<String, Object> description = (Map<String, Object>) section.get("description");
		if (description != null) {
			html.append("<p class=\"hero-description\">").append(description.get("text")).append("</p>");
		}

		// Buttons
		List<Map<String, Object>> buttons = (List<Map<String, Object>>) section.get("buttons");
		if (buttons != null && !buttons.isEmpty()) {
			html.append("<div class=\"cta-buttons\">");
			for (Map<String, Object> btn : buttons) {
				html.append("<a href=\"").append(btn.getOrDefault("action", "#")).append("\" class=\"")
						.append(btn.getOrDefault("class", "btn")).append("\">")
						.append(btn.getOrDefault("label", "Click")).append("</a>");
			}
			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderHeaderSection(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		String sectionClass = getString(section, "class", "hero-header");

		html.append("<section class=\"").append(sectionClass).append("\">");

		for (Map.Entry<String, Object> entry : section.entrySet()) {
			String key = entry.getKey();
			Object value = entry.getValue();

			if ("class".equalsIgnoreCase(key))
				continue;

			if (value instanceof String) {
				if (key.toLowerCase().contains("heading")) {
					html.append("<h1>").append(value).append("</h1>");
				} else if (key.toLowerCase().contains("subheading") || key.toLowerCase().contains("paragraph")) {
					html.append("<p>").append(value).append("</p>");
				} else {
					html.append("<div class=\"").append(key.toLowerCase().replace(" ", "-")).append("\">").append(value)
							.append("</div>");
				}
			} else if (value instanceof Map) {
				Map<String, Object> nested = (Map<String, Object>) value;
				String nestedClass = getString(nested, "class", key.toLowerCase().replace(" ", "-"));
				html.append("<div class=\"").append(nestedClass).append("\">");

				Object items = nested.get("items");
				if (items instanceof List) {
					for (Object item : (List<?>) items) {
						html.append("<button>").append(item).append("</button>");
					}
				}

				html.append("</div>");
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderFromMap(Map<String, Object> node) {
		StringBuilder html = new StringBuilder();

		// Get tag from 'tag' or fallback to 'type'
		String type = getString(node, "type", "div");
		String rawTag = getString(node, "tag", "");
		String tag = !rawTag.isEmpty() ? rawTag : TYPE_TAG_MAP.getOrDefault(type.toLowerCase(), type);

		html.append("<").append(tag);

		// Add class and id if present
		String className = getString(node, "class", getString(node, "ref", ""));
		String id = getString(node, "id", "");

		if (!className.isEmpty())
			html.append(" class=\"").append(className).append("\"");
		if (!id.isEmpty())
			html.append(" id=\"").append(id).append("\"");

		// Add other attributes (like src, alt for img)
		for (Map.Entry<String, Object> entry : node.entrySet()) {
			String key = entry.getKey();
			Object value = entry.getValue();
			if (!Arrays.asList("type", "tag", "class", "id", "content", "children", "menu", "actions", "buttons")
					.contains(key) && !(value instanceof Map || value instanceof List)) {
				html.append(" ").append(key).append("=\"").append(value).append("\"");
			}
		}

		// Self-closing tag support (like img)
		// Self-closing tag like <img />
		if ("img".equalsIgnoreCase(tag)) {
			html.append(" src=\"").append(getString(node, "src", "")).append("\"");
			html.append(" alt=\"").append(getString(node, "alt", "")).append("\"");
			html.append(" />");
			return html.toString();
		}

		// Content rendering
		if (node.containsKey("content")) {
			html.append(node.get("content"));
		}

		html.append(">");

		// Render inline content if present

		// Special short-circuit rendering for link and button
		if ("link".equalsIgnoreCase(type)) {
			html.append("<a href=\"#\">").append(node.get("content")).append("</a>");
			return html.toString();
		}

		if ("text".equalsIgnoreCase(type)) {
			html.append(getString(node, "content", ""));
			return html.toString();
		}

		if ("logo".equalsIgnoreCase(type)) {
			html.append("<div class=\"").append(className).append("\">").append(getString(node, "content", "Logo"))
					.append("</div>");
			return html.toString();
		}

		if ("icon".equalsIgnoreCase(type)) {
			String label = getString(node, "content", "");
			String emoji = getIconEmoji(label);
			html.append("<div>").append(emoji).append(" ").append(label).append("</div>");
			return html.toString();
		}

		if ("a".equalsIgnoreCase(type)) {
			String href = getString(node, "href", "#");
			html.append("<a href=\"").append(href).append("\">").append(getString(node, "content", "")).append("</a>");
			return html.toString();
		}

		if ("button".equalsIgnoreCase(type)) {
			html.append("<button class=\"").append(className).append("\">").append(node.get("content"))
					.append("</button>");
			return html.toString();
		}

		if (node.containsKey("content")) {
			html.append(node.get("content"));
		}

		// Handle structured known patterns
		if (node.containsKey("logo")) {
			html.append("<div class=\"logo-1\">").append(node.get("logo")).append("</div>");
		}

		if (node.containsKey("heading")) {
			html.append("<h1>").append(node.get("heading")).append("</h1>");
		}

		if (node.containsKey("subheading")) {
			html.append("<p>").append(node.get("subheading")).append("</p>");
		}

		if (node.containsKey("text")) {
			html.append("<p>").append(node.get("text")).append("</p>");
		}

		if (node.containsKey("menu")) {
			html.append(renderMenu(node.get("menu")));
		}

		if (node.containsKey("actions")) {
			html.append(renderActions(node.get("actions")));
		}

		if (node.containsKey("buttons")) {
			html.append(renderButtons(node.get("buttons")));
		}

		if (node.containsKey("columns")) {
			html.append(renderColumns(node.get("columns")));
		}

		if (node.containsKey("children")) {
			html.append(buildHtml(node.get("children")));
		}

		html.append("</").append(tag).append(">");
		return html.toString();
	}

	private static String renderFromList(List<Object> list) {
		StringBuilder html = new StringBuilder();
		for (Object item : list) {
			html.append(buildHtml(item));
		}
		return html.toString();
	}

	private static String renderButtons(Object obj) {
		StringBuilder html = new StringBuilder();

		// Case 1: Simple list of string labels
		if (obj instanceof List) {
			List<Object> btns = (List<Object>) obj;
			html.append("<div class=\"cta-buttons\">");
			for (Object item : btns) {
				if (item instanceof String) {
					html.append("<button>").append(item).append("</button>");
				} else if (item instanceof Map) {
					html.append(renderSingleButton((Map<String, Object>) item));
				}
			}
			html.append("</div>");
		}

		// Case 2: Object with "items" list and optional class
		else if (obj instanceof Map) {
			Map<String, Object> btnMap = (Map<String, Object>) obj;
			List<Object> items = (List<Object>) btnMap.get("items");
			String btnClass = getString(btnMap, "class", "cta-buttons");

			html.append("<div class=\"").append(btnClass).append("\">");
			if (items != null) {
				for (Object btn : items) {
					if (btn instanceof String) {
						html.append("<button>").append(btn).append("</button>");
					} else if (btn instanceof Map) {
						html.append(renderSingleButton((Map<String, Object>) btn));
					}
				}
			}
			html.append("</div>");
		}

		return html.toString();
	}

	private static String renderSingleButton(Map<String, Object> btn) {
		String label = getString(btn, "label", "Button");
		String href = getString(btn, "action", "#");
		String style = getString(btn, "style", "filled");
		String bg = getString(btn, "backgroundColor", style.equals("outlined") ? "white" : "black");
		String color = getString(btn, "textColor", style.equals("outlined") ? "black" : "white");
		String border = style.equals("outlined") ? "1px solid " + getString(btn, "borderColor", "#000") : "none";

		return new StringBuilder().append("<a href=\"").append(href).append("\" style=\"").append("background:")
				.append(bg).append("; ").append("color:").append(color).append("; ")
				.append("padding:10px 20px; border-radius:4px; text-decoration:none; ").append("border:").append(border)
				.append("; margin-right:10px; display:inline-block;\">").append(label).append("</a>").toString();
	}

	private static String renderColumns(Object obj) {
		StringBuilder html = new StringBuilder();
		html.append("<div class=\"blog-layout\">");

		List<Map<String, Object>> columns = (List<Map<String, Object>>) obj;
		for (Map<String, Object> col : columns) {
			String type = getString(col, "type", "");
			if ("main".equalsIgnoreCase(type)) {
				html.append("<main class=\"main-column\">");
				if (col.containsKey("contentBlocks")) {
					List<Map<String, Object>> blocks = (List<Map<String, Object>>) col.get("contentBlocks");
					for (Map<String, Object> block : blocks) {
						html.append("<div class=\"content-block\">").append("<h2>")
								.append(getString(block, "heading", "")).append("</h2>").append("<p>")
								.append(getString(block, "text", "")).append("</p>").append("</div>");
					}
				}
				html.append("</main>");
			} else if ("sidebar".equalsIgnoreCase(type)) {
				html.append("<aside class=\"sidebar-column\">");
				List<String> widgets = (List<String>) col.get("widgets");
				for (String widget : widgets) {
					html.append("<div class=\"widget\">").append(getWidgetIcon(widget)).append(" ").append(widget)
							.append("</div>");
				}
				html.append("</aside>");
			}
		}

		html.append("</div>");
		return html.toString();
	}

	private static String renderMenu(Object obj) {
		StringBuilder html = new StringBuilder("<ul class=\"nav-1\">");

		List<Object> menu = (List<Object>) obj;
		for (Object item : menu) {
			if (item instanceof String) {
				html.append("<li><a href=\"#\">").append(item).append("</a></li>");
			} else if (item instanceof Map) {
				Map<String, Object> dropdownItem = (Map<String, Object>) item;
				html.append("<li class=\"dropdown\">");
				html.append("<a href=\"#\">").append(dropdownItem.get("title")).append("</a>");

				if (dropdownItem.containsKey("dropdown")) {
					html.append(renderDropdown(dropdownItem.get("dropdown")));
				}
				html.append("</li>");
			}
		}

		html.append("</ul>");
		return html.toString();
	}

	private static String renderDropdown(Object obj) {
		StringBuilder html = new StringBuilder("<div class=\"dropdown-content\"><div class=\"dropdown-columns\">");

		Map<String, Object> dropdown = (Map<String, Object>) obj;
		List<Map<String, Object>> columns = (List<Map<String, Object>>) dropdown.get("columns");

		for (Map<String, Object> column : columns) {
			html.append("<div class=\"column\">");
			html.append("<h4>").append(column.get("title")).append("</h4>");
			html.append("<ul>");

			if (column.containsKey("items")) {
				List<Map<String, Object>> items = (List<Map<String, Object>>) column.get("items");
				for (Map<String, Object> item : items) {
					html.append("<li><span>").append(item.get("icon")).append("</span>").append("<strong>")
							.append(item.get("title")).append("</strong>").append("<p>").append(item.get("description"))
							.append("</p>").append("</li>");
				}
			} else if (column.containsKey("blogs")) {
				List<Map<String, Object>> blogs = (List<Map<String, Object>>) column.get("blogs");
				for (Map<String, Object> blog : blogs) {
					html.append("<li><strong>").append(blog.get("title")).append("</strong>").append("<p>")
							.append(blog.get("description")).append("</p>").append("<a href=\"#\">")
							.append(blog.get("cta")).append("</a></li>");
				}
				if (column.containsKey("footerLink")) {
					html.append("<div class=\"footer-link\"><a href=\"#\">").append(column.get("footerLink"))
							.append("</a></div>");
				}
			}

			html.append("</ul></div>");
		}

		html.append("</div></div>");
		return html.toString();
	}

	private static String renderActions(Object obj) {
		StringBuilder html = new StringBuilder("<div class=\"navbar-actions\">");

		List<Map<String, Object>> actions = (List<Map<String, Object>>) obj;
		for (Map<String, Object> action : actions) {
			String label = getString(action, "label", "Button");
			String variant = getString(action, "variant", "");
			String btnClass = "join-btn";
			if (!variant.isEmpty()) {
				btnClass += " " + variant;
			}
			html.append("<button class=\"").append(btnClass).append("\">").append(label).append("</button>");
		}

		html.append("</div>");
		return html.toString();
	}

	private static String renderNavbarBlock(Map<String, Object> nav) {
		StringBuilder html = new StringBuilder();

		// Inline styles
		StringBuilder style = new StringBuilder();
		if (nav.containsKey("style")) {
			Map<String, Object> styleMap = (Map<String, Object>) nav.get("style");
			for (Map.Entry<String, Object> s : styleMap.entrySet()) {
				appendStyle(style, s.getKey(), s.getValue());
			}
		}

		html.append("<nav style=\"").append(style).append("\">");

		// Logo
		if (nav.containsKey("Logo")) {
			Map<String, Object> logo = (Map<String, Object>) nav.get("Logo");
			String type = getString(logo, "type", "text");
			if ("image".equalsIgnoreCase(type)) {
				html.append("<img src=\"").append(logo.get("src")).append("\" alt=\"").append(logo.get("alt"))
						.append("\" width=\"").append(logo.get("width")).append("\" height=\"")
						.append(logo.get("height")).append("\" />");
			} else if ("text".equalsIgnoreCase(type)) {
				html.append("<div style=\"font-weight:").append(getString(logo, "fontWeight", "normal"))
						.append("; font-size:").append(getString(logo, "fontSize", "16px")).append(";\">")
						.append(getString(logo, "text", "Logo")).append("</div>");
			}
		}

		// Links
		if (nav.containsKey("Links")) {
			List<Map<String, Object>> links = (List<Map<String, Object>>) nav.get("Links");
			html.append("<ul style=\"display:flex; gap:20px; list-style:none\">");
			for (Map<String, Object> link : links) {
				html.append("<li><a href=\"").append(link.get("href")).append("\">")
						.append(getString(link, "label", "")).append("</a></li>");
			}
			html.append("</ul>");
		}

		// Buttons
		if (nav.containsKey("Buttons")) {
			List<Map<String, Object>> buttons = (List<Map<String, Object>>) nav.get("Buttons");
			for (Map<String, Object> btn : buttons) {
				String bg = getString(btn, "background", "white");
				String color = getString(btn, "textColor", "black");
				String border = getString(btn, "border", "none");

				html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" style=\"")
						.append("background:").append(bg).append(";").append("color:").append(color).append(";")
						.append("padding:8px 16px;").append("border:").append(border).append(";")
						.append("text-decoration:none; margin-left:10px;").append("\">")
						.append(getString(btn, "label", "Button")).append("</a>");
			}
		}

		html.append("</nav>");
		return html.toString();
	}

	private static String renderFooterBlock(Map<String, Object> footer) {
		StringBuilder html = new StringBuilder();

		// Inline styles
		StringBuilder style = new StringBuilder();
		appendStyle(style, "background", footer.get("background"));
		appendStyle(style, "padding", footer.get("padding"));
		appendStyle(style, "font-family", footer.get("fontFamily"));

		html.append("<footer style=\"").append(style).append("\">");

		// Logo
		if (footer.containsKey("Logo")) {
			Map<String, Object> logo = (Map<String, Object>) footer.get("Logo");
			html.append("<div style=\"font-weight:").append(getString(logo, "fontWeight", "normal"))
					.append("; font-size:").append(getString(logo, "fontSize", "16px")).append(";\">")
					.append(getString(logo, "text", "Logo")).append("</div>");
		}

		// Address
		if (footer.containsKey("Address")) {
			html.append("<p>").append(getString(footer, "Address", "")).append("</p>");
		}

		// Contact
		if (footer.containsKey("Contact")) {
			Map<String, Object> contact = (Map<String, Object>) footer.get("Contact");
			html.append("<p>Phone: ").append(getString(contact, "phone", "")).append("</p>");
			html.append("<p>Email: <a href=\"mailto:").append(getString(contact, "email", "")).append("\">")
					.append(getString(contact, "email", "")).append("</a></p>");
		}

		// Social Links
		if (footer.containsKey("SocialLinks")) {
			List<Map<String, Object>> social = (List<Map<String, Object>>) footer.get("SocialLinks");
			html.append("<div class=\"social-icons\">");
			for (Map<String, Object> s : social) {
				String platform = getString(s, "platform", "");
				String emoji = getIconEmoji(platform);
				html.append("<a href=\"").append(getString(s, "href", "#")).append("\" style=\"margin-right:12px;\">")
						.append(emoji).append("</a>");
			}
			html.append("</div>");
		}

		// Links
		if (footer.containsKey("Links")) {
			Map<String, List<Map<String, Object>>> links = (Map<String, List<Map<String, Object>>>) footer.get("Links");
			html.append("<div style=\"display:flex; gap:40px; margin-top:20px;\">");
			for (Map.Entry<String, List<Map<String, Object>>> col : links.entrySet()) {
				html.append("<div class=\"link-column\">");
				for (Map<String, Object> link : col.getValue()) {
					html.append("<p><a href=\"").append(getString(link, "href", "#")).append("\">")
							.append(getString(link, "label", "")).append("</a></p>");
				}
				html.append("</div>");
			}
			html.append("</div>");
		}

		html.append("</footer>");
		return html.toString();
	}

	private static String renderMdBootstrapFooter(Map<String, Object> footer) {
		StringBuilder html = new StringBuilder();
		String theme = getString(footer, "theme", "light");

		html.append("<footer class=\"footer-mdb ").append(theme).append("\">");

		// Top Bar
		if (footer.containsKey("topBar")) {
			Map<String, Object> topBar = (Map<String, Object>) footer.get("topBar");
			html.append("<div class=\"top-bar\">");

			html.append("<p>").append(getString(topBar, "text", "")).append("</p>");

			if (topBar.containsKey("socialLinks")) {
				List<Map<String, Object>> socials = (List<Map<String, Object>>) topBar.get("socialLinks");
				for (Map<String, Object> s : socials) {
					String icon = getIconEmoji(getString(s, "platform", ""));
					html.append("<a href=\"").append(getString(s, "href", "#"))
							.append("\" style=\"margin-right:12px;\">").append(icon).append("</a>");
				}
			}
			html.append("</div>");
		}

		// Columns
		if (footer.containsKey("columns")) {
			List<Map<String, Object>> columns = (List<Map<String, Object>>) footer.get("columns");
			html.append("<div class=\"footer-columns\" style=\"display:flex; gap:40px; flex-wrap:wrap;\">");
			for (Map<String, Object> col : columns) {
				html.append("<div class=\"footer-col\">");
				html.append("<h4>").append(getString(col, "title", "")).append("</h4>");

				if (col.containsKey("content")) {
					html.append("<p>").append(getString(col, "content", "")).append("</p>");
				}

				if (col.containsKey("links")) {
					List<Map<String, Object>> links = (List<Map<String, Object>>) col.get("links");
					for (Map<String, Object> link : links) {
						html.append("<p><a href=\"").append(getString(link, "href", "#")).append("\">")
								.append(getString(link, "label", "")).append("</a></p>");
					}
				}

				if (col.containsKey("info")) {
					Map<String, Object> info = (Map<String, Object>) col.get("info");
					html.append("<p>").append(getString(info, "address", "")).append("</p>");
					html.append("<p><a href=\"mailto:").append(getString(info, "email", "")).append("\">")
							.append(getString(info, "email", "")).append("</a></p>");
					html.append("<p>").append(getString(info, "phone", "")).append("</p>");
					html.append("<p>").append(getString(info, "fax", "")).append("</p>");
				}

				html.append("</div>");
			}
			html.append("</div>");
		}

		// Bottom Bar
		if (footer.containsKey("bottom")) {
			Map<String, Object> bottom = (Map<String, Object>) footer.get("bottom");
			html.append("<div class=\"footer-bottom\">").append("<p>").append(getString(bottom, "text", ""))
					.append("</p>").append("</div>");
		}

		html.append("</footer>");
		return html.toString();
	}

	private static String renderCompactFooter(Map<String, Object> footer) {
		StringBuilder html = new StringBuilder();

		String bg = getString(footer, "backgroundColor", "#222");
		String color = getString(footer, "textColor", "white");

		html.append("<footer style=\"background:").append(bg).append("; color:").append(color)
				.append("; padding:40px;\">");

		// Logo and Slogan
		if (footer.containsKey("logo")) {
			Map<String, Object> logo = (Map<String, Object>) footer.get("logo");
			html.append("<div style=\"margin-bottom:20px;\">").append("<h2>").append(getString(logo, "text", "LOGO"))
					.append("</h2>").append("<p>").append(getString(logo, "slogan", "")).append("</p>")
					.append("</div>");
		}

		// Link Columns
		if (footer.containsKey("linkColumns")) {
			List<Map<String, Object>> columns = (List<Map<String, Object>>) footer.get("linkColumns");
			html.append("<div style=\"display:flex; gap:40px; flex-wrap:wrap;\">");
			for (Map<String, Object> col : columns) {
				html.append("<div class=\"link-col\">");
				String title = getString(col, "title", "");
				if (!title.isEmpty()) {
					html.append("<h4>").append(title).append("</h4>");
				}
				if (col.containsKey("links")) {
					List<Map<String, Object>> links = (List<Map<String, Object>>) col.get("links");
					for (Map<String, Object> link : links) {
						html.append("<p><a href=\"").append(getString(link, "href", "#"))
								.append("\" style=\"color:inherit;\">").append(getString(link, "label", ""))
								.append("</a></p>");
					}
				}
				html.append("</div>");
			}
			html.append("</div>");
		}

		// Social Icons
		if (footer.containsKey("socialIcons")) {
			List<Map<String, Object>> icons = (List<Map<String, Object>>) footer.get("socialIcons");
			html.append("<div class=\"social-icons\" style=\"margin-top:20px;\">");
			for (Map<String, Object> icon : icons) {
				String label = getString(icon, "icon", "");
				String emoji = getIconEmoji(label);
				html.append("<a href=\"").append(getString(icon, "href", "#"))
						.append("\" style=\"margin-right:10px; color:inherit;\">").append(emoji).append("</a>");
			}
			html.append("</div>");
		}

		// Copyright
		if (footer.containsKey("copyright")) {
			html.append("<p style=\"margin-top:20px; font-size:12px;\">").append(getString(footer, "copyright", ""))
					.append("</p>");
		}

		html.append("</footer>");
		return html.toString();
	}

	private static String renderContactSection(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();

		String bg = getString(section, "background", "#fff");
		String color = getString(section, "textColor", "#000");
		String font = getString(section, "fontFamily", "sans-serif");

		html.append("<section style=\"background:").append(bg).append("; color:").append(color).append("; font-family:")
				.append(font).append("; padding:40px;\">");

		html.append("<div style=\"display:flex; gap:40px; flex-wrap:wrap;\">");

		// LEFT COLUMN
		if (section.containsKey("left")) {
			Map<String, Object> left = (Map<String, Object>) section.get("left");
			html.append("<div style=\"flex:1; min-width:300px;\">");

			if (left.containsKey("heading")) {
				html.append("<h2>").append(getString(left, "heading", "")).append("</h2>");
			}
			if (left.containsKey("description")) {
				html.append("<p>").append(getString(left, "description", "")).append("</p>");
			}

			if (left.containsKey("ctaButton")) {
				Map<String, Object> btn = (Map<String, Object>) left.get("ctaButton");
				Map<String, Object> style = (Map<String, Object>) btn.get("style");
				html.append("<a href=\"").append(getString(btn, "action", "#"))
						.append("\" style=\"display:inline-block; padding:10px 20px; background:")
						.append(getString(style, "backgroundColor", "#000")).append("; color:")
						.append(getString(style, "textColor", "#fff")).append("; font-weight:")
						.append(getString(style, "fontWeight", "normal"))
						.append("; text-decoration:none; border-radius:4px; margin-top:10px;\">")
						.append(getString(btn, "label", "Click")).append("</a>");
			}

			html.append("</div>");
		}

		// RIGHT COLUMN
		if (section.containsKey("right")) {
			Map<String, Object> right = (Map<String, Object>) section.get("right");
			html.append("<div style=\"flex:1; min-width:300px;\">");

			if (right.containsKey("contactDetails")) {
				Map<String, Object> details = (Map<String, Object>) right.get("contactDetails");

				if (details.containsKey("email")) {
					Map<String, Object> email = (Map<String, Object>) details.get("email");
					html.append("<p><strong>").append(getString(email, "label", "Email")).append(":</strong> ")
							.append("<a href=\"").append(getString(email, "href", "#")).append("\" style=\"color:")
							.append(getString(email, "color", "#00aaff")).append(";\">")
							.append(getString(email, "value", "")).append("</a></p>");
				}
				if (details.containsKey("phone")) {
					Map<String, Object> phone = (Map<String, Object>) details.get("phone");
					html.append("<p><strong>").append(getString(phone, "label", "Phone")).append(":</strong> ")
							.append("<a href=\"").append(getString(phone, "href", "#")).append("\" style=\"color:")
							.append(getString(phone, "color", "#00aaff")).append(";\">")
							.append(getString(phone, "value", "")).append("</a></p>");
				}
				if (details.containsKey("address")) {
					Map<String, Object> addr = (Map<String, Object>) details.get("address");
					html.append("<p><strong>").append(getString(addr, "label", "Address")).append(":</strong><br/>");
					List<String> lines = (List<String>) addr.get("lines");
					for (String line : lines) {
						html.append(line).append("<br/>");
					}
					html.append("</p>");
				}
			}

			if (right.containsKey("socialLinks")) {
				List<Map<String, Object>> socials = (List<Map<String, Object>>) right.get("socialLinks");
				html.append("<div class=\"social-icons\" style=\"margin-top:20px;\">");
				for (Map<String, Object> s : socials) {
					String icon = getString(s, "icon", "");
					String emoji = getIconEmoji(icon);
					html.append("<a href=\"").append(getString(s, "href", "#"))
							.append("\" style=\"margin-right:10px; color:inherit;\">").append(emoji).append("</a>");
				}
				html.append("</div>");
			}

			html.append("</div>");
		}

		html.append("</div>");
		html.append("</section>");

		return html.toString();
	}

	private static String renderHowToBlogPost(Map<String, Object> blog) {
		StringBuilder html = new StringBuilder();
		html.append("<article class=\"how-to-post\" style=\"padding:30px; font-family:sans-serif;\">");

		html.append("<h1>").append(getString(blog, "title", "How to Do Something")).append("</h1>");
		html.append("<p class=\"hook\" style=\"font-style:italic; margin-bottom:20px;\">")
				.append(getString(blog, "hook", "")).append("</p>");

		// Content Section
		if (blog.containsKey("content")) {
			Map<String, Object> content = (Map<String, Object>) blog.get("content");
			html.append("<section class=\"how-to-content\">");
			for (Map.Entry<String, Object> entry : content.entrySet()) {
				html.append("<div class=\"approach\">").append("<h3>").append(formatKey(entry.getKey())).append("</h3>")
						.append("<p>").append(entry.getValue()).append("</p>").append("</div>");
			}
			html.append("</section>");
		}

		// Conclusion Section
		if (blog.containsKey("conclusion")) {
			Map<String, Object> conclusion = (Map<String, Object>) blog.get("conclusion");
			html.append("<section class=\"how-to-conclusion\" style=\"margin-top:20px;\">");

			if (conclusion.containsKey("recap")) {
				html.append("<p><strong>Summary:</strong> ").append(conclusion.get("recap")).append("</p>");
			}
			if (conclusion.containsKey("cta")) {
				html.append("<p><em>").append(conclusion.get("cta")).append("</em></p>");
			}

			html.append("</section>");
		}

		html.append("</article>");
		return html.toString();
	}

	private static String renderBlogListSection(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"blog-list-section\" style=\"padding: 40px; font-family: sans-serif;\">");

		// Title and Subtitle
		html.append("<div class=\"section-header\" style=\"margin-bottom: 30px;\">");
		html.append("<h2>").append(getString(section, "title", "Blog List")).append("</h2>");
		html.append("<p>").append(getString(section, "subtitle", "")).append("</p>");
		html.append("</div>");

		// Blogs
		if (section.containsKey("blogs")) {
			List<Map<String, Object>> blogs = (List<Map<String, Object>>) section.get("blogs");

			html.append("<div class=\"blog-grid\" style=\"display: flex; flex-wrap: wrap; gap: 20px;\">");

			for (Map<String, Object> blog : blogs) {
				html.append("<div class=\"blog-card\" style=\"border: 1px solid #ccc; padding: 20px; width: 300px;\">");

				String img = getString(blog, "image", "");
				if (!img.isEmpty()) {
					html.append("<img src=\"").append(img).append(
							"\" alt=\"blog thumbnail\" style=\"width: 100%; height: auto; margin-bottom: 10px;\"/>");
				}

				html.append("<p style=\"color: gray; font-size: 14px;\">").append(getString(blog, "category", ""))
						.append("</p>");
				html.append("<h3>").append(getString(blog, "title", "")).append("</h3>");
				html.append("<p>").append(getString(blog, "description", "")).append("</p>");
				html.append("<p style=\"font-size: 13px; margin-top: 10px; color: #666;\">By <strong>")
						.append(getString(blog, "author", "")).append("</strong> • ")
						.append(getString(blog, "date", "")).append(" • ").append(getString(blog, "readTime", ""))
						.append("</p>");

				html.append("</div>");
			}

			html.append("</div>");
		}

		// CTA Button
		if (section.containsKey("cta")) {
			Map<String, Object> cta = (Map<String, Object>) section.get("cta");
			html.append("<div class=\"section-cta\" style=\"margin-top: 30px;\">");
			html.append("<a href=\"").append(getString(cta, "link", "#"))
					.append("\" style=\"padding: 10px 20px; background: black; color: white; text-decoration: none;\">")
					.append(getString(cta, "text", "Read More")).append("</a>");
			html.append("</div>");
		}

		html.append("</section>");

		return html.toString();
	}

	private static String renderBlogPreviewSection(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"blog-preview-section\" style=\"padding: 40px; font-family: sans-serif;\">");

		// Section Label
		String sectionLabel = getString(section, "sectionLabel", "");
		if (!sectionLabel.isEmpty()) {
			html.append("<p style=\"text-transform: uppercase; font-size: 13px; color: gray;\">").append(sectionLabel)
					.append("</p>");
		}

		// Heading
		html.append("<h2>").append(getString(section, "heading", "Our Blogs")).append("</h2>");
		html.append("<p>").append(getString(section, "subtext", "")).append("</p>");

		// Blog Grid
		if (section.containsKey("blogs")) {
			List<Map<String, Object>> blogs = (List<Map<String, Object>>) section.get("blogs");

			html.append(
					"<div class=\"blog-preview-grid\" style=\"display: flex; gap: 30px; flex-wrap: wrap; margin-top: 30px;\">");

			for (Map<String, Object> blog : blogs) {
				html.append("<div class=\"blog-card\" style=\"width: 300px; border: 1px solid #eee; padding: 16px;\">");

				String image = getString(blog, "image", "");
				if (!image.isEmpty()) {
					html.append("<img src=\"").append(image)
							.append("\" alt=\"blog\" style=\"width: 100%; height: auto; margin-bottom: 12px;\"/>");
				}

				html.append("<p style=\"font-size: 13px; color: gray;\">").append(getString(blog, "category", ""))
						.append(" • ").append(getString(blog, "readTime", "")).append("</p>");

				html.append("<h3>").append(getString(blog, "title", "")).append("</h3>");
				html.append("<p>").append(getString(blog, "excerpt", "")).append("</p>");

				html.append("<a href=\"").append(getString(blog, "readMoreLink", "#"))
						.append("\" style=\"color: blue; text-decoration: underline;\">Read more</a>");

				html.append("</div>");
			}

			html.append("</div>");
		}

		// View All CTA
		if (section.containsKey("viewAll")) {
			Map<String, Object> viewAll = (Map<String, Object>) section.get("viewAll");
			html.append("<div class=\"view-all\" style=\"margin-top: 30px;\">");
			html.append("<a href=\"").append(getString(viewAll, "link", "#"))
					.append("\" style=\"text-decoration: none; padding: 10px 20px; background: black; color: white;\">")
					.append(getString(viewAll, "text", "View all")).append("</a>");
			html.append("</div>");
		}

		html.append("</section>");

		return html.toString();
	}

	private static String renderBlogHomePage(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<div class=\"blog-home-page\" style=\"font-family: sans-serif; padding: 40px;\">");

		// Logo
		String logo = getString(data, "logo", "Logo");
		html.append("<h1 style=\"font-size: 32px; font-weight: bold;\">").append(logo).append("</h1>");

		// Nav Menu
		if (data.containsKey("navMenu")) {
			List<String> navItems = (List<String>) data.get("navMenu");
			html.append(
					"<nav style=\"margin-top: 10px; margin-bottom: 30px;\"><ul style=\"display: flex; gap: 20px; list-style: none; padding: 0;\">");
			for (String item : navItems) {
				html.append("<li><a href=\"#\" style=\"text-decoration: none; color: black;\">").append(item)
						.append("</a></li>");
			}
			html.append("</ul></nav>");
		}

		// Top Bar Icons
		if (data.containsKey("topBarIcons")) {
			List<String> icons = (List<String>) data.get("topBarIcons");
			html.append("<div class=\"top-bar-icons\" style=\"margin-bottom: 30px;\">");
			for (String icon : icons) {
				String emoji = getIconEmoji(icon);
				html.append("<span style=\"margin-right: 10px;\">").append(emoji).append("</span>");
			}
			html.append("</div>");
		}

		// Hero Section
		if (data.containsKey("heroSection")) {
			Map<String, Object> hero = (Map<String, Object>) data.get("heroSection");
			html.append("<div class=\"hero-section\" style=\"margin-bottom: 40px;\">");
			html.append("<p style=\"font-size: 12px; text-transform: uppercase; color: gray;\">")
					.append(getString(hero, "label", "")).append("</p>");
			html.append("<h2>").append(getString(hero, "title", "")).append("</h2>");
			html.append("<p>").append(getString(hero, "excerpt", "")).append("</p>");
			html.append("<p style=\"color: gray; font-size: 13px;\">By ").append(getString(hero, "author", ""))
					.append(" • ").append(getString(hero, "date", "")).append("</p>");
			html.append("</div>");
		}

		// Editor Pick
		if (data.containsKey("editorPick")) {
			List<Map<String, Object>> picks = (List<Map<String, Object>>) data.get("editorPick");
			html.append("<div class=\"editor-pick\"><h3>Editor's Pick</h3><div style=\"display: flex; gap: 20px;\">");
			for (Map<String, Object> post : picks) {
				html.append("<div class=\"pick-card\">");
				html.append("<img src=\"").append(getString(post, "image", ""))
						.append("\" alt=\"thumb\" style=\"width: 200px; height: auto;\"/>");
				html.append("<p>").append(getString(post, "title", "")).append("</p>");
				html.append("</div>");
			}
			html.append("</div></div>");
		}

		// Trending Section
		if (data.containsKey("trending")) {
			List<Map<String, Object>> trending = (List<Map<String, Object>>) data.get("trending");
			html.append("<div class=\"trending-section\" style=\"margin-top: 40px;\"><h3>Trending</h3>");
			for (Map<String, Object> t : trending) {
				html.append(
						"<div class=\"trend-item\" style=\"margin-bottom: 15px; display: flex; align-items: center; gap: 10px;\">");
				html.append("<img src=\"").append(getString(t, "image", ""))
						.append("\" alt=\"trend\" style=\"width: 60px; height: 60px; object-fit: cover;\"/>");
				html.append("<span>").append(getString(t, "rank", "1")).append(".</span>");
				html.append("<span>").append(getString(t, "title", "")).append("</span>");
				html.append("</div>");
			}
			html.append("</div>");
		}

		html.append("</div>");
		return html.toString();
	}

	private static String renderBlogPage(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<div class=\"blog-page\" style=\"font-family: sans-serif; padding: 40px;\">");

		// Header
		if (data.containsKey("header")) {
			Map<String, Object> header = (Map<String, Object>) data.get("header");
			html.append(
					"<header style=\"display: flex; justify-content: space-between; align-items: center; margin-bottom: 40px;\">");

			// Logo
			html.append("<h1>").append(getString(header, "logo", "Logo")).append("</h1>");

			// Menu
			if (header.containsKey("menu")) {
				List<String> menu = (List<String>) header.get("menu");
				html.append("<nav><ul style=\"display: flex; gap: 20px; list-style: none; padding: 0;\">");
				for (String item : menu) {
					html.append("<li><a href=\"#\" style=\"text-decoration: none; color: black;\">").append(item)
							.append("</a></li>");
				}
				html.append("</ul></nav>");
			}

			// Icons
			html.append("<div style=\"display: flex; gap: 10px;\">");

			if (header.containsKey("socialIcons")) {
				List<String> icons = (List<String>) header.get("socialIcons");
				for (String icon : icons) {
					html.append("<span>").append(getIconEmoji(icon)).append("</span>");
				}
			}
			if (header.containsKey("actions")) {
				List<String> actions = (List<String>) header.get("actions");
				for (String action : actions) {
					html.append("<span>").append(getIconEmoji(action)).append("</span>");
				}
			}

			html.append("</div>");
			html.append("</header>");
		}

		// Hero Section
		if (data.containsKey("heroSection")) {
			Map<String, Object> hero = (Map<String, Object>) data.get("heroSection");
			html.append("<section class=\"hero-section\" style=\"display: flex; gap: 40px; margin-bottom: 40px;\">");

			// Main Post
			if (hero.containsKey("mainPost")) {
				Map<String, Object> main = (Map<String, Object>) hero.get("mainPost");
				html.append("<div style=\"flex: 2;\">");
				html.append("<img src=\"").append(getString(main, "image", ""))
						.append("\" style=\"width: 100%; height: auto;\"/>");
				html.append("<p style=\"font-size: 12px; color: gray;\">").append(getString(main, "category", ""))
						.append("</p>");
				html.append("<h2>").append(getString(main, "title", "")).append("</h2>");
				html.append("<p style=\"font-size: 14px; color: gray;\">By ").append(getString(main, "author", ""))
						.append("</p>");
				html.append("</div>");
			}

			// Featured Side Posts
			if (hero.containsKey("featuredPosts")) {
				List<Map<String, Object>> side = (List<Map<String, Object>>) hero.get("featuredPosts");
				html.append("<div style=\"flex: 1; display: flex; flex-direction: column; gap: 20px;\">");
				for (Map<String, Object> post : side) {
					html.append("<div>");
					html.append("<img src=\"").append(getString(post, "image", ""))
							.append("\" style=\"width: 100%; height: auto;\"/>");
					html.append("<p>").append(getString(post, "title", "")).append("</p>");
					html.append("</div>");
				}
				html.append("</div>");
			}

			html.append("</section>");
		}

		// Post Grid
		if (data.containsKey("postGrid")) {
			List<Map<String, Object>> posts = (List<Map<String, Object>>) data.get("postGrid");
			html.append(
					"<section class=\"post-grid\" style=\"display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px;\">");
			for (Map<String, Object> post : posts) {
				html.append("<div class=\"post-card\">");
				html.append("<img src=\"").append(getString(post, "image", ""))
						.append("\" style=\"width: 100%; height: auto;\"/>");
				html.append("<h3>").append(getString(post, "title", "")).append("</h3>");
				html.append("</div>");
			}
			html.append("</section>");
		}

		html.append("</div>");
		return html.toString();
	}

	private static String renderBlogCardSection(Map<String, Object> blog) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"blog-section\" style=\"padding: 40px; font-family: sans-serif;\">");

		// Heading
		if (blog.containsKey("heading")) {
			Map<String, Object> heading = (Map<String, Object>) blog.get("heading");
			html.append("<div class=\"section-heading\" style=\"text-align: center; margin-bottom: 40px;\">");
			html.append("<h2>").append(getString(heading, "title", "My Blog")).append("</h2>");
			html.append("<p style=\"max-width: 600px; margin: auto; color: gray;\">")
					.append(getString(heading, "description", "")).append("</p>");
			html.append("</div>");
		}

		// Posts
		if (blog.containsKey("posts")) {
			List<Map<String, Object>> posts = (List<Map<String, Object>>) blog.get("posts");

			html.append(
					"<div class=\"blog-grid\" style=\"display: flex; flex-wrap: wrap; gap: 30px; justify-content: center;\">");
			for (Map<String, Object> post : posts) {
				html.append(
						"<div class=\"blog-card\" style=\"width: 300px; border: 1px solid #eee; border-radius: 8px; overflow: hidden;\">");

				html.append("<img src=\"").append(getString(post, "image", ""))
						.append("\" style=\"width: 100%; height: auto;\" />");

				html.append("<div style=\"padding: 20px;\">");
				html.append("<p style=\"color: gray; font-size: 13px;\">").append(getString(post, "date", ""))
						.append(" | ").append(getString(post, "category", "")).append("</p>");
				html.append("<h3 style=\"margin: 10px 0;\">").append(getString(post, "title", "")).append("</h3>");
				html.append("<p style=\"font-size: 14px; color: #555;\">").append(getString(post, "description", ""))
						.append("</p>");
				html.append(
						"<a href=\"#\" style=\"display: inline-block; margin-top: 10px; color: blue; text-decoration: underline;\">")
						.append(getString(post, "cta", "Read More")).append("</a>");
				html.append("</div>");

				html.append("</div>");
			}
			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderBlogThumbnailGrid(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		// Outer Section
		html.append("<section class=\"blog-thumbnail-grid\" style=\"padding: 40px; font-family: sans-serif;\">");

		// Find the <h2> heading
		List<Map<String, Object>> children = (List<Map<String, Object>>) data.getOrDefault("children",
				new ArrayList<>());

		for (Map<String, Object> child : children) {
			String type = getString(child, "type", "");

			if ("h2".equalsIgnoreCase(type)) {
				String title = getString(child, "content", "Featured Insights");
				html.append("<h2 style=\"text-align:center; margin-bottom: 30px;\">").append(title).append("</h2>");
			}

			// Grid Block
			if ("div".equalsIgnoreCase(type) && "blog-grid".equalsIgnoreCase(getString(child, "class", ""))) {
				List<Map<String, Object>> blogCards = (List<Map<String, Object>>) child.getOrDefault("children",
						new ArrayList<>());

				html.append("<div style=\"display: grid; grid-template-columns: repeat(5, 1fr); gap: 20px;\">");

				for (Map<String, Object> card : blogCards) {
					html.append(
							"<div class=\"blog-card\" style=\"border: 1px solid #eee; border-radius: 8px; overflow: hidden; background: #fff;\">");

					List<Map<String, Object>> cardChildren = (List<Map<String, Object>>) card.getOrDefault("children",
							new ArrayList<>());

					for (Map<String, Object> cardChild : cardChildren) {
						String childType = getString(cardChild, "type", "");

						if ("a".equalsIgnoreCase(childType)) {
							String href = getString(cardChild, "href", "#");
							html.append("<a href=\"").append(href).append("\">");

							List<Map<String, Object>> innerChildren = (List<Map<String, Object>>) cardChild
									.getOrDefault("children", new ArrayList<>());

							for (Map<String, Object> inner : innerChildren) {
								if ("img".equalsIgnoreCase(getString(inner, "type", ""))) {
									String src = getString(inner, "src", "default-placeholder.png");
									String alt = getString(inner, "alt", "Image");
									html.append("<img src=\"").append(src).append("\" alt=\"").append(alt)
											.append("\" style=\"width: 100%; height: auto;\">");
								}
							}

							html.append("</a>");
						}

						if ("div".equalsIgnoreCase(childType)
								&& "blog-card-content".equalsIgnoreCase(getString(cardChild, "class", ""))) {
							List<Map<String, Object>> contentItems = (List<Map<String, Object>>) cardChild
									.getOrDefault("children", new ArrayList<>());

							html.append("<div style=\"padding: 15px;\">");

							for (Map<String, Object> contentItem : contentItems) {
								String contentType = getString(contentItem, "type", "");

								if ("p".equalsIgnoreCase(contentType)) {
									String category = getString(contentItem, "content", "");
									html.append("<p style=\"color: gray; font-size: 13px; margin-bottom: 5px;\">")
											.append(category).append("</p>");
								}

								if ("h4".equalsIgnoreCase(contentType)) {
									List<Map<String, Object>> h4Children = (List<Map<String, Object>>) contentItem
											.getOrDefault("children", new ArrayList<>());
									for (Map<String, Object> h4Child : h4Children) {
										String href = getString(h4Child, "href", "#");
										String title = getString(h4Child, "content", "Blog Title");
										html.append("<h4 style=\"margin: 0; font-size: 16px;\"><a href=\"").append(href)
												.append("\" style=\"text-decoration: none; color: black;\">")
												.append(title).append("</a></h4>");
									}
								}

								if ("a".equalsIgnoreCase(contentType)
										&& "read-more".equalsIgnoreCase(getString(contentItem, "class", ""))) {
									String href = getString(contentItem, "href", "#");
									String label = getString(contentItem, "content", "Read More →");
									html.append("<a href=\"").append(href).append(
											"\" style=\"display: block; margin-top: 8px; font-size: 14px; color: #007bff; text-decoration: none;\">")
											.append(label).append("</a>");
								}
							}

							html.append("</div>"); // end card content div
						}
					}

					html.append("</div>"); // end blog-card
				}

				html.append("</div>"); // end grid div
			}
		}

		html.append("</section>"); // end section
		return html.toString();
	}

	private static String renderBlogSection(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"blog-section\" style=\"padding: 40px; font-family: sans-serif;\">");

		// Optional heading
		if (section.containsKey("sectionLabel") || section.containsKey("title") || section.containsKey("heading")) {
			html.append("<div style=\"text-align:center; margin-bottom: 30px;\">");

			if (section.containsKey("sectionLabel")) {
				html.append("<p style=\"color:gray; font-size: 14px;\">").append(section.get("sectionLabel"))
						.append("</p>");
			}
			if (section.containsKey("breadcrumb")) {
				html.append("<p style=\"color:gray; font-size: 14px;\">").append(section.get("breadcrumb"))
						.append("</p>");
			}

			if (section.containsKey("heading")) {
				Object headingObj = section.get("heading");
				if (headingObj instanceof Map) {
					Map<String, Object> heading = (Map<String, Object>) headingObj;
					html.append("<h2>").append(heading.getOrDefault("title", ""))
							.append(" <span style=\"color: #007BFF\">").append(heading.getOrDefault("highlighted", ""))
							.append("</span></h2>");
					html.append("<p>").append(heading.getOrDefault("description", "")).append("</p>");
				} else {
					html.append("<h2>").append(section.get("heading")).append("</h2>");
				}
			} else if (section.containsKey("title")) {
				html.append("<h2>").append(section.get("title")).append("</h2>");
			}

			if (section.containsKey("subtext")) {
				html.append("<p>").append(section.get("subtext")).append("</p>");
			}
			html.append("</div>");
		}

		// Blogs/Articles list
		List<Map<String, Object>> posts = null;
		if (section.containsKey("blogs")) {
			posts = (List<Map<String, Object>>) section.get("blogs");
		} else if (section.containsKey("articles")) {
			posts = (List<Map<String, Object>>) section.get("articles");
		} else if (section.containsKey("posts")) {
			posts = (List<Map<String, Object>>) section.get("posts");
		}

		if (posts != null && !posts.isEmpty()) {
			html.append(
					"<div class=\"blog-grid\" style=\"display:flex; gap:20px; flex-wrap:wrap; justify-content:center;\">");

			for (Map<String, Object> post : posts) {
				String title = getString(post, "title", "Untitled");
				String image = getString(post, "image", "");
				String link = getString(post, "link", "#");
				String category = getString(post, "category", "");
				String date = getString(post, "date", "");
				String readTime = getString(post, "readTime", "");
				String description = getString(post, "description", getString(post, "excerpt", ""));

				html.append(
						"<div style=\"width:280px; background:white; border-radius:8px; box-shadow:0 0 8px rgba(0,0,0,0.05); overflow:hidden;\">");
				if (!image.isEmpty()) {
					html.append("<img src=\"").append(image).append("\" style=\"width:100%; height:auto;\">");
				}
				html.append("<div style=\"padding:16px;\">");
				if (!category.isEmpty())
					html.append("<p style=\"font-size:12px; color:gray; margin:0;\">").append(category).append("</p>");
				html.append("<h4 style=\"margin:8px 0 4px;\"><a href=\"").append(link)
						.append("\" style=\"text-decoration:none; color:black;\">").append(title).append("</a></h4>");
				if (!description.isEmpty())
					html.append("<p style=\"font-size:14px; color:#555;\">").append(description).append("</p>");
				if (!date.isEmpty() || !readTime.isEmpty()) {
					html.append("<p style=\"font-size:12px; color:gray;\">").append(date).append(" ").append(readTime)
							.append("</p>");
				}
				if (post.containsKey("cta")) {
					html.append("<a href=\"").append(link)
							.append("\" style=\"color:blue; text-decoration:underline; font-size:13px;\">")
							.append(post.get("cta")).append("</a>");
				}
				if (post.containsKey("readMoreLink")) {
					html.append("<a href=\"").append(post.get("readMoreLink")).append(
							"\" style=\"color:blue; text-decoration:underline; font-size:13px;\">Read more</a>");
				}
				html.append("</div></div>");
			}
			html.append("</div>");
		}

		// Optional CTA/View All
		if (section.containsKey("viewAll") || section.containsKey("cta")) {
			Map<String, Object> viewAll = (Map<String, Object>) section.getOrDefault("viewAll", section.get("cta"));
			String text = getString(viewAll, "text", "View All");
			String link = getString(viewAll, "link", "#");
			html.append("<div style=\"text-align:center; margin-top: 20px;\"><a href=\"").append(link)
					.append("\" style=\"color:#007BFF; text-decoration:underline; font-weight:bold;\">").append(text)
					.append("</a></div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderArticlePage(Map<String, Object> articlePage) {
		StringBuilder html = new StringBuilder();

		html.append(
				"<article class=\"article-page\" style=\"max-width:800px; margin:auto; padding:40px; font-family:sans-serif;\">");

		// Title & Subtitle
		html.append("<header style=\"margin-bottom:30px;\">");
		html.append("<h1>").append(getString(articlePage, "title", "Untitled")).append("</h1>");
		html.append("<p style=\"color:gray; font-size:18px;\">").append(getString(articlePage, "subtitle", ""))
				.append("</p>");
		html.append("</header>");

		// Cover Image
		String coverImage = getString(articlePage, "coverImage", "");
		if (!coverImage.isEmpty()) {
			html.append("<img src=\"").append(coverImage)
					.append("\" alt=\"cover\" style=\"width:100%; border-radius:8px; margin-bottom:30px;\"/>");
		}

		// Author + Metadata
		if (articlePage.containsKey("author")) {
			Map<String, Object> author = (Map<String, Object>) articlePage.get("author");
			html.append("<div style=\"display:flex; align-items:center; gap:12px; margin-bottom:30px;\">");
			html.append("<img src=\"").append(getString(author, "avatar", ""))
					.append("\" style=\"width:48px; height:48px; border-radius:50%;\" />");
			html.append("<div>");
			html.append("<strong>").append(getString(author, "name", "")).append("</strong><br/>");
			html.append("<small>").append(getString(author, "role", "")).append("</small>");
			html.append("</div>");
			html.append("</div>");
		}

		// Publish Date
		html.append("<p style=\"font-size:14px; color:gray; margin-bottom:30px;\">Published on ")
				.append(getString(articlePage, "publishedDate", "")).append("</p>");

		// Main Content
		if (articlePage.containsKey("content")) {
			List<Map<String, Object>> content = (List<Map<String, Object>>) articlePage.get("content");

			for (Map<String, Object> block : content) {
				String type = getString(block, "type", "");
				switch (type) {
				case "paragraph":
					html.append("<p style=\"line-height:1.8; font-size:16px; margin-bottom:20px;\">")
							.append(getString(block, "text", "")).append("</p>");
					break;
				case "image":
					html.append("<figure style=\"margin-bottom:30px;\">");
					html.append("<img src=\"").append(getString(block, "src", ""))
							.append("\" style=\"width:100%; border-radius:6px;\"/>");
					String caption = getString(block, "caption", "");
					if (!caption.isEmpty()) {
						html.append(
								"<figcaption style=\"text-align:center; font-size:14px; color:gray; margin-top:8px;\">")
								.append(caption).append("</figcaption>");
					}
					html.append("</figure>");
					break;
				case "heading":
					html.append("<h2 style=\"margin-top:30px; margin-bottom:15px;\">")
							.append(getString(block, "text", "")).append("</h2>");
					break;
				}
			}
		}

		// Sidebar
		if (articlePage.containsKey("sidebar")) {
			Map<String, Object> sidebar = (Map<String, Object>) articlePage.get("sidebar");
			html.append("<aside style=\"margin-top:40px; padding-top:20px; border-top:1px solid #ccc;\">");

			if (sidebar.containsKey("categories")) {
				html.append("<h4>Categories</h4><ul>");
				List<String> cats = (List<String>) sidebar.get("categories");
				for (String cat : cats) {
					html.append("<li>").append(cat).append("</li>");
				}
				html.append("</ul>");
			}

			if (sidebar.containsKey("tags")) {
				html.append("<h4>Tags</h4><div style=\"display:flex; gap:10px; flex-wrap:wrap;\">");
				List<String> tags = (List<String>) sidebar.get("tags");
				for (String tag : tags) {
					html.append(
							"<span style=\"background:#f0f0f0; padding:6px 12px; border-radius:20px; font-size:14px;\">")
							.append(tag).append("</span>");
				}
				html.append("</div>");
			}

			html.append("</aside>");
		}

		html.append("</article>");
		return html.toString();
	}

	private static String renderTemplateLibrary(Map<String, Object> lib) {
		StringBuilder html = new StringBuilder();

		html.append(
				"<section class=\"template-library\" style=\"font-family:sans-serif; padding:40px; max-width:1000px; margin:auto;\">");

		// Title and subtitle
		html.append("<header style=\"text-align:center; margin-bottom:30px;\">");
		html.append("<h2>").append(getString(lib, "title", "")).append("</h2>");
		html.append("<p>").append(getString(lib, "subtitle", "")).append("</p>");
		html.append("</header>");

		// Search input
		html.append("<div style=\"text-align:center; margin-bottom:30px;\">");
		html.append("<input type=\"text\" placeholder=\"").append(getString(lib, "searchPlaceholder", "Search"))
				.append("\" ")
				.append("style=\"padding:10px 16px; width:60%; max-width:400px; border:1px solid #ccc; border-radius:6px;\"/>");
		html.append("</div>");

		// Categories
		if (lib.containsKey("categories")) {
			List<String> categories = (List<String>) lib.get("categories");
			html.append(
					"<div class=\"categories\" style=\"display:flex; flex-wrap:wrap; gap:12px; justify-content:center; margin-bottom:40px;\">");
			for (String cat : categories) {
				html.append(
						"<button style=\"padding:8px 16px; border:1px solid #ddd; border-radius:20px; background:white; cursor:pointer;\">")
						.append(cat).append("</button>");
			}
			html.append("</div>");
		}

		// Templates
		if (lib.containsKey("templates")) {
			List<Map<String, Object>> templates = (List<Map<String, Object>>) lib.get("templates");

			html.append(
					"<div class=\"template-grid\" style=\"display:grid; grid-template-columns:repeat(auto-fit, minmax(280px, 1fr)); gap:20px;\">");
			for (Map<String, Object> template : templates) {
				html.append(
						"<div class=\"template-card\" style=\"border:1px solid #eee; border-radius:8px; padding:20px; background:#fafafa;\">");

				html.append("<img src=\"").append(getString(template, "icon", ""))
						.append("\" alt=\"icon\" style=\"width:40px; height:40px; margin-bottom:10px;\"/>");
				html.append("<h4 style=\"margin:10px 0 5px;\">").append(getString(template, "title", ""))
						.append("</h4>");
				html.append("<p style=\"font-size:14px; color:#555;\">").append(getString(template, "description", ""))
						.append("</p>");
				html.append("<span style=\"font-size:12px; color:#888;\">").append(getString(template, "category", ""))
						.append("</span>");

				html.append("</div>");
			}
			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderBlogHeader(Map<String, Object> header) {
		StringBuilder html = new StringBuilder();

		Map<String, Object> style = (Map<String, Object>) header.getOrDefault("style", new HashMap<>());
		String font = getString(style, "font", "sans-serif");
		String primaryColor = getString(style, "primaryColor", "#000");
		String accentColor = getString(style, "accentColor", "#ccc");
		String alignment = getString(style, "alignment", "left");

		// Background images
		Map<String, Object> background = (Map<String, Object>) header.getOrDefault("background", new HashMap<>());
		String topBg = getString(background, "top", "");
		String bottomBg = getString(background, "bottom", "");

		html.append("<section class=\"blog-header\" style=\"text-align:").append(alignment).append("; font-family:")
				.append(font).append("; color:").append(primaryColor)
				.append("; padding: 40px 20px; position: relative;\">");

		if (!topBg.isEmpty()) {
			html.append("<img src=\"").append(topBg).append(
					"\" class=\"bg-top\" style=\"position:absolute; top:0; left:0; width:100%; z-index:-1;\" />");
		}

		if (header.containsKey("date")) {
			html.append("<p style=\"color:").append(accentColor).append("; font-weight: bold;\">")
					.append(header.get("date")).append("</p>");
		}

		if (header.containsKey("title")) {
			html.append("<h1 style=\"margin: 10px 0;\">").append(header.get("title")).append("</h1>");
		}

		if (header.containsKey("subtitle")) {
			html.append("<p style=\"max-width: 700px; margin: 0 auto; font-size: 1.1em;\">")
					.append(header.get("subtitle")).append("</p>");
		}

		if (!bottomBg.isEmpty()) {
			html.append("<img src=\"").append(bottomBg).append(
					"\" class=\"bg-bottom\" style=\"position:absolute; bottom:0; left:0; width:100%; z-index:-1;\" />");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderHeroSection(Map<String, Object> section) {
		String layout = getString(section, "layout", "centered").toLowerCase();
		switch (layout) {
		case "two-column":
			return renderTwoColumnHeroV2(section);
		case "centered":
		default:
			return renderCenteredHeroSection(section); // fallback
		}
	}

	private static String renderCenteredHeroSection(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"hero-section centered-hero\" style=\"background:")
				.append(getString(section, "background", "#fff")).append("; font-family:")
				.append(getString(section, "fontFamily", "sans-serif")).append("; text-align:")
				.append(getString(section, "textAlign", "center")).append("; padding: 60px 20px;\">");

		// Heading
		if (section.containsKey("heading")) {
			Map<String, Object> heading = (Map<String, Object>) section.get("heading");
			html.append("<h1 style=\"font-size:").append(getString(heading, "fontSize", "32px"))
					.append("; font-weight:").append(getString(heading, "fontWeight", "bold")).append("; color:")
					.append(getString(heading, "textColor", "#000")).append(";\">")
					.append(getString(heading, "text", "")).append("</h1>");
		}

		// Description
		if (section.containsKey("description")) {
			Map<String, Object> desc = (Map<String, Object>) section.get("description");
			html.append("<p style=\"font-size:").append(getString(desc, "fontSize", "16px")).append("; color:")
					.append(getString(desc, "textColor", "#333")).append("; max-width:")
					.append(getString(desc, "maxWidth", "600px")).append("; margin:")
					.append(getString(desc, "margin", "0 auto")).append(";\">").append(getString(desc, "text", ""))
					.append("</p>");
		}

		// Buttons
		if (section.containsKey("buttons")) {
			List<Map<String, Object>> buttons = (List<Map<String, Object>>) section.get("buttons");
			html.append(
					"<div class=\"cta-buttons\" style=\"margin-top: 30px; display: flex; justify-content: center; gap: 10px;\">");
			for (Map<String, Object> btn : buttons) {
				String style = getString(btn, "style", "filled");
				String bg = getString(btn, "backgroundColor", "#000");
				String color = getString(btn, "textColor", "#fff");
				String border = "outlined".equals(style) ? "1px solid " + getString(btn, "borderColor", "#000")
						: "none";
				html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" style=\"")
						.append("padding: 10px 20px; background:").append(bg).append("; color:").append(color)
						.append("; border:").append(border)
						.append("; text-decoration:none; border-radius:4px; font-weight:500;\">")
						.append(getString(btn, "label", "Button")).append("</a>");
			}
			html.append("</div>");
		}

		// Image
		if (section.containsKey("image")) {
			Map<String, Object> img = (Map<String, Object>) section.get("image");
			html.append("<img src=\"").append(getString(img, "src", "")).append("\" alt=\"")
					.append(getString(img, "alt", "Image")).append("\" style=\"margin-top:")
					.append(getString(img, "marginTop", "40px")).append("; width:")
					.append(getString(img, "width", "100%")).append("; height:")
					.append(getString(img, "height", "auto")).append("; display:")
					.append(getString(img, "display", "block")).append("; background:")
					.append(getString(img, "backgroundColor", "#e5e5e5")).append(";\"/>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderTwoColumnHeroV2(Map<String, Object> section) {
		String bg = getString(section, "backgroundColor", "#fff");
		String font = getString(section, "fontFamily", "sans-serif");

		Map<String, Object> left = (Map<String, Object>) section.get("leftColumn");
		Map<String, Object> right = (Map<String, Object>) section.get("rightColumn");

		StringBuilder html = new StringBuilder();
		html.append("<section class=\"feature-section\" style=\"background:").append(bg).append("; font-family:")
				.append(font).append(";\">");

		// --- LEFT COLUMN ---
		html.append("<div class=\"feature-content\">");

		// Heading
		if (left.containsKey("heading")) {
			Map<String, Object> heading = (Map<String, Object>) left.get("heading");
			String text = getString(heading, "text", "");
			String highlight = getString(heading, "highlight", "");
			if (!highlight.isEmpty()) {
				text = text.replace(highlight, "<mark>" + highlight + "</mark>");
			}
			html.append("<h2 style=\"font-size:").append(getString(heading, "fontSize", "32px"))
					.append("; font-weight:").append(getString(heading, "fontWeight", "bold")).append("; color:")
					.append(getString(heading, "textColor", "#000")).append(";\">").append(text).append("</h2>");
		}

		// Subheading
		if (left.containsKey("subheading")) {
			Map<String, Object> sub = (Map<String, Object>) left.get("subheading");
			html.append("<p style=\"font-size:").append(getString(sub, "fontSize", "16px")).append("; color:")
					.append(getString(sub, "textColor", "#444")).append(";\">").append(getString(sub, "text", ""))
					.append("</p>");
		}

		// Buttons
		if (left.containsKey("buttons")) {
			html.append("<div class=\"cta-buttons\">");
			List<Map<String, Object>> buttons = (List<Map<String, Object>>) left.get("buttons");
			for (Map<String, Object> btn : buttons) {
				String style = getString(btn, "style", "filled");
				String bgCol = getString(btn, "backgroundColor", "#000");
				String txtCol = getString(btn, "textColor", "#fff");
				String brdCol = getString(btn, "borderColor", "");
				String borderRadius = getString(btn, "borderRadius", "4px");
				String label = getString(btn, "label", "Button");

				html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" style=\"")
						.append("background:").append(style.equals("outlined") ? "transparent" : bgCol).append("; ")
						.append("color:").append(txtCol).append("; ")
						.append("padding:10px 20px; text-decoration:none; border-radius:").append(borderRadius)
						.append("; font-weight:500; ");

				if (style.equals("outlined")) {
					html.append("border:1px solid ").append(brdCol).append(";");
				} else {
					html.append("border:none;");
				}
				html.append("\">").append(label).append("</a>");
			}
			html.append("</div>");
		}

		// Partners
		if (left.containsKey("partners")) {
			Map<String, Object> partners = (Map<String, Object>) left.get("partners");
			html.append("<div style=\"margin-top:20px;\"><strong>").append(getString(partners, "label", ""))
					.append("</strong><div style=\"display:flex; gap:10px; margin-top:10px;\">");

			List<Map<String, Object>> logos = (List<Map<String, Object>>) partners.get("logos");
			for (Map<String, Object> logo : logos) {
				html.append("<img src=\"").append(getString(logo, "src", "#")).append("\" alt=\"")
						.append(getString(logo, "name", "")).append("\" style=\"height:24px;\"/>");
			}
			html.append("</div></div>");
		}

		html.append("</div>"); // end left

		// --- RIGHT COLUMN ---
		html.append("<div>");
		if (right.containsKey("illustration")) {
			Map<String, Object> illus = (Map<String, Object>) right.get("illustration");
			Map<String, Object> styleMap = (Map<String, Object>) illus.get("style");

			StringBuilder style = new StringBuilder();
			if (styleMap != null) {
				style.append("border-radius:").append(getString(styleMap, "borderRadius", "0")).append("; ");
				style.append("background:").append(getString(styleMap, "backgroundColor", "#fff")).append("; ");
				style.append("padding:").append(getString(styleMap, "padding", "0")).append(";");
			}

			html.append("<img src=\"").append(getString(illus, "src", "")).append("\" alt=\"")
					.append(getString(illus, "alt", "")).append("\" style=\"").append(style).append("\" />");
		}

		if (right.containsKey("caption")) {
			Map<String, Object> cap = (Map<String, Object>) right.get("caption");
			html.append("<p style=\"text-align:center; margin-top:10px; font-size:14px; color:#555;\">")
					.append(getString(cap, "text", "")).append("</p>");
		}
		html.append("</div>"); // end right

		html.append("</section>");

		// Decorations
		if (section.containsKey("decorations")) {
			List<Map<String, Object>> shapes = (List<Map<String, Object>>) section.get("decorations");
			for (Map<String, Object> shape : shapes) {
				html.append("<div class=\"decoration ").append(getString(shape, "style", "circle"))
						.append("\" style=\"background:").append(getString(shape, "color", "#ccc"))
						.append(";\"></div>");
			}
		}

		// Scroll Indicator
		if (section.containsKey("scrollIndicator")) {
			Map<String, Object> si = (Map<String, Object>) section.get("scrollIndicator");
			html.append("<div class=\"scroll-indicator ").append(getString(si, "position", "bottom-left"))
					.append("\">↓</div>");
		}

		return html.toString();
	}

	private static String renderTwoColumnHeroSection(Map<String, Object> section) {
		String bg = getString(section, "background", "#fff");
		String font = getString(section, "fontFamily", "sans-serif");

		Map<String, Object> left = (Map<String, Object>) section.get("leftColumn");
		Map<String, Object> right = (Map<String, Object>) section.get("rightColumn");

		StringBuilder html = new StringBuilder();
		html.append("<section style=\"background:").append(bg).append("; font-family:").append(font)
				.append("; padding:60px 40px; display:flex; flex-wrap:wrap; align-items:center; gap:40px;\">");

		// Left Column
		html.append("<div style=\"flex:1; min-width:300px;\">");

		if (left.containsKey("heading")) {
			html.append("<h1 style=\"font-size:28px; font-weight:bold; margin-bottom:20px;\">")
					.append(getString(left, "heading", "")).append("</h1>");
		}

		if (left.containsKey("description")) {
			html.append("<p style=\"font-size:16px; color:#444; margin-bottom:20px;\">")
					.append(getString(left, "description", "")).append("</p>");
		}

		if (left.containsKey("buttons")) {
			html.append(renderButtons(left.get("buttons")));
		}
		html.append("</div>");

		// Right Column
		html.append("<div style=\"flex:1; min-width:300px;\">");
		if (right != null && "image".equalsIgnoreCase(getString(right, "type", ""))) {
			html.append("<img src=\"").append(getString(right, "src", "")).append("\" alt=\"")
					.append(getString(right, "alt", "image")).append("\" style=\"width:")
					.append(getString(right, "width", "100%")).append("; height:")
					.append(getString(right, "height", "auto")).append("; background:")
					.append(getString(right, "backgroundColor", "#ccc")).append(";\"/>");
		}
		html.append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderHeroLeftCards(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"hero-left-cards\">");
		html.append("<div class=\"hero-container\">");

		// Left Column
		if (section.containsKey("leftColumn")) {
			Map<String, Object> left = (Map<String, Object>) section.get("leftColumn");
			html.append("<div class=\"hero-left\">");

			if (left.containsKey("logo")) {
				Map<String, Object> logo = (Map<String, Object>) left.get("logo");
				html.append("<img src=\"").append(logo.get("src")).append("\" alt=\"").append(logo.get("alt"))
						.append("\" class=\"hero-logo\" />");
			}

			if (left.containsKey("label")) {
				html.append("<span class=\"hero-label\">").append(left.get("label")).append("</span>");
			}

			if (left.containsKey("title")) {
				Map<String, Object> title = (Map<String, Object>) left.get("title");
				html.append("<h1 class=\"hero-heading\">").append(title.get("text")).append("</h1>");
			}

			html.append("</div>");
		}

		// Right Column
		if (section.containsKey("rightColumn")) {
			Map<String, Object> right = (Map<String, Object>) section.get("rightColumn");
			List<Map<String, Object>> cards = (List<Map<String, Object>>) right.get("cards");

			html.append("<div class=\"hero-right\">");
			for (Map<String, Object> card : cards) {
				html.append("<div class=\"hero-card\">");

				if (card.containsKey("title")) {
					html.append("<h3>").append(card.get("title")).append("</h3>");
				}

				if (card.containsKey("image")) {
					Map<String, Object> img = (Map<String, Object>) card.get("image");
					html.append("<img src=\"").append(img.get("src")).append("\" alt=\"").append(img.get("alt"))
							.append("\" class=\"card-img\" />");
				}

				if (card.containsKey("buttons")) {
					html.append("<div class=\"card-buttons\">");
					List<Map<String, Object>> buttons = (List<Map<String, Object>>) card.get("buttons");
					for (Map<String, Object> btn : buttons) {
						String btnClass = getString(btn, "class", "btn");
						html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" class=\"")
								.append(btnClass).append("\">").append(btn.get("label")).append("</a>");
					}
					html.append("</div>");
				}

				html.append("</div>");
			}
			html.append("</div>");
		}

		html.append("</div></section>");
		return html.toString();
	}

	private static String renderHeroCenteredWithArt(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"hero-centered-art\">");

		// Artworks
		if (section.containsKey("artwork")) {
			Map<String, Object> art = (Map<String, Object>) section.get("artwork");

			if (art.containsKey("left")) {
				Map<String, Object> left = (Map<String, Object>) art.get("left");
				html.append("<img class=\"hero-art-left\" src=\"").append(left.get("src")).append("\" alt=\"")
						.append(left.get("alt")).append("\" />");
			}
			if (art.containsKey("right")) {
				Map<String, Object> right = (Map<String, Object>) art.get("right");
				html.append("<img class=\"hero-art-right\" src=\"").append(right.get("src")).append("\" alt=\"")
						.append(right.get("alt")).append("\" />");
			}
		}

		// Heading
		if (section.containsKey("heading")) {
			Map<String, Object> heading = (Map<String, Object>) section.get("heading");
			html.append("<h1 class=\"hero-heading\">").append(getString(heading, "text", "").replace("\n", "<br/>"))
					.append("</h1>");
		}

		// CTA
		if (section.containsKey("ctaButton")) {
			Map<String, Object> btn = (Map<String, Object>) section.get("ctaButton");
			html.append("<a href=\"").append(getString(btn, "action", "#")).append("\" class=\"btn-teal\">")
					.append(btn.get("label")).append("</a>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderSubSectionCentered(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"subsection-centered\">");

		if (section.containsKey("title")) {
			html.append("<h2>").append(section.get("title")).append("</h2>");
		}

		if (section.containsKey("description")) {
			html.append("<p>").append(section.get("description")).append("</p>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderSimpleTestimonial(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		String theme = getString(data, "theme", "light");
		html.append("<section class=\"testimonial-section simple-testimonial ").append(theme).append("\">");

		// Heading
		if (data.containsKey("heading")) {
			html.append("<h2 class=\"testimonial-heading\">").append(data.get("heading")).append("</h2>");
		}

		// Check for multiple cards
		if (data.containsKey("cards")) {
			List<Map<String, Object>> cards = (List<Map<String, Object>>) data.get("cards");
			html.append("<div class=\"testimonial-grid\">");

			for (Map<String, Object> card : cards) {
				html.append("<div class=\"testimonial-card\">");
				html.append("<div class=\"stars\">★★★★★</div>");
				html.append("<p>").append(card.get("quote")).append("</p>");

				if (card.containsKey("author")) {
					Map<String, Object> author = (Map<String, Object>) card.get("author");
					html.append("<div class=\"author\">");

					if (author.containsKey("image")) {
						html.append("<img class=\"avatar\" src=\"").append(author.get("image")).append("\" alt=\"")
								.append(author.get("name")).append("\" />");
					}

					html.append("<strong>").append(author.get("name")).append("</strong>");
					html.append("<p>").append(author.get("position")).append("</p>");
					html.append("</div>");
				}

				html.append("</div>");
			}

			html.append("</div>");
		}
		// Fallback: single quote + author + optional logo
		else {
			if (data.containsKey("logo")) {
				Map<String, Object> logo = (Map<String, Object>) data.get("logo");
				html.append("<div class=\"testimonial-logo\">").append("<img src=\"").append(logo.get("src"))
						.append("\" alt=\"").append(logo.get("alt")).append("\" />").append("</div>");
			}

			html.append("<blockquote class=\"testimonial-quote\">").append(data.getOrDefault("quote", ""))
					.append("</blockquote>");

			if (data.containsKey("author")) {
				Map<String, Object> author = (Map<String, Object>) data.get("author");
				html.append("<div class=\"testimonial-author\">");

				if (author.containsKey("image")) {
					html.append("<img class=\"author-img\" src=\"").append(author.get("image"))
							.append("\" alt=\"author\" />");
				}

				html.append("<div class=\"author-details\">").append("<strong>").append(author.get("name"))
						.append("</strong><br/>").append("<span>").append(author.get("position")).append("</span>")
						.append("</div>").append("</div>");
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderClientTestimonial(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"client-testimonial-section\">");

		// Background image
		if (data.containsKey("backgroundImage")) {
			html.append("<div class=\"testimonial-bg\" style=\"background-image: url('")
					.append(data.get("backgroundImage")).append("');\"></div>");
		}

		// Logo
		if (data.containsKey("logo")) {
			html.append("<img class=\"testimonial-logo\" src=\"").append(data.get("logo")).append("\" alt=\"logo\"/>");
		}

		// Title
		html.append("<h2 class=\"testimonial-title\">").append(data.get("title")).append("</h2>");

		// Cards
		if (data.containsKey("testimonials")) {
			List<Map<String, Object>> testimonials = (List<Map<String, Object>>) data.get("testimonials");
			html.append("<div class=\"testimonial-cards\">");
			for (Map<String, Object> t : testimonials) {
				html.append("<div class=\"testimonial-card\">");
				html.append("<img class=\"avatar\" src=\"").append(t.get("image")).append("\" alt=\"")
						.append(t.get("name")).append("\"/>");
				html.append("<blockquote>").append(t.get("quote")).append("</blockquote>");
				html.append("<div class=\"author\">");
				html.append("<strong>").append(t.get("name")).append("</strong><br/>");
				html.append("<span class=\"stars\">").append("★★★★★".substring(0, (int) t.get("rating")))
						.append("</span>");
				html.append("</div></div>");
			}
			html.append("</div>");
		}

		// CTA
		if (data.containsKey("cta")) {
			Map<String, Object> cta = (Map<String, Object>) data.get("cta");
			html.append("<div class=\"testimonial-cta\">").append("<a href=\"").append(cta.get("link"))
					.append("\" class=\"btn btn-filled\">").append(cta.get("label")).append("</a></div>");
		}

		// Contact Info
		if (data.containsKey("contactInfo")) {
			Map<String, Object> contact = (Map<String, Object>) data.get("contactInfo");
			html.append("<div class=\"testimonial-contact\">").append("<p>").append(contact.get("phone")).append("</p>")
					.append("<p><a href=\"mailto:").append(contact.get("email")).append("\">")
					.append(contact.get("email")).append("</a></p>").append("<p><a href=\"https://")
					.append(contact.get("website")).append("\" target=\"_blank\">").append(contact.get("website"))
					.append("</a></p>").append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderTestimonialLanding(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		String theme = getString(data, "theme", "orange");

		html.append("<section class=\"testimonial-landing ").append(theme).append("\">");

		// Title
		html.append("<h2 class=\"landing-title\">").append(data.get("title")).append("</h2>");

		// Description
		if (data.containsKey("description")) {
			html.append("<p class=\"landing-description\">").append(data.get("description")).append("</p>");
		}

		// Testimonials
		if (data.containsKey("testimonials")) {
			List<Map<String, Object>> testimonials = (List<Map<String, Object>>) data.get("testimonials");
			html.append("<div class=\"testimonial-grid\">");
			for (Map<String, Object> t : testimonials) {
				boolean highlight = Boolean.TRUE.equals(t.get("highlight"));
				html.append("<div class=\"testimonial-box").append(highlight ? " highlight" : "").append("\">");
				html.append("<blockquote>").append(t.get("quote")).append("</blockquote>");
				html.append("<p class=\"author-name\">— ").append(t.get("name")).append("</p>");
				html.append("</div>");
			}
			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderFaqSection(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"faq-section\" style=\"font-family: sans-serif; padding: 40px;\">");

		// Title
		if (section.containsKey("title")) {
			html.append("<h2 style=\"text-align:center;\">").append(section.get("title")).append("</h2>");
		}

		// Subtitle
		if (section.containsKey("subtitle")) {
			html.append("<p style=\"text-align:center; max-width:600px; margin: 0 auto 30px; color: gray;\">")
					.append(section.get("subtitle")).append("</p>");
		}

		// Questions
		if (section.containsKey("questions")) {
			List<Map<String, Object>> questions = (List<Map<String, Object>>) section.get("questions");
			html.append("<div class=\"faq-list\" style=\"max-width: 700px; margin:auto;\">");

			for (Map<String, Object> qa : questions) {
				html.append("<div class=\"faq-item\" style=\"margin-bottom: 20px;\">");
				html.append("<h4 style=\"margin-bottom: 8px;\">").append(qa.get("question")).append("</h4>");
				html.append("<p style=\"color: #555;\">").append(qa.get("answer")).append("</p>");
				html.append("</div>");
			}

			html.append("</div>");
		}

		// CTA
		if (section.containsKey("cta")) {
			Map<String, Object> cta = (Map<String, Object>) section.get("cta");

			html.append("<div class=\"faq-cta\" style=\"text-align:center; margin-top:40px;\">");
			html.append("<h3>").append(cta.get("title")).append("</h3>");
			html.append("<p>").append(cta.get("subtitle")).append("</p>");

			if (cta.containsKey("button")) {
				Map<String, Object> btn = (Map<String, Object>) cta.get("button");
				html.append("<a href=\"").append(btn.get("link")).append(
						"\" style=\"display:inline-block; margin-top:10px; padding:10px 20px; background:black; color:white; border-radius:4px; text-decoration:none;\">")
						.append(btn.get("label")).append("</a>");
			}

			html.append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderFaqTwoColumn(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"faq-two-column\" style=\"font-family: sans-serif; padding: 40px;\">");

		// Title
		html.append("<h2 style=\"text-align:center;\">").append(getString(section, "title", "FAQs")).append("</h2>");

		// Description
		html.append("<p style=\"text-align:center; max-width:700px; margin: 0 auto 30px; color: gray;\">")
				.append(getString(section, "description", "")).append("</p>");

		// FAQ Grid
		List<Map<String, Object>> questions = (List<Map<String, Object>>) section.get("questions");
		html.append(
				"<div class=\"faq-grid\" style=\"display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; max-width: 900px; margin: auto;\">");

		for (Map<String, Object> qa : questions) {
			html.append("<div class=\"faq-item\" style=\"background: #f9f9f9; padding: 20px; border-radius: 6px;\">")
					.append("<h4 style=\"margin-bottom: 10px;\">").append(qa.get("question")).append("</h4>")
					.append("<p style=\"color: #555;\">").append(qa.get("answer")).append("</p>").append("</div>");
		}

		html.append("</div>");

		// CTA
		if (section.containsKey("cta")) {
			Map<String, Object> cta = (Map<String, Object>) section.get("cta");
			html.append("<div style=\"text-align:center; margin-top:40px;\">").append("<a href=\"")
					.append(getString(cta, "link", "#"))
					.append("\" style=\"background:black; color:white; padding:10px 20px; border-radius:4px; text-decoration:none;\">")
					.append(getString(cta, "label", "Contact")).append("</a>").append("</div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderFaqIllustrated(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append(
				"<section class=\"faq-illustrated\" style=\"font-family:sans-serif; padding: 40px; max-width: 1000px; margin: auto;\">");

		// Title
		html.append("<h2 style=\"text-align:center; margin-bottom: 20px;\">")
				.append(getString(section, "title", "FAQs")).append("</h2>");

		// Search
		if (section.containsKey("searchPlaceholder")) {
			html.append("<div style=\"text-align:center; margin-bottom:30px;\">")
					.append("<input type=\"text\" placeholder=\"").append(section.get("searchPlaceholder"))
					.append("\" style=\"padding:10px 16px; width:60%; max-width:400px; border:1px solid #ccc; border-radius:6px;\"/>")
					.append("</div>");
		}

		// Illustration
		if (section.containsKey("illustration")) {
			html.append("<div style=\"text-align:center; margin-bottom:30px;\">").append("<img src=\"")
					.append(section.get("illustration"))
					.append("\" alt=\"FAQ Illustration\" style=\"max-width:300px;\"/>").append("</div>");
		}

		// Questions
		List<Map<String, Object>> questions = (List<Map<String, Object>>) section.get("questions");
		html.append("<div class=\"faq-list\" style=\"display: flex; flex-direction: column; gap: 20px;\">");

		for (Map<String, Object> qa : questions) {
			html.append("<div class=\"faq-item\" style=\"background: #f9f9f9; padding: 20px; border-radius: 6px;\">")
					.append("<h4 style=\"margin-bottom: 10px;\">").append(qa.get("question")).append("</h4>")
					.append("<p style=\"color: #555;\">").append(qa.get("answer")).append("</p>").append("</div>");
		}

		html.append("</div>");
		html.append("</section>");
		return html.toString();
	}

	private static String renderDashboardLayout(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<div class=\"dashboard-layout\" style=\"display: flex; font-family: sans-serif;\">");

		// Sidebar
		if (section.containsKey("sidebar")) {
			Map<String, Object> sidebar = (Map<String, Object>) section.get("sidebar");
			List<String> items = (List<String>) sidebar.get("items");
			int active = (int) sidebar.getOrDefault("activeIndex", 0);

			html.append("<aside class=\"sidebar\" style=\"width: 200px; padding: 20px; background: #f0f0f0;\">")
					.append("<ul style=\"list-style:none; padding:0;\">");
			for (int i = 0; i < items.size(); i++) {
				String item = items.get(i);
				boolean isActive = (i == active);
				html.append("<li style=\"margin-bottom: 10px;\">")
						.append("<a href=\"#\" style=\"text-decoration:none; color:").append(isActive ? "blue" : "#333")
						.append("; font-weight:").append(isActive ? "bold" : "normal").append(";\">").append(item)
						.append("</a></li>");
			}
			html.append("</ul></aside>");
		}

		// Main content
		if (section.containsKey("mainContent")) {
			List<Map<String, Object>> main = (List<Map<String, Object>>) section.get("mainContent");
			html.append("<main class=\"main-content\" style=\"flex: 1; padding: 20px;\">");
			for (Map<String, Object> item : main) {
				html.append("<div class=\"content-block\" style=\"margin-bottom: 20px;\">").append("<h3>")
						.append(item.get("title")).append("</h3>").append("</div>");
			}
			html.append("</main>");
		}

		// Right panel
		if (section.containsKey("rightPanel")) {
			Map<String, Object> right = (Map<String, Object>) section.get("rightPanel");
			List<Map<String, Object>> sections = (List<Map<String, Object>>) right.get("sections");
			html.append("<aside class=\"right-panel\" style=\"width: 300px; padding: 20px; background: #fafafa;\">");
			for (Map<String, Object> block : sections) {
				html.append("<div class=\"panel-section\" style=\"margin-bottom: 20px;\">").append("<h4>")
						.append(block.get("title")).append("</h4>").append("<p style=\"color:#555;\">")
						.append(block.get("text")).append("</p>").append("</div>");
			}
			html.append("</aside>");
		}

		html.append("</div>");
		return html.toString();
	}

	private static String renderEcommerceFAQs(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		html.append("<section class=\"ecommerce-faqs\" style=\"font-family:sans-serif; padding:40px;\">");

		// Title
		html.append("<h2 style=\"text-align:center; margin-bottom:30px;\">").append(getString(data, "title", "FAQs"))
				.append("</h2>");

		// Categories
		List<Map<String, Object>> categories = (List<Map<String, Object>>) data.get("categories");
		html.append(
				"<div class=\"faq-categories\" style=\"display:grid; grid-template-columns:repeat(auto-fit, minmax(250px, 1fr)); gap:30px;\">");

		for (Map<String, Object> category : categories) {
			html.append("<div class=\"faq-category\">");
			html.append("<h3>").append(category.get("title")).append("</h3>");

			List<String> questions = (List<String>) category.get("questions");
			html.append("<ul style=\"list-style:disc; padding-left:20px; color:#555;\">");
			for (String q : questions) {
				html.append("<li>").append(q).append("</li>");
			}
			html.append("</ul>");

			html.append("</div>");
		}

		html.append("</div>");
		html.append("</section>");
		return html.toString();
	}

	@SuppressWarnings("unchecked")
	private static String renderLogoCloud(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		String sectionClass = getString(data, "class", "logo-cloud");
		String theme = getString(data, "theme", "");

		html.append("<section class=\"").append(sectionClass);
		if (!theme.isEmpty()) {
			html.append(" theme-").append(theme);
		}
		html.append("\" style=\"padding: 40px; font-family: sans-serif; text-align: center;\">");

		List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");
		if (children != null) {
			for (Map<String, Object> child : children) {
				String childClass = getString(child, "class", "");
				String childType = getString(child, "type", "");

				if ("div".equals(childType)) {
					html.append("<div");
					if (!childClass.isEmpty()) {
						html.append(" class=\"").append(childClass).append("\"");
					}
					html.append(">");

					List<Map<String, Object>> innerChildren = (List<Map<String, Object>>) child.get("children");
					if (innerChildren != null) {
						for (Map<String, Object> inner : innerChildren) {
							String innerType = getString(inner, "type", "");
							String innerClass = getString(inner, "class", "");
							String content = getString(inner, "content", "");

							if ("h2".equals(innerType)) {
								html.append("<h2 style=\"margin-bottom: 30px;\">").append(content).append("</h2>");
							}

							if ("div".equals(innerType)) {
								// 🎯 Call reusable method
								html.append("<div class=\"").append(innerClass).append("\">")
										.append(renderImageDiv(inner)).append("</div>");
							}
						}
					}

					html.append("</div>");
				}
			}
		}

		html.append("</section>");
		return html.toString();
	}

	@SuppressWarnings("unchecked")
	private static String renderLogoShowcase(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		String sectionClass = getString(data, "class", "logo-showcase");
		String theme = getString(data, "theme", "");

		html.append("<section class=\"").append(sectionClass);
		if (!theme.isEmpty()) {
			html.append(" theme-").append(theme);
		}
		html.append("\" style=\"padding: 40px; font-family: sans-serif; text-align: center;\">");

		List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");
		if (children != null) {
			for (Map<String, Object> child : children) {
				String childClass = getString(child, "class", "");
				String childType = getString(child, "type", "");

				if ("div".equals(childType)) {
					html.append("<div");
					if (!childClass.isEmpty()) {
						html.append(" class=\"").append(childClass).append("\"");
					}
					html.append(">");

					List<Map<String, Object>> innerChildren = (List<Map<String, Object>>) child.get("children");
					if (innerChildren != null) {
						for (Map<String, Object> inner : innerChildren) {
							String innerType = getString(inner, "type", "");
							String innerClass = getString(inner, "class", "");
							String href = getString(inner, "href", "");
							String content = getString(inner, "content", "");

							if ("div".equals(innerType)) {
								// 🎯 Use reusable image method here
								html.append(renderImageDiv(inner));
							}
							if ("a".equals(innerType)) {
								html.append("<a href=\"").append(href).append("\" class=\"").append(innerClass)
										.append("\">").append(content).append("</a>");
							}
						}
					}

					html.append("</div>");
				}
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderBrandGuideline(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"brand-guideline\">");

		// Project Info
		Map<String, Object> project = (Map<String, Object>) data.get("project");
		html.append("<div class=\"project-info\">").append("<h2 class=\"brand-title\">")
				.append(getString(project, "name", "")).append("</h2>")
				.append("<p class=\"brand-meta\"><strong>Designer:</strong> ")
				.append(getString(project, "designer", "")).append("</p>")
				.append("<p class=\"brand-meta\"><strong>Client:</strong> ").append(getString(project, "client", ""))
				.append("</p>").append("<p class=\"brand-meta\"><strong>Website:</strong> <a href=\"")
				.append(getString(project, "website", "#")).append("\">").append(getString(project, "website", ""))
				.append("</a></p>").append("<p class=\"brand-meta\"><strong>Logo Date:</strong> ")
				.append(getString(project, "logoDate", "")).append("</p>").append("</div>");

		// Logos
		Map<String, Object> logo = (Map<String, Object>) data.get("logo");
		html.append("<div class=\"logo-section\">").append("<h3 class=\"section-heading\">Logo Variants</h3>");

		html.append("<p class=\"logo-label\">Primary Logo:</p><div class=\"logo-img\"><img src=\"")
				.append(getOrDefaultImage(logo.get("primary")))
				.append("\" alt=\"Primary Logo\" class=\"logo-primary\" /></div>");

		html.append("<p class=\"logo-label\">Icon Logo:</p><div class=\"logo-img\"><img src=\"")
				.append(getOrDefaultImage(logo.get("icon")))
				.append("\" alt=\"Icon Logo\" class=\"logo-icon\" /></div>");

		List<String> mono = (List<String>) logo.get("monochrome");
		if (mono != null && mono.size() == 2) {
			html.append("<p class=\"logo-label\">Monochrome Logos:</p>").append("<div class=\"logo-mono-group\">")
					.append("<img src=\"").append(getOrDefaultImage(mono.get(0)))
					.append("\" alt=\"Black Logo\" class=\"logo-mono\" />").append("<img src=\"")
					.append(getOrDefaultImage(mono.get(1)))
					.append("\" alt=\"White Logo\" class=\"logo-mono white-bg\" />").append("</div>");
		}

		Map<String, Object> social = (Map<String, Object>) logo.get("social");
		html.append("<p class=\"logo-label\">Social Logos:</p>").append("<div class=\"logo-social-group\">")
				.append("<img src=\"").append(getOrDefaultImage(social.get("square")))
				.append("\" alt=\"Social Square\" class=\"logo-social-square\" />").append("<img src=\"")
				.append(getOrDefaultImage(social.get("round")))
				.append("\" alt=\"Social Round\" class=\"logo-social-round\" />").append("</div>").append("</div>");

		// Colors
		List<Map<String, Object>> colors = (List<Map<String, Object>>) data.get("colors");
		html.append("<div class=\"brand-colors\">").append("<h3 class=\"section-heading\">Brand Colors</h3>")
				.append("<div class=\"color-group\">");

		for (Map<String, Object> color : colors) {
			String hex = getString(color, "hex", "#000");
			String slug = color.get("name").toString().toLowerCase().replaceAll("\\s+", "-");
			html.append("<div class=\"color-block ").append(slug).append("\">").append("<p class=\"color-name\">")
					.append(getString(color, "name", "")).append(" (").append(hex).append(")</p>")
					.append("<p class=\"color-usage\">").append(getString(color, "usage", "")).append("</p>")
					.append("</div>");
		}
		html.append("</div></div>");

		// Typography
		Map<String, Object> typography = (Map<String, Object>) data.get("typography");
		html.append("<div class=\"typography-section\">").append("<h3 class=\"section-heading\">Typography</h3>");

		Map<String, Object> headline = (Map<String, Object>) typography.get("headline");
		html.append("<div class=\"font-block\">").append("<p class=\"font-role\">Headline</p>")
				.append("<p class=\"font-family\">").append(getString(headline, "fontFamily", "")).append(" — ")
				.append(getString(headline, "weight", "")).append("</p>").append("</div>");

		Map<String, Object> body = (Map<String, Object>) typography.get("body");
		html.append("<div class=\"font-block\">").append("<p class=\"font-role\">Body</p>")
				.append("<p class=\"font-family\">").append(getString(body, "fontFamily", "")).append(" — ")
				.append(getString(body, "weight", "")).append("</p>").append("</div>").append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String getOrDefaultImage(Object src) {
		String s = src == null ? "" : src.toString().trim();
		return s.isEmpty() ? "/assets/images/placeholder.png" : s;
	}

	private static String renderLogoGrid(List<Map<String, Object>> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"logo-grid-section\" style=\"padding: 40px; font-family: sans-serif;\">")
				.append("<h2 style=\"text-align: center; margin-bottom: 30px;\">Logo Grid</h2>")
				.append("<div class=\"logo-grid\" style=\"display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px;\">");

		for (Map<String, Object> logo : data) {
			html.append(
					"<div class=\"logo-card\" style=\"border: 1px solid #ddd; padding: 16px; border-radius: 8px; background: #fff;\">")
					.append("<h3 style=\"margin: 0 0 10px; font-size: 16px;\">").append(getString(logo, "title", ""))
					.append("</h3>").append("<p style=\"margin: 0; font-size: 14px;\"><strong>Category:</strong> ")
					.append(getString(logo, "category", "")).append("</p>")
					.append("<p style=\"margin: 0; font-size: 14px;\"><strong>Style:</strong> ")
					.append(getString(logo, "style", "")).append("</p>").append("</div>");
		}

		html.append("</div></section>");
		return html.toString();
	}

	private static String renderLogoGuidelines(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"logo-guidelines\" style=\"padding: 40px; font-family: sans-serif;\">");

		// Header info
		html.append("<h2 style=\"text-align:center;\">").append(getString(data, "templateName", "Logo Guidelines"))
				.append("</h2>").append("<p style=\"text-align:center; margin-bottom: 30px;\">Created in ")
				.append(getString(data, "createdIn", "")).append(" • ").append(getString(data, "date", ""))
				.append("</p>");

		// Sections
		List<Map<String, Object>> sections = (List<Map<String, Object>>) data.get("sections");
		if (sections != null) {
			for (Map<String, Object> section : sections) {
				html.append("<div class=\"guideline-section\" style=\"margin-bottom: 30px;\">").append("<h3>")
						.append(getString(section, "title", "")).append("</h3>").append("<p>")
						.append(getString(section, "description", "")).append("</p>");

				// If Cover section
				if ("Cover".equalsIgnoreCase(getString(section, "title", "")) && section.containsKey("content")) {
					Map<String, Object> content = (Map<String, Object>) section.get("content");
					html.append(
							"<div class=\"cover-info\" style=\"margin-top: 10px; padding: 10px; border-left: 3px solid #000;\">")
							.append("<p><strong>Version:</strong> ").append(getString(content, "version", ""))
							.append("</p>").append("<h4>").append(getString(content, "title", "")).append("</h4>")
							.append("<p>").append(getString(content, "subtitle", "")).append("</p>").append("</div>");
				}

				// If Typography section
				if ("Typography".equalsIgnoreCase(getString(section, "title", "")) && section.containsKey("font")) {
					Map<String, Object> font = (Map<String, Object>) section.get("font");
					html.append("<div class=\"font-preview\" style=\"font-family: ").append(getString(font, "name", ""))
							.append("; font-size: 24px; margin-top: 10px;\">Aa</div>")
							.append("<p style=\"font-size: 14px; color: #666;\"><strong>")
							.append(getString(font, "name", "")).append("</strong> - ")
							.append(getString(font, "usage", "")).append("</p>");
				}

				html.append("</div>");
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderTeamSection(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append(
				"<section class=\"team-section\" style=\"padding: 40px; text-align: center; font-family: sans-serif;\">");

		// Title & Description
		html.append("<h2>").append(getString(data, "title", "Our Team")).append("</h2>");
		html.append("<p style=\"max-width: 600px; margin: 10px auto 30px;\">")
				.append(getString(data, "description", "")).append("</p>");

		// Team Members
		List<Map<String, Object>> members = (List<Map<String, Object>>) data.get("members");
		if (members != null && !members.isEmpty()) {
			html.append(
					"<div class=\"team-grid\" style=\"display: flex; flex-wrap: wrap; justify-content: center; gap: 30px;\">");
			for (Map<String, Object> member : members) {
				html.append("<div class=\"team-member\" style=\"width: 220px; text-align: center;\">")
						.append("<img src=\"").append(getString(member, "image", "")).append("\" alt=\"")
						.append(getString(member, "name", "")).append("\" style=\"width: 100%; border-radius: 8px;\">")
						.append("<h4 style=\"margin: 10px 0 5px;\">").append(getString(member, "name", ""))
						.append("</h4>").append("<p style=\"color: gray; font-size: 14px; margin-bottom: 10px;\">")
						.append(getString(member, "role", "")).append("</p>");

				// Socials
				List<String> socials = (List<String>) member.get("socials");
				if (socials != null && !socials.isEmpty()) {
					html.append(
							"<div class=\"team-socials\" style=\"display: flex; justify-content: center; gap: 10px;\">");
					for (String social : socials) {
						html.append("<a href=\"#\" class=\"social-icon ").append(social).append("\" title=\"")
								.append(social).append("\" style=\"text-decoration: none; font-size: 16px;\">")
								.append("<i class=\"fab fa-").append(social).append("\"></i></a>");
					}
					html.append("</div>");
				}

				html.append("</div>");
			}
			html.append("</div>");
		}

		// CTA Button
		if (data.containsKey("button")) {
			Map<String, Object> button = (Map<String, Object>) data.get("button");
			html.append("<div class=\"team-cta\" style=\"margin-top: 30px;\">").append("<a href=\"")
					.append(button.get("link"))
					.append("\" class=\"btn btn-primary\" style=\"padding: 10px 20px; background: black; color: white; text-decoration: none; border-radius: 4px;\">")
					.append(button.get("label")).append("</a></div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderTeamSectionTemplate(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		String title = getString(data, "title", "Team");
		html.append("<section class=\"team-section-template\" style=\"padding: 40px; font-family: sans-serif;\">")
				.append("<h2 style=\"text-align: center;\">").append(title).append("</h2>");

		List<Map<String, Object>> variations = (List<Map<String, Object>>) data.get("variations");
		if (variations != null) {
			for (Map<String, Object> variation : variations) {
				String layout = getString(variation, "layout", "grid");
				String sectionTitle = getString(variation, "sectionTitle", "");

				html.append("<div class=\"team-variation ").append(layout).append("\" style=\"margin-top: 40px;\">");
				html.append("<h3 style=\"text-align: center;\">").append(sectionTitle).append("</h3>");

				if ("highlighted-center".equals(layout)) {
					// Highlighted member at top
					Map<String, Object> highlighted = (Map<String, Object>) variation.get("highlightedMember");
					if (highlighted != null) {
						html.append(
								"<div class=\"highlighted-member\" style=\"text-align: center; margin-bottom: 30px;\">")
								.append("<img src=\"").append(highlighted.get("image")).append("\" alt=\"")
								.append(highlighted.get("name"))
								.append("\" style=\"width: 160px; border-radius: 50%;\">").append("<h4>")
								.append(highlighted.get("name")).append("</h4>").append("<p>")
								.append(highlighted.get("role")).append("</p>")
								.append("<p style=\"max-width: 500px; margin: 0 auto;\">")
								.append(highlighted.get("bio")).append("</p>");

						List<String> socials = (List<String>) highlighted.get("socials");
						if (socials != null) {
							html.append("<div class=\"highlighted-socials\" style=\"margin-top: 10px;\">");
							for (String soc : socials) {
								html.append("<a href=\"#\" style=\"margin: 0 5px;\"><i class=\"fab fa-").append(soc)
										.append("\"></i></a>");
							}
							html.append("</div>");
						}

						html.append("</div>");
					}
				}

				// Team grid
				List<Map<String, Object>> members = (List<Map<String, Object>>) variation.get("members");
				if (members != null && !members.isEmpty()) {
					html.append(
							"<div class=\"team-grid\" style=\"display: flex; flex-wrap: wrap; justify-content: center; gap: 30px;\">");
					for (Map<String, Object> member : members) {
						html.append("<div class=\"team-card\" style=\"width: 200px; text-align: center;\">")
								.append("<img src=\"").append(member.get("image")).append("\" alt=\"")
								.append(member.get("name")).append("\" style=\"width: 100%; border-radius: 8px;\">")
								.append("<h4>").append(member.get("name")).append("</h4>")
								.append("<p style=\"color: gray; font-size: 14px;\">").append(member.get("role"))
								.append("</p>").append("</div>");
					}
					html.append("</div>");
				}

				html.append("</div>");
			}
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderTeamSlider(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		String title = getString(data, "title", "Our Team");
		String subtitle = getString(data, "subtitle", "");

		html.append("<section class=\"team-slider-section\">").append("<h2>").append(title).append("</h2>")
				.append("<p>").append(subtitle).append("</p>").append("<div class=\"team-slider\">");

		List<Map<String, Object>> members = (List<Map<String, Object>>) data.get("members");
		if (members != null) {
			for (Map<String, Object> member : members) {
				html.append("<div class=\"team-member\">").append("<img src=\"").append(member.get("photo"))
						.append("\" alt=\"").append(member.get("name")).append("\" />").append("<h4>")
						.append(member.get("name")).append("</h4>").append("<p>").append(member.get("role"))
						.append("</p>").append("<p>").append(member.get("bio")).append("</p>");

				List<Map<String, Object>> socials = (List<Map<String, Object>>) member.get("socials");
				if (socials != null) {
					html.append("<div class=\"social-icons\">");
					for (Map<String, Object> soc : socials) {
						String platform = getString(soc, "platform", "");
						String link = getString(soc, "link", "#");
						html.append("<a href=\"").append(link).append("\" target=\"_blank\">")
								.append("<i class=\"fab fa-").append(platform).append("\"></i></a>");
					}
					html.append("</div>");
				}

				String profileLink = getString(member, "profileLink", "");
				if (!profileLink.isEmpty()) {
					html.append("<div><a href=\"").append(profileLink)
							.append("\" class=\"profile-link\">View Profile</a></div>");
				}

				html.append("</div>");
			}
		}

		html.append("</div></section>");
		return html.toString();
	}

	private static String renderSmartHeader(Map<String, Object> node) {
		if (node.containsKey("buttons")) {
			return renderHeaderWithButtons(node); // Case: logo + nav + buttons
		} else if (node.containsKey("navMenu") || node.containsKey("icons")) {
			return renderCustomHeader(node); // Case: navMenu with dropdowns/icons
		} else {
			return wrapTag("header", "navbar-1", node); // Fallback to generic header wrapper
		}
	}

	private static String renderSmartHeroSection(Map<String, Object> node) {
		String layout = getString(node, "layout", "").toLowerCase();

		if ((layout.contains("centered") || layout.equals("")) && node.containsKey("heading")) {
			return renderHeroCenteredSection(node); // hero-centered
		}

		if (layout.contains("left-text-right-cards")) {
			return renderHeroLeftCards(node);
		}

		if (layout.contains("two-column") || node.containsKey("rightImage") || node.containsKey("leftColumn")) {
			return renderHeroTwoColumn(node); // 🔁 Standardized to use this one
		}

		return wrapTag("section", "hero-section", node); // fallback
	}

	private static String renderHeroTwoColumn(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"hero-section\">");

		// Left Content
		html.append("<div class=\"hero-left\">");

		Map<String, Object> heading = (Map<String, Object>) data.get("heading");
		html.append("<h1 class=\"").append(heading.get("class")).append("\">").append(heading.get("text"))
				.append("</h1>");

		Map<String, Object> subheading = (Map<String, Object>) data.get("subheading");
		html.append("<p class=\"").append(subheading.get("class")).append("\">").append(subheading.get("text"))
				.append("</p>");

		List<Map<String, Object>> ctaButtons = (List<Map<String, Object>>) data.get("ctaButtons");
		html.append("<div class=\"hero-buttons\">");
		for (Map<String, Object> btn : ctaButtons) {
			html.append("<button class=\"").append(btn.get("class")).append("\">").append(btn.get("label"))
					.append("</button>");
		}
		html.append("</div></div>");

		// Right Image
		Map<String, Object> image = (Map<String, Object>) data.get("rightImage");
		html.append("<div class=\"hero-right\">").append("<img class=\"").append(image.get("class")).append("\" src=\"")
				.append(image.get("src")).append("\" alt=\"").append(image.get("alt")).append("\">").append("</div>");

		html.append("</section>");
		return html.toString();
	}

	private static String renderCenteredSectionWithImage(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"hero-centered\">\n");

		// Tagline
		Map<String, Object> tagline = (Map<String, Object>) data.get("tagline");
		if (tagline != null) {
			html.append("<p class=\"hero-label\">" + tagline.get("text") + "</p>\n");
		}

		// Heading
		Map<String, Object> heading = (Map<String, Object>) data.get("heading");
		if (heading != null) {
			html.append("<h2 class=\"hero-heading\">" + heading.get("text") + "</h2>\n");
		}

		// Description
		Map<String, Object> desc = (Map<String, Object>) data.get("description");
		if (desc != null) {
			html.append("<p class=\"hero-description\">" + desc.get("text") + "</p>\n");
		}

		// Buttons
		List<Map<String, Object>> buttons = (List<Map<String, Object>>) data.get("buttons");
		if (buttons != null && !buttons.isEmpty()) {
			html.append("<div class=\"hero-buttons\">\n");
			for (Map<String, Object> btn : buttons) {
				String label = (String) btn.get("label");
				String style = (String) btn.get("style");
				String cssClass = "filled".equalsIgnoreCase(style) ? "btn-filled" : "btn-outlined";
				html.append("<a href=\"#\" class=\"" + cssClass + "\">" + label + "</a>\n");
			}
			html.append("</div>\n");
		}

		// Image
		Map<String, Object> image = (Map<String, Object>) data.get("image");
		if (image != null) {
			html.append("<img class=\"hero-image\" src=\"" + image.get("src") + "\" alt=\"" + image.get("alt")
					+ "\" style=\"height:" + image.get("height") + ";\"/>\n");
		}

		html.append("</section>\n");
		return html.toString();
	}

	@SuppressWarnings("unchecked")
	private static List<Map<String, Object>> getChildren(Map<String, Object> node) {
		Object children = node.get("children");
		if (children instanceof List) {
			return (List<Map<String, Object>>) children;
		}
		return Collections.emptyList();
	}

	private static String renderHeroCenteredHeadingSplit(Map<String, Object> section) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"hero-centered\">");

		// Heading with split text
		Map<String, Object> heading = (Map<String, Object>) section.get("heading");
		if (heading != null && heading.containsKey("textParts")) {
			html.append("<h1 class=\"hero-heading\">");
			List<Map<String, Object>> parts = (List<Map<String, Object>>) heading.get("textParts");
			for (Map<String, Object> part : parts) {
				String text = (String) part.getOrDefault("text", "");
				String spanClass = (String) part.getOrDefault("class", "");
				html.append("<span class=\"").append(spanClass).append("\">").append(text).append("</span> ");
			}
			html.append("</h1>");
		}

		// Description
		Map<String, Object> description = (Map<String, Object>) section.get("description");
		if (description != null) {
			html.append("<p class=\"hero-description\">").append(description.get("text")).append("</p>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String renderHeaderWithButtons(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<header class=\"navbar-1\">");

		// Logo
		Map<String, Object> logo = (Map<String, Object>) data.get("logo");
		html.append("<div class=\"logo-1\"><img src=\"").append(logo.get("src")).append("\" alt=\"")
				.append(logo.get("alt")).append("\"></div>");

		// Nav Links
		Map<String, Object> navLinks = (Map<String, Object>) data.get("navLinks");
		List<Map<String, Object>> items = (List<Map<String, Object>>) navLinks.get("items");
		html.append("<ul class=\"nav-1\">");
		for (Map<String, Object> item : items) {
			html.append("<li><a href=\"").append(item.get("href")).append("\">").append(item.get("label"))
					.append("</a></li>");
		}
		html.append("</ul>");

		// Buttons
		html.append("<div class=\"hero-buttons\">");
		List<Map<String, Object>> buttons = (List<Map<String, Object>>) data.get("buttons");
		for (Map<String, Object> btn : buttons) {
			html.append("<button class=\"").append(btn.get("class")).append("\">").append(btn.get("label"))
					.append("</button>");
		}
		html.append("</div>");

		html.append("</header>");
		return html.toString();
	}

	private static String renderCustomHeader(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<header class=\"mega-navbar\">");

		// Logo
		if (data.containsKey("logo")) {
			Map<String, Object> logo = (Map<String, Object>) data.get("logo");
			html.append("<div class=\"logo-1\">").append(logo.get("text")).append("</div>");
		}

		// Site Info
		if (data.containsKey("siteInfo")) {
			Map<String, Object> site = (Map<String, Object>) data.get("siteInfo");
			html.append("<div class=\"site-info\">");
			html.append("<h2>").append(site.get("title")).append("</h2>");
			html.append("<p>").append(site.get("description")).append("</p>");
			html.append("</div>");
		}

		// Navigation
		if (data.containsKey("navMenu")) {
			Map<String, Object> nav = (Map<String, Object>) data.get("navMenu");
			List<Map<String, Object>> links = (List<Map<String, Object>>) nav.get("links");

			html.append("<ul class=\"nav-1\">");
			for (Map<String, Object> link : links) {
				boolean isActive = Boolean.TRUE.equals(link.get("active"));
				boolean isDropdown = Boolean.TRUE.equals(link.get("dropdown"));
				String label = (String) link.get("label");
				String href = (String) link.getOrDefault("href", "#");

				if (isDropdown) {
					html.append("<li class=\"dropdown\"><a href=\"").append(href).append("\">").append(label)
							.append("</a><div class=\"dropdown-content\"><div class=\"dropdown-columns\">")
							.append("<div class=\"column\"><h4>Menu</h4><ul><li><span>📦</span><strong>Dropdown</strong><p>Sample</p></li></ul></div>")
							.append("</div></div></li>");
				} else {
					html.append("<li><a href=\"").append(href).append("\"")
							.append(isActive ? " style=\"color:#ffffff; background:#00acc1;\"" : "").append(">")
							.append(label).append("</a></li>");
				}
			}
			html.append("</ul>");
		}

		// Icons
		if (data.containsKey("icons")) {
			html.append("<div class=\"navbar-actions\">");
			List<Map<String, Object>> icons = (List<Map<String, Object>>) data.get("icons");
			for (Map<String, Object> icon : icons) {
				html.append("<span>").append(icon.get("symbol")).append("</span> ");
			}
			html.append("</div>");
		}

		html.append("</header>");
		return html.toString();
	}

	private static String renderTeamShowcase(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();
		html.append("<section class=\"team-showcase\">");

		html.append("<h2>").append(data.get("title")).append("</h2>");
		html.append("<p class=\"subtitle\">").append(data.get("subtitle")).append("</p>");

		List<Map<String, Object>> groups = (List<Map<String, Object>>) data.get("groups");
		for (Map<String, Object> group : groups) {
			html.append("<div class=\"group\">");
			html.append("<h3>").append(group.get("groupName")).append("</h3>");
			html.append("<div class=\"member-grid\">");

			List<Map<String, Object>> members = (List<Map<String, Object>>) group.get("members");
			for (Map<String, Object> member : members) {
				html.append("<div class=\"member\">");
				html.append("<img src=\"").append(member.get("image")).append("\" alt=\"").append(member.get("name"))
						.append("\"/>");
				html.append("<div class=\"name\">").append(member.get("name")).append("</div>");
				html.append("<div class=\"role\">").append(member.get("role")).append("</div>");
				html.append("</div>");
			}

			html.append("</div></div>");
		}

		html.append("</section>");
		return html.toString();
	}

	private static String formatKey(String key) {
		key = key.replaceAll("([a-z])([A-Z])", "$1 $2"); // camelCase to space
		key = key.substring(0, 1).toUpperCase() + key.substring(1); // capitalize first
		return key.replace("-", " ");
	}

	private static String getIconEmoji(String label) {
		label = label.toLowerCase();
		if (label.contains("facebook"))
			return "📘";
		if (label.contains("instagram"))
			return "📷";
		if (label.equals("x"))
			return "𝕏";
		if (label.contains("search"))
			return "🔍";
		if (label.contains("profile"))
			return "👤";
		if (label.contains("twitter"))
			return "🐦";

		if (label.contains("linkedin"))
			return "🔗";
		if (label.contains("youtube"))
			return "▶️";
		return "📦";
	}

	private static void appendStyle(StringBuilder style, String key, Object value) {
		if (value != null) {
			style.append(key).append(":").append(value).append("; ");
		}
	}

	private static String getWidgetIcon(String widget) {
		widget = widget.toLowerCase();
		if (widget.contains("search"))
			return "🔍";
		if (widget.contains("recent"))
			return "📝";
		if (widget.contains("newsletter"))
			return "📬";
		return "📦";
	}

	private static String getString(Map<String, Object> map, String key, String defaultValue) {
		Object val = map.get(key);
		return val instanceof String ? (String) val : defaultValue;
	}

	private static String renderImageDiv(Map<String, Object> data) {
		StringBuilder html = new StringBuilder();

		// Get attributes from JSON
//		String className = getString(data, "class", "placeholder-img");
		String className = "placeholder-img";
		String src = getString(data, "src", "/src/assets/images/place.png");
		String width = getString(data, "width", ""); // optional
		String height = getString(data, "height", ""); // optional

		// Fallback to default image if src is missing or blank
		if (src.isEmpty()) {
			src = "/src/assets/images/place.png";
		}

		// Build style
		StringBuilder style = new StringBuilder();
		style.append("background-image: url('").append(src).append("');");

		// Add inline height/width only if provided, else CSS will handle default
		if (!width.isEmpty()) {
			style.append(" width: ").append(width).append(";");
		}
		if (!height.isEmpty()) {
			style.append(" height: ").append(height).append(";");
		}

		// Return final div
		html.append("<div class=\"").append(className).append("\" style=\"").append(style).append("\"></div>");

		return html.toString();
	}

}
