/* ============================================================
   GenBox — Studio : fil de conversation + barre de composition
   ============================================================ */

.studio-layout { display: flex; width: 100%; min-height: 0; }
.studio-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* ---------- fil ---------- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--s5) 0;
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  /* PAS de scroll-behavior: smooth ici. Il transforme chaque
     `scrollTop = scrollHeight` en ANIMATION : à l'ouverture, le navigateur
     faisait défiler tout le fil du haut vers le bas sous les yeux de
     l'utilisateur, au lieu de l'y placer instantanément. Une messagerie
     n'anime jamais ce placement — on doit être en bas, tout de suite. */
  scroll-behavior: auto;
  overflow-anchor: auto;
}

/* Le fil est masqué le temps d'être positionné en bas, puis révélé : on ne
   voit donc jamais le haut de la conversation, même une fraction de seconde. */
.chat-area.chat-placing { visibility: hidden; }
.chat-area.chat-loading-fade > .chat-msg { opacity: 0; }
.chat-msg { opacity: 1; transition: opacity 0.2s ease; }

/* Chaque tour est centré sur une colonne de lecture confortable. */
.chat-msg, .chat-loading, .chat-error, .chat-skeleton {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 var(--s5);
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  color: var(--tx3);
}
.chat-empty-icon {
  width: 46px; height: 46px;
  border-radius: var(--r);
  background: linear-gradient(140deg, var(--violet), var(--terra));
  color: var(--void);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700;
}
.chat-empty p { font-size: 13.5px; }

/* ---------- demande ---------- */
.chat-msg.user { display: flex; justify-content: flex-end; }
.chat-bubble {
  background: var(--raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg) var(--r-lg) var(--r-xs) var(--r-lg);
  padding: 11px 15px;
  font-size: var(--fs);
  line-height: 1.55;
  max-width: 78%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-user-image { margin-bottom: var(--s2); }
.chat-user-image img {
  max-width: 190px;
  max-height: 190px;
  border-radius: var(--r-sm);
  display: block;
}

/* ---------- réponse ---------- */
.chat-msg.assistant { display: flex; }
.chat-image-card { display: flex; flex-direction: column; gap: 10px; max-width: 460px; }
.chat-image-card > img {
  max-width: 100%;
  border-radius: var(--r);
  border: 1px solid var(--line-soft);
  background: var(--void);
  cursor: zoom-in;
  display: block;
}
/* Place réservée tant que l'image n'est pas arrivée (classe posée par
   App.stageChatImages, retirée au `load`). Le fil a ainsi presque sa hauteur
   définitive dès le premier rendu : on se pose en bas juste du premier coup. */
.chat-image-card > img.img-reserving {
  width: 100%;
  min-height: 300px;
  background: var(--base);
}
.chat-image-deleted {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 168px;
  border: 1px dashed var(--line);
  border-radius: var(--r);
  color: var(--tx3);
  font-size: var(--fs-sm);
  background: var(--base);
}
.chat-image-meta { display: flex; flex-direction: column; gap: var(--s2); }
.chat-image-info { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chat-image-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.chat-image-actions button, .variant-actions button {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--tx2);
  background: var(--raised);
  padding: 6px 11px;
  border-radius: var(--r-sm);
  transition: background var(--speed), color var(--speed);
}
.chat-image-actions button:hover, .variant-actions button:hover { background: var(--hover); color: var(--tx); }

/* ---------- grille de variantes ---------- */
.chat-variants-card { max-width: 460px; }
.chat-variants-meta { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--s2); }
.variants-hint { font-size: var(--fs-sm); color: var(--tx3); }
.variants-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.variant-tile {
  position: relative;
  border-radius: var(--r-sm);
  overflow: hidden;
  border: 1px solid var(--line-soft);
  background: var(--void);
  transition: border-color var(--speed), box-shadow var(--speed);
}
.variant-tile img { width: 100%; display: block; aspect-ratio: 1; object-fit: contain; cursor: zoom-in; }
.variant-tile:hover { border-color: var(--line); }
.variant-tile.chosen { border-color: var(--violet); box-shadow: 0 0 0 1px var(--violet); }
.variant-num {
  position: absolute; top: 6px; left: 6px;
  font-family: var(--mono); font-size: 10px; font-weight: 500;
  background: oklch(0.10 0 0 / 0.72);
  color: var(--tx);
  padding: 2px 6px;
  border-radius: var(--r-xs);
}
.variant-tile.chosen .variant-num { background: var(--violet); color: var(--void); }
.variant-actions {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  gap: 4px;
  padding: 6px;
  background: linear-gradient(transparent, oklch(0.10 0 0 / 0.82));
  opacity: 0;
  transition: opacity var(--speed);
}
.variant-tile:hover .variant-actions { opacity: 1; }
.variant-actions button { padding: 4px 8px; font-size: var(--fs-xs); }

/* ---------- états ---------- */
.chat-loading, .chat-error {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.chat-loading > *, .chat-error > * { flex: none; }
.chat-loading {
  color: var(--tx2);
}
.chat-error {
  color: var(--danger-txt);
  background: var(--danger-tint);
  border-radius: var(--r-sm);
  padding: 11px 14px;
  max-width: 800px;
  width: calc(100% - var(--s5) * 2);
  margin: 0 auto;
  line-height: 1.5;
}
.chat-skeleton { display: flex; justify-content: center; padding: 40px 0; }

/* Bandeau discret pendant le chargement des messages précédents (en haut). */
.chat-older-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: var(--s4) 0;
  font-size: var(--fs-sm);
  color: var(--tx3);
}

/* ---------- barre de composition ---------- */
/* La barre passe au-dessus du fil : ses menus s'ouvrent vers le haut et
   doivent recouvrir les messages, pas se glisser dessous. */
.prompt-bar { flex: none; padding: 0 var(--s5) var(--s4); position: relative; z-index: 20; }
.prompt-bar.drag-over .prompt-shell { border-color: var(--violet); background: var(--violet-tint); }

.prompt-shell {
  max-width: 800px;
  margin: 0 auto;
  background: var(--base);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  transition: border-color var(--speed), background var(--speed);
  /* PAS d'overflow: hidden ici — il découpait les menus (modèle, style) qui
     s'ouvrent vers le haut, d'où des listes tronquées passant sous la barre.
     Les coins arrondis tiennent sans, aucun enfant n'a de fond débordant. */
}
.prompt-shell:focus-within { border-color: var(--violet-dim); }

.prompt-input-row { display: flex; align-items: flex-end; gap: var(--s2); padding: var(--s3) var(--s3) 6px; }
#prompt-input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 5px 4px;
  font-size: 14.5px;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
}
#prompt-input:focus { outline: none; }

.btn-upload {
  flex: none;
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  color: var(--tx3);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background var(--speed), color var(--speed);
}
.btn-upload:hover { background: var(--raised); color: var(--tx2); }
.upload-preview { position: relative; flex: none; }
.upload-preview img {
  width: 42px; height: 42px;
  object-fit: cover;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  display: block;
}
.btn-remove-upload {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--raised);
  border: 1px solid var(--line);
  color: var(--tx2);
  font-size: 13px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.btn-remove-upload:hover { background: var(--danger); color: var(--void); }

.btn-improve {
  flex: none;
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  background: var(--raised);
  color: var(--tx2);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  transition: background var(--speed), color var(--speed);
}
.btn-improve:hover:not(:disabled) { background: var(--violet); color: var(--void); }

/* ---------- réglages en pastilles ---------- */
.prompt-options {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px var(--s3) var(--s3);
}
.btn-queue {
  margin-left: auto;
  width: 34px; height: 34px;
  border-radius: var(--r-full);
  border: 1px solid var(--line-soft);
  color: var(--tx3);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--speed), color var(--speed), border-color var(--speed);
}
.btn-queue:hover { background: var(--raised); color: var(--tx); border-color: var(--line); }
.btn-queue.pending { background: var(--violet-tint); border-color: var(--violet-dim); color: var(--violet-txt); }

.btn-generate {
  display: flex;
  align-items: center;
  gap: var(--s2);
  background: var(--violet);
  color: var(--void);
  border-radius: var(--r-full);
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 700;
  transition: background var(--speed);
}
.btn-generate:hover:not(:disabled) { background: var(--violet-hi); }
.btn-generate .spinner { border-color: oklch(0.30 0 0 / 0.4); border-top-color: var(--void); }

.prompt-hint {
  max-width: 800px;
  margin: var(--s2) auto 0;
  display: flex;
  gap: var(--s4);
  font-size: var(--fs-xs);
  color: var(--tx3);
}
.prompt-hint .rate { margin-left: auto; font-family: var(--mono); }

/* ---------- sélecteur de preset ---------- */
.preset-picker, .style-picker { position: relative; }
.preset-picker-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--tx2);
  background: transparent;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-full);
  padding: 6px 12px;
  transition: background var(--speed), color var(--speed), border-color var(--speed);
}
.preset-picker-btn:hover { background: var(--raised); color: var(--tx); }
.preset-picker-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.preset-picker-label { max-width: 190px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.style-picker-btn.style-active { background: var(--violet-tint); border-color: var(--violet-dim); color: var(--violet-txt); }

.preset-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 330px;
  background: var(--base);
  /* Bordure ET ombre portée marquées : le menu flotte au-dessus du fil de
     conversation, il doit s'en détacher franchement. */
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  overflow: hidden;
}
.preset-dropdown-list { max-height: 340px; overflow-y: auto; padding: var(--s1); }
.preset-dropdown-footer { padding: var(--s2); border-top: 1px solid var(--line-soft); }
.preset-dropdown-footer .btn-sm { width: 100%; background: var(--raised); color: var(--tx2); border-radius: var(--r-sm); padding: 8px; font-weight: 600; }
.preset-dropdown-footer .btn-sm:hover { background: var(--hover); color: var(--tx); }

.preset-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--speed);
}
.preset-option:hover { background: var(--raised); }
.preset-option.active { background: var(--violet-tint); }
.preset-option-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.preset-option-info { flex: 1; min-width: 0; }
.preset-option-name { font-size: 13px; font-weight: 600; }
.preset-option-desc {
  font-size: var(--fs-xs);
  color: var(--tx3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.preset-option-rate { font-family: var(--mono); font-size: 10px; color: var(--tx3); flex: none; }
.preset-option-provider {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--tx3);
  background: var(--raised);
  padding: 2px 6px;
  border-radius: var(--r-xs);
  flex: none;
}

/* ---------- sélecteur de style ---------- */
.style-dropdown { width: 300px; }
.style-cat {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tx3);
  padding: var(--s3) 10px 5px;
}
.style-option {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  transition: background var(--speed);
}
.style-option:hover { background: var(--raised); }
.style-option.active { background: var(--violet-tint); color: var(--violet-txt); }
.style-emoji { flex: none; }
.style-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.style-size { font-family: var(--mono); font-size: 10px; color: var(--tx3); flex: none; }

/* Modifier ou supprimer son propre style, sans quitter le sélecteur. */
.style-actions { display: none; gap: 2px; flex: none; }
.style-option.own:hover .style-actions { display: flex; }
.style-option.own:hover .style-size { display: none; }
.style-actions button {
  width: 20px; height: 20px;
  border-radius: var(--r-xs);
  color: var(--tx3);
  font-size: 12px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.style-actions button:hover { background: var(--hover); color: var(--tx); }
.style-actions button[data-sedit="del"]:hover { background: var(--danger-tint); color: var(--danger-txt); }

/* ---------- taille / variantes ---------- */
.size-selector { display: flex; gap: 2px; background: var(--void); border: 1px solid var(--line-soft); border-radius: var(--r-full); padding: 2px; }
.size-btn {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--tx3);
  padding: 5px 11px;
  border-radius: var(--r-full);
  transition: background var(--speed), color var(--speed);
}
.size-btn:hover { color: var(--tx2); }
.size-btn.active { background: var(--violet); color: var(--void); }

.toggle-variants {
  border: 1px solid var(--line-soft);
  border-radius: var(--r-full);
  padding: 5px 12px 5px 8px;
  font-size: var(--fs-sm);
}
.toggle-variants input[type="checkbox"] { width: 30px; height: 17px; }
.toggle-variants input[type="checkbox"]::after { width: 11px; height: 11px; }
.toggle-variants input[type="checkbox"]:checked::after { left: 16px; }

.variety-select {
  width: auto;
  font-size: var(--fs-sm);
  padding: 6px 28px 6px 12px;
  border-radius: var(--r-full);
  border-color: var(--line-soft);
  background-color: transparent;
  color: var(--tx2);
}

/* ---------- adaptatif ---------- */
@media (max-width: 768px) {
  .chat-area { padding: var(--s4) 0 var(--s2); }
  .chat-msg, .chat-loading, .chat-error, .chat-skeleton { padding: 0 var(--s3); }
  .chat-bubble { max-width: 88%; }
  .prompt-bar { padding: 0 var(--s3) 62px; }
  .prompt-options { gap: 5px; }
  .preset-picker-label { max-width: 110px; }
  .preset-dropdown { width: min(330px, calc(100vw - 30px)); }
  .btn-generate { padding: 9px 14px; }
  .prompt-hint { display: none; }
}
