/*
 * Header search: a command-palette-style overlay.
 *
 * Its own sheet, same reasoning as newsletter.css and article.css: a
 * component with a dialog, an animated backdrop, a live-typeahead list and
 * four states (idle / loading / results / empty) is easier to reason about
 * whole than folded into brand.css.
 *
 * Native <dialog> in the top layer, so nothing here fights the sticky
 * header or the cookie banner for z-index and none is set (same trick as
 * .c-nl in newsletter.css).
 *
 * COLOUR NOTES, same measured palette as the newsletter modal:
 *   #FFFFFF on #7C5CFC   4.38:1   the active result row, the "view all" pill
 *   #FFFFFF on #0D0D0F  19.5:1    the search bar
 *   #B3B3B3 on #141416   9.1:1    meta text (category / date)
 *   #9478FD on #141416   5.4:1    accent used as small text
 */

.c-search {
	width: min(100%, 40rem);
	max-width: calc(100vw - 2rem);
	max-height: calc(100dvh - 4rem);
	margin-top: 4dvh;
	padding: 0;
	border: 0;
	border-radius: 20px;
	background: transparent;
	color: #FFFFFF;
	overflow: visible;
}

.c-search::backdrop {
	background: rgba(6, 6, 8, 0.78);
	backdrop-filter: blur(10px) saturate(120%);
	opacity: 0;
	transition: opacity 240ms ease;
}

.c-search.is-open::backdrop {
	opacity: 1;
}

/* Same display:none -> block reasoning as .c-nl: showModal() cannot be
   observed by a transition until a layout read separates the two (see
   search.js). */
.c-search__shell {
	transform: translateY(-14px) scale(0.97);
	opacity: 0;
	transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1), opacity 200ms ease;

	display: flex;
	flex-direction: column;
	max-height: calc(100dvh - 4rem);
	border-radius: 20px;
	background: #141416;
	box-shadow:
		0 24px 60px -12px rgba(0, 0, 0, 0.55),
		0 0 0 1px rgba(255, 255, 255, 0.06),
		0 0 80px -20px rgba(124, 92, 252, 0.35);
	overflow: hidden;
}

.c-search.is-open .c-search__shell {
	transform: translateY(0) scale(1);
	opacity: 1;
}

/* ------------------------------------------------------------- search bar */

.c-search__bar {
	position: relative;
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 1.1rem 1.25rem;
	background: #0D0D0F;
	border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.c-search__bar-icon {
	flex: 0 0 auto;
	color: rgba(255, 255, 255, 0.45);
}

.c-search__bar:focus-within .c-search__bar-icon {
	color: #9478FD;
}

.c-search__input {
	flex: 1 1 auto;
	min-width: 0;
	border: 0;
	background: transparent;
	color: #FFFFFF;
	font-family: var(--font-family-serif, 'Instrument Serif', Georgia, serif);
	font-size: clamp(1.15rem, 2.4vw, 1.4rem);
	line-height: 1.2;
}

.c-search__input:focus {
	outline: none;
}

.c-search__input::placeholder {
	color: rgba(255, 255, 255, 0.38);
}

/* Kill the native OS clear/cancel button so it doesn't collide with our own
   close icon, which stays reachable and visible at all times instead. */
.c-search__input::-webkit-search-cancel-button {
	-webkit-appearance: none;
	appearance: none;
}

.c-search__close {
	flex: 0 0 auto;
	display: grid;
	place-items: center;
	width: 32px;
	height: 32px;
	border: 0;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.06);
	color: rgba(255, 255, 255, 0.7);
	cursor: pointer;
	transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.c-search__close:hover {
	background: rgba(255, 255, 255, 0.12);
	color: #FFFFFF;
	transform: rotate(90deg);
}

/* ------------------------------------------------------------------- body */

.c-search__body {
	position: relative;
	overflow-y: auto;
	max-height: calc(100dvh - 4rem - 68px); /* shell max-height minus the bar */
}

/* A thin animated top border while a request is in flight — quieter than a
   spinner, and it can't jump the layout the way a centred loader would. */
.c-search__body.is-loading::before {
	content: "";
	position: absolute;
	inset: 0 0 auto 0;
	height: 2px;
	background: linear-gradient(90deg, transparent, #7C5CFC, #9478FD, #7C5CFC, transparent);
	background-size: 200% 100%;
	animation: afw-search-scan 1.1s linear infinite;
	z-index: 1;
}

@keyframes afw-search-scan {
	from { background-position: 200% 0; }
	to   { background-position: -200% 0; }
}

/* -------------------------------------------------------------------- idle */

.c-search__idle {
	padding: 1.5rem 1.25rem 1.75rem;
}

.c-search__idle-label {
	margin: 0 0 0.75rem;
	font-family: var(--font-family-sansSerif);
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: rgba(255, 255, 255, 0.45);
}

.c-search__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.c-search__chip {
	display: inline-flex;
	align-items: center;
	padding: 0.45rem 0.9rem;
	border-radius: 999px;
	background: rgba(124, 92, 252, 0.12);
	border: 1px solid rgba(124, 92, 252, 0.35);
	color: #C7B9FF;
	font-family: var(--font-family-sansSerif);
	font-size: 13px;
	font-weight: 600;
	text-decoration: none;
	transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.c-search__chip:hover {
	background: rgba(124, 92, 252, 0.24);
	border-color: rgba(124, 92, 252, 0.6);
	transform: translateY(-1px);
}

/* ---------------------------------------------------------------- results */

.c-search__results {
	margin: 0;
	padding: 0.5rem;
	list-style: none;
}

.c-search__result {
	margin: 0;
}

.c-search__result-link {
	display: flex;
	align-items: center;
	gap: 0.85rem;
	padding: 0.6rem 0.75rem;
	border-radius: 12px;
	text-decoration: none;
	color: inherit;
	opacity: 0;
	animation: afw-search-row-in 240ms ease forwards;
	animation-delay: calc(var(--i, 0) * 35ms);
}

@keyframes afw-search-row-in {
	from { opacity: 0; transform: translateY(4px); }
	to   { opacity: 1; transform: translateY(0); }
}

.c-search__result-link:hover,
.c-search__result-link.is-active {
	background: rgba(124, 92, 252, 0.14);
}

.c-search__result-link:focus-visible {
	outline: 2px solid #9478FD;
	outline-offset: -2px;
}

.c-search__result-thumb {
	flex: 0 0 auto;
	width: 56px;
	height: 56px;
	border-radius: 10px;
	object-fit: cover;
	background: rgba(255, 255, 255, 0.06);
}

.c-search__result-thumb--empty {
	background: linear-gradient(135deg, rgba(124, 92, 252, 0.35), rgba(75, 47, 191, 0.35));
}

.c-search__result-copy {
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
}

.c-search__result-title {
	font-family: var(--font-family-sansSerif);
	font-size: 14.5px;
	font-weight: 600;
	line-height: 1.35;
	color: #FFFFFF;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.c-search__result-title mark {
	background: transparent;
	color: #C7B9FF;
	font-weight: 700;
}

.c-search__result-meta {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	font-family: var(--font-family-sansSerif);
	font-size: 12px;
	color: #B3B3B3;
}

.c-search__result-cat {
	color: #9478FD;
	font-weight: 600;
}

.c-search__result-cat::after {
	content: "";
	display: inline-block;
	width: 3px;
	height: 3px;
	margin-left: 0.5rem;
	border-radius: 50%;
	background: currentColor;
	vertical-align: middle;
}

/* --------------------------------------------------------------------empty */

.c-search__empty {
	padding: 2.5rem 1.5rem;
	text-align: center;
}

.c-search__empty p {
	margin: 0;
	font-family: var(--font-family-sansSerif);
	color: rgba(255, 255, 255, 0.85);
}

.c-search__empty-hint {
	margin-top: 0.35rem !important;
	font-size: 13px;
	color: rgba(255, 255, 255, 0.5) !important;
}

/* -------------------------------------------------------------------footer */

/* The [hidden] attribute is toggled by search.js to switch panels, but a
   plain-class `display: flex` sits at the same specificity as the UA
   stylesheet's `[hidden] { display: none }` and author rules always beat
   UA rules regardless of specificity — so without this, the footer would
   stay visible (empty) even while [hidden] is set. */
.c-search__footer[hidden] {
	display: none;
}

.c-search__footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.75rem 1.25rem;
	background: #0D0D0F;
	border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.c-search__view-all {
	font-family: var(--font-family-sansSerif);
	font-size: 13px;
	font-weight: 600;
	color: #FFFFFF;
	text-decoration: none;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.c-search__view-all::after {
	content: " →";
	color: #9478FD;
}

.c-search__view-all:hover {
	text-decoration: underline;
	text-decoration-color: #9478FD;
}

.c-search__kbd-hint {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	gap: 0.3rem;
	font-family: var(--font-family-sansSerif);
	font-size: 12px;
	color: rgba(255, 255, 255, 0.4);
}

.c-search__kbd-hint kbd {
	padding: 0.1rem 0.4rem;
	border-radius: 5px;
	background: rgba(255, 255, 255, 0.08);
	border: 1px solid rgba(255, 255, 255, 0.14);
	font-family: inherit;
	font-size: 11px;
}

@media (max-width: 640px) {
	.c-search {
		margin-top: 0;
		max-height: 100dvh;
		border-radius: 0;
	}

	.c-search__shell {
		max-height: 100dvh;
		border-radius: 0;
		height: 100dvh;
	}

	.c-search__kbd-hint {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.c-search__shell,
	.c-search__result-link,
	.c-search__close {
		animation: none !important;
		transition: none !important;
	}
}
