/*
 * NutriScrolls data blocks: shared components (Figma "04 Components").
 * Only semantic tokens from the theme (web/app/themes/nutriscrolls/TOKENS.md), so light and dark
 * mode switch with the theme. Block-specific rules live in blocks/<slug>/style.css.
 */

.ns-visually-hidden {
	border: 0;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	white-space: nowrap;
	width: 1px;
}

/* Controls that need script (switches, filters, "show all") are hidden without it. */
@media (scripting: none) {
	[data-ns-requires-js] {
		display: none !important;
	}
}

/* Elements toggled with [hidden] ("Show all" labels, filtered hub items) stay hidden whatever display a class sets. */
[class*="wp-block-nutriscrolls-"] [hidden] {
	display: none !important;
}

.ns-cell-num {
	font-variant-numeric: tabular-nums;
	text-align: end;
	white-space: nowrap;
}

/* ---------- Panel (white card used by tables and lists) ---------- */
.ns-nutrition-facts,
.ns-top-foods,
.ns-reference-intakes,
.ns-comparison-table {
	background: var(--wp--preset--color--surface-raised);
	border: var(--wp--custom--border--hairline) solid var(--wp--preset--color--line);
	border-radius: var(--wp--custom--radius--lg);
	box-sizing: border-box;
	color: var(--wp--preset--color--ink);
	padding: var(--wp--preset--spacing--50);
}

/* ---------- Icons: Figma SVGs as masks, so they follow currentColor ---------- */
.ns-icon {
	background-color: currentcolor;
	display: inline-block;
	flex: none;
	height: 16px;
	-webkit-mask: var(--ns-icon) center / contain no-repeat;
	mask: var(--ns-icon) center / contain no-repeat;
	vertical-align: middle;
	width: 16px;
}
.ns-icon--arrow-right { --ns-icon: url("assets/icons/arrow-right.svg"); }
.ns-icon--chevron-right { --ns-icon: url("assets/icons/chevron-right.svg"); }
.ns-icon--chevron-down { --ns-icon: url("assets/icons/chevron-down.svg"); height: 20px; width: 20px; }
.ns-icon--chevron-up { --ns-icon: url("assets/icons/chevron-up.svg"); height: 20px; width: 20px; }
.ns-icon--person { --ns-icon: url("assets/icons/person-20.svg"); height: 20px; width: 20px; }
.ns-icon--search { --ns-icon: url("assets/icons/search.svg"); height: 20px; width: 20px; }
.ns-icon--check { --ns-icon: url("assets/icons/check.svg"); }
.ns-icon--info { --ns-icon: url("assets/icons/info.svg"); height: 24px; width: 24px; }

/* ---------- Text link (standalone, with arrow) ---------- */
.ns-text-link {
	align-items: center;
	background: none;
	border: 0;
	border-radius: var(--wp--custom--radius--sm);
	color: var(--wp--preset--color--link-default);
	cursor: pointer;
	display: inline-flex;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--body-small);
	font-weight: 600;
	gap: var(--wp--preset--spacing--10);
	line-height: var(--wp--custom--line-height--body-small);
	min-height: 24px;
	padding: 0;
	text-decoration: none;
}
.ns-text-link:hover {
	color: var(--wp--preset--color--link-hover);
	text-decoration: underline;
	text-underline-offset: 0.2em;
}

/* ---------- Tag ---------- */
.ns-tag {
	align-items: center;
	background: var(--wp--preset--color--action-subtle);
	border-radius: var(--wp--custom--radius--sm);
	color: var(--wp--preset--color--on-action-subtle);
	display: inline-flex;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--caption);
	font-weight: 500;
	gap: 0.3em;
	line-height: var(--wp--custom--line-height--caption);
	padding: var(--wp--preset--spacing--10) var(--wp--preset--spacing--20);
	white-space: nowrap;
}
.ns-tag--accent {
	background: var(--wp--preset--color--accent-subtle);
	color: var(--wp--preset--color--on-accent-subtle);
}
.ns-tag--neutral {
	background: var(--wp--preset--color--surface-strong);
	color: var(--wp--preset--color--ink);
}
.ns-tag--outline {
	background: transparent;
	box-shadow: inset 0 0 0 1px var(--wp--preset--color--line-strong);
	color: var(--wp--preset--color--ink);
}

/* ---------- Segmented control (44 px: 4 px track + 36 px segments) ---------- */
.ns-segmented {
	background: var(--wp--preset--color--surface-strong);
	border-radius: var(--wp--custom--radius--md);
	box-sizing: border-box;
	display: inline-flex;
	gap: var(--wp--preset--spacing--10);
	padding: var(--wp--preset--spacing--10);
}
.ns-segmented__option {
	align-items: center;
	background: transparent;
	border: var(--wp--custom--border--hairline) solid transparent;
	border-radius: var(--wp--custom--radius--sm);
	color: var(--wp--preset--color--ink-muted);
	cursor: pointer;
	display: inline-flex;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--label-small);
	font-weight: 600;
	height: 36px;
	justify-content: center;
	line-height: var(--wp--custom--line-height--label-small);
	margin: 0;
	padding: 0 var(--wp--preset--spacing--40);
	transition: var(--ns-transition-hover, color 120ms, background-color 120ms);
	white-space: nowrap;
}
.ns-segmented__option:hover {
	color: var(--wp--preset--color--ink);
}
.ns-segmented__option[aria-pressed="true"] {
	background: var(--wp--preset--color--surface-raised);
	border-color: var(--wp--preset--color--line-strong);
	box-shadow: var(--wp--preset--shadow--sm);
	color: var(--wp--preset--color--ink);
}
@media (max-width: 599px) {
	.ns-segmented {
		display: flex;
		width: 100%;
	}
	.ns-segmented__option {
		flex: 1 1 0;
		padding-inline: var(--wp--preset--spacing--20);
	}
}

/* ---------- % DV bar: 8 px pill track, fill = % (or % of the list maximum), marker at 100 % ---------- */
.ns-dv-bar {
	display: block;
	height: 14px;
	position: relative;
	width: 100%;
}
.ns-dv-bar::before {
	background: var(--wp--preset--color--dv-track);
	border-radius: var(--wp--custom--radius--pill);
	content: "";
	height: 8px;
	inset-inline: 0;
	position: absolute;
	top: 3px;
}
.ns-dv-bar__fill {
	background: var(--wp--preset--color--dv-fill);
	border-radius: var(--wp--custom--radius--pill);
	height: 8px;
	inset-inline-start: 0;
	min-width: 2px;
	position: absolute;
	top: 3px;
	width: var(--ns-fill, 0%);
}
.ns-dv-bar.is-over .ns-dv-bar__fill {
	background: var(--wp--preset--color--dv-fill-high);
}
.ns-dv-bar__marker {
	background: var(--wp--preset--color--dv-marker);
	height: 14px;
	inset-inline-start: var(--ns-marker, 100%);
	position: absolute;
	top: 0;
	transform: translateX(-1px);
	width: 2px;
}
.ns-dv-bar.is-none::before {
	background: transparent;
	border: var(--wp--custom--border--hairline) dashed var(--wp--preset--color--line-strong);
	box-sizing: border-box;
}

/* ---------- Click-to-play video (Support\VideoConsent) ---------- */
.ns-video__frame {
	aspect-ratio: 16 / 9;
	background: var(--wp--preset--color--surface-inverse);
	border-radius: var(--wp--custom--radius--lg);
	overflow: hidden;
	position: relative;
}
.ns-video__frame iframe {
	border: 0;
	height: 100%;
	inset: 0;
	position: absolute;
	width: 100%;
}
.ns-video__play {
	align-items: center;
	background: transparent;
	border: 0;
	color: var(--wp--preset--color--ink-inverse);
	cursor: pointer;
	display: flex;
	flex-direction: column;
	font-family: var(--wp--preset--font-family--body);
	gap: var(--wp--preset--spacing--20);
	height: 100%;
	justify-content: center;
	width: 100%;
}
.ns-video__icon {
	border-bottom: 18px solid transparent;
	border-left: 30px solid currentColor;
	border-top: 18px solid transparent;
	height: 0;
	margin-bottom: var(--wp--preset--spacing--20);
	width: 0;
}
.ns-video__label {
	font-size: var(--wp--preset--font-size--label);
	font-weight: 600;
}
.ns-video__note {
	color: var(--wp--preset--color--ink-inverse-muted);
	font-size: var(--wp--preset--font-size--caption);
}
.ns-video__play:focus-visible {
	outline: 2px solid var(--wp--preset--color--focus);
	outline-offset: -4px;
}

/* ---------- Buttons used inside blocks ---------- */
.ns-button {
	align-items: center;
	border-radius: var(--wp--custom--radius--md);
	box-sizing: border-box;
	display: inline-flex;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--label);
	font-weight: 600;
	gap: var(--wp--preset--spacing--20);
	justify-content: center;
	line-height: var(--wp--custom--line-height--label);
	min-height: 44px;
	padding: 0 var(--wp--preset--spacing--50);
	text-decoration: none;
	transition: var(--ns-transition-hover, background-color 120ms);
}
.ns-button--secondary {
	background: var(--wp--preset--color--surface-raised);
	border: var(--wp--custom--border--hairline) solid var(--wp--preset--color--action);
	color: var(--wp--preset--color--link-default);
}
.ns-button--secondary:hover {
	background: var(--wp--preset--color--action-subtle);
}

/* ---------- Empty state (Figma "Data block state", Empty) ---------- */
.ns-empty {
	align-items: center;
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--30);
	padding: var(--wp--preset--spacing--60) 0;
	text-align: center;
}
.ns-empty__icon {
	align-items: center;
	background: var(--wp--preset--color--surface-strong);
	border-radius: var(--wp--custom--radius--pill);
	color: var(--wp--preset--color--ink-muted);
	display: inline-flex;
	height: 48px;
	justify-content: center;
	width: 48px;
}
.ns-empty__title {
	color: var(--wp--preset--color--ink);
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--h-5);
	font-weight: 600;
	line-height: var(--wp--custom--line-height--h-5);
	margin: 0;
}
.ns-empty__text {
	color: var(--wp--preset--color--ink-muted);
	font-size: var(--wp--preset--font-size--body-small);
	line-height: var(--wp--custom--line-height--body-small);
	margin: 0;
	max-width: 440px;
}

/* ---------- Cards (Figma "Food card", "Nutrient card") ---------- */
.ns-card-grid {
	display: grid;
	gap: var(--wp--preset--spacing--50);
	grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
	list-style: none;
	margin: 0;
	padding: 0;
}
.ns-card-grid > li {
	display: flex;
	margin: 0;
}
.ns-card {
	background: var(--wp--preset--color--surface-raised);
	border: var(--wp--custom--border--hairline) solid var(--wp--preset--color--line);
	border-radius: var(--wp--custom--radius--lg);
	box-sizing: border-box;
	color: var(--wp--preset--color--ink);
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	overflow: hidden;
	position: relative;
	transition: var(--ns-transition-hover, border-color 120ms, box-shadow 120ms);
}
.ns-card:hover {
	border-color: var(--wp--preset--color--line-strong);
	box-shadow: var(--wp--preset--shadow--md);
}
.ns-card:has(.ns-card__link:focus-visible) {
	outline: var(--wp--custom--border--focus) solid var(--wp--preset--color--focus);
	outline-offset: 2px;
}
.ns-card__media {
	aspect-ratio: 296 / 200;
	background: var(--wp--preset--color--surface-strong);
	flex: none;
	overflow: hidden;
}
.ns-card__img {
	display: block;
	height: 100%;
	object-fit: cover;
	width: 100%;
}
.ns-card__body {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	gap: var(--wp--preset--spacing--20);
	padding: var(--wp--preset--spacing--40);
}
.ns-card--no-media .ns-card__body {
	padding: var(--wp--preset--spacing--50);
}
.ns-card__eyebrow {
	color: var(--wp--preset--color--accent);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--eyebrow);
	font-weight: 600;
	letter-spacing: 0.08em;
	line-height: var(--wp--custom--line-height--eyebrow);
	margin: 0;
	text-transform: uppercase;
}
.ns-card__title {
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--h-5);
	font-weight: 600;
	line-height: var(--wp--custom--line-height--h-5);
	margin: 0;
	width: fit-content;
}
.ns-card__link {
	color: inherit;
	text-decoration: none;
}
.ns-card__link::after {
	content: "";
	inset: 0;
	position: absolute;
	z-index: 1;
}
.ns-card__link:focus-visible {
	outline: none;
}
.ns-card:hover .ns-card__link {
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
}
.ns-card__meta,
.ns-card__reference p {
	color: var(--wp--preset--color--ink-muted);
	margin: 0;
}
.ns-card__reference {
	border-top: var(--wp--custom--border--hairline) solid var(--wp--preset--color--line);
	display: flex;
	flex-direction: column;
	gap: 2px;
	margin-top: auto;
	padding-top: var(--wp--preset--spacing--20);
}
.ns-card__reference p:first-child {
	color: var(--wp--preset--color--ink);
}
.ns-card__tags {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--10);
	margin: 0;
}
.ns-card__summary {
	color: var(--wp--preset--color--ink-muted);
	font-size: var(--wp--preset--font-size--body-small);
	line-height: var(--wp--custom--line-height--body-small);
	margin: 0;
}
/* Nutrient badge (NutrientBadge.php): a symbol tile in the image slot, same aspect ratio as the card image.
   vitamins green, minerals blue, others neutral; the symbol scales with the tile (container query units). */
.ns-card__media--badge {
	align-items: center;
	container-type: inline-size;
	display: flex;
	justify-content: center;
}
.ns-card__media--vitamin {
	background: var(--wp--preset--color--google-green-soft);
	color: var(--wp--preset--color--on-google-green-soft);
}
.ns-card__media--mineral {
	background: var(--wp--preset--color--google-blue-soft);
	color: var(--wp--preset--color--on-google-blue-soft);
}
.ns-card__media--other {
	background: var(--wp--preset--color--surface-strong);
	color: var(--wp--preset--color--ink);
}
.ns-card__symbol {
	font-family: var(--wp--preset--font-family--body);
	font-size: 3rem;
	font-variant-numeric: lining-nums;
	font-weight: 600;
	letter-spacing: -0.01em;
	line-height: 1;
	text-align: center;
	white-space: nowrap;
}
@supports (width: 1cqw) {
	.ns-card__symbol--s { font-size: 28cqw; }
	.ns-card__symbol--m { font-size: 23cqw; }
	.ns-card__symbol--l { font-size: 17cqw; }
}

/* Mobile: horizontal cards (image left) in a single column */
@media (max-width: 599px) {
	.ns-card-grid {
		gap: var(--wp--preset--spacing--30);
		grid-template-columns: 1fr;
	}
	.ns-card--food,
	.ns-card--page,
	.ns-card--phytochemical,
	.ns-card--nutrient:not(.ns-card--no-media) {
		flex-direction: row;
	}
	/* A 4:3 thumbnail at the top (the photos are 4:3, so nothing is cropped), not a column as tall as the text, which
	   cropped the photos to a sliver. */
	.ns-card--food .ns-card__media,
	.ns-card--page .ns-card__media,
	.ns-card--phytochemical .ns-card__media,
	.ns-card--nutrient .ns-card__media {
		align-self: flex-start;
		aspect-ratio: 4 / 3;
		border-radius: var(--wp--custom--radius--md);
		margin: var(--wp--preset--spacing--30) 0 var(--wp--preset--spacing--30) var(--wp--preset--spacing--30);
		width: 96px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ns-card,
	.ns-segmented__option,
	.ns-button {
		transition: none;
	}
}

/* ---------- Personal needs (blocks/view/personal.js) ---------- */
/* With sex and age set (html[data-personal]) the % values are recomputed in the browser: hide them (they keep their space, no
   layout shift) until personal.js has set html[data-personal-ready]; after 1.5 s without data the label values show. */
html[data-personal]:not([data-personal-ready]) [data-ns-p],
html[data-personal]:not([data-personal-ready]) [data-ns-sub],
html[data-personal]:not([data-personal-ready]) .ns-nf__vm,
html[data-personal]:not([data-personal-ready]) .ns-nf__more--vm .ns-nf__rows {
	visibility: hidden;
}

/* ---------- Popover (evidence labels, nutrient density): native popover anchored to its button, a bottom sheet on
   narrow screens; blocks/view/evidence-label.js adds aria-expanded, focus and placement without anchor positioning. */
.ns-evidence-label__pop {
	background: var(--wp--preset--color--surface-raised);
	border: 1px solid var(--wp--preset--color--line);
	border-radius: var(--wp--custom--radius--lg);
	box-shadow: var(--wp--preset--shadow--md);
	box-sizing: border-box;
	color: var(--wp--preset--color--ink);
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--body-sm, 0.9375rem);
	inset: auto;
	line-height: 1.5;
	margin: 0;
	max-width: min(22rem, calc(100vw - 1rem));
	overflow: visible;
	padding: var(--wp--preset--spacing--40) var(--wp--preset--spacing--40) var(--wp--preset--spacing--30);
	position: fixed;
	width: max-content;
}
@supports (anchor-name: --a) {
	.ns-evidence-label__pop {
		margin-block-start: 6px;
		position-try-fallbacks: flip-block, flip-inline;
		top: anchor(bottom);
		left: anchor(left);
	}
}
@supports not selector(:popover-open) {
	.ns-evidence-label__pop { display: none; }
}
.ns-evidence-label__fallback {
	display: none;
}
@supports not selector(:popover-open) {
	.ns-evidence-label__fallback {
		color: var(--wp--preset--color--link-default);
		display: inline;
		font-size: var(--wp--preset--font-size--caption);
	}
}
.ns-evidence-label__pop-title {
	font-family: var(--wp--preset--font-family--body);
	font-weight: 600;
	margin: 0 var(--wp--preset--spacing--50) var(--wp--preset--spacing--10) 0;
}
.ns-evidence-label__pop-text {
	color: var(--wp--preset--color--ink);
	margin: 0 0 var(--wp--preset--spacing--30);
}
.ns-evidence-label__pop-link {
	color: var(--wp--preset--color--link-default);
	font-weight: 500;
	text-underline-offset: 0.2em;
}
.ns-evidence-label__pop-link:hover {
	color: var(--wp--preset--color--link-hover);
}
.ns-evidence-label__close {
	align-items: center;
	appearance: none;
	background: transparent;
	border: 0;
	border-radius: var(--wp--custom--radius--md);
	color: var(--wp--preset--color--ink-muted);
	cursor: pointer;
	display: inline-flex;
	font-size: 1.25rem;
	height: 32px;
	justify-content: center;
	line-height: 1;
	padding: 0;
	position: absolute;
	right: var(--wp--preset--spacing--20);
	top: var(--wp--preset--spacing--20);
	width: 32px;
}
.ns-evidence-label__close:hover {
	background: var(--wp--preset--color--surface-strong);
	color: var(--wp--preset--color--ink);
}
.ns-evidence-label__close:focus-visible,
.ns-evidence-label__pop-link:focus-visible {
	outline: var(--wp--custom--border--focus) solid var(--wp--preset--color--focus);
	outline-offset: 2px;
}

/* Narrow screens: bottom sheet */
@media (max-width: 479.98px) {
	.ns-evidence-label__pop {
		border-radius: var(--wp--custom--radius--lg) var(--wp--custom--radius--lg) 0 0;
		border-width: 1px 0 0;
		bottom: 0;
		left: 0;
		margin: 0;
		max-width: none;
		padding: var(--wp--preset--spacing--50) var(--wp--preset--spacing--40) var(--wp--preset--spacing--60);
		position: fixed;
		right: 0;
		top: auto;
		width: 100%;
	}
	.ns-evidence-label__pop::backdrop {
		background: rgb(15 27 45 / 40%);
	}
}
@media (prefers-reduced-motion: no-preference) {
	.ns-evidence-label__pop:popover-open {
		animation: ns-evidence-pop 120ms ease-out;
	}
	@keyframes ns-evidence-pop {
		from { opacity: 0; }
	}
}
