/* =========================================================
   1. Variables & Thème (Design System)
   ========================================================= */
   :root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --secondary: #64748b;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --bg-color: #f1f5f9;
    --surface: #ffffff;
    --text-main: #0f172a;
    --text-muted: #475569;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --border-radius: 12px;
    --border-light: rgba(0,0,0,0.08);
  
    --barH: 60px;
    --toolsH: 50px;
    --navH: 50px;
    --maxw: 1400px; /* J'ai élargi un peu le site pour que les contenus variables respirent */
  }
  
  /* =========================================================
     2. Reset & Base
     ========================================================= */
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  
  body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-main);
    background-color: var(--bg-color);
    transition: background-color 0.3s ease;
    padding-top: calc(var(--barH) + var(--navH) + 20px);
  }
  
  a { color: var(--primary); text-decoration: none; font-weight: 500; }
  a:hover { color: var(--primary-hover); }
  
  h1, h2, h3 { margin-top: 0; color: var(--text-main); font-weight: 700; }
  h1 { font-size: 2.5rem; margin-bottom: 1rem; }
  
  .page, .wrap {
    width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px;
    animation: fadeIn 0.6s ease-out;
  }
  @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
  
  /* =========================================================
     3. Fonds
     ========================================================= */
  body.accueil {
    --accueil-bg: none;
    background-color: #0f172a;
    background-image: linear-gradient(to bottom, rgba(15,23,42,0.4), rgba(15,23,42,0.8)), var(--accueil-bg);
    background-size: cover; background-position: center; background-attachment: fixed;
    color: white;
    padding-top: calc(var(--barH) + var(--toolsH) + var(--navH) + 20px);
  }
  body.accueil main.page { text-align: center; margin-top: 8vh; }
  body.accueil h1 { color: white; font-size: 3.5rem; text-shadow: 0 4px 12px rgba(0,0,0,0.3); }
  body.accueil h2, body.accueil p { color: rgba(255,255,255,0.9); }
  
  body.entreprise, body.missions, body.bilan {
    background: url("mur_vegetal.png") center/cover fixed no-repeat, var(--bg-color);
  }
  body.entreprise .hero-entreprise h1, body.missions .hero-missions h1, body.bilan > main > h1, body:not(.accueil) .hint {
    color: white; text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  }
  
  /* =========================================================
     4. Barres (Profil, Nav, Outils)
     ========================================================= */
  .profile-bar, .bg-toolbar, nav {
    position: fixed; left: 0; right: 0;
    display: flex; justify-content: center; align-items: center; gap: 10px; padding: 0 1rem;
    background: rgba(15, 23, 42, 0.65); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.1);
  }
  
  .profile-bar { top: 0; height: var(--barH); flex-wrap: wrap; z-index: 2001; }
  .bg-toolbar { top: var(--barH); height: var(--toolsH); z-index: 99; background: rgba(15, 23, 42, 0.5); }
  nav { top: var(--barH); height: var(--navH); z-index: 98; background: rgba(255,255,255,0.1); border-bottom: none; }
  body.accueil nav { top: calc(var(--barH) + var(--toolsH)); }
  
  nav ul { list-style: none; padding: 0; margin: 0; display: flex; gap: 20px; }
  nav a { color: rgba(255,255,255,0.9); padding: 8px 16px; border-radius: 20px; transition: all 0.2s; }
  nav a:hover { background: rgba(255,255,255,0.15); color: white; }
  nav a.active { background: white; color: var(--primary); font-weight: 700; }
  
  .profile-bar label { color: rgba(255,255,255,0.9); font-weight: 600; }
  .profile-bar input {
    background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.2); color: white;
    padding: 6px 12px; border-radius: 6px; outline: none;
  }
  .profile-bar input:focus { border-color: var(--primary); background: rgba(0,0,0,0.5); }
  
  /* =========================================================
     5. Boutons
     ========================================================= */
  .btn, .btn-secondary, .btn-danger {
    border: none; cursor: pointer; padding: 8px 16px; border-radius: 8px; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .btn { background: var(--primary); color: white; }
  .btn:hover { background: var(--primary-hover); }
  
  .profile-bar .btn, .profile-bar .btn-secondary { background: rgba(255,255,255,0.15); backdrop-filter: blur(4px); color: white; }
  .profile-bar .btn:hover, .profile-bar .btn-secondary:hover { background: rgba(255,255,255,0.25); }
  .profile-bar .btn-danger { background: var(--danger); color: white; }
  
  .card .btn-secondary, .mission .btn-secondary { background: #e2e8f0; color: var(--text-main); }
  .card .btn-secondary:hover, .mission .btn-secondary:hover { background: #cbd5e1; }
  
  /* =========================================================
     6. Contenu (Cartes Ajustables)
     ========================================================= */
  
  /* MODIF : On passe de Grid à Flex pour que les éléments aient des tailles variées */
  .missions-grid, .doc {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    justify-content: center; /* Centre les éléments sur la page */
    align-items: flex-start; /* Évite que les cartes s'étirent en hauteur */
  }
  
  /* Style des cartes (Missions, Images, Semaines) */
  .card, .mission, .doc-page, .week {
    background: var(--surface);
    color: var(--text-main);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    margin-bottom: 20px;
    
    /* MODIF : S'ajuste au contenu */
    width: fit-content;
    min-width: 320px; /* Taille minimum pour ne pas être illisible */
    max-width: 100%;  /* Ne dépasse pas l'écran */
    flex: 0 1 auto;   /* Flexibilité naturelle */
  }
  
  /* Cas spécifique pour les images (Entreprise) */
  .doc-page {
    max-width: 100%; /* Permet à l'image de prendre de la place */
  }
  
  /* Cas spécifique pour les missions/bilans (Texte) */
  .mission, .week {
    max-width: 900px; /* On limite la largeur max pour que le texte reste lisible */
  }
  
  .mission:hover, .doc-page:hover, .week:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
  }
  
  /* Image dans la galerie */
  .page-media { 
    display: block;
    max-width: 100%; /* L'image ne dépasse pas le conteneur */
    height: auto;
    border-radius: 8px;
    margin-bottom: 10px; 
    cursor: zoom-in;
    transition: opacity 0.2s;
  }
  .page-media:hover { opacity: 0.9; }
  
  .mission-head { display: flex; justify-content: space-between; margin-bottom: 16px; border-bottom: 1px solid #e2e8f0; padding-bottom: 12px; }
  .mission-head h2 { margin: 0; font-size: 1.4rem; color: var(--primary); }
  
  .chips { display: flex; gap: 8px; flex-wrap: wrap; }
  .chip { padding: 4px 10px; border-radius: 20px; background: #eff6ff; color: var(--primary); border: 1px solid #dbeafe; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; }
  
  .mission ul { list-style: none; padding: 0; }
  .mission li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed #e2e8f0; }
  
  .editable[contenteditable] { padding: 2px 4px; border-radius: 4px; outline: none; }
  .editable[contenteditable]:hover { background: rgba(0,0,0,0.03); }
  .editable[contenteditable]:focus { background: #eff6ff; box-shadow: 0 0 0 2px var(--primary); }
  .editable[contenteditable]:empty:before { content: attr(data-placeholder); color: #94a3b8; font-style: italic; }
  
  .doc-toolbar { background: rgba(255,255,255,0.1); backdrop-filter: blur(4px); padding: 10px; border-radius: 12px; margin-bottom: 24px; display: flex; align-items: center; gap: 15px; border: 1px solid rgba(255,255,255,0.2); }
  
  /* =========================================================
     7. Gate (Login)
     ========================================================= */
  .profile-gate {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    background: rgba(15, 23, 42, 0.9); backdrop-filter: blur(10px);
    z-index: 2000;
  }
  .profile-gate[hidden] { display: none !important; } 
  
  .gate-card {
    background: white; padding: 40px 30px; border-radius: 20px; text-align: center;
    max-width: 450px; width: 90%; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
    border: 1px solid rgba(255, 255, 255, 0.1); animation: popIn 0.4s;
  }
  @keyframes popIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
  
  .gate-card h2 { color: #1e293b !important; font-size: 1.4rem; margin: 0; }
  .gate-card h2::after { content: ""; display: block; width: 50px; height: 4px; background: var(--primary); margin: 15px auto 0; border-radius: 2px; }
  
  body.locked nav, body.locked .bg-toolbar, body.locked main, body.locked footer { display: none !important; }
  
  /* =========================================================
     8. LIGHTBOX (Zoom Image)
     ========================================================= */
  #lightbox {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.92); z-index: 5000;
    display: flex; justify-content: center; align-items: center;
    cursor: zoom-out; opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
  }
  #lightbox.active { opacity: 1; pointer-events: auto; }
  #lightbox img {
    max-width: 90vw; max-height: 90vh;
    border-radius: 4px; box-shadow: 0 0 20px rgba(0,0,0,0.5);
    transform: scale(0.95); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  }
  #lightbox.active img { transform: scale(1); }
  
  /* =========================================================
     9. MODE DIAPORAMA (CORRIGÉ & RESPECTUEUX DU DESIGN)
     ========================================================= */
  
  /* Masquer l'interface purement et simplement */
  body.slideshow nav, 
  body.slideshow .profile-bar, 
  body.slideshow .bg-toolbar,
  body.slideshow .doc-toolbar, 
  body.slideshow .doc-actions, 
  body.slideshow .mission-actions,
  body.slideshow .picker,
  body.slideshow .btn, 
  body.slideshow .btn-secondary, 
  body.slideshow .btn-danger,
  body.slideshow input[type="file"] {
    display: none !important;
  }
  
  /* Le corps de page en diapo */
  body.slideshow {
    /* On annule juste le padding du haut (puisque les barres sont cachées) */
    padding-top: 20px !important;
    overflow-y: auto !important;
    /* Le fond reste celui de la page (mur végétal ou accueil) */
  }
  
  /* La page elle-même garde ses propriétés */
  body.slideshow .page {
    margin: 0 auto;
  }
  
  /* On s'assure que le layout Flexbox créé plus haut reste actif */
  body.slideshow .missions-grid, 
  body.slideshow .doc {
    /* Hérite des propriétés normales définies en section 6 */
  }
  
  /* Désactiver l'édition */
  body.slideshow [contenteditable] {
    pointer-events: none !important;
    user-select: none !important;
    outline: none !important;
    border: none !important;
    background: transparent !important;
  }
  
  body.slideshow .editable[contenteditable]:empty:before { content: "" !important; }
  
  body.slideshow::after {
    content: "Mode Diaporama (Échap pour quitter)";
    position: fixed; bottom: 10px; right: 10px;
    background: rgba(0,0,0,0.5); color: white; 
    padding: 4px 10px; border-radius: 10px;
    font-size: 0.7rem; pointer-events: none; opacity: 0.5;
  }
  
  /* =========================================================
     10. Mobile & Footer
     ========================================================= */
  .site-footer { text-align: center; padding: 40px; color: rgba(255,255,255,0.6); }
  body:not(.accueil):not(.entreprise):not(.missions):not(.bilan) .site-footer { color: var(--text-muted); }
  
  @media (max-width: 768px) {
    .profile-bar { position: relative; flex-direction: column; height: auto; padding: 10px; }
    nav { position: relative; top: 0; height: auto; overflow-x: auto; justify-content: flex-start; }
    body { padding-top: 0; }
    .missions-grid, .doc { grid-template-columns: 1fr; }
  }
  @media print {
    .profile-bar, nav, .bg-toolbar, .btn, .doc-toolbar { display: none !important; }
    body { background: white !important; color: black !important; padding: 0 !important; }
    .card, .mission { border: 1px solid #ccc !important; box-shadow: none !important; }
  }