/* Rafa — assistant intégré AHS. Design épuré, palette des applis (encre + vert). */
.rafa-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 9999;
  width: 58px; height: 58px; border-radius: 50%;
  border: none; cursor: pointer;
  background: #2E7D32; color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
  transition: transform .15s ease, box-shadow .15s ease;
}
.rafa-fab:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(0, 0, 0, .34); }
.rafa-fab svg { width: 27px; height: 27px; }

.rafa-panel {
  position: fixed; right: 20px; bottom: 90px; z-index: 9998;
  width: 372px; max-width: calc(100vw - 24px);
  height: 520px; max-height: calc(100vh - 130px);
  display: flex; flex-direction: column;
  background: #fff; border: 1px solid #e6e1d1; border-radius: 18px;
  box-shadow: 0 24px 60px rgba(8, 44, 66, .24);
  overflow: hidden;
  opacity: 0; transform: translateY(14px) scale(.98); pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.rafa-panel.on { opacity: 1; transform: none; pointer-events: auto; }

.rafa-head {
  background: #0A1A20; color: #FFF9E5;
  padding: 14px 16px; display: flex; align-items: center; gap: 11px;
}
.rafa-head .avatar {
  width: 34px; height: 34px; border-radius: 50%; background: #2E7D32;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1rem;
}
.rafa-head .t { font-weight: 700; font-size: 1.02rem; line-height: 1.2; }
.rafa-head .s { font-size: .72rem; color: #C9C2A8; }
.rafa-close {
  margin-left: auto; background: none; border: none; color: #C9C2A8;
  font-size: 1.5rem; cursor: pointer; line-height: 1; padding: 0 2px;
}
.rafa-close:hover { color: #fff; }

.rafa-msgs {
  flex: 1; overflow-y: auto; padding: 14px 14px 8px;
  display: flex; flex-direction: column; gap: 10px; background: #faf8f1;
}
.rafa-msg {
  max-width: 82%; padding: 10px 12px; border-radius: 14px;
  font-size: .9rem; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
}
.rafa-msg.user { align-self: flex-end; background: #0A1A20; color: #FFF9E5; border-bottom-right-radius: 4px; }
.rafa-msg.bot { align-self: flex-start; background: #fff; border: 1px solid #e6e1d1; border-bottom-left-radius: 4px; }
.rafa-msg.typing { color: #8a8573; font-style: italic; border: 1px dashed #d8d3c2; }

.rafa-act { margin: 2px 14px 10px; }
.rafa-act button {
  width: 100%; background: #2E7D32; color: #fff; border: none; border-radius: 10px;
  padding: 12px; font-weight: 700; cursor: pointer; font-size: .92rem;
}

.rafa-input { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid #e6e1d1; background: #fff; }
.rafa-input input {
  flex: 1; border: 1px solid #e6e1d1; border-radius: 10px; padding: 11px 12px;
  font-size: 1rem; outline: none; font-family: inherit;
}
.rafa-input input:focus { border-color: #2E7D32; }
.rafa-input button {
  background: #0A1A20; color: #fff; border: none; border-radius: 10px;
  padding: 0 18px; font-weight: 700; cursor: pointer; font-size: .92rem;
}
.rafa-input button:disabled { opacity: .6; }

/* Pastille de notification sur l'icône Rafa (masquée en mode coupé). */
.rafa-badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: #DC2626; color: #fff; border: 2px solid #fff;
  font-size: .68rem; font-weight: 700; line-height: 16px; text-align: center;
}
.rafa-badge[hidden] { display: none; }
.rafa-fab.relance { animation: rafa-relance .6s ease-in-out 3; }
@keyframes rafa-relance { 0%, 100% { transform: none; } 50% { transform: scale(1.12); } }
@media (prefers-reduced-motion: reduce) { .rafa-fab.relance { animation: none; } }

.rafa-son {
  margin-left: auto; background: none; border: 1px solid rgba(255, 249, 229, .3); color: #C9C2A8;
  width: 32px; height: 32px; border-radius: 9px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.rafa-son svg { width: 17px; height: 17px; }
.rafa-son:hover { color: #fff; }
.rafa-son[aria-pressed="true"] { color: #f2a28f; border-color: rgba(242, 162, 143, .5); }
.rafa-son + .rafa-close { margin-left: 4px; }

.rafa-msg.question { border-color: #2E7D32; border-left-width: 3px; }
.rafa-msg.rappel { background: #FFF9E5; border-color: #e6d9a8; }

/* Boutons de Rafa : « Valider » (action sensible) et raccourcis (rubrique, fiche, appel, lien). */
.rafa-act { display: flex; flex-wrap: wrap; gap: 6px; max-height: 10.5rem; overflow-y: auto; }
.rafa-act[hidden] { display: none; }
.rafa-act .sec {
  width: auto; flex: 1 1 auto; background: #fff; color: #0A1A20; border: 1px solid #cfd8c9; border-radius: 999px;
  padding: 8px 12px; font-size: .82rem; font-weight: 600; cursor: pointer; text-align: center; text-decoration: none;
}
.rafa-act .sec:hover { border-color: #2E7D32; color: #2E7D32; }
.rafa-act button:disabled { opacity: .6; cursor: default; }
.rafa-msg a { color: #2E7D32; font-weight: 600; }
.rafa-msg.user a { color: #FFF9E5; }

/* Demande de position du bureau (point GPS ponctuel). */
.rafa-gps { position: fixed; inset: 0; z-index: 10000; background: rgba(10, 26, 32, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.rafa-gps-box { background: #fff; border-radius: 16px; padding: 18px; max-width: 360px; width: 100%; box-shadow: 0 24px 60px rgba(8, 44, 66, .3); font-size: .92rem; line-height: 1.5; }
.rafa-gps-box p { margin: 8px 0 14px; color: #4a4a40; }
.rafa-gps-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.rafa-gps-btns button { flex: 1; border: 0; border-radius: 10px; padding: 12px; font-weight: 700; cursor: pointer; font-size: .9rem; }
.rafa-gps-btns .ok { background: #2E7D32; color: #fff; }
.rafa-gps-btns .non { background: #f0ede3; color: #0A1A20; }
.rafa-gps-etat { margin-top: 10px; font-size: .84rem; color: #2E7D32; min-height: 1.2em; }

/* Impression d'une fiche (bouton « Imprimer ») : seule la fiche part à l'imprimante. */
.print-fiche { display: none; }
@media print {
  body > *:not(.print-fiche) { display: none !important; }
  body { background: #fff !important; }
  .print-fiche { display: block; color: #0A1A20; font: 11pt/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
  .print-fiche .pf-ent { font-size: 8pt; letter-spacing: .14em; text-transform: uppercase; color: #2E7D32; font-weight: 700; margin: 0; }
  .print-fiche h1 { font-size: 18pt; margin: 4px 0 14px; padding-bottom: 8px; border-bottom: 2px solid #0A1A20; }
  .print-fiche dl { display: grid; grid-template-columns: 34mm 1fr; gap: 6px 12px; margin: 0; }
  .print-fiche dt { font-weight: 700; color: #555; }
  .print-fiche dd { margin: 0; white-space: pre-wrap; }
  .print-fiche .pf-date { margin-top: 18px; font-size: 8pt; color: #777; }
}

@media (max-width: 480px) {
  .rafa-panel { right: 12px; left: 12px; width: auto; bottom: calc(82px + env(safe-area-inset-bottom, 0px)); }
  .rafa-fab { right: 14px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
}
