.metra-chat {
    --metra-chat-primary: #2563eb;
    --metra-chat-text: #172033;
    --metra-chat-muted: #778197;
    --metra-chat-border: #e7eaf0;
    --metra-chat-bg: #ffffff;
    position: fixed;
    bottom: 14px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--metra-chat-text);
}

.metra-chat--right { right: 74px; }
.metra-chat--left { left: 24px; }

.metra-chat *,
.metra-chat *::before,
.metra-chat *::after {
    box-sizing: border-box;
}

.metra-chat__launcher {
    width: 58px;
    height: 58px;
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: var(--metra-chat-primary);
    color: #fff;
    box-shadow: 0 12px 32px rgba(15, 23, 42, .22);
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease;
}

.metra-chat--left .metra-chat__launcher { margin-left: 0; }

.metra-chat__launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 36px rgba(15, 23, 42, .28);
}

.metra-chat__launcher svg,
.metra-chat__send svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
}

.metra-chat__panel {
    position: absolute;
    bottom: 72px;
    width: 380px;
    height: min(620px, calc(100vh - 125px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(15, 23, 42, .08);
    border-radius: 18px;
    background: var(--metra-chat-bg);
    box-shadow: 0 22px 60px rgba(15, 23, 42, .22);
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(.98);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease, visibility .2s ease;
}

.metra-chat--right .metra-chat__panel { right: 0; }
.metra-chat--left .metra-chat__panel {
    left: 0;
    transform-origin: bottom left;
}

.metra-chat__panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.metra-chat__header {
    flex: 0 0 auto;
    min-height: 74px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px;
    background: var(--metra-chat-primary);
    color: #fff;
}

.metra-chat__title {
    font-size: 17px;
    line-height: 1.25;
    font-weight: 700;
}

.metra-chat__status {
    margin-top: 3px;
    font-size: 12px;
    opacity: .82;
}

.metra-chat__close {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font-size: 27px;
    line-height: 1;
    cursor: pointer;
}

.metra-chat__lead,
.metra-chat__conversation {
    min-height: 0;
    flex: 1 1 auto;
}

.metra-chat__lead {
    overflow-y: auto;
    padding: 22px 20px;
}

.metra-chat__lead-intro {
    margin-bottom: 18px;
    font-size: 15px;
    line-height: 1.5;
}

.metra-chat__lead-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.metra-chat__field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.metra-chat__field[hidden] { display: none !important; }

.metra-chat__field span {
    font-size: 13px;
    font-weight: 600;
}

.metra-chat__field input {
    width: 100%;
    height: 44px;
    padding: 0 12px;
    border: 1px solid var(--metra-chat-border);
    border-radius: 9px;
    background: #fff;
    color: var(--metra-chat-text);
    font: inherit;
    outline: none;
}

.metra-chat__field input:focus {
    border-color: var(--metra-chat-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--metra-chat-primary) 14%, transparent);
}

.metra-chat__start {
    min-height: 44px;
    padding: 10px 16px;
    border: 0;
    border-radius: 9px;
    background: var(--metra-chat-primary);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.metra-chat__start:disabled,
.metra-chat__send:disabled {
    opacity: .55;
    cursor: wait;
}

.metra-chat__privacy {
    font-size: 11px;
    line-height: 1.45;
    color: var(--metra-chat-muted);
    text-align: center;
}

.metra-chat__privacy a {
    color: inherit;
    text-decoration: underline;
}

.metra-chat__form-error {
    padding: 10px 12px;
    border-radius: 8px;
    background: #fff1f2;
    color: #be123c;
    font-size: 12px;
}

.metra-chat__conversation {
    display: flex;
    flex-direction: column;
    background: #f8fafc;
}

.metra-chat__conversation[hidden],
.metra-chat__lead[hidden] {
    display: none !important;
}

.metra-chat__messages {
    min-height: 0;
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 18px 15px;
    scroll-behavior: smooth;
}

.metra-chat__message {
    display: flex;
    margin: 8px 0;
}

.metra-chat__message--user {
    justify-content: flex-end;
}

.metra-chat__message--assistant {
    justify-content: flex-start;
}

.metra-chat__bubble {
    max-width: 82%;
    padding: 10px 12px;
    border-radius: 13px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.metra-chat__message--assistant .metra-chat__bubble {
    background: #fff;
    border: 1px solid var(--metra-chat-border);
    border-bottom-left-radius: 4px;
}

.metra-chat__message--user .metra-chat__bubble {
    background: var(--metra-chat-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.metra-chat__typing {
    flex: 0 0 auto;
    width: fit-content;
    margin: 0 15px 10px;
    padding: 9px 12px;
    border: 1px solid var(--metra-chat-border);
    border-radius: 12px;
    background: #fff;
}

.metra-chat__typing span {
    width: 6px;
    height: 6px;
    display: inline-block;
    margin: 0 2px;
    border-radius: 50%;
    background: #9ca3af;
    animation: metra-chat-dot 1.15s infinite ease-in-out;
}

.metra-chat__typing span:nth-child(2) { animation-delay: .15s; }
.metra-chat__typing span:nth-child(3) { animation-delay: .3s; }

@keyframes metra-chat-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: .55; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.metra-chat__composer {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 11px;
    border-top: 1px solid var(--metra-chat-border);
    background: #fff;
}

.metra-chat__input {
    min-height: 42px;
    max-height: 110px;
    flex: 1 1 auto;
    resize: none;
    overflow-y: auto;
    padding: 10px 12px;
    border: 1px solid var(--metra-chat-border);
    border-radius: 10px;
    background: #fff;
    color: var(--metra-chat-text);
    font: inherit;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
}

.metra-chat__input:focus {
    border-color: var(--metra-chat-primary);
}

.metra-chat__send {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 10px;
    background: var(--metra-chat-primary);
    color: #fff;
    cursor: pointer;
}

.metra-chat__send svg {
    width: 21px;
    height: 21px;
}

.metra-chat__reset {
    flex: 0 0 auto;
    width: 100%;
    padding: 7px 10px 10px;
    border: 0;
    background: #fff;
    color: var(--metra-chat-muted);
    font: inherit;
    font-size: 11px;
    text-decoration: underline;
    cursor: pointer;
}

@media (max-width: 520px) {
    .metra-chat {
        right: 14px;
        left: 14px;
        bottom: 14px;
    }

    .metra-chat--right,
    .metra-chat--left {
        right: 14px;
        left: 14px;
    }

    .metra-chat__launcher {
        margin-left: auto;
    }

    .metra-chat__panel,
    .metra-chat--right .metra-chat__panel,
    .metra-chat--left .metra-chat__panel {
        position: fixed;
        right: 10px;
        left: 10px;
        bottom: 82px;
        width: auto;
        height: min(680px, calc(100dvh - 96px));
        transform-origin: bottom center;
    }
}

/* ==========================================
   FIX ICONE CHAT
   ========================================== */

/* Reset pulsanti */
.metra-chat__launcher,
.metra-chat__send,
.metra-chat__close {
    padding: 0 !important;
    margin: 0;
    line-height: 1 !important;
    font-size: 0;
    text-indent: 0;
    appearance: none;
    -webkit-appearance: none;
}


/* ==========================================
   PULSANTE APERTURA CHAT
   ========================================== */

.metra-chat__launcher {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.metra-chat__launcher svg {
    display: block !important;

    width: 27px !important;
    height: 27px !important;

    min-width: 27px;
    min-height: 27px;

    fill: #ffffff !important;
    color: #ffffff !important;

    opacity: 1 !important;
    visibility: visible !important;

    position: static !important;
    transform: none !important;

    margin: 0 !important;
    padding: 0 !important;
}


/* forza anche il path dell'icona */
.metra-chat__launcher svg path {
    fill: #ffffff !important;
    stroke: none !important;
}


/* ==========================================
   PULSANTE INVIO
   ========================================== */

.metra-chat__send {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    padding: 0 !important;
}

.metra-chat__send svg {
    display: block !important;

    width: 22px !important;
    height: 22px !important;

    min-width: 22px;
    min-height: 22px;

    fill: #ffffff !important;
    color: #ffffff !important;

    opacity: 1 !important;
    visibility: visible !important;

    position: static !important;
    transform: none !important;

    margin: 0 !important;
    padding: 0 !important;
}

.metra-chat__send svg path {
    fill: #ffffff !important;
    stroke: none !important;
}


/* ==========================================
   X CHIUSURA
   ========================================== */

.metra-chat__close {
    width: 34px !important;
    height: 34px !important;

    min-width: 34px !important;
    min-height: 34px !important;

    flex: 0 0 34px;

    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    padding: 0 !important;

    border-radius: 50% !important;

    font-size: 26px !important;
    font-family: Arial, Helvetica, sans-serif !important;
    font-weight: 300 !important;

    line-height: 34px !important;

    text-align: center !important;

    color: #ffffff !important;
}
