/* ── CrossMediaBot Chat Widget — v2.0 ─────────────────────────────────────── */

/*
 * Color tokens (all overridden by admin-set inline style):
 *   --cx-header-bg      header background          #1a1a2e
 *   --cx-header-text    header text & button color #ffffff
 *   --cx-user-bg        user bubble background     #f0f4ff
 *   --cx-user-text      user bubble text           #1a1a2e
 *   --cx-bot-bg         bot bubble background      #f6f6f6
 *   --cx-text-color     bot message text           #000000
 *   --cx-link-color     bot message links          #1a1a2e
 *   --cx-send-bg        send button background     #1a1a2e
 */

#cx-chat-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 320px;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
    z-index: 99999;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;

    /* Default token values — overridden by wp_add_inline_style() */
    --cx-header-bg:    #1a1a2e;
    --cx-header-text:  #ffffff;
    --cx-user-bg:      #f0f4ff;
    --cx-user-text:    #1a1a2e;
    --cx-bot-bg:       #f6f6f6;
    --cx-text-color:   #000000;
    --cx-link-color:   #1a1a2e;
    --cx-send-bg:      #1a1a2e;
}

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

#cx-header {
    background: var(--cx-header-bg);
    color: var(--cx-header-text);
    padding: 11px 12px;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: default;
    user-select: none;
    gap: 8px;
}

#cx-header-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#cx-header-btns {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

#cx-toggle,
#cx-close {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.30);
    color: var(--cx-header-text);
    border-radius: 4px;
    width: 24px;
    height: 24px;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

#cx-toggle:hover,
#cx-close:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.55);
}

/* ── Body ────────────────────────────────────────────────────────────────── */

#cx-body {
    display: flex;
    flex-direction: column;
}

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

#cx-messages {
    height: 280px;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

.cx-msg {
    padding: 8px 10px;
    border-radius: 8px;
    max-width: 100%;
    word-break: break-word;
}

.u-msg {
    background: var(--cx-user-bg);
    color: var(--cx-user-text);
    align-self: flex-end;
}

.b-msg {
    background: var(--cx-bot-bg);
    color: var(--cx-text-color);
    align-self: flex-start;
}

.cx-error {
    background: #fff0f0;
    color: #c00000;
    border-left: 3px solid #c00000;
    align-self: flex-start;
}

/* ── Typing indicator ────────────────────────────────────────────────────── */

.cx-typing {
    background: var(--cx-bot-bg);
    align-self: flex-start;
}

.cx-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
    height: 16px;
    vertical-align: middle;
}

.cx-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--cx-text-color);
    border-radius: 50%;
    animation: cx-bounce 1.2s infinite ease-in-out;
}

.cx-dots span:nth-child(2) { animation-delay: 0.2s; }
.cx-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cx-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40%            { transform: scale(1);   opacity: 1;   }
}

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

#cx-footer {
    padding: 10px;
    border-top: 1px solid #eeeeee;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #fafafa;
}

#cx-char-counter {
    font-size: 11px;
    color: #999999;
    text-align: right;
    padding-right: 2px;
    transition: color 0.2s;
}

#cx-char-counter.cx-over-limit {
    color: #c00000;
    font-weight: 600;
}

.cx-input-row {
    display: flex;
    gap: 6px;
}

#cx-input {
    flex: 1;
    border: 1px solid #dddddd;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13px;
    background: #ffffff;
    color: #1a1a1a;
    outline: none;
    transition: border-color 0.15s;
}

#cx-input:focus {
    border-color: var(--cx-send-bg);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--cx-send-bg) 20%, transparent);
}

#cx-input:disabled {
    background: #f5f5f5;
    color: #aaaaaa;
}

#cx-send {
    background: var(--cx-send-bg);
    color: var(--cx-header-text);
    border: none;
    border-radius: 8px;
    width: 36px;
    min-width: 36px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s;
}

#cx-send:hover:not(:disabled) {
    opacity: 0.82;
}

#cx-send:disabled {
    opacity: 0.40;
    cursor: not-allowed;
}

/* ── Internal links in bot replies ───────────────────────────────────────── */

.b-msg .cx-content a {
    color: var(--cx-link-color);
    text-decoration: underline;
    word-break: break-word;
}

.b-msg .cx-content a:hover {
    opacity: 0.75;
}

/* ── Testing mode badge ──────────────────────────────────────────────────── */

#cx-test-badge {
    display: inline-block;
    background: #c07000;
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
    cursor: default;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 400px) {
    #cx-chat-container {
        width: calc(100vw - 32px);
        right: 16px;
        bottom: 16px;
    }
}

/* ─── WhatsApp escalation ───────────────────────────────────────────────── */
.cx-wa-wrap {
    margin: 6px 10px 4px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.cx-wa-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: #25d366;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    border-radius: 20px;
    text-decoration: none;
    transition: background .15s, transform .1s;
    white-space: nowrap;
}
.cx-wa-btn:hover {
    background: #1ebe5a;
    transform: translateY(-1px);
    color: #fff;
    text-decoration: none;
}

.cx-wa-wait {
    font-size: 11px;
    color: #666;
    margin: 6px 4px 0;
    line-height: 1.5;
    max-width: 90%;
}

/* button_top mode */
.cx-wa-top {
    padding: 7px 10px 6px;
    background: #f0faf4;
    border-bottom: 1px solid #d4edda;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.cx-wa-btn-top {
    font-size: 12px;
    padding: 5px 12px;
    background: #25d366;
}
.cx-wa-wait-top {
    margin: 5px 2px 0;
}
