/* OakWrites AI chat widget. Colors and font come from CSS variables set in Settings. */
#owai-chat-root {
	--owai-primary: #1F4D3A;
	--owai-accent: #C8A15A;
	--owai-surface: #FFFFFF;
	--owai-text: #1C2430;
	--owai-font: inherit;
	--owai-muted: #6B7380;
	--owai-line: rgba(28, 36, 48, 0.09);
	--owai-soft: #F5F6F4;
	--owai-radius: 18px;
	position: fixed;
	--owai-bottom: 96px;
	--owai-side: 22px;
	--owai-bottom-mobile: 84px;
	bottom: var(--owai-bottom);
	z-index: 999990;
	font-family: var(--owai-font);
	font-size: 15px;
	line-height: 1.5;
	color: var(--owai-text);
	-webkit-font-smoothing: antialiased;
}
#owai-chat-root *, #owai-chat-root *::before, #owai-chat-root *::after { box-sizing: border-box; }
#owai-chat-root.owai-pos-right { right: var(--owai-side); }
#owai-chat-root.owai-pos-left { left: var(--owai-side); }
/* When open, the panel drops to the normal corner so it never runs off the top of the screen. */
#owai-chat-root.is-open { bottom: 22px; z-index: 2147483000; }

/* Launcher */
#owai-chat-root .owai-launcher {
	display: inline-flex; align-items: center; gap: 10px;
	height: 54px; padding: 0 22px 0 18px; margin: 0;
	border: 0; border-radius: 999px; cursor: pointer;
	background: var(--owai-primary); color: #fff;
	font: 600 15px/1 var(--owai-font); letter-spacing: 0.01em;
	box-shadow: 0 10px 28px rgba(16, 24, 32, 0.22), 0 2px 6px rgba(16, 24, 32, 0.12);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}
#owai-chat-root .owai-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(16, 24, 32, 0.26); }
#owai-chat-root .owai-launcher:focus-visible { outline: 3px solid var(--owai-accent); outline-offset: 3px; }
#owai-chat-root .owai-launcher svg { color: var(--owai-accent); }
#owai-chat-root.is-open .owai-launcher { display: none; }

/* Panel */
#owai-chat-root .owai-panel {
	position: absolute; bottom: 0;
	width: 384px; height: min(640px, calc(100vh - 44px));
	z-index: 2;
	display: flex; flex-direction: column;
	background: var(--owai-surface);
	border: 1px solid var(--owai-line);
	border-radius: var(--owai-radius);
	box-shadow: 0 24px 64px rgba(16, 24, 32, 0.20), 0 4px 14px rgba(16, 24, 32, 0.08);
	overflow: hidden;
	transform-origin: bottom right;
	animation: owai-pop 0.2s ease-out;
}
#owai-chat-root.owai-pos-right .owai-panel { right: 0; }
#owai-chat-root.owai-pos-left .owai-panel { left: 0; transform-origin: bottom left; }
#owai-chat-root .owai-panel[hidden] { display: none; }
#owai-chat-root .owai-panel.is-minimized { height: auto; }
#owai-chat-root .owai-panel.is-minimized .owai-body,
#owai-chat-root .owai-panel.is-minimized .owai-composer,
#owai-chat-root .owai-panel.is-minimized .owai-foot { display: none; }
#owai-chat-root .owai-panel.is-minimized .owai-head { cursor: pointer; }

@keyframes owai-pop { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }

/* Header */
#owai-chat-root .owai-head {
	display: flex; align-items: center; gap: 12px;
	padding: 16px 14px 16px 18px;
	background: var(--owai-primary); color: #fff;
}
#owai-chat-root .owai-avatar {
	flex: 0 0 40px; width: 40px; height: 40px; border-radius: 12px;
	display: grid; place-items: center; overflow: hidden;
	background: rgba(255, 255, 255, 0.14); color: var(--owai-accent);
	font: 700 18px/1 var(--owai-font);
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
#owai-chat-root .owai-avatar img { width: 100%; height: 100%; object-fit: cover; }
#owai-chat-root .owai-head-text { flex: 1; min-width: 0; }
#owai-chat-root .owai-head-name { font-weight: 650; font-size: 15.5px; line-height: 1.25; }
#owai-chat-root .owai-head-sub { display: flex; align-items: center; gap: 6px; font-size: 12.5px; opacity: 0.82; }
#owai-chat-root .owai-online { width: 7px; height: 7px; border-radius: 50%; background: #4ADE80; box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.25); }
#owai-chat-root .owai-head-tools { display: flex; gap: 2px; }
#owai-chat-root .owai-icon-btn {
	width: 34px; height: 34px; padding: 0; margin: 0; border: 0; border-radius: 10px;
	display: grid; place-items: center; cursor: pointer;
	background: transparent; color: rgba(255, 255, 255, 0.85);
	transition: background 0.15s ease, color 0.15s ease;
}
#owai-chat-root .owai-icon-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
#owai-chat-root .owai-icon-btn:focus-visible { outline: 2px solid var(--owai-accent); outline-offset: 1px; }

/* Messages */
#owai-chat-root .owai-body { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--owai-soft); }
#owai-chat-root .owai-messages { flex: 1; overflow-y: auto; padding: 18px 16px 8px; scroll-behavior: smooth; overscroll-behavior: contain; }
#owai-chat-root .owai-msg { display: flex; flex-direction: column; margin: 0 0 12px; max-width: 88%; }
#owai-chat-root .owai-msg-user { margin-left: auto; align-items: flex-end; }
#owai-chat-root .owai-msg-bot { align-items: flex-start; }
#owai-chat-root .owai-in { animation: owai-rise 0.22s ease-out; }
@keyframes owai-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

#owai-chat-root .owai-bubble {
	padding: 11px 14px; border-radius: 16px;
	word-wrap: break-word; overflow-wrap: anywhere;
}
#owai-chat-root .owai-msg-bot .owai-bubble {
	background: var(--owai-surface); color: var(--owai-text);
	border: 1px solid var(--owai-line);
	border-bottom-left-radius: 6px;
	box-shadow: 0 1px 2px rgba(16, 24, 32, 0.04);
}
#owai-chat-root .owai-msg-user .owai-bubble {
	background: var(--owai-primary); color: #fff;
	border-bottom-right-radius: 6px;
	white-space: pre-wrap;
}
#owai-chat-root .owai-bubble p { margin: 0 0 8px; }
#owai-chat-root .owai-bubble p:last-child, #owai-chat-root .owai-bubble ul:last-child, #owai-chat-root .owai-bubble ol:last-child { margin-bottom: 0; }
#owai-chat-root .owai-bubble ul, #owai-chat-root .owai-bubble ol { margin: 4px 0 8px; padding-left: 20px; }
#owai-chat-root .owai-bubble li { margin: 2px 0; }
#owai-chat-root .owai-bubble strong { font-weight: 650; }
#owai-chat-root .owai-bubble a { color: var(--owai-primary); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--owai-accent); }
#owai-chat-root .owai-msg-user .owai-bubble a { color: #fff; }

/* CTAs */
#owai-chat-root .owai-ctas { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
#owai-chat-root .owai-cta {
	display: inline-flex; align-items: center;
	padding: 7px 13px; border-radius: 999px;
	background: var(--owai-surface); color: var(--owai-primary);
	border: 1px solid var(--owai-primary);
	font-size: 13px; font-weight: 600; text-decoration: none; line-height: 1.2;
	transition: background 0.15s ease, color 0.15s ease;
}
#owai-chat-root .owai-cta:hover, #owai-chat-root .owai-cta:focus-visible { background: var(--owai-primary); color: #fff; outline: none; }

/* Typing */
#owai-chat-root .owai-typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
#owai-chat-root .owai-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--owai-muted); opacity: 0.4; animation: owai-blink 1.2s infinite ease-in-out; }
#owai-chat-root .owai-typing span:nth-child(2) { animation-delay: 0.15s; }
#owai-chat-root .owai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes owai-blink { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 0.9; transform: translateY(-3px); } }

/* Suggestions */
#owai-chat-root .owai-suggestions { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 16px 12px; }
#owai-chat-root .owai-suggestions[hidden] { display: none; }
#owai-chat-root .owai-chip {
	margin: 0; padding: 8px 12px; border-radius: 12px; cursor: pointer;
	background: var(--owai-surface); color: var(--owai-text);
	border: 1px solid var(--owai-line);
	font: 500 13px/1.3 var(--owai-font); text-align: left;
	transition: border-color 0.15s ease, color 0.15s ease;
}
#owai-chat-root .owai-chip:hover, #owai-chat-root .owai-chip:focus-visible { border-color: var(--owai-primary); color: var(--owai-primary); outline: none; }

/* Composer */
#owai-chat-root .owai-composer {
	display: flex; align-items: flex-end; gap: 8px; margin: 0;
	padding: 12px 12px 10px 14px;
	border-top: 1px solid var(--owai-line);
	background: var(--owai-surface);
}
#owai-chat-root .owai-input {
	flex: 1; resize: none; margin: 0;
	min-height: 42px; max-height: 120px;
	padding: 10px 12px; border-radius: 12px;
	border: 1px solid var(--owai-line); background: var(--owai-soft);
	color: var(--owai-text); font: 15px/1.4 var(--owai-font);
	box-shadow: none; outline: none;
	transition: border-color 0.15s ease, background 0.15s ease;
}
#owai-chat-root .owai-input:focus { border-color: var(--owai-primary); background: var(--owai-surface); }
#owai-chat-root .owai-send {
	flex: 0 0 42px; width: 42px; height: 42px; padding: 0; margin: 0;
	border: 0; border-radius: 12px; cursor: pointer;
	display: grid; place-items: center;
	background: var(--owai-primary); color: #fff;
	transition: opacity 0.15s ease, transform 0.15s ease;
}
#owai-chat-root .owai-send:hover { transform: translateY(-1px); }
#owai-chat-root .owai-send:disabled { opacity: 0.5; cursor: default; transform: none; }
#owai-chat-root .owai-send:focus-visible { outline: 2px solid var(--owai-accent); outline-offset: 2px; }
#owai-chat-root .owai-foot { padding: 0 14px 10px; font-size: 11px; color: var(--owai-muted); text-align: center; background: var(--owai-surface); }

/* Mobile */
@media (max-width: 640px) {
	#owai-chat-root { bottom: var(--owai-bottom-mobile); }
	#owai-chat-root.is-open { bottom: 14px; }
	#owai-chat-root.owai-pos-right { right: min(var(--owai-side), 14px); }
	#owai-chat-root.owai-pos-left { left: min(var(--owai-side), 14px); }
	#owai-chat-root .owai-launcher { height: 50px; padding: 0 18px 0 15px; }
	#owai-chat-root.is-open .owai-panel {
		position: fixed; inset: 0; width: 100%; height: 100%;
		height: 100dvh; border-radius: 0; border: 0;
	}
	#owai-chat-root .owai-panel.is-minimized { inset: auto 0 0 0; height: auto; border-radius: 16px 16px 0 0; }
	#owai-chat-root .owai-input { font-size: 16px; }
	#owai-chat-root .owai-msg { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
	#owai-chat-root *, #owai-chat-root *::before, #owai-chat-root *::after { animation: none !important; transition: none !important; }
}

@media print { #owai-chat-root { display: none !important; } }

/* ---------- Live team takeover ---------- */
#owai-chat-root .owai-launcher { position: relative; }
#owai-chat-root .owai-badge {
	position: absolute; top: -4px; right: -4px;
	min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
	display: grid; place-items: center;
	background: #DC2626; color: #fff; font: 700 11px/1 var(--owai-font);
	box-shadow: 0 0 0 2px var(--owai-surface);
}
#owai-chat-root .owai-badge[hidden] { display: none; }
#owai-chat-root .owai-launcher.owai-has-unread { animation: owai-nudge 2.4s ease-in-out 2; }
@keyframes owai-nudge { 0%, 100% { transform: none; } 10% { transform: translateY(-4px); } 20% { transform: none; } }

#owai-chat-root .owai-avatar-human { background: var(--owai-accent); color: var(--owai-primary); }
#owai-chat-root .owai-online.owai-waiting { background: var(--owai-accent); box-shadow: 0 0 0 2px rgba(200, 161, 90, 0.35); animation: owai-pulse 1.4s infinite; }
@keyframes owai-pulse { 50% { opacity: 0.4; } }

#owai-chat-root .owai-msg-name { font-size: 11.5px; font-weight: 600; color: var(--owai-muted); margin: 0 0 3px 4px; }
#owai-chat-root .owai-msg-agent { align-items: flex-start; }
#owai-chat-root .owai-msg-agent .owai-bubble {
	background: var(--owai-surface); color: var(--owai-text);
	border: 1px solid var(--owai-accent);
	border-left: 3px solid var(--owai-accent);
	border-bottom-left-radius: 6px;
}
#owai-chat-root .owai-msg-system { max-width: 100%; align-items: center; margin: 4px auto 14px; }
#owai-chat-root .owai-msg-system .owai-bubble {
	background: transparent; border: 0; padding: 6px 12px;
	color: var(--owai-muted); font-size: 13px; text-align: center;
}
#owai-chat-root .owai-msg-system .owai-ctas { justify-content: center; }

#owai-chat-root .owai-foot { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#owai-chat-root .owai-human-btn {
	display: inline-flex; align-items: center; gap: 5px;
	margin: 0; padding: 5px 12px; border-radius: 999px; cursor: pointer;
	background: transparent; color: var(--owai-primary);
	border: 1px solid var(--owai-line);
	font: 600 12px/1.2 var(--owai-font);
	transition: border-color 0.15s ease;
}
#owai-chat-root .owai-human-btn:hover, #owai-chat-root .owai-human-btn:focus-visible { border-color: var(--owai-primary); outline: none; }
#owai-chat-root .owai-human-btn[hidden] { display: none; }
