/* Widget AI bot - Sistema Group Engineering */
#sg-chat, #sg-chat * { box-sizing: border-box; }

#sg-chat {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 9999;
    font-family: inherit;
}

#sg-chat-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: #0950e6;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(9, 80, 230, .35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease, background .2s ease;
}
#sg-chat-toggle:hover { transform: scale(1.06); background: #073fbb; }
#sg-chat-toggle svg { width: 30px; height: 30px; }

/* Vibrazione del bottone quando richiama l'attenzione (idle) */
#sg-chat.sg-nudging #sg-chat-toggle {
    animation: sg-shake 2.6s ease-in-out infinite;
}
@keyframes sg-shake {
    0%, 78%, 100% { transform: translateX(0) rotate(0); }
    80% { transform: translateX(-3px) rotate(-7deg); }
    83% { transform: translateX(3px)  rotate(7deg); }
    86% { transform: translateX(-3px) rotate(-6deg); }
    89% { transform: translateX(3px)  rotate(5deg); }
    92% { transform: translateX(-2px) rotate(-3deg); }
    95% { transform: translateX(1px)  rotate(2deg); }
}
@media (prefers-reduced-motion: reduce) {
    #sg-chat.sg-nudging #sg-chat-toggle { animation: none; }
}

/* Badge "AI" sul bottone */
.sg-ai-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #fff;
    color: #0950e6;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: .3px;
    padding: 3px 5px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,.2);
}

/* Puntino "online" nel titolo */
.sg-chat-title { display: inline-flex; align-items: center; gap: 7px; }
.sg-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #2ec16b; box-shadow: 0 0 0 rgba(46,193,107,.6);
    animation: sg-pulse 2s infinite;
}
@keyframes sg-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(46,193,107,.5); }
    70%  { box-shadow: 0 0 0 6px rgba(46,193,107,0); }
    100% { box-shadow: 0 0 0 0 rgba(46,193,107,0); }
}

/* Fumetto richiamo (idle) */
#sg-chat-nudge {
    position: absolute;
    right: 4px;
    bottom: 74px;
    max-width: 220px;
    background: #fff;
    color: #1b2a4a;
    font-size: 14px;
    font-weight: 500;
    padding: 12px 34px 12px 16px;
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 8px 26px rgba(0,0,0,.16);
    cursor: pointer;
    animation: sg-nudge-in .35s ease, sg-nudge-bob 2.4s ease-in-out .4s infinite;
    white-space: nowrap;
}
#sg-chat-nudge[hidden] { display: none; }
#sg-chat-nudge-close {
    position: absolute;
    top: 4px; right: 6px;
    background: none; border: none;
    color: #9aa3b2; font-size: 16px; line-height: 1;
    cursor: pointer; padding: 2px;
}
@keyframes sg-nudge-in {
    from { opacity: 0; transform: translateY(8px) scale(.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes sg-nudge-bob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-4px); }
}

#sg-chat-panel {
    position: absolute;
    right: 0;
    bottom: 74px;
    width: 360px;
    max-width: calc(100vw - 44px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
    display: none;
    flex-direction: column;
    overflow: hidden;
}
#sg-chat.open #sg-chat-panel { display: flex; }

.sg-chat-header {
    background: #0950e6;
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 15px;
}
.sg-chat-header button {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

#sg-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f5f7fb;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sg-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.sg-msg.bot  { background: #fff; color: #222; align-self: flex-start; border: 1px solid #e4e8f0; border-bottom-left-radius: 4px; }
.sg-msg.user { background: #0950e6; color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.sg-msg.typing { color: #888; font-style: italic; }

/* Contenuto formattato (Markdown -> HTML) nelle risposte del bot */
.sg-msg p { margin: 0 0 8px; }
.sg-msg p:last-child { margin-bottom: 0; }
.sg-msg ul, .sg-msg ol { margin: 4px 0 8px; padding-left: 20px; }
.sg-msg li { margin: 2px 0; }
.sg-msg a { color: #0950e6; text-decoration: underline; font-weight: 600; }
.sg-msg.user a { color: #fff; }
.sg-msg strong { font-weight: 700; }

#sg-chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e4e8f0;
    background: #fff;
}
#sg-chat-input {
    flex: 1;
    border: 1px solid #d6dbe6;
    border-radius: 22px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
}
#sg-chat-input:focus { border-color: #0950e6; }
#sg-chat-form button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: #0950e6;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
}
#sg-chat-form button:disabled { opacity: .5; cursor: default; }

.sg-chat-footer {
    text-align: center;
    font-size: 11px;
    color: #9aa3b2;
    padding: 6px;
    background: #fff;
}
.sg-chat-footer a { color: #9aa3b2; text-decoration: underline; }
