#mf-ai-chat-root {
    --mf-chat-primary: #001030;
    --mf-chat-primary-light: #0a2456;
    --mf-chat-accent: #f0b000;
    --mf-chat-accent-soft: #fde9b8;
    position: fixed;
    z-index: 999999;
    bottom: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
#mf-ai-chat-root.mf-pos-right { right: 20px; }
#mf-ai-chat-root.mf-pos-left { left: 20px; }
#mf-ai-chat-root * { box-sizing: border-box; }

/* Reset native OS/browser button chrome (Chrome/Safari/Edge otherwise
   paint a platform pill/bezel behind buttons, which shows as a grey-blue
   halo around our circular buttons regardless of the background we set). */
#mf-ai-chat-root button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    font: inherit;
    line-height: normal;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}
#mf-ai-chat-root button::-moz-focus-inner { border: 0; }

/* Bubble launcher */
.mf-chat-bubble {
    width: 62px;
    height: 62px;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--mf-chat-primary) 0%, var(--mf-chat-primary-light) 100%);
    color: #fff;
    border: none;
    box-shadow: 0 8px 24px rgba(0, 16, 48, 0.35), 0 0 0 4px rgba(240, 176, 0, 0.12);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    position: relative;
}
.mf-chat-bubble:hover {
    transform: scale(1.07);
    box-shadow: 0 10px 28px rgba(0, 16, 48, 0.4), 0 0 0 5px rgba(240, 176, 0, 0.18);
}
.mf-chat-bubble svg { width: 26px; height: 26px; fill: #fff; transition: transform 0.18s ease; }
.mf-chat-bubble:active svg { transform: scale(0.9); }

.mf-chat-bubble::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--mf-chat-accent);
    border: 2px solid #fff;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
#mf-ai-chat-root.mf-attention .mf-chat-bubble::after {
    opacity: 1;
    transform: scale(1);
    animation: mf-chat-pulse 1.8s ease-in-out infinite;
}
@keyframes mf-chat-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(240, 176, 0, 0.55); }
    50% { box-shadow: 0 0 0 5px rgba(240, 176, 0, 0); }
}

/* Window */
.mf-chat-window {
    position: absolute;
    bottom: 78px;
    width: 372px;
    max-width: calc(100vw - 40px);
    height: 540px;
    max-height: 72vh;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(0, 16, 48, 0.28), 0 2px 8px rgba(0, 16, 48, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
#mf-ai-chat-root.mf-pos-right .mf-chat-window { right: 0; }
#mf-ai-chat-root.mf-pos-left .mf-chat-window { left: 0; }
#mf-ai-chat-root.mf-open .mf-chat-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.mf-chat-header {
    background: linear-gradient(120deg, var(--mf-chat-primary) 0%, var(--mf-chat-primary-light) 100%);
    color: #fff;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 11px;
    position: relative;
    overflow: hidden;
}
.mf-chat-header::before {
    /* subtle gold glow, MF brand accent */
    content: '';
    position: absolute;
    top: -40%;
    right: -10%;
    width: 140px;
    height: 140px;
    background: radial-gradient(circle, rgba(240, 176, 0, 0.35) 0%, rgba(240, 176, 0, 0) 70%);
    pointer-events: none;
}
.mf-chat-header .mf-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    color: var(--mf-chat-primary);
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
    position: relative;
    z-index: 1;
}
.mf-chat-header .mf-chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.mf-chat-header-text { position: relative; z-index: 1; flex: 1; min-width: 0; }
.mf-chat-header-title { font-weight: 600; font-size: 14.5px; line-height: 1.3; }
.mf-chat-header-status { font-size: 11px; color: var(--mf-chat-accent-soft); display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.mf-chat-header-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #3ecf8e;
    display: inline-block;
    box-shadow: 0 0 0 2px rgba(62, 207, 142, 0.25);
}
.mf-chat-close {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    margin: 0;
    padding: 0;
    color: #fff;
    cursor: pointer;
    font-size: 17px;
    line-height: 1;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    transition: background 0.15s ease;
    flex-shrink: 0;
}
.mf-chat-close:hover { background: rgba(255, 255, 255, 0.22); }

/* Messages */
.mf-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    background: #f6f7f9;
    display: flex;
    flex-direction: column;
    gap: 11px;
}
.mf-chat-messages::-webkit-scrollbar { width: 6px; }
.mf-chat-messages::-webkit-scrollbar-thumb { background: #d6d9de; border-radius: 3px; }
.mf-chat-messages::-webkit-scrollbar-track { background: transparent; }

.mf-chat-msg {
    max-width: 84%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    animation: mf-chat-msg-in 0.22s ease both;
}
@keyframes mf-chat-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.mf-chat-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--mf-chat-primary) 0%, var(--mf-chat-primary-light) 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.mf-chat-msg.bot {
    align-self: flex-start;
    background: #fff;
    color: #1d2327;
    border: 1px solid #e6e8ec;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 16, 48, 0.04);
    white-space: normal;
}
.mf-chat-msg.bot p { margin: 0 0 8px; }
.mf-chat-msg.bot p:last-child { margin-bottom: 0; }
.mf-chat-msg.bot ul, .mf-chat-msg.bot ol { margin: 0 0 8px; padding-left: 20px; }
.mf-chat-msg.bot ul:last-child, .mf-chat-msg.bot ol:last-child { margin-bottom: 0; }
.mf-chat-msg.bot li { margin-bottom: 3px; }
.mf-chat-msg.bot li:last-child { margin-bottom: 0; }
.mf-chat-msg.bot strong { font-weight: 600; }
.mf-chat-msg.bot code {
    background: #f0f1f3;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.92em;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.mf-chat-msg.bot br { line-height: 0.4; }
.mf-chat-msg.system {
    align-self: center;
    background: transparent;
    color: #9aa0a8;
    font-size: 11px;
    text-align: center;
    max-width: 100%;
    border: 1px dashed #d6d9de;
    border-radius: 8px;
    padding: 6px 10px;
}

.mf-chat-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 11px 14px;
    background: #fff;
    border: 1px solid #e6e8ec;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.mf-chat-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--mf-chat-accent); animation: mf-chat-bounce 1.2s infinite ease-in-out; }
.mf-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.mf-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes mf-chat-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* Lead capture card */
.mf-chat-lead {
    border: 1px solid #e6e8ec;
    background: #fff;
    border-radius: 12px;
    padding: 12px;
    align-self: stretch;
    font-size: 13px;
    box-shadow: 0 1px 2px rgba(0, 16, 48, 0.04);
}
.mf-chat-lead p { margin: 0 0 9px; color: #1d2327; }
.mf-chat-lead input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    margin-bottom: 7px;
    border: 1px solid #d6d9de;
    border-radius: 8px;
    font-size: 13px;
    transition: border-color 0.15s ease;
}
.mf-chat-lead input:focus { outline: none; border-color: var(--mf-chat-accent); }
.mf-chat-lead-actions { display: flex; gap: 8px; margin-top: 4px; }
.mf-chat-lead-actions button { flex: 1; margin: 0; padding: 8px 10px; border-radius: 8px; border: none; cursor: pointer; font-size: 12.5px; font-weight: 500; transition: opacity 0.15s ease; }
.mf-chat-lead-actions button:hover { opacity: 0.88; }
.mf-chat-lead-submit { background: var(--mf-chat-primary); color: #fff; }
.mf-chat-lead-dismiss { background: #eceef1; color: #444; }

/* Input row */
.mf-chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e6e8ec;
    background: #fff;
}
.mf-chat-input-row textarea {
    flex: 1;
    resize: none;
    border: 1px solid #d6d9de;
    border-radius: 12px;
    padding: 10px 13px;
    font-size: 13.5px;
    font-family: inherit;
    max-height: 90px;
    min-height: 40px;
    transition: border-color 0.15s ease;
}
.mf-chat-input-row textarea:focus { outline: none; border-color: var(--mf-chat-accent); box-shadow: 0 0 0 3px rgba(240, 176, 0, 0.15); }
.mf-chat-send {
    background: linear-gradient(135deg, var(--mf-chat-primary) 0%, var(--mf-chat-primary-light) 100%);
    color: #fff;
    border: none;
    margin: 0;
    padding: 0;
    border-radius: 12px;
    width: 42px;
    height: 40px;
    flex-shrink: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s ease, opacity 0.12s ease;
}
.mf-chat-send:hover:not(:disabled) { transform: translateY(-1px); }
.mf-chat-send:disabled { opacity: 0.45; cursor: default; }
.mf-chat-send svg { width: 17px; height: 17px; fill: #fff; margin-left: -1px; }

.mf-chat-footer-note {
    text-align: center;
    font-size: 10.5px;
    color: #adb1b8;
    padding: 5px 0 10px;
    background: #fff;
}

@media (max-width: 480px) {
    .mf-chat-window { width: calc(100vw - 24px); height: 74vh; bottom: 74px; border-radius: 16px; }
    #mf-ai-chat-root { bottom: 14px; }
    #mf-ai-chat-root.mf-pos-right { right: 14px; }
    #mf-ai-chat-root.mf-pos-left { left: 14px; }
}
