/**
 * VPS Consent — frontend styles
 *
 * Design targets:
 *  - WCAG 2.1 Level AA colour contrast throughout.
 *  - Accessible focus indicators (WCAG SC 1.4.11, 3:1 non-text contrast).
 *  - prefers-reduced-motion: removes transitions and slide animations.
 *  - Mobile-first responsive layout.
 *  - No colour used as the sole differentiator between Accept and Reject.
 */

/* ── Reset ──────────────────────────────────────────────────────────────── */

.vps-consent-banner *,
.vps-consent-modal *,
.vps-consent-overlay,
.vps-consent-reopen {
	box-sizing: border-box;
}

/* ── Tokens ─────────────────────────────────────────────────────────────── */

:root {
	/* Mapped to the serp-shop "NoeraSkin" dark theme (theme assets/css/tokens.css,
	   compiled to :root,:host in dist/css/tailwind.min.css). Each token references
	   the live theme custom property with a hex fallback, so the consent UI tracks
	   the theme automatically yet still renders correctly if the plugin is used in
	   a project that does not define these variables.

	   The legacy --vps-gray-* / --vps-white names are preserved so the component
	   rules below need no rename — only their values change. On this dark palette
	   the "gray" scale runs dark→light:
	     gray-50/100  = nested dark surfaces
	     gray-200     = hairline borders
	     gray-500     = muted text
	     gray-700     = body text
	     gray-900     = headings (near-white) */
	--vps-white:        #ffffff;  /* text on filled accent buttons only */

	/* Surfaces (elevated above the page background) */
	--vps-surface:      var(--color-bg-overlay,  #1E1C1A);  /* banner, modal, reopen pill */
	--vps-surface-2:    var(--color-bg-alt,      #181714);  /* hover / table header */
	--vps-gray-50:      var(--color-bg-deepest,  #0D0C0B);  /* deepest nested surface (cookie table) */
	--vps-gray-100:     var(--color-bg-alt,      #181714);  /* table header, close-button hover */

	/* Borders */
	--vps-gray-200:        var(--color-border,           rgba(242, 237, 228, 0.07));
	--vps-border-strong:   var(--color-hairline-strong,  rgba(242, 237, 228, 0.14));

	/* Text */
	--vps-gray-500:     var(--color-text-light,  #7A7068);  /* descriptions, legal basis, icons */
	--vps-gray-700:     var(--color-text-main,   #B5A898);  /* body copy */
	--vps-gray-900:     var(--color-secondary,   #F2EDE4);  /* titles / headings */

	/* Brand */
	--vps-primary:      var(--color-primary,        #BFA46F);  /* gold — Reject action, toggles, focus, links */
	--vps-primary-dark: var(--color-primary-dark,   #D4B87A);
	--vps-on-primary:   var(--color-bg-deepest,     #0D0C0B);  /* dark text on gold (matches theme .scroll-top) */
	--vps-accent:       var(--color-accent,         #C8593F);  /* terracotta — primary CTA (Accept / Save) */
	--vps-accent-hover: var(--color-accent-hover,   #A8472F);
	--vps-success:      var(--color-success,        #38A169);  /* "Always active" label */

	--vps-radius:       var(--radius-DEFAULT, 16px);   /* cards / modal / banner corners */
	--vps-radius-sm:    var(--radius-sm,       8px);
	--vps-btn-radius:   4px;       /* theme .btn (rounded-sm) */

	--vps-shadow:       var(--shadow-lg, 0 10px 30px rgba(0, 0, 0, 0.4));
	--vps-shadow-sm:    var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2));
	--vps-shadow-md:    var(--shadow-md, 0 4px 12px rgba(0, 0, 0, 0.35));

	--vps-transition:   0.2s ease;

	--vps-z-banner:     9998;
	--vps-z-overlay:    9999;
	--vps-z-modal:      10000;
	--vps-z-reopen:     9997;
}

/* ── Screen-reader only ─────────────────────────────────────────────────── */

.vps-consent-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ── Banner ─────────────────────────────────────────────────────────────── */

.vps-consent-banner {
	position: fixed;
	z-index: var(--vps-z-banner);
	background: var(--vps-surface);
	box-shadow: var(--vps-shadow);
	font-family: inherit;
	font-size: 14px;
	line-height: 1.5;
	color: var(--vps-gray-900);
}

.vps-consent-banner--hidden {
	display: none;
}

.vps-consent-banner--bottom-bar {
	bottom: 0;
	left: 0;
	right: 0;
	border-top: 1px solid var(--vps-gray-200);
}

.vps-consent-banner--bottom-left {
	bottom: 16px;
	left: 16px;
	width: 100%;
	max-width: 400px;
	border-radius: var(--vps-radius);
	border: 1px solid var(--vps-gray-200);
}

.vps-consent-banner--bottom-right {
	bottom: 16px;
	right: 16px;
	width: 100%;
	max-width: 400px;
	border-radius: var(--vps-radius);
	border: 1px solid var(--vps-gray-200);
}

.vps-consent-banner--center-modal {
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 90%;
	max-width: 540px;
	border-radius: var(--vps-radius);
	border: 1px solid var(--vps-gray-200);
}

.vps-consent-banner__inner {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
	padding: 16px 20px;
	max-width: 1280px;
	margin: 0 auto;
}

.vps-consent-banner__body {
	flex: 1;
	min-width: 0;
}

.vps-consent-banner__title {
	margin: 0 0 4px;
	font-size: 0.95rem;
	font-weight: 700;
	color: var(--vps-gray-900);
}

.vps-consent-banner__text {
	margin: 0;
	color: var(--vps-gray-700);
}

.vps-consent-banner__policy-link {
	margin-left: 4px;
	color: var(--vps-primary);
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

.vps-consent-banner__policy-link:hover,
.vps-consent-banner__policy-link:focus {
	text-decoration: none;
}

.vps-consent-banner__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: center;
	flex-shrink: 0;
}

/*
 * Banner buttons carry their own variant colours (see Buttons below): Accept =
 * orange CTA, Reject = teal action, Manage = outline. The previous blanket
 * flattening override has been removed so the branded variants render.
 */

/* ── Buttons ─────────────────────────────────────────────────────────────── */

/*
 * Buttons match the serp-shop button system (theme assets/css/components.css):
 * 44px min-height, 4px radius, 1px border, 600 weight, .9375rem. border-box
 * sizing (set in the reset) keeps all variants identical regardless of border.
 *
 * Visual hierarchy / GDPR balance: Accept (orange) and Reject (teal) are both
 * filled and equal weight — colour is never the sole differentiator and neither
 * choice is visually suppressed. Manage is a de-emphasised outline (it opens
 * options rather than recording a decision).
 */
.vps-consent-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 0.75rem 1.25rem;
	border: 1px solid transparent;
	border-radius: var(--vps-btn-radius);
	font-family: inherit;
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
	white-space: nowrap;
	text-decoration: none;
	-webkit-appearance: none;
	transition: background var(--vps-transition), color var(--vps-transition), border-color var(--vps-transition), transform var(--vps-transition), box-shadow var(--vps-transition);
}

/* Accept / Save — primary CTA, theme accent (orange). Matches .btn--primary. */
.vps-consent-btn--accept {
	background: var(--vps-accent);
	color: var(--vps-white);
	border-color: var(--vps-accent);
}
.vps-consent-btn--accept:hover {
	background: var(--vps-accent-hover);
	border-color: var(--vps-accent-hover);
	transform: translateY(-1px);
	box-shadow: var(--vps-shadow-md);
}

/* Reject — secondary action, theme primary (gold). Matches .btn--secondary.
   Dark text on gold (var(--vps-on-primary)) — the theme uses this same
   dark-on-gold pairing for .scroll-top, and it clears AA contrast where
   white-on-gold would not. */
.vps-consent-btn--reject {
	background: var(--vps-primary);
	color: var(--vps-on-primary);
	border-color: var(--vps-primary);
}
.vps-consent-btn--reject:hover {
	background: var(--vps-primary-dark);
	border-color: var(--vps-primary-dark);
}

/* Secondary — modal "Accept all" shortcut. Gold, equal weight to Reject all. */
.vps-consent-btn--secondary {
	background: var(--vps-primary);
	color: var(--vps-on-primary);
	border-color: var(--vps-primary);
}
.vps-consent-btn--secondary:hover {
	background: var(--vps-primary-dark);
	border-color: var(--vps-primary-dark);
}

/* Manage — de-emphasised outline on the dark surface. Matches .btn--outline. */
.vps-consent-btn--manage {
	background: transparent;
	color: var(--vps-gray-700);
	border-color: var(--vps-border-strong);
}
.vps-consent-btn--manage:hover {
	background: transparent;
	border-color: var(--vps-primary);
	color: var(--vps-primary);
}

/*
 * Focus indicator is keyboard-only. The banner auto-focuses "Accept all" on open
 * (consent.js showBanner); browsers do not apply :focus-visible to that
 * programmatic focus for pointer users, so the CTA stays a clean solid button on
 * load. Plain :focus is suppressed for mouse / programmatic focus; :focus-visible
 * restores the gold ring for keyboard users on every button — including the
 * primary CTA, which must keep a visible focus state (WCAG 2.4.7).
 */
.vps-consent-btn:focus {
	outline: none;
}

.vps-consent-btn:focus-visible {
	outline: 3px solid var(--vps-primary);
	outline-offset: 2px;
}

/* ── Overlay ─────────────────────────────────────────────────────────────── */

.vps-consent-overlay {
	display: none;
	position: fixed;
	inset: 0;
	z-index: var(--vps-z-overlay);
	background: rgba(0, 0, 0, 0.6);
}

.vps-consent-overlay--visible {
	display: block;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */

.vps-consent-modal {
	display: none;
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	z-index: var(--vps-z-modal);
	width: 90%;
	max-width: 640px;
	max-height: 90vh;
	background: var(--vps-surface);
	border: 1px solid var(--vps-gray-200);
	border-radius: var(--vps-radius);
	box-shadow: var(--vps-shadow);
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
}

.vps-consent-modal--open {
	display: block;
}

.vps-consent-no-scroll {
	overflow: hidden;
}

.vps-consent-modal__inner {
	padding: 24px;
}

.vps-consent-modal__header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 16px;
}

.vps-consent-modal__title {
	font-size: 18px;
	font-weight: 700;
	margin: 0;
	color: var(--vps-gray-900);
}

.vps-consent-modal__close {
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	background: none;
	border: 2px solid transparent;
	border-radius: var(--vps-radius-sm);
	cursor: pointer;
	color: var(--vps-gray-500);
	padding: 0;
	transition: color var(--vps-transition), background var(--vps-transition);
}

.vps-consent-modal__close:hover {
	color: var(--vps-gray-900);
	background: var(--vps-gray-100);
}

.vps-consent-modal__close:focus-visible {
	outline: 3px solid var(--vps-primary);
	outline-offset: 2px;
}

.vps-consent-modal__intro {
	font-size: 13px;
	color: var(--vps-gray-700);
	margin: 0 0 20px;
}

.vps-consent-modal__intro a {
	color: var(--vps-primary);
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

/* ── Category rows ───────────────────────────────────────────────────────── */

.vps-consent-modal__categories {
	display: flex;
	flex-direction: column;
	border: 1px solid var(--vps-gray-200);
	border-radius: var(--vps-radius);
	overflow: hidden;
}

.vps-consent-modal__category {
	border-bottom: 1px solid var(--vps-gray-200);
	background: transparent;
}

.vps-consent-modal__category:last-child {
	border-bottom: none;
}

.vps-consent-modal__category-header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 16px;
	padding: 16px;
}

.vps-consent-modal__category-info {
	flex: 1;
	min-width: 0;
}

.vps-consent-modal__category-title {
	font-size: 14px;
	font-weight: 600;
	margin: 0 0 4px;
	color: var(--vps-gray-900);
}

.vps-consent-modal__category-title label {
	cursor: pointer;
}

.vps-consent-modal__category-desc {
	font-size: 13px;
	color: var(--vps-gray-500);
	margin: 0 0 4px;
}

.vps-consent-modal__legal-basis {
	font-size: 11px;
	color: var(--vps-gray-500);
	margin: 0;
	font-style: italic;
}

/* ── Native checkboxes ───────────────────────────────────────────────────── */

.vps-consent-modal__toggle-wrap {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	flex-shrink: 0;
}

.vps-consent-modal__always-active {
	font-size: 11px;
	font-weight: 600;
	color: var(--vps-success);
	white-space: nowrap;
}

/*
 * Native checkbox — browser renders the control.
 * accent-color tints the checkbox fill to the theme primary when checked.
 * No appearance overrides: accessible in all contexts, including high-contrast mode.
 */
.vps-consent-toggle {
	width: 18px;
	height: 18px;
	flex-shrink: 0;
	cursor: pointer;
	accent-color: var(--vps-primary);
}

.vps-consent-toggle:disabled {
	cursor: not-allowed;
	opacity: 0.5;
}

.vps-consent-toggle:focus-visible {
	outline: 3px solid var(--vps-primary);
	outline-offset: 2px;
}

/* ── Cookie table ────────────────────────────────────────────────────────── */

.vps-consent-cookie-table-wrap {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	background: var(--vps-gray-50);
	border-top: 1px solid var(--vps-gray-200);
}

.vps-consent-cookie-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 12px;
	color: var(--vps-gray-700);
}

.vps-consent-cookie-table th {
	text-align: left;
	padding: 8px 12px;
	font-weight: 600;
	color: var(--vps-gray-900);
	background: var(--vps-gray-100);
	border-bottom: 1px solid var(--vps-gray-200);
	white-space: nowrap;
}

.vps-consent-cookie-table td {
	padding: 8px 12px;
	border-bottom: 1px solid var(--vps-gray-200);
	vertical-align: top;
}

.vps-consent-cookie-table tbody tr:last-child td {
	border-bottom: none;
}

.vps-consent-cookie-table code {
	font-size: 11px;
	color: var(--vps-gray-900);
	background: var(--vps-border-strong);
	padding: 1px 4px;
	border-radius: 3px;
	font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

/* ── Modal footer ────────────────────────────────────────────────────────── */

.vps-consent-modal__footer {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 20px;
	padding-top: 16px;
	border-top: 1px solid var(--vps-gray-200);
}

/*
 * Footer buttons use their variant colours: Save = orange CTA (--accept),
 * Accept all / Reject all = teal (--secondary / --reject), equal weight. The
 * previous blanket flattening override has been removed.
 */

/* ── Re-open button (persistent footer) ─────────────────────────────────── */

.vps-consent-reopen {
	position: fixed;
	bottom: 16px;
	left: 16px;
	z-index: var(--vps-z-reopen);
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 14px;
	background: var(--vps-surface);
	color: var(--vps-gray-700);
	border: 1px solid var(--vps-border-strong);
	border-radius: 20px;
	font-family: inherit;
	font-size: 12px;
	font-weight: 500;
	cursor: pointer;
	box-shadow: var(--vps-shadow-sm);
	transition: background var(--vps-transition), box-shadow var(--vps-transition);
}

.vps-consent-reopen:hover {
	background: var(--vps-surface-2);
	box-shadow: var(--vps-shadow);
}

.vps-consent-reopen:focus-visible {
	outline: 3px solid var(--vps-primary);
	outline-offset: 2px;
}

/* ── Reduced motion ──────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
	.vps-consent-banner,
	.vps-consent-modal,
	.vps-consent-overlay,
	.vps-consent-btn,
	.vps-consent-modal__close,
	.vps-consent-reopen {
		transition: none;
	}
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
	.vps-consent-banner__inner {
		flex-direction: column;
		align-items: stretch;
	}

	.vps-consent-banner__actions {
		flex-direction: column;
	}

	.vps-consent-btn {
		width: 100%;
		justify-content: center;
	}

	.vps-consent-modal__inner {
		padding: 16px;
	}

	.vps-consent-modal__footer {
		flex-direction: column;
	}

	.vps-consent-reopen {
		bottom: 8px;
		left: 8px;
	}

	.vps-consent-banner--bottom-left,
	.vps-consent-banner--bottom-right {
		left: 0;
		right: 0;
		bottom: 0;
		max-width: 100%;
		border-radius: 0;
	}
}
