:root{
  --primary:#4f46e5;
  --primary-dark:#4338ca;
  --bg:#f3f4f6;
  --card:#ffffff;
  --text:#1f2937;
  --text-light:#6b7280;
  --border:#e5e7eb;
  --success:#10b981;
  --danger:#ef4444;
  --warning:#f59e0b;
  --radius:12px;
  --shadow:0 4px 20px rgba(0,0,0,0.06);
}
*{box-sizing:border-box;margin:0;padding:0}
body{font-family:'Segoe UI',system-ui,-apple-system,sans-serif;background:var(--bg);color:var(--text);-webkit-font-smoothing:antialiased}

/* LOGIN */
.login-body{min-height:100vh;display:flex;align-items:center;justify-content:center;
  background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);padding:20px}
.login-container{width:100%;max-width:420px}
.login-card{background:#fff;border-radius:20px;padding:40px 32px;box-shadow:0 20px 60px rgba(0,0,0,.25)}
.logo{text-align:center;margin-bottom:32px}
.logo-icon{width:64px;height:64px;border-radius:16px;background:linear-gradient(135deg,var(--primary),#8b5cf6);
  color:#fff;font-size:32px;font-weight:700;display:flex;align-items:center;justify-content:center;margin:0 auto 12px}
.logo-icon.small{width:36px;height:36px;font-size:18px;border-radius:10px;margin:0}
.logo h1{font-size:24px;margin-bottom:4px}
.logo p{color:var(--text-light);font-size:14px}
.form-group{margin-bottom:18px}
.form-group label{display:block;font-size:13px;font-weight:600;margin-bottom:6px;color:var(--text)}
.form-group input,.form-group select,.form-group textarea{
  width:100%;padding:12px 14px;border:2px solid var(--border);border-radius:10px;font-size:15px;
  transition:border-color .2s,box-shadow .2s;font-family:inherit;background:#fff}
.form-group input:focus,.form-group select:focus,.form-group textarea:focus{
  outline:none;border-color:var(--primary);box-shadow:0 0 0 4px rgba(79,70,229,.1)}
.btn{padding:11px 18px;border:none;border-radius:10px;font-size:15px;font-weight:600;cursor:pointer;
  transition:all .2s;font-family:inherit;display:inline-flex;align-items:center;justify-content:center;gap:8px}
.btn-primary{background:var(--primary);color:#fff}
.btn-primary:hover{background:var(--primary-dark);transform:translateY(-1px)}
.btn-danger{background:var(--danger);color:#fff}
.btn-danger:hover{background:#dc2626}
.btn-block{width:100%}
.error-msg{color:var(--danger);font-size:14px;text-align:center;margin-top:12px;min-height:20px}
.demo-info{margin-top:24px;padding:14px;background:#f9fafb;border-radius:10px;font-size:12px;color:var(--text-light);text-align:center}
.demo-info p{margin:2px 0}

/* APP LAYOUT */
.app{display:flex;min-height:100vh}
.sidebar{width:260px;background:#fff;border-right:1px solid var(--border);display:flex;flex-direction:column;
  position:fixed;height:100vh;left:0;top:0;z-index:100;transition:transform .3s}
.sidebar-header{display:flex;align-items:center;gap:10px;padding:20px;border-bottom:1px solid var(--border);font-weight:700}
.sidebar-nav{flex:1;padding:16px 12px;display:flex;flex-direction:column;gap:4px;overflow-y:auto}
.nav-item{display:flex;align-items:center;gap:12px;padding:12px 14px;border-radius:10px;text-decoration:none;
  color:var(--text);font-size:15px;font-weight:500;transition:all .15s}
.nav-item span{font-size:18px}
.nav-item:hover{background:#f3f4f6}
.nav-item.active{background:var(--primary);color:#fff}
.sidebar-footer{padding:16px;border-top:1px solid var(--border)}
.user-info{display:flex;gap:10px;align-items:center;margin-bottom:12px}
.avatar{width:40px;height:40px;border-radius:50%;background:linear-gradient(135deg,var(--primary),#8b5cf6);
  color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:14px;flex-shrink:0}
.user-name{font-size:14px;font-weight:600}
.user-role{font-size:12px;color:var(--text-light);text-transform:capitalize}
.btn-logout{display:block;text-align:center;padding:10px;background:#fef2f2;color:var(--danger);
  border-radius:10px;text-decoration:none;font-size:14px;font-weight:600;transition:background .2s}
.btn-logout:hover{background:#fee2e2}

.main{flex:1;margin-left:260px;display:flex;flex-direction:column;min-height:100vh}
.topbar{background:#fff;padding:16px 24px;border-bottom:1px solid var(--border);display:flex;align-items:center;gap:16px;
  position:sticky;top:0;z-index:50}
.topbar h2{font-size:20px}
.menu-toggle{display:none;background:none;border:none;font-size:24px;cursor:pointer;color:var(--text)}
.content{padding:24px;flex:1}
.loading{text-align:center;padding:60px;color:var(--text-light)}

/* CARDS & TABLES */
.card{background:var(--card);border-radius:var(--radius);padding:20px;box-shadow:var(--shadow);margin-bottom:20px}
.card h3{margin-bottom:16px;font-size:17px}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:16px;margin-bottom:20px}
.stat{background:#fff;border-radius:var(--radius);padding:20px;box-shadow:var(--shadow)}
.stat-label{font-size:13px;color:var(--text-light);margin-bottom:6px}
.stat-value{font-size:28px;font-weight:700;color:var(--primary)}
.table{width:100%;border-collapse:collapse}
.table th,.table td{padding:12px;text-align:left;border-bottom:1px solid var(--border);font-size:14px}
.table th{font-size:12px;text-transform:uppercase;color:var(--text-light);letter-spacing:.5px}
.table tr:last-child td{border-bottom:none}
.table tr:hover{background:#f9fafb}
.badge{padding:4px 10px;border-radius:20px;font-size:12px;font-weight:600;display:inline-block}
.badge-success{background:#d1fae5;color:#065f46}
.badge-danger{background:#fee2e2;color:#991b1b}
.badge-warning{background:#fef3c7;color:#92400e}
.badge-info{background:#dbeafe;color:#1e40af}

/* FORM inline */
.form-row{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:14px;margin-bottom:14px}
.empty{text-align:center;padding:40px;color:var(--text-light);font-style:italic}
.actions{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:16px}

/* RESPONSIVE */
@media (max-width: 768px){
  .sidebar{transform:translateX(-100%)}
  .sidebar.open{transform:translateX(0)}
  .main{margin-left:0}
  .menu-toggle{display:block}
  .content{padding:16px}
  .topbar{padding:14px 16px}
  .topbar h2{font-size:17px}
  .table{font-size:13px}
  .table th,.table td{padding:8px}
  .hide-mobile{display:none}
}

/* === PHOTOS DE PROFIL === */
.avatar {
  overflow: hidden;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-large {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 32px;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.avatar-large img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar-large .overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  opacity: 0;
  transition: opacity .2s;
}
.avatar-large:hover .overlay { opacity: 1; }

.profile-header {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.profile-header-info h2 { margin-bottom: 4px; }
.profile-header-info p { color: var(--text-light); font-size: 14px; }

.profile-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.btn-secondary {
  background: #f3f4f6;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #e5e7eb; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 768px) {
  .two-col { grid-template-columns: 1fr; }
  .profile-header { text-align: center; justify-content: center; }
}

.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 14px;
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .2s ease;
}
.btn-logout:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}
.btn-logout:active {
  transform: translateY(0);
}
.btn-logout .logout-icon {
  font-size: 16px;
  line-height: 1;
  transition: transform .2s;
}
.btn-logout:hover .logout-icon {
  transform: translateX(2px);
}

/* ============================================================
   MODAL GÉNÉRIQUE
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  animation: fadeIn .2s ease forwards;
}
@keyframes fadeIn { to { opacity: 1; } }

.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  transform: translateY(20px);
  animation: slideUp .25s ease forwards;
}
@keyframes slideUp { to { transform: translateY(0); } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: all .15s;
}
.modal-close:hover {
  background: #f3f4f6;
  color: var(--text);
}

.modal-body {
  padding: 20px 22px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.modal-footer .btn { min-width: 90px; }

/* ============================================================
   BOUTONS D'ACTION DANS LES TABLEAUX
   ============================================================ */
.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 15px;
  transition: all .15s;
  font-family: inherit;
}
.btn-icon:hover { transform: translateY(-1px); }
.btn-icon.edit {
  color: var(--primary);
  border-color: #c7d2fe;
  background: #eef2ff;
}
.btn-icon.edit:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-icon.delete {
  color: var(--danger);
  border-color: #fecaca;
  background: #fef2f2;
}
.btn-icon.delete:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* Tags de rôle */
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tag-small {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: #f3f4f6;
  color: var(--text-light);
  font-weight: 600;
}

@media (max-width: 600px) {
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; }
}

/* ============================================================
   EMPLOI DU TEMPS
   ============================================================ */
.jour-bloc {
  margin-bottom: 24px;
}
.jour-title {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--primary);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
  margin-bottom: 12px;
}
.cours-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cours-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: all .15s;
}
.cours-item:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,.06);
  border-color: #c7d2fe;
}
.cours-time {
  font-weight: 700;
  font-size: 15px;
  color: var(--primary);
  min-width: 80px;
  text-align: center;
  line-height: 1.3;
}
.cours-time span {
  font-weight: 400;
  font-size: 12px;
  color: var(--text-light);
}
.cours-info {
  flex: 1;
  min-width: 0;
}
.cours-matiere {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 3px;
}
.cours-meta {
  font-size: 13px;
  color: var(--text-light);
}
.cours-target {
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .cours-item {
    flex-wrap: wrap;
    gap: 10px;
  }
  .cours-time {
    min-width: 60px;
    font-size: 13px;
  }
  .cours-info {
    flex-basis: calc(100% - 80px);
  }
  .cours-target {
    flex-basis: 100%;
  }
}

@media print {
  .sidebar, .topbar, .card:first-child, .btn, .row-actions, #filterEleve, #btnPrint { display: none !important; }
  .main { margin-left: 0 !important; }
  .card { box-shadow: none !important; border: none !important; }
  .cours-item { break-inside: avoid; }
}


/* ============================================================
   MESSAGERIE
   ============================================================ */

/* Badge sur l'icône du menu */
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

/* Toolbar boîte de réception */
.msg-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.msg-tab {
  padding: 8px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-family: inherit;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.msg-tab:hover { background: #f9fafb; }
.msg-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.msg-tab .tab-count {
  background: rgba(255,255,255,.25);
  border-radius: 8px;
  font-size: 11px;
  padding: 1px 6px;
}
.msg-tab:not(.active) .tab-count {
  background: #f3f4f6;
  color: var(--text-light);
}

/* Liste des messages */
.msg-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all .15s;
}
.msg-row:hover {
  border-color: #c7d2fe;
  box-shadow: 0 4px 12px rgba(0,0,0,.05);
}
.msg-row.unread {
  background: #f5f3ff;
  border-color: #c7d2fe;
  font-weight: 600;
}
.msg-row.unread::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}
.msg-avatar {
  flex-shrink: 0;
}
.msg-content {
  flex: 1;
  min-width: 0;
}
.msg-line-1 {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.msg-sujet {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.msg-row:not(.unread) .msg-sujet {
  font-weight: 500;
}
.msg-date {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-light);
  flex-shrink: 0;
}
.msg-line-2 {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Vue détaillée d'un message */
.msg-detail {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.msg-detail-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.msg-detail-meta {
  flex: 1;
  min-width: 0;
}
.msg-detail-meta h2 {
  font-size: 20px;
  margin-bottom: 6px;
}
.msg-detail-from {
  font-size: 14px;
  color: var(--text-light);
}
.msg-detail-body {
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--text);
  margin-bottom: 24px;
}
.msg-detail-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Message vide */
.msg-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}
.msg-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: .5;
}

@media (max-width: 600px) {
  .msg-row { padding: 12px; gap: 10px; }
  .msg-sujet { font-size: 14px; }
  .msg-date { display: none; }
  .msg-actions { flex-direction: column; }
  .msg-detail { padding: 16px; }
}