/* AI Chatbot for n8n — widget styles (scoped under #n8nac-root) */
#n8nac-root {
	--n8nac-primary: #e2f460;
	--n8nac-on-primary: #2f3503;
	--n8nac-secondary: #2f3503;
	--n8nac-accent: #2f3503;
	--n8nac-bg: #ffffff;
	--n8nac-surface: #f3f4f6;
	--n8nac-text: #111827;
	--n8nac-muted: #6b7280;
	--n8nac-border: #e5e7eb;
	position: fixed;
	bottom: 20px;
	z-index: 2147483000;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.45;
	color: var(--n8nac-text);
}
#n8nac-root.n8nac-pos-right { right: 20px; }
#n8nac-root.n8nac-pos-left  { left: 20px; }
#n8nac-root *, #n8nac-root *::before, #n8nac-root *::after { box-sizing: border-box; }

#n8nac-root button { font: inherit; cursor: pointer; margin: 0; }

/* Launcher */
#n8nac-root .n8nac-launcher {
	width: 58px; height: 58px; border-radius: 50%;
	border: 0; padding: 0;
	background: var(--n8nac-primary); color: var(--n8nac-on-primary);
	display: flex; align-items: center; justify-content: center;
	box-shadow: 0 8px 24px rgba(0,0,0,.18);
	position: relative;
	transition: transform .15s ease, box-shadow .15s ease;
	margin-left: auto;
}
#n8nac-root.n8nac-pos-left .n8nac-launcher { margin-left: 0; }
#n8nac-root .n8nac-launcher:hover { transform: scale(1.05); box-shadow: 0 10px 28px rgba(0,0,0,.22); }
#n8nac-root .n8nac-launcher:focus-visible { outline: 3px solid rgba(0,0,0,.35); outline-offset: 3px; }

/* Panel */
#n8nac-root .n8nac-panel {
	position: absolute; bottom: 74px;
	width: 370px; height: 560px; max-height: calc(100vh - 110px);
	background: var(--n8nac-bg);
	border-radius: 16px;
	box-shadow: 0 16px 48px rgba(0,0,0,.2);
	display: flex; flex-direction: column; overflow: hidden;
	opacity: 0; transform: translateY(12px) scale(.98); pointer-events: none; visibility: hidden;
	transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s;
}
#n8nac-root.n8nac-pos-right .n8nac-panel { right: 0; }
#n8nac-root.n8nac-pos-left  .n8nac-panel { left: 0; }
#n8nac-root.n8nac-open .n8nac-panel {
	opacity: 1; transform: none; pointer-events: auto; visibility: visible;
	transition: opacity .18s ease, transform .18s ease;
}

/* Header */
#n8nac-root .n8nac-header {
	display: flex; align-items: center; gap: 10px;
	padding: 14px 14px 14px 16px;
	background: var(--n8nac-primary); color: var(--n8nac-on-primary);
}
#n8nac-root .n8nac-avatar {
	width: 36px; height: 36px; border-radius: 50%; flex: none;
	background: color-mix(in srgb, var(--n8nac-on-primary) 16%, transparent);
	display: flex; align-items: center; justify-content: center; font-weight: 700;
	overflow: hidden;
}
#n8nac-root .n8nac-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; background: #fff; }
#n8nac-root .n8nac-titles { flex: 1; min-width: 0; }
#n8nac-root .n8nac-title { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#n8nac-root .n8nac-sub { font-size: 12.5px; opacity: .85; }
#n8nac-root .n8nac-close {
	background: transparent; border: 0; color: var(--n8nac-on-primary); padding: 6px; border-radius: 8px;
	display: flex; opacity: .9;
}
#n8nac-root .n8nac-close:hover { background: color-mix(in srgb, var(--n8nac-on-primary) 14%, transparent); opacity: 1; }

/* Messages */
#n8nac-root .n8nac-messages {
	flex: 1; overflow-y: auto; padding: 16px 14px;
	display: flex; flex-direction: column; gap: 8px;
	background: var(--n8nac-bg);
	overscroll-behavior: contain;
}
#n8nac-root .n8nac-msg {
	max-width: 85%; padding: 9px 13px; border-radius: 16px;
	word-wrap: break-word; overflow-wrap: anywhere; white-space: normal;
}
#n8nac-root .n8nac-bot {
	align-self: flex-start; background: var(--n8nac-surface); color: var(--n8nac-text);
	border-bottom-left-radius: 4px;
}
#n8nac-root .n8nac-user {
	align-self: flex-end; background: var(--n8nac-primary); color: var(--n8nac-on-primary);
	border-bottom-right-radius: 4px; white-space: pre-wrap;
}
#n8nac-root .n8nac-error { /* friendly "busy" message: same look as a normal reply */ }
#n8nac-root .n8nac-msg a { color: inherit; text-decoration: underline; }
#n8nac-root .n8nac-li { display: block; padding-left: 14px; position: relative; }
#n8nac-root .n8nac-li::before { content: "•"; position: absolute; left: 2px; }

/* Typing indicator */
#n8nac-root .n8nac-typing { display: flex; gap: 4px; padding: 13px 14px; }
#n8nac-root .n8nac-typing span {
	width: 7px; height: 7px; border-radius: 50%; background: var(--n8nac-muted);
	animation: n8nac-bounce 1.2s infinite ease-in-out;
}
#n8nac-root .n8nac-typing span:nth-child(2) { animation-delay: .15s; }
#n8nac-root .n8nac-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes n8nac-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Quick replies */
#n8nac-root .n8nac-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
#n8nac-root .n8nac-chip {
	background: var(--n8nac-bg); color: var(--n8nac-accent);
	border: 1px solid var(--n8nac-accent); border-radius: 999px;
	padding: 6px 12px; font-size: 13.5px; line-height: 1.2;
}
#n8nac-root .n8nac-chip:hover { background: var(--n8nac-primary); color: var(--n8nac-on-primary); border-color: var(--n8nac-primary); }

/* Input */
#n8nac-root .n8nac-form {
	display: flex; align-items: flex-end; gap: 8px;
	padding: 10px 10px 10px 14px; border-top: 1px solid var(--n8nac-border);
	background: var(--n8nac-bg); margin: 0;
}
#n8nac-root .n8nac-input {
	flex: 1; resize: none; border: 0; outline: none; background: transparent;
	font: inherit; color: var(--n8nac-text); padding: 8px 0; margin: 0;
	max-height: 120px; min-height: 22px; box-shadow: none; line-height: 1.4;
}
#n8nac-root .n8nac-input::placeholder { color: var(--n8nac-muted); }
#n8nac-root .n8nac-send {
	width: 40px; height: 40px; border-radius: 50%; border: 0; padding: 0; flex: none;
	background: var(--n8nac-primary); color: var(--n8nac-on-primary);
	display: flex; align-items: center; justify-content: center;
}
#n8nac-root .n8nac-send:disabled { opacity: .5; cursor: default; }
#n8nac-root .n8nac-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }

/* Launcher icon / logo */
#n8nac-root .n8nac-launcher-icon { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; border-radius: 50%; overflow: hidden; }
#n8nac-root .n8nac-has-logo .n8nac-launcher-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
#n8nac-root .n8nac-has-logo { background: #fff; }

/* Notification badge */
#n8nac-root .n8nac-badge {
	position: absolute; top: -3px; right: -3px;
	min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
	background: #ef4444; color: #fff; border: 2px solid #fff;
	font-size: 11px; font-weight: 700; line-height: 16px; text-align: center;
	animation: n8nac-pop .35s ease-out;
}

/* Pulse ring around launcher */
#n8nac-root.n8nac-attn .n8nac-launcher::before,
#n8nac-root.n8nac-attn .n8nac-launcher::after {
	content: ""; position: absolute; inset: 0; border-radius: 50%;
	border: 2px solid var(--n8nac-accent); pointer-events: none;
	animation: n8nac-ring 2.2s ease-out infinite;
}
#n8nac-root.n8nac-attn .n8nac-launcher::after { animation-delay: 1.1s; }
#n8nac-root.n8nac-attn .n8nac-launcher { animation: n8nac-wiggle 5s ease-in-out 1.5s infinite; }
@keyframes n8nac-ring { 0% { transform: scale(1); opacity: .55; } 100% { transform: scale(1.7); opacity: 0; } }
@keyframes n8nac-wiggle { 0%, 88%, 100% { transform: rotate(0); } 90% { transform: rotate(-12deg); } 93% { transform: rotate(10deg); } 96% { transform: rotate(-6deg); } }
@keyframes n8nac-pop { 0% { transform: scale(0); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* Greeting popup */
#n8nac-root .n8nac-teaser {
	position: absolute; bottom: 72px; width: max-content; max-width: min(280px, calc(100vw - 40px));
	display: flex; align-items: flex-start; gap: 4px;
	background: #fff; color: var(--n8nac-text);
	border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.16);
	padding: 4px 4px 4px 0;
	opacity: 0; transform: translateY(8px) scale(.96); visibility: hidden; pointer-events: none;
	transition: opacity .25s ease, transform .25s ease, visibility 0s linear .25s;
}
#n8nac-root.n8nac-pos-right .n8nac-teaser { right: 0; border-bottom-right-radius: 4px; }
#n8nac-root.n8nac-pos-left  .n8nac-teaser { left: 0;  border-bottom-left-radius: 4px; }
#n8nac-root.n8nac-teaser-on:not(.n8nac-open) .n8nac-teaser {
	opacity: 1; transform: none; visibility: visible; pointer-events: auto;
	transition: opacity .25s ease, transform .25s ease;
}
#n8nac-root .n8nac-teaser-text {
	background: none; border: 0; text-align: left; color: inherit;
	padding: 9px 4px 9px 14px; font-size: 14px; line-height: 1.4;
}
#n8nac-root .n8nac-teaser-close {
	background: none; border: 0; color: var(--n8nac-muted);
	width: 24px; height: 24px; border-radius: 50%; font-size: 18px; line-height: 1; padding: 0; flex: none;
}
#n8nac-root .n8nac-teaser-close:hover { background: var(--n8nac-surface); color: var(--n8nac-text); }

/* Mobile: full screen */
@media (max-width: 480px) {
	#n8nac-root { bottom: 16px; }
	#n8nac-root.n8nac-pos-right { right: 16px; }
	#n8nac-root.n8nac-pos-left  { left: 16px; }
	#n8nac-root .n8nac-panel {
		position: fixed; inset: 0; width: 100%; height: 100%; max-height: none; border-radius: 0;
	}
	#n8nac-root.n8nac-open .n8nac-launcher { display: none; }
	#n8nac-root .n8nac-input { font-size: 16px; } /* prevents iOS zoom */
}

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

/* Admin preview bar */
#n8nac-root .n8nac-preview-bar { background: #fef3c7; color: #78350f; font-size: 12px; text-align: center; padding: 5px 10px; }
