/* ============================================================
   OrinStudioIA v4.1 - Design System Responsive Universel
   ============================================================ */

/* === POLICE PERSONNALISÉE === */
@font-face {
  font-family: 'TommySoft';
  src: url('/assets/font/tommy-soft.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* === VARIABLES CSS === */
:root {
  /* Couleurs */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a2e;
  --bg-card: #16162a;
  --accent: #00d4aa;
  --accent-hover: #00f0c0;
  --accent-dim: rgba(0, 212, 170, 0.15);
  --accent-glow: rgba(0, 212, 170, 0.3);
  --text-primary: #e8e8f0;
  --text-secondary: #8888a8;
  --text-muted: #55556a;
  --border: #2a2a40;
  --border-light: #3a3a55;
  --danger: #ff4466;
  --warning: #ffaa33;
  --success: #00d4aa;
  --info: #4488ff;
  --code-bg: #0d0d18;

  /* Dimensions */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --sidebar-width: 280px;
  --header-height: 60px;
  --input-height: 56px;

  /* Transitions */
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  /* Polices */
  --font-main: 'TommySoft', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-code: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
}

/* === RESET === */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; }

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh; /* Support mobile moderne */
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent; /* Pas de flash au tap mobile */
  touch-action: manipulation; /* Améliore le tactile */
}

/* Empêcher le zoom sur focus input mobile */
input, textarea, select { font-size: 16px; }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* === LAYOUT === */
.app-layout {
  display: flex;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

/* === SIDEBAR === */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s ease;
  z-index: 40;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), #0088ff);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  box-shadow: 0 0 20px var(--accent-glow);
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #0088ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.btn-new-chat {
  width: 100%;
  padding: 10px 16px;
  background: var(--accent-dim);
  border: 1px solid rgba(0, 212, 170, 0.3);
  border-radius: var(--radius-md);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);
  font-family: var(--font-main);
}

.btn-new-chat:hover {
  background: var(--accent);
  color: var(--bg-primary);
  box-shadow: 0 0 20px var(--accent-glow);
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 12px 8px 6px;
  font-weight: 600;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  border-left: 3px solid transparent;
  margin-bottom: 2px;
}

.conv-item:hover { background: var(--bg-tertiary); }
.conv-item.active { background: var(--accent-dim); border-left-color: var(--accent); }

.conv-item-icon { color: var(--text-muted); font-size: 12px; flex-shrink: 0; }
.conv-item-content { flex: 1; min-width: 0; }
.conv-item-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.conv-item-delete {
  opacity: 0;
  color: var(--text-muted);
  font-size: 11px;
  padding: 6px;
  border-radius: 4px;
  transition: var(--transition);
  flex-shrink: 0;
  border: none;
  background: none;
  cursor: pointer;
}
.conv-item:hover .conv-item-delete { opacity: 1; }
.conv-item-delete:hover { color: var(--danger); background: rgba(255, 68, 102, 0.1); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.user-avatar { display: flex; align-items: center; gap: 8px; }

.user-avatar-circle {
  width: 30px;
  height: 30px;
  background: var(--bg-tertiary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.user-name { font-size: 12px; color: var(--text-secondary); }

.btn-logout {
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  font-size: 13px;
  border: none;
  background: none;
}
.btn-logout:hover { color: var(--danger); background: rgba(255, 68, 102, 0.1); }

.model-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.model-indicator i { color: var(--accent); font-size: 10px; }

/* === MAIN CONTENT === */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* === HEADER === */
.header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }

.btn-menu {
  display: none;
  color: var(--text-secondary);
  font-size: 18px;
  padding: 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  border: none;
  background: none;
}
.btn-menu:hover { color: var(--text-primary); background: var(--bg-tertiary); }

.conv-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* === SELECTEUR DE MODÈLE === */
.model-selector { position: relative; }

.btn-model {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-main);
}
.btn-model:hover { border-color: var(--accent); color: var(--text-primary); }
.btn-model i.accent { color: var(--accent); }
.btn-model .chevron { font-size: 9px; color: var(--text-muted); }

.model-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 280px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  z-index: 50;
  overflow: hidden;
  display: none;
}
.model-dropdown.show { display: block; }

.model-dropdown-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.model-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
}
.model-option:hover { background: var(--bg-tertiary); }
.model-option.active { background: var(--accent-dim); border-color: rgba(0, 212, 170, 0.2); }
.model-option.disabled { opacity: 0.4; pointer-events: none; }

.model-option-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #fff;
  flex-shrink: 0;
}
.model-option.active .model-option-icon { background: var(--accent); }
.model-option:not(.active) .model-option-icon { background: var(--bg-tertiary); }

.model-option-info { flex: 1; min-width: 0; }
.model-option-name { font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.model-option-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.model-option-check { color: var(--accent); font-size: 11px; }

/* === BADGE STATUT === */
.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--bg-tertiary);
  border-radius: 20px;
  font-size: 11px;
  color: var(--text-secondary);
}

.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.status-dot.loading { background: var(--info); animation: pulse 1.5s infinite; }
.status-dot.busy { background: var(--warning); animation: pulse 1.5s infinite; }
.status-dot.offline { background: var(--danger); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* === ZONE DE CHAT === */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  scroll-behavior: smooth;
  overscroll-behavior: contain; /* Empêche le rebond mobile */
}

/* === ÉCRAN D'ACCUEIL === */
.chat-welcome {
  display: flex;
  justify-content: center;
  padding-top: 60px;
}

.welcome-card { text-align: center; max-width: 420px; width: 100%; }

.welcome-icon {
  font-size: 40px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--accent), #0088ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; color: var(--text-primary); }

.welcome-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 24px; line-height: 1.5; }

.welcome-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.welcome-btn {
  text-align: left;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-main);
}
.welcome-btn:hover { border-color: var(--accent); color: var(--text-primary); background: var(--bg-tertiary); }
.welcome-btn i { font-size: 14px; flex-shrink: 0; }

/* === MESSAGES === */
.message {
  display: flex;
  margin-bottom: 16px;
  animation: msgSlideIn 0.3s ease-out;
}
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

@keyframes msgSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-wrapper { max-width: 85%; min-width: 0; }

.message-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.message.user .message-header { justify-content: flex-end; }
.message-header i { font-size: 10px; }
.message.user .message-header i { color: var(--accent); }
.message.assistant .message-header i { color: var(--info); }

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, var(--accent), #0088ff);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* === MARKDOWN / CODE === */
.prose pre {
  background: var(--code-bg) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  overflow-x: auto;
  position: relative;
  margin: 10px 0;
  -webkit-overflow-scrolling: touch;
}

.prose pre code {
  font-family: var(--font-code);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
}

.prose code:not(pre code) {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  color: var(--warning);
  font-family: var(--font-code);
}

.prose p { margin: 6px 0; }
.prose h1, .prose h2, .prose h3 { font-weight: 600; margin: 14px 0 6px; color: var(--text-primary); }
.prose h1 { font-size: 1.2rem; }
.prose h2 { font-size: 1.1rem; }
.prose h3 { font-size: 1rem; }
.prose ul, .prose ol { margin: 6px 0; padding-left: 20px; }
.prose li { margin: 3px 0; }
.prose blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-secondary); margin: 8px 0; }
.prose a { color: var(--accent); text-decoration: underline; }
.prose table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 13px; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px; }
.prose th { background: var(--code-bg); }

.lang-badge {
  position: absolute;
  top: 8px;
  left: 12px;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  transition: var(--transition);
  z-index: 10;
  font-family: var(--font-main);
}
.copy-btn:hover { background: var(--border); color: var(--text-primary); }
.copy-btn.copied { background: var(--accent); color: var(--bg-primary); border-color: var(--accent); }

/* === IMAGES GÉNÉRÉES === */
.image-container { position: relative; display: inline-block; margin: 8px 0; max-width: 100%; }

.generated-image {
  max-width: 100%;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.2s;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}
.generated-image:hover { transform: scale(1.02); }

.image-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  min-height: 200px;
  background: var(--code-bg);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  padding: 24px;
  gap: 10px;
}
.image-loading i { font-size: 24px; }
.image-loading span { font-size: 13px; }

.image-error {
  color: var(--danger);
  font-size: 13px;
  padding: 16px;
  background: var(--code-bg);
  border-radius: var(--radius-md);
  text-align: center;
}

.image-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
.image-modal img { max-width: 92%; max-height: 90vh; border-radius: var(--radius-md); }

.image-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: var(--transition);
}
.image-modal-close:hover { background: var(--danger); border-color: var(--danger); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* === CURSEUR DE FRAPPE === */
.typing-cursor::after {
  content: '▊';
  animation: blink 1s infinite;
  color: var(--accent);
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* === ZONE DE SAISIE === */
.input-area {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  flex-shrink: 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom)); /* Support iPhone notch */
}

.input-wrapper { max-width: 768px; margin: 0 auto; }

.input-form { display: flex; gap: 8px; align-items: flex-end; }

.input-field {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 16px; /* Empêche le zoom auto iOS */
  color: var(--text-primary);
  resize: none;
  max-height: 120px;
  min-height: 48px;
  outline: none;
  transition: var(--transition);
  font-family: var(--font-main);
  line-height: 1.5;
}
.input-field::placeholder { color: var(--text-muted); }
.input-field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

.btn-send {
  width: 48px;
  height: 48px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  color: var(--bg-primary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-hover); box-shadow: 0 0 20px var(--accent-glow); }
.btn-send:disabled { background: var(--bg-tertiary); color: var(--text-muted); cursor: not-allowed; box-shadow: none; }

.input-hint { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 8px; }
.input-hint i { color: var(--warning); margin-right: 4px; }

/* === MODALS === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.show { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1;
}

.modal-title { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.modal-title i { color: var(--accent); }

.btn-close-modal {
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  border: none;
  background: none;
}
.btn-close-modal:hover { color: var(--text-primary); background: var(--bg-tertiary); }

.modal-body { padding: 20px; }

/* === FORMULAIRES === */
.form-group { margin-bottom: 16px; }

.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text-secondary); }
.form-label-row { display: flex; justify-content: space-between; align-items: center; }
.form-label-value { color: var(--accent); font-weight: 600; }

.form-input, .form-textarea {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
  font-family: var(--font-main);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-input:focus, .form-textarea:focus { border-color: var(--accent); }
.form-input.mono { font-family: var(--font-code); font-size: 12px; }

.form-range { width: 100%; accent-color: var(--accent); cursor: pointer; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.preset-buttons { display: flex; gap: 6px; margin-bottom: 8px; }

.btn-preset {
  font-size: 11px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-family: var(--font-main);
}
.btn-preset:hover { border-color: var(--accent); color: var(--text-primary); }
.btn-preset.primary { background: var(--accent); color: var(--bg-primary); border-color: var(--accent); }

.modal-actions { display: flex; gap: 8px; padding-top: 16px; border-top: 1px solid var(--border); }

.btn-secondary {
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-main);
}
.btn-secondary:hover { background: var(--border); color: var(--text-primary); }

.btn-primary {
  flex: 1;
  padding: 10px 16px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--bg-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-main);
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 0 15px var(--accent-glow); }

/* === LOADING OVERLAY === */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 15, 0.9);
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
}
.loading-overlay.show { display: flex; }

.loading-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.loading-subtitle { font-size: 12px; color: var(--text-muted); }

/* === SIDEBAR MOBILE === */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 35;
}
.sidebar-backdrop.show { display: block; }

/* ============================================================
   RESPONSIVE UNIVERSEL - TOUS LES APPAREILS
   ============================================================ */

/* === ULTRA-WIDE (> 1920px) === */
@media (min-width: 1921px) {
  :root {
    --sidebar-width: 320px;
    --header-height: 68px;
  }
  html { font-size: 18px; }
  .input-wrapper { max-width: 900px; }
  .message-wrapper { max-width: 75%; }
  .chat-area { padding: 28px 24px; }
  .welcome-card { max-width: 520px; }
  .welcome-grid { grid-template-columns: 1fr 1fr; }
  .prose pre code { font-size: 14px; }
}

/* === GRAND DESKTOP (1440px - 1920px) === */
@media (min-width: 1440px) and (max-width: 1920px) {
  .input-wrapper { max-width: 820px; }
  .message-wrapper { max-width: 80%; }
}

/* === DESKTOP / LAPTOP (1024px - 1439px) === */
@media (min-width: 1024px) and (max-width: 1439px) {
  :root { --sidebar-width: 260px; }
  .input-wrapper { max-width: 720px; }
  .conv-title { max-width: 240px; }
}

/* === TABLETTE PAYSAGE / PETIT LAPTOP (768px - 1023px) === */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
  }
  .sidebar.open { transform: translateX(0); }
  .btn-menu { display: block; }
  .message-wrapper { max-width: 90%; }
  .welcome-grid { grid-template-columns: 1fr 1fr; }
  .conv-title { max-width: 180px; }
  .chat-area { padding: 16px 14px; }
}

/* === TABLETTE PORTRAIT (600px - 767px) === */
@media (max-width: 767px) {
  :root { --header-height: 56px; }
  .header { padding: 0 12px; }
  .chat-area { padding: 14px 12px; }
  .input-area { padding: 10px 12px; }
  .message-wrapper { max-width: 92%; }
  .welcome-grid { grid-template-columns: 1fr; }
  .welcome-card { padding: 0 8px; }
  .welcome-title { font-size: 20px; }
  .conv-title { max-width: 140px; font-size: 13px; }
  .model-dropdown { width: 260px; }
}

/* === MOBILE (360px - 599px) === */
@media (max-width: 599px) {
  :root {
    --header-height: 52px;
    --sidebar-width: 260px;
  }
  .header { padding: 0 10px; }
  .header-right { gap: 6px; }
  .chat-area { padding: 12px 10px; }
  .input-area { padding: 10px 10px; }
  .message-bubble { padding: 10px 14px; font-size: 13px; }
  .message-wrapper { max-width: 94%; }
  .welcome-title { font-size: 18px; }
  .welcome-subtitle { font-size: 12px; }
  .brand-name { font-size: 14px; }
  .status-badge span { display: none; }
  .status-badge { padding: 5px 8px; }
  .btn-model span { display: none; }
  .btn-model { padding: 6px 10px; }
  .modal { max-width: 100%; border-radius: var(--radius-lg); }
  .modal-overlay { padding: 10px; }
  .prose pre { padding: 10px; }
  .prose pre code { font-size: 12px; }
  .input-field { padding: 10px 14px; }
  .btn-send { width: 44px; height: 44px; }
  .input-hint { font-size: 10px; }
  .image-modal-close { top: 10px; right: 10px; }
}

/* === PETIT MOBILE (< 360px) === */
@media (max-width: 359px) {
  :root { --sidebar-width: 240px; }
  .brand-name { font-size: 13px; }
  .brand-icon { width: 30px; height: 30px; font-size: 14px; }
  .btn-new-chat { font-size: 12px; padding: 9px 12px; }
  .conv-title { max-width: 100px; font-size: 12px; }
  .message-bubble { padding: 9px 12px; font-size: 12.5px; }
  .welcome-title { font-size: 16px; }
  .welcome-btn { font-size: 11px; padding: 10px 12px; }
  .input-field { font-size: 14px; }
  .btn-send { width: 40px; height: 40px; font-size: 14px; }
  .status-badge { display: none; }
  .prose pre code { font-size: 11px; }
}

/* === PAYSAGE MOBILE (hauteur réduite) === */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --header-height: 46px; }
  .chat-welcome { padding-top: 20px; }
  .welcome-icon { font-size: 28px; margin-bottom: 8px; }
  .welcome-title { font-size: 16px; }
  .welcome-subtitle { margin-bottom: 12px; }
  .welcome-grid { grid-template-columns: 1fr 1fr; }
  .input-hint { display: none; }
  .input-area { padding: 8px 10px; }
  .input-field { min-height: 40px; }
  .btn-send { width: 40px; height: 40px; }
  .chat-area { padding: 10px; }
}

/* === SUPPORT ORIENTATION / ROTATION === */
@media (orientation: portrait) {
  .message-wrapper { max-width: 92%; }
}

/* === PRÉFÉRENCES UTILISATEUR (accessibilité) === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .chat-area { scroll-behavior: auto; }
}

@media (prefers-color-scheme: light) {
  /* Garde le thème sombre (design dark-first) */
  :root { color-scheme: dark; }
}

/* === MODE SOMBRE FORCÉ === */
:root { color-scheme: dark; }

/* === ÉCRANS TACTILES (amélioration des zones de clic) === */
@media (pointer: coarse) {
  .btn-menu, .btn-logout, .btn-close-modal { padding: 10px; }
  .conv-item { padding: 12px; }
  .conv-item-delete { opacity: 1; padding: 8px; }
  .btn-model { padding: 8px 12px; }
  .copy-btn { padding: 6px 12px; font-size: 12px; }
  .welcome-btn { padding: 14px; }
  .btn-send { width: 52px; height: 52px; }
  .image-modal-close { width: 48px; height: 48px; }
}

/* === IMPRESSION (si l'utilisateur imprime le chat) === */
@media print {
  body { overflow: visible; height: auto; }
  .sidebar, .header, .input-area, .modal-overlay, .loading-overlay { display: none !important; }
  .chat-area { overflow: visible; padding: 0; }
  .message-bubble { border: 1px solid #ccc; background: #fff !important; color: #000 !important; }
  .prose pre { border: 1px solid #ccc; }
}

/* === UTILITAIRES === */
.fade-in { animation: fadeIn 0.3s ease; }
.slide-up { animation: slideUp 0.3s ease; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-success { color: var(--success); }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }

/* ============================================================
   AJOUT — COULEUR D'ICÔNE PAR FAMILLE DE PROVIDER OMNIROUTE
   ------------------------------------------------------------
   Repère visuel dans le sélecteur de modèles : chaque famille
   (cloud Claude / GPT / Gemini / DeepSeek / Kimi, ou local)
   reçoit une teinte dédiée sur .model-option-icon, dérivée des
   tokens déjà définis plus haut (aucune nouvelle couleur créée
   hors de la palette existante, sauf 2 teintes de complément).
   ============================================================ */
:root {
  --route-claude: var(--accent);      /* turquoise (déjà la couleur "active") */
  --route-gpt:     var(--success);    /* alias de --accent, cohérent avec l'accent principal */
  --route-gemini:  var(--info);       /* bleu */
  --route-deepseek:#ff8a3d;           /* corail — variation chaude complémentaire */
  --route-kimi:    #c084fc;           /* violet clair — variation complémentaire */
  --route-local:   var(--warning);    /* ambre, pour distinguer clairement le local du cloud */
}

.model-option-icon[data-route="claude"]  { background: var(--route-claude) !important; }
.model-option-icon[data-route="gpt"]     { background: var(--route-gpt) !important; }
.model-option-icon[data-route="gemini"]  { background: var(--route-gemini) !important; }
.model-option-icon[data-route="deepseek"]{ background: var(--route-deepseek) !important; }
.model-option-icon[data-route="kimi"]    { background: var(--route-kimi) !important; }
.model-option-icon[data-route="local"]   { background: var(--route-local) !important; }

/* Sur les modèles inactifs on garde une bordure de la même teinte
   plutôt qu'un fond plein, pour ne pas concurrencer l'état "actif" */
.model-option:not(.active) .model-option-icon[data-route] {
  background: var(--bg-tertiary) !important;
  border: 1.5px solid currentColor;
}
.model-option-icon[data-route="claude"]:not(.active-icon)   { color: var(--route-claude); }
.model-option:not(.active) .model-option-icon[data-route="gpt"]      { color: var(--route-gpt); }
.model-option:not(.active) .model-option-icon[data-route="gemini"]   { color: var(--route-gemini); }