/* Chatbot widget */
.sh-chatbot {
    --sh-chatbot-dark: #1D1D1C;
    --sh-chatbot-accent: #DC0811;
    --sh-chatbot-grey: #9E9E9E;
    --sh-chatbot-light: #F4F4F4;

    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999;

    .sh-chatbot__launcher {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 60px;
        height: 60px;
        margin-left: auto;
        padding: 0;

        border: 0;
        border-radius: 50%;

        color: #fff;
        background: var(--sh-chatbot-dark);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
        cursor: pointer;

        transition: background 0.2s ease, transform 0.2s ease;

        &:hover,
        &:focus-visible {
            background: var(--sh-chatbot-accent);
            transform: scale(1.05);
        }

        .sh-chatbot__icon-close {
            display: none;
        }
    }

    &.sh-chatbot--open .sh-chatbot__launcher {
        .sh-chatbot__icon-open {
            display: none;
        }

        .sh-chatbot__icon-close {
            display: block;
        }
    }

    .sh-chatbot__panel {
        position: absolute;
        right: 0;
        bottom: 76px;

        display: flex;
        flex-direction: column;
        width: 370px;
        max-width: calc(100vw - 40px);
        height: 560px;
        max-height: calc(100vh - 120px);
        overflow: hidden;

        border-radius: 16px;

        background: #fff;
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);

        &[hidden] {
            display: none;
        }
    }

    .sh-chatbot__header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 16px 18px;

        color: #fff;
        background: var(--sh-chatbot-dark);
    }

    .sh-chatbot__title {
        display: block;
        font-size: 1rem;
    }

    .sh-chatbot__subtitle {
        display: block;
        font-size: 0.8rem;
        opacity: 0.75;
    }

    .sh-chatbot__header-handoff {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 36px;
        height: 36px;
        flex-shrink: 0;
        padding: 0;

        border: 0;
        border-radius: 50%;

        color: #fff;
        background: rgba(255, 255, 255, 0.15);
        cursor: pointer;

        transition: background 0.2s ease;

        &:hover,
        &:focus-visible {
            background: var(--sh-chatbot-accent);
        }
    }

    .sh-chatbot__messages {
        display: flex;
        flex: 1;
        flex-direction: column;
        gap: 10px;
        padding: 16px;
        overflow-y: auto;

        background: var(--sh-chatbot-light);
    }

    .sh-chatbot__message {
        max-width: 85%;
        padding: 10px 14px;

        border-radius: 14px;

        font-size: 0.9rem;
        line-height: 1.45;
        word-break: break-word;

        p {
            margin: 0 0 6px;

            &:last-child {
                margin-bottom: 0;
            }
        }

        ul {
            margin: 4px 0 6px;
            padding-left: 18px;
        }

        a {
            color: var(--sh-chatbot-accent);
            text-decoration: underline;
        }

        &.sh-chatbot__message--assistant {
            align-self: flex-start;
            border-bottom-left-radius: 4px;
            color: var(--sh-chatbot-dark);
            background: #fff;
        }

        &.sh-chatbot__message--user {
            align-self: flex-end;
            border-bottom-right-radius: 4px;
            white-space: pre-wrap;
            color: #fff;
            background: var(--sh-chatbot-dark);
        }

        &.sh-chatbot__message--typing {
            display: flex;
            gap: 4px;
            padding: 14px;

            span {
                width: 7px;
                height: 7px;
                border-radius: 50%;
                background: var(--sh-chatbot-grey);
                animation: sh-chatbot-typing 1.2s infinite ease-in-out;

                &:nth-child(2) {
                    animation-delay: 0.15s;
                }

                &:nth-child(3) {
                    animation-delay: 0.3s;
                }
            }
        }
    }

    .sh-chatbot__handoff-button {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        margin-top: 10px;
        padding: 9px 14px;

        border: 0;
        border-radius: 999px;

        font-family: inherit;
        font-size: 0.85rem;
        font-weight: 700;

        color: #fff;
        background: var(--sh-chatbot-accent);
        cursor: pointer;

        transition: background 0.2s ease;

        &:hover,
        &:focus-visible {
            background: var(--sh-chatbot-dark);
        }
    }

    .sh-chatbot__close-button {
        background: var(--sh-chatbot-dark);

        &:hover,
        &:focus-visible {
            background: var(--sh-chatbot-accent);
        }
    }

    .sh-chatbot__handoff-form {
        width: 85%;
        box-sizing: border-box;

        .sh-chatbot__handoff-row {
            display: flex;
            gap: 6px;
            margin: 8px 0 6px;
        }

        .sh-chatbot__handoff-email {
            flex: 1;
            min-width: 0;
            height: 38px;
            padding: 0 10px;
            box-sizing: border-box;

            border: 1px solid var(--sh-chatbot-grey);
            border-radius: 8px;

            font-size: 16px;

            &:focus {
                border-color: var(--sh-chatbot-dark);
                outline: none;
            }
        }

        .sh-chatbot__handoff-submit {
            flex-shrink: 0;
            height: 38px;
            padding: 0 14px;

            border: 0;
            border-radius: 8px;

            font-family: inherit;
            font-size: 0.85rem;
            font-weight: 700;

            color: #fff;
            background: var(--sh-chatbot-accent);
            cursor: pointer;

            &:disabled {
                opacity: 0.5;
                cursor: not-allowed;
            }
        }

        .sh-chatbot__handoff-error {
            font-size: 0.8rem;
            color: var(--sh-chatbot-accent);
        }

        .sh-chatbot__handoff-note {
            font-size: 0.72rem;
            color: var(--sh-chatbot-grey);
        }
    }

    .sh-chatbot__quick-replies {
        display: flex;
        gap: 6px;
        padding: 10px 12px 0;
        overflow-x: auto;
        background: #fff;
        scrollbar-width: none;
    }

    .sh-chatbot__quick-reply {
        flex-shrink: 0;
        padding: 6px 12px;

        border: 1px solid var(--sh-chatbot-dark);
        border-radius: 999px;

        font-size: 0.8rem;
        white-space: nowrap;

        color: var(--sh-chatbot-dark);
        background: #fff;
        cursor: pointer;

        transition: background 0.2s ease, color 0.2s ease;

        &:hover,
        &:focus-visible {
            color: #fff;
            background: var(--sh-chatbot-dark);
        }
    }

    &.sh-chatbot--busy .sh-chatbot__quick-reply {
        opacity: 0.5;
        pointer-events: none;
    }

    .sh-chatbot__form {
        display: flex;
        align-items: flex-end;
        gap: 8px;
        padding: 12px;
        border-top: 1px solid #E5E5E5;
        background: #fff;
    }

    .sh-chatbot__input {
        flex: 1;
        min-height: 40px;
        max-height: 120px;
        padding: 9px 12px;
        box-sizing: border-box;

        border: 1px solid var(--sh-chatbot-grey);
        border-radius: 10px;

        font-size: 16px;
        line-height: 1.4;

        resize: none;

        &:focus {
            border-color: var(--sh-chatbot-dark);
            outline: none;
        }
    }

    .sh-chatbot__send {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 40px;
        height: 40px;
        flex-shrink: 0;
        padding: 0;

        border: 0;
        border-radius: 10px;

        color: #fff;
        background: var(--sh-chatbot-accent);
        cursor: pointer;

        &:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }
    }

    .sh-chatbot__disclaimer {
        margin: 0;
        padding: 0 12px 10px;
        font-size: 0.7rem;
        text-align: center;
        color: var(--sh-chatbot-grey);
        background: #fff;
    }

    @media (max-width: 480px) {
        right: 12px;
        bottom: 12px;

        .sh-chatbot__panel {
            position: fixed;
            top: 50%;
            right: auto;
            left: 50%;
            transform: translate(-50%, -50%);
            width: calc(100% - 40px);
            max-width: none;
            height: 80vh;
            max-height: none;
        }
    }
}

@keyframes sh-chatbot-typing {

    0%,
    60%,
    100% {
        opacity: 0.4;
        transform: translateY(0);
    }

    30% {
        opacity: 1;
        transform: translateY(-4px);
    }
}