/* Mind Map Layout */
.mindmap-wrapper {
  position: relative;
  width: 100%;
  height: calc(100vh - 140px);
  background: #f8fafc;
  overflow: hidden; /* Hide anything outside viewport */
  cursor: grab;
  border-bottom: 1px solid var(--border);
}
.mindmap-wrapper:active {
  cursor: grabbing;
}

.mindmap-controls {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}
.mindmap-controls button {
  width: 40px;
  height: 40px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dark);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}
.mindmap-controls button:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: translateY(-2px);
}

.mindmap-viewport {
  width: 100%;
  height: 100%;
  position: relative;
  background-color: #f1f5f9;
  background-image: 
    linear-gradient(rgba(203, 213, 225, 0.3) 1px, transparent 1px),
    linear-gradient(90deg, rgba(203, 213, 225, 0.3) 1px, transparent 1px);
  background-size: 30px 30px;
  /* Will be transformed via JS */
}

.mindmap-container {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  display: inline-block;
  transition: opacity 0.5s ease;
}

.tree {
  margin: 0;
  padding: 0;
  list-style-type: none;
  display: flex;
  align-items: center;
  animation: fadeIn 0.8s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

.tree ul {
  padding-left: 50px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0;
  list-style-type: none;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.tree li {
  position: relative;
  display: flex;
  align-items: center;
}

/* Horizontal line entering the node */
.tree li::before {
  content: '';
  position: absolute;
  top: 50%;
  left: -50px;
  width: 50px;
  height: 2px;
  border-top: 1.5px dashed #4b6584;
  transform: translateY(-50%);
  opacity: 0.7;
}

/* Vertical line connecting siblings */
.tree ul::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  border-left: 1.5px dashed #4b6584;
  opacity: 0.7;
}

/* Hide entering line for the root node */
.tree > li::before {
  display: none;
}
/* Hide the vertical line for the root ul */
.tree > ul::before {
  display: none;
}

/* The horizontal line exiting the node towards its children */
.node {
  background: #2f3640; 
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: "Poppins", sans-serif;
  letter-spacing: 0.3px;
  box-shadow: 0 4px 12px rgba(47, 54, 64, 0.15);
  white-space: nowrap;
  position: relative;
  z-index: 2;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(255,255,255,0.05);
}

.node:not(.leaf-node)::after {
  content: '';
  position: absolute;
  top: 50%;
  right: -50px; 
  width: 50px;
  border-top: 1.5px dashed #4b6584;
  transform: translateY(-50%);
  z-index: 1;
  opacity: 0.7;
}

/* Hide half of the vertical line for the first child */
.tree li:first-child::after {
  content: '';
  position: absolute;
  top: 0;
  left: -50px;
  width: 1.5px;
  height: 50%;
  background: #f1f5f9; /* match background grid color */
}

/* Hide half of the vertical line for the last child */
.tree li:last-child::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: -50px;
  width: 1.5px;
  height: 50%;
  background: #f1f5f9;
}

/* Clear pseudo elements if it's both first and last (only child) */
.tree li:first-child:last-child::after {
  display: none;
}

/* Dynamic Interaction Styles */
.node.expandable {
  cursor: pointer;
  padding-right: 42px;
}

.node.expandable::before {
  content: '\f068';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  width: 18px;
  height: 18px;
  background: rgba(255,255,255,0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.li-collapsed > ul {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.9) translateX(-20px);
  pointer-events: none;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.tree li > ul {
  max-height: 2000px; /* Large value to allow expansion */
  opacity: 1;
  transform: scale(1) translateX(0);
  pointer-events: auto;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hide the outgoing dashed line from a collapsed node */
.li-collapsed > .node::after {
  opacity: 0;
  width: 0;
}

/* Smooth transition for node hover */
.node:hover {
  transform: scale(1.05) translateY(-3px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
  z-index: 10;
  background: var(--dark) !important;
}

.node.expandable:hover::before {
  background: var(--primary);
  transform: translateY(-50%) rotate(90deg);
}

.root-node {
  background: linear-gradient(135deg, #192a56 0%, #273c75 100%);
  font-size: 16px;
  padding: 16px 36px;
  border: 1px solid rgba(255,255,255,0.2);
  box-shadow: 0 10px 25px rgba(25, 42, 86, 0.3);
}

.root-node.expandable {
  padding-right: 52px;
}

.branch-node {
  background: #353b48;
}

.leaf-node {
  background: #273c38;
  font-weight: 500;
  font-size: 13px;
  padding: 10px 20px;
}

.node::after {
  content: '';
  position: absolute;
  top: 50%;
  right: -50px; 
  width: 50px;
  height: 1.5px;
  background: transparent;
  border-top: 1.5px dashed #4b6584;
  transform: translateY(-50%);
  z-index: 1;
}

.leaf-node::after {
  display: none;
}
