/* ===== Live chat widget =====
   Floating launcher bottom-right + sliding panel.
   Self-contained — no theme dependency. */

.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1080;
    font-family: inherit;
}

.chat-launcher {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ai-accent);
    color: #fff;
    border: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
    position: relative;
}
.chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(0,0,0,.22); }

.chat-launcher-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    border-radius: 999px;
    font-size: 11px;
    line-height: 1;
    padding: 4px 6px;
    min-width: 20px;
    text-align: center;
}

.chat-panel {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 340px;
    max-width: calc(100vw - 32px);
    height: 480px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatPop .15s ease-out;
}
@keyframes chatPop {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-header {
    background: var(--ai-dark, #3A2D22);
    border-bottom: 3px solid var(--ai-accent-2, #B87333);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
}
.chat-header .chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.18);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.chat-status { font-size: 11px; opacity: .85; }
.chat-status.live { color: #d1fae5; }
.chat-status.offline { color: #fecaca; }

.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
}
.chat-prechat { background: #fff; }
.chat-thread  { background: #f8fafc; }

.chat-messages { display: flex; flex-direction: column; gap: 8px; }

.chat-msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 8px;
    line-height: 1.4;
    word-break: break-word;
    white-space: pre-wrap;
    font-size: 13px;
}
.chat-msg.visitor { background: var(--ai-accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-msg.agent   { background: #fff; color: #111827; align-self: flex-start; border-bottom-left-radius: 4px; border: 1px solid #e5e7eb; }
/* Not italic. It used to be, back when the only bot message was a one-line "an agent will join
   you shortly" aside. The assistant now writes the substantive answers, and a whole paragraph
   set in italics reads as a footnote rather than as the reply. */
.chat-msg.bot     { background: var(--ai-cream); color: var(--ai-dark); align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-msg a { color: inherit; text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.chat-msg-meta { font-size: 10px; color: #6b7280; margin-top: 2px; }
.chat-msg.visitor + .chat-msg-meta { text-align: right; }

/* Typing indicator — shown while the assistant is composing.
   The answer takes a couple of seconds; without this the panel just sits there and the visitor
   cannot tell the difference between "thinking" and "broken". Shaped and positioned like a bot
   bubble so the real answer appears to land where the dots were. */
.chat-typing {
    align-self: flex-start;
    background: var(--ai-cream);
    border-radius: 8px;
    border-bottom-left-radius: 4px;
    padding: 10px 14px;
    display: flex;
    gap: 4px;
    align-items: center;
}
.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #B87333;
    animation: chat-typing-bounce 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0);    opacity: .45; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* Respect the OS setting — a looping animation is exactly what this is for. */
@media (prefers-reduced-motion: reduce) {
    .chat-typing span { animation: none; opacity: .7; }
}

.chat-composer {
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: #fff;
}
.chat-composer textarea {
    resize: none;
    max-height: 100px;
}

/* WhatsApp click-to-chat (wa.me). Darker WhatsApp green so the icon and label pass contrast on white. */
.wa-green { color: #128C7E; }
.chat-widget .chat-or {
    display: flex; align-items: center; gap: .5rem;
    margin: .75rem 0; color: #8a8178; font-size: .75rem;
}
.chat-widget .chat-or::before,
.chat-widget .chat-or::after { content: ""; flex: 1; border-top: 1px solid #e6dcd0; }
.chat-widget .chat-wa-btn {
    display: flex; align-items: center; justify-content: center; gap: .4rem;
    width: 100%; padding: .4rem .75rem; border-radius: 6px;
    border: 1px solid #128C7E; color: #0b6b60; background: #fff;
    font-size: .875rem; font-weight: 600; text-decoration: none;
}
.chat-widget .chat-wa-btn i { font-size: 1.1rem; color: #128C7E; }
.chat-widget .chat-wa-btn:hover { background: #e9f7f4; color: #0b6b60; }

/* WhatsApp in the chat header, visible for the whole conversation. */
.chat-widget .chat-head-wa {
    width: 32px; height: 32px; border-radius: 50%; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    background: #25D366; color: #fff; font-size: 18px; text-decoration: none;
    box-shadow: 0 0 0 3px rgba(37, 211, 102, .25); transition: transform .15s ease, background .15s ease;
}
.chat-widget .chat-head-wa:hover { background: #1ebe5b; color: #fff; transform: scale(1.06); }
