/* CrossMediaBot Chat Widget — SiteHarbour quiet-launch CSS */

#cx-chat-container {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 60px;
    height: 60px;
    padding: 0;
    overflow: hidden;
    border-radius: 50%;
    background: #1a1a2e;
    box-shadow: 0 4px 16px rgba(0,0,0,.18);
    z-index: 99999;
    cursor: pointer;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    transition: box-shadow .2s ease, transform .2s ease;

    --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;
}

/* Quiet collapsed state: visible as a small floating button from first paint. */
#cx-chat-container:not(.cx-open) #cx-header,
#cx-chat-container:not(.cx-open) #cx-body {
    display: none !important;
}

#cx-chat-container:not(.cx-open)::after {
    content: "";
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: var(--cx-header-bg, #1a1a2e) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23ffffff' viewBox='0 0 24 24' width='26' height='26'%3E%3Cpath d='M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z'/%3E%3C/svg%3E") no-repeat center;
}

#cx-chat-container:not(.cx-open):hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,.23);
}

/* Expanded chat panel. Width/height are deliberately NOT animated. */
#cx-chat-container.cx-open {
    width: 380px;
    height: auto;
    border-radius: 14px;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0 12px 32px rgba(0,0,0,.18);
    cursor: default;
}

#cx-chat-container.cx-open::after { display: none; }
#cx-chat-container.cx-open #cx-header { display: flex; }
#cx-chat-container.cx-open #cx-body { display: flex; }

/* 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,.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 .15s, border-color .15s;
    flex-shrink: 0;
}

#cx-toggle:hover,
#cx-close:hover {
    background: rgba(255,255,255,.16);
    border-color: rgba(255,255,255,.55);
}

/* Body and messages */
#cx-body { display: flex; flex-direction: column; }

#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: #f6f7f7; color: #50575e; border-left: 3px solid #c3c4c7; align-self: flex-start; }
.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: .2s; }
.cx-dots span:nth-child(3) { animation-delay: .4s; }

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

/* Input footer */
#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 .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 .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 .15s;
}
#cx-send:hover:not(:disabled) { opacity: .82; }
#cx-send:disabled { opacity: .40; cursor: not-allowed; }

/* 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: .75; }

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

/* 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: #ffffff;
    font-size: 13px;
    font-weight: 600;
    border-radius: 20px;
    text-decoration: none;
    transition: background .15s, transform .1s;
    white-space: nowrap;
    cursor: pointer;
    pointer-events: auto;
}
.cx-wa-btn:hover { background: #1ebe5a; transform: translateY(-1px); color: #ffffff; text-decoration: none; }
.cx-wa-btn * { cursor: pointer; }
.cx-wa-wait { font-size: 11px; color: #666666; margin: 6px 4px 0; line-height: 1.5; max-width: 90%; }
.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; }

/* Admin diagnostics and retry */
#cx-chat-widget .cx-admin-note {
    margin: 4px 0 2px;
    padding: 7px 9px;
    border-left: 3px solid #c3c4c7;
    background: #f6f7f7;
    color: #50575e;
    font-size: 11px;
    line-height: 1.45;
    border-radius: 3px;
}
#cx-chat-widget .cx-admin-note strong { color: #646970; }
#cx-chat-widget .cx-admin-msg { margin-top: 3px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; word-break: break-word; color: #787c82; }
#cx-chat-widget .cx-retry-bar { margin: 6px 0 2px; }
#cx-chat-widget .cx-retry-btn { background: transparent; border: 1px solid rgba(0,0,0,.18); border-radius: 14px; padding: 4px 12px; font-size: 12px; cursor: pointer; color: inherit; opacity: .8; }
#cx-chat-widget .cx-retry-btn:hover { opacity: 1; border-color: rgba(0,0,0,.35); }

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