/**
 * AI Chatbot Widget — Stylesheet
 * @package     mod_aichatbot
 * @copyright   Copyright (c) 2025. Jeroen Moolenschot | Joomill
 * @license     GNU General Public License version 3 or later
 */

/* ============================================================
   CSS Custom Properties
   ============================================================ */
.joomill-aichatbot {
	--aichatbot-primary:       #0d6efd;
	--aichatbot-primary-dark:  color-mix(in srgb, var(--aichatbot-primary) 80%, black);
	--aichatbot-bg:            #ffffff;
	--aichatbot-surface:       #f8f9fa;
	--aichatbot-border:        #dee2e6;
	--aichatbot-text:          #212529;
	--aichatbot-text-muted:    #6c757d;
	--aichatbot-user-bg:       var(--aichatbot-primary);
	--aichatbot-user-text:     #ffffff;
	--aichatbot-bot-bg:        #f1f3f5;
	--aichatbot-bot-text:      var(--aichatbot-text);
	--aichatbot-radius:        16px;
	--aichatbot-radius-sm:     8px;
	--aichatbot-shadow:        0 8px 32px rgba(0, 0, 0, 0.18);
	--aichatbot-z:             9999;
	--aichatbot-toggle-size:   56px;
	--aichatbot-window-width:  370px;
	--aichatbot-window-height: 520px;
}

/* ============================================================
   Positioning Container
   ============================================================ */
.joomill-aichatbot {
	position: fixed;
	bottom: 24px;
	z-index: var(--aichatbot-z);
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	font-size: 15px;
	line-height: 1.5;
}

.joomill-aichatbot--bottom-right {
	right: 24px;
}

.joomill-aichatbot--bottom-left {
	left: 24px;
}

/* ============================================================
   Toggle Button
   ============================================================ */
.joomill-aichatbot__toggle {
	width: var(--aichatbot-toggle-size);
	height: var(--aichatbot-toggle-size);
	border-radius: 50%;
	background-color: var(--aichatbot-primary);
	border: none;
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--aichatbot-shadow);
	transition: background-color 0.2s ease, transform 0.2s ease;
	padding: 0;
	outline-offset: 3px;
}

.joomill-aichatbot__toggle:hover {
	background-color: var(--aichatbot-primary-dark);
	transform: scale(1.06);
}

.joomill-aichatbot__toggle:focus-visible {
	outline: 3px solid var(--aichatbot-primary);
}

.joomill-aichatbot__toggle svg {
	width: 26px;
	height: 26px;
	pointer-events: none;
}

/* Show/hide icons based on open state */
.joomill-aichatbot__icon-close {
	display: none;
}

.joomill-aichatbot--open .joomill-aichatbot__icon-open {
	display: none;
}

.joomill-aichatbot--open .joomill-aichatbot__icon-close {
	display: block;
}

/* ============================================================
   Chat Window
   ============================================================ */
.joomill-aichatbot__window {
	position: absolute;
	bottom: calc(var(--aichatbot-toggle-size) + 12px);
	width: var(--aichatbot-window-width);
	height: var(--aichatbot-window-height);
	background: var(--aichatbot-bg);
	border-radius: var(--aichatbot-radius);
	box-shadow: var(--aichatbot-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	border: 1px solid var(--aichatbot-border);
	transform-origin: bottom right;
	animation: aichatbot-open 0.22s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.joomill-aichatbot--bottom-right .joomill-aichatbot__window {
	right: 0;
	transform-origin: bottom right;
}

.joomill-aichatbot--bottom-left .joomill-aichatbot__window {
	left: 0;
	transform-origin: bottom left;
}

.joomill-aichatbot__window[hidden] {
	display: none;
}

@keyframes aichatbot-open {
	from {
		opacity: 0;
		transform: scale(0.85) translateY(12px);
	}
	to {
		opacity: 1;
		transform: scale(1) translateY(0);
	}
}

/* ============================================================
   Header
   ============================================================ */
.joomill-aichatbot__header {
	background: var(--aichatbot-primary);
	color: #fff;
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-shrink: 0;
}

.joomill-aichatbot__header-info {
	display: flex;
	align-items: center;
	gap: 10px;
}

.joomill-aichatbot__avatar {
	width: 36px;
	height: 36px;
	background: rgba(255, 255, 255, 0.25);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.joomill-aichatbot__avatar svg {
	width: 20px;
	height: 20px;
}

.joomill-aichatbot__title {
	font-weight: 600;
	font-size: 15px;
	letter-spacing: 0.01em;
}

.joomill-aichatbot__close-btn {
	background: transparent;
	border: none;
	color: rgba(255, 255, 255, 0.85);
	cursor: pointer;
	padding: 4px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background-color 0.15s;
}

.joomill-aichatbot__close-btn:hover {
	background: rgba(255, 255, 255, 0.2);
	color: #fff;
}

.joomill-aichatbot__close-btn svg {
	width: 20px;
	height: 20px;
}

/* ============================================================
   Messages Area
   ============================================================ */
.joomill-aichatbot__messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	scroll-behavior: smooth;
	background: var(--aichatbot-surface);
}

.joomill-aichatbot__messages::-webkit-scrollbar {
	width: 5px;
}

.joomill-aichatbot__messages::-webkit-scrollbar-thumb {
	background: var(--aichatbot-border);
	border-radius: 3px;
}

/* Individual message bubble */
.joomill-aichatbot__message {
	max-width: 82%;
	padding: 10px 14px;
	border-radius: var(--aichatbot-radius);
	word-break: break-word;
	line-height: 1.55;
	animation: aichatbot-msg-in 0.18s ease forwards;
}

@keyframes aichatbot-msg-in {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.joomill-aichatbot__message--user {
	background: var(--aichatbot-user-bg);
	color: var(--aichatbot-user-text);
	align-self: flex-end;
	border-bottom-right-radius: var(--aichatbot-radius-sm);
}

.joomill-aichatbot__message--assistant {
	background: var(--aichatbot-bot-bg);
	color: var(--aichatbot-bot-text);
	align-self: flex-start;
	border-bottom-left-radius: var(--aichatbot-radius-sm);
}

/* Typing indicator */
.joomill-aichatbot__typing {
	display: flex;
	align-items: center;
	gap: 5px;
	padding: 12px 16px;
	background: var(--aichatbot-bot-bg);
	border-radius: var(--aichatbot-radius);
	border-bottom-left-radius: var(--aichatbot-radius-sm);
	align-self: flex-start;
}

.joomill-aichatbot__typing span {
	width: 7px;
	height: 7px;
	background: var(--aichatbot-text-muted);
	border-radius: 50%;
	animation: aichatbot-bounce 1.2s infinite ease-in-out;
}

.joomill-aichatbot__typing span:nth-child(1) { animation-delay: 0s; }
.joomill-aichatbot__typing span:nth-child(2) { animation-delay: 0.2s; }
.joomill-aichatbot__typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aichatbot-bounce {
	0%, 60%, 100% { transform: translateY(0); }
	30%           { transform: translateY(-6px); }
}

/* ============================================================
   Input Area
   ============================================================ */
.joomill-aichatbot__input-area {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 14px;
	border-top: 1px solid var(--aichatbot-border);
	background: var(--aichatbot-bg);
	flex-shrink: 0;
}

.joomill-aichatbot__input {
	flex: 1;
	border: 1px solid var(--aichatbot-border);
	border-radius: var(--aichatbot-radius);
	padding: 9px 13px;
	font-size: 14px;
	font-family: inherit;
	resize: none;
	outline: none;
	min-height: 40px;
	max-height: 120px;
	overflow-y: auto;
	transition: border-color 0.15s;
	color: var(--aichatbot-text);
	background: var(--aichatbot-bg);
}

.joomill-aichatbot__input:focus {
	border-color: var(--aichatbot-primary);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--aichatbot-primary) 20%, transparent);
}

.joomill-aichatbot__send-btn {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: var(--aichatbot-primary);
	border: none;
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background-color 0.15s, transform 0.15s;
	padding: 0;
}

.joomill-aichatbot__send-btn:hover:not(:disabled) {
	background: var(--aichatbot-primary-dark);
	transform: scale(1.05);
}

.joomill-aichatbot__send-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.joomill-aichatbot__send-btn svg {
	width: 20px;
	height: 20px;
}

/* ============================================================
   Footer
   ============================================================ */
.joomill-aichatbot__footer {
	text-align: center;
	padding: 5px 12px 8px;
	background: var(--aichatbot-bg);
	flex-shrink: 0;
}

.joomill-aichatbot__footer a {
	font-size: 11px;
	color: var(--aichatbot-text-muted);
	text-decoration: none;
	opacity: 0.7;
}

.joomill-aichatbot__footer a:hover {
	opacity: 1;
}

/* ============================================================
   Error state
   ============================================================ */
.joomill-aichatbot__message--error {
	background: #fff3cd;
	color: #856404;
	border: 1px solid #ffc107;
	align-self: flex-start;
}

/* ============================================================
   Sources / contact bar (shown below assistant messages)
   ============================================================ */
.joomill-aichatbot__sources {
	font-size: 0.78em;
	color: #888;
	padding: 4px 12px 8px;
	line-height: 1.6;
}

.joomill-aichatbot__sources-label {
	display: block;
	font-weight: 600;
	margin-bottom: 2px;
	color: #666;
}

.joomill-aichatbot__sources-link {
	display: inline-block;
	margin-right: 8px;
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.joomill-aichatbot__sources-link:hover {
	color: #444;
}

.joomill-aichatbot__sources-link--contact {
	font-weight: 600;
}

/* ============================================================
   Responsive: full-screen on very small viewports
   ============================================================ */
@media (max-width: 430px) {
	.joomill-aichatbot__window {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		width: 100%;
		height: 100dvh;
		border-radius: 0;
	}

	.joomill-aichatbot--bottom-right .joomill-aichatbot__window,
	.joomill-aichatbot--bottom-left .joomill-aichatbot__window {
		right: 0;
		left: 0;
	}
}
