/* ============================================================
   VARIABLES CSS
============================================================ */
:root {
  --node-w: 160px;
  --node-h: 130px;
  --gap-xl: 56px;
  --gap-lg: 36px;
  --gap-md: 20px;
  --radius: 14px;
  --safe-gutter: 0px;
}

/* ============================================================
   PAGE
============================================================ */
body.tree-page {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 12px 36px;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 50%, #f5f5f5 100%);
  min-height: 100vh;
  box-sizing: border-box;
  font-family: Inter, system-ui, 'Segoe UI', Roboto, Arial, sans-serif;
  color: #333333;
}
header { position: sticky; top: 0; z-index: 100; }
.close, .open { background: #000000 !important; backdrop-filter: none !important; }

/* ============================================================
   TITRE
============================================================ */
.tree-title {
  text-align: center;
  font-family: 'Aboreto', cursive;
  font-size: 2.5rem;
  font-weight: 300;
  color: #2c3e50;
  text-shadow: 0 2px 4px rgba(0,0,0,0.1);
  margin: 24px 0 0;
}

/* ============================================================
   ASTUCE MOBILE + BARRE COMPACTE
============================================================ */
.page-hint-mobile {
  display: none;
  text-align: center;
  font-size: 13px;
  color: #666666;
  margin: 6px 16px 2px;
}
.compact-toggle-row {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: transparent;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  padding: 10px 16px;
}
.view-toggle {
  border: 1px solid rgba(41,182,246,0.3);
  background: transparent;
  color: #333333;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.3s;
}

/* ============================================================
   RECHERCHE
============================================================ */
#memberSearch {
  border-radius: 6px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #333333;
  font-size: 14px;
  padding: 6px 10px;
  min-width: 200px;
  outline: none;
  transition: border-color 0.2s;
}
#memberSearch:focus { border-color: #29b6f6; }
#memberSearch::placeholder { color: #666666; }
.search-results {
  position: absolute;
  background: rgba(15,15,20,0.95);
  border: 1px solid #29b6f6;
  border-top: none;
  border-radius: 0 0 6px 6px;
  z-index: 100;
  max-height: 250px;
  overflow-y: auto;
  width: 100%;
}
.search-results .result-item {
  padding: 10px 12px;
  font-size: 14px;
  color: #cccccc;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
  transition: background 0.2s;
}
.search-results .result-item:hover { background: rgba(41,182,246,0.1); }

/* ============================================================
   TREE WRAPPER + CANVAS
============================================================ */
.tree-wrapper {
  overflow: auto;
  scroll-behavior: smooth;
  background: linear-gradient(135deg, rgba(41,182,246,0.02) 0%, rgba(99,102,241,0.02) 100%);
  flex: 1;
  min-height: 0;
  cursor: grab;
}
.tree-wrapper:active { cursor: grabbing; }
.tree {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 24px 0;
  min-height: 560px;
}
#dynamicGenerations {
  display: block;
  position: relative;
  max-width: 1400px;
  width: 100%;
}

/* ============================================================
   NIVEAUX (.level)
============================================================ */
.level {
  display: flex;
  align-items: flex-start;
  column-gap: var(--gap-lg);
  min-height: 220px;
  padding: 12px 0;
}
.level.gp {
  align-items: flex-end;
  justify-content: center;
}
.gp-pair {
  display: flex;
  align-items: flex-end;
  gap: 44px;
}
.level.gen2 {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  min-height: 220px;
}
.gen2-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.level.children {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--gap-lg);
  border-top: 1px solid rgba(41,182,246,0.1);
  width: 100%;
  overflow-x: auto;
  min-height: unset;
  padding: 12px 10px;
}
.children-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  border-left: 2px solid rgba(0,0,0,0.06);
  padding-left: 8px;
}
.children-container {
  display: flex;
  gap: var(--gap-md);
  flex-wrap: wrap;
  padding: 4px 0;
  align-items: flex-start;
}
.child-wrapper {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  flex-direction: column;
  gap: 6px;
}
.expanded-children { border-top: 2px dashed rgba(41,182,246,0.08); padding: 6px 12px 12px; }
.family-group     { border: 1px dashed rgba(0,0,0,0.06); border-radius: 6px; padding: 6px; margin: 6px; }

/* ============================================================
   NŒUD (.node)
============================================================ */
.node {
  position: relative;
  width: var(--node-w);
  min-height: var(--node-h);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  text-align: center;
  gap: 10px;
  font-family: 'Aboreto', cursive;
  font-weight: 600;
  color: #333333;
  box-sizing: border-box;
  background: transparent;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.node.parent:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 24px rgba(0,0,0,0.35);
}
.node:focus-visible {
  box-shadow: 0 0 0 3px rgba(123,228,149,0.08);
}
.node.highlight {
  outline: 3px solid rgba(58,208,255,0.12);
  border-radius: calc(var(--radius) + 6px);
}
.node.spouse {
  opacity: 0.95;
  border: 1px dashed rgba(255,255,255,0.3);
  width: calc(var(--node-w) - 20px);
}

/* Avatar */
.node .avatar {
  width: 90px;
  height: 90px;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.12);
  background-color: #1b2230;
  box-shadow: 0 6px 14px rgba(0,0,0,0.25);
  transition: opacity 0.3s ease;
  display: block;
}

/* Bloc nom */
.node .name {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  white-space: normal;
  word-break: break-word;
}
.node .prenom,
.node .nom_famille { display: block; }

/* Bouton conjoint (absolu top-right) */
.node .toggle-conjoint {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #ff6b9d, #c06c84);
  box-shadow: 0 2px 8px rgba(255,107,157,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  transition: all 0.3s ease;
  z-index: 10;
}
.node .toggle-conjoint:hover { transform: scale(1.1); }
.node .toggle-conjoint.showing-conjoint {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

/* Bouton Voir */
.node .view {
  border-radius: 999px;
  background: #29b6f6;
  color: #071018;
  font-size: 0.85rem;
  border: none;
  padding: 4px 12px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* ============================================================
   BOUTONS EXPAND
============================================================ */
.expand-lineage-btn,
.expand-child-btn {
  min-width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(41,182,246,0.2);
  background: transparent;
  color: #333333;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.2s ease;
}
.expand-lineage-btn { font-size: 16px; }
.expand-child-btn   { font-size: 14px; }
.expand-lineage-btn:hover,
.expand-child-btn:hover {
  background: rgba(41,182,246,0.08);
  transform: translateY(-2px);
}
.expand-lineage-btn.active,
.expand-child-btn.active {
  background: rgba(41,182,246,0.18);
  border-color: rgba(41,182,246,0.3);
  transform: translateY(-1px);
}

/* ============================================================
   SÉPARATEUR CŒUR GEN1
============================================================ */
.gp-heart {
  font-size: 1.4rem;
  color: #d4af37;
  align-self: center;
  user-select: none;
}

/* ============================================================
   LABEL ENFANTS
============================================================ */
.children-label {
  width: 100%;
  text-align: center;
  font-size: 11px;
  font-weight: 500;
  color: #64748b;
  letter-spacing: 0.4px;
  padding: 4px 0 8px;
  text-transform: uppercase;
}

/* ============================================================
   RESPONSIVE
============================================================ */
@media (max-width: 1200px) {
  .tree { padding-left: 80px; }
}
@media (max-width: 1024px) {
  :root { --node-w: 140px; --node-h: 110px; }
  .compact-toggle-row { display: flex; }
  .page-hint-mobile   { display: block; }
}
@media (max-width: 900px) {
  :root { --node-w: 140px; }
  .tree { padding-left: 100px; min-width: 900px; }
  .tree-wrapper { padding-left: 8px; }
}
@media (max-width: 640px) {
  :root { --node-w: 132px; --safe-gutter: 84px; }
  .node .avatar { width: 80px; height: 80px; }
  .tree { min-width: 780px; }
  .spouse-pair { flex-direction: row !important; }
}
@media (max-width: 480px) {
  :root { --node-w: 132px; }
  .node .avatar { width: 80px; height: 80px; }
  .node .nom_famille { font-size: 12px; }
  .compact-toggle-row { flex-direction: column; }
  #memberSearch { width: 100%; min-width: unset; }
}
