/**
 * Feuille de styles — Arbre Généalogique Interactif
 * Maison Girard Jacquet — Pommard, Bourgogne
 * Éco-conçu en CSS3 pur (Green IT < 10 Ko, zéro dépendance)
 */

:root {
  --mgj-burgundy: #722f37;
  --mgj-burgundy-dark: #4a1d23;
  --mgj-burgundy-light: #944049;
  --mgj-gold: #c59b27;
  --mgj-gold-light: #e8c86b;
  --mgj-gold-subtle: #fcf8ee;
  --mgj-stone: #fdfbf7;
  --mgj-stone-dark: #e8e2d5;
  --mgj-text: #2d2621;
  --mgj-text-muted: #6e645a;
  --mgj-white: #ffffff;
  --mgj-shadow-sm: 0 2px 8px rgba(45, 38, 33, 0.08);
  --mgj-shadow-md: 0 6px 20px rgba(45, 38, 33, 0.12);
  --mgj-shadow-lg: 0 12px 36px rgba(45, 38, 33, 0.18);
  --mgj-radius: 8px;
  --mgj-transition: 0.22s ease-in-out;
}

/* Base du conteneur de page */
.mgj-genealogy-page {
  background: var(--mgj-stone);
  color: var(--mgj-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, serif;
  line-height: 1.5;
  padding: 2rem 1rem 4rem;
  max-width: 1600px;
  margin: 0 auto;
  box-sizing: border-box;
}

/* En-tête explicatif */
.mgj-gen-header {
  text-align: center;
  max-width: 860px;
  margin: 0 auto 2rem;
}
.mgj-gen-badge {
  display: inline-block;
  padding: 0.35rem 1rem;
  background: var(--mgj-gold-subtle);
  border: 1px solid var(--mgj-gold);
  color: var(--mgj-burgundy-dark);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  border-radius: 30px;
  margin-bottom: 0.75rem;
}
.mgj-gen-title {
  font-family: "Playfair Display", "Cinzel", "Georgia", serif;
  font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  font-weight: 700;
  color: var(--mgj-burgundy-dark);
  margin: 0 0 0.75rem;
  line-height: 1.25;
}
.mgj-gen-subtitle {
  font-size: 1.05rem;
  color: var(--mgj-text-muted);
  margin: 0 0 1rem;
  font-style: italic;
}
.mgj-gen-intro {
  font-size: 0.95rem;
  color: var(--mgj-text);
  line-height: 1.65;
  margin: 0;
}

/* Barre d'outils interactive */
.mgj-toolbar {
  background: var(--mgj-white);
  border: 1px solid var(--mgj-stone-dark);
  border-radius: var(--mgj-radius);
  box-shadow: var(--mgj-shadow-sm);
  padding: 0.85rem 1.2rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.mgj-toolbar-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.mgj-toolbar-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--mgj-text-muted);
  letter-spacing: 0.06em;
  margin-right: 0.25rem;
}

/* Boutons d'outils */
.mgj-btn {
  appearance: none;
  background: var(--mgj-stone);
  border: 1px solid var(--mgj-stone-dark);
  color: var(--mgj-text);
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all var(--mgj-transition);
  user-select: none;
}
.mgj-btn:hover {
  background: var(--mgj-gold-subtle);
  border-color: var(--mgj-gold);
  color: var(--mgj-burgundy-dark);
}
.mgj-btn.active {
  background: var(--mgj-burgundy);
  border-color: var(--mgj-burgundy-dark);
  color: var(--mgj-white);
  font-weight: 600;
}
.mgj-btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  justify-content: center;
}
.mgj-btn-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Sélecteur de génération */
.mgj-select {
  background: var(--mgj-stone);
  border: 1px solid var(--mgj-stone-dark);
  color: var(--mgj-text);
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  border-radius: 6px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--mgj-transition);
}
.mgj-select:focus {
  border-color: var(--mgj-gold);
}

/* Barre de recherche et autocomplétion */
.mgj-search-box {
  position: relative;
  min-width: 260px;
  flex: 1 1 260px;
  max-width: 340px;
}
.mgj-search-input {
  width: 100%;
  padding: 0.45rem 2.2rem 0.45rem 0.85rem;
  border: 1px solid var(--mgj-stone-dark);
  border-radius: 6px;
  background: var(--mgj-stone);
  font-size: 0.85rem;
  box-sizing: border-box;
  color: var(--mgj-text);
  outline: none;
  transition: all var(--mgj-transition);
}
.mgj-search-input:focus {
  background: var(--mgj-white);
  border-color: var(--mgj-gold);
  box-shadow: 0 0 0 3px rgba(197, 155, 39, 0.15);
}
.mgj-search-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--mgj-text-muted);
  pointer-events: none;
}
.mgj-autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--mgj-white);
  border: 1px solid var(--mgj-stone-dark);
  border-radius: 6px;
  box-shadow: var(--mgj-shadow-md);
  max-height: 280px;
  overflow-y: auto;
  z-index: 100;
  margin: 0;
  padding: 0.35rem 0;
  list-style: none;
  display: none;
}
.mgj-autocomplete-list.visible {
  display: block;
}
.mgj-autocomplete-item {
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  border-bottom: 1px solid #f2eee6;
  transition: background var(--mgj-transition);
}
.mgj-autocomplete-item:last-child {
  border-bottom: none;
}
.mgj-autocomplete-item:hover,
.mgj-autocomplete-item.selected {
  background: var(--mgj-gold-subtle);
  color: var(--mgj-burgundy-dark);
}
.mgj-ac-name {
  font-weight: 600;
}
.mgj-ac-meta {
  font-size: 0.72rem;
  color: var(--mgj-text-muted);
}

/* Zone du canvas interactif SVG */
.mgj-tree-viewport {
  position: relative;
  width: 100%;
  height: 680px;
  background: #fbf9f4;
  background-image: 
    radial-gradient(#e5dec9 1px, transparent 1px), 
    radial-gradient(#e5dec9 1px, #fbf9f4 1px);
  background-size: 32px 32px;
  background-position: 0 0, 16px 16px;
  border: 1px solid var(--mgj-stone-dark);
  border-radius: var(--mgj-radius);
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.03);
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.mgj-tree-viewport.is-dragging {
  cursor: grabbing;
}
.mgj-tree-svg {
  width: 100%;
  height: 100%;
  display: block;
  transform-origin: 0 0;
  will-change: transform;
}

/* Lignes et liens SVG */
.mgj-link {
  fill: none;
  stroke: #c8beac;
  stroke-width: 2.2;
  stroke-linecap: round;
  transition: stroke 0.2s, stroke-width 0.2s, opacity 0.2s;
}
.mgj-link.link-direct {
  stroke: #b8a892;
}
.mgj-link.link-marriage {
  stroke: var(--mgj-gold);
  stroke-width: 2.5;
  stroke-dasharray: 6 3;
}
.mgj-link.highlight {
  stroke: var(--mgj-burgundy);
  stroke-width: 3.5;
}

/* Nœuds / Cartes d'ancêtres */
.mgj-node {
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
  outline: none;
}
.mgj-node:hover {
  filter: drop-shadow(0 6px 14px rgba(74, 29, 35, 0.2));
}
.mgj-node.dimmed {
  opacity: 0.18;
  pointer-events: none;
}
.mgj-node.focused rect.node-card {
  stroke: var(--mgj-gold);
  stroke-width: 3.5;
  filter: drop-shadow(0 0 12px rgba(197, 155, 39, 0.5));
}

/* Éléments internes des cartes */
rect.node-card {
  fill: var(--mgj-white);
  stroke: #ded6c5;
  stroke-width: 1.5;
  rx: 8px;
  ry: 8px;
  transition: stroke 0.2s, stroke-width 0.2s;
}
.mgj-node:hover rect.node-card {
  stroke: var(--mgj-gold);
}
rect.node-stripe-girard { fill: var(--mgj-burgundy); }
rect.node-stripe-jacquet { fill: var(--mgj-gold); }
rect.node-stripe-alliance { fill: url(#grad-alliance); }

text.node-name {
  font-family: "Playfair Display", "Georgia", serif;
  font-size: 13.5px;
  font-weight: 700;
  fill: var(--mgj-burgundy-dark);
}
text.node-dates {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 600;
  fill: var(--mgj-gold);
}
text.node-role {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 10px;
  fill: var(--mgj-text-muted);
}
text.node-gen-badge {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  fill: #8b7d6b;
}

/* Pastille & Légende */
.mgj-legend {
  margin-top: 1.25rem;
  background: var(--mgj-white);
  border: 1px solid var(--mgj-stone-dark);
  border-radius: var(--mgj-radius);
  padding: 0.85rem 1.2rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.8rem;
}
.mgj-legend-items {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.2rem;
}
.mgj-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--mgj-text);
}
.mgj-legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-block;
}
.dot-girard { background: var(--mgj-burgundy); }
.dot-jacquet { background: var(--mgj-gold); }
.dot-alliance { background: linear-gradient(135deg, var(--mgj-burgundy), var(--mgj-gold)); }
.dot-marriage {
  width: 20px;
  height: 2px;
  border-top: 2px dashed var(--mgj-gold);
}

/* Boutons de zoom flottants */
.mgj-floating-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--mgj-stone-dark);
  box-shadow: var(--mgj-shadow-sm);
  z-index: 10;
}
.mgj-zoom-level {
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  color: var(--mgj-text-muted);
  padding: 2px 0;
}

/* Modale / Panneau latéral escamotable */
.mgj-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 15, 0.45);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  z-index: 999;
}
.mgj-drawer-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}
.mgj-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 460px;
  background: var(--mgj-stone);
  box-shadow: -6px 0 28px rgba(0, 0, 0, 0.22);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-sizing: border-box;
}
.mgj-drawer.is-open {
  transform: translateX(0);
}

/* Contenu du Drawer */
.mgj-drawer-header {
  position: sticky;
  top: 0;
  background: var(--mgj-white);
  border-bottom: 1px solid var(--mgj-stone-dark);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 2;
}
.mgj-drawer-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--mgj-text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--mgj-transition);
}
.mgj-drawer-close:hover {
  background: var(--mgj-stone-dark);
  color: var(--mgj-burgundy-dark);
}
.mgj-drawer-body {
  padding: 1.5rem;
}
.mgj-portrait-wrap {
  text-align: center;
  margin-bottom: 1.25rem;
}
.mgj-portrait-svg {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 3px solid var(--mgj-gold);
  background: var(--mgj-stone);
  box-shadow: var(--mgj-shadow-sm);
}
.mgj-drawer-name {
  font-family: "Playfair Display", "Georgia", serif;
  font-size: 1.6rem;
  color: var(--mgj-burgundy-dark);
  margin: 0 0 0.35rem;
  text-align: center;
}
.mgj-drawer-dates {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--mgj-gold);
  margin-bottom: 1rem;
}
.mgj-drawer-badges {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
}
.mgj-drawer-badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.65rem;
  border-radius: 20px;
  font-weight: 600;
}
.badge-girard { background: rgba(114, 47, 55, 0.12); color: var(--mgj-burgundy); }
.badge-jacquet { background: rgba(197, 155, 39, 0.16); color: #916f14; }
.badge-alliance { background: linear-gradient(135deg, rgba(114, 47, 55, 0.15), rgba(197, 155, 39, 0.2)); color: var(--mgj-burgundy-dark); }

.mgj-drawer-section {
  background: var(--mgj-white);
  border: 1px solid var(--mgj-stone-dark);
  border-radius: 8px;
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}
.mgj-drawer-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mgj-burgundy);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.mgj-drawer-section p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--mgj-text);
}

/* Liens de parenté dans le tiroir */
.mgj-kin-links {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.mgj-kin-btn {
  background: var(--mgj-stone);
  border: 1px solid var(--mgj-stone-dark);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all var(--mgj-transition);
}
.mgj-kin-btn:hover {
  background: var(--mgj-gold-subtle);
  border-color: var(--mgj-gold);
  color: var(--mgj-burgundy-dark);
}
.mgj-kin-relation {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--mgj-text-muted);
}

/* Animations légères */
@keyframes mgj-pulse-gold {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(197, 155, 39, 0.4)); }
  50% { filter: drop-shadow(0 0 16px rgba(197, 155, 39, 0.9)); }
}
.pulse-node {
  animation: mgj-pulse-gold 1.8s infinite ease-in-out;
}

/* Responsive */
@media (max-width: 900px) {
  .mgj-tree-viewport {
    height: 560px;
  }
  .mgj-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .mgj-search-box {
    max-width: 100%;
  }
  .mgj-drawer {
    max-width: 100%;
  }
}
