/* Reset et variables */
:root {
  --primary-color: #4CAF50;
  --secondary-color: #FF6B6B;
  --gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --border-radius: 12px;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.16);
  --header-height: 60px;
  --cta-height-mobile: 170px;
  --input-height: 60px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Mobile First - Base styles for mobile */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100vw;
  background: white;
  position: relative;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  overflow: hidden;
  height: 100vh;
}

/* Header - Optimisé mobile */
.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 12px 16px;
  box-shadow: var(--shadow-md);
  height: var(--header-height);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-circle {
  width: 36px;
  height: 36px;
  background: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #667eea;
  font-size: 14px;
}

.header-text h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.subtitle {
  font-size: 11px;
  opacity: 0.9;
  margin-top: 2px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: rgba(255,255,255,0.2);
  padding: 4px 10px;
  border-radius: 20px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #4CAF50;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

/* Main chat area - Mobile optimized avec calculs précis */
.chat-main {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height) - var(--cta-height-mobile));
  position: relative;
  overflow: hidden;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Messages - Mobile optimized */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden; /* Empêche le scroll horizontal */
  padding: 16px;
  padding-right: 12px; /* Réduit pour éviter débordement */
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  height: calc(100% - var(--input-height));
  width: 100%;
  max-width: 100vw;
}

.message {
  margin-bottom: 16px;
  animation: fadeInUp 0.3s ease;
  max-width: 100%; /* Assure que rien ne dépasse */
}

.message-header {
  margin-bottom: 6px;
  padding: 0 4px;
}

.message-author {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.user-author { color: #667eea; }
.bot-author { color: #764ba2; }

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--border-radius);
  background: #f5f5f5;
  font-size: 14px;
  line-height: 1.5;
  max-width: 100%;
  word-wrap: break-word; /* Force le retour à la ligne */
  overflow-wrap: break-word; /* Support iOS */
}

.message.user .message-bubble {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  margin-left: auto;
  max-width: 80%; /* Réduit pour éviter débordement */
}

.message.bot .message-bubble {
  background: #f8f9fa;
  max-width: 85%; /* Réduit pour éviter débordement */
}

/* Input form - Position en bas de la zone de chat */
.input-form {
  padding: 10px 12px;
  padding-bottom: env(safe-area-inset-bottom, 10px); /* Support iPhone X+ */
  background: white;
  border-top: 1px solid #e0e0e0;
  height: var(--input-height);
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  z-index: 10;
}

.input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  max-width: 100%;
}

.message-input {
  flex: 1;
  min-width: 0; /* Important pour iOS */
  padding: 10px 14px;
  border: 2px solid #e0e0e0;
  border-radius: 24px;
  font-size: 16px; /* 16px minimum évite le zoom sur iOS */
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
  background: white;
  -webkit-appearance: none; /* Évite les styles iOS par défaut */
}

.message-input:focus {
  border-color: #667eea;
}

.send-button {
  width: 38px;
  height: 38px;
  min-width: 38px; /* Empêche la compression sur iOS */
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent; /* Enlève le highlight iOS */
}

.send-button:active {
  transform: scale(0.95);
}

.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-button svg {
  width: 18px;
  height: 18px;
}

/* CTA Zone - Position fixe en bas sur mobile */
.cta-zone {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  background: white;
  border-top: 1px solid #e0e0e0;
  padding: 10px 12px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
  z-index: 100;
  height: var(--cta-height-mobile);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.cta-header {
  margin-bottom: 8px;
  padding: 0 4px;
}

.cta-header h3 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 2px 0;
}

.cta-header p {
  font-size: 10px;
  color: var(--text-secondary);
  margin: 0;
}

/* CTA Buttons - Compact pour mobile */
.cta-button {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  margin-bottom: 6px;
  border-radius: 10px;
  text-decoration: none;
  transition: all 0.2s;
  gap: 8px;
  background: white;
  border: 2px solid #e0e0e0;
  min-height: 44px;
}

.cta-button.primary {
  background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
  color: white;
  border: none;
}

.cta-button.secondary {
  background: linear-gradient(135deg, #FF6B6B 0%, #ee5a24 100%);
  color: white;
  border: none;
}

.cta-icon {
  width: 30px;
  height: 30px;
  background: rgba(255,255,255,0.2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cta-icon svg {
  width: 16px;
  height: 16px;
}

.cta-content {
  flex: 1;
  min-width: 0;
}

.cta-title {
  display: block;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.cta-subtitle {
  display: block;
  font-size: 10px;
  opacity: 0.9;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cta-arrow {
  flex-shrink: 0;
  opacity: 0.7;
  width: 14px;
  height: 14px;
}

.info-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #f0f7ff;
  border-radius: 8px;
  margin-top: 6px;
  font-size: 10px;
  color: #4a5568;
}

.info-card svg {
  width: 12px;
  height: 12px;
  color: #667eea;
  flex-shrink: 0;
}

.disclaimer-text {
  font-size: 9px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 8px;
  padding: 0 4px;
  opacity: 0.7;
  line-height: 1.3;
}

/* Footer - Supprimé car intégré dans CTA */
.footer {
  display: none;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: #999;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

.error-message {
  color: #FF6B6B;
  font-size: 11px;
  margin-top: 4px;
  padding: 0 14px;
}

/* Ajustements pour très petits écrans */
@media (max-width: 380px) {
  :root {
    --cta-height-mobile: 160px;
  }
  
  .cta-title { font-size: 11px; }
  .cta-subtitle { font-size: 9px; }
  .cta-icon { 
    width: 26px; 
    height: 26px;
  }
  .cta-button { 
    padding: 6px 8px;
    min-height: 40px;
  }
  .message-input { 
    font-size: 16px; /* CORRIGÉ : 16px au lieu de 13px pour éviter le zoom iOS */
    padding: 8px 12px;
  }
  .send-button {
    width: 34px;
    height: 34px;
  }
  .disclaimer-text {
    font-size: 8px;
  }
}

/* Tablette (iPad) */
@media (min-width: 768px) {
  :root {
    --header-height: 80px;
    --cta-height-mobile: auto;
    --input-height: 80px;
  }

  .app-container {
    display: flex;
    flex-direction: row;
    max-width: 1400px;
    margin: 0 auto;
    height: 100vh;
  }

  .chat-container {
    flex: 1;
  }

  .chat-header {
    padding: 16px 24px;
    height: var(--header-height);
  }

  .header-text h1 {
    font-size: 20px;
  }

  .subtitle {
    font-size: 13px;
  }

  .chat-main {
    flex-direction: row;
    height: calc(100vh - var(--header-height));
  }

  .chat-area {
    flex: 1.5;
  }

  .messages-container {
    padding: 24px;
    height: calc(100% - var(--input-height));
  }

  .message-bubble {
    font-size: 15px;
  }

  .input-form {
    padding: 16px 24px;
    height: var(--input-height);
    position: relative;
    border-top: 1px solid #e0e0e0;
  }

  .message-input {
    font-size: 15px;
    padding: 12px 20px;
  }

  .send-button {
    width: 44px;
    height: 44px;
  }

  /* CTA zone en sidebar sur tablette */
  .cta-zone {
    position: relative;
    width: 320px;
    border-left: 1px solid #e0e0e0;
    border-top: none;
    padding: 20px;
    box-shadow: none;
    height: auto;
    overflow-y: auto;
  }

  .cta-header h3 {
    font-size: 16px;
  }

  .cta-header p {
    font-size: 12px;
  }

  .cta-button {
    padding: 14px 16px;
    margin-bottom: 12px;
  }

  .cta-icon {
    width: 40px;
    height: 40px;
  }

  .cta-icon svg {
    width: 20px;
    height: 20px;
  }

  .cta-title {
    font-size: 14px;
  }

  .cta-subtitle {
    font-size: 12px;
  }

  .info-card {
    font-size: 12px;
    padding: 10px 14px;
  }

  .disclaimer-text {
    font-size: 11px;
    margin-top: 12px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .cta-zone {
    width: 360px;
    padding: 24px;
  }

  .messages-container {
    padding: 32px;
  }

  .cta-button {
    padding: 16px 20px;
  }

  .cta-title {
    font-size: 15px;
  }

  .cta-subtitle {
    font-size: 13px;
  }
  
  .disclaimer-text {
    font-size: 12px;
    margin-top: 16px;
    padding: 12px 8px 0;
    border-top: 1px solid #e0e0e0;
  }
}

/* Large Desktop */
@media (min-width: 1440px) {
  .cta-zone {
    width: 400px;
  }

  .chat-area {
    flex: 2;
  }
}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-10px); }
}

/* Accessibility & Performance */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --text-primary: #f0f0f0;
    --text-secondary: #a0a0a0;
  }
  
  body {
    background: #1a1a1a;
  }
  
  .app-container,
  .chat-container {
    background: #1a1a1a;
  }
  
  .message.bot .message-bubble {
    background: #2a2a2a;
    color: #f0f0f0;
  }
  
  .input-form,
  .cta-zone {
    background: #1a1a1a;
    border-color: #333;
  }
  
  .message-input {
    background: #2a2a2a;
    color: #f0f0f0;
    border-color: #444;
  }
  
  .info-card {
    background: #2a2a2a;
    color: #a0a0a0;
  }
  
  .disclaimer-text {
    color: #808080;
    border-color: #444;
  }
}

/* Gestion spéciale pour les claviers virtuels sur mobile */
@supports (-webkit-touch-callout: none) {
  /* iOS Safari */
  .chat-main {
    height: calc(100vh - var(--header-height) - var(--cta-height-mobile) - env(safe-area-inset-bottom));
  }
  
  .cta-zone {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}

/* Focus visible pour accessibilité */
.cta-button:focus-visible,
.message-input:focus-visible,
.send-button:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

/* Amélioration contraste pour accessibilité */
@media (prefers-contrast: high) {
  .cta-button.primary,
  .cta-button.secondary {
    border: 2px solid currentColor;
  }
  
  .disclaimer-text {
    opacity: 1;
    font-weight: 500;
  }
}
