/* Main Stylesheet */

/* Buttons */
.btn {
  display: inline-block;
  font-weight: 400;
  color: #212529;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  background-color: transparent;
  border: 1px solid transparent;
  padding: 0.375rem 0.75rem;
  font-size: 1rem;
  line-height: 1.5;
  border-radius: 0.25rem;
  transition:
    color 0.15s ease-in-out,
    background-color 0.15s ease-in-out,
    border-color 0.15s ease-in-out,
    box-shadow 0.15s ease-in-out;
}

.btn-primary {
  color: #fff;
  background-color: #2589bd;
  border-color: #2589bd;
}

.btn-primary:hover {
  color: #fff;
  background-color: #187795;
  border-color: #187795;
}

/* ... (other styles) */

/* Tree Visual Nodes */
/* ... */

.tree-node.active {
  border: 2px solid #2589bd;
  box-shadow: 0 0 10px rgba(37, 137, 189, 0.3);
}

.tree-node i {
  font-size: 2rem;
  color: #a3b4a2; /* Using the sage green for inactive icons */
  margin-bottom: 5px;
  display: block;
}

.tree-node.active i {
  color: #2589bd;
}

/* Tree Section Background */
.tree-visual-section {
  flex: 0 0 70%;
  max-width: 70%;
  background-color: #cdc6ae; /* Using the beige color for background */
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.btn-lg {
  padding: 0.5rem 1rem;
  font-size: 1.25rem;
  line-height: 1.5;
  border-radius: 0.3rem;
}

.btn-block {
  display: block;
  width: 100%;
}

.btn-outline-secondary {
  color: #6c757d;
  border-color: #6c757d;
}

.btn-outline-secondary:hover {
  color: #fff;
  background-color: #6c757d;
  border-color: #6c757d;
}

/* Jumbotron (Hero section) */
.jumbotron {
  padding: 2rem 1rem;
  margin-bottom: 2rem;
  background-color: #e9ecef;
  border-radius: 0.3rem;
}

@media (min-width: 576px) {
  .jumbotron {
    padding: 4rem 2rem;
  }
}

.display-4 {
  font-size: 3.5rem;
  font-weight: 300;
  line-height: 1.2;
}

.lead {
  font-size: 1.25rem;
  font-weight: 300;
}

.my-4 {
  margin-top: 1.5rem !important;
  margin-bottom: 1.5rem !important;
}

hr {
  box-sizing: content-box;
  height: 0;
  overflow: visible;
  border: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

/* Tree Creation UI */
.tree-split-container {
  display: flex;
  min-height: calc(100vh - 70px); /* Subtract header height */
  /* margin removed to prevent overflow */
}

.tree-form-section {
  flex: 0 0 30%;
  max-width: 30%;
  padding: 3rem;
  padding-top: 6rem; /* Added extra top padding to prevent cutoff */
  background-color: #fff;
  display: flex;
  flex-direction: column;
  overflow-y: auto; /* Allow scrolling for long forms */
  justify-content: flex-start; /* Start from top, don't center if overflowing */
  height: calc(100vh - 70px); /* Fixed height to enable scrolling */
}

.tree-visual-section {
  flex: 0 0 70%;
  max-width: 70%;
  background-color: #e0e0e0;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden; /* Hide scrollbars, drag enabled */
  cursor: grab;
  user-select: none;
}

.tree-visual-section:active {
  cursor: grabbing;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  color: #555;
  font-weight: 500;
}

.form-control {
  display: block;
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  line-height: 1.5;
  color: #495057;
  background-color: #fff;
  background-clip: padding-box;
  border: 1px solid #ced4da;
  border-radius: 0.25rem;
  transition:
    border-color 0.15s ease-in-out,
    box-shadow 0.15s ease-in-out;
}

.form-control:focus {
  color: #495057;
  background-color: #fff;
  border-color: #80bdff;
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* Tree Visual Connections */
.tree-structure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 80px; /* Increased gap for vertical lines */
}

.tree-level {
  display: flex;
  gap: 80px; /* Space between family groups */
  justify-content: center;
  position: relative;
}

.tree-node {
  background: #fff;
  border-radius: 8px;
  padding: 15px;
  width: 100px;
  min-height: 120px;
  text-align: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05); /* Softer shadow */
  position: relative;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 2; /* Ensure nodes are above lines */
}

.tree-node.active {
  border: 2px solid #2589bd;
  box-shadow: 0 0 15px rgba(37, 137, 189, 0.2);
  transform: scale(1.05); /* Slight emphasis */
}

.tree-node.disabled {
  opacity: 0.5;
  background-color: #f8f9fa;
  border: 1px dashed #dee2e6;
  box-shadow: none;
}

.tree-node i {
  font-size: 2rem;
  color: #adb5bd;
  margin-bottom: 8px;
  display: block;
}

.tree-node.active i {
  color: #2589bd;
}

.tree-node.filled i {
  color: #2589bd;
}

.node-label {
  display: block;
  font-weight: 600;
  color: #495057;
  margin-bottom: 4px;
}

.node-name {
  display: block;
  color: #6c757d;
  font-size: 0.75rem;
  line-height: 1.2;
}

.family-group {
  display: flex;
  gap: 20px; /* Space between partners */
  position: relative;
}

/* Connect Partners (Grandparents) - THE BOTTOM CENTER STEM */
.grandparents-level .family-group::after {
  content: "";
  position: absolute;
  /* Start from the horizontal bar level */
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 40px;
  background-color: #999;
  z-index: 1;
  margin-top: 40px; /* Offset by the vertical drop length */
}

/* Horizontal Connector Bar (The Crossbar of the T) for Grandparents */
/* Gap increased to 200px. Node width 100px. Center-to-center = 300px. */
.grandparents-level .family-group::before {
  content: "";
  position: absolute;
  bottom: -40px; /* Placed below the nodes */
  left: 50%;
  transform: translateX(-50%);
  width: 302px; /* Center-to-center distance (300px + 2px overlap) */
  height: 2px;
  background-color: #999;
  z-index: 1;
  top: auto; /* Override previous center alignment */
  right: auto;
}

/* Vertical Lines DOWN from each Grandparent Node */
.grandparents-level .tree-node::after {
  content: "";
  position: absolute;
  bottom: -40px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 40px;
  background-color: #999;
  z-index: 0;
}

/* Connect Father/Mother UP to GPs */
.parents-level .branch-wrapper {
  width: 220px;
  display: flex;
  justify-content: center;
  position: relative;
  /* Maintain equal height for children */
  align-items: stretch;
}

/* Ensure tree node fills the wrapper for uniform look */
.parents-level .tree-node {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Connect Father/Mother UP to GPs */
.parents-level .branch-wrapper::before {
  content: "";
  position: absolute;
  top: -40px; /* Starts just above the connector bar level */
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 40px; /* Exact height to reach the bar */
  background-color: #999;
  z-index: 1; /* Bring it back IN FRONT to be visible */
}

/* Hide the duplicate stem down from GP to avoid double drawing,
   but ensuring the parent's line reaches up. */
.grandparents-level .family-group::after {
  display: none;
}

/* --- Connect Parents DOWN to Child (The Requested Style) --- */

/* 1. Vertical Lines DOWN from each Parent Wrapper (Aligned Baseline) */
.parents-level .branch-wrapper::after {
  content: "";
  position: absolute;
  top: 100%; /* Start exactly at bottom of wrapper */
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 40px;
  background-color: #999; /* Updated to match new style */
  z-index: 0;
}

/* Remove old node connector to avoid duplication */
.parents-level .tree-node::after {
  display: none;
}

/* 4. Remove duplicate/conflicting lines */
.parents-level::after {
  display: none;
}

/* ADJUSTMENT: Align Parents with widening Grandparents level */
/* GP Groups are centered at +/- 300px. Distance 600px.
   Parent Wrappers (220px) need to center at +/- 300px.
   Gap + Wrapper = 600 => Gap = 600 - 220 = 380px. */
.parents-level {
  gap: 380px;
}

/* Adjust connector between Father and Mother to span the new distance */
/* Distance between centers is 600px */
.parents-connector {
  position: absolute;
  top: calc(100% + 40px);
  left: 50%;
  transform: translateX(-50%);
  width: 600px; /* Center-to-center dist */
  height: 2px;
  background-color: #999;
  z-index: 5;
}

/* Connect Self UP to Parents Connector */
.self-level .tree-node::before {
  content: "";
  position: absolute;
  top: -40px; /* Exact fit, was -42px causing overlap */
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 40px; /* Exact fit */
  background-color: #999; /* Updated to match new style */
  z-index: 1; /* Match visibility */
}

/* Modern Tree Creation Styles */
.modern-tree-card {
  background: white;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08); /* Suave sombra */
  border: none;
  overflow: hidden;
  transition: transform 0.3s ease;
  margin: 0;
  max-width: 450px;
  width: 100%;
}

.modern-tree-card:hover {
  transform: translateY(-5px);
}

.modern-tree-card .card-body {
  padding: 3rem !important;
}

.modern-icon-container {
  width: 90px;
  height: 90px;
  background: linear-gradient(
    135deg,
    rgba(37, 137, 189, 0.1) 0%,
    rgba(37, 137, 189, 0.05) 100%
  );
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  box-shadow: 0 5px 15px rgba(37, 137, 189, 0.1);
}

.modern-icon-container i {
  color: #2589bd;
  font-size: 2.5rem;
}

.modern-title {
  color: #2c3e50;
  font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: -0.5px;
}

.modern-subtitle {
  color: #7f8c8d;
  font-size: 1.1rem;
  margin-bottom: 2rem;
}

.modern-input-group {
  position: relative;
  margin-bottom: 1.5rem;
  background: #f8f9fa;
  border-radius: 12px;
  border: 1px solid #e9ecef;
  transition: all 0.3s ease;
  padding: 5px;
}

.modern-input-group:focus-within {
  background: white;
  border-color: #2589bd;
  box-shadow: 0 0 0 4px rgba(37, 137, 189, 0.1);
}

.modern-input-icon {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: #adb5bd;
  font-size: 1.1rem;
  transition: color 0.3s ease;
  z-index: 10;
}

.modern-input-group:focus-within .modern-input-icon {
  color: #2589bd;
}

.modern-form-control {
  width: 100%;
  border: none;
  background: transparent;
  padding: 12px 15px 12px 45px; /* Space for icon */
  font-size: 1rem;
  color: #495057;
  border-radius: 10px;
  outline: none;
}

.modern-form-control::placeholder {
  color: #ced4da;
}

.modern-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: #34495e;
  margin-bottom: 0.5rem;
  margin-left: 5px;
}

.modern-btn {
  background: linear-gradient(135deg, #2589bd 0%, #1a5c80 100%);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 15px 30px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  width: 100%;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(37, 137, 189, 0.3);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.modern-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(37, 137, 189, 0.4);
  background: linear-gradient(135deg, #2aa0dd 0%, #1e6ea0 100%);
  color: white; /* Ensure text remains white */
}

.modern-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 10px rgba(37, 137, 189, 0.3);
}

.invalid-feedback-modern {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  font-size: 0.875em;
  color: #dc3545;
  padding-left: 10px;
}

/* Custom Modal Styles */
.modal-overlay {
  display: none; /* Hidden by default */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black */
  z-index: 2000; /* Above everything */
  justify-content: center; /* Flex center IF we switch to flex in JS */
  align-items: center;
}

.modal-content {
  background-color: #fff;
  padding: 2rem;
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
  /* Ensure it's centered if overlay uses flex */
  margin: auto;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 1.5rem;
  cursor: pointer;
  color: #aaa;
}

.modal-close:hover {
  color: #333;
}

.modal-header {
  margin-bottom: 1.5rem;
  text-align: center;
}

.modal-body .form-control {
  margin-bottom: 1rem;
}

/* CONNECTOR STYLES FOR GREAT-GRANDPARENTS LEVEL */

/* 1. Horizontal Connector Bar below the GGP Couple */
.great-grandparents-level .family-group::before {
  content: "";
  position: absolute;
  bottom: -40px; /* Below the nodes */
  left: 50%;
  transform: translateX(-50%);
  width: 122px; /* Connects the centers of two 100px nodes with 20px gap */
  height: 2px;
  background-color: #999;
  z-index: 1;
}

/* 2. Vertical Lines DOWN from each GGP Node to the bar */
.great-grandparents-level .tree-node::after {
  content: "";
  position: absolute;
  bottom: -40px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 40px;
  background-color: #999;
  z-index: 0;
}

/* 3. Vertical Stem DOWN from the center of GGP Couple towards Grandparent */
.great-grandparents-level .family-group::after {
  content: "";
  position: absolute;
  top: 100%; /* Starts at bottom of family group */
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 40px; /* Go down 40px to meet the GP's UP line */
  background-color: #999;
  z-index: 1;
  margin-top: 40px; /* Starts after the vertical node lines */
}

/* 4. Vertical Line UP from each Grandparent Node to meet the GGP Stem */
.grandparents-level .tree-node::before {
  content: "";
  position: absolute;
  top: -40px; /* Go up 40px */
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 40px;
  background-color: #999;
  z-index: 0;
}

/* ADJUSTMENT: Increase inner gap in Grandparents groups to align with GGP groups */
/* Calculated: Node(100) + Gap + Node(100). Centers dist = 100+Gap.
   GGP Neighbor Centers dist = 110(HalfGroup)+80(Gap)+110(HalfGroup) = 300.
   100+Gap = 300 => Gap = 200px. */
.grandparents-level .family-group {
  gap: 200px;
}

/* ADJUSTMENT: Increase outer gap between Grandparents groups (Pat vs Mat sides) */
/* We need to align the Group Centers.
   GGP Side Center (from midline) = 40(HalfGap) + 260(HalfSideWidth) = 300px.
   GP Side Center = GapMajor/2 + WidthGroup/2.
   WidthGroup = 100+200+100 = 400.
   300 = GapMajor/2 + 200 => GapMajor = 200px. */
.grandparents-level {
  gap: 200px;
}

/* Tree Controls (Zoom & Pan) */
.tree-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}

.control-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: white;
  border: 1px solid #e0e0e0;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  color: #555;
  font-size: 1.1rem;
}

.control-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
  color: #2589bd;
}

.control-btn:active {
  transform: translateY(0);
}

/* --- RECURSIVE DYNAMIC TREE CSS --- */
.tf-tree {
  display: flex;
  flex-direction: column; /* Ancestors First (Top), Self Second (Bottom) */
  align-items: center;
  padding: 50px;
  transform-origin: center top;
}

.tf-node-wrapper {
  display: flex; /* THIS WAS MISSING IN MY PREVIOUS ATTEMPT? No, it was display:flex */
  flex-direction: column; /* Ancestors First (Top), Node Second (Bottom) */
  align-items: center;
  position: relative;
  padding: 0 5px;
}

/* Container for Father/Mother branches */
.tf-ancestors {
  display: flex;
  flex-direction: row;
  align-items: flex-end; /* Align branches to bottom */
  justify-content: center;
  position: relative;
  padding-bottom: 20px; /* Space for the connectors downwards */
}

/* Individual Branch (contains a full recursive tf-node-wrapper of the Parent) */
.tf-branch {
  position: relative;
  padding: 0 10px;
}

/* 1. Vertical Line from Parent (inside branch) DOWN to Bridge */
/* This connects the bottom of the Parent Node (inside the branch) to the bridge */
.tf-branch::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 2px;
  height: 20px; /* Connects bottom of branch to bottom of ancestors container */
  background: #ccc;
  transform: translateX(-50%);
}

/* 2. Horizontal Bridge Line */
.tf-branch::after {
  content: "";
  position: absolute;
  bottom: 0;
  height: 2px;
  background: #ccc;
  /* Width set by child selectors */
}

/* Left Branch: Center to Right */
/* We target the first child branch */
.tf-ancestors > .tf-branch:first-child:not(:last-child)::after {
  left: 50%;
  width: 50%;
}

/* Right Branch: Left to Center */
.tf-ancestors > .tf-branch:last-child:not(:first-child)::after {
  left: 0;
  width: 51%; /* Slight overlap */
}

/* Remove bridge if single parent */
.tf-branch:only-child::after {
  display: none;
}

/* 3. Vertical Line from Node (Self) UP to Bridge */

/* Use a pseudo on the ancestors container to draw the line connecting Bridge to Node */
/* This avoids issues with emptiness checking on Node */
.tf-ancestors::after {
  content: "";
  position: absolute;
  bottom: -20px; /* Drop down to touch the Node */
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 20px;
  background: #ccc;
}

/* Node Styling */
.tf-node-content {
  background: white;
  padding: 15px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
  text-align: center;
  width: 140px;
  min-height: 80px;
  z-index: 2;
  margin: 10px;
  border: 2px solid transparent;
  transition: all 0.3s ease;
  /* Remove any old pseudos */
}

.tf-node-content::before {
  display: none;
}

.tf-node-content.filled {
  border-color: #e0e0e0;
}
.tf-node-content.active {
  border-color: #2589bd;
  background: #f0f9ff;
  transform: scale(1.05);
}
.tf-node-content.empty {
  border: 2px dashed #ddd;
  background: #f9f9f9;
  opacity: 0.7;
}
.tf-node-content:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.tf-icon {
  font-size: 1.5rem;
  color: #aaa;
  margin-bottom: 5px;
}
.tf-node-content.filled .tf-icon {
  color: #2589bd;
}
.tf-name {
  font-weight: 600;
  color: #333;
  font-size: 0.9rem;
  line-height: 1.2;
}
.tf-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 4px;
  display: block;
}
