/**
 * PeepSo Photo Link
 *
 * The badge sits inside .ps-media-grid-fitwidth, never as a sibling of the photo anchor:
 * peepso-core-photos grid.js only ever reveals direct [data-ps-grid-item] children of the
 * gallery, so nothing may be inserted between the gallery and the anchor.
 */

.mjwp-photo-link {
	cursor: pointer;
}

/*
 * The badge hugs the PICTURE, not the image element's box.
 *
 * A theme that frames photos does it with padding on the img (this plugin's site uses
 * `.ps-media-grid-fitwidth img { padding: 20px }`), and padding sits inside the border box the
 * badge is positioned against - so the badge would float out over the frame. CSS cannot read a
 * sibling's padding, so the frame thickness has to be declared once:
 *
 *     .ps-post__gallery--single { --mjwp-photo-frame: 20px; }
 *
 * Set it to whatever that padding is and the badge follows. --mjwp-photo-badge-gap is the
 * plugin's own breathing room inside the picture.
 */
.mjwp-photo-link__badge {
	position: absolute;
	right: calc(var(--mjwp-photo-frame, 0px) + var(--mjwp-photo-badge-gap, 8px));
	bottom: calc(var(--mjwp-photo-frame, 0px) + var(--mjwp-photo-badge-gap, 8px));
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: rgba(255, 0, 0, 0.8);
	color: #fff;
	font-size: 13px;
	line-height: 1;
	pointer-events: none;
	transition: background 0.15s ease-in-out;
}

.mjwp-photo-link:hover .mjwp-photo-link__badge {
	background: rgba(0, 0, 0, 0.75);
}

/*
 * Anchor the badge to the IMAGE, not to the container.
 *
 * On a single-photo post core scopes its `.ps-media-grid-fitwidth { position: relative }` to
 * `:not(.ps-media-grid--single)`, so in the single case there is no positioned box around the
 * image and the badge resolves against `.ps-post__gallery > a`, which is `position: relative`
 * and full container width. The image inside is `width: auto; max-width: 100%; max-height:
 * 500px; margin: 0 auto`, so anything narrower than the container gets letterboxed - and the
 * badge floats out into that empty space instead of sitting on the photo.
 *
 * Shrink-wrapping the fitwidth box to the image and re-centring it puts the image in exactly
 * the same place while giving the badge the right box to hug. fit-content follows the
 * max-height-driven width too, so tall photos work as well as wide ones.
 *
 * Scoped to our linked photos and to the single gallery: a multi-photo gallery already has a
 * correctly positioned, image-sized fitwidth box from core.
 *
 * ALIGNMENT: shrink-wrapping moves the decision here, because the image's own margins go inert
 * once its parent hugs it - and CSS cannot read them back, so this cannot be automatic.
 *
 * The default is LEFT, matching how this plugin's site aligns its photos (its theme CSS zeroes
 * the image margins that stock PeepSo sets to auto). Stock PeepSo centres instead; a site that
 * wants that sets both variables to auto:
 *
 *     .ps-post__gallery--single { --mjwp-photo-align-start: auto; --mjwp-photo-align-end: auto; }
 */
.ps-post__gallery--single > a.mjwp-photo-link .ps-media-grid-fitwidth {
	position: relative;
	width: -moz-fit-content;
	width: fit-content;
	margin-left: var(--mjwp-photo-align-start, 0);
	margin-right: var(--mjwp-photo-align-end, auto);
}

/*
 * Comment photos have no inner .ps-media-grid-fitwidth to position against, so the badge is a
 * direct child of the anchor. The anchor itself is not positioned by core, hence the rule below.
 */
.mjwp-photo-link.ps-js-photo {
	position: relative;
	display: inline-block;
}

.mjwp-photo-link__badge--comment {
	right: calc(var(--mjwp-photo-frame, 0px) + var(--mjwp-photo-badge-gap, 6px));
	bottom: calc(var(--mjwp-photo-frame, 0px) + var(--mjwp-photo-badge-gap, 6px));
	width: 24px;
	height: 24px;
	font-size: 11px;
}

/* Dialog */

.mjwp-photo-link__form {
	text-align: left;
}

.mjwp-photo-link__label {
	display: block;
	margin-bottom: 6px;
	font-weight: 600;
}

.mjwp-photo-link__input {
	width: 100%;
	box-sizing: border-box;
}

.mjwp-photo-link__help {
	margin: 8px 0 0;
	opacity: 0.7;
	font-size: 0.9em;
}

.mjwp-photo-link__error {
	margin: 8px 0 0;
	color: #d63638;
	font-size: 0.9em;
}
