/*
 * Tool reviews.
 *
 * Summary and form in a left column, the reviews themselves in a wider right
 * column, stacking on narrow screens. Reads from the theme's design tokens, so
 * it follows the Customizer palette without a second set of rules.
 *
 * Grid and flex children carry min-width: 0 throughout; they default to
 * min-width: auto and refuse to shrink below their content.
 */

.cw-reviews {
	margin-top: 40px;
	padding-top: 32px;
	border-top: 1px solid var(--cw-color-border);
	min-width: 0;
}

.cw-reviews-head { margin-bottom: 20px; min-width: 0; }
.cw-reviews-title { margin: 0 0 8px; font-size: clamp(1.45rem, 3vw, 1.9rem); line-height: 1.2; }
.cw-reviews-lede { margin: 0; max-width: 62ch; color: var(--cw-color-muted); }

/* ------------------------------------------------------------------ *
 * Notices
 * ------------------------------------------------------------------ */

.cw-review-notice {
	margin: 0 0 20px;
	padding: 12px 16px;
	border-radius: var(--cw-radius-sm);
	border-inline-start: 3px solid var(--cw-color-primary);
	background: var(--cw-color-bg);
	font-size: 0.93rem;
	color: var(--cw-color-text);
}
.cw-review-notice.is-thanks { border-inline-start-color: var(--cw-color-success); }
.cw-review-notice.is-error { border-inline-start-color: var(--cw-color-danger); }

/* ------------------------------------------------------------------ *
 * Layout
 * ------------------------------------------------------------------ */

.cw-reviews-layout {
	display: grid;
	grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
	gap: 24px;
	align-items: start;
}
.cw-reviews-aside { display: grid; gap: 20px; min-width: 0; }
.cw-reviews-main { min-width: 0; }

/* ------------------------------------------------------------------ *
 * Stars
 * ------------------------------------------------------------------ */

.cw-stars { display: inline-flex; gap: 3px; line-height: 1; }
.cw-star {
	display: inline-block;
	width: var(--cw-star-size, 18px);
	height: var(--cw-star-size, 18px);
}
.cw-star svg { width: 100%; height: 100%; display: block; }

/* Explicit colours rather than a color-mix: the empty star has to stay
   visible against the card in both themes, and a mix resolved to near-white
   in dark mode elsewhere in this theme. */
.cw-star.is-empty svg { fill: var(--cw-color-star-empty); }
.cw-star.is-full svg { fill: var(--cw-color-star); }

/* Half star: an empty glyph with a gold copy clipped over its left half. */
.cw-star.is-half { position: relative; }
.cw-star.is-half > svg { fill: var(--cw-color-star-empty); }
.cw-star-half {
	position: absolute;
	inset: 0;
	display: block;
	clip-path: inset(0 50% 0 0);
}
.cw-star-half svg { fill: var(--cw-color-star); }

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

.cw-review-summary,
.cw-review-form-card {
	padding: 20px;
	background: var(--cw-color-card);
	border: 1px solid var(--cw-color-border);
	border-radius: var(--cw-radius);
	min-width: 0;
}

.cw-review-average { margin: 12px 0 2px; display: flex; align-items: baseline; gap: 7px; }
.cw-review-average strong { font-size: 1.5rem; line-height: 1; color: var(--cw-color-heading); }
.cw-review-average.is-empty strong { font-size: 1.05rem; }
.cw-review-average span { font-size: 0.88rem; color: var(--cw-color-muted); }
.cw-review-total { margin: 0 0 16px; font-size: 0.88rem; color: var(--cw-color-muted); }

.cw-review-bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.cw-review-bar { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cw-review-bar-label {
	display: inline-flex;
	align-items: center;
	gap: 3px;
	flex: 0 0 auto;
	font-size: 0.82rem;
	font-weight: 600;
	color: var(--cw-color-text);
}
.cw-review-bar-label .cw-star { width: 13px; height: 13px; }
.cw-review-bar-track {
	flex: 1 1 auto;
	min-width: 0;
	height: 8px;
	border-radius: 999px;
	background: var(--cw-color-bg);
	border: 1px solid var(--cw-color-border);
	overflow: hidden;
}
.cw-review-bar-fill { display: block; height: 100%; background: var(--cw-color-star); }
.cw-review-bar-count {
	flex: 0 0 auto;
	min-width: 2ch;
	text-align: end;
	font-size: 0.8rem;
	color: var(--cw-color-muted);
	font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ *
 * The form
 * ------------------------------------------------------------------ */

.cw-review-form-title { margin: 0 0 6px; font-size: 1.08rem; }
.cw-review-form-lede { margin: 0 0 16px; font-size: 0.88rem; color: var(--cw-color-muted); }

.cw-review-label {
	display: block;
	margin-bottom: 6px;
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--cw-color-heading);
}

.cw-rating-field { margin: 0 0 16px; padding: 0; border: 0; min-width: 0; }

/*
 * The stars are laid out in reverse so that `~` can reach the stars that come
 * after the checked input in the DOM but appear before it on screen. That is
 * the only way to light up "this star and everything to its left" in CSS.
 */
.cw-rating-stars {
	display: flex;
	flex-direction: row-reverse;
	justify-content: flex-end;
	align-items: center;
	gap: 4px;
	min-width: 0;
}
.cw-rating-star {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	cursor: pointer;
	color: var(--cw-color-star-empty);
	border-radius: var(--cw-radius-sm);
	transition: color 0.12s ease, transform 0.08s ease;
}
.cw-rating-star svg { width: 28px; height: 28px; fill: currentColor; display: block; }

.cw-rating-input:checked ~ .cw-rating-star,
.cw-rating-star:hover,
.cw-rating-star:hover ~ .cw-rating-star { color: var(--cw-color-star); }

.cw-rating-input:focus-visible + .cw-rating-star {
	outline: 2px solid var(--cw-color-primary);
	outline-offset: 2px;
}
.cw-rating-star:active { transform: scale(0.92); }

/* The hint sits after the stars in the DOM and before them on screen, because
   the row is reversed. */
.cw-rating-hint {
	order: -1;
	margin-inline-end: auto;
	font-size: 0.85rem;
	color: var(--cw-color-muted);
}

.cw-review-row { margin: 0 0 14px; min-width: 0; }
.cw-review-row-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.cw-review-counter { font-size: 0.78rem; color: var(--cw-color-muted); font-variant-numeric: tabular-nums; }
.cw-review-counter.is-near { color: var(--cw-color-danger); }

.cw-review-input,
.cw-review-textarea {
	display: block;
	width: 100%;
	min-width: 0;
	padding: 10px 12px;
	font-family: var(--cw-font-body);
	font-size: 0.95rem;
	color: var(--cw-color-editor-text);
	background: var(--cw-color-editor-bg);
	border: 1px solid var(--cw-color-border);
	border-radius: var(--cw-radius-sm);
}
.cw-review-input { min-height: var(--cw-tap); }
.cw-review-textarea { min-height: 110px; line-height: 1.55; resize: vertical; }
.cw-review-input:focus-visible,
.cw-review-textarea:focus-visible {
	outline: 2px solid var(--cw-color-primary);
	outline-offset: 1px;
	border-color: var(--cw-color-primary);
}

.cw-review-submit { width: 100%; justify-content: center; min-height: var(--cw-tap); }

/* The honeypot. Off-screen rather than display:none, because some bots skip
   anything hidden outright. */
.cw-review-hp {
	position: absolute !important;
	left: -9999px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.cw-review-privacy {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	margin: 12px 0 0;
	font-size: 0.78rem;
	line-height: 1.5;
	color: var(--cw-color-muted);
}
.cw-review-privacy svg { flex: 0 0 auto; margin-top: 2px; color: var(--cw-color-success); }

/* ------------------------------------------------------------------ *
 * The list
 * ------------------------------------------------------------------ */

.cw-reviews-bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 8px 14px;
	margin-bottom: 12px;
	min-width: 0;
}
.cw-reviews-count { margin: 0; font-size: 0.9rem; font-weight: 600; color: var(--cw-color-heading); }
.cw-reviews-sort { margin: 0; }
.cw-reviews-sort select {
	font-size: 0.85rem;
	padding: 6px 10px;
	min-height: var(--cw-tap);
	color: var(--cw-color-text);
	background: var(--cw-color-card);
	border: 1px solid var(--cw-color-border);
	border-radius: var(--cw-radius-sm);
}

.cw-review-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.cw-review {
	padding: 16px 18px;
	background: var(--cw-color-card);
	border: 1px solid var(--cw-color-border);
	border-radius: var(--cw-radius);
	min-width: 0;
}
.cw-review-head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 4px 12px;
	min-width: 0;
}
.cw-review-author { margin: 0; font-weight: 700; color: var(--cw-color-heading); overflow-wrap: anywhere; min-width: 0; }
.cw-review-date { font-size: 0.8rem; color: var(--cw-color-muted); flex: 0 0 auto; }
.cw-review-rating { margin: 6px 0 0; }
.cw-review-body { margin: 8px 0 0; color: var(--cw-color-text); overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ *
 * Empty state
 * ------------------------------------------------------------------ */

.cw-reviews-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
	padding: 44px 24px;
	background: var(--cw-color-bg);
	border: 1px dashed var(--cw-color-border);
	border-radius: var(--cw-radius);
	min-width: 0;
}
.cw-reviews-empty-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 46px;
	height: 46px;
	margin-bottom: 14px;
	border-radius: var(--cw-radius);
	background: var(--cw-color-star-soft);
}
.cw-reviews-empty-icon svg { width: 24px; height: 24px; fill: var(--cw-color-star); }
.cw-reviews-empty-title { margin: 0 0 6px; font-size: 1.15rem; font-weight: 700; color: var(--cw-color-heading); }
.cw-reviews-empty-text { margin: 0 0 18px; max-width: 46ch; color: var(--cw-color-muted); }

@media (prefers-reduced-motion: reduce) {
	.cw-rating-star { transition: none; }
	.cw-rating-star:active { transform: none; }
}

/* ------------------------------------------------------------------ *
 * Responsive
 * ------------------------------------------------------------------ */

@media (max-width: 900px) {
	.cw-reviews-layout { grid-template-columns: minmax(0, 1fr); }

	/*
	 * On one column the form goes last: someone scrolling a phone wants to
	 * read what others said before being asked to write something.
	 */
	.cw-reviews-aside { order: 2; }
	.cw-reviews-main { order: 1; }
	.cw-reviews-layout { display: flex; flex-direction: column; }
}

@media (max-width: 600px) {
	.cw-reviews { margin-top: 28px; padding-top: 24px; }
	.cw-review-summary,
	.cw-review-form-card { padding: 16px; }
	.cw-rating-star { width: 44px; height: 44px; }
	.cw-rating-star svg { width: 30px; height: 30px; }
	.cw-rating-hint { flex-basis: 100%; order: 1; margin: 6px 0 0; }
	.cw-reviews-empty { padding: 32px 18px; }
}
