/* ── CSS isolation: prevent WordPress theme styles from leaking in ───────── */
body button.sperling-chat-bubble,
body button.sperling-chat-close,
body button.sperling-chat-new,
body button.sperling-chat-undo,
body button.sperling-chat-send,
body button.sperling-chat-jump {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    box-sizing: border-box;
    display: inline-flex;
    margin: 0;
    text-transform: none;
    letter-spacing: normal;
    word-spacing: normal;
    white-space: nowrap;
    vertical-align: baseline;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.sperling-chat-window,
.sperling-chat-window * {
    box-sizing: border-box;
}

body button.sperling-chat-bubble,
.sperling-chat-window {
    --sp-brand: #2563eb;
    --sp-brand-strong: #1d4ed8;
    --sp-bg: #fff;
    --sp-assistant: #f1f5f9;
    --sp-text: #1e293b;
    --sp-muted: #64748b;
}

.sperling-chat-window {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--sp-text);
}
/* ────────────────────────────────────────────────────────────────────────── */

body button.sperling-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--sp-brand);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

body button.sperling-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 28px rgba(37, 99, 235, 0.45);
}

body button.sperling-chat-bubble:active {
    transform: scale(0.96);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}

body button.sperling-chat-bubble svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
    display: block;
    flex-shrink: 0;
}

.sperling-chat-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 380px;
    height: 560px;
    background: var(--sp-bg);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    z-index: 99999;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.sperling-chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.sperling-chat-window.sperling-chat-inline {
    position: static;
    width: var(--sp-w, 100%);
    max-width: 100%;
    height: var(--sp-h, 560px);
    bottom: auto;
    right: auto;
    left: auto;
    opacity: 1;
    transform: none;
    pointer-events: auto;
    z-index: auto;
    border: 1px solid #e2e8f0;
    /* Re-assert the rounded corners the mobile full-screen override drops;
       this selector outranks it, so one declaration covers every width. */
    border-radius: 16px;
}

.sperling-chat-header {
    background: var(--sp-brand);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.sperling-chat-header-copy {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1;
}

.sperling-chat-header-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

.sperling-chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-right: 12px;
}

.sperling-chat-bubble-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

body button.sperling-chat-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    font-size: 20px;
    font-weight: normal;
    opacity: 0.8;
    transition: opacity 0.15s;
    width: auto;
    height: auto;
    border-radius: 0;
    box-shadow: none;
}

body button.sperling-chat-close:hover {
    opacity: 1;
    background: none;
    box-shadow: none;
}

.sperling-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

body button.sperling-chat-new {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.15s;
    width: auto;
    height: auto;
    border-radius: 4px;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

body button.sperling-chat-new:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
    box-shadow: none;
}

body button.sperling-chat-new svg {
    display: block;
}

.sperling-chat-toast {
    position: absolute;
    left: 16px;
    right: 16px;
    top: 12px;
    bottom: auto;
    background: #1e293b;
    color: #fff;
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 13px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 3;
}

.sperling-chat-messages-wrap.sperling-toast-open .sperling-chat-messages {
    padding-top: 68px;
}

.sperling-chat-toast.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.sperling-chat-toast-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body button.sperling-chat-undo {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: #fff;
    cursor: pointer;
    padding: 4px 10px;
    line-height: 1.4;
    font-size: 13px;
    font-weight: 500;
    border-radius: 8px;
    box-shadow: none;
    width: auto;
    height: auto;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
}

body button.sperling-chat-undo:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: #fff;
}

body button.sperling-chat-jump {
    position: absolute;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--sp-brand);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
    z-index: 2;
    width: auto;
    height: auto;
}

body button.sperling-chat-jump[hidden] {
    display: none;
}

body button.sperling-chat-jump:hover {
    background: var(--sp-brand-strong);
}

body button.sperling-chat-jump svg {
    display: block;
    flex-shrink: 0;
}

@keyframes sperling-jump-bounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-8px); }
}

body button.sperling-chat-jump.sperling-chat-jump-bounce {
    animation: sperling-jump-bounce 0.65s ease-in-out 8;
}

.sperling-chat-messages-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.sperling-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    transition: padding-top 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: stretch;
    background: #f8fafc;
    position: relative;
}

.sperling-chat-messages > * {
    flex-shrink: 0;
}

.sperling-chat-window .sperling-msg {
    max-width: 85% !important;
    padding: 10px 14px !important;
    border-radius: 16px !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    overflow-wrap: break-word !important;
    word-wrap: break-word !important;
    margin: 0 !important;
    float: none !important;
    clear: both !important;
    position: relative !important;
}

.sperling-chat-window .sperling-msg.sperling-msg-in {
    animation: sperling-msg-fade-in 0.2s ease-out;
}

@keyframes sperling-msg-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.sperling-msg-text {
    display: block;
}

.sperling-chat-window .sperling-msg-text p {
    margin: 0 0 8px 0 !important;
    padding: 0;
    font-size: 14px;
    line-height: 1.5;
}

.sperling-chat-window .sperling-msg-text p:last-child {
    margin-bottom: 0 !important;
}

.sperling-chat-window .sperling-msg.sperling-msg-user {
    align-self: flex-end;
    background: var(--sp-brand) !important;
    color: #fff !important;
    border-bottom-right-radius: 6px;
    position: relative;
    display: block;
}

.sperling-chat-window .sperling-msg.sperling-msg-assistant {
    align-self: flex-start;
    background: var(--sp-assistant) !important;
    color: var(--sp-text) !important;
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    position: relative;
    display: block;
}

.sperling-chat-window .sperling-msg-assistant a {
    color: var(--sp-brand);
    text-decoration: underline;
}

.sperling-chat-window .sperling-msg.sperling-msg-assistant .sperling-sources {
    margin-top: 8px !important;
    padding-top: 8px !important;
    border-top: 1px solid #cbd5e1 !important;
    font-size: 12px !important;
    background: #f1f5f9 !important;
    position: relative !important;
    display: block !important;
    width: auto !important;
    float: none !important;
    clear: both !important;
    margin-left: -14px !important;
    margin-right: -14px !important;
    margin-bottom: -10px !important;
    padding-left: 14px !important;
    padding-right: 14px !important;
    padding-bottom: 10px !important;
    border-bottom-left-radius: 6px !important;
    border-bottom-right-radius: 16px !important;
}

.sperling-chat-window .sperling-sources-toggle {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    width: auto !important;
    min-height: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    font-family: inherit !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    line-height: 1.4 !important;
    letter-spacing: normal !important;
    text-transform: none !important;
    text-align: left !important;
    color: var(--sp-muted) !important;
    cursor: pointer !important;
}

.sperling-chat-window .sperling-sources-toggle:hover .sperling-sources-title {
    text-decoration: underline !important;
}

.sperling-chat-window .sperling-sources-toggle:focus-visible {
    outline: 2px solid var(--sp-brand) !important;
    outline-offset: 2px !important;
}

.sperling-chat-window .sperling-sources-caret {
    display: inline-block !important;
    font-size: 10px !important;
    line-height: 1 !important;
    color: inherit !important;
    background: transparent !important;
}

.sperling-chat-window .sperling-sources-title {
    font-weight: 600 !important;
    color: var(--sp-muted) !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
}

.sperling-chat-window .sperling-sources-list {
    margin-top: 4px !important;
    background: transparent !important;
}

.sperling-chat-window .sperling-sources-list[hidden] {
    display: none !important;
}

.sperling-chat-window .sperling-sources a {
    display: block !important;
    color: var(--sp-brand) !important;
    text-decoration: underline !important;
    padding: 2px 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    background: transparent !important;
    margin: 0 !important;
}

.sperling-chat-window .sperling-sources a:hover {
    text-decoration: underline !important;
}

.sperling-chat-window .sperling-msg.sperling-msg-assistant .sperling-recommendations {
    margin-top: 8px !important;
    padding-top: 8px !important;
    border-top: 1px solid #cbd5e1 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    background: transparent !important;
    position: relative !important;
    width: auto !important;
    float: none !important;
    clear: both !important;
}

/* Resting + hover cssText in chatbot.js appendRecommendationsToMessage must stay in sync. */
.sperling-chat-window .sperling-recommendation-chip {
    display: inline-block !important;
    padding: 8px 12px !important;
    background: #fff !important;
    color: var(--sp-brand) !important;
    border: 1px solid var(--sp-brand) !important;
    border-radius: 16px !important;
    text-decoration: none !important;
    font-size: 12px !important;
    line-height: 1.4 !important;
    cursor: pointer !important;
    font-family: inherit !important;
    margin: 0 !important;
    text-align: left !important;
    max-width: 100% !important;
    overflow-wrap: break-word !important;
}

.sperling-chat-window .sperling-recommendation-chip:hover {
    background: var(--sp-brand) !important;
    border-color: var(--sp-brand) !important;
    color: #fff !important;
}

.sperling-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 10px 14px;
    align-self: flex-start;
    background: #f1f5f9;
    border-radius: 16px;
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.sperling-typing-dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: sperling-bounce 1.2s ease-in-out infinite;
}

.sperling-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.sperling-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes sperling-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

.sperling-chat-input-area {
    display: flex;
    padding: 12px 16px;
    border-top: 1px solid #e2e8f0;
    gap: 8px;
    flex-shrink: 0;
    background: #fff;
}

.sperling-chat-disclaimer {
    flex-shrink: 0;
    padding: 6px 16px 12px;
    text-align: center;
    font-size: 11px;
    line-height: 1.4;
    color: var(--sp-muted);
    background: #fff;
}

.sperling-chat-disclaimer a {
    color: var(--sp-brand);
    text-decoration: underline;
}

.sperling-chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    font-family: inherit;
    line-height: 1.4;
    max-height: 80px;
}

.sperling-chat-input:focus {
    border-color: var(--sp-brand);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

body button.sperling-chat-send {
    background: var(--sp-brand-strong);
    color: #fff;
    border: none;
    border-radius: 50%;
    padding: 0;
    width: 38px;
    height: 38px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    flex-shrink: 0;
    align-self: flex-end;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

body button.sperling-chat-send svg {
    display: block;
    flex-shrink: 0;
}

body button.sperling-chat-send:hover {
    transform: scale(1.06);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

body button.sperling-chat-send:active {
    transform: scale(0.94);
}

body button.sperling-chat-send:disabled {
    background: var(--sp-brand-strong);
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

@media (max-width: 480px) {
    .sperling-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
    }

    body button.sperling-chat-bubble {
        bottom: 16px;
        right: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sperling-chat-window,
    .sperling-chat-window.open,
    .sperling-chat-toast,
    .sperling-chat-toast.open,
    .sperling-chat-messages,
    body button.sperling-chat-bubble,
    body button.sperling-chat-send,
    body button.sperling-chat-jump,
    body button.sperling-chat-jump.sperling-chat-jump-bounce,
    .sperling-chat-window .sperling-msg.sperling-msg-in {
        animation: none;
        transition: none;
    }
}
