/* ═══════════════════════════════════════════════════════════════════════════
   main.css — Styles complets de Hermes Chat
   Thème sombre moderne, inspiré de Claude/ChatGPT
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Variables CSS ──────────────────────────────────────────────────────── */
:root {
  /* Palette principale */
  --bg-primary:    #0f0f0f;
  --bg-secondary:  #171717;
  --bg-tertiary:   #1e1e1e;
  --bg-hover:      #2a2a2a;
  --bg-active:     #333333;

  /* Texte */
  --text-primary:  #f0f0f0;
  --text-secondary:#b0b0b0;
  --text-muted:    #6b6b6b;

  /* Accent */
  --accent:        #8b5cf6;
  --accent-hover:  #7c3aed;
  --accent-light:  rgba(139, 92, 246, 0.15);

  /* Bordures */
  --border:        rgba(255, 255, 255, 0.08);
  --border-hover:  rgba(255, 255, 255, 0.15);

  /* Messages */
  --msg-user-bg:   #1e1b2e;
  --msg-user-border: rgba(139, 92, 246, 0.3);
  --msg-ai-bg:     #1a1a1a;

  /* Status */
  --success:       #22c55e;
  --danger:        #ef4444;
  --danger-hover:  #dc2626;
  --warning:       #f59e0b;

  /* Layout */
  --sidebar-width: 260px;
  --header-height: 56px;

  /* Animations */
  --transition:    150ms ease;
}

/* ─── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100dvh;
  overflow: hidden;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Utilitaires ────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); font-size: 0.8rem; }

/* ─── Boutons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 7px 14px; font-size: 0.85rem; }

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 16px;
  transition: all var(--transition);
}
.btn-new-chat:hover { background: rgba(139, 92, 246, 0.25); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn-danger:hover { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* ─── Formulaires ────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-group input,
.form-group textarea,
.settings-textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.95rem;
  padding: 10px 14px;
  transition: border-color var(--transition);
  outline: none;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.settings-textarea:focus {
  border-color: var(--accent);
}

.form-hint {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 8px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   ÉCRAN D'AUTHENTIFICATION
   ═══════════════════════════════════════════════════════════════════════════ */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 0%, rgba(139, 92, 246, 0.12) 0%, transparent 70%),
              var(--bg-primary);
}

.auth-container {
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 36px;
}

.auth-logo-icon {
    width: 120px;
    height: 120px;
    object-fit: contain;
}

.auth-logo-title {
  font-size: 1.0rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.auth-logo-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 2px;
}

.auth-form {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
}

.auth-form h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 24px;
}

.auth-switch {
  text-align: center;
  margin-top: 16px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════════
   LAYOUT PRINCIPAL
   ═══════════════════════════════════════════════════════════════════════════ */
.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
  transition: transform 300ms ease;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 600;
}

.sidebar-logo-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  vertical-align: middle;
}

.sidebar-logo-text { color: var(--text-primary); }

/* Bouton toggle sidebar (visible mobile) */
.sidebar-toggle { display: none; }

.sidebar > .btn-new-chat {
  margin: 14px 12px 0;
  width: calc(100% - 24px);
}

.sidebar-section-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 14px 16px 6px;
}

/* ─── Liste des chats ─────────────────────────────────────────────────────── */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-active) transparent;
}

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-track { background: transparent; }
.chat-list::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 2px; }

.chat-list-empty {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.8;
}

/* Item de conversation dans la sidebar */
.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
  min-height: 40px;
}

.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }

.chat-item-title {
  flex: 1;
  font-size: 0.88rem;
  color: var(--text-primary);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.chat-item-actions {
  display: none;
  gap: 2px;
  flex-shrink: 0;
}

.chat-item:hover .chat-item-actions,
.chat-item.active .chat-item-actions {
  display: flex;
}

.chat-item .icon-btn {
  width: 26px;
  height: 26px;
}

/* ─── Footer sidebar ─────────────────────────────────────────────────────── */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-footer-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.88rem;
  transition: background var(--transition);
  overflow: hidden;
}

.sidebar-footer-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ─── Zone principale ───────────────────────────────────────────────────── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
}

/* Header mobile (masqué sur desktop) */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.mobile-chat-title {
  font-size: 0.95rem;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* ─── Vue d'accueil ──────────────────────────────────────────────────────── */
.welcome-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome-content {
  text-align: center;
  max-width: 400px;
  padding: 40px 20px;
}

.welcome-icon img {
  width: 180px;   /* ajuste selon tes besoins */
  height: 180px;
  object-fit: contain;
}

.welcome-content h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.welcome-content p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 0.95rem;
}

/* ─── Vue de conversation ────────────────────────────────────────────────── */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.chat-title-display {
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: calc(100% - 80px);
}

.chat-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ─── Messages ───────────────────────────────────────────────────────────── */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-active) transparent;
}

.messages-container::-webkit-scrollbar { width: 5px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 3px; }

.messages-list {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Message générique */
.message {
  display: flex;
  gap: 14px;
  animation: fadeIn 200ms ease;
}

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

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  font-weight: 700;
}

.message-user .message-avatar {
  background: var(--accent);
  color: #fff;
}

.message-assistant .message-avatar {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  font-size: 1.1rem;
}

.message-body { flex: 1; min-width: 0; }

.message-role {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.message-content {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-primary);
  word-break: break-word;
  white-space: pre-wrap;
}

/* Code blocks dans les messages */
.message-content code {
  background: var(--bg-active);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.88em;
  color: #e2b96f;
}

.message-content pre {
  background: var(--bg-active);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
  margin: 10px 0;
}

.message-content pre code {
  background: none;
  padding: 0;
  color: var(--text-primary);
}

/* Indicateur de saisie IA */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 6px 0;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-pulse 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(1); }
  40% { opacity: 1; transform: scale(1.2); }
}

/* ─── Zone de saisie ─────────────────────────────────────────────────────── */
.input-area {
  padding: 16px 20px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.input-wrapper {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  transition: border-color var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--accent);
}

.message-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.message-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), opacity var(--transition);
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint {
  max-width: 760px;
  margin: 6px auto 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
}

.modal-box {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 540px;
  max-height: 90dvh;
  overflow-y: auto;
  z-index: 1;
  scrollbar-width: thin;
}

.modal-box-sm { max-width: 400px; }

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

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
}

.modal-body { padding: 20px 24px 24px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* Paramètres */
.settings-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

#settings-username-display {
  font-weight: 700;
  font-size: 1rem;
}

.badge {
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 500;
}

.settings-section {
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child { border-bottom: none; }

.settings-section h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.settings-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.settings-textarea {
  width: 100%;
  resize: vertical;
  min-height: 90px;
}

.settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.settings-actions.gap { gap: 10px; flex-wrap: wrap; }

.settings-danger-zone h4.danger-title { color: var(--danger); }

.settings-message {
  margin-top: 16px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
}

.settings-message.success {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.settings-message.error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOASTS
   ═══════════════════════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.88rem;
  color: var(--text-primary);
  pointer-events: auto;
  animation: slideInRight 200ms ease;
  max-width: 320px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--accent); }

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

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
  }

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

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    backdrop-filter: blur(2px);
  }

  .mobile-header { display: flex; }

  .chat-header { display: none; }

  .messages-list { padding: 0 12px; }

  .input-area { padding: 10px 12px 8px; }

  .input-hint { display: none; }

  .auth-form { padding: 24px 20px; }
}

@media (max-width: 480px) {
  .modal { padding: 10px; }
  .modal-body { padding: 16px 16px 20px; }
  .modal-header { padding: 16px 16px 12px; }
}
