/* ============================================================
   Nav Search — search.css
   ============================================================ */

/* ── Toggle button ── */
.nav-search {
	position: relative;
	display: flex;
	align-items: center;
}

.nav-search-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.375rem;
	height: 2.25rem;
	padding: 0 0.75rem;
	border: 1px solid hsl(var(--border));
	border-radius: 9999px;
	background: transparent;
	color: hsl(var(--muted-foreground));
	font-size: 0.8125rem;
	font-family: var(--font-sans);
	cursor: pointer;
	transition:
		background 0.2s,
		color 0.2s,
		border-color 0.2s;
	white-space: nowrap;
}

.nav-search-toggle:hover,
.nav-search-toggle:focus-visible {
	background: hsl(var(--secondary));
	color: hsl(var(--foreground));
	border-color: hsl(var(--foreground) / 0.2);
	outline: none;
}

.nav-search-toggle[aria-expanded='true'] {
	background: hsl(var(--secondary));
	color: hsl(var(--accent));
	border-color: hsl(var(--accent) / 0.3);
}

.nav-search-toggle-icon {
	width: 0.9375rem;
	height: 0.9375rem;
	pointer-events: none;
	flex-shrink: 0;
}

.nav-search-toggle-label {
	display: none;
}

@media (min-width: 1024px) {
	.nav-search-toggle-label {
		display: inline;
	}
}

.nav-search-toggle-kbd {
	display: none;
	font-size: 0.6875rem;
	padding: 0.1em 0.4em;
	border-radius: 0.25rem;
	background: hsl(var(--muted));
	color: hsl(var(--muted-foreground));
	border: 1px solid hsl(var(--border));
	line-height: 1.4;
	font-family: var(--font-sans);
}

@media (min-width: 1024px) {
	.nav-search-toggle-kbd {
		display: inline;
	}
}

/* ── Panel ── */
.nav-search-panel {
	position: absolute;
	top: calc(100% + 0.625rem);
	right: 0;
	width: 22rem;
	background: hsl(var(--background));
	border: 1px solid hsl(var(--border));
	border-top: 3px solid hsl(var(--accent));
	border-radius: 0.875rem;
	box-shadow:
		0 4px 6px hsl(var(--foreground) / 0.04),
		0 12px 40px hsl(var(--foreground) / 0.12);
	overflow: hidden;
	opacity: 0;
	transform: translateY(-0.375rem) scale(0.98);
	transform-origin: top right;
	pointer-events: none;
	transition:
		opacity 0.18s ease,
		transform 0.18s ease;
	z-index: 200;
}

.nav-search-panel.is-open {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* ── Input wrap ── */
.nav-search-input-wrap {
	display: flex;
	align-items: center;
	padding: 0.625rem 0.875rem;
	border-bottom: 1px solid hsl(var(--border));
	gap: 0.5rem;
	transition: box-shadow 0.15s;
}

.nav-search-input-wrap:focus-within {
	box-shadow: inset 0 -2px 0 hsl(var(--accent) / 0.5);
}

.nav-search-input-icon {
	flex-shrink: 0;
	width: 1rem;
	height: 1rem;
	color: hsl(var(--muted-foreground));
	pointer-events: none;
}

.nav-search-input {
	flex: 1;
	min-width: 0;
	border: none;
	background: transparent;
	font-size: 1rem;
	font-family: var(--font-sans);
	color: hsl(var(--foreground));
	outline: none;
}

.nav-search-input::placeholder {
	color: hsl(var(--muted-foreground));
}

/* remove browser default clear button */
.nav-search-input::-webkit-search-cancel-button {
	display: none;
}

/* ── Spinner ── */
.nav-search-spinner {
	display: none;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.nav-search-spinner.is-visible {
	display: flex;
}

.nav-search-spinner-icon {
	width: 1rem;
	height: 1rem;
	color: hsl(var(--accent));
	animation: search-spin 0.75s linear infinite;
}

@keyframes search-spin {
	to {
		transform: rotate(360deg);
	}
}

/* ── Clear button ── */
.nav-search-clear {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 1.375rem;
	height: 1.375rem;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: hsl(var(--muted));
	color: hsl(var(--muted-foreground));
	cursor: pointer;
	flex-shrink: 0;
	transition:
		background 0.15s,
		color 0.15s;
}

.nav-search-clear:hover {
	background: hsl(var(--accent) / 0.15);
	color: hsl(var(--accent));
}

.nav-search-clear svg {
	width: 0.75rem;
	height: 0.75rem;
	pointer-events: none;
}

/* ── Results list ── */
.nav-search-results {
	list-style: none;
	margin: 0;
	padding: 0.375rem 0 0;
	max-height: 26rem;
	overflow-y: auto;
	overscroll-behavior: contain;
}

/* ── Single result ── */
.nav-search-result-link {
	display: block;
	padding: 0.625rem 0.875rem;
	text-decoration: none;
	color: hsl(var(--foreground));
	transition: background 0.12s;
	position: relative;
	border-left: 2px solid transparent;
}

.nav-search-result-link:hover,
.nav-search-result-link:focus-visible,
.nav-search-result-link.is-active {
	background: hsl(var(--secondary));
	border-left-color: hsl(var(--accent));
	outline: none;
}

.nav-search-result-top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	margin-bottom: 0.25rem;
}

.nav-search-result-title {
	font-size: 0.875rem;
	font-weight: 600;
	line-height: 1.3;
	color: hsl(var(--foreground));
	flex: 1;
	min-width: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.nav-search-result-type {
	flex-shrink: 0;
	font-size: 0.625rem;
	font-weight: 600;
	line-height: 1;
	padding: 0.25em 0.6em;
	border-radius: 9999px;
	background: hsl(var(--accent) / 0.1);
	color: hsl(var(--accent));
	text-transform: uppercase;
	letter-spacing: 0.06em;
}

.nav-search-result-excerpt {
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	font-size: 0.8125rem;
	color: hsl(var(--muted-foreground));
	line-height: 1.5;
}

/* ── Highlight ── */
.search-highlight {
	background: hsl(var(--accent) / 0.15);
	color: inherit;
	border-radius: 2px;
	padding: 0 1px;
}

/* ── Empty / error states ── */
.nav-search-no-results,
.nav-search-error {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.5rem;
	padding: 1.5rem 1rem;
	font-size: 0.875rem;
	color: hsl(var(--muted-foreground));
	text-align: center;
}

.nav-search-no-results svg,
.nav-search-error svg {
	width: 1.5rem;
	height: 1.5rem;
	opacity: 0.4;
}

.nav-search-error {
	color: hsl(0 72% 51%);
}

/* ── Keyboard hint footer ── */
.nav-search-hints {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.875rem;
	padding: 0.5rem 0.875rem;
	border-top: 1px solid hsl(var(--border));
	background: hsl(var(--muted) / 0.5);
}

.nav-search-hint {
	display: flex;
	align-items: center;
	gap: 0.3rem;
	font-size: 0.6875rem;
	color: hsl(var(--muted-foreground));
}

.nav-search-hint-key {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 1.25rem;
	height: 1.25rem;
	padding: 0 0.25rem;
	border-radius: 0.25rem;
	background: hsl(var(--background));
	border: 1px solid hsl(var(--border));
	font-size: 0.625rem;
	font-weight: 600;
	line-height: 1;
	color: hsl(var(--foreground));
}

/* ── Mobile (< 1024 px) ── */
@media (max-width: 1023px) {
	.nav-search-panel {
		position: fixed;
		top: 4rem;
		left: 0;
		right: 0;
		width: 100%;
		border-radius: 0;
		border-left: none;
		border-right: none;
		border-top: 3px solid hsl(var(--accent));
		transform: translateY(-0.25rem) scale(1);
		transform-origin: top center;
	}

	.nav-search-panel.is-open {
		transform: translateY(0) scale(1);
	}

	.nav-search-hints {
		display: none;
	}
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
	.nav-search-toggle,
	.nav-search-panel,
	.nav-search-result-link,
	.nav-search-input-wrap,
	.nav-search-clear {
		transition: none !important;
		animation: none !important;
	}

	.nav-search-spinner-icon {
		animation: none !important;
	}
}

/* ── High contrast ── */
html.high-contrast .nav-search-toggle {
	border-color: hsl(var(--foreground) / 0.5);
}

html.high-contrast .nav-search-panel {
	border-color: hsl(var(--foreground));
	border-top-color: hsl(var(--accent));
}

html.high-contrast .nav-search-result-link:hover,
html.high-contrast .nav-search-result-link.is-active {
	background: hsl(var(--foreground) / 0.12);
}

html.high-contrast .search-highlight {
	background: hsl(var(--accent) / 0.35);
	text-decoration: underline;
}

html.high-contrast .nav-search-result-type {
	border: 1px solid hsl(var(--accent) / 0.5);
}
