/* The Purchases band at the top of the member page (EditMember.cshtml, filled by MemberPurchaseProfileController).
   Scoped to member-purchases as member-pulse.css scopes Pulse, so it never restyles another page's elements. Custom
   elements are inline by default, so every one used for layout states its display. App tokens only, so light and dark
   themes come for free. */

member-purchases {
	display: block;
	/* member-main is a scrolling flex column; the band keeps its height rather than giving it up to the form. */
	flex: none;
	/* The band lays itself out by its own width, which is a share of the member page rather than of the window. */
	container-type: inline-size;
	padding: 0.9rem 1.25rem 1rem;
	border: 1px solid var(--border-color);
	border-radius: 1rem;
	/* The same surface as the side cards beside it. */
	background: var(--blue-gray);
	box-shadow: var(--soft-continer-outer-shadow);

	/* Holds the band's height while it loads, so the form does not jump down when it arrives. */
	> sl-spinner {
		display: block;
		margin-block: 4.5rem;
	}

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

	.purchases-empty {
		margin: 0;
		color: var(--light-global-font-color);
	}

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

	purchases-head {
		display: flex;
		align-items: baseline;
		justify-content: space-between;
		gap: 1rem;

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

	/* #region Figures and chart */

	purchases-body {
		display: grid;
		grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
		align-items: end;
		gap: 1.75rem;
		margin-top: 0.6rem;
	}

	purchases-summary {
		display: flex;
		flex-direction: column;
		gap: 1rem;
		min-width: 0;
	}

	purchases-headline {
		display: flex;
		flex-direction: column;
		gap: 0.1rem;

		b {
			font-size: 2rem;
			font-weight: 800;
			line-height: 1.1;
			font-variant-numeric: tabular-nums;
		}

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

	purchases-figures {
		display: grid;
		grid-template-columns: repeat(4, auto);
		justify-content: start;
		gap: 0.75rem 1.5rem;
	}

	purchases-figure {
		display: flex;
		flex-direction: column;
		gap: 0.15rem;
		min-width: 0;

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

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

		/* Amber, as Pulse marks a member who needs a look: the member has stayed away well past their usual gap. */
		&[late] span {
			align-self: flex-start;
			padding: 0.05rem 0.45rem;
			margin-left: -0.45rem;
			border-radius: 999px;
			background: var(--status-pill-2-background);
			color: var(--status-pill-2-color);
		}
	}

	purchases-chart {
		display: flex;
		flex-direction: column;
		gap: 0.35rem;
		min-width: 0;
	}

	/* The whole column is the hit target and the bar is drawn inside it, so the pointer only has to be over the right
	   month, not on a bar that may be two pixels tall. */
	purchases-bars {
		position: relative;
		display: flex;
		gap: 4px;
		height: 5.5rem;
		border-radius: 0.35rem;
		outline: none;

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

		> i {
			position: relative;
			flex: 1 1 0;
			min-width: 0;
			border-radius: 0.25rem;

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

			/* A month with no visits keeps a stub on the baseline, so a gap reads as a gap rather than a missing bar. */
			&[zero]::after {
				height: 2px;
				background: var(--border-color);
			}

			/* The current month is only part-way through, so its bar is drawn lighter rather than read as a drop. */
			&[current]:not([zero])::after {
				background: color-mix(in srgb, var(--primary-green) 55%, transparent);
			}

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

		/* The other months 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;
		}
	}

	purchases-axis {
		display: flex;
		gap: 4px;

		span {
			flex: 1 1 0;
			min-width: 0;
			overflow: hidden;
			font-size: var(--font-size-tiny);
			text-align: center;
			color: var(--light-global-font-color);
		}

		span[current] {
			font-weight: 700;
			color: var(--global-font-color);
		}
	}

	/* Opens beside its bar and within the chart's height (member-purchases.js places it), since the desktop client has
	   no top layer to lift it into. Above the bar it would run off the top of the band, which is the first thing on a
	   scrolling page, and be clipped. pointer-events: none lets the pointer keep moving across the bars underneath. */
	purchases-tip {
		position: absolute;
		z-index: 2;
		top: 0;
		left: 0;
		display: flex;
		flex-direction: column;
		gap: 0.2rem;
		padding: 0.45rem 0.7rem;
		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 spend leads; the reader already knows which month they are on. */
		> b {
			font-size: var(--font-size-normal);
			font-variant-numeric: tabular-nums;
			color: var(--global-font-color);
		}
	}

	/* #endregion */

	/* #region Limit and favourites */

	purchases-foot {
		display: grid;
		grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
		align-items: start;
		gap: 1.75rem;
		margin-top: 1rem;
		padding-top: 0.9rem;
		border-top: 1px solid var(--border-color);
	}

	purchases-limit,
	purchases-favourites {
		display: flex;
		flex-direction: column;
		gap: 0.45rem;
		min-width: 0;

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

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

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

	purchases-meter {
		display: block;
		height: 6px;
		overflow: hidden;
		border-radius: 3px;
		background: color-mix(in srgb, var(--light-global-font-color) 18%, transparent);

		/* Success green rather than the app's primary, which is close enough to the amber below that "fine" and
		   "nearly there" would look alike. */
		span {
			display: block;
			width: calc(var(--fill) * 100%);
			height: 100%;
			border-radius: 3px;
			background: var(--success-green);
		}
	}

	purchases-limit[tone="near"] purchases-meter span {
		background: var(--orange);
	}

	purchases-limit[tone="over"] purchases-meter span {
		background: var(--danger-red);
	}

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

		li {
			display: inline-flex;
			align-items: center;
			gap: 0.4rem;
			max-width: 100%;
			padding: 0.25rem 0.7rem 0.25rem 0.35rem;
			border-radius: 999px;
			background: color-mix(in srgb, var(--light-global-font-color) 10%, transparent);
			font-size: var(--font-size-small);

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

			span {
				overflow: hidden;
				font-weight: 600;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			small {
				flex: none;
				font-size: var(--font-size-tiny);
				color: var(--light-global-font-color);
			}
		}
	}

	/* #endregion */

	/* On a narrow member page the chart goes under the figures instead of being squeezed beside them. */
	@container (max-width: 44rem) {
		purchases-body,
		purchases-foot {
			grid-template-columns: minmax(0, 1fr);
			gap: 1.1rem;
		}

		purchases-figures {
			grid-template-columns: repeat(2, auto);
		}
	}

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