/* FamilyHub — feuille de style. Thème clair/sombre par jetons, mobile d'abord. */
:root {
  color-scheme: light;
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --border: #dfe3e9; --border-strong: #b9c0cb;
  --text: #161a22; --muted: #5b6472; --accent: #3b5bdb; --accent-hover: #2f4ac0; --accent-soft: #e7ecff; --on-accent: #ffffff;
  --ok: #18794e; --ok-soft: #e1f5ea; --warn: #8a5a00; --warn-soft: #fff1cf; --danger: #c22b2b; --danger-soft: #fde7e7;
  --vault: #6b3fc4; --vault-soft: #efe7ff;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --radius: 14px; --radius-sm: 9px; --nav-w: 248px; --tap: 44px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1217; --surface: #171b22; --surface-2: #1f242d; --border: #2b323d; --border-strong: #4a5464;
  --text: #e9ecf1; --muted: #a2abb9; --accent: #8ea2ff; --accent-hover: #a9b8ff; --accent-soft: #232c4d; --on-accent: #0c1024;
  --ok: #5fd39a; --ok-soft: #14301f; --warn: #f1c35b; --warn-soft: #3a2d0c; --danger: #ff8f8f; --danger-soft: #3d1717;
  --vault: #c3a6ff; --vault-soft: #2c2147;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1217; --surface: #171b22; --surface-2: #1f242d; --border: #2b323d; --border-strong: #4a5464;
    --text: #e9ecf1; --muted: #a2abb9; --accent: #8ea2ff; --accent-hover: #a9b8ff; --accent-soft: #232c4d; --on-accent: #0c1024;
    --ok: #5fd39a; --ok-soft: #14301f; --warn: #f1c35b; --warn-soft: #3a2d0c; --danger: #ff8f8f; --danger-soft: #3d1717;
    --vault: #c3a6ff; --vault-soft: #2c2147;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); min-height: 100dvh; }
h1, h2, h3 { line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(1.4rem, 1.1rem + 1.4vw, 1.9rem); letter-spacing: -.02em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--accent); }
img, svg { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.boot { padding: 3rem 1rem; text-align: center; color: var(--muted); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--accent); color: var(--on-accent); padding: .6rem 1rem; border-radius: 8px; z-index: 100; }
.skip-link:focus { top: 8px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- Icônes ---------- */
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Boutons & champs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: var(--tap); padding: 0 1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon-only { padding: 0; width: var(--tap); }
.btn.sm { min-height: 36px; padding: 0 .7rem; font-size: .875rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

label, .label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; min-width: 0; }
.hint { font-size: .85rem; color: var(--muted); margin-top: .3rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], input[type=number], input[type=tel], select, textarea {
  width: 100%; min-height: var(--tap); padding: .55rem .75rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; }
textarea { min-height: 88px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 500; min-height: 32px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: .15rem; accent-color: var(--accent); flex: none; }
.grid-2 { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .9rem; margin: 0 0 1rem; min-width: 0; }
legend { font-weight: 700; padding: 0 .4rem; font-size: .9rem; }

/* ---------- Structure ---------- */
.shell { display: grid; grid-template-columns: 1fr; min-height: 100dvh; }
.sidebar { display: none; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .5rem; padding: .5rem 1rem; padding-top: max(.5rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; letter-spacing: -.02em; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.brand img { width: 30px; height: 30px; }
.topbar .search { flex: 1; min-width: 0; position: relative; }
.topbar .search input { padding-left: 2.4rem; background: var(--surface); }
.topbar .search .icon { position: absolute; left: .7rem; top: 50%; translate: 0 -50%; color: var(--muted); pointer-events: none; }
.topbar .brand span { display: none; }
main { padding: 1rem 1rem 6.5rem; max-width: 1180px; width: 100%; margin: 0 auto; min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head p { color: var(--muted); margin-top: .25rem; }

.tabbar { position: fixed; inset: auto 0 0 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); }
.tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px; font-size: .72rem; font-weight: 600;
  color: var(--muted); text-decoration: none; background: none; border: 0; font-family: inherit; cursor: pointer; }
.tabbar a[aria-current=page] { color: var(--accent); }
.tabbar .add span.fab { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: var(--on-accent); margin-top: -18px; box-shadow: var(--shadow); }
.tabbar .add { color: var(--text); }

@media (min-width: 900px) {
  .shell { grid-template-columns: var(--nav-w) 1fr; }
  .sidebar { display: flex; flex-direction: column; gap: .25rem; position: sticky; top: 0; height: 100dvh; padding: 1rem .75rem; border-right: 1px solid var(--border); background: var(--surface); overflow-y: auto; }
  .sidebar .brand { padding: .25rem .5rem 1rem; }
  .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar a.nav { display: flex; align-items: center; gap: .7rem; min-height: 42px; padding: 0 .7rem; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-weight: 600; }
  .sidebar a.nav:hover { background: var(--surface-2); }
  .sidebar a.nav[aria-current=page] { background: var(--accent-soft); color: var(--accent); }
  .sidebar .count { margin-left: auto; }
  .sidebar .foot { margin-top: auto; padding: .75rem .5rem 0; border-top: 1px solid var(--border); font-size: .85rem; }
  .tabbar { display: none; }
  .topbar .brand { display: none; }
  main { padding: 1.5rem 2rem 3rem; }
}

/* ---------- Cartes, listes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); min-width: 0; }
.card > h2 { margin-bottom: .75rem; display: flex; align-items: center; gap: .5rem; }
.stack { display: grid; gap: 1rem; }
.cols { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .cols { grid-template-columns: 1fr 1fr; } .cols.wide-left { grid-template-columns: 1.6fr 1fr; } }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; text-decoration: none; color: var(--text); }
.stat:hover { border-color: var(--accent); }
.stat b { display: block; font-size: 1.7rem; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .875rem; }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.vault { background: var(--vault-soft); color: var(--vault); }
.badge .icon { width: 13px; height: 13px; }
.count { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: .75rem; font-weight: 700; }
.tag { display: inline-flex; align-items: center; padding: .05rem .5rem; border-radius: 6px; font-size: .78rem; border: 1px solid var(--border); color: var(--muted); }

.alert { display: flex; gap: .6rem; align-items: flex-start; padding: .75rem .9rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); text-decoration: none; color: var(--text); }
.alert.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.alert.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.alert.info { background: var(--accent-soft); border-color: transparent; }
.alert.vault { background: var(--vault-soft); border-color: transparent; }

.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li + li { border-top: 1px solid var(--border); }
.doc-row { display: grid; grid-template-columns: 40px 1fr auto; gap: .75rem; align-items: center; padding: .65rem .25rem; color: var(--text); text-decoration: none; min-height: 60px; }
.doc-row:hover { background: var(--surface-2); border-radius: var(--radius-sm); }
.doc-ico { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.doc-ico.vault { background: var(--vault-soft); color: var(--vault); }
.doc-main { min-width: 0; }
.doc-title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { display: flex; flex-wrap: wrap; gap: .3rem .5rem; align-items: center; font-size: .82rem; color: var(--muted); }
.doc-side { text-align: right; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.doc-side b { display: block; color: var(--text); font-variant-numeric: tabular-nums; }
.member-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty .icon { width: 36px; height: 36px; margin-bottom: .5rem; }

/* ---------- Documents : dossiers + liste ---------- */
.docs-layout { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .docs-layout { grid-template-columns: 260px 1fr; align-items: start; } }
.folders { padding: .5rem; }
.folders details { border-radius: var(--radius-sm); }
.folders summary, .folders a.folder { display: flex; align-items: center; gap: .55rem; min-height: 40px; padding: 0 .6rem; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; color: var(--text); text-decoration: none; list-style: none; }
.folders summary::-webkit-details-marker { display: none; }
.folders summary:hover, .folders a.folder:hover { background: var(--surface-2); }
.folders a.folder[aria-current=true] { background: var(--accent-soft); color: var(--accent); }
.folders .sub { padding-left: 1.2rem; }
.folders .sub a.folder { font-weight: 500; font-size: .93rem; min-height: 36px; }
.folders .n { margin-left: auto; font-size: .78rem; color: var(--muted); font-weight: 600; }
.folders-toggle { display: flex; }
@media (min-width: 900px) { .folders-toggle { display: none; } }
@media (max-width: 899px) { .folders.collapsed { display: none; } }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.filters select { width: auto; min-height: 38px; padding: .3rem .6rem; }
.chip { display: inline-flex; align-items: center; gap: .35rem; min-height: 34px; padding: 0 .7rem; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; text-decoration: none; }
.chip[aria-pressed=true], .chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---------- Zone de dépôt ---------- */
.drop { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 1.5rem 1rem; text-align: center; background: var(--surface); transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .icon { width: 34px; height: 34px; color: var(--accent); }
.drop .btn-row { justify-content: center; margin-top: .9rem; }
.queue { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: .5rem; }
.queue li { display: grid; grid-template-columns: 1fr auto; gap: .25rem .75rem; align-items: center; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.queue .path { grid-column: 1 / -1; font-size: .85rem; color: var(--muted); }
progress { width: 100%; height: 6px; accent-color: var(--accent); grid-column: 1 / -1; }

/* ---------- Détail document ---------- */
.preview { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); min-height: 240px; display: grid; place-items: center; overflow: hidden; }
.preview img { display: block; max-height: 75dvh; object-fit: contain; }
.pdf-pages { width: 100%; max-height: 80dvh; overflow: auto; display: grid; gap: .5rem; padding: .5rem; }
.pdf-pages canvas { width: 100%; height: auto; display: block; background: #fff; border-radius: 6px; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0; font-size: .93rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 700; padding: .5rem .6rem; border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
td { padding: .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- CNS : étapes ---------- */
.steps { display: flex; gap: .25rem; list-style: none; padding: 0; margin: .6rem 0; }
.steps li { flex: 1; font-size: .75rem; font-weight: 700; color: var(--muted); padding-top: .45rem; border-top: 4px solid var(--border); }
.steps li.done { border-color: var(--ok); color: var(--ok); }
.steps li.current { border-color: var(--accent); color: var(--accent); }
.steps li.bad { border-color: var(--danger); color: var(--danger); }
.claim { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; background: var(--surface); }
.claim-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; align-items: baseline; }

/* ---------- Dialogues, toasts, notifications ---------- */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(640px, calc(100vw - 1.5rem)); max-height: calc(100dvh - 2rem); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,14,22,.55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .9rem 1rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-body { padding: 1rem; }
.dlg-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .9rem 1rem; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
#toasts { position: fixed; z-index: 200; left: 50%; translate: -50% 0; bottom: calc(76px + env(safe-area-inset-bottom)); display: grid; gap: .5rem; width: min(440px, calc(100vw - 2rem)); pointer-events: none; }
@media (min-width: 900px) { #toasts { bottom: 1.5rem; left: auto; right: 1.5rem; translate: 0; } }
.toast { background: var(--text); color: var(--bg); padding: .75rem 1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-weight: 600; pointer-events: auto; }
.toast.error { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .toast.error { color: #1a0505; }
.notif-panel { position: absolute; right: .75rem; top: calc(100% + 6px); width: min(400px, calc(100vw - 1.5rem)); max-height: 70dvh; overflow: auto; z-index: 40; padding: .5rem; }
.notif { display: block; padding: .6rem .7rem; border-radius: var(--radius-sm); text-decoration: none; color: var(--text); }
.notif:hover { background: var(--surface-2); }
.notif.unread { background: var(--accent-soft); }
.notif time { font-size: .78rem; color: var(--muted); }
.bell { position: relative; }
.bell .count { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; font-size: .68rem; }

/* ---------- Connexion ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.auth-card { width: min(440px, 100%); }
.auth-card .brand { justify-content: center; font-size: 1.5rem; margin-bottom: .4rem; }
.auth-card .brand img { width: 44px; height: 44px; }
.auth-card > p.lead { text-align: center; color: var(--muted); margin-bottom: 1.25rem; }
.slug-input { display: flex; align-items: center; }
.slug-input input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.slug-input span { min-height: var(--tap); display: grid; place-items: center; padding: 0 .7rem; border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface-2); color: var(--muted); font-size: .9rem; white-space: nowrap; }
.error-text { color: var(--danger); font-weight: 600; margin-bottom: .75rem; }
.recovery { font: 700 1.15rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .06em; padding: .9rem; background: var(--surface-2); border-radius: var(--radius-sm); text-align: center; overflow-wrap: anywhere; user-select: all; }
.qr { background: #fff; padding: 10px; border-radius: 10px; width: 200px; margin: 0 auto 1rem; }
.qr svg { display: block; width: 100%; height: auto; }

@media print {
  .sidebar, .topbar, .tabbar, .no-print, #toasts { display: none !important; }
  .shell { display: block; } main { padding: 0; max-width: none; }
  .card, .claim { box-shadow: none; border-color: #999; break-inside: avoid; }
  body { background: #fff; color: #000; }
}

/* ---------- Statistiques ---------- */
:root { --series-1: #2a78d6; --series-2: #eb6834; }
:root[data-theme="dark"] { --series-1: #3987e5; --series-2: #d95926; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --series-1: #3987e5; --series-2: #d95926; } }
.chart { position: relative; width: 100%; min-height: 260px; }
.chart svg { display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover, .chart .hit:focus-visible { fill: color-mix(in srgb, var(--text) 7%, transparent); outline: none; }
.chart .hit:focus-visible { stroke: var(--accent); stroke-width: 2; }
.chart-tip { position: absolute; top: 4px; width: 180px; padding: .5rem .65rem; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow); font-size: .82rem; pointer-events: none; z-index: 2; }
.tip-row { display: flex; align-items: center; gap: .4rem; margin-top: .2rem; }
.tip-row .num { margin-left: auto; font-weight: 700; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.legend { display: flex; gap: 1rem; list-style: none; padding: 0; margin: 0 0 .5rem; font-size: .85rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: .4rem; }
.stat-table th[scope=row] { text-align: left; font-size: .93rem; color: var(--text); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; left: 0; background: var(--surface); }
.stat-table td { white-space: nowrap; }
.stat-table tfoot th, .stat-table tfoot td { border-top: 2px solid var(--border-strong); border-bottom: 0; }
