/**
 * Four Office Smart Product Search – frontend-styling.
 * v1.3: stor sökpanel med produktkort, kategorichips och färgswatchar.
 */

.fo-sps-container {
	--fo-sps-primary: #6b7280;
	--fo-sps-border: #e5e7eb;
	--fo-sps-bg: #f9fafb;
	--fo-sps-text: #374151;
	--fo-sps-placeholder: #9ca3af;
	--fo-sps-radius: 24px;
	--fo-sps-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
	--fo-sps-focus-shadow: 0 0 0 3px rgba(107, 114, 128, 0.08);
	--fo-sps-panel-width: 860px;
	position: relative;
	width: 100%;
	min-width: 300px;
	box-sizing: border-box;
	z-index: 999;
}

.fo-sps-container *,
.fo-sps-container *::before,
.fo-sps-container *::after {
	box-sizing: border-box;
}

/* hidden-attributet ska alltid vinna över display-regler nedan */
.fo-sps-container [hidden],
.fo-sps-modal [hidden],
.fo-sps-modal[hidden] {
	display: none !important;
}

/* ---------- Input ---------- */

.fo-sps-input-wrapper {
	position: relative;
	display: flex;
	align-items: center;
	width: 100%;
}

/* Hög specificitet + !important på nyckelvärden så temats input-styling inte slår igenom */
.fo-sps-container .fo-sps-input-wrapper input.fo-sps-input {
	width: 100% !important;
	height: 52px !important;
	padding: 0 48px 0 50px !important;
	margin: 0 !important;
	border: 1.5px solid var(--fo-sps-border) !important;
	border-radius: 999px !important;
	font-size: 15px !important;
	line-height: 50px !important;
	outline: none !important;
	transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
	background: #ffffff !important;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05) !important;
	color: #111827 !important;
	font-weight: 400;
	-webkit-appearance: none;
	appearance: none;
}

.fo-sps-container .fo-sps-input-wrapper input.fo-sps-input::placeholder {
	color: var(--fo-sps-placeholder);
	opacity: 1;
}

.fo-sps-container .fo-sps-input-wrapper input.fo-sps-input:focus {
	border-color: #111827 !important;
	background: #ffffff !important;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1) !important;
}

.fo-sps-input::-webkit-search-cancel-button,
.fo-sps-input::-webkit-search-decoration {
	display: none;
	-webkit-appearance: none;
}

.fo-sps-input-wrapper:focus-within .fo-sps-icon-search {
	color: #111827;
}

.fo-sps-icon,
.fo-sps-clear {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--fo-sps-placeholder);
}

.fo-sps-icon svg,
.fo-sps-clear svg,
.fo-sps-icon-btn svg,
.fo-sps-modal-close svg {
	width: 18px;
	height: 18px;
}

.fo-sps-icon-search {
	left: 16px;
	pointer-events: none;
}

.fo-sps-clear {
	right: 12px;
	border: none;
	background: transparent;
	cursor: pointer;
	padding: 6px;
	border-radius: 6px;
	transition: color 0.2s ease, background 0.2s ease;
}

.fo-sps-clear:hover {
	color: #dc2626;
	background: rgba(220, 38, 38, 0.05);
}

/* ---------- Resultatpanel (desktop) ---------- */

.fo-sps-desktop .fo-sps-results {
	position: absolute;
	top: calc(100% + 10px);
	left: 0;
	width: max(100%, var(--fo-sps-panel-width));
	max-width: calc(100vw - 32px);
	background: #ffffff;
	border: 1px solid var(--fo-sps-border);
	border-radius: 20px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.04);
	z-index: 999;
	max-height: min(82vh, 780px);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	animation: fo-sps-slide-down 0.2s ease-out;
}

@keyframes fo-sps-slide-down {
	from {
		opacity: 0;
		transform: translateY(-8px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ---------- Kategorichips ---------- */

.fo-sps-categories {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 16px 20px 4px;
	flex-shrink: 0;
}

.fo-sps-cat-chip {
	display: inline-flex !important;
	align-items: center !important;
	gap: 8px;
	padding: 7px 14px !important;
	border: 1px solid var(--fo-sps-border) !important;
	border-radius: 999px !important;
	background: var(--fo-sps-bg) !important;
	color: var(--fo-sps-text) !important;
	font-size: 13px !important;
	line-height: 1.2 !important;
	font-weight: 500 !important;
	text-decoration: none !important;
	visibility: visible !important;
	opacity: 1 !important;
	transition: all 0.15s ease;
}

.fo-sps-cat-chip:hover {
	border-color: #d1d5db;
	background: #ffffff;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
	color: #111827;
}

.fo-sps-cat-chip-count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 22px;
	padding: 1px 7px;
	border-radius: 999px;
	background: #e5e7eb;
	color: #4b5563;
	font-size: 11px;
	font-weight: 600;
}

/* ---------- Produktgrid ---------- */

.fo-sps-items {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain;
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 16px;
	padding: 16px 20px;
	align-content: start;
	background: #ffffff;
	-webkit-overflow-scrolling: touch;
}

/* !important på allt i korten: sökfältet ligger ofta i headern där teman
   har aggressiva regler (font-size: 0, display på länkar/rubriker osv.) */
.fo-sps-container .fo-sps-item {
	display: flex !important;
	flex-direction: column !important;
	text-decoration: none !important;
	color: #111827 !important;
	font-size: 14px !important;
	line-height: 1.4 !important;
	height: auto !important;
	max-height: none !important;
	width: auto !important;
	visibility: visible !important;
	opacity: 1 !important;
	border-radius: 14px;
	overflow: visible !important;
	background: #ffffff;
	border: 1px solid transparent;
	padding: 0 !important;
	margin: 0 !important;
	transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.fo-sps-container .fo-sps-item:hover {
	border-color: var(--fo-sps-border);
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.07);
	transform: translateY(-2px);
}

/* Fast höjd: robust mot temats CSS, ingen procenttrolleri */
.fo-sps-item-media {
	position: relative;
	width: 100%;
	height: 280px;
	background: #f6f6f6;
	overflow: hidden;
	border-radius: 12px;
	flex-shrink: 0;
}

/* contain visar hela plagget utan beskärning */
.fo-sps-item-media img {
	position: absolute;
	top: 0;
	left: 0;
	width: 100% !important;
	height: 100% !important;
	max-width: 100% !important;
	max-height: 100% !important;
	object-fit: contain;
	display: block;
	margin: 0 !important;
	transition: transform 0.25s ease, opacity 0.25s ease;
}

.fo-sps-item:hover .fo-sps-item-media img {
	transform: scale(1.03);
}

/* Andra galleribilden tonas in vid hover */
.fo-sps-item-media .fo-sps-img-hover {
	opacity: 0;
}

.fo-sps-item:hover .fo-sps-item-media .fo-sps-img-hover {
	opacity: 1;
}

.fo-sps-container .fo-sps-item-details {
	display: flex !important;
	flex-direction: column !important;
	gap: 4px;
	padding: 10px 4px 8px !important;
	margin: 0 !important;
	height: auto !important;
	max-height: none !important;
	overflow: visible !important;
	visibility: visible !important;
	opacity: 1 !important;
}

.fo-sps-container .fo-sps-item-title {
	font-weight: 500 !important;
	margin: 0 !important;
	padding: 0 !important;
	font-size: 13px !important;
	line-height: 1.4 !important;
	color: #111827 !important;
	height: auto !important;
	max-height: none !important;
	min-height: 0 !important;
	text-indent: 0 !important;
	text-transform: none !important;
	letter-spacing: normal !important;
	visibility: visible !important;
	opacity: 1 !important;
	display: -webkit-box !important;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden !important;
}

.fo-sps-container .fo-sps-item-foot {
	display: flex !important;
	align-items: center !important;
	justify-content: space-between !important;
	gap: 8px;
	margin-top: 2px !important;
	height: auto !important;
	visibility: visible !important;
	opacity: 1 !important;
}

.fo-sps-container .fo-sps-item-price {
	color: #111827 !important;
	font-weight: 600 !important;
	font-size: 13px !important;
	line-height: 1.4 !important;
	height: auto !important;
	display: block !important;
	visibility: visible !important;
	opacity: 1 !important;
}

.fo-sps-container .fo-sps-item-price * {
	font-size: 13px !important;
	line-height: 1.4 !important;
	visibility: visible !important;
}

.fo-sps-container .fo-sps-item-price del {
	opacity: 0.55 !important;
	margin-right: 4px;
	font-weight: 400 !important;
	color: #6b7280 !important;
}

.fo-sps-container .fo-sps-item-price ins {
	text-decoration: none !important;
	color: #dc2626 !important;
	background: transparent !important;
}

/* ---------- Färgswatchar ---------- */

.fo-sps-container .fo-sps-colors {
	display: flex !important;
	align-items: center !important;
	gap: 4px;
	flex-shrink: 0;
	visibility: visible !important;
	opacity: 1 !important;
}

.fo-sps-container .fo-sps-color-dot {
	display: inline-block !important;
	width: 14px !important;
	height: 14px !important;
	min-width: 14px !important;
	border-radius: 50% !important;
	border: 1px solid rgba(0, 0, 0, 0.12) !important;
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
	flex-shrink: 0;
	visibility: visible !important;
	opacity: 1 !important;
}

.fo-sps-container .fo-sps-color-more {
	font-size: 11px !important;
	font-weight: 600 !important;
	color: var(--fo-sps-placeholder) !important;
	margin-left: 2px;
	cursor: default;
	visibility: visible !important;
	opacity: 1 !important;
}

/* ---------- Highlighting ---------- */

.fo-sps-highlight {
	background: rgba(107, 114, 128, 0.12) !important;
	color: inherit !important;
	border-radius: 3px;
	padding: 0 1px !important;
	font-weight: 600 !important;
	font-size: inherit !important;
}

/* ---------- Lagerbadge (på produktbilden) ---------- */

.fo-sps-stock-badge {
	position: absolute;
	top: 8px;
	left: 8px;
	z-index: 2;
	font-size: 10px;
	font-weight: 600;
	padding: 4px 8px;
	border-radius: 8px;
	text-transform: uppercase;
	letter-spacing: 0.3px;
	backdrop-filter: blur(4px);
}

.fo-sps-stock-badge.low-stock {
	background: rgba(255, 251, 235, 0.95);
	color: #d97706;
}

.fo-sps-stock-badge.out-of-stock {
	background: rgba(254, 242, 242, 0.95);
	color: #dc2626;
}

/* ---------- Laddning / inga träffar ---------- */

.fo-sps-loading {
	padding: 32px 20px;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	color: var(--fo-sps-placeholder);
	font-size: 14px;
	background: #ffffff;
}

.fo-sps-spinner {
	width: 16px;
	height: 16px;
	border: 2px solid var(--fo-sps-border);
	border-top-color: var(--fo-sps-primary);
	border-radius: 50%;
	animation: fo-sps-spin 0.8s linear infinite;
}

@keyframes fo-sps-spin {
	to {
		transform: rotate(360deg);
	}
}

.fo-sps-no-results {
	grid-column: 1 / -1;
	padding: 40px 20px;
	text-align: center;
	color: var(--fo-sps-placeholder);
	background: #ffffff;
}

.fo-sps-no-results-title {
	font-weight: 500;
	color: #374151;
	margin-bottom: 6px;
	font-size: 15px;
}

.fo-sps-no-results-text {
	font-size: 13px;
	line-height: 1.4;
}

/* ---------- "Se alla resultat" ---------- */

.fo-sps-view-all {
	padding: 12px 20px;
	text-align: center;
	border-top: 1px solid #f3f4f6;
	background: #fafafa;
	flex-shrink: 0;
}

.fo-sps-view-all-link {
	display: inline-block;
	color: var(--fo-sps-text);
	text-decoration: none;
	font-weight: 600;
	font-size: 13px;
	padding: 8px 22px;
	border-radius: 999px;
	border: 1px solid var(--fo-sps-border);
	background: #ffffff;
	transition: all 0.15s ease;
}

.fo-sps-view-all-link:hover {
	border-color: #d1d5db;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
	color: #111827;
}

/* ---------- Mobil trigger + modal ---------- */

.fo-sps-mobile-trigger {
	display: none;
}

.fo-sps-container .fo-sps-icon-btn {
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	width: 44px !important;
	height: 44px !important;
	min-width: 44px !important;
	min-height: 44px !important;
	border: none !important;
	border-radius: 10px !important;
	background: transparent !important;
	color: #374151 !important;
	cursor: pointer;
	padding: 0 !important;
	margin: 0 !important;
	box-shadow: none !important;
	visibility: visible !important;
	opacity: 1 !important;
	transition: all 0.2s ease;
}

.fo-sps-container .fo-sps-icon-btn:hover {
	background: rgba(107, 114, 128, 0.05) !important;
	color: #111827 !important;
}

.fo-sps-container .fo-sps-icon-btn svg {
	display: block !important;
	width: 22px !important;
	height: 22px !important;
	min-width: 22px !important;
	stroke: currentColor !important;
	fill: none !important;
	color: inherit !important;
	visibility: visible !important;
	opacity: 1 !important;
}

.fo-sps-modal {
	position: fixed;
	inset: 0;
	z-index: 99999;
	animation: fo-sps-fade-in 0.25s ease-out;
}

@keyframes fo-sps-fade-in {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

.fo-sps-modal-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.5);
	backdrop-filter: blur(4px);
}

.fo-sps-modal-content {
	position: relative;
	background: #ffffff;
	height: 100vh;
	height: 100dvh;
	display: flex;
	flex-direction: column;
	animation: fo-sps-slide-up 0.25s ease-out;
}

@keyframes fo-sps-slide-up {
	from {
		transform: translateY(100%);
	}
	to {
		transform: translateY(0);
	}
}

.fo-sps-modal-header {
	padding: 16px 20px;
	border-bottom: 1px solid var(--fo-sps-border);
	display: flex;
	align-items: center;
	gap: 12px;
	background: #fafafa;
	flex-shrink: 0;
}

.fo-sps-modal-header .fo-sps-input-wrapper {
	flex: 1;
	min-width: 0;
}

.fo-sps-modal-close {
	width: 48px;
	height: 48px;
	border: 1px solid #d1d5db;
	border-radius: var(--fo-sps-radius);
	background: #ffffff;
	color: #374151;
	cursor: pointer;
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.fo-sps-modal-close:hover {
	border-color: #ef4444;
	color: #ef4444;
	background: #fef2f2;
}

.fo-sps-modal .fo-sps-results {
	flex: 1;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	min-height: 0;
}

.fo-sps-modal .fo-sps-items {
	grid-template-columns: repeat(2, 1fr);
	gap: 12px;
	padding: 14px 16px;
	padding-bottom: calc(14px + env(safe-area-inset-bottom));
}

.fo-sps-modal .fo-sps-item-media {
	height: 220px;
}

.fo-sps-modal .fo-sps-categories {
	padding: 14px 16px 2px;
	overflow-x: auto;
	flex-wrap: nowrap;
}

.fo-sps-modal .fo-sps-cat-chip {
	white-space: nowrap;
}

.fo-sps-modal .fo-sps-view-all {
	padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
	box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.05);
}

.fo-sps-modal .fo-sps-view-all-link {
	display: block;
	width: 100%;
	padding: 12px 16px;
	background: #111827;
	border-color: #111827;
	color: #ffffff;
	font-size: 14px;
}

/* Wrapper för modalen när den flyttats till <body> – ska inte påverka layouten */
.fo-sps-container.fo-sps-modal-host {
	position: fixed;
	width: 0;
	height: 0;
	min-width: 0;
	margin: 0;
	padding: 0;
	overflow: visible;
}

body.fo-sps-no-scroll {
	overflow: hidden;
}

/* Göm alla sök-triggers (även i sticky header-kloner med hög z-index)
   när modalen är öppen, så ingen ikon flyter ovanpå sökpanelen. */
body.fo-sps-no-scroll .fo-sps-mobile-trigger {
	visibility: hidden !important;
	pointer-events: none !important;
}

/* ---------- Responsivt ---------- */

@media (max-width: 1024px) {
	.fo-sps-mobile-trigger {
		display: block;
	}

	.fo-sps-desktop {
		display: none;
	}

	.fo-sps-container {
		min-width: auto;
		width: auto;
	}

	.fo-sps-modal .fo-sps-input {
		font-size: 16px; /* förhindrar zoom på iOS */
	}
}

@media (min-width: 1025px) {
	.fo-sps-modal {
		display: none;
	}
}
