/* Focal Person Family Tree – Modern Animated Pedigree UI */
:root {
  --tree-bg: #f8fafc; /* Very light slate for modern background */
  --card-bg: rgba(255, 255, 255, 0.95); /* Slight transparency for glass effect */
  --card-border: rgba(226, 232, 240, 0.8);
  --focal-border: #3b82f6;
  
  /* Modern gender gradients matching Father/Mother side */
  --male-bg: linear-gradient(145deg, #e7f1ff 0%, #cfe2ff 100%);
  --male-border: #0d6efd;
  --female-bg: linear-gradient(145deg, #cff4fc 0%, #9eeaf9 100%);
  --female-border: #0dcaf0;
  
  --line-color: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --shadow-sm: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
  --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.08), 0 10px 10px -5px rgba(0,0,0,0.04);
}

.tree-page { min-height: 100vh; display: flex; flex-direction: column; background: var(--tree-bg); }

/* Header & Toolbar */
.tree-page .tree-page-header {
  background: linear-gradient(135deg, var(--primary, #16a34a) 0%, var(--primary-dark, #15803d) 50%, #0f172a 100%);
  color: #fff;
  padding: 1.5rem 0 1rem;
}
.tree-page-header h1 { font-size: 1.5rem; font-weight: 700; margin: 0; }
.tree-page-header .tree-subtitle { font-size: 0.9rem; opacity: 0.9; margin: 0; }

.tree-toolbar {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border, #e2e8f0);
  padding: 0.75rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.03);
}
.tree-toolbar-inner { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; justify-content: space-between; }
.tree-back-link { font-size: 0.85rem; font-weight: 500; color: #334155; text-decoration: none; padding: 0.4rem 0.8rem; border: 1px solid #cbd5e1; border-radius: 8px; transition: all 0.2s; }
.tree-back-link:hover { background: #f1f5f9; color: #0f172a; }
.tree-btn { padding: 0.4rem 0.8rem; font-size: 0.85rem; border-radius: 8px; border: 1px solid #cbd5e1; background: #fff; cursor: pointer; color: #334155; font-weight: 500; transition: all 0.2s; }
.tree-btn:hover { background: #f1f5f9; color: #0f172a; }

/* Focal Tree Container with smooth transitions */
.focal-tree-container {
  flex: 1;
  display: block; /* Use block to prevent flex align-items clipping on overflow */
  text-align: center;
  padding: 2.5rem 1rem 5rem;
  overflow-x: auto;
  overflow-y: auto;
  transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
}
.focal-tree-container.reloading {
  opacity: 0.4;
  transform: scale(0.98);
}

.tree-tier {
  display: inline-flex; /* Safe centering when combined with text-align: center on parent */
  justify-content: center;
  align-items: flex-start;
  gap: 1.5rem;
  position: relative;
  margin: 0 auto;
}

.tier-ancestors { margin-bottom: 1rem; }
.tier-focal { margin-bottom: 1rem; gap: 1.5rem; flex-wrap: wrap; z-index: 10; }

.highlight-tier {
  position: relative;
  padding: 1.5rem 2rem;
  border: 2px dashed #94a3b8;
  border-radius: 40px;
  background: rgba(226, 232, 240, 0.3);
  display: inline-flex; /* allow it to grow horizontally with children */
  justify-content: center;
}

.tier-descendants { flex-wrap: nowrap; gap: 1.5rem; }

/* Elegant Connecting Lines */
.vertical-line {
  width: 3px;
  height: 2.5rem;
  background-color: var(--line-color);
  margin: 0 auto;
  border-radius: 2px;
}
.connection-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

/* CSS-Only Responsive Tree Connections for Descendants */
.tier-descendants {
  flex-wrap: nowrap;
  gap: 0;
  justify-content: center;
}

.child-node {
  position: relative;
  padding: 2.5rem 0.75rem 0; /* Space for the line above */
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* The vertical drop-down line to the child card */
.child-node::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 3px;
  height: 2.5rem;
  background-color: var(--line-color);
  transform: translateX(-50%);
  border-radius: 2px;
}

/* The horizontal spanning line */
.child-node::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background-color: var(--line-color);
  border-radius: 2px;
}

/* Hide horizontal line for single child */
.child-node:only-child::after { display: none; }

/* For the first child, line starts at 50% */
.child-node:first-child::after {
  left: 50%;
  width: 50%;
}

/* For the last child, line stops at 50% */
.child-node:last-child::after {
  width: 50%;
}

/* Modern Tree Cards */
.person-card, .focal-card, .spouse-card {
  width: 160px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease, border-color 0.3s ease;
  position: relative;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.person-top-label {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 10px;
  border-radius: 12px;
  white-space: nowrap;
  z-index: 10;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.person-card:hover .person-top-label, .focal-card:hover .person-top-label {
  background: var(--focal-border);
}

/* Staggered entrance animation */
.animate-in {
  opacity: 0;
  animation: slideFadeUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes slideFadeUp {
  0% { opacity: 0; transform: translateY(15px); }
  100% { opacity: 1; transform: translateY(0); }
}

.person-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
  border-color: #94a3b8;
  z-index: 20;
}

.focal-card {
  border: 2px dashed var(--focal-border);
  box-shadow: 0 10px 25px -5px rgba(59, 130, 246, 0.25);
  transform: scale(1);
}
.focal-card:hover { transform: translateY(-4px); border-color: var(--focal-border); }

/* Remove old spouse-card background override so it inherits gradients */
.spouse-card {
  /* No solid white background, it inherits from male/female below */
}

.person-card.male, .focal-card.male, .spouse-card.male { background: var(--male-bg); border-color: var(--male-border); }
.person-card.female, .focal-card.female, .spouse-card.female { background: var(--female-bg); border-color: var(--female-border); }

.focal-card.male { border: 2px dashed #3b82f6; }
.focal-card.female { border: 2px dashed #ec4899; }

/* Sub-ordinate styling for descendant spouses */
.tier-descendants .spouse-card {
  width: 120px;
  padding: 0.75rem 0.5rem;
  border-radius: 16px;
}
.tier-descendants .spouse-card .person-avatar {
  width: 44px;
  height: 44px;
  border-width: 2px;
}
.tier-descendants .spouse-card .person-name {
  font-size: 0.75rem;
}
.tier-descendants .spouse-card .person-top-label {
  font-size: 0.65rem;
  padding: 2px 8px;
  top: -10px;
}

.person-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 0.6rem;
  border: 3px solid #fff;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  transition: transform 0.3s ease;
}
.person-card:hover .person-avatar, .focal-card:hover .person-avatar, .spouse-card:hover .person-avatar { transform: scale(1.08); }

.person-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.3;
  margin-bottom: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.person-meta { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }
.person-status { font-size: 0.75rem; font-weight: 600; color: #ef4444; margin-top: 4px; background: #fef2f2; padding: 2px 6px; border-radius: 12px; }

.tree-placeholder {
  width: 155px;
  height: 100px;
  border: 2px dashed #cbd5e1;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  font-size: 0.85rem;
  font-weight: 500;
  background: rgba(241, 245, 249, 0.5);
}

/* Loader */
.tree-loader {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.7);
  display: none; align-items: center; justify-content: center;
  z-index: 1050; backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid #e2e8f0; border-top-color: var(--primary, #16a34a);
  border-radius: 50%; animation: spin 0.8s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Mobile Adaptations */
@media (max-width: 768px) {
  .tree-tier { gap: 1rem; }
  .person-card, .focal-card, .spouse-card { width: 130px; padding: 0.75rem 0.5rem; border-radius: 16px; }
  .person-avatar { width: 48px; height: 48px; }
  .person-name { font-size: 0.8rem; }
  .tree-placeholder { width: 130px; }
  
  .tier-descendants .spouse-card { width: 100px; padding: 0.5rem; border-radius: 12px; }
  .tier-descendants .spouse-card .person-avatar { width: 36px; height: 36px; }
  .tier-descendants .spouse-card .person-name { font-size: 0.7rem; }
}
