/*
 * Codigi QA Forum — Reddit-minimal, host-aware design system.
 * ───────────────────────────────────────────────────────────
 * The forum reads its palette and typography from the HOST THEME first (via the
 * WordPress block-theme preset custom properties `--wp--preset--*`) and only
 * falls back to neutral defaults when the theme exposes nothing. Every derived
 * surface/border/muted tone is computed from the resolved text/background with
 * color-mix(), so the forum auto-adapts to light OR dark host themes without any
 * per-site configuration ("generata in automatico e in linea col sito ospitante").
 *
 * Everything remains overridable via the `clc_qa_forum_custom_css` option
 * (loaded AFTER this file) or by redefining the tokens on `.clc-qa-forum`.
 */

.clc-qa-forum {
	/* Inherit host typography; fall back through common preset keys, then font stack. */
	--clc-font: var(--wp--preset--font-family--body,
		var(--wp--preset--font-family--base,
		var(--wp--preset--font-family--system-font,
		-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif)));

	/* Base colors: follow the host theme, fall back to neutral light. */
	--clc-bg:   var(--wp--preset--color--background, #ffffff);
	--clc-text: var(--wp--preset--color--foreground, var(--wp--preset--color--contrast, #1a1a1b));

	/* Accent: follow the host brand/primary, fall back to a modern blue. */
	--clc-brand: var(--wp--preset--color--primary,
		var(--wp--preset--color--accent,
		var(--wp--preset--color--vivid-cyan-blue, #2563eb)));
	--clc-brand-contrast: #ffffff;

	/* Derived tones — computed from the resolved text/bg so they track the theme. */
	--clc-surface:    color-mix(in srgb, var(--clc-text) 4%,  var(--clc-bg));
	--clc-surface-2:  color-mix(in srgb, var(--clc-text) 8%,  var(--clc-bg));
	--clc-border:     color-mix(in srgb, var(--clc-text) 14%, var(--clc-bg));
	--clc-text-muted: color-mix(in srgb, var(--clc-text) 55%, var(--clc-bg));
	--clc-brand-hover: color-mix(in srgb, var(--clc-brand) 82%, #000);
	--clc-brand-soft:  color-mix(in srgb, var(--clc-brand) 12%, transparent);

	--clc-success: #1a7f56;
	--clc-danger:  #d93a3a;

	--clc-radius:      12px;
	--clc-radius-sm:   8px;
	--clc-radius-pill: 999px;
	--clc-gap: 0.75rem;

	font-family: var(--clc-font);
	font-size: 15px;
	line-height: 1.55;
	color: var(--clc-text);
	max-width: 860px;
	margin: 1.5rem auto;
	box-sizing: border-box;
}

.clc-qa-forum *,
.clc-qa-forum *::before,
.clc-qa-forum *::after {
	box-sizing: border-box;
}

/* Dark host fallback: only flips the literal defaults; derived tones follow. */
@media (prefers-color-scheme: dark) {
	.clc-qa-forum {
		--clc-bg:   var(--wp--preset--color--background, #0f1113);
		--clc-text: var(--wp--preset--color--foreground, var(--wp--preset--color--contrast, #e7e9ea));
		--clc-brand: var(--wp--preset--color--primary,
			var(--wp--preset--color--accent, #4c8dff));
	}
}

/* ─── Icons ───────────────────────────────────────────────────────────── */

.clc-qa-icon {
	flex-shrink: 0;
	vertical-align: -0.15em;
}

/* ─── Header ──────────────────────────────────────────────────────────── */

.clc-qa-header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--clc-gap);
	margin-bottom: 1rem;
	padding-bottom: 0.85rem;
	border-bottom: 1px solid var(--clc-border);
}

.clc-qa-header-titles h1,
.clc-qa-title {
	margin: 0;
	font-size: 1.5rem;
	font-weight: 700;
	line-height: 1.2;
	letter-spacing: -0.01em;
	color: var(--clc-text);
}

.clc-qa-header-titles p,
.clc-qa-subtitle {
	margin: 0.3rem 0 0;
	font-size: 0.9rem;
	color: var(--clc-text-muted);
}

.clc-qa-count {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	padding: 0.3rem 0.75rem;
	font-size: 0.8rem;
	font-weight: 600;
	color: var(--clc-text);
	background: var(--clc-surface-2);
	border-radius: var(--clc-radius-pill);
}

/* ─── Breadcrumb ──────────────────────────────────────────────────────── */

.clc-qa-breadcrumb {
	margin-bottom: 1rem;
	font-size: 0.85rem;
}

.clc-qa-breadcrumb a {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	color: var(--clc-text-muted);
	text-decoration: none;
	font-weight: 500;
}

.clc-qa-breadcrumb a:hover {
	color: var(--clc-brand);
}

/* ─── Question feed (Reddit-style cards) ──────────────────────────────── */

.clc-qa-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	counter-reset: none;
}

.clc-qa-card {
	display: flex;
	align-items: stretch;
	gap: 0.9rem;
	padding: 0.85rem 1rem 0.85rem 0.75rem;
	background: var(--clc-bg);
	border: 1px solid var(--clc-border);
	border-radius: var(--clc-radius);
	transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.clc-qa-card:hover {
	border-color: color-mix(in srgb, var(--clc-brand) 45%, var(--clc-border));
	box-shadow: 0 1px 0 var(--clc-border), 0 6px 18px color-mix(in srgb, var(--clc-text) 8%, transparent);
}

/* Left vote/score rail */
.clc-qa-rail {
	flex-shrink: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
	gap: 0.1rem;
	width: 3rem;
	padding-top: 0.15rem;
	color: var(--clc-text-muted);
}

.clc-qa-rail .clc-qa-icon-arrow-up {
	width: 20px;
	height: 20px;
	color: color-mix(in srgb, var(--clc-text) 40%, var(--clc-bg));
}

.clc-qa-card:hover .clc-qa-rail .clc-qa-icon-arrow-up {
	color: var(--clc-brand);
}

.clc-qa-rail-score {
	font-size: 1rem;
	font-weight: 700;
	color: var(--clc-text);
	line-height: 1.1;
}

.clc-qa-rail-label {
	font-size: 0.62rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--clc-text-muted);
}

.clc-qa-card-main {
	min-width: 0;
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
}

.clc-qa-card-top {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.4rem;
}

.clc-qa-chip {
	display: inline-flex;
	align-items: center;
	padding: 0.1rem 0.5rem;
	font-size: 0.72rem;
	font-weight: 600;
	color: var(--clc-text);
	background: var(--clc-surface-2);
	border-radius: var(--clc-radius-pill);
}

.clc-qa-card-title {
	display: block;
	font-size: 1.08rem;
	font-weight: 600;
	line-height: 1.35;
	color: var(--clc-text);
	text-decoration: none;
}

.clc-qa-card-title:hover {
	color: var(--clc-brand);
}

.clc-qa-card-meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.35rem;
	font-size: 0.8rem;
	color: var(--clc-text-muted);
}

.clc-qa-card-meta .clc-qa-meta-item {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	color: inherit;
}

.clc-qa-author-inline {
	font-style: normal;
	font-weight: 600;
	color: var(--clc-text);
}

.clc-qa-meta-dot {
	color: var(--clc-text-muted);
	opacity: 0.6;
}

.clc-qa-comments-link {
	text-decoration: none;
	color: var(--clc-text-muted);
}

.clc-qa-comments-link:hover {
	color: var(--clc-brand);
}

/* ─── Badges ──────────────────────────────────────────────────────────── */

.clc-qa-badge {
	display: inline-flex;
	align-items: center;
	padding: 0.1rem 0.5rem;
	font-size: 0.68rem;
	font-weight: 700;
	border-radius: var(--clc-radius-pill);
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

.clc-qa-badge-human {
	color: var(--clc-success);
	background: color-mix(in srgb, var(--clc-success) 14%, transparent);
}

.clc-qa-badge-ai {
	color: var(--clc-brand);
	background: var(--clc-brand-soft);
}

/* ─── Empty state ─────────────────────────────────────────────────────── */

.clc-qa-empty {
	padding: 2.25rem 1.5rem;
	text-align: center;
	color: var(--clc-text-muted);
	background: var(--clc-surface);
	border: 1px dashed var(--clc-border);
	border-radius: var(--clc-radius);
}

/* ─── Single thread ───────────────────────────────────────────────────── */

.clc-qa-single {
	margin-top: 1.5rem;
}

.clc-qa-answers-title {
	display: flex;
	align-items: center;
	gap: 0.45rem;
	margin: 0 0 1rem;
	font-size: 1.15rem;
	font-weight: 700;
	color: var(--clc-text);
}

.clc-qa-answers {
	list-style: none;
	margin: 0 0 1.75rem;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
}

.clc-qa-answer {
	padding: 0.9rem 1rem;
	background: var(--clc-surface);
	border: 1px solid var(--clc-border);
	border-radius: var(--clc-radius);
}

.clc-qa-answer-head {
	display: flex;
	align-items: center;
	gap: 0.55rem;
	margin-bottom: 0.55rem;
	font-size: 0.82rem;
}

.clc-qa-avatar {
	border-radius: 50%;
	width: 34px;
	height: 34px;
	object-fit: cover;
	flex-shrink: 0;
	background: var(--clc-surface-2);
}

.clc-qa-avatar-fallback {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	flex-shrink: 0;
	font-weight: 700;
	font-size: 0.9rem;
	color: var(--clc-brand-contrast);
	background: var(--clc-brand);
}

.clc-qa-author {
	font-style: normal;
	font-weight: 600;
	color: var(--clc-text);
}

.clc-qa-date {
	color: var(--clc-text-muted);
}

.clc-qa-answer-head .clc-qa-badge {
	margin-left: auto;
}

.clc-qa-answer-body {
	line-height: 1.65;
	color: var(--clc-text);
}

.clc-qa-answer-body p:last-child {
	margin-bottom: 0;
}

.clc-qa-internal-link {
	color: var(--clc-brand);
	text-decoration: underline;
}

/* ─── Forms ───────────────────────────────────────────────────────────── */

.clc-qa-form {
	margin: 1.25rem 0 0;
	padding: 1.25rem;
	background: var(--clc-bg);
	border: 1px solid var(--clc-border);
	border-radius: var(--clc-radius);
}

.clc-qa-form h3 {
	margin: 0 0 0.9rem;
	font-size: 1.1rem;
	font-weight: 700;
	color: var(--clc-text);
}

.clc-qa-form p {
	margin: 0 0 0.8rem;
}

.clc-qa-form label {
	display: block;
	margin-bottom: 0.3rem;
	font-size: 0.82rem;
	font-weight: 600;
	color: var(--clc-text-muted);
}

.clc-qa-form input[type="text"],
.clc-qa-form input[type="email"],
.clc-qa-form textarea {
	width: 100%;
	padding: 0.6rem 0.75rem;
	font-family: var(--clc-font);
	font-size: 0.95rem;
	color: var(--clc-text);
	background: var(--clc-surface);
	border: 1px solid var(--clc-border);
	border-radius: var(--clc-radius-sm);
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.clc-qa-form input[type="text"]:focus,
.clc-qa-form input[type="email"]:focus,
.clc-qa-form textarea:focus {
	outline: none;
	border-color: var(--clc-brand);
	box-shadow: 0 0 0 3px var(--clc-brand-soft);
	background: var(--clc-bg);
}

.clc-qa-form textarea {
	resize: vertical;
	min-height: 92px;
}

.clc-qa-form button {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	font-family: var(--clc-font);
	font-size: 0.92rem;
	font-weight: 600;
	cursor: pointer;
	padding: 0.62rem 1.3rem;
	color: var(--clc-brand-contrast);
	background: var(--clc-brand);
	border: none;
	border-radius: var(--clc-radius-pill);
	transition: background 0.15s ease, opacity 0.15s ease;
}

.clc-qa-form button:hover {
	background: var(--clc-brand-hover);
}

.clc-qa-form button:disabled,
.clc-qa-form[aria-busy="true"] button {
	opacity: 0.65;
	cursor: not-allowed;
}

/* ─── CTA button ──────────────────────────────────────────────────────── */

.clc-qa-cta {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	margin-top: 1.25rem;
	font-size: 0.92rem;
	font-weight: 600;
	color: var(--clc-brand);
	background: transparent;
	border: 1px solid var(--clc-brand);
	border-radius: var(--clc-radius-pill);
	padding: 0.55rem 1.15rem;
	cursor: pointer;
	text-decoration: none;
	transition: background 0.15s ease, color 0.15s ease;
}

.clc-qa-cta:hover {
	background: var(--clc-brand);
	color: var(--clc-brand-contrast);
}

/* ─── Captcha & status ────────────────────────────────────────────────── */

.clc-qa-captcha {
	margin: 0.75rem 0;
}

.clc-qa-msg {
	margin: 0.75rem 0 0;
	font-size: 0.88rem;
	font-weight: 500;
	color: var(--clc-text-muted);
	min-height: 1.2em;
}

.clc-qa-msg.is-error {
	color: var(--clc-danger);
}

.clc-qa-msg.is-success {
	color: var(--clc-success);
}

/* ─── Spinner ─────────────────────────────────────────────────────────── */

.clc-qa-spinner {
	display: inline-block;
	width: 1em;
	height: 1em;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	animation: clc-qa-spin 0.6s linear infinite;
	vertical-align: -0.15em;
}

@keyframes clc-qa-spin {
	to { transform: rotate(360deg); }
}

/* ─── Responsive ──────────────────────────────────────────────────────── */

@media (max-width: 600px) {
	.clc-qa-forum {
		margin: 1rem 0;
	}

	.clc-qa-header {
		flex-direction: column;
		align-items: flex-start;
	}

	.clc-qa-rail {
		width: 2.4rem;
	}

	.clc-qa-card-title {
		font-size: 1.02rem;
	}

	.clc-qa-form {
		padding: 1rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.clc-qa-card,
	.clc-qa-form input,
	.clc-qa-form textarea,
	.clc-qa-form button {
		transition: none;
	}

	.clc-qa-spinner {
		animation-duration: 1.2s;
	}
}
