/* EvolvingDesk SalesAssist Widget */
#edsa-widget {
	/* Appearance defaults — overridden by inline CSS vars from settings */
	--edsa-primary:          #124CBF;
	--edsa-primary-hover:    #145AE2;
	--edsa-header-bg:        #124CBF;
	--edsa-header-text:      #ffffff;
	--edsa-bubble-user-bg:   #124CBF;
	--edsa-bubble-user-text: #ffffff;
	--edsa-bubble-bot-bg:    #f0f4ff;
	--edsa-bubble-bot-text:  #1A1A1A;
	--edsa-send-btn:         #124CBF;
	--edsa-bg:               #ffffff;
	--edsa-input-border:     #e0e4ef;
	--edsa-radius:           16px;
	--edsa-font:             'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
	--edsa-widget-width:     380px;
	--edsa-widget-height:    580px;
	--edsa-bottom:           24px;
	--edsa-right:            24px;
	--edsa-left:             auto;
	--edsa-shadow:           0 8px 32px rgba(18, 76, 191, 0.18);

	font-family: var(--edsa-font);
	position: fixed;
	bottom: var(--edsa-bottom);
	right: var(--edsa-right);
	left: var(--edsa-left);
	z-index: 999999;
	box-sizing: border-box;
}

#edsa-widget *,
#edsa-widget *::before,
#edsa-widget *::after {
	box-sizing: border-box;
}

/* Launcher button */
#edsa-launcher {
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: var(--edsa-primary);
	color: #fff;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--edsa-shadow);
	transition: background 0.2s, transform 0.2s;
	outline: none;
	position: relative;
	z-index: 1;
}
#edsa-launcher:hover,
#edsa-launcher:focus-visible {
	background: var(--edsa-primary-hover);
	transform: scale(1.06);
}
#edsa-launcher:focus-visible {
	box-shadow: 0 0 0 3px rgba(18,76,191,0.3);
}

/* Chat panel */
#edsa-chat-panel {
	position: absolute;
	bottom: 70px;
	right: 0;
	width: var(--edsa-widget-width);
	max-width: calc(100vw - 32px);
	height: var(--edsa-widget-height);
	max-height: calc(100vh - 120px);
	background: var(--edsa-bg);
	border-radius: var(--edsa-radius);
	box-shadow: var(--edsa-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	transform-origin: bottom right;
	transform: scale(0.95);
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.2s ease, transform 0.2s ease;
}

/* When launcher is on the left, panel opens to the right */
#edsa-widget[style*="--edsa-left"] #edsa-chat-panel {
	right: auto;
	left: 0;
	transform-origin: bottom left;
}

#edsa-chat-panel.edsa-open {
	transform: scale(1);
	opacity: 1;
	pointer-events: all;
}

/* Header */
#edsa-chat-header {
	background: var(--edsa-header-bg);
	color: var(--edsa-header-text);
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-shrink: 0;
}
#edsa-chat-header-info {
	display: flex;
	align-items: center;
	gap: 10px;
}
#edsa-avatar {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: rgba(255,255,255,0.2);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
#edsa-bot-name {
	font-weight: 600;
	font-size: 15px;
	line-height: 1.2;
	color: var(--edsa-header-text);
}
#edsa-bot-status {
	font-size: 12px;
	opacity: 0.82;
	color: var(--edsa-header-text);
}
#edsa-close-btn {
	background: none;
	border: none;
	color: var(--edsa-header-text);
	cursor: pointer;
	padding: 4px;
	border-radius: 6px;
	display: flex;
	opacity: 0.85;
	transition: opacity 0.15s;
}
#edsa-close-btn:hover { opacity: 1; }

/* Messages */
#edsa-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	scroll-behavior: smooth;
}
#edsa-messages::-webkit-scrollbar { width: 4px; }
#edsa-messages::-webkit-scrollbar-track { background: transparent; }
#edsa-messages::-webkit-scrollbar-thumb { background: var(--edsa-input-border); border-radius: 2px; }

.edsa-message-row { display: flex; flex-direction: column; }
.edsa-message-row.edsa-from-user { align-items: flex-end; }
.edsa-message-row.edsa-from-bot  { align-items: flex-start; }

.edsa-bubble {
	max-width: 82%;
	padding: 10px 14px;
	border-radius: 18px;
	font-size: 14px;
	line-height: 1.55;
	word-break: break-word;
	white-space: pre-wrap;
}
.edsa-from-bot .edsa-bubble {
	background: var(--edsa-bubble-bot-bg);
	color: var(--edsa-bubble-bot-text);
	border-bottom-left-radius: 4px;
}
.edsa-from-user .edsa-bubble {
	background: var(--edsa-bubble-user-bg);
	color: var(--edsa-bubble-user-text);
	border-bottom-right-radius: 4px;
}

.edsa-action-btn {
	display: inline-block;
	background: var(--edsa-primary);
	color: #fff !important;
	text-decoration: none;
	padding: 10px 20px;
	border-radius: calc(var(--edsa-radius) * 0.6);
	font-family: var(--edsa-font);
	font-size: 14px;
	font-weight: 600;
	transition: background 0.2s, transform 0.1s;
	cursor: pointer;
	margin-top: 4px;
}
.edsa-action-btn:hover {
	background: var(--edsa-primary-hover);
	transform: translateY(-1px);
	color: #fff !important;
}

.edsa-bubble-tool {
	background: #f0f4ff;
	color: #555;
	font-style: italic;
	font-size: 13px;
	opacity: 0.85;
}

/* Typing indicator */
#edsa-typing {
	padding: 4px 20px 8px;
	display: flex;
	gap: 4px;
	align-items: center;
	flex-shrink: 0;
}
#edsa-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--edsa-primary);
	opacity: 0.4;
	animation: edsa-bounce 1.2s infinite ease-in-out;
}
#edsa-typing span:nth-child(2) { animation-delay: 0.15s; }
#edsa-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes edsa-bounce {
	0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
	40% { transform: translateY(-6px); opacity: 1; }
}

/* Lead form */
#edsa-lead-form-wrap {
	border-top: 1px solid var(--edsa-input-border);
	padding: 16px;
	background: #f9fafb;
	flex-shrink: 0;
}
#edsa-lead-form-header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 8px;
	margin-bottom: 12px;
}
#edsa-lead-form-title {
	font-size: 13px;
	font-weight: 600;
	color: var(--edsa-bubble-bot-text);
	margin: 0;
	flex: 1;
}
#edsa-lead-close {
	background: none;
	border: none;
	cursor: pointer;
	color: #888;
	padding: 2px;
	display: flex;
	flex-shrink: 0;
	border-radius: 4px;
	transition: color 0.15s;
}
#edsa-lead-close:hover { color: #333; }
#edsa-lead-fields { display: flex; flex-direction: column; gap: 8px; }
#edsa-lead-fields input,
#edsa-lead-fields textarea {
	width: 100%;
	padding: 9px 12px;
	border: 1px solid var(--edsa-input-border);
	border-radius: calc(var(--edsa-radius) * 0.6);
	font-family: var(--edsa-font);
	font-size: 13px;
	color: var(--edsa-bubble-bot-text);
	background: var(--edsa-bg);
	transition: border-color 0.15s;
	outline: none;
	resize: none;
}
#edsa-lead-fields input:focus,
#edsa-lead-fields textarea:focus {
	border-color: var(--edsa-primary);
	box-shadow: 0 0 0 2px rgba(18,76,191,0.12);
}
#edsa-lead-submit {
	background: var(--edsa-primary);
	color: #fff;
	border: none;
	border-radius: calc(var(--edsa-radius) * 0.6);
	padding: 10px;
	font-family: var(--edsa-font);
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.2s;
	width: 100%;
}
#edsa-lead-submit:hover { background: var(--edsa-primary-hover); }
#edsa-lead-submit:disabled { opacity: 0.65; cursor: not-allowed; }
#edsa-lead-error { font-size: 12px; color: #c0392b; margin: 0; }
#edsa-lead-success { font-size: 14px; font-weight: 500; color: #1a7a40; text-align: center; padding: 8px 0; }

/* Input area */
#edsa-input-area {
	border-top: 1px solid var(--edsa-input-border);
	padding: 10px 12px;
	background: var(--edsa-bg);
	flex-shrink: 0;
}
#edsa-input-row { display: flex; align-items: flex-end; gap: 8px; }
#edsa-input {
	flex: 1;
	border: 1px solid var(--edsa-input-border);
	border-radius: 12px;
	padding: 9px 12px;
	font-family: var(--edsa-font);
	font-size: 14px;
	color: var(--edsa-bubble-bot-text);
	resize: none;
	outline: none;
	overflow-y: hidden;
	max-height: 120px;
	line-height: 1.4;
	transition: border-color 0.15s;
	background: var(--edsa-bg);
}
#edsa-input:focus {
	border-color: var(--edsa-primary);
	box-shadow: 0 0 0 2px rgba(18,76,191,0.12);
}
#edsa-send-btn {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: var(--edsa-send-btn);
	color: #fff;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background 0.2s;
}
#edsa-send-btn:hover { background: var(--edsa-primary-hover); }
#edsa-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Mobile */
@media (max-width: 480px) {
	#edsa-widget {
		bottom: 16px;
		right: 16px;
		left: auto;
	}
	#edsa-chat-panel {
		bottom: 64px;
		right: -16px;
		left: auto;
		width: 100vw;
		max-width: 100vw;
		height: calc(100vh - 90px);
		border-radius: 16px 16px 0 0;
	}
}