/*
 * Native Gutenberg/Jetpack galleries on imported YAK-42 dossier pages.
 * Match the two-column, contained-image, caption-below layout used by
 * galleries generated by the dossier form. Never modify image/block HTML:
 * Jetpack must keep its attachment IDs, srcset, ALT and click handlers.
 *
 * The body class is only added to an imported dossier with an external
 * gallery (see yak42_df_enqueue_public_gallery_styles()).
 */
body.yak42-dossier-native-gallery .entry-content figure.wp-block-gallery.has-nested-images {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 16px !important;
    align-items: stretch !important;
    width: 100% !important;
    max-width: 1100px;
    padding: 0 !important;
    margin: 0 auto 36px !important;
    box-sizing: border-box;
}

body.yak42-dossier-native-gallery .entry-content figure.wp-block-gallery.has-nested-images > figure.wp-block-image {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    flex: none !important;
    width: 100% !important;
    max-width: none !important;
    height: auto !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    border: 1px solid #dedede !important;
    border-radius: 5px !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

/* Neutralize Gutenberg's cropped/flexing images; retain the whole photograph. */
body.yak42-dossier-native-gallery .entry-content figure.wp-block-gallery.has-nested-images > figure.wp-block-image > img {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    flex: none !important;
    aspect-ratio: 4 / 3 !important;
    object-fit: contain !important;
    object-position: center !important;
    background: #f3f3f3 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Also support WordPress galleries whose images are wrapped in an anchor. */
body.yak42-dossier-native-gallery .entry-content figure.wp-block-gallery.has-nested-images > figure.wp-block-image > a,
body.yak42-dossier-native-gallery .entry-content figure.wp-block-gallery.has-nested-images > figure.wp-block-image > div:not(.components-drop-zone) {
    display: flex !important;
    flex: none !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    aspect-ratio: 4 / 3 !important;
    background: #f3f3f3 !important;
    overflow: hidden;
}

body.yak42-dossier-native-gallery .entry-content figure.wp-block-gallery.has-nested-images > figure.wp-block-image > a img,
body.yak42-dossier-native-gallery .entry-content figure.wp-block-gallery.has-nested-images > figure.wp-block-image > div:not(.components-drop-zone) img {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    flex: none !important;
    object-fit: contain !important;
    object-position: center !important;
    background: #f3f3f3 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* WordPress normally absolutely positions captions OVER the photographs. */
body.yak42-dossier-native-gallery .entry-content figure.wp-block-gallery.has-nested-images > figure.wp-block-image > figcaption {
    position: static !important;
    inset: auto !important;
    display: block !important;
    flex: none !important;
    width: 100% !important;
    max-height: none !important;
    height: auto !important;
    margin: 0 !important;
    padding: 12px !important;
    background: #ffffff !important;
    background-image: none !important;
    color: #555555 !important;
    font-family: Arial, Helvetica, sans-serif !important;
    font-size: 13px !important;
    font-weight: 400 !important;
    line-height: 1.5 !important;
    text-align: center !important;
    text-shadow: none !important;
    box-sizing: border-box !important;
    overflow-wrap: anywhere;
}

/* Remove Gutenberg's decorative dark gradient behind overlay captions. */
body.yak42-dossier-native-gallery .entry-content figure.wp-block-gallery.has-nested-images > figure.wp-block-image::before {
    content: none !important;
    display: none !important;
    background: none !important;
}

@media (max-width: 600px) {
    body.yak42-dossier-native-gallery .entry-content figure.wp-block-gallery.has-nested-images {
        grid-template-columns: minmax(0, 1fr) !important;
    }
}
