/* 0. GLOBAALIT RESETIT CHATILLE JA MOBIILILLE */
html,
body {
    overflow-x: hidden !important;
    width: 100%;
}

[id^="pm-v55-"],
.pm-v55-msg,
.pm-v55-contact-form {
    box-sizing: border-box !important;
    margin: 0;
    padding: 0;
}

/* 1. CHAT-IKKUNA */
#pm-v55-container {
    display: none;
    position: fixed !important;
    bottom: 85px;
    right: 25px;
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.4);
    flex-direction: column;
    overflow: hidden;
    z-index: 2147483647 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transform: none !important;
    margin: 0 !important;
}

#pm-v55-container.active {
    display: flex;
}

/* 2. AVAUSPAINIKE */
#pm-v55-toggle {
    position: fixed !important;
    bottom: 25px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #6D4E9F !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2147483647 !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    transition: transform 0.2s;
    transform: none !important;
    margin: 0 !important;
}

#pm-v55-toggle:active {
    transform: scale(0.95);
}

#pm-v55-toggle img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

#pm-v55-toggle svg {
    width: 30px;
    height: 30px;
    stroke: white;
    fill: none;
    stroke-width: 2.5;
}

/* 3. HEADER */
#pm-v55-header {
    height: 60px;
    padding: 0 15px;
    background-color: #6a1b9a;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

#pm-v55-header>div:first-child {
    display: flex;
    align-items: center;
    min-width: 0;
    /* Mahdollistaa kutistumisen */
    flex: 1;
}

#pm-v55-header span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    max-width: 100%;
    font-size: 14px;
    /* Hieman pienempi fontti mobiiliystävällisyyden vuoksi */
}

@media (max-width: 400px) {
    #pm-v55-header span {
        max-width: 100px;
        /* Hyvin pienillä näytöillä rajoitetaan tekstiä rajusti */
    }
}

.pm-v55-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgba(255, 255, 255, 0.3);
    margin-right: 10px;
}

#pm-v55-header-actions {
    display: flex;
    align-items: center;
}

#pm-v55-close-btn,
#pm-v55-email-btn,
#pm-v55-clear-btn {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: white !important;
    cursor: pointer !important;
    padding: 0 !important;
    margin-left: 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: auto !important;
    width: auto !important;
    height: auto !important;
    opacity: 0.9;
    font-size: 20px !important;
}

#pm-v55-close-btn:hover,
#pm-v55-clear-btn:hover {
    opacity: 1;
}

#pm-v55-close-btn svg,
#pm-v55-clear-btn svg {
    width: 24px !important;
    height: 24px !important;
    fill: white !important;
}

/* 4. VIESTIALUE */
#pm-v55-body {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f4f7f9;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

.pm-v55-msg {
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 12px;
    font-size: 15px;
    line-height: 1.5;
    max-width: 85%;
    word-wrap: break-word;
}

.pm-v55-user {
    background: #6a1b9a;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.pm-v55-bot {
    background: white;
    border: 1px solid #e0e0e0;
    align-self: flex-start;
    color: #333;
    border-bottom-left-radius: 2px;
}

.pm-v55-bot p {
    margin: 0 0 10px 0;
}

.pm-v55-bot p:last-child {
    margin-bottom: 0;
}

.pm-v55-bot strong,
.pm-v55-bot b {
    font-weight: 700;
    color: #000;
}

.pm-v55-bot ul {
    margin: 5px 0 10px 20px;
    padding: 0;
    list-style-type: disc;
}

.pm-v55-bot li {
    margin-bottom: 5px;
}

.pm-v55-bot a {
    color: #6a1b9a;
    text-decoration: underline;
    font-weight: 600;
}

.pm-v55-chat-img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    margin: 8px 0;
    cursor: pointer;
    display: block;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.pm-v55-chat-img:hover {
    transform: scale(1.02);
}

/* 5. INPUT JA NAPPI */
#pm-v55-inputbar {
    padding: 10px;
    background: white;
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

#pm-v55-input {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 25px;
    outline: none;
    font-size: 16px;
}

#pm-v55-input:focus {
    border-color: #6a1b9a;
}

#pm-v55-send-btn {
    margin-left: 10px;
    background: #6a1b9a;
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}

/* 6. DISCLAIMER (UUSI) */
#pm-v55-disclaimer {
    font-size: 11px;
    color: #999;
    text-align: center;
    padding: 5px 10px 8px 10px;
    background: white;
    flex-shrink: 0;
    line-height: 1.3;
}

/* 7. TYPING */
#pm-v55-typing {
    padding: 15px;
    display: none;
    background: white;
    border-radius: 10px;
    width: fit-content;
    margin-bottom: 10px;
    border: 1px solid #eee;
    align-items: center;
    gap: 10px;
}

.pm-typing-dots {
    display: flex;
    gap: 4px;
}

.pm-typing-dot {
    width: 6px;
    height: 6px;
    background-color: #888;
    border-radius: 50%;
    animation: pm-bounce 1.4s infinite ease-in-out both;
}

.pm-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.pm-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes pm-bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* 8. MOBIILI: KELLUVA IKKUNA */
@media (max-width: 600px) {
    #pm-v55-container {
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        /* Täyttää koko leveyden ilman ylivalumista */
        height: 100% !important;
        height: 100dvh !important;
        /* dvh huomioi selainpalkit paremmin */
        bottom: 0 !important;
        top: 0 !important;
        border-radius: 0 !important;
        transform: none !important;
        position: fixed !important;
        max-width: 100% !important;
        z-index: 2147483647 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    #pm-v55-toggle {
        right: 20px !important;
        bottom: 25px !important;
        width: 60px !important;
        height: 60px !important;
        position: fixed !important;
        z-index: 2147483647 !important;
        margin: 0 !important;
        transform: none !important;
    }

    #pm-v55-toggle img {
        width: 60px !important;
        height: 60px !important;
        border-radius: 50%;
        object-fit: cover;
    }

    #pm-v55-header {
        border-radius: 0 !important;
        padding: 0 10px !important;
    }

    .pm-v55-avatar {
        width: 32px !important;
        height: 32px !important;
    }

    #pm-v55-header span {
        font-size: 13px !important;
        max-width: 120px !important;
    }

    /* Varmistetaan että kaikki 3 nappia näkyy */
    #pm-v55-header-actions {
        gap: 5px !important;
    }

    #pm-v55-email-btn,
    #pm-v55-clear-btn,
    #pm-v55-close-btn {
        margin-left: 5px !important;
        padding: 5px !important;
    }

    /* Varmistetaan ett채 disclaimerissa on tilaa alareunassa iPhonella */
    #pm-v55-disclaimer {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        border-radius: 0;
    }
}

/* =========================================
   ALVARIINI BOTIN ANIMAATIOT JA TEKSTI (VÄRI #6D4E9F)
   ========================================= */

/* 1. Määritellään syke-animaatio (Väri #6D4E9F) */
@keyframes bot-pulse {
    0% {
        transform: scale(1);
        /* Alussa väri on vahva #6D4E9F (RGB: 109, 78, 159) */
        box-shadow: 0 0 0 0 rgba(109, 78, 159, 0.7);
    }

    70% {
        transform: scale(1.05);
        /* Suurenee hieman */
        /* Lopussa väri on haalistunut ja levinnyt */
        box-shadow: 0 0 0 15px rgba(109, 78, 159, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(109, 78, 159, 0);
    }
}

/* 2. Sovelletaan animaatio nappiin */
#pm-v55-toggle {
    animation: bot-pulse 2s infinite;
    /* Pyörii ikuisesti */
    overflow: visible !important;
    /* TÄRKEÄ: Sallii tekstin näkyä napin ulkopuolella */
    position: fixed;
    /* Varmistetaan että pysyy paikallaan */
    z-index: 2147483647;
    /* Varmistetaan että on kaiken päällä */

    /* Varmistetaan että itse nappikin on oikean värinen */
    background-color: #6D4E9F !important;

    /* Varmistetaan ettei mikään ulkoinen tyyli siirrä nappia */
    left: auto !important;
}

/* 3. Tekstilaatikko napin viereen */
#pm-v55-toggle::before {
    content: "Miten voin auttaa?";
    /* Teksti tässä */

    /* Sijainti */
    position: absolute;
    right: 85px;
    /* Etäisyys napista vasemmalle. Kasvata jos menee päälle. */
    top: 50%;
    transform: translateY(-50%);

    /* Ulkonäkö */
    background-color: #ffffff;
    color: #6E56CF;
    /* Tekstin väri (tummanharmaa on luettavin) */
    padding: 8px 14px;
    border-radius: 20px;
    font-family: sans-serif;
    font-size: 14px;
    font-weight: bold;
    white-space: nowrap;
    /* Estää rivittymisen */

    /* Varjo ja näkyvyys */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    opacity: 0;
    pointer-events: none;
    /* Klikkaukset menevät läpi */

    /* Ilmestymis-animaatio (tulee näkyviin 1s viiveellä) */
    animation: pm-fade-in-text 0.5s ease-out 1s forwards;
}

/* Tekstin ilmestyminen */
@keyframes pm-fade-in-text {
    from {
        opacity: 0;
        transform: translate(-10px, -50%);
    }

    to {
        opacity: 1;
        transform: translate(0, -50%);
    }
}

/* 4. Piilotetaan teksti mobiilissa (tila loppuu kesken) */
@media (max-width: 768px) {
    #pm-v55-toggle::before {
        display: none !important;
    }
}

/* 10. SUGGESTION CHIPS */
#pm-v55-suggestions {
    display: none;
    flex-wrap: nowrap;
    gap: 10px;
    padding: 12px 15px;
    background: #fdfdfd;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Tyylitelty rullapalkki */
#pm-v55-suggestions::-webkit-scrollbar {
    height: 5px;
    display: block;
}

#pm-v55-suggestions::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#pm-v55-suggestions::-webkit-scrollbar-thumb {
    background: #6D4E9F;
    border-radius: 10px;
}

.pm-v55-suggestion-chip {
    flex-shrink: 0;
    background: #ffffff;
    border: 1.2px solid #6D4E9F;
    color: #6D4E9F;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.pm-v55-suggestion-chip:hover {
    background: #6D4E9F;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(109, 78, 159, 0.25);
    transform: translateY(-1px);
}

.pm-v55-suggestion-chip:active {
    transform: translateY(0);
}

@media (max-width: 768px) {
    #pm-v55-suggestions {
        padding: 8px 10px;
    }

    #pm-v55-suggestions::-webkit-scrollbar {
        display: none;
    }
}

/* 11. CONTACT FORM IN CHAT */
.pm-v55-contact-form {
    margin-top: 10px;
    padding: 12px;
    background: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 8px;
    width: 100%;
    box-sizing: border-box;
}

.pm-v55-contact-form h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #333;
}

.pm-v55-form-group {
    margin-bottom: 8px;
}

.pm-v55-contact-form input,
.pm-v55-contact-form textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 13px;
    box-sizing: border-box;
    font-family: inherit;
}

.pm-v55-contact-form input:focus,
.pm-v55-contact-form textarea:focus {
    border-color: #6a1b9a;
    outline: none;
}

.pm-v55-contact-send {
    width: 100%;
    padding: 10px;
    background: #6a1b9a;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: background 0.2s;
}

.pm-v55-contact-send:hover {
    background: #4a148c;
}

.pm-v55-contact-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.pm-v55-form-status {
    margin-top: 5px;
    font-size: 12px;
    min-height: 15px;
}

.pm-v55-form-success {
    color: #2e7d32;
    font-weight: 600;
    font-size: 13px;
    padding: 10px;
    background: #e8f5e9;
    border-radius: 5px;
    text-align: center;
}