body {
  font-family: 'Poppins', sans-serif;
  background: #fff2beff;
  color: #222;
  margin: 0;
  text-align: center;
  padding: 0;
}

/* ----------- HERO IA (Chat Intégré) ----------- */
.ia-hero {
  display: flex;
  flex-direction: column;
  padding: 10px 20px 40px 20px;
  max-width: 1250px;
  margin: 0 auto;
  width: 100%;
  min-height: 70vh;
  background: transparent;
  /* Couleurs pour les catégories */
  --color-discoveries: #4CAF50;
  --color-personalities: #2196F3;
  --color-phenomena: #FF9800;
  --color-history: #9C27B0;
}

.request-counter {
  margin-left: auto;
  margin-right: 15px;
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  color: white;
  display: flex;
  align-items: center;
  gap: 5px;
}

.integrated-chat-container {
  width: 100%;
  height: 85vh;
  max-height: 850px;
  display: flex;
  flex-direction: row;
  /* Modern gradient background */
  background: linear-gradient(145deg, #1a1a2e 0%, #16213e 50%, #0f0f23 100%);
  border-radius: 28px;
  box-shadow: 
    0 25px 80px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 0 40px rgba(255, 115, 0, 0.08);
  overflow: hidden;
  border: 1px solid rgba(255, 174, 66, 0.1);
  position: relative;
}

.integrated-chat-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 200px;
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 115, 0, 0.08) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ----------- SIDEBAR ----------- */
.chat-sidebar {
  width: 280px;
  background: linear-gradient(180deg, rgba(20, 20, 35, 0.98) 0%, rgba(15, 15, 28, 0.98) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid rgba(255, 174, 66, 0.1);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  z-index: 10;
}

.sidebar-header {
  padding: 24px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.sidebar-header h3 {
  margin: 0;
  color: #f0f0f0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.new-chat-btn {
  background: linear-gradient(135deg, #ff7300, #ffae42);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 15px rgba(255, 115, 0, 0.3);
}

.new-chat-btn:hover {
  transform: scale(1.1) rotate(90deg);
  box-shadow: 0 6px 25px rgba(255, 115, 0, 0.5);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 15px 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 174, 66, 0.3) transparent;
}

.history-item {
  padding: 14px 16px;
  margin-bottom: 10px;
  border-radius: 14px;
  color: rgba(200, 200, 210, 0.8);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 0.9rem;
  border: 1px solid transparent;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.history-item span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.delete-chat-btn {
  background: transparent;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 6px 8px;
  border-radius: 8px;
  opacity: 0;
  transition: all 0.2s;
}

.history-item:hover .delete-chat-btn {
  opacity: 1;
}

.delete-chat-btn:hover {
  background: rgba(255, 80, 80, 0.15);
  color: #ff6b6b;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #f0f0f0;
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateX(4px);
}

.history-item.active {
  background: linear-gradient(135deg, rgba(255, 115, 0, 0.15) 0%, rgba(255, 174, 66, 0.1) 100%);
  color: #ffae42;
  border-color: rgba(255, 174, 66, 0.3);
  box-shadow: 0 4px 15px rgba(255, 115, 0, 0.1);
}

.sidebar-footer {
  padding: 18px 15px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.clear-all-btn {
  width: 100%;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 100, 100, 0.2);
  color: rgba(200, 150, 150, 0.8);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 0.85rem;
  font-weight: 500;
}

.clear-all-btn:hover {
  background: rgba(255, 80, 80, 0.1);
  color: #ff7070;
  border-color: rgba(255, 100, 100, 0.4);
  transform: scale(1.02);
}

/* ----------- MAIN CHAT AREA ----------- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* Important pour le flexbox et text-overflow */
  position: relative;
  z-index: 1;
  background: transparent;
}

.sidebar-toggle {
  display: none;
  /* Caché sur desktop */
  background: transparent;
  border: none;
  color: #f0f0f0;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 12px 0 0;
  transition: transform 0.2s ease;
}

.sidebar-toggle:hover {
  transform: scale(1.1);
}

.chat-title-bar {
  font-size: 1.15rem;
  font-weight: 600;
  color: #f5f5f5;
  padding: 22px 28px;
  background: linear-gradient(180deg, rgba(30, 30, 50, 0.95) 0%, rgba(25, 25, 45, 0.9) 100%);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border-bottom: 1px solid rgba(255, 174, 66, 0.1);
  text-align: left;
  font-family: 'Poppins', sans-serif;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 5;
}

.chat-title-bar::before {
  content: '🤖';
  font-size: 1.5rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.integrated-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 25px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: #1a1a1a;
  scrollbar-width: thin;
  scrollbar-color: #444 #1a1a1a;
}

.integrated-chat-messages::-webkit-scrollbar {
  width: 10px;
}

.integrated-chat-messages::-webkit-scrollbar-track {
  background: #1a1a1a;
}

.integrated-chat-messages::-webkit-scrollbar-thumb {
  background-color: #444;
  border-radius: 5px;
  border: 2px solid #1a1a1a;
}

.integrated-chat-messages::-webkit-scrollbar-thumb:hover {
  background-color: #555;
}

.chat-message {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

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

.chat-message.bot {
  align-self: flex-start;
}

.chat-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-top: 4px;
}

.chat-message.bot .message-avatar {
  background: linear-gradient(135deg, #ff7300, #ffae42);
}

.chat-message.user .message-avatar {
  background: #3a3a3a;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: 16px;
  color: #e8e8e8;
  font-size: 0.95rem;
  line-height: 1.6;
  font-family: 'Poppins', sans-serif;
  word-wrap: break-word;
  transition: background-color 0.2s ease;
}

.chat-message.bot .message-bubble {
  background: #2d2d2d;
  border: 1px solid #3a3a3a;
  text-align: left;
}

.chat-message.user .message-bubble {
  background: linear-gradient(135deg, #ff6a00, #ffae42);
  color: #ffffff;
  font-weight: 500;
  box-shadow: 0 4px 15px rgba(255, 106, 0, 0.3);
}

.message-bubble img,
.uploaded-image {
  max-width: 75%;
  height: auto;
  border-radius: 8px;
  display: block;
  margin: 10px 0;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

/* Styles pour le contenu Markdown */
.message-bubble strong {
  font-weight: 600;
  color: inherit;
}

.message-bubble code {
  background: rgba(255, 255, 255, 0.1);
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.message-bubble ul,
.message-bubble ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-bubble li {
  margin: 4px 0;
}

/* Indicateur de frappe */
.typing-indicator {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  max-width: 85%;
  animation: slideIn 0.3s ease;
}

.typing-indicator .message-bubble {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #888;
  animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
  animation-delay: 0ms;
}

.typing-dot:nth-child(2) {
  animation-delay: 200ms;
}

.typing-dot:nth-child(3) {
  animation-delay: 400ms;
}

@keyframes typing {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }

  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* Input en bas */
.integrated-chat-input-container {
  display: flex;
  gap: 12px;
  padding: 0 25px 25px;
  background: transparent;
  border-top: none;
  flex-shrink: 0;
  align-items: center;
  position: relative;
  z-index: 10;
}

#integratedChatInput {
  flex: 1;
  background: #2a2a2a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 14px 20px;
  font-size: 0.95rem;
  color: #e8e8e8;
  font-family: 'Poppins', sans-serif;
  outline: none;
  transition: all 0.2s ease;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

#integratedChatInput:focus {
  border-color: #ffae42;
  box-shadow: 0 0 0 3px rgba(255, 174, 66, 0.15);
}

#integratedChatInput::placeholder {
  color: #666;
}

#integratedChatSend {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #ff7300, #ffae42);
  color: #fff;
  font-size: 1.3rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

#integratedChatSend:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(255, 115, 0, 0.4);
}

#integratedChatSend:active {
  transform: scale(0.95);
}

#integratedChatSend:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: scale(1);
}

/* Message d'erreur */
.error-message {
  background: #4a2020 !important;
  border: 1px solid #6a3030 !important;
  color: #ffaaaa !important;
}

/* Bouton pour effacer l'historique */
.chat-clear-history {
  background: #3a3a3a;
  border: none;
  color: #999;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-left: auto;
}

.chat-clear-history:hover {
  background: #4a4a4a;
  color: #fff;
}

/* ----------- GENERATOR SECTION ----------- */
.generator-section {
  padding: 50px 20px;
  max-width: 1250px;
  margin: 0 auto 50px auto;
}

.generator-container {
  background: #1e1e1e;
  border-radius: 24px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
  color: #e0e0e0;
}

.generator-title {
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 10px;
  background: linear-gradient(135deg, #ff7300, #ffae42);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}

.generator-subtitle {
  text-align: center;
  color: #aaa;
  margin-bottom: 40px;
  font-size: 1.1rem;
}

.generator-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 20px;
  margin-bottom: 30px;
  align-items: end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-group label {
  font-weight: 600;
  color: #e0e0e0;
  font-size: 0.95rem;
}

.form-group select {
  padding: 14px;
  background: #2a2a2a;
  border: 1px solid #333;
  border-radius: 12px;
  font-family: 'Poppins', sans-serif;
  font-size: 1rem;
  color: #e0e0e0;
  outline: none;
  transition: all 0.2s;
}

.form-group select:focus {
  border-color: #ffae42;
  box-shadow: 0 0 0 2px rgba(255, 174, 66, 0.1);
}

.generate-btn {
  padding: 14px 28px;
  background: linear-gradient(135deg, #ff7300, #ffae42);
  color: white;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  height: 52px;
  /* Match select height */
}

.generate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(255, 115, 0, 0.3);
}

.generate-btn:disabled {
  opacity: 0.7;
  cursor: wait;
  transform: none;
}

.exercise-display {
  min-height: 200px;
  padding: 30px;
  border: 2px dashed #333;
  border-radius: 16px;
  background: #252525;
  position: relative;
  transition: all 0.3s ease;
}

.exercise-display.loading {
  border-style: solid;
  border-color: #ffae42;
}

.exercise-display.loading::after {
  content: "Génération en cours... Newton réfléchit 🍎";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #ffae42;
  font-weight: 600;
  font-size: 1.1rem;
}

.placeholder-text {
  text-align: center;
  color: #666;
  font-style: italic;
  margin-top: 40px;
}

.generated-content h3 {
  color: #ffae42;
  margin-bottom: 20px;
  border-bottom: 1px solid #444;
  padding-bottom: 15px;
  font-size: 1.4rem;
}

.exercise-body {
  color: #d0d0d0;
  line-height: 1.7;
  font-size: 1.05rem;
  text-align: left;
}

.exercise-body strong {
  color: #fff;
}

/* Responsive */
/* Overlay pour fermer la sidebar */
.sidebar-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Responsive */
@media (max-width: 768px) {
  /* Restore scroll */
  body {
    height: auto;
    display: block;
    overflow: auto;
  }

  main {
    display: block;
    height: auto;
    overflow: visible;
  }

  /* Compact IA Header */
  .ia-page-header {
    padding: 15px 0 5px 0;
  }

  .ia-header {
    margin-bottom: 10px;
    padding: 0 15px;
  }

  .ia-header h1 {
    font-size: 1.6rem;
    margin-bottom: 5px;
  }

  .ia-badge {
    padding: 4px 10px;
    font-size: 0.75rem;
    margin-bottom: 8px;
  }

  .ia-page-subtitle {
    display: block; /* Restore subtitle */
    font-size: 0.85rem;
    margin-bottom: 10px;
  }

  /* Chat container height adjustment */
  .ia-hero {
    padding: 0 10px;
    margin: 0;
    height: auto;
    min-height: 0;
    display: block;
  }

  .integrated-chat-container {
    border-radius: 16px;
    height: 80dvh; /* Dynamic viewport height */
    max-height: 700px;
    display: flex;
    flex-direction: column;
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
  }

  /* Sidebar Mobile */
  .chat-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 280px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
  }

  .chat-sidebar.open {
    transform: translateX(0);
  }

  /* Toggle Button */
  .sidebar-toggle {
    display: block;
    margin-right: 10px;
    padding: 5px;
  }

  .chat-title-bar {
    padding: 10px 15px;
    font-size: 0.95rem;
    min-height: 50px;
    border-radius: 16px 16px 0 0;
    flex-shrink: 0; /* Prevent shrinking */
  }

  .ia-prevention-message {
    flex-shrink: 0; /* Prevent shrinking */
  }

  .integrated-chat-messages {
    padding: 10px;
    flex: 1 1 0; /* Grow, shrink, basis 0 (critical for scroll) */
    height: 0; /* Force height calculation from flex */
    overflow-y: auto; /* Enable scroll */
    -webkit-overflow-scrolling: touch;
  }

  .message-bubble {
    padding: 8px 12px;
    font-size: 0.9rem;
    max-width: 100%;
  }

  .message-bubble img,
  .uploaded-image {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
    margin-bottom: 8px;
  }

  .integrated-chat-input-container {
    padding: 10px;
    gap: 8px;
    flex-shrink: 0; /* Prevent shrinking */
    background: #1e1e1e; /* Ensure background covers content behind */
  }

  #integratedChatInput {
    padding: 10px 15px;
    font-size: 16px;
    min-width: 0;
  }

  /* Restore footer and generator */
  .generator-section, footer {
    display: block;
  }
  
  .generator-section {
    padding: 20px 10px;
  }
}

/* ----------- SECTIONS SUIVANTES (Cachées) ----------- */
.ia-separator,
.ia-col.droite,
.ia-col.gauche,
.ia-subtitle,
.ia-desc,
.ia-right-content,
.ia-titre-droite,
.btn-ia-launch,
.ia-desc-droite,
.ia-desc-droite,
#snackbar-dev {
  display: none;
}

/* Construction Mode Styles */
.generator-container.construction-mode {
  position: relative;
  overflow: hidden;
}

.construction-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(30, 30, 30, 0.85);
  backdrop-filter: blur(4px);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #fff;
  padding: 20px;
  border-radius: 24px;
}

.construction-message {
  text-align: center;
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  padding: 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
  100% { transform: translateY(0px); }
}

/* ----------- PREVENTION MESSAGE ----------- */
.ia-prevention-message {
  width: 100%;
  background: rgba(255, 174, 66, 0.05);
  border-bottom: 1px solid rgba(255, 174, 66, 0.15);
  padding: 12px 20px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  font-size: 0.85rem;
  color: #ccc;
  line-height: 1.4;
  flex-shrink: 0;
}

.ia-prevention-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.ia-prevention-content strong {
  color: #ffae42;
  display: block;
  margin-bottom: 2px;
  font-size: 0.9rem;
}

.ia-prevention-content a {
  color: #ffae42;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ia-prevention-content a:hover {
  color: #ffc107;
}

.prevention-mobile {
  display: none;
}

@media (max-width: 768px) {
  .prevention-desktop {
    display: none;
  }
  
  .prevention-mobile {
    display: block;
  }
  
  .ia-prevention-message {
    padding: 10px 15px;
    font-size: 0.8rem;
  }
}

@media (max-width: 768px) {
  .ia-prevention-message {
    margin: 10px 15px 20px 15px;
    font-size: 0.85rem;
  }
}

.generator-container.construction-mode .generator-form,
.generator-container.construction-mode .exercise-display,
.generator-container.construction-mode .generator-title,
.generator-container.construction-mode .generator-subtitle {
  opacity: 0.3;
  pointer-events: none;
  filter: grayscale(0.8);
}

/* --- HEADER IA (Homogenized) --- */
.ia-page-header {
  padding: 50px 0 20px 0;
  text-align: center;
}

.ia-header {
  text-align: center;
  margin-bottom: 20px;
}

.ia-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 106, 0, 0.1);
  color: #ff6a00;
  padding: 8px 20px;
  border-radius: 50px;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 20px;
  border: 1px solid rgba(255, 106, 0, 0.2);
}

.ia-header h1 {
  font-family: 'Poppins', sans-serif;
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.1;
  color: #222;
  margin-bottom: 15px;
  letter-spacing: -1px;
}

.ia-page-subtitle {
  font-size: 1rem;
  color: #222;
  font-weight: 400;
  line-height: 1.6;
  max-width: 700px;
  margin: 0 auto;
}

.gradient-text {
  background: linear-gradient(135deg, #ff6a00, #ff9500);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}