/*
 * MỘC MIÊN RESPONSIVE ENGINE
 * Safe baseline: fluid sizing and small-screen layout rules.
 * Desktop layout is intentionally left untouched (>=1200px).
 */

/* Global sizing safeguards */
html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

body:not(.mmre-disable-images) img,
body:not(.mmre-disable-images) video,
body:not(.mmre-disable-images) iframe,
body:not(.mmre-disable-images) embed,
body:not(.mmre-disable-images) object {
	max-width: 100%;
}

body:not(.mmre-disable-images) img,
body:not(.mmre-disable-images) video {
	height: auto;
}

body:not(.mmre-disable-images) svg {
	max-width: 100%;
}

@media (max-width: 1199px) {
	/* Apply sizing safeguards only below desktop width to preserve desktop geometry. */
	*, *::before, *::after {
		box-sizing: border-box;
	}

	/* Prevent fixed-width theme containers from exceeding the viewport. */
	body:not(.mmre-disable-header) .ast-container,
	body:not(.mmre-disable-header) .site-content .ast-container,
	body:not(.mmre-disable-elementor) .elementor-section.elementor-section-boxed > .elementor-container,
	body:not(.mmre-disable-elementor) .e-con,
	body:not(.mmre-disable-woocommerce) .woocommerce,
	body:not(.mmre-disable-woocommerce).woocommerce-page .site-content {
		max-width: 100%;
	}

	body:not(.mmre-disable-header) .ast-container,
	body:not(.mmre-disable-header) .site-content .ast-container {
		padding-left: clamp(16px, 3vw, 28px);
		padding-right: clamp(16px, 3vw, 28px);
	}
}

@media (max-width: 1024px) {
	/* Tablet: Elementor columns may wrap rather than overflow. */
	body:not(.mmre-disable-elementor) .elementor-section .elementor-container {
		flex-wrap: wrap;
	}

	body:not(.mmre-disable-elementor) .elementor-widget-wrap,
	body:not(.mmre-disable-elementor) .elementor-widget-container,
	body:not(.mmre-disable-elementor) .e-con-inner {
		min-width: 0;
	}

	/* Fluid text prevents long headings from forcing horizontal scroll. */
	h1, .entry-title {
		overflow-wrap: anywhere;
	}
}

@media (max-width: 767px) {
	/* Mobile page gutters */
	body:not(.mmre-disable-header) .ast-container,
	body:not(.mmre-disable-header) .site-content .ast-container,
	body:not(.mmre-disable-elementor) .elementor-section.elementor-section-boxed > .elementor-container,
	body:not(.mmre-disable-elementor) .e-con,
	body:not(.mmre-disable-woocommerce) .woocommerce,
	body:not(.mmre-disable-woocommerce).woocommerce-page .site-content {
		width: 100%;
		max-width: 100%;
	}

	body:not(.mmre-disable-header) .ast-container,
	body:not(.mmre-disable-header) .site-content .ast-container {
		padding-left: 16px;
		padding-right: 16px;
	}

	/* Elementor: stack columns and containers unless a widget explicitly needs a row. */
	body:not(.mmre-disable-elementor) .elementor-section .elementor-container {
		display: flex;
		flex-wrap: wrap;
	}

	body:not(.mmre-disable-elementor) .elementor-column,
	body:not(.mmre-disable-elementor) .elementor-widget-wrap,
	body:not(.mmre-disable-elementor) .e-con,
	body:not(.mmre-disable-elementor) .e-con-inner {
		min-width: 0;
		max-width: 100%;
	}

	body:not(.mmre-disable-elementor) .elementor-column {
		width: 100%;
	}

	/* Avoid fixed media dimensions from desktop layouts. */
	body:not(.mmre-disable-images) .elementor-widget-image img,
	body:not(.mmre-disable-images) .wp-block-image img,
	body:not(.mmre-disable-images) .woocommerce-product-gallery img {
		max-width: 100%;
		height: auto;
		object-fit: contain;
	}

	/* Flexible headings and text; preserve authored typography scale where possible. */
	body:not(.mmre-disable-elementor) h1,
	body:not(.mmre-disable-elementor) .entry-content h1 {
		font-size: clamp(1.7rem, 7vw, 2.35rem);
		line-height: 1.15;
	}

	body:not(.mmre-disable-elementor) h2,
	body:not(.mmre-disable-elementor) .entry-content h2 {
		font-size: clamp(1.35rem, 5.5vw, 1.85rem);
		line-height: 1.2;
	}

	/* Long content should wrap instead of forcing viewport overflow. */
	body p, body li, body td, body th, body label,
	body:not(.mmre-disable-elementor) .elementor-heading-title {
		overflow-wrap: anywhere;
	}

	/* Astra content columns */
	#primary,
	#secondary,
	.ast-left-sidebar #primary,
	.ast-right-sidebar #primary {
		width: 100%;
	}

	/* Tables that are not explicitly responsive can scroll within their own area. */
	.entry-content table:not(.shop_table),
	body:not(.mmre-disable-woocommerce) .woocommerce table.shop_table {
		display: block;
		width: 100%;
		max-width: 100%;
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
	}

	/* Checkout and account forms */
	body:not(.mmre-disable-forms) .woocommerce form .form-row,
	body:not(.mmre-disable-forms) .woocommerce-page form .form-row {
		float: none;
		width: 100%;
	}

	body:not(.mmre-disable-forms) .woocommerce form .form-row-first,
	body:not(.mmre-disable-forms) .woocommerce form .form-row-last {
		width: 100%;
	}

	body:not(.mmre-disable-forms) .woocommerce form .input-text,
	body:not(.mmre-disable-forms) .woocommerce form select,
	body:not(.mmre-disable-forms) .woocommerce form textarea,
	body:not(.mmre-disable-forms) .woocommerce-page form .input-text,
	body:not(.mmre-disable-forms) .woocommerce-page form select,
	body:not(.mmre-disable-forms) .woocommerce-page form textarea {
		width: 100%;
		max-width: 100%;
		min-width: 0;
	}

	/* Product listing: use a stable two-column grid on phones. */
	body:not(.mmre-disable-woocommerce) .woocommerce ul.products,
	body:not(.mmre-disable-woocommerce) .woocommerce-page ul.products {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 14px 10px;
		margin-left: 0;
		margin-right: 0;
	}

	body:not(.mmre-disable-woocommerce) .woocommerce ul.products::before,
	body:not(.mmre-disable-woocommerce) .woocommerce ul.products::after {
		display: none;
	}

	body:not(.mmre-disable-woocommerce) .woocommerce ul.products li.product,
	body:not(.mmre-disable-woocommerce) .woocommerce-page ul.products li.product {
		float: none;
		width: auto;
		min-width: 0;
		max-width: 100%;
		margin: 0;
	}

	body:not(.mmre-disable-woocommerce) .woocommerce ul.products li.product a img {
		width: 100%;
		height: auto;
		object-fit: cover;
	}

	/* Single product: stack gallery and summary. */
	body:not(.mmre-disable-woocommerce) .single-product div.product {
		display: flex;
		flex-direction: column;
		gap: 22px;
	}

	body:not(.mmre-disable-woocommerce) .single-product div.product .woocommerce-product-gallery,
	body:not(.mmre-disable-woocommerce) .single-product div.product .summary {
		float: none;
		width: 100%;
		max-width: 100%;
		margin: 0;
	}

	body:not(.mmre-disable-woocommerce) .single-product div.product .summary.entry-summary {
		padding: clamp(18px, 5vw, 26px) !important;
	}

	body:not(.mmre-disable-woocommerce) .single-product .summary .woocommerce-breadcrumb {
		white-space: normal;
		overflow-wrap: anywhere;
	}

	body:not(.mmre-disable-woocommerce) .single-product .quantity,
	body:not(.mmre-disable-woocommerce) .single-product .single_add_to_cart_button {
		max-width: 100%;
	}

	/* Cart action controls */
	body:not(.mmre-disable-woocommerce) .woocommerce-cart .coupon,
	body:not(.mmre-disable-woocommerce) .woocommerce-cart .actions .button,
	body:not(.mmre-disable-woocommerce) .woocommerce-cart .wc-proceed-to-checkout a.checkout-button {
		max-width: 100%;
	}

	body:not(.mmre-disable-woocommerce) .woocommerce-cart .wc-proceed-to-checkout a.checkout-button {
		width: 100%;
		white-space: normal;
	}

	/* Checkout columns */
	body:not(.mmre-disable-woocommerce) .woocommerce-checkout #customer_details,
	body:not(.mmre-disable-woocommerce) .woocommerce-checkout #order_review,
	body:not(.mmre-disable-woocommerce) .woocommerce-checkout .col2-set,
	body:not(.mmre-disable-woocommerce) .woocommerce-checkout .col-1,
	body:not(.mmre-disable-woocommerce) .woocommerce-checkout .col-2 {
		float: none;
		width: 100%;
		max-width: 100%;
	}

	/* Invoice plugin: fit the paper to the viewport without changing its desktop design. */
	body:not(.mmre-disable-woocommerce) .mm-invoice,
	body:not(.mmre-disable-woocommerce) .mm-invoice-wrap,
	body:not(.mmre-disable-woocommerce) .mm-invoice-paper {
		width: 100%;
		max-width: 100%;
		min-width: 0;
	}

	body:not(.mmre-disable-woocommerce) .mm-invoice-shell, body:not(.mmre-disable-woocommerce) .mm-invoice-paper {
		padding: clamp(16px, 4vw, 24px) !important;
	}

	body:not(.mmre-disable-woocommerce) .mm-invoice-table-wrap {
		width: 100%;
		max-width: 100%;
	}

	body:not(.mmre-disable-woocommerce) .mm-invoice-table th,
	body:not(.mmre-disable-woocommerce) .mm-invoice-table td {
		padding: 8px 6px;
		font-size: 12px;
		overflow-wrap: anywhere;
	}

	body:not(.mmre-disable-woocommerce) .mm-invoice-actions {
		display: flex;
		flex-wrap: wrap;
		gap: 10px;
	}

	body:not(.mmre-disable-woocommerce) .mm-invoice-actions a,
	body:not(.mmre-disable-woocommerce) .mm-invoice-actions button {
		max-width: 100%;
	}
}

@media (max-width: 480px) {
	body:not(.mmre-disable-header) .ast-container,
	body:not(.mmre-disable-header) .site-content .ast-container {
		padding-left: 12px;
		padding-right: 12px;
	}

	body:not(.mmre-disable-woocommerce) .woocommerce ul.products,
	body:not(.mmre-disable-woocommerce) .woocommerce-page ul.products {
		gap: 12px 8px;
	}

	body:not(.mmre-disable-woocommerce) .woocommerce ul.products li.product .button,
	body:not(.mmre-disable-woocommerce) .woocommerce-page ul.products li.product .button {
		width: 100%;
		padding-left: 8px;
		padding-right: 8px;
		white-space: normal;
	}

	/* Header rows can wrap instead of forcing horizontal overflow. */
	.site-header .ast-container,
	.ast-primary-header-bar .ast-container,
	.ast-builder-grid-row {
		min-width: 0;
	}

	/* Keep invoice content legible on narrow screens. */
	body:not(.mmre-disable-woocommerce) .mm-invoice-table th,
	body:not(.mmre-disable-woocommerce) .mm-invoice-table td {
		font-size: 11px;
		padding: 6px 4px;
	}
}

/* Respect reduced-motion preferences; do not disable all animation by default. */
@media (prefers-reduced-motion: reduce) {
	.mmre-responsive * {
		scroll-behavior: auto !important;
	}
}
