/**
 * web51net Cookie Manager – Banner styles
 * Philosophy: light, fluid, non-invasive.
 */

/* ─── Design tokens ─────────────────────────────────────────────────────── */
:root {
	--w51cm-primary:          #1a73e8;
	--w51cm-bg:               #ffffff;
	--w51cm-text:             #1f1f1f;
	--w51cm-overlay:          rgba(0, 0, 0, 0); /* always transparent — no dimming */
	--w51cm-radius:           12px;
	--w51cm-shadow:           0 8px 32px rgba(0, 0, 0, 0.18);
	--w51cm-z:                2147483000;
	--w51cm-banner-max-width: 960px;
	/* private – not overridden by admin inline style */
	--w51cm-text-muted:   #666;
	--w51cm-border:       rgba(0, 0, 0, 0.08);
	--w51cm-toggle-off:   #c8d0da;
	--w51cm-toggle-thumb: #ffffff;
}

/* ─── Dark mode ──────────────────────────────────────────────────────────
   Scoped to banner elements: admin :root colors stay intact for the page,
   the banner itself auto-adapts to the OS colour scheme.               */
@media (prefers-color-scheme: dark) {
	.w51cm-banner,
	.w51cm-manage-btn {
		--w51cm-bg:           #1e1e2e;
		--w51cm-text:         #e8e8f4;
		--w51cm-text-muted:   #9ca3af;
		--w51cm-border:       rgba(255, 255, 255, 0.09);
		--w51cm-toggle-off:   #4b5563;
		--w51cm-toggle-thumb: #f9fafb;
		--w51cm-shadow:       0 8px 32px rgba(0, 0, 0, 0.55);
	}
}

/* ─── Utility ────────────────────────────────────────────────────────────── */
.w51cm-hidden { display: none !important; }

/* ─── Stack & overlay ────────────────────────────────────────────────────── */
.w51cm-stack {
	position: fixed;
	inset: 0;
	z-index: var(--w51cm-z);
	pointer-events: none;
}

.w51cm-overlay {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.18);
	z-index: 0;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.55s ease;
}

.w51cm-overlay--visible {
	opacity: 1;
}

/* ─── Banner shell ───────────────────────────────────────────────────────── */
.w51cm-banner {
	position: fixed;
	z-index: 1;
	padding: 16px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
	font-size: 14px;
	line-height: 1.5;
	color: var(--w51cm-text);
	pointer-events: none;
	box-sizing: border-box;
	transform: translateY(0);
	/* Slide-only transition — no opacity, zero "lights on/off" effect */
	transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Entry: slide in from off-screen edge when banner first appears.
   @starting-style fires on the transition from display:none → visible.
   Chrome 117+, Firefox 129+, Safari 17.5+; instant appear on older browsers. */
@starting-style {
	.w51cm-banner.w51cm-y-bottom { transform: translateY(110%); }
	.w51cm-banner.w51cm-y-top    { transform: translateY(-110%); }
}

/* Dismiss: slide back to off-screen edge */
.w51cm-banner.w51cm-y-bottom.w51cm-banner--closing { transform: translateY(110%); }
.w51cm-banner.w51cm-y-top.w51cm-banner--closing    { transform: translateY(-110%); }

/* ─── Position helpers ───────────────────────────────────────────────────── */
.w51cm-y-top    { top: 0;    bottom: auto; }
.w51cm-y-bottom { bottom: 0; top: auto; }

.w51cm-x-center { left: 0; right: 0; }

.w51cm-x-left {
	left: 0; right: auto;
	width:     min(var(--w51cm-banner-max-width), calc(100% - 32px));
	max-width: min(var(--w51cm-banner-max-width), calc(100% - 32px));
}

.w51cm-x-right {
	right: 0; left: auto;
	width:     min(var(--w51cm-banner-max-width), calc(100% - 32px));
	max-width: min(var(--w51cm-banner-max-width), calc(100% - 32px));
}

/* ─── Card ───────────────────────────────────────────────────────────────── */
.w51cm-banner__inner {
	position: relative;
	width: 100%;
	margin: 0 auto;
	background: var(--w51cm-bg);
	color: var(--w51cm-text);
	border-radius: var(--w51cm-radius);
	box-shadow: var(--w51cm-shadow);
	border: 1px solid var(--w51cm-border);
	padding: 24px;
	z-index: 1;
	box-sizing: border-box;
	pointer-events: auto;
}

.w51cm-x-center .w51cm-banner__inner { max-width: var(--w51cm-banner-max-width); }
.w51cm-x-left  .w51cm-banner__inner,
.w51cm-x-right .w51cm-banner__inner  { max-width: none; margin: 0; }

/* ─── View switching (main ↔ preferences) ───────────────────────────────── */
.w51cm-banner__main,
.w51cm-banner__preferences {
	min-width: 0;
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
	transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease;
}

.w51cm-view-hidden {
	position: absolute;
	top: 0; left: 0; right: 0;
	max-height: 0;
	overflow: hidden;
	opacity: 0;
	visibility: hidden;
	transform: translateY(8px);
	pointer-events: none;
}

/* Preferences open: flex column so "Salva" is always anchored at the bottom.
   Categories get the scrollable area; actions never scroll off screen.    */
.w51cm-banner--preferences-open .w51cm-banner__inner {
	display: flex;
	flex-direction: column;
	max-height: min(85vh, 640px);
	overflow: hidden;
}

.w51cm-banner--preferences-open .w51cm-banner__preferences {
	display: flex;
	flex-direction: column;
	min-height: 0;
	overflow: hidden;
}

.w51cm-banner--preferences-open .w51cm-categories {
	flex: 1;
	overflow-y: auto;
	min-height: 0;   /* critical: allows flex child to shrink below content height */
	max-height: none;
	/* Keep the same padding-right as base so toggle → scrollbar gap is consistent */
	padding-right: 14px;
}

.w51cm-banner--preferences-open .w51cm-banner__preferences .w51cm-banner__actions {
	flex-shrink: 0;
	padding-top: 12px;
	margin-top: 8px;
	border-top: 1px solid var(--w51cm-border);
}

/* ─── Content ────────────────────────────────────────────────────────────── */
/*
 * Explicit color on every text element: theme h2/p/label rules are "direct"
 * and beat inherited values. Explicit class selectors win over bare element
 * selectors (0-1-0 > 0-0-1), so we lock in our palette regardless of theme.
 */
.w51cm-banner__title {
	margin: 0 0 8px;
	font-size: 18px;
	font-weight: 600;
	color: var(--w51cm-text);
}

.w51cm-banner__description {
	margin: 0 0 12px;
	color: var(--w51cm-text-muted, #666);
}

.w51cm-banner__links {
	margin: 0 0 16px;
	font-size: 13px;
}

.w51cm-banner__links a {
	color: var(--w51cm-primary);
	margin-right: 16px;
	text-decoration: underline;
	text-underline-offset: 2px;
}

/* ─── Action row ─────────────────────────────────────────────────────────── */
.w51cm-banner__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	position: relative;
	z-index: 2;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.w51cm-btn {
	border: none;
	border-radius: 8px;
	padding: 10px 18px;
	min-height: 44px;
	font-size: 14px;
	font-weight: 500;
	cursor: pointer !important;
	transition:
		background-color 0.18s ease,
		border-color     0.18s ease,
		color            0.18s ease,
		box-shadow       0.18s ease,
		transform        0.12s ease,
		opacity          0.18s ease;
	pointer-events: auto !important;
	position: relative;
	z-index: 5;
	-webkit-appearance: none;
	appearance: none;
	touch-action: manipulation;
	user-select: none;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.w51cm-btn:hover {
	transform: translateY(-1px);
	box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
}

.w51cm-btn:active,
.w51cm-btn.w51cm-btn--pressed {
	transform: translateY(0) scale(0.98);
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
	transition-duration: 0.08s;
}

.w51cm-btn--primary {
	background: var(--w51cm-primary);
	color: #fff;
}

.w51cm-btn--secondary {
	background: transparent;
	color: var(--w51cm-text);
	border: 1px solid var(--w51cm-border, rgba(0, 0, 0, 0.2));
}

.w51cm-btn--secondary:hover {
	color: var(--w51cm-primary);
	border-color: var(--w51cm-primary);
	box-shadow: none;
}

.w51cm-btn--text {
	background: transparent;
	color: var(--w51cm-text);
	padding: 10px 12px;
	text-decoration: underline;
	text-underline-offset: 2px;
	box-shadow: none;
}

.w51cm-btn--text:hover {
	box-shadow: none;
	transform: none;
	opacity: 0.85;
}

.w51cm-btn--text:active,
.w51cm-btn--text.w51cm-btn--pressed {
	transform: scale(0.98);
	opacity: 0.75;
	box-shadow: none;
}

/* ─── Preferences panel ──────────────────────────────────────────────────── */
.w51cm-banner__subtitle {
	margin: 0 0 16px;
	font-size: 16px;
	color: var(--w51cm-text);
}

.w51cm-categories {
	display: flex;
	flex-direction: column;
	gap: 16px;
	margin-bottom: 16px;
	max-height: 40vh;
	overflow-y: auto;
	/* Right padding leaves room for the scrollbar thumb so it never overlaps toggles */
	padding-right: 14px;
	/* Thin, unobtrusive custom scrollbar */
	scrollbar-width: thin;
	scrollbar-color: rgba(0, 0, 0, 0.18) transparent;
}

.w51cm-categories::-webkit-scrollbar {
	width: 4px;
}

.w51cm-categories::-webkit-scrollbar-track {
	background: transparent;
	margin: 4px 0;
}

.w51cm-categories::-webkit-scrollbar-thumb {
	background: rgba(0, 0, 0, 0.18);
	border-radius: 2px;
}

@media (prefers-color-scheme: dark) {
	.w51cm-categories {
		scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
	}

	.w51cm-categories::-webkit-scrollbar-thumb {
		background: rgba(255, 255, 255, 0.22);
	}
}

.w51cm-category__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.w51cm-category__label { font-weight: 600; color: var(--w51cm-text); }

.w51cm-category__required {
	display: block;
	font-size: 12px;
	font-weight: 400;
	color: var(--w51cm-text-muted, #666);
}

.w51cm-category__desc {
	margin: 4px 0 0;
	font-size: 13px;
	color: var(--w51cm-text-muted, #555);
}

/* ─── Custom toggle switch ───────────────────────────────────────────────── */
/* CSS-only pill toggle using appearance:none + ::after (no JS required).    */
.w51cm-toggle {
	flex-shrink: 0;
	width: 44px;
	height: 24px;
	background: var(--w51cm-toggle-off, #c8d0da);
	border-radius: 12px;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	position: relative;
	margin: 0;
	outline-offset: 3px;
	transition: background 0.2s ease;
}

/* Thumb */
.w51cm-toggle::after {
	content: '';
	position: absolute;
	width: 18px;
	height: 18px;
	background: var(--w51cm-toggle-thumb, #fff);
	border-radius: 50%;
	top: 3px;
	left: 3px;
	/* Elastic spring feel on toggle */
	transition: left 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
}

.w51cm-toggle:checked          { background: var(--w51cm-primary); }
.w51cm-toggle:checked::after   { left: 23px; }

.w51cm-toggle:disabled         { opacity: 0.55; cursor: not-allowed; }

.w51cm-toggle:focus-visible    { outline: 2px solid var(--w51cm-primary); }

/* ─── Manage cookies button ──────────────────────────────────────────────── */
.w51cm-manage-btn {
	position: fixed;
	bottom: 10px;
	left: 10px;
	z-index: var(--w51cm-z);
	pointer-events: auto;
	background: var(--w51cm-bg);
	color: var(--w51cm-text);
	border: 1px solid rgba(0, 0, 0, 0.15);
	border-radius: 20px;
	padding: 6px 12px;
	font-size: 12px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	line-height: 1.3;
	cursor: pointer;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
	transition:
		background-color 0.18s ease,
		box-shadow       0.18s ease,
		transform        0.18s ease,
		opacity          0.22s ease,
		visibility       0.22s ease;
	touch-action: manipulation;
	user-select: none;
}

.w51cm-manage-btn:hover {
	transform: translateY(-1px);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.w51cm-manage-btn:active { transform: translateY(0) scale(0.98); }

.w51cm-manage-btn--scroll-gated {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: translateY(8px);
}

.w51cm-manage-btn--scroll-gated.w51cm-manage-btn--visible {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: translateY(0);
}

.w51cm-manage-btn--scroll-gated.w51cm-manage-btn--visible:hover {
	transform: translateY(-1px);
}

/* ─── Cookie table (shortcode) ───────────────────────────────────────────── */
.w51cm-cookie-table {
	width: 100%;
	border-collapse: collapse;
	margin: 0;
	font-size: 14px;
}

.w51cm-cookie-table th,
.w51cm-cookie-table td {
	border: 1px solid #ddd;
	padding: 8px 12px;
	text-align: left;
}

.w51cm-cookie-table th { background: #f5f5f5; }

/* ─── Mobile ─────────────────────────────────────────────────────────────── */
/* The banner is a floating card — it never covers the entire screen.        */
@media (max-width: 600px) {
	.w51cm-banner {
		--w51cm-mobile-gutter: 12px;
		left:      var(--w51cm-mobile-gutter) !important;
		right:     var(--w51cm-mobile-gutter) !important;
		width:     auto !important;
		max-width: none !important;
		padding:   0 !important;
	}

	.w51cm-y-top {
		top: var(--w51cm-mobile-gutter);
		padding-top: env(safe-area-inset-top, 0px);
	}

	.w51cm-y-bottom {
		bottom: var(--w51cm-mobile-gutter);
		padding-bottom: env(safe-area-inset-bottom, 0px);
	}

	/* Cap the main banner at ~50 % viewport so page content is visible behind */
	.w51cm-banner__inner {
		width: 100%;
		max-width: none;
		margin: 0;
		max-height: min(52dvh, 400px);
		overflow-y: auto;
		-webkit-overflow-scrolling: touch;
		padding: 16px;
		border-radius: var(--w51cm-radius);
		box-shadow: var(--w51cm-shadow);
	}

	/* Preferences: more room; flex layout keeps Salva anchored at bottom */
	.w51cm-banner--preferences-open .w51cm-banner__inner {
		max-height: min(72dvh, 520px);
	}

	.w51cm-x-left  .w51cm-banner__inner,
	.w51cm-x-right .w51cm-banner__inner {
		max-width: var(--w51cm-banner-max-width);
		max-height: min(55dvh, 420px);
	}

	.w51cm-banner__title       { font-size: 16px; }
	.w51cm-banner__description { font-size: 13px;  margin-bottom: 10px; }
	.w51cm-banner__links       { margin-bottom: 12px; }

	.w51cm-banner__actions {
		display: grid;
		grid-template-columns: 1fr 1fr;
		gap: 8px;
	}

	.w51cm-banner__actions .w51cm-btn--text { grid-column: 1 / -1; }

	.w51cm-banner .w51cm-btn {
		width: 100%;
		text-align: center;
		min-height: 40px;
		padding: 8px 12px;
		font-size: 13px;
	}

	.w51cm-manage-btn {
		bottom: 8px;
		left: 8px;
		padding: 6px 12px;
		min-height: 36px;
		font-size: 12px;
		line-height: 1.3;
		box-sizing: border-box;
		max-width: calc(100% - 16px);
	}
}

/* Firefox mobile: safe-area padding on the bottom banner can jump on scroll */
@supports (-moz-appearance: none) {
	@media (max-width: 600px) {
		.w51cm-y-bottom { padding-bottom: 0; }
	}
}
