.cpaic-chat {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 999999;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.cpaic-launcher {
    -webkit-appearance: none !important;
    appearance: none !important;
    box-sizing: border-box !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 56px !important;
    min-width: 56px !important;
    max-width: 56px !important;
    height: 56px !important;
    min-height: 56px !important;
    max-height: 56px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 50% !important;
    background: #245f91 !important;
    color: #fff !important;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .22) !important;
    cursor: pointer;
    line-height: 1 !important;
    text-decoration: none !important;
    transition: transform .15s ease, box-shadow .15s ease;
}

.cpaic-launcher:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 28px rgba(0, 0, 0, .26) !important;
}

.cpaic-launcher:focus-visible {
    outline: 3px solid rgba(34, 113, 177, .35);
    outline-offset: 3px;
}

/* Draw the icon with CSS rather than SVG so theme-wide SVG rules cannot hide it. */
.cpaic-launcher-icon {
    position: relative !important;
    display: block !important;
    box-sizing: border-box !important;
    width: 29px !important;
    height: 22px !important;
    border-radius: 11px !important;
    background: #fff !important;
    color: #245f91 !important;
    overflow: visible !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.cpaic-launcher-icon::after {
    content: "";
    position: absolute;
    right: 3px;
    bottom: -5px;
    width: 10px;
    height: 10px;
    background: #fff;
    clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.cpaic-launcher-dots,
.cpaic-launcher-dots::before,
.cpaic-launcher-dots::after {
    position: absolute;
    top: 9px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #245f91;
    content: "";
}

.cpaic-launcher-dots {
    left: 12.5px;
}

.cpaic-launcher-dots::before {
    top: 0;
    left: -7px;
}

.cpaic-launcher-dots::after {
    top: 0;
    left: 7px;
}

.cpaic-panel {
    position: absolute;
    right: 0;
    bottom: 70px;
    width: min(380px, calc(100vw - 28px));
    height: min(560px, calc(100vh - 100px));
    background: #fff;
    color: #1d2327;
    border: 1px solid #dcdcde;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.cpaic-panel[hidden] {
    display: none;
}

.cpaic-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 48px;
    padding: 12px 14px 12px 16px;
    border-bottom: 1px solid #eee;
}

.cpaic-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #50575e;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.cpaic-close:hover {
    background: #f0f0f1;
}

.cpaic-messages {
    flex: 1;
    overflow: auto;
    padding: 14px;
    background: #f6f7f7;
}

.cpaic-message {
    max-width: 86%;
    margin: 0 0 10px;
    padding: 10px 12px;
    border-radius: 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.cpaic-assistant {
    background: #fff;
    border: 1px solid #ddd;
}

.cpaic-user {
    margin-left: auto;
    background: #1d2327;
    color: #fff;
}

.cpaic-form {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #eee;
}

.cpaic-form textarea {
    flex: 1;
    resize: none;
    border: 1px solid #8c8f94;
    border-radius: 8px;
    padding: 8px;
}

.cpaic-form button {
    align-self: stretch;
    border: 0;
    border-radius: 8px;
    padding: 0 14px;
    background: #2271b1;
    color: #fff;
    font-weight: 600;
}

.cpaic-form.is-busy {
    opacity: .65;
    pointer-events: none;
}

@media (max-width: 480px) {
    .cpaic-chat {
        right: 10px;
        bottom: 10px;
    }

    .cpaic-panel {
        width: calc(100vw - 20px);
        height: 70vh;
    }
}

.cpaic-assistant a {
    color: #2271b1;
    text-decoration: underline;
    text-underline-offset: 2px;
    overflow-wrap: anywhere;
}

.cpaic-assistant a:hover,
.cpaic-assistant a:focus {
    text-decoration-thickness: 2px;
}

.cpaic-thinking {
    width: fit-content;
    min-width: 48px;
    letter-spacing: 3px;
    font-weight: 700;
    color: #646970;
    animation: cpaic-thinking-pulse 1s ease-in-out infinite;
}

@keyframes cpaic-thinking-pulse {
    0%, 100% { opacity: .45; }
    50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .cpaic-thinking {
        animation: none;
    }
}
