/* ==========================================================================
   Pretraga (dodatak Tamban Smart Commerce): lupa u zaglavlju i prozor pretrage.
   Boje i radius dolaze iz theme.json aktivne teme, uz rezervne vrednosti.
   ========================================================================== */

.tb-search-block,
.tb-search {
	--tbs-ink: var(--wp--preset--color--ink, #17231f);
	--tbs-muted: var(--wp--preset--color--muted, #6e756f);
	--tbs-line: var(--wp--preset--color--line, #dedbd3);
	--tbs-paper: var(--wp--preset--color--paper, #fbfaf7);
	--tbs-accent: var(--wp--preset--color--forest, #0d352d);
	--tbs-gold: var(--wp--preset--color--gold, #b99554);
	--tbs-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

.tb-search *,
.tb-search *::before,
.tb-search *::after {
	box-sizing: border-box;
}

.tb-search .tb-sr,
.tb-search-block .tb-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Lupa u zaglavlju */
.tb-search-block {
	margin: 0;
}

.tb-search-trigger {
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	border-radius: 999px;
	color: var(--tbs-ink);
	text-decoration: none;
	transition: background-color 160ms ease;
}

.tb-search-trigger:hover {
	background: var(--tbs-paper);
}

/* --------------------------------------------------------------------------
   Prozor
   -------------------------------------------------------------------------- */
.tb-search {
	position: fixed;
	inset: 0;
	width: 100%;
	max-width: none;
	height: 100%;
	max-height: none;
	margin: 0;
	padding: 0;
	overflow: hidden;
	overflow: clip;
	border: 0;
	background: transparent;
	color: var(--tbs-ink);
}

.tb-search::backdrop {
	background: rgba(10, 43, 36, 0.5);
	-webkit-backdrop-filter: blur(4px);
	backdrop-filter: blur(4px);
	animation: tbs-fade-in 220ms ease;
}

.tb-search.is-closing::backdrop {
	animation: tbs-fade-out 180ms ease forwards;
}

.tb-search__panel {
	position: absolute;
	top: 0;
	right: 0;
	left: 0;
	max-height: 92vh;
	max-height: 92dvh;
	overflow-y: auto;
	overscroll-behavior: contain;
	border-radius: 0 0 24px 24px;
	background: #fff;
	box-shadow: 0 30px 80px -20px rgba(10, 43, 36, 0.35);
	animation: tbs-slide-in 300ms var(--tbs-ease);
}

.tb-search.is-closing .tb-search__panel {
	animation: tbs-slide-out 180ms ease forwards;
}

/* Tanka traka napretka dok stižu rezultati */
.tb-search__panel::before {
	content: "";
	position: sticky;
	top: 0;
	z-index: 2;
	display: block;
	height: 3px;
	background: linear-gradient(90deg, transparent, var(--tbs-gold), transparent);
	background-size: 40% 100%;
	background-repeat: no-repeat;
	opacity: 0;
	transition: opacity 160ms ease;
}

.tb-search.is-loading .tb-search__panel::before {
	opacity: 1;
	animation: tbs-progress 900ms linear infinite;
}

.tb-search__inner {
	width: min(1120px, 100%);
	margin-inline: auto;
	/* Sigurna zona: ispod statusne trake i van izreza kada je iPhone položen. */
	padding: calc(clamp(1.25rem, 3vw, 2.25rem) + var(--tb-sa-t, env(safe-area-inset-top, 0px))) max(clamp(1rem, 3vw, 2rem), var(--tb-sa-r, env(safe-area-inset-right, 0px))) 1.5rem max(clamp(1rem, 3vw, 2rem), var(--tb-sa-l, env(safe-area-inset-left, 0px)));
}

.tb-search__head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1.5rem;
}

.tb-search__title {
	margin: 0;
	font-size: clamp(1.625rem, 3.2vw, 2.5rem);
	font-weight: 600;
	letter-spacing: -0.025em;
	line-height: 1.1;
}

.tb-search__text {
	max-width: 62ch;
	margin: 0.45rem 0 0;
	color: var(--tbs-muted);
	font-size: 1rem;
	line-height: 1.5;
}

.tb-search__close {
	display: inline-flex;
	flex: none;
	align-items: center;
	gap: 0.5rem;
	min-height: 44px;
	padding: 0 0.5rem 0 0.75rem;
	border: 1px solid var(--tbs-line);
	border-radius: 999px;
	background: #fff;
	color: var(--tbs-ink);
	cursor: pointer;
	transition: border-color 160ms ease;
}

.tb-search__close:hover {
	border-color: var(--tbs-accent);
}

.tb-search__close kbd {
	padding: 0.1rem 0.4rem;
	border-radius: 6px;
	background: var(--tbs-paper);
	color: var(--tbs-muted);
	font: 600 0.6875rem/1.4 inherit;
	letter-spacing: 0.04em;
}

/* Polje */
.tb-search__form {
	position: relative;
	display: flex;
	align-items: center;
	gap: 0.75rem;
	min-height: 64px;
	margin: 1.25rem 0 0.5rem;
	padding: 0 0.5rem 0 1.25rem;
	border: 1.5px solid var(--tbs-line);
	border-radius: 999px;
	background: #fff;
	transition: border-color 160ms ease, box-shadow 160ms ease;
}

.tb-search__form:focus-within {
	border-color: var(--tbs-accent);
	box-shadow: 0 0 0 4px rgba(13, 53, 45, 0.1);
}

.tb-search__form > svg {
	flex: none;
	color: var(--tbs-muted);
}

.tb-search__form input[type="search"] {
	flex: 1;
	min-width: 0;
	height: 60px;
	padding: 0;
	border: 0;
	outline: 0;
	background: transparent;
	color: var(--tbs-ink);
	font: inherit;
	font-size: 1.125rem;
	-webkit-appearance: none;
	appearance: none;
}

.tb-search__form input[type="search"]::-webkit-search-cancel-button {
	-webkit-appearance: none;
}

.tb-search__clear {
	display: grid;
	place-items: center;
	flex: none;
	width: 40px;
	height: 40px;
	border: 0;
	border-radius: 999px;
	background: var(--tbs-paper);
	color: var(--tbs-muted);
	cursor: pointer;
}

.tb-search__clear[hidden] {
	display: none;
}

@media (pointer: coarse) {
	.tb-search__clear {
		width: 44px;
		height: 44px;
	}
}

.tb-search__submit {
	flex: none;
	min-height: 48px;
	padding: 0 1.5rem;
	border: 0;
	border-radius: 999px;
	background: var(--tbs-accent);
	color: #fff;
	font: inherit;
	font-size: 0.8125rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	cursor: pointer;
	transition: background-color 160ms ease;
}

.tb-search__submit:hover {
	background: var(--wp--preset--color--forest-2, #16483d);
}

/* Sadržaj */
.tb-search__body {
	padding-top: 1rem;
}

.tb-search__section + .tb-search__section {
	margin-top: 1.5rem;
}

.tb-search__label {
	display: flex;
	align-items: baseline;
	gap: 0.75rem;
	margin: 0 0 0.75rem;
	color: var(--tbs-muted);
	font-size: 0.75rem;
	font-weight: 700;
	letter-spacing: 0.14em;
	text-transform: uppercase;
}

.tb-search__link {
	padding: 0;
	border: 0;
	background: none;
	color: var(--tbs-muted);
	font: inherit;
	font-size: 0.75rem;
	letter-spacing: 0;
	text-decoration: underline;
	text-transform: none;
	cursor: pointer;
}

.tb-search__chips,
.tb-search__cats,
.tb-search__suggest,
.tb-search__products {
	margin: 0;
	padding: 0;
	list-style: none;
}

.tb-search__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.tb-search__chip {
	display: inline-flex;
	align-items: center;
	gap: 0.45rem;
	min-height: 40px;
	padding: 0 1rem;
	border: 1px solid var(--tbs-line);
	border-radius: 999px;
	background: var(--tbs-paper);
	color: var(--tbs-ink);
	font-size: 0.9375rem;
	font-weight: 500;
	text-decoration: none;
	transition: border-color 140ms ease, background-color 140ms ease;
}

.tb-search__chip::before {
	content: "";
	width: 0.9rem;
	height: 0.9rem;
	background: currentColor;
	opacity: 0.5;
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 7 13.5 15.5 8.5 10.5 2 17'/%3E%3Cpath d='M16 7h6v6'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 7 13.5 15.5 8.5 10.5 2 17'/%3E%3Cpath d='M16 7h6v6'/%3E%3C/svg%3E") center / contain no-repeat;
}

.tb-search__chip--recent::before {
	-webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 6v6l4 2'/%3E%3C/svg%3E");
	mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 6v6l4 2'/%3E%3C/svg%3E");
}

.tb-search__chip:hover,
.tb-search__chip:focus-visible {
	border-color: var(--tbs-accent);
	background: #fff;
	text-decoration: none;
}

/* Kategorije sa slikom (pre kucanja) */
.tb-search__cats {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
	gap: 0.75rem;
}

.tb-search__cat {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.5rem 0.9rem 0.5rem 0.5rem;
	border: 1px solid var(--tbs-line);
	border-radius: 14px;
	color: var(--tbs-ink);
	text-decoration: none;
	transition: border-color 140ms ease, box-shadow 140ms ease;
}

.tb-search__cat:hover,
.tb-search__cat:focus-visible {
	border-color: var(--tbs-accent);
	box-shadow: 0 10px 24px -16px rgba(10, 43, 36, 0.5);
	text-decoration: none;
}

.tb-search__cat-img {
	flex: none;
	width: 52px;
	height: 52px;
	overflow: hidden;
	border-radius: 10px;
	background: var(--tbs-paper);
}

.tb-search__cat-img img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.tb-search__cat-name {
	flex: 1;
	font-weight: 600;
	line-height: 1.25;
}

.tb-search__cat-count {
	color: var(--tbs-muted);
	font-size: 0.8125rem;
}

/* Rezultati */
.tb-search__fix {
	margin: 0 0 1.25rem;
	padding: 0.75rem 1rem;
	border-radius: 12px;
	background: #f7f1e4;
	color: var(--tbs-ink);
	font-size: 0.9375rem;
}

.tb-search__fix-term {
	padding: 0;
	border: 0;
	background: none;
	color: var(--tbs-accent);
	font: inherit;
	font-weight: 700;
	text-decoration: underline;
	text-underline-offset: 3px;
	cursor: pointer;
}

.tb-search__cols {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 1.5rem;
}

.tb-search__side:not(:has(.tb-search__section:not([hidden]))) {
	display: none;
}

.tb-search__suggestion {
	display: flex;
	align-items: center;
	gap: 0.7rem;
	min-height: 44px;
	padding: 0.35rem 0.6rem;
	margin: 0 -0.6rem;
	border-radius: 10px;
	color: var(--tbs-ink);
	text-decoration: none;
	transition: background-color 120ms ease;
}

.tb-search__suggestion:hover,
.tb-search__suggestion:focus-visible {
	background: var(--tbs-paper);
	text-decoration: none;
}

.tb-search__suggestion-icon {
	flex: none;
	width: 1rem;
	height: 1rem;
	background: var(--tbs-muted);
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m21 21-4.34-4.34'/%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m21 21-4.34-4.34'/%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3C/svg%3E") center / contain no-repeat;
}

.tb-search__suggestion-img {
	flex: none;
	width: 32px;
	height: 32px;
	border-radius: 8px;
	object-fit: cover;
}

.tb-search__suggestion-name {
	flex: 1;
	min-width: 0;
}

.tb-search__suggestion-count {
	color: var(--tbs-muted);
	font-size: 0.8125rem;
}

.tb-search mark {
	padding: 0;
	background: none;
	color: inherit;
	font-weight: 700;
}

.tb-search__products {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 0.5rem;
}

.tb-search__product {
	display: flex;
	align-items: center;
	gap: 0.9rem;
	padding: 0.55rem;
	border: 1px solid transparent;
	border-radius: 14px;
	color: var(--tbs-ink);
	text-decoration: none;
	transition: border-color 140ms ease, background-color 140ms ease;
}

.tb-search__product:hover,
.tb-search__product:focus-visible {
	border-color: var(--tbs-line);
	background: var(--tbs-paper);
	text-decoration: none;
}

.tb-search__product-img {
	position: relative;
	flex: none;
	width: 76px;
	height: 76px;
	overflow: hidden;
	border-radius: 10px;
	background: var(--tbs-paper);
}

.tb-search__product-img img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.tb-search__badge {
	position: absolute;
	top: 4px;
	left: 4px;
	padding: 0.1rem 0.35rem;
	border-radius: 4px;
	background: var(--wp--preset--color--sale, #c93a29);
	color: #fff;
	font-size: 0.5625rem;
	font-weight: 700;
	letter-spacing: 0.05em;
	text-transform: uppercase;
}

.tb-search__badge.is-new {
	background: #fff;
	box-shadow: inset 0 0 0 1px var(--tbs-ink);
	color: var(--tbs-ink);
}

.tb-search__product-body {
	display: grid;
	gap: 0.15rem;
	min-width: 0;
}

.tb-search__product-name {
	overflow: hidden;
	font-weight: 500;
	line-height: 1.3;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.tb-search__product-meta {
	color: var(--tbs-muted);
	font-size: 0.8125rem;
}

.tb-search__product-price {
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.tb-search__product-price del {
	margin-right: 0.35rem;
	color: var(--tbs-muted);
	font-weight: 400;
}

.tb-search__product-price ins {
	color: var(--wp--preset--color--sale, #c93a29);
	text-decoration: none;
}

.tb-search__all {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	margin-top: 1rem;
	padding: 0.85rem 1.4rem;
	border: 1.5px solid var(--tbs-accent);
	border-radius: 999px;
	color: var(--tbs-accent);
	font-size: 0.8125rem;
	font-weight: 700;
	letter-spacing: 0.05em;
	text-decoration: none;
	text-transform: uppercase;
	transition: background-color 140ms ease, color 140ms ease;
}

.tb-search__all::after {
	content: "→";
}

.tb-search__all:hover,
.tb-search__all:focus-visible {
	background: var(--tbs-accent);
	color: #fff;
	text-decoration: none;
}

.tb-search__all[hidden],
.tb-search__results.is-empty .tb-search__cols {
	display: none;
}

.tb-search__empty {
	padding: 1.25rem 0 1.5rem;
	color: var(--tbs-muted);
}

.tb-search__empty p {
	margin: 0;
}

.tb-search__empty .tb-search__empty-title {
	margin-bottom: 0.35rem;
	color: var(--tbs-ink);
	font-size: 1.125rem;
	font-weight: 600;
}

.tb-search.is-loading .tb-search__results {
	opacity: 0.6;
	transition: opacity 160ms ease;
}

.tb-search__help {
	margin: 1.75rem 0 0;
	padding-top: 1rem;
	border-top: 1px solid var(--tbs-line);
	color: var(--tbs-muted);
	font-size: 0.875rem;
	text-align: center;
}

.tb-search__help a {
	color: var(--tbs-accent);
	font-weight: 700;
	text-decoration: none;
}

@media (min-width: 900px) {
	.tb-search__cols {
		grid-template-columns: 280px minmax(0, 1fr);
		gap: 2.5rem;
	}

	/* Bez kategorija i predloga (npr. pretraga po šifri) proizvodi zauzimaju celu širinu. */
	.tb-search__cols:not(:has(.tb-search__side .tb-search__section:not([hidden]))) {
		grid-template-columns: minmax(0, 1fr);
	}

	.tb-search__products {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 0.5rem 1rem;
	}
}

/* Telefon: prozor preko celog ekrana, polje na vrhu */
@media (max-width: 767px) {
	.tb-search__panel {
		bottom: 0;
		max-height: none;
		border-radius: 0;
	}

	.tb-search__inner {
		padding: max(1rem, var(--tb-sa-t, env(safe-area-inset-top, 0px))) 1rem calc(1.5rem + var(--tb-sa-b, env(safe-area-inset-bottom, 0px)));
	}

	.tb-search__close kbd,
	.tb-search__submit {
		display: none;
	}

	.tb-search__close {
		padding: 0 0.6rem;
	}

	.tb-search__form {
		position: sticky;
		top: var(--tb-sa-t, env(safe-area-inset-top, 0px));
		z-index: 1;
		min-height: 56px;
		padding-left: 1rem;
		box-shadow: 0 10px 20px -18px rgba(10, 43, 36, 0.6);
	}

	/* Bela traka iznad lepljivog polja pokriva sigurnu zonu, da rezultati ne prolaze ispod statusne trake. */
	.tb-search__form::before {
		content: "";
		position: absolute;
		inset: auto -1rem calc(100% + 1.5px);
		height: var(--tb-sa-t, env(safe-area-inset-top, 0px));
		background: #fff;
		pointer-events: none;
	}

	.tb-search__form input[type="search"] {
		height: 52px;
		font-size: 1rem;
	}

	.tb-search__cats {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 0.5rem;
	}

	.tb-search__cat {
		flex-direction: column;
		align-items: flex-start;
		gap: 0.5rem;
		padding: 0.5rem;
	}

	.tb-search__cat-img {
		width: 100%;
		height: 84px;
	}

	.tb-search__product-img {
		width: 64px;
		height: 64px;
	}
}

@keyframes tbs-slide-in {
	from { opacity: 0; transform: translateY(-24px); }
}

@keyframes tbs-slide-out {
	to { opacity: 0; transform: translateY(-16px); }
}

@keyframes tbs-fade-in {
	from { opacity: 0; }
}

@keyframes tbs-fade-out {
	to { opacity: 0; }
}

@keyframes tbs-progress {
	from { background-position: -40% 0; }
	to { background-position: 140% 0; }
}

html:has(.tb-search[open]) {
	overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
	.tb-search__panel,
	.tb-search::backdrop,
	.tb-search__panel::before {
		animation: none !important;
	}
}
