/**
 * Smart Popup Builder – Frontend
 *
 * Layout und Verhalten stecken hier, alle Designwerte kommen als
 * CSS-Variablen aus dem generierten Inline-CSS.
 */

.spb-popup {
	--spb-width: 520px;
	--spb-max-width: 92vw;
	--spb-min-width: 0;
	--spb-height: auto;
	--spb-max-height: 86vh;
	--spb-padding: 32px;
	--spb-gap: 24px;
	--spb-align: center;
	--spb-radius: 16px;
	--spb-border: 0 solid transparent;
	--spb-shadow: 0 18px 48px -8px rgba(16, 24, 43, 0.22);
	--spb-opacity: 1;
	--spb-bg-color: #fff;
	--spb-bg-image: none;
	--spb-bg-position: center center;
	--spb-bg-size: cover;
	--spb-bg-repeat: no-repeat;
	--spb-overlay-bg: #0b1220;
	--spb-overlay-op: 0.55;
	--spb-overlay-blur: 0px;
	--spb-duration: 420ms;
	--spb-delay: 0ms;
	--spb-easing: cubic-bezier(0.22, 0.68, 0, 1);
	--spb-close-size: 18px;
	--spb-close-color: #64748b;
	--spb-close-bg: transparent;
	--spb-close-hover: #10182b;
	--spb-close-offset: 14px;
	--spb-heading-size: 30px;
	--spb-heading-family: inherit;
	--spb-heading-weight: 700;
	--spb-heading-line: 1.25;
	--spb-heading-spacing: 0;
	--spb-heading-color: #10182b;
	--spb-heading-transform: none;
	--spb-heading-decoration: none;
	--spb-text-size: 16px;
	--spb-text-family: inherit;
	--spb-text-weight: 400;
	--spb-text-line: 1.6;
	--spb-text-spacing: 0;
	--spb-text-color: #3c465c;
	--spb-text-transform: none;
	--spb-text-decoration: none;
	--spb-button-size: 16px;
	--spb-button-family: inherit;
	--spb-button-weight: 600;
	--spb-button-line: 1.2;
	--spb-button-spacing: 0;
	--spb-button-color: #fff;
	--spb-button-transform: none;
	--spb-button-decoration: none;

	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	height: 100vh;
	z-index: 99990;
	display: none;
}

/* Dynamische Viewport-Höhe, wo verfügbar: verhindert, dass die
   Adressleiste mobiler Browser den unteren Rand abschneidet. */
@supports (height: 100dvh) {
	.spb-popup:not(.spb-inline) {
		height: 100dvh;
	}
}

.spb-popup[hidden] {
	display: none;
}

.spb-popup.is-open {
	display: block;
}

.spb-popup.spb-inline {
	position: static;
	display: block;
	height: auto;
	z-index: auto;
}

/* ---------- Overlay ---------- */

.spb-overlay {
	position: absolute;
	inset: 0;
	background: var(--spb-overlay-bg);
	opacity: 0;
	transition: opacity var(--spb-duration) var(--spb-easing);
}

.spb-popup.is-open .spb-overlay {
	opacity: var(--spb-overlay-op);
}

.spb-popup.is-closing .spb-overlay {
	opacity: 0;
}

.spb-popup:not(.spb-inline) .spb-overlay {
	-webkit-backdrop-filter: blur(var(--spb-overlay-blur));
	backdrop-filter: blur(var(--spb-overlay-blur));
}

/* ---------- Positionierung ---------- */

.spb-wrap {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: var(--spb-gap);
	padding-top: max(var(--spb-gap), env(safe-area-inset-top));
	padding-bottom: max(var(--spb-gap), env(safe-area-inset-bottom));
	padding-left: max(var(--spb-gap), env(safe-area-inset-left));
	padding-right: max(var(--spb-gap), env(safe-area-inset-right));
	pointer-events: none;
}

.spb-inline .spb-wrap {
	position: static;
	padding: 0;
	display: block;
}

.spb-pos-top .spb-wrap {
	align-items: flex-start;
}

.spb-pos-bottom .spb-wrap {
	align-items: flex-end;
}

.spb-type-slide_left .spb-wrap {
	justify-content: flex-start;
}

.spb-type-slide_right .spb-wrap,
.spb-type-notification .spb-wrap,
.spb-type-floating .spb-wrap {
	justify-content: flex-end;
}

.spb-type-slide_top .spb-wrap,
.spb-type-bar_top .spb-wrap {
	align-items: flex-start;
}

.spb-type-slide_bottom .spb-wrap,
.spb-type-bar_bottom .spb-wrap,
.spb-type-notification .spb-wrap,
.spb-type-floating .spb-wrap {
	align-items: flex-end;
}

.spb-type-bar_top .spb-wrap,
.spb-type-bar_bottom .spb-wrap,
.spb-type-fullscreen .spb-wrap {
	padding: 0;
}

/* ---------- Popup-Box ---------- */

.spb-box {
	pointer-events: auto;
	position: relative;
	box-sizing: border-box;
	width: var(--spb-width);
	min-width: var(--spb-min-width);
	max-width: min(var(--spb-max-width), 100%);
	height: var(--spb-height);
	max-height: var(--spb-max-height);
	overflow-wrap: break-word;
	word-break: break-word;
	padding: var(--spb-padding);
	text-align: var(--spb-align);
	background-color: var(--spb-bg-color);
	background-image: var(--spb-bg-image);
	background-position: var(--spb-bg-position);
	background-size: var(--spb-bg-size);
	background-repeat: var(--spb-bg-repeat);
	border: var(--spb-border);
	border-radius: var(--spb-radius);
	box-shadow: var(--spb-shadow);
	opacity: var(--spb-opacity);
	overflow-y: auto;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
}

@supports (height: 100dvh) {
	.spb-popup:not(.spb-inline):not(.spb-type-fullscreen):not(.spb-type-bar_top):not(.spb-type-bar_bottom) .spb-box {
		max-height: min(var(--spb-max-height), calc(100dvh - 2 * var(--spb-gap)));
	}
}

.spb-type-bar_top .spb-box,
.spb-type-bar_bottom .spb-box {
	width: 100%;
	max-width: 100%;
	border-radius: 0;
}

.spb-type-fullscreen .spb-box {
	width: 100%;
	max-width: 100%;
	height: 100%;
	max-height: 100%;
	border-radius: 0;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.spb-inline .spb-box {
	max-height: none;
	margin: 0 auto;
}

/* ---------- Inhalt ---------- */

.spb-content > .spb-block + .spb-block {
	margin-top: 14px;
}

.spb-popup .spb-heading {
	margin: 0;
	font-family: var(--spb-heading-family);
	font-size: var(--spb-heading-size);
	font-weight: var(--spb-heading-weight);
	line-height: var(--spb-heading-line);
	letter-spacing: var(--spb-heading-spacing);
	color: var(--spb-heading-color);
	text-transform: var(--spb-heading-transform);
	text-decoration: var(--spb-heading-decoration);
}

.spb-popup .spb-subheading {
	font-size: calc(var(--spb-heading-size) * 0.62);
	font-weight: 500;
	opacity: 0.85;
}

.spb-popup .spb-text,
.spb-popup .spb-text p {
	margin: 0;
	font-family: var(--spb-text-family);
	font-size: var(--spb-text-size);
	font-weight: var(--spb-text-weight);
	line-height: var(--spb-text-line);
	letter-spacing: var(--spb-text-spacing);
	color: var(--spb-text-color);
	text-transform: var(--spb-text-transform);
}

.spb-text p + p {
	margin-top: 0.7em;
}

.spb-block-image img {
	display: block;
	max-width: 100%;
	height: auto;
	margin: 0 auto;
}

.spb-video {
	position: relative;
	width: 100%;
}

.spb-video iframe,
.spb-video video {
	width: 100%;
	aspect-ratio: 16 / 9;
	border: 0;
	display: block;
	border-radius: 10px;
}

.spb-ratio-4-3 iframe,
.spb-ratio-4-3 video {
	aspect-ratio: 4 / 3;
}

.spb-ratio-1-1 iframe,
.spb-ratio-1-1 video {
	aspect-ratio: 1 / 1;
}

.spb-ratio-9-16 iframe,
.spb-ratio-9-16 video {
	aspect-ratio: 9 / 16;
}

.spb-icon {
	display: inline-flex;
	line-height: 1;
}

.spb-popup .spb-divider {
	border: 0;
	border-top-style: solid;
	margin: 0;
}

/* ---------- Buttons ---------- */

.spb-popup .spb-btn {
	display: inline-block;
	box-sizing: border-box;
	font-family: var(--spb-button-family);
	font-size: var(--spb-button-size);
	font-weight: var(--spb-button-weight);
	line-height: var(--spb-button-line);
	letter-spacing: var(--spb-button-spacing);
	text-transform: var(--spb-button-transform);
	text-decoration: none;
	background: var(--btn-bg, #192634);
	color: var(--btn-color, #fff);
	border: 0;
	cursor: pointer;
	transition: background-color 180ms ease, transform 180ms ease;
}

.spb-popup .spb-btn:hover,
.spb-popup .spb-btn:focus-visible {
	background: var(--btn-hover, #24384c);
	color: var(--btn-color, #fff);
	transform: translateY(-1px);
}

.spb-popup .spb-btn-full {
	display: block;
	width: 100%;
	text-align: center;
}

/* ---------- Gutscheincode ---------- */

.spb-coupon {
	display: flex;
	align-items: stretch;
	justify-content: center;
	gap: 8px;
	flex-wrap: wrap;
}

.spb-popup .spb-coupon-code {
	display: inline-flex;
	align-items: center;
	padding: 12px 20px;
	border: 2px dashed currentColor;
	border-radius: 8px;
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 1.05em;
	letter-spacing: 0.14em;
	color: var(--spb-heading-color);
	background: rgba(0, 0, 0, 0.03);
}

.spb-popup .spb-coupon-copy {
	padding: 12px 18px;
	border: 0;
	border-radius: 8px;
	background: var(--spb-heading-color);
	color: #fff;
	font: inherit;
	font-size: 0.9em;
	cursor: pointer;
}

/* ---------- Countdown ---------- */

.spb-countdown {
	display: flex;
	gap: 10px;
	justify-content: center;
	flex-wrap: wrap;
}

.spb-cd-unit {
	display: flex;
	flex-direction: column;
	align-items: center;
	min-width: 64px;
	padding: 10px 6px;
	border-radius: 10px;
	background: rgba(16, 24, 43, 0.06);
}

.spb-cd-unit b {
	font-size: 1.7em;
	font-weight: 700;
	line-height: 1;
	font-variant-numeric: tabular-nums;
	color: var(--spb-heading-color);
}

.spb-cd-unit i {
	margin-top: 4px;
	font-style: normal;
	font-size: 0.72em;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--spb-text-color);
}

/* ---------- Schließen-Button ---------- */

.spb-popup .spb-close {
	position: absolute;
	z-index: 3;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: calc(var(--spb-close-size) * 2);
	height: calc(var(--spb-close-size) * 2);
	padding: 0;
	font-size: var(--spb-close-size);
	line-height: 1;
	color: var(--spb-close-color);
	background: var(--spb-close-bg);
	border: 0;
	border-radius: 999px;
	cursor: pointer;
	transition: color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.spb-popup .spb-close:hover,
.spb-popup .spb-close:focus-visible {
	color: var(--spb-close-hover);
	background: rgba(16, 24, 43, 0.08);
	transform: rotate(90deg);
}

.spb-close-inside_tr {
	top: var(--spb-close-offset);
	right: var(--spb-close-offset);
}

.spb-close-inside_tl {
	top: var(--spb-close-offset);
	left: var(--spb-close-offset);
}

.spb-close-outside_tr {
	top: calc(var(--spb-close-offset) * -1 - var(--spb-close-size) * 1.6);
	right: 0;
	color: #fff;
}

.spb-close-outside_tl {
	top: calc(var(--spb-close-offset) * -1 - var(--spb-close-size) * 1.6);
	left: 0;
	color: #fff;
}

.spb-close-bottom_center {
	bottom: calc(var(--spb-close-offset) * -1 - var(--spb-close-size) * 2.4);
	left: 50%;
	transform: translateX(-50%);
	color: #fff;
}

.spb-close-bottom_center:hover {
	transform: translateX(-50%) rotate(90deg);
}

/* ---------- Fokus ---------- */

.spb-box :focus-visible,
.spb-close:focus-visible {
	outline: 2px solid #8fb2cf;
	outline-offset: 2px;
}

/* ---------- Scroll-Sperre ---------- */

html.spb-locked,
body.spb-locked {
	overflow: hidden !important;
	touch-action: none;
}

/* ---------- Animationen ---------- */

.spb-popup .spb-box {
	animation-duration: var(--spb-duration);
	animation-delay: var(--spb-delay);
	animation-timing-function: var(--spb-easing);
	animation-fill-mode: both;
}

.spb-popup.is-open.spb-anim-fade_in .spb-box { animation-name: spbFadeIn; }
.spb-popup.is-open.spb-anim-zoom_in .spb-box { animation-name: spbZoomIn; }
.spb-popup.is-open.spb-anim-slide_in .spb-box { animation-name: spbSlideIn; }
.spb-popup.is-open.spb-anim-bounce_in .spb-box { animation-name: spbBounceIn; }
.spb-popup.is-open.spb-anim-flip_in .spb-box { animation-name: spbFlipIn; }
.spb-popup.is-open.spb-anim-rotate_in .spb-box { animation-name: spbRotateIn; }
.spb-popup.is-open.spb-anim-scale_in .spb-box { animation-name: spbScaleIn; }
.spb-popup.is-open.spb-anim-none .spb-box { animation-name: none; }

.spb-popup.is-closing.spb-out-fade_out .spb-box { animation-name: spbFadeOut; animation-delay: 0ms; }
.spb-popup.is-closing.spb-out-zoom_out .spb-box { animation-name: spbZoomOut; animation-delay: 0ms; }
.spb-popup.is-closing.spb-out-slide_out .spb-box { animation-name: spbSlideOut; animation-delay: 0ms; }
.spb-popup.is-closing.spb-out-scale_out .spb-box { animation-name: spbScaleOut; animation-delay: 0ms; }
.spb-popup.is-closing.spb-out-none .spb-box { animation-name: none; opacity: 0; }

@keyframes spbFadeIn {
	from { opacity: 0; }
	to { opacity: var(--spb-opacity); }
}

@keyframes spbFadeOut {
	from { opacity: var(--spb-opacity); }
	to { opacity: 0; }
}

@keyframes spbZoomIn {
	from { opacity: 0; transform: scale(0.86); }
	to { opacity: var(--spb-opacity); transform: scale(1); }
}

@keyframes spbZoomOut {
	from { opacity: var(--spb-opacity); transform: scale(1); }
	to { opacity: 0; transform: scale(0.9); }
}

@keyframes spbScaleIn {
	from { opacity: 0; transform: scale(1.08); }
	to { opacity: var(--spb-opacity); transform: scale(1); }
}

@keyframes spbScaleOut {
	from { opacity: var(--spb-opacity); transform: scale(1); }
	to { opacity: 0; transform: scale(1.06); }
}

@keyframes spbSlideIn {
	from { opacity: 0; transform: translate3d(var(--spb-slide-x, 0), var(--spb-slide-y, 40px), 0); }
	to { opacity: var(--spb-opacity); transform: translate3d(0, 0, 0); }
}

@keyframes spbSlideOut {
	from { opacity: var(--spb-opacity); transform: translate3d(0, 0, 0); }
	to { opacity: 0; transform: translate3d(var(--spb-slide-x, 0), var(--spb-slide-y, 40px), 0); }
}

@keyframes spbBounceIn {
	0% { opacity: 0; transform: scale(0.8); }
	60% { opacity: 1; transform: scale(1.04); }
	80% { transform: scale(0.985); }
	100% { opacity: var(--spb-opacity); transform: scale(1); }
}

@keyframes spbFlipIn {
	from { opacity: 0; transform: perspective(1000px) rotateX(-22deg); }
	to { opacity: var(--spb-opacity); transform: perspective(1000px) rotateX(0); }
}

@keyframes spbRotateIn {
	from { opacity: 0; transform: rotate(-6deg) scale(0.92); }
	to { opacity: var(--spb-opacity); transform: rotate(0) scale(1); }
}

/* Richtung der Slide-Animation je Popup-Typ */
.spb-type-slide_left { --spb-slide-x: -60px; --spb-slide-y: 0; }
.spb-type-slide_right { --spb-slide-x: 60px; --spb-slide-y: 0; }
.spb-type-slide_top,
.spb-type-bar_top { --spb-slide-x: 0; --spb-slide-y: -60px; }
.spb-type-slide_bottom,
.spb-type-bar_bottom,
.spb-type-notification,
.spb-type-floating { --spb-slide-x: 0; --spb-slide-y: 60px; }

@media (prefers-reduced-motion: reduce) {
	.spb-popup .spb-box,
	.spb-overlay {
		animation-duration: 1ms !important;
		animation-delay: 0ms !important;
		transition-duration: 1ms !important;
	}
	.spb-close:hover {
		transform: none;
	}
}

/* ---------- Mobile Grundverhalten ---------- */

@media (max-width: 767px) {
	.spb-hide-mobile {
		display: none !important;
	}

	.spb-coupon {
		flex-direction: column;
	}
}

/* ---------- Geräteanpassungen ---------- */

/* Medien laufen nie aus dem Popup heraus. */
.spb-content img,
.spb-content video,
.spb-content iframe,
.spb-content table {
	max-width: 100%;
}

/* Touch-Bedienung: Mindestgröße 44 x 44 px nach WCAG. */
@media (pointer: coarse) {
	.spb-close {
		min-width: 44px;
		min-height: 44px;
	}

	.spb-btn {
		min-height: 44px;
		display: inline-flex;
		align-items: center;
		justify-content: center;
	}

	.spb-coupon-copy {
		min-height: 44px;
	}
}

/* Hinweisleisten: seitliche Safe Areas auch ohne Randabstand. */
.spb-type-bar_top .spb-box,
.spb-type-bar_bottom .spb-box {
	padding-left: max(var(--spb-padding), env(safe-area-inset-left));
	padding-right: max(var(--spb-padding), env(safe-area-inset-right));
}

.spb-type-bar_bottom .spb-box {
	padding-bottom: max(var(--spb-padding), env(safe-area-inset-bottom));
}

.spb-type-bar_top .spb-box {
	padding-top: max(var(--spb-padding), env(safe-area-inset-top));
}

/* Vollbild: dynamische Viewport-Höhe statt starrer 100 %. */
@supports (height: 100dvh) {
	.spb-popup.spb-type-fullscreen .spb-box {
		height: 100dvh;
		max-height: 100dvh;
	}
}

/* Querformat auf Smartphones: wenig Höhe, also flacher und scrollbar. */
@media (max-height: 500px) and (orientation: landscape) {
	.spb-wrap {
		padding-top: max(8px, env(safe-area-inset-top));
		padding-bottom: max(8px, env(safe-area-inset-bottom));
		align-items: flex-start;
	}

	.spb-popup:not(.spb-inline):not(.spb-type-fullscreen) .spb-box {
		max-height: calc(100vh - 16px);
		padding: min(var(--spb-padding), 20px);
	}

	.spb-content > .spb-block + .spb-block {
		margin-top: 10px;
	}

	.spb-cd-unit {
		min-width: 54px;
		padding: 6px 4px;
	}
}

/* Sehr kleine Displays (iPhone SE und schmaler). */
@media (max-width: 380px) {
	.spb-popup:not(.spb-inline) .spb-box {
		padding: min(var(--spb-padding), 20px);
	}

	.spb-heading {
		font-size: min(var(--spb-heading-size), 26px);
	}

	.spb-btn {
		width: 100%;
		text-align: center;
	}

	.spb-cd-unit {
		min-width: 0;
		flex: 1;
	}

	.spb-countdown {
		gap: 6px;
		flex-wrap: nowrap;
	}
}

/* Bottom Sheet: Griff-Andeutung und daumenfreundlicher Abschluss. */
.spb-mobile-bottom_sheet .spb-box::before {
	content: "";
	display: none;
	width: 42px;
	height: 4px;
	margin: -8px auto 14px;
	border-radius: 999px;
	background: currentColor;
	opacity: 0.22;
}

@media (max-width: 767px) {
	.spb-mobile-bottom_sheet .spb-box::before {
		display: block;
	}

	/* Slide-In-Varianten verhalten sich mobil wie eine Karte am unteren Rand. */
	.spb-type-slide_left .spb-wrap,
	.spb-type-slide_right .spb-wrap {
		justify-content: center;
	}
}

/* Sehr hohe Inhalte: der Scrollbereich bleibt im Popup, nicht auf der Seite. */
.spb-box::-webkit-scrollbar {
	width: 8px;
}

.spb-box::-webkit-scrollbar-thumb {
	border-radius: 8px;
	background: rgba(16, 24, 43, 0.18);
}

/* Browser-Zoom und große Schriftgrößen: nichts wird abgeschnitten. */
@media (min-resolution: 1.5dppx) and (max-width: 600px) {
	.spb-popup:not(.spb-inline):not(.spb-type-fullscreen):not(.spb-type-bar_top):not(.spb-type-bar_bottom) .spb-box {
		max-height: calc(100vh - 2 * var(--spb-gap));
	}
}

/* ---------- Formatierter Text im Popup ---------- */

.spb-text strong,
.spb-text b,
.spb-heading strong,
.spb-heading b {
	font-weight: 700;
}

.spb-text a,
.spb-heading a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.spb-text a:hover,
.spb-heading a:hover {
	text-decoration-thickness: 2px;
}

.spb-text ul,
.spb-text ol {
	margin: 0.6em 0;
	padding-left: 1.35em;
	text-align: left;
}

.spb-text li {
	margin-bottom: 0.3em;
}

.spb-text li:last-child {
	margin-bottom: 0;
}
