/* ===================================================
   TREE APP – Full-Page Family Tree Application
   =================================================== */

.tree-app {
  max-width: 1400px;
  margin: 20px auto 0;
  padding: 0 20px;
}

/* ---- Hero Banner ---- */
.tree-hero {
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  padding: 50px 40px;
  text-align: center;
  background: linear-gradient(160deg, var(--brown-dark) 0%, var(--brown-mid) 50%, #7a5c47 100%);
  background-size: 200% 200%;
  animation: gradientShift 10s ease infinite;
}

.tree-hero-bg {
  position: absolute;
  inset: 0;
  opacity: 0.04;
  background-image:
    radial-gradient(circle at 30% 30%, #fff 1px, transparent 1px),
    radial-gradient(circle at 70% 70%, #fff 1px, transparent 1px);
  background-size: 50px 50px;
  pointer-events: none;
}

.tree-hero-content { position: relative; z-index: 1; }

.tree-hero-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  font-size: 28px; color: #fff;
  backdrop-filter: blur(6px);
  border: 2px solid rgba(255,255,255,0.15);
  animation: float 4s ease-in-out infinite;
}

.tree-hero h1 {
  color: #fff; font-size: 42px; font-weight: 800;
  font-family: var(--font-serif); margin-bottom: 8px;
}

.tree-hero p {
  color: rgba(255,255,255,0.8); font-size: 16px;
  max-width: 520px; margin: 0 auto 24px; line-height: 1.7;
}

.tree-hero-stats {
  display: flex; justify-content: center; gap: 14px; flex-wrap: wrap;
}

.tree-stat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 30px; padding: 8px 20px;
  color: #fff; font-size: 14px; font-weight: 600;
}

.tree-stat-num { font-size: 20px; font-weight: 800; font-family: var(--font-serif); }

/* ---- Tabs ---- */
.tree-tabs {
  display: flex; gap: 0; margin-top: 20px;
  background: var(--white); border-radius: 16px 16px 0 0;
  padding: 6px; box-shadow: var(--shadow-sm);
  border: 1px solid var(--brown-pale); border-bottom: none;
}

.tree-tab {
  flex: 1; padding: 14px 16px; border-radius: 12px;
  background: transparent; color: var(--brown-mid);
  font-weight: 700; font-size: 14px;
  transition: all 0.3s ease; display: flex;
  align-items: center; justify-content: center; gap: 8px;
}

.tree-tab:hover { background: rgba(136,102,77,0.06); }

.tree-tab.active {
  background: linear-gradient(135deg, var(--brown-mid), var(--brown-dark));
  color: #fff; box-shadow: var(--shadow-sm);
}

/* ---- Layout ---- */
.tree-layout {
  display: flex; gap: 0;
  border: 1px solid var(--brown-pale); border-top: none;
  border-radius: 0 0 16px 16px;
  overflow: hidden; background: var(--white);
  min-height: 600px; box-shadow: var(--shadow-md);
}

/* ---- Sidebar ---- */
.tree-sidebar {
  width: 300px; flex-shrink: 0;
  background: var(--dark);
  color: #fff; padding: 0;
  overflow-y: auto; transition: width 0.4s ease, opacity 0.3s ease;
  border-left: 1px solid rgba(255,255,255,0.06);
}

.tree-sidebar.collapsed { width: 0; opacity: 0; overflow: hidden; padding: 0; }

.sidebar-section {
  padding: 20px; border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-section h3 {
  font-size: 15px; font-weight: 800; margin-bottom: 0;
  display: flex; align-items: center; gap: 8px;
  color: rgba(255,255,255,0.9);
}

.sidebar-section h4 {
  font-size: 13px; font-weight: 700; margin-bottom: 12px;
  color: rgba(255,255,255,0.6); display: flex;
  align-items: center; gap: 8px;
}

/* Branch List */
.branch-list { display: flex; flex-direction: column; gap: 4px; }

.branch-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 10px;
  background: rgba(255,255,255,0.04);
  color: rgba(255,255,255,0.8); font-size: 14px;
  font-weight: 600; transition: all 0.3s ease;
  text-align: right; width: 100%;
}

.branch-item i { font-size: 16px; opacity: 0.5; width: 20px; text-align: center; }
.branch-item span:first-of-type { flex: 1; }

.branch-badge {
  background: rgba(255,255,255,0.1);
  padding: 2px 10px; border-radius: 12px;
  font-size: 12px; font-weight: 700;
}

.branch-item:hover { background: rgba(255,255,255,0.08); }

.branch-item.active {
  background: linear-gradient(135deg, var(--brown-mid), var(--brown-dark));
  color: #fff;
}

.branch-item.active .branch-badge {
  background: rgba(255,255,255,0.2);
}

/* Search */
.tree-search-box {
  position: relative; margin-bottom: 12px;
}

.tree-search-box input {
  width: 100%; padding: 10px 14px 10px 36px;
  border-radius: 10px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.06); color: #fff;
  font-size: 14px; outline: none; transition: all 0.3s ease;
}

.tree-search-box input::placeholder { color: rgba(255,255,255,0.35); }
.tree-search-box input:focus { border-color: var(--brown-light); background: rgba(255,255,255,0.1); }

.tree-search-box i {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%); color: rgba(255,255,255,0.3); font-size: 14px;
}

.search-results {
  max-height: 200px; overflow-y: auto;
}

.search-result-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
  transition: background 0.2s ease; font-size: 13px;
  color: rgba(255,255,255,0.8);
}

.search-result-item:hover { background: rgba(255,255,255,0.08); }

.search-result-item .sr-icon {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}

.search-result-item .sr-info { flex: 1; }
.search-result-item .sr-name { font-weight: 700; display: block; }
.search-result-item .sr-role { font-size: 11px; opacity: 0.5; }

.advanced-toggle {
  background: none; color: rgba(255,255,255,0.4);
  font-size: 12px; padding: 6px 0; display: flex;
  align-items: center; gap: 6px; transition: color 0.3s ease;
  width: 100%;
}

.advanced-toggle:hover { color: rgba(255,255,255,0.7); }

.advanced-fields {
  display: none; flex-direction: column; gap: 8px; margin-top: 10px;
}

.advanced-fields.show { display: flex; }

.advanced-fields input {
  width: 100%; padding: 8px 12px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04); color: #fff;
  font-size: 13px; outline: none;
}

.advanced-fields input::placeholder { color: rgba(255,255,255,0.25); }

/* Tips */
.sidebar-tips { padding: 16px 20px; }

.tip {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 12px; color: rgba(255,255,255,0.35);
  margin-bottom: 10px; line-height: 1.5;
}

.tip i { margin-top: 2px; font-size: 11px; color: var(--brown-light); }

/* ---- Main Area ---- */
.tree-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.tree-tab-content { display: none; flex: 1; flex-direction: column; }
.tree-tab-content.active { display: flex; }

/* Toolbar */
.tree-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--brown-pale);
  background: var(--cream-light);
}

.toolbar-right, .toolbar-left { display: flex; align-items: center; gap: 6px; }

.tb-btn {
  padding: 7px 12px; border-radius: 8px; font-size: 13px;
  background: var(--white); color: var(--brown-dark);
  border: 1px solid var(--brown-pale); font-weight: 600;
  transition: all 0.25s ease; display: flex;
  align-items: center; gap: 5px;
}

.tb-btn:hover {
  background: var(--brown-dark); color: #fff;
  border-color: var(--brown-dark);
}

.tb-zoom {
  font-size: 12px; color: var(--gray); font-weight: 700;
  min-width: 40px; text-align: center;
}

.tb-sidebar-toggle { display: none; }

/* Viewport */
.tree-viewport {
  flex: 1; overflow: auto; position: relative;
  cursor: grab; min-height: 400px;
  background:
    radial-gradient(circle at 50% 50%, rgba(187,161,136,0.03) 0%, transparent 70%),
    var(--cream-light);
}

.tree-viewport:active { cursor: grabbing; }

.tree-canvas {
  padding: 50px 30px 80px;
  min-width: fit-content;
  transform-origin: top center;
  transition: transform 0.3s ease;
}

/* ---- TREE CSS ---- */
.ftree, .ftree ul { list-style: none; padding: 0; margin: 0; display: flex; justify-content: center; position: relative; }
.ftree ul { padding-top: 40px; }
.ftree ul::before { content: ''; position: absolute; top: 0; left: 50%; width: 0; height: 40px; border-left: 2px dashed var(--brown-pale); }
.ftree li { display: flex; flex-direction: column; align-items: center; position: relative; padding: 0 14px; }
.ftree li::before, .ftree li::after { content: ''; position: absolute; top: 0; width: 50%; height: 0; border-top: 2px dashed var(--brown-pale); }
.ftree li::before { right: 50%; }
.ftree li::after { left: 50%; }
.ftree li:first-child::before, .ftree li:last-child::after { border: none; }
.ftree li:only-child::before, .ftree li:only-child::after { border: none; }
.ftree > li::before, .ftree > li::after { border: none; }

/* Node */
.ftree-node {
  position: relative; background: var(--white);
  border: 2px solid var(--brown-pale); border-radius: 16px;
  padding: 16px 14px 12px; text-align: center;
  min-width: 110px; max-width: 140px; cursor: pointer;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(86,60,47,0.06); z-index: 1;
}

.ftree-node:hover {
  transform: translateY(-5px) scale(1.04);
  box-shadow: 0 12px 30px rgba(86,60,47,0.15);
  border-color: var(--brown-light); z-index: 5;
}

.ftree-node.ftree-active {
  border-color: var(--brown-dark);
  background: var(--cream);
  box-shadow: 0 8px 24px rgba(86,60,47,0.2);
}

.ftree-node.highlight {
  animation: pulse-ring 1s ease 3;
  border-color: var(--brown-dark);
  box-shadow: 0 0 0 4px rgba(86,60,47,0.15);
}

/* Root */
.ftree-root {
  background: linear-gradient(135deg, var(--brown-mid), var(--brown-dark));
  border-color: var(--brown-dark); color: #fff;
  min-width: 140px; padding: 20px 16px 16px;
  box-shadow: 0 8px 30px rgba(86,60,47,0.25);
}

.ftree-root .ftree-name, .ftree-root .ftree-role { color: #fff; }
.ftree-root .ftree-role { opacity: 0.75; }

/* Branch Head */
.ftree-branch-head {
  border: 2px solid var(--brown-light);
  background: linear-gradient(180deg, var(--white), var(--cream-light));
}

/* Avatar */
.ftree-avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cream), var(--brown-pale));
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 8px; font-size: 18px; color: var(--brown-dark);
  transition: transform 0.35s ease;
  border: 2px solid var(--brown-pale);
}

.ftree-avatar-root {
  background: rgba(255,255,255,0.15); color: #fff;
  width: 52px; height: 52px; font-size: 20px;
  border-color: rgba(255,255,255,0.25);
}

.ftree-node:hover .ftree-avatar { transform: scale(1.12); }

.ftree-name { display: block; font-size: 13px; font-weight: 800; color: var(--dark); line-height: 1.3; }
.ftree-role { display: block; font-size: 10px; color: var(--brown-mid); font-weight: 600; margin-top: 2px; }

/* Toggle */
.ftree-toggle {
  position: absolute; bottom: -13px; left: 50%;
  transform: translateX(-50%); width: 26px; height: 26px;
  border-radius: 50%; background: var(--white);
  color: var(--brown-dark); border: 2px solid var(--brown-pale);
  font-size: 10px; display: flex; align-items: center;
  justify-content: center; z-index: 3;
  transition: all 0.3s ease; box-shadow: var(--shadow-sm);
}

.ftree-toggle:hover { background: var(--brown-dark); color: #fff; border-color: var(--brown-dark); }
.ftree-toggle.expanded i { transform: rotate(180deg); }

.ftree-collapsed {
  max-height: 0; overflow: hidden; opacity: 0; padding-top: 0 !important;
  transition: max-height 0.5s cubic-bezier(0.4,0,0.2,1), opacity 0.4s ease 0.1s, padding-top 0.4s ease;
}

.ftree-collapsed.ftree-expanded {
  max-height: 3000px; opacity: 1; padding-top: 40px !important; overflow: visible;
}

.ftree-leaf { border-style: dashed; background: var(--cream-light); }

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(86,60,47,0.4); }
  70% { box-shadow: 0 0 0 12px rgba(86,60,47,0); }
  100% { box-shadow: 0 0 0 0 rgba(86,60,47,0); }
}

/* ---- Detail Panel ---- */
.ftree-detail {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  background: var(--white); border-radius: 24px;
  padding: 40px 32px; text-align: center;
  width: 400px; max-width: 92vw;
  box-shadow: 0 30px 80px rgba(0,0,0,0.25);
  z-index: 10000; opacity: 0; pointer-events: none;
  transition: all 0.4s cubic-bezier(0.4,0,0.2,1);
  border: 2px solid var(--brown-pale);
}

.ftree-detail.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }

.ftree-detail-close {
  position: absolute; top: 14px; left: 14px;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--cream-light); color: var(--brown-dark);
  font-size: 14px; display: flex; align-items: center;
  justify-content: center; transition: var(--transition);
  border: 1px solid var(--brown-pale);
}

.ftree-detail-close:hover { background: var(--brown-dark); color: #fff; transform: rotate(90deg); }

.ftree-detail-avatar {
  width: 80px; height: 80px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brown-mid), var(--brown-dark));
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px; font-size: 30px; color: #fff;
}

.ftree-detail h3 { font-size: 22px; font-weight: 800; color: var(--dark); margin-bottom: 8px; font-family: var(--font-serif); }

.ftree-detail-role {
  display: inline-block; background: linear-gradient(135deg, var(--brown-mid), var(--brown-dark));
  color: #fff; padding: 4px 16px; border-radius: 16px;
  font-size: 13px; font-weight: 600; margin-bottom: 8px;
}

.ftree-detail-year { display: block; font-size: 14px; color: var(--gray); font-weight: 600; margin-bottom: 16px; }
.ftree-detail-year i { margin-left: 4px; }
.ftree-detail p { font-size: 15px; line-height: 1.9; color: var(--gray); }

.ftree-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  z-index: 9999;
  opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}

.ftree-overlay.show { opacity: 1; pointer-events: auto; }

/* ---- Members Tab ---- */
.members-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px; padding: 24px;
}

.member-card {
  background: var(--cream-light); border: 1px solid var(--brown-pale);
  border-radius: 14px; padding: 20px; text-align: center;
  cursor: pointer; transition: all 0.35s ease;
}

.member-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--brown-light); }

.member-card .mc-avatar {
  width: 50px; height: 50px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cream), var(--brown-pale));
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 10px; font-size: 20px; color: var(--brown-dark);
}

.member-card h4 { font-size: 14px; font-weight: 800; color: var(--dark); margin-bottom: 4px; }
.member-card p { font-size: 12px; color: var(--gray); }

/* ---- Stats Tab ---- */
.tree-stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 16px; padding: 24px;
}

.ts-card {
  background: var(--cream-light); border: 1px solid var(--brown-pale);
  border-radius: 16px; padding: 24px; text-align: center;
  transition: all 0.35s ease;
}

.ts-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }

.ts-icon {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brown-mid), var(--brown-dark));
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px; font-size: 18px; color: #fff;
}

.ts-card h3 { font-size: 28px; font-weight: 800; color: var(--brown-dark); font-family: var(--font-serif); }
.ts-card p { font-size: 13px; color: var(--gray); margin-top: 4px; }

.ts-branches-chart {
  padding: 0 24px 24px;
}

.ts-branches-chart h3 {
  font-size: 18px; font-weight: 800; color: var(--dark);
  margin-bottom: 20px; font-family: var(--font-serif);
}

.ts-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.ts-bar-label { width: 100px; font-size: 13px; font-weight: 700; color: var(--dark); text-align: right; }
.ts-bar-track { flex: 1; height: 24px; background: var(--cream); border-radius: 12px; overflow: hidden; }
.ts-bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--brown-mid), var(--brown-dark)); border-radius: 12px; transition: width 1.2s cubic-bezier(0.16,1,0.3,1); }
.ts-bar-fill.animated { width: var(--bar-w); }
.ts-bar-val { font-size: 14px; font-weight: 800; color: var(--brown-dark); min-width: 40px; }

/* ---- About Tab ---- */
.tab-about-content { padding: 40px; max-width: 700px; }
.tab-about-content h2 { font-size: 28px; font-weight: 800; color: var(--brown-dark); font-family: var(--font-serif); margin-bottom: 16px; }
.tab-about-content p { font-size: 15px; line-height: 2; color: var(--gray); margin-bottom: 16px; }

.about-features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 30px; }

.about-feat {
  text-align: center; padding: 20px; background: var(--cream-light);
  border-radius: 14px; border: 1px solid var(--brown-pale);
}

.about-feat i { font-size: 24px; color: var(--brown-dark); margin-bottom: 10px; display: block; }
.about-feat h4 { font-size: 15px; font-weight: 800; color: var(--dark); margin-bottom: 6px; }
.about-feat p { font-size: 12px; color: var(--gray); line-height: 1.6; }

/* ---- Responsive ---- */
@media (max-width: 992px) {
  .tree-sidebar { position: fixed; right: 0; top: 0; bottom: 0; z-index: 1000; width: 300px; transform: translateX(100%); transition: transform 0.4s ease; }
  .tree-sidebar.open { transform: translateX(0); }
  .tree-sidebar.collapsed { transform: translateX(100%); }
  .tb-sidebar-toggle { display: flex; }
  .tree-tabs { overflow-x: auto; }
  .tree-tab { white-space: nowrap; font-size: 13px; padding: 12px; }
  .tree-stats-grid { grid-template-columns: repeat(2, 1fr); }
  .about-features { grid-template-columns: 1fr; }
  .tree-hero h1 { font-size: 30px; }
}

@media (max-width: 600px) {
  .tree-hero { padding: 30px 20px; border-radius: 16px; }
  .tree-hero h1 { font-size: 24px; }
  .tree-stat-pill { font-size: 12px; padding: 6px 14px; }
  .tree-stats-grid { grid-template-columns: 1fr; }
  .tree-canvas { padding: 30px 10px 60px; }
  .ftree li { padding: 0 6px; }
  .ftree-node { min-width: 80px; max-width: 110px; padding: 12px 8px 8px; }
  .ftree-name { font-size: 11px; }
  .ftree-avatar { width: 36px; height: 36px; font-size: 14px; }
  .members-grid { grid-template-columns: 1fr 1fr; gap: 10px; padding: 16px; }
}
