@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;1,400&family=DM+Sans:wght@300;400;500&family=DM+Mono:wght@400&display=swap');

:root {
  --bg:         #F5F1EB;
  --bg2:        #EDE8DF;
  --surface:    #FAF8F4;
  --border:     #D5CFC4;
  --border2:    #C4BDB0;
  --text:       #1C1A17;
  --text2:      #5C5649;
  --text3:      #8C8478;
  --accent:     #8B3A2A;
  --accent2:    #A84E3A;
  --accent-bg:  #F2E8E5;
  --green:      #2D6A4F;
  --green-bg:   #E6F0EC;
  --amber:      #7A5C1E;
  --amber-bg:   #F5EDD8;
  --info:       #1D4E89;
  --info-bg:    #E3ECF5;
  --danger:     #7B1D1D;
  --danger-bg:  #F5E3E3;
  --dark:       #1C1A17;
  --dark2:      #2C2A27;

  --font-display: 'Playfair Display', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
  --font-mono:    'DM Mono', monospace;

  --radius-sm: 6px;
  --radius:    12px;
  --radius-lg: 18px;
  --shadow:    0 2px 8px rgba(28,26,23,.10);
  --shadow-lg: 0 8px 32px rgba(28,26,23,.15);

  --nav-h: 60px;
  --header-h: 56px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-weight: 300;
  line-height: 1.6; min-height: 100%; min-height: 100dvh;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: var(--font-body); }
input, select, textarea { font-family: var(--font-body); }
h1,h2,h3,h4 { font-family: var(--font-display); font-weight: 400; line-height: 1.25; }

/* ── App shell ─────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

/* ── Header ────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: var(--dark); color: #fff;
  display: flex; align-items: center; padding: 0 16px; gap: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.app-header .back-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,.1); border: none; color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.app-header .title {
  font-family: var(--font-display); font-size: 1.05rem;
  color: #fff; flex: 1;
}
.app-header .header-actions { display: flex; gap: 8px; }

/* ── Bottom nav ────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: var(--dark); border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  color: rgba(255,255,255,.4); font-size: .65rem;
  border: none; background: transparent; cursor: pointer;
  transition: color .15s;
}
.nav-item.active { color: var(--accent2); }
.nav-item svg { width: 22px; height: 22px; }

/* ── Pages ─────────────────────────────────── */
.page { display: none; flex: 1; overflow-y: auto; padding-bottom: calc(var(--nav-h) + 16px); }
.page.active { display: block; }

/* ── Login screen ──────────────────────────── */
.login-screen {
  min-height: 100dvh; background: var(--dark);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px;
}
.login-logo {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-family: var(--font-display); font-size: 1.8rem;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px;
}
.login-title {
  font-family: var(--font-display); font-size: 1.8rem;
  color: #fff; margin-bottom: 4px;
}
.login-sub { color: rgba(255,255,255,.4); font-size: .85rem; margin-bottom: 36px; }
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border-radius: var(--radius-lg);
  overflow: hidden; box-shadow: var(--shadow-lg);
}
.login-card-body { padding: 24px; }
.login-field { margin-bottom: 16px; }
.login-field label { display: block; font-size: .75rem; font-weight: 500; color: var(--text3); margin-bottom: 5px; }
.login-field input {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font-size: 1rem;
  -webkit-appearance: none;
}
.login-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139,58,42,.15); }
.login-btn {
  width: 100%; padding: 14px;
  background: var(--accent); border: none; border-radius: var(--radius-sm);
  color: #fff; font-size: 1rem; font-family: var(--font-display);
  cursor: pointer; margin-top: 4px; transition: background .15s;
}
.login-btn:active { background: var(--accent2); }
.login-error {
  background: var(--danger-bg); color: var(--danger);
  border-radius: var(--radius-sm); padding: 10px 14px;
  font-size: .82rem; margin-bottom: 14px; display: none;
}
.login-error.show { display: block; }

/* ── Branche selector ──────────────────────── */
.branch-screen {
  min-height: 100dvh; background: var(--dark);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px;
}
.branch-title { font-family: var(--font-display); font-size: 1.3rem; color: #fff; margin-bottom: 8px; }
.branch-sub { color: rgba(255,255,255,.4); font-size: .85rem; margin-bottom: 28px; text-align: center; }
.branch-list { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.branch-item {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px 18px; display: flex; align-items: center; gap: 14px;
  cursor: pointer; transition: all .15s; border: 2px solid transparent;
}
.branch-item:active { border-color: var(--accent); background: var(--accent-bg); }
.branch-icon {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent-bg); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 1.1rem; flex-shrink: 0;
}
.branch-name { font-weight: 500; }
.branch-count { font-size: .78rem; color: var(--text3); margin-top: 2px; }

/* ── Cards ─────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin: 12px 16px;
  overflow: hidden; box-shadow: var(--shadow);
}
.card-header {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.card-header h3 { font-family: var(--font-display); font-size: .95rem; flex: 1; }
.card-body { padding: 16px; }

/* ── Fiche individu ────────────────────────── */
.fiche-hero {
  background: var(--dark); padding: 24px 16px 20px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.fiche-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-family: var(--font-display); font-size: 1.6rem;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px; border: 3px solid rgba(255,255,255,.15);
}
.fiche-nom { font-family: var(--font-display); font-size: 1.3rem; color: #fff; }
.fiche-aboville { color: rgba(255,255,255,.5); font-size: .78rem; font-family: var(--font-mono); margin-top: 4px; }
.fiche-badges { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }

/* ── Info rows ─────────────────────────────── */
.info-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--border);
}
.info-row:last-child { border-bottom: none; }
.info-label { font-size: .72rem; font-weight: 500; color: var(--text3); min-width: 110px; flex-shrink: 0; }
.info-val { font-size: .9rem; color: var(--text); flex: 1; }
.info-val a { color: var(--accent); }

/* ── Famille links ─────────────────────────── */
.famille-link {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .12s;
  -webkit-tap-highlight-color: transparent;
}
.famille-link:last-child { border-bottom: none; }
.famille-link:active { background: var(--bg2); margin: 0 -16px; padding: 12px 16px; }
.famille-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent-bg); color: var(--accent);
  font-family: var(--font-display); font-size: .9rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.famille-info { flex: 1; }
.famille-nom { font-size: .9rem; font-weight: 500; }
.famille-lien { font-size: .75rem; color: var(--text3); }
.famille-aboville { font-size: .72rem; color: var(--text3); font-family: var(--font-mono); }
.famille-chevron { color: var(--text3); }

/* ── Arbre généalogique ────────────────────── */
.tree-wrap { padding: 16px; overflow-x: auto; }
.tree-level { display: flex; gap: 10px; justify-content: center; margin-bottom: 20px; position: relative; }
.tree-level::after {
  content: ''; position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%);
  width: 1px; height: 12px; background: var(--border2);
}
.tree-node {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer; padding: 10px 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  min-width: 90px; transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.tree-node:active { border-color: var(--accent); background: var(--accent-bg); }
.tree-node.current { border-color: var(--accent); background: var(--accent-bg); }
.tree-node .t-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg2); color: var(--text2);
  font-family: var(--font-display); font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
}
.tree-node.current .t-avatar { background: var(--accent); color: #fff; }
.tree-node .t-nom { font-size: .72rem; font-weight: 500; text-align: center; line-height: 1.2; }
.tree-node .t-lien { font-size: .65rem; color: var(--text3); }
.tree-connector { display: flex; justify-content: center; margin-bottom: 8px; }
.tree-connector-line { width: 1px; height: 16px; background: var(--border2); }

/* ── Search ────────────────────────────────── */
.search-wrap { padding: 12px 16px; position: sticky; top: var(--header-h); z-index: 50; background: var(--bg); border-bottom: 1px solid var(--border); }
.search-input-wrap { position: relative; }
.search-input-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text3); }
.search-input {
  width: 100%; padding: 10px 12px 10px 38px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: .9rem; color: var(--text);
  -webkit-appearance: none;
}
.search-input:focus { outline: none; border-color: var(--accent); }

/* ── Liste individus ───────────────────────── */
.individu-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .12s;
  -webkit-tap-highlight-color: transparent;
}
.individu-item:active { background: var(--bg2); }
.ind-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent-bg); color: var(--accent);
  font-family: var(--font-display); font-size: 1rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.ind-info { flex: 1; }
.ind-nom { font-weight: 500; font-size: .95rem; }
.ind-meta { font-size: .75rem; color: var(--text3); margin-top: 2px; }
.ind-chevron { color: var(--text3); }

/* ── Badges ────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 99px; font-size: .7rem; font-weight: 500; }
.badge-terra  { background: var(--accent-bg); color: var(--accent); }
.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-amber  { background: var(--amber-bg);  color: var(--amber); }
.badge-blue   { background: var(--info-bg);   color: var(--info); }
.badge-gray   { background: var(--bg2);       color: var(--text2); }
.badge-red    { background: var(--danger-bg); color: var(--danger); }

/* ── Boutons ───────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 400; transition: all .15s;
  border: 1px solid var(--border); background: var(--surface); color: var(--text2);
  cursor: pointer; font-family: var(--font-body);
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent2); }
.btn-full { width: 100%; }
.btn-lg { padding: 14px 20px; font-size: 1rem; }

/* ── Formulaire MAJ ────────────────────────── */
.form-section { padding: 0 16px; margin-bottom: 8px; }
.form-section-title {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text3); font-weight: 500; padding: 14px 0 6px;
}
.form-field { margin-bottom: 14px; }
.form-field label { display: block; font-size: .75rem; font-weight: 500; color: var(--text2); margin-bottom: 5px; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: .9rem;
  font-family: var(--font-body); -webkit-appearance: none;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: none; border-color: var(--accent);
}
.form-field textarea { min-height: 80px; resize: vertical; }
.form-check { display: flex; align-items: center; gap: 10px; padding: 12px 0; }
.form-check input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.form-check label { font-size: .9rem; color: var(--text); }

/* ── Admin MAJ panel ───────────────────────── */
.maj-card {
  margin: 12px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.maj-card-header {
  padding: 14px 16px; background: var(--accent-bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.maj-card-header .title { font-weight: 500; font-size: .9rem; flex: 1; }
.maj-card-header .date { font-size: .72rem; color: var(--text3); font-family: var(--font-mono); }
.maj-card-body { padding: 14px 16px; }
.maj-stat { font-size: .82rem; color: var(--text2); margin-bottom: 12px; }

/* ── Toast ─────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 16px; right: 16px;
  background: var(--text); color: var(--bg);
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: .875rem; z-index: 500;
  animation: slideUp .25s ease; box-shadow: var(--shadow-lg);
}
@keyframes slideUp { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:translateY(0); } }

/* ── Modal ─────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(28,26,23,.5);
  z-index: 300; display: flex; align-items: flex-end;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-sheet {
  width: 100%; background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 90dvh; overflow-y: auto;
  transform: translateY(100%); transition: transform .25s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
.modal-overlay.open .modal-sheet { transform: translateY(0); }
.modal-handle { width: 36px; height: 4px; background: var(--border2); border-radius: 2px; margin: 12px auto 0; }
.modal-header { padding: 16px 20px 12px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-family: var(--font-display); font-size: 1.05rem; }
.modal-body { padding: 16px 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; }

/* ── Empty state ───────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text3); }
.empty-state svg { opacity: .3; margin-bottom: 12px; }
.empty-state p { font-size: .875rem; }

/* ── Skeleton loader ───────────────────────── */
.skeleton { background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3,#ddd) 50%, var(--bg2) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Scroll ────────────────────────────────── */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── Utilitaires ───────────────────────────── */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.px-16 { padding: 0 16px; }
.text-sm { font-size: .8rem; }
.text-muted { color: var(--text3); }
.text-mono { font-family: var(--font-mono); font-size: .82rem; }
.ml-auto { margin-left: auto; }
.w-full { width: 100%; }
.divider { height: 1px; background: var(--border); margin: 8px 0; }
