/* ===================================================================
   Santé Famille — feuille de style
   Mobile d'abord. Cible : noter quelque chose en moins de 20 secondes.
   =================================================================== */

:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #f0f2f5;
  --border:    #e3e6eb;
  --text:      #14181f;
  --muted:     #6b7280;
  --accent:    #0d9488;
  --accent-soft:#ccfbf1;
  --danger:    #dc2626;
  --danger-soft:#fee2e2;
  --warn:      #d97706;
  --warn-soft: #fef3c7;
  --ok:        #16a34a;
  --ok-soft:   #dcfce7;
  --info:      #2563eb;
  --info-soft: #dbeafe;
  --radius:    16px;
  --shadow:    0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --safe-b:    env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0e1116;
    --surface:   #161a21;
    --surface-2: #1e232c;
    --border:    #2a303a;
    --text:      #e8ebf0;
    --muted:     #97a0ae;
    --accent:    #2dd4bf;
    --accent-soft:#0f3f3a;
    --danger:    #f87171;
    --danger-soft:#3d1a1a;
    --warn:      #fbbf24;
    --warn-soft: #3a2c0d;
    --ok:        #4ade80;
    --ok-soft:   #10331e;
    --info:      #60a5fa;
    --info-soft: #16243d;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }

/* L'attribut HTML `hidden` doit l'emporter sur les `display: grid` / `flex`
   déclarés plus bas. La règle par défaut du navigateur ([hidden]{display:none})
   est moins prioritaire qu'une règle de classe : sans ce !important, masquer
   #boot ne fait rien et l'écran de chargement reste par-dessus l'application. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny  { font-size: .74rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.spacer { height: 8px; }

/* ---------- Écran de démarrage ---------- */
.boot {
  position: fixed; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 12px;
  background: var(--bg); z-index: 200;
}
.boot-logo { font-size: 56px; animation: pulse 1.4s ease-in-out infinite; }
.boot-text { color: var(--muted); }
.boot-diag {
  max-width: 420px; margin: 6px 18px 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px 18px;
  font-size: .86rem; line-height: 1.5; text-align: left;
}
.boot-diag p  { margin: 8px 0; color: var(--muted); }
.boot-diag ul { margin: 8px 0 0; padding-left: 20px; color: var(--muted); }
.boot-diag li { margin: 3px 0; }
.boot-diag pre {
  margin: 12px 0 0; padding: 9px 11px;
  background: var(--surface-2); border-radius: 9px;
  font-size: .72rem; white-space: pre-wrap; word-break: break-all; color: var(--danger);
}
@keyframes pulse { 0%,100% { opacity: .35; transform: scale(.94); } 50% { opacity: 1; transform: scale(1); } }

/* ---------- Connexion ---------- */
.login {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--accent-soft), var(--bg) 55%);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login-logo { font-size: 44px; text-align: center; }
.login-card h1 { text-align: center; font-size: 1.4rem; }
.login-card > .muted { text-align: center; margin-bottom: 6px; }
.login-error {
  background: var(--danger-soft); color: var(--danger);
  padding: 10px 12px; border-radius: 10px; font-size: .88rem;
}

/* ---------- Barre de titre ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 900px; margin: 0 auto;
  padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-size: 1.3rem; flex: 1; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); border-radius: 10px;
  width: 36px; height: 36px; font-size: 1rem; cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }

/* ---------- Zone de contenu ---------- */
.view {
  max-width: 900px; margin: 0 auto;
  padding: 16px 16px calc(150px + var(--safe-b));
  display: flex; flex-direction: column; gap: 16px;
}

/* ---------- Barre d'onglets ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 2px 10px;
  font-size: .66rem; font-weight: 550; color: var(--muted);
}
.tabbar a span { font-size: 1.25rem; line-height: 1; }
.tabbar a.active { color: var(--accent); }

/* ---------- Bouton d'ajout rapide ---------- */
.fab {
  position: fixed; right: 18px; z-index: 45;
  bottom: calc(74px + var(--safe-b));
  width: 58px; height: 58px; border-radius: 50%;
  border: none; background: var(--accent); color: #fff;
  font-size: 32px; line-height: 1; font-weight: 300;
  box-shadow: 0 6px 20px rgba(13,148,136,.42); cursor: pointer;
}
.fab:active { transform: scale(.92); }

/* ---------- Cartes ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: .96rem; flex: 1; }
.card-body { padding: 14px 15px; }
.card-body.tight { padding: 6px 0; }

.section-title {
  font-size: .74rem; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
  padding: 0 3px;
}

/* ---------- Liste ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 15px; width: 100%;
  border: none; background: none; color: inherit;
  text-align: left; font: inherit; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--surface-2); }
.list-item .chev { color: var(--muted); font-size: 1.1rem; }

.empty {
  padding: 26px 18px; text-align: center; color: var(--muted); font-size: .9rem;
}
.empty .emoji { font-size: 30px; display: block; margin-bottom: 8px; }

/* ---------- Avatar ---------- */
.avatar {
  width: 42px; height: 42px; flex: 0 0 42px;
  border-radius: 50%; display: grid; place-items: center;
  font-size: 20px; color: #fff;
}
.avatar.sm { width: 30px; height: 30px; flex-basis: 30px; font-size: 15px; }
.avatar.lg { width: 68px; height: 68px; flex-basis: 68px; font-size: 34px; }

/* ---------- Pastilles ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: .72rem; font-weight: 650; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.warn   { background: var(--warn-soft);   color: var(--warn); }
.pill.ok     { background: var(--ok-soft);     color: var(--ok); }
.pill.info   { background: var(--info-soft);   color: var(--info); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 15px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger  { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-block   { width: 100%; }
.btn-sm      { padding: 7px 11px; font-size: .8rem; border-radius: 9px; }
.btn-row     { display: flex; gap: 9px; flex-wrap: wrap; }

/* ---------- Formulaires ---------- */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; margin-top: 5px;
  padding: 11px 12px; font: inherit; font-size: 16px;  /* 16px = pas de zoom iOS */
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 11px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface);
}
textarea { min-height: 76px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.help { font-size: .75rem; color: var(--muted); font-weight: 400; margin-top: 4px; }

/* Sélecteur de personne */
.member-picker { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.member-chip {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px 6px 6px; border-radius: 999px;
  border: 2px solid var(--border); background: var(--surface);
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
}
.member-chip[aria-pressed="true"] { border-color: currentColor; }

/* Sélecteur de gravité */
.sev-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 6px; }
.sev-btn {
  padding: 9px 4px; border-radius: 11px; border: 2px solid var(--border);
  background: var(--surface); font: inherit; font-size: .75rem; font-weight: 600;
  cursor: pointer; color: var(--muted);
}
.sev-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ---------- Fenêtre modale ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8,12,18,.5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .16s ease;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; padding: 24px; } }
@keyframes fade { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(22px); opacity: .6; } }

.modal {
  width: 100%; max-width: 560px;
  max-height: 92dvh; overflow-y: auto;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  animation: slideup .2s ease;
  padding-bottom: calc(16px + var(--safe-b));
}
@media (min-width: 640px) { .modal { border-radius: 20px; } }
.modal-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px 13px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 1.05rem; flex: 1; }
.modal-body { padding: 17px 18px; display: flex; flex-direction: column; gap: 14px; }

/* Menu de la modale d'ajout rapide */
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.quick-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 5px;
  padding: 15px 14px; border-radius: 15px;
  border: 1px solid var(--border); background: var(--surface-2);
  font: inherit; text-align: left; cursor: pointer; color: inherit;
}
.quick-btn .qi { font-size: 25px; }
.quick-btn b { font-size: .9rem; font-weight: 650; }

/* ---------- Onglets internes ---------- */
.subtabs {
  display: flex; gap: 6px; overflow-x: auto;
  padding-bottom: 2px; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.subtabs::-webkit-scrollbar { display: none; }
.subtab {
  padding: 8px 14px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface);
  font: inherit; font-size: .84rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.subtab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Alertes du tableau de bord ---------- */
.alert-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 15px; border-bottom: 1px solid var(--border);
}
.alert-item:last-child { border-bottom: none; }
.alert-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; }
.alert-dot.danger { background: var(--danger); }
.alert-dot.warn   { background: var(--warn); }
.alert-dot.info   { background: var(--info); }

/* ---------- Graphiques ---------- */
.chart-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-wrap svg { display: block; max-width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 13px; padding: 4px 2px 0; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; }
.legend-swatch { width: 15px; height: 3.5px; border-radius: 2px; }

/* ---------- Vignettes photo ---------- */
.thumb {
  width: 56px; height: 56px; flex: 0 0 56px;
  border-radius: 11px; object-fit: cover;
  background: var(--surface-2); border: 1px solid var(--border);
  cursor: pointer;
}
.photo-full { width: 100%; border-radius: 13px; display: block; }

/* ---------- Info-bulles ---------- */
.toast-root {
  position: fixed; left: 0; right: 0; z-index: 150;
  bottom: calc(88px + var(--safe-b));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  background: #14181f; color: #fff;
  padding: 10px 17px; border-radius: 999px;
  font-size: .85rem; font-weight: 600;
  box-shadow: 0 6px 22px rgba(0,0,0,.28);
  animation: fade .16s ease;
}
.toast.err { background: var(--danger); }

/* ---------- Divers ---------- */
.kv { display: flex; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: none; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; font-weight: 600; text-align: right; font-size: .9rem; }

.banner {
  padding: 12px 14px; border-radius: 13px;
  font-size: .84rem; line-height: 1.45;
  background: var(--info-soft); color: var(--info);
}
.banner.warn { background: var(--warn-soft); color: var(--warn); }
