/**
 * Language-aware writing direction without changing the designer's alignment.
 *
 * Direction and alignment are separate concerns:
 * - direction follows the active language (RTL/LTR),
 * - alignment intent is detected at runtime from the source design and stored
 *   in data-sast-align-intent (center, justify, start, or end).
 *
 * Layout containers are deliberately excluded so grids, columns, and sections
 * are never reordered by this stylesheet.
 */
html[dir="rtl"],
body.sast-dir-rtl {
	direction: rtl;
}

html[dir="ltr"],
body.sast-dir-ltr {
	direction: ltr;
}

/* Text-bearing WordPress, Elementor, WooCommerce, and block elements. These
 * rules set writing direction only. Runtime alignment markers are declared at
 * the end of the file and remain authoritative. */
body.sast-dir-rtl :is(
	.entry-title,
	.entry-content,
	.site-title,
	.site-description,
	.widget-title,
	.widget_text,
	.elementor-widget-heading .elementor-heading-title,
	.elementor-widget-text-editor .elementor-widget-container,
	.elementor-widget-text-editor p,
	.elementor-widget-text-editor li,
	.elementor-widget-text-editor blockquote,
	.elementor-widget-button .elementor-button,
	.elementor-widget-button .elementor-button-text,
	.elementor-widget-icon-list .elementor-icon-list-item,
	.elementor-widget-icon-list .elementor-icon-list-text,
	.elementor-widget-counter .elementor-counter-number-wrapper,
	.elementor-widget-counter .elementor-counter-title,
	.elementor-widget-price-table .elementor-price-table__heading,
	.elementor-widget-price-table .elementor-price-table__subheading,
	.elementor-widget-price-table .elementor-price-table__price,
	.elementor-widget-price-table .elementor-price-table__features-list,
	.elementor-widget-testimonial .elementor-testimonial-content,
	.elementor-widget-testimonial .elementor-testimonial-name,
	.elementor-widget-accordion .elementor-accordion-title,
	.elementor-widget-tabs .elementor-tab-title,
	.elementor-widget-form .elementor-field-label,
	.elementor-widget-form .elementor-message,
	.elementor-cta__title,
	.elementor-cta__description,
	.woocommerce .woocommerce-breadcrumb,
	.woocommerce .woocommerce-loop-product__title,
	.woocommerce .product_title,
	.woocommerce .woocommerce-product-details__short-description,
	.woocommerce .woocommerce-tabs,
	.woocommerce form label,
	.woocommerce .cart_totals,
	.woocommerce .woocommerce-checkout-review-order,
	.woocommerce .woocommerce-billing-fields,
	.woocommerce .woocommerce-shipping-fields,
	.woocommerce .woocommerce-additional-fields,
	.wc-block-cart,
	.wc-block-checkout,
	.wc-block-components-form,
	.wc-block-components-title,
	.wc-block-components-product-name,
	.wc-block-components-product-metadata,
	.wc-block-components-totals-item,
	.wc-block-components-address-form,
	.wc-block-components-checkout-step,
	.wc-block-components-checkout-step__description,
	.wc-block-components-order-summary,
	.wc-block-components-order-summary-item__description,
	.wc-block-components-validation-error,
	.sast-directed-text
) {
	direction: rtl !important;
	unicode-bidi: plaintext;
}

body.sast-dir-ltr :is(
	.entry-title,
	.entry-content,
	.site-title,
	.site-description,
	.widget-title,
	.widget_text,
	.elementor-widget-heading .elementor-heading-title,
	.elementor-widget-text-editor .elementor-widget-container,
	.elementor-widget-text-editor p,
	.elementor-widget-text-editor li,
	.elementor-widget-text-editor blockquote,
	.elementor-widget-button .elementor-button,
	.elementor-widget-button .elementor-button-text,
	.elementor-widget-icon-list .elementor-icon-list-item,
	.elementor-widget-icon-list .elementor-icon-list-text,
	.elementor-widget-counter .elementor-counter-number-wrapper,
	.elementor-widget-counter .elementor-counter-title,
	.elementor-widget-price-table .elementor-price-table__heading,
	.elementor-widget-price-table .elementor-price-table__subheading,
	.elementor-widget-price-table .elementor-price-table__price,
	.elementor-widget-price-table .elementor-price-table__features-list,
	.elementor-widget-testimonial .elementor-testimonial-content,
	.elementor-widget-testimonial .elementor-testimonial-name,
	.elementor-widget-accordion .elementor-accordion-title,
	.elementor-widget-tabs .elementor-tab-title,
	.elementor-widget-form .elementor-field-label,
	.elementor-widget-form .elementor-message,
	.elementor-cta__title,
	.elementor-cta__description,
	.woocommerce .woocommerce-breadcrumb,
	.woocommerce .woocommerce-loop-product__title,
	.woocommerce .product_title,
	.woocommerce .woocommerce-product-details__short-description,
	.woocommerce .woocommerce-tabs,
	.woocommerce form label,
	.woocommerce .cart_totals,
	.woocommerce .woocommerce-checkout-review-order,
	.woocommerce .woocommerce-billing-fields,
	.woocommerce .woocommerce-shipping-fields,
	.woocommerce .woocommerce-additional-fields,
	.wc-block-cart,
	.wc-block-checkout,
	.wc-block-components-form,
	.wc-block-components-title,
	.wc-block-components-product-name,
	.wc-block-components-product-metadata,
	.wc-block-components-totals-item,
	.wc-block-components-address-form,
	.wc-block-components-checkout-step,
	.wc-block-components-checkout-step__description,
	.wc-block-components-order-summary,
	.wc-block-components-order-summary-item__description,
	.wc-block-components-validation-error,
	.sast-directed-text
) {
	direction: ltr !important;
	unicode-bidi: plaintext;
}

/* Third-party Elementor widgets do not share a naming scheme. Target leaf
 * text elements only, never the widget/container itself. */
body.sast-dir-rtl .elementor-widget :is(
	h1, h2, h3, h4, h5, h6, p, li, blockquote, figcaption, label, legend,
	button, a, strong, small, dt, dd, td, th,
	.elementor-button-text,
	.elementor-post__title,
	.elementor-post__excerpt,
	.elementor-post-info__item,
	.elementor-price-list-title,
	.elementor-price-list-description,
	.elementor-price-list-price,
	.elementor-flip-box__layer__title,
	.elementor-flip-box__layer__description,
	.elementor-slide-heading,
	.elementor-slide-description,
	.elementor-testimonial__text,
	.elementor-testimonial__name,
	.elementor-testimonial__title,
	.elementor-widget-container > span:not([aria-hidden="true"]):not([class*="icon"]),
	[class*="__title"], [class*="-title"], [class*="heading"],
	[class*="description"], [class*="excerpt"], [class*="price"],
	[class*="amount"], [class*="label"], [class*="caption"],
	[class*="message"], [class*="author"], [class*="category"],
	[class*="badge"], .sast-directed-text
) {
	direction: rtl !important;
	unicode-bidi: plaintext;
}

body.sast-dir-ltr .elementor-widget :is(
	h1, h2, h3, h4, h5, h6, p, li, blockquote, figcaption, label, legend,
	button, a, strong, small, dt, dd, td, th,
	.elementor-button-text,
	.elementor-post__title,
	.elementor-post__excerpt,
	.elementor-post-info__item,
	.elementor-price-list-title,
	.elementor-price-list-description,
	.elementor-price-list-price,
	.elementor-flip-box__layer__title,
	.elementor-flip-box__layer__description,
	.elementor-slide-heading,
	.elementor-slide-description,
	.elementor-testimonial__text,
	.elementor-testimonial__name,
	.elementor-testimonial__title,
	.elementor-widget-container > span:not([aria-hidden="true"]):not([class*="icon"]),
	[class*="__title"], [class*="-title"], [class*="heading"],
	[class*="description"], [class*="excerpt"], [class*="price"],
	[class*="amount"], [class*="label"], [class*="caption"],
	[class*="message"], [class*="author"], [class*="category"],
	[class*="badge"], .sast-directed-text
) {
	direction: ltr !important;
	unicode-bidi: plaintext;
}

/* Form values follow the active language. Contact identifiers and numerical
 * values remain isolated so their glyph order stays readable. */
body.sast-dir-rtl :is(
	input:not([type="email"]):not([type="url"]):not([type="tel"]):not([type="number"]),
	textarea,
	select,
	option,
	.select2-selection,
	.wc-block-components-text-input
) {
	direction: rtl !important;
}

body.sast-dir-ltr :is(input, textarea, select, option, .select2-selection, .wc-block-components-text-input) {
	direction: ltr !important;
}

body.sast-dir-rtl :is(.select2-container, .select2-dropdown, .select2-results, .woocommerce form.checkout, .wc-block-checkout) {
	direction: rtl !important;
}

body.sast-dir-ltr :is(.select2-container, .select2-dropdown, .select2-results, .woocommerce form.checkout, .wc-block-checkout) {
	direction: ltr !important;
}

body :is(
	.woocommerce .amount,
	.woocommerce .price,
	.wc-block-components-product-price,
	.wc-block-formatted-money-amount,
	input[type="email"],
	input[type="url"],
	input[type="tel"],
	input[type="number"]
) {
	unicode-bidi: isolate;
}

/* Alignment intent is captured from the source design before any language
 * override. These selectors are deliberately last and stronger than theme or
 * generic direction selectors. */
html body [data-sast-align-intent="center"] {
	text-align: center !important;
}

html body [data-sast-align-intent="justify"] {
	text-align: justify !important;
}

html body [data-sast-align-intent="start"] {
	text-align: start !important;
}

html body [data-sast-align-intent="end"] {
	text-align: end !important;
}
