/* ================================================================
 * Haika Search Widget — V2 (Premium UI)
 *   • spinner فقط در حالت loading
 *   • favicon ثابت در حالت idle
 *   • panel با z-index بالا و backdrop blur
 *   • نتایج با تصویر بزرگ + variation status
 * ================================================================ */

.hsw {
	--hsw-bg:        var(--cb-bg-2, rgba(255,255,255,0.05));
	--hsw-bg-solid:  var(--cb-bg, #0d1117);
	--hsw-border:    var(--cb-border, rgba(255,255,255,0.10));
	--hsw-fg:        var(--cb-text, #e6edf3);
	--hsw-fg-muted:  var(--cb-text-2, rgba(255,255,255,0.6));
	--hsw-accent:    var(--ks-purple-glow, #c084fc);
	--hsw-accent-2:  var(--ks-purple, #5b2c87);
	--hsw-purple-soft: rgba(139, 92, 246, 0.12);
	--hsw-radius:    18px;
	--hsw-shadow:    0 20px 60px rgba(0,0,0,0.45);
	position: relative;
	width: 100%;
	z-index: 9000; /* همیشه بالای toolbar (z-index: 20) و mini-cart */
}
.hsw[aria-expanded="true"] { z-index: 10000; }
.haika-theme-light .hsw {
	--hsw-bg:        #ffffff;
	--hsw-bg-solid:  #ffffff;
	--hsw-border:    rgba(91, 44, 135, 0.18);
	--hsw-fg:        #1a1a2e;
	--hsw-fg-muted:  #6b7280;
	--hsw-shadow:    0 20px 60px rgba(91, 44, 135, 0.18);
}

/* ─── Form ─── */
.hsw__form {
	display: flex;
	align-items: center;
	gap: 10px;
	position: relative;
	background: var(--hsw-bg);
	border: 2px solid var(--hsw-border);
	border-radius: 999px;
	padding: 4px 4px 4px 18px;
	transition: all .25s cubic-bezier(0.22, 1, 0.36, 1);
	backdrop-filter: blur(20px);
	-webkit-backdrop-filter: blur(20px);
}
.hsw__form:focus-within {
	border-color: var(--hsw-accent);
	box-shadow:
		0 0 0 6px rgba(139, 92, 246, 0.12),
		0 16px 50px rgba(139, 92, 246, 0.25);
}

/* Size variants */
.hsw--small .hsw__form  { padding: 2px 2px 2px 14px; }
.hsw--small .hsw__input { font-size: 13px; padding: 8px 4px; }
.hsw--large .hsw__form  { padding: 6px 6px 6px 24px; }
.hsw--large .hsw__input { font-size: 16px; padding: 16px 6px; }

/* Leading icon area — برند ثابت / spinner چرخان */
.hsw__icon {
	display: inline-flex;
	flex-shrink: 0;
	width: 28px; height: 28px;
	align-items: center;
	justify-content: center;
	color: var(--hsw-accent);
	position: relative;
}
.hsw--large .hsw__icon { width: 32px; height: 32px; }
.hsw--small .hsw__icon { width: 22px; height: 22px; }

/* همیشه آیکن جستجو نمایش داده می‌شود؛ هنگام loading تبدیل به spinner می‌شود */
.hsw__icon svg {
	transition: opacity .15s;
	display: block;
	width: 100%;
	height: 100%;
}
.hsw__icon .hsw__icon-search,
.hsw__icon .hsw__icon-spin {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
}
.hsw__icon .hsw__icon-spin {
	opacity: 0;
	transform-origin: 50% 50%;
}
.hsw__icon .hsw__icon-spin svg {
	transform-origin: 50% 50%;
	animation: hsw-spin 0.8s linear infinite;
	animation-play-state: paused;
}
.hsw.is-loading .hsw__icon-search { opacity: 0; }
.hsw.is-loading .hsw__icon-spin   { opacity: 1; }
.hsw.is-loading .hsw__icon-spin svg { animation-play-state: running; }
@keyframes hsw-spin {
	from { transform: rotate(0deg); }
	to   { transform: rotate(360deg); }
}

.hsw__input {
	flex: 1;
	background: transparent;
	border: 0;
	outline: 0;
	padding: 12px 4px;
	color: var(--hsw-fg);
	font-family: inherit;
	font-size: 14.5px;
	font-weight: 500;
	min-width: 0;
}
.hsw__input::placeholder {
	color: var(--hsw-fg-muted);
	font-weight: 400;
}
.hsw__input::-webkit-search-cancel-button { display: none; }

/* shortcut badge */
.hsw__shortcut {
	flex-shrink: 0;
	background: var(--hsw-purple-soft);
	color: var(--hsw-accent);
	border: 1px solid rgba(139, 92, 246, 0.25);
	padding: 3px 9px;
	border-radius: 6px;
	font-size: 11px;
	font-weight: 700;
	font-family: 'SF Mono', Menlo, Consolas, monospace;
	margin-inline-end: 4px;
	opacity: .8;
	transition: opacity .2s;
}
.hsw__form:focus-within .hsw__shortcut { opacity: 0; pointer-events: none; }
@media (max-width: 560px) { .hsw__shortcut { display: none; } }

/* clear button */
.hsw__clear {
	flex-shrink: 0;
	width: 36px; height: 36px;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--hsw-accent), var(--hsw-accent-2));
	border: 0;
	color: #fff;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	transition: transform .2s;
	box-shadow: 0 4px 12px rgba(139, 92, 246, 0.35);
}
.hsw__clear:hover { transform: scale(1.08); }
.hsw--small .hsw__clear { width: 28px; height: 28px; }
.hsw--large .hsw__clear { width: 42px; height: 42px; }

/* ─── Panel — solid background to prevent overlap ─── */
.hsw__panel {
	position: absolute;
	top: calc(100% + 10px);
	left: 0;
	right: 0;
	background: var(--hsw-bg-solid);
	border: 1px solid var(--hsw-border);
	border-radius: var(--hsw-radius);
	box-shadow: var(--hsw-shadow);
	max-height: 70vh;
	overflow-y: auto;
	z-index: 10001;
	opacity: 0;
	transform: translateY(-8px) scale(.98);
	pointer-events: none;
	transition: opacity .2s ease, transform .2s ease;
}
.hsw[aria-expanded="true"] .hsw__panel {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* States */
.hsw__state { padding: 12px; }

/* Results state */
.hsw__results-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 8px 12px 12px;
	border-bottom: 1px solid var(--hsw-border);
	margin-bottom: 6px;
}
.hsw__results-head [data-haika-search-count] {
	font-size: 12px;
	color: var(--hsw-fg-muted);
	font-weight: 600;
}
.hsw__results-head [data-haika-search-count] strong {
	color: var(--hsw-accent);
	margin: 0 3px;
}
.hsw__view-all {
	background: transparent;
	border: 0;
	color: var(--hsw-accent);
	font-family: inherit;
	font-size: 12px;
	font-weight: 700;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 4px 8px;
	border-radius: 8px;
}
.hsw__view-all:hover { background: var(--hsw-purple-soft); }

/* Items */
.hsw__list { list-style: none; padding: 0; margin: 0; }
.hsw__item {
	border-radius: 12px;
	margin: 2px 0;
	transition: background .15s;
}
.hsw__item.is-active,
.hsw__item:hover { background: var(--hsw-purple-soft); }

.hsw__item-link {
	display: flex;
	align-items: flex-start;
	gap: 12px;
	padding: 12px;
	color: var(--hsw-fg);
	text-decoration: none;
	border-radius: 12px;
}

.hsw__item-img {
	position: relative;
	flex-shrink: 0;
	width: 64px; height: 64px;
	border-radius: 12px;
	background: var(--hsw-purple-soft);
	overflow: hidden;
}
.hsw__item-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hsw__item-placeholder {
	position: absolute; inset: 0;
	display: flex; align-items: center; justify-content: center;
	color: var(--hsw-accent);
}
.hsw__item-stock-corner {
	position: absolute;
	bottom: 0;
	inset-inline-end: 0;
	font-size: 9px;
	font-weight: 800;
	padding: 1px 4px;
	background: #10b981;
	color: #fff;
	border-radius: 4px 0 0 0;
}
.hsw__item-stock-corner.is-out { background: #ef4444; }

.hsw__item-body {
	flex: 1;
	min-width: 0;
}
.hsw__item-title {
	font-size: 14.5px;
	font-weight: 700;
	color: var(--hsw-fg);
	margin-bottom: 4px;
	line-height: 1.4;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}
.hsw__item-title mark.hsw-hl {
	background: linear-gradient(180deg, transparent 50%, rgba(192, 132, 252, 0.45) 50%);
	color: var(--hsw-fg);
	padding: 0 1px;
	font-weight: 800;
}
.hsw__item-meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px;
	font-size: 11.5px;
	color: var(--hsw-fg-muted);
	margin-bottom: 6px;
}
.hsw__item-cat { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hsw__item-cat:empty { display: none; }
.hsw__item-sku {
	padding: 2px 7px;
	background: var(--hsw-purple-soft);
	color: var(--hsw-accent);
	border-radius: 5px;
	font-family: 'SF Mono', Menlo, Consolas, monospace;
	font-size: 10.5px;
	direction: ltr;
	font-weight: 700;
}
.hsw__item-sku:empty { display: none; }
.hsw__item-sku mark.hsw-hl {
	background: var(--hsw-accent);
	color: #fff;
	padding: 0 2px;
	border-radius: 2px;
	font-weight: 800;
}

/* Variations row */
.hsw__item-vars {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	margin-top: 4px;
}
.hsw__item-vars-label {
	font-size: 10.5px;
	color: var(--hsw-fg-muted);
	margin-inline-end: 2px;
}
.hsw__item-var {
	display: inline-flex;
	align-items: center;
	gap: 3px;
	padding: 2px 7px;
	border-radius: 5px;
	font-size: 10.5px;
	font-weight: 700;
	border: 1px solid;
}
.hsw__item-var.is-in {
	background: rgba(16, 185, 129, 0.10);
	color: #10b981;
	border-color: rgba(16, 185, 129, 0.30);
}
.hsw__item-var.is-out {
	background: rgba(239, 68, 68, 0.08);
	color: #ef4444;
	border-color: rgba(239, 68, 68, 0.25);
	text-decoration: line-through;
	opacity: .7;
}

.hsw__item-aside {
	flex-shrink: 0;
	text-align: end;
	min-width: 80px;
}
.hsw__item-price {
	font-size: 13px;
	font-weight: 800;
	color: var(--hsw-fg);
	white-space: nowrap;
	line-height: 1.3;
}
.hsw__item-price del {
	font-size: 10.5px;
	opacity: .55;
	font-weight: 400;
	display: block;
}
.hsw__item-price ins {
	background: transparent;
	color: var(--hsw-accent);
	text-decoration: none;
}

/* Empty state */
.hsw__state--empty {
	text-align: center;
	padding: 36px 20px;
}
.hsw__empty-icon {
	color: var(--hsw-fg-muted);
	margin-bottom: 12px;
}
.hsw__empty-title {
	margin: 0 0 4px;
	font-size: 15px;
	font-weight: 700;
	color: var(--hsw-fg);
}
.hsw__empty-sub {
	margin: 0;
	font-size: 13px;
	color: var(--hsw-fg-muted);
}

/* ═══════════════════════════════════════════════════════════════
   Mobile responsive
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 560px) {
	.hsw__item-img {
		width: 56px;
		height: 56px;
	}
	.hsw__item-title { font-size: 13px; }
	.hsw__item-meta  { font-size: 11px; }
	.hsw--large .hsw__form  { padding: 4px 4px 4px 16px; }
	.hsw--large .hsw__input { font-size: 14px; padding: 12px 6px; }
	.hsw--large .hsw__icon  { width: 26px; height: 26px; }
	.hsw__panel { max-height: 65vh; }
}
