/* ============================================================
   Gestion du Personnel — Feuille de style principale
   Design: Professionnel, épuré, bleu institutionnel
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

/* ── Variables ───────────────────────────────────────────── */
:root {
  --blue-50:  #eff6ff;
  --blue-100: #dbeafe;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --red-500:  #ef4444;
  --red-100:  #fee2e2;
  --green-500:#22c55e;
  --green-100:#dcfce7;
  --yellow-500:#f59e0b;
  --sidebar-w: 200px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.04);
}

/* ── Reset & Base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Login page ──────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--gray-100);
}

.login-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,.10);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-logo {
  width: 64px; height: 64px;
  background: var(--blue-600);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.25rem;
}
.login-logo svg { width: 36px; height: 36px; color: #fff; }

.login-title { font-size: 1.4rem; font-weight: 700; color: var(--gray-900); }
.login-subtitle { color: var(--gray-500); font-size: .9rem; margin-bottom: 1.75rem; }

.tab-toggle {
  display: flex;
  background: var(--gray-100);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 1.5rem;
  gap: 4px;
}
.tab-toggle button {
  flex: 1;
  padding: .45rem;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--gray-500);
  transition: all .2s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.tab-toggle button.active {
  background: #fff;
  color: var(--gray-800);
  box-shadow: var(--shadow);
}

/* ── Form elements ───────────────────────────────────────── */
.form-group { margin-bottom: 1rem; text-align: left; }
.form-label { display: block; font-size: .85rem; font-weight: 500; color: var(--gray-700); margin-bottom: .35rem; }

.input-wrap { position: relative; }
.input-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--gray-400); pointer-events: none; }

.form-control {
  width: 100%;
  padding: .6rem .75rem .6rem 2.25rem;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-family: inherit;
  font-size: .9rem;
  color: var(--gray-800);
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}
.form-control:focus {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
.form-control.no-icon { padding-left: .75rem; }
select.form-control { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 2rem; }
textarea.form-control { resize: vertical; min-height: 90px; padding-left: .75rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: .6rem 1.1rem;
  border: none; border-radius: 8px;
  font-family: inherit; font-size: .875rem; font-weight: 600;
  cursor: pointer; transition: all .18s;
  white-space: nowrap;
}
.btn-primary { background: var(--blue-600); color: #fff; }
.btn-primary:hover { background: var(--blue-700); }
.btn-primary:disabled { background: var(--gray-300); cursor: not-allowed; }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger { background: var(--red-100); color: var(--red-500); }
.btn-danger:hover { background: var(--red-500); color: #fff; }
.btn-success { background: var(--green-100); color: var(--green-500); }
.btn-success:hover { background: var(--green-500); color: #fff; }
.btn-full { width: 100%; padding: .75rem; font-size: 1rem; }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }

/* ── Alerts ──────────────────────────────────────────────── */
.alert { padding: .75rem 1rem; border-radius: 8px; font-size: .875rem; margin-bottom: 1rem; }
.alert-danger  { background: var(--red-100);   color: #b91c1c; }
.alert-success { background: var(--green-100); color: #15803d; }
.alert-info    { background: var(--blue-50);   color: var(--blue-700); }

/* ── Layout with sidebar ─────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--gray-900);
  color: #fff;
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand-name { font-weight: 700; font-size: .95rem; }
.sidebar-brand-ver  { font-size: .7rem; color: var(--gray-400); }

.sidebar-nav { flex: 1; padding: .75rem 0; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem 1rem;
  color: var(--gray-400);
  font-size: .875rem; font-weight: 500;
  transition: all .15s;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
  color: #fff;
  background: rgba(255,255,255,.06);
  border-left-color: var(--blue-500);
  text-decoration: none;
}
.sidebar-nav a svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer {
  padding: .75rem 1rem;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: .65rem;
}
.avatar-sm {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--blue-600);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.sidebar-user-name  { font-size: .8rem; font-weight: 600; color: #fff; }
.sidebar-user-email { font-size: .7rem; color: var(--gray-400); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.sidebar-logout { margin-left: auto; color: var(--gray-400); }
.sidebar-logout:hover { color: #fff; }

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 2rem;
  max-width: 100%;
}

/* ── Page header ─────────────────────────────────────────── */
.page-header { margin-bottom: 1.75rem; display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); display: flex; align-items: center; gap: .5rem; }
.page-title svg { width: 24px; height: 24px; color: var(--blue-500); }
.page-subtitle { color: var(--gray-500); font-size: .875rem; margin-top: 2px; }

/* ── Card ────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  margin-bottom: 1.5rem;
}
.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 1rem; font-weight: 600; color: var(--gray-900); }
.card-body { padding: 1.5rem; }

/* ── Form grid ───────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }

/* ── Table ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: .75rem 1rem;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--gray-200);
}
tbody td {
  padding: .85rem 1rem;
  font-size: .875rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: .2rem .65rem;
  border-radius: 99px;
  font-size: .75rem; font-weight: 600;
}
.badge-blue   { background: var(--blue-100);  color: var(--blue-700); }
.badge-green  { background: var(--green-100); color: #15803d; }
.badge-red    { background: var(--red-100);   color: #b91c1c; }
.badge-gray   { background: var(--gray-100);  color: var(--gray-600); }
.badge-yellow { background: #fef3c7; color: #92400e; }

/* ── Action buttons in table ─────────────────────────────── */
.actions { display: flex; align-items: center; gap: .35rem; }
.icon-btn {
  width: 30px; height: 30px;
  border-radius: 6px; border: none;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .15s;
  background: transparent;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn-edit  { color: var(--gray-400); } .icon-btn-edit:hover  { background: var(--gray-100); color: var(--gray-700); }
.icon-btn-del   { color: var(--red-500); }  .icon-btn-del:hover   { background: var(--red-100); }
.icon-btn-ok    { color: var(--green-500); } .icon-btn-ok:hover   { background: var(--green-100); }
.icon-btn-power { color: var(--red-500); }  .icon-btn-power:hover { background: var(--red-100); }

/* ── Filters row ─────────────────────────────────────────── */
.filters { display: flex; gap: .75rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.filters select { min-width: 150px; }

/* ── Permissions matrix ──────────────────────────────────── */
.matrix-wrap { overflow-x: auto; }
.matrix-table th { text-align: center; }
.matrix-table th:first-child { text-align: left; }
.matrix-table td { text-align: center; }
.matrix-table td:first-child { text-align: left; font-size: .85rem; }
.check-yes { color: var(--blue-600); } .check-no { color: var(--gray-300); }

/* ── Role cards ──────────────────────────────────────────── */
.role-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.role-card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.role-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.role-card-title { font-weight: 600; font-size: .9rem; }
.role-count { background: var(--gray-100); color: var(--gray-600); font-size: .8rem; font-weight: 600; border-radius: 99px; padding: .1rem .6rem; }
.role-desc { color: var(--gray-500); font-size: .8rem; margin-bottom: .75rem; }
.role-members { font-size: .8rem; }
.role-member { display: flex; justify-content: space-between; padding: .2rem 0; color: var(--gray-700); }
.role-member-email { color: var(--gray-400); }
.role-empty { color: var(--gray-400); font-style: italic; }

/* ── Avatar ──────────────────────────────────────────────── */
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--blue-600); display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700; color: #fff; flex-shrink: 0; }
.user-cell { display: flex; align-items: center; gap: .65rem; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--gray-100); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--gray-400); font-size: 1.25rem; line-height: 1; }
.modal-close:hover { color: var(--gray-700); }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--gray-100); display: flex; justify-content: flex-end; gap: .65rem; }

/* ── Barre de navigation mobile (bottom nav) ─────────────── */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--gray-900);
  border-top: 1px solid rgba(255,255,255,.08);
  z-index: 200;
  padding: .4rem 0 calc(.4rem + env(safe-area-inset-bottom));
}
.mobile-nav-inner {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.mobile-nav-item {
  display: flex; flex-direction: column; align-items: center;
  gap: .2rem;
  color: var(--gray-400);
  font-size: .65rem; font-weight: 500;
  padding: .4rem .6rem;
  border-radius: 8px;
  text-decoration: none !important;
  transition: color .15s;
  min-width: 56px;
}
.mobile-nav-item svg { width: 22px; height: 22px; }
.mobile-nav-item.active,
.mobile-nav-item:hover { color: #fff; }
.mobile-nav-item.active svg { color: var(--blue-500); }

/* ── Bouton hamburger mobile ─────────────────────────────── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--gray-900);
  z-index: 150;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.mobile-header-brand { color: #fff; font-weight: 700; font-size: .95rem; }
.mobile-header-user  { display: flex; align-items: center; gap: .5rem; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Cacher la sidebar desktop */
  .sidebar { display: none; }

  /* Afficher header et bottom nav mobiles */
  .mobile-header { display: flex; }
  .mobile-nav    { display: block; }

  /* Décaler le contenu principal */
  .main-content {
    margin-left: 0;
    padding: 1rem;
    padding-top: calc(56px + 1rem);   /* espace pour le header fixe */
    padding-bottom: calc(70px + 1rem); /* espace pour la bottom nav */
  }

  /* Grilles → 1 colonne */
  .form-grid, .form-grid-2 { grid-template-columns: 1fr; }
  .col-span-2, .col-span-3 { grid-column: span 1; }

  /* En-tête de page empilé */
  .page-header { flex-direction: column; align-items: flex-start; gap: .75rem; }
  .page-header .btn { width: 100%; justify-content: center; }

  /* Tables scrollables horizontalement */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }

  /* Cartes rôles → 1 colonne */
  .role-cards { grid-template-columns: 1fr; }

  /* Modals → plein écran en bas */
  .modal-overlay { align-items: flex-end; }
  .modal {
    border-radius: 18px 18px 0 0;
    max-width: 100%;
    max-height: 92vh;
    width: 100%;
  }

  /* Filtres empilés */
  .filters { flex-direction: column; }
  .filters select { width: 100%; }

  /* Login card plein écran sur très petit */
  .login-card { margin: 1rem; padding: 1.75rem 1.25rem; }

  /* Boutons plus grands (touch-friendly) */
  .btn { min-height: 44px; }
  .icon-btn { width: 38px; height: 38px; }

  /* Titre de page plus petit */
  .page-title { font-size: 1.25rem; }
}

/* ── Utilities ───────────────────────────────────────────── */
.text-muted { color: var(--gray-400); }
.text-right { text-align: right; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: .5rem; }
.fw-600 { font-weight: 600; }
.font-mono { font-family: 'DM Mono', monospace; }
