:root {
    --demg-blue: #1e3a8a;
    --demg-accent: #3b82f6;
    --demg-bg: #f8fafc;
    --demg-surface: #ffffff;
    --demg-border: #e5e7eb;
    --demg-text: #0f172a;
    --demg-muted: #64748b;
    --demg-success: #10b981;
    --demg-warning: #f59e0b;
    --demg-error: #ef4444;
}

html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

html.demg-no-x-scroll,
body.demg-no-x-scroll {
    overflow-x: hidden !important;
    width: 100%;
    max-width: 100vw;
}

.demg-chat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--demg-blue), var(--demg-accent));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 18px 38px rgba(59, 130, 246, 0.35);
    border: none;
    cursor: pointer;
    z-index: 9999;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.demg-chat-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 20px 40px rgba(59, 130, 246, 0.4);
}

.demg-chat-window {
    position: fixed;
    bottom: 98px;
    right: clamp(12px, 3vw, 24px);
    width: min(380px, calc(100vw - 32px));
    max-width: min(380px, calc(100vw - 32px));
    max-height: 78vh;
    background: var(--demg-surface);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
    border: 1px solid var(--demg-border);
    display: none;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
}

.demg-chat-window.open {
    display: flex;
}

.demg-chat-header {
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--demg-blue), var(--demg-accent));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.demg-chat-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.demg-chat-meta small {
    color: rgba(255, 255, 255, 0.85);
    font-weight: 500;
}

.demg-chat-close {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 6px 8px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.demg-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.demg-chat-body {
    padding: 14px;
    overflow-y: auto;
    background: var(--demg-bg);
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.demg-chat-bubble {
    padding: 12px 14px;
    border-radius: 12px;
    max-width: 85%;
    line-height: 1.5;
    font-size: 0.95rem;
    color: var(--demg-text);
    position: relative;
    word-break: break-word;
}

.demg-chat-bubble.bot {
    background: #eef2ff;
    border: 1px solid #cbd5ff;
}

.demg-chat-bubble.user {
    margin-left: auto;
    background: #dbeafe;
    border: 1px solid #bfdbfe;
}

.demg-chat-bubble small {
    display: block;
    margin-top: 6px;
    color: var(--demg-muted);
    font-size: 0.8rem;
}

.demg-chat-input {
    border-top: 1px solid var(--demg-border);
    padding: 12px;
    background: var(--demg-surface);
}

.demg-chat-input textarea {
    width: 100%;
    min-height: 60px;
    max-height: 140px;
    resize: vertical;
    padding: 10px 12px;
    border: 1px solid var(--demg-border);
    border-radius: 10px;
    font-size: 0.95rem;
    color: var(--demg-text);
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #fff;
}

.demg-chat-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    gap: 10px;
}

.demg-chat-send {
    background: linear-gradient(135deg, var(--demg-blue), var(--demg-accent));
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.demg-chat-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.demg-chat-rating {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.demg-chat-rating button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--demg-border);
    background: #fff;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

.demg-chat-rating button:hover {
    background: #f1f5f9;
    transform: translateY(-1px);
}

.demg-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #ecfeff;
    color: var(--demg-blue);
    border-radius: 999px;
    font-size: 0.85rem;
    border: 1px solid #bae6fd;
}

.demg-handoff {
    border: 1px solid var(--demg-border);
    background: #fff7ed;
    border-radius: 12px;
    padding: 12px;
}

.demg-handoff input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--demg-border);
    border-radius: 8px;
    margin-bottom: 8px;
}

.demg-typing {
    display: inline-block;
    width: 36px;
    text-align: center;
    letter-spacing: 2px;
    color: var(--demg-muted);
}

@media (max-width: 640px) {
    .demg-chat-window {
        right: 12px;
        left: 12px;
        width: auto;
        max-width: calc(100vw - 24px);
        max-height: 80vh;
    }

    .demg-chat-launcher {
        bottom: 16px;
        right: 16px;
    }
}

@media (max-width: 480px) {
    .demg-chat-window {
        bottom: 86px;
        left: 10px;
        right: 10px;
        width: auto;
        max-width: calc(100vw - 20px);
        border-radius: 14px;
    }

    .demg-chat-body {
        padding: 12px;
    }

    .demg-chat-input textarea {
        min-height: 56px;
    }
}
