/* ... existing styles ... */

/* --- Grid Layout Styles --- */

.wpb-tabs-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 20px;
	width: 100%;
}

/* Handle grid items: 3 top, 2 bottom if 5 items. 
   Grid auto-flow handles 3 cols. 
   If we want specifically 3 up 2 down centered, we can use flex-wrap or grid alignment.
   Let's stick to standard grid flow. If there are 5 items, last 2 will be on 2nd row left-aligned.
   To center the last row if it has fewer items:
*/
.wpb-tabs-grid {
	display: flex;
	flex-wrap: wrap;
	justify-content: center; /* Centers items in last row */
}

.wpb-grid-card {
	width: calc(33.333% - 20px); /* 3 columns minus gap approx */
	margin-bottom: 20px;
	margin-right: 20px;
	background: #fff;
	border-radius: 0; /* Remove border-radius */
	overflow: hidden;
	box-shadow: 0 10px 30px rgba(0,0,0,0.1);
	display: flex;
	flex-direction: column;
	position: relative;
	transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.wpb-grid-card:hover {
	transform: none; /* Remove translate */
	box-shadow: 0 15px 40px rgba(0,0,0,0.15);
}

.wpb-grid-card:hover .wpb-grid-card-icon {
    background: linear-gradient(135deg, #014576 0%, #26949D 100%);
}

.wpb-grid-card:hover .wpb-grid-card-icon .grid-icon-mask {
    background: #fff; /* Icon becomes white */
}

.wpb-grid-card:hover .wpb-grid-card-image > img {
    transform: scale(1.1); /* Zoom effect */
}

/* Ensure container clips the image so it doesn't overflow */
.wpb-grid-card-image {
    overflow: hidden;
    /* Other styles remain... */
}

.wpb-grid-card:nth-child(3n) {
	margin-right: 0; /* No margin on 3rd item in flex row if we controlled margins manually, but with flex gap property is better */
}

/* Better approach with gap if supported (modern browsers) */
.wpb-tabs-grid {
	gap: 20px;
}
.wpb-grid-card {
	width: calc(33.333% - 14px); /* (100% - 2*20px gap) / 3 */
	margin: 0;
}

@media (max-width: 992px) {
	.wpb-grid-card {
		width: calc(50% - 10px);
	}
}
@media (max-width: 600px) {
	.wpb-grid-card {
		width: 100%;
	}
}


/* Special layout for last 2 items if total is 5 (assuming 3 top, 2 bottom) */
/* We target the 4th and 5th items specifically */
.wpb-tabs-grid .wpb-grid-card:nth-child(4),
.wpb-tabs-grid .wpb-grid-card:nth-child(5) {
	width: calc(50% - 10px); /* 2 columns */
	flex-direction: row; /* Image left, content right */
	align-items: stretch;
}

/* Adjust image for these horizontal cards */
.wpb-tabs-grid .wpb-grid-card:nth-child(4) .wpb-grid-card-image,
.wpb-tabs-grid .wpb-grid-card:nth-child(5) .wpb-grid-card-image {
	width: 50%;
	height: 100%; /* Fill container height */
	min-height: 250px; /* Ensure minimum height */
	padding: 0; /* Remove padding if we want full bleed or adjust? 
	   "non vengono stampate sotto l'immagine ma accanto" -> Suggests side-by-side.
	   Let's keep image padding? Or remove it for cleaner side-by-side?
	   If we keep padding, image is small inside left half.
	   Let's assuming padding is still desired for consistency of style.
	   BUT, "le card devono coprire tutto il container in due colonne".
	*/
	padding: 35px 0 35px 35px; /* Adjust padding: Top, Right 0, Bottom 35, Left 35 */
	display: flex; /* Flex to stretch img */
}

/* Adjust content for these horizontal cards */
.wpb-tabs-grid .wpb-grid-card:nth-child(4) .wpb-grid-card-content,
.wpb-tabs-grid .wpb-grid-card:nth-child(5) .wpb-grid-card-content {
	width: 50%;
	padding: 35px 35px 25px 35px; /* Keep consistent padding */
}

/* Adjust button for these horizontal cards */
.wpb-tabs-grid .wpb-grid-card:nth-child(4) .wpb-grid-cta,
.wpb-tabs-grid .wpb-grid-card:nth-child(5) .wpb-grid-cta {
	/* The button needs to cover the entire width of the card (left + right column) 
	   OR just the content column?
	   "il pulsante come le card superiori devono coprire l'intera larghezza della card"
	   -> Covers WHOLE card width (spanning both image and text columns).
	*/
	position: absolute;
	bottom: 0;
	left: 0;
	width: 100%;
	margin: 0;
	z-index: 10;
}

/* Add padding bottom to card to make space for absolute button */
.wpb-tabs-grid .wpb-grid-card:nth-child(4),
.wpb-tabs-grid .wpb-grid-card:nth-child(5) {
	padding-bottom: 50px; /* Space for button approx */
}

/* Responsive fallback for these 2 special cards */
@media (max-width: 992px) {
	/* Tablet: 2 columns grid generally, but let's reset special cards to be normal vertical cards 
	   if we want consistency, or keep them horizontal if space permits.
	   Usually tablet is 2 cols. 
	*/
	.wpb-tabs-grid {
		grid-template-columns: repeat(2, 1fr);
	}
	.wpb-grid-card {
		width: calc(50% - 10px);
	}
}

@media (max-width: 768px) {
	/* Mobile: 1 column stack */
	.wpb-tabs-grid {
		display: flex;
		flex-direction: column;
		grid-template-columns: 1fr; /* Reset grid just in case */
	}

	.wpb-grid-card {
		width: 100% !important; /* Force full width */
		margin-right: 0;
		margin-bottom: 30px;
	}

	/* Reset special layout for last 2 items to be normal vertical stack */
	.wpb-tabs-grid .wpb-grid-card:nth-child(4),
	.wpb-tabs-grid .wpb-grid-card:nth-child(5) {
		width: 100% !important;
		flex-direction: column;
		padding-bottom: 0;
		align-items: flex-start;
	}
	
	.wpb-tabs-grid .wpb-grid-card:nth-child(4) .wpb-grid-card-image,
	.wpb-tabs-grid .wpb-grid-card:nth-child(5) .wpb-grid-card-image {
		width: 100%;
		padding: 35px 35px 0 35px; /* Restore standard padding */
		height: 250px;
		display: block; /* Reset flex to block for standard img handling */
	}
	
	.wpb-tabs-grid .wpb-grid-card:nth-child(4) .wpb-grid-card-image > img,
	.wpb-tabs-grid .wpb-grid-card:nth-child(5) .wpb-grid-card-image > img {
		width: 100%;
		height: 100%;
		object-fit: cover;
	}
	
	.wpb-tabs-grid .wpb-grid-card:nth-child(4) .wpb-grid-card-content,
	.wpb-tabs-grid .wpb-grid-card:nth-child(5) .wpb-grid-card-content {
		width: 100%;
		padding: 35px 35px 25px 35px; /* Restore standard padding */
	}
	
	.wpb-tabs-grid .wpb-grid-card:nth-child(4) .wpb-grid-cta,
	.wpb-tabs-grid .wpb-grid-card:nth-child(5) .wpb-grid-cta {
		position: static;
		width: calc(100% + 70px);
		margin: auto -35px -25px -35px;
	}
}

/* Card Image Section */
.wpb-grid-card-image {
	position: relative;
	width: 100%;
	height: 250px; 
	padding: 35px 35px 0 35px; 
	box-sizing: border-box;
    overflow: visible; /* Allow icon to sit on edge if needed, but mainly we use inner mask for image */
}

/* Wrapper for Image to handle Zoom and Clipping */
.wpb-grid-image-mask {
    position: relative;
    width: 100%;
    height: 100%;
    max-height: 230px; /* Added as requested */
    overflow: hidden; /* This clips the zoomed image */
    border-radius: 4px;
}

.wpb-grid-image-mask img {
	width: 100% !important;
	height: 100% !important;
	object-fit: cover;
	display: block;
    transition: transform 0.3s ease; /* Smooth transition for zoom */
}

/* Icon in top-left */
.wpb-grid-card-icon {
	position: absolute;
	top: 0px;
	left: 0px;
	width: 70px;
	height: 70px;
	background: #fff;
	border-radius: 50%;
	display: flex;
	justify-content: center;
	align-items: center;
	/* box-shadow removed as requested */
	box-shadow: none; 
	z-index: 2;
    transition: background 0.3s ease; /* Smooth transition for background */
}

.wpb-grid-card-icon img {
	width: 30px;
	height: 30px;
	object-fit: contain;
}

/* Update zoom selector */
.wpb-grid-card:hover .wpb-grid-image-mask img {
    transform: scale(1.1);
}

/* Icon Mask for Grid */
.wpb-grid-card-icon .grid-icon-mask {
	width: 40px; /* Increased to 40px */
	height: 40px;
	background: linear-gradient(135deg, #014576 0%, #26949D 100%);
	-webkit-mask-image: var(--grid-icon-url);
	mask-image: var(--grid-icon-url);
	-webkit-mask-repeat: no-repeat;
	mask-repeat: no-repeat;
	-webkit-mask-position: center;
	mask-position: center;
	-webkit-mask-size: contain;
	mask-size: contain;
    transition: background 0.3s ease; /* Smooth transition for mask color */
}

/* Card Content Section */
.wpb-grid-card-content {
	padding: 35px 35px 25px 35px; /* Added 35px top padding */
	display: flex;
	flex-direction: column;
	flex-grow: 1;
	text-align: left;
}

.wpb-grid-card-content h4 {
	font-size: 20px;
	font-weight: 700;
	margin: 0 0 15px 0;
	color: #024576; /* Updated color */
}

.wpb-grid-card-content p {
	font-size: 15px;
	line-height: 1.6;
	color: #666;
	margin-bottom: 25px;
	flex-grow: 1; /* Push button to bottom */
}

/* Button */
.wpb-grid-cta {
	display: block;
	width: calc(100% + 70px); /* 100% + 35px left + 35px right */
	margin: auto -35px -25px -35px; /* Top auto (push down), Right -35, Bottom -25, Left -35 */
	padding: 15px 0;
	background: linear-gradient(135deg, #014576 0%, #26949D 100%);
	color: #fff;
	text-decoration: none;
	text-transform: uppercase;
	font-weight: 600;
	border-radius: 0;
	text-align: center; /* Ensure text is centered */
}

.wpb-grid-cta:hover {
	opacity: 1; /* Keep opacity full */
	color: #fff !important; /* Keep white text */
	text-decoration: underline !important; /* Add underline */
}
