/* assets/css/tree.css - Interactive Canvas Engine Styles */

.tree-page-wrapper {
  position: relative;
  width: 100vw;
  height: calc(100vh - 65px);
  overflow: hidden;
  background-color: var(--bg-primary);
  display: flex;
  flex-direction: column;
}

/* Canvas Viewport Container */
.canvas-viewport {
  flex: 1;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  background-image: radial-gradient(var(--border-subtle) 1px, transparent 1px);
  background-size: 28px 28px;
}

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

/* World Container (transformed by pan/zoom) */
.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 6000px;
  height: 6000px;
  transform-origin: 0 0;
  will-change: transform;
}

/* SVG Line Routing Layer */
.canvas-svg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

/* High-Contrast Path Connections & Directional Arrowheads */
.tree-connector-halo {
  fill: none;
  stroke: #090d16;
  stroke-width: 8px;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.95;
  pointer-events: none;
}

.tree-connector {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.2s ease, stroke-width 0.2s ease, opacity 0.25s ease, filter 0.2s ease;
  pointer-events: visibleStroke;
}

.tree-connector.biological {
  stroke: #f59e0b;
  stroke-width: 3.5px;
  filter: drop-shadow(0 0 5px rgba(245, 158, 11, 0.45));
}

.tree-connector.union {
  stroke: #fbbf24;
  stroke-dasharray: 6 3;
  stroke-width: 3px;
  filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.35));
}

.tree-connector.step, .tree-connector.adopted {
  stroke: #c084fc;
  stroke-dasharray: 6 4;
  stroke-width: 3px;
  filter: drop-shadow(0 0 5px rgba(192, 132, 252, 0.5));
}

/* Active Highlight on Node Hover / Selection */
.tree-connector.active-line {
  stroke: #38bdf8 !important;
  stroke-width: 5px !important;
  filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.95)) !important;
  stroke-dasharray: 8 6;
  animation: lineFlowAnim 0.8s linear infinite;
  z-index: 50;
}

.tree-connector.dimmed {
  opacity: 0.12 !important;
}

/* Animated flow pulses across all arrows */
.flow-animated .tree-connector.biological,
.flow-animated .tree-connector.step {
  stroke-dasharray: 10 5;
  animation: lineFlowAnim 1.4s linear infinite;
}

@keyframes lineFlowAnim {
  from { stroke-dashoffset: 30; }
  to { stroke-dashoffset: 0; }
}

/* Spousal Marriage Ring Hub */
.union-marker {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  border: 2px solid var(--accent-gold);
  color: var(--text-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  position: absolute;
  transform: translate(-50%, -50%);
  box-shadow: var(--shadow-sm);
  z-index: 5;
  cursor: pointer;
}

.union-marker:hover {
  transform: translate(-50%, -50%) scale(1.2);
  border-color: #fbbf24;
}

/* Family Node Cards */
.tree-node-card {
  position: absolute;
  width: 240px;
  background: var(--bg-glass-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-normal);
  z-index: 10;
  cursor: pointer;
}

.tree-node-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: var(--shadow-lg), var(--shadow-gold);
  border-color: var(--border-gold-bright);
  z-index: 20;
}

.tree-node-card.highlighted {
  border-color: #38bdf8 !important;
  box-shadow: 0 0 25px rgba(56, 189, 248, 0.6) !important;
  animation: pulseHighlight 1.5s infinite alternate;
}

@keyframes pulseHighlight {
  0% { transform: scale(1.02); }
  100% { transform: scale(1.07); }
}

/* Node Header & Avatar */
.node-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.node-avatar-wrap {
  position: relative;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
}

.node-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-gold);
  background: var(--bg-surface);
}

.status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
}

.status-dot.living {
  background-color: var(--accent-emerald);
}

.status-dot.deceased {
  background-color: #64748b;
}

/* Node Identity Details */
.node-meta {
  flex: 1;
  min-width: 0;
}

.node-name {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-dates {
  font-size: 0.78rem;
  color: var(--text-gold);
  font-weight: 500;
}

.node-occupation {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Node Action Footer & Collapse Badges */
.node-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.4rem;
  font-size: 0.75rem;
}

.node-tag-type {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
}

/* Branch Collapse/Expand Toggle Pill */
.branch-toggle-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  border: 1.5px solid var(--border-gold);
  color: var(--text-gold);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
  z-index: 15;
}

.branch-toggle-btn.bottom {
  bottom: -11px;
}

.branch-toggle-btn.top {
  top: -11px;
}

.branch-toggle-btn:hover {
  background: var(--accent-gold);
  color: #fff;
  transform: translateX(-50%) scale(1.2);
}

/* Floating Control Toolbar */
.tree-toolbar {
  position: absolute;
  top: 1.25rem;
  left: 1.25rem;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 0.45rem 0.65rem;
  box-shadow: var(--shadow-md);
}

/* Search Bar on Canvas */
.tree-search-box {
  position: relative;
  width: 220px;
}

.tree-search-input {
  width: 100%;
  padding: 0.4rem 0.75rem 0.4rem 2rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.85rem;
}

.tree-search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.search-results-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.4rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 250px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}

.search-results-dropdown.active {
  display: block;
}

.search-result-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
}

.search-result-item:hover {
  background: rgba(217, 119, 6, 0.18);
  color: var(--text-gold);
}

/* Zoom Controls Dock */
.zoom-dock {
  position: absolute;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-md);
  padding: 0.4rem;
  box-shadow: var(--shadow-md);
}

/* Minimap radar */
.minimap-container {
  position: absolute;
  bottom: 1.5rem;
  left: 1.5rem;
  width: 180px;
  height: 120px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 50;
  overflow: hidden;
}

.minimap-radar {
  width: 100%;
  height: 100%;
}

.minimap-viewport-box {
  position: absolute;
  border: 1.5px solid #38bdf8;
  background: rgba(56, 189, 248, 0.15);
  pointer-events: none;
}

/* Quick Member Side Inspector */
.node-inspector-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: 380px;
  height: 100%;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-gold);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  transform: translateX(100%);
  transition: transform var(--transition-normal);
  display: flex;
  flex-direction: column;
}

.node-inspector-drawer.active {
  transform: translateX(0);
}

/* =====================================================
   RESPONSIVE
   ===================================================== */

@media (max-width: 768px) {

  /* Tree page: account for shorter header on mobile */
  .tree-page-wrapper {
    height: calc(100vh - 52px);
  }

  /* Toolbar: compact — make it scrollable horizontally */
  .tree-toolbar {
    top: 0.75rem;
    left: 0.75rem;
    right: 0.75rem;
    padding: 0.35rem 0.5rem;
    gap: 0.35rem;
    overflow-x: auto;
    scrollbar-width: none;
    border-radius: var(--radius-md);
  }

  .tree-toolbar::-webkit-scrollbar { display: none; }

  /* Search box: narrower on mobile */
  .tree-search-box {
    width: 160px;
  }

  .tree-search-input {
    font-size: 0.8rem;
    padding: 0.35rem 0.6rem 0.35rem 1.7rem;
  }

  /* Minimap: hidden by default on mobile — can be toggled */
  .minimap-container {
    display: none;
  }

  .minimap-container.mobile-visible {
    display: block;
    width: 130px;
    height: 85px;
    bottom: 5rem;
    left: 0.75rem;
  }

  /* Zoom dock: move up from bottom to avoid browser chrome */
  .zoom-dock {
    bottom: 1rem;
    right: 0.75rem;
  }

  /* Node inspector: full-screen on mobile */
  .node-inspector-drawer {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border-gold);
    top: auto;
    bottom: 0;
    height: 75vh;
    transform: translateY(100%);
  }

  .node-inspector-drawer.active {
    transform: translateY(0);
  }

  /* Node cards: slightly smaller */
  .tree-node-card {
    width: 200px;
    padding: 0.6rem;
  }

  .node-name {
    font-size: 0.85rem;
  }

  .node-dates {
    font-size: 0.72rem;
  }
}

@media (max-width: 480px) {

  /* Even more compact toolbar on small phones */
  .tree-toolbar {
    top: 0.5rem;
    left: 0.5rem;
    right: 0.5rem;
    padding: 0.3rem 0.4rem;
  }

  .tree-search-box {
    width: 130px;
  }

  /* Node cards: minimum useful size */
  .tree-node-card {
    width: 170px;
    padding: 0.5rem;
  }
}

/* =====================================================
   LIGHT THEME ENHANCEMENTS — ULTRA-MODERN & EYE-CATCHING
   ===================================================== */

[data-theme="light"] .tree-page-wrapper {
  background-color: #f8fafc;
}

[data-theme="light"] .canvas-viewport {
  background-color: #f8fafc;
  background-image: radial-gradient(#cbd5e1 1.2px, transparent 1.2px);
  background-size: 28px 28px;
}

/* Remove dark halo in light mode: use subtle soft canvas tone */
[data-theme="light"] .tree-connector-halo {
  stroke: #f8fafc;
  stroke-width: 6px;
  opacity: 1;
}

/* Crisp, warm burnished bronze biological lineage arrows */
[data-theme="light"] .tree-connector.biological {
  stroke: #d97706;
  stroke-width: 3px;
  filter: drop-shadow(0 2px 4px rgba(217, 119, 6, 0.22));
}

[data-theme="light"] .tree-connector.union {
  stroke: #b45309;
  stroke-width: 2.5px;
  stroke-dasharray: 6 3;
  filter: none;
}

[data-theme="light"] .tree-connector.step,
[data-theme="light"] .tree-connector.adopted {
  stroke: #9333ea;
  stroke-width: 2.5px;
  stroke-dasharray: 6 3;
  filter: drop-shadow(0 2px 4px rgba(147, 51, 234, 0.2));
}

/* Union Marriage Ring Hub */
[data-theme="light"] .union-marker {
  background: #ffffff;
  border: 2px solid #d97706;
  color: #b45309;
  box-shadow: 0 2px 8px rgba(180, 83, 9, 0.16);
}

[data-theme="light"] .union-marker:hover {
  background: #fef3c7;
  border-color: #b45309;
}

/* Sleek Apple/Stripe-Level Card Styling */
[data-theme="light"] .tree-node-card {
  background: #ffffff;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 14px;
  box-shadow: 0 4px 14px -2px rgba(15, 23, 42, 0.06), 0 2px 4px -1px rgba(15, 23, 42, 0.03);
}

[data-theme="light"] .tree-node-card:hover {
  transform: translateY(-5px) scale(1.02);
  border-color: #d97706;
  box-shadow: 0 16px 32px -4px rgba(217, 119, 6, 0.18), 0 4px 10px -2px rgba(15, 23, 42, 0.06);
}

[data-theme="light"] .node-avatar {
  border: 2px solid #d97706;
  background: #f8fafc;
  box-shadow: 0 2px 6px rgba(217, 119, 6, 0.18);
}

[data-theme="light"] .node-name {
  color: #0f172a;
  font-weight: 700;
  font-family: var(--font-serif);
}

[data-theme="light"] .node-dates {
  color: #b45309;
  font-weight: 600;
}

[data-theme="light"] .node-occupation {
  color: #475569;
  font-weight: 500;
}

[data-theme="light"] .node-footer {
  border-top: 1px solid #f1f5f9;
}

/* Gender Pills with Crisp Modern Palette */
[data-theme="light"] .node-tag-type {
  background: #f1f5f9;
  color: #475569;
  font-weight: 600;
  border: 1px solid #e2e8f0;
}

[data-theme="light"] .node-tag-type.gender-male {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #dbeafe;
}

[data-theme="light"] .node-tag-type.gender-female {
  background: #fff1f2;
  color: #be123c;
  border-color: #ffe4e6;
}

[data-theme="light"] .node-gen-badge {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
  border-radius: 9999px;
  padding: 0.1rem 0.5rem;
  font-size: 0.68rem;
  font-weight: 700;
}

/* Branch Toggle Button */
[data-theme="light"] .branch-toggle-btn {
  background: #ffffff;
  border: 1.5px solid #d97706;
  color: #b45309;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .branch-toggle-btn:hover {
  background: #d97706;
  color: #ffffff;
}

/* Floating Controls Toolbar */
[data-theme="light"] .tree-toolbar {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #e2e8f0;
  box-shadow: 0 10px 25px -3px rgba(15, 23, 42, 0.08), 0 4px 8px -2px rgba(15, 23, 42, 0.04);
}

[data-theme="light"] .tree-search-input {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #0f172a;
}

[data-theme="light"] .tree-search-input:focus {
  border-color: #d97706;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
}

[data-theme="light"] .search-results-dropdown {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  box-shadow: 0 16px 36px -4px rgba(15, 23, 42, 0.14);
}

[data-theme="light"] .search-result-item:hover {
  background: #fef3c7;
  color: #92400e;
}

/* Zoom Dock */
[data-theme="light"] .zoom-dock {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #e2e8f0;
  box-shadow: 0 6px 20px -2px rgba(15, 23, 42, 0.08);
}

[data-theme="light"] .zoom-dock .btn-icon {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #334155;
}

[data-theme="light"] .zoom-dock .btn-icon:hover {
  background: #f1f5f9;
  color: #0f172a;
}

/* Minimap radar */
[data-theme="light"] .minimap-container {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #cbd5e1;
  box-shadow: 0 8px 24px -3px rgba(15, 23, 42, 0.09);
}

[data-theme="light"] .minimap-viewport-box {
  border: 2px solid #d97706;
  background: rgba(217, 119, 6, 0.14);
}

/* Side Inspector Drawer */
[data-theme="light"] .node-inspector-drawer {
  background: #ffffff;
  border-left: 1px solid #e2e8f0;
  box-shadow: -10px 0 35px -5px rgba(15, 23, 42, 0.1);
}

[data-theme="light"] .node-inspector-drawer .modal-header {
  border-bottom: 1px solid #f1f5f9;
  padding: 1rem 1.25rem;
}

[data-theme="light"] .node-inspector-drawer .modal-title {
  color: #0f172a;
  font-weight: 700;
}

[data-theme="light"] .node-vital-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}
