/**
 * archichat.css
 * Stile widget ArchiChat - grafica fumetto, responsive, mobile-friendly.
 * Compatibile con il layout ArchiMed (menu laterale + header + contenuto).
 */

/* -- Reset widget */
#ac-widget * {
    box-sizing: border-box;
}
/* ::before e ::after NON resettati: le codette fumetto usano border trick */
#ac-widget *::before,
#ac-widget *::after {
    box-sizing: border-box;
}

/* -- Variabili colore */
#ac-widget {
    --ac-brand:        #1a73e8;
    --ac-brand-dark:   #1557b0;
    --ac-brand-light:  #e8f0fe;
    --ac-urgente:      #e53935;
    --ac-urgente-bg:   #fff3e0;
    --ac-bg-chat:      #ece5dd;   /* sfondo area messaggi - verde WhatsApp */
    --ac-fumetto-in:   #ffffff;
    --ac-fumetto-out:  #d9fdd3;   /* verde uscente */
    --ac-fumetto-urg:  #fff3e0;
    --ac-text:         #111;
    --ac-text-muted:   #888;
    --ac-border:       #e0e0e0;
    --ac-header-h:     48px;
    --ac-panel-w:      340px;
    --ac-panel-h:      540px;
    --ac-radius:       14px;
    --ac-shadow:       0 4px 24px rgba(0,0,0,.18);
    --ac-font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* -- Posizionamento widget */
#ac-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9000;
    font-family: var(--ac-font);
    font-size: 14px;
    color: var(--ac-text);
}

/* -- Bottone flottante */
#ac-btn-toggle {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--ac-brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--ac-shadow);
    font-size: 24px;
    position: relative;
    user-select: none;
    touch-action: none;          /* drag con pointer events su touch */
    transition: background .2s, transform .15s;
}
#ac-btn-toggle:hover  { background: var(--ac-brand-dark); }
#ac-btn-toggle:active { transform: scale(.93); }
#ac-btn-toggle .ac-icon svg { display: block; }

.ac-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--ac-urgente);
    color: #fff;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid #fff;
}

/* -- Pannello principale */
#ac-panel {
    display: none;
    width: var(--ac-panel-w);
    height: var(--ac-panel-h);
    background: #fff;
    border-radius: var(--ac-radius);
    box-shadow: var(--ac-shadow);
    flex-direction: column;
    overflow: visible;
    position: absolute;
    bottom: 62px;
    right: 0;
    /* Animazione apertura */
    transform-origin: bottom right;
    animation: ac-open .18s ease-out;
}

@keyframes ac-open {
    from { opacity: 0; transform: scale(.92) translateY(8px); }
    to   { opacity: 1; transform: scale(1)   translateY(0);   }
}

#ac-widget:not(.ac-chiuso) #ac-panel {
    display: flex;
}

/* -- Icona trascinabile: nascondi finche' non e' nota la posizione salvata */
#ac-widget.ac-pos-loading #ac-btn-toggle { visibility: hidden; }

/* Durante il trascinamento */
#ac-widget.ac-trascino #ac-btn-toggle { cursor: grabbing; }
#ac-widget.ac-trascino #ac-panel      { animation: none; }

/* -- Ancoraggio del pannello secondo il quadrante dell'icona
      (classi ac-pos-sx / ac-pos-alto impostate via JS) */
#ac-widget.ac-pos-sx   #ac-panel { right: auto; left: 0; }
#ac-widget.ac-pos-alto #ac-panel { bottom: auto; top: 62px; }

#ac-widget.ac-pos-sx              #ac-panel { transform-origin: bottom left; }
#ac-widget.ac-pos-alto            #ac-panel { transform-origin: top right; }
#ac-widget.ac-pos-sx.ac-pos-alto  #ac-panel { transform-origin: top left; }



/* -- Header pannello */
#ac-header {
    background: var(--ac-brand);
    color: #fff;
    height: var(--ac-header-h);
    padding: 0 12px;
    border-radius: var(--ac-radius) var(--ac-radius) 0 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

#ac-title {
    flex: 1;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: .2px;
}

#ac-btn-nuova,
#ac-btn-avatar,
#ac-btn-close {
    display: inline-flex;          /* il bottone diventa un container flex */
    align-items: center;           /* centra il glifo verticalmente */
    justify-content: center;       /* e orizzontalmente */
    width: 30px;                   /* box uguali ? allineati in riga */
    height: 30px;
    padding: 0;                    /* il padding asimmetrico spostava il glifo */
    line-height: 1;
}
.ac-hico {
    display: inline-block;
    line-height: 1;
    vertical-align: middle;
}
/*
#ac-btn-nuova .ac-hico {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 22px;
    height: 22px;
    border: 1.5px solid currentColor;
    border-radius: 50%;
    /* niente translateY: l'SVG è centrato dal flex, identico su ogni OS */
/*}
*/
#ac-btn-nuova .ac-plus-svg { display: block; }

#ac-btn-avatar .ac-hico { font-size: 22px; transform: translateY(2px); }

#ac-btn-close .ac-hico  { font-size: 24px; font-weight: 700; }

#ac-header button {
    background: none;
    border: none;
    color: rgba(255,255,255,.85);
    cursor: pointer;
    font-size: 17px;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
    transition: background .15s;
}
#ac-header button:hover { background: rgba(255,255,255,.15); }

/* -- Sezione Account (header, a sinistra) */
#ac-account-wrap { position: relative; flex-shrink: 0; }

#ac-btn-account {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}
#ac-btn-account .ac-account-ico  { font-size: 18px; line-height: 1; transform: translateY(1.5px);}
#ac-btn-account .ac-account-dots { font-size: 15px; line-height: 1; opacity: .85; }

#ac-account-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 180px;
    white-space: nowrap;
    background: #fff;
    border: 1px solid var(--ac-border);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
    padding: 4px;
    z-index: 50;
}
#ac-account-menu .ac-account-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: none;
    border: none;
    color: var(--ac-text);
    font-size: 13.5px;
    text-align: left;
    padding: 9px 10px;
    border-radius: 7px;
    cursor: pointer;
    font-family: var(--ac-font);
    line-height: 1.2;
    transition: background .12s, color .12s;
}
#ac-account-menu .ac-account-item:hover {
    background: var(--ac-brand-light);
    color: var(--ac-brand);
}
#ac-account-menu .ac-acc-ico { font-size: 16px; }

/* -- Lista conversazioni */
#ac-lista-conv {
    flex: 1;
    overflow-y: auto;
    padding: 0 4px;
    border-radius: 0 0 var(--ac-radius) var(--ac-radius);
}
#ac-lista-conv::-webkit-scrollbar { width: 4px; }
#ac-lista-conv::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

.ac-conv-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px 11px 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--ac-border);
    transition: background .12s;
}
.ac-conv-item:hover { background: #f5f8ff; }
.ac-conv-item:active { background: var(--ac-brand-light); }

.ac-conv-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--ac-brand-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.ac-avatar-gruppo { background: #e8f5e9; }

.ac-conv-info {
    flex: 1;
    min-width: 0;
}
.ac-conv-nome {
    display: block;
    font-weight: 600;
    font-size: 13.5px;
    white-space: nowrap;
    overflow: hidden;
    /* clip codette fumetti */
    text-overflow: ellipsis;
}
.ac-conv-preview {
    display: block;
    font-size: 12px;
    color: var(--ac-text-muted);
    white-space: nowrap;
    overflow: hidden;
    /* clip codette fumetti */
    text-overflow: ellipsis;
    margin-top: 2px;
}

.ac-conv-typing {
    display: block;
    font-size: 12px;
    color: var(--ac-brand);
    font-style: italic;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.ac-conv-meta {
    text-align: right;
    flex-shrink: 0;
    min-width: 38px;
}
.ac-conv-ora {
    display: block;
    font-size: 11px;
    color: var(--ac-text-muted);
}
.ac-conv-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--ac-brand);
    color: #fff;
    border-radius: 50%;
    min-width: 18px;
    height: 18px;
    font-size: 11px;
    font-weight: 700;
    padding: 0 4px;
    margin-top: 3px;
}

/* -- Area chat */
#ac-chat-area {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    /* clip codette fumetti */
}

#ac-chat-header {
    background: var(--ac-brand);
    color: #fff;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--ac-brand-dark);
    flex-shrink: 0;
    border-radius: var(--ac-radius) var(--ac-radius) 0 0;   /* <-- aggiungi */
}

#ac-btn-back {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #fff;
    padding: 2px 4px;
    line-height: 1;
}

/* Wrapper titolo: flex-item elastico in riga */
#ac-chat-titolo-wrap {
    flex: 1;
    min-width: 0;          /* annulla il min-width:auto di default dei flex-item */
    display: flex;
    align-items: baseline;
    gap: 6px;
    overflow: hidden;
}

#ac-chat-titolo {
    flex: 1;
    min-width: 0;          /* serve anche qui: è il titolo a doversi rimpicciolire e tagliare */
    font-weight: 700;
    font-size: 14px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#ac-partecipanti-count {
    flex-shrink: 0;        /* il conteggio resta sempre intero accanto al titolo */
    font-size: 12px;
    color: rgba(255,255,255,.8);
}

#ac-btn-back,
#ac-btn-info {
    flex-shrink: 0;        /* i bottoni non vanno mai compressi o spinti fuori */
}


#ac-btn-info {
    background: none;
    border: none;
    color: rgba(255,255,255,.9);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
    transition: background .15s;
}
#ac-btn-info:hover { background: rgba(255,255,255,.15); }

/* Avatar nell'header della chat */
#ac-chat-header-avatar { flex-shrink: 0; display: flex; }
.ac-chat-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,.25);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
}

/* -- Area messaggi */
#ac-messaggi {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    background: var(--ac-bg-chat);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
#ac-messaggi::-webkit-scrollbar { width: 4px; }
#ac-messaggi::-webkit-scrollbar-thumb { background: #bbb; border-radius: 4px; }
#ac-load-msgs {
    text-align: center;
    font-size: 12px;
    color: var(--ac-text-muted) !important;
    padding: 6px 0 !important;
    flex-shrink: 0;
}

/* -- Fumetti */
.ac-msg-wrap {
    display: flex;
    margin-bottom: 2px;
}
.ac-msg-in  { justify-content: flex-start; }
.ac-msg-out { justify-content: flex-end; }

.ac-fumetto {
    max-width: 76%;
    padding: 7px 11px 5px;
    border-radius: 12px;
    position: relative;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,.12);
    font-size: 13.5px;
    line-height: 1.45;
}

.ac-msg-cancellato-txt {
    font-style: italic;
    opacity: .7;
}
.ac-msg-cancellato-txt em { font-style: italic; }

/* Codetta del fumetto */
.ac-msg-in .ac-fumetto {
    background: var(--ac-fumetto-in);
    border-bottom-left-radius: 3px;
    margin-left: 7px;
}
.ac-msg-in .ac-fumetto::before {
    content: '';
    position: absolute;
    left: -6px;
    bottom: 0;
    width: 0;
    height: 0;
    border: 6px solid transparent;
    border-right-color: var(--ac-fumetto-in);
    border-bottom-color: var(--ac-fumetto-in);
}
.ac-msg-in .ac-fumetto:has(.ac-msg-urgente)::before {
    border-right-color: var(--ac-fumetto-urg);
    border-bottom-color: var(--ac-fumetto-urg);
}

.ac-msg-out .ac-fumetto {
    background: var(--ac-fumetto-out);
    border-bottom-right-radius: 3px;
    margin-right: 7px;
}
.ac-msg-out .ac-fumetto::after {
    content: '';
    position: absolute;
    right: -6px;
    bottom: 0;
    width: 0;
    height: 0;
    border: 6px solid transparent;
    border-left-color: var(--ac-fumetto-out);
    border-bottom-color: var(--ac-fumetto-out);
}

.ac-msg-out .ac-fumetto:has(.ac-msg-urgente)::after {
    border-left-color: var(--ac-fumetto-urg);
    border-bottom-color: var(--ac-fumetto-urg);
}

/* Sequenza stesso mittente: codetta solo sull'ultimo del run */
.ac-msg-in  .ac-fumetto.ac-no-tail::before,
.ac-msg-out .ac-fumetto.ac-no-tail::after { display: none; }
.ac-msg-in  .ac-fumetto.ac-no-tail { border-bottom-left-radius: 12px; }
.ac-msg-out .ac-fumetto.ac-no-tail { border-bottom-right-radius: 12px; }

/* Nome mittente (solo nei gruppi, per i messaggi in entrata) */
.ac-msg-mittente {
    display: block;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--ac-brand);
    margin-bottom: 2px;
}

/* Etichetta "Inoltrato" (stile WhatsApp) */
.ac-msg-inoltrato {
    display: block;
    font-size: 11px;
    font-style: italic;
    color: var(--ac-text-muted);
    margin-bottom: 2px;
}

/* Footer messaggio: ora + spunta sulla stessa riga */
.ac-msg-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
    margin-top: 3px;
}
.ac-msg-ora {
    font-size: 10px;
    color: var(--ac-text-muted);
    white-space: nowrap;
}
.ac-msg-letto {
    font-size: 10px;
    color: var(--ac-text-muted);
    line-height: 1;
    letter-spacing: -1px;
}
.ac-msg-out .ac-msg-letto { color: #4fc3f7; }

/* -- Messaggio urgente */
.ac-msg-urgente {
    background: var(--ac-urgente-bg);
    border-left: 4px solid var(--ac-urgente);
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.5;
}
.ac-msg-urgente strong {
    color: var(--ac-urgente);
}

/* Fumetto urgente: sfondo speciale */
.ac-msg-in .ac-fumetto:has(.ac-msg-urgente),
.ac-msg-out .ac-fumetto:has(.ac-msg-urgente) {
    background: var(--ac-fumetto-urg);
    box-shadow: 0 1px 4px rgba(229,57,53,.2);
}
/* codette urgente: rimosse */

/* -- Allegati */
.ac-msg-img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    display: block;
    cursor: pointer;
    margin-top: 2px;
}
.ac-msg-img:hover { opacity: .9; }

.ac-msg-pdf {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--ac-brand);
    text-decoration: none;
    font-size: 13px;
    padding: 4px 0;
}
.ac-msg-pdf:hover { text-decoration: underline; }

/* Separatore data */
.ac-data-sep {
    text-align: center;
    font-size: 11px;
    color: var(--ac-text-muted);
    margin: 8px 0 4px;
    position: relative;
}
.ac-data-sep span {
    background: var(--ac-bg-chat);
    padding: 0 8px;
    position: relative;
    z-index: 1;
}
.ac-data-sep::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0; right: 0;
    border-top: 1px solid #ccc;
}

/* -- Barra "sta scrivendo" */
#ac-typing-bar {
    padding: 3px 14px;
    font-size: 11.5px;
    color: var(--ac-text-muted);
    font-style: italic;
    background: var(--ac-bg-chat);
    min-height: 20px;
}

/* -- Area input */
#ac-input-area {
    display: flex;
    align-items: flex-end;
    padding: 7px 8px;
    gap: 6px;
    background: #f0f0f0;
    border-top: 1px solid var(--ac-border);
    flex-shrink: 0;
    border-radius: 0 0 var(--ac-radius) var(--ac-radius);
    order: 2;     /* resta in fondo -> conserva l'arrotondamento */
}

#ac-input-msg {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 22px;
    padding: 8px 14px;
    resize: none;
    font-size: 13.5px;
    font-family: var(--ac-font);
    max-height: 90px;
    outline: none;
    line-height: 1.4;
    background: #fff;
    transition: border-color .15s;
}
#ac-input-msg:focus { border-color: var(--ac-brand); }

#ac-input-area button,
#ac-btn-allegato {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    width: 36px;            /* box fissa -> cerchio uniforme */
    height: 36px;
    padding: 0;             /* il padding rendeva il cerchio irregolare */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;         /* non si comprimono accanto al textarea */
    transition: background .15s, color .15s;
    line-height: 1;
}
#ac-input-area button:hover,
#ac-btn-allegato:hover {
    background: rgba(0,0,0,.06);
    color: var(--ac-brand);
}

#ac-btn-invia {
    color: var(--ac-brand) !important;
    font-size: 22px !important;
}
#ac-btn-invia:hover { color: var(--ac-brand-dark) !important; }

/* Anteprima dell'allegato in attesa (sopra l'area input) */
#ac-allegato-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px !important;
    margin: 0 !important;
    background: var(--ac-brand-light);
    border-left: 3px solid var(--ac-brand);
    border-radius: 6px 6px 0 0;
    order: 1;            /* nel cluster sopra l'area input */
    flex-shrink: 0;
}
.ac-allegato-thumb {
    width: 38px;
    height: 38px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}
.ac-allegato-ico {
    font-size: 22px;
    flex-shrink: 0;
}
.ac-allegato-nome {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12.5px;
    color: var(--ac-text) !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#ac-allegato-rimuovi {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    color: var(--ac-text-muted) !important;
    font-size: 16px;
    line-height: 1;
    padding: 0 !important;
    margin: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
}
#ac-allegato-rimuovi:hover { background: rgba(0,0,0,.08); color: var(--ac-brand) !important; }

/* Didascalia testuale che accompagna un allegato (eredita il colore del fumetto) */
.ac-msg-didascalia {
    margin-top: 5px !important;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 13.5px;
    line-height: 1.4;
}

#ac-btn-invia.ac-invia-urgente {
    color: var(--ac-urgente) !important;
    background: var(--ac-urgente-bg);
}
#ac-btn-invia.ac-invia-urgente:hover {
    color: #fff !important;
    background: var(--ac-urgente) !important;
}

#ac-btn-urgente { font-size: 18px !important; }
#ac-btn-urgente:hover { color: var(--ac-urgente) !important; }

/* -- Barra urgenza paziente */
#ac-urgente-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    background: var(--ac-urgente-bg);
    border-top: 1px solid #ffcc80;
    flex-shrink: 0;
    position: relative;
    order: 1;     /* sopra l'area input */
}

/* Dropdown autocomplete pazienti (custom) */
#ac-paziente-risultati {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 8px;
    right: 8px;
    background: #fff;
    border: 1px solid var(--ac-border);
    border-radius: 8px;
    box-shadow: 0 3px 12px rgba(0,0,0,.18);
    max-height: 180px;
    overflow-y: auto;
    z-index: 20;
}
.ac-paz-item {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--ac-text);
    cursor: pointer;
    border-bottom: 1px solid var(--ac-border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ac-paz-item:last-child { border-bottom: none; }
.ac-paz-item:hover {
    background: var(--ac-brand-light);
    color: var(--ac-brand);
}

.ac-paz-item.ac-paz-active {
    background: var(--ac-brand-light);
    color: var(--ac-brand);
}
.ac-modal-op-item.ac-modal-op-active { background: #f5f8ff; }

#ac-paziente-input {
    flex: 1;
    border: 1px solid #ffb74d;
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 12.5px;
    outline: none;
    background: #fff;
}
#ac-paziente-input:focus { border-color: var(--ac-urgente); }


#ac-urgente-cancel {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #888;
    padding: 2px;
}

/* -- Dialog nuova chat */
#ac-modal-nuova {
    position: absolute;
    inset: 0;
    background: #fff;
    z-index: 10;
    display: flex;
    flex-direction: column;
    border-radius: var(--ac-radius);
    overflow: hidden;
}

#ac-modal-header {
    background: var(--ac-brand);
    color: #fff;
    height: var(--ac-header-h);
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
    border-radius: var(--ac-radius) var(--ac-radius) 0 0;   /* <-- aggiungi */
}
#ac-modal-header button {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
    transition: background .15s;
}
#ac-modal-header button:hover { background: rgba(255,255,255,.2); }

/* -- Tab Privata / Gruppo -- */
#ac-modal-tabs {
    display: flex;
    gap: 8px;
    padding: 10px 12px 6px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--ac-border);
}
.ac-tab {
    flex: 1;
    padding: 7px 10px;
    border: 2px solid var(--ac-border);
    border-radius: 20px;
    background: #fff;
    color: var(--ac-text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
.ac-tab:hover {
    border-color: var(--ac-brand);
    color: var(--ac-brand);
}
.ac-tab.active {
    background: var(--ac-brand);
    border-color: var(--ac-brand);
    color: #fff;
}

/* -- Reazioni emoji */
.ac-msg-wrap { align-items: flex-end; }   /* trigger allineato in basso alla bolla */

.ac-msg-col {
    display: flex;
    flex-direction: column;
    max-width: 76%;
    min-width: 0;
}
.ac-msg-col .ac-fumetto { max-width: 100%; }

.ac-reaz-trigger {
    background: #fff;
    border: 1px solid var(--ac-border);
    color: var(--ac-text-muted);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 13px;
    line-height: 1;
    padding: 0;
    margin: 0 4px 4px;
    cursor: pointer;
    flex-shrink: 0;
    opacity: .35;                /* visibile ma discreto: tappabile anche su mobile */
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0,0,0,.12);
    transition: opacity .15s, background .15s, color .15s;
}
.ac-msg-wrap:hover .ac-reaz-trigger { opacity: 1; }
.ac-reaz-trigger:hover { background: var(--ac-brand-light); color: var(--ac-brand); }
/* -- Icona opzioni messaggio (compare al passaggio del mouse, stile WhatsApp) */
.ac-msg-menu-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    padding: 0 !important;
    margin: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--ac-text-muted) !important;
    background: transparent;
    opacity: 0;
    transition: opacity .15s, background .15s, color .15s;
}
.ac-msg-in  .ac-msg-menu-btn { background: linear-gradient(225deg, var(--ac-fumetto-in)  65%, transparent); }
.ac-msg-out .ac-msg-menu-btn { background: linear-gradient(225deg, var(--ac-fumetto-out) 65%, transparent); }
.ac-fumetto:has(.ac-msg-urgente) .ac-msg-menu-btn { background: linear-gradient(225deg, var(--ac-fumetto-urg) 65%, transparent); }
.ac-msg-wrap:hover .ac-msg-menu-btn,
.ac-msg-menu-btn:focus-visible { opacity: 1; }
.ac-msg-menu-btn:hover { color: var(--ac-brand) !important; }

/* -- Dropdown opzioni messaggio (appeso a body: colori letterali) */
#ac-msg-menu {
    position: fixed;
    z-index: 9999;
    min-width: 150px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 5px !important;
    box-shadow: 0 6px 20px rgba(0,0,0,.18);
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.ac-msg-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: none;
    border: none;
    border-radius: 7px;
    padding: 8px 10px !important;
    margin: 0 !important;
    font-size: 13.5px;
    color: #111 !important;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
}
.ac-msg-menu-item:hover,
.ac-msg-menu-item:focus-visible { background: #e8f0fe; outline: none; }
.ac-msg-menu-item.ac-danger { color: #d93025 !important; }
.ac-msg-menu-item.ac-danger:hover,
.ac-msg-menu-item.ac-danger:focus-visible { background: #fde8e7; }
.ac-msg-menu-ico { font-size: 15px; width: 18px; text-align: center; }

@media (prefers-color-scheme: dark) {
    #ac-msg-menu { background: #2a2a2a; border-color: #444; }
    .ac-msg-menu-item { color: #e0e0e0 !important; }
    .ac-msg-menu-item:hover,
    .ac-msg-menu-item:focus-visible { background: #33415a; }
}

/* -- Citazione dentro il fumetto (messaggio a cui si risponde) */
.ac-msg-quote {
    display: block;
    border-left: 3px solid var(--ac-brand);
    background: rgba(0,0,0,.05);
    border-radius: 5px;
    padding: 3px 7px !important;
    margin: 0 0 4px !important;
    font-size: 12.5px;
    line-height: 1.35;
    cursor: pointer;
    max-width: 100%;
    overflow: hidden;
}
.ac-msg-out .ac-msg-quote { background: rgba(0,0,0,.07); }
.ac-msg-quote-aut {
    display: block;
    font-weight: 600;
    color: var(--ac-brand) !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ac-msg-quote-txt {
    display: block;
    color: var(--ac-text-muted) !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Evidenziazione al salto sul messaggio originale */
.ac-msg-evidenzia .ac-fumetto { animation: ac-flash 1.5s ease; }
@keyframes ac-flash {
    0%, 100% { box-shadow: 0 1px 2px rgba(0,0,0,.12); }
    25%      { box-shadow: 0 0 0 3px var(--ac-brand-light); }
}

/* -- Barra "stai rispondendo a..." sopra l'input */
#ac-reply-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px !important;
    margin: 0 !important;
    background: var(--ac-brand-light);
    border-left: 3px solid var(--ac-brand);
    border-radius: 6px 6px 0 0;
}
#ac-reply-bar.ac-hidden { display: none; }
.ac-reply-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.ac-reply-aut {
    font-size: 12px;
    font-weight: 600;
    color: var(--ac-brand) !important;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ac-reply-txt {
    font-size: 12px;
    color: var(--ac-text-muted) !important;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#ac-reply-cancel {
    flex-shrink: 0;
    width: 26px; height: 26px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    color: var(--ac-text-muted) !important;
    font-size: 13px;
    line-height: 1;
    padding: 0 !important;
    margin: 0 !important;
    display: flex; align-items: center; justify-content: center;
}
#ac-reply-cancel:hover { background: rgba(0,0,0,.08); color: var(--ac-brand) !important; }

.ac-reazioni {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 3px;
}
.ac-msg-out .ac-reazioni { justify-content: flex-end; }
.ac-msg-in  .ac-reazioni { justify-content: flex-start; }

.ac-reaz-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: #fff;
    border: 1px solid var(--ac-border);
    border-radius: 11px;
    padding: 1px 6px 1px 5px;
    font-size: 12px;
    line-height: 1.4;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
    user-select: none;
    transition: border-color .15s, background .15s;
}
.ac-reaz-chip:hover { border-color: var(--ac-brand); }
.ac-reaz-chip.ac-reaz-mia { background: var(--ac-brand-light); border-color: var(--ac-brand); }
.ac-reaz-n { font-size: 11px; font-weight: 600; color: var(--ac-text-muted); }
.ac-reaz-chip.ac-reaz-mia .ac-reaz-n { color: var(--ac-brand); }

/* Popover scelta reazione */
#ac-reaz-popover {
    position: fixed;
    z-index: 9999;
    display: flex;
    gap: 2px;
    background: #fff;
    border: 1px solid var(--ac-border);
    border-radius: 22px;
    padding: 4px 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.ac-reaz-opt {
    background: none;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .1s, background .15s;
}
.ac-reaz-opt:hover { background: var(--ac-brand-light); transform: scale(1.2); }
.ac-msg-out .ac-reaz-chip { cursor: default; }
.ac-msg-out .ac-reaz-chip:hover { border-color: var(--ac-border); }

@media (prefers-color-scheme: dark) {
    .ac-reaz-chip, .ac-reaz-trigger, .ac-fwd-trigger, #ac-reaz-popover {
        background: #2a2a2a; border-color: #444; color: #e0e0e0;
    }
}

/* -- Campo ricerca -- */
#ac-modal-search {
    padding: 8px 12px;
    flex-shrink: 0;
}
#ac-op-search {
    width: 100%;
    border: 1px solid var(--ac-border);
    border-radius: 20px;
    padding: 7px 14px;
    font-size: 13px;
    outline: none;
    background: #f5f5f5;
    transition: border-color .15s;
}
#ac-op-search:focus {
    border-color: var(--ac-brand);
    background: #fff;
}

/* -- Lista operatori -- */
#ac-modal-lista-op {
    flex: 1;
    overflow-y: auto;
}
.ac-modal-op-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--ac-border);
    transition: background .12s;
}
.ac-modal-op-item:hover { background: #f5f8ff; }
.ac-modal-op-item:last-child { border-bottom: none; }

.ac-modal-op-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--ac-brand-light);
    color: var(--ac-brand) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700 !important;
    flex-shrink: 0;
}

.ac-modal-op-info {
    flex: 1;
    min-width: 0;
}
.ac-modal-op-nome {
    display: block;
    font-size: 13.5px;
    font-weight: 600;
    color: #111 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ac-modal-op-qual {
    display: block;
    font-size: 11.5px;
    color: #666 !important;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* check a destra, visibile solo in modalità gruppo */
.ac-modal-op-check {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
    transition: all .15s;
    color: transparent;
}
.ac-modal-op-item.selezionato .ac-modal-op-check {
    background: var(--ac-brand);
    border-color: var(--ac-brand);
    color: #fff;
}

/* -- Nome gruppo -- */
#ac-modal-gruppo-nome {
    padding: 8px 12px;
    border-top: 1px solid var(--ac-border);
    flex-shrink: 0;
}
#ac-gruppo-nome {
    width: 100%;
    border: 1px solid var(--ac-border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    outline: none;
}
#ac-gruppo-nome:focus { border-color: var(--ac-brand); }

/* -- Footer crea -- */
#ac-modal-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--ac-border);
    flex-shrink: 0;
}
#ac-modal-crea {
    width: 100%;
    background: var(--ac-brand);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
#ac-modal-crea:hover:not(:disabled) { background: var(--ac-brand-dark); }
#ac-modal-crea:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.ac-btn-primary {
    flex: 1;
    background: var(--ac-brand);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 9px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.ac-btn-primary:hover { background: var(--ac-brand-dark); }
.ac-btn-secondary {
    background: #f0f0f0;
    color: #555;
    border: none;
    border-radius: 8px;
    padding: 9px 14px;
    font-size: 13px;
    cursor: pointer;
}


/* -- Pannello info conversazione */
#ac-info-panel {
    position: absolute;
    inset: 0;
    background: #fff;
    z-index: 10;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: var(--ac-radius) var(--ac-radius) 0 0;   /* <-- aggiungi */
}

#ac-info-header {
    background: var(--ac-brand);
    color: #fff;
    height: var(--ac-header-h);
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
    border-radius: var(--ac-radius) var(--ac-radius) 0 0;   /* <-- aggiungi */
}

#ac-info-header button {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
    transition: background .15s;
}
#ac-info-header button:hover { background: rgba(255,255,255,.2); }

#ac-info-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

/* Nome e tipo conversazione */
.ac-info-hero {
    padding: 20px 16px 14px;
    text-align: center;
    border-bottom: 1px solid var(--ac-border);
}
.ac-info-hero-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--ac-brand-light);
    color: var(--ac-brand);
    font-size: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 10px;;
}
.ac-info-hero-nome {
    font-size: 16px;
    font-weight: 700;
    color: #111 !important;
    display: block;
    margin-bottom: 4px;
}
.ac-info-hero-tipo {
    font-size: 12px;
    color: var(--ac-text-muted);
}

/* Sezione partecipanti */
.ac-info-section-title {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--ac-brand);
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 12px 16px 4px;
    display: block;
}
.ac-info-op {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--ac-border);
}
.ac-info-op:last-child { border-bottom: none; }
.ac-info-op-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--ac-brand-light);
    color: var(--ac-brand);
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ac-info-op-nome {
    flex: 1;
    font-size: 13.5px;
    font-weight: 600;
    color: #111 !important;
}
.ac-info-admin {
    font-size: 11px;
    background: var(--ac-brand-light);
    color: var(--ac-brand);
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 600;
}

/* -- Rendi admin */
.ac-info-op-admin {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--ac-brand) !important;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    flex-shrink: 0;
}
.ac-info-op-admin:hover { background: var(--ac-brand-light); }

/* -- Modale "scegli successore" */
#ac-succ-modal {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    border-radius: var(--ac-radius);
}
#ac-succ-box {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 280px;
    max-height: 80%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 28px rgba(0,0,0,.3);
}
#ac-succ-title {
    padding: 14px 16px 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ac-text);
}
#ac-succ-lista { overflow-y: auto; flex: 1; }
.ac-succ-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    cursor: pointer;
    transition: background .12s;
}
.ac-succ-item:hover { background: var(--ac-brand-light); }
.ac-succ-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--ac-brand-light);
    color: var(--ac-brand) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
}
.ac-succ-avatar.ac-avatar-foto { padding: 0; }
.ac-succ-nome { flex: 1; font-size: 13.5px; font-weight: 600; color: #111 !important; }
#ac-succ-cancel {
    margin: 6px 12px 12px;
    background: #f0f0f0;
    color: #555;
    border: none;
    border-radius: 8px;
    padding: 9px;
    font-size: 13px;
    cursor: pointer;
}

/* -- Admin/successore: dark */
@media (prefers-color-scheme: dark) {
    #ac-succ-box    { background: #1e1e1e; }
    #ac-succ-title  { color: #e0e0e0; }
    .ac-succ-item:hover { background: #2a2a2e; }
    .ac-succ-nome   { color: #e0e0e0 !important; }
    #ac-succ-cancel { background: #2a2a2a; color: #ccc; }
}

#ac-info-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--ac-border);
    flex-shrink: 0;
}

/* -- Pin conversazione */
.ac-conv-pin-ind { display: block; font-size: 11px; line-height: 1; margin-bottom: 2px; opacity: .7; }
.ac-conv-fissata { background: #fafbff; }
.ac-conv-fissata:hover { background: #eef3ff; }

#ac-btn-fissa {
    display: block;
    width: calc(100% - 32px);
    margin: 12px 16px 4px;
    background: #fff;
    color: var(--ac-brand) !important;
    border: 1.5px solid var(--ac-brand);
    border-radius: 8px;
    padding: 9px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
#ac-btn-fissa:hover { background: var(--ac-brand); color: #fff !important; }

/* -- Rimuovi partecipante */
.ac-info-op-rm {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--ac-urgente) !important;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    flex-shrink: 0;
}
.ac-info-op-rm:hover { background: #fde8e7; }

/* -- Inoltra: trigger sul fumetto */
.ac-fwd-trigger {
    background: #fff;
    border: 1px solid var(--ac-border);
    color: var(--ac-text-muted);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 13px;
    line-height: 1;
    padding: 0;
    margin: 0 4px 4px;
    cursor: pointer;
    flex-shrink: 0;
    opacity: .35;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0,0,0,.12);
    transition: opacity .15s, background .15s, color .15s;
}
.ac-msg-wrap:hover .ac-fwd-trigger { opacity: 1; }
.ac-fwd-trigger:hover { background: var(--ac-brand-light); color: var(--ac-brand) !important; }

/* -- Inoltra: modale scelta conversazione */
#ac-fwd-modal {
    position: absolute;
    inset: 0;
    background: #fff;
    z-index: 12;
    display: flex;
    flex-direction: column;
    border-radius: var(--ac-radius);
    overflow: hidden;
}
#ac-fwd-header {
    background: var(--ac-brand);
    color: #fff;
    height: var(--ac-header-h);
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
    border-radius: var(--ac-radius) var(--ac-radius) 0 0;
}
#ac-fwd-header button {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
}
#ac-fwd-header button:hover { background: rgba(255,255,255,.2); }
#ac-fwd-search-wrap { padding: 8px 12px; flex-shrink: 0; }
#ac-fwd-search {
    width: 100%;
    border: 1px solid var(--ac-border);
    border-radius: 20px;
    padding: 7px 14px;
    font-size: 13px;
    outline: none;
    background: #f5f5f5;
}
#ac-fwd-search:focus { border-color: var(--ac-brand); background: #fff; }
#ac-fwd-lista { flex: 1; overflow-y: auto; }
#ac-fwd-nota-wrap {
    padding: 8px 12px !important;
    border-top: 1px solid var(--ac-border);
    flex-shrink: 0;
}
#ac-fwd-nota {
    width: 100%;
    border: 1px solid var(--ac-border);
    border-radius: 18px;
    padding: 8px 14px !important;
    font-size: 13px;
    font-family: var(--ac-font);
    resize: none;
    max-height: 80px;
    outline: none;
    background: #f5f5f5;
    line-height: 1.4;
}
#ac-fwd-nota:focus { border-color: var(--ac-brand); background: #fff; }
.ac-fwd-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--ac-border);
    transition: background .12s;
}
.ac-fwd-item:hover { background: #f5f8ff; }
.ac-fwd-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--ac-brand-light);
    color: var(--ac-brand) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
}
.ac-fwd-avatar.ac-avatar-foto { padding: 0; }
.ac-fwd-nome { flex: 1; font-size: 13.5px; font-weight: 600; color: #111 !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-fwd-vuoto { padding: 14px; font-size: 12px; color: var(--ac-text-muted) !important; text-align: center; }

/* -- Inoltra: dark */
@media (prefers-color-scheme: dark) {
    #ac-fwd-modal   { background: #1e1e1e; }
    #ac-fwd-search  { background: #2a2a2a; color: #e0e0e0; border-color: #444; }
    #ac-fwd-search:focus { background: #333; }
    #ac-fwd-nota    { background: #2a2a2a; color: #e0e0e0; border-color: #444; }
    #ac-fwd-nota:focus { background: #333; }
    .ac-fwd-item:hover { background: #2a2a2e; }
    .ac-fwd-nome    { color: #e0e0e0 !important; }
}

/* -- Aggiungi partecipante */
#ac-add-part-wrap { padding: 8px 16px 14px; }
#ac-add-part-btn {
    width: 100%;
    background: #fff;
    color: var(--ac-brand) !important;
    border: 1.5px dashed var(--ac-brand);
    border-radius: 8px;
    padding: 9px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
}
#ac-add-part-btn:hover { background: var(--ac-brand-light); }
#ac-add-part-box { margin-top: 8px; }
#ac-add-part-search {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--ac-border);
    border-radius: 8px;
    font-size: 13px;
    box-sizing: border-box;
}
#ac-add-part-lista { margin-top: 6px; max-height: 180px; overflow-y: auto; }
.ac-add-part-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 4px;
    cursor: pointer;
    border-radius: 8px;
}
.ac-add-part-item:hover { background: var(--ac-brand-light); }
.ac-add-part-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--ac-brand-light);
    color: var(--ac-brand) !important;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ac-add-part-nome { flex: 1; font-size: 13px; font-weight: 600; color: #111 !important; }
.ac-add-part-plus { color: var(--ac-brand) !important; font-size: 18px; font-weight: 700; }
.ac-add-part-vuoto { padding: 8px 4px; font-size: 12px; color: var(--ac-text-muted) !important; }

#ac-btn-abbandona {
    width: 100%;
    background: #fff;
    color: var(--ac-urgente);
    border: 1.5px solid var(--ac-urgente);
    border-radius: 8px;
    padding: 9px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
#ac-btn-abbandona:hover {
    background: var(--ac-urgente);
    color: #fff;
}

/* -- Avatar con foto */
.ac-avatar-foto { padding: 0; overflow: hidden; }
.ac-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 50%;
}

/* -- Foto gruppo modificabile (admin) */
.ac-hero-foto-wrap {
    position: relative;
    width: 60px;
    height: 60px;
    margin: 0 auto 10px;
    cursor: pointer;
}
.ac-hero-foto-wrap .ac-info-hero-avatar { margin: 0; }
.ac-hero-foto-cam {
    position: absolute;
    right: -2px;
    bottom: -2px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--ac-brand);
    color: #fff;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.ac-hero-foto-wrap:hover .ac-hero-foto-cam { background: var(--ac-brand-dark); }

/* -- Avatar mittente (solo gruppi, messaggi in entrata) */
.ac-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--ac-brand-light) !important;
    color: var(--ac-brand) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700 !important;
    flex-shrink: 0;
    align-self: flex-end;            /* allineato al fondo della bolla */
    margin: 0 5px 4px 0 !important;
    overflow: hidden;
}
.ac-msg-avatar.ac-avatar-foto { padding: 0 !important; }

/* La spunta di lettura sui propri messaggi è cliccabile (dettaglio letture) */
.ac-msg-out .ac-msg-letto { cursor: pointer; }

/* -- Tooltip generico (HTML statico o via AJAX) */
/* Appeso al body, FUORI da #ac-widget: niente var(--ac-*), uso valori letterali */
#ac-tooltip {
    position: fixed;
    z-index: 9999;
    max-width: 240px;
    max-height: 260px;
    overflow-y: auto;
    background: #fff;
    color: #111;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
    padding: 8px 10px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 12.5px;
    line-height: 1.4;
}
#ac-tooltip::-webkit-scrollbar { width: 4px; }
#ac-tooltip::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

.ac-tip-title {
    font-size: 11px;
    font-weight: 700;
    color: #1a73e8;
    text-transform: uppercase;
    letter-spacing: .4px;
    margin-bottom: 6px;
}
.ac-tip-empty { color: #888; font-style: italic; }
.ac-tip-load  { color: #888; }
.ac-tip-pre   { white-space: pre-wrap; word-break: break-word; font-size: 11.5px; }

.ac-tip-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
}
.ac-tip-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #e8f0fe;
    color: #1a73e8;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.ac-tip-avatar.ac-avatar-foto { padding: 0; }
.ac-tip-nome { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-tip-ora  { font-size: 11px; color: #888; white-space: nowrap; }

@media (prefers-color-scheme: dark) {
    #ac-tooltip   { background: #2a2a2a; color: #e0e0e0; border-color: #444; }
    .ac-tip-avatar { background: #1e3a5f; color: #9ec5ff; }
}

/* -- Utility */
.ac-hidden { display: none !important; }

/* -- Accessibilità: contenuto solo per screen reader */
.ac-sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* -- Accessibilità: focus visibile da tastiera (non col mouse) */
#ac-widget :focus-visible,
#ac-reaz-popover :focus-visible,
#ac-lightbox :focus-visible,
#ac-tooltip :focus-visible {
    outline: 2px solid transparent;   /* resta visibile in modalità alto contrasto */
    outline-offset: 2px;
    box-shadow: 0 0 0 2px rgba(26, 115, 232, .55),
                0 0 6px 1px rgba(26, 115, 232, .45);
}

/* -- Responsive mobile */
@media (max-width: 480px) {
    #ac-panel {
        width: 100vw;
        height: 72vh;
        bottom: 62px;
        right: 0;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,.15);
    }

    #ac-widget {
        bottom: 12px;
        right: 12px;
    }

    .ac-fumetto { max-width: 85%; }

    /* Su mobile l'icona non si trascina: pannello sempre in basso a destra */
    #ac-widget.ac-pos-sx   #ac-panel,
    #ac-widget.ac-pos-alto #ac-panel {
        left: auto; right: 0;
        top: auto; bottom: 62px;
        transform-origin: bottom right;
    }
}

/* -- Tema scuro (opzionale, rispetta prefers-color-scheme) */
@media (prefers-color-scheme: dark) {
    #ac-widget {
        --ac-fumetto-in:  #2a2a2a;
        --ac-fumetto-out: #1e3a2f;
        --ac-bg-chat:     #1a1a2e;
        --ac-text:        #e0e0e0;
        --ac-text-muted:  #999;
        --ac-border:      #333;
    }
    #ac-panel        { background: #1e1e1e; }
    #ac-input-msg    { background: #2a2a2a; color: #e0e0e0; border-color: #444; }
    #ac-input-area   { background: #252525; }
    #ac-lista-conv   { background: #1e1e1e; }
    .ac-conv-item:hover { background: #2a2a2e; }
    #ac-chat-header  { background: #252535; }
    #ac-urgente-bar  { background: #2a1f00; }
    #ac-paziente-input { background: #2a2a2a; color: #e0e0e0; }
.ac-msg-urgente  { background: #2a1500; }

    /* Conversazioni fissate: era #fafbff -> testo chiaro illeggibile */
    .ac-conv-fissata        { background: #20202c; }
    .ac-conv-fissata:hover  { background: #2a2a3a; }

    /* Pannelli a tutta superficie */
    #ac-modal-nuova,
    #ac-info-panel,
    #ac-info-body { background: #1e1e1e; }

    /* Nomi forzati a #111 nei template */
    .ac-info-hero-nome,
    .ac-info-op-nome,
    .ac-modal-op-nome,
    .ac-add-part-nome { color: #e0e0e0 !important; }
    .ac-modal-op-qual { color: #aaa !important; }

    /* Voci selezionabili */
    .ac-modal-op-item:hover,
    .ac-modal-op-item.ac-modal-op-active,
    .ac-info-op:hover { background: #2a2a2e; }

    /* Campi di testo */
    #ac-op-search,
    #ac-gruppo-nome,
    #ac-add-part-search { background: #2a2a2a; color: #e0e0e0; border-color: #444; }
    #ac-op-search:focus { background: #333; }

    /* Tab e bottoni outline (erano su #fff) */
    .ac-tab,
    #ac-btn-fissa,
    #ac-add-part-btn,
    #ac-btn-abbandona { background: #2a2a2a; }

    /* Autocomplete pazienti */
    #ac-paziente-risultati { background: #2a2a2a; border-color: #444; }
    .ac-paz-item { color: #e0e0e0; }
    .ac-paz-item:hover,
    .ac-paz-item.ac-paz-active { background: #33415a; color: #9ec5ff; }

    /* Badge admin leggibile su scuro */
    .ac-info-admin { background: #1e3a5f; color: #9ec5ff; }


}

