/* ── Reset ─────────────────────────────────────────────────── */
.chatnpals-wrap *,
.chatnpals-wrap *::before,
.chatnpals-wrap *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Wrap — fixed on frontend (bubble mode only) ────────────── */
.chatnpals-wrap {
    position: fixed;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Inline mode: normal document flow, no z-index magic */
.chatnpals-wrap.cnp-inline-mode {
    position: relative !important;
    z-index: auto !important;
    bottom: auto !important;
    right: auto !important;
    left: auto !important;
    display: block;
}

/* In Elementor editor: show inline */
.elementor-editor-active .chatnpals-wrap {
    position: relative !important;
    bottom: auto !important; right: auto !important; left: auto !important;
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
}

/* ── Bubble button ──────────────────────────────────────────── */
.cf-bubble {
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform .2s ease, box-shadow .2s ease;
    position: relative;
    flex-shrink: 0;
}
.cf-bubble:hover  { transform: scale(1.07); }
.cf-bubble:active { transform: scale(.96); }
.cf-bubble img,
.cf-bubble svg    { display: block; flex-shrink: 0; pointer-events: none; }

.cf-dot {
    position: absolute; top: 3px; right: 3px;
    border-radius: 50%;
    border: 2.5px solid #fff;
    animation: cf-pulse 2.4s infinite;
    pointer-events: none;
}
@keyframes cf-pulse {
    0%,100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.25); opacity: .75; }
}

/* ── Chat window ────────────────────────────────────────────── */
.cf-window {
    /* display is controlled entirely by JS — never set here */
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,.14);
    position: absolute;
    bottom: 70px;
    right: 0;
    animation: cf-open .22s cubic-bezier(.34,1.56,.64,1) both;
}
/* When JS opens it, flex layout is applied via inline style */
.cf-window[hidden] { display: none !important; }
@keyframes cf-open {
    from { transform: scale(.85); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}
.elementor-editor-active .cf-window {
    position: relative !important;
    bottom: auto !important; right: auto !important; left: auto !important;
    display: flex !important;
    animation: none;
}

/* ── Header — rounded top corners, clips its own content ───── */
.cf-header {
    padding: 13px 15px;
    display: flex; align-items: center; gap: 10px;
    flex-shrink: 0;
    /* Top corners match window radius — set via inline style from PHP */
    /* This prevents the white bleed */
    overflow: hidden;
}

/* ── Avatar ─────────────────────────────────────────────────── */
.cf-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600; flex-shrink: 0;
    border: 1.5px solid rgba(255,255,255,.3);
}
.cf-header-info { flex: 1; overflow: hidden; }
.cf-name   { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cf-status { display: flex; align-items: center; gap: 5px; font-size: 11px; opacity: .75; }
.cf-online-dot { width: 6px; height: 6px; border-radius: 50%; }

/* ── Close button ───────────────────────────────────────────── */
.cf-close {
    background: none; border: none; cursor: pointer;
    line-height: 1; padding: 0; flex-shrink: 0;
    transition: opacity .15s, filter .15s;
    opacity: .85;
}
.cf-close:hover { opacity: 1; filter: brightness(1.2); }

/* ── Messages ───────────────────────────────────────────────── */
.cf-messages {
    flex: 1; overflow-y: auto;
    padding: 13px;
    display: flex; flex-direction: column;
    scroll-behavior: smooth;
}
.cf-messages::-webkit-scrollbar { width: 4px; }
.cf-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

.cf-msg { max-width: 83%; display: flex; flex-direction: column; gap: 2px; }
.cf-msg.bot  { align-self: flex-start; flex-direction: row; align-items: flex-end; gap: 0; }
.cf-msg.user { align-self: flex-end; }
.cf-msg.bot .cf-msg-body { display: flex; flex-direction: column; gap: 2px; }
.cf-bubble-msg { word-break: break-word; line-height: 1.5; }
.cf-msg-time   { font-size: 10px; color: #aaa; }
.cf-msg.user .cf-msg-time { text-align: right; }

/* Avatar in messages */
.cf-msg-avatar {
    width: 26px; height: 26px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    align-self: flex-end;
    margin-right: 7px;
}
.cf-msg-avatar-placeholder {
    width: 26px; height: 26px;
    border-radius: 50%;
    flex-shrink: 0;
    align-self: flex-end;
    margin-right: 7px;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 600;
    background: #e8e8e8; color: #555;
}

/* ── Typing indicator ───────────────────────────────────────── */
.cf-typing { display: flex; align-items: center; gap: 4px; padding: 10px 12px; }
.cf-typing span { width: 6px; height: 6px; background: #aaa; border-radius: 50%; animation: cf-bounce 1.2s infinite; }
.cf-typing span:nth-child(2) { animation-delay: .2s; }
.cf-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes cf-bounce {
    0%,60%,100% { transform: translateY(0); }
    30%          { transform: translateY(-5px); }
}

/* ── Bar ────────────────────────────────────────────────────── */
.cf-bar { flex-shrink: 0; }

.cf-accept-area {
    padding: 12px 14px;
    border-top: 1px solid rgba(0,0,0,.08);
    display: flex; flex-direction: column; gap: 7px;
    /* bottom corners match window radius — set via overflow:hidden on a wrapper */
    overflow: hidden;
}
.cf-accept-note { font-size: 11px; color: #999; text-align: center; }
.cf-accept-btn,
.cf-decline-btn {
    width: 100%; border: none; cursor: pointer; font-weight: 600;
    transition: filter .15s; text-align: center;
}
.cf-accept-btn:hover,
.cf-decline-btn:hover { filter: brightness(1.08); }
.cf-accept-btn:active,
.cf-decline-btn:active { filter: brightness(.94); }

.cf-progress {
    padding: 5px 14px; font-size: 10px; color: #bbb; text-align: center;
    border-top: 1px solid rgba(0,0,0,.08); letter-spacing: .3px;
}
.cf-input-area { padding: 9px 12px; border-top: 1px solid rgba(0,0,0,.08); }
.cf-input-row  { display: flex; gap: 8px; align-items: center; }
.cf-input-row input {
    flex: 1; border: 1px solid #e8e8e8;
    padding: 8px 13px; outline: none;
    transition: border-color .15s;
    font-family: inherit;
}
.cf-send-btn {
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: filter .15s;
}
.cf-send-btn:hover  { filter: brightness(1.12); }
.cf-send-btn:active { filter: brightness(.9); }
.cf-send-btn svg, .cf-send-btn img { display: block; pointer-events: none; }

/* Success box */
.cf-success { text-align: center; padding: 18px 14px; }
.cf-success-icon { width: 48px; height: 48px; background: #eaf3de; border-radius: 50%; margin: 0 auto 10px; display: flex; align-items: center; justify-content: center; }
.cf-success h4 { font-size: 14px; font-weight: 600; color: #222; margin-bottom: 4px; }
.cf-success p  { font-size: 12px; color: #888; }

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 400px) {
    .cf-window { width: calc(100vw - 32px) !important; right: 0 !important; }
    .chatnpals-wrap { right: 16px !important; bottom: 16px !important; }
}

/* ── Validation ─────────────────────────────────────────────── */
.cnp-error {
    font-size: 12px;
    color: #dc2626;
    margin-top: 5px;
    padding: 0 4px;
    line-height: 1.4;
    animation: cnp-shake .3s ease;
}
@keyframes cnp-shake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-5px); }
    60%       { transform: translateX(5px); }
    80%       { transform: translateX(-3px); }
}

/* ── Inline / content mode — window ─────────────────────────── */
.cnp-inline .cf-window {
    display: flex !important;
    position: relative !important;
    bottom: auto !important;
    right: auto !important;
    left: auto !important;
    visibility: visible !important;
    opacity: 1 !important;
    animation: none !important;
    box-shadow: 0 4px 24px rgba(0,0,0,.10);
}

/* ── Critical overrides — must come last ────────────────────── */
/* Inline mode window is ALWAYS visible */
.cnp-inline .cf-window,
.cnp-inline .cf-window[hidden] {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    bottom: auto !important;
    right: auto !important;
    left: auto !important;
    animation: none !important;
}
