/* ========================================
   AVATAR WIDGET (Pyöreä pallo alakulmassa)
   Modulaarinen widget-pohja käytettäväksi missä tahansa sivulla
   ======================================== */

/* Brandon-fontti */
@font-face {
    font-family: 'Brandon';
    src: url('https://a3s.fi/agentformers-website/assets/brandon/Brandon_reg.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Brandon';
    src: url('https://a3s.fi/agentformers-website/assets/brandon/Brandon_med.otf') format('opentype');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Brandon';
    src: url('https://a3s.fi/agentformers-website/assets/brandon/Brandon_bld.otf') format('opentype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Brandon';
    src: url('https://a3s.fi/agentformers-website/assets/brandon/Brandon_light.otf') format('opentype');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}

/* Widget-kontaineri */
.avatar-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Brandon', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Pieni pyöreä nappi (suljettu tila) */
.widget-bubble {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #f5f5f5; /* Harmaa tausta (ei gradient) */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); /* Harmaa varjostus */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    border: 2px solid #e5e7eb; /* Harmaa reuna */
}

.widget-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); /* Tummempi harmaa varjostus */
    background: #e8e8e8; /* Hieman tummempi harmaa hoverissa */
}

.widget-bubble:active {
    transform: scale(0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); /* Pienempi varjostus klikkauksessa */
}

.widget-bubble.open {
    display: none;
}

/* Avatar-kuva pallossa */
.widget-icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 20%; /* Keskitä kasvot (20% ylhäältä) */
    border-radius: 50%;
    mask: circle();
    -webkit-mask: circle();
    display: block;
    animation: subtle-pulse 3s ease-in-out infinite;
}

@keyframes subtle-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.95; }
}

/* Pulssi-efekti (harmaa) */
.widget-bubble::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #f5f5f5; /* Harmaa tausta (ei gradient) */
    animation: pulse-ring 2s ease-out infinite;
}

@keyframes pulse-ring {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* Badge (uusi viesti -indikaattori) */
.widget-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Laajennettu näkymä */
.widget-expanded {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    height: 600px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: visible; /* Muutettu: visible jotta sulku-nappi ei leikkaudu pois */
    animation: slideUp 0.3s ease-out;
}

.widget-expanded.open {
    display: flex;
    flex-direction: column;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Avatar iframe */
.widget-frame {
    flex: 1;
    border: none;
    width: 100%;
    height: 100%;
    border-radius: 20px; /* Varmista että iframe noudattaa widgetin pyöristyksiä */
    overflow: hidden; /* Piilota iframe:n sisällön ylivuoto */
    position: relative; /* Varmista että iframe on oikein asemoitu */
}

/* Sulku-nappi (vasempaan kulmaan, harmaat reunat ja X, pienempi) */
.widget-close-btn {
    position: absolute;
    top: -15px;
    left: -15px; /* Vasempaan kulmaan */
    width: 36px; /* Pienempi koko */
    height: 36px;
    background: linear-gradient(135deg, #ffffff 0%, #f5f5f5 100%);
    border: 2px solid #888888; /* Harmaat reunat */
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px; /* Pienempi X */
    font-weight: bold;
    color: #666666; /* Harmaa X */
    z-index: 10001;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2), 0 0 0 3px rgba(255, 255, 255, 0.5);
    transition: all 0.3s ease;
    /* Varmista että nappi on kokonaan widgetin ulkopuolella */
    transform: translate(0, 0);
}

.widget-close-btn:hover {
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    border-color: #666666; /* Tummempi harmaa hoverissa */
    color: #333333; /* Tummempi X hoverissa */
    transform: translate(0, 0) scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3), 0 0 0 4px rgba(255, 255, 255, 0.6);
}

.widget-close-btn:active {
    transform: translate(0, 0) scale(0.95);
}

/* Mobiili-responsiivisuus */
@media (max-width: 768px) {
    /* Widget-bubble palautetaan oikeaan alakulmaan (mutta jätetään vähän tilaa reunoihin) */
    .avatar-widget {
        position: fixed !important;
        bottom: 20px !important;  /* Vähän tilaa alareunasta */
        right: 20px !important;   /* Vähän tilaa oikeasta reunasta */
        left: auto !important;
        top: auto !important;
        width: auto !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        z-index: 99999 !important;
    }
    
    /* Widget-expanded täyttää koko näytön kun avattu */
    .avatar-widget:has(.widget-expanded.open) {
        position: fixed !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
    }
    
    .widget-expanded {
        /* Koko näyttö mobiilissa - täyttää koko näytön ilman marginaaleja */
        position: fixed !important;
        width: 100vw !important;
        height: 100vh !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border-radius: 0 !important; /* Ei pyöristyksiä koko näytön tilassa */
        box-shadow: none !important; /* Ei varjoa koko näytön tilassa */
    }
    
    .widget-bubble {
        width: 70px;
        height: 70px;
    }
    
    .widget-frame {
        position: fixed !important;
        border-radius: 0 !important; /* Ei pyöristyksiä koko näytön tilassa */
        width: 100vw !important;
        height: 100vh !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
    .widget-expanded {
        width: 380px;
        height: 550px;
    }
}

