/* ── SPCA FAQ Chatbot Widget ──────────────────────────────────────────────── */

:root {
    --chatbot-primary:    #e85d26;   /* SPCA orange */
    --chatbot-primary-dk: #c44d1e;
    --chatbot-bg:         #ffffff;
    --chatbot-surface:    #f7f7f7;
    --chatbot-border:     #e0e0e0;
    --chatbot-text:       #1a1a1a;
    --chatbot-text-muted: #666666;
    --chatbot-bot-bubble: #f0f0f0;
    --chatbot-user-bubble:#e85d26;
    --chatbot-radius:     16px;
    --chatbot-shadow:     0 8px 32px rgba(0,0,0,0.18);
    --chatbot-width:      360px;
    --chatbot-height:     500px;
    --chatbot-z:          9999;
}

/* ── Wrapper ── */
#spca-chatbot-wrapper {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--chatbot-z);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
}

/* ── Toggle Bubble ── */
#spca-chatbot-toggle {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--chatbot-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 4px 16px rgba(232,93,38,0.45);
    transition: background 0.2s, transform 0.2s;
    margin-left: auto;
}
#spca-chatbot-toggle:hover {
    background: var(--chatbot-primary-dk);
    transform: scale(1.07);
}
#spca-chatbot-toggle .spca-close-icon { display: none; }
#spca-chatbot-toggle.is-open .spca-chat-icon  { display: none; }
#spca-chatbot-toggle.is-open .spca-close-icon {
    display: block;
    color: #fff;
    font-size: 20px;
    font-style: normal;
}

/* ── Chat Window ── */
#spca-chatbot-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: var(--chatbot-width);
    height: var(--chatbot-height);
    background: var(--chatbot-bg);
    border-radius: var(--chatbot-radius);
    box-shadow: var(--chatbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: chatbot-pop-in 0.2s ease;
}
#spca-chatbot-window[hidden] { display: none; }

@keyframes chatbot-pop-in {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

/* ── Header ── */
#spca-chatbot-header {
    background: var(--chatbot-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.01em;
}
#spca-chatbot-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.15s;
    padding: 0;
}
#spca-chatbot-close:hover { opacity: 1; }

/* ── Messages ── */
#spca-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--chatbot-surface);
}
#spca-chatbot-messages::-webkit-scrollbar { width: 4px; }
#spca-chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--chatbot-border);
    border-radius: 4px;
}

/* ── Message Bubbles ── */
.spca-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    line-height: 1.5;
    word-break: break-word;
    font-size: 14px;
}
.spca-msg.bot {
    background: var(--chatbot-bot-bubble);
    color: var(--chatbot-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.spca-msg.user {
    background: var(--chatbot-user-bubble);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
/* Typing indicator */
.spca-msg.typing {
    background: var(--chatbot-bot-bubble);
    align-self: flex-start;
    padding: 12px 16px;
}
.spca-typing-dots span {
    display: inline-block;
    width: 6px; height: 6px;
    background: var(--chatbot-text-muted);
    border-radius: 50%;
    margin: 0 2px;
    animation: spca-bounce 1.2s infinite;
}
.spca-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.spca-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes spca-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%           { transform: translateY(-6px); }
}

/* ── Input Area ── */
#spca-chatbot-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    background: var(--chatbot-bg);
    border-top: 1px solid var(--chatbot-border);
}
#spca-chatbot-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--chatbot-border);
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 14px;
    line-height: 1.4;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}
#spca-chatbot-input:focus { border-color: var(--chatbot-primary); }
#spca-chatbot-send {
    background: var(--chatbot-primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    align-self: flex-end;
}
#spca-chatbot-send:hover    { background: var(--chatbot-primary-dk); }
#spca-chatbot-send:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Footer ── */
#spca-chatbot-footer {
    text-align: center;
    font-size: 11px;
    color: var(--chatbot-text-muted);
    padding: 6px;
    background: var(--chatbot-bg);
    border-top: 1px solid var(--chatbot-border);
}

/* ── Responsive ── */
@media (max-width: 420px) {
    :root {
        --chatbot-width:  calc(100vw - 16px);
        --chatbot-height: 420px;
    }
    #spca-chatbot-wrapper {
        bottom: 12px;
        right: 8px;
    }
}

/* ── Feedback ── */
.spca-msg-wrap { display: flex; flex-direction: column; align-self: flex-start; max-width: 82%; }
.spca-msg-wrap .spca-msg.bot { border-bottom-left-radius: 4px; max-width: 100%; }

.spca-feedback-block {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 6px 10px;
    background: #f0f0f0;
    border-radius: 0 0 10px 10px;
    border-top: 1px solid #e0e0e0;
}
.spca-feedback-prompt {
    font-size: 12px;
    color: var(--chatbot-text-muted);
    flex: 1 1 100%;
    margin-bottom: 2px;
}
.spca-feedback-btn {
    background: #fff;
    border: 1px solid var(--chatbot-border);
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.spca-feedback-btn:hover { background: #f7f7f7; border-color: #aaa; }
.spca-feedback-yes:hover { border-color: #4caf50; color: #2e7d32; }
.spca-feedback-no:hover  { border-color: var(--chatbot-primary); color: var(--chatbot-primary); }
.spca-feedback-thanks    { font-size: 12px; color: var(--chatbot-text-muted); font-style: italic; }

.spca-feedback-note-wrap { display: flex; gap: 6px; width: 100%; margin-top: 4px; }
.spca-feedback-note-input {
    flex: 1;
    border: 1px solid var(--chatbot-border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    outline: none;
}
.spca-feedback-note-input:focus { border-color: var(--chatbot-primary); }

/* ── Closed-chat banner (shown after abuse-triggered closure) ── */
#spca-chatbot-closed-banner {
    padding: 10px 14px;
    background: #fdecea;
    color: #b71c1c;
    font-size: 12px;
    text-align: center;
    border-top: 1px solid #f5c6c2;
    border-bottom: 1px solid #f5c6c2;
}

/* ── Live staff handoff ───────────────────────────────────────────────────── */
#spca-handoff-banner {
    padding: 8px 14px;
    background: #fff4e0;
    color: #8a4a00;
    font-size: 12px;
    text-align: center;
    border-top: 1px solid #f0d9a8;
    border-bottom: 1px solid #f0d9a8;
}
#spca-handoff-banner[data-kind="active"]    { background: #e6f4ea; color: #1f7a39; border-color: #c3e2cd; }
#spca-handoff-banner[data-kind="ended"]     { background: #eee; color: #555; border-color: #ddd; }
#spca-handoff-banner[data-kind="timed_out"] { background: #fdecea; color: #b71c1c; border-color: #f5c6c2; }

.spca-msg.staff {
    background: #ffeed1;
    color: #5a3a00;
    align-self: flex-start;
    border: 1px solid #f0d9a8;
    border-bottom-left-radius: 4px;
}
.spca-msg.system {
    background: transparent;
    color: #888;
    align-self: center;
    font-size: 12px;
    font-style: italic;
    padding: 4px 8px;
    max-width: 90%;
    text-align: center;
}
