/**
 * Chagency styles, Settings page + floating widget.
 *
 * Theming is centralised on `--chagency-accent` so the widget feels native
 * on both the WordPress admin (uses the admin theme color) and the public
 * site (uses a refined neutral fallback).
 */

/* ============================================================
   Settings → Chagency page
   ============================================================ */

.chagency-settings-column {
	box-sizing: border-box;
	width: 100%;
	max-width: 720px;
	margin: 0 auto;
	padding: 24px 24px 48px;
}

.chagency-provider-row {
	padding: 12px 0;
	border-bottom: 1px solid var(--wpds-color-stroke-surface-neutral-weak, #e0e0e0);
}

.chagency-providers .chagency-provider-row:last-child {
	border-bottom: 0;
}

.chagency-provider-row__name {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-width: 0;
}

.chagency-badge {
	display: inline-block;
	padding: 2px 10px;
	border-radius: 12px;
	font-size: 11px;
	font-weight: 600;
	line-height: 1.6;
	white-space: nowrap;
}

.chagency-badge--ok {
	background: #e6f6ec;
	color: #1c6b3a;
}

.chagency-badge--warn {
	background: #fef3d4;
	color: #6b5113;
}

.chagency-placeholders {
	font-size: 13px;
}

.chagency-placeholders summary {
	cursor: pointer;
	color: var(--wpds-color-fg-content-neutral-weak, #6d6d6d);
}

.chagency-placeholders ul {
	margin: 8px 0 0;
	padding-left: 20px;
	color: var(--wpds-color-fg-content-neutral, #1e1e1e);
}

.chagency-placeholders li {
	margin: 4px 0;
}

.chagency-placeholders code {
	font-size: 12px;
	background: var(--wpds-color-bg-surface-neutral, #f4f4f4);
	padding: 1px 5px;
	border-radius: 3px;
}

/* ============================================================
   Floating widget, surface-aware accent
   ============================================================ */

.chagency {
	--chagency-accent: var(--wp-admin-theme-color, #1f1f1f);
	--chagency-accent-hover: color-mix(in srgb, var(--chagency-accent) 85%, #000);
	--chagency-bg: #fff;
	--chagency-bg-soft: #f6f7f9;
	--chagency-text: #1f1f1f;
	--chagency-text-soft: #6d6d6d;
	--chagency-border: #e6e8eb;
	--chagency-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
	--chagency-radius: 16px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
	z-index: 99999;
}

/* Frontend gets a refined dark accent so it looks elegant on any theme. */
.chagency--frontend {
	--chagency-accent: #1f2937;
	--chagency-accent-hover: #0f172a;
}

/* --- Launcher: small round floating button --- */
.chagency-launcher {
	position: fixed;
	right: 24px;
	bottom: 24px;
	width: 56px;
	height: 56px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 0;
	border-radius: 50%;
	background: var(--chagency-accent);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 6px 18px rgba(15, 23, 42, 0.22);
	transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
	z-index: 99999;
}

.chagency-launcher:hover {
	background: var(--chagency-accent-hover);
	transform: translateY(-1px);
	box-shadow: 0 10px 24px rgba(15, 23, 42, 0.28);
}

.chagency-launcher:focus-visible {
	outline: 2px solid var(--chagency-accent);
	outline-offset: 3px;
}

.chagency-launcher__badge {
	position: absolute;
	top: -4px;
	right: -4px;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 10px;
	background: #e84a4a;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	line-height: 1;
	box-shadow: 0 0 0 2px #fff;
}

/* --- Panel: floating card aligned with the launcher --- */
.chagency-panel {
	position: fixed;
	right: 24px;
	bottom: 24px;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: min(580px, calc(100vh - 96px));
	background: var(--chagency-bg);
	border: 1px solid var(--chagency-border);
	border-radius: var(--chagency-radius);
	box-shadow: var(--chagency-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	z-index: 99999;
	animation: chagencyPop 0.18s ease-out;
	transform-origin: bottom right;
}

@keyframes chagencyPop {

	from {
		opacity: 0;
		transform: translateY(12px) scale(0.98);
	}

	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

@media (prefers-reduced-motion: reduce) {

	.chagency-panel {
		animation: none;
	}
}

.chagency-panel__header {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 14px;
	background: var(--chagency-accent);
	color: #fff;
}

.chagency-panel__title {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-weight: 600;
	font-size: 14px;
	letter-spacing: 0.01em;
}

.chagency-panel__dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #7dd892;
	box-shadow: 0 0 0 0 rgba(125, 216, 146, 0.55);
	animation: chagencyPulse 2.4s ease-out infinite;
}

@keyframes chagencyPulse {

	0% {
		box-shadow: 0 0 0 0 rgba(125, 216, 146, 0.55);
	}

	70% {
		box-shadow: 0 0 0 8px rgba(125, 216, 146, 0);
	}

	100% {
		box-shadow: 0 0 0 0 rgba(125, 216, 146, 0);
	}
}

@media (prefers-reduced-motion: reduce) {

	.chagency-panel__dot {
		animation: none;
	}
}

.chagency-panel__actions {
	display: flex;
	gap: 4px;
	align-items: center;
}

.chagency-panel__action {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: 28px;
	min-width: 28px;
	padding: 0 4px;
	border: 0;
	border-radius: 6px;
	background: transparent;
	color: rgba(255, 255, 255, 0.85);
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.chagency-panel__action:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.chagency-panel__action:hover:not(:disabled) {
	background: rgba(255, 255, 255, 0.12);
	color: #fff;
}

.chagency-panel__action--text {
	font-size: 12px;
	font-weight: 500;
	padding: 0 8px;
}

.chagency-panel__body {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: var(--chagency-bg-soft);
}

.chagency-bubble {
	max-width: 85%;
	padding: 10px 12px;
	border-radius: 14px;
	line-height: 1.5;
	font-size: 13.5px;
	color: var(--chagency-text);
	white-space: pre-wrap;
	word-break: break-word;
	overflow-wrap: anywhere;
}

.chagency-bubble--assistant {
	align-self: flex-start;
	background: #fff;
	border: 1px solid var(--chagency-border);
	border-bottom-left-radius: 4px;
}

.chagency-bubble--user {
	align-self: flex-end;
	background: var(--chagency-accent);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.chagency-bubble--error {
	background: #fcf0f1;
	color: #b32d2e;
	border-color: #f0b7b8;
	font-style: italic;
}

.chagency-bubble--pending {
	display: inline-flex;
	gap: 8px;
	align-items: center;
	color: var(--chagency-text-soft);
	background: #fff;
	border: 1px solid var(--chagency-border);
	padding: 12px 14px;
}

/* Typing indicator */
.chagency-typing {
	display: inline-flex;
	gap: 4px;
	align-items: center;
	height: 10px;
}

.chagency-typing__dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--chagency-text-soft);
	animation: chagencyTypingBounce 1.2s infinite ease-in-out;
}

.chagency-typing__dot:nth-child(2) {
	animation-delay: 0.15s;
}

.chagency-typing__dot:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes chagencyTypingBounce {

	0%,
	60%,
	100% {
		opacity: 0.3;
		transform: translateY(0);
	}

	30% {
		opacity: 1;
		transform: translateY(-3px);
	}
}

@media (prefers-reduced-motion: reduce) {

	.chagency-typing__dot {
		animation: none;
		opacity: 0.6;
	}
}

/* Markdown content inside assistant bubbles */
.chagency-bubble--assistant p,
.chagency-bubble--assistant ul,
.chagency-bubble--assistant ol,
.chagency-bubble--assistant pre,
.chagency-bubble--assistant blockquote {
	margin: 0 0 8px;
}

.chagency-bubble--assistant > :last-child {
	margin-bottom: 0;
}

.chagency-bubble--assistant ul,
.chagency-bubble--assistant ol {
	padding-inline-start: 20px;
}

.chagency-bubble--assistant li {
	margin: 2px 0;
}

.chagency-bubble--assistant code {
	background: var(--chagency-bg-soft);
	padding: 1px 5px;
	border-radius: 3px;
	font-size: 12px;
	font-family: Menlo, Consolas, monaco, monospace;
}

.chagency-bubble--assistant pre {
	background: var(--chagency-bg-soft);
	padding: 8px 10px;
	border-radius: 6px;
	overflow-x: auto;
	font-size: 12px;
}

.chagency-bubble--assistant pre code {
	background: transparent;
	padding: 0;
	font-size: 12px;
}

.chagency-bubble--assistant a {
	color: var(--chagency-accent);
	text-decoration: underline;
}

.chagency-bubble--assistant h1,
.chagency-bubble--assistant h2,
.chagency-bubble--assistant h3,
.chagency-bubble--assistant h4 {
	margin: 8px 0 4px;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.3;
}

.chagency-bubble--assistant strong {
	font-weight: 600;
}

.chagency-bubble--assistant em {
	font-style: italic;
}

/* Composer: textarea + round send button */
.chagency-panel__composer {
	flex: 0 0 auto;
	padding: 10px 12px;
	border-top: 1px solid var(--chagency-border);
	background: #fff;
	display: flex;
	gap: 8px;
	align-items: flex-end;
}

.chagency-input {
	flex: 1 1 auto;
	min-width: 0;
	min-height: 40px;
	max-height: 120px;
	padding: 10px 12px;
	border: 1px solid var(--chagency-border);
	border-radius: 12px;
	background: var(--chagency-bg-soft);
	color: var(--chagency-text);
	font-family: inherit;
	font-size: 13.5px;
	line-height: 1.4;
	resize: none;
	box-sizing: border-box;
	outline: none;
	transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.chagency-input::placeholder {
	color: var(--chagency-text-soft);
}

.chagency-input:focus {
	border-color: var(--chagency-accent);
	background: #fff;
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--chagency-accent) 18%, transparent);
}

.chagency-input:disabled {
	opacity: 0.7;
	cursor: not-allowed;
}

.chagency-send {
	flex: 0 0 auto;
	width: 40px;
	height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 0;
	border-radius: 50%;
	background: var(--chagency-accent);
	color: #fff;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.chagency-send:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.chagency-send:hover:not(:disabled) {
	background: var(--chagency-accent-hover);
}

.chagency-send:active:not(:disabled) {
	transform: scale(0.96);
}

/* On the public site, lift the panel above any sticky header. */
.chagency--frontend .chagency-panel,
.chagency--frontend .chagency-launcher {
	z-index: 999999;
}

/* Mobile: panel becomes a full-bleed sheet */
@media (max-width: 480px) {

	.chagency-panel {
		right: 8px;
		left: 8px;
		bottom: 8px;
		width: auto;
		max-width: none;
		height: min(640px, calc(100vh - 16px));
	}

	.chagency-launcher {
		right: 16px;
		bottom: 16px;
	}
}

/* ============================================================
   Snackbar host (save feedback, provider-test feedback)
   ============================================================ */

.chagency-snackbars {
	position: fixed;
	bottom: 24px;
	left: 0;
	right: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	z-index: 100000;
	pointer-events: none;
}

.chagency-snackbars .components-snackbar {
	pointer-events: auto;
	max-width: 520px;
	margin: 0;
}
