/**
 * AI Customer Support — hovering chat bubble.
 */

.ai-ceo-chat {
    --ai-ceo-accent: #ff3b30;
    --ai-ceo-accent-dark: #d92d23;
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 99990;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Floating bubble button */
.ai-ceo-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--ai-ceo-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease, background 0.2s ease;
    position: relative;
    z-index: 2;
}

.ai-ceo-chat-toggle:hover {
    transform: scale(1.06);
    background: var(--ai-ceo-accent-dark);
}

.ai-ceo-chat-toggle .ai-ceo-chat-icon-close { display: none; }
.ai-ceo-chat.open .ai-ceo-chat-toggle .ai-ceo-chat-icon-open { display: none; }
.ai-ceo-chat.open .ai-ceo-chat-toggle .ai-ceo-chat-icon-close { display: block; }

/* Unread/attention pulse on the bubble */
.ai-ceo-chat-toggle::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--ai-ceo-accent);
    opacity: 0;
    animation: ai-ceo-ping 2.4s ease-out infinite;
}
.ai-ceo-chat.open .ai-ceo-chat-toggle::after { animation: none; }

@keyframes ai-ceo-ping {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* Chat window */
.ai-ceo-chat-window {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: 350px;
    max-width: calc(100vw - 44px);
    height: 480px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ai-ceo-chat.open .ai-ceo-chat-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.ai-ceo-chat-header {
    background: var(--ai-ceo-accent);
    color: #fff;
    padding: 16px 18px;
}

.ai-ceo-chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
}

.ai-ceo-chat-status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.3);
}

.ai-ceo-chat-header-sub {
    display: block;
    font-size: 12px;
    opacity: 0.9;
    margin-top: 4px;
}

/* Messages */
.ai-ceo-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f7f7f8;
}

.ai-ceo-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.ai-ceo-msg.bot {
    align-self: flex-start;
    background: #fff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

.ai-ceo-msg.user {
    align-self: flex-end;
    background: var(--ai-ceo-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ai-ceo-msg.system {
    align-self: center;
    background: #eef2ff;
    color: #4338ca;
    font-size: 12.5px;
    text-align: center;
    max-width: 95%;
}

/* Typing indicator */
.ai-ceo-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.ai-ceo-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    animation: ai-ceo-bounce 1.2s infinite ease-in-out;
}
.ai-ceo-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-ceo-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-ceo-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* Actions */
.ai-ceo-chat-actions {
    padding: 8px 16px 0;
    background: #f7f7f8;
}

.ai-ceo-chat-escalate {
    background: none;
    border: none;
    color: var(--ai-ceo-accent-dark);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
    text-decoration: underline;
}
.ai-ceo-chat-escalate:hover { color: var(--ai-ceo-accent); }

/* Input */
.ai-ceo-chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px 16px;
    background: #f7f7f8;
}

.ai-ceo-chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 22px;
    padding: 11px 16px;
    font-size: 14px;
    outline: none;
    background: #fff;
}
.ai-ceo-chat-input:focus { border-color: var(--ai-ceo-accent); }

.ai-ceo-chat-send {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 50%;
    border: none;
    background: var(--ai-ceo-accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}
.ai-ceo-chat-send:hover { background: var(--ai-ceo-accent-dark); }
.ai-ceo-chat-send:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 480px) {
    .ai-ceo-chat-window {
        width: calc(100vw - 24px);
        height: calc(100vh - 110px);
    }
    .ai-ceo-chat { right: 14px; bottom: 14px; }
}
