/* Sales → Product Performance. Scoped to product-performance (plus performance-title in the page header) as
   member-pulse.css scopes Pulse, so one page never restyles another's elements. Custom elements are inline by
   default, so every one used for layout states its display. The summary cards and trend chips reuse analytics.css,
   so this page and Sales Analytics read as one section. */

performance-title {
	display: flex;
	flex-direction: column;
	gap: 0.2rem;

	h2 {
		margin: 0;
	}

	span {
		font-size: var(--font-size-small);
		color: var(--light-global-font-color);
	}
}

product-performance {
	display: flex;
	flex-direction: column;
	gap: 1.25rem;
	padding: 0 1rem 2rem;

	.performance-note {
		max-width: 70rem;
		margin: -0.5rem 0 0;
		font-size: var(--font-size-tiny);
		color: var(--light-global-font-color);
	}

	.performance-eyebrow {
		font-size: var(--font-size-tiny);
		font-weight: 700;
		letter-spacing: 0.14em;
		text-transform: uppercase;
		color: var(--light-global-font-color);
	}

	.performance-empty {
		margin: 0;
		padding: 1rem 0.25rem;
		color: var(--light-global-font-color);
	}

	.performance-sr-only {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip-path: inset(50%);
		white-space: nowrap;
	}

	/* #region Category tabs */

	performance-tabs {
		display: flex;
		flex-wrap: wrap;
		gap: 0.5rem;
	}

	[role="tab"] {
		display: flex;
		align-items: center;
		gap: 0.6rem;
		padding: 0.5rem 0.9rem 0.5rem 0.6rem;
		border: 1px solid var(--border-color);
		border-radius: 0.7rem;
		background: var(--blue-gray);
		font: inherit;
		color: var(--global-font-color);
		cursor: pointer;

		img,
		svg {
			flex: none;
			width: 1.75rem;
			height: 1.75rem;
		}

		span {
			font-weight: 600;
		}

		b {
			font-size: var(--font-size-small);
			font-variant-numeric: tabular-nums;
			color: var(--light-global-font-color);
		}

		&:hover {
			background: var(--hover-gray);
		}

		&:focus-visible {
			outline: 2px solid var(--primary-green);
			outline-offset: 2px;
		}

		/* An inset ring as well as the border, so the selected tab still stands out where borders are faint. */
		&[aria-selected="true"] {
			border-color: var(--primary-green);
			box-shadow: inset 0 0 0 1px var(--primary-green);

			b {
				color: var(--global-font-color);
			}
		}
	}

	section[role="tabpanel"] {
		display: flex;
		flex-direction: column;
		gap: 1rem;
	}

	/* The author display above outranks the user-agent [hidden] rule, so it has to be restated. */
	section[role="tabpanel"][hidden] {
		display: none;
	}

	/* #endregion */

	/* #region Leaderboard */

	/* The same surface as the Statistics stat cards and the Pulse panels. */
	performance-list {
		display: flex;
		flex-direction: column;
		padding: 0.4rem 0.9rem 0.6rem;
		border: 1px solid var(--border-color);
		border-radius: 0.8rem;
		background: var(--blue-gray);
		box-shadow: var(--soft-continer-outer-shadow);
	}

	performance-row {
		display: grid;
		grid-template-areas: "rank product revenue volume spark trend last";
		grid-template-columns: 2rem minmax(11rem, 1.5fr) minmax(9rem, 1fr) minmax(7.5rem, 0.8fr) minmax(10rem, 1.6fr) 6.25rem 7.5rem;
		align-items: center;
		column-gap: 1.25rem;
		padding: 0.85rem 0.25rem;
		border-top: 1px solid var(--border-color);
	}

	performance-row[header] {
		padding: 0.6rem 0.25rem 0.5rem;
		border-top: none;
		font-size: var(--font-size-tiny);
		font-weight: 700;
		letter-spacing: 0.14em;
		text-transform: uppercase;
		color: var(--light-global-font-color);
	}

	performance-rank {
		grid-area: rank;
		font-size: var(--font-size-large);
		font-weight: 800;
		font-variant-numeric: tabular-nums;
		color: var(--light-global-font-color);
	}

	/* The top three are the ones people come for, so they carry the full ink. */
	performance-row:nth-child(-n + 4) performance-rank {
		color: var(--global-font-color);
	}

	performance-product {
		display: flex;
		grid-area: product;
		flex-direction: column;
		align-items: flex-start;
		gap: 0.2rem;
		min-width: 0;

		strong {
			max-width: 100%;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		> span {
			font-size: var(--font-size-small);
			color: var(--light-global-font-color);
		}
	}

	performance-revenue {
		grid-area: revenue;
	}

	performance-volume {
		grid-area: volume;
	}

	performance-last {
		grid-area: last;
	}

	performance-revenue,
	performance-volume,
	performance-last {
		display: flex;
		flex-direction: column;
		gap: 0.3rem;
		min-width: 0;

		b {
			font-weight: 700;
			font-variant-numeric: tabular-nums;
		}

		small {
			font-size: var(--font-size-tiny);
			font-variant-numeric: tabular-nums;
			color: var(--light-global-font-color);
		}
	}

	performance-share {
		display: block;
		height: 4px;
		overflow: hidden;
		border-radius: 2px;
		background: color-mix(in srgb, var(--light-global-font-color) 18%, transparent);

		span {
			display: block;
			width: calc(var(--share) * 100%);
			height: 100%;
			border-radius: 2px;
			background: var(--primary-green);
		}
	}

	performance-trend {
		grid-area: trend;

		.statistics-stat-card-delta {
			white-space: nowrap;
		}
	}

	performance-axis {
		display: flex;
		grid-area: spark;
		justify-content: space-between;
		gap: 0.5rem;
		white-space: nowrap;

		span:nth-child(2) {
			overflow: hidden;
			text-overflow: ellipsis;
		}
	}

	/* #endregion */

	/* #region Chart */

	/* space-between pins the first and last periods to the chart's edges, under the axis labels in the header,
	   however many periods the range has. */
	performance-spark {
		position: relative;
		display: flex;
		grid-area: spark;
		justify-content: space-between;
		gap: 2px;
		height: 2.75rem;
		border-radius: 0.35rem;
		outline: none;

		&:focus-visible {
			box-shadow: 0 0 0 2px var(--primary-green);
		}

		/* The whole column is the hit target and the bar is drawn inside it, so the pointer only has to be over the
		   right period, not on a bar that may be two pixels tall. */
		> i {
			position: relative;
			flex: 1 1 0;
			min-width: 0;
			max-width: 1.25rem;
			border-radius: 0.2rem;

			&::after {
				position: absolute;
				right: 1px;
				bottom: 0;
				left: 1px;
				height: max(2px, calc(var(--h) * 100%));
				border-radius: 2px 2px 1px 1px;
				background: var(--primary-green);
				content: "";
			}

			/* A period with no sales keeps a stub on the baseline, so the timeline stays readable before a product
			   launched and through gaps in its sales. */
			&[zero]::after {
				height: 2px;
				background: var(--border-color);
			}

			&[active] {
				background: var(--hover-gray);
			}
		}

		/* The other periods fade back while one is read, so the eye lands on the bar the readout belongs to. */
		&:has(> i[active]) > i:not([active])::after {
			opacity: 0.4;
		}
	}

	/* Opens above its bar, inside the row, since the desktop client has no top layer to lift it into.
	   pointer-events: none lets the pointer keep moving across the bars underneath. */
	performance-tip {
		position: absolute;
		z-index: 2;
		bottom: calc(100% + 0.45rem);
		left: 0;
		display: flex;
		flex-direction: column;
		gap: 0.3rem;
		padding: 0.6rem 0.75rem;
		border: 1px solid var(--border-color);
		border-radius: 0.6rem;
		background: var(--deep-background-color);
		box-shadow: var(--soft-continer-outer-shadow);
		font-size: var(--font-size-small);
		white-space: nowrap;
		color: var(--light-global-font-color);
		pointer-events: none;

		&[hidden] {
			display: none;
		}

		> strong {
			font-size: var(--font-size-tiny);
			font-weight: 700;
			letter-spacing: 0.08em;
			text-transform: uppercase;
		}

		/* The value leads; the reader already knows which product and period they are on. */
		> b {
			font-size: var(--font-size-normal);
			font-variant-numeric: tabular-nums;
			color: var(--global-font-color);
		}
	}

	/* #endregion */

	/* #region Variants */

	.performance-variants-toggle {
		display: inline-flex;
		align-items: center;
		gap: 0.3rem;
		margin-left: -0.4rem;
		padding: 0.1rem 0.4rem;
		border: none;
		border-radius: 0.4rem;
		background: none;
		font: inherit;
		font-size: var(--font-size-small);
		font-weight: 600;
		color: var(--primary-green);
		cursor: pointer;

		&::after {
			content: "▾";
		}

		&[aria-expanded="true"]::after {
			content: "▴";
		}

		&:hover {
			background: var(--hover-gray);
		}

		&:focus-visible {
			outline: 2px solid var(--primary-green);
		}
	}

	/* Subgrids of the row, so each variant's name, revenue and volume sit under the product's own columns and read as
	   sub-rows of the table rather than a second layout. Starts at the product column, leaving the rank column as an
	   indent. */
	performance-variants {
		display: grid;
		grid-column: 2 / -1;
		grid-template-columns: subgrid;
		margin-top: 0.6rem;
	}

	performance-variants[hidden] {
		display: none;
	}

	performance-variant {
		display: grid;
		grid-column: 1 / -1;
		grid-template-columns: subgrid;
		align-items: center;
		padding: 0.3rem 0;
		font-size: var(--font-size-small);

		/* The line down the names ties the variants to the product above them. */
		> span {
			align-self: stretch;
			display: flex;
			align-items: center;
			padding-left: 0.85rem;
			border-left: 2px solid var(--border-color);
		}

		/* Back into the flow of the subgrid; the row's named areas belong to the row, not to a variant. */
		performance-revenue,
		performance-volume {
			grid-area: auto;
		}
	}

	/* #endregion */

	/* #region Not sold */

	performance-unsold {
		display: flex;
		flex-direction: column;
		gap: 0.6rem;
		padding: 0 0.25rem;

		ul {
			display: flex;
			flex-wrap: wrap;
			gap: 0.4rem;
			margin: 0;
			padding: 0;
			list-style: none;
		}

		li {
			padding: 0.25rem 0.65rem;
			border-radius: 999px;
			background: color-mix(in srgb, var(--light-global-font-color) 12%, transparent);
			font-size: var(--font-size-small);
			color: var(--light-global-font-color);
		}
	}

	/* #endregion */

	/* On a narrow pane the chart drops under the figures instead of being squeezed to a few pixels per period. The
	   header's chart axis goes with it, since it would no longer sit over the charts. */
	@media (max-width: 1100px) {
		performance-row {
			grid-template-areas:
				"rank product revenue volume"
				". spark spark spark"
				". trend last last";
			grid-template-columns: 2rem minmax(9rem, 1.3fr) minmax(8rem, 1fr) minmax(7rem, 0.8fr);
			row-gap: 0.7rem;
		}

		performance-row[header] {
			grid-template-areas: "rank product revenue volume";

			performance-axis,
			> span:nth-last-child(-n + 2) {
				display: none;
			}
		}
	}

	@media (prefers-reduced-motion: no-preference) {
		performance-spark > i::after {
			transition: opacity 0.12s ease;
		}
	}
}
