/* Barre de commande (Ctrl+K) */
.cmd {
  width: min(680px, calc(100vw - 32px)); max-height: min(640px, calc(100vh - 120px)); margin: 12vh auto auto; padding: 0;
  border: 1px solid var(--glass-line); border-radius: 16px; color: var(--graphite);
  background: color-mix(in oklab, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(170%); backdrop-filter: blur(24px) saturate(170%);
  box-shadow: inset 0 1px 0 var(--glass-edge), 0 24px 60px -20px rgb(0 0 0 / .45);
  overflow: hidden;
}
.cmd[open] { display: flex; flex-direction: column; }
.cmd::backdrop { background: rgb(15 17 19 / .28); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.cmd-input-row { display: flex; align-items: center; gap: var(--sp-3); padding: 14px var(--sp-4); border-bottom: 1px solid var(--trait); flex: none; }
.cmd-input-row > svg.icon { width: 18px; height: 18px; color: var(--ardoise); flex: none; }
.cmd-input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font: 400 16px/1.4 var(--f-texte); color: var(--graphite); }
.cmd-input::placeholder { color: var(--ardoise); }
.cmd-close { width: 30px; height: 30px; margin-right: -6px; }
.cmd-close svg.icon { width: 16px; height: 16px; }
/* flex-basis auto, pas 0 % : sans hauteur fixe (seulement max-height), Safari iOS réduisait la zone à 0 px (contenu invisible). */
.cmd-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: var(--sp-2); scrollbar-width: thin; scrollbar-color: var(--trait) transparent; }

/* Propositions */
.cmd-items { list-style: none; margin: 0; padding: 0; }
.cmd-item { display: flex; align-items: center; gap: var(--sp-3); padding: 9px 12px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.cmd-item svg.icon { width: 16px; height: 16px; color: var(--ardoise); flex: none; }
.cmd-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-item.selected { background: var(--surface-2); }
.cmd-item.selected svg.icon { color: var(--graphite); }

/* Aide (champ vide, pas de conversation) */
.cmd-help { font-size: 13px; }
.cmd-help-title { font-weight: 500; margin-bottom: var(--sp-2); }
.cmd-help-title .muted { font-weight: 400; color: var(--ardoise); }
.cmd-help-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cmd-help-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; color: var(--ardoise); }
.cmd-help-list b { color: var(--graphite); font-weight: 500; }
.cmd-example { padding: 2px 8px; border: 1px solid var(--trait); border-radius: 999px; background: var(--surface); color: var(--graphite); font-size: 12.5px; text-align: left; }
.cmd-example:hover { border-color: var(--ardoise); }
.cmd-help-note { margin-top: var(--sp-3); color: var(--ardoise); font-size: 12px; line-height: 1.5; }
.cmd-help-note a { color: var(--prusse); }

/* Conversation */
.cmd-thread { display: flex; flex-direction: column; gap: var(--sp-2); }
.cmd-thread:not(:empty) { padding: var(--sp-2) var(--sp-2) var(--sp-3); margin-bottom: var(--sp-2); border-bottom: 1px solid var(--trait); }
.cmd-turn.user { align-self: flex-end; max-width: 85%; padding: 8px 12px; border-radius: 12px 12px 4px 12px; background: var(--graphite); color: var(--surface); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.cmd-turn.assistant { display: flex; flex-direction: column; gap: var(--sp-2); max-width: 100%; }
.cmd-text { font-size: 14px; line-height: 1.55; }
.cmd-text p + p { margin-top: .5em; }
.cmd-card { border: 1px solid var(--trait); border-radius: 10px; background: var(--surface); padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.cmd-card-title { display: flex; align-items: center; gap: 6px; font-weight: 500; padding: 2px 2px 4px; }
.cmd-card-title svg.icon { width: 15px; height: 15px; color: var(--ardoise); }
.cmd-row { display: flex; align-items: baseline; gap: var(--sp-3); padding: 6px 8px; border-radius: 6px; color: var(--graphite); }
.cmd-row:hover { background: var(--surface-2); }
.cmd-row .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-row .mono { flex: none; font-size: 11.5px; color: var(--ardoise); }
.cmd-row svg.icon { width: 15px; height: 15px; color: var(--ardoise); flex: none; align-self: center; }
.cmd-undo { align-self: flex-start; margin: 2px 8px; font-size: 12px; }
.cmd-card form { display: contents; }
.cmd-confirm { border-color: var(--ambre); box-shadow: inset 3px 0 0 var(--ambre); }
.cmd-actions { display: flex; gap: var(--sp-2); padding: 4px 2px 2px; }
.cmd-error { flex-direction: row; align-items: center; gap: 8px; color: var(--erreur); border-color: color-mix(in oklab, var(--erreur) 35%, var(--trait)); }
.cmd-error svg.icon { width: 14px; height: 14px; flex: none; }
.cmd-muted { color: var(--ardoise); }
.cmd-thinking { flex-direction: row; gap: 5px; padding: 10px 4px; }
.cmd-thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--ardoise); animation: cmd-dot 1s ease-in-out infinite; }
.cmd-thinking i:nth-child(2) { animation-delay: .15s; }
.cmd-thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes cmd-dot { 0%, 100% { opacity: .25; translate: 0 0; } 50% { opacity: 1; translate: 0 -3px; } }

.cmd-foot { display: flex; align-items: center; gap: var(--sp-4); padding: 8px var(--sp-4); border-top: 1px solid var(--trait); font-size: 12px; color: var(--ardoise); flex: none; }
.cmd-foot kbd { padding: 2px 5px; margin-right: 2px; }
.cmd-mode { margin-left: auto; }
.cmd-foot .link { font-size: 12px; }
.cmd-mic { width: 30px; height: 30px; }
.cmd-mic svg.icon { width: 17px; height: 17px; }
.cmd-mic.listening { color: var(--erreur); background: color-mix(in oklab, var(--erreur) 12%, transparent); animation: cmd-pulse 1.2s ease-in-out infinite; }
@keyframes cmd-pulse { 50% { box-shadow: 0 0 0 4px color-mix(in oklab, var(--erreur) 18%, transparent); } }
/* Écoute en cours : ondes à côté du micro, bordure du champ animée */
.cmd-wave { display: none; align-items: center; gap: 3px; height: 20px; flex: none; }
.cmd-wave i { width: 3px; height: 6px; border-radius: 2px; background: var(--erreur); animation: cmd-wave 0.9s ease-in-out infinite; }
.cmd-wave i:nth-child(2) { animation-delay: .12s; } .cmd-wave i:nth-child(3) { animation-delay: .24s; }
.cmd-wave i:nth-child(4) { animation-delay: .36s; } .cmd-wave i:nth-child(5) { animation-delay: .48s; }
@keyframes cmd-wave { 0%, 100% { height: 5px; } 50% { height: 18px; } }
.cmd.listening .cmd-wave { display: inline-flex; }
.cmd.listening .cmd-input-row { box-shadow: inset 0 -2px 0 color-mix(in oklab, var(--erreur) 70%, transparent); }
.cmd.listening .cmd-input::placeholder { color: var(--erreur); }
@media (prefers-reduced-motion: reduce) { .cmd-mic.listening, .cmd-wave i { animation: none; } .cmd-wave i { height: 12px; } }
.cmd-turn .cmd-help { padding: var(--sp-2) var(--sp-1); margin: 0; border: 0; }

/* Bouton flottant (mobile) */
.cmd-fab { display: none; }
@media (max-width: 767px) {
  /* --cmd-vh / --cmd-vt : hauteur et décalage de la zone visible au-dessus du clavier (posés par command_controller). */
  .cmd { margin-top: calc(8px + var(--cmd-vt, 0px)); max-height: min(calc(100dvh - 140px), calc(var(--cmd-vh, 100dvh) - 16px)); width: calc(100vw - 16px); }
  .cmd-foot > span:first-child { display: none; }
  .cmd-fab {
    display: grid; place-items: center; position: fixed; right: 16px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 25;
    width: 52px; height: 52px; border-radius: 50%; color: var(--graphite);
  }
  .cmd-fab svg.icon { width: 20px; height: 20px; }
}
@media (prefers-reduced-motion: reduce) { .cmd-thinking i { animation: none; opacity: .6; } }
.cmd-warning { margin: 4px 2px 2px; padding: 6px 8px; border-radius: 6px; background: color-mix(in oklab, var(--ambre-doux) 80%, transparent); color: var(--graphite); font-size: 12.5px; line-height: 1.45; }

/* Fiches du cerveau dans une réponse */
.cmd-note + .cmd-note { margin-top: var(--sp-2); }
.cmd-note .note-secret { margin: 4px 0 0; }

/* Liens des réponses : boutons ouverts dans un nouvel onglet */
.cmd-link-btn { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; margin: 2px 0; padding: 4px 10px; font-size: 13px; vertical-align: middle; }
.cmd-link-btn svg.icon { width: 14px; height: 14px; flex: none; }
.cmd-link-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.cmd-text code { font-family: var(--f-donnees); font-size: .92em; padding: 0 4px; border-radius: 4px; background: var(--surface-2); }
/* « 🔊 Écouter » sous une réponse de l'IA */
.cmd-speak { align-self: flex-start; display: inline-flex; align-items: center; gap: 5px; margin-top: 4px; font-size: 12.5px; border: 0; background: none; padding: 0; cursor: pointer; }
.cmd-speak.on { color: var(--erreur); }
.cmd-speak.on::after { content: " · arrêter"; }
/* Réponses de l'IA : gras bien visible, intertitres, listes */
.cmd-text strong { font-weight: 600; color: var(--graphite); background: color-mix(in oklab, var(--ambre) 14%, transparent); padding: 0 2px; border-radius: 3px; }
.cmd-text .cmd-heading { margin: .8em 0 .2em; font: 600 13.5px/1.3 var(--f-titre); color: var(--graphite); }
.cmd-text .cmd-heading:first-child { margin-top: 0; }
.cmd-text ul, .cmd-text ol { margin: .3em 0 .5em; padding-left: 20px; }
.cmd-text li + li { margin-top: 3px; }
/* Barre du bas : raccourcis discrets à gauche, actions en icônes à droite, état de l'IA */
.cmd-foot { justify-content: space-between; gap: var(--sp-3); padding: 6px 10px 6px var(--sp-4); }
.cmd-keys { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.cmd-keys kbd { margin-right: 0; }
.cmd-foot-actions { display: inline-flex; align-items: center; gap: 2px; margin-left: auto; }
.cmd-foot-btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 9px; border: 0; border-radius: 8px; background: none; color: var(--ardoise); font: inherit; font-size: 12.5px; cursor: pointer; }
.cmd-foot-btn:hover { background: var(--surface-2); color: var(--graphite); }
.cmd-foot-btn svg.icon { width: 16px; height: 16px; }
.cmd-foot-btn.icon-only { width: 32px; padding: 0; justify-content: center; }
.cmd-voice .icon.off { display: none; }
.cmd-voice[aria-pressed="false"] .icon.on { display: none; }
.cmd-voice[aria-pressed="false"] .icon.off { display: inline; }
.cmd-voice[aria-pressed="true"] { color: var(--prusse); }
.cmd-voice.speaking { color: var(--prusse); background: color-mix(in oklab, var(--prusse) 12%, transparent); animation: cmd-pulse 1.4s ease-in-out infinite; }
.cmd-mode { display: inline-flex; align-items: center; gap: 5px; margin-left: 6px; padding: 3px 8px; border-radius: 99px; background: var(--surface-2); font-size: 11.5px; color: var(--graphite); }
.cmd-mode i { width: 7px; height: 7px; border-radius: 50%; background: var(--succes); }
.cmd-mode.off i { background: var(--ardoise); }
@media (max-width: 640px) { .cmd-keys { display: none; } .cmd-foot-btn span { display: none; } .cmd-foot-btn { width: 36px; padding: 0; justify-content: center; } }

/* Résultats de recherche repliés sous la réponse */
.cmd-sources { font-size: 13px; }
.cmd-sources > summary { cursor: pointer; color: var(--ardoise); display: inline-flex; align-items: center; gap: 6px; padding: 2px 0; list-style: none; }
.cmd-sources > summary::-webkit-details-marker { display: none; }
.cmd-sources > summary:hover { color: var(--graphite); }
.cmd-sources[open] > summary { margin-bottom: 6px; }
.cmd-sources .cmd-card + .cmd-card { margin-top: 6px; }
