/**
 * TherapyBuilt automatic layout intelligence.
 *
 * Variable-size public collections use a centered flex grid so incomplete
 * final rows (for example 5 items in a 3-column collection) remain balanced.
 * PHP supplies the initial visible count; smart-layout.js keeps that count in
 * sync when filters/search controls hide or add cards.
 */
.tb-smart-layout {
	--tb-smart-gap: 20px;
	--tb-smart-single-width: 780px;
	--tb-smart-columns: 3;
	display: flex !important;
	flex-wrap: wrap;
	justify-content: center;
	align-items: stretch;
	gap: var(--tb-smart-gap) !important;
}

.tb-smart-layout > * {
	min-width: 0;
	box-sizing: border-box;
}

.tb-smart-layout--columns-1 > * {
	flex: 0 1 min(100%, var(--tb-smart-single-width));
	width: min(100%, var(--tb-smart-single-width));
	max-width: var(--tb-smart-single-width);
}

.tb-smart-layout--columns-2 > * {
	flex: 0 1 calc(50% - var(--tb-smart-gap));
	width: calc(50% - var(--tb-smart-gap));
}

.tb-smart-layout--columns-3 > * {
	flex: 0 1 calc(33.333333% - var(--tb-smart-gap));
	width: calc(33.333333% - var(--tb-smart-gap));
}

.tb-smart-layout--columns-4 > * {
	flex: 0 1 calc(25% - var(--tb-smart-gap));
	width: calc(25% - var(--tb-smart-gap));
}

/* Context-aware widths preserve the intentional single-item designs that
   already exist in TherapyBuilt while sharing the same balancing engine. */
.tb-clinicians__grid { --tb-smart-gap: clamp(16px,2.5vw,28px); --tb-smart-single-width: 820px; }
/* Standard clinician directories keep the established card scale when only
   two profiles are present; the pair centers instead of stretching into two
   oversized half-page cards. Featured two-card layouts retain their wider design. */
.tb-clinicians__grid.tb-smart-layout--max-3:not(.tb-smart-layout--single) > .tb-clinician-card { max-width: 380px; }
.tb-clinicians__support-list { --tb-smart-gap: 16px; --tb-smart-single-width: 380px; }
.tb-services__entry-list--cards { --tb-smart-gap: clamp(14px,2vw,22px); --tb-smart-single-width: 640px; }
.tb-practice-highlights__grid { --tb-smart-gap: clamp(1rem,2.2vw,1.5rem); --tb-smart-single-width: 760px; }
.tb-featured-programs__grid { --tb-smart-gap: clamp(1rem,2.2vw,1.5rem); --tb-smart-single-width: 760px; }
.tb-featured-careers__grid { --tb-smart-gap: 1rem; --tb-smart-single-width: 760px; }
.tb-home-resources__cards { --tb-smart-gap: 14px; --tb-smart-single-width: 520px; }
.tb-resource-card-grid { --tb-smart-gap: 18px; --tb-smart-single-width: 760px; }
.tb-location-grid { --tb-smart-gap: 28px; --tb-smart-single-width: 920px; }
.tb-location-roster > ul { --tb-smart-gap: 20px; --tb-smart-single-width: 820px; }
.tb-location-programs > ul { --tb-smart-gap: 20px; --tb-smart-single-width: 760px; }
.tb-program-grid { --tb-smart-gap: 22px; --tb-smart-single-width: 900px; }
.tb-career-grid { --tb-smart-gap: 1.25rem; --tb-smart-single-width: 780px; }
.tb-dir-spec-cards { --tb-smart-gap: 12px; --tb-smart-single-width: 720px; }
.tb-dir-compact-list { --tb-smart-gap: 12px; --tb-smart-single-width: 720px; }
.tb-dir-program-grid { --tb-smart-gap: 14px; --tb-smart-single-width: 760px; }
.tb-dir-insurance-grid { --tb-smart-gap: 12px; --tb-smart-single-width: 620px; }
.tb-dir-search-results__list { --tb-smart-gap: 10px; --tb-smart-single-width: 720px; }
.tb-contact-page__location-grid { --tb-smart-gap: 18px; --tb-smart-single-width: 760px; }
.tb-clinician-profile__others-list { --tb-smart-gap: 14px; --tb-smart-single-width: 760px; }
.tb-fees-home__logo-grid { --tb-smart-gap: 10px; --tb-smart-single-width: 420px; }
.tb-fees-info-cards { --tb-smart-gap: 1px; --tb-smart-single-width: 760px; }
.tb-testimonials--grid .tb-testimonials__items { --tb-smart-gap: 20px; --tb-smart-single-width: 720px; }
.tb-wte__grid { --tb-smart-gap: clamp(16px,2.5vw,24px); --tb-smart-single-width: 680px; }
.tb-wte-grid { --tb-smart-gap: var(--space-6,24px); --tb-smart-single-width: 680px; }
.tb-location__office-grid { --tb-smart-gap: 24px; --tb-smart-single-width: 880px; }
.tb-location-single__note-grid { --tb-smart-gap: 16px; --tb-smart-single-width: 760px; }
.tb-careers-benefits { --tb-smart-gap: 1rem; --tb-smart-single-width: 760px; }
.tb-practice-credentials__grid { --tb-smart-gap: 18px; --tb-smart-single-width: 860px; }
.tb-answer-ready__grid { --tb-smart-gap: 14px; --tb-smart-single-width: 760px; }
.tb-blog-grid { --tb-smart-gap: clamp(20px,3vw,32px); --tb-smart-single-width: 760px; }
.tb-services__grid { --tb-smart-gap: clamp(16px,2.5vw,24px); --tb-smart-single-width: 720px; }
.tb-referral-return__grid { --tb-smart-gap: 14px; --tb-smart-single-width: 760px; }
.tb-about-page__team-preview { --tb-smart-gap: clamp(16px,2.5vw,24px); --tb-smart-single-width: 320px; }

/* Tablet: large 3/4-column collections become balanced two-column rows.
   A 3-item set becomes 2 + 1 centered; a 5-item set becomes 2 + 2 + 1. */
@media (max-width: 980px) {
	.tb-smart-layout--max-3 > *,
	.tb-smart-layout--max-4 > * {
		flex-basis: calc(50% - var(--tb-smart-gap));
		width: calc(50% - var(--tb-smart-gap));
	}

	.tb-smart-layout--columns-1 > * {
		flex-basis: min(100%, var(--tb-smart-single-width));
		width: min(100%, var(--tb-smart-single-width));
		max-width: var(--tb-smart-single-width);
	}
}

/* Narrow cards that traditionally stayed two-up can hold until 680px. */
@media (max-width: 680px) {
	.tb-smart-layout > * {
		flex-basis: 100% !important;
		width: 100% !important;
		max-width: 100% !important;
	}
}

/* Filtered cards use data-hidden in the clinician directory. The explicit
   selector prevents a hidden item from reserving flex space in older themes. */
.tb-smart-layout > [hidden],
.tb-smart-layout > [data-hidden="true"] {
	display: none !important;
}
.tb-fees-insurers { --tb-smart-gap: 12px; --tb-smart-single-width: 320px; }
.tb-fees-insurers.tb-smart-layout > .tb-fees-insurers__item { display: block; }
.tb-fees-insurers.tb-smart-layout .tb-fees-insurers__card { height: 100%; }

/* Preserve component-specific comfortable breakpoints where the legacy grid
   intentionally stacked earlier than the generic card system. */
@media (max-width: 900px) {
	.tb-location-grid.tb-smart-layout > * {
		flex-basis: 100% !important;
		width: 100% !important;
		max-width: var(--tb-smart-single-width) !important;
	}
}

@media (max-width: 760px) {
	.tb-location__office-grid.tb-smart-layout > *,
	.tb-location-roster > ul.tb-smart-layout > *,
	.tb-location-programs > ul.tb-smart-layout > * {
		flex-basis: 100% !important;
		width: 100% !important;
		max-width: 100% !important;
	}
}
