/**
 * Bagan Silsilah Interaktif (Sliding 3-Tier Pedigree Chart)
 * Gaya Desain: Modern Islami / Klasik Elegan (Dark Slate Navy & Gold Accent)
 */

:root {
  --color-canvas: #0a0e17;
  --color-surface: #111827;
  --color-surface-hover: #1f2937;
  --color-border: #334155;
  --color-gold: #c5a059;
  --color-gold-light: #e5c178;
  --color-gold-glow: rgba(197, 160, 89, 0.4);
  --color-male: #38bdf8;
  --color-female: #f472b6;
  --color-sage: #10b981;
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Base Canvas & Background Motif */
body {
  font-family: var(--font-primary);
  background-color: var(--color-canvas);
  color: #f1f5f9;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

.silsilah-canvas-bg {
  background-color: var(--color-canvas);
  background-image: 
    radial-gradient(circle at 50% 20%, rgba(30, 41, 59, 0.45) 0%, rgba(10, 14, 23, 0.98) 100%),
    linear-gradient(to right, rgba(51, 65, 85, 0.18) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(51, 65, 85, 0.18) 1px, transparent 1px);
  background-size: 100% 100%, 32px 32px, 32px 32px;
}

/* Tree Stage Container */
#tree-stage {
  position: relative;
  width: 100%;
  max-width: 1140px;
  min-height: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3.5rem;
  padding: 2.5rem 1rem 3rem 1rem;
  overflow: visible;
  box-sizing: border-box;
}

/* SVG Connector Overlay */
#svgOverlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

.svg-line-ancestor {
  stroke: url(#gradAncestor);
  stroke-width: 2.5;
  stroke-linecap: round;
  filter: url(#glowFilter);
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
  animation: drawLineAnim 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.svg-line-marriage {
  stroke: #f472b6;
  stroke-width: 2;
  stroke-dasharray: 4, 4;
}

.svg-line-descendant {
  stroke: url(#gradDescendant);
  stroke-width: 2.5;
  stroke-linecap: round;
  filter: url(#glowFilter);
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
  animation: drawLineAnim 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes drawLineAnim {
  to {
    stroke-dashoffset: 0;
  }
}

/* Tier Wrappers */
.tier-wrapper {
  position: relative;
  z-index: 10;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tier-badge {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 14px;
  border-radius: 9999px;
  backdrop-filter: blur(8px);
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.tier-badge.badge-ancestor {
  color: #7dd3fc;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.tier-badge.badge-focus {
  color: var(--color-gold-light);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(197, 160, 89, 0.4);
}

.tier-badge.badge-descendant {
  color: #6ee7b7;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Focus Tier Container Box */
.focus-tier-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.5rem 1.75rem;
  background: rgba(17, 24, 39, 0.65);
  border: 1px solid rgba(51, 65, 85, 0.8);
  border-radius: 1.25rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  max-width: 100%;
}

/* Person Card */
.person-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 145px;
  background: rgba(17, 24, 39, 0.9);
  border: 2px solid var(--color-border);
  border-radius: 1rem;
  padding: 0.85rem 0.6rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  box-sizing: border-box;
}

.person-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.6);
}

/* Card Gender Border */
.person-card.gender-male {
  border-color: rgba(56, 189, 248, 0.6);
}

.person-card.gender-female {
  border-color: rgba(244, 114, 182, 0.6);
}

/* Active Focus Glow */
.person-card.active-focus {
  border-color: var(--color-gold) !important;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.95) 0%, rgba(17, 24, 39, 0.98) 100%);
  box-shadow: 0 0 25px var(--color-gold-glow), 0 10px 25px rgba(0, 0, 0, 0.5) !important;
  transform: scale(1.03);
}

/* Avatar Photo */
.avatar-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 9999px;
  overflow: hidden;
  border: 2px solid;
  background: #1e293b;
  margin-bottom: 0.5rem;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
  flex-shrink: 0;
}

.avatar-wrap.border-male {
  border-color: var(--color-male);
}

.avatar-wrap.border-female {
  border-color: var(--color-female);
}

.avatar-wrap.border-gold {
  border-color: var(--color-gold);
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Person Name & Link */
.person-name-link {
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.25;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 0.25rem;
  transition: all 0.2s ease;
}

/* Link Aktif: Memiliki Halaman Profil Tokoh */
.person-name-link.has-profile {
  color: #f8fafc;
  text-decoration: none;
  cursor: pointer;
}

.person-name-link.has-profile:hover {
  color: var(--color-gold-light);
  text-decoration: underline;
}

/* Link Tidak Aktif: Belum Memiliki Halaman Profil */
.person-name-link.no-profile {
  color: #cbd5e1;
  text-decoration: none !important;
  cursor: default;
  user-select: text;
}

.person-name-link.no-profile:hover {
  color: #cbd5e1;
  text-decoration: none !important;
}

/* Avatar Link */
.avatar-link {
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s ease;
  display: block;
}

.avatar-link:hover {
  transform: scale(1.08);
  box-shadow: 0 0 14px rgba(197, 160, 89, 0.45);
}

/* Title & Period Label */
.person-title-label {
  font-size: 0.65rem;
  font-weight: 500;
  color: #94a3b8;
  text-align: center;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.35rem;
}

.role-tag {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.role-tag.tag-focus {
  background: rgba(197, 160, 89, 0.25);
  color: var(--color-gold-light);
  border: 1px solid rgba(197, 160, 89, 0.4);
}

.role-tag.tag-default {
  background: rgba(30, 41, 59, 0.8);
  color: #94a3b8;
  border: 1px solid rgba(51, 65, 85, 0.6);
}

/* Navigation Arrows (▲ / ▼) */
.nav-arrow-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 28px;
  border-radius: 9999px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  color: #0b0f19;
  z-index: 30;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.nav-arrow-btn:hover {
  transform: translateX(-50%) scale(1.22);
}

.nav-arrow-up {
  top: -14px;
  background: #f59e0b;
}

.nav-arrow-up:hover {
  background: #fbbf24;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.6);
}

.nav-arrow-down {
  bottom: -14px;
  background: #10b981;
}

.nav-arrow-down:hover {
  background: #34d399;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.6);
}

/* Union Marriage Icon & Badge */
.union-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.union-ring {
  width: 32px;
  height: 32px;
  border-radius: 9999px;
  background: rgba(30, 41, 59, 0.8);
  border: 1.5px solid rgba(244, 114, 182, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f472b6;
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.union-label {
  font-size: 9px;
  font-weight: 600;
  color: #cbd5e1;
  margin-top: 4px;
  white-space: nowrap;
}

/* Children Grouping (Per Istri) */
.children-group-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(17, 24, 39, 0.5);
  border: 1px solid rgba(51, 65, 85, 0.6);
  border-radius: 1.25rem;
  padding: 0.85rem 1.25rem 1rem 1.25rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.children-group-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #a7f3d0;
  margin-bottom: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.children-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
}

/* Empty State / Notice Box */
.silsilah-empty-box {
  padding: 0.75rem 1.5rem;
  border-radius: 0.75rem;
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid rgba(51, 65, 85, 0.6);
  font-size: 0.8rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Loading Skeleton */
.silsilah-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 23, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  border-radius: 1.5rem;
  transition: opacity 0.25s ease;
}

.silsilah-spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(197, 160, 89, 0.2);
  border-top-color: var(--color-gold);
  border-radius: 50%;
  animation: silsilahSpin 0.75s linear infinite;
}

@keyframes silsilahSpin {
  to {
    transform: rotate(360deg);
  }
}

/* Custom Scrollbar for Tree Stage */
.tree-scroll-container {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  padding-bottom: 1.5rem;
  -webkit-overflow-scrolling: touch;
}

.tree-scroll-container::-webkit-scrollbar {
  height: 8px;
}

.tree-scroll-container::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.8);
  border-radius: 4px;
}

.tree-scroll-container::-webkit-scrollbar-thumb {
  background: rgba(197, 160, 89, 0.4);
  border-radius: 4px;
}

.tree-scroll-container::-webkit-scrollbar-thumb:hover {
  background: rgba(197, 160, 89, 0.7);
}

/* Responsive Breakpoints */
@media (max-width: 640px) {
  #tree-stage {
    gap: 2.75rem;
    padding: 1.5rem 0.5rem 2rem 0.5rem;
  }
  .person-card {
    width: 130px;
    padding: 0.75rem 0.5rem;
  }
  .avatar-wrap {
    width: 52px;
    height: 52px;
  }
  .person-name-link {
    font-size: 0.75rem;
  }
  .focus-tier-box {
    padding: 1.25rem 0.75rem;
    gap: 1rem;
  }
}

/* ==========================================================
   IN-PLACE VISUAL TREE EDITOR (TAHAP 3)
   ========================================================== */

/* Admin Action Buttons on Nodes */
.tree-admin-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 0.5rem;
  width: 100%;
  z-index: 10;
}

.tree-admin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.68rem;
  font-weight: 600;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
  outline: none;
  text-decoration: none;
}

.tree-admin-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.15);
}

.tree-admin-btn-spouse {
  background: rgba(244, 114, 182, 0.15);
  border-color: rgba(244, 114, 182, 0.4);
  color: #f472b6;
}
.tree-admin-btn-spouse:hover {
  background: rgba(244, 114, 182, 0.28);
  box-shadow: 0 0 10px rgba(244, 114, 182, 0.3);
}

.tree-admin-btn-child {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}
.tree-admin-btn-child:hover {
  background: rgba(16, 185, 129, 0.28);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.tree-admin-btn-parent {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.4);
  color: #38bdf8;
}
.tree-admin-btn-parent:hover {
  background: rgba(56, 189, 248, 0.28);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
}

/* Placeholder Node Card (+ Tambah Ayah / + Tambah Ibu / + Tambah Pasangan) */
.node-placeholder-card {
  width: 140px;
  min-height: 120px;
  border-radius: 1rem;
  border: 2px dashed rgba(197, 160, 89, 0.35);
  background: rgba(15, 23, 42, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 0.5rem;
  cursor: pointer;
  transition: all 0.25s ease;
  text-align: center;
}

.node-placeholder-card:hover {
  border-color: var(--color-gold);
  background: rgba(197, 160, 89, 0.08);
  transform: translateY(-3px);
  box-shadow: 0 8px 20px -4px rgba(197, 160, 89, 0.2);
}

.node-placeholder-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(197, 160, 89, 0.15);
  color: var(--color-gold);
  font-size: 0.95rem;
  transition: all 0.25s ease;
}

.node-placeholder-card:hover .node-placeholder-icon {
  background: var(--color-gold);
  color: #0f172a;
  transform: scale(1.1);
}

.node-placeholder-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #cbd5e1;
}

/* In-Place Quick Modal Overlay */
.silsilah-quick-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.78);
  backdrop-filter: blur(8px);
  z-index: 99999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.silsilah-quick-modal-overlay.active {
  display: flex;
  opacity: 1;
}

.silsilah-quick-modal-card {
  width: 100%;
  max-width: 520px;
  background: #0d131f;
  border: 1px solid rgba(197, 160, 89, 0.35);
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.8), 0 0 35px rgba(197, 160, 89, 0.15);
  border-radius: 1.25rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  animation: modalPopIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalPopIn {
  from {
    transform: scale(0.92);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.modal-header-gold {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.9) 0%, rgba(15, 23, 42, 0.95) 100%);
  border-bottom: 1px solid rgba(197, 160, 89, 0.25);
  padding: 1.15rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid rgba(51, 65, 85, 0.4);
  background: rgba(15, 23, 42, 0.5);
}

.modal-tab-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  color: #94a3b8;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  cursor: pointer;
  background: transparent;
  border-top: none;
  border-left: none;
  border-right: none;
}

.modal-tab-btn.active {
  color: var(--color-gold-light);
  border-bottom-color: var(--color-gold);
  background: rgba(197, 160, 89, 0.08);
}

.modal-body-scroll {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer-action {
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(51, 65, 85, 0.4);
  background: rgba(15, 23, 42, 0.7);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Toast Notifications */
.silsilah-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100000;
  background: #0f172a;
  border: 1px solid var(--color-gold);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  color: #f1f5f9;
  padding: 0.85rem 1.25rem;
  border-radius: 0.75rem;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.silsilah-toast.show {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

