:root {
    --cw-primary: #003865;
    --cw-primary-dark: #002a4d;
    --cw-surface: #f1f3f6;
    --cw-muted: #6b7280;
}

#cw-root {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
}

#cw-bubble {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary-dark));
    color: #fff;
    box-shadow: 0 6px 20px rgba(0, 56, 101, .4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s ease;
}
#cw-bubble:hover { transform: scale(1.06); }
#cw-bubble .cw-ic-close { display: none; }
#cw-root.cw-open #cw-bubble .cw-ic-chat { display: none; }
#cw-root.cw-open #cw-bubble .cw-ic-close { display: block; }

#cw-panel {
    position: fixed;
    right: 20px;
    bottom: 92px;
    width: 380px;
    height: min(600px, calc(100vh - 120px));
    height: min(600px, calc(100dvh - 120px));
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(15, 23, 42, .22);
    display: flex;
    flex-direction: column;
}
#cw-panel[hidden] { display: none; }

#cw-header {
    background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary-dark));
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.cw-head-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
#cw-header h1 {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
}

#cw-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: .85;
    display: flex;
}
#cw-close:hover { opacity: 1; }

.cw-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #9ca3af;
    flex: none;
}
.cw-dot.cw-online {
    background: #4ade80;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, .25);
}
.cw-dot.cw-reconnecting {
    background: #fbbf24;
    animation: cw-pulse 1s infinite;
}
.cw-dot.cw-offline {
    background: #f87171;
}
@keyframes cw-pulse { 50% { opacity: .35; } }

#cw-messages {
    flex: 1;
    overflow-y: auto;
    background: #fafbfd;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.cw-row {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}
.cw-row.cw-bot { align-self: flex-start; align-items: flex-start; }
.cw-row.cw-user { align-self: flex-end; align-items: flex-end; }

.cw-bubble-msg {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    max-width: 100%;
}
.cw-bot .cw-bubble-msg {
    background: var(--cw-surface);
    color: #1f2937;
    border-bottom-left-radius: 4px;
}
.cw-user .cw-bubble-msg {
    background: var(--cw-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.cw-time {
    font-size: 10px;
    color: var(--cw-muted);
    margin-top: 3px;
    padding: 0 4px;
}

.cw-banner {
    align-self: center;
    text-align: center;
    max-width: 92%;
    font-size: 12px;
    color: #475569;
    background: #eef1f6;
    border: 1px solid #e2e8f0;
    padding: 5px 12px;
    border-radius: 999px;
}

.cw-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-self: flex-start;
    max-width: 85%;
}
.cw-chip {
    background: #fff;
    border: 1px solid var(--cw-primary);
    color: var(--cw-primary);
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: background .12s;
}
.cw-chip:hover:not(:disabled) { background: #eff4ff; }
.cw-chip:disabled { cursor: default; opacity: .5; }

.cw-cta {
    display: inline-block;
    background: var(--cw-primary);
    color: #fff;
    text-decoration: none;
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
}
.cw-cta:hover { background: var(--cw-primary-dark); }

.cw-typing {
    display: flex;
    gap: 4px;
    padding: 13px 14px;
}
.cw-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: cw-blink 1.2s infinite;
}
.cw-typing span:nth-child(2) { animation-delay: .15s; }
.cw-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes cw-blink {
    0%, 60%, 100% { opacity: .25; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-3px); }
}

#cw-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e5e9f0;
    background: #fff;
}
#cw-input {
    flex: 1;
    min-width: 0;
    border: 1px solid #d6dbe4;
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
}
#cw-input:focus {
    border-color: var(--cw-primary);
    box-shadow: 0 0 0 3px rgba(0, 56, 101, .12);
}
#cw-input:disabled { background: #f8fafc; }

#cw-send {
    width: 42px;
    height: 42px;
    flex: none;
    border: none;
    border-radius: 50%;
    background: var(--cw-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .12s;
}
#cw-send:hover:not(:disabled) { background: var(--cw-primary-dark); }
#cw-send:disabled { opacity: .5; cursor: default; }

@media (max-width: 480px) {
    #cw-panel {
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
    }
    #cw-root.cw-open #cw-bubble { display: none; }
}
