/* WP AI Assistant - Chat Widget */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600&display=swap');

:root {
    --wpaia-accent: #1aaa8c;
    --wpaia-accent-dark: #1aaa8ccc;
}

#wpaia-wrapper {
    position: fixed;
    bottom: 24px;
    z-index: 999999;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}
#wpaia-wrapper.wpaia-right { right: 24px; }
#wpaia-wrapper.wpaia-left { left: 24px; }

/* Toggle button */
#wpaia-toggle {
    width: 62px; height: 62px;
    border-radius: 50%;
    background: var(--wpaia-accent);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    box-shadow: 0 4px 24px rgba(0,0,0,.22), 0 0 0 0 var(--wpaia-accent);
    transition: transform .2s, box-shadow .2s;
    position: relative;
    animation: wpaia-pulse 3s infinite;
    z-index: 2;
}
@keyframes wpaia-pulse {
    0%  { box-shadow: 0 4px 24px rgba(0,0,0,.22), 0 0 0 0 var(--wpaia-accent-dark); }
    70% { box-shadow: 0 4px 24px rgba(0,0,0,.22), 0 0 0 14px rgba(26,170,140,0); }
    100%{ box-shadow: 0 4px 24px rgba(0,0,0,.22), 0 0 0 0 rgba(26,170,140,0); }
}
#wpaia-toggle:hover { transform: scale(1.08); }
#wpaia-toggle.is-open { animation: none; background: #e53e3e; }
#wpaia-toggle svg { width: 24px; height: 24px; }

/* Unread badge */
#wpaia-unread-badge {
    position: absolute; top: -2px; right: -2px;
    background: #ef4444; color: #fff;
    width: 18px; height: 18px; border-radius: 50%;
    font-size: 11px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid #fff;
}

/* Chat window */
#wpaia-window {
    position: absolute;
    bottom: 74px;
    width: 360px;
    max-height: 540px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 8px 40px rgba(0,0,0,.18), 0 1px 4px rgba(0,0,0,.06);
    display: flex; flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: wpaia-pop-in .22s cubic-bezier(.175,.885,.32,1.275);
}
.wpaia-left #wpaia-window {
    right: auto; left: 0;
    transform-origin: bottom left;
    animation: wpaia-pop-in-left .22s cubic-bezier(.175,.885,.32,1.275);
}
.wpaia-right #wpaia-window { right: 0; }
@keyframes wpaia-pop-in {
    from { opacity: 0; transform: scale(.85) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes wpaia-pop-in-left {
    from { opacity: 0; transform: scale(.85) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Header */
#wpaia-header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 18px;
    background: var(--wpaia-accent);
    color: #fff;
    flex-shrink: 0;
}
#wpaia-header-avatar {
    width: 38px; height: 38px;
    background: rgba(255,255,255,.2);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
#wpaia-header-avatar svg { width: 20px; height: 20px; }
#wpaia-header-info { flex: 1; }
#wpaia-header-name { font-weight: 700; font-size: 15px; line-height: 1; }
#wpaia-header-status {
    font-size: 12px; opacity: .85; margin-top: 3px;
    display: flex; align-items: center; gap: 5px;
}
.wpaia-status-dot {
    width: 7px; height: 7px;
    background: #4ade80; border-radius: 50%;
    animation: wpaia-blink 2s infinite;
}
@keyframes wpaia-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: .5; }
}
#wpaia-minimize {
    background: rgba(255,255,255,.15); border: none;
    width: 32px; height: 32px; border-radius: 50%;
    cursor: pointer; color: #fff;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s; flex-shrink: 0;
}
#wpaia-minimize:hover { background: rgba(255,255,255,.3); }
#wpaia-minimize svg { width: 16px; height: 16px; }

/* Messages */
#wpaia-messages {
    flex: 1; overflow-y: auto;
    padding: 18px 16px;
    display: flex; flex-direction: column; gap: 14px;
    scroll-behavior: smooth;
}
#wpaia-messages::-webkit-scrollbar { width: 4px; }
#wpaia-messages::-webkit-scrollbar-track { background: transparent; }
#wpaia-messages::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 99px; }

.wpaia-msg {
    display: flex; gap: 8px; align-items: flex-end;
    animation: wpaia-msg-in .2s ease;
}
@keyframes wpaia-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.wpaia-msg--user { flex-direction: row-reverse; }

.wpaia-msg-avatar {
    width: 28px; height: 28px;
    background: var(--wpaia-accent);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff; flex-shrink: 0;
}
.wpaia-msg-avatar svg { width: 15px; height: 15px; }
.wpaia-msg--user .wpaia-msg-avatar { display: none; }

.wpaia-msg-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px; line-height: 1.55;
    word-break: break-word;
}
.wpaia-msg--bot .wpaia-msg-bubble {
    background: #f3f4f6;
    color: #111827;
    border-bottom-left-radius: 4px;
}
.wpaia-msg--user .wpaia-msg-bubble {
    background: var(--wpaia-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.wpaia-msg-sender {
    display: block; font-size: 11px; font-weight: 700;
    color: var(--wpaia-accent); margin-bottom: 4px;
    opacity: .85;
}
.wpaia-msg-bubble p { margin: 0; }

/* Typing indicator */
#wpaia-typing {
    display: flex; align-items: center; gap: 4px;
    padding: 10px 14px;
    background: #f3f4f6;
    border-radius: 16px; border-bottom-left-radius: 4px;
    width: fit-content; margin: 0 0 0 36px;
}
#wpaia-typing span {
    width: 7px; height: 7px;
    background: #9ca3af;
    border-radius: 50%;
    animation: wpaia-bounce .8s infinite;
}
#wpaia-typing span:nth-child(2) { animation-delay: .1s; }
#wpaia-typing span:nth-child(3) { animation-delay: .2s; }
@keyframes wpaia-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* Error message */
.wpaia-msg--error .wpaia-msg-bubble {
    background: #fee2e2; color: #991b1b;
}

/* Input area */
#wpaia-input-area {
    padding: 12px 14px 14px;
    border-top: 1px solid #f3f4f6;
    flex-shrink: 0;
}
#wpaia-input-row {
    display: flex; gap: 8px; align-items: flex-end;
}
#wpaia-input {
    flex: 1; padding: 10px 14px;
    border: 1.5px solid #e5e7eb;
    border-radius: 12px;
    font-size: 14px; font-family: inherit;
    resize: none; outline: none;
    line-height: 1.5; color: #111827;
    max-height: 100px; overflow-y: auto;
    transition: border-color .15s;
}
#wpaia-input:focus { border-color: var(--wpaia-accent); }
#wpaia-input::placeholder { color: #9ca3af; }

#wpaia-send {
    width: 40px; height: 40px; border-radius: 10px;
    background: var(--wpaia-accent); border: none;
    cursor: pointer; color: #fff;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: all .15s;
}
#wpaia-send:hover { opacity: .85; transform: scale(1.05); }
#wpaia-send:disabled { opacity: .4; cursor: default; transform: none; }
#wpaia-send svg { width: 18px; height: 18px; }

#wpaia-footer-note {
    font-size: 11px; color: #d1d5db;
    text-align: center; margin-top: 8px;
}

/* ── Avatar swap fade ─────────────────────────────────── */
#wpaia-peek {
    transition: opacity .3s ease, transform .3s ease;
}
#wpaia-peek.wpaia-swap-fade-out {
    opacity: 0 !important;
    transform: translateX(-50%) translateY(6px) !important;
}
#wpaia-peek.wpaia-swap-fade-in {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Peek Avatar ──────────────────────────────────────── */
#wpaia-peek {
    position: absolute;
    bottom: 58px;
    left: 50%;
    transform: translateX(-50%) translateY(40px); /* starts hidden below FAB */
    width: 82px;
    pointer-events: none;
    z-index: 1;                 /* BEHIND the FAB (z-index: 2) */
    filter: drop-shadow(0 6px 16px rgba(0,0,0,.22));
    opacity: 0;                 /* invisible on load */
    transition: opacity .3s, transform .3s;
    object-fit: contain;
    object-position: center bottom;
}

/* peek idle bob */
#wpaia-peek.wpaia-peek--visible {
    opacity: 1;
    pointer-events: auto;
    cursor: pointer;
    animation: wpaia-peek-bob 3.2s ease-in-out infinite;
}
@keyframes wpaia-peek-bob {
    0%,100% { transform: translateX(-50%) translateY(0)    rotate(-1.5deg); opacity: 1; }
    50%     { transform: translateX(-50%) translateY(-10px) rotate(1.5deg);  opacity: 1; }
}

/* fully hidden — pushed back down behind FAB */
#wpaia-peek.wpaia-peek--hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(40px);
    pointer-events: none;
    cursor: default;
}

/* Speech bubble — sits to the left of the avatar on right-position,
   to the right on left-position. Anchored relative to #wpaia-wrapper */
#wpaia-peek-bubble {
    position: absolute;
    bottom: 168px;      /* above the avatar */
    white-space: nowrap;
    background: #fff;
    border: 1.5px solid #d1fae5;
    border-radius: 16px 16px 4px 16px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    color: #065f46;
    box-shadow: 0 4px 20px rgba(0,0,0,.12);
    pointer-events: none;
    transition: opacity .35s, transform .35s;
    transform-origin: bottom right;
    line-height: 1.4;
}

/* Right widget: bubble opens to the left */
.wpaia-right #wpaia-peek-bubble {
    right: 0;
    border-radius: 16px 16px 4px 16px;
}
/* Left widget: bubble opens to the right */
.wpaia-left #wpaia-peek-bubble {
    left: 0;
    border-radius: 16px 16px 16px 4px;
}

/* Tail — right side */
.wpaia-right #wpaia-peek-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px; right: 18px;
    border: 7px solid transparent;
    border-top-color: #d1fae5;
}
.wpaia-right #wpaia-peek-bubble::before {
    content: '';
    position: absolute;
    bottom: -6px; right: 19px;
    border: 6px solid transparent;
    border-top-color: #fff;
    z-index: 1;
}
/* Tail — left side */
.wpaia-left #wpaia-peek-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px; left: 18px;
    border: 7px solid transparent;
    border-top-color: #d1fae5;
}
.wpaia-left #wpaia-peek-bubble::before {
    content: '';
    position: absolute;
    bottom: -6px; left: 19px;
    border: 6px solid transparent;
    border-top-color: #fff;
    z-index: 1;
}

#wpaia-peek-bubble.wpaia-peek-bubble--hidden {
    opacity: 0;
    transform: scale(.88) translateY(6px);
    pointer-events: none;
}

/* Entry — avatar rises up out of the FAB button */
@keyframes wpaia-peek-enter {
    0%   { opacity: 0;   transform: translateX(-50%) translateY(40px)  rotate(0deg); }
    40%  { opacity: 1;   transform: translateX(-50%) translateY(-14px) rotate(-2deg); }
    65%  { opacity: 1;   transform: translateX(-50%) translateY(4px)   rotate(1deg); }
    82%  { opacity: 1;   transform: translateX(-50%) translateY(-5px)  rotate(-.8deg); }
    100% { opacity: 1;   transform: translateX(-50%) translateY(0)     rotate(0deg); }
}
#wpaia-peek.wpaia-peek--enter {
    animation: wpaia-peek-enter .8s cubic-bezier(.175,.885,.32,1.275) forwards;
}

/* Mobile — chat window stays fully on screen */
@media (max-width: 480px) {
    #wpaia-wrapper.wpaia-right,
    #wpaia-wrapper.wpaia-left {
        right: 16px;
        left: auto;
    }
    #wpaia-window {
        position: fixed !important;
        bottom: 96px !important;
        right: 16px !important;
        left: 16px !important;
        width: auto !important;
        max-height: 72vh;
    }
    .wpaia-left #wpaia-window {
        right: 16px !important;
        left: 16px !important;
    }
    #wpaia-peek        { width: 68px; bottom: 54px; }
    #wpaia-peek-bubble {
        font-size: 12px; padding: 7px 11px; bottom: 150px;
        max-width: calc(100vw - 100px);
        white-space: normal;
    }
}
