/**
 * WordPress editor alignment is authoritative when the author has explicitly
 * selected one. All unmarked content keeps the theme's existing RTL styles.
 *
 * Gutenberg: has-text-align-* classes on paragraph, heading, list and groups.
 * Classic editor: style="text-align: ..." or legacy align="..." attributes.
 *
 * Do not force direction:ltr: text alignment and writing direction are distinct
 * properties and Persian paragraphs should retain their intended bidi flow.
 */

/* Explicitly aligned editor blocks override the theme's generic heading,
   paragraph, list and caption rules, even where older styles are very specific. */
body :is(.has-text-align-left, [style*="text-align:left" i], [style*="text-align: left" i], [align="left" i]) {
  text-align: left !important;
}
body :is(.has-text-align-right, [style*="text-align:right" i], [style*="text-align: right" i], [align="right" i]) {
  text-align: right !important;
}
body :is(.has-text-align-center, [style*="text-align:center" i], [style*="text-align: center" i], [align="center" i]) {
  text-align: center !important;
}
body :is(.has-text-align-justify, [style*="text-align:justify" i], [style*="text-align: justify" i], [align="justify" i]) {
  text-align: justify !important;
}

/* Group/column/quote alignment must also flow through theme rules that set
   text-align on individual children. Respect nested, explicitly aligned blocks. */
body :is(
  .has-text-align-left, .has-text-align-right,
  .has-text-align-center, .has-text-align-justify,
  [style*="text-align:left" i], [style*="text-align: left" i],
  [style*="text-align:right" i], [style*="text-align: right" i],
  [style*="text-align:center" i], [style*="text-align: center" i],
  [style*="text-align:justify" i], [style*="text-align: justify" i],
  [align="left" i], [align="right" i], [align="center" i], [align="justify" i]
) :where(div, section, article, header, blockquote, p, h1, h2, h3, h4, h5, h6, ul, ol, li, figcaption, span, small):not(:is(.has-text-align-left, .has-text-align-right, .has-text-align-center, .has-text-align-justify)):not([style*="text-align" i]):not([align]) {
  text-align: inherit !important;
}

/* The alignleft/alignright editor controls for images are placement controls,
   not paragraph text alignment. Keep their float behavior inside rich content. */
:where(.hs-prose, .hs-entry-content, .hs-nr-article__body, .hs-blog-article__content, .entry-content, .wp-block-post-content)
  :is(img, figure, .wp-caption).alignleft {
  float: left !important;
  margin: .4em 1.5em 1em 0 !important;
}
:where(.hs-prose, .hs-entry-content, .hs-nr-article__body, .hs-blog-article__content, .entry-content, .wp-block-post-content)
  :is(img, figure, .wp-caption).alignright {
  float: right !important;
  margin: .4em 0 1em 1.5em !important;
}
:where(.hs-prose, .hs-entry-content, .hs-nr-article__body, .hs-blog-article__content, .entry-content, .wp-block-post-content)
  :is(img, figure, .wp-caption).aligncenter {
  float: none !important;
  margin-inline: auto !important;
}
