/**
 * Compos Customer Chat — frontend widget styles.
 *
 * Uses Compos brand tokens (--cp-accent, --cp-bg, --cp-surface,
 * --cp-text-*) so the chat picks up the operator's brand palette
 * automatically. No JavaScript theming.
 *
 * Float over content, position fixed, z-index above standard chrome.
 *
 * @since 2026-05-07
 */

#compos-chat-root {
    position: fixed;
    bottom: 20px;
    /* Stack: cart drawer (9999) + overlay (9998) sit ABOVE chat. Operator-
       flagged 2026-05-09 — chat bubble was covering the Buy Now button
       in the slide-out cart drawer. Chat lives below all transactional
       drawers / modals / overlays; only above page chrome. */
    z-index: 9990;
    font-family: var(--cp-font-body, system-ui, -apple-system, "Segoe UI", sans-serif);
    color: var(--cp-text, #111);
}

#compos-chat-root.compos-chat-position-bottom-right {
    right: 20px;
}
#compos-chat-root.compos-chat-position-bottom-left {
    left: 20px;
}

/* ============ Bubble ============ */

.compos-chat-bubble-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

#compos-chat-root.compos-chat-position-bottom-left .compos-chat-bubble-wrap {
    flex-direction: row-reverse;
}

.compos-chat-bubble-cta {
    background: var(--cp-bg, #fff);
    color: var(--cp-text, #111);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 999px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    border: 1px solid var(--cp-border, rgba(0,0,0,0.08));
    line-height: 1.4;
    user-select: none;
    transition: transform 150ms ease, box-shadow 150ms ease;
    animation: compos-chat-cta-pulse 2.5s ease-in-out 2;
}

.compos-chat-bubble-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
}

@keyframes compos-chat-cta-pulse {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-3px); }
}

.compos-chat-bubble {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--cp-accent, #ff650e);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.20);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 150ms ease, box-shadow 150ms ease;
    padding: 0;
}

.compos-chat-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}

.compos-chat-bubble:active {
    transform: translateY(0);
}

/* ============ Panel ============ */

.compos-chat-panel {
    position: absolute;
    bottom: 0;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 80px);
    background: var(--cp-bg, #fff);
    border: 1px solid var(--cp-border, rgba(0,0,0,0.08));
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.20);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: compos-chat-panel-slidein 200ms ease;
}

#compos-chat-root.compos-chat-position-bottom-right .compos-chat-panel { right: 0; }
#compos-chat-root.compos-chat-position-bottom-left  .compos-chat-panel { left: 0; }

@keyframes compos-chat-panel-slidein {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============ Header ============ */

.compos-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--cp-accent, #ff650e);
    color: #fff;
    flex-shrink: 0;
}

.compos-chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.compos-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.20);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.compos-chat-header-name {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.3;
}

.compos-chat-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    opacity: 0.9;
    margin-top: 2px;
}

.compos-chat-dot {
    width: 7px;
    height: 7px;
    background: #16a34a;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5);
    animation: compos-chat-dot-pulse 2s infinite;
}

@keyframes compos-chat-dot-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5); }
    70%  { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); }
    100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

.compos-chat-close {
    width: 30px;
    height: 30px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 150ms ease;
}

.compos-chat-close:hover {
    background: rgba(255, 255, 255, 0.30);
}

/* ============ Messages ============ */

.compos-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--cp-bg-alt, #f7f7f9);
}

.compos-chat-msg {
    max-width: 80%;
    display: flex;
}

.compos-chat-msg-body {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.compos-chat-msg-user {
    align-self: flex-end;
}

.compos-chat-msg-user .compos-chat-msg-body {
    background: var(--cp-accent, #ff650e);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.compos-chat-msg-assistant {
    align-self: flex-start;
}

.compos-chat-msg-assistant .compos-chat-msg-body {
    background: var(--cp-surface, #fff);
    color: var(--cp-text, #111);
    border: 1px solid var(--cp-border, rgba(0,0,0,0.06));
    border-bottom-left-radius: 4px;
}

/* Thinking indicator (typing dots) */

.compos-chat-typing {
    display: inline-flex;
    gap: 3px;
    padding: 4px 0;
}

.compos-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--cp-text-muted, #999);
    animation: compos-chat-typing-dot 1.2s infinite;
}

.compos-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.compos-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes compos-chat-typing-dot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30%           { opacity: 1; transform: translateY(-3px); }
}

/* ============ Input form ============ */

.compos-chat-form {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    background: var(--cp-bg, #fff);
    border-top: 1px solid var(--cp-border, rgba(0,0,0,0.06));
    flex-shrink: 0;
}

.compos-chat-input {
    flex: 1;
    padding: 9px 14px;
    font-size: 13px;
    background: var(--cp-bg-alt, #f5f5f7);
    border: 1px solid var(--cp-border, rgba(0,0,0,0.08));
    border-radius: 999px;
    color: var(--cp-text, #111);
    outline: none;
    transition: border-color 150ms ease;
    font-family: inherit;
}

.compos-chat-input:focus {
    border-color: var(--cp-accent, #ff650e);
    background: var(--cp-bg, #fff);
}

.compos-chat-send {
    width: 38px;
    height: 38px;
    background: var(--cp-accent, #ff650e);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 150ms ease, opacity 150ms ease;
}

.compos-chat-send:hover {
    transform: translateY(-1px);
}

.compos-chat-send:active {
    transform: translateY(0);
}

/* Mobile responsive */
@media (max-width: 480px) {
    .compos-chat-panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 90px);
        max-height: 600px;
    }
    .compos-chat-bubble-cta {
        display: none;  /* save real estate on mobile */
    }
}
