/* Counter (docs/widgets/counter.md), in the design language (spec §3.7). This is Soft, the default:
   a white card with a thin border and a soft shadow, the icon on a pale tint of the accent, the
   number in the accent. Fonts come from the theme. counter-outline.css and counter-solid.css change
   only the --hafe-counter-d-* tokens below, so a Style control's own property always wins.

   The Layout controls set the direction (--hafe-counter-flow) and what aligns the icon: the
   alignment above the text, the middle beside it (--hafe-counter-cross). */
.hafe-counter {
	--hafe-counter-d-bg: var(--hafe-surface);
	--hafe-counter-d-line: var(--hafe-line);
	--hafe-counter-d-shadow: var(--hafe-shadow);
	--hafe-counter-d-radius: var(--hafe-radius);
	--hafe-counter-d-padding: 1.75em 1.5em;
	--hafe-counter-d-media: var(--hafe-tint);
	--hafe-counter-d-media-ink: var(--hafe-accent-ink);
	--hafe-counter-d-media-line: transparent;
	--hafe-counter-d-media-radius: var(--hafe-radius-sm);
	--hafe-counter-d-number: var(--hafe-accent-ink);
	--hafe-counter-d-affix: var(--hafe-accent-ink);
	display: flex;
	flex-direction: var(--hafe-counter-flow, column);
	/* Beside a narrow card's icon, the text drops below it rather than squeeze. */
	flex-wrap: wrap;
	align-items: var(--hafe-counter-cross, var(--hafe-counter-items, center));
	/* Above the text, the parts start at the top, so icons and numbers line up across a row of cards. */
	justify-content: var(--hafe-counter-main, flex-start);
	gap: var(--hafe-counter-media-gap, 1em);
	block-size: 100%;
	padding: var(--hafe-counter-padding, var(--hafe-counter-d-padding));
	border: var(--hafe-counter-line-width, 1px) solid var(--hafe-counter-line, var(--hafe-counter-d-line));
	border-radius: var(--hafe-counter-radius, var(--hafe-counter-d-radius));
	background: var(--hafe-counter-bg, var(--hafe-counter-d-bg));
	color: var(--hafe-ink);
	box-shadow: var(--hafe-counter-d-shadow);
	text-align: var(--hafe-counter-align, center);
	/* Whole words: a title beside the icon wraps between words rather than inside one. */
	overflow-wrap: break-word;
	container-type: inline-size;
}

/* Without Elementor's lean markup there's a wrapper between the widget and the box. */
.elementor-widget-hafe-counter > .elementor-widget-container {
	block-size: 100%;
}

/* A grid column never grows to fit a card: a long word wraps inside it instead. */
.elementor-widget-hafe-counter {
	min-inline-size: 0;
}

/* No card: the number straight on the section, in the scheme's colours. */
.hafe-counter-box-none .hafe-counter {
	--hafe-counter-d-bg: transparent;
	--hafe-counter-d-line: transparent;
	--hafe-counter-d-shadow: none;
	--hafe-counter-d-padding: 0;
}

.hafe-counter__media {
	box-sizing: border-box;
	display: flex;
	flex: none;
	align-items: center;
	justify-content: center;
	border: 1px solid var(--hafe-counter-media-line, var(--hafe-counter-d-media-line));
	border-radius: var(--hafe-counter-media-radius, var(--hafe-counter-d-media-radius));
	background: var(--hafe-counter-media-bg, var(--hafe-counter-d-media));
	color: var(--hafe-counter-media-color, var(--hafe-counter-d-media-ink));
	line-height: 1;
}

/* The tile grows with the icon, a little over twice its size. */
.hafe-counter__media--icon {
	inline-size: 2.25em;
	block-size: 2.25em;
	font-size: var(--hafe-counter-icon, 1.375em);
}

.hafe-counter__media--icon i,
.hafe-counter__media--icon svg {
	inline-size: 1em;
	block-size: 1em;
	font-size: 1em;
	line-height: 1;
	text-align: center;
	fill: currentColor;
}

/* An image shows as it is: no frame or tint. */
.hafe-counter .hafe-counter__media--image {
	inline-size: var(--hafe-counter-image, 4em);
	max-inline-size: 100%;
	overflow: hidden;
	border: 0;
	background: none;
}

.hafe-counter .hafe-counter__media--image img {
	display: block;
	width: 100%;
	max-width: none;
	height: auto;
}

.hafe-counter__body {
	display: flex;
	flex: var(--hafe-counter-body, 0 1 auto);
	flex-direction: column;
	align-items: var(--hafe-counter-items, center);
	gap: var(--hafe-counter-gap, 0.35em);
	/* Never wider than the card, so a word too long for it wraps inside it. */
	min-inline-size: 0;
	max-inline-size: 100%;
}

/* The number grows with the card up to its full size, the same in every card of a row; a figure
   too long for its card shrinks to fit, from its count of characters (--hafe-counter-chars). */
.hafe-counter .hafe-counter__number {
	order: 0;
	margin: 0;
	color: var(--hafe-counter-number-color, var(--hafe-counter-d-number));
	font-size: min(clamp(1.75em, 18cqi, 2.75em), 100cqi / (var(--hafe-counter-chars, 6) * 0.62));
	font-weight: 700;
	line-height: 1.1;
}

.hafe-counter__affix {
	color: var(--hafe-counter-affix-color, var(--hafe-counter-number-color, var(--hafe-counter-d-affix)));
	font-size: var(--hafe-counter-affix-size, 1em);
}

.hafe-counter-raised-yes .hafe-counter__affix {
	font-size: var(--hafe-counter-affix-size, 0.55em);
	vertical-align: 0.65em;
}

/* The value: the final number and the count in one grid cell, as wide as the wider, digits all the
   same width and the count kept to the right, so the figures stay put while it counts. The count
   and the room it may need are hidden until the script plays. */
.hafe-counter__value {
	display: inline-grid;
	direction: ltr;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
	unicode-bidi: isolate;
}

.hafe-counter__value > span {
	grid-area: 1 / 1;
	justify-self: end;
}

.hafe-counter__count,
.hafe-counter__room {
	visibility: hidden;
}

/* With a script and motion welcome, the count shows from the first paint until it's done. If the
   script never comes, the number shows after five seconds anyway. */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
	.hafe-counter__value:not(.is-done) > .hafe-counter__final {
		opacity: 0;
		animation: hafe-counter-show 0s 5s forwards;
	}

	.hafe-counter__value:not(.is-done) > .hafe-counter__count {
		visibility: visible;
		animation: hafe-counter-hide 0s 5s forwards;
	}

	.hafe-counter__value.is-ready > span {
		animation: none;
	}
}

@keyframes hafe-counter-show {
	to {
		opacity: 1;
	}
}

@keyframes hafe-counter-hide {
	to {
		visibility: hidden;
	}
}

.hafe-counter .hafe-counter__title {
	order: var(--hafe-counter-title-order, 0);
	margin: 0;
	color: var(--hafe-counter-title-color, var(--hafe-ink));
	font-size: 1.05em;
	font-weight: 600;
	line-height: 1.35;
}

.hafe-counter__text {
	color: var(--hafe-counter-text-color, var(--hafe-ink-soft));
	font-size: 0.9375em;
}

.hafe-counter__text > :first-child {
	margin-block-start: 0;
}

.hafe-counter__text > :last-child {
	margin-block-end: 0;
}

/* Links in a description stand out by more than colour (WCAG 1.4.1), whatever the theme does. */
.hafe-counter .hafe-counter__text a {
	color: inherit;
	text-decoration: underline;
}

/* Print shows the number itself. */
@media print {
	.hafe-counter .hafe-counter__value > .hafe-counter__final {
		opacity: 1;
	}

	.hafe-counter .hafe-counter__value > .hafe-counter__count {
		visibility: hidden;
	}
}
