/* ─────────────────────────────────────────────────────────────────────────
   AI Chat Support Widget
   ───────────────────────────────────────────────────────────────────────── */

:root {
    --aichat-accent:       #6d28d9;
    --aichat-accent-light: #7c3aed;
    --aichat-accent-glow:  rgba(109, 40, 217, 0.25);
    --aichat-bg:           #ffffff;
    --aichat-surface:      #f9fafb;
    --aichat-border:       #e5e7eb;
    --aichat-text:         #111827;
    --aichat-muted:        #6b7280;
    --aichat-user-bg:      #6d28d9;
    --aichat-user-text:    #ffffff;
    --aichat-bot-bg:       #f3f4f6;
    --aichat-bot-text:     #111827;
    --aichat-radius:       1rem;
    --aichat-shadow:       0 8px 32px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.10);
    --aichat-z:            99999;
    --aichat-width:        360px;
    --aichat-height:       520px;
}

/* ── Launcher button ──────────────────────────────────────────────────────── */
#aichat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--aichat-z);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--aichat-accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px var(--aichat-accent-glow), 0 2px 6px rgba(0,0,0,.2);
    transition: transform .2s ease, box-shadow .2s ease;
    outline: none;
}
#aichat-launcher:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px var(--aichat-accent-glow), 0 2px 8px rgba(0,0,0,.25);
}
#aichat-launcher:active { transform: scale(.96); }
#aichat-launcher svg  { width: 24px; height: 24px; transition: opacity .15s, transform .15s; }
#aichat-launcher .icon-chat  { display: block; }
#aichat-launcher .icon-close { display: none; }
#aichat-launcher.is-open .icon-chat  { display: none; }
#aichat-launcher.is-open .icon-close { display: block; }

/* Unread badge */
#aichat-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none;
}
#aichat-badge.visible { display: block; }

/* ── Chat window ──────────────────────────────────────────────────────────── */
#aichat-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    z-index: var(--aichat-z);
    width: var(--aichat-width);
    max-height: var(--aichat-height);
    display: flex;
    flex-direction: column;
    background: var(--aichat-bg);
    border-radius: var(--aichat-radius);
    box-shadow: var(--aichat-shadow);
    border: 1px solid var(--aichat-border);
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(.92) translateY(12px);
    opacity: 0;
    pointer-events: none;
    transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .18s ease;
}
#aichat-window.is-open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
#aichat-header {
    background: var(--aichat-accent);
    color: #fff;
    padding: .85rem 1rem;
    display: flex;
    align-items: center;
    gap: .65rem;
    flex-shrink: 0;
}
.aichat-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.aichat-avatar svg { width: 18px; height: 18px; }
.aichat-header-info { flex: 1; min-width: 0; }
.aichat-header-title {
    font-size: .9rem;
    font-weight: 600;
    letter-spacing: .01em;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.aichat-header-sub {
    font-size: .73rem;
    opacity: .8;
    margin-top: 1px;
}
.aichat-online-dot {
    display: inline-block;
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #4ade80;
    margin-right: 4px;
    vertical-align: middle;
}

/* ── Messages area ────────────────────────────────────────────────────────── */
#aichat-messages {
    flex: 1;
    overflow-y: auto;
    padding: .85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    background: var(--aichat-surface);
    scroll-behavior: smooth;
}
#aichat-messages::-webkit-scrollbar { width: 4px; }
#aichat-messages::-webkit-scrollbar-track { background: transparent; }
#aichat-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

.aichat-msg {
    display: flex;
    align-items: flex-end;
    gap: .45rem;
    max-width: 88%;
    animation: aichat-pop .18s ease;
}
@keyframes aichat-pop {
    from { opacity:0; transform: translateY(6px) scale(.97); }
    to   { opacity:1; transform: translateY(0) scale(1); }
}
.aichat-msg.bot  { align-self: flex-start; }
.aichat-msg.user { align-self: flex-end; flex-direction: row-reverse; }

.aichat-msg-bubble {
    padding: .55rem .8rem;
    border-radius: 1rem;
    font-size: .87rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}
.aichat-msg.bot  .aichat-msg-bubble { background: var(--aichat-bot-bg);  color: var(--aichat-bot-text);  border-bottom-left-radius: .25rem; }
.aichat-msg.user .aichat-msg-bubble { background: var(--aichat-user-bg); color: var(--aichat-user-text); border-bottom-right-radius: .25rem; }

.aichat-msg-icon {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--aichat-accent);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.aichat-msg-icon svg { width: 13px; height: 13px; color: #fff; }

/* Typing indicator */
#aichat-typing {
    display: none;
    align-self: flex-start;
    align-items: center;
    gap: 4px;
    padding: .55rem .75rem;
    background: var(--aichat-bot-bg);
    border-radius: 1rem;
    border-bottom-left-radius: .25rem;
}
#aichat-typing.visible { display: flex; }
#aichat-typing span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    animation: aichat-bounce 1.2s infinite;
}
#aichat-typing span:nth-child(2) { animation-delay: .15s; }
#aichat-typing span:nth-child(3) { animation-delay: .30s; }
@keyframes aichat-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-5px); }
}

/* ── Input area ───────────────────────────────────────────────────────────── */
#aichat-input-area {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    padding: .7rem .85rem;
    border-top: 1px solid var(--aichat-border);
    background: var(--aichat-bg);
    flex-shrink: 0;
}
#aichat-input {
    flex: 1;
    border: 1px solid var(--aichat-border);
    border-radius: .65rem;
    padding: .55rem .75rem;
    font-size: .87rem;
    font-family: inherit;
    color: var(--aichat-text);
    background: var(--aichat-surface);
    resize: none;
    min-height: 38px;
    max-height: 120px;
    overflow-y: auto;
    outline: none;
    transition: border-color .15s;
    line-height: 1.45;
}
#aichat-input:focus { border-color: var(--aichat-accent); }
#aichat-input::placeholder { color: #9ca3af; }

#aichat-send {
    flex-shrink: 0;
    width: 38px; height: 38px;
    border-radius: .65rem;
    background: var(--aichat-accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, transform .1s;
    outline: none;
}
#aichat-send:hover  { background: var(--aichat-accent-light); }
#aichat-send:active { transform: scale(.92); }
#aichat-send:disabled { background: #d1d5db; cursor: not-allowed; }
#aichat-send svg { width: 17px; height: 17px; }

/* ── Branding footer ──────────────────────────────────────────────────────── */
#aichat-footer {
    text-align: center;
    font-size: .68rem;
    color: var(--aichat-muted);
    padding: .35rem 0 .45rem;
    background: var(--aichat-bg);
    border-top: 1px solid var(--aichat-border);
    flex-shrink: 0;
}

/* ── Unavailable state ────────────────────────────────────────────────────── */
#aichat-launcher.is-unavailable {
    background: #9ca3af;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
#aichat-launcher.is-unavailable:hover {
    background: #6b7280;
    transform: none;
}

.aichat-offline-dot {
    display: inline-block;
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #f97316;
    margin-right: 4px;
    vertical-align: middle;
    animation: aichat-pulse 2s infinite;
}
@keyframes aichat-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .4; }
}

.aichat-unavailable-banner {
    align-self: center;
    text-align: center;
    background: #fff7ed;
    border: 1.5px solid #fed7aa;
    border-radius: .85rem;
    padding: 1.25rem 1rem;
    margin: .5rem 0;
    width: 100%;
    box-sizing: border-box;
    animation: aichat-pop .2s ease;
}
.aichat-unavail-icon {
    width: 40px; height: 40px;
    background: #ffedd5;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto .65rem;
    color: #ea580c;
}
.aichat-unavail-icon svg { width: 22px; height: 22px; }
.aichat-unavail-title {
    font-size: .92rem;
    font-weight: 700;
    color: #9a3412;
    margin-bottom: .35rem;
}
.aichat-unavail-sub {
    font-size: .8rem;
    color: #c2410c;
    line-height: 1.5;
}

#aichat-input-area.is-unavailable {
    background: #f9fafb;
    opacity: .65;
    pointer-events: none;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    :root {
        --aichat-width: calc(100vw - 24px);
        --aichat-height: 70vh;
    }
    #aichat-window {
        right: 12px;
        bottom: 80px;
    }
    #aichat-launcher {
        right: 16px;
        bottom: 16px;
    }
}
