* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, sans-serif; background: #f4f4f9; height: 100vh; height: 100dvh; }

/* Page de connexion */
.auth-box { max-width: 380px; margin: 10vh auto; background: #fff; padding: 2rem;
  border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.1); }
.auth-box h1 { margin-bottom: 1rem; }
.auth-box form { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.auth-box input, .auth-box select, .sidebar input, .sidebar select, #chat-input { padding: .6rem; border: 1px solid #ccc; border-radius: 6px; }
.auth-box button { padding: .6rem; background: #4a5fd4; color: #fff; border: 0; border-radius: 6px; cursor: pointer; }
.error { color: #c0392b; font-size: .85rem; }
.recovery { background: #fff8dc; padding: .8rem; border-radius: 6px; word-break: break-all; }
.recovery code { display: block; margin-top: .5rem; }

/* Application */
.layout { display: flex; height: 100vh; height: 100dvh; }
.sidebar { width: 300px; background: #2c3140; color: #fff; padding: 1rem; display: flex; flex-direction: column; }
.sidebar h1 { font-size: 1.2rem; margin-bottom: 1rem; }
.sidebar form { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.sidebar button { padding: .5rem; background: #4a5fd4; color: #fff; border: 0; border-radius: 6px; cursor: pointer; }
#conversation-list { flex: 1; min-height: 0; overflow-y: auto; list-style: none; }
#conversation-list li { display: flex; justify-content: space-between; align-items: center;
  padding: .55rem; margin-bottom: .25rem; border-radius: 6px; cursor: pointer; }
#conversation-list li:hover, #conversation-list li.active { background: #3d4356; }
.conv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }                                                                                                                                                                      
.conv-actions { flex-shrink: 0; }      
.conv-actions button { background: none; border: 0; cursor: pointer; }
.sidebar-footer { margin-top: .5rem; display: flex; flex-direction: column; align-items: flex-start; gap: .4rem; }                                                                                                                                                          
.sidebar-footer [hidden] { display: none; } /* filet de sécurité : jamais visible tant que app.js ne l'a pas autorisé */     
main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#chat-area { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 1rem; }                                                                                                                                                                                
#messages { flex: 1; min-height: 0; overflow-y: auto; } 
.message { max-width: 70%; margin-bottom: .6rem; padding: .6rem .9rem; border-radius: 10px; white-space: pre-wrap; overflow-wrap: break-word; }
.message.user { background: #4a5fd4; color: #fff; margin-left: auto; }
.message.assistant { background: #e8e8f0; }
#chat-form { display: flex; gap: .5rem; }
#chat-input { flex: 1; min-width: 0; }
#chat-form[hidden] { display: none; }
#chat-form button { padding: .5rem 1rem; background: #4a5fd4; color: #fff; border: 0; border-radius: 6px; cursor: pointer; }
.placeholder { color: #888; text-align: center; margin-top: 2rem; }
#usage-panel { border-top: 1px solid #ddd; background: #fff; padding: .8rem 1rem; }
#usage-panel table { width: 100%; font-size: .85rem; }
#usage-panel th, #usage-panel td { text-align: left; padding: .25rem .5rem; }
/* Entête du chat : ☰ (mobile), titre et modèle de la conversation ouverte */                                                                                                                                                                                              
#chat-header { display: flex; align-items: center; gap: .8rem; min-height: 3rem;                                                                                                                                                                                            
  padding: .4rem 1rem; background: #fff; border-bottom: 1px solid #ddd; }                                                                                                                                                                                                   
#chat-header button { background: none; border: 0; padding: .2rem .5rem;                                                                                                                                                                                                    
  font-size: 1.25rem; color: #2c3140; cursor: pointer; }                                                                                                                                                                                                                    
#sidebar-toggle { display: none; } /* desktop : la sidebar y est permanente */                                                                                                                                                                                              
#chat-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }                                                                                                                                                             
#chat-model { flex-shrink: 0; margin-left: auto; font-size: .75rem;                                                                                                                                                                                                         
  background: #eef0fb; color: #4a5fd4; border-radius: 999px; padding: .25rem .7rem; }                                                                                                                                                                                       
#backdrop { display: none; }     

/* ===== Mobile / petits écrans (app.html) ===== */
@media (max-width: 768px) {
  /* Entête mobile : bouton menu visible + marges resserrées */                                                                                                                                                                                                             
  #sidebar-toggle { display: inline-block; }                                                                                                                                                                                                                                
  #chat-header { padding: .4rem .8rem; }                                                                                                                                                                                                                                    
  #chat-model { font-size: .7rem; }
  
  /* Modale : presque plein écran sur téléphone */
  #model-compare-modal.open { padding: .5rem; }
  .modal-box { max-height: 90vh; max-height: 90dvh; }

  /* La sidebar devient un tiroir coulissant au-dessus du chat */
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 20;
    width: min(85vw, 320px); transform: translateX(-100%);
    transition: transform .25s ease; box-shadow: 0 0 20px rgba(0,0,0,.35); }
  body.sidebar-open .sidebar { transform: translateX(0); }

  /* Voile sombre : clic = fermeture du tiroir */
  #backdrop { display: block; position: fixed; inset: 0; z-index: 10;
    background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .25s ease; }
  body.sidebar-open #backdrop { opacity: 1; pointer-events: auto; }

  /* Chat : plein écran, bulles plus larges pour la lisibilité */
  #chat-area { padding: .6rem; }
  .message { max-width: 85%; }

  /* Table de consommation : défilement horizontal au lieu du débordement */
  #usage-panel { overflow-x: auto; padding: .6rem; }
  #usage-panel table { font-size: .75rem; }
  #usage-panel th, #usage-panel td { padding: .2rem .3rem; }

  /* iOS : police >= 16px dans les champs pour éviter le zoom automatique au focus */
  input, select, button { font-size: 1rem; }
}

/* ===== Markdown (réponses de l'IA — rendu sécurisé côté client) ===== */                                                                                                                                                                                                  
.md { line-height: 1.55; white-space: normal; }                                                                                                                                                                                                                             
.md > :first-child { margin-top: 0; }                                                                                                                                                                                                                                       
.md > :last-child { margin-bottom: 0; }                                                                                                                                                                                                                                     
.md p { margin-bottom: .6rem; }                                                                                                                                                                                                                                             
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: .8rem 0 .35rem; line-height: 1.3; }                                                                                                                                                                                
.md h1 { font-size: 1.25rem; }                                                                                                                                                                                                                                              
.md h2 { font-size: 1.15rem; }                                                                                                                                                                                                                                              
.md h3 { font-size: 1.05rem; }                                                                                                                                                                                                                                              
.md h4, .md h5, .md h6 { font-size: 1rem; }                                                                                                                                                                                                                                 
.md ul, .md ol { margin: .4rem 0 .6rem; padding-left: 1.4rem; }                                                                                                                                                                                                             
.md li { margin-bottom: .25rem; }                                                                                                                                                                                                                                           
.md blockquote { border-left: 3px solid #c9cfe0; margin: .4rem 0 .6rem; padding-left: .7rem; color: #444; }                                                                                                                                                                 
.md a { color: #4a5fd4; }                                                                                                                                                                                                                                                   
.md code { background: rgba(0,0,0,.08); border-radius: 4px; padding: .1rem .3rem;                                                                                                                                                                                           
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }                                                                                                                                                                                 
.md pre { background: #2c3140; color: #f4f4f9; border-radius: 8px; overflow-x: auto;                                                                                                                                                                                        
  padding: .7rem .9rem; margin: .4rem 0 .6rem; }                                                                                                                                                                                                                            
.md pre code { background: none; color: inherit; padding: 0; font-size: .85rem; }                                                                                                                                                                                           
.md hr { border: 0; border-top: 1px solid #ccc; margin: .6rem 0; }  

/* ===== Modale : comparaison des modèles IA ===== */
.link-btn { padding: .2rem 0; background: none; border: 0; color: #b9c0d8;
  text-decoration: underline; cursor: pointer; font-size: .78rem; text-align: left; }
.link-btn:hover { color: #fff; }

#model-compare-modal { display: none; }
#model-compare-modal.open { display: flex; position: fixed; inset: 0; z-index: 50;
  align-items: center; justify-content: center; background: rgba(0,0,0,.55); padding: 1rem; }
.modal-box { background: #fff; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.3);
  width: 100%; max-width: 900px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center;
  padding: .9rem 1.2rem; border-bottom: 1px solid #ddd; flex-shrink: 0; }
.modal-head h2 { font-size: 1.1rem; }
.modal-head button { background: none; border: 0; font-size: 1.1rem; cursor: pointer;
  color: #666; padding: .2rem .4rem; border-radius: 6px; }
.modal-scroll { overflow-y: auto; padding: .9rem 1.2rem 1.2rem; min-height: 0; }
.modal-note { font-size: .78rem; color: #666; background: #fafafc; border: 1px solid #eee;
  border-radius: 8px; padding: .6rem .8rem; margin-bottom: .8rem; }
.modal-footnote { font-size: .72rem; color: #888; margin-top: .6rem; }
.table-wrap { overflow-x: auto; } /* mobile : scroll horizontal du tableau */
#model-compare-table { border-collapse: collapse; width: 100%; font-size: .85rem; min-width: 640px; }
#model-compare-table th, #model-compare-table td { border-bottom: 1px solid #eee;
  padding: .5rem .6rem; text-align: left; vertical-align: top; }
#model-compare-table th { background: #fafafc; }
#model-compare-table td.crit { font-weight: 600; white-space: nowrap; }
.warn-cost { display: block; background: #fdecea; color: #c0392b; border-radius: 6px;
  padding: .15rem .5rem; font-weight: 600; font-size: .75rem; margin-top: .3rem; }
.warn-privacy { display: inline-block; background: #fff3cd; color: #8a6d00; border-radius: 6px;
  padding: .15rem .5rem; font-weight: 600; font-size: .75rem; }

/* ===== Administration (admin.html) ===== */
.admin-container { max-width: 960px; margin: 0 auto; padding: 2rem 1rem; }
.admin-container [hidden] { display: none !important; }
.admin-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .8rem; margin-bottom: 1.5rem; }
.admin-header h1 { font-size: 1.4rem; }
.admin-actions { display: flex; align-items: center; gap: 1rem; }
.admin-actions a { color: #4a5fd4; text-decoration: none; font-size: .9rem; }
.admin-error { background: #fdecea; color: #c0392b; padding: .8rem 1rem; border-radius: 6px; margin-bottom: 1.5rem; font-size: .9rem; }
.btn { padding: .5rem .9rem; background: #4a5fd4; color: #fff; border: 0; border-radius: 6px; cursor: pointer; font-size: .85rem; }
.btn.ghost { background: #fff; color: #4a5fd4; border: 1px solid #4a5fd4; }
.btn.danger { background: #c0392b; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; }
.stat-card { background: #fafafc; border: 1px solid #eee; border-radius: 8px; padding: .9rem 1rem; }
.stat-value { font-size: 1.25rem; font-weight: 600; }
.stat-label { font-size: .78rem; color: #666; margin-top: .15rem; }
.admin-section { background: #fff; border-radius: 10px; box-shadow: 0 1px 6px rgba(0,0,0,.08); padding: 1rem 1.2rem; margin-bottom: 1.5rem; }
.admin-section h2 { font-size: 1rem; margin-bottom: .8rem; }
.detail-subtitle { font-size: .9rem; margin: 1.2rem 0 .6rem; color: #555; }
.admin-section table { width: 100%; font-size: .9rem; border-collapse: collapse; }
.admin-section th, .admin-section td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid #eee; }
.admin-section tr:last-child td { border-bottom: 0; }
.detail-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
.reset-result { background: #fff8dc; padding: .8rem 1rem; border-radius: 6px; margin-top: 1rem; font-size: .9rem; }
.reset-result p { margin-top: .4rem; }
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .75rem; }
.badge.active { background: #e6f4ea; color: #1e7e34; }
.badge.disabled { background: #fdecea; color: #c0392b; }
.badge.admin { background: #eef0fb; color: #4a5fd4; }
.badge.neutral { background: #eee; color: #555; }
.invite-form { display: flex; gap: .5rem; margin-bottom: .8rem; }                                                                                                                                                                                                           
.invite-form input { flex: 1; padding: .5rem; border: 1px solid #ccc; border-radius: 6px; }
/* Récapitulatif mensuel + formulaire de quota (admin) */                                                                                                                                                                                                                   
.monthly-controls { display: flex; align-items: center; gap: .5rem; margin-bottom: .7rem; }                                                                                                                                                                                 
.monthly-controls select { padding: .3rem .5rem; }                                                                                                                                                                                                                          
#admin-monthly-table tfoot td { font-weight: 700; border-top: 2px solid currentColor; }                                                                                                                                                                                     
.quota-form { display: flex; gap: .6rem; align-items: center; margin: .4rem 0 1rem; }                                                                                                                                                                                       
.quota-form input { max-width: 130px; padding: .35rem .5rem; } 