/*
 * IMAGE BLOCK - the image module's look (inc/image-block/image-block.php):
 * figure.qm-image and div.qm-image-text. Only the layout - size, alignment,
 * shape, focus point, frame. The space round the figure, the corner radius and
 * the caption's type are the page's.
 *
 * The page's own rules for the figure set only its top and bottom margins:
 * the left and right ones are the alignment's.
 *
 * Size and alignment also serve other media of the same width scale -
 * `.qm-media--{size}` / `.qm-media--align-*` (the KB article's Video block,
 * a figure round the shared video component). And the "beside a text" grid
 * takes any figure.
 */

.qm-image { max-width: 100%; }
.qm-image img { display: block; max-width: 100%; height: auto; }
.qm-image__link { display: block; }
.qm-image--zoom .qm-image__link { cursor: zoom-in; }

/* ---------- Size: a share of the column; Original: the file's own width ---------- */
.qm-image--full, .qm-media--full { width: 100%; margin-left: 0; margin-right: 0; }
.qm-image--large, .qm-media--large { width: 75%; }
.qm-image--medium, .qm-media--medium { width: 50%; }
.qm-image--small, .qm-media--small { width: 33.333%; }
.qm-image:not(.qm-image--original) img { width: 100%; }
.qm-image--original { width: fit-content; }
/* A long caption wraps under the image instead of widening it. */
.qm-image--original figcaption { contain: inline-size; }

/* ---------- Alignment ---------- */
.qm-image--align-left, .qm-media--align-left { margin-left: 0; margin-right: auto; }
.qm-image--align-center, .qm-media--align-center { margin-left: auto; margin-right: auto; }
.qm-image--align-right, .qm-media--align-right { margin-left: auto; margin-right: 0; }

/* ---------- Shape: the image fills it, cut at the edges ---------- */
/* (No object-position here: this selector outweighs the focus point's.
   Centre is the browser's default.) */
.qm-image[class*="qm-image--ratio-"] img { object-fit: cover; }
.qm-image--ratio-16-9 img { aspect-ratio: 16 / 9; }
.qm-image--ratio-4-3 img { aspect-ratio: 4 / 3; }
.qm-image--ratio-3-2 img { aspect-ratio: 3 / 2; }
.qm-image--ratio-1-1 img { aspect-ratio: 1 / 1; }

.qm-image--focus-top-left img { object-position: left top; }
.qm-image--focus-top img { object-position: center top; }
.qm-image--focus-top-right img { object-position: right top; }
.qm-image--focus-left img { object-position: left center; }
.qm-image--focus-right img { object-position: right center; }
.qm-image--focus-bottom-left img { object-position: left bottom; }
.qm-image--focus-bottom img { object-position: center bottom; }
.qm-image--focus-bottom-right img { object-position: right bottom; }

/* ---------- Frame ---------- */
.qm-image--frame img { border: 1px solid var(--qm-image-frame, #5336a1); }

/* ---------- Image + text ---------- */
.qm-image-text {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  gap: 24px;
  align-items: start;
}
.qm-image-text--half { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.qm-image-text--right:not(.qm-image-text--half) { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.qm-image-text--right > figure { order: 2; }
.qm-image-text--center { align-items: center; }
.qm-image-text > figure { width: 100%; margin: 0; }

/* ---------- Phones ---------- */
@media (max-width: 767px) {
  .qm-image--large,
  .qm-image--medium,
  .qm-image--small,
  .qm-media--large,
  .qm-media--medium,
  .qm-media--small { width: 100%; }

  /* The image (video) above the text. */
  .qm-image-text,
  .qm-image-text--half,
  .qm-image-text--right:not(.qm-image-text--half) { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .qm-image-text--right > figure { order: 0; }
}
