/* AI Support Chatbot — Frontend Widget */
:root {
    --ac-primary: #534AB7;
    --ac-primary-dark: #3C3489;
    --ac-bg: #F7F6FF;
    --ac-white: #FFFFFF;
    --ac-text: #1A1A1A;
    --ac-text2: #5A5A5A;
    --ac-text3: #9A9A9A;
    --ac-border: rgba(0,0,0,0.10);
    --ac-radius: 16px;
    --ac-shadow: 0 8px 32px rgba(83, 74, 183, 0.20);
    --ac-z: 999999;
}

/* Container */
#aichat-root { position: fixed; z-index: var(--ac-z); }
#aichat-root.bottom-right { bottom: 24px; right: 24px; }
#aichat-root.bottom-left  { bottom: 24px; left: 24px; }

/* FAB button */
#aichat-fab {
    width: 60px; height: 60px;
    background: var(--ac-primary);
    border-radius: 50%;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 20px rgba(83,74,183,0.45);
    transition: transform .2s, box-shadow .2s, background .2s;
    outline: none;
    position: relative;
}
#aichat-fab:hover {
    transform: scale(1.10);
    box-shadow: 0 8px 32px rgba(83,74,183,.55);
    background: var(--ac-primary-dark);
}
#aichat-fab svg { width: 28px; height: 28px; color: white; transition: transform .2s, opacity .2s; }
#aichat-fab .icon-close { display: none; }

#aichat-root.open #aichat-fab .icon-chat  { display: none; }
#aichat-root.open #aichat-fab .icon-close { display: block; }
#aichat-root.open #aichat-fab { background: #444; box-shadow: 0 4px 16px rgba(0,0,0,0.25); }
#aichat-root.open #aichat-pulse { display: none; }

/* Pulse ring animation (shows only when closed) */
#aichat-pulse {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 3px solid var(--ac-primary);
    opacity: 0;
    animation: aichat-pulse-ring 2.5s ease-out infinite;
    pointer-events: none;
}
#aichat-pulse-2 {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 3px solid var(--ac-primary);
    opacity: 0;
    animation: aichat-pulse-ring 2.5s ease-out 1.2s infinite;
    pointer-events: none;
}
@keyframes aichat-pulse-ring {
    0%   { inset: 0px; opacity: 0.7; }
    100% { inset: -14px; opacity: 0; }
}

/* Tooltip label next to FAB */
#aichat-tooltip {
    position: absolute;
    bottom: 14px;
    white-space: nowrap;
    background: #1A1A1A;
    color: white;
    font-size: 13px;
    font-weight: 500;
    padding: 7px 14px;
    border-radius: 20px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.18);
    pointer-events: none;
    transition: opacity .25s, transform .25s;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
#aichat-root.bottom-right #aichat-tooltip { right: 70px; }
#aichat-root.bottom-left  #aichat-tooltip { left:  70px; }

/* Tooltip arrow */
#aichat-tooltip::after {
    content: '';
    position: absolute;
    top: 50%; transform: translateY(-50%);
    border: 6px solid transparent;
}
#aichat-root.bottom-right #aichat-tooltip::after {
    right: -11px; border-left-color: #1A1A1A;
}
#aichat-root.bottom-left #aichat-tooltip::after {
    left: -11px; border-right-color: #1A1A1A;
}

/* Hide tooltip once chat is opened or after first interaction */
#aichat-root.open    #aichat-tooltip { opacity: 0; pointer-events: none; }
#aichat-root.chatted #aichat-tooltip { display: none; }

/* Unread badge */
#aichat-unread {
    position: absolute; top: -4px; right: -4px;
    background: #EF4444; color: white;
    font-size: 11px; font-weight: 700;
    width: 20px; height: 20px; border-radius: 50%;
    display: none; align-items: center; justify-content: center;
    border: 2px solid white;
}
#aichat-unread.show { display: flex; }

/* Chat window */
#aichat-window {
    position: absolute;
    width: 360px;
    max-height: 560px;
    background: var(--ac-white);
    border-radius: var(--ac-radius);
    box-shadow: var(--ac-shadow);
    display: flex; flex-direction: column;
    overflow: hidden;
    bottom: 68px;
    opacity: 0; pointer-events: none;
    transform: translateY(12px) scale(0.97);
    transition: opacity .22s ease, transform .22s ease;
}
#aichat-root.bottom-right #aichat-window { right: 0; }
#aichat-root.bottom-left  #aichat-window { left: 0; }
#aichat-root.open #aichat-window { opacity: 1; pointer-events: all; transform: translateY(0) scale(1); }

/* Header */
#aichat-header {
    background: var(--ac-primary);
    padding: 14px 16px;
    display: flex; align-items: center; gap: 10px;
    flex-shrink: 0;
}
#aichat-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
#aichat-avatar svg { width: 20px; height: 20px; color: white; }
#aichat-header-info { flex: 1; }
#aichat-bot-name   { font-size: 14px; font-weight: 700; color: white; line-height: 1.2; }
#aichat-bot-status { font-size: 12px; color: rgba(255,255,255,0.75); }
#aichat-minimize   { background: none; border: none; cursor: pointer; padding: 4px; color: rgba(255,255,255,0.75); }
#aichat-minimize:hover { color: white; }
#aichat-minimize svg { width: 18px; height: 18px; }

/* Name/email collect form */
#aichat-collect-form {
    padding: 16px;
    border-bottom: 1px solid var(--ac-border);
    background: var(--ac-bg);
}
#aichat-collect-form p { font-size: 13px; color: var(--ac-text2); margin: 0 0 12px; }
#aichat-collect-form input {
    width: 100%; padding: 8px 12px; margin-bottom: 8px;
    border: 1px solid var(--ac-border); border-radius: 8px;
    font-size: 13px; font-family: inherit; box-sizing: border-box;
    outline: none;
}
#aichat-collect-form input:focus { border-color: var(--ac-primary); }
#aichat-collect-submit {
    width: 100%; padding: 9px; background: var(--ac-primary); color: white;
    border: none; border-radius: 8px; font-size: 13px; font-weight: 600;
    cursor: pointer; font-family: inherit;
}

/* Messages area */
#aichat-messages {
    flex: 1; overflow-y: auto; padding: 14px;
    display: flex; flex-direction: column; gap: 10px;
    background: var(--ac-bg);
    scroll-behavior: smooth;
}
#aichat-messages::-webkit-scrollbar { width: 4px; }
#aichat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 4px; }

/* Chips */
#aichat-chips {
    padding: 8px 14px 4px;
    display: flex; flex-wrap: wrap; gap: 6px;
    background: var(--ac-bg);
    border-top: 1px solid var(--ac-border);
}
.aichat-chip {
    background: white; border: 1px solid rgba(83,74,183,0.25);
    color: var(--ac-primary); border-radius: 20px;
    padding: 5px 12px; font-size: 12px; font-weight: 500;
    cursor: pointer; transition: background .15s, border-color .15s;
    line-height: 1.4;
}
.aichat-chip:hover { background: var(--ac-primary); color: white; border-color: var(--ac-primary); }

/* Message bubbles */
.aichat-msg {
    display: flex; gap: 8px; align-items: flex-end; max-width: 88%;
}
.aichat-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.aichat-msg.bot  { align-self: flex-start; }

.aichat-msg-avatar {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
}
.aichat-msg.bot  .aichat-msg-avatar { background: var(--ac-primary); color: white; }
.aichat-msg.user .aichat-msg-avatar { background: #e8e8e8; }

.aichat-msg-bubble {
    padding: 10px 14px; border-radius: 14px;
    font-size: 13px; line-height: 1.6; word-break: break-word;
}
.aichat-msg.bot  .aichat-msg-bubble {
    background: white; color: var(--ac-text);
    border: 1px solid var(--ac-border);
    border-bottom-left-radius: 4px;
}
.aichat-msg.user .aichat-msg-bubble {
    background: var(--ac-primary); color: white;
    border-bottom-right-radius: 4px;
}
.aichat-msg-time { font-size: 10px; color: var(--ac-text3); margin-top: 3px; text-align: right; }
.aichat-msg.bot .aichat-msg-time { text-align: left; }

/* Typing indicator */
.aichat-typing .aichat-msg-bubble {
    display: flex; align-items: center; gap: 5px;
    padding: 12px 16px;
}
.aichat-typing-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--ac-text3);
    animation: aichat-bounce 1.2s infinite;
}
.aichat-typing-dot:nth-child(2) { animation-delay: .2s; }
.aichat-typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes aichat-bounce {
    0%,80%,100% { transform: translateY(0); }
    40%          { transform: translateY(-5px); }
}

/* Input row */
#aichat-input-row {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--ac-border);
    background: white; flex-shrink: 0;
}
#aichat-input {
    flex: 1; border: 1px solid var(--ac-border); border-radius: 22px;
    padding: 9px 14px; font-size: 13px; font-family: inherit;
    outline: none; resize: none; line-height: 1.4;
    max-height: 80px; overflow-y: auto;
}
#aichat-input:focus { border-color: var(--ac-primary); }
#aichat-send {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    background: var(--ac-primary); border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s;
}
#aichat-send:hover { background: var(--ac-primary-dark); }
#aichat-send svg { width: 17px; height: 17px; color: white; }
#aichat-send:disabled { background: #ccc; cursor: not-allowed; }

/* Branding */
#aichat-branding {
    text-align: center; padding: 6px; font-size: 10px;
    color: var(--ac-text3); background: white;
    border-top: 1px solid var(--ac-border);
    flex-shrink: 0;
}

/* Mobile */
@media (max-width: 420px) {
    #aichat-window { width: calc(100vw - 32px); }
    #aichat-root.bottom-right { right: 16px; }
    #aichat-root.bottom-left  { left:  16px; }
}
