/**
 * Digital Solution AI — chat widget styles.
 * Colors, radius, width and font size come from CSS custom properties
 * injected by the plugin (Appearance settings).
 */

#dsai-root {
	--dsai-primary: #1d4ed8;
	--dsai-secondary: #0f172a;
	--dsai-button: #1d4ed8;
	--dsai-text: #0f172a;
	--dsai-bg: #f8fafc;
	--dsai-radius: 16px;
	--dsai-font-size: 15px;
	--dsai-width: 380px;
	position: fixed;
	bottom: 20px;
	z-index: 99999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Devanagari", "Noto Sans", sans-serif;
	font-size: var(--dsai-font-size);
	line-height: 1.5;
	color: var(--dsai-text);
}

#dsai-root[data-position="right"] { right: 20px; }
#dsai-root[data-position="left"] { left: 20px; }

#dsai-root *,
#dsai-root *::before,
#dsai-root *::after { box-sizing: border-box; }

.dsai-visually-hidden {
	position: absolute !important;
	width: 1px; height: 1px;
	margin: -1px; padding: 0; border: 0;
	clip: rect(0 0 0 0); overflow: hidden; white-space: nowrap;
}

/* Launcher --------------------------------------------------------------- */

.dsai-launcher {
	display: flex;
	align-items: center;
	gap: 10px;
	border: none;
	cursor: pointer;
	background: var(--dsai-button);
	color: #fff;
	padding: 13px 20px;
	border-radius: 999px;
	font-size: 15px;
	font-weight: 600;
	box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.dsai-launcher:hover,
.dsai-launcher:focus-visible {
	transform: translateY(-2px);
	box-shadow: 0 12px 28px rgba(15, 23, 42, 0.3);
}

.dsai-launcher:focus-visible {
	outline: 3px solid rgba(29, 78, 216, 0.5);
	outline-offset: 2px;
}

/* Panel ------------------------------------------------------------------ */

.dsai-panel {
	display: flex;
	flex-direction: column;
	width: var(--dsai-width);
	max-width: calc(100vw - 32px);
	height: 600px;
	max-height: calc(100vh - 110px);
	max-height: calc(100dvh - 110px);
	margin-bottom: 14px;
	background: var(--dsai-bg);
	border-radius: var(--dsai-radius);
	box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
	overflow: hidden;
}

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

/* Header ----------------------------------------------------------------- */

.dsai-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	background: linear-gradient(135deg, var(--dsai-primary), var(--dsai-secondary));
	color: #fff;
}

.dsai-avatar {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	object-fit: cover;
	background: rgba(255, 255, 255, 0.18);
	flex-shrink: 0;
}

.dsai-avatar-fallback {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	font-size: 14px;
	color: #fff;
}

.dsai-header-meta {
	display: flex;
	flex-direction: column;
	min-width: 0;
	flex: 1;
}

.dsai-title {
	font-weight: 700;
	font-size: 15px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.dsai-status {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	opacity: 0.85;
}

.dsai-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #34d399;
	box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.25);
}

.dsai-header-actions { display: flex; gap: 4px; }

.dsai-icon-btn {
	border: none;
	background: rgba(255, 255, 255, 0.14);
	color: #fff;
	width: 30px;
	height: 30px;
	border-radius: 8px;
	cursor: pointer;
	font-size: 14px;
	line-height: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.dsai-icon-btn:hover,
.dsai-icon-btn:focus-visible { background: rgba(255, 255, 255, 0.28); }

.dsai-icon-btn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* Messages --------------------------------------------------------------- */

.dsai-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
}

.dsai-msg { display: flex; flex-direction: column; max-width: 88%; }
.dsai-msg-user { align-self: flex-end; align-items: flex-end; }
.dsai-msg-bot { align-self: flex-start; align-items: flex-start; }

.dsai-bubble {
	padding: 10px 14px;
	border-radius: 14px;
	word-break: break-word;
	overflow-wrap: anywhere;
}

.dsai-msg-user .dsai-bubble {
	background: var(--dsai-primary);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.dsai-msg-bot .dsai-bubble {
	background: #fff;
	color: var(--dsai-text);
	border: 1px solid rgba(15, 23, 42, 0.08);
	border-bottom-left-radius: 4px;
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.dsai-bubble p { margin: 0 0 8px; }
.dsai-bubble p:last-child { margin-bottom: 0; }
.dsai-bubble ul { margin: 4px 0; padding-left: 20px; }
.dsai-bubble li { margin: 2px 0; }

/* Outcome states --------------------------------------------------------- */

/* Upstream/service failure — visually distinct from a genuine "no match". */
.dsai-msg-bot .dsai-bubble-unavailable {
	background: #fff7ed;
	border-color: #fed7aa;
}

.dsai-outage-note {
	margin-top: 8px;
	padding-top: 8px;
	border-top: 1px dashed #fdba74;
	font-size: 12px;
	color: #9a3412;
}

/* Knowledge base had no verified answer — informational, not an error. */
.dsai-msg-bot .dsai-bubble-noanswer {
	background: #f8fafc;
	border-color: #cbd5e1;
}

.dsai-retry { margin-top: 8px; }
.dsai-retry-btn:disabled { opacity: 0.5; cursor: default; }

/* Typing indicator ------------------------------------------------------- */

.dsai-typing { display: inline-flex; gap: 5px; padding: 14px 16px; }
.dsai-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: rgba(15, 23, 42, 0.35);
	animation: dsai-bounce 1.2s infinite ease-in-out;
}
.dsai-typing span:nth-child(2) { animation-delay: 0.15s; }
.dsai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dsai-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
	30% { transform: translateY(-5px); opacity: 1; }
}

/* Sources & freshness ---------------------------------------------------- */

.dsai-sources {
	margin-top: 8px;
	padding: 10px 12px;
	background: rgba(29, 78, 216, 0.06);
	border-radius: 10px;
	font-size: 13px;
	width: 100%;
}

.dsai-sources-title {
	font-weight: 700;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	opacity: 0.7;
	margin-bottom: 4px;
}

.dsai-sources-list { margin: 0; padding-left: 18px; }
.dsai-sources-list a { color: var(--dsai-primary); text-decoration: underline; }
.dsai-updated { margin-top: 6px; font-size: 11px; opacity: 0.65; }

/* CTA -------------------------------------------------------------------- */

.dsai-cta { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.dsai-cta-text { width: 100%; font-size: 13px; font-weight: 600; }

.dsai-cta-btn {
	display: inline-flex;
	align-items: center;
	padding: 8px 14px;
	border-radius: 999px;
	background: var(--dsai-primary);
	color: #fff !important;
	text-decoration: none !important;
	font-size: 13px;
	font-weight: 600;
}

.dsai-cta-whatsapp { background: #25d366; }

/* Lead form -------------------------------------------------------------- */

.dsai-lead-form {
	margin-top: 10px;
	width: 100%;
	display: flex;
	flex-direction: column;
	gap: 8px;
	background: #fff;
	border: 1px solid rgba(15, 23, 42, 0.1);
	border-radius: 12px;
	padding: 12px;
}

.dsai-lead-input {
	border: 1px solid rgba(15, 23, 42, 0.15);
	border-radius: 8px;
	padding: 9px 12px;
	font: inherit;
	width: 100%;
}

.dsai-lead-input:focus {
	outline: none;
	border-color: var(--dsai-primary);
	box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.dsai-lead-form .dsai-cta-btn { border: none; cursor: pointer; justify-content: center; }
.dsai-lead-done { font-weight: 600; color: #047857; }

/* Feedback --------------------------------------------------------------- */

.dsai-feedback { margin-top: 6px; display: flex; gap: 6px; }
.dsai-fb-btn {
	border: 1px solid rgba(15, 23, 42, 0.12);
	background: #fff;
	border-radius: 8px;
	padding: 4px 10px;
	cursor: pointer;
	font-size: 14px;
}
.dsai-fb-btn:hover { background: rgba(15, 23, 42, 0.05); }
.dsai-fb-thanks { font-size: 12px; opacity: 0.7; }

/* Suggestions ------------------------------------------------------------ */

.dsai-suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.dsai-chip {
	border: 1px solid rgba(29, 78, 216, 0.35);
	background: #fff;
	color: var(--dsai-primary);
	border-radius: 999px;
	padding: 7px 14px;
	font-size: 13px;
	cursor: pointer;
	transition: background 0.12s ease;
	min-height: 34px;
}

.dsai-chip:hover,
.dsai-chip:focus-visible { background: rgba(29, 78, 216, 0.08); }

/* Composer --------------------------------------------------------------- */

.dsai-composer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	background: #fff;
	border-top: 1px solid rgba(15, 23, 42, 0.08);
}

.dsai-input {
	flex: 1;
	resize: none;
	border: 1px solid rgba(15, 23, 42, 0.15);
	border-radius: 12px;
	padding: 10px 14px;
	font: inherit;
	color: inherit;
	max-height: 120px;
	background: var(--dsai-bg);
}

.dsai-input:focus {
	outline: none;
	border-color: var(--dsai-primary);
	box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

.dsai-send {
	border: none;
	background: var(--dsai-button);
	color: #fff;
	width: 42px;
	height: 42px;
	border-radius: 12px;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.dsai-send:hover { filter: brightness(1.08); }
.dsai-send:focus-visible { outline: 3px solid rgba(29, 78, 216, 0.4); outline-offset: 2px; }

.dsai-disclaimer {
	padding: 6px 14px 10px;
	background: #fff;
	font-size: 11px;
	opacity: 0.6;
	text-align: center;
}

/* Mobile ----------------------------------------------------------------- */

@media (max-width: 480px) {
	#dsai-root[data-position="right"],
	#dsai-root[data-position="left"] { right: 12px; left: 12px; bottom: 12px; }

	.dsai-panel {
		width: 100%;
		max-width: none;
		height: calc(100dvh - 90px);
		max-height: none;
	}

	.dsai-launcher { margin-left: auto; }
	.dsai-launcher-label { display: none; }
	.dsai-launcher { padding: 15px; }
}

@media (prefers-reduced-motion: reduce) {
	#dsai-root * { animation: none !important; transition: none !important; }
}
