/**
 * GSM Notes Secure Core — Enhanced Search Field Styles.
 *
 * CRITICAL FIXES in this version:
 *   1. FORM HEIGHT: .header-search uses align-self:center so it does NOT
 *      stretch to the full header row height (was 60-80px causing the
 *      "very large" appearance). Now clamped to 42px.
 *   2. WRAP HEIGHT: explicit height clamp prevents any vertical expansion
 *      regardless of parent flex-stretch inheritance.
 *   3. DROPDOWN WIDTH: max-width: 540px even in stretch mode so it never
 *      spans the entire header — looks like a proper dropdown, not a modal.
 *   4. DROPDOWN HEIGHT: max-height + overflow-y scroll prevents it from
 *      pushing content far down the page.
 *   5. Security: `position:absolute` with `z-index:9999` ensures the dropdown
 *      never affects document flow (no layout injection risk).
 *
 * Structure:
 *   A. BASE LAYOUT — form (flex-row), wrap (fixed height), input, buttons
 *   B. VISUAL STYLES — 8 colour presets
 *   C. LIGHT-MODE OVERRIDES
 *   D. POSITIONS — center, stretch (FIXED), left, right
 *   E. DROPDOWN — compact smart suggestions
 *   F. TOGGLE — auto-search toggle
 *   G. RESPONSIVE
 */

/* =====================================================================
 * A) BASE LAYOUT
 *
 * The form is flex-row: [WRAP  |  TOGGLE]
 * The wrap is a pill, fixed height — nothing can stretch it beyond ~42px.
 * The dropdown is absolutely positioned below the WRAP (not the form).
 * =================================================================== */

/* Form row — NEVER expands vertically */
.gnsc-search-form {
	position: relative;
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: 8px;
	width: 100%;
	/* No height: auto keeps it hugging its content */
}

/* CRITICAL: keep .header-search centered in its flex parent (.site-header__actions)
   so it is NOT stretched to the full header row height. */
.header-search {
	align-self: center !important;
}

/* PILL WRAP — fixed height, all content inside stays within ~42px */
.gnsc-search-wrap {
	flex: 1 1 auto;
	min-width: 0;
	/* ANCHOR for the dropdown */
	position: relative;
	/* FIXED HEIGHT — prevents any vertical expansion */
	height: clamp(38px, 3.2vw, 42px);
	max-height: 42px;
	/* Pill appearance */
	display: flex;
	align-items: center;
	border-radius: 999px;
	border: 1.5px solid var(--gss-border, rgba(255,255,255,0.22));
	background: var(--gss-bg, rgba(255,255,255,0.10));
	overflow: hidden;
	transition: border-color 0.22s ease, box-shadow 0.22s ease, background 0.22s ease;
}

.gnsc-search-form:focus-within .gnsc-search-wrap {
	border-color: var(--gss-border-focus, var(--gss-border, rgba(255,255,255,0.55)));
	box-shadow: 0 0 0 3px var(--gss-ring, rgba(255,255,255,0.18));
}

/* Input — fills the wrap, no own height so it respects the wrap */
.gnsc-search-input {
	flex: 1 1 auto;
	min-width: 0;
	height: 100%;
	border: none !important;
	background: transparent !important;
	outline: none !important;
	box-shadow: none !important;
	padding: 0 10px 0 16px;
	font-size: 0.88rem;
	font-weight: 500;
	color: var(--gss-text, inherit);
	line-height: 1;
	-webkit-appearance: none;
}
.gnsc-search-input::placeholder {
	color: var(--gss-placeholder, rgba(150,150,160,0.70));
	font-weight: 400;
}
.gnsc-search-input::-webkit-search-decoration,
.gnsc-search-input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }

/* Clear (×) button */
.gnsc-search-clear {
	display: none;
	align-items: center;
	justify-content: center;
	padding: 0 6px 0 0;
	height: 100%;
	border: none;
	background: transparent;
	color: var(--gss-text, rgba(140,140,150,0.65));
	cursor: pointer;
	opacity: 0.55;
	transition: opacity 0.18s;
	flex-shrink: 0;
}
.gnsc-search-clear:hover { opacity: 1; }
.gnsc-search-form.has-value .gnsc-search-clear { display: flex; }

/* Submit button — fills wrap height naturally */
.gnsc-search-submit {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	height: 100%;
	border: none;
	border-radius: 0 999px 999px 0;
	background: var(--gss-btn-bg, rgba(255,255,255,0.15));
	color: var(--gss-btn-fg, currentColor);
	padding: 0 13px;
	cursor: pointer;
	transition: background 0.20s ease;
	position: relative;
}
.gnsc-search-submit:hover { background: var(--gss-btn-hover, rgba(255,255,255,0.25)); }

/* Spinner */
.gnsc-search-spinner {
	display: none;
	animation: gnsc-spin 0.72s linear infinite;
	position: absolute;
}
.gnsc-search-form.is-loading .gnsc-search-icon   { opacity: 0; }
.gnsc-search-form.is-loading .gnsc-search-spinner { display: block; }

@keyframes gnsc-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* =====================================================================
 * B) VISUAL STYLE PRESETS (unchanged from previous)
 * =================================================================== */

/* Rose */
body.gnsc-search-style-rose {
	--gss-bg: #fff0f3; --gss-border: #fca5a5; --gss-border-focus: #f43f5e;
	--gss-text: #881337; --gss-placeholder: #fda4af;
	--gss-btn-bg: #fb7185; --gss-btn-fg: #ffffff; --gss-btn-hover: #f43f5e;
	--gss-ring: rgba(251,113,133,0.30);
}
/* Amber */
body.gnsc-search-style-amber {
	--gss-bg: #fffbeb; --gss-border: #fcd34d; --gss-border-focus: #f59e0b;
	--gss-text: #78350f; --gss-placeholder: #fbbf24;
	--gss-btn-bg: #f59e0b; --gss-btn-fg: #ffffff; --gss-btn-hover: #d97706;
	--gss-ring: rgba(245,158,11,0.28);
}
/* Teal */
body.gnsc-search-style-teal {
	--gss-bg: #f0fdfa; --gss-border: #5eead4; --gss-border-focus: #0d9488;
	--gss-text: #134e4a; --gss-placeholder: #99f6e4;
	--gss-btn-bg: #14b8a6; --gss-btn-fg: #ffffff; --gss-btn-hover: #0d9488;
	--gss-ring: rgba(20,184,166,0.28);
}
/* Slate */
body.gnsc-search-style-slate {
	--gss-bg: #1e293b; --gss-border: #334155; --gss-border-focus: #64748b;
	--gss-text: #f1f5f9; --gss-placeholder: #475569;
	--gss-btn-bg: #334155; --gss-btn-fg: #94a3b8; --gss-btn-hover: #475569;
	--gss-ring: rgba(148,163,184,0.22);
}
body.gnsc-search-style-slate .gnsc-search-submit:hover { color: #f1f5f9; }
/* Violet */
body.gnsc-search-style-violet {
	--gss-bg: #faf5ff; --gss-border: #c084fc; --gss-border-focus: #7c3aed;
	--gss-text: #3b0764; --gss-placeholder: #d8b4fe;
	--gss-btn-bg: #7c3aed; --gss-btn-fg: #ffffff; --gss-btn-hover: #6d28d9;
	--gss-ring: rgba(124,58,237,0.28);
}
/* Glass */
body.gnsc-search-style-glass {
	--gss-bg: rgba(255,255,255,0.14); --gss-border: rgba(255,255,255,0.30);
	--gss-border-focus: rgba(255,255,255,0.62);
	--gss-text: #ffffff; --gss-placeholder: rgba(255,255,255,0.52);
	--gss-btn-bg: rgba(255,255,255,0.18); --gss-btn-fg: #ffffff;
	--gss-btn-hover: rgba(255,255,255,0.30); --gss-ring: rgba(255,255,255,0.22);
}
body.gnsc-search-style-glass .gnsc-search-wrap {
	-webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
/* Neon */
body.gnsc-search-style-neon {
	--gss-bg: rgba(17,5,45,0.85); --gss-border: #a855f7;
	--gss-border-focus: #e879f9;
	--gss-text: #f0e6ff; --gss-placeholder: rgba(192,132,252,0.65);
	--gss-btn-bg: linear-gradient(135deg,#a855f7,#ec4899);
	--gss-btn-fg: #ffffff;
	--gss-btn-hover: linear-gradient(135deg,#9333ea,#db2777);
	--gss-ring: rgba(168,85,247,0.44);
}
body.gnsc-search-style-neon .gnsc-search-form:focus-within .gnsc-search-wrap {
	box-shadow: 0 0 0 3px rgba(168,85,247,0.40), 0 0 18px rgba(168,85,247,0.32);
}

/* =====================================================================
 * C) LIGHT-MODE OVERRIDES
 * =================================================================== */

/* Default style in light mode */
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-default .gnsc-search-wrap {
	background: #ffffff !important;
	border-color: #2563eb !important;
	border-width: 2px;
}
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-default .gnsc-search-input {
	color: #1e293b !important;
}
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-default .gnsc-search-input::placeholder {
	color: #94a3b8 !important;
}
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-default .gnsc-search-submit {
	background: #2563eb !important;
	color: #ffffff !important;
}
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-default .gnsc-search-submit:hover {
	background: #1d4ed8 !important;
}
/* Glass in light mode */
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-glass .gnsc-search-wrap {
	background: rgba(255,255,255,0.90) !important;
	border-color: rgba(37,99,235,0.35) !important;
}
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-glass .gnsc-search-input {
	color: #1e293b !important;
}
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-glass .gnsc-search-input::placeholder {
	color: #64748b !important;
}
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-glass .gnsc-search-submit {
	background: #2563eb !important;
	color: #ffffff !important;
}
/* Neon in light mode */
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-neon .gnsc-search-wrap {
	background: rgba(76,29,149,0.10) !important;
	border-color: #7c3aed !important;
}
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-neon .gnsc-search-input {
	color: #3b0764 !important;
}
body.gnsc-global-sidebar-enabled.gnsc-shop-mode-light.gnsc-search-style-neon .gnsc-search-input::placeholder {
	color: #a855f7 !important;
}
/* Auto-toggle in light mode */
body.gnsc-shop-mode-light .gnsc-autosearch-toggle {
	background: rgba(37,99,235,0.10);
	border-color: rgba(37,99,235,0.28);
	color: #1e40af;
}
body.gnsc-shop-mode-light .gnsc-autosearch-toggle.is-on {
	background: #2563eb;
	border-color: #2563eb;
	color: #ffffff;
}

/* =====================================================================
 * D) POSITION VARIANTS
 * =================================================================== */

/* Center (compact) — DEFAULT */
body.gnsc-global-sidebar-enabled.gnsc-search-pos-center .site-header__actions {
	justify-content: center;
}
body.gnsc-global-sidebar-enabled.gnsc-search-pos-center .gnsc-search-form {
	max-width: min(100%, var(--gnsc-header-search-max, 400px));
}

/* Stretch — fills center column; dropdown still max-width 540px */
body.gnsc-global-sidebar-enabled.gnsc-search-pos-stretch .site-header__inner {
	grid-template-columns: minmax(max-content, auto) 1fr auto;
}
body.gnsc-global-sidebar-enabled.gnsc-search-pos-stretch .site-header__actions {
	width: 100%;
	justify-content: flex-start;
	min-width: 0;
}
body.gnsc-global-sidebar-enabled.gnsc-search-pos-stretch .header-search {
	max-width: none !important;
	width: 100% !important;
}
body.gnsc-global-sidebar-enabled.gnsc-search-pos-stretch .gnsc-search-form {
	flex: 1 1 auto;
	max-width: none;
	width: 100%;
}
body.gnsc-global-sidebar-enabled.gnsc-search-pos-stretch .gnsc-search-wrap {
	width: 100%;
}

/* Left */
body.gnsc-global-sidebar-enabled.gnsc-search-pos-left .site-header__inner {
	grid-template-columns: minmax(max-content, auto) auto 1fr;
}
body.gnsc-global-sidebar-enabled.gnsc-search-pos-left .site-branding    { grid-column: 1; grid-row: 1; }
body.gnsc-global-sidebar-enabled.gnsc-search-pos-left .site-header__actions {
	grid-column: 2; grid-row: 1;
	width: auto; min-width: min(180px, 26vw); justify-content: flex-start;
}
body.gnsc-global-sidebar-enabled.gnsc-search-pos-left .site-header__actions .header-search { max-width: none; }
body.gnsc-global-sidebar-enabled.gnsc-search-pos-left .primary-nav {
	grid-column: 3; grid-row: 1; justify-content: flex-end;
}
body.gnsc-global-sidebar-enabled.gnsc-search-pos-left .primary-nav ul { justify-content: flex-end; }

/* Right */
body.gnsc-global-sidebar-enabled.gnsc-search-pos-right .site-header__inner {
	grid-template-columns: minmax(max-content, auto) 1fr auto;
}
body.gnsc-global-sidebar-enabled.gnsc-search-pos-right .site-branding   { grid-column: 1; grid-row: 1; }
body.gnsc-global-sidebar-enabled.gnsc-search-pos-right .primary-nav {
	grid-column: 2; grid-row: 1; justify-content: flex-end;
}
body.gnsc-global-sidebar-enabled.gnsc-search-pos-right .primary-nav ul  { justify-content: flex-end; }
body.gnsc-global-sidebar-enabled.gnsc-search-pos-right .site-header__actions {
	grid-column: 3; grid-row: 1;
	width: auto; min-width: min(180px, 26vw); justify-content: flex-end;
}
body.gnsc-global-sidebar-enabled.gnsc-search-pos-right .site-header__actions .header-search { max-width: none; }

/* =====================================================================
 * E) DROPDOWN — smart, compact, max-width constrained
 *
 * CRITICAL FIXES:
 *   - max-width: 520px → never spans a 900px form width (prevents "modal" feel)
 *   - max-height: 340px + overflow-y: auto → bounded downward growth
 *   - Positioned relative to .gnsc-search-wrap (which is also position:relative)
 * =================================================================== */
.gnsc-search-dropdown {
	position: absolute;
	top: calc(100% + 8px);
	left: 0;
	/* KEY FIX: not right:0 — instead use max-width so it's compact */
	right: auto;
	width: 100%;
	max-width: 520px;
	/* HEIGHT LIMIT — prevents downward explosion */
	max-height: 340px;
	overflow-y: auto;
	overflow-x: hidden;
	z-index: 9999;
	/* Visual */
	background: #ffffff;
	border: 1px solid rgba(0,0,0,0.10);
	border-radius: 14px;
	box-shadow:
		0 2px 8px rgba(0,0,0,0.06),
		0 12px 36px rgba(0,0,0,0.14);
	animation: gnsc-drop-in 0.18s ease;
	/* Security: prevent overflow from leaking layout info */
	contain: layout style;
}
.gnsc-search-dropdown[hidden] { display: none; }

@keyframes gnsc-drop-in {
	from { opacity: 0; transform: translateY(-5px) scale(0.98); }
	to   { opacity: 1; transform: translateY(0)     scale(1); }
}

/* Scrollbar — slim, theme-coloured */
.gnsc-search-dropdown::-webkit-scrollbar { width: 4px; }
.gnsc-search-dropdown::-webkit-scrollbar-track { background: transparent; }
.gnsc-search-dropdown::-webkit-scrollbar-thumb {
	background: rgba(124,58,237,0.28);
	border-radius: 4px;
}

/* Dark-mode dropdown */
body.gnsc-shop-mode-current .gnsc-search-dropdown {
	background: #1a1235;
	border-color: rgba(255,255,255,0.12);
	box-shadow: 0 2px 8px rgba(0,0,0,0.22), 0 16px 44px rgba(0,0,0,0.42);
}

/* Status (searching / no results) */
.gnsc-search-status {
	padding: 14px 16px;
	font-size: 0.84rem;
	color: #64748b;
	text-align: center;
}
body.gnsc-shop-mode-current .gnsc-search-status { color: rgba(255,255,255,0.50); }

/* Result link */
.gnsc-search-result {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 9px 14px;
	text-decoration: none;
	color: inherit;
	transition: background 0.14s;
	border-bottom: 1px solid rgba(0,0,0,0.05);
}
.gnsc-search-result:last-of-type { border-bottom: none; }
.gnsc-search-result:hover, .gnsc-search-result.is-active {
	background: rgba(124,58,237,0.07);
}
body.gnsc-shop-mode-current .gnsc-search-result {
	border-bottom-color: rgba(255,255,255,0.06);
	color: #f0e6ff;
}
body.gnsc-shop-mode-current .gnsc-search-result:hover,
body.gnsc-shop-mode-current .gnsc-search-result.is-active {
	background: rgba(124,58,237,0.20);
}

/* Icon cell */
.gnsc-search-result__icon {
	flex-shrink: 0;
	width: 28px;
	height: 28px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 7px;
	background: rgba(124,58,237,0.10);
	color: #7c3aed;
}

/* Text */
.gnsc-search-result__text { flex: 1; min-width: 0; }
.gnsc-search-result__title {
	display: block;
	font-size: 0.85rem;
	font-weight: 600;
	color: #1e293b;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	line-height: 1.35;
}
body.gnsc-shop-mode-current .gnsc-search-result__title { color: #ffffff; }
.gnsc-search-result__title mark {
	background: transparent;
	color: #7c3aed;
	font-weight: 800;
}
body.gnsc-shop-mode-current .gnsc-search-result__title mark { color: #c084fc; }
.gnsc-search-result__type {
	display: inline-block;
	font-size: 0.70rem;
	color: #94a3b8;
	margin-top: 1px;
}

/* "See all results" footer link */
.gnsc-search-see-all {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 5px;
	padding: 10px 14px;
	font-size: 0.80rem;
	font-weight: 600;
	color: #7c3aed;
	text-decoration: none;
	background: rgba(124,58,237,0.05);
	border-top: 1px solid rgba(0,0,0,0.06);
	transition: background 0.16s;
	/* Sticky at bottom of dropdown */
	position: sticky;
	bottom: 0;
}
.gnsc-search-see-all:hover { background: rgba(124,58,237,0.11); }
body.gnsc-shop-mode-current .gnsc-search-see-all {
	background: rgba(124,58,237,0.16);
	border-top-color: rgba(255,255,255,0.08);
	color: #c084fc;
}
body.gnsc-shop-mode-current .gnsc-search-see-all:hover {
	background: rgba(124,58,237,0.26);
}

/* =====================================================================
 * F) AUTO-SEARCH TOGGLE BUTTON
 * =================================================================== */
.gnsc-autosearch-toggle {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	flex-shrink: 0;
	height: clamp(30px, 2.8vw, 34px);
	padding: 0 10px;
	border: 1.5px solid rgba(255,255,255,0.20);
	border-radius: 999px;
	background: rgba(255,255,255,0.08);
	color: rgba(255,255,255,0.45);
	cursor: pointer;
	font-size: 0.70rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	white-space: nowrap;
	transition: all 0.20s ease;
	line-height: 1;
}
.gnsc-autosearch-toggle:hover {
	background: rgba(255,255,255,0.14);
	color: rgba(255,255,255,0.70);
}
.gnsc-autosearch-toggle.is-on {
	background: linear-gradient(135deg, #7c3aed, #c026d3);
	border-color: rgba(245,176,255,0.55);
	color: #ffffff;
	box-shadow: 0 4px 12px rgba(124,58,237,0.35);
}
.gnsc-autosearch-toggle.is-on:hover { filter: brightness(1.10); }
.gnsc-auto-icon { flex-shrink: 0; }
@media (max-width: 420px) { .gnsc-auto-label { display: none; } }

/* =====================================================================
 * G) RESPONSIVE — collapse positions at tablet/mobile
 * =================================================================== */
@media (max-width: 980px) {
	body.gnsc-global-sidebar-enabled.gnsc-search-pos-left .site-header__inner,
	body.gnsc-global-sidebar-enabled.gnsc-search-pos-right .site-header__inner,
	body.gnsc-global-sidebar-enabled.gnsc-search-pos-stretch .site-header__inner {
		grid-template-columns: minmax(0, 1fr) auto !important;
	}
	body.gnsc-global-sidebar-enabled.gnsc-search-pos-left .site-branding,
	body.gnsc-global-sidebar-enabled.gnsc-search-pos-right .site-branding  { grid-column: 1 !important; grid-row: 1 !important; }
	body.gnsc-global-sidebar-enabled.gnsc-search-pos-left .site-header__actions,
	body.gnsc-global-sidebar-enabled.gnsc-search-pos-right .site-header__actions,
	body.gnsc-global-sidebar-enabled.gnsc-search-pos-stretch .site-header__actions {
		grid-column: 2 !important; grid-row: 1 !important;
		width: auto !important; min-width: auto !important;
	}
	body.gnsc-global-sidebar-enabled.gnsc-search-pos-left .primary-nav,
	body.gnsc-global-sidebar-enabled.gnsc-search-pos-right .primary-nav {
		grid-column: 1 / -1 !important; grid-row: 2 !important;
	}
	/* Dropdown: left-align, reasonable width on narrow screens */
	.gnsc-search-dropdown {
		max-width: min(92vw, 400px);
	}
	.gnsc-autosearch-toggle { padding: 0 8px; }
}
