/* AI Reason Box add-ons (disclaimer badge)
	 Loaded after fgw_style.css
*/

.ai-reason-box.has-disclaimer {
	padding-bottom: 58px;
}

.ai-reason-box > .ai-reason-box__disclaimer {
	position: absolute;
	right: 6px;
	bottom: 6px;
	z-index: 4;

	display: inline-flex;
	align-items: center;
	gap: 8px;

	max-width: min(760px, calc(100% - 16px));
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;

	-webkit-appearance: none;
	appearance: none;

	border: 1px solid rgba(245, 158, 11, 0.28);
	background: rgba(255, 251, 235, 0.92);
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	color: rgba(17, 24, 39, 0.92);
	font-size: 12px;
	line-height: 1.15;
	padding: 7px 12px;
	border-radius: 999px;

	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.65),
		0 6px 18px rgba(17, 24, 39, 0.08);

	pointer-events: none;
	cursor: default;
	user-select: none;
	transition: none;
}

.ai-reason-box > .ai-reason-box__disclaimer:focus {
	outline: none;
}

.ai-reason-box__disclaimer-text {
	font-weight: 700;
	letter-spacing: 0.01em;
	text-shadow: none;
}

.ai-reason-box__disclaimer-icon {
	width: 18px;
	height: 18px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;

	border-radius: 999px;
	font-weight: 900;
	font-size: 9px;
	line-height: 1;
	letter-spacing: 0.04em;

	color: #92400e;
	background: rgba(245, 158, 11, 0.18);
	border: 1px solid rgba(245, 158, 11, 0.28);
}

[data-theme="dark"] .ai-reason-box > .ai-reason-box__disclaimer {
	background: rgba(30, 27, 75, 0.66);
	border-color: rgba(251, 191, 36, 0.24);
	color: rgba(255, 255, 255, 0.9);
	box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
}

[data-theme="dark"] .ai-reason-box__disclaimer-icon {
	color: rgba(255, 255, 255, 0.92);
	background: rgba(251, 191, 36, 0.18);
	border-color: rgba(251, 191, 36, 0.26);
}

/* LLM reasoning progress (shown when explanation_status=pending) */
.ai-reason-progress {
	display: grid;
	gap: 10px;
	padding: 10px 10px 6px;
	border-radius: 12px;
	border: 1px solid rgba(17, 24, 39, 0.10);
	background: rgba(255, 255, 255, 0.72);
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.75),
		0 10px 24px rgba(17, 24, 39, 0.08);
}

.ai-reason-progress__title {
	font-size: 14px;
	font-weight: 800;
	color: rgba(17, 24, 39, 0.92);
}

.ai-reason-progress__track {
	position: relative;
	height: 12px;
	border-radius: 999px;
	overflow: hidden;
	background: rgba(17, 24, 39, 0.08);
	box-shadow: inset 0 1px 2px rgba(17, 24, 39, 0.10);
}

.ai-reason-progress__fill {
	position: relative;
	height: 100%;
	width: 0%;
	border-radius: 999px;
	background: linear-gradient(90deg, rgba(245, 158, 11, 0.55), rgba(245, 158, 11, 0.95));
	box-shadow: 0 6px 16px rgba(245, 158, 11, 0.18);
	transition: width 520ms cubic-bezier(0.16, 1, 0.3, 1);
	will-change: width;
}

/* Progress color follows result type */
.popup-result.safe .ai-reason-progress__fill {
	background: linear-gradient(90deg, rgba(34, 197, 94, 0.6), rgba(22, 163, 74, 0.98));
	box-shadow: 0 6px 16px rgba(34, 197, 94, 0.24);
}

.popup-result.warning .ai-reason-progress__fill {
	background: linear-gradient(90deg, rgba(245, 158, 11, 0.6), rgba(245, 158, 11, 0.98));
	box-shadow: 0 6px 16px rgba(245, 158, 11, 0.24);
}

.popup-result.danger .ai-reason-progress__fill {
	background: linear-gradient(90deg, rgba(239, 68, 68, 0.62), rgba(220, 38, 38, 0.98));
	box-shadow: 0 6px 16px rgba(239, 68, 68, 0.24);
}

/* Shimmer overlay for a subtle “alive” effect */
.ai-reason-progress__fill::after {
	content: "";
	position: absolute;
	top: 0;
	bottom: 0;
	left: -40%;
	width: 40%;
	background: linear-gradient(
		90deg,
		rgba(255, 255, 255, 0) 0%,
		rgba(255, 255, 255, 0.45) 50%,
		rgba(255, 255, 255, 0) 100%
	);
	filter: blur(0.2px);
	opacity: 0.8;
	animation: aiReasonShimmer 1.15s linear infinite;
}

@keyframes aiReasonShimmer {
	0% { transform: translateX(0); }
	100% { transform: translateX(240%); }
}

.ai-reason-progress__label {
	font-size: 12px;
	font-weight: 700;
	color: rgba(17, 24, 39, 0.72);
}

[data-theme="dark"] .ai-reason-progress {
	border-color: rgba(251, 191, 36, 0.18);
	background: rgba(30, 27, 75, 0.38);
}

[data-theme="dark"] .ai-reason-progress__title {
	color: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] .ai-reason-progress__track {
	background: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .ai-reason-progress__fill::after {
	opacity: 0.65;
}

[data-theme="dark"] .ai-reason-progress__label {
	color: rgba(255, 255, 255, 0.78);
}

/* Smooth swap when LLM result arrives */
.ai-reason-fade {
	opacity: 1;
	transform: translateY(0);
	transition: opacity 420ms ease, transform 420ms ease;
}

.ai-reason-fade.ai-reason-fade--out {
	opacity: 0;
	transform: translateY(14px);
}

@media (prefers-reduced-motion: reduce) {
	.ai-reason-progress__fill {
		transition: none;
	}
	.ai-reason-progress__fill::after {
		animation: none;
	}
	.ai-reason-fade {
		transition: none;
	}
}

/* ========================================
   AI Reason Box - Extra FX (scoped)
   Only affects the result popup (#popupBox)
   ======================================== */

/* Boost the existing neon frame without touching other UI */
#popupBox .ai-reason-box {
	will-change: transform, box-shadow, filter;
	transform: translateZ(0);
	box-shadow:
		0 0 60px rgba(56, 189, 248, 0.22),
		0 18px 60px rgba(2, 6, 23, 0.22);
	filter: saturate(1.08);
}

#popupBox .ai-reason-box::before {
	filter: blur(0.8px) saturate(1.35) brightness(1.12);
	animation-duration: 2.2s;
}

/* ========================================
   LLM Reasoning Box - Rainbow Glow Border
   Scoped to only the reasoning box (#llmReasoning)
   Requirement: "เอาแค่ขอบ"
   ======================================== */

@property --llm-angle {
	syntax: '<angle>';
	inherits: false;
	initial-value: 0deg;
}

@keyframes llmReasonBorderCycle {
	0% { --llm-angle: 0deg; }
	100% { --llm-angle: 360deg; }
}

/* Use an inset inner fill to reveal the border (no mask-composite; avoids diagonal leak) */
#popupBox #llmReasoning.ai-reason-box {
	/* Thin border, big glow */
	--llm-rainbow-border: 2px;
	--llm-rainbow-cover: 2px; /* extra cover to prevent glow bleeding into the inside */
	--llm-rainbow-glow: 5px; /* outer spread (smaller) */
	--llm-rainbow-radius: 24px;
	overflow: visible; /* allow glow to bloom outside the frame */
	isolation: isolate; /* keep pseudo layers contained */
}

/* Outer fuzzy rainbow glow (behind the card) */
#popupBox #llmReasoning.ai-reason-box::before {
	inset: calc(var(--llm-rainbow-glow) * -1);
	border-radius: calc(var(--llm-rainbow-radius) + var(--llm-rainbow-glow));
	border: 0;
	box-sizing: border-box;
	/* Disable legacy border masking from fgw_style.css (prevents diagonal leaks / disappearing glow) */
	mask: none;
	-webkit-mask: none;
	mask-composite: initial;
	-webkit-mask-composite: initial;
	/* Loader-like cycling border: colors move around without rotating the element */
	background: conic-gradient(
		from var(--llm-angle),
		rgba(255,255,255,0.90) 0%,
		#ad5fff 10%,
		#471eec 22%,
		#d60a47 38%,
		#ff8a3c 52%,
		#fff06a 64%,
		#38f9d7 78%,
		#5b8cff 90%,
		rgba(255,255,255,0.90) 100%
	);
	opacity: 0.92;
	filter: blur(12px) saturate(1.45) brightness(1.04);
	/* Clip the blur so corners stay rounded (prevents a square-looking glow) */
	clip-path: inset(0 round calc(var(--llm-rainbow-radius) + var(--llm-rainbow-glow)));
	animation: llmReasonBorderCycle 10.2s linear infinite;
	will-change: filter;
	/* behind the fill */
	z-index: 0;
}

/* Inner fill sits above glow and is inset so the glow reads as a border only */
#popupBox #llmReasoning.ai-reason-box::after {
	inset: calc(var(--llm-rainbow-border) + var(--llm-rainbow-cover));
	border-radius: calc(var(--llm-rainbow-radius) - var(--llm-rainbow-border) - var(--llm-rainbow-cover));
	/* Requirement: keep only the border (remove inner rainbow/pastel wash) */
	background: #ffffff;
	animation: none;
	z-index: 1;
}

/* Dark mode fill for #llmReasoning only (still border-only) */
[data-theme="dark"] #popupBox #llmReasoning.ai-reason-box::after {
	background: rgb(15, 23, 42);
}

#popupBox #llmReasoning.ai-reason-box > * {
	z-index: 2;
}



@media (prefers-reduced-motion: reduce) {
	#popupBox #llmReasoning.ai-reason-box::before,
	#popupBox #llmReasoning.ai-reason-box::after {
		animation: none;
	}
}

/* Animated aurora/shimmer background overlay (reuses ::after layer) */
@keyframes aiReasonAurora {
	0% {
		background-position: 0% 50%, 100% 20%, 20% 100%;
		opacity: 0.92;
	}
	50% {
		background-position: 100% 50%, 0% 40%, 80% 0%;
		opacity: 0.96;
	}
	100% {
		background-position: 0% 50%, 100% 20%, 20% 100%;
		opacity: 0.92;
	}
}

#popupBox .ai-reason-box::after {
	background:
		radial-gradient(900px 520px at 18% 12%, rgba(124, 58, 237, 0.18) 0%, rgba(255, 255, 255, 0.90) 52%),
		radial-gradient(860px 520px at 92% 18%, rgba(56, 189, 248, 0.16) 0%, rgba(255, 255, 255, 0.88) 55%),
		radial-gradient(900px 560px at 50% 120%, rgba(34, 197, 94, 0.10) 0%, rgba(255, 255, 255, 0.90) 60%);
	background-size: 220% 220%, 220% 220%, 220% 220%;
	animation: aiReasonAurora 6.8s ease-in-out infinite;
}

@keyframes aiReasonGlowPulse {
	0%, 100% {
		box-shadow:
			0 0 46px rgba(56, 189, 248, 0.18),
			0 18px 60px rgba(2, 6, 23, 0.22);
		transform: translateY(0);
	}
	50% {
		box-shadow:
			0 0 86px rgba(124, 58, 237, 0.22),
			0 26px 78px rgba(2, 6, 23, 0.26);
		transform: translateY(-2px);
	}
}

@keyframes aiReasonPopIn {
	0% { opacity: 0; transform: translateY(14px) scale(0.985); }
	100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes aiReasonItemIn {
	0% { opacity: 0; transform: translateY(10px); }
	100% { opacity: 1; transform: translateY(0); }
}

/* Run the "extra" entrance + stagger only when JS marks it rendered */
#popupBox .ai-reason-box.ai-reason-box--rendered {
	animation: aiReasonPopIn 520ms cubic-bezier(0.16, 1, 0.3, 1) both, aiReasonGlowPulse 2.9s ease-in-out infinite;
}

#popupBox .ai-reason-box.ai-reason-box--rendered .ai-reason-box__summary-title,
#popupBox .ai-reason-box.ai-reason-box--rendered .ai-reason-box__summary-text,
#popupBox .ai-reason-box.ai-reason-box--rendered .ai-reason-box__guidance-title {
	animation: aiReasonItemIn 520ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

#popupBox .ai-reason-box.ai-reason-box--rendered .ai-reason-box__guidance-list li {
	opacity: 0;
	animation: aiReasonItemIn 520ms cubic-bezier(0.16, 1, 0.3, 1) both;
	animation-delay: calc(var(--i, 0) * 70ms + 120ms);
}

/* Dark mode: keep aurora but deepen the base */
[data-theme="dark"] #popupBox .ai-reason-box {
	box-shadow:
		0 0 64px rgba(34, 211, 238, 0.16),
		0 24px 72px rgba(2, 6, 23, 0.55);
}

[data-theme="dark"] #popupBox .ai-reason-box::after {
	background:
		radial-gradient(980px 560px at 18% 12%, rgba(99, 102, 241, 0.20) 0%, rgba(15, 23, 42, 0.94) 55%),
		radial-gradient(920px 560px at 92% 18%, rgba(34, 211, 238, 0.16) 0%, rgba(15, 23, 42, 0.94) 58%),
		radial-gradient(980px 620px at 50% 120%, rgba(34, 197, 94, 0.10) 0%, rgba(2, 6, 23, 0.94) 62%);
}

@media (prefers-reduced-motion: reduce) {
	#popupBox .ai-reason-box.ai-reason-box--rendered {
		animation: none;
	}
	#popupBox .ai-reason-box::after {
		animation: none;
	}
	#popupBox .ai-reason-box.ai-reason-box--rendered .ai-reason-box__guidance-list li,
	#popupBox .ai-reason-box.ai-reason-box--rendered .ai-reason-box__summary-title,
	#popupBox .ai-reason-box.ai-reason-box--rendered .ai-reason-box__summary-text,
	#popupBox .ai-reason-box.ai-reason-box--rendered .ai-reason-box__guidance-title {
		opacity: 1;
		animation: none;
	}
}

@media (max-width: 480px) {
	.ai-reason-box.has-disclaimer {
		padding-bottom: 66px;
	}

	.ai-reason-box > .ai-reason-box__disclaimer {
		right: 6px;
		bottom: 6px;
		font-size: 11px;
		padding: 7px 11px;
	}
}

@media (max-width: 480px) {
	/* Anchor the disclaimer to the bottom edge and allow full wrapping.
	   Increase bottom padding so the disclaimer does not overlap text. */
	.ai-reason-box.has-disclaimer {
		padding-bottom: 120px !important;
	}

	.ai-reason-box > .ai-reason-box__disclaimer {
		position: absolute !important;
		left: 12px !important;
		right: 12px !important;
		bottom: 12px !important;
		z-index: 6 !important;
		display: flex !important;
		align-items: center !important;
		gap: 8px !important;
		font-size: 13px !important;
		line-height: 1.25 !important;
		padding: 10px 12px !important;
		border-radius: 12px !important;
		background-clip: padding-box !important;
		white-space: normal !important;
		overflow: visible !important;
		max-width: calc(100% - 24px) !important;
		box-shadow: 0 6px 18px rgba(17,24,39,0.08) !important;
	}

	.ai-reason-box > .ai-reason-box__disclaimer .ai-reason-box__disclaimer-text {
		display: inline-block !important;
		white-space: normal !important;
		overflow-wrap: anywhere !important;
		word-break: break-word !important;
		max-width: 100% !important;
	}
}
