/**
 * iBreathe Brand Grid
 *
 * Structural rules are fixed and live here.
 * Per-instance values arrive as custom properties on .ibr-brand-grid-wrapper,
 * and per-tile values on each .custom-grid-item, set inline by
 * ibr-brand-grid.php. Fallbacks below match the Shopify defaults.
 */

/* ---------------------------------------------------------------
   Outer strip — breaks out of the theme container to full viewport width
   --------------------------------------------------------------- */

.ibr-brand-grid-wrapper {
	width: 100vw;
	max-width: 100vw;
	margin-left: calc(50% - 50vw);
	margin-right: calc(50% - 50vw);
	box-sizing: border-box;
	padding-top: 20px;
	padding-bottom: 20px;
	margin-top: var(--ibrbrand-mt-desktop, 40px);
	margin-bottom: var(--ibrbrand-mb-desktop, 0px);
	background-color: var(--ibrbrand-bg-color, #ffffff);
	background-image: var(--ibrbrand-bg-image, none);
	background-size: var(--ibrbrand-bg-size, cover);
	background-repeat: var(--ibrbrand-bg-repeat, no-repeat);
	background-position: center;
	color: var(--ibrbrand-text-color, #000000);
}

/* WordPress's block layout system sets margin-block-start/end on children of
   .is-layout-constrained and .is-layout-flow, including a 24px block gap and a
   first-child reset to zero. Those are logical properties and resolve to the
   same computed value as margin-top/bottom, so they compete with the rule
   above. Restating them here as logical properties at a higher specificity
   settles it, on any template. Do not remove. */
.ibr-brand-grid-wrapper.alignfull {
	margin-block-start: var(--ibrbrand-mt-desktop, 40px);
	margin-block-end: var(--ibrbrand-mb-desktop, 0px);
}

/* ---------------------------------------------------------------
   Inner container — width constrained by Blocksy's .ct-container
   --------------------------------------------------------------- */

.ibr-brand-grid {
	width: 100%;
	box-sizing: border-box;
	text-align: left;
}

/* Blocksy applies its own vertical padding to .ct-container; the strip
   already supplies that, so remove it here to avoid doubling up. */
.ibr-brand-grid-wrapper .ibr-brand-grid.ct-container {
	padding-top: 0;
	padding-bottom: 0;
}

/* Heading inherits the section colour rather than the theme's heading colour. */
.ibr-brand-grid .custom-grid-section-title {
	color: inherit;
	font-size: 24px;
	font-weight: 700;
	line-height: 1.2;
	margin-top: 0;
	margin-bottom: 15px;
	padding: 0;
}

/* ---------------------------------------------------------------
   Grid

   Desktop column count is set per instance. The two lower tiers are
   fixed, as per the Shopify section: four across below 1024px and
   three across below 600px, so nine tiles form a 3x3 on mobile.
   --------------------------------------------------------------- */

.ibr-brand-grid .custom-grid {
	display: grid;
	grid-template-columns: repeat(var(--ibrbrand-cols, 9), 1fr);
	gap: 15px;
	margin: 0;
	width: 100%;
}

/* ---------------------------------------------------------------
   Tiles

   The tile carries its own background and text colour. A tile with no
   colours set falls back to a white box, and to the section text colour
   for its label.

   Artwork is cropped to a square by object-fit, so logos supplied at
   other proportions lose their edges rather than changing the row height.
   --------------------------------------------------------------- */

.ibr-brand-grid .custom-grid-item {
	display: flex;
	flex-direction: column;
	text-decoration: none;
	text-align: center;
	border-radius: 6px;
	overflow: hidden;
	box-shadow: 0 0 4px rgba(0, 0, 0, 0.15);
	padding-bottom: 12px;
	background-color: var(--ibrbrand-tile-bg, #ffffff);
	color: var(--ibrbrand-tile-text, inherit);
}

.ibr-brand-grid .brand-asset-box {
	display: block;
	width: 100%;
	aspect-ratio: 1;
	margin: 0;
	padding: 0;
	overflow: hidden;
}

.ibr-brand-grid .brand-asset-box img {
	width: 100%;
	height: 100%;
	display: block;
	margin: 0;
	padding: 0;
	object-fit: cover;
}

.ibr-brand-grid .brand-item-label {
	color: inherit;
	font-size: 12px;
	font-weight: 400;
	text-transform: none;
	letter-spacing: 0.5px;
	margin: 0;
	padding: 0 8px;
	word-break: break-word;
}

/* ---------------------------------------------------------------
   Tablet — 1024px, as per the Shopify section
   --------------------------------------------------------------- */

@media screen and (max-width: 1024px) {

	.ibr-brand-grid .custom-grid {
		grid-template-columns: repeat(4, 1fr);
		gap: 12px;
	}
}

/* ---------------------------------------------------------------
   Strip spacing switches at 749px, independently of the grid.
   This mismatch is in the Shopify original and is deliberate here.
   --------------------------------------------------------------- */

@media screen and (max-width: 749px) {

	.ibr-brand-grid-wrapper {
		margin-top: var(--ibrbrand-mt-mobile, 20px);
		margin-bottom: var(--ibrbrand-mb-mobile, 0px);
		padding-top: 25px;
		padding-bottom: 25px;
	}

	/* Logical restatement, as above. Do not remove. */
	.ibr-brand-grid-wrapper.alignfull {
		margin-block-start: var(--ibrbrand-mt-mobile, 20px);
		margin-block-end: var(--ibrbrand-mb-mobile, 0px);
	}
}

/* ---------------------------------------------------------------
   Mobile — 600px, as per the Shopify section
   --------------------------------------------------------------- */

@media screen and (max-width: 600px) {

	.ibr-brand-grid .custom-grid {
		grid-template-columns: repeat(3, 1fr);
		gap: 10px;
	}
}
