:root {
    --cl-ai-z-index: 10050;
}

#cl-ai-widget-root {
    --cl-ai-accent: #667eea;
    --cl-ai-z-index: 10050;
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: var(--cl-ai-z-index);
    font-family: var(--font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
    font-size: 14px;
    line-height: 1.5;
}

#cl-ai-widget-root[data-scope="card"] {
    --cl-ai-accent: #6bb890;
}

#cl-ai-widget-root.cl-ai-ready .cl-ai-fab {
    opacity: 1;
    transform: translateY(0);
}

.cl-ai-fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--cl-ai-accent);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s, transform 0.25s;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

#cl-ai-widget-root.cl-ai-ready .cl-ai-fab {
    pointer-events: auto;
}

.cl-ai-panel {
    display: none;
    position: absolute;
    right: 0;
    bottom: 68px;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 480px;
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    flex-direction: column;
    overflow: hidden;
}

#cl-ai-widget-root.cl-ai-open .cl-ai-panel {
    display: flex;
    animation: clAiSlideDown 0.25s ease;
}

@keyframes clAiSlideDown {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.cl-ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #eee;
    background: #fff;
}

.cl-ai-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
}

.cl-ai-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #6b7280;
    line-height: 1;
}

.cl-ai-privacy {
    padding: 10px 16px;
    background: #f9fafb;
    font-size: 12px;
    color: #6b7280;
    border-bottom: 1px solid #eee;
}

.cl-ai-privacy a { color: var(--cl-ai-accent); }

.cl-ai-privacy-accept {
    margin-top: 6px;
    padding: 4px 10px;
    border: 1px solid var(--cl-ai-accent);
    background: #fff;
    color: var(--cl-ai-accent);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}

.cl-ai-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 16px;
    background: #fafafa;
}

.cl-ai-msg {
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
}

.cl-ai-msg--user { align-items: flex-end; }
.cl-ai-msg--assistant { align-items: flex-start; }

.cl-ai-msg-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

.cl-ai-msg--user .cl-ai-msg-bubble {
    background: rgba(233, 69, 96, 0.12);
    color: #1f2937;
}

#cl-ai-widget-root[data-scope="card"] .cl-ai-msg--user .cl-ai-msg-bubble {
    background: rgba(107, 184, 144, 0.15);
}

@supports (background: color-mix(in srgb, red 15%, white)) {
    .cl-ai-msg--user .cl-ai-msg-bubble {
        background: color-mix(in srgb, var(--cl-ai-accent) 15%, white);
    }
}

.cl-ai-msg--assistant .cl-ai-msg-bubble {
    background: #f3f4f6;
    color: #374151;
}

.cl-ai-refs {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
}

.cl-ai-feedback {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.cl-ai-feedback-btn {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 11px;
    cursor: pointer;
    padding: 0;
}

.cl-ai-feedback-btn:hover { color: var(--cl-ai-accent); }

.cl-ai-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 16px;
    border-top: 1px solid #eee;
}

.cl-ai-quick-btn {
    padding: 4px 10px;
    border-radius: 14px;
    border: 1px solid #e5e7eb;
    background: #fff;
    font-size: 12px;
    cursor: pointer;
    color: #374151;
}

.cl-ai-quick-btn:hover {
    border-color: var(--cl-ai-accent);
    color: var(--cl-ai-accent);
}

.cl-ai-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 8px;
}

.cl-ai-action-btn {
    padding: 6px 12px;
    border-radius: 8px;
    border: none;
    background: var(--cl-ai-accent);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
}

.cl-ai-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid #eee;
    background: #fff;
    align-items: flex-end;
}

.cl-ai-init-error {
    padding: 10px 16px;
    background: #fef2f2;
    color: #b91c1c;
    font-size: 13px;
    border-bottom: 1px solid #fecaca;
}

.cl-ai-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px 10px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    min-height: 36px;
    max-height: 80px;
}

.cl-ai-send, .cl-ai-wechat-btn {
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.cl-ai-send {
    background: var(--cl-ai-accent);
    color: #fff;
}

.cl-ai-wechat-btn {
    background: #f3f4f6;
    color: #374151;
}

.cl-ai-wechat-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: calc(var(--cl-ai-z-index) + 1);
    background: rgba(0, 0, 0, 0.4);
    align-items: center;
    justify-content: center;
}

.cl-ai-wechat-modal.cl-ai-wechat-open { display: flex; }

.cl-ai-wechat-content {
    background: #fff;
    border-radius: 20px;
    padding: 24px;
    max-width: 320px;
    width: 90%;
    text-align: center;
    position: relative;
}

.cl-ai-wechat-close {
    position: absolute;
    right: 12px;
    top: 8px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #9ca3af;
}

.cl-ai-wechat-qr img {
    max-width: 200px;
    margin: 12px auto;
    display: block;
}

.cl-ai-wechat-link {
    display: inline-block;
    margin-top: 12px;
    color: var(--cl-ai-accent);
}

@media (max-width: 480px) {
    #cl-ai-widget-root.cl-ai-open .cl-ai-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        bottom: 0;
        border-radius: 0;
    }
    #cl-ai-widget-root.cl-ai-open .cl-ai-fab {
        display: none;
    }
}

.cl-ai-msg--assistant.cl-ai-typing .cl-ai-msg-bubble {
    color: var(--cl-ai-text-muted, #888);
    font-style: italic;
}

.cl-ai-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#cl-ai-widget-root.cl-ai-init-failed .cl-ai-fab {
    opacity: 0.45;
}

.cl-ai-init-error.cl-ai-init-warning {
    background: #fffbeb;
    border-color: #fcd34d;
    color: #92400e;
}

@media (prefers-reduced-motion: reduce) {
    .cl-ai-fab, .cl-ai-panel { transition: none; animation: none; }
}
