/* Portail familial — design simple, chaleureux, natif sur mobile */
:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --ink: #1c1f22;
  --muted: #6b6f73;
  --line: rgba(28, 31, 34, .08);
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: rgba(47, 111, 94, .12);
  --danger: #b5523b;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --radius: 18px;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1d2125;
    --surface-2: #262b30;
    --ink: #eceae6;
    --muted: #9a9fa4;
    --line: rgba(255, 255, 255, .08);
    --accent: #5fb39b;
    --accent-ink: #0e1a16;
    --accent-soft: rgba(95, 179, 155, .16);
    --danger: #e0806a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  -webkit-user-select: none; user-select: none;
}
input { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }
.defs { position: absolute; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.4em; font-size: 14px; margin: 12px 0 0; }

/* Boutons et champs */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 50px; padding: 0 18px; border-radius: 14px;
  font-weight: 600; text-decoration: none; color: var(--ink);
  transition: transform .12s ease, opacity .2s ease, background .2s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.soft { background: var(--accent-soft); color: var(--accent); margin-top: 14px; }
.btn.ghost { color: var(--accent); margin-top: 6px; }
.btn.big { min-height: 56px; font-size: 17px; }
.btn[disabled] { opacity: .5; }
.stack { display: grid; gap: 10px; margin-top: 12px; }
.field {
  width: 100%; height: 52px; padding: 0 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  font: inherit; font-size: 17px; outline: none; transition: border-color .2s, background .2s;
}
.field:focus { border-color: var(--accent); background: var(--surface); }
.field.pin { letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.field.pin::placeholder { letter-spacing: normal; }

/* Connexion */
.auth {
  min-height: 100%; display: grid; place-items: center;
  padding: calc(var(--safe-t) + 24px) 20px calc(var(--safe-b) + 24px);
  animation: fade .4s ease;
}
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-logo { border-radius: 20px; box-shadow: var(--shadow); }
.auth-title { font-size: 28px; letter-spacing: -.02em; margin: 18px 0 4px; }
.auth-card .muted { margin: 0 0 24px; }

/* Coquille */
.shell { min-height: 100%; }
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(var(--safe-t) + 14px) 20px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px);
}
.kicker { margin: 0; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.top h1 { margin: 0; font-size: 32px; letter-spacing: -.025em; }
main { padding: 6px 16px calc(var(--tabbar-h) + var(--safe-b) + 28px); max-width: 640px; margin: 0 auto; }
.pane { animation: rise .32s cubic-bezier(.2, .8, .2, 1); }
.section { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 4px 8px; font-weight: 600; }

/* Barre d'onglets */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; transition: color .2s; }
.tab svg { width: 25px; height: 25px; transition: transform .25s cubic-bezier(.3, 1.5, .5, 1); }
.tab.active { color: var(--accent); }
.tab.active svg { transform: translateY(-1px) scale(1.06); }

/* Cartes et listes */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.hero {
  border-radius: var(--radius); padding: 22px 20px; margin-top: 4px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #1b3a5c));
  color: #fff; box-shadow: var(--shadow);
}
.hero-hello { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.hero-sub { margin: 4px 0 0; opacity: .85; }
.members { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.member { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 8px 12px; text-align: center; }
.avatar { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 8px; color: #fff; font-weight: 700; font-size: 21px; }
.member-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-role { font-size: 12px; color: var(--muted); }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 54px; padding: 8px 14px; text-align: left; }
.row + .row { border-top: 1px solid var(--line); }
.row.action:active { background: var(--surface-2); }
.row.danger { color: var(--danger); }
.row .grow { flex: 1; }
.dot { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.row.danger .dot { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.dot svg { width: 19px; height: 19px; }
.chev { width: 18px; height: 18px; color: var(--muted); }

.vault { text-align: center; padding: 28px 20px 20px; margin-top: 4px; }
.vault h2 { margin: 12px 0 4px; font-size: 22px; }
.vault .muted { margin: 0 0 18px; }
.vault-icon { width: 64px; height: 64px; border-radius: 20px; margin: 0 auto; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.vault-icon svg { width: 32px; height: 32px; }
.tip p { margin: 0 0 12px; }
.tip .fine { margin: 12px 0 0; }
.copy { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.copy code { font: 600 14px ui-monospace, SFMono-Regular, Menlo, monospace; overflow: hidden; text-overflow: ellipsis; }
.copy span { color: var(--accent); font-weight: 600; font-size: 14px; }

.empty { text-align: center; padding: 56px 20px; }
.empty-icon { width: 76px; height: 76px; border-radius: 24px; margin: 0 auto; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.empty-icon svg { width: 36px; height: 36px; }
.empty h2 { margin: 18px 0 6px; }
.empty .muted { max-width: 320px; margin: 0 auto; }

/* Feuille modale */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); animation: fade .2s ease; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 8px 20px calc(var(--safe-b) + 22px); max-height: 88vh; overflow: auto;
  animation: up .32s cubic-bezier(.2, .8, .2, 1);
}
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet h3 { margin: 0 0 6px; font-size: 20px; }
.sheet p { margin: 0 0 14px; }
.sheet .btn + .btn { margin-top: 8px; }
.linkbox { word-break: break-all; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font: 13px ui-monospace, Menlo, monospace; margin-bottom: 12px; -webkit-user-select: all; user-select: all; }
.device { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.device + .device { border-top: 1px solid var(--line); }
.device .grow { flex: 1; }
.device small { display: block; color: var(--muted); }
.device button { color: var(--danger); font-weight: 600; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  transition: opacity .25s, transform .25s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes up { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Papiers, admin, visionneuse ---------- */
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.icon-btn.light { background: rgba(255,255,255,.14); color: #fff; }
.text-btn { color: #fff; font-weight: 600; padding: 8px 4px; }
.tab { position: relative; }
.badge { position: absolute; top: 5px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.row small, .device small { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }
.dot.red { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.dot.amber { background: rgba(196, 139, 36, .16); color: #b57d14; }
button.member { font: inherit; color: inherit; width: 100%; }
button.member:not([disabled]):active { transform: scale(.97); }
button.member[disabled] { opacity: 1; cursor: default; }
.avatar.small { width: 44px; height: 44px; font-size: 18px; margin: 0; }
.avatar.tiny { width: 30px; height: 30px; font-size: 13px; margin: 0; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.sheet-head h3 { margin: 0; }
.sheet-head p { margin: 2px 0 0; }
.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 16px 2px 6px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.seg button { height: 40px; border-radius: 10px; font-weight: 600; color: var(--muted); transition: background .2s, color .2s; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.inline { display: flex; gap: 8px; }
.btn.fit { width: auto; margin: 0; padding: 0 18px; }
.btn.secondary { background: var(--surface-2); color: var(--ink); }
.btn.danger-soft { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.top-gap { margin-top: 12px; }
.stack.top-gap { margin-top: 18px; }
.stack.narrow { max-width: 320px; margin: 22px auto 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bigpin { font: 700 40px/1 ui-monospace, Menlo, monospace; letter-spacing: .12em; text-align: center; padding: 22px; margin: 6px 0 16px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); -webkit-user-select: all; user-select: all; }
.list.flat { box-shadow: none; background: var(--surface-2); margin-bottom: 12px; }
select.field { -webkit-appearance: none; appearance: none; }
.pad { padding: 40px 20px; }
.readonly { text-align: center; margin: 4px 0 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { height: 36px; padding: 0 14px; border-radius: 18px; background: var(--surface-2); font-size: 14px; font-weight: 600; color: var(--muted); transition: background .2s, color .2s; }
.chips button.on { background: var(--accent); color: var(--accent-ink); }
.preview { display: flex; align-items: center; gap: 12px; margin-top: 14px; padding: 10px; border-radius: 14px; background: var(--surface-2); }
.preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.preview svg { width: 40px; height: 40px; color: var(--muted); }

.person { margin-top: 22px; }
.person-head { display: flex; align-items: center; gap: 10px; margin: 0 4px 10px; }
.person-head h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; flex: 1; }
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 10px; }
.doc { text-align: left; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 8px 10px; transition: transform .12s; }
.doc:active { transform: scale(.97); }
.doc-thumb { position: relative; aspect-ratio: 1.45; border-radius: 12px; background: var(--surface-2); overflow: hidden; display: grid; place-items: center; color: var(--muted); }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-thumb svg { width: 30px; height: 30px; }
.doc.add { box-shadow: none; background: transparent; border: 1.5px dashed color-mix(in srgb, var(--muted) 45%, transparent); }
.doc.add .doc-thumb { background: transparent; color: var(--accent); }
.doc.add .doc-name { text-align: center; color: var(--accent); }
.pdf-tag { position: absolute; top: 6px; right: 6px; font: 700 10px/1 -apple-system, sans-serif; font-style: normal; padding: 4px 6px; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; }
.doc-name { font-weight: 600; font-size: 14px; margin: 8px 2px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 8px; margin-left: 2px; }
.chip.ok, .chip.none { background: var(--surface-2); color: var(--muted); }
.chip.soon { background: rgba(196, 139, 36, .16); color: #b57d14; }
.chip.expired { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

.viewer { position: fixed; inset: 0; z-index: 40; background: #0c0d0e; color: #fff; display: flex; flex-direction: column; animation: fade .2s ease; }
.viewer-top { display: flex; align-items: center; gap: 10px; padding: calc(var(--safe-t) + 10px) 12px 10px; background: rgba(12,13,14,.9); }
.viewer-title { flex: 1; min-width: 0; }
.viewer-title b, .viewer-title small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-title small { color: rgba(255,255,255,.65); font-size: 13px; }
.viewer-body { flex: 1; overflow: auto; padding: 12px 12px calc(var(--safe-b) + 16px); display: flex; flex-direction: column; align-items: center; gap: 12px; -webkit-overflow-scrolling: touch; }
.viewer-img { max-width: 100%; height: auto; border-radius: 8px; margin: auto 0; -webkit-user-select: none; user-select: none; touch-action: pinch-zoom; }
.viewer-img.zoom { max-width: none; width: 250%; margin: 0; }
.pdf-page { width: 100%; max-width: 900px; height: auto; background: #fff; border-radius: 4px; }
body.noscroll { overflow: hidden; }
/* Corrections d'alignement (les <button> centrent leur contenu par défaut) */
.doc, button.member { display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch; }
button.member { align-items: center; }
.doc .chip { align-self: flex-start; }
.two .btn, .sheet .two .btn + .btn { margin-top: 0; }
