:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --ink: #1b1d22;
  --muted: #6b6f78;
  --line: #e3e0d9;
  --accent: #3b5bdb;
  --accent-ink: #ffffff;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 6px 24px rgba(20, 20, 30, .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121317;
    --surface: #1b1d23;
    --ink: #ecebe8;
    --muted: #9a9ea8;
    --line: #2b2e36;
    --accent: #7b93ff;
    --accent-ink: #0d1020;
    --danger: #ff6b6b;
    --ok: #69db7c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}
a { color: var(--accent); }
[hidden] { display: none !important; }

.wrap { max-width: 920px; margin: 0 auto; padding: 32px 16px 64px; }

/* ---------- en-tête ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 36px; }
.brand { white-space: nowrap; display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--ink); color: var(--bg); display: grid; place-items: center; font-size: 15px; }
.top-actions { display: flex; gap: 8px; align-items: center; }

h1 { font-size: clamp(26px, 5vw, 34px); line-height: 1.15; letter-spacing: -.02em; margin: 0 0 6px; }
.sub { color: var(--muted); margin: 0 0 28px; }
h2 { font-size: 18px; margin: 0 0 12px; }

/* ---------- boutons & champs ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 600; padding: 9px 14px; border-radius: 10px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn:focus-visible, input:focus-visible, .tile:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

label { display: block; font-size: 14px; font-weight: 600; margin: 0 0 6px; }
input[type=text], input[type=password] {
  width: 100%; font: inherit; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.field { margin-bottom: 16px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

.msg { font-size: 14px; padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; }
.msg.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.msg.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }

/* ---------- page de connexion ---------- */
.login-page { display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 380px; }
.login .brand { justify-content: center; margin-bottom: 24px; }
.login .btn.primary { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.login-foot { text-align: center; font-size: 13px; color: var(--muted); margin-top: 18px; }

/* ---------- tuiles des applications ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.tile {
  --c: var(--accent);
  position: relative; display: flex; flex-direction: column; gap: 14px; min-height: 160px;
  padding: 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); color: var(--ink); text-decoration: none; overflow: hidden;
  transition: transform .15s ease, border-color .15s ease;
}
.tile::after { content: ""; position: absolute; inset: auto 0 0 0; height: 4px; background: var(--c); }
.tile:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--c) 50%, var(--line)); }
.tile-icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; font-weight: 700;
  background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c);
}
.tile-name { font-weight: 700; font-size: 18px; }
.tile-desc { color: var(--muted); font-size: 14px; margin-top: -8px; }
.tile.soon { box-shadow: none; border-style: dashed; background: transparent; color: var(--muted); justify-content: center; align-items: center; text-align: center; font-size: 14px; }
.tile.soon::after { display: none; }
.tile.soon:hover { transform: none; }

/* ---------- compte ---------- */
.stack { display: grid; gap: 20px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); font-size: 14px; }
.list li:first-child { border-top: 0; }
.list .meta { color: var(--muted); font-size: 13px; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); white-space: nowrap; }
.badge.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.row-end { display: flex; justify-content: flex-end; margin-top: 12px; }

@media (max-width: 520px) {
  .wrap { padding-top: 20px; }
  .top { margin-bottom: 24px; }
  .card { padding: 18px; }
  .list li { flex-direction: column; gap: 4px; }
  .list .badge { align-self: flex-start; }
  .top-actions .btn { padding: 8px 10px; font-size: 13px; }
}

/* ---------- ajouts : 2FA, administration ---------- */
:root { --warn: #b35c00; }
@media (prefers-color-scheme: dark) { :root { --warn: #ffb35c; } }
.msg.warn { background: color-mix(in srgb, var(--warn) 13%, transparent); color: var(--warn); }
.msg.warn a { color: inherit; font-weight: 700; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; word-break: break-all; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; }
.grow { flex: 1 1 200px; }
.steps { padding-left: 20px; margin: 0 0 16px; display: grid; gap: 10px; font-size: 15px; }
.qr { margin: 12px 0 6px; }
.qr img { display: block; border-radius: 10px; background: #fff; padding: 6px; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; margin-top: 8px; }
details[open] summary { margin-bottom: 12px; }
h2 .badge { vertical-align: middle; margin-left: 6px; }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.muted { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }

.wrap.wide { max-width: 1100px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 26px; letter-spacing: -.02em; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.alert b { color: var(--danger); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }

.users { width: 100%; border-collapse: collapse; font-size: 14px; }
.users th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 0 10px 10px; }
.users td { padding: 12px 10px; border-top: 1px solid var(--line); vertical-align: middle; }
.users tr.off td { opacity: .55; }
.users .name b { display: block; }
.users .tags { display: flex; gap: 4px; flex-wrap: wrap; }
.users td:last-child { text-align: right; white-space: nowrap; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 0; width: min(480px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 12, 18, .5); }
.dlg { padding: 22px; }
.dlg h2 { margin-bottom: 4px; }
.dlg .sub { margin-bottom: 18px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.checks { display: grid; gap: 8px; }
.checks label { display: flex; gap: 10px; align-items: center; font-weight: 500; margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg label { margin: 0; padding: 8px 14px; font-weight: 600; font-size: 14px; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: var(--accent); }
.seg label:has(input:checked) { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.action-list { display: grid; gap: 8px; }
.action-list .btn { justify-content: flex-start; }
.secret-box { display: flex; gap: 8px; align-items: center; margin: 12px 0; }
.secret-box code { font-size: 18px; padding: 8px 12px; flex: 1; text-align: center; letter-spacing: .04em; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
select { font: inherit; font-size: 14px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.log { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.log li { display: grid; grid-template-columns: 150px 120px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: baseline; }
.log li:first-child { border-top: 0; }
.log .meta { color: var(--muted); font-size: 13px; }
.center { text-align: center; margin-top: 12px; }

@media (max-width: 720px) {
  .users thead { display: none; }
  .users, .users tbody, .users tr, .users td { display: block; width: 100%; }
  .users tr { border-top: 1px solid var(--line); padding: 10px 0; }
  .users td { border: 0; padding: 4px 0; text-align: left !important; }
  .log li { grid-template-columns: 1fr; gap: 2px; }
}
