/*
 * AMEAQ Responsive Foundation 1.0.0
 * Shared mobile/tablet improvements for /, /en/, /ar/.
 * Scoped to body.ameaq-rf-enabled. Avoids broad header/navigation changes.
 * Does not set global fonts, hide overflow, or rewrite the AMEAQ home carousel.
 * Disable under Settings > AMEAQ Responsive to roll back.
 */

/* CONTENT GUARDRAILS: conservative and also useful on desktop. */
body.ameaq-rf-enabled :where(
  .entry-content,
  .wp-block-post-content,
  .wp-block-group,
  .wp-block-columns,
  .wp-block-column,
  .wpb_wrapper,
  .vc_column-inner,
  .uagb-container-inner-blocks-wrap,
  .wp-block-uagb-container
) {
  min-width: 0;
}

/* Don't allow regular content images to extend beyond their own column. */
body.ameaq-rf-enabled :where(
  .entry-content,
  .wp-block-post-content,
  .wpb_wrapper,
  .wp-block-post-template,
  .uagb-container-inner-blocks-wrap
) :where(img, svg) {
  max-width: 100%;
}

body.ameaq-rf-enabled :where(
  .entry-content,
  .wp-block-post-content,
  .wpb_wrapper
) :where(img) {
  height: auto;
}

/* Avoid overflow from embeds, long filenames, and links. No automatic iframe rewriting. */
body.ameaq-rf-enabled :where(
  .entry-content,
  .wp-block-post-content,
  .wpb_wrapper
) :where(iframe, video, embed, object) {
  max-width: 100%;
}

body.ameaq-rf-enabled :where(
  .entry-content,
  .wp-block-post-content,
  .wpb_wrapper
) :where(p, li, blockquote, h1, h2, h3, h4, h5, h6, figcaption) {
  overflow-wrap: break-word;
}

/* Respect Arabic direction: only direction-neutral logical properties are used here. */
@media (max-width: 1024px) {
  /* Shared WP blocks: let child items shrink instead of causing sideways scroll. */
  body.ameaq-rf-enabled :where(
    .wp-block-columns,
    .wp-block-column,
    .wp-block-group,
    .uagb-container-inner-blocks-wrap,
    .vc_row,
    .vc_column_container,
    .wpb_wrapper
  ) {
    min-inline-size: 0;
    max-inline-size: 100%;
  }

  /* Images in editor-built sections remain within available content width. */
  body.ameaq-rf-enabled :where(
    .wp-block-image img,
    .wp-block-gallery img,
    .wpb_single_image img,
    .uagb-image__figure img
  ) {
    max-inline-size: 100%;
    block-size: auto;
  }

  /* Let wide tables scroll; don't globally alter table semantics. */
  body.ameaq-rf-enabled :where(
    .wp-block-table,
    .tablepress-scroll-wrapper,
    .ameaq-data-table-wrap,
    .dataTables_wrapper
  ) {
    max-inline-size: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.ameaq-rf-enabled :where(
    .wp-block-table,
    .tablepress-scroll-wrapper,
    .ameaq-data-table-wrap
  ) table {
    max-inline-size: 100%;
  }
}

@media (max-width: 781px) {
  /* Core Gutenberg columns. Intentional non-stacked layouts keep their own setting. */
  body.ameaq-rf-enabled .wp-block-columns:not(.is-not-stacked-on-mobile) {
    flex-wrap: wrap;
  }
  body.ameaq-rf-enabled .wp-block-columns:not(.is-not-stacked-on-mobile) > .wp-block-column {
    min-width: 0;
    max-width: 100%;
    flex-basis: 100% !important;
  }
}

@media (max-width: 767px) {
  /* WPBakery grids: stack standard columns on phones without touching content text. */
  body.ameaq-rf-enabled .vc_row > .vc_column_container,
  body.ameaq-rf-enabled .vc_row > .wpb_column {
    float: none !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-inline: 0 !important;
    min-inline-size: 0;
  }

  /* Spectra legacy column groups. Does not modify newer custom home dashboards. */
  body.ameaq-rf-enabled .uagb-columns__inner-wrap {
    flex-wrap: wrap;
  }
  body.ameaq-rf-enabled .uagb-columns__inner-wrap > .wp-block-uagb-column {
    min-width: 0;
    max-width: 100%;
    flex-basis: 100% !important;
  }

  /* Gutenberg query-loop cards: one column on small devices. */
  body.ameaq-rf-enabled .wp-block-post-template.is-layout-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Form inputs should never be wider than their containers. */
  body.ameaq-rf-enabled :where(
    .wpcf7-form,
    .wpforms-container,
    .gform_wrapper,
    .wp-block-search,
    .wp-block-post-content
  ) :where(input, select, textarea, button) {
    max-inline-size: 100%;
    box-sizing: border-box;
  }

  /* Classic tables inside WPBakery text blocks can scroll horizontally. */
  body.ameaq-rf-enabled .wpb_text_column table:not(.ae24-data table) {
    display: block;
    max-inline-size: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Keep long headings and document names readable on narrow screens. */
  body.ameaq-rf-enabled :where(
    .entry-content,
    .wp-block-post-content,
    .wpb_text_column
  ) :where(h1, h2, h3, h4, p, a) {
    overflow-wrap: anywhere;
  }
}

@media (max-width: 480px) {
  /* Preserve original type and carousel styles; only protect narrow content width. */
  body.ameaq-rf-enabled :where(
    .entry-content,
    .wp-block-post-content,
    .wpb_wrapper
  ) :where(pre, code) {
    max-inline-size: 100%;
    overflow-wrap: anywhere;
  }

  body.ameaq-rf-enabled :where(
    .wp-block-table,
    .tablepress-scroll-wrapper,
    .ameaq-data-table-wrap
  ) {
    scrollbar-width: thin;
  }
}
