/* =========================================================
   SARA v2.1 — Avatar AI con voce e microfono
   Stile sardo/mediterraneo caldo
   ========================================================= */
:root {
    --sara-brand:   #C4683A;
    --sara-teal:    #4E8B8D;
    --sara-dark:    #2C1A0E;
    --sara-surface: #FDFAF7;
    --sara-border:  rgba(196,104,58,0.18);
    --sara-radius:  20px;
}

/* ── FAB ── */
.sara-fab {
    position: fixed;
    bottom: 1.5rem; right: 1.5rem;
    width: 72px; height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, #C4683A, #4E8B8D);
    background-image: url('../img/saraavatar.jpg');
    background-size: cover;
    background-position: center;
    border: 3px solid #fff;
    box-shadow: 0 4px 20px rgba(196,104,58,0.45);
    cursor: pointer;
    z-index: 9990;
    padding: 0; overflow: hidden;
    transition: transform .2s, box-shadow .2s;
    animation: sara-pulse 3.5s ease-in-out infinite;
}
.sara-fab:hover { transform: scale(1.08); box-shadow: 0 8px 28px rgba(196,104,58,.55); animation: none; }
.sara-fab.is-open { animation: none; transform: scale(1.05); }
@keyframes sara-pulse {
    0%,100%{ box-shadow: 0 4px 20px rgba(196,104,58,.45); }
    50%    { box-shadow: 0 4px 30px rgba(196,104,58,.75), 0 0 0 8px rgba(196,104,58,.12); }
}
.sara-fab__badge {
    position: absolute; top: 2px; right: 2px;
    width: 14px; height: 14px;
    background: #22C55E; border-radius: 50%; border: 2px solid #fff;
    animation: sara-blink 2.5s ease-in-out infinite;
}
@keyframes sara-blink { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── Pannello ── */
.sara-panel {
    position: fixed;
    bottom: 6rem; right: 1.5rem;
    width: 360px; max-height: 600px;
    background: var(--sara-surface);
    border-radius: var(--sara-radius);
    box-shadow: 0 20px 60px rgba(44,26,14,.18), 0 4px 20px rgba(44,26,14,.1);
    border: 1px solid var(--sara-border);
    display: flex; flex-direction: column;
    overflow: hidden;
    z-index: 9991;
    opacity: 0; transform: translateY(20px) scale(.96);
    pointer-events: none;
    transition: opacity .25s, transform .25s;
}
.sara-panel.is-open { opacity: 1; transform: translateY(0) scale(1); pointer-events: all; }

/* ── Header ── */
.sara-panel__header {
    background: linear-gradient(135deg, #2C1A0E 0%, #5a2d0c 45%, #C4683A 100%);
    padding: 1rem 1rem .875rem;
    display: flex; align-items: center; gap: .875rem;
}
.sara-avatar-wrap {
    position: relative; flex-shrink: 0;
    width: 60px; height: 60px;
}
.sara-avatar-svg {
    width: 60px; height: 60px;
    border-radius: 50%;
    border: 2.5px solid rgba(255,255,255,.35);
    overflow: visible;
    filter: drop-shadow(0 2px 8px rgba(0,0,0,.3));
}

/* Avatar umano nell'header del pannello */
.sara-avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
    background-image: url('../img/saraavatar.jpg');
    background-size: cover;
    background-position: center;
    background-color: #C4683A;
    border: 2.5px solid rgba(255,255,255,.35);
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

/* Animazione parlato — pulsazione sul FAB */
.sara-fab.is-speaking-anim {
    animation: sara-speaking 1.2s ease-in-out infinite !important;
}
@keyframes sara-speaking {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(196,104,58,.45), 0 0 0 0 rgba(196,104,58,.4);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 6px 28px rgba(196,104,58,.65), 0 0 0 10px rgba(196,104,58,0);
        transform: scale(1.06);
    }
}

.sara-panel__info { flex: 1; min-width: 0; }
.sara-panel__name {
    font-size: .92rem; font-weight: 700; color: #fff; margin: 0 0 .2rem;
    font-family: 'Outfit', sans-serif;
}
.sara-panel__status {
    font-size: .72rem; color: rgba(255,255,255,.65);
    display: flex; align-items: center; gap: .35rem; margin: 0;
}
.sara-panel__status-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #4ade80; animation: sara-blink 2.5s ease-in-out infinite; flex-shrink: 0;
}
.sara-wave {
    display: none; align-items: center; gap: 3px; height: 16px;
}
.sara-wave.is-active { display: flex; }
.sara-wave span {
    width: 3px; background: rgba(255,255,255,.8); border-radius: 3px;
    animation: sara-wave-bar .8s ease-in-out infinite;
}
.sara-wave span:nth-child(1){height:5px;animation-delay:0s}
.sara-wave span:nth-child(2){height:13px;animation-delay:.1s}
.sara-wave span:nth-child(3){height:9px;animation-delay:.2s}
.sara-wave span:nth-child(4){height:16px;animation-delay:.15s}
.sara-wave span:nth-child(5){height:7px;animation-delay:.05s}
@keyframes sara-wave-bar { 0%,100%{transform:scaleY(1);opacity:.7} 50%{transform:scaleY(1.8);opacity:1} }
.sara-lang-badge {
    font-size: .63rem; font-weight: 700;
    background: rgba(255,255,255,.15); color: rgba(255,255,255,.85);
    padding: .18rem .5rem; border: 0; border-radius: 9999px; letter-spacing: .06em;
    cursor: pointer;
}
.sara-panel__close {
    background: rgba(255,255,255,.12); border: none; color: #fff;
    width: 28px; height: 28px; border-radius: 50%;
    cursor: pointer; font-size: .9rem;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s; flex-shrink: 0;
}
.sara-panel__close:hover { background: rgba(255,255,255,.28); }

/* ── Messaggi ── */
.sara-messages {
    flex: 1; overflow-y: auto; padding: 1rem;
    display: flex; flex-direction: column; gap: .625rem;
    scroll-behavior: smooth;
}
.sara-messages::-webkit-scrollbar { width: 3px; }
.sara-messages::-webkit-scrollbar-thumb { background: rgba(196,104,58,.25); border-radius: 3px; }
.sara-msg {
    max-width: 82%; padding: .625rem .875rem;
    border-radius: 14px; font-size: .84rem; line-height: 1.55;
    word-break: break-word;
}
.sara-msg--bot {
    background: #fff; color: var(--sara-dark);
    border: 1px solid rgba(196,104,58,.12);
    border-bottom-left-radius: 4px; align-self: flex-start;
    box-shadow: 0 1px 6px rgba(44,26,14,.06);
}
.sara-msg--user {
    background: linear-gradient(135deg, #C4683A, #a3522d); color: #fff;
    border-bottom-right-radius: 4px; align-self: flex-end;
}
.sara-msg__audio {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-left: .45rem;
    vertical-align: middle;
    border: 1px solid rgba(196,104,58,.22);
    border-radius: 9999px;
    background: #fff8f3;
    color: var(--sara-brand);
    font-size: .72rem;
    line-height: 1;
    cursor: pointer;
}
.sara-msg__audio:hover {
    background: var(--sara-brand);
    color: #fff;
}
.sara-typing {
    display: flex; gap: 4px; align-items: center;
    padding: .625rem .875rem;
    background: #fff; border: 1px solid rgba(196,104,58,.12);
    border-radius: 14px; border-bottom-left-radius: 4px;
    width: fit-content; box-shadow: 0 1px 6px rgba(44,26,14,.06);
}
.sara-typing span {
    width: 6px; height: 6px; background: #C4683A; border-radius: 50%;
    animation: sara-bounce .9s ease-in-out infinite;
}
.sara-typing span:nth-child(2){animation-delay:.15s}
.sara-typing span:nth-child(3){animation-delay:.30s}
@keyframes sara-bounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-6px)} }

/* ── Suggerimenti ── */
.sara-suggestions {
    padding: 0 .75rem .5rem;
    display: flex; flex-wrap: wrap; gap: .375rem;
}
.sara-suggestion {
    background: #fff; border: 1px solid rgba(196,104,58,.25);
    color: var(--sara-brand); font-size: .72rem; font-weight: 600;
    padding: .3rem .7rem; border-radius: 9999px;
    cursor: pointer; transition: all .15s; white-space: nowrap;
}
.sara-suggestion:hover { background: var(--sara-brand); color: #fff; border-color: var(--sara-brand); }

/* ── Input area ── */
.sara-input-area {
    padding: .75rem; border-top: 1px solid rgba(196,104,58,.1);
    background: #fff; display: flex; gap: .5rem; align-items: flex-end;
}
.sara-input {
    flex: 1; border: 1.5px solid rgba(196,104,58,.2);
    border-radius: 12px; padding: .5rem .75rem;
    font-size: .84rem; font-family: 'Plus Jakarta Sans', sans-serif;
    resize: none; outline: none; line-height: 1.4;
    max-height: 80px; overflow-y: auto;
    color: var(--sara-dark); transition: border-color .15s;
    background: var(--sara-surface);
}
.sara-input:focus { border-color: var(--sara-brand); }

/* ── Pulsante microfono ── */
.sara-mic {
    width: 36px; height: 36px; border-radius: 50%;
    border: 1.5px solid rgba(196,104,58,.25); background: #fff;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--sara-brand); transition: all .2s ease; flex-shrink: 0;
    font-size: 1rem;
}
.sara-mic:hover { background: #fff5f0; border-color: var(--sara-brand); }

/* Stato ascolto attivo — rosso pulsante con scale */
.sara-mic.is-listening {
    background: #ef4444;
    border-color: #ef4444;
    color: #fff;
    transform: scale(1.15);
    animation: sara-mic-pulse .85s ease-in-out infinite;
}

/* Non supportato dal browser */
.sara-mic.is-unsupported { opacity: .3; cursor: not-allowed; }

@keyframes sara-mic-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239,68,68,.5);
        transform: scale(1.15);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(239,68,68,0);
        transform: scale(1.18);
    }
}

.sara-send {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, #C4683A, #a3522d);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: #fff; transition: transform .15s, box-shadow .15s; flex-shrink: 0;
}
.sara-send:hover { transform: scale(1.08); box-shadow: 0 4px 12px rgba(196,104,58,.4); }
.sara-send:disabled { opacity: .4; transform: none; cursor: not-allowed; }
.sara-disclaimer {
    font-size: .65rem; color: rgba(44,26,14,.35); text-align: center;
    padding: .35rem .75rem .5rem; margin: 0;
    background: #fff; border-top: 1px solid rgba(196,104,58,.06);
}

@media (max-width: 480px) {
    .sara-panel { width: calc(100vw - 2rem); right: 1rem; bottom: 5.5rem; max-height: 70vh; }
    .sara-fab   { bottom: 1rem; right: 1rem; width: 64px; height: 64px; }
}
