#r4-chatbot-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999;
    font-family: Arial, sans-serif;
}

#r4-chatbot-floating-area {
    position: relative;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
}

/* toggle button */

#r4-chatbot-toggle {
    width: 64px;
    height: 64px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, #001c8f 0%, #1636bf 100%);
    cursor: pointer;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    position: relative;
    overflow: visible;
    animation: r4-chatbot-idle-float 3.6s ease-in-out infinite;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#r4-chatbot-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 34px rgba(0, 28, 143, 0.26);
}

#r4-chatbot-toggle::before {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 999px;
    background: radial-gradient(circle, rgba(0, 28, 143, 0.18) 0%, rgba(0, 28, 143, 0) 70%);
    z-index: -1;
    animation: r4-chatbot-glow 2.8s ease-in-out infinite;
}

.r4-chatbot-toggle-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.r4-chatbot-online-dot {
    position: absolute;
    right: 5px;
    bottom: 5px;
    width: 13px;
    height: 13px;
    border-radius: 999px;
    background: #22c55e;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
    animation: r4-chatbot-online-ping 1.8s infinite;
}

/* teaser bubble */

.r4-chatbot-teaser {
    position: absolute;
    right: 78px;
    bottom: 8px;
    width: 280px;
    max-width: calc(100vw - 120px);
    background: #ffffff;
    color: #0f172a;
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
    padding: 14px 16px;
    border: 1px solid rgba(0, 28, 143, 0.08);
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
    z-index: 2;
    cursor: pointer;
}

.r4-chatbot-teaser::after {
    content: "";
    position: absolute;
    right: 18px;
    bottom: -8px;
    width: 16px;
    height: 16px;
    background: #ffffff;
    transform: rotate(45deg);
    border-right: 1px solid rgba(0, 28, 143, 0.08);
    border-bottom: 1px solid rgba(0, 28, 143, 0.08);
}

.r4-chatbot-teaser-hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px) scale(0.96);
    pointer-events: none;
}

.r4-chatbot-teaser-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    animation: r4-chatbot-teaser-bob 3s ease-in-out infinite;
}

.r4-chatbot-teaser-title {
    font-size: 13px;
    font-weight: 700;
    color: #001c8f;
    margin-bottom: 4px;
    padding-right: 20px;
}

.r4-chatbot-teaser-text {
    font-size: 13px;
    line-height: 1.45;
    color: #334155;
}

.r4-chatbot-teaser-close {
    position: absolute;
    top: 6px;
    right: 8px;
    border: 0;
    background: transparent;
    color: #64748b;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 2px;
}

/* window */

#r4-chatbot-window {
    width: 370px;
    max-width: calc(100vw - 30px);
    height: 620px;
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 22px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin-bottom: 12px;
    border: 1px solid rgba(0, 28, 143, 0.08);
}

.r4-chatbot-hidden {
    display: none !important;
}

/* header */

.r4-chatbot-header {
    background: linear-gradient(135deg, #001c8f 0%, #1636bf 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.r4-chatbot-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.r4-chatbot-avatar {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px;
    min-height: 40px;
    max-width: 40px;
    max-height: 40px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

/* titles */

.r4-chatbot-title {
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
}

.r4-chatbot-subtitle {
    font-size: 12px;
    opacity: 0.9;
    line-height: 1.35;
}

/* header actions */

.r4-chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 12px;
    flex-shrink: 0;
}

.r4-chatbot-icon-btn {
    width: 36px;
    height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-radius: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.10);
    padding: 0;
}

.r4-chatbot-icon-btn:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.20);
    border-color: rgba(255, 255, 255, 0.28);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
}

.r4-chatbot-icon-btn:active {
    transform: scale(0.96);
}

.r4-chatbot-icon-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.22);
}

.r4-chatbot-icon {
    font-size: 18px;
    line-height: 1;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.r4-chatbot-close-btn .r4-chatbot-icon {
    font-size: 22px;
    transform: translateY(-1px);
}

#r4-chatbot-reset:hover {
    background: rgba(255, 255, 255, 0.24);
}

#r4-chatbot-close:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* messages */

.r4-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    background:
        radial-gradient(circle at top, rgba(0, 28, 143, 0.03), transparent 30%),
        #f6f8fc;
}

.r4-chatbot-msg {
    margin-bottom: 14px;
    display: flex;
}

.r4-chatbot-msg.bot {
    justify-content: flex-start;
    flex-direction: column;
    align-items: flex-start;
}

.r4-chatbot-msg.user {
    justify-content: flex-end;
}

.r4-chatbot-msg.system {
    justify-content: center;
}

.r4-chatbot-bubble {
    max-width: 85%;
    padding: 11px 13px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
    word-break: break-word;
}

.r4-chatbot-msg.bot .r4-chatbot-bubble {
    background: #ffffff;
    color: #0f172a;
    border: 1px solid #e6ebf5;
}

.r4-chatbot-msg.user .r4-chatbot-bubble {
    background: linear-gradient(135deg, #001c8f 0%, #1636bf 100%);
    color: #fff;
}

.r4-chatbot-msg.system .r4-chatbot-bubble {
    background: #eef2f7;
    color: #334155;
    font-size: 13px;
    text-align: center;
}

.r4-chatbot-bubble a {
    color: inherit;
    text-decoration: underline;
}

/* feedback */

.r4-chatbot-feedback {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding-left: 6px;
}

.r4-chatbot-feedback-btn {
    min-width: 38px;
    height: 34px;
    border: 1px solid #dbe2ef;
    background: rgba(255, 255, 255, 0.92);
    color: #475569;
    border-radius: 999px;
    padding: 0 12px;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
    transition: transform 0.18s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.r4-chatbot-feedback-btn:hover {
    transform: translateY(-1px);
    background: #f8fbff;
    border-color: #b9c8f0;
    color: #001c8f;
    box-shadow: 0 8px 18px rgba(0, 28, 143, 0.10);
}

.r4-chatbot-feedback-btn:active {
    transform: scale(0.96);
}

.r4-chatbot-feedback-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 28, 143, 0.12);
}

.r4-chatbot-feedback-btn.is-active {
    background: linear-gradient(135deg, #001c8f 0%, #1636bf 100%);
    border-color: #001c8f;
    color: #fff;
    box-shadow: 0 10px 24px rgba(0, 28, 143, 0.20);
}

.r4-chatbot-feedback-btn[data-feedback="down"].is-active {
    background: linear-gradient(135deg, #0f172a 0%, #334155 100%);
    border-color: #0f172a;
    color: #fff;
}

/* quick buttons */

.r4-chatbot-quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 12px 14px 0;
}

.r4-chatbot-quick-btn {
    border: 1px solid #d8def0;
    background: #fff;
    color: #001c8f;
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.r4-chatbot-quick-btn:hover {
    background: #f3f6ff;
    transform: translateY(-1px);
    border-color: #bfd0f8;
    box-shadow: 0 8px 16px rgba(0, 28, 143, 0.08);
}

/* form */

.r4-chatbot-form {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid #edf1f7;
    background: #fff;
}

#r4-chatbot-input {
    flex: 1;
    resize: none;
    border: 1px solid #dbe2ef;
    border-radius: 12px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    min-height: 44px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#r4-chatbot-input:focus {
    outline: none;
    border-color: #9fb5f0;
    box-shadow: 0 0 0 3px rgba(0, 28, 143, 0.08);
}

#r4-chatbot-send,
#r4-chatbot-capture-btn {
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, #001c8f 0%, #1636bf 100%);
    color: #fff;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 8px 18px rgba(0, 28, 143, 0.16);
}

#r4-chatbot-send:hover,
#r4-chatbot-capture-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(0, 28, 143, 0.22);
}

#r4-chatbot-send:disabled,
#r4-chatbot-capture-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* lead form */

.r4-chatbot-capture {
    padding: 0 14px 14px;
    background: #fff;
}

.r4-chatbot-capture details {
    border-top: 1px solid #edf1f7;
    padding-top: 12px;
}

.r4-chatbot-capture summary {
    cursor: pointer;
    color: #001c8f;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    list-style: none;
}

.r4-chatbot-capture summary::-webkit-details-marker {
    display: none;
}

.r4-chatbot-lead-form {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.r4-chatbot-lead-form input,
.r4-chatbot-lead-form textarea {
    border: 1px solid #dbe2ef;
    border-radius: 12px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.r4-chatbot-lead-form input:focus,
.r4-chatbot-lead-form textarea:focus {
    outline: none;
    border-color: #9fb5f0;
    box-shadow: 0 0 0 3px rgba(0, 28, 143, 0.08);
}

/* stato lavoro bottone flottante */

#r4-chatbot-toggle.r4-chatbot-loading {
    position: relative;
    animation: r4-chatbot-pulse 1.2s ease-in-out infinite;
}

#r4-chatbot-toggle.r4-chatbot-loading::after {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 999px;
    border: 2px solid rgba(0, 28, 143, 0.25);
    animation: r4-chatbot-ring 1.4s linear infinite;
}

#r4-chatbot-toggle.r4-chatbot-loading .r4-chatbot-toggle-avatar {
    animation: r4-chatbot-breathe 1s ease-in-out infinite;
}

/* typing indicator */

.r4-chatbot-typing {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 12px;
}

.r4-chatbot-typing-bubble {
    background: #ffffff;
    color: #0f172a;
    border-radius: 14px;
    padding: 10px 12px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-width: 52px;
    border: 1px solid #e6ebf5;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.r4-chatbot-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: #001c8f;
    opacity: 0.35;
    animation: r4-chatbot-dot 1.2s infinite ease-in-out;
}

.r4-chatbot-typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.r4-chatbot-typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

/* custom modal reset */

.r4-chatbot-modal {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.40);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 30;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.r4-chatbot-modal-card {
    width: 100%;
    max-width: 300px;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 24px 50px rgba(15, 23, 42, 0.24);
    padding: 18px;
    animation: r4-chatbot-modal-in 0.18s ease;
}

.r4-chatbot-modal-title {
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 8px;
}

.r4-chatbot-modal-text {
    font-size: 14px;
    line-height: 1.5;
    color: #475569;
    margin-bottom: 16px;
}

.r4-chatbot-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.r4-chatbot-modal-btn {
    border: 1px solid #dbe2ef;
    background: #fff;
    color: #334155;
    border-radius: 12px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.r4-chatbot-modal-btn:hover {
    transform: translateY(-1px);
}

.r4-chatbot-modal-btn-primary {
    background: linear-gradient(135deg, #001c8f 0%, #1636bf 100%);
    color: #fff;
    border-color: #001c8f;
    box-shadow: 0 8px 18px rgba(0, 28, 143, 0.16);
}

/* animations */

@keyframes r4-chatbot-dot {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.35;
    }
    40% {
        transform: translateY(-3px);
        opacity: 1;
    }
}

@keyframes r4-chatbot-pulse {
    0%, 100% {
        box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
    }
    50% {
        box-shadow: 0 12px 34px rgba(0, 28, 143, 0.32);
    }
}

@keyframes r4-chatbot-ring {
    0% {
        transform: scale(0.9);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.12);
        opacity: 0;
    }
}

@keyframes r4-chatbot-breathe {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.92);
    }
}

@keyframes r4-chatbot-idle-float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-6px);
    }
}

@keyframes r4-chatbot-glow {
    0%, 100% {
        opacity: 0.55;
        transform: scale(1);
    }
    50% {
        opacity: 0.9;
        transform: scale(1.08);
    }
}

@keyframes r4-chatbot-online-ping {
    0% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}

@keyframes r4-chatbot-teaser-bob {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-2px) scale(1);
    }
}

@keyframes r4-chatbot-modal-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* mobile */

@media (max-width: 640px) {
    #r4-chatbot-widget {
        right: 14px;
        bottom: 14px;
    }

    #r4-chatbot-window {
        width: calc(100vw - 20px);
        height: min(620px, calc(100vh - 90px));
        border-radius: 18px;
    }

    .r4-chatbot-teaser {
        width: 240px;
        right: 72px;
    }

    .r4-chatbot-quick-actions {
        grid-template-columns: 1fr 1fr;
    }

    .r4-chatbot-header-actions {
        gap: 6px;
    }

    .r4-chatbot-icon-btn {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }

    .r4-chatbot-feedback {
        gap: 6px;
        margin-top: 7px;
    }

    .r4-chatbot-feedback-btn {
        min-width: 34px;
        height: 32px;
        padding: 0 10px;
        font-size: 13px;
    }
}
