/**
 * Infineural CRM — website assistant.
 *
 * Everything is namespaced under .infcrm-chat and uses its own values rather
 * than inheriting the theme's, because this renders on somebody else's site:
 * a theme that sets `button { width: 100% }` must not be able to break it.
 */

.infcrm-chat {
    position: fixed;
    /* Offsets and size are custom properties so the admin can move the launcher
       clear of whatever else occupies the corner, without touching CSS. */
    --infcrm-chat-x: 20px;
    --infcrm-chat-y: 20px;
    --infcrm-chat-size: 56px;
    right: var(--infcrm-chat-x);
    bottom: var(--infcrm-chat-y);
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #1e293b;
}

/* Left placement: flip the anchor and the panel's origin with it, or the
   panel opens off-screen. */
.infcrm-chat--left { right: auto; left: var(--infcrm-chat-x); }
.infcrm-chat--left .infcrm-chat-panel { right: auto; left: 0; transform-origin: bottom left; }

/* ── Launcher ─────────────────────────────────────────────── */
.infcrm-chat-launcher {
    position: relative;
    width: var(--infcrm-chat-size);
    height: var(--infcrm-chat-size);
    border-radius: 50%;
    border: none;
    background: var(--infcrm-chat-accent, #4f46e5);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.24);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.infcrm-chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(15, 23, 42, 0.3); }
.infcrm-chat-launcher svg { width: 26px; height: 26px; }

.infcrm-chat-badge {
    position: absolute;
    top: 2px; right: 2px;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: #f43f5e;
    border: 2px solid #fff;
}

/* ── Panel ────────────────────────────────────────────────── */
.infcrm-chat-panel {
    position: absolute;
    right: 0;
    bottom: calc(var(--infcrm-chat-size) + 16px);
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Hidden by default without display:none, so opening can animate. */
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
}
.infcrm-chat.is-open .infcrm-chat-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.infcrm-chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: var(--infcrm-chat-accent, #4f46e5);
    color: #fff;
    flex-shrink: 0;
}
.infcrm-chat-title { font-weight: 600; font-size: 15px; }
.infcrm-chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.85;
}
.infcrm-chat-close:hover { opacity: 1; }

/* ── Log ──────────────────────────────────────────────────── */
.infcrm-chat-log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.infcrm-chat-msg { display: flex; }
.infcrm-chat-msg.is-visitor { justify-content: flex-end; }

.infcrm-chat-bubble {
    max-width: 82%;
    padding: 10px 13px;
    border-radius: 14px;
    /* Answers arrive as plain text with real newlines; preserve them without
       letting a long URL push the panel wider. */
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: #fff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.infcrm-chat-msg.is-visitor .infcrm-chat-bubble {
    background: var(--infcrm-chat-accent, #4f46e5);
    border-color: transparent;
    color: #fff;
}

/* Typing indicator */
.infcrm-chat-typing .infcrm-chat-bubble { display: flex; gap: 4px; padding: 13px; }
.infcrm-chat-typing span {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: infcrmChatDot 1.2s infinite ease-in-out;
}
.infcrm-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.infcrm-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes infcrmChatDot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-3px); }
}

/* ── Suggestion chips ─────────────────────────────────────── */
.infcrm-chat-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.infcrm-chat-chip {
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12.5px;
    color: #334155;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: border-color 0.15s ease, color 0.15s ease;
}
.infcrm-chat-chip:hover { border-color: var(--infcrm-chat-accent, #4f46e5); color: var(--infcrm-chat-accent, #4f46e5); }

/* ── Capture form ─────────────────────────────────────────── */
.infcrm-chat-capture {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-left: 3px solid var(--infcrm-chat-accent, #4f46e5);
    border-radius: 12px;
    padding: 12px;
}
.infcrm-chat-capture-text { font-size: 13.5px; margin-bottom: 10px; color: #334155; }
.infcrm-chat-capture-form { display: flex; flex-direction: column; gap: 8px; }
.infcrm-chat-capture-send {
    background: var(--infcrm-chat-accent, #4f46e5);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 9px 14px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}
.infcrm-chat-capture-send:disabled { opacity: 0.6; cursor: default; }
.infcrm-chat-error { color: #dc2626; font-size: 12.5px; margin-top: 8px; }

/* ── Composer ─────────────────────────────────────────────── */
.infcrm-chat-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
}
.infcrm-chat-input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    color: #1e293b;
    background: #fff;
    box-sizing: border-box;
}
.infcrm-chat-input:focus {
    outline: none;
    border-color: var(--infcrm-chat-accent, #4f46e5);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--infcrm-chat-accent, #4f46e5) 22%, transparent);
}
.infcrm-chat-send {
    width: 42px;
    flex-shrink: 0;
    border: none;
    border-radius: 10px;
    background: var(--infcrm-chat-accent, #4f46e5);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.infcrm-chat-send:disabled { opacity: 0.5; cursor: default; }
.infcrm-chat-send svg { width: 17px; height: 17px; }

/* ── Attribution ──────────────────────────────────────────── */
.infcrm-chat-credit {
    padding: 6px 12px 9px;
    text-align: center;
    font-size: 10.5px;
    letter-spacing: 0.02em;
    color: #94a3b8;
    background: #fff;
    border-top: 1px solid #f1f5f9;
    flex-shrink: 0;
}
.infcrm-chat-credit a {
    color: #64748b;
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}
.infcrm-chat-credit a:hover { color: var(--infcrm-chat-accent, #4f46e5); }

/* ── Phone ────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .infcrm-chat { right: 12px; bottom: 12px; }
    .infcrm-chat--left { left: 12px; right: auto; }
    .infcrm-chat-panel,
    .infcrm-chat--left .infcrm-chat-panel {
        position: fixed;
        right: 0; left: 0; bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 82vh;
        max-height: 82vh;
        border-radius: 16px 16px 0 0;
        transform-origin: bottom center;
    }
}

/* Respect a reduced-motion preference — this is decoration, not information. */
@media (prefers-reduced-motion: reduce) {
    .infcrm-chat-panel,
    .infcrm-chat-launcher { transition: none; }
    .infcrm-chat-typing span { animation: none; opacity: 0.6; }
}
