/* ============================================================================
   Consentinel — front-end banner + preferences modal.

   ISOLATION MODEL (why every selector is prefixed with an id):
   The widget lives inside the host page's DOM, so theme / Elementor CSS would
   otherwise cascade into it (fonts, button styles, letter-spacing, resets) and
   produce inconsistent results per site. To make it self-contained:
     1. Every rule is scoped under #consentinel-root (banner + modal) or
        #consentinel-fab (the floating launcher, which renders outside the root).
        An id (specificity 1,0,0) beats theme element/class rules, so we win
        WITHOUT the old !important patches.
     2. A reset (below) neutralizes inherited/host styling on our own elements.
        It is element-level (id + tag = 1,0,1); the component rules that follow
        are id + class (1,1,0), so they always win over the reset.
     3. Typography is set explicitly from CSS custom properties (--cg-font, etc.)
        emitted per-site by Frontend::banner_css_vars(). The banner no longer
        inherits the theme's fonts/sizes by default — 'Inherit from theme' font
        is an explicit opt-in (--cg-font: inherit).
   Nothing here targets a bare element selector, so the widget never leaks styles
   back onto the host page either.
   ============================================================================ */

#consentinel-root {
	/* Colors (set inline per-site; fallbacks here). */
	--cg-accent: #0c7ee9;
	--cg-bg: #fff;
	--cg-fg: #1a1a1a;
	--cg-muted: #323232;
	--cg-border: #e1e3e8;
	/* Typography & shape (set inline per-site; fallbacks here). */
	--cg-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	--cg-font-size: 14px;
	--cg-title-size: 19px;
	--cg-radius: 12px;
	--cg-btn-radius: 8px;
	--cg-btn-transform: none;

	position: fixed;
	inset: 0;
	display: flex;
	pointer-events: none; /* let clicks through to the page; banner re-enables them */

	font-family: var(--cg-font);
	font-size: var(--cg-font-size);
	line-height: 1.45;
	color: var(--cg-fg);
	z-index: 999999;
}
#consentinel-root[hidden] { display: none; } /* hidden attribute beats display:flex without this */

/* --- Isolation reset (see header). Box-sizing on everything; typography and
   appearance neutralized on the elements themes most often style. --- */
#consentinel-root *,
#consentinel-root *::before,
#consentinel-root *::after,
#consentinel-fab,
#consentinel-fab * { box-sizing: border-box; }

#consentinel-root button,
#consentinel-root a,
#consentinel-root p,
#consentinel-root span,
#consentinel-root label,
#consentinel-root ul,
#consentinel-root li,
#consentinel-root input,
#consentinel-fab {
	margin: 0;
	padding: 0;
	font-family: inherit;
	font-size: inherit;
	font-weight: inherit;
	font-style: inherit;
	line-height: inherit;
	letter-spacing: normal;
	text-transform: none;
	text-shadow: none;
	text-decoration: none;
	color: inherit;
	background: none;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	text-align: left;
	min-width: 0;
	min-height: 0;
}
#consentinel-root button,
#consentinel-fab {
	-webkit-appearance: none;
	appearance: none;
	width: auto;
	cursor: pointer;
}
#consentinel-root img {
	border-radius: 0;
	box-shadow: none;
	max-width: 100%;
	height: auto;
}

/* Keep the consent banner bar hidden whenever the preferences modal is open
   (cg-prefs-open), and when the modal was opened standalone via the
   [consentinel_preferences] shortcode / floating button (cg-modal-only). */
#consentinel-root.cg-modal-only .cg-banner,
#consentinel-root.cg-prefs-open .cg-banner { display: none; }

#consentinel-root .cg-banner {
	position: relative; /* anchor for the close button */
	pointer-events: auto;
	background: var(--cg-bg);
	padding: 16px 20px;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 16px;
}

/* Close-and-accept "×" (banner only, not the modal). */
#consentinel-root .cg-banner__close {
	position: absolute;
	top: 4px;
	right: 8px;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	font-size: 22px;
	line-height: 1;
	color: var(--cg-fg); /* follows the Text color (subtle via opacity) */
	opacity: 0.7;
	transition: opacity 0.15s ease;
}
#consentinel-root .cg-banner__close:hover,
#consentinel-root .cg-banner__close:focus-visible { opacity: 1; }

/* Vertical placement (applies to both layouts) */
#consentinel-root[data-position="top"]    { align-items: flex-start; }
#consentinel-root[data-position="bottom"] { align-items: flex-end; }

/* --- Bar layout: full-width strip --- */
#consentinel-root[data-layout="bar"] .cg-banner {
	width: 100%;
	border-top: 1px solid var(--cg-border);
	box-shadow: 0 -8px 24px rgba(0,0,0,0.08);
	margin: 0 20px 20px;
	border-radius: var(--cg-radius);
}
#consentinel-root[data-layout="bar"][data-position="top"] .cg-banner {
	border-top: 0;
	border-bottom: 1px solid var(--cg-border);
	box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

/* --- Box layout: floating card, aligned via justify-content --- */
#consentinel-root[data-layout="box"] { padding: 16px; }
#consentinel-root[data-layout="box"] .cg-banner {
	max-width: 420px;
	border: 1px solid var(--cg-border);
	border-radius: var(--cg-radius);
	box-shadow: 0 4px 16px rgba(0,0,0,0.08);
	overflow: hidden; /* clip the full-bleed brand strip to the rounded corners */
}
#consentinel-root[data-layout="box"][data-box-align="left"]   { justify-content: flex-start; }
#consentinel-root[data-layout="box"][data-box-align="center"] { justify-content: center; }
#consentinel-root[data-layout="box"][data-box-align="right"]  { justify-content: flex-end; }

#consentinel-root .cg-body { flex: 1 1 320px; }
/* Title is a <span> (not a heading) so theme/Elementor h2 rules can't inflate
   it; display:block keeps it stacked above the message. */
#consentinel-root .cg-title {
	display: block;
	font-size: var(--cg-title-size);
	font-weight: 600;
	line-height: 1.25;
	color: var(--cg-title, var(--cg-fg));
}
#consentinel-root .cg-message { color: var(--cg-fg); }

/* Heading icons (banner cookie, modal shield). CSS mask so the single-color SVG
   is recolored via background-color — inherits --cg-bg-fg (auto-contrast of the
   background) and stays legible on any background. */
#consentinel-root .cg-heading-icon {
	display: inline-block;
	flex: 0 0 auto;
	background-color: var(--cg-bg-fg, var(--cg-fg));
	-webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
	-webkit-mask-position: center; mask-position: center;
	-webkit-mask-size: contain; mask-size: contain;
}
#consentinel-root .cg-heading-icon--cookie {
	width: 20px; height: 20px;
	-webkit-mask-image: url(../img/cookie.svg); mask-image: url(../img/cookie.svg);
}
#consentinel-root .cg-heading-icon--shield {
	width: 22px; height: 24px;
	-webkit-mask-image: url(../img/consentinel-icon-black.svg); mask-image: url(../img/consentinel-icon-black.svg);
}
/* Banner: cookie + title on one row; the row owns the title's bottom margin. */
#consentinel-root .cg-title-row { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; }
/* Modal: shield + title grouped at the left of the header; close button stays right. */
#consentinel-root .cg-prefs__heading { display: flex; align-items: center; gap: 10px; min-width: 0; }

#consentinel-root .cg-links { margin: 8px 0 0; }
/* Policy links auto-contrast against the banner background; underlined so they
   stay identifiable as links. */
#consentinel-root .cg-links a {
	color: var(--cg-bg-fg, var(--cg-accent));
	display: inline-block;
	border-bottom: 1px dotted;
}
#consentinel-root .cg-links__sep { color: var(--cg-fg); margin: 0 2px; }

#consentinel-root .cg-actions { display: flex; gap: 8px; flex-wrap: wrap; }

#consentinel-root .cg-btn {
	border: 1px solid var(--cg-border);
	background: #fff;
	color: var(--cg-fg);
	padding: 8px 16px;
	border-radius: var(--cg-btn-radius);
	font-size: 1em;
	font-weight: 500;
	line-height: 1.4;
	text-transform: var(--cg-btn-transform);
	cursor: pointer;
	transition: border-color 0.15s ease, background 0.15s ease;
}
#consentinel-root .cg-btn:hover { border-color: var(--cg-accent); }
#consentinel-root .cg-btn--primary {
	background: var(--cg-accent);
	color: var(--cg-accent-fg, #fff); /* auto-contrast so the label stays legible on a light accent */
	border-color: var(--cg-accent);
}
#consentinel-root .cg-btn--ghost { background: transparent; }
#consentinel-root .cg-link {
	color: var(--cg-accent);
	cursor: pointer;
	text-decoration: underline;
}
#consentinel-root button.cg-link { text-decoration: none; }

/* --- Preferences modal --- */
#consentinel-root .cg-prefs {
	position: fixed;
	inset: 0;
	background: rgba(15,20,28,0.55);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	z-index: 1000000;
	pointer-events: auto; /* re-enable: root sets pointer-events:none */
}
/* The modal is shown/hidden via its `hidden` attribute (showPrefs() in
   banner.js). `display:flex` above would otherwise beat the attribute — so the
   modal would show on every fresh load (when show() reveals the root) and could
   never be closed. Restore the attribute's effect, same as #consentinel-root[hidden]. */
#consentinel-root .cg-prefs[hidden] { display: none; }
#consentinel-root .cg-prefs__inner {
	background: var(--cg-bg);
	border-radius: var(--cg-radius);
	max-width: 560px;
	width: 100%;
	max-height: 90vh;
	display: flex;
	flex-direction: column;
	overflow: hidden; /* clip the full-bleed brand strip to the rounded corners */
}

/* "Powered by Consentinel" branding strip (banner + preferences modal). */
#consentinel-root .cg-brandbar {
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 8px 20px;
	background: #eef4fb;
	border-radius: 8px 8px 0 0;
}
#consentinel-root .cg-brandbar__link { display: inline-flex; align-items: center; opacity: 0.85; transition: opacity 0.15s ease; }
#consentinel-root .cg-brandbar__link:hover,
#consentinel-root .cg-brandbar__link:focus { opacity: 1; }
#consentinel-root .cg-brandbar__logo { height: 18px; width: auto; display: block; }
/* Banner: full-bleed across the banner's own padding (16px 20px). */
#consentinel-root .cg-banner .cg-brandbar { flex: 0 0 100%; margin: 0 0 -16px; }

#consentinel-root .cg-prefs__head,
#consentinel-root .cg-prefs__foot {
	padding: 16px 20px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	border-bottom: 1px solid var(--cg-border);
}
#consentinel-root .cg-prefs__foot {
	border-top: 1px solid var(--cg-border);
	border-bottom: 0;
	gap: 8px;
	justify-content: flex-end;
}
#consentinel-root .cg-prefs__title {
	display: block;
	font-size: calc(var(--cg-title-size) + 4px);
	line-height: 1.2;
	font-weight: 600;
}
#consentinel-root .cg-iconbtn {
	font-size: 2em;
	line-height: 1;
	cursor: pointer;
	color: var(--cg-bg-fg, var(--cg-muted));
	border-radius: 999px;
	width: 35px;
	height: 35px;
	display: flex;
	align-items: center;
	justify-content: center;
	align-self: flex-start;
}
#consentinel-root .cg-prefs__body { padding: 8px 20px 20px; overflow: auto; }

#consentinel-root .cg-category {
	display: flex; align-items: flex-start; justify-content: space-between;
	gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--cg-border);
}
#consentinel-root .cg-category:last-of-type { border-bottom: 0; }
#consentinel-root .cg-category__label { flex: 1; }
/* Auto-contrast against the banner/modal background so the muted description
   stays legible on a dark background (falls back to --cg-muted). */
#consentinel-root .cg-category__desc {
	display: block;
	color: var(--cg-bg-fg, var(--cg-muted));
	opacity: 0.75;
	font-size: 13px;
	margin-top: 2px;
}

#consentinel-root .cg-switch { position: relative; width: 40px; height: 22px; flex: 0 0 40px; }
#consentinel-root .cg-switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
#consentinel-root .cg-switch__slider {
	position: absolute; inset: 0;
	background: #c8ccd2;
	border-radius: 999px;
	transition: background 120ms ease;
	pointer-events: none;
}
#consentinel-root .cg-switch__slider::before {
	content: '';
	position: absolute;
	top: 2px; left: 2px;
	width: 18px; height: 18px;
	/* Knob rides the accent-colored "on" track, so it takes the accent's
	   contrast color — stays visible even for a light/white accent. */
	background: var(--cg-accent-fg, #fff);
	border-radius: 50%;
	transition: transform 120ms ease;
}
#consentinel-root .cg-switch input:checked ~ .cg-switch__slider { background: var(--cg-accent); }
#consentinel-root .cg-switch input:checked ~ .cg-switch__slider::before { transform: translateX(18px); }
#consentinel-root .cg-switch input:disabled ~ .cg-switch__slider { opacity: 0.6; }

#consentinel-root .cg-detected { margin-top: 16px; }
/* Detected-tracker detail is collapsed behind a disclosure (paintDetected()
   renders <details class="cg-detected__acc">) so the modal stays short on mobile.
   Scoped + id so theme <summary>/<details> styling can't leak in. */
#consentinel-root .cg-detected__summary {
	list-style: none; /* remove default disclosure triangle (Firefox) */
	cursor: pointer;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 12px;
	font-size: 13px;
	font-weight: 600;
	color: var(--cg-bg-fg, var(--cg-muted));
	background: rgba(127,127,127,0.10);
	border-radius: var(--cg-btn-radius);
}
#consentinel-root .cg-detected__summary::-webkit-details-marker { display: none; } /* remove default triangle (WebKit) */
#consentinel-root .cg-detected__summary::before {
	content: '';
	flex: 0 0 auto;
	width: 7px; height: 7px;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(-45deg);            /* points right when closed */
	transition: transform 0.15s ease;
	opacity: 0.8;
}
#consentinel-root .cg-detected__acc[open] .cg-detected__summary::before { transform: rotate(45deg); } /* points down when open */
#consentinel-root .cg-detected__list { padding: 4px 2px 2px; }
#consentinel-root .cg-detected__group { margin-top: 12px; }
/* Group heading is a <span> (not <h4>) so theme heading rules can't touch it. */
#consentinel-root .cg-detected__title {
	display: block; margin: 0 0 4px;
	font-size: 13px; text-transform: uppercase;
	color: var(--cg-bg-fg, var(--cg-muted)); opacity: 0.75;
}
#consentinel-root .cg-detected__group ul { margin: 0; padding-left: 0; list-style-type: none; }
#consentinel-root .cg-detected__group li { margin-bottom: 6px; font-size: 13px; }
#consentinel-root .cg-detected__data { color: var(--cg-bg-fg, var(--cg-muted)); opacity: 0.75; }

@media (max-width: 600px) {
	#consentinel-root .cg-banner { flex-direction: column; align-items: stretch; }
	#consentinel-root .cg-actions { justify-content: stretch; }
	#consentinel-root .cg-btn { flex: 1; }
	#consentinel-root .cg-body { flex: 1 1 auto; }
}

/* ============================================================================
   Floating launcher — reopens the preferences modal (the `reopen` action).
   Rendered OUTSIDE #consentinel-root, so scoped under its own id. It carries the
   banner's CSS vars inline so its accent/contrast colors track the theme. Hidden
   while the banner or modal is open (html.cg-open, toggled by show()).
   ============================================================================ */
#consentinel-fab {
	position: fixed;
	left: 20px;
	bottom: 20px;
	z-index: 999998; /* below the root (999999) and modal (1000000); hidden while they're open anyway */
	width: 52px;
	height: 52px;
	border-radius: 50%;
	background: var(--cg-accent);
	box-shadow: 0 4px 14px rgba(0,0,0,0.25);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#consentinel-fab:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.30); }
#consentinel-fab:focus-visible { outline: 2px solid var(--cg-accent); outline-offset: 3px; }
#consentinel-fab .cg-fab__icon {
	display: block;
	width: 26px;
	height: 26px;
	background-color: var(--cg-accent-fg, #fff);
	-webkit-mask: url(../img/cookie.svg) no-repeat center / contain;
	        mask: url(../img/cookie.svg) no-repeat center / contain;
}
.cg-open #consentinel-fab { display: none; } /* banner or modal open → hide the launcher */

@media (max-width: 600px) {
	#consentinel-fab { width: 46px; height: 46px; left: 14px; bottom: 14px; }
	#consentinel-fab .cg-fab__icon { width: 23px; height: 23px; }
}
