/* Impact Report category tooltips (mu-plugin). Colours follow the theme's text colour. */

/* Pill row */
.aaaf-term-pills {
	display: inline-flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	vertical-align: middle;
}

.aaaf-term-tip {
	position: relative;
	display: inline-block;
}

/* Pill */
.aaaf-term-tip__term {
	display: inline-block;
	padding: 0.25em 0.8em;
	border: 1px solid currentColor;
	border-radius: 999px;
	font-size: 0.875em;
	line-height: 1.4;
	white-space: nowrap;
}

.aaaf-term-tip--has-tip .aaaf-term-tip__term {
	cursor: help;
	transition: background-color 0.15s ease;
}

/* Small "i" marker on pills that have a definition. */
.aaaf-term-tip--has-tip .aaaf-term-tip__term::after {
	content: "i";
	content: "i" / ""; /* empty alt text: screen readers don't announce the "i" */
	display: inline-block;
	width: 1.1em;
	height: 1.1em;
	margin-left: 0.4em;
	border: 1px solid currentColor;
	border-radius: 50%;
	font-size: 0.75em;
	font-style: italic;
	font-weight: 700;
	line-height: 1.05em;
	text-align: center;
	vertical-align: 0.1em;
	opacity: 0.75;
}

.aaaf-term-tip--has-tip .aaaf-term-tip__term:hover,
.aaaf-term-tip--has-tip.is-open .aaaf-term-tip__term {
	background-color: rgba(0, 0, 0, 0.06);
	background-color: color-mix(in srgb, currentColor 10%, transparent);
}

.aaaf-term-tip__term:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.aaaf-term-tip__tooltip {
	--aaaf-tip-shift: 0px;
	position: absolute;
	bottom: calc(100% + 0.5rem);
	left: 50%;
	z-index: 1000;
	box-sizing: border-box;
	width: max-content;
	max-width: min(18rem, calc(100vw - 2rem));
	padding: 0.5rem 0.75rem;
	border-radius: 6px;
	background: #1d1d1d;
	color: #fff;
	font-size: 0.8125rem;
	font-weight: 400;
	font-style: normal;
	letter-spacing: normal;
	line-height: 1.45;
	text-align: left;
	text-transform: none;
	white-space: normal;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
	transform: translateX(calc(-50% + var(--aaaf-tip-shift))) translateY(4px);
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s linear 0.15s;
}

/* Arrow */
.aaaf-term-tip__tooltip::after {
	content: "";
	position: absolute;
	top: 100%;
	left: calc(50% - var(--aaaf-tip-shift));
	border: 6px solid transparent;
	border-top-color: #1d1d1d;
	transform: translateX(-50%);
}

/* Invisible bridge so the pointer can move from the label onto the tooltip. */
.aaaf-term-tip__tooltip::before {
	content: "";
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	height: 0.75rem;
}

/* Below the label when there's no room above (set by tooltips.js). */
.aaaf-term-tip.is-below .aaaf-term-tip__tooltip {
	top: calc(100% + 0.5rem);
	bottom: auto;
	transform: translateX(calc(-50% + var(--aaaf-tip-shift))) translateY(-4px);
}

.aaaf-term-tip.is-below .aaaf-term-tip__tooltip::after {
	top: auto;
	bottom: 100%;
	border-top-color: transparent;
	border-bottom-color: #1d1d1d;
}

.aaaf-term-tip.is-below .aaaf-term-tip__tooltip::before {
	top: auto;
	bottom: 100%;
}

/*
 * Show on keyboard focus, or when tapped open (is-open, set by tooltips.js).
 * Hover is limited to real pointers so touch screens don't get a "sticky"
 * hover state that a second tap can't close.
 */
.aaaf-term-tip__term:focus-visible + .aaaf-term-tip__tooltip,
.aaaf-term-tip--has-tip.is-open .aaaf-term-tip__tooltip {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: translateX(calc(-50% + var(--aaaf-tip-shift))) translateY(0);
	transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s;
}

@media (hover: hover) {
	.aaaf-term-tip--has-tip:hover .aaaf-term-tip__tooltip {
		opacity: 1;
		visibility: visible;
		pointer-events: auto;
		transform: translateX(calc(-50% + var(--aaaf-tip-shift))) translateY(0);
		transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s;
	}
}

/* Esc dismisses until the pointer leaves or focus moves (set by tooltips.js). */
.aaaf-term-tip--has-tip.is-dismissed .aaaf-term-tip__tooltip {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
	.aaaf-term-tip__tooltip,
	.aaaf-term-tip--has-tip .aaaf-term-tip__tooltip {
		transition: none !important;
	}
}

@media (forced-colors: active) {
	.aaaf-term-tip__tooltip {
		border: 1px solid CanvasText;
	}
}
