/* ========== TREE WRAPPER ========== */
#tree-wrapper {
  display: flex;
  min-height: calc(100vh - 80px);
  background: var(--color-bg, #FDFAF4);
  overflow: hidden;
}

#tree-main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* ========== SIDEBAR ========== */
#tree-sidebar {
  width: 260px;
  min-width: 260px;
  flex-shrink: 0;
  background: var(--color-surface, #FFFDF8);
  border-right: 1px solid var(--color-border, #E8E4DC);
  padding: 20px;
  overflow-y: auto;
}

#tree-sidebar h3 {
  font-size: 0.85rem;
  color: var(--color-gold, #C9A84C);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-section {
  margin-bottom: 1.5rem;
}

.sidebar-search-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid #1A6B2E;
  border-radius: 8px;
  font-size: 0.9rem;
  background: white;
}

.sidebar-link {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--color-gold);
}
.sidebar-link.muted { color: var(--color-muted, #718096); }
.sidebar-link:hover { text-decoration: underline; }

#sidebar-focus-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

#sidebar-focus-meta {
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-bottom: 0.5rem;
}

.branch-radio {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.branch-radio input { margin-right: 0.5rem; }

.legend-item {
  display: flex;
  align-items: center;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 0.5rem;
}
.legend-dot.focus { background: #C9A84C; border: 1px solid #8B7355; }
.legend-dot.ancestor { background: #5B8DEE; }
.legend-dot.descendant { background: #1A6B2E; }
.legend-dot.spouse { background: #E87A9E; }
.legend-dot.notable { background: #C9A84C; }
.legend-dot.deceased { background: #718096; }

.sidebar-btn {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  border: 1.5px solid #1A6B2E;
  border-radius: 8px;
  background: white;
  color: #1A6B2E;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}
.sidebar-btn:hover {
  background: #1A6B2E;
  color: white;
}

/* ========== PHASE 1: SEARCH STATE ========== */
#tree-search-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: calc(100vh - 200px);
  gap: 24px;
  background: #FDFAF4;
  padding: 40px 20px;
}

.tree-icon-svg {
  width: 80px;
  height: 80px;
  color: #1A6B2E;
}
.tree-icon-svg svg { width: 100%; height: 100%; }

.tree-icon-animated {
  animation: treeSway 3s ease-in-out infinite;
}
@keyframes treeSway {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}

.search-state-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: #2D3748;
  margin: 0;
  text-align: center;
}

.search-state-subtitle {
  font-size: 1rem;
  color: var(--color-muted, #718096);
  margin: -8px 0 0 0;
  text-align: center;
}

.search-input-wrapper {
  position: relative;
  width: 100%;
  max-width: 480px;
}

#tree-main-search {
  width: 100%;
  max-width: 480px;
  height: 56px;
  border: 2px solid #1A6B2E;
  border-radius: 28px;
  padding: 0 24px 0 52px;
  font-size: 17px;
  background: white;
  box-shadow: 0 4px 24px rgba(26, 107, 46, 0.15);
  transition: all 0.3s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23718096' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 18px center;
}
#tree-main-search:focus {
  outline: none;
  border-color: #C9A84C;
  box-shadow: 0 4px 32px rgba(201, 168, 76, 0.25);
  transform: scale(1.02);
}

.search-or-browse {
  font-size: 0.9rem;
  color: var(--color-muted);
  margin: 8px 0 0 0;
}

.gen-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 600px;
}

.gen-pill {
  padding: 8px 18px;
  border-radius: 20px;
  border: 1.5px solid #1A6B2E;
  color: #1A6B2E;
  background: white;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}
.gen-pill:hover,
.gen-pill.active {
  background: #1A6B2E;
  color: white;
}

.search-divider {
  font-size: 0.9rem;
  color: var(--color-muted);
  margin: 8px 0;
}

.btn-foundation {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 32px;
  border: 2px solid #C9A84C;
  border-radius: 12px;
  background: linear-gradient(135deg, #FFFDF5 0%, #FFF8E7 100%);
  color: #2D3748;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-foundation:hover {
  border-color: #1A6B2E;
  box-shadow: 0 4px 20px rgba(201, 168, 76, 0.3);
}
.btn-foundation-icon { font-size: 1.5rem; margin-bottom: 4px; }
.btn-foundation-text { font-weight: 600; font-size: 1rem; }
.btn-foundation-sub { font-size: 0.85rem; color: var(--color-muted); margin-top: 4px; }

/* ========== SEARCH DROPDOWN ========== */
#tree-search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: white;
  border: 1px solid #E2E8F0;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.12);
  max-height: 320px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}
#tree-search-dropdown.open { display: block; }

.dropdown-header {
  padding: 10px 16px;
  font-size: 0.8rem;
  color: var(--color-muted);
  border-bottom: 1px solid #E2E8F0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  gap: 12px;
}
.dropdown-item:hover { background: #F0FAF2; }

.dropdown-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #1A6B2E;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.dropdown-content {
  flex: 1;
  min-width: 0;
}
.dropdown-name { font-weight: 600; display: block; }
.dropdown-meta { font-size: 0.85rem; color: var(--color-muted); }
.notable-badge { margin-left: 4px; }
.dropdown-arrow { color: #C9A84C; font-size: 1.2rem; }
.dropdown-empty { padding: 20px; text-align: center; color: var(--color-muted); }

/* ========== LOADING STATE ========== */
#tree-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 60vh;
}

.tree-loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.tree-loading-icon {
  width: 64px;
  height: 64px;
  color: #1A6B2E;
}
.tree-loading-icon svg {
  width: 100%;
  height: 100%;
  animation: grow 1.5s ease-in-out infinite alternate;
}
@keyframes grow {
  from { transform: scale(0.8); opacity: 0.6; }
  to { transform: scale(1.1); opacity: 1; }
}
.tree-loading-state .muted { font-size: 0.9rem; color: var(--color-muted); }

/* ========== TREE CANVAS STATE ========== */
#tree-canvas-state {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#tree-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.toolbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
.breadcrumb-search {
  font-weight: 600;
  font-size: 1rem;
}
.breadcrumb-clear {
  background: none;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0 4px;
  line-height: 1;
}
.breadcrumb-clear:hover { color: #c53030; }

.btn-link {
  background: none;
  border: none;
  color: var(--color-gold);
  cursor: pointer;
  font-size: 0.9rem;
}
.btn-link:hover { text-decoration: underline; }

.toolbar-info {
  font-size: 0.85rem;
  color: var(--color-muted);
}

.toolbar-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#tree-container {
  flex: 1;
  min-height: 400px;
  cursor: grab;
  overflow: hidden;
  font-family: 'Noto Serif Bengali', 'Noto Sans Bengali', serif;
}
#tree-container:active { cursor: grabbing; }
#tree-container text { font-family: inherit; }

/* ========== GENERATION GRID ========== */
#tree-gen-grid {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.gen-grid-header {
  margin-bottom: 24px;
}
.btn-back {
  background: none;
  border: none;
  color: var(--color-gold);
  cursor: pointer;
  font-size: 0.95rem;
  margin-bottom: 12px;
}
.btn-back:hover { text-decoration: underline; }
#gen-grid-title { font-size: 1.5rem; margin: 0; }

#gen-grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
}

.gen-card {
  background: white;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  transition: all 0.2s;
}
.gen-card:hover {
  border-color: #1A6B2E;
  box-shadow: 0 4px 16px rgba(26, 107, 46, 0.15);
}

.gen-card-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #1A6B2E;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 10px;
  font-weight: 600;
  font-size: 14px;
}

.gen-card-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 4px;
}
.gen-card-meta {
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-bottom: 12px;
}
.gen-card-btn {
  padding: 6px 12px;
  border: 1.5px solid #1A6B2E;
  border-radius: 8px;
  background: white;
  color: #1A6B2E;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.gen-card-btn:hover {
  background: #1A6B2E;
  color: white;
}

/* ========== NODE STYLES ========== */
.node-card rect {
  transition: filter 0.2s ease;
}
.node-card:hover rect {
  filter: drop-shadow(0 4px 12px rgba(201, 168, 76, 0.4)) !important;
}

.node-focus rect {
  animation: focusPulse 2s ease-in-out;
}
@keyframes focusPulse {
  0%, 100% { filter: drop-shadow(0 0 12px rgba(201,168,76,0.4)); }
  50% { filter: drop-shadow(0 0 20px rgba(201,168,76,0.6)); }
}

/* ========== POPUP ========== */
#member-popup {
  position: fixed;
  right: -400px;
  top: 80px;
  width: 360px;
  background: var(--color-surface);
  border: 1px solid var(--color-gold);
  border-radius: var(--radius, 12px);
  padding: 24px;
  transition: right 0.3s ease;
  z-index: 100;
  box-shadow: var(--shadow, 0 10px 40px rgba(0,0,0,0.15));
}

#member-popup.active { right: 20px; }

#member-popup .popup-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 1.2rem;
}

#member-popup .popup-photo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin: 0 auto 1rem;
}

#member-popup .popup-name {
  font-weight: 600;
  font-size: 1.1rem;
  text-align: center;
  margin-bottom: 0.25rem;
}

#member-popup .popup-assamese,
#member-popup .popup-name {
  font-family: 'Noto Serif Bengali', 'Noto Sans Bengali', serif;
}

#member-popup .popup-assamese {
  text-align: center;
  color: var(--color-muted);
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

#member-popup .popup-years {
  text-align: center;
  font-size: 0.9rem;
  color: var(--color-muted);
  margin-bottom: 1rem;
}

#member-popup .popup-link {
  display: block;
  text-align: center;
  padding: 0.5rem;
  background: var(--color-gold);
  color: var(--color-bg);
  border-radius: 4px;
  font-weight: 600;
}

#member-popup .popup-link:hover {
  background: var(--color-gold-light, #D4B85C);
  text-decoration: none;
}

.popup-set-focus {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.5rem;
  border: 1.5px solid #C9A84C;
  border-radius: 4px;
  background: #FFFDF5;
  color: #1A6B2E;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: center;
}
.popup-set-focus:hover { background: #C9A84C; color: white; }

/* ========== MODAL ========== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-content {
  background: white;
  padding: 24px;
  border-radius: 12px;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-content h3 { margin: 0 0 12px 0; }
.modal-content p { margin: 0 0 20px 0; color: var(--color-muted); }
.modal-actions { display: flex; gap: 12px; }

/* ========== LEGACY (full tree nodes) ========== */
.link {
  fill: none;
  stroke: var(--color-gold);
  stroke-opacity: 0.4;
  stroke-width: 1.5px;
}

.node rect { transition: filter 0.2s ease; }
.node:hover rect { filter: drop-shadow(0 4px 12px rgba(201,168,76,0.5)) !important; }
.node.gen-1 rect { stroke: var(--color-gold) !important; stroke-width: 3px !important; }

/* ========== RESPONSIVE — Mobile & Tablet ========== */
@media (max-width: 1024px) {
  #tree-wrapper {
    flex-direction: column;
    min-height: auto;
  }
  #tree-sidebar {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--color-border, #E8E4DC);
    padding: 1rem;
    max-height: 280px;
    overflow-y: auto;
  }
  #tree-main-area {
    min-height: 60vh;
  }
  #tree-search-state {
    padding: 2rem 1rem;
    min-height: 50vh;
  }
  .search-state-title { font-size: 1.25rem; }
  .gen-pills { max-width: 100%; }
  #tree-toolbar {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
  }
  .toolbar-breadcrumb { flex-wrap: wrap; }
  #gen-grid-cards {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
  }
  #member-popup {
    width: calc(100vw - 2rem);
    max-width: 360px;
    right: -100%;
    left: auto;
  }
  #member-popup.active {
    right: 1rem;
    left: 1rem;
    width: auto;
  }
}

@media (max-width: 768px) {
  #tree-sidebar {
    max-height: 240px;
    padding: 0.75rem 1rem;
  }
  #tree-search-state {
    padding: 1.5rem 1rem;
    gap: 1rem;
  }
  .tree-icon-svg { width: 60px; height: 60px; }
  .search-state-title { font-size: 1.1rem; }
  .search-state-subtitle { font-size: 0.9rem; }
  #tree-main-search {
    height: 48px;
    padding: 0 1rem 0 44px;
    font-size: 1rem;
  }
  .search-input-wrapper,
  #tree-main-search { max-width: 100%; }
  #tree-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .toolbar-buttons { justify-content: flex-start; }
  #gen-grid-cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
  .gen-card { padding: 1rem; }
  .gen-card-avatar { width: 40px; height: 40px; font-size: 0.85rem; }
  #member-popup {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: none;
    border-radius: 16px 16px 0 0;
  }
  #member-popup.active {
    right: 0;
    left: 0;
  }
  .modal-content {
    max-width: calc(100vw - 2rem);
    margin: 1rem;
  }
}

@media (max-width: 480px) {
  #gen-grid-cards { grid-template-columns: 1fr; }
  .gen-pill { padding: 6px 14px; font-size: 12px; }
}
