/* EDIH4Marche Chatbot Widget — v1.0.0 */
:root {
    --e4m-primary: #0F1F42;
    --e4m-primary-light: #1a2d5a;
    --e4m-accent: #00B0F0;
    --e4m-accent-dark: #0090c8;
    --e4m-bg: #ffffff;
    --e4m-bg-chat: #f2f4f8;
    --e4m-text: #1a1a2e;
    --e4m-text-light: #5c6370;
    --e4m-border: #dce1e8;
    --e4m-radius: 16px;
    --e4m-shadow: 0 8px 32px rgba(15, 31, 66, .22);
    --e4m-bot-bubble: #e4eaf5;
    --e4m-user-bubble: var(--e4m-primary);
}

/* ── Toggle button ── */
.e4m-toggle {
    position: fixed;
    bottom: 24px;
    z-index: 999999;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--e4m-primary) 0%, var(--e4m-primary-light) 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(15, 31, 66, .35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease, box-shadow .2s ease;
}
.e4m-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(15, 31, 66, .4);
}
.e4m-toggle svg { width: 28px; height: 28px; }
.e4m-pos-right .e4m-toggle { right: 24px; }
.e4m-pos-left  .e4m-toggle { left: 24px; }

/* Unread badge pulse */
.e4m-toggle::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--e4m-accent);
    border: 2px solid #fff;
    animation: e4m-pulse 2s infinite;
}
.e4m-toggle.e4m-no-badge::after { display: none; }
@keyframes e4m-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: .7; }
}

/* ── Chat window ── */
.e4m-window {
    position: fixed;
    bottom: 100px;
    z-index: 999999;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 570px;
    max-height: calc(100vh - 140px);
    background: var(--e4m-bg);
    border-radius: var(--e4m-radius);
    box-shadow: var(--e4m-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(16px) scale(.96);
    transition: opacity .25s ease, transform .25s ease;
}
.e4m-window.e4m-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}
.e4m-pos-right .e4m-window { right: 24px; }
.e4m-pos-left  .e4m-window { left: 24px; }

/* ── Header ── */
.e4m-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(135deg, var(--e4m-primary) 0%, var(--e4m-primary-light) 100%);
    color: #fff;
    flex-shrink: 0;
}
.e4m-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(255,255,255,.12);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 20px;
}
.e4m-header-info { flex: 1; min-width: 0; }
.e4m-header-name {
    font-family: Tahoma, Verdana, sans-serif;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.e4m-header-status {
    font-size: 12px;
    opacity: .8;
    display: flex;
    align-items: center;
    gap: 5px;
}
.e4m-header-status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
}
.e4m-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.e4m-close:hover { background: rgba(255,255,255,.15); }
.e4m-close svg { width: 20px; height: 20px; }

/* ── Messages area ── */
.e4m-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--e4m-bg-chat);
}
.e4m-messages::-webkit-scrollbar { width: 5px; }
.e4m-messages::-webkit-scrollbar-thumb { background: #bfc5d0; border-radius: 3px; }

/* ── Bubbles ── */
.e4m-msg {
    max-width: 84%;
    padding: 10px 14px;
    border-radius: 14px;
    font-family: Tahoma, Verdana, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.e4m-msg a {
    color: var(--e4m-accent);
    text-decoration: underline;
}
.e4m-msg-bot {
    align-self: flex-start;
    background: var(--e4m-bot-bubble);
    color: var(--e4m-text);
    border-bottom-left-radius: 4px;
}
.e4m-msg-user {
    align-self: flex-end;
    background: var(--e4m-user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.e4m-msg-user a { color: var(--e4m-accent); }
.e4m-msg-error {
    align-self: center;
    background: #fce8e8;
    color: #b71c1c;
    font-size: 13px;
    text-align: center;
    border-radius: 10px;
}

/* ── Typing indicator ── */
.e4m-typing {
    align-self: flex-start;
    display: none;
    gap: 5px;
    padding: 12px 18px;
    background: var(--e4m-bot-bubble);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.e4m-typing.e4m-visible { display: flex; }
.e4m-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--e4m-text-light);
    animation: e4m-bounce .6s infinite alternate;
}
.e4m-typing span:nth-child(2) { animation-delay: .15s; }
.e4m-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes e4m-bounce {
    to { opacity: .3; transform: translateY(-4px); }
}

/* ── Lead form ── */
.e4m-lead-form {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--e4m-border);
    border-radius: 12px;
    padding: 14px;
    max-width: 90%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.e4m-lead-form p {
    margin: 0;
    font-family: Tahoma, Verdana, sans-serif;
    font-size: 13px;
    color: var(--e4m-text);
    line-height: 1.45;
}
.e4m-lead-form input {
    font-family: Tahoma, Verdana, sans-serif;
    font-size: 13px;
    padding: 8px 10px;
    border: 1px solid var(--e4m-border);
    border-radius: 8px;
    outline: none;
    width: 100%;
    box-sizing: border-box;
}
.e4m-lead-form input:focus { border-color: var(--e4m-accent); }
.e4m-lead-btn {
    font-family: Tahoma, Verdana, sans-serif;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: var(--e4m-accent);
    color: #fff;
    cursor: pointer;
    transition: background .15s;
    align-self: flex-start;
}
.e4m-lead-btn:hover { background: var(--e4m-accent-dark); }

/* ── Input area ── */
.e4m-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--e4m-border);
    background: var(--e4m-bg);
    flex-shrink: 0;
}
.e4m-input {
    flex: 1;
    border: 1px solid var(--e4m-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-family: Tahoma, Verdana, sans-serif;
    font-size: 14px;
    resize: none;
    min-height: 20px;
    max-height: 100px;
    line-height: 1.45;
    outline: none;
    transition: border-color .15s;
    background: var(--e4m-bg);
    color: var(--e4m-text);
}
.e4m-input:focus { border-color: var(--e4m-accent); }
.e4m-input::placeholder { color: #999; }
.e4m-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--e4m-accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, opacity .15s;
}
.e4m-send:hover { background: var(--e4m-accent-dark); }
.e4m-send:disabled { opacity: .4; cursor: default; }
.e4m-send svg { width: 18px; height: 18px; }

/* ── Footer ── */
.e4m-footer {
    text-align: center;
    padding: 6px 14px 10px;
    font-family: Tahoma, Verdana, sans-serif;
    font-size: 11px;
    color: var(--e4m-text-light);
    background: var(--e4m-bg);
}
.e4m-footer a { color: var(--e4m-accent); text-decoration: none; }

/* ── Mobile ── */
@media (max-width: 480px) {
    .e4m-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 90px);
        max-height: calc(100vh - 90px);
        bottom: 82px;
        left: 8px !important;
        right: 8px !important;
        border-radius: 14px;
    }
    .e4m-toggle { bottom: 16px; }
    .e4m-pos-right .e4m-toggle { right: 16px; }
    .e4m-pos-left  .e4m-toggle { left: 16px; }
}
