/* AI Chatbot Pro — Frontend Widget */
:root {
    --aicp-c:       #2563eb;
    --aicp-c-light: #eff6ff;
    --aicp-radius:  16px;
    --aicp-shadow:  0 8px 40px rgba(0,0,0,.18);
    --aicp-font:    -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Launcher button ──────────────────────────────────────────── */
#aicp-launcher {
    position: fixed;
    bottom: 24px; right: 24px;
    width: 58px; height: 58px;
    border-radius: 50%;
    background: var(--aicp-c);
    border: none; cursor: pointer;
    box-shadow: 0 4px 20px rgba(37,99,235,.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 999998;
    transition: transform .2s, box-shadow .2s;
}
#aicp-launcher:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(37,99,235,.55); }
#aicp-launcher svg   { width: 26px; height: 26px; fill: #fff; transition: opacity .2s; }
#aicp-launcher .icon-close { display: none; }

#aicp-launcher.open .icon-chat  { display: none; }
#aicp-launcher.open .icon-close { display: block; }

.aicp-pos-left  #aicp-launcher,
.aicp-pos-left  #aicp-window { left: 24px; right: auto; }

/* Pulse ring */
#aicp-launcher::after {
    content: '';
    position: absolute; inset: -4px;
    border-radius: 50%;
    border: 3px solid var(--aicp-c);
    animation: aicp-pulse 2.5s ease-out infinite;
    opacity: 0;
}
@keyframes aicp-pulse {
    0%   { transform: scale(1); opacity: .6; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* ── Chat window ──────────────────────────────────────────────── */
#aicp-window {
    position: fixed;
    bottom: 96px; right: 24px;
    width: 380px; height: 560px;
    background: #fff;
    border-radius: var(--aicp-radius);
    box-shadow: var(--aicp-shadow);
    display: flex; flex-direction: column;
    z-index: 999997;
    opacity: 0; pointer-events: none;
    transform: translateY(16px) scale(.97);
    transition: opacity .25s, transform .25s;
    font-family: var(--aicp-font);
    overflow: hidden;
}
#aicp-window.open {
    opacity: 1; pointer-events: all;
    transform: translateY(0) scale(1);
}

#aicp-window.expanded {
    width: min(90vw, 900px);
    height: min(85vh, 720px);
    bottom: auto;
    right: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    transition: width .3s ease, height .3s ease, top .3s ease, left .3s ease, transform .3s ease, opacity .25s;
}

/* Header */
#aicp-header {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 16px;
    background: var(--aicp-c);
    color: #fff;
    border-radius: var(--aicp-radius) var(--aicp-radius) 0 0;
}
#aicp-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
}
#aicp-title-wrap { flex: 1; }
#aicp-title { font-weight: 700; font-size: 15px; margin: 0; }
#aicp-status { font-size: 11px; opacity: .8; margin-top: 1px; }

/* Expand button */
#aicp-expand {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    opacity: 0.75;
    transition: opacity .2s, background .2s;
    flex-shrink: 0;
}
#aicp-expand:hover { opacity: 1; background: rgba(255,255,255,.15); }
#aicp-expand svg {
    width: 18px; height: 18px;
    fill: #fff;
    transition: transform .25s;
}
#aicp-expand.active svg {
    transform: rotate(180deg);
}

.aicp-dot { display: inline-block; width: 7px; height: 7px; background: #4ade80; border-radius: 50%; margin-right: 4px; animation: aicp-blink 2s infinite; }
@keyframes aicp-blink { 0%,100%{opacity:1}50%{opacity:.4} }

/* GDPR banner — bottom panel replacing input area */
#aicp-gdpr-banner {
    display: none;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    font-size: 13px; color: #475569; line-height: 1.5;
}
#aicp-gdpr-banner a { color: var(--aicp-c); }
#aicp-gdpr-accept {
    width: 100%;
    padding: 10px; border: none; border-radius: 22px;
    background: var(--aicp-c); color: #fff;
    font-weight: 600; font-size: 13px; cursor: pointer;
    transition: background .2s;
}

/* Messages area */
#aicp-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
    scroll-behavior: smooth;
}
#aicp-messages::-webkit-scrollbar { width: 4px; }
#aicp-messages::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 4px; }

/* Bubbles */
.aicp-bubble-wrap { display: flex; gap: 8px; max-width: 88%; }
.aicp-bubble-wrap.user  { flex-direction: row-reverse; align-self: flex-end; }
.aicp-bubble-wrap.bot   { align-self: flex-start; }

.aicp-bubble-avatar {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    background: var(--aicp-c-light); display: flex; align-items: center; justify-content: center;
    font-size: 13px; margin-top: 4px;
}
.aicp-bubble-wrap.user .aicp-bubble-avatar { background: #f1f5f9; }
.aicp-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.aicp-bubble {
    padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6;
    max-width: 100%; word-break: break-word;
}
.aicp-bubble.user { background: var(--aicp-c); color: #fff; border-bottom-right-radius: 4px; }
.aicp-bubble.bot  { background: #f8fafc; color: #1e293b; border-bottom-left-radius: 4px; border: 1px solid #e2e8f0; }
.aicp-bubble a    { color: inherit; text-decoration: underline; }

/* Typing indicator */
.aicp-typing { display: flex; gap: 4px; padding: 12px 14px; }
.aicp-typing span {
    width: 7px; height: 7px; border-radius: 50%; background: #94a3b8;
    animation: aicp-bounce .9s infinite;
}
.aicp-typing span:nth-child(2) { animation-delay: .15s; }
.aicp-typing span:nth-child(3) { animation-delay: .30s; }
@keyframes aicp-bounce { 0%,80%,100%{transform:translateY(0)}40%{transform:translateY(-7px)} }

/* Rate limit badge */
#aicp-rate-badge {
    text-align: center; font-size: 11px; color: #94a3b8;
    padding: 2px 0; margin-top: -8px;
}

/* Input area — hidden until GDPR consent */
#aicp-input-area {
    display: none; flex-direction: column; gap: 4px;
    padding: 12px 14px 8px;
    border-top: 1px solid #e2e8f0; background: #fff;
}
#aicp-input-area.visible { display: flex; }
#aicp-input-row {
    display: flex; gap: 8px; align-items: flex-end;
}
#aicp-input {
    flex: 1; padding: 10px 14px; border: 1.5px solid #e2e8f0;
    border-radius: 22px; font-size: 14px; font-family: var(--aicp-font);
    outline: none; resize: none; height: 42px; line-height: 1.4;
    transition: border .2s;
}
#aicp-input:focus { border-color: var(--aicp-c); }
#aicp-input:disabled { opacity: .5; }

#aicp-send {
    width: 42px; height: 42px; border-radius: 50%; border: none;
    background: var(--aicp-c); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: background .2s, transform .15s;
}
#aicp-send:disabled { opacity: .4; cursor: not-allowed; }
#aicp-send svg { width: 18px; height: 18px; fill: #fff; }

#aicp-char-counter {
    font-size: 11px; color: #94a3b8; text-align: right;
    padding: 0 2px; transition: color .15s;
}
#aicp-char-counter.over-limit { color: #ef4444; font-weight: 600; }

/* Rate limit warning */
.aicp-rate-warning {
    font-size: 12px; color: #ef4444; text-align: center;
    padding: 8px 14px; background: #fef2f2; border-radius: 8px;
}

/* Powered by */
#aicp-footer {
    text-align: center; font-size: 10px; color: #cbd5e1;
    padding: 4px 0 8px; letter-spacing: .03em;
}

/* Mobile */
@media (max-width: 480px) {
    #aicp-window {
        width: calc(100vw - 24px);
        height: 65vh;
        bottom: 84px;
        right: 12px;
    }
    .aicp-pos-left #aicp-window,
    .aicp-pos-left #aicp-launcher { left: 12px; right: auto; }
    #aicp-expand { display: none; }
    #aicp-window.expanded {
        width: calc(100vw - 24px);
        height: 65vh;
        top: auto;
        bottom: 84px;
        left: auto;
        right: 12px;
        transform: none;
    }
}

/* ── Rich content inside bot bubbles ─────────────────────────── */
.aicp-bubble.bot p {
    margin: 0 0 8px;
}
.aicp-bubble.bot p:last-child {
    margin-bottom: 0;
}
.aicp-bubble.bot ul,
.aicp-bubble.bot ol {
    margin: 4px 0 8px;
    padding-left: 18px;
}
.aicp-bubble.bot ul:last-child,
.aicp-bubble.bot ol:last-child {
    margin-bottom: 0;
}
.aicp-bubble.bot li {
    margin-bottom: 4px;
    line-height: 1.5;
}
.aicp-bubble.bot li:last-child {
    margin-bottom: 0;
}
.aicp-bubble.bot a {
    color: var(--aicp-c);
    text-decoration: underline;
    word-break: break-all;
}
.aicp-bubble.bot code {
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    color: #1e293b;
}
.aicp-bubble.bot hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 10px 0;
}

/* ── Suggestion chips ─────────────────────────────────────────── */
.aicp-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0 4px 36px; /* 36px aligns with bot bubble (avatar width + gap) */
    align-self: flex-start;
    max-width: 100%;
}

.aicp-suggestion-btn {
    background: #fff;
    border: 1.5px solid var(--aicp-c);
    color: var(--aicp-c);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 13px;
    font-family: var(--aicp-font);
    cursor: pointer;
    transition: background .15s, color .15s;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.aicp-suggestion-btn:hover {
    background: var(--aicp-c);
    color: #fff;
}

/* ── WhatsApp share button ─────────────────────────────────────── */
.aicp-whatsapp-btn-wrap {
    padding: 4px 0 4px 36px;
    align-self: flex-start;
}

.aicp-whatsapp-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #25D366;
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    font-family: var(--aicp-font);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, transform .15s;
    white-space: nowrap;
}

.aicp-whatsapp-btn:hover {
    background: #128C7E;
    transform: scale(1.03);
    color: #fff;
}

.aicp-whatsapp-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
    flex-shrink: 0;
}
