/* ===== SAM, assistant virtuel ===== */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.sam {
  position: fixed; left: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); z-index: 70;
  font-family: var(--f-texte); color: var(--texte);
}
.sam button { font: inherit; cursor: pointer; }
.sam svg { width: 20px; height: 20px; fill: currentColor; display: block; }
.sam-cache { display: none; }
.sam [hidden] { display: none !important; }

/* --- Ordinateur / tablette --- */
.sam-bureau { display: flex; align-items: flex-end; gap: 8px; }
.sam-mobile { display: none; }
.sam-perso { position: relative; padding: 0; border: 0; background: none; border-radius: 50%; line-height: 0; }
.sam-perso:focus-visible { outline: 3px solid var(--rouge); outline-offset: 4px; }
.sam-corps { display: none; height: 250px; width: auto; filter: drop-shadow(0 8px 14px rgba(0,0,0,.28)); }
.sam-tete {
  width: 74px; height: 74px; border-radius: 50%; object-fit: cover; background: #e9e4e1;
  border: 3px solid var(--blanc); box-shadow: 0 0 0 3px var(--rouge), 0 10px 24px rgba(0,0,0,.3);
  transition: transform .2s;
}
.sam-perso:hover .sam-tete { transform: scale(1.05); }
/* Grand écran : SAM en pied, dans la marge, sans toucher au texte */
@media (min-width: 1500px) {
  .sam-corps { display: block; }
  .sam-tete { display: none; }
  .sam-perso { border-radius: 8px; }
}
/* Pendant la lecture, barre réduite (pause, stop, vitesse) sauf si on ouvre le menu */
.sam[data-etat="lecture"]:not(.sam-ouvert) .sam-outils [data-act="son"],
.sam[data-etat="lecture"]:not(.sam-ouvert) .sam-outils [data-act="question"],
.sam[data-etat="lecture"]:not(.sam-ouvert) .sam-outils [data-act="masquer"],
.sam[data-etat="lecture"]:not(.sam-ouvert) .sam-outils [data-act="reglages"] { display: none; }

/* Barre de commandes verticale */
.sam-outils {
  display: flex; flex-direction: row; gap: 4px; padding: 5px; border-radius: 26px; align-self: center;
  background: var(--noir); box-shadow: 0 8px 22px rgba(0,0,0,.3);
  opacity: 0; visibility: hidden; transform: translateX(-8px); transition: opacity .2s, transform .2s, visibility .2s;
}
.sam-outils button {
  width: 38px; height: 38px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: transparent; color: var(--blanc);
}
.sam-outils button:hover, .sam-outils button:focus-visible { background: var(--rouge); outline: none; }
.sam-outils button.actif { background: var(--rouge); }
.sam-outils button[aria-pressed="true"] { color: #ff8a8d; }
.sam-vitesse { font-family: var(--f-titre) !important; font-weight: 800; font-size: .95rem !important; letter-spacing: .02em; }
.sam-ouvert .sam-outils,
.sam[data-etat="lecture"] .sam-outils, .sam[data-etat="pause"] .sam-outils,
.sam-bureau:focus-within .sam-outils { opacity: 1; visibility: visible; transform: none; }
@media (hover: hover) { .sam-bureau:hover .sam-outils { opacity: 1; visibility: visible; transform: none; } }

/* SAM parle : anneau qui pulse + petites ondes */
.sam-onde { position: absolute; top: -4px; right: -6px; display: none; gap: 2px; align-items: flex-end; height: 18px;
  padding: 3px 5px; border-radius: 10px; background: var(--rouge); }
.sam-onde i { width: 3px; background: var(--blanc); border-radius: 2px; height: 40%; animation: sam-onde 1s ease-in-out infinite; }
.sam-onde i:nth-child(2) { animation-delay: .2s; } .sam-onde i:nth-child(3) { animation-delay: .4s; }
@media (min-width: 1500px) { .sam-outils { flex-direction: column; align-self: flex-end; } }
@media (min-width: 1500px) { .sam-onde { top: 6px; right: 0; } }
.sam-parle .sam-onde { display: flex; }
.sam-parle .sam-tete { animation: sam-pouls 1.4s ease-in-out infinite; }
@keyframes sam-onde { 0%,100% { height: 30%; } 50% { height: 100%; } }
@keyframes sam-pouls { 0%,100% { box-shadow: 0 0 0 3px var(--rouge), 0 10px 24px rgba(0,0,0,.3); } 50% { box-shadow: 0 0 0 7px rgba(215,25,31,.45), 0 10px 24px rgba(0,0,0,.3); } }

/* Bulle d'invitation */
.sam-invite {
  position: absolute; left: 0; bottom: calc(100% + 12px); display: flex; align-items: center;
  background: var(--blanc); border: 2px solid var(--rouge); border-radius: 18px 18px 18px 4px;
  box-shadow: 0 10px 26px rgba(0,0,0,.22); white-space: nowrap; animation: sam-apparait .35s ease-out both;
}
.sam-invite[hidden] { display: none; }
.sam-invite-txt { border: 0; background: none; padding: .6rem .4rem .6rem .95rem; font-weight: 600; color: var(--texte); }
.sam-invite-txt:hover { color: var(--rouge); }
.sam-invite-x { border: 0; background: none; padding: .5rem .55rem .5rem .2rem; color: var(--texte-doux); }
.sam-invite-x svg { width: 16px; height: 16px; }
@keyframes sam-apparait { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Bouton pour faire réapparaître SAM */
.sam-rappel {
  position: fixed; left: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); z-index: 70;
  display: flex; align-items: center; gap: .4rem; padding: 3px .8rem 3px 3px; border: 0; border-radius: 30px;
  background: var(--noir); color: var(--blanc); font-family: var(--f-titre); font-weight: 800; letter-spacing: .06em;
  box-shadow: 0 6px 18px rgba(0,0,0,.3); cursor: pointer; opacity: .85;
}
.sam-rappel:hover, .sam-rappel:focus-visible { opacity: 1; background: var(--rouge); outline: none; }
.sam-rappel img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.sam-rappel[hidden] { display: none; }

/* Texte en cours de lecture */
.sam-lu { outline: 3px solid var(--rouge); outline-offset: 5px; border-radius: 3px; background-color: rgba(215,25,31,.07); scroll-margin: 120px; transition: outline-color .2s; }

/* --- Panneau de questions --- */
.sam-panneau {
  position: fixed; left: 14px; bottom: calc(102px + env(safe-area-inset-bottom, 0px)); z-index: 75;
  width: min(390px, calc(100vw - 28px)); max-height: min(600px, calc(100vh - 190px));
  display: flex; flex-direction: column; background: var(--blanc); border-top: 4px solid var(--rouge);
  box-shadow: 0 18px 50px rgba(0,0,0,.35); border-radius: 6px; overflow: hidden; animation: sam-apparait .25s ease-out both;
}
.sam-panneau[hidden] { display: none; }
@media (min-width: 1500px) { .sam-panneau { left: 190px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); max-height: min(600px, calc(100vh - 110px)); } }
.sam-p-tete { display: flex; align-items: center; gap: .7rem; padding: .7rem .7rem .7rem .9rem; background: var(--noir); color: var(--blanc); }
.sam-p-tete img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; border: 2px solid var(--rouge); }
.sam-p-tete div { flex: 1; min-width: 0; line-height: 1.15; }
.sam-p-tete strong { display: block; font-family: var(--f-titre); font-size: 1.35rem; letter-spacing: .05em; }
.sam-p-tete span { font-size: .8rem; color: var(--texte-inverse-doux); }
.sam-p-tete button { width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; color: var(--blanc); display: grid; place-items: center; }
.sam-p-tete button:hover, .sam-p-tete button:focus-visible { background: var(--rouge); outline: none; }
.sam-fil { flex: 1; overflow-y: auto; padding: 1rem .9rem .5rem; display: flex; flex-direction: column; gap: .6rem; background: var(--gris-clair); overscroll-behavior: contain; }
.sam-msg { max-width: 88%; padding: .6rem .8rem; border-radius: 14px; font-size: .95rem; line-height: 1.45; }
.sam-msg-sam { align-self: flex-start; background: var(--blanc); border: 1px solid var(--gris-ligne); border-bottom-left-radius: 4px; }
.sam-msg-vous { align-self: flex-end; background: var(--noir); color: var(--blanc); border-bottom-right-radius: 4px; }
.sam-choix { display: flex; flex-wrap: wrap; gap: .4rem; }
.sam-questions { flex-direction: column; align-items: flex-start; }
.sam-puce {
  border: 1.5px solid var(--noir); background: var(--blanc); color: var(--texte); border-radius: 18px;
  padding: .4rem .8rem; font-size: .88rem !important; text-align: left; line-height: 1.3;
}
.sam-puce:hover, .sam-puce:focus-visible { background: var(--noir); color: var(--blanc); outline: none; }
.sam-lien {
  display: inline-block; background: var(--rouge); color: var(--blanc); text-decoration: none; font-weight: 600;
  padding: .45rem .9rem; border-radius: 18px; font-size: .88rem;
}
.sam-lien:hover, .sam-lien:focus-visible { background: var(--rouge-fonce); color: var(--blanc); outline: 2px solid var(--noir); outline-offset: 2px; }
.sam-sous { font-size: .8rem; color: var(--texte-doux); margin: .2rem 0 -.2rem; }
.sam-aide { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-size: .82rem; color: var(--texte-doux); }
.sam-aide span { width: 100%; }
.sam-aide .sam-puce { padding: .25rem .7rem; font-size: .8rem !important; border-width: 1px; }
.sam-form { display: flex; gap: .4rem; padding: .6rem; border-top: 1px solid var(--gris-ligne); background: var(--blanc); }
.sam-form input { flex: 1; min-width: 0; border: 1.5px solid var(--gris-ligne); border-radius: 22px; padding: .55rem .9rem; font: inherit; font-size: 16px; }
.sam-form input:focus { outline: none; border-color: var(--noir); }
.sam-form button { flex: none; width: 42px; height: 42px; border: 0; border-radius: 50%; display: grid; place-items: center; background: var(--noir); color: var(--blanc); }
.sam-form button:hover, .sam-form button:focus-visible { background: var(--rouge); outline: none; }
.sam-micro.actif { background: var(--rouge); animation: sam-pouls 1.2s infinite; }
.sam-mention { font-size: .72rem; color: var(--texte-doux); padding: 0 .9rem .6rem; background: var(--blanc); margin: 0; }

/* --- Téléphone : bouton d'écoute + bulle --- */
@media (max-width: 767px) {
  .sam-cache { display: block; }
  .sam-rappel { display: none !important; }
  .sam-bureau { display: none; }
  .sam-mobile { display: flex; align-items: center; gap: 8px; }
  .sam-m-lire, .sam-m-vitesse {
    height: 44px; border: 0; border-radius: 22px; background: var(--noir); color: var(--blanc);
    display: flex; align-items: center; gap: .35rem; padding: 0 .95rem 0 .75rem; font-weight: 600; font-size: .9rem;
    box-shadow: 0 6px 18px rgba(0,0,0,.3);
  }
  .sam-m-vitesse { padding: 0 .8rem; }
  .sam-m-vitesse[hidden] { display: none; }
  .sam-m-lire.actif { background: var(--rouge); }
  .sam-m-question { order: -1; width: 56px; height: 56px; padding: 0; border: 3px solid var(--blanc); border-radius: 50%; overflow: hidden;
    box-shadow: 0 0 0 3px var(--rouge), 0 8px 20px rgba(0,0,0,.3); background: #e9e4e1; position: relative; }
  .sam-m-question img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .sam-parle .sam-m-question { animation: sam-pouls 1.4s ease-in-out infinite; }
  .sam-invite { bottom: calc(100% + 10px); }
  .sam-panneau { left: 8px; right: 8px; width: auto; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); max-height: calc(100vh - 170px); max-height: calc(100dvh - 170px); }
}

@media (prefers-reduced-motion: reduce) {
  .sam *, .sam-lu { animation: none !important; transition: none !important; }
}
@media print { .sam, .sam-rappel { display: none !important; } .sam-lu { outline: 0; background: none; } }

/* Réglages : choix de la voix */
.sam-reglages {
  position: fixed; left: 14px; bottom: calc(102px + env(safe-area-inset-bottom, 0px)); z-index: 76;
  width: min(390px, calc(100vw - 28px)); max-height: min(560px, calc(100vh - 190px));
  display: flex; flex-direction: column; background: var(--blanc); border-top: 4px solid var(--rouge);
  box-shadow: 0 18px 50px rgba(0,0,0,.35); border-radius: 6px; overflow: hidden; animation: sam-apparait .25s ease-out both;
}
.sam-reglages[hidden] { display: none; }
@media (min-width: 1500px) { .sam-reglages { left: 190px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); } }
.sam-r-corps { overflow-y: auto; padding: 1rem .9rem 1.1rem; display: grid; gap: .8rem; background: var(--gris-clair); }
.sam-r-aide, .sam-r-note, .sam-r-vitesse { font-size: .86rem; color: var(--texte-doux); margin: 0; line-height: 1.4; }
.sam-r-liste { display: grid; gap: .45rem; }
.sam-r-voix { display: grid; grid-template-columns: auto 1fr auto; gap: .6rem; align-items: center; background: var(--blanc); border: 1.5px solid var(--gris-ligne); border-radius: 10px; padding: .55rem .6rem; }
.sam-r-voix:has(input:checked) { border-color: var(--rouge); }
.sam-r-voix input { accent-color: var(--rouge); width: 18px; height: 18px; margin: 0; }
.sam-r-voix label { display: grid; gap: .1rem; cursor: pointer; font-size: .92rem; }
.sam-r-voix small { color: var(--texte-doux); font-size: .78rem; }
.sam-r-test { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--noir); color: var(--blanc); display: grid; place-items: center; }
.sam-r-test:hover, .sam-r-test:focus-visible { background: var(--rouge); outline: none; }
.sam-r-test svg { width: 18px; height: 18px; }
.sam-m-reglages { display: none; }
@media (max-width: 767px) {
  .sam-m-reglages { display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--noir); color: var(--blanc); box-shadow: 0 6px 18px rgba(0,0,0,.3); order: -1; }
  .sam-m-reglages svg { width: 19px; height: 19px; }
  .sam-m-question { order: -2; }
  .sam-reglages { left: 8px; right: 8px; width: auto; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); max-height: calc(100dvh - 170px); }
}
.sam-r-vide { margin: 0; padding: .8rem .9rem; background: var(--blanc); border-left: 4px solid var(--rouge); font-size: .9rem; line-height: 1.45; }
