/* ── CorePay Chatbot Widget ───────────────────────────────────────────────── */
/* Scoped under #corepay-chatbot-root to prevent theme interference.          */
/* Uses CSS custom properties from the global design system where available,  */
/* with inline fallbacks for environments where they are not loaded.          */

#corepay-chatbot-root *,
#corepay-chatbot-root *::before,
#corepay-chatbot-root *::after {
    box-sizing: border-box;
}

/* Use all:initial to break inheritance from theme, then re-declare everything needed */
#corepay-chatbot-root {
    all: initial;
    position: fixed;
    bottom: 1.5rem;
    left: 1.5rem;
    z-index: 9990;
    font-family: -apple-system, BlinkMacSystemFont, 'Geist', 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-base, #eef2ff);
    box-sizing: border-box;
}

/* Prevent theme from injecting margin/padding/list-style into widget children */
#corepay-chatbot-root p,
#corepay-chatbot-root ul,
#corepay-chatbot-root li {
    margin: 0;
    padding: 0;
    list-style: none;
}

/* ── Launcher button ──────────────────────────────────────────────────────── */

.cp-chat-launcher {
    width: 3.25rem;
    height: 3.25rem;
    border-radius: 50%;
    border: none;
    outline: none;
    background: var(--accent-solid, #0072A0);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 114, 160, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.15s;
    position: relative;
    z-index: 9991;
}

.cp-chat-launcher:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 20px rgba(0, 114, 160, 0.5);
    background: var(--accent, #009CDC);
}

.cp-chat-launcher__icon { transition: opacity 0.15s, transform 0.15s; }
.cp-chat-launcher__icon--close { position: absolute; opacity: 0; transform: rotate(-90deg); }
.cp-chat-launcher__icon--chat  { opacity: 1; transform: rotate(0); }

.cp-chat-launcher--open .cp-chat-launcher__icon--close { opacity: 1; transform: rotate(0); }
.cp-chat-launcher--open .cp-chat-launcher__icon--chat  { opacity: 0; transform: rotate(90deg); }

/* ── Widget panel — mobile-first, no !important ───────────────────────────── */

/* Mobile base: full-screen slide-up panel */
.cp-chat-widget {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    max-height: none;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface, #0f172a);
    border: 1px solid var(--border, rgba(255,255,255,0.08));
    border-radius: 0;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    opacity: 0;
    transform: translateY(100%);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    overscroll-behavior: contain;
}

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

/* Hide launcher when fullscreen — close button in header handles it */
.cp-chat-launcher--open {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* iOS Safari: inputs must be >= 16px to prevent auto-zoom on focus */
.cp-chat-text-input {
    font-size: 16px;
    touch-action: manipulation;
}
.cp-chat-option-btn,
.cp-chat-send-btn,
.cp-chat-skip-btn,
.cp-chat-pill,
.cp-chat-launcher { touch-action: manipulation; }

/* Desktop: constrained floating panel */
@media (min-width: 601px) {
    .cp-chat-widget {
        position: absolute;
        inset: auto;
        bottom: calc(3.25rem + 0.75rem);
        left: 0;
        width: 360px;
        height: auto;
        max-height: 560px;
        border-radius: var(--radius, 0.875rem);
        transform: translateY(12px) scale(0.97);
    }

    .cp-chat-widget--open {
        transform: translateY(0) scale(1);
    }

    /* Restore launcher visibility on desktop */
    .cp-chat-launcher--open {
        opacity: 1;
        pointer-events: auto;
        transform: scale(1.06);
    }

    .cp-chat-text-input { font-size: 0.9rem; }
}

@media (prefers-reduced-motion: reduce) {
    .cp-chat-widget, .cp-chat-launcher { transition: none; }
}

/* ── Header ───────────────────────────────────────────────────────────────── */

.cp-chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--bg-raised, #1e293b);
    border-bottom: 1px solid var(--border, rgba(255,255,255,0.06));
    flex-shrink: 0;
}

.cp-chat-header__avatar {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--accent-solid, #0072A0);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9375rem;
    flex-shrink: 0;
}

.cp-chat-header__info { flex: 1; min-width: 0; }

.cp-chat-header__name {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text-base, #eef2ff);
}

.cp-chat-header__status {
    font-size: 0.75rem;
    color: var(--text-muted, #94a3b8);
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.cp-chat-header__dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--success, #4ade80);
    display: inline-block;
    animation: cp-chat-pulse 2.5s ease-in-out infinite;
}

@keyframes cp-chat-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

@media (prefers-reduced-motion: reduce) {
    .cp-chat-header__dot { animation: none; }
}

.cp-chat-header__close {
    background: transparent;
    border: none;
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: color 0.15s;
}

.cp-chat-header__close:hover { color: var(--text-base, #eef2ff); }

/* ── Messages ─────────────────────────────────────────────────────────────── */

.cp-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.cp-chat-msg {
    display: flex;
    max-width: 88%;
}

.cp-chat-msg--bot  { align-self: flex-start; }
.cp-chat-msg--user { align-self: flex-end; }

.cp-chat-msg__bubble {
    padding: 0.625rem 0.875rem;
    border-radius: 1rem;
    font-size: 0.9rem;
    line-height: 1.6;
    word-break: break-word;
}

.cp-chat-msg--bot .cp-chat-msg__bubble {
    background: var(--bg-raised, #1e293b);
    color: var(--text-base, #eef2ff);
    border-radius: 0.25rem 1rem 1rem 1rem;
    border: 1px solid var(--border, rgba(255,255,255,0.06));
}

.cp-chat-msg--user .cp-chat-msg__bubble {
    background: var(--accent-solid, #0072A0);
    color: #fff;
    border-radius: 1rem 0.25rem 1rem 1rem;
}

.cp-chat-meta {
    font-size: 0.8125rem;
    color: var(--text-muted, #94a3b8);
    padding: 0 0.25rem;
    font-style: italic;
}

.cp-chat-info-wrap { padding: 0 0.25rem; }
.cp-chat-info-btn {
    font-size: 0.8125rem;
    color: var(--accent, #009CDC);
    background: transparent;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    padding: 0;
    transition: opacity 0.15s;
}
.cp-chat-info-btn:hover { opacity: 0.75; }

/* Typing indicator */
.cp-chat-msg--typing .cp-chat-msg__bubble {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.75rem 1rem;
}

.cp-chat-dot {
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 50%;
    background: var(--text-muted, #94a3b8);
    animation: cp-chat-bounce 1.2s ease-in-out infinite;
    display: inline-block;
}

.cp-chat-dot:nth-child(2) { animation-delay: 0.2s; }
.cp-chat-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes cp-chat-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%           { transform: translateY(-5px); }
}

@media (prefers-reduced-motion: reduce) {
    .cp-chat-dot { animation: none; opacity: 0.6; }
}

/* ── Input area ───────────────────────────────────────────────────────────── */

.cp-chat-input-area {
    padding: 0.75rem;
    border-top: 1px solid var(--border, rgba(255,255,255,0.06));
    flex-shrink: 0;
    background: var(--bg-surface, #0f172a);
    min-height: 3.5rem;
}

/* Option buttons */
.cp-chat-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.cp-chat-options--links {
    flex-direction: column;
}

.cp-chat-option-btn {
    padding: 0.5rem 0.875rem;
    border-radius: 2rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    background: var(--bg-raised, #1e293b);
    color: var(--text-base, #eef2ff);
    border: 1px solid var(--border, rgba(255,255,255,0.1));
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.4;
}

.cp-chat-option-btn:hover {
    border-color: var(--accent-ring, rgba(0,156,220,0.22));
    background: var(--accent-dim, rgba(0,156,220,0.1));
    color: var(--accent, #009CDC);
}

.cp-chat-option-btn--primary {
    background: var(--accent-solid, #0072A0);
    color: #fff;
    border-color: transparent;
}

.cp-chat-option-btn--primary:hover {
    background: var(--accent, #009CDC);
    color: #fff;
    border-color: transparent;
}

.cp-chat-option-btn--shake {
    animation: cp-chat-shake 0.4s ease;
}

@keyframes cp-chat-shake {
    0%, 100% { transform: translateX(0); }
    25%       { transform: translateX(-4px); }
    75%       { transform: translateX(4px); }
}

/* Multi-select pills */
.cp-chat-multi { display: flex; flex-direction: column; gap: 0.625rem; }

.cp-chat-multi__pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.cp-chat-pill {
    padding: 0.4rem 0.875rem;
    border-radius: 2rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    background: var(--bg-raised, #1e293b);
    color: var(--text-muted, #94a3b8);
    border: 1px solid var(--border, rgba(255,255,255,0.1));
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    white-space: nowrap;
}

.cp-chat-pill:hover {
    border-color: var(--accent-ring, rgba(0,156,220,0.22));
    color: var(--text-base, #eef2ff);
}

.cp-chat-pill--selected {
    background: var(--accent-dim, rgba(0,156,220,0.15));
    border-color: var(--accent, #009CDC);
    color: var(--accent, #009CDC);
    font-weight: 600;
}

.cp-chat-multi__continue {
    width: 100%;
    border-radius: var(--radius-sm, 0.4rem);
    padding: 0.625rem 1rem;
}

/* Text inputs */
.cp-chat-text-wrap {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.cp-chat-text-input {
    flex: 1;
    padding: 0.625rem 0.875rem;
    background: var(--bg-raised, #1e293b);
    border: 1px solid var(--border, rgba(255,255,255,0.1));
    border-radius: var(--radius-sm, 0.4rem);
    color: var(--text-base, #eef2ff);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s;
    width: 100%;
}

.cp-chat-text-input::placeholder { color: var(--text-muted, #94a3b8); }

.cp-chat-text-input:focus {
    border-color: var(--accent, #009CDC);
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-dim, rgba(0,156,220,0.1));
}

.cp-chat-text-input--error {
    border-color: var(--error, #f87171);
    animation: cp-chat-shake 0.4s ease;
}

.cp-chat-send-btn {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--accent-solid, #0072A0);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.cp-chat-send-btn:hover { background: var(--accent, #009CDC); }

.cp-chat-skip-btn {
    font-size: 0.8125rem;
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    background: transparent;
    white-space: nowrap;
    padding: 0 0.25rem;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.15s;
}

.cp-chat-skip-btn:hover { color: var(--text-base, #eef2ff); }
