/* EgyptCRM Assistant — brand green, stacked above WhatsApp */
.ecrm-chat-root {
    --ecrm-chat-bg: #0f2412;
    --ecrm-chat-panel: #ffffff;
    --ecrm-chat-accent: #1B5E20;
    --ecrm-chat-accent-2: #2E7D32;
    --ecrm-chat-muted: #5f6b66;
    --ecrm-chat-border: rgba(27, 94, 32, 0.12);
    font-family: 'Cairo', 'Inter', system-ui, sans-serif;
}

.ecrm-chat-launcher {
    position: fixed;
    z-index: 10000;
    width: 62px;
    height: 62px;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: linear-gradient(145deg, var(--ecrm-chat-accent-2), var(--ecrm-chat-accent));
    box-shadow: 0 10px 28px rgba(13, 74, 20, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

body.ltr .ecrm-chat-launcher { right: 28px; bottom: 104px; }
body.rtl .ecrm-chat-launcher { left: 28px; bottom: 104px; }

.ecrm-chat-launcher:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 14px 32px rgba(13, 74, 20, 0.42);
}

.ecrm-chat-launcher svg { width: 28px; height: 28px; }

.ecrm-chat-panel {
    position: fixed;
    z-index: 10001;
    width: min(380px, calc(100vw - 24px));
    height: min(560px, calc(100vh - 120px));
    display: none;
    flex-direction: column;
    overflow: hidden;
    border-radius: 22px;
    background: var(--ecrm-chat-panel);
    border: 1px solid var(--ecrm-chat-border);
    box-shadow: 0 24px 60px rgba(15, 36, 18, 0.28);
}

body.ltr .ecrm-chat-panel { right: 28px; bottom: 180px; }
body.rtl .ecrm-chat-panel { left: 28px; bottom: 180px; }

.ecrm-chat-panel.is-open { display: flex; animation: ecrmChatIn 0.22s ease; }

@keyframes ecrmChatIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

.ecrm-chat-header {
    padding: 1rem 1.1rem;
    color: #fff;
    background:
        radial-gradient(120% 80% at 100% 0%, rgba(255,255,255,0.16), transparent 50%),
        linear-gradient(135deg, #1B5E20 0%, #0D4A14 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.ecrm-chat-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.ecrm-chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: rgba(255,255,255,0.14);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.ecrm-chat-brand h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
}

.ecrm-chat-brand p {
    margin: 0.15rem 0 0;
    font-size: 0.78rem;
    opacity: 0.88;
}

.ecrm-chat-close {
    border: 0;
    background: rgba(255,255,255,0.12);
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
}

.ecrm-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background:
        linear-gradient(180deg, #f4faf5 0%, #ffffff 40%);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ecrm-chat-bubble {
    max-width: 92%;
    padding: 0.75rem 0.9rem;
    border-radius: 16px;
    font-size: 0.92rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.ecrm-chat-bubble.bot {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--ecrm-chat-border);
    color: #14301a;
    border-bottom-left-radius: 6px;
}

body.rtl .ecrm-chat-bubble.bot { border-bottom-left-radius: 16px; border-bottom-right-radius: 6px; }

.ecrm-chat-bubble.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #1B5E20, #2E7D32);
    color: #fff;
    border-bottom-right-radius: 6px;
}

body.rtl .ecrm-chat-bubble.user { border-bottom-right-radius: 16px; border-bottom-left-radius: 6px; }

.ecrm-chat-sources {
    margin-top: 0.55rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.ecrm-chat-sources a {
    font-size: 0.72rem;
    color: var(--ecrm-chat-accent);
    background: rgba(27, 94, 32, 0.08);
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    text-decoration: none;
}

.ecrm-chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0 1rem 0.65rem;
    background: #fff;
}

.ecrm-chat-chip {
    border: 1px solid var(--ecrm-chat-border);
    background: #f7fbf8;
    color: var(--ecrm-chat-accent);
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ecrm-chat-chip:hover { background: rgba(27, 94, 32, 0.1); }

.ecrm-chat-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid var(--ecrm-chat-border);
    background: #fff;
}

.ecrm-chat-form input {
    flex: 1;
    border: 1px solid var(--ecrm-chat-border);
    border-radius: 14px;
    padding: 0.7rem 0.85rem;
    font: inherit;
    outline: none;
}

.ecrm-chat-form input:focus {
    border-color: var(--ecrm-chat-accent);
    box-shadow: 0 0 0 3px rgba(27, 94, 32, 0.12);
}

.ecrm-chat-form button {
    border: 0;
    border-radius: 14px;
    padding: 0 1rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #1B5E20, #2E7D32);
    cursor: pointer;
}

.ecrm-chat-form button:disabled { opacity: 0.6; cursor: wait; }

.ecrm-chat-typing {
    align-self: flex-start;
    color: var(--ecrm-chat-muted);
    font-size: 0.8rem;
}

@media (max-width: 640px) {
    body.ltr .ecrm-chat-launcher,
    body.rtl .ecrm-chat-launcher { bottom: 90px; }
    body.ltr .ecrm-chat-launcher { right: 20px; }
    body.rtl .ecrm-chat-launcher { left: 20px; }

    body.ltr .ecrm-chat-panel,
    body.rtl .ecrm-chat-panel {
        right: 12px;
        left: 12px;
        bottom: 12px;
        width: auto;
        height: min(70vh, 560px);
    }
}
