/* 搜索 — 放大镜按钮 + 点击展开的灰线输入框，位于 RSS 按钮左侧 */
.search-box {
	position: relative;
	display: flex;
	align-items: center;
	height: 2.4rem;
	margin-left: auto;
	margin-right: 0.5em;
	margin-top: 1.6em;
}

/* 放大镜按钮 */
.search-toggle-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2.4rem;
	height: 2.4rem;
	padding: 0;
	background: transparent;
	border: none;
	border-radius: 0.375rem;
	cursor: pointer;
	font-size: inherit;
	flex-shrink: 0;
	transition: background-color 0.15s ease;
	color: var(--theme-nav-btn);
	/* 浅色模式下放大镜图标颜色 */
}

.search-toggle-btn:hover {
	background: var(--highlight-weak, rgba(128, 128, 128, 0.2));
}

.search-toggle-btn:focus-visible {
	outline: 2px solid var(--highlight-strong, rgba(128, 128, 128, 0.4));
	outline-offset: 2px;
}

.search-toggle-btn svg {
	width: 1.8rem;
	height: 1.8rem;
}

/* 深色模式下放大镜图标颜色 */
html[data-theme="dark"] .search-toggle-btn {
	color: var(--theme-nav-btn);
}

/* 灰线输入框 — 默认收起，点击放大镜后展开 */
.search-input {
	width: 0;
	height: 100%;
	padding: 0;
	border: none;
	border-bottom: 2px solid var(--theme-table-border, #ccc);
	background: transparent;
	/* 取消按钮（✕）与导航按钮配色一致 */
	color: var(--theme-nav-btn);
	-webkit-text-fill-color: var(--theme-text, #111);
	font-size: 0.95rem;
	outline: none;
	opacity: 0;
	box-sizing: border-box;
	flex-shrink: 0;
	transition:
		width 0.25s ease,
		opacity 0.25s ease;
}

/* 自定义 ✕：禁用原生外观，用 mask 绘制并跟随 currentColor */
.search-input::-webkit-search-cancel-button {
	-webkit-appearance: none;
	appearance: none;
	width: 0.9em;
	height: 0.9em;
	background: currentColor;
	mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M18.3 5.71 12.71 11.3l5.59 5.59a1 1 0 0 1-1.41 1.41L11.3 12.71l-5.59 5.59a1 1 0 0 1-1.41-1.41l5.59-5.59L4.3 5.71A1 1 0 0 1 5.71 4.3l5.59 5.59L16.89 4.3a1 1 0 1 1 1.41 1.41Z' fill='black'/></svg>") center / contain no-repeat;
	-webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M18.3 5.71 12.71 11.3l5.59 5.59a1 1 0 0 1-1.41 1.41L11.3 12.71l-5.59 5.59a1 1 0 0 1-1.41-1.41l5.59-5.59L4.3 5.71A1 1 0 0 1 5.71 4.3l5.59 5.59L16.89 4.3a1 1 0 1 1 1.41 1.41Z' fill='black'/></svg>") center / contain no-repeat;
	cursor: pointer;
}

/* 输入为空（placeholder 显示）时隐藏 ✕，虚拟文字占满整行 */
.search-input:placeholder-shown::-webkit-search-cancel-button {
	display: none;
}

html[data-theme="dark"] .search-input {
	color: var(--theme-nav-btn);
}

.search-input::placeholder {
	color: var(--theme-line-numbers-text, #aaa);
	opacity: 0.8;
}

.search-input:focus {
	border-bottom-color: var(--highlight-strong, rgba(128, 128, 128, 0.4));
}

.search-box.open .search-input {
	width: 34rem;
	padding: 0 0.3em;
	opacity: 1;
}

/* 下拉结果 */
.search-results {
	position: absolute;
	top: 100%;
	right: 0;
	width: 24rem;
	max-width: 80vw;
	max-height: 60vh;
	overflow-y: auto;
	display: none;
	background: var(--theme-bg, #fffff8);
	border: 1px solid var(--theme-table-border, #ccc);
	border-radius: 0.5rem;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
	z-index: 60;
}

.search-results.open {
	display: block;
}

/* 结果项 — 用高优先级选择器覆盖 .site-nav a:any-link 的泄漏样式
   （后者会给 nav 内所有 <a> 加 margin-top: 1em / font-size: 1.5rem） */
.site-nav .search-results a.search-result {
	display: flex;
	flex-direction: column;
	gap: 0.15em;
	padding: 0.6em 0.9em;
	margin: 0;
	font-size: inherit;
	text-decoration: none;
	color: var(--theme-text, #111);
	border-bottom: 1px solid var(--theme-table-row-even, #fafafa);
	transition: background-color 0.12s ease;
}

.site-nav .search-results a.search-result:last-child {
	border-bottom: none;
}

.site-nav .search-results a.search-result:hover {
	background: var(--highlight-weak, rgba(128, 128, 128, 0.2));
}

.search-result-title {
	font-size: 1rem;
	font-weight: 600;
	color: var(--theme-heading, #111);
}

.search-result-meta {
	font-size: 0.8rem;
	color: var(--theme-back-to-top, #777);
}

/* 命中关键字高亮 */
.search-highlight {
	background: var(--theme-search-highlight, rgba(255, 193, 7, 0.35));
	color: inherit;
	border-radius: 2px;
	padding: 0 0.1em;
}

.search-empty {
	padding: 0.8em 0.9em;
	color: var(--theme-back-to-top, #777);
	font-size: 0.9rem;
}

@media (max-width: 760px) {
	.search-box {
		margin-left: 0;
		margin-right: 0;
	}

	.search-box.open .search-input {
		width: 32vw;
		min-width: 8rem;
	}
}
