.udsm-chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

.udsm-chatbot-bubble {
    position: relative;
    z-index: 1;
    width: 88px;
    height: 92px;
    padding: 0;
    border-radius: 0;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    transition: transform 0.2s ease;
}

.udsm-chatbot-bubble:hover {
    transform: scale(1.04);
}

.udsm-chatbot-bubble img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.22));
}

.udsm-chatbot-bubble .udsm-chatbot-icon {
    font-size: 28px;
}

.udsm-chatbot-greeting {
    position: absolute;
    right: 74px;
    bottom: 0;
    width: 250px;
    padding: 13px 16px;
    border: 1px solid #dce9e3;
    border-radius: 14px;
    background: #fff;
    color: #285443;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
    font-size: 14px;
    line-height: 1.5;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
}

.udsm-chatbot-greeting::before {
    content: '';
    position: absolute;
    right: -6px;
    bottom: 23px;
    width: 10px;
    height: 10px;
    background: #fff;
    border-top: 1px solid #dce9e3;
    border-right: 1px solid #dce9e3;
    transform: rotate(45deg);
}

/* Bridge the gap so the greeting stays visible while the pointer moves to it. */
.udsm-chatbot-greeting::after {
    content: '';
    position: absolute;
    left: 100%;
    bottom: 0;
    width: 16px;
    height: 100%;
}

.udsm-chatbot-widget:not(.udsm-chatbot-greeting-dismissed) .udsm-chatbot-bubble[aria-expanded="false"]:focus-visible + .udsm-chatbot-greeting,
.udsm-chatbot-widget.udsm-chatbot-greeting-hover:not(.udsm-chatbot-greeting-dismissed) .udsm-chatbot-bubble[aria-expanded="false"] + .udsm-chatbot-greeting {
    opacity: 1;
    visibility: visible;
}

@keyframes udsmChatbotPulse {
    0% { box-shadow: 0 0 0 0 rgba(67, 168, 131, 0.5); }
    70% { box-shadow: 0 0 0 14px rgba(67, 168, 131, 0); }
    100% { box-shadow: 0 0 0 0 rgba(67, 168, 131, 0); }
}

.udsm-chatbot-pulse {
    animation: udsmChatbotPulse 2s infinite;
}

.udsm-chatbot-window {
    position: fixed;
    z-index: 2;
    bottom: 122px;
    right: 20px;
    width: 400px;
    height: 550px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 140px);
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.udsm-chatbot-header {
    background-color: #43A883;
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.udsm-chatbot-header img {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #fff;
    object-fit: cover;
}

.udsm-chatbot-header-copy {
    flex: 1;
    min-width: 0;
}

.udsm-chatbot-header-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    flex: 1;
}

.udsm-chatbot-header-subtitle {
    font-size: 12px;
    opacity: 0.9;
}

.udsm-chatbot-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    margin-left: auto;
    flex-shrink: 0;
}

.udsm-chatbot-close:hover {
    opacity: 0.8;
}

.udsm-chatbot-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
    background-color: #f6f7f8;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.udsm-chatbot-msg {
    flex-shrink: 0;
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.udsm-chatbot-msg.user {
    background-color: #43A883;
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.udsm-chatbot-msg.bot {
    background-color: #fff;
    color: #333;
    align-self: flex-start;
    border: 1px solid #e5e5e5;
    border-bottom-left-radius: 4px;
}

.udsm-chatbot-msg.bot ul, .udsm-chatbot-msg.bot ol {
    margin: 4px 0 4px 18px;
    padding: 0;
}

.udsm-chatbot-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 12px 15px;
    background-color: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 14px;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.udsm-chatbot-typing span {
    width: 7px;
    height: 7px;
    background-color: #aaa;
    border-radius: 50%;
    display: inline-block;
    animation: udsmChatbotBlink 1.2s infinite;
}

.udsm-chatbot-typing span:nth-child(2) { animation-delay: 0.2s; }
.udsm-chatbot-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes udsmChatbotBlink {
    0%, 80%, 100% { opacity: 0.2; }
    40% { opacity: 1; }
}

.udsm-chatbot-sources {
    font-size: 11px;
    color: #999;
    margin-top: 6px;
    word-wrap: break-word;
}

.udsm-chatbot-faq {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    flex-shrink: 0;
}

.udsm-chatbot-faq-title {
    width: 100%;
    color: #52615b;
    font-size: 12px;
    font-weight: 600;
    margin: 2px 0;
}

.udsm-chatbot-question {
    max-width: 100%;
    border: 1px solid #bedfd2;
    border-radius: 14px;
    background: #fff;
    color: #246c53;
    padding: 6px 10px;
    font: inherit;
    font-size: 12px;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
}

.udsm-chatbot-question:hover,
.udsm-chatbot-question:focus-visible {
    background: #e7f5ee;
    border-color: #43A883;
}

.udsm-chatbot-question:disabled {
    opacity: 0.6;
    cursor: wait;
}

.udsm-chatbot-input-row {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e5e5e5;
    background: #fff;
    flex-shrink: 0;
}

.udsm-chatbot-input-row input {
    flex: 1;
    min-width: 0;
    border: 1px solid #d0d0d0;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 14px;
    outline: none;
}

.udsm-chatbot-input-row input:focus {
    border-color: #43A883;
}

.udsm-chatbot-input-row button {
    border: none;
    background-color: #43A883;
    color: #fff;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
}

.udsm-chatbot-input-row button:disabled {
    background-color: #aaa;
    cursor: not-allowed;
}

.udsm-chatbot-error {
    background-color: #fdecea;
    color: #c0392b;
    border: 1px solid #f5c6cb;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 13px;
    align-self: center;
    text-align: center;
}

@media (max-width: 767px), (max-height: 500px) and (pointer: coarse) {
    .udsm-chatbot-widget {
        --chat-launcher-width: 88px;
        --chat-launcher-height: 92px;
        --chat-edge-right: max(12px, env(safe-area-inset-right, 0px));
        --chat-edge-bottom: max(12px, env(safe-area-inset-bottom, 0px));
        left: calc(var(--chat-viewport-left, 0px) + var(--chat-viewport-width, 100vw) - var(--chat-launcher-width) - var(--chat-edge-right));
        top: calc(var(--chat-viewport-top, 0px) + var(--chat-viewport-height, 100vh) - var(--chat-launcher-height) - var(--chat-edge-bottom));
        right: auto;
        bottom: auto;
        width: var(--chat-launcher-width);
        height: var(--chat-launcher-height);
    }

    .udsm-chatbot-bubble:hover {
        transform: none;
    }

    .udsm-chatbot-greeting {
        right: 0;
        bottom: calc(var(--chat-launcher-height) + 14px);
        max-width: calc(var(--chat-viewport-width, 100vw) - 24px);
    }

    .udsm-chatbot-greeting::before {
        right: 24px;
        bottom: -6px;
        transform: rotate(135deg);
    }

    .udsm-chatbot-greeting::after {
        left: auto;
        top: 100%;
        right: 0;
        width: 60px;
        height: 16px;
    }

    .udsm-chatbot-window {
        position: absolute;
        bottom: calc(var(--chat-launcher-height) + 12px);
        right: 0;
        width: calc(var(--chat-viewport-width, 100vw) - var(--chat-edge-right) - max(12px, env(safe-area-inset-left, 0px)));
        height: 550px;
        max-width: 400px;
        max-height: calc(var(--chat-viewport-height, 100vh) - var(--chat-launcher-height) - 24px - var(--chat-edge-bottom) - env(safe-area-inset-top, 0px));
        border-radius: 12px;
    }

    .udsm-chatbot-close {
        min-width: 36px;
        min-height: 36px;
    }

    .udsm-chatbot-input-row input {
        font-size: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .udsm-chatbot-greeting {
        transition: none;
    }
}
