/* Conversation : une seule zone défilante, une saisie toujours accessible. */
body:has(.page-assistant.visible) {
  padding-bottom: 0;
  overflow: hidden;
}
#appli:has(.page-assistant.visible) {
  position: fixed;
  inset: var(--assistant-top, 0px) 0 auto;
  height: var(--assistant-height, 100dvh);
  min-height: 0;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(var(--h-onglets) + env(safe-area-inset-bottom));
  overflow: hidden;
}
#appli:has(.page-assistant.visible) > .barre {
  flex: none;
}
.page-assistant {
  min-height: 0;
  padding: 14px 0 24px;
  animation: none;
}
.page-assistant.visible {
  display: flex;
}
.assistant-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 1440px;
}
.tete-assistant {
  flex: none;
  align-items: center;
  margin-bottom: 18px;
  gap: 12px;
}
.tete-assistant h1 {
  font-family: var(--sans);
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -0.04em;
}
.tete-assistant .aide {
  margin-top: 3px;
  font-size: 13px;
}
.tete-assistant .tete-outils .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: 12px;
}
.tete-assistant .tete-outils svg {
  width: 19px;
  height: 19px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chat-layout {
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
  gap: 20px;
  flex: 1;
  min-height: 0;
}
.conversations {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 10px;
  border: 1px solid var(--trait);
  border-radius: 20px;
}
.conversations-tete {
  padding: 0 10px 14px;
}
.liste-conversations {
  display: grid;
  gap: 6px;
  overflow-y: auto;
  min-height: 0;
  align-content: start;
}
.liste-conversations > .aide-champ {
  padding: 0 10px;
}
.conversation-ligne {
  position: relative;
}
.conversation {
  width: 100%;
  min-height: 64px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 44px 11px 12px;
  cursor: pointer;
  display: grid;
  gap: 4px;
}
.conversation:hover {
  background: var(--carte);
}
.conversation.active {
  background: var(--pin-pale);
  border-color: var(--trait);
}
.conversation .titre {
  font-weight: 500;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation .meta {
  font-size: 11px;
  color: var(--gris);
}
.conversation-ligne .supprimer {
  position: absolute;
  top: 10px;
  right: 2px;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--gris);
  font-size: 20px;
  cursor: pointer;
}
.conversation-ligne .supprimer:hover {
  color: var(--ambre);
  background: var(--carte);
}
#voile-conversations .liste-conversations {
  max-height: 50dvh;
}
#btn-conversations {
  display: none;
}
.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--carte);
  border: 1px solid var(--trait);
  border-radius: 22px;
  overflow: hidden;
}
.chat-entete {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 24px;
}
.chat-entete-icone,
.chat-vide-icone,
.chat-auteur-icone {
  display: grid;
  place-items: center;
  background: var(--pin-pale);
  color: var(--pin);
}
.chat-entete-icone {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  flex: none;
}
.chat-entete-texte {
  display: grid;
  min-width: 0;
  line-height: 1.4;
}
.chat-entete-texte strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
}
.chat-entete-texte span {
  color: var(--gris);
  font-size: 11px;
}
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 20px max(28px, calc((100% - 760px) / 2)) 32px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--trait-fort) transparent;
  scroll-padding: 24px;
}
.bulle-msg {
  flex: none;
  min-width: 0;
  font-size: 15px;
  line-height: 1.75;
  overflow-wrap: anywhere;
}
.bulle-msg.user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--pin-pale);
  color: var(--encre);
  padding: 10px 18px;
  border-radius: 20px 20px 6px 20px;
  white-space: pre-wrap;
}
.bulle-msg.assistant {
  align-self: stretch;
}
.chat-auteur {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 600;
}
.chat-auteur-icone {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 15px;
}
.bulle-msg .contenu > :first-child {
  margin-top: 0;
}
.bulle-msg .contenu > :last-child {
  margin-bottom: 0;
}
.bulle-msg p {
  margin: 0 0 12px;
}
.bulle-msg ul,
.bulle-msg ol {
  margin: 0 0 14px;
  padding-left: 22px;
}
.bulle-msg li {
  margin: 6px 0;
}
.bulle-msg h4 {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  margin: 16px 0 8px;
}
.bulle-msg code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--canvas);
  border-radius: 4px;
  padding: 2px 5px;
}
.bulle-msg.attente {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
}
.bulle-msg.attente span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pin);
  animation: pulse 1.1s infinite ease-in-out;
}
.bulle-msg.attente span:nth-child(2) {
  animation-delay: 0.15s;
}
.bulle-msg.attente span:nth-child(3) {
  animation-delay: 0.3s;
}
.bulle-msg.attente small {
  margin-left: 6px;
  font-size: 12px;
  color: var(--gris);
}
@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.3;
  }
  40% {
    opacity: 1;
  }
}
.chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}
.puce.action {
  background: var(--pin-pale);
  color: var(--pin);
  white-space: normal;
}
.chat-vide {
  flex: none;
  margin: auto 0;
  width: 100%;
  padding: 20px 0;
  text-align: center;
}
.chat-vide-icone {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  font-size: 29px;
  margin: 0 auto 20px;
}
.chat-vide h2 {
  font-size: clamp(26px, 3vw, 34px);
  margin-bottom: 12px;
}
.chat-vide p {
  color: var(--gris);
  font-size: 14px;
  margin-bottom: 28px;
}
.chat-suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.suggestion {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--carte);
  border: 1px solid var(--trait-fort);
  border-radius: 14px;
  color: var(--encre);
  text-align: left;
  cursor: pointer;
  line-height: 1.4;
  transition:
    background var(--t),
    border-color var(--t);
}
.suggestion:hover {
  border-color: var(--pin);
  background: var(--pin-pale);
}
.suggestion > svg {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: var(--pin);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.suggestion strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
}
.suggestion small {
  display: block;
  font-size: 12px;
  color: var(--gris);
  margin-top: 3px;
}
.chat-composer-zone {
  flex: none;
  padding: 12px 28px 18px;
  background: var(--carte);
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 10px 8px 16px;
  border: 1px solid var(--trait-fort);
  border-radius: 20px;
  background: var(--canvas);
  box-shadow: var(--ombre);
}
.composer:focus-within {
  border-color: var(--pin);
  box-shadow: 0 0 0 3px var(--anneau);
}
.composer textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--encre);
  padding: 11px 0;
  min-height: 44px;
  max-height: min(160px, 24dvh);
  resize: none;
  font-size: 16px;
  line-height: 1.4;
}
.composer textarea:focus {
  outline: none;
  box-shadow: none;
}
.composer .btn.icone {
  flex: none;
  width: 44px;
  height: 44px;
  min-height: 44px;
  border-radius: 14px;
}
.composer .btn.icone:disabled {
  cursor: default;
  opacity: 0.4;
}
.composer .btn.icone svg {
  width: 22px;
  height: 22px;
}
.chat-aide {
  margin: 10px auto 0;
  color: var(--gris);
  font-size: 11px;
  text-align: center;
  line-height: 1.5;
}

/* Réglages IA (administration) */
.champ-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  cursor: pointer;
}
.champ-inline input {
  width: 20px;
  height: 20px;
  accent-color: var(--pin);
}
.aide-champ {
  font-size: 12.5px;
  color: var(--gris);
  margin-top: 6px;
}
.etat-ia {
  font-size: 13.5px;
  color: var(--gris);
  border-top: 1px solid var(--trait);
  padding-top: 12px;
}
.etat-ia.ok {
  color: var(--vert);
}
.etat-ia.erreur {
  color: var(--ambre);
}

/* Idées de recettes */
.idees {
  display: grid;
  gap: 10px;
  max-height: 50vh;
  overflow: auto;
  margin-top: 8px;
}
.idee {
  background: var(--canvas);
  border: 1px solid var(--trait);
  border-radius: var(--r-m);
  padding: 14px 16px;
  display: grid;
  gap: 6px;
}
.idee .nom {
  font-family: var(--serif);
  font-size: 19px;
}
.idee .desc {
  color: var(--gris);
  font-size: 13.5px;
}
.idee .puces {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.idee .actions {
  margin-top: 6px;
  justify-content: flex-start;
}

/* Bilan d'équilibre */
.bilan-tete {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}
.score {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 26px;
  color: var(--sur-pin);
  background: var(--pin);
  flex: none;
}
.score.moyen {
  background: var(--ambre);
}
.score.bon {
  background: var(--vert);
}
.bilan-tete p {
  font-size: 14.5px;
}
.bilan-section {
  margin-top: 14px;
}
.bilan-section .titre {
  font-size: 11.5px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--gris-clair);
  margin-bottom: 6px;
}
.bilan-section ul {
  margin: 0;
  padding-left: 18px;
  font-size: 14px;
}
.bilan-section li {
  margin: 3px 0;
}
.bilan-section li b {
  font-weight: 600;
}

@media (max-width: 1000px) {
  .chat-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .conversations {
    display: none;
  }
  #btn-conversations {
    display: inline-flex;
  }
}
@media (max-width: 900px) {
  #appli:has(.page-assistant.visible) {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }
  #appli.assistant-clavier:has(.page-assistant.visible) {
    padding-bottom: 0;
  }
  #appli.assistant-clavier:has(.page-assistant.visible) .onglets-bas {
    display: none;
  }
}
@media (max-width: 620px) {
  .page-assistant {
    padding: 0 0 12px;
  }
  .assistant-wrap {
    padding: 0 12px;
  }
  .tete-assistant {
    min-height: 58px;
    margin: 0 2px 8px;
    flex-wrap: nowrap;
  }
  .tete-assistant h1 {
    font-size: 21px;
  }
  .tete-assistant .aide {
    display: none;
  }
  .tete-assistant .tete-outils {
    width: auto;
    gap: 6px;
    flex-wrap: nowrap;
  }
  .tete-assistant .tete-outils .btn {
    width: 44px;
    height: 44px;
    padding: 0;
  }
  .tete-assistant .tete-outils .btn span {
    display: none;
  }
  .chat {
    border: 0;
    background: transparent;
    border-radius: 0;
  }
  .chat-entete {
    display: none;
  }
  .chat-messages {
    padding: 14px 6px 24px;
    gap: 24px;
  }
  .bulle-msg {
    font-size: 15px;
    line-height: 1.7;
  }
  .bulle-msg.user {
    max-width: 88%;
    padding: 9px 15px;
  }
  .chat-auteur {
    margin-bottom: 10px;
  }
  .chat-vide {
    padding: 12px 0;
  }
  .chat-vide-icone {
    width: 44px;
    height: 44px;
    font-size: 25px;
    margin-bottom: 16px;
  }
  .chat-vide h2 {
    font-size: 27px;
  }
  .chat-vide p {
    font-size: 13px;
    margin-bottom: 20px;
  }
  .chat-suggestions {
    gap: 8px;
  }
  .suggestion {
    padding: 12px;
    gap: 8px;
    flex-direction: column;
    align-items: flex-start;
  }
  .suggestion small {
    display: none;
  }
  .suggestion strong {
    font-size: 12px;
  }
  .chat-composer-zone {
    padding: 10px 2px 0;
    background: transparent;
  }
  .composer {
    padding: 7px 8px 7px 14px;
    gap: 6px;
    background: var(--carte);
    border-radius: 20px;
  }
  .composer textarea {
    padding: 11px 0;
  }
  .chat-aide {
    font-size: 10px;
    margin-top: 8px;
  }
  .assistant-clavier .chat-aide {
    display: none;
  }
  .assistant-clavier .page-assistant {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
}
@media (prefers-reduced-motion: reduce) {
  .bulle-msg.attente span {
    animation: none;
  }
}
