/* =========================================================================
   MODULE 6 — Anchor Ad (sticky footer/header bar)                 v5.3.2
   Loaded only on pages that actually render an anchor ad.

   Variables (set by lp-anchor.php inline CSS + anchor-ad.js):
     --lp-anchor-slot-h   height reserved for the creative (CLS-safe)
     --lp-anchor-h        total BOTTOM-anchored bar height incl. padding +
                           safe-area inset (Position = Bottom only)
     --lp-anchor-h-top    total TOP-anchored bar height, same idea, kept as a
                           separate variable so a top bar never feeds into the
                           bottom-offset math that floating/slide-in Popups
                           use (see popup.css) — those always sit in a bottom
                           corner and must stay untouched by a top bar.
   Theming: override --lp-anchor-bg / --lp-anchor-border / --lp-anchor-z on
   .lp-anchor from your theme.

   Position: the bar prints with a modifier class, `.lp-anchor--bottom`
   (default) or `.lp-anchor--top`, set from the "Anchor Position" admin
   setting. Shared rules live on `.lp-anchor`; each modifier only overrides
   what actually differs (which edge it pins to, which side the border/
   shadow/slide direction faces, which safe-area inset applies).

   NOTE: env(safe-area-inset-*) is only non-zero when the page's viewport
   meta contains `viewport-fit=cover` (typical for PWA / app-style themes).
   Without it browsers keep content out of the notch/home-indicator area
   themselves, so the bar still sits correctly.
   ========================================================================= */

.lp-anchor {
	--lp-anchor-bg: #fff;
	--lp-anchor-border: rgba(0, 0, 0, .12);
	--lp-anchor-z: 10001; /* above .sicfm-dock-shell (9999); overridden per-ad via lp_anchor_inline_css() */

	position: fixed;
	left: 0;
	right: 0;
	z-index: var(--lp-anchor-z);
	box-sizing: border-box;
	display: flex;
	justify-content: center;
	align-items: center;
	padding-left: calc(8px + env(safe-area-inset-left, 0px));
	padding-right: calc(8px + env(safe-area-inset-right, 0px));
	background: var(--lp-anchor-bg);
	transition: transform .3s ease;
}

/* ---- Bottom (default): sticky footer bar, slides up from the bottom edge. ---- */
.lp-anchor--bottom {
	bottom: 0;
	/* 6px top / bottom padding — keep in sync with the "12px" in lp-anchor.php */
	padding-top: 6px;
	padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
	border-top: 1px solid var(--lp-anchor-border);
	box-shadow: 0 -2px 12px rgba(0, 0, 0, .08);
	transform: translateY(100%);
}

/* ---- Top: sticky header bar, slides down from the top edge. ---- */
.lp-anchor--top {
	top: 0;
	padding-top: calc(6px + env(safe-area-inset-top, 0px));
	padding-bottom: 6px;
	border-bottom: 1px solid var(--lp-anchor-border);
	box-shadow: 0 2px 12px rgba(0, 0, 0, .08);
	transform: translateY(-100%);
}

/* display:flex above would otherwise override the [hidden] attribute. */
.lp-anchor[hidden] { display: none; }
.lp-anchor.is-visible { transform: translateY(0); }

.lp-anchor__slot {
	box-sizing: border-box;
	display: flex;
	justify-content: center;
	align-items: center;
	width: 100%;
	min-height: var(--lp-anchor-slot-h, 0px);
	overflow: hidden;
}

.lp-anchor__link { display: block; line-height: 0; }
.lp-anchor__slot img { display: block; max-width: 100%; height: auto; }

/* Desktop: never let the anchor bar consume more than 30% of the viewport
   height. Caps the slot (creative area) and images inside it so both image
   creatives and ad-code (iframes / async tags) stay within the limit.
   The bar's own padding (~12px) is negligible, so total bar height remains
   ≤ ~30vh. Mobile is left unconstrained — typical mobile creatives (320×50)
   are already well under 30vh. */
@media (min-width: 768px) {
	.lp-anchor {
		max-height: 30vh;
	}
	.lp-anchor__slot {
		max-height: 30vh;
	}
	.lp-anchor__slot img {
		max-height: 30vh;
		width: auto; /* preserve aspect ratio when height is the limiting factor */
	}
}

/* ---- Close button: a small tab attached to the bar ---- */
.lp-anchor__close {
	position: absolute;
	width: 44px;
	height: 28px;
	margin: 0;
	padding: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--lp-anchor-bg);
	color: #444;
	border: 1px solid var(--lp-anchor-border);
	border-radius: 8px;
	cursor: pointer;
	line-height: 1;
	-webkit-tap-highlight-color: transparent;
}

/* Bottom bar: tab sits ABOVE the bar, opening upward. */
.lp-anchor--bottom .lp-anchor__close {
	bottom: 100%;
	right: calc(12px + env(safe-area-inset-right, 0px));
	border-bottom: 0;
	border-radius: 8px 8px 0 0;
}
.lp-anchor--bottom.lp-anchor--close-left .lp-anchor__close {
	right: auto;
	left: calc(12px + env(safe-area-inset-left, 0px));
}
/* Extend the tap target upward to 44×44 without making the tab taller. */
.lp-anchor--bottom .lp-anchor__close::before {
	content: "";
	position: absolute;
	top: -16px;
	right: 0;
	bottom: 0;
	left: 0;
}

/* Top bar: tab sits BELOW the bar, opening downward, so it's never clipped
   by the top edge of the viewport. */
.lp-anchor--top .lp-anchor__close {
	top: 100%;
	right: calc(12px + env(safe-area-inset-right, 0px));
	border-top: 0;
	border-radius: 0 0 8px 8px;
}
.lp-anchor--top.lp-anchor--close-left .lp-anchor__close {
	right: auto;
	left: calc(12px + env(safe-area-inset-left, 0px));
}
/* Extend the tap target downward to 44×44 without making the tab taller. */
.lp-anchor--top .lp-anchor__close::before {
	content: "";
	position: absolute;
	top: 0;
	right: 0;
	bottom: -16px;
	left: 0;
}

.lp-anchor__close[hidden] { display: none; }
.lp-anchor__close:hover { color: #000; }
.lp-anchor__close:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }

/* Reserve room so the bar never hides the page footer (bottom) or covers
   the top of the page content / a sticky header (top). Two separate rules,
   matching the two separate CSS variables above, so a top bar can never
   accidentally reserve bottom space (or vice-versa) if both were ever
   present in markup at once. */
body.lp-has-anchor-bottom { padding-bottom: var(--lp-anchor-h, 0px); }
body.lp-has-anchor-top    { padding-top: var(--lp-anchor-h-top, 0px); }

@media (prefers-reduced-motion: reduce) {
	.lp-anchor { transition: none; }
}
@media print {
	.lp-anchor { display: none !important; }
}
