/*
 * AuthorWings AI Chatbot widget.
 *
 * A floating launcher + slide-up chat panel in the AuthorWings palette — deep
 * navy, terracotta accent and warm cream — self-contained with no theme
 * dependency. The palette lives in CSS custom properties on the widget root, so
 * a site can override any of them by re-declaring --awgc-* on .awg-aig-chat.
 */

.awg-aig-chat {
	--awgc-ink: #10243c;        /* deep navy (headers, launcher, user bubble) */
	--awgc-ink-hover: #1b3a5c;  /* lighter navy on hover */
	--awgc-gold: #c8794f;       /* terracotta accent (send, avatar, focus) */
	--awgc-gold-deep: #a85a34;  /* deeper terracotta (links) */
	--awgc-gold-soft: #d68a63;  /* lighter terracotta (send hover) */
	--awgc-paper: #fdfaf3;      /* near-white cream (bubbles, inputs) */
	--awgc-cream: #f2ead9;      /* warm cream card background */
	--awgc-sand: #efe6d6;       /* soft cream tint (chips, scrollbar) */
	--awgc-line: #e5dac4;       /* soft cream border */
	--awgc-text: #33291c;       /* deep warm brown body text */
	--awgc-muted: #8b7e6f;      /* muted warm gray */
	--awgc-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	--awgc-serif: 'Lora', 'Cormorant Garamond', Georgia, Cambria, "Times New Roman", Times, serif;

	position: fixed;
	bottom: 24px;
	z-index: 99990;
	font-family: var(--awgc-sans);
	line-height: 1.5;
}

.awg-aig-chat--right { right: 24px; }
.awg-aig-chat--left { left: 24px; }

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

.awg-aig-chat__launcher {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 60px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 999px;
	cursor: pointer;
	color: var(--awgc-paper);
	background: var(--awgc-ink);
	box-shadow: 0 14px 34px -12px rgba(16, 36, 60, 0.55);
	transition: transform .2s ease, background .2s ease, box-shadow .2s ease;
}

.awg-aig-chat__launcher:hover,
.awg-aig-chat__launcher:focus-visible {
	transform: translateY(-2px);
	background: var(--awgc-ink-hover);
	outline: none;
}

.awg-aig-chat__launcher:focus-visible {
	box-shadow: 0 0 0 3px rgba(200, 121, 79, 0.55), 0 14px 34px -12px rgba(16, 36, 60, 0.55);
}

.awg-aig-chat__launcher::after {
	content: "";
	position: absolute;
	top: 6px;
	right: 6px;
	width: 12px;
	height: 12px;
	border-radius: 999px;
	background: var(--awgc-gold);
	border: 2px solid var(--awgc-ink);
	transition: opacity .2s ease, transform .2s ease;
}

.awg-aig-chat__launcher-icon,
.awg-aig-chat__launcher-close {
	display: inline-flex;
	transition: opacity .18s ease, transform .18s ease;
}

.awg-aig-chat__launcher-close {
	position: absolute;
	opacity: 0;
	transform: rotate(-90deg) scale(.6);
}

.awg-aig-chat[data-state="open"] .awg-aig-chat__launcher-icon {
	opacity: 0;
	transform: rotate(90deg) scale(.6);
}
.awg-aig-chat[data-state="open"] .awg-aig-chat__launcher-close {
	opacity: 1;
	transform: rotate(0) scale(1);
}
.awg-aig-chat[data-state="open"] .awg-aig-chat__launcher::after { opacity: 0; }

/* --------------------------------------------------------------- Greeting */

.awg-aig-chat__greeting {
	position: absolute;
	bottom: 74px;
	/* Explicit width: the launcher's fixed container is only ~60px wide, so an
	   auto-width bubble would shrink-to-fit and wrap one word per line. A set
	   width makes it a proper speech bubble that extends away from the corner. */
	width: 264px;
	max-width: calc(100vw - 48px);
	box-sizing: border-box;
	padding: 13px 38px 13px 16px;
	font-size: .9rem;
	line-height: 1.45;
	color: var(--awgc-text);
	background: var(--awgc-paper);
	border: 1px solid var(--awgc-line);
	border-radius: 16px;
	box-shadow: 0 16px 40px -20px rgba(16, 36, 60, 0.5);
	cursor: pointer;
	animation: awgc-pop .35s ease both;
}
.awg-aig-chat--right .awg-aig-chat__greeting { right: 2px; border-bottom-right-radius: 5px; }
.awg-aig-chat--left .awg-aig-chat__greeting { left: 2px; border-bottom-left-radius: 5px; }

.awg-aig-chat__greeting-close {
	position: absolute;
	top: 8px;
	right: 8px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	border: 0;
	border-radius: 999px;
	background: var(--awgc-sand);
	color: var(--awgc-muted);
	font-size: 15px;
	line-height: 1;
	cursor: pointer;
	padding: 0;
	transition: background .15s ease, color .15s ease;
}
.awg-aig-chat__greeting-close:hover { background: var(--awgc-line); color: var(--awgc-ink); }

.awg-aig-chat[data-state="open"] .awg-aig-chat__greeting,
.awg-aig-chat.awg-aig-chat--greeted .awg-aig-chat__greeting { display: none; }

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

.awg-aig-chat__panel {
	position: absolute;
	bottom: 74px;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 560px;
	max-height: calc(100vh - 120px);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: var(--awgc-cream);
	border: 1px solid var(--awgc-line);
	border-radius: 18px;
	box-shadow: 0 30px 70px -28px rgba(16, 36, 60, 0.6);
	opacity: 0;
	transform: translateY(14px) scale(.98);
	transform-origin: bottom right;
	transition: opacity .22s ease, transform .22s ease;
	pointer-events: none;
}
.awg-aig-chat--right .awg-aig-chat__panel { right: 0; }
.awg-aig-chat--left .awg-aig-chat__panel { left: 0; transform-origin: bottom left; }

.awg-aig-chat[data-state="open"] .awg-aig-chat__panel {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* Header */
.awg-aig-chat__header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 14px 14px 16px;
	color: var(--awgc-paper);
	background: var(--awgc-ink);
	background-image: radial-gradient(120% 140% at 0% 0%, rgba(200, 121, 79, 0.28), transparent 55%);
}

.awg-aig-chat__avatar {
	flex: 0 0 auto;
	width: 40px;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 999px;
	font-family: var(--awgc-serif);
	font-weight: 600;
	font-size: .95rem;
	letter-spacing: .02em;
	color: var(--awgc-ink);
	background: #ffffff;
}

.awg-aig-chat__heading { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.awg-aig-chat__title {
	font-family: var(--awgc-serif);
	font-size: 1.06rem;
	font-weight: 600;
	color: var(--awgc-paper);
}
.awg-aig-chat__status {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: .76rem;
	color: rgba(254, 252, 246, 0.72);
}
.awg-aig-chat__dot {
	width: 7px;
	height: 7px;
	border-radius: 999px;
	background: #74c47c;
	box-shadow: 0 0 0 0 rgba(116, 196, 124, 0.6);
	animation: awgc-pulse 2.4s infinite;
}

.awg-aig-chat__close {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	border: 0;
	border-radius: 999px;
	cursor: pointer;
	color: rgba(254, 252, 246, 0.85);
	background: rgba(255, 255, 255, 0.08);
	transition: background .18s ease, color .18s ease;
}
.awg-aig-chat__close:hover { background: rgba(255, 255, 255, 0.16); color: #fff; }

/* Message log */
.awg-aig-chat__log {
	flex: 1 1 auto;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 18px 16px 6px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	scroll-behavior: smooth;
	overscroll-behavior: contain;
}

.awg-aig-chat__msg {
	max-width: 84%;
	padding: 10px 14px;
	font-size: .92rem;
	border-radius: 16px;
	white-space: pre-wrap;
	word-wrap: break-word;
	overflow-wrap: anywhere;
	animation: awgc-rise .25s ease both;
}
.awg-aig-chat__msg a { color: var(--awgc-gold-deep); text-decoration: underline; }

.awg-aig-chat__msg--bot {
	align-self: flex-start;
	color: var(--awgc-text);
	background: var(--awgc-paper);
	border: 1px solid var(--awgc-line);
	border-bottom-left-radius: 5px;
}
.awg-aig-chat__msg--user {
	align-self: flex-end;
	color: var(--awgc-paper);
	background: var(--awgc-ink);
	border-bottom-right-radius: 5px;
}
.awg-aig-chat__msg--error {
	align-self: flex-start;
	color: #7a2c1c;
	background: #f7e4de;
	border: 1px solid #e9c6ba;
	border-bottom-left-radius: 5px;
}
.awg-aig-chat__msg p { margin: 0 0 8px; }
.awg-aig-chat__msg p:last-child { margin-bottom: 0; }
.awg-aig-chat__msg ul,
.awg-aig-chat__msg ol { margin: 4px 0 8px; padding-left: 20px; }
.awg-aig-chat__msg li { margin: 2px 0; }

/* Suggested-question chips */
.awg-aig-chat__suggestions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 2px 0 4px;
	align-self: stretch;
	animation: awgc-rise .25s ease both;
}
.awg-aig-chat__chip {
	appearance: none;
	cursor: pointer;
	font-family: inherit;
	font-size: .84rem;
	line-height: 1.3;
	padding: 8px 13px;
	color: var(--awgc-gold-deep);
	background: var(--awgc-paper);
	border: 1px solid var(--awgc-line);
	border-radius: 999px;
	transition: background .16s ease, border-color .16s ease, transform .12s ease;
}
.awg-aig-chat__chip:hover,
.awg-aig-chat__chip:focus-visible {
	background: var(--awgc-sand);
	border-color: var(--awgc-gold);
	outline: none;
	transform: translateY(-1px);
}

/* Typing indicator */
.awg-aig-chat__typing {
	align-self: flex-start;
	display: inline-flex;
	gap: 4px;
	padding: 13px 15px;
	background: var(--awgc-paper);
	border: 1px solid var(--awgc-line);
	border-radius: 16px;
	border-bottom-left-radius: 5px;
}
.awg-aig-chat__typing span {
	width: 7px;
	height: 7px;
	border-radius: 999px;
	background: var(--awgc-muted);
	opacity: .5;
	animation: awgc-bounce 1.2s infinite;
}
.awg-aig-chat__typing span:nth-child(2) { animation-delay: .18s; }
.awg-aig-chat__typing span:nth-child(3) { animation-delay: .36s; }

/* Composer */
.awg-aig-chat__form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 12px 10px;
	border-top: 1px solid var(--awgc-line);
	background: var(--awgc-cream);
}
.awg-aig-chat__input {
	flex: 1 1 auto;
	resize: none;
	max-height: 120px;
	padding: 10px 14px;
	font-family: inherit;
	font-size: .92rem;
	line-height: 1.45;
	color: var(--awgc-text);
	background: var(--awgc-paper);
	border: 1px solid var(--awgc-line);
	border-radius: 14px;
	outline: none;
	transition: border-color .18s ease, box-shadow .18s ease;
}
.awg-aig-chat__input:focus {
	border-color: var(--awgc-gold);
	box-shadow: 0 0 0 3px rgba(200, 121, 79, 0.18);
}
.awg-aig-chat__input::placeholder { color: var(--awgc-muted); }

.awg-aig-chat__send {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	border: 0;
	border-radius: 13px;
	cursor: pointer;
	color: var(--awgc-ink);
	background: var(--awgc-gold);
	transition: transform .15s ease, background .18s ease, opacity .18s ease;
}
.awg-aig-chat__send:hover { background: var(--awgc-gold-soft); transform: translateY(-1px); }
.awg-aig-chat__send:disabled { opacity: .5; cursor: default; transform: none; }
.awg-aig-chat__send:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(200, 121, 79, 0.5); }

/* The close (×) and send (➤) buttons are display:inline-flex and hold their
   <svg> as a direct flex child. The SVG's width/height="20" are only
   presentation attributes, so a theme's global `svg { max-width: 100%;
   height: auto }` rule can override them; flexbox then collapses the icon to
   0x0 and it disappears. Size the SVG here — class specificity beats a bare
   `svg` selector — so both icons stay 20x20 and centred by the button. */
.awg-aig-chat__close svg,
.awg-aig-chat__send svg {
	display: block;
	flex: 0 0 auto;
	width: 20px;
	height: 20px;
	pointer-events: none;
}

.awg-aig-chat__footer {
	padding: 0 14px 10px;
	font-size: .68rem;
	text-align: center;
	color: var(--awgc-muted);
	background: var(--awgc-cream);
}

/* Scrollbar */
.awg-aig-chat__log::-webkit-scrollbar { width: 8px; }
.awg-aig-chat__log::-webkit-scrollbar-thumb { background: var(--awgc-sand); border-radius: 999px; }
.awg-aig-chat__log::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------- Motion */

@keyframes awgc-rise {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: translateY(0); }
}
@keyframes awgc-pop {
	from { opacity: 0; transform: translateY(10px) scale(.96); }
	to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes awgc-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: .5; }
	30% { transform: translateY(-5px); opacity: 1; }
}
@keyframes awgc-pulse {
	0% { box-shadow: 0 0 0 0 rgba(116, 196, 124, 0.55); }
	70% { box-shadow: 0 0 0 6px rgba(116, 196, 124, 0); }
	100% { box-shadow: 0 0 0 0 rgba(116, 196, 124, 0); }
}

/* --------------------------------------------------------------- Responsive */

@media (max-width: 480px) {
	.awg-aig-chat { bottom: 16px; }
	.awg-aig-chat--right { right: 16px; }
	.awg-aig-chat--left { left: 16px; }
	.awg-aig-chat__panel {
		width: calc(100vw - 24px);
		height: calc(100vh - 96px);
		bottom: 76px;
	}
	.awg-aig-chat--right .awg-aig-chat__panel { right: -4px; }
	.awg-aig-chat--left .awg-aig-chat__panel { left: -4px; }
}

@media (prefers-reduced-motion: reduce) {
	.awg-aig-chat__launcher,
	.awg-aig-chat__panel,
	.awg-aig-chat__msg,
	.awg-aig-chat__greeting,
	.awg-aig-chat__dot,
	.awg-aig-chat__typing span,
	.awg-aig-chat__launcher-icon,
	.awg-aig-chat__launcher-close {
		animation: none !important;
		transition: none !important;
	}
}

.awg-aig-chat .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	border: 0;
}
