:root {
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #3b82f6;
  --primary: #3b82f6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 60px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); }

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w); background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  transition: width .25s; z-index: 200; overflow: hidden;
}
#sidebar.collapsed { width: var(--sidebar-w-collapsed); }

.sidebar-logo {
  padding: 20px 16px 12px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-logo .logo-icon { font-size: 1.4rem; flex-shrink: 0; }
.sidebar-logo .logo-text { color: #fff; font-weight: 700; font-size: .95rem; white-space: nowrap; }
.sidebar-logo .logo-sub  { color: var(--sidebar-text); font-size: .7rem; white-space: nowrap; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-section { padding: 16px 16px 4px; font-size: .65rem; font-weight: 700;
  color: rgba(148,163,184,.5); text-transform: uppercase; letter-spacing: .08em;
  white-space: nowrap; }
.sidebar.collapsed .nav-section { visibility: hidden; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; cursor: pointer; border-radius: 0;
  color: var(--sidebar-text); font-size: .85rem; font-weight: 500;
  white-space: nowrap; transition: all .15s; border: none; background: none;
  width: 100%; text-align: left;
}
.nav-item i { width: 18px; text-align: center; flex-shrink: 0; font-size: .9rem; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(59,130,246,.18); color: var(--primary); }
.nav-item .badge {
  margin-left: auto; background: var(--primary); color: #fff;
  font-size: .65rem; padding: 2px 6px; border-radius: 9px; font-weight: 600;
}

.sidebar-user {
  padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary); display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .85rem;
}
.user-info { overflow: hidden; }
.user-name { color: #fff; font-size: .8rem; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.user-role { color: var(--sidebar-text); font-size: .7rem; white-space: nowrap; }

/* ── Main content ────────────────────────────────────────── */
#main {
  margin-left: var(--sidebar-w); min-height: 100vh;
  transition: margin-left .25s; display: flex; flex-direction: column;
}
#main.collapsed { margin-left: var(--sidebar-w-collapsed); }

/* ── Topbar ──────────────────────────────────────────────── */
#topbar {
  position: sticky; top: 0; z-index: 100;
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 12px 24px; display: flex; align-items: center; gap: 12px;
}
#topbar h2 { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.topbar-breadcrumb { font-size: .75rem; color: var(--text-muted); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ── Page content ────────────────────────────────────────── */
#page { padding: 24px; flex: 1; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card-bg); border-radius: 16px;
  border: 1px solid var(--border); padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.stat-card {
  background: var(--card-bg); border-radius: 14px;
  border: 1px solid var(--border); padding: 16px 20px;
  display: flex; align-items: center; gap: 14px;
}
.stat-icon { width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem; }
.stat-val { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-lbl { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  border-radius: 8px; border: none; cursor: pointer; font-size: .82rem; font-weight: 600;
  transition: all .15s; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #2563eb; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-secondary { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text-muted);
  padding: 6px; border-radius: 6px; transition: all .15s; }
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ── Table ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
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); }
td { padding: 11px 14px; border-bottom: 1px solid #f1f5f9; font-size: .85rem; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

/* ── Badges ──────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px;
  border-radius: 99px; font-size: .72rem; font-weight: 600; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-archived { background: #f1f5f9; color: #64748b; }
.badge-completed { background: #ede9fe; color: #5b21b6; }
.badge-present { background: #d1fae5; color: #065f46; }
.badge-absent  { background: #fee2e2; color: #991b1b; }
.badge-retard  { background: #fef3c7; color: #92400e; }
.badge-excuse  { background: #ede9fe; color: #5b21b6; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-grey { background: #f1f5f9; color: #475569; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: .8rem; font-weight: 600; color: var(--text); }
.form-input {
  border: 1.5px solid var(--border); border-radius: 9px; padding: 8px 12px;
  font-size: .85rem; color: var(--text); background: #fff; outline: none;
  transition: border-color .15s; font-family: inherit; width: 100%;
}
.form-input:focus { border-color: var(--primary); }
select.form-input { cursor: pointer; }
textarea.form-input { resize: vertical; min-height: 80px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.col-2 { grid-column: span 2; }

/* ── Modal ───────────────────────────────────────────────── */
#modal-overlay { display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 1000;
  align-items: center; justify-content: center; padding: 16px; }
#modal-overlay.open { display: flex; }
.modal-box {
  background: #fff; border-radius: 20px; width: 100%; max-width: 580px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity:0; transform:scale(.96) translateY(8px); } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 0; border-bottom: 1px solid var(--border); padding-bottom: 14px;
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-body   { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; }

/* ── QR Code display ─────────────────────────────────────── */
#qr-display {
  background: #fff; border-radius: 20px; padding: 24px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
}
#qr-canvas { border-radius: 12px; }
.qr-timer { font-size: .8rem; color: var(--text-muted); }
.qr-timer span { font-weight: 700; color: var(--primary); }

/* ── Taux présence ───────────────────────────────────────── */
.taux-bar { height: 6px; border-radius: 3px; background: #e2e8f0; overflow: hidden; }
.taux-fill { height: 100%; border-radius: 3px; transition: width .5s; }

/* ── Présence session ────────────────────────────────────── */
.presence-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid #f1f5f9;
}
.presence-row:last-child { border-bottom: none; }
.presence-status-btn {
  padding: 4px 12px; border-radius: 99px; border: none; cursor: pointer;
  font-size: .75rem; font-weight: 600; transition: all .15s;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { width: 0; }
  #main { margin-left: 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .col-2 { grid-column: span 1; }
}

/* ── Toast ───────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: 12px; color: #fff; font-size: .85rem;
  font-weight: 500; box-shadow: 0 4px 16px rgba(0,0,0,.2);
  animation: toastIn .3s ease; max-width: 320px;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--primary); }
@keyframes toastIn { from { opacity:0; transform:translateY(12px); } }

/* ── Calendar/planning ───────────────────────────────────── */
.week-grid { display: grid; grid-template-columns: 60px repeat(5,1fr); gap: 1px;
  background: var(--border); border-radius: 12px; overflow: hidden; }
.week-header { background: #f8fafc; padding: 8px 4px; text-align: center;
  font-size: .72rem; font-weight: 700; color: var(--text-muted); }
.week-slot-label { background: #f8fafc; padding: 6px 8px; font-size: .7rem;
  color: var(--text-muted); display: flex; align-items: center; }
.week-cell { background: #fff; min-height: 60px; padding: 4px; }
.session-chip {
  border-radius: 6px; padding: 4px 6px; font-size: .7rem; font-weight: 600;
  cursor: pointer; transition: opacity .15s; margin-bottom: 2px;
}
.session-chip:hover { opacity: .8; }
.chip-centre { background: #dbeafe; color: #1e40af; border-left: 3px solid #3b82f6; }
.chip-entreprise { background: #fef3c7; color: #92400e; border-left: 3px solid #f59e0b; }
.chip-ouverte { background: #d1fae5; color: #065f46; border-left: 3px solid #10b981; }
.chip-terminee { background: #f1f5f9; color: #64748b; border-left: 3px solid #94a3b8; }
