/**
 * Tainacan Semântico: relations preview on the faceted search results
 * (badge on each item + side drawer with the constellation).
 *
 * Tokens mirror the Tainacan theme variables, with fallbacks for themes that do
 * not define them. The drawer follows the site, not the operating system: the
 * script copies the page background and text colour into --tnc-relp-bg and
 * --tnc-relp-ink and sets color-scheme from them, so the constellation
 * (relations.css, drawn on the system colour Canvas) matches a light or a dark
 * theme alike.
 */
:root {
	--tnc-relp-accent: var(--tainacan-secondary, #187181);
	--tnc-relp-bg: var(--tainacan-background-color, #ffffff);
	--tnc-relp-ink: var(--tainacan-label-color, #1d1d1d);
	--tnc-relp-radius: var(--tainacan-button-border-radius, 999px);
	--tnc-relp-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
}

/* ---- badge ---------------------------------------------------------------- */

.tnc-relp-host {
	position: relative;
}

.tnc-relp-badge {
	position: absolute;
	top: 8px;
	right: 8px;
	z-index: 3;
	display: inline-flex;
	align-items: center;
	gap: 5px;
	margin: 0;
	padding: 4px 9px 4px 6px;
	border: 1px solid rgba(0, 0, 0, 0.08);
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.92);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.16);
	color: #1d1d1d;
	font: 600 12px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	letter-spacing: 0;
	text-transform: none;
	white-space: nowrap;
	cursor: pointer;
	-webkit-backdrop-filter: blur(6px);
	backdrop-filter: blur(6px);
	transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.tnc-relp-badge:hover,
.tnc-relp-badge:focus-visible {
	background: var(--tnc-relp-accent);
	border-color: transparent;
	color: #ffffff;
	transform: translateY(-1px);
}

.tnc-relp-badge:focus-visible {
	outline: 2px solid var(--tnc-relp-accent);
	outline-offset: 2px;
}

.tnc-relp-badge.is-inline {
	position: static;
	margin-top: 6px;
}

.tnc-relp-icon {
	width: 16px;
	height: 16px;
	flex: none;
	fill: currentColor;
	stroke: currentColor;
	stroke-width: 1.1;
}

.tnc-relp-icon circle:first-of-type {
	fill: var(--tnc-relp-accent);
	stroke: none;
}

.tnc-relp-badge:hover .tnc-relp-icon circle:first-of-type,
.tnc-relp-badge:focus-visible .tnc-relp-icon circle:first-of-type {
	fill: #ffffff;
}

/* Cards, records and list views put the title at the top: keep the badge clear of it. */
.tainacan-cards-container [data-tainacan-item-id] > .tnc-relp-badge,
.tainacan-records-container [data-tainacan-item-id] > .tnc-relp-badge,
.tainacan-list-container [data-tainacan-item-id] > .tnc-relp-badge {
	top: auto;
	bottom: 8px;
}

/* ---- drawer --------------------------------------------------------------- */

.tnc-relp {
	position: fixed;
	inset: 0;
	z-index: 100000;
	pointer-events: none;
}

.tnc-relp[hidden] {
	display: none;
}

.tnc-relp-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(10, 14, 18, 0.28);
	opacity: 0;
	pointer-events: auto;
	transition: opacity 0.2s ease;
}

.tnc-relp-drawer {
	--tnc-relp-muted: color-mix(in srgb, var(--tnc-relp-ink) 68%, transparent);
	--tnc-relp-line: color-mix(in srgb, var(--tnc-relp-ink) 16%, transparent);

	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	display: flex;
	flex-direction: column;
	width: min(780px, 100vw);
	background: var(--tnc-relp-bg);
	box-shadow: var(--tnc-relp-shadow);
	color: var(--tnc-relp-ink);
	font-size: 16px;
	line-height: 1.5;
	pointer-events: auto;
	transform: translateX(100%);
	transition: transform 0.24s ease;
}

/* Dark sites: a lighter accent keeps the kind label and buttons readable. */
.tnc-relp-drawer.is-dark {
	--tnc-relp-accent: #6cc4cc;
	--tnc-relp-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
}

.tnc-relp-drawer.is-dark .tnc-relp-open,
.tnc-relp-drawer.is-dark .tnc-relp-open:hover,
.tnc-relp-drawer.is-dark .tnc-relp-open:focus-visible {
	color: #0e1a1b;
}

.tnc-relp.is-open .tnc-relp-backdrop {
	opacity: 1;
}

.tnc-relp.is-open .tnc-relp-drawer {
	transform: none;
}

.tnc-relp-drawer *,
.tnc-relp-drawer *::before,
.tnc-relp-drawer *::after {
	box-sizing: border-box;
}

.tnc-relp-head {
	flex: none;
	padding: 14px clamp(16px, 3vw, 28px) 16px;
	border-bottom: 1px solid var(--tnc-relp-line);
}

.tnc-relp-bar {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 36px;
	margin-bottom: 8px;
}

.tnc-relp-eyebrow {
	flex: 1;
	color: var(--tnc-relp-muted);
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.tnc-relp-back,
.tnc-relp-close {
	margin: 0;
	border: 1px solid var(--tnc-relp-line);
	background: transparent;
	color: inherit;
	font: inherit;
	cursor: pointer;
}

.tnc-relp-back {
	padding: 4px 12px;
	border-radius: var(--tnc-relp-radius);
	font-size: 14px;
}

.tnc-relp-back[hidden] {
	display: none;
}

.tnc-relp-close {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	font-size: 22px;
	line-height: 1;
}

.tnc-relp-back:hover,
.tnc-relp-close:hover,
.tnc-relp-back:focus-visible,
.tnc-relp-close:focus-visible {
	border-color: var(--tnc-relp-accent);
	color: var(--tnc-relp-accent);
}

.tnc-relp-kind {
	display: block;
	color: var(--tnc-relp-accent);
	font-size: 13px;
	font-weight: 600;
}

.tnc-relp-title {
	margin: 2px 0 6px;
	color: inherit;
	font-size: clamp(20px, 2.4vw, 26px);
	line-height: 1.25;
	letter-spacing: -0.01em;
}

.tnc-relp-title:focus {
	outline: none;
}

.tnc-relp-summary {
	margin: 0 0 10px;
	color: var(--tnc-relp-muted);
	font-size: 15px;
}

.tnc-relp-summary:empty {
	display: none;
}

.tnc-relp-open {
	display: inline-block;
	padding: 7px 16px;
	border-radius: var(--tnc-relp-radius);
	background: var(--tnc-relp-accent);
	color: #ffffff;
	font-size: 14px;
	font-weight: 600;
	text-decoration: none;
}

.tnc-relp-open:hover,
.tnc-relp-open:focus-visible {
	color: #ffffff;
	filter: brightness(1.1);
	text-decoration: none;
}

.tnc-relp-body {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: 8px clamp(16px, 3vw, 28px) 16px;
	overscroll-behavior: contain;
}

.tnc-relp-hint {
	flex: none;
	margin: 0;
	padding: 10px clamp(16px, 3vw, 28px);
	border-top: 1px solid var(--tnc-relp-line);
	color: var(--tnc-relp-muted);
	font-size: 13px;
}

.tnc-relp-status {
	margin: 2rem 0;
	color: var(--tnc-relp-muted);
	text-align: center;
}

.tnc-relp-status.is-error {
	color: #b42318;
}

/* The constellation inside the drawer: the drawer already frames it. */
.tnc-relp-drawer .tnc-rel {
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
}

/* relations.css lightens two tooltip colours for a dark system scheme; the drawer follows the site instead. */
.tnc-relp-drawer:not(.is-dark) .tnc-rel-tip-kind {
	color: hsl(var(--h) 62% 36%);
}

.tnc-relp-drawer:not(.is-dark) .tnc-rel-tip-open {
	color: hsl(var(--h) 62% 40%);
}

.tnc-relp-drawer.is-dark .tnc-rel-tip-kind {
	color: hsl(var(--h) 70% 74%);
}

.tnc-relp-drawer.is-dark .tnc-rel-tip-open {
	color: hsl(var(--h) 70% 72%);
}

@media (prefers-reduced-motion: reduce) {
	.tnc-relp-drawer,
	.tnc-relp-backdrop,
	.tnc-relp-badge {
		transition: none;
	}
}

@media print {
	.tnc-relp,
	.tnc-relp-badge {
		display: none !important;
	}
}
