/**
 * Image responsiveness fixes for Elementor-built service pages.
 *
 * The problem, as found on /tax-accounting-services-glasgow-accountants/:
 *
 *   .elementor-element-9a32ec8 img { width: 300px; border-style: dotted; }
 *   .elementor-element-9a32ec8 > .elementor-widget-container {
 *       margin: 30px; padding: 30px; border-radius: 30px;
 *   }
 *   .elementor-element-d87b051 { width: 35%; }
 *
 * A 35% column at a 1140px container is roughly 400px wide. Take off 60px of
 * margin and 60px of padding and about 280px of usable width is left — but the
 * image is pinned to a fixed 300px with no max-width and no height:auto. It
 * therefore overflows its rounded container, and because the intrinsic aspect
 * ratio is not preserved it also distorts. Below ~1024px the same fixed width
 * leaves the image marooned in a box far wider than itself.
 *
 * These rules restore normal responsive behaviour without touching the
 * Elementor data, so the page can still be edited normally.
 */

/* ==========================================================================
   Baseline: every content image behaves responsively
   ========================================================================== */

.elementor-widget-image img,
.entry-content img,
.lpa-media img {
	max-width: 100%;
	height: auto;
}

/*
 * Override the generated fixed width. Elementor writes its rules as
 * `.elementor-{post} .elementor-element.elementor-element-{id} img`, which is
 * 0,3,1. Matching that specificity from a stylesheet loaded afterwards is not
 * reliable across every page id, so the width reset is scoped tightly to image
 * widgets and marked important. Nothing else here uses !important.
 */
.elementor-widget-image .elementor-widget-container img {
	width: auto !important;
	max-width: 100% !important;
	height: auto !important;
	display: block;
	margin-inline: auto;
	/* Fill the container on desktop rather than sitting small inside it. */
	object-fit: contain;
}

/* The rounded card the image sits in should hug the image, not dwarf it. */
.elementor-widget-image .elementor-widget-container {
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	box-sizing: border-box;
	max-width: 100%;
}

/* A dotted border with no width declared renders inconsistently between
   browsers; give it an explicit, deliberate value. */
.elementor-widget-image img[style*="border"],
.elementor-widget-image .elementor-widget-container img {
	border-width: 0;
}

/* ==========================================================================
   Desktop: image beside text, properly bounded
   ========================================================================== */

@media (min-width: 1024px) {
	/* Inner sections used as an image/text pair. */
	.elementor-inner-section > .elementor-container {
		display: flex;
		flex-wrap: nowrap;
		align-items: center;
		gap: clamp(1rem, 3vw, 2.5rem);
	}

	.elementor-inner-section > .elementor-container > .elementor-column {
		display: flex;
		min-width: 0; /* lets a flex child shrink instead of overflowing */
	}

	.elementor-inner-section > .elementor-container > .elementor-column > .elementor-widget-wrap {
		width: 100%;
		min-width: 0;
	}

	/*
	 * No fixed max-width here on purpose.
	 *
	 * An earlier version capped every image widget at 360px to fix the
	 * tax-services cards. That also hit the homepage hero, which is a
	 * full-width image widget, and shrank it to a third of its intended size.
	 * Letting the container decide the width fixes the overflowing card
	 * (the image can no longer exceed its box) without touching layouts where
	 * a large image is the point.
	 */

	/* Keep the decorative padding proportionate to the box, but only where
	   the widget container actually has a background card. */
	.elementor-widget-image .elementor-widget-container[style*="background"] {
		padding: clamp(1rem, 2vw, 1.75rem) !important;
		margin: clamp(0.5rem, 1.5vw, 1.25rem) !important;
	}
}

/* ==========================================================================
   Tablet and mobile: stack, full visibility
   ========================================================================== */

@media (max-width: 1023px) {
	.elementor-inner-section > .elementor-container {
		flex-wrap: wrap;
	}

	.elementor-inner-section > .elementor-container > .elementor-column {
		width: 100% !important;
	}

	.elementor-widget-image .elementor-widget-container[style*="background"] {
		margin: 1rem auto !important;
		padding: 1rem !important;
	}
}

/* ==========================================================================
   Tall portrait images in full-width sections
   ========================================================================== */

/*
 * The homepage hero is three stacked image widgets, two of them 1024x1536
 * portrait. At full container width a portrait image that tall renders a block
 * roughly 1,800px high, so the page opens with three screens of picture before
 * any text. Capping the height and using object-fit: contain keeps the whole
 * image visible — nothing is cropped — while stopping it from dominating the
 * viewport.
 */
.elementor-widget-image img {
	max-height: 85vh;
	object-fit: contain;
}

@media (max-width: 782px) {
	.elementor-widget-image img {
		max-height: 70vh;
	}
}

/* ==========================================================================
   Inline-styled buttons in raw HTML widgets
   ========================================================================== */

/*
 * Several call-to-action links carry an inline `width: 200px`. That fits a
 * 320px viewport, but the fixed width stops them filling the available space
 * and they wrap awkwardly when three sit side by side. Capping to the
 * container keeps them predictable at every size.
 */
.elementor-widget-html a[style*="width: 200px"],
.elementor-widget-html a[style*="width:200px"] {
	max-width: 100%;
	box-sizing: border-box;
}

@media (max-width: 600px) {
	.elementor-widget-html a[style*="width: 200px"],
	.elementor-widget-html a[style*="width:200px"] {
		display: block !important;
		width: auto !important;
		margin-inline: auto;
	}
}

@media (max-width: 600px) {
	.elementor-widget-image .elementor-widget-container {
		margin: 0.75rem auto !important;
		padding: 0.75rem !important;
		border-radius: var(--lpa-radius) !important;
	}
}
