/* Choix du modèle d'IA dans la zone de saisie : pastille + menu ancré au-dessus.
   Complète app.css (mêmes jetons de couleur) ; chargé après lui. */

#model-picker { position: relative; flex: none; display: flex; align-items: center; }

.model-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 40px; padding: 0 10px;
  background: transparent; border: 1px solid var(--line-strong);
  color: var(--sand); font-size: 12px; line-height: 1; cursor: pointer;
  max-width: 240px; white-space: nowrap;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.model-pill .mp-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-pill .ico { flex: none; opacity: .75; }
.model-pill:hover { color: var(--ivory); background: rgba(246,242,234,.06); border-color: rgba(59,217,219,.45); }
.model-pill:focus-visible { outline: 1px solid var(--turq); outline-offset: 1px; }
.model-pill.disabled { opacity: .5; }
.model-pill[aria-expanded="true"] { color: var(--ivory); border-color: rgba(59,217,219,.6); }

.model-menu {
  position: absolute; left: 0; bottom: calc(100% + 8px);
  width: 320px; max-height: 360px; overflow: auto;
  background: #131D40; border: 1px solid var(--line-strong);
  box-shadow: 0 18px 40px rgba(15,23,51,.55);
  z-index: 30; animation: mnFade .12s ease;
}

.mm-search { position: sticky; top: 0; background: #131D40; padding: 8px; border-bottom: 1px solid var(--line); }
.mm-search input {
  width: 100%; padding: 8px 10px; font-size: 13px;
  background: rgba(246,242,234,.05); border: 1px solid var(--line-strong);
  color: var(--ivory); outline: none;
}
.mm-search input:focus { border-color: rgba(59,217,219,.6); }
.mm-search input::placeholder { color: var(--mute); }

.mm-body { padding: 4px 0; }
.mm-group + .mm-group { border-top: 1px solid var(--line); }
.mm-head { padding: 10px 10px 6px; font-size: 10px; letter-spacing: .18em; text-transform: uppercase; font-weight: 700; color: var(--mute); }

.model-opt {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; text-align: left;
  background: transparent; border: 0; color: var(--ivory); font-size: 13px; cursor: pointer;
}
.model-opt:hover { background: rgba(246,242,234,.06); }
.model-opt .mo-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-opt .mo-check { flex: none; width: 14px; height: 14px; display: grid; place-items: center; }
.model-opt.current { color: var(--turq); }
.model-opt .mo-prov { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--mute); }
.model-opt.is-off .mo-name { color: var(--mute); }
.model-pill .mp-prov { flex: none; font-size: 11px; color: var(--mute); white-space: nowrap; }
.model-pill .mp-prov:empty { display: none; }

.mm-chip { flex: none; padding: 2px 6px; font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--mute); border: 1px solid var(--line-strong); }

.model-empty { padding: 14px 12px; font-size: 12px; color: var(--mute); line-height: 1.5; }
.mm-foot { position: sticky; bottom: 0; background: #131D40; padding: 8px 10px;
  border-top: 1px solid var(--line); font-size: 11px; color: var(--mute); }

@media (max-width: 1100px) {
  /* Ancré à droite de la pastille : le menu ne peut pas déborder du bord de l'écran. */
  .model-menu { left: auto; right: 0; width: min(320px, calc(100vw - 32px)); }
}
@media (max-width: 860px) {
  .model-pill { max-width: 200px; padding: 0 8px; }
  .model-opt { min-height: 40px; padding: 9px 10px; }
  .mm-search input { min-height: 38px; }
}

@media (max-width: 560px) {
  /* Téléphone : la pastille est dans la rangée d'outils, trop à gauche pour ancrer un menu de 320 px.
     On se cale alors sur la zone de saisie elle-même (#model-picker passe en position statique). */
  #model-picker { position: static; flex: 0 1 auto; min-width: 0; }
  .model-pill { max-width: 200px; }
  .model-menu { left: 0; right: 0; width: auto; max-height: min(360px, 50dvh); }
}

/* ── Choix de l'agent (en-tête de la conversation) ───────────────────────── */

#agent-picker { position: relative; flex: none; display: flex; align-items: center; }

.agent-pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 10px 0 6px; max-width: 220px;
  background: transparent; border: 1px solid var(--line-strong);
  color: var(--ivory); font-size: 13px; font-weight: 600; line-height: 1; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.agent-pill .ap-face { display: flex; flex: none; }
.agent-pill .ap-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-pill .ico { flex: none; opacity: .75; }
.agent-pill:hover { background: rgba(246,242,234,.06); border-color: rgba(59,217,219,.45); }
.agent-pill:focus-visible { outline: 1px solid var(--turq); outline-offset: 1px; }
.agent-pill[aria-expanded="true"] { border-color: rgba(59,217,219,.6); }

/* Menu « choisir un agent » (conversation ET Accueil : une seule règle). Position, hauteur et décalage viennent de
   js/chat/agent-menu.js (variables --am-* posées sur <html>) : sous la pastille à 8 px, jamais plus haut ni plus bas que la
   fenêtre (marge 14 px), il défile à l'intérieur quand la liste est plus longue que la place. Sans elles : sous la pastille. */
.agent-menu {
  position: absolute; right: 0; top: var(--am-top, calc(100% + 8px)); bottom: var(--am-bottom, auto);
  translate: var(--am-dx, 0px) 0;
  width: 320px; max-width: calc(100vw - 28px); max-height: var(--am-max, min(60vh, 420px));
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth;
  background: #131D40; --av-ring: #131D40; border: 1px solid var(--line-strong);
  box-shadow: 0 18px 40px rgba(15,23,51,.55); z-index: 30; animation: mnFade .12s ease;
}
/* Barre de défilement discrète, qui s'arrête avant les coins arrondis. */
.agent-menu::-webkit-scrollbar-track-piece:start { margin-top: 8px; }
.agent-menu::-webkit-scrollbar-track-piece:end { margin-bottom: 8px; }
@supports not selector(::-webkit-scrollbar) { .agent-menu { scrollbar-width: thin; scrollbar-color: rgba(246,242,234,.2) transparent; } }
@media (prefers-reduced-motion: reduce) { .agent-menu { animation: none; scroll-behavior: auto; } }
.agent-opt {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 8px 10px;
  background: transparent; border: 0; border-left: 3px solid transparent;
  color: var(--ivory); font: inherit; text-align: left; cursor: pointer;
}
.agent-opt:hover { background: rgba(246,242,234,.06); }
.agent-opt:focus-visible { outline: none; background: rgba(246,242,234,.06); box-shadow: inset 0 0 0 2px var(--turq); }
.agent-opt.current { border-left-color: var(--turq); background: rgba(59,217,219,.07); }
.agent-opt .ao-text { flex: 1; min-width: 0; }
.agent-opt .ao-name { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-opt .ao-role { display: block; font-size: 12px; color: var(--mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-opt .ao-state { flex: none; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--turq); }
.agent-opt .ao-state.busy { color: var(--ochre-light); }
.agent-opt .ao-state.off { color: var(--mute); }
.agent-opt .ico { flex: none; color: var(--turq); }
.ao-foot { position: sticky; bottom: 0; background: #131D40; padding: 8px 10px;
  border-top: 1px solid var(--line); font-size: 11px; color: var(--mute); }

@media (max-width: 860px) {
  /* Place comptée dans l'en-tête : l'avatar suffit à identifier l'agent. */
  .agent-pill { max-width: none; padding: 0 6px; gap: 4px; }
  .agent-pill .ap-label { display: none; }
  .agent-menu { width: min(320px, calc(100vw - 32px)); }
}

/* ── Règle d'accord (bouclier de la zone de saisie) ──────────────────────── */

#rule-picker { position: relative; flex: none; display: flex; align-items: center; gap: 6px; }
.rule-btn.is-ask { color: var(--turq); }
.rule-btn.is-alone { color: var(--ochre-light); background: transparent; }
.rule-btn[aria-expanded="true"] { color: var(--ivory); background: rgba(246,242,234,.06); }
.rule-btn.is-alone[aria-expanded="true"] { color: var(--ochre-light); }

.rule-backdrop { display: none; }
.rule-menu {
  position: absolute; left: 0; bottom: calc(100% + 8px); width: 380px; max-width: calc(100vw - 32px);
  background: #131D40; border: 1px solid var(--line-strong); box-shadow: 0 18px 40px rgba(15,23,51,.55);
  z-index: 30; animation: mnFade .12s ease; padding-bottom: 4px;
}
.rule-grab { display: none; }
.rule-title { padding: 12px 14px 6px; font-size: 13px; font-weight: 700; color: var(--ivory); }
.rule-opt { display: grid; grid-template-columns: 24px minmax(0, 1fr) 20px; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 14px;
  background: transparent; border: 0; color: var(--ivory); text-align: left; cursor: pointer; font: inherit; }
.rule-opt:hover, .rule-opt:focus-visible { background: rgba(246,242,234,.06); outline: none; }
.rule-opt:focus-visible { box-shadow: inset 0 0 0 2px rgba(59,217,219,.6); }
.ro-txt { display: grid; gap: 2px; min-width: 0; }
.ro-name { font-size: 14px; font-weight: 600; }
.ro-sub { font-size: 12px; line-height: 1.4; color: var(--mute); }
.ro-ico { display: grid; place-items: center; color: var(--mute); }
.ro-check { display: grid; place-items: center; color: var(--turq); }
.rule-opt.tone-alone .ro-name, .rule-opt.tone-alone .ro-ico { color: var(--ochre-light); }
.rule-opt.is-over { opacity: .55; cursor: not-allowed; }
.rule-note { padding: 6px 14px; font-size: 12px; color: var(--ochre-light); }
.rule-foot { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; padding: 8px 14px 6px; border-top: 1px solid var(--line); font-size: 12px; color: var(--mute); }
.rule-more-btn { background: none; border: 0; padding: 4px 0; color: var(--turq); font: inherit; font-size: 12px; text-decoration: underline; cursor: pointer; min-height: 28px; }
.rule-more { margin: 0; padding: 0 14px 10px; font-size: 12px; line-height: 1.5; color: var(--mute); }

@media (max-width: 700px) {
  /* Téléphone : feuille du bas, pleine largeur, qu'on peut faire glisser vers le bas. */
  .rule-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); animation: mnFade .15s ease; }
  .rule-menu { position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-width: none; max-height: 85dvh; overflow: auto; z-index: 41;
    padding-bottom: env(safe-area-inset-bottom, 0px); animation: ruleUp .2s ease; border-width: 1px 0 0; }
  .rule-grab { display: flex; justify-content: center; padding: 8px 0 0; touch-action: none; }
  .rule-grab span { width: 36px; height: 4px; background: var(--line-strong); }
  .rule-opt { min-height: 64px; }
  .rule-btn { width: 44px; height: 44px; }
}
@keyframes ruleUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .rule-menu, .rule-backdrop { animation: none; } }
