/**
 * TB Google Reviews — front-end styles.
 *
 * Every colour, radius and typeface is a custom property with a neutral
 * fallback, so a theme restyles the widget by setting variables on the wrapper
 * rather than by fighting these rules with `!important`. That was the whole
 * problem with the third-party widget this replaces: its CSS arrived after the
 * theme's and had to be overridden from selectors carrying ids.
 *
 * There is no `!important` anywhere in this file, and there should not need to
 * be one.
 */

.tbgr {
	/*
	 * How many cards are visible, mobile-first.
	 *
	 * The setting arrives as `--tbgr-columns` in an inline style, and inline
	 * styles beat everything in a stylesheet — so the setting must NOT be
	 * `--tbgr-per-view` itself. Doing that pins the widget to the desktop column
	 * count at every width: the media queries below are outranked, phones get
	 * three cards squeezed into 390px, and the track overflows the document.
	 */
	--tbgr-per-view: 1;

	/* Surfaces and lines. */
	--tbgr-card-bg: #fff;
	--tbgr-line: rgba(0, 0, 0, 0.12);
	--tbgr-radius: 0;

	/* Text. */
	--tbgr-font: inherit;
	--tbgr-ink: #27242c;
	--tbgr-muted: #6b6b6b;

	/* The Google review star, sampled from Google's own asset. */
	--tbgr-star: #f6bb06;
	--tbgr-star-empty: rgba(0, 0, 0, 0.16);

	/*
	 * Controls. The outline is its own variable rather than reusing
	 * --tbgr-line: a card divider wants to be barely there, but a button people
	 * are meant to click needs an edge they can see.
	 */
	--tbgr-control-bg: #fff;
	--tbgr-control-ink: #27242c;
	--tbgr-control-line: #767676;

	font-family: var(--tbgr-font);
	color: var(--tbgr-ink);
}

.tbgr *,
.tbgr *::before,
.tbgr *::after {
	box-sizing: border-box;
}

.tbgr__layout {
	display: flex;
	align-items: flex-start;
	gap: 0;
}

/* ------------------------------------------------------------- profile --- */

.tbgr__profile {
	display: flex;
	flex: 0 0 295px;
	gap: 15px;
	align-items: flex-start;
	padding-right: 20px;
}

.tbgr__profile-photo {
	flex: 0 0 65px;
}

/*
 * `contain`, not `cover`. A Google business profile photo is a picture of the
 * premises in whatever aspect ratio the owner uploaded — this one is 3:4 — and
 * cropping it to a square to fill the box cuts the subject in half. Letterboxed
 * inside a 65px square it stays intact and still aligns with the text beside it.
 */
.tbgr__profile-img {
	display: block;
	width: 65px;
	height: 65px;
	border-radius: var(--tbgr-radius);
	object-fit: contain;
	object-position: left center;
}

.tbgr__profile-details {
	min-width: 0;
}

.tbgr__profile-name {
	margin: 0 0 5px;
	font-size: 15px;
	font-weight: 600;
	line-height: 21px;
	color: var(--tbgr-ink);
}

.tbgr__profile-count {
	margin: 0;
	font-size: 15px;
	line-height: 21px;
	color: var(--tbgr-ink);
}

.tbgr__write {
	display: inline-block;
	margin-top: 12px;
	padding: 9px 17px;
	border: 1px solid var(--tbgr-control-line);
	border-radius: var(--tbgr-radius);
	background: var(--tbgr-control-bg);
	color: var(--tbgr-control-ink);
	font-size: 14px;
	font-weight: 600;
	line-height: 1;
	text-decoration: none;
}

.tbgr__write:hover,
.tbgr__write:focus-visible {
	background: var(--tbgr-control-ink);
	color: var(--tbgr-control-bg);
}

/* --------------------------------------------------------------- stars --- */

/*
 * No gap between stars. A rating is read as one mark, not as five icons, and
 * spacing them apart makes the row look like a control someone could click.
 */
.tbgr-stars {
	display: inline-flex;
	vertical-align: middle;
	color: var(--tbgr-star);
}

.tbgr-star {
	width: 17px;
	height: 17px;
	fill: currentColor;
}

.tbgr-star--empty {
	color: var(--tbgr-star-empty);
}

.tbgr__profile .tbgr-stars {
	margin-bottom: 2px;
}

/* -------------------------------------------------------------- slider --- */

.tbgr__slider {
	position: relative;
	flex: 1 1 auto;
	min-width: 0;
}

/*
 * The scroll container IS the slider.
 *
 * Scroll snapping does natively what a transform-based carousel needs
 * JavaScript for, and it keeps working when the script does not load or fails:
 * the cards stay swipeable on touch, scrollable with a trackpad, and reachable
 * with the keyboard. The buttons below only drive this element's scrollLeft —
 * they are a convenience over a control that already works.
 */
.tbgr__viewport {
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;

	/* The scrollbar is replaced by the arrows and the pager. */
	scrollbar-width: none;
	-ms-overflow-style: none;

	/*
	 * Keep the track's width to itself.
	 *
	 * Without this the off-screen cards still count towards the scrollWidth of
	 * every ancestor up to <html>, which reports the document as thousands of
	 * pixels wide. Nothing paints outside the viewport and the page cannot
	 * actually be scrolled sideways, but "document is wider than the screen" is
	 * what a horizontal-overflow audit measures, and it would be flagged on
	 * every page carrying this band.
	 *
	 * `contain` rather than `overflow: clip`, because the arrows are positioned
	 * just outside this element and clipping here must not reach them.
	 */
	contain: paint;
}

.tbgr__viewport::-webkit-scrollbar {
	display: none;
}

.tbgr__viewport:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.tbgr__track {
	display: flex;
	align-items: stretch;
	margin: 0;
	padding: 0;
	list-style: none;
}

.tbgr__slide {
	display: flex;
	flex: 0 0 calc(100% / var(--tbgr-per-view));
	scroll-snap-align: start;
	max-width: calc(100% / var(--tbgr-per-view));
}

/* ---------------------------------------------------------------- card --- */

/*
 * Cards sit flush against each other with no gap, so adjacent one-pixel borders
 * read as a single hairline divider — the strip of reviews looks like one
 * object rather than three floating tiles. This is what the previous widget
 * ended up looking like once the theme had squared its corners, and it is the
 * look being kept.
 */
.tbgr__card {
	display: flex;
	flex: 1;
	flex-direction: column;
	margin: 0;
	padding: 20px 28px;
	border: 1px solid var(--tbgr-line);
	border-radius: var(--tbgr-radius);
	background: var(--tbgr-card-bg);
}

.tbgr__slide + .tbgr__slide .tbgr__card {
	border-left: 0;
}

.tbgr__card-head {
	display: flex;
	gap: 12px;
	align-items: center;
	margin-bottom: 10px;
}

.tbgr__avatar {
	flex: 0 0 40px;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	object-fit: cover;
}

/* Google's own placeholder for a reviewer with no photo, drawn locally. */
.tbgr__avatar--initial {
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--tbgr-ink);
	color: var(--tbgr-card-bg);
	font-size: 17px;
	font-weight: 600;
	line-height: 1;
}

.tbgr__card-meta {
	flex: 1 1 auto;
	min-width: 0;
}

.tbgr__author {
	margin: 0;
	overflow: hidden;
	font-size: 15px;
	font-weight: 600;
	line-height: 21px;
	color: var(--tbgr-ink);
	text-overflow: ellipsis;
	white-space: nowrap;
}

.tbgr__date {
	display: block;
	font-size: 13px;
	line-height: 18px;
	color: var(--tbgr-muted);
}

.tbgr__source {
	flex: 0 0 20px;
	align-self: flex-start;
}

.tbgr-google {
	display: block;
	width: 20px;
	height: 20px;
}

.tbgr__rating {
	display: flex;
	gap: 6px;
	align-items: center;
	margin: 0 0 10px;
}

.tbgr-verified {
	display: block;
	width: 15px;
	height: 15px;
}

/*
 * Three lines, then an ellipsis and a "read more" the script adds.
 *
 * The clamp is what makes every card the same height, which is why it is here
 * rather than left to the script: a band of cards that settled into their final
 * heights only after JavaScript ran would shift the page under the reader.
 */
.tbgr__text {
	display: -webkit-box;
	overflow: hidden;
	margin: 0;
	font-size: 15px;
	line-height: 1.45;
	color: var(--tbgr-ink);
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
}

.tbgr__text--rating-only {
	color: var(--tbgr-muted);
	font-style: italic;
}

.tbgr__card.is-expanded .tbgr__text {
	display: block;
	-webkit-line-clamp: unset;
}

.tbgr__more {
	margin-top: auto;
	padding: 8px 0 0;
	border: 0;
	background: none;
	color: var(--tbgr-muted);
	font: inherit;
	font-size: 14px;
	text-align: left;
	cursor: pointer;
}

.tbgr__more:hover,
.tbgr__more:focus-visible {
	color: var(--tbgr-ink);
	text-decoration: underline;
}

.tbgr__reply {
	margin-top: 12px;
	padding-top: 12px;
	border-top: 1px solid var(--tbgr-line);
	font-size: 14px;
	line-height: 1.45;
}

.tbgr__reply p {
	margin: 0;
}

.tbgr__reply-label {
	margin: 0 0 4px;
	color: var(--tbgr-muted);
	font-weight: 600;
}

/* ------------------------------------------------------------ controls --- */

.tbgr__nav {
	position: absolute;
	top: 50%;
	display: flex;
	width: 30px;
	height: 30px;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 1px solid var(--tbgr-control-line);
	border-radius: var(--tbgr-radius);
	background: var(--tbgr-control-bg);
	color: var(--tbgr-control-ink);
	cursor: pointer;
	transform: translateY(-50%);
}

.tbgr__nav--prev {
	left: -8px;
}

.tbgr__nav--next {
	right: -8px;
}

.tbgr__nav:hover,
.tbgr__nav:focus-visible {
	background: var(--tbgr-control-ink);
	color: var(--tbgr-control-bg);
}

/*
 * At either end of the list the matching arrow is removed from the tab order
 * rather than dimmed in place: a control that is visibly there but does nothing
 * is a small lie, and there is nothing else in this layout that shifts when it
 * disappears.
 */
.tbgr__nav[hidden] {
	display: none;
}

.tbgr-chevron {
	width: 16px;
	height: 16px;
}

.tbgr__pager {
	display: flex;
	gap: 3px;
	width: 155px;
	margin: 22px auto 0;
}

.tbgr__pager[hidden] {
	display: none;
}

.tbgr__pager-dot {
	height: 3px;
	flex: 1;
	padding: 0;
	border: 0;
	background: var(--tbgr-line);
	cursor: pointer;
}

.tbgr__pager-dot.is-current {
	background: var(--tbgr-ink);
}

/* Nothing to scroll to: the controls would be decoration. */
.tbgr--static .tbgr__nav,
.tbgr--static .tbgr__pager {
	display: none;
}

/* --------------------------------------------------------- breakpoints --- */

/*
 * One card at a time below the desktop layout, with the pager instead of the
 * arrows: a 30px arrow overlapping a card edge is an awkward touch target, and
 * a swipe is the obvious gesture on a phone anyway.
 */
@media (max-width: 900px) {
	.tbgr__layout {
		display: block;
	}

	.tbgr__profile {
		justify-content: center;
		padding: 0 0 24px;
	}

	.tbgr__nav {
		display: none;
	}
}

/*
 * `min()` so that a site configured for two cards does not get three at the
 * widest breakpoint — the setting is a ceiling, and the viewport lowers it.
 */
@media (min-width: 901px) {
	.tbgr {
		--tbgr-per-view: min( 2, var( --tbgr-columns, 3 ) );
	}

	/* The pager is the narrow-screen control; here the arrows do the job. */
	.tbgr__pager {
		display: none;
	}
}

@media (min-width: 1201px) {
	.tbgr {
		--tbgr-per-view: var( --tbgr-columns, 3 );
	}
}

@media (prefers-reduced-motion: reduce) {
	.tbgr__viewport {
		scroll-behavior: auto;
	}
}

/* ---------------------------------------------------------- editor-only --- */

.tbgr-placeholder {
	padding: 1.5rem;
	border: 1px dashed var(--tbgr-line, rgba(0, 0, 0, 0.12));
	color: var(--tbgr-muted, #6b6b6b);
	font-size: 0.875em;
	text-align: center;
}
