/* AI Chatbot widget — ChatGPT-style, self-contained. Theme colour is overridden
   at runtime via inline CSS custom properties set on .aichat-root by the JS. */
.aichat-root { --aic-em: #059669; --aic-em-d: #047857; --aic-em-rgb: 5,150,105; --aic-bg: #ffffff; --aic-fg: #1f2937; --aic-muted: #6b7280; --aic-border: #e5e7eb; --aic-soft: #f3f4f6; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif; box-sizing: border-box; }
.aichat-root *, .aichat-root *::before, .aichat-root *::after { box-sizing: border-box; }

/* Inline embed */
.aichat-root--inline { width: 100%; max-width: 720px; margin: 1rem auto; }
.aichat-root--inline .aichat-panel { height: 600px; }

/* Floating launcher — WhatsApp-style circular toggle button.
   The button is ALWAYS visible. Clicking it toggles the panel open/closed
   and swaps the icon between a chat bubble (closed) and an X (open). */
.aichat-root--floating { position: fixed; z-index: 99999; bottom: 20px; right: 20px; }
.aichat-launcher { width: 60px; height: 60px; border-radius: 50%; background: var(--aic-em); color: #fff; border: none; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.25), 0 8px 24px rgba(var(--aic-em-rgb),.4); display: flex; align-items: center; justify-content: center; transition: transform .2s, box-shadow .2s, background .2s; position: relative; padding: 0; }
.aichat-launcher:hover { transform: scale(1.08); box-shadow: 0 6px 16px rgba(0,0,0,.3), 0 10px 28px rgba(var(--aic-em-rgb),.5); }
.aichat-launcher:active { transform: scale(0.94); }
.aichat-launcher:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.aichat-launcher svg { width: 30px; height: 30px; fill: #fff; }
/* Two stacked icons — CSS toggles which one is visible based on .aichat-open */
.aichat-launcher .aichat-ico-chat { display: block; }
.aichat-launcher .aichat-ico-close { display: none; }
.aichat-root--floating.aichat-open .aichat-launcher { background: var(--aic-em-d); }
.aichat-root--floating.aichat-open .aichat-launcher .aichat-ico-chat { display: none; }
.aichat-root--floating.aichat-open .aichat-launcher .aichat-ico-close { display: block; }
/* Gentle attention pulse on first load (plays once) */
.aichat-launcher::after { content: ''; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--aic-em); opacity: 0; animation: aichat-pulse 2.5s ease-out 1s 2; pointer-events: none; }
@keyframes aichat-pulse { 0% { opacity: .6; transform: scale(1); } 100% { opacity: 0; transform: scale(1.6); } }
/* Panel sits ABOVE the launcher button (bottom offset = button height + gap) */
.aichat-root--floating .aichat-panel { display: none; width: 380px; height: 560px; position: absolute; bottom: 72px; right: 0; }
.aichat-root--floating.aichat-open .aichat-panel { display: flex; animation: aichat-pop .25s ease; }
@keyframes aichat-pop { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@media (max-width: 480px) {
        .aichat-root--floating { bottom: 16px; right: 16px; }
        .aichat-root--floating .aichat-panel { width: calc(100vw - 32px); height: calc(100vh - 140px); right: 0; bottom: 72px; }
}

/* Panel */
.aichat-panel { display: flex; flex-direction: column; background: var(--aic-bg); border: 1px solid var(--aic-border); border-radius: 16px; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.08); }

/* Header */
.aichat-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: linear-gradient(135deg, var(--aic-em), var(--aic-em-d)); color: #fff; }
.aichat-header-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.aichat-avatar { width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center; position: relative; flex-shrink: 0; }
.aichat-avatar svg { width: 20px; height: 20px; }
.aichat-status-dot { position: absolute; bottom: -1px; right: -1px; width: 11px; height: 11px; border-radius: 50%; background: #6ee7b7; border: 2px solid var(--aic-em); }
.aichat-title { font-weight: 600; font-size: 14px; line-height: 1.2; }
.aichat-subtitle { font-size: 11px; opacity: .85; line-height: 1.2; }
.aichat-header-actions { display: flex; gap: 4px; }
.aichat-icon-btn { background: transparent; border: none; color: #fff; cursor: pointer; width: 30px; height: 30px; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.aichat-icon-btn:hover { background: rgba(255,255,255,.2); }
.aichat-icon-btn svg { width: 16px; height: 16px; }

/* Messages */
.aichat-messages { flex: 1; overflow-y: auto; padding: 16px; background: var(--aic-soft); scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
.aichat-messages::-webkit-scrollbar { width: 8px; }
.aichat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 9999px; }
.aichat-msg { display: flex; gap: 10px; margin-bottom: 16px; }
.aichat-msg--user { flex-direction: row-reverse; }
.aichat-msg-avatar { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 2px; }
.aichat-msg-avatar svg { width: 16px; height: 16px; }
.aichat-msg--user .aichat-msg-avatar { background: rgba(var(--aic-em-rgb),.15); color: var(--aic-em-d); }
.aichat-msg--assistant .aichat-msg-avatar { background: linear-gradient(135deg, var(--aic-em), var(--aic-em-d)); color: #fff; }
.aichat-msg-body { max-width: 80%; display: flex; flex-direction: column; gap: 4px; }
.aichat-msg--user .aichat-msg-body { align-items: flex-end; }
.aichat-bubble { padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.55; word-break: break-word; }
.aichat-msg--user .aichat-bubble { background: var(--aic-em); color: #fff; border-bottom-right-radius: 4px; }
.aichat-msg--assistant .aichat-bubble { background: var(--aic-bg); border: 1px solid var(--aic-border); border-bottom-left-radius: 4px; }
.aichat-msg--error .aichat-bubble { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.aichat-meta { font-size: 10px; color: var(--aic-muted); padding: 0 4px; }

/* Markdown inside bubble */
.aichat-bubble p { margin: 0 0 8px; }
.aichat-bubble p:last-child { margin-bottom: 0; }
.aichat-bubble ul, .aichat-bubble ol { margin: 0 0 8px; padding-left: 20px; }
.aichat-bubble code { background: var(--aic-soft); padding: 2px 5px; border-radius: 4px; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.aichat-bubble pre { background: var(--aic-soft); padding: 10px; border-radius: 6px; overflow-x: auto; margin: 0 0 8px; }
.aichat-bubble pre code { background: none; padding: 0; }
.aichat-bubble a { color: var(--aic-em-d); }
.aichat-bubble strong { font-weight: 600; }

/* Typing indicator */
.aichat-typing { display: flex; gap: 4px; padding: 4px 0; }
.aichat-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--aic-em); animation: aichat-bounce 1.2s infinite; }
.aichat-typing span:nth-child(2) { animation-delay: .15s; }
.aichat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes aichat-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Input */
.aichat-input-wrap { padding: 12px; border-top: 1px solid var(--aic-border); background: var(--aic-bg); }
.aichat-error-banner { display: none; align-items: flex-start; gap: 6px; font-size: 12px; color: #b91c1c; background: #fef2f2; border-radius: 6px; padding: 6px 8px; margin-bottom: 8px; }
.aichat-error-banner.is-visible { display: flex; }
.aichat-input-row { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--aic-border); border-radius: 12px; background: var(--aic-bg); }
.aichat-input-row:focus-within { border-color: var(--aic-em); box-shadow: 0 0 0 3px rgba(var(--aic-em-rgb),.15); }
.aichat-textarea { flex: 1; border: none; outline: none; resize: none; padding: 12px; font-size: 14px; font-family: inherit; line-height: 1.4; min-height: 44px; max-height: 160px; background: transparent; color: var(--aic-fg); }
.aichat-send { margin: 4px; background: var(--aic-em); color: #fff; border: none; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.aichat-send:disabled { opacity: .4; cursor: not-allowed; }
.aichat-send svg { width: 18px; height: 18px; fill: currentColor; }
.aichat-input-foot { display: flex; justify-content: space-between; padding: 4px 4px 0; font-size: 11px; color: var(--aic-muted); }
.aichat-input-foot svg { width: 12px; height: 12px; vertical-align: -2px; }
