/*
 * Benchmark comparison charts — styled with the site's own Retro Material 3
 * language (header.php's --m3-* custom properties, 3px outlines, hard offset
 * shadows), so the module inherits light/dark mode for free.
 *
 * Written as plain CSS on purpose: the Tailwind build only scans the theme +
 * binosha-core/binosha-point for class names, so utility classes invented for
 * this module could silently never make it into tailwind-built.css. Interactive
 * controls reuse the theme's real .retro-btn/.retro-chip/.retro-input classes
 * instead of re-implementing them.
 */

.bbc-chart {
	/* Site red (#FF2A5F light / #d61849 dark) and site cyan — the two bar colours.
	   Since red is also the brand's "featured" colour, a highlighted device is set
	   apart by its raised card + striped fills below rather than by a third hue. */
	--bbc-multi: var(--m3-primary);
	--bbc-single: var(--m3-secondary);
	--bbc-highlight: var(--m3-primary);

	background-color: var(--m3-card);
	color: var(--m3-text);
	border: 3px solid var(--m3-outline);
	border-radius: 28px;
	box-shadow: 6px 6px 0 0 var(--m3-outline);
	padding: 22px;
	margin: 28px 0;
	direction: ltr;
	font-family: inherit;
}

.bbc-skeleton {
	text-align: center;
	padding: 30px 0;
	font-weight: 800;
	color: var(--m3-text);
	opacity: .6;
}

.bbc-error {
	background-color: var(--m3-primary);
	color: #fff;
	border: 3px solid var(--m3-outline);
	border-radius: 20px;
	box-shadow: 4px 4px 0 0 var(--m3-outline);
	padding: 12px 16px;
	margin: 20px 0;
	font-weight: 800;
}

/* ------------------------------------------------------------------- header */

.bbc-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 4px;
}

.bbc-title {
	font-size: 22px;
	font-weight: 900;
	margin: 0;
	color: var(--m3-text);
	line-height: 1.4;
}

.bbc-better {
	font-size: 13px;
	font-weight: 700;
	margin: 0 0 16px;
	color: var(--m3-text);
	opacity: .7;
}

.bbc-head-tools {
	display: flex;
	align-items: center;
	gap: 10px;
}

/* .retro-btn (theme) supplies the border/shadow/press animation; only the circle
   sizing is module-specific. */
.bbc-replay {
	width: 40px;
	height: 40px;
	padding: 0;
	flex-shrink: 0;
	background-color: var(--m3-tertiary);
	color: var(--m3-outline);
}

.bbc-replay:hover {
	background-color: var(--m3-primary);
	color: #fff;
}

.bbc-replay[disabled] {
	opacity: .45;
	cursor: not-allowed;
	transform: none;
}

.bbc-replay.is-busy svg {
	animation: bbc-spin .9s linear infinite;
}

@keyframes bbc-spin {
	to { transform: rotate(-360deg); }
}

.bbc-replay svg {
	width: 18px;
	height: 18px;
	display: block;
}

.bbc-metric-select {
	padding: 8px 14px;
	font-size: 13px;
	font-weight: 800;
	font-family: inherit;
	cursor: pointer;
	max-width: 230px;
	-webkit-appearance: none;
	appearance: none;
}

/* ------------------------------------------------------------------- legend */

.bbc-legend {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: 20px;
}

.bbc-pill {
	font-size: 12px;
	gap: 7px;
	cursor: default;
}

.bbc-dot {
	width: 11px;
	height: 11px;
	border-radius: 9999px;
	border: 2px solid var(--m3-outline);
	flex-shrink: 0;
	display: inline-block;
}

.bbc-dot--multi { background-color: var(--bbc-multi); }
.bbc-dot--single { background-color: var(--bbc-single); }
.bbc-dot--highlight { background-color: var(--bbc-highlight); }

/* --------------------------------------------------------------------- rows */

.bbc-rows {
	display: flex;
	flex-direction: column;
	gap: 18px;
}

.bbc-row {
	/* The row layout follows the chart's own width (see the @container rule
	   below): the same chart sits full width on its page and narrower inside an
	   article. */
	container-type: inline-size;
	border-bottom: 2px dashed var(--m3-outline);
	padding-bottom: 16px;
	opacity: 1;
}

.bbc-rows .bbc-row:last-child {
	border-bottom: 0;
	padding-bottom: 0;
}

/* The remove button first, then the name - and the two packed against the
   side the bars start on, so the names line up on the left like their bars. */
.bbc-row-head {
	display: flex;
	align-items: center;
	justify-content: flex-start;
	gap: 8px;
	margin-bottom: 10px;
}

.bbc-row-head .bbc-remove {
	order: -1;
}

.bbc-name-group {
	display: flex;
	align-items: center;
	gap: 6px;
	min-width: 0;
}

/* Shown only for devices linked to a product on the site — opens that page. */
.bbc-product-link {
	width: 30px;
	height: 30px;
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background-color: var(--m3-secondary);
	color: var(--m3-outline);
	border: 2px solid var(--m3-outline);
	border-radius: 9999px;
	box-shadow: 2px 2px 0 0 var(--m3-outline);
	text-decoration: none;
	transition: background-color .15s ease, color .15s ease, transform .15s ease;
}

.bbc-product-link:hover {
	background-color: var(--m3-primary);
	color: #fff;
}

.bbc-product-link:active {
	transform: translate(2px, 2px);
	box-shadow: none;
}

.bbc-product-link svg {
	width: 15px;
	height: 15px;
	display: block;
}

.bbc-row--highlight .bbc-product-link {
	border-color: rgba(255, 255, 255, .5);
}

/* The name is a button: clicking it makes that device the baseline. Boxed so it
   reads as clickable and so each device is clearly separated from its bars. */
.bbc-row-name {
	font-size: 14px;
	font-weight: 900;
	color: var(--m3-text);
	direction: ltr;
	text-align: left;
	unicode-bidi: plaintext;
	background-color: var(--m3-card);
	border: 2px solid var(--m3-outline);
	border-radius: 12px;
	box-shadow: 2px 2px 0 0 var(--m3-outline);
	padding: 6px 12px;
	cursor: pointer;
	font-family: inherit;
	transition: background-color .15s ease, color .15s ease, transform .15s ease;
}

.bbc-row-name:hover {
	background-color: var(--m3-tertiary);
	color: var(--m3-outline);
}

.bbc-row-name:active {
	transform: translate(2px, 2px);
	box-shadow: none;
}

.bbc-row--highlight .bbc-row-name {
	background-color: var(--m3-primary);
	color: #fff;
}

.bbc-remove {
	background-color: var(--m3-muted);
	border: 2px solid var(--m3-outline);
	color: var(--m3-text);
	border-radius: 9999px;
	width: 26px;
	height: 26px;
	font-size: 15px;
	font-weight: 900;
	line-height: 1;
	cursor: pointer;
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	transition: background-color .15s ease, color .15s ease;
}

.bbc-remove:hover {
	background-color: var(--m3-primary);
	color: #fff;
}

/* Share: same circle as the replay button, in the secondary colour so the two read apart. */
.bbc-share {
	background-color: var(--m3-secondary);
}

/* Bars always run left-to-right like every other benchmark chart. */
.bbc-bars {
	direction: ltr;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.bbc-bar {
	display: flex;
	align-items: center;
	gap: 10px;
}

.bbc-track {
	flex: 1;
	background-color: var(--m3-muted);
	border: 2px solid var(--m3-outline);
	border-radius: 9999px;
	height: 22px;
	overflow: hidden;
	min-width: 0;
	box-sizing: border-box;
}

/* No CSS transition here on purpose — the grow-in is driven by the Web Animations
   API in benchmark-charts.js so it replays reliably on every refresh click. A CSS
   transition on the same property would fight those animations. */
.bbc-fill {
	height: 100%;
	border-radius: 9999px;
	width: 0;
}

.bbc-chart.is-animated .bbc-fill {
	width: var(--bbc-w, 0%);
}

.bbc-fill--multi { background-color: var(--bbc-multi); }
.bbc-fill--single { background-color: var(--bbc-single); }

/* The baseline device: a darker, raised panel so it's obvious at a glance which
   laptop everything else is being read against. */
.bbc-row--highlight {
	background-color: var(--m3-outline);
	border: 2px solid var(--m3-outline);
	border-radius: 20px;
	box-shadow: 3px 3px 0 0 var(--m3-primary);
	padding: 12px 14px;
}

.bbc-row--highlight .bbc-score {
	color: #fff;
}

.bbc-row--highlight .bbc-track {
	background-color: rgba(255, 255, 255, .14);
	border-color: rgba(255, 255, 255, .35);
}

.bbc-row--highlight .bbc-remove {
	background-color: transparent;
	border-color: rgba(255, 255, 255, .5);
	color: #fff;
}

.bbc-row--highlight .bbc-remove:hover {
	background-color: var(--m3-primary);
	border-color: var(--m3-primary);
}

.bbc-row--highlight .bbc-fill {
	background-image: repeating-linear-gradient(
		45deg,
		rgba(255, 255, 255, .45) 0,
		rgba(255, 255, 255, .45) 6px,
		transparent 6px,
		transparent 12px
	);
}

/* Large: the number is what the chart is read for. */
.bbc-score {
	font-size: 18px;
	font-weight: 900;
	line-height: 1.2;
	color: var(--m3-text);
	min-width: 84px;
	text-align: left;
	font-variant-numeric: tabular-nums;
	flex-shrink: 0;
}

.bbc-empty {
	font-size: 13px;
	font-weight: 700;
	padding: 6px 0;
	direction: ltr;
	color: var(--m3-text);
	opacity: .6;
}

/* Wide enough: each device on one line - its name beside its bars instead of
   above them, in a column of its own so every chart starts at the same point.
   The name gets two fifths of the row and never less than 22rem, so even the
   sheet's longest names take two lines at most. Below the width that leaves
   the bars room - in an article, on a phone - the name stays above them. */
@container (min-width: 800px) {
	.bbc-row {
		display: grid;
		grid-template-columns: minmax(22rem, 2fr) minmax(0, 3fr);
		align-items: center;
		column-gap: 18px;
	}
	.bbc-row-head {
		margin-bottom: 0;
		min-width: 0;
	}
	.bbc-row-name {
		min-width: 0;
		max-width: 100%;
		overflow-wrap: anywhere;
	}
}

/* ------------------------------------------------------------------- picker */

.bbc-picker {
	margin-top: 22px;
	padding-top: 18px;
	border-top: 2px dashed var(--m3-outline);
	position: relative;
}

.bbc-search {
	width: 100%;
	padding: 11px 18px;
	font-size: 13px;
	font-weight: 700;
	font-family: inherit;
	box-sizing: border-box;
}

.bbc-results {
	list-style: none;
	margin: 10px 0 0;
	padding: 8px;
	background-color: var(--m3-card);
	border: 3px solid var(--m3-outline);
	border-radius: 20px;
	box-shadow: 4px 4px 0 0 var(--m3-outline);
	max-height: 240px;
	overflow-y: auto;
	position: absolute;
	inset-inline: 0;
	z-index: 20;
}

.bbc-results[hidden] { display: none; }

.bbc-results li {
	margin: 0;
	padding: 0;
	list-style: none;
}

.bbc-result {
	width: 100%;
	background: transparent;
	border: 2px solid transparent;
	color: var(--m3-text);
	text-align: left;
	padding: 8px 12px;
	border-radius: 12px;
	cursor: pointer;
	font-size: 13px;
	font-weight: 700;
	font-family: inherit;
	direction: ltr;
	unicode-bidi: plaintext;
	transition: background-color .15s ease;
}

.bbc-result:hover,
.bbc-result:focus {
	background-color: var(--m3-tertiary);
	border-color: var(--m3-outline);
	color: var(--m3-outline);
	outline: none;
}

.bbc-note {
	font-size: 12px;
	font-weight: 700;
	margin-top: 10px;
	color: var(--m3-text);
	opacity: .65;
}

@media (max-width: 600px) {
	.bbc-chart {
		padding: 16px;
		border-radius: 20px;
		box-shadow: 4px 4px 0 0 var(--m3-outline);
	}
	.bbc-title { font-size: 18px; }
	.bbc-score { min-width: 64px; font-size: 15px; }
	.bbc-track { height: 18px; }
	.bbc-metric-select { max-width: 100%; }
}

/* ------------------------------------------------------------------
   Charts page: heading row
   ------------------------------------------------------------------ */
.bbc-page-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 12px 16px;
	margin-bottom: 1.5rem;
}

/* ---------------------------------------------------------------------------
 * Server-rendered scores (inside .bbc-chart until the script draws the chart)
 * and the /benchmark/{metric}/{a}-vs-{b}/ page's summary and links.
 * ------------------------------------------------------------------------- */
.bbc-ssr { font-weight: 700; color: var(--m3-text); }
.bbc-ssr-note { margin: 0 0 12px; font-size: .9rem; }
.bbc-ssr-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.bbc-ssr-table caption { text-align: start; font-weight: 900; margin-bottom: 8px; }
.bbc-ssr-table th, .bbc-ssr-table td { padding: 8px 10px; border-bottom: 2px dashed var(--m3-outline); text-align: start; vertical-align: middle; }
.bbc-ssr-table thead th { border-bottom-style: solid; font-weight: 900; }
.bbc-ssr-bar { display: block; height: 10px; margin-bottom: 4px; border: 2px solid var(--m3-outline); border-radius: 999px; background: var(--m3-primary); min-width: 4px; }

.bbc-pair-summary { margin: 0 0 20px; font-size: 1.05rem; font-weight: 700; line-height: 1.9; color: var(--m3-text); }
.bbc-pair-links { margin-top: 32px; color: var(--m3-text); }
.bbc-pair-links h2 { margin: 24px 0 12px; font-size: 1.15rem; font-weight: 900; }
.bbc-pair-links ul { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; list-style: none; }
.bbc-pair-links a { text-decoration: none; }
