#cpw-chat-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
#cpw-chat-widget.cpw-position-left {
    right: auto;
    left: 20px;
}
#cpw-chat-widget.cpw-position-left #cpw-panel {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}
#cpw-chat-widget.cpw-position-left #cpw-unread-dot {
    right: auto;
    left: 2px;
}

#cpw-toggle-btn {
    position: relative;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: var(--cpw-primary, #2563eb);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}
#cpw-toggle-btn:hover {
    transform: scale(1.06);
}

#cpw-unread-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #e11d48;
    border: 2px solid #fff;
}
#cpw-unread-dot.cpw-hidden {
    display: none;
}

#cpw-panel {
    position: absolute;
    right: 0;
    bottom: 74px;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: var(--cpw-radius, 16px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: opacity 0.15s ease, transform 0.15s ease;
}
#cpw-panel.cpw-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.95) translateY(8px);
}

#cpw-header {
    background: var(--cpw-primary, #2563eb);
    color: #fff;
    padding: 16px 18px;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}
#cpw-header-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}
#cpw-header-avatar.cpw-hidden {
    display: none;
}

#cpw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f7f8fa;
    scrollbar-width: thin;
    scrollbar-color: #cfd3da transparent;
}
#cpw-messages::-webkit-scrollbar {
    width: 6px;
}
#cpw-messages::-webkit-scrollbar-track {
    background: transparent;
}
#cpw-messages::-webkit-scrollbar-thumb {
    background: #cfd3da;
    border-radius: 999px;
}
#cpw-messages::-webkit-scrollbar-button {
    display: none;
    height: 0;
    width: 0;
}

.cpw-sender {
    align-self: flex-start;
    font-size: 11px;
    font-weight: 600;
    color: #16845d;
    margin-bottom: -4px;
    padding-left: 2px;
}
.cpw-msg {
    max-width: 82%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.cpw-msg.cpw-user {
    align-self: flex-end;
    background: var(--cpw-primary, #2563eb);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.cpw-msg.cpw-bot {
    align-self: flex-start;
    background: #fff;
    color: #1f2430;
    border: 1px solid #e6e8ec;
    border-bottom-left-radius: 4px;
}
.cpw-msg.cpw-agent {
    align-self: flex-start;
    background: #e9f8f1;
    color: #14532d;
    border: 1px solid #bfe9d4;
    border-bottom-left-radius: 4px;
}
.cpw-msg.cpw-system {
    align-self: center;
    background: #f0f1f4;
    color: #5a6270;
    border: 1px solid #e2e4ea;
    font-size: 12px;
    text-align: center;
}
.cpw-msg.cpw-error {
    align-self: center;
    background: #fdecea;
    color: #b3261e;
    border: 1px solid #f5c6c3;
    font-size: 13px;
}

.cpw-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    align-self: stretch;
    max-width: 100%;
}
.cpw-suggestion {
    border: 1px solid color-mix(in srgb, var(--cpw-primary, #2563eb) 30%, transparent);
    color: var(--cpw-primary, #2563eb);
    background: #fff;
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s ease;
}
.cpw-suggestion:hover {
    background: color-mix(in srgb, var(--cpw-primary, #2563eb) 8%, #fff);
}
.cpw-suggestion:disabled {
    opacity: 0.5;
    cursor: default;
}

#cpw-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #eceef1;
    background: #fff;
}

#cpw-input {
    flex: 1;
    resize: none;
    border: 1px solid #dcdfe4;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    max-height: 90px;
    outline: none;
}
#cpw-input:focus {
    border-color: var(--cpw-primary, #2563eb);
}

#cpw-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: var(--cpw-primary, #2563eb);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
#cpw-send-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.cpw-typing {
    display: inline-flex;
    gap: 4px;
    align-self: flex-start;
    padding: 10px 13px;
    background: #fff;
    border: 1px solid #e6e8ec;
    border-radius: 14px;
}
.cpw-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9aa0ab;
    animation: cpw-bounce 1.2s infinite ease-in-out;
}
.cpw-typing span:nth-child(2) { animation-delay: 0.15s; }
.cpw-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cpw-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 480px) {
    #cpw-panel {
        width: calc(100vw - 24px);
        right: -8px;
        height: calc(100vh - 120px);
    }
}
