/**
 * Alee Search Enhance — Frontend styles (v2.2.3)
 *
 * Design philosophy:
 *   - Clean, lightweight, and uncluttered — the content is the star
 *   - Exactly ONE search icon visible (decorative, placed on the right for a cleaner action pattern)
 *   - Mobile-first; the docked overlay docks under the theme's header
 *   - Respect system color scheme (light/dark)
 *   - Zero animation jank, sub-60ms input response
 *
 * Structure:
 *   .alee-se-trigger     → the button that opens the docked overlay
 *   .alee-se-overlay     → the full-viewport docked container (injected in footer)
 *   .alee-se-overlay__scrim → dark backdrop (click to close)
 *   .alee-se-overlay__panel → the docked panel below the header
 *   .alee-se-wrap        → form + dropdown container (inline or docked)
 *   .alee-se-form        → the search bar itself
 *   .alee-se-dropdown    → suggestion results list
 *
 * All tokens are scoped under .alee-se-wrap and .alee-se-overlay so we never
 * pollute the theme's variable namespace.
 */

/* ============================================================
 *  DESIGN TOKENS
 * ============================================================ */
.alee-se-wrap,
.alee-se-overlay,
.alee-se-trigger {
	--alee-se-bg:           #ffffff;
	--alee-se-bg-subtle:    #f8fafc;
	--alee-se-text:         #0f172a;
	--alee-se-text-soft:    #334155;
	--alee-se-muted:        #64748b;
	--alee-se-border:       #e5e7eb;
	--alee-se-border-soft:  #f1f5f9;
	--alee-se-accent:       #4f46e5;
	--alee-se-accent-text:  #4338ca;
	--alee-se-accent-soft:  rgba(79, 70, 229, 0.08);
	--alee-se-accent-ring:  rgba(79, 70, 229, 0.18);
	--alee-se-danger:       #dc2626;
	--alee-se-shadow-sm:    0 1px 2px rgba(15, 23, 42, 0.04);
	--alee-se-shadow:       0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
	--alee-se-shadow-lg:    0 12px 32px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.04);
	--alee-se-radius:       12px;
	--alee-se-radius-sm:    8px;
	--alee-se-radius-xs:    6px;
	--alee-se-dock-top:     0px;

	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
	             "Helvetica Neue", Arial, "Noto Sans Thai", "Sarabun",
	             "Prompt", "Kanit", sans-serif;
	box-sizing: border-box;
}

.alee-se-wrap *,
.alee-se-wrap *::before,
.alee-se-wrap *::after,
.alee-se-overlay *,
.alee-se-overlay *::before,
.alee-se-overlay *::after {
	box-sizing: border-box;
}

@media (prefers-color-scheme: dark) {
	.alee-se-wrap,
	.alee-se-overlay,
	.alee-se-trigger {
		--alee-se-bg:           #0f172a;
		--alee-se-bg-subtle:    #1e293b;
		--alee-se-text:         #f1f5f9;
		--alee-se-text-soft:    #cbd5e1;
		--alee-se-muted:        #94a3b8;
		--alee-se-border:       #1e293b;
		--alee-se-border-soft:  #334155;
		--alee-se-accent:       #818cf8;
		--alee-se-accent-text:  #a5b4fc;
		--alee-se-accent-soft:  rgba(129, 140, 248, 0.14);
		--alee-se-accent-ring:  rgba(129, 140, 248, 0.28);
		--alee-se-shadow-sm:    0 1px 2px rgba(0, 0, 0, 0.3);
		--alee-se-shadow:       0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
		--alee-se-shadow-lg:    0 16px 40px rgba(0, 0, 0, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
	}
}

/* ============================================================
 *  TRIGGER BUTTON  (replaces the theme's search form when docked)
 * ============================================================ */
.alee-se-trigger {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 9px 14px 9px 12px;
	background: var(--alee-se-bg-subtle);
	border: 1px solid var(--alee-se-border);
	border-radius: 999px;
	color: var(--alee-se-muted);
	font-size: 14px;
	line-height: 1;
	cursor: pointer;
	max-width: 320px;
	width: 100%;
	transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
	-webkit-tap-highlight-color: transparent;
}

.alee-se-trigger:hover {
	background: var(--alee-se-bg);
	border-color: var(--alee-se-border);
	color: var(--alee-se-text-soft);
}

.alee-se-trigger:focus-visible {
	outline: 0;
	border-color: var(--alee-se-accent);
	box-shadow: 0 0 0 3px var(--alee-se-accent-ring);
}

.alee-se-trigger__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	color: var(--alee-se-text-soft);
}

.alee-se-trigger__label {
	flex: 1 1 auto;
	min-width: 0;
	text-align: left;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-weight: 400;
}

/* Compact icon-only variant — .alee-se-trigger[data-compact] or via media query */
@media (max-width: 480px) {
	.alee-se-trigger {
		padding: 9px 10px;
		gap: 0;
	}
	.alee-se-trigger__label {
		display: none;
	}
}

/* ============================================================
 *  DOCKED OVERLAY
 * ============================================================ */
.alee-se-overlay {
	position: fixed;
	inset: 0;
	z-index: 99998;
	display: block;
	pointer-events: none;
}

.alee-se-overlay[hidden] {
	display: none;
}

.alee-se-overlay.is-open {
	pointer-events: auto;
}

.alee-se-overlay__scrim {
	position: absolute;
	inset: 0;
	background: rgba(15, 23, 42, 0.48);
	opacity: 0;
	transition: opacity 0.2s ease;
	cursor: pointer;
}

@supports (backdrop-filter: blur(4px)) {
	.alee-se-overlay__scrim {
		background: rgba(15, 23, 42, 0.32);
		backdrop-filter: blur(6px);
		-webkit-backdrop-filter: blur(6px);
	}
}

.alee-se-overlay.is-open .alee-se-overlay__scrim {
	opacity: 1;
}

.alee-se-overlay__panel {
	position: absolute;
	top: var(--alee-se-dock-top);
	left: 0;
	right: 0;
	background: var(--alee-se-bg);
	border-bottom: 1px solid var(--alee-se-border);
	box-shadow: var(--alee-se-shadow-lg);
	padding: 14px 16px 16px;
	max-height: calc(100vh - var(--alee-se-dock-top));
	overflow-y: auto;
	overscroll-behavior: contain;
	opacity: 0;
	transform: translateY(-8px);
	transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
	-webkit-overflow-scrolling: touch;
}

.alee-se-overlay.is-open .alee-se-overlay__panel {
	opacity: 1;
	transform: translateY(0);
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
	.alee-se-overlay__scrim,
	.alee-se-overlay__panel {
		transition: none;
		transform: none;
	}
}

/* Inner wrap in docked mode — full-width form */
.alee-se-wrap--docked {
	max-width: 720px;
	margin: 0 auto;
	width: 100%;
}

/* ============================================================
 *  INLINE WRAP
 * ============================================================ */
.alee-se-wrap--inline {
	position: relative;
	width: 100%;
	max-width: 560px;
}

/* ============================================================
 *  FORM (search bar)
 * ============================================================ */
.alee-se-form {
	display: flex;
	align-items: center;
	gap: 0;
	position: relative;
	background: var(--alee-se-bg-subtle);
	border: 1px solid var(--alee-se-border);
	border-radius: var(--alee-se-radius);
	padding: 4px 6px 4px 14px;
	overflow: hidden;
	transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.alee-se-form:focus-within {
	background: var(--alee-se-bg);
	border-color: var(--alee-se-accent);
	box-shadow: 0 0 0 4px var(--alee-se-accent-ring);
}

/* In docked mode, make the bar a little taller and crisper */
.alee-se-wrap--docked .alee-se-form {
	padding: 8px 8px 8px 18px;
	border-radius: 18px;
}

/* The ONE search icon (decorative, right-side action cue) */
.alee-se-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	margin-left: 4px;
	border-radius: 999px;
	background: transparent;
	color: var(--alee-se-muted);
	flex-shrink: 0;
	pointer-events: none;
	transition: color 0.15s ease, background 0.15s ease;
}

.alee-se-wrap--docked .alee-se-icon {
	width: 40px;
	height: 40px;
	margin-left: 6px;
	background: var(--alee-se-accent-soft);
	color: var(--alee-se-accent-text);
}

.alee-se-form:focus-within .alee-se-icon {
	color: var(--alee-se-accent);
}

.alee-se-wrap--docked .alee-se-form:focus-within .alee-se-icon {
	background: var(--alee-se-accent-soft);
	color: var(--alee-se-accent-text);
}

/* Input */
.alee-se-input,
.alee-se-form .alee-se-input,
.alee-se-form input[type="search"].alee-se-input {
	flex: 1 1 auto;
	min-width: 0;
	border: 0 !important;
	outline: 0;
	box-shadow: none !important;
	background: transparent !important;
	font-size: 15px;
	line-height: 1.5;
	padding: 10px 8px 10px 0;
	margin: 0;
	color: var(--alee-se-text);
	font-family: inherit;
	border-radius: 0 !important;
	min-height: 0;
	-webkit-appearance: none;
	appearance: none;
}

.alee-se-input:hover,
.alee-se-input:focus,
.alee-se-form .alee-se-input:hover,
.alee-se-form .alee-se-input:focus,
.alee-se-form input[type="search"].alee-se-input:hover,
.alee-se-form input[type="search"].alee-se-input:focus {
	border: 0 !important;
	outline: 0 !important;
	box-shadow: none !important;
	background: transparent !important;
}

.alee-se-wrap--docked .alee-se-input,
.alee-se-wrap--docked .alee-se-form .alee-se-input,
.alee-se-wrap--docked .alee-se-form input[type="search"].alee-se-input {
	font-size: 18px; /* prevent iOS zoom on focus and feel more premium */
	padding: 12px 8px 12px 0;
}

.alee-se-input::placeholder {
	color: var(--alee-se-muted);
	opacity: 1;
	font-weight: 500;
}

.alee-se-input::-webkit-search-decoration,
.alee-se-input::-webkit-search-cancel-button,
.alee-se-input::-webkit-search-results-button,
.alee-se-input::-webkit-search-results-decoration {
	-webkit-appearance: none;
	appearance: none;
}

/* Clear button (only shown when there's text) */
.alee-se-clear {
	appearance: none;
	-webkit-appearance: none;
	background: transparent;
	border: 0;
	cursor: pointer;
	color: var(--alee-se-muted);
	width: 32px;
	height: 32px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	padding: 0;
	margin-left: 2px;
	transition: background 0.15s ease, color 0.15s ease;
	flex-shrink: 0;
}

.alee-se-clear:hover,
.alee-se-clear:focus-visible {
	background: var(--alee-se-border);
	color: var(--alee-se-text);
	outline: 0;
}

.alee-se-clear[hidden] {
	display: none;
}

/* Close overlay button — only in docked mode, visually separate from clear */
.alee-se-close {
	appearance: none;
	-webkit-appearance: none;
	background: transparent;
	border: 0;
	cursor: pointer;
	color: var(--alee-se-text-soft);
	width: 38px;
	height: 38px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 12px;
	padding: 0;
	margin-left: 8px;
	flex-shrink: 0;
	transition: background 0.15s ease, color 0.15s ease;
	position: relative;
}

.alee-se-close::before {
	content: '';
	position: absolute;
	left: -7px;
	top: 7px;
	bottom: 7px;
	width: 1px;
	background: var(--alee-se-border);
}

.alee-se-close:hover,
.alee-se-close:focus-visible {
	background: var(--alee-se-border-soft);
	color: var(--alee-se-text);
	outline: 0;
}

/* Honeypot — off-screen but reachable by bots that fill every field */
.alee-se-hp {
	position: absolute !important;
	left: -9999px !important;
	top: -9999px !important;
	width: 1px !important;
	height: 1px !important;
	opacity: 0 !important;
	pointer-events: none !important;
	overflow: hidden !important;
}

/* ============================================================
 *  DROPDOWN (suggestion results)
 * ============================================================ */
.alee-se-dropdown {
	position: absolute;
	top: calc(100% + 8px);
	left: 0;
	right: 0;
	background: var(--alee-se-bg);
	border: 1px solid var(--alee-se-border);
	border-radius: var(--alee-se-radius);
	box-shadow: var(--alee-se-shadow-lg);
	z-index: 100;
	max-height: 70vh;
	overflow-y: auto;
	overscroll-behavior: contain;
	animation: alee-se-fade-up 0.18s ease-out;
}

/* In docked mode the dropdown is relative (not absolute) — it flows under the bar */
.alee-se-wrap--docked .alee-se-dropdown {
	position: relative;
	top: auto;
	margin-top: 12px;
	box-shadow: none;
	border: 1px solid var(--alee-se-border-soft);
	max-height: none;
	animation: none;
}

.alee-se-dropdown[hidden] {
	display: none;
}

.alee-se-list {
	list-style: none;
	margin: 0;
	padding: 4px 0;
}

.alee-se-item {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 14px;
	cursor: pointer;
	color: var(--alee-se-text);
	text-decoration: none;
	transition: background 0.1s ease;
	position: relative;
}

.alee-se-item::before {
	content: '';
	position: absolute;
	left: 0;
	top: 0;
	bottom: 0;
	width: 3px;
	background: transparent;
	transition: background 0.15s ease;
}

.alee-se-item:hover,
.alee-se-item.is-active {
	background: var(--alee-se-accent-soft);
}

.alee-se-item:hover::before,
.alee-se-item.is-active::before {
	background: var(--alee-se-accent);
}

.alee-se-item__thumb {
	width: 48px;
	height: 48px;
	border-radius: var(--alee-se-radius-sm);
	overflow: hidden;
	background: var(--alee-se-border-soft);
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
}

.alee-se-item__thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.alee-se-item__thumb-placeholder {
	color: var(--alee-se-muted);
	opacity: 0.6;
}

.alee-se-item__body {
	flex: 1 1 auto;
	min-width: 0;
}

.alee-se-item__title {
	font-size: 14.5px;
	font-weight: 500;
	line-height: 1.4;
	color: var(--alee-se-text);
	margin: 0 0 3px;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	line-clamp: 2;
	overflow: hidden;
}

.alee-se-item__title mark {
	background: transparent;
	color: var(--alee-se-accent-text);
	font-weight: 700;
	padding: 0;
}

.alee-se-item__meta {
	font-size: 12px;
	color: var(--alee-se-muted);
	display: flex;
	gap: 8px;
	align-items: center;
	flex-wrap: wrap;
}

.alee-se-item__meta-dot {
	width: 3px;
	height: 3px;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.5;
	flex-shrink: 0;
}

/* States: empty / loading / error */
.alee-se-state {
	padding: 24px 16px;
	text-align: center;
	color: var(--alee-se-muted);
	font-size: 14px;
}

.alee-se-state--empty {
	padding: 40px 16px;
}

.alee-se-state__icon {
	display: inline-flex;
	margin-bottom: 10px;
	color: var(--alee-se-muted);
	opacity: 0.5;
}

.alee-se-state__query {
	font-size: 12.5px;
	margin-top: 4px;
	opacity: 0.7;
}

/* Spinner */
.alee-se-spinner {
	display: inline-block;
	width: 14px;
	height: 14px;
	border: 2px solid var(--alee-se-border);
	border-top-color: var(--alee-se-accent);
	border-radius: 50%;
	animation: alee-se-spin 0.7s linear infinite;
	vertical-align: middle;
	margin-right: 8px;
}

/* Error */
.alee-se-error {
	padding: 16px;
	color: var(--alee-se-danger);
	font-size: 13.5px;
	text-align: center;
}

/* View-all footer */
.alee-se-footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 12px 14px;
	border-top: 1px solid var(--alee-se-border-soft);
	font-size: 13px;
	color: var(--alee-se-muted);
	background: var(--alee-se-bg-subtle);
}

.alee-se-wrap--docked .alee-se-footer {
	background: transparent;
}

.alee-se-footer__link {
	color: var(--alee-se-accent-text);
	font-weight: 600;
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	gap: 4px;
}

.alee-se-footer__link:hover {
	text-decoration: underline;
}

.alee-se-kbd {
	display: inline-flex;
	align-items: center;
	padding: 2px 6px;
	border: 1px solid var(--alee-se-border);
	border-bottom-width: 2px;
	border-radius: 4px;
	background: var(--alee-se-bg);
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 11px;
	color: var(--alee-se-muted);
	line-height: 1;
	margin: 0 2px;
}

/* ============================================================
 *  ANIMATIONS
 * ============================================================ */
@keyframes alee-se-spin {
	to { transform: rotate(360deg); }
}

@keyframes alee-se-fade-up {
	from {
		opacity: 0;
		transform: translateY(-4px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

@media (prefers-reduced-motion: reduce) {
	.alee-se-dropdown,
	.alee-se-spinner {
		animation: none;
	}
}

/* ============================================================
 *  BODY LOCK (prevent scrolling behind overlay)
 * ============================================================ */
body.alee-se-locked {
	overflow: hidden;
	touch-action: none;
}

/* ============================================================
 *  MOBILE TWEAKS
 * ============================================================ */
@media (max-width: 640px) {
	.alee-se-overlay__panel {
		padding: 10px 12px 14px;
	}
	.alee-se-wrap--inline {
		max-width: 100%;
	}
	.alee-se-dropdown {
		max-height: 60vh;
	}
	.alee-se-item {
		padding: 10px 12px;
	}
	.alee-se-item__thumb {
		width: 44px;
		height: 44px;
	}
	.alee-se-item__title {
		font-size: 14px;
	}
}

@media (max-width: 400px) {
	.alee-se-close {
		width: 32px;
		height: 32px;
	}
	.alee-se-wrap--docked .alee-se-form {
		padding: 4px 4px 4px 12px;
	}
}

@media (max-width: 640px) {
	.alee-se-wrap--docked .alee-se-form {
		padding: 6px 6px 6px 14px;
		border-radius: 16px;
	}

	.alee-se-wrap--docked .alee-se-input,
	.alee-se-wrap--docked .alee-se-form .alee-se-input,
	.alee-se-wrap--docked .alee-se-form input[type="search"].alee-se-input {
		font-size: 17px;
	}

	.alee-se-wrap--docked .alee-se-icon {
		width: 38px;
		height: 38px;
	}
}
