/**
 * Chagency supplemental styles.
 *
 * One admin page (Settings → Chagency) + a floating widget on every admin
 * page when enabled. The widget uses the soft-gradient launcher + a
 * compact chat panel.
 */

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

/* `.admin-ui-page` fallback styles — only win if WP's own
   `wp-admin-ui` stylesheet isn't loaded. Mirrors core's Connectors /
   ai-wp-admin look. */
.admin-ui-page {
	background-color: #fff;
	color: #1e1e1e;
	display: flex;
	flex-flow: column;
	min-height: calc(100vh - 32px);
	position: relative;
	z-index: 1;
}

.admin-ui-page__header {
	background: #fff;
	border-bottom: 1px solid #e0e0e0;
	padding: 16px 24px;
	position: sticky;
	top: 32px;
	z-index: 1;
	display: flex;
	gap: 16px;
	align-items: center;
	justify-content: space-between;
}

.admin-ui-page__header-title-wrapper {
	min-width: 0;
	flex: 1 1 auto;
}

.admin-ui-page__header-title {
	font-size: 20px;
	font-weight: 500;
	line-height: 32px;
	margin: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.admin-ui-page__header-subtitle {
	color: #6d6d6d;
	font-size: 13px;
	line-height: 24px;
	margin: 0;
	padding-block-end: 4px;
}

.admin-ui-page__header-actions {
	display: flex;
	gap: 12px;
	align-items: center;
	flex: 0 0 auto;
}

.admin-ui-page__content {
	display: flex;
	flex-direction: column;
	flex-grow: 1;
	overflow: auto;
}

.admin-ui-page__content.has-padding {
	padding: 16px 24px;
}

@media ( max-width: 782px ) {

	.admin-ui-page__header {
		top: 46px;
	}
}

.boot-layout-container {
	min-height: calc(100vh - 32px);
}

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

@media ( max-width: 480px ) {

	.chagency-settings-column {
		padding: 0 0 32px;
	}
}

.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 8px;
	border-radius: 10px;
	font-size: 11px;
	font-weight: 600;
	line-height: 1.6;
	white-space: nowrap;
}

.chagency-badge--ok {
	background: #d1f2df;
	color: #114926;
}

.chagency-badge--warn {
	background: #fef1d4;
	color: #674e14;
}

.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, #f8f8f8);
	padding: 1px 4px;
	border-radius: 3px;
}

/* ============================================================
   Floating widget — soft-gradient launcher + panel
   ============================================================ */

.chagency-widget-root {
	position: relative;
	z-index: 99999;
}

/* --- Launcher: tight bar flush to the bottom, soft vertical gradient. --- */
.chagency-widget-launcher {
	position: fixed;
	right: 24px;
	bottom: 0;
	display: inline-flex;
	align-items: center;
	gap: 12px;
	padding: 13px 20px;
	border: 0;
	border-radius: 8px 8px 0 0;
	background: linear-gradient(180deg, color-mix(in srgb, var(--wp-admin-theme-color, #2271b1) 88%, #fff) 0%, var(--wp-admin-theme-color, #2271b1) 100%);
	color: #fff;
	font-family: inherit;
	font-size: 13px;
	font-weight: 500;
	line-height: 1;
	cursor: pointer;
	box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.16);
	transition: box-shadow 0.18s ease, filter 0.18s ease;
	z-index: 99999;
}

.chagency-widget-launcher:hover {
	filter: brightness(1.08);
	box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.22);
}

.chagency-widget-launcher:focus-visible {
	outline: 2px solid var(--wp-admin-theme-color, #2271b1);
	outline-offset: 3px;
}

.chagency-widget-launcher__dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #7dd892;
	box-shadow: 0 0 0 0 rgba(125, 216, 146, 0.7);
	animation: chagencyLauncherPulse 2.4s ease-out infinite;
	flex-shrink: 0;
}

@keyframes chagencyLauncherPulse {

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

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

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

.chagency-widget-launcher__badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 20px;
	height: 20px;
	min-width: 20px;
	border-radius: 50%;
	background: #e84a4a;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	line-height: 1;
	margin-left: 2px;
}

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

	.chagency-widget-launcher__dot {
		animation: none;
	}
}

/* --- Panel: flush-bottom chat surface that rises out of the launcher. --- */
.chagency-widget-panel {
	position: fixed;
	right: 24px;
	bottom: 0;
	width: 380px;
	max-width: calc(100vw - 48px);
	height: min(560px, calc(100vh - 80px));
	background: #fff;
	border: 1px solid var(--wpds-color-stroke-surface-neutral-weak, #e0e0e0);
	border-bottom: 0;
	border-radius: 12px 12px 0 0;
	box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.14);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	z-index: 99999;
	animation: chagencySlideUp 0.18s ease-out;
	transform-origin: bottom right;
}

@keyframes chagencySlideUp {

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

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

.chagency-widget-panel__header {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	border-bottom: 1px solid var(--wpds-color-stroke-surface-neutral-weak, #e0e0e0);
}

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

.chagency-widget-panel__title .chagency-widget-launcher__dot {
	box-shadow: 0 0 0 0 rgba(125, 216, 146, 0.7);
}

.chagency-widget-panel__header-actions {
	display: flex;
	gap: 6px;
	align-items: center;
}

.chagency-widget-panel__body {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: var(--wpds-color-bg-surface-neutral, #f8f8f8);
}

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

.chagency-widget-bubble--assistant {
	align-self: flex-start;
	background: #fff;
	border: 1px solid var(--wpds-color-stroke-surface-neutral-weak, #e0e0e0);
	border-bottom-left-radius: 4px;
}

.chagency-widget-bubble--user {
	align-self: flex-end;
	background: var(--wp-admin-theme-color, #2271b1);
	color: #fff;
	border-bottom-right-radius: 4px;
}

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

.chagency-widget-bubble--pending {
	display: inline-flex;
	gap: 8px;
	align-items: center;
	color: var(--wpds-color-fg-content-neutral-weak, #6d6d6d);
	background: #fff;
	border: 1px solid var(--wpds-color-stroke-surface-neutral-weak, #e0e0e0);
	padding: 12px 14px;
}

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

.chagency-typing__dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--wpds-color-fg-content-neutral-weak, #6d6d6d);
	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-widget-bubble--assistant p,
.chagency-widget-bubble--assistant ul,
.chagency-widget-bubble--assistant ol,
.chagency-widget-bubble--assistant pre,
.chagency-widget-bubble--assistant blockquote {
	margin: 0 0 8px;
}

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

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

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

.chagency-widget-bubble--assistant code {
	background: var(--wpds-color-bg-surface-neutral, #f8f8f8);
	padding: 1px 5px;
	border-radius: 3px;
	font-size: 12px;
	font-family: Menlo, Consolas, monaco, monospace;
}

.chagency-widget-bubble--assistant pre {
	background: var(--wpds-color-bg-surface-neutral, #f8f8f8);
	padding: 8px 10px;
	border-radius: 6px;
	overflow-x: auto;
	font-size: 12px;
}

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

.chagency-widget-bubble--assistant a {
	color: var(--wp-admin-theme-color, #2271b1);
	text-decoration: underline;
}

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

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

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

/* Composer */
.chagency-widget-panel__composer {
	flex: 0 0 auto;
	padding: 10px;
	border-top: 1px solid var(--wpds-color-stroke-surface-neutral-weak, #e0e0e0);
	display: flex;
	gap: 8px;
	align-items: stretch;
}

.chagency-widget-input {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
}

.chagency-widget-input .components-base-control__field {
	flex: 1 1 auto;
	display: flex;
}

.chagency-widget-input .components-textarea-control__input {
	max-height: 120px;
	font-size: 13px;
	resize: none;
}

.chagency-widget-panel__composer .components-button {
	height: 40px;
	align-self: stretch;
}

/* ============================================================
   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;
}
