/* ==========================================================================
   WPD-5106: "Boxed" style for the core Group block (Ad / promo box)
   Applied only when an editor picks Styles > Boxed on a Group block
   (class .is-style-boxed), so normal Group blocks are unaffected.
   Loaded on the front end and inside the block editor.

   Works with and without the classic-theme inner wrapper
   (.wp-block-group__inner-container), so the same rules apply in the
   editor and on the front end.
   ========================================================================== */

.wp-block-group.is-style-boxed {
	--ot-boxed-bg: #f5f6f7;
	--ot-boxed-border: #e3e6ea;
	--ot-boxed-radius: 16px;
	--ot-boxed-pad: clamp(24px, 4vw, 40px);
	--ot-boxed-text: #4b5563;
	--ot-boxed-heading: #111827;
	--ot-boxed-btn: #0066ff;      /* brand blue, same as the rest of the child theme */
	--ot-boxed-btn-hover: #0052cc;

	box-sizing: border-box;
	background-color: var(--ot-boxed-bg);
	border: 1px solid var(--ot-boxed-border);
	border-radius: var(--ot-boxed-radius);
	padding: var(--ot-boxed-pad);
	margin-top: 2em;
	margin-bottom: 2em;
	overflow: hidden; /* keeps the image inside the rounded corners */
	color: var(--ot-boxed-text);
}

/* ---- Content ----------------------------------------------------------- */
.wp-block-group.is-style-boxed :is(h1, h2, h3, h4, h5, h6) {
	color: var(--ot-boxed-heading);
	font-size: clamp(22px, 2.2vw, 28px);
	font-weight: 800;
	letter-spacing: -0.01em;
	line-height: 1.2;
	margin-top: 0;
	margin-bottom: 0.6em;
}

.wp-block-group.is-style-boxed p {
	color: var(--ot-boxed-text);
	line-height: 1.6;
	margin-top: 0;
	margin-bottom: 1.25em;
}

.wp-block-group.is-style-boxed .wp-block-buttons {
	margin-top: 0.5em;
	margin-bottom: 0;
}

.wp-block-group.is-style-boxed .wp-block-button:not(.is-style-outline) .wp-block-button__link:not(.has-background) {
	background-color: var(--ot-boxed-btn);
}

/* "#the-post ..." matches Jannah's own post-content button rule (ID-level
   specificity) so the boxed button can be a little larger, like the old Ad. */
.wp-block-group.is-style-boxed .wp-block-button__link,
#the-post .entry-content .wp-block-group.is-style-boxed .wp-block-button a.wp-block-button__link {
	display: inline-block;
	color: #ffffff;
	font-size: 16px;
	font-weight: 700;
	line-height: 1.2;
	padding: 16px 32px;
	border-radius: 14px;
	text-decoration: none;
	transition: background-color 0.2s ease;
}

.wp-block-group.is-style-boxed .wp-block-button:not(.is-style-outline) .wp-block-button__link:not(.has-background):hover,
.wp-block-group.is-style-boxed .wp-block-button:not(.is-style-outline) .wp-block-button__link:not(.has-background):focus-visible {
	background-color: var(--ot-boxed-btn-hover);
	color: #ffffff;
}

.wp-block-group.is-style-boxed .wp-block-button__link:focus-visible {
	outline: 2px solid var(--ot-boxed-btn);
	outline-offset: 3px;
}

/* No stray space below the last item in the box. */
.wp-block-group.is-style-boxed > :last-child,
.wp-block-group.is-style-boxed > .wp-block-group__inner-container > :last-child,
.wp-block-group.is-style-boxed .wp-block-group > :last-child,
.wp-block-group.is-style-boxed .wp-block-group > .wp-block-group__inner-container > :last-child {
	margin-bottom: 0;
}

/* ---- Optional image -----------------------------------------------------
   If the first block inside the box is an Image, show it on the left and
   the text on the right (stacked on mobile). Everything after the image
   sits in the right-hand column. The image runs to the box edges, like
   the old Ad block.
   ------------------------------------------------------------------------ */
.wp-block-group.is-style-boxed .wp-block-image img {
	border-radius: 0;
}

@media (min-width: 768px) {
	.wp-block-group.is-style-boxed:has(> .wp-block-image:first-child),
	.wp-block-group.is-style-boxed:has(> .wp-block-group__inner-container > .wp-block-image:first-child) {
		padding: 0;
	}

	.wp-block-group.is-style-boxed:has(> .wp-block-image:first-child),
	.wp-block-group.is-style-boxed > .wp-block-group__inner-container:has(> .wp-block-image:first-child) {
		display: grid;
		grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
		column-gap: 0;
		row-gap: 0;
		align-items: center;
	}

	.wp-block-group.is-style-boxed:has(> .wp-block-image:first-child) > .wp-block-image:first-child,
	.wp-block-group.is-style-boxed > .wp-block-group__inner-container > .wp-block-image:first-child {
		grid-column: 1;
		grid-row: 1 / span 12;
		align-self: stretch;
		margin: 0;
		height: 100%;
	}

	.wp-block-group.is-style-boxed:has(> .wp-block-image:first-child) > .wp-block-image:first-child img,
	.wp-block-group.is-style-boxed > .wp-block-group__inner-container > .wp-block-image:first-child img {
		width: 100%;
		height: 100%;
		object-fit: cover;
		display: block;
	}

	.wp-block-group.is-style-boxed:has(> .wp-block-image:first-child) > :not(.wp-block-image:first-child),
	.wp-block-group.is-style-boxed > .wp-block-group__inner-container:has(> .wp-block-image:first-child) > :not(.wp-block-image:first-child) {
		grid-column: 2;
		margin-left: var(--ot-boxed-pad);
		margin-right: var(--ot-boxed-pad);
	}

	/* Text wrapped in its own inner Group (as in the "with image" pattern):
	   vertically centred next to the image. */
	.wp-block-group.is-style-boxed:has(> .wp-block-image:first-child) > .wp-block-group,
	.wp-block-group.is-style-boxed > .wp-block-group__inner-container > .wp-block-image:first-child ~ .wp-block-group {
		padding-top: var(--ot-boxed-pad);
		padding-bottom: var(--ot-boxed-pad);
	}
}

@media (max-width: 767px) {
	/* Image on top, edge to edge, text underneath. */
	.wp-block-group.is-style-boxed:has(> .wp-block-image:first-child) > .wp-block-image:first-child,
	.wp-block-group.is-style-boxed > .wp-block-group__inner-container > .wp-block-image:first-child {
		margin: calc(-1 * var(--ot-boxed-pad)) calc(-1 * var(--ot-boxed-pad)) var(--ot-boxed-pad);
	}

	.wp-block-group.is-style-boxed .wp-block-image:first-child img {
		width: 100%;
		display: block;
	}
}
