/*
 * Chat IQ front-end widget. All classes prefixed civ- (Chat IQ Visitor) so
 * they never collide with a theme's own CSS. Colors/position come from
 * inline custom properties set by chat-iq-widget.js from the /config response.
 */

#chat-iq-root {
	--civ-primary: #0f8577;
	--civ-accent: #3ec4b2;
	--civ-on-primary: #ffffff;
	--civ-radius: 16px;
	--civ-offset-x: 20px;
	--civ-offset-y: 20px;
	--civ-bg: #ffffff;
	--civ-surface: #f7f7f8;
	--civ-ink: #14181c;
	--civ-muted: #6b7280;
	--civ-line: #e7e7ea;
	position: fixed;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#chat-iq-root[data-theme="dark"] {
	--civ-bg: #1b2026;
	--civ-surface: #242a31;
	--civ-ink: #f2f4f6;
	--civ-muted: #9aa4af;
	--civ-line: #333b44;
}
@media (prefers-color-scheme: dark) {
	#chat-iq-root[data-theme="auto"] {
		--civ-bg: #1b2026;
		--civ-surface: #242a31;
		--civ-ink: #f2f4f6;
		--civ-muted: #9aa4af;
		--civ-line: #333b44;
	}
}

#chat-iq-root[data-position="bottom-right"] { right: var(--civ-offset-x); bottom: var(--civ-offset-y); }
#chat-iq-root[data-position="bottom-left"] { left: var(--civ-offset-x); bottom: var(--civ-offset-y); }

#chat-iq-root[data-radius="square"] { --civ-radius: 4px; }
#chat-iq-root[data-radius="soft"] { --civ-radius: 10px; }

.civ-launcher {
	display: flex; align-items: center; gap: 8px;
	background: var(--civ-primary); color: var(--civ-on-primary);
	border: none; border-radius: 999px; cursor: pointer;
	width: 60px; height: 60px; justify-content: center;
	box-shadow: 0 6px 20px rgba(0,0,0,.2);
	transition: transform .15s ease;
	padding: 0;
}
.civ-launcher:hover { transform: scale(1.05); }
.civ-launcher--labeled { width: auto; padding: 0 18px 0 16px; border-radius: 30px; }
.civ-launcher__icon { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; font-size: 22px; line-height: 1; }
.civ-launcher__icon img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.civ-launcher__label { font-size: 14px; font-weight: 600; white-space: nowrap; }
.civ-launcher__badge {
	position: absolute; top: -4px; right: -4px; background: #e0483c; color: var(--civ-on-primary);
	border-radius: 999px; font-size: 10px; min-width: 16px; height: 16px; display: flex;
	align-items: center; justify-content: center; padding: 0 4px; font-weight: 700;
}

.civ-window {
	position: absolute; bottom: 76px; width: 380px; max-width: calc(100vw - 32px);
	height: min(620px, calc(100vh - 120px));
	background: var(--civ-bg); border-radius: var(--civ-radius);
	box-shadow: 0 12px 40px rgba(0,0,0,.25);
	display: none; flex-direction: column; overflow: hidden;
	border: 1px solid var(--civ-line);
}
#chat-iq-root[data-position="bottom-right"] .civ-window { right: 0; }
#chat-iq-root[data-position="bottom-left"] .civ-window { left: 0; }
.civ-window.is-open { display: flex; }

.civ-header {
	background: var(--civ-primary); color: var(--civ-on-primary);
	padding: 18px 18px 16px; flex-shrink: 0;
}
.civ-header__top { display: flex; justify-content: space-between; align-items: flex-start; }
.civ-header__title { font-size: 17px; font-weight: 700; margin: 0; }
.civ-header__subtitle { font-size: 12.5px; opacity: .85; margin: 4px 0 0; }
.civ-header__close, .civ-header__icon-btn {
	background: rgba(255,255,255,.15); border: none; color: inherit;
	width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
}
.civ-header__close { font-size: 16px; line-height: 1; }
.civ-header__icon-btn { display: flex; align-items: center; justify-content: center; }
.civ-header__icon-btn:hover { background: rgba(255,255,255,.28); }
.civ-header__status { font-size: 11px; opacity: .8; margin-top: 6px; display: flex; align-items: center; gap: 5px; }
.civ-header__dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; }
.civ-header__dot.is-offline { background: #f59e0b; }
.civ-header__btns { display: flex; gap: 6px; flex-shrink: 0; }
.civ-transcript-form {
	/* display:none by default, not the [hidden] attribute — a class selector
	   and [hidden] share specificity, and this rule would otherwise win the
	   cascade (it loads after the UA stylesheet) and show the form on every
	   load regardless of the attribute. is-open is the only thing that shows it. */
	display: none; gap: 6px; margin-top: 10px;
}
.civ-transcript-form.is-open { display: flex; }
.civ-transcript-input { flex: 1; border: none; border-radius: 8px; padding: 7px 10px; font-size: 12.5px; background: rgba(255,255,255,.92); color: var(--civ-ink); }
.civ-transcript-send { background: rgba(255,255,255,.2); border: none; color: inherit; border-radius: 8px; padding: 7px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.civ-transcript-send:hover { background: rgba(255,255,255,.32); }

.civ-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--civ-surface); }

.civ-msg { max-width: 82%; display: flex; flex-direction: column; gap: 3px; }
.civ-msg--visitor { align-self: flex-end; align-items: flex-end; }
.civ-msg--bot, .civ-msg--agent, .civ-msg--agent-typing { align-self: flex-start; align-items: flex-start; }
.civ-msg__row { display: flex; gap: 8px; align-items: flex-end; }
.civ-msg--visitor .civ-msg__row { flex-direction: row-reverse; }
.civ-avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--civ-primary); color: var(--civ-on-primary); display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; overflow: hidden; }
.civ-avatar img { width: 100%; height: 100%; object-fit: cover; }
.civ-bubble { padding: 9px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.civ-msg--visitor .civ-bubble { background: var(--civ-primary); color: var(--civ-on-primary); border-bottom-right-radius: 4px; }
.civ-msg--bot .civ-bubble, .civ-msg--agent .civ-bubble, .civ-msg--agent-typing .civ-bubble { background: var(--civ-bg); color: var(--civ-ink); border: 1px solid var(--civ-line); border-bottom-left-radius: 4px; }
.civ-msg__author { font-size: 11px; font-weight: 600; color: var(--civ-muted); padding: 0 4px; }
.civ-msg__link { color: var(--civ-primary); font-weight: 600; text-decoration: underline; text-decoration-color: var(--civ-accent); text-underline-offset: 2px; word-break: break-all; }
.civ-msg--visitor .civ-msg__link { color: var(--civ-on-primary); text-decoration-color: currentColor; }
.civ-msg__link:hover { text-decoration-thickness: 2px; }

.civ-status-note { align-self: flex-end; font-size: 11px; color: var(--civ-muted); padding: 0 4px; }

.civ-typing-wrap { align-self: flex-start; }
.civ-typing { display: flex; gap: 4px; padding: 10px 13px; }
.civ-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--civ-muted); animation: civ-bounce 1.2s infinite ease-in-out; }
.civ-typing span:nth-child(2) { animation-delay: .15s; }
.civ-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes civ-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.civ-quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.civ-quick-btn {
	background: var(--civ-bg); border: 1px solid var(--civ-primary); color: var(--civ-primary);
	border-radius: 999px; padding: 6px 12px; font-size: 12.5px; cursor: pointer; font-weight: 600;
}
.civ-quick-btn:hover { background: var(--civ-primary); color: var(--civ-on-primary); }

/* A solid pill, not a bare underlined link — this is the one real next step
   once the AI has offered a handoff, so it should read as a clear call to
   action, not an afterthought hanging off the bottom of the reply. */
.civ-handoff-btn {
	align-self: flex-start; background: var(--civ-primary); border: none; color: var(--civ-on-primary);
	border-radius: 999px; font-size: 12.5px; font-weight: 600; cursor: pointer;
	padding: 7px 14px; margin-top: 2px; transition: transform .1s ease, opacity .15s ease;
}
.civ-handoff-btn:hover { opacity: .9; }
.civ-handoff-btn:active { transform: scale(.97); }

.civ-footer { border-top: 1px solid var(--civ-line); padding: 10px; flex-shrink: 0; background: var(--civ-bg); }
.civ-form { display: flex; gap: 8px; align-items: flex-end; }
.civ-input {
	flex: 1; resize: none; border: 1px solid var(--civ-line); border-radius: 20px;
	padding: 9px 14px; font-size: 13.5px; font-family: inherit; max-height: 90px;
	background: var(--civ-surface); color: var(--civ-ink);
}
.civ-input:focus { outline: none; border-color: var(--civ-primary); }
.civ-send {
	background: var(--civ-primary); color: var(--civ-on-primary); border: none; border-radius: 50%;
	width: 36px; height: 36px; flex-shrink: 0; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.civ-send:disabled { opacity: .5; cursor: default; }
.civ-branding { text-align: center; font-size: 10.5px; color: var(--civ-muted); padding: 6px 0 2px; }
.civ-branding a { color: inherit; }

.civ-csat { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px; background: var(--civ-bg); border: 1px solid var(--civ-line); border-radius: 12px; align-self: center; }
.civ-csat__stars { display: flex; gap: 4px; }
.civ-csat__star { font-size: 22px; cursor: pointer; color: var(--civ-line); background: none; border: none; }
.civ-csat__star.is-active, .civ-csat__star:hover { color: #f5a623; }

@media (max-width: 480px) {
	.civ-window { width: 100vw; height: 100vh; max-width: 100vw; border-radius: 0; bottom: 0; right: 0; left: 0; position: fixed; top: 0; }
	#chat-iq-root { right: var(--civ-offset-x); bottom: var(--civ-offset-y); }
}
