/* ============================================================
   Style global - Chantier La Vaupalière
   ============================================================ */

:root {
  --primary:       #1E3A5F;
  --primary-light: #2E5491;
  --accent:        #F59E0B;
  --success:       #10B981;
  --danger:        #EF4444;
  --warning:       #F59E0B;
  --info:          #3B82F6;
  --bg:            #F1F5F9;
  --sidebar-bg:    #1E3A5F;
  --card:          #FFFFFF;
  --text:          #1E293B;
  --text-muted:    #64748B;
  --border:        #E2E8F0;
  --shadow:        0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:     0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --radius:        8px;
  --sidebar-w:     240px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-light); }
img { max-width: 100%; }
ul { list-style: none; }
button { cursor: pointer; }

/* ---- Layout ---- */
.app-wrapper { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform .25s ease;
}
.sidebar-logo {
  padding: 18px 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.sidebar-logo img { width: 100%; max-width: 160px; height: auto; object-fit: contain; }
.sidebar-logo .site-name { font-size: .78rem; font-weight: 800; line-height: 1.3; letter-spacing: .06em; text-transform: uppercase; color: #fff; }
.sidebar-logo .site-sub  { font-size: .65rem; opacity: .65; text-transform: uppercase; letter-spacing: .05em; margin-top: -6px; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-section { padding: 8px 16px 4px; font-size: .65rem; font-weight: 600; opacity: .5; text-transform: uppercase; letter-spacing: .08em; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px;
  font-size: .875rem;
  color: rgba(255,255,255,.75);
  border-radius: 6px;
  margin: 1px 8px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: .8rem;
}
.sidebar-user { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; color: #fff; flex-shrink: 0;
}
.user-info .name { font-weight: 600; color: #fff; }
.user-info .role { opacity: .6; font-size: .7rem; }
.btn-logout {
  margin-top: 8px; width: 100%;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  color: rgba(255,255,255,.8);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: .8rem;
  transition: background .15s;
}
.btn-logout:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ---- Main content ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;   /* CRITIQUE : empêche le flex-item d'élargir la page */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Header ---- */
.main-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.page-title { font-size: 1.1rem; font-weight: 700; color: var(--primary); }
.header-actions { display: flex; gap: 10px; align-items: center; }

/* ---- Page body ---- */
.page-body { padding: 28px; flex: 1; overflow-x: hidden; }

/* ---- Cards ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: #FAFBFC;
}
.card-title { font-weight: 700; font-size: .95rem; color: var(--text); }
.card-body { padding: 20px; }

/* ---- Stat cards ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px;
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 24px; height: 24px; }
.stat-icon.blue   { background: #EFF6FF; color: #3B82F6; }
.stat-icon.green  { background: #ECFDF5; color: #10B981; }
.stat-icon.orange { background: #FFFBEB; color: #F59E0B; }
.stat-icon.red    { background: #FEF2F2; color: #EF4444; }
.stat-icon.purple { background: #F5F3FF; color: #8B5CF6; }
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: .85rem;
  font-weight: 600;
  border: none;
  transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover  { background: #DC2626; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-secondary { background: #E2E8F0; color: var(--text); }
.btn-secondary:hover { background: #CBD5E1; }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn svg { width: 15px; height: 15px; }

/* ---- Badges / Statuts ---- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .73rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-planifie  { background: #F1F5F9; color: #64748B; }
.badge-en_cours  { background: #EFF6FF; color: #2563EB; }
.badge-termine   { background: #ECFDF5; color: #059669; }
.badge-en_retard { background: #FEF2F2; color: #DC2626; }
.badge-suspendu  { background: #FFF7ED; color: #D97706; }
.badge-a_venir   { background: #F8FAFC; color: #94A3B8; }
.badge-atteint   { background: #ECFDF5; color: #059669; }
.badge-retarde   { background: #FEF2F2; color: #DC2626; }

/* ---- Tables ---- */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th {
  background: #F8FAFC;
  padding: 10px 14px;
  text-align: left;
  font-size: .75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid #F1F5F9; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFBFC; }
.actions-cell { display: flex; gap: 6px; align-items: center; }

/* ---- Formulaires ---- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .82rem; font-weight: 600; color: var(--text); margin-bottom: 5px; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .875rem;
  color: var(--text);
  background: #fff;
  transition: border .15s, box-shadow .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,58,95,.1); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236B7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; padding-right: 36px; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: 3px; }
.required { color: var(--danger); }

/* ---- Modals ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal {
  background: var(--card);
  border-radius: 12px;
  width: 90%; max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  transform: translateY(10px);
  transition: transform .2s;
}
.modal-overlay.active .modal { transform: translateY(0); }
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--primary); }
.modal-close {
  background: none; border: none; font-size: 1.3rem; color: var(--text-muted);
  width: 28px; height: 28px; border-radius: 4px; display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ---- Progress bar ---- */
.progress-wrap { background: #E2E8F0; border-radius: 99px; height: 10px; overflow: hidden; }
.progress-bar  { height: 100%; border-radius: 99px; transition: width .5s ease; background: var(--success); }

/* ---- Timeline jalons ---- */
.timeline { position: relative; padding-left: 32px; }
.timeline::before {
  content: '';
  position: absolute; left: 14px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; margin-bottom: 22px; }
.timeline-dot {
  position: absolute; left: -25px; top: 4px;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--card);
  box-shadow: 0 0 0 2px var(--border);
}
.timeline-content { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.timeline-title { font-weight: 700; font-size: .9rem; }
.timeline-date  { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }
.timeline-desc  { font-size: .82rem; color: var(--text-muted); margin-top: 6px; }

/* ---- Commentaires ---- */
.comment-thread { display: flex; flex-direction: column; gap: 12px; }
.comment-item {
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.comment-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.comment-author { font-weight: 700; font-size: .82rem; color: var(--primary); }
.comment-date   { font-size: .73rem; color: var(--text-muted); }
.comment-body   { font-size: .875rem; color: var(--text); white-space: pre-wrap; }
.comment-form   { margin-top: 14px; display: flex; gap: 10px; }
.comment-form textarea { flex: 1; min-height: 60px; resize: vertical; }

/* ---- File upload zone ---- */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 32px 20px;
  text-align: center;
  transition: border .2s, background .2s;
  cursor: pointer;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--primary); background: #EFF6FF; }
.upload-zone svg { width: 40px; height: 40px; color: var(--text-muted); margin-bottom: 8px; }
.upload-zone p { font-size: .875rem; color: var(--text-muted); }
.upload-zone strong { color: var(--primary); }

/* ---- Document cards ---- */
.docs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: 14px; }
.doc-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  transition: box-shadow .15s;
}
.doc-card:hover { box-shadow: var(--shadow-md); }
.doc-icon { font-size: 2rem; margin-bottom: 8px; }
.doc-name { font-weight: 600; font-size: .875rem; margin-bottom: 4px; word-break: break-word; }
.doc-meta { font-size: .75rem; color: var(--text-muted); }
.doc-actions { margin-top: 10px; display: flex; gap: 6px; }

/* ---- Filtres ---- */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-bar .form-control { width: auto; min-width: 160px; }
.search-input { width: 260px !important; }

/* ---- Toast notifications ---- */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: var(--shadow-md);
  font-size: .875rem;
  min-width: 260px;
  max-width: 360px;
  display: flex; align-items: center; gap: 10px;
  animation: slideIn .2s ease;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error   { border-left: 4px solid var(--danger); }
.toast.info    { border-left: 4px solid var(--info); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 12px; opacity: .4; }
.empty-state p { font-size: .9rem; }

/* ---- Login page ---- */
.login-page {
  min-height: 100vh;
  background: #F1F5F9;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-box {
  display: flex;
  border-radius: 18px;
  overflow: hidden;
  width: 100%; max-width: 820px;
  box-shadow: 0 24px 80px rgba(0,0,0,.18);
  min-height: 480px;
}
/* Panneau gauche — branding */
.login-brand {
  flex: 1;
  background: linear-gradient(160deg, #1E3A5F 0%, #2E5491 60%, #3B6CB5 100%);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 36px;
  text-align: center;
  gap: 24px;
}
.login-brand img {
  width: 100%; max-width: 200px;
  height: auto; object-fit: contain;
  filter: drop-shadow(0 4px 16px rgba(0,0,0,.25));
}
.login-brand-text { color: #fff; }
.login-brand-text h2 {
  font-size: 1.1rem; font-weight: 800;
  letter-spacing: .08em; text-transform: uppercase;
  line-height: 1.3; margin: 0 0 6px;
}
.login-brand-text p {
  font-size: .78rem; opacity: .65;
  text-transform: uppercase; letter-spacing: .05em; margin: 0;
}
/* Panneau droit — formulaire */
.login-form-panel {
  flex: 1;
  background: #fff;
  display: flex; flex-direction: column; justify-content: center;
  padding: 48px 44px;
}
.login-form-panel h3 {
  font-size: 1.25rem; font-weight: 700; color: var(--text);
  margin: 0 0 6px;
}
.login-form-panel .login-subtitle {
  font-size: .82rem; color: var(--text-muted); margin: 0 0 28px;
}
.login-error { background: #FEF2F2; color: #DC2626; border-radius: 8px; padding: 10px 14px; font-size: .82rem; margin-bottom: 16px; display: none; }
.login-error.show { display: block; }
.login-divider { border: none; border-top: 1px solid #E2E8F0; margin: 20px 0; }
/* Responsive : empiler sur mobile */
@media (max-width: 600px) {
  .login-box { flex-direction: column; max-width: 400px; }
  .login-brand { padding: 32px 24px; }
  .login-form-panel { padding: 32px 24px; }
}

/* ---- Responsive ---- */
/* ---- Bouton hamburger (mobile) ---- */
.btn-hamburger {
  display: none;
  align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: none; border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer;
  color: var(--text); flex-shrink: 0;
  transition: background .15s;
}
.btn-hamburger:hover { background: var(--bg); }
.btn-hamburger svg { width: 20px; height: 20px; }

/* ---- Overlay mobile (fond sombre derrière la sidebar) ---- */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 99;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

@media (max-width: 768px) {
  /* Sidebar cachée par défaut, glisse depuis la gauche */
  .sidebar {
    transform: translateX(-100%);
    z-index: 100;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,.3);
  }

  /* Contenu prend tout l'écran */
  .main-content { margin-left: 0; }

  /* Header ajusté : hamburger visible */
  .btn-hamburger { display: flex; }
  .main-header { padding: 0 14px; gap: 10px; }
  .page-title { font-size: .95rem; }

  /* Grilles réduites */
  .form-row    { grid-template-columns: 1fr; }
  .stats-grid  { grid-template-columns: 1fr 1fr; }
  .page-body   { padding: 16px; }

  /* Stats sur 2 colonnes */
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ---- Utilitaires ---- */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
