/* D3 AI — Support Chat Widget */

:root {
    --d3-chat-primary:    #2271b1;
    --d3-chat-primary-dk: #1a5a8a;
    --d3-chat-bg:         #ffffff;
    --d3-chat-bubble-ai:  #f1f3f5;
    --d3-chat-bubble-user:#2271b1;
    --d3-chat-text:       #1a1a1a;
    --d3-chat-muted:      #888;
    --d3-chat-radius:     16px;
    --d3-chat-shadow:     0 8px 32px rgba(0,0,0,.15);
    --d3-chat-z:          99999;
    --d3-chat-width:      360px;
    --d3-chat-height:     480px;
}

.d3-ai-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--d3-chat-z);
    font-family: inherit;
}

/* Toggle button */
.d3-ai-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50% !important;
    background: var(--d3-chat-primary);
    border: none !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 4px 16px rgba(34, 113, 177, 0.45) !important;
    transition: background 0.2s, transform 0.2s !important;
    color: #fff;
    padding: 0 !important;
}

.d3-ai-chat-toggle:hover {
    background: var(--d3-chat-primary-dk);
    transform: scale(1.06);
}

/* Chat box */
.d3-ai-chat-box {
    position: absolute;
    bottom: 68px;
    right: 0;
    width: var(--d3-chat-width);
    max-height: var(--d3-chat-height);
    background: var(--d3-chat-bg);
    border-radius: var(--d3-chat-radius);
    box-shadow: var(--d3-chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: d3ChatSlideIn 0.22s ease;
}

@keyframes d3ChatSlideIn {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
.d3-ai-chat-header {
    background: var(--d3-chat-primary);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
}

.d3-ai-chat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    margin-left: auto;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
}

/* Messages */
.d3-ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.d3-ai-chat-messages::-webkit-scrollbar {
    width: 4px;
}
.d3-ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.d3-ai-chat-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 2px;
}

.d3-ai-message {
    max-width: 84%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}

.d3-ai-message.ai {
    background: var(--d3-chat-bubble-ai);
    color: var(--d3-chat-text);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.d3-ai-message.user {
    background: var(--d3-chat-bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

.d3-ai-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 14px;
    background: var(--d3-chat-bubble-ai);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.d3-ai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #aaa;
    animation: d3Bounce 1.2s infinite;
}

.d3-ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.d3-ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes d3Bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-5px); }
}

/* Input area */
.d3-ai-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid #eee;
    background: #fafafa;
}

.d3-ai-chat-input-area textarea {
    flex: 1;
    border: 1px solid #ddd !important;
    border-radius: 10px !important;
    padding: 9px 12px !important;
    font-size: 14px !important;
    resize: none !important;
    outline: none;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.15s !important;
    height: 100px !important;
    overflow-y: auto !important;
    min-height: unset !important;
}

.d3-ai-chat-input-area textarea:focus {
    border-color: var(--d3-chat-primary);
}

.d3-ai-chat-input-area button {
    width: 38px;
    height: 38px;
    min-height: unset !important;
    border-radius: 50%;
    background: var(--d3-chat-primary);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
    padding: 0;
}

.d3-ai-chat-input-area button:hover {
    background: var(--d3-chat-primary-dk);
}

.d3-ai-chat-input-area button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.d3-ai-chat-footer {
    text-align: center;
    font-size: 10px;
    color: var(--d3-chat-muted);
    padding: 4px 0 8px;
    background: #fafafa;
}

/* Mobile */
@media (max-width: 480px) {
    .d3-ai-chat-box {
        width: calc(100vw - 24px);
        right: 0;
        left: 0;
        margin: 0 auto;
        bottom: 72px;
        position: fixed;
    }
    .d3-ai-chat-widget {
        right: 12px;
        bottom: 12px;
    }
}
