/**
 * Routin Instant Search — visual system (Phase 2 UI + Phase 4 suggestions).
 * Digikala-parity, RTL, mobile-first. Brand: rose/magenta #CC3366 (from the live header).
 * Light + dark, reduced-motion aware, WCAG-AA. All selectors namespaced .rtns / .rtns-*.
 * [FOUNDATION §6; PLAN §4 task 2.8, §6 tasks 4.1/4.2]
 */

/* ============================================================ design tokens */
.rtns,
.rtns-overlay {
	/* brand (rose) */
	--rtns-brand:        #cc3366;
	--rtns-brand-strong: #b02a56;
	--rtns-brand-ink:    #8f1f47;
	--rtns-brand-tint:   #fdeef4;
	--rtns-brand-tint-2: #fbdce8;
	--rtns-ring:         rgba(204, 51, 102, 0.30);

	/* neutrals / ink */
	--rtns-ink:      #17181c;
	--rtns-text:     #33373d;
	--rtns-muted:    #6b7280;
	--rtns-faint:    #9aa1ab;

	/* surfaces */
	--rtns-surface:   #ffffff;
	--rtns-surface-2: #f6f7f9;
	--rtns-surface-3: #eceef1;
	--rtns-border:    #e9ebef;
	--rtns-border-2:  #dde0e5;

	/* semantic */
	--rtns-price:   #17181c;
	--rtns-instock: #0f9d58;
	--rtns-danger:  #d0264b;

	/* shape + depth */
	--rtns-r:      14px;
	--rtns-r-sm:   10px;
	--rtns-r-pill: 999px;
	--rtns-sh-1: 0 1px 2px rgba(16, 18, 25, 0.06);
	--rtns-sh-2: 0 8px 30px rgba(16, 18, 25, 0.10);
	--rtns-sh-pop: 0 28px 70px rgba(16, 18, 25, 0.24);

	/* motion */
	--rtns-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
	--rtns-dur:  0.2s;

	--rtns-safe-top: env(safe-area-inset-top, 0px);
	--rtns-safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
	.rtns,
	.rtns-overlay {
		--rtns-brand:        #f0769f; /* lighter rose for text/icons on dark */
		--rtns-brand-strong: #f491b3;
		--rtns-brand-ink:    #f6aecb; /* legible tag/label text on the dark tint (AA) */
		--rtns-brand-tint:   #38202b;
		--rtns-brand-tint-2: #472a37;
		--rtns-ring:         rgba(240, 118, 160, 0.38);
		--rtns-ink:      #f3f4f6;
		--rtns-text:     #d5d8de;
		--rtns-muted:    #9aa1ab;
		--rtns-faint:    #6b7280;
		--rtns-surface:   #16181d;
		--rtns-surface-2: #1e2128;
		--rtns-surface-3: #272b33;
		--rtns-border:    #2a2e37;
		--rtns-border-2:  #363b45;
		--rtns-price:   #f3f4f6;
		--rtns-sh-2: 0 8px 30px rgba(0, 0, 0, 0.5);
		--rtns-sh-pop: 0 28px 70px rgba(0, 0, 0, 0.6);
	}
	.rtns__result-thumb img,
	.rtns__result-thumb { background: var(--rtns-surface-3); }
}

.rtns-locked { overflow: hidden; }

/* Theme sets button{display:block}; re-assert [hidden] inside the search UI. */
.rtns [hidden] { display: none !important; }

/* ============================================================ header icon */
.rtns-header-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: var(--rtns-r-pill);
	background: transparent;
	color: inherit;
	cursor: pointer;
	line-height: 0;
	vertical-align: middle;
	transition: background var(--rtns-dur) var(--rtns-ease), color var(--rtns-dur) var(--rtns-ease);
}
.rtns-header-icon:hover { background: var(--rtns-brand-tint); color: var(--rtns-brand); }
.rtns-header-icon:focus-visible {
	outline: none;
	box-shadow: 0 0 0 3px var(--rtns-ring);
}

/* retired old header search widget — hidden fallback [PLAN §6 task 4.4] */
.rtns-retired { display: none !important; }

/* ============================================================ overlay (desktop) */
.rtns-overlay {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: flex-start;
	justify-content: center;
}
.rtns-overlay[hidden] { display: none; }
.rtns-overlay__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(12, 14, 22, 0.52);
	backdrop-filter: blur(3px);
	-webkit-backdrop-filter: blur(3px);
	animation: rtns-fade var(--rtns-dur) var(--rtns-ease);
}
.rtns-overlay__panel {
	position: relative;
	width: min(720px, 94vw);
	margin-top: 7.5vh;
	max-height: 85vh;
	background: var(--rtns-surface);
	border-radius: 18px;
	box-shadow: var(--rtns-sh-pop);
	overflow: hidden;
	display: flex;
	flex-direction: column;
	animation: rtns-pop 0.24s var(--rtns-ease);
}
@keyframes rtns-fade { from { opacity: 0; } }
@keyframes rtns-pop {
	from { opacity: 0; transform: translateY(-10px) scale(0.985); }
}

/* ============================================================ full-screen /search page */
.rtns-page { margin: 0; background: var(--rtns-surface); }
.rtns-page__main {
	min-height: 100vh;
	min-height: 100dvh;
	display: flex;
	flex-direction: column;
}
.rtns-page .rtns { flex: 1; min-height: 0; }

/* ============================================================ shared shell */
.rtns {
	direction: rtl;
	display: flex;
	flex-direction: column;
	min-height: 0;
	font-family: inherit;
	color: var(--rtns-text);
	background: var(--rtns-surface);
	-webkit-tap-highlight-color: transparent;
}
.rtns__form { margin: 0; }

/* --- search bar --- */
.rtns__bar {
	position: sticky;
	top: 0;
	z-index: 2;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: calc(10px + var(--rtns-safe-top)) 14px 10px;
	background: var(--rtns-surface);
	border-bottom: 1px solid var(--rtns-border);
}
/* the input group is a pill that lights up on focus */
.rtns__field {
	display: flex;
	align-items: center;
	gap: 8px;
	flex: 1 1 auto;
	min-width: 0;
	height: 48px;
	padding: 0 14px;
	background: var(--rtns-surface-2);
	border: 1.5px solid var(--rtns-border);
	border-radius: var(--rtns-r-pill);
	transition: border-color var(--rtns-dur) var(--rtns-ease), box-shadow var(--rtns-dur) var(--rtns-ease), background var(--rtns-dur) var(--rtns-ease);
}
.rtns__bar:focus-within .rtns__field {
	background: var(--rtns-surface);
	border-color: var(--rtns-brand);
	box-shadow: 0 0 0 4px var(--rtns-ring);
}
.rtns__icon { display: inline-flex; color: var(--rtns-faint); flex: 0 0 auto; }
.rtns__bar:focus-within .rtns__icon { color: var(--rtns-brand); }
.rtns__input {
	flex: 1 1 auto;
	min-width: 0;
	height: 100%;
	border: 0;
	outline: 0;
	background: transparent;
	font-family: inherit;
	font-size: 16px; /* ≥16px avoids iOS zoom */
	line-height: 1.6;
	color: var(--rtns-ink);
}
.rtns__input::placeholder { color: var(--rtns-faint); }
/* hide the browser's native search decorations (we render our own clear button) */
.rtns__input::-webkit-search-cancel-button,
.rtns__input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.rtns__clear-input {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 0;
	background: var(--rtns-surface-3);
	color: var(--rtns-muted);
	width: 26px; height: 26px;
	border-radius: 50%;
	cursor: pointer;
	font-size: 17px;
	line-height: 1;
	transition: background var(--rtns-dur) var(--rtns-ease), color var(--rtns-dur) var(--rtns-ease);
}
.rtns__clear-input:hover { background: var(--rtns-brand-tint); color: var(--rtns-brand); }
.rtns__close {
	flex: 0 0 auto;
	border: 0;
	background: transparent;
	color: var(--rtns-brand);
	font-family: inherit;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	padding: 8px 6px;
	border-radius: var(--rtns-r-sm);
	min-height: 44px;
}
.rtns__close:hover { color: var(--rtns-brand-strong); }

/* --- scroll panel --- */
.rtns__panel {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	padding: 6px 8px calc(20px + var(--rtns-safe-bottom));
	overscroll-behavior: contain;
}

/* --- section head --- */
.rtns__section-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 12px 8px;
}
.rtns__section-title {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	font-size: 12.5px;
	font-weight: 700;
	letter-spacing: 0.01em;
	color: var(--rtns-muted);
	margin: 0;
}
.rtns__section-title svg { color: var(--rtns-faint); }
.rtns__recent-clear {
	border: 0; background: transparent;
	color: var(--rtns-danger); font-size: 12.5px; font-weight: 600;
	cursor: pointer; padding: 6px 8px; border-radius: var(--rtns-r-sm);
	min-height: 40px;
}
.rtns__recent-clear:hover { background: var(--rtns-brand-tint); }

/* ============================================================ chips (recent / popular) */
.rtns__recent-list,
.rtns__popular-list {
	list-style: none; margin: 0; padding: 2px 8px 6px;
	display: flex; flex-wrap: wrap; gap: 8px;
}
.rtns__recent-btn,
.rtns__popular-btn {
	display: inline-flex; align-items: center; gap: 6px;
	border: 1px solid var(--rtns-border-2);
	background: var(--rtns-surface-2);
	border-radius: var(--rtns-r-pill);
	padding: 9px 14px;
	font-family: inherit;
	font-size: 13px;
	color: var(--rtns-text);
	cursor: pointer;
	min-height: 40px;
	transition: background var(--rtns-dur) var(--rtns-ease), border-color var(--rtns-dur) var(--rtns-ease), color var(--rtns-dur) var(--rtns-ease), transform 0.1s var(--rtns-ease);
}
.rtns__recent-btn svg,
.rtns__popular-btn svg { color: var(--rtns-faint); flex: 0 0 auto; }
.rtns__recent-btn:hover,
.rtns__popular-btn:hover {
	background: var(--rtns-brand-tint);
	border-color: var(--rtns-brand-tint-2);
	color: var(--rtns-brand-ink);
}
.rtns__recent-btn:hover svg,
.rtns__popular-btn:hover svg { color: var(--rtns-brand); }
.rtns__recent-btn:active,
.rtns__popular-btn:active { transform: scale(0.96); }
.rtns__recent-btn:focus-visible,
.rtns__popular-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--rtns-ring); }

/* ============================================================ typing-state suggestions [PLAN §6] */
.rtns__suggest-list { list-style: none; margin: 0; padding: 4px 0; }
.rtns__suggest-item { border-radius: var(--rtns-r-sm); }

/* term suggestion (🔍 re-search) */
.rtns__suggest-term,
.rtns__suggest-cat {
	position: relative;
	display: flex;
	align-items: center;
	gap: 11px;
	width: 100%;
	padding: 11px 12px;
	border: 0;
	background: transparent;
	text-align: start;
	text-decoration: none;
	color: var(--rtns-text);
	font-family: inherit;
	font-size: 14px;
	cursor: pointer;
	border-radius: var(--rtns-r-sm);
	transition: background var(--rtns-dur) var(--rtns-ease);
}
.rtns__suggest-ico { flex: 0 0 auto; color: var(--rtns-faint); }
.rtns__suggest-text {
	flex: 1 1 auto; min-width: 0;
	overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
	color: var(--rtns-ink);
}
/* trailing "insert into search" arrow, revealed on hover/active */
.rtns__suggest-arrow {
	flex: 0 0 auto; color: var(--rtns-faint);
	opacity: 0; transform: translateX(4px);
	transition: opacity var(--rtns-dur) var(--rtns-ease), transform var(--rtns-dur) var(--rtns-ease), color var(--rtns-dur) var(--rtns-ease);
}
.rtns__suggest-term:hover,
.rtns__suggest-cat:hover,
.rtns__suggest-item.is-active > .rtns__suggest-term,
.rtns__suggest-item.is-active > .rtns__suggest-cat { background: var(--rtns-surface-2); }
.rtns__suggest-term:hover .rtns__suggest-arrow,
.rtns__suggest-item.is-active .rtns__suggest-arrow { opacity: 1; transform: translateX(0); color: var(--rtns-brand); }

/* category-scoped: query text + "در" + category tag + chevron */
.rtns__suggest-q { color: var(--rtns-ink); font-weight: 600; }
.rtns__suggest-in { color: var(--rtns-muted); flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rtns__suggest-tag {
	display: inline-flex; align-items: center;
	background: var(--rtns-brand-tint);
	color: var(--rtns-brand-ink);
	border-radius: var(--rtns-r-pill);
	padding: 3px 11px;
	font-size: 12.5px;
	font-weight: 600;
	white-space: nowrap;
}
.rtns__suggest-cat:hover .rtns__suggest-tag { background: var(--rtns-brand); color: #fff; }
.rtns__suggest-chevron { flex: 0 0 auto; color: var(--rtns-faint); }

/* divider between suggestions and product hits */
.rtns__suggest + .rtns__results-wrap:not(:empty) { border-top: 1px solid var(--rtns-border); margin-top: 4px; padding-top: 4px; }

/* ============================================================ product hits */
.rtns__results { list-style: none; margin: 0; padding: 0; }
.rtns__result { position: relative; border-radius: var(--rtns-r); }
.rtns__result::before { /* brand rail on active/hover (RTL: inline-start = right) */
	content: "";
	position: absolute;
	inset-block: 10px;
	inset-inline-start: 0;
	width: 3px;
	border-radius: 3px;
	background: var(--rtns-brand);
	opacity: 0;
	transition: opacity var(--rtns-dur) var(--rtns-ease);
}
.rtns__result.is-active,
.rtns__result:hover { background: var(--rtns-surface-2); }
.rtns__result.is-active::before,
.rtns__result:hover::before { opacity: 1; }
.rtns__result-link {
	display: flex;
	align-items: center;
	gap: 13px;
	padding: 11px 12px;
	text-decoration: none;
	color: inherit;
}
.rtns__result-thumb {
	flex: 0 0 auto;
	width: 56px; height: 56px;
	border-radius: 12px;
	object-fit: cover;
	background: var(--rtns-surface-3);
	border: 1px solid var(--rtns-border);
}
.rtns__result-thumb--empty { display: inline-block; }
.rtns__result-body { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1 1 auto; }
.rtns__result-title {
	font-size: 14px; line-height: 1.5; color: var(--rtns-ink);
	display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
	overflow: hidden;
}
.rtns__result-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rtns__result-price {
	font-size: 14.5px; font-weight: 700; color: var(--rtns-price);
	font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
}
.rtns__result-price del { color: var(--rtns-faint); font-weight: 400; font-size: 12.5px; margin-inline-start: 6px; }
.rtns__result-price ins { text-decoration: none; }
.rtns__result-badge {
	font-size: 11px; font-weight: 700; border-radius: var(--rtns-r-pill);
	padding: 2px 8px; line-height: 1.6;
}
.rtns__result-badge--stock { color: var(--rtns-instock); background: rgba(15, 157, 88, 0.10); }
.rtns__result-badge--out   { color: var(--rtns-muted);  background: var(--rtns-surface-3); }
.rtns__result.is-out .rtns__result-thumb,
.rtns__result.is-out .rtns__result-title { opacity: 0.6; }

/* stagger the rows in gently */
.rtns__result,
.rtns__suggest-item { animation: rtns-row 0.26s var(--rtns-ease) both; }
@keyframes rtns-row { from { opacity: 0; transform: translateY(4px); } }

/* ============================================================ empty / no-results */
.rtns__empty {
	display: flex; flex-direction: column; align-items: center;
	text-align: center; gap: 6px; padding: 40px 20px 28px; color: var(--rtns-muted);
}
.rtns__empty-ico {
	width: 56px; height: 56px; border-radius: 50%;
	display: inline-flex; align-items: center; justify-content: center;
	background: var(--rtns-surface-2); color: var(--rtns-faint); margin-bottom: 4px;
}
.rtns__empty-title { font-size: 15px; font-weight: 700; color: var(--rtns-ink); }
.rtns__empty-title b { color: var(--rtns-brand); }
.rtns__empty-hint { font-size: 13px; color: var(--rtns-muted); }
.rtns__empty-fallback { margin-top: 14px; width: 100%; }

/* ============================================================ loading skeletons */
.rtns__skeleton { list-style: none; margin: 0; padding: 4px 0; }
.rtns__sk-row { display: flex; align-items: center; gap: 13px; padding: 11px 12px; }
.rtns__sk-thumb { width: 56px; height: 56px; border-radius: 12px; flex: 0 0 auto; }
.rtns__sk-lines { flex: 1 1 auto; display: flex; flex-direction: column; gap: 8px; }
.rtns__sk-line { height: 11px; border-radius: 6px; }
.rtns__sk-line--sm { width: 40%; }
.rtns__sk-thumb, .rtns__sk-line {
	background: linear-gradient(100deg, var(--rtns-surface-2) 30%, var(--rtns-surface-3) 50%, var(--rtns-surface-2) 70%);
	background-size: 220% 100%;
	animation: rtns-shimmer 1.2s linear infinite;
}
@keyframes rtns-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ============================================================ desktop refinements */
@media (min-width: 769px) {
	.rtns__close { display: none; } /* overlay uses backdrop/Esc to close */
	.rtns__result-link { padding: 12px 14px; }
}

/* ============================================================ accessibility */
@media (prefers-reduced-motion: reduce) {
	.rtns *,
	.rtns-overlay * {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.001ms !important;
	}
}
.rtns a:focus-visible,
.rtns button:focus-visible {
	outline: none;
	box-shadow: 0 0 0 3px var(--rtns-ring);
	border-radius: var(--rtns-r-sm);
}
