#chat-toggle {
  position: fixed;
  bottom: 40px;
  left: 20px;
  background: linear-gradient(135deg, #1d4ed8 0%, #0ea5e9 100%);
  color: white;
  padding: 12px 20px;
  border-radius: 25px;
  cursor: pointer;
  z-index: 9999;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 4px 15px rgba(29, 78, 216, 0.35);
  transition: all 0.3s ease;
  border: none;
  width: fit-content;
  display: inline-block;
  white-space: nowrap;
}

#chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(29, 78, 216, 0.5);
}

/* Effet visuel de chargement sur le toggle */
#chat-toggle.generating {
  position: fixed;
  animation: toggle-pulse 1.5s ease-in-out infinite;
  box-shadow: 0 4px 15px rgba(29, 78, 216, 0.35),
    0 0 20px rgba(14, 165, 233, 0.45),
    0 0 40px rgba(29, 78, 216, 0.3);
  transform-origin: left bottom;
}

@keyframes toggle-pulse {

  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 4px 15px rgba(29, 78, 216, 0.35),
      0 0 20px rgba(14, 165, 233, 0.45),
      0 0 40px rgba(29, 78, 216, 0.3);
  }

  50% {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(29, 78, 216, 0.35),
      0 0 30px rgba(14, 165, 233, 0.65),
      0 0 60px rgba(29, 78, 216, 0.45);
  }
}

#chat-box {
  position: fixed;
  bottom: 120px;
  left: 20px;
  width: 450px;
  height: 550px;
  background: white;
  border: none;
  border-radius: 20px;
  display: none;
  flex-direction: column;
  z-index: 9999;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  animation: slideIn 0.3s ease;
}

#chat-header {
  background: linear-gradient(135deg, #1d4ed8 0%, #0ea5e9 100%);
  color: white;
  padding: 20px;
  text-align: center;
}

#chat-header h3 {
  margin: 0 0 8px 0;
  font-size: 18px;
  font-weight: 600;
  color: white;
}

#chat-header .warning-text {
  margin: 0;
  font-size: 12px;
  opacity: 0.9;
  line-height: 1.4;
  color: white;
}

#chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  font-size: 14px;
  background: #f8f9fa;
}

#chat-messages .user-message {
  background: #e3f2fd;
  padding: 12px 16px;
  border-radius: 18px;
  margin-bottom: 12px;
  border-bottom-left-radius: 4px;
  max-width: 90%;
  margin-left: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  line-height: 1.4;
  min-height: 44px;
  display: flex;
  align-items: center;
}

#chat-messages .ai-message {
  background: white;
  padding: 12px 16px;
  border-radius: 18px;
  margin-bottom: 12px;
  border-bottom-right-radius: 4px;
  max-width: 90%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border-left: 3px solid #4caf50;
  line-height: 1.5;
  min-height: 44px;
  display: block;
  text-align: left;
}

/* Corps du message IA (markdown léger → HTML) : pas de flex multi-colonnes */
#chat-messages .ai-message .ai-message-body {
  display: block;
  width: 100%;
  text-align: left;
  word-wrap: break-word;
  overflow-wrap: break-word;
  column-count: 1;
}

#chat-messages .ai-message .ai-message-body strong {
  font-weight: 600;
  margin-right: 0;
}

#chat-messages .ai-message.error {
  border-left-color: #f44336;
  background: #ffebee;
}

#chat-messages .user-message strong {
  margin-right: 8px;
}

#chat-messages .ai-message strong {
  margin-right: 8px;
}

#chat-input {
  border-top: 1px solid #e0e0e0;
  display: flex;
  padding: 15px;
  background: white;
  gap: 8px;
}

#chat-input textarea {
  flex: 1;
  border: 2px solid #e0e0e0;
  border-radius: 15px;
  padding: 12px 16px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.3s ease;
  resize: none;
  font-family: inherit;
  line-height: 1.4;
  min-height: 60px;
  max-height: 120px;
}

#chat-input textarea:focus {
  border-color: #2563eb;
}

#chat-input textarea::placeholder {
  color: #999;
  font-style: italic;
}

#chat-input .chat-actions button {
  background: linear-gradient(135deg, #1d4ed8 0%, #0ea5e9 100%);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 25px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.3s ease;
  min-width: 80px;
}

#chat-input .chat-actions button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(29, 78, 216, 0.35);
}

#chat-input .chat-actions button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

#chat-input .chat-actions button.loading {
  position: relative;
  cursor: wait;
  opacity: 0.9;
  font-size: 0px;
  /* Cache le texte original du bouton */
}

/* Libellé visible pendant le chargement */
#chat-input .chat-actions button.loading::before {
  content: 'Generating…';
  color: #fff;
  font-size: 14px;
  /* Restaure la taille de police */
  padding-right: 12px;
}

/* Spinner moderne à droite du bouton */
#chat-input .chat-actions button.loading::after {
  content: '';
  position: absolute;
  right: 8px;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-top-color: #ffffff;
  animation: chat-spin 0.7s linear infinite;
}

#chat-undo {
  background: #f44336 !important;
  min-width: 60px;
}

#chat-undo:hover {
  background: #d32f2f !important;
}

/* Scrollbar personnalisée */
#chat-messages::-webkit-scrollbar {
  width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Animation d'apparition */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Animation du spinner */
@keyframes chat-spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* Responsive */
@media (max-width: 768px) {
  #chat-box {
    width: calc(100vw - 40px);
    left: 20px;
    right: 20px;
  }

  #chat-toggle {
    left: 20px;
    right: 20px;
    text-align: center;
  }
}
/* Boutons de réessai sous un échec de génération (chat + panneau Modify) */
.aibui-retry-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 6px 0 10px;
}

.aibui-retry-note {
  font-size: 12px;
  opacity: 0.75;
}

.aibui-retry-btn {
  appearance: none;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
}

.aibui-retry-btn:hover {
  background: rgba(127, 127, 127, 0.15);
}

.aibui-retry-btn--primary {
  background: #00b87c;
  border-color: #00b87c;
  color: #ffffff;
}

.aibui-retry-btn--primary:hover {
  background: #009e6a;
  border-color: #009e6a;
}

.aibui-retry-btn:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* Styles visuels : carte « No style », badge du style du site, lien réglages */
.chat-style-card-none {
  display: flex !important;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  opacity: 0.6;
}

/* Carte « My style » (style décrit par l'utilisateur, sans image) */
.chat-style-fallback--custom {
  background: #f1f5f9;
  border: 2px dashed #94a3b8;
  box-sizing: border-box;
}

.chat-style-fallback--custom::before {
  content: "✎";
  font-size: 28px;
  color: #475569;
}

.chat-style-card-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #00b87c;
  color: #ffffff;
  font-size: 10px;
  font-weight: 600;
  vertical-align: middle;
}

.chat-style-detail-edit {
  display: inline-block;
  margin-top: 12px;
  font-weight: 600;
}

#chat-style-picker[hidden] {
  display: none !important;
}

/* Anciennes actions : conservées dans le DOM, déclenchées par le bouton d'envoi */
#chat-input .chat-actions[hidden] {
  display: none !important;
}

/* Zone de saisie (widget flottant de repli ; la barre latérale a son propre style) */
.aibui-composer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.aibui-composer-select {
  font-size: 12px;
  min-height: 26px;
}

.aibui-send-wrap {
  flex: 1 1 100%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.aibui-cost-estimate {
  order: -1;
  font-size: 11px;
  opacity: 0.7;
}

/* Info-bulle « Answers and small edits cost less. » */
.aibui-cost-estimate[title] {
  cursor: help;
}

.aibui-send {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: #1d4ed8;
  color: #fff;
  cursor: pointer;
}

.aibui-send.is-stop {
  background: #111827;
}

.aibui-composer-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
}

.aibui-msg-meta {
  font-size: 11px;
  opacity: 0.6;
  margin: -6px 0 10px;
}

.aibui-activity {
  font-size: 12px;
  opacity: 0.8;
  margin-bottom: 10px;
}

.aibui-activity-list {
  margin: 4px 0 0 16px;
  padding: 0;
  list-style: none;
}

/* Bulle « prompt prêt » (page créée depuis Page ideas), au-dessus de la zone de saisie */
#chat-input {
  position: relative;
}

.aibui-ready-bubble {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  z-index: 5;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 260px;
  padding: 10px 12px;
  background: #1e1e1e;
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

/* Flèche vers le bouton d'envoi (en bas à droite de la zone de saisie) */
.aibui-ready-bubble::after {
  content: "";
  position: absolute;
  right: 16px;
  bottom: -6px;
  border: 6px solid transparent;
  border-bottom: 0;
  border-top-color: #1e1e1e;
}

.aibui-ready-bubble-close {
  flex-shrink: 0;
  padding: 0 2px;
  border: 0;
  background: none;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

/* Inscription dans le chat (pas encore de compte) */
.aibui-chat-signup-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, currentColor 15%, transparent);
  border-radius: 10px;
}

.aibui-chat-signup-title {
  font-size: 14px;
}

.aibui-chat-signup-sub,
.aibui-chat-signup-notice {
  margin: 0;
  font-size: 12px;
  opacity: 0.8;
}

.aibui-chat-signup-notice.is-success,
.aibui-chat-signup-notice.is-info {
  opacity: 1;
  padding: 6px 8px;
  border-radius: 6px;
  background: color-mix(in srgb, #2271b1 10%, transparent);
}

.aibui-chat-signup-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
}

.aibui-chat-signup-label input,
.aibui-chat-signup-password input {
  width: 100%;
  box-sizing: border-box;
  min-height: 32px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 400;
  border: 1px solid #8c8f94;
  border-radius: 4px;
}

.aibui-chat-signup-password {
  position: relative;
  display: block;
}

.aibui-chat-signup-password input {
  padding-right: 52px;
}

.aibui-chat-signup-reveal {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  padding: 2px 6px;
  border: 0;
  background: none;
  color: #2271b1;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.aibui-chat-signup-terms {
  display: block;
  font-size: 12px;
  line-height: 1.5;
}

.aibui-chat-signup-terms input {
  margin: 0 6px 0 0;
  vertical-align: -2px;
}

.aibui-chat-signup-error {
  margin: 0;
  color: #d63638;
  font-size: 12px;
}

.aibui-chat-signup-submit {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: #2271b1;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.aibui-chat-signup-submit:disabled {
  opacity: 0.6;
  cursor: default;
}

.aibui-chat-signup-switch {
  align-self: flex-start;
  padding: 0;
  border: 0;
  background: none;
  color: #2271b1;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}

.aibui-chat-signup-done {
  margin: 0;
}

/* Plus de crédits : formule suivante */
.aibui-upgrade p {
  margin: 0 0 8px;
}

.aibui-upgrade-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.aibui-upgrade-btn {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid #2271b1;
  border-radius: 6px;
  color: #2271b1;
  font-weight: 600;
  text-decoration: none;
}

.aibui-upgrade-btn.is-primary {
  background: #2271b1;
  color: #fff;
}

.aibui-suggestions-account {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, #2271b1 8%, transparent);
  font-size: 12px;
}

/* ---------------------------------------------------------------------------
 * Images jointes au prompt (chat et panneau Modify with AI)
 * ------------------------------------------------------------------------- */

/* Trombone : à gauche de la ligne d'envoi */
.aibui-attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-right: auto;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  opacity: 0.75;
  cursor: pointer;
}

/* Ligne d'envoi : trombone en premier, avant le coût et le bouton d'envoi */
.aibui-send-wrap .aibui-attach-btn {
  order: -2;
}

.aibui-attach-btn:hover:not(:disabled),
.aibui-attach-btn:focus-visible {
  opacity: 1;
  border-color: color-mix(in srgb, currentColor 25%, transparent);
  outline: none;
}

.aibui-attach-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Miniatures au-dessus du champ, avec une croix pour retirer chaque image */
.aibui-attach-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px;
}

.aibui-attach-tray[hidden],
.aibui-attach-notice[hidden] {
  display: none;
}

.aibui-attach-item {
  position: relative;
  width: 56px;
  height: 56px;
  border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
  border-radius: 6px;
  background: color-mix(in srgb, currentColor 6%, transparent);
  overflow: hidden;
}

.aibui-attach-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.aibui-attach-item.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: #2271b1;
  border-radius: 50%;
  animation: aibui-attach-spin 0.8s linear infinite;
}

@keyframes aibui-attach-spin {
  to { transform: rotate(360deg); }
}

.aibui-attach-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.aibui-attach-remove:hover,
.aibui-attach-remove:focus-visible {
  background: #b32d2e;
  outline: none;
}

.aibui-attach-notice {
  margin: 0 0 8px;
  font-size: 12px;
  opacity: 0.75;
}

.aibui-attach-notice.is-error {
  color: #b32d2e;
  opacity: 1;
}

/* Glisser-déposer : le panneau se signale */
.aibui-drop-active {
  outline: 2px dashed #2271b1;
  outline-offset: -4px;
}

/* Miniatures dans la bulle du message de l'utilisateur */
.aibui-msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.aibui-msg-images img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

@media (prefers-reduced-motion: reduce) {
  .aibui-attach-item.is-loading::after {
    animation: none;
  }
}

/* Explication du design automatique, en tête du choix des styles */
.chat-style-auto-hint {
  margin: 0 0 8px;
  font-size: 12px;
  line-height: 1.4;
  opacity: 0.75;
}

.chat-style-auto-hint[hidden] {
  display: none;
}
