/**
 * Chat AI — floating chat widget styles.
 *
 * All selectors are prefixed with .chat-ai- to avoid conflicts with
 * themes and page builders.
 *
 * Every styleable property reads a --chat-ai-* custom property with the
 * built-in value as fallback. The Elementor widget's style controls set
 * these variables on the widget wrapper; without them (e.g. shortcode use)
 * the defaults below apply.
 *
 * @package ChatAI
 */

.chat-ai-launcher,
.chat-ai-panel,
.chat-ai-panel * {
	box-sizing: border-box;
}

/* ------------------------------ launcher ------------------------------ */

.chat-ai-launcher {
	position: fixed;
	right: var(--chat-ai-pos-x, 20px);
	bottom: var(--chat-ai-pos-y, 20px);
	z-index: var(--chat-ai-z-index, 99999);
	width: var(--chat-ai-launcher-size, 56px);
	height: var(--chat-ai-launcher-size, 56px);
	padding: 0;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: var(--chat-ai-launcher-gap, 0);
	color: var(--chat-ai-launcher-icon-color, #fff);
	background: var(--chat-ai-launcher-bg, linear-gradient(135deg, #6a5af9 0%, #5248e0 100%));
	box-shadow: 0 8px 24px rgba(82, 72, 224, 0.35);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-ai-launcher:hover {
	transform: translateY(-2px) scale(1.05);
	box-shadow: 0 12px 28px rgba(82, 72, 224, 0.45);
	color: var(--chat-ai-launcher-icon-hover-color, var(--chat-ai-launcher-icon-color, #fff));
	background: var(--chat-ai-launcher-bg-hover, var(--chat-ai-launcher-bg, linear-gradient(135deg, #6a5af9 0%, #5248e0 100%)));
}

/* Text mode: a rounded pill whose width fits its label. */
.chat-ai-launcher--text {
	width: auto;
	padding: 0 22px;
	border-radius: 999px;
	height: var(--chat-ai-launcher-size, 56px);
}

.chat-ai-launcher--text .chat-ai-launcher-label {
	font-size: 15px;
	font-weight: 600;
	line-height: 1;
	color: var(--chat-ai-launcher-text-color, var(--chat-ai-launcher-icon-color, #fff));
	white-space: nowrap;
}

.chat-ai-launcher:focus-visible {
	outline: 3px solid rgba(106, 90, 249, 0.5);
	outline-offset: 2px;
}

.chat-ai-launcher svg {
	display: block;
	width: var(--chat-ai-icon-size, 26px);
	height: var(--chat-ai-icon-size, 26px);
}

.chat-ai-launcher .chat-ai-launcher-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.chat-ai-launcher .chat-ai-icon-close {
	display: none;
}

/* Closed state: show the launcher icon, hide the close icon. */
.chat-ai-launcher .chat-ai-icon-chat {
	display: block;
}

/* Open state: swap to the close icon. */
.chat-ai-launcher--open .chat-ai-icon-chat,
.chat-ai-launcher--open .chat-ai-launcher-icon {
	display: none;
}

.chat-ai-launcher--open .chat-ai-icon-close {
	display: block;
}

/* When the panel is open in text mode, hide the label so the close icon
   sits alone and the pill doesn't grow when the label stays put. */
.chat-ai-launcher--open.chat-ai-launcher--text .chat-ai-launcher-label {
	display: none;
}

/* When open in text mode, the close icon replaces the icon+label and is
   centered like the round button. */
.chat-ai-launcher--text.chat-ai-launcher--open .chat-ai-icon-close {
	display: flex;
	align-items: center;
	justify-content: center;
}

/* -------------------------------- panel -------------------------------- */

.chat-ai-panel {
	position: fixed;
	right: var(--chat-ai-pos-x, 20px);
	/* Sit above the launcher: offset + launcher size + 12px gap. */
	bottom: calc(var(--chat-ai-pos-y, 20px) + var(--chat-ai-launcher-size, 56px) + 12px);
	z-index: var(--chat-ai-z-index, 99999);
	width: var(--chat-ai-panel-width, 380px);
	height: 560px;
	max-height: calc(100vh - 110px);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: #fff;
	border-radius: 16px;
	box-shadow: 0 12px 48px rgba(17, 17, 34, 0.2);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
	opacity: 0;
	transform: translateY(12px) scale(0.98);
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-ai-panel[hidden] {
	display: none;
}

.chat-ai-panel--open {
	opacity: 1;
	transform: translateY(0) scale(1);
}

/* Position variant — toggled by the Elementor widget "Position" control
   (prefix class chat-ai-pos-*). Bottom right is the default above. */
.chat-ai-pos-bottom-left .chat-ai-launcher,
.chat-ai-pos-bottom-left .chat-ai-panel {
	right: auto;
	left: var(--chat-ai-pos-x, 20px);
}

/* ------------------------------- header -------------------------------- */

.chat-ai-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 14px 16px;
	color: var(--chat-ai-header-text-color, #fff);
	background: var(--chat-ai-header-bg, linear-gradient(135deg, #6a5af9 0%, #8d6bff 100%));
}

.chat-ai-header-info {
	display: flex;
	align-items: center;
	gap: 9px;
	min-width: 0;
}

.chat-ai-title {
	font-size: 15px;
	font-weight: 600;
	line-height: 1.3;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.chat-ai-status-dot {
	flex: none;
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.55);
}

.chat-ai-status-dot--online {
	background: #3ddc84;
	box-shadow: 0 0 0 3px rgba(61, 220, 132, 0.3);
}

.chat-ai-status-dot--offline {
	background: #ff5d5d;
}

.chat-ai-status-dot--checking {
	animation: chat-ai-pulse 1s ease-in-out infinite;
}

.chat-ai-close {
	flex: none;
	border: 0;
	background: transparent;
	color: var(--chat-ai-header-text-color, rgba(255, 255, 255, 0.92));
	font-size: 24px;
	line-height: 1;
	padding: 2px 8px;
	border-radius: 8px;
	cursor: pointer;
}

.chat-ai-close:hover {
	background: rgba(255, 255, 255, 0.18);
}

.chat-ai-header-actions {
	flex: none;
	display: flex;
	align-items: center;
	gap: 4px;
}

.chat-ai-new,
.chat-ai-history-btn {
	flex: none;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 0;
	background: transparent;
	color: var(--chat-ai-header-text-color, rgba(255, 255, 255, 0.92));
	padding: 6px;
	border-radius: 8px;
	cursor: pointer;
}

.chat-ai-new:hover:not(:disabled),
.chat-ai-history-btn:hover:not(:disabled) {
	background: rgba(255, 255, 255, 0.18);
}

.chat-ai-new:disabled,
.chat-ai-history-btn:disabled {
	opacity: 0.5;
	cursor: default;
}

.chat-ai-new svg,
.chat-ai-history-btn svg {
	display: block;
}

/* ------------------------------ messages ------------------------------- */

.chat-ai-messages {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 16px;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: var(--chat-ai-chat-bg, #f6f7fb);
}

.chat-ai-msg {
	display: flex;
}

.chat-ai-msg--user {
	justify-content: flex-end;
}

.chat-ai-msg--assistant {
	justify-content: flex-start;
}

.chat-ai-msg--system {
	justify-content: center;
}

.chat-ai-bubble {
	max-width: 85%;
	padding: 10px 13px;
	border-radius: 14px;
	font-size: 14px;
	line-height: 1.55;
	overflow-wrap: anywhere;
	word-break: break-word;
}

.chat-ai-msg--user .chat-ai-bubble {
	color: var(--chat-ai-user-bubble-text-color, #fff);
	background: var(--chat-ai-user-bubble-bg, linear-gradient(135deg, #6a5af9 0%, #5248e0 100%));
	border-bottom-right-radius: 4px;
}

.chat-ai-msg--assistant .chat-ai-bubble {
	color: var(--chat-ai-bot-bubble-text-color, #2b2b3a);
	background: var(--chat-ai-bot-bubble-bg, #fff);
	border: 1px solid #e7e8f0;
	border-bottom-left-radius: 4px;
}

.chat-ai-msg--user .chat-ai-content {
	white-space: pre-wrap;
}

.chat-ai-content a {
	color: #5248e0;
	text-decoration: underline;
}

.chat-ai-msg--user .chat-ai-content a {
	color: var(--chat-ai-user-bubble-text-color, #fff);
}

/* rendered markdown inside assistant messages */

.chat-ai-content p {
	margin: 0 0 8px;
}

.chat-ai-content p:last-child,
.chat-ai-content ol:last-child,
.chat-ai-content ul:last-child,
.chat-ai-content pre:last-child {
	margin-bottom: 0;
}

.chat-ai-heading {
	display: block;
	margin: 2px 0 6px;
}

.chat-ai-list {
	margin: 0 0 8px;
	padding-left: 20px;
}

.chat-ai-content ul.chat-ai-list {
	list-style: disc;
}

.chat-ai-content ol.chat-ai-list {
	list-style: decimal;
}

.chat-ai-list li {
	margin: 3px 0;
}

.chat-ai-code-block {
	margin: 0 0 8px;
	padding: 10px 12px;
	border-radius: 8px;
	background: #232338;
	color: #e9e9f4;
	font-family: Menlo, Consolas, "Liberation Mono", monospace;
	font-size: 12.5px;
	line-height: 1.5;
	white-space: pre-wrap;
	overflow-x: auto;
}

.chat-ai-code-block code {
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font-family: inherit;
	font-size: inherit;
}

.chat-ai-inline-code {
	padding: 1px 5px;
	border-radius: 4px;
	background: rgba(82, 72, 224, 0.08);
	border: 1px solid rgba(82, 72, 224, 0.16);
	font-family: Menlo, Consolas, "Liberation Mono", monospace;
	font-size: 12.5px;
}

.chat-ai-system {
	max-width: 90%;
	padding: 2px 10px;
	font-size: 12px;
	line-height: 1.5;
	text-align: center;
	color: #8a8fa3;
}

.chat-ai-system--error {
	color: #d64545;
}

/* sources */

.chat-ai-sources {
	margin-top: 10px;
	padding-top: 8px;
	border-top: 1px solid #eef0f6;
}

.chat-ai-sources-label {
	display: block;
	margin-bottom: 6px;
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: #8a8fa3;
}

.chat-ai-sources-list {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.chat-ai-source-chip {
	display: inline-block;
	max-width: 100%;
	padding: 4px 10px;
	border: 1px solid rgba(82, 72, 224, 0.25);
	border-radius: 999px;
	background: rgba(82, 72, 224, 0.06);
	color: #5248e0;
	font-size: 12px;
	line-height: 1.4;
	text-decoration: none;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	transition: background 0.15s ease, border-color 0.15s ease;
}

a.chat-ai-source-chip:hover {
	background: rgba(82, 72, 224, 0.14);
	border-color: rgba(82, 72, 224, 0.45);
}

.chat-ai-source-chip--plain {
	color: #6b7085;
	border-color: #dfe1ec;
	background: #f4f5f9;
}

/* typing indicator */

.chat-ai-dots {
	display: inline-flex;
	gap: 4px;
	padding: 5px 2px;
}

.chat-ai-dots span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #b6bad1;
	animation: chat-ai-blink 1.2s infinite;
}

.chat-ai-dots span:nth-child(2) {
	animation-delay: 0.2s;
}

.chat-ai-dots span:nth-child(3) {
	animation-delay: 0.4s;
}

/* -------------------------------- input -------------------------------- */

.chat-ai-input-row {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	background: #fff;
	border-top: 1px solid #eceef5;
}

.chat-ai-input {
	flex: 1;
	min-height: 40px;
	max-height: 120px;
	padding: 9px 12px;
	resize: none;
	border: 1px solid #d9dbe7;
	border-radius: 12px;
	background: #fbfbfd;
	color: #2b2b3a;
	font-family: inherit;
	font-size: 14px;
	line-height: 1.4;
	outline: none;
}

.chat-ai-input:focus {
	border-color: #6a5af9;
	background: #fff;
	box-shadow: 0 0 0 3px rgba(106, 90, 249, 0.15);
}

.chat-ai-input:disabled {
	opacity: 0.6;
}

.chat-ai-send {
	flex: none;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--chat-ai-send-icon-color, #fff);
	background: var(--chat-ai-send-bg, linear-gradient(135deg, #6a5af9 0%, #5248e0 100%));
	transition: transform 0.15s ease, opacity 0.15s ease;
}

.chat-ai-send:hover:not(:disabled) {
	transform: scale(1.06);
}

.chat-ai-send:disabled {
	opacity: 0.5;
	cursor: default;
}

/* ------------------------------ history -------------------------------- */

/* The [hidden] attribute must win over the flex display rules above. */
.chat-ai-messages[hidden],
.chat-ai-input-row[hidden],
.chat-ai-history[hidden] {
	display: none;
}

.chat-ai-history {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-height: 0;
	background: var(--chat-ai-chat-bg, #f6f7fb);
}

.chat-ai-history-head {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 12px;
	background: #fff;
	border-bottom: 1px solid #eceef5;
}

.chat-ai-history-back {
	flex: none;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: #5248e0;
	cursor: pointer;
}

.chat-ai-history-back:hover {
	background: rgba(82, 72, 224, 0.1);
}

.chat-ai-history-title {
	font-size: 13.5px;
	font-weight: 600;
	color: #2b2b3a;
}

.chat-ai-history-list {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain;
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 10px;
}

.chat-ai-history-item {
	display: flex;
	align-items: center;
	gap: 4px;
	background: #fff;
	border: 1px solid #e7e8f0;
	border-radius: 10px;
	padding: 4px 6px 4px 0;
	transition: opacity 0.15s ease;
}

.chat-ai-history-item--deleting {
	opacity: 0.5;
	pointer-events: none;
}

.chat-ai-history-item--error {
	border-color: #f0b6b6;
	background: #fdf3f3;
}

.chat-ai-history-open {
	flex: 1;
	min-width: 0;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 2px;
	padding: 8px 10px;
	border: 0;
	background: transparent;
	text-align: left;
	font-family: inherit;
	cursor: pointer;
}

.chat-ai-history-open:hover .chat-ai-history-item-title {
	color: #5248e0;
}

.chat-ai-history-item-title {
	max-width: 100%;
	font-size: 13px;
	font-weight: 500;
	color: #2b2b3a;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.chat-ai-history-item-time {
	font-size: 11px;
	color: #8a8fa3;
}

.chat-ai-history-delete {
	flex: none;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: #8a8fa3;
	cursor: pointer;
}

.chat-ai-history-delete:hover {
	background: rgba(214, 69, 69, 0.12);
	color: #d64545;
}

.chat-ai-history-note {
	padding: 14px 10px;
	text-align: center;
	font-size: 12.5px;
	color: #8a8fa3;
}

.chat-ai-history-note--error {
	color: #d64545;
}

/* ------------------------------ animations ------------------------------ */

@keyframes chat-ai-blink {
	0%, 80%, 100% {
		opacity: 0.25;
		transform: translateY(0);
	}
	40% {
		opacity: 1;
		transform: translateY(-3px);
	}
}

@keyframes chat-ai-pulse {
	0%, 100% {
		opacity: 0.35;
	}
	50% {
		opacity: 1;
	}
}

/* -------------------------------- mobile -------------------------------- */

@media (max-width: 480px) {
	.chat-ai-launcher {
		right: var(--chat-ai-pos-x, 14px);
		bottom: var(--chat-ai-pos-y, 14px);
	}

	.chat-ai-panel {
		left: 12px;
		right: 12px;
		bottom: calc(var(--chat-ai-pos-y, 14px) + var(--chat-ai-launcher-size, 56px) + 12px);
		width: auto;
		height: calc(100vh - 100px);
		max-height: none;
	}

	/* Keep the full-width sheet anchored on both sides for bottom-left too. */
	.chat-ai-pos-bottom-left .chat-ai-panel {
		left: 12px;
		right: 12px;
	}
}
