* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #94a3b8;
  --primary: #171717;
  --accent: #8391fb;
  --green: #059669;
  --amber: #d97706;
  --red: #dc2626;
  --sky: #0284c7;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- Auth ---------- */
.auth-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f8fafc, #e2e8f0);
  z-index: 100;
}
.auth-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 40px; width: 360px; text-align: center; box-shadow: 0 10px 40px rgba(15,23,42,.08);
}
.auth-logo { font-size: 40px; margin-bottom: 8px; }
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-card p { font-size: 13px; margin-bottom: 20px; }
.auth-card input { width: 100%; margin-bottom: 10px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-header {
  height: 64px; display: flex; align-items: center; gap: 10px; padding: 0 20px;
  border-bottom: 1px solid var(--border);
}
.logo { font-size: 22px; }
.brand { font-weight: 700; font-size: 15px; }
.nav { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px;
  color: var(--text-2); text-decoration: none; font-weight: 500; font-size: 13.5px; transition: background .15s;
}
.nav a:hover { background: var(--border-light); }
.nav a.active { background: var(--primary); color: #fff; }
.nav a span { font-size: 16px; }
.sidebar-footer { border-top: 1px solid var(--border); padding: 12px; }
.btn-ghost {
  background: none; border: none; cursor: pointer; width: 100%; text-align: left;
  padding: 9px 12px; border-radius: 10px; color: var(--text-2); font-size: 13.5px; font-weight: 500;
}
.btn-ghost:hover { background: var(--border-light); }
.main { flex: 1; min-width: 0; }

/* ---------- Page header ---------- */
.page-header {
  height: 64px; background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 10; gap: 12px;
}
.page-header h1 { font-size: 17px; font-weight: 600; }
.page-header .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.page-header .actions { display: flex; gap: 8px; align-items: center; }
.content { padding: 24px; }

/* ---------- Cards / stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; align-items: stretch; }
.stat-grid .card { display: flex; flex-direction: column; justify-content: center; }
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; }
.stat { padding: 18px 20px; }
.stat .label { font-size: 13px; color: var(--text-2); }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat .value.green { color: var(--green); }
.stat .value.amber { color: var(--amber); }
.stat .value.red { color: var(--red); }
.stat .value.sky { color: var(--sky); }
.card-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex;
  align-items: center; justify-content: space-between; font-weight: 600;
}
.card + .card, .table-card { margin-top: 20px; }
/* dans une grille, l'espacement vient du gap : pas de marge qui décale les cartes */
.stat-grid .card, .grid-2 .card { margin-top: 0; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; padding: 10px 20px; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--border); font-weight: 600;
  white-space: nowrap;
}
td { padding: 11px 20px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }
.table-wrap { overflow-x: auto; }
td .small { font-size: 12px; color: var(--muted); }

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px;
  padding: 2px 10px; font-size: 11.5px; font-weight: 600; border: 1px solid transparent; white-space: nowrap;
}
.badge.green { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.badge.amber { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge.red { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.badge.gray { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.badge.sky { background: #e0f2fe; color: #075985; border-color: #bae6fd; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px;
  font-size: 11px; font-weight: 600; background: #f1f5f9; color: #334155; margin: 1px 3px 1px 0;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.pill.tag { background: #eef2ff; color: #4338ca; }

/* ---------- Buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); padding: 8px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--border-light); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #333; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: #fee2e2; border-color: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; font-size: 13.5px;
  font-family: inherit; background: var(--card); color: var(--text); outline: none; transition: border .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.search-input { width: 240px; }

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 60px 20px;
  overflow-y: auto;
}
.modal {
  background: var(--card); border-radius: 16px; width: 100%; max-width: 520px;
  box-shadow: 0 20px 60px rgba(15,23,42,.25);
}
.modal-header { padding: 18px 24px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-list { display: flex; flex-wrap: wrap; gap: 8px; }
.checkbox-list label {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 12.5px; font-weight: 500;
}
.checkbox-list label:has(input:checked) { background: var(--primary); color: #fff; border-color: var(--primary); }
.checkbox-list input { display: none; }

/* ---------- TOTP ---------- */
.totp-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 20px; font-weight: 700;
  letter-spacing: 3px; color: var(--text); cursor: pointer;
}
.totp-bar { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; width: 90px; margin-top: 4px; }
.totp-bar > div { height: 100%; background: var(--green); transition: width 1s linear; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--primary); color: #fff;
  padding: 12px 20px; border-radius: 12px; font-size: 13.5px; font-weight: 500; z-index: 200;
  box-shadow: 0 8px 30px rgba(15,23,42,.3); max-width: 420px;
}
.toast.error { background: var(--red); }

/* ---------- Empty state ---------- */
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty .icon { font-size: 36px; margin-bottom: 10px; }

/* ---------- Misc ---------- */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar { width: 64px; }
  .brand, .nav a { font-size: 0; gap: 0; justify-content: center; }
  .nav a span { font-size: 18px; }
  .sidebar-footer { display: none; }
}
.help-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; font-size: 12.5px; color: var(--text-2); line-height: 1.6; }
.help-box code { background: #e2e8f0; padding: 1px 6px; border-radius: 5px; font-size: 11.5px; }
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { color: var(--sky); cursor: pointer; text-decoration: underline; }
.actions-cell { text-align: right; white-space: nowrap; }
.actions-cell .btn { margin-left: 6px; }
