:root {
  --ft-bg: #f4f6f9;
  --ft-surface: #ffffff;
  --ft-border: #dbe2ea;
  --ft-text: #1f2937;
  --ft-muted: #64748b;
  --ft-male: #1565c0;
  --ft-male-bg: #eff6ff;
  --ft-female: #ad1457;
  --ft-female-bg: #fdf2f8;
  --ft-unknown: #546e7a;
  --ft-unknown-bg: #f8fafc;
  --ft-gold: #f59e0b;
  --ft-indigo: #283593;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--ft-bg);
  color: var(--ft-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.ft-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.mb-0 {
  margin-bottom: 0 !important;
}

/* Header & Navbar */
.ft-header {
  position: relative;
  z-index: 50;
}

.ft-navbar {
  height: 58px;
  line-height: 58px;
}

.ft-nav-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}

.ft-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
  white-space: nowrap;
}

.ft-logo-svg {
  width: 24px;
  height: 24px;
}

.ft-nav-center {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.ft-switcher-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  font-size: 0.98rem;
  font-weight: 500;
  padding: 0 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  max-width: 100%;
  overflow: hidden;
}

.ft-switcher-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

#nav-tree-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}

.ft-role-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  text-transform: uppercase;
}

.ft-sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #e0f2fe;
  background: rgba(0, 0, 0, 0.18);
  padding: 3px 10px;
  border-radius: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.ft-sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
}

.ft-sync-pill.syncing .ft-sync-dot {
  background: #facc15;
}

.ft-nav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Visited Trees Switcher Popover */
.ft-switcher-panel {
  position: absolute;
  top: 58px;
  left: 16px;
  width: min(440px, calc(100vw - 32px));
  z-index: 200;
  margin: 0;
  border-radius: 8px;
  overflow: hidden;
}

.ft-switcher-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #eef2ff;
  border-bottom: 1px solid var(--ft-border);
}

.ft-switcher-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
}

.ft-visited-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--ft-border);
  margin-bottom: 6px;
  background: #fff;
}

.ft-visited-item.active {
  border-color: var(--ft-indigo);
  background: #eef2ff;
}

.ft-visited-meta {
  min-width: 0;
  flex: 1;
}

.ft-visited-name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ft-visited-sub {
  font-size: 0.76rem;
  color: var(--ft-muted);
}

.ft-visited-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.ft-switcher-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: #f8fafc;
  border-top: 1px solid var(--ft-border);
}

/* Main Layout */
.ft-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Landing View */
.ft-landing {
  padding: 28px 0 40px;
}

.ft-hero-card {
  border-radius: 10px;
  background: linear-gradient(135deg, #ffffff 0%, #eef2ff 100%);
}

.ft-hero-tag {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  color: #3949ab;
  background: #e0e7ff;
  padding: 4px 10px;
  border-radius: 16px;
  margin-bottom: 12px;
}

.ft-hero-title {
  font-size: 2rem;
  line-height: 1.22;
  font-weight: 700;
  margin: 0 0 12px;
  color: #1e1b4b;
}

.ft-hero-desc {
  font-size: 1.02rem;
  color: #475569;
  margin-bottom: 22px;
}

.ft-hero-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ft-card-title-sm {
  font-size: 1.15rem !important;
  font-weight: 600 !important;
  margin-bottom: 12px !important;
}

.ft-feature-box {
  height: 100%;
  border-radius: 8px;
}

.ft-feature-box h5 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 0;
  color: #1e3a8a;
}

/* Workspace & Toolbar */
.ft-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 58px);
}

.ft-toolbar {
  background: #fff;
  border-bottom: 1px solid var(--ft-border);
  padding: 8px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ft-mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.ft-mode-btn {
  border: 1px solid var(--ft-border);
  background: #f8fafc;
  color: var(--ft-text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ft-mode-btn:hover {
  background: #e2e8f0;
}

.ft-mode-btn.active {
  background: var(--ft-indigo);
  color: #fff;
  border-color: var(--ft-indigo);
}

.ft-toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.ft-search-box {
  position: relative;
  width: 210px;
}

.ft-search-box input {
  height: 32px !important;
  margin: 0 !important;
  padding: 0 10px !important;
  border: 1px solid var(--ft-border) !important;
  border-radius: 6px !important;
  background: #f8fafc !important;
  font-size: 0.85rem !important;
  box-sizing: border-box !important;
}

.ft-search-results {
  position: absolute;
  top: 35px;
  left: 0;
  right: 0;
  background: #fff;
  border-radius: 6px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 120;
  border: 1px solid var(--ft-border);
}

.ft-search-item {
  padding: 7px 10px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.84rem;
}

.ft-search-item:hover {
  background: #eef2ff;
}

.ft-gen-control,
.ft-branch-control {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
}

.ft-mini-select {
  height: 30px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--ft-border);
  background: #fff;
  font-size: 0.82rem;
}

.ft-zoom-controls,
.ft-image-export-group {
  display: inline-flex;
  gap: 3px;
}

/* Canvas Area */
.ft-canvas-layout {
  flex: 1;
  display: flex;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.ft-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: radial-gradient(#e2e8f0 1px, transparent 1px);
  background-size: 22px 22px;
  background-color: #f8fafc;
  min-height: 520px;
}

.ft-svg-host,
.ft-html-host {
  width: 100%;
  height: 100%;
}

.ft-html-host {
  overflow-y: auto;
  padding: 18px;
}

.ft-svg-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

.ft-svg-canvas:active {
  cursor: grabbing;
}

.ft-canvas-overlay-info {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--ft-border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.ft-stats-label {
  color: var(--ft-muted);
}

.ft-tooltip {
  position: fixed;
  z-index: 300;
  background: #0f172a;
  color: #fff;
  padding: 8px 11px;
  border-radius: 6px;
  font-size: 0.8rem;
  max-width: 260px;
  pointer-events: none;
  line-height: 1.4;
}

/* SVG Genealogy Elements */
.ft-edge-parent {
  fill: none;
  stroke: #64748b;
  stroke-width: 1.8px;
}

.ft-edge-parent.adoptive {
  stroke: #0284c7;
  stroke-dasharray: 6, 4;
}

.ft-edge-parent.foster {
  stroke: #0d9488;
  stroke-dasharray: 4, 4;
}

.ft-edge-parent.step {
  stroke: #9333ea;
  stroke-dasharray: 2, 3;
}

.ft-edge-parent.highlighted {
  stroke: #f59e0b;
  stroke-width: 3.2px;
}

.ft-edge-partner {
  fill: none;
  stroke: #ec4899;
  stroke-width: 2px;
}

.ft-edge-partner.former {
  stroke: #94a3b8;
  stroke-dasharray: 4, 4;
}

.ft-couple-box {
  fill: rgba(252, 231, 243, 0.35);
  stroke: #f472b6;
  stroke-width: 1.2px;
  stroke-dasharray: 5, 3;
  rx: 14;
  ry: 14;
}

.ft-node-group {
  cursor: pointer;
}

.ft-node-rect {
  rx: 10;
  ry: 10;
  stroke-width: 2px;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.08));
}

.ft-node-rect.sex-male {
  fill: var(--ft-male-bg);
  stroke: var(--ft-male);
}

.ft-node-rect.sex-female {
  fill: var(--ft-female-bg);
  stroke: var(--ft-female);
}

.ft-node-rect.sex-unknown {
  fill: var(--ft-unknown-bg);
  stroke: var(--ft-unknown);
}

.ft-node-rect.is-center {
  stroke-width: 3.5px;
  stroke: #f59e0b;
}

.ft-node-rect.is-highlighted {
  stroke: #d97706;
  stroke-width: 3px;
}

.ft-node-name {
  font-size: 12px;
  font-weight: 700;
  fill: #0f172a;
}

.ft-node-dates {
  font-size: 10.5px;
  fill: #475569;
}

.ft-node-badge {
  font-size: 9.5px;
  font-weight: 600;
  fill: #334155;
}

.ft-fan-sector {
  stroke: #ffffff;
  stroke-width: 1.5px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.ft-fan-sector:hover {
  opacity: 0.88;
}

.ft-fan-sector.is-duplicate {
  stroke: #f59e0b;
  stroke-width: 2.2px;
  stroke-dasharray: 4, 2;
}

.ft-fan-sector.is-highlighted {
  stroke: #d97706;
  stroke-width: 2.8px;
}

.ft-fan-label {
  font-size: 10px;
  font-weight: 600;
  fill: #1e293b;
  pointer-events: none;
}

/* Compact Generation List */
.ft-gen-group {
  background: #fff;
  border: 1px solid var(--ft-border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.ft-gen-group-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 10px;
  color: #1e3a8a;
}

.ft-gen-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: stretch;
}

.ft-compact-unit {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 6px;
}

.ft-compact-unit.is-couple {
  background: #fdf2f8;
  border: 1px dashed #f472b6;
  border-radius: 10px;
  padding: 6px;
}

.ft-compact-partner-sep {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ec4899;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0 2px;
}

.ft-compact-card {
  width: 225px;
  border: 1px solid var(--ft-border);
  border-left-width: 4px;
  border-radius: 6px;
  padding: 10px;
  background: #fff;
  cursor: pointer;
  transition: box-shadow 0.15s ease;
}

.ft-compact-card:hover {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

.ft-compact-card.sex-male {
  border-left-color: var(--ft-male);
}

.ft-compact-card.sex-female {
  border-left-color: var(--ft-female);
}

.ft-compact-card.sex-unknown {
  border-left-color: var(--ft-unknown);
}

/* Side Inspector Drawer */
.ft-person-drawer {
  width: 360px;
  max-width: 92vw;
  margin: 0;
  border-radius: 0;
  border-left: 1px solid var(--ft-border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  overflow: hidden;
}

.ft-drawer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: #eef2ff;
  border-bottom: 1px solid var(--ft-border);
}

.ft-drawer-avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #c7d2fe;
  color: #1e1b4b;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.15rem;
  overflow: hidden;
  flex-shrink: 0;
}

.ft-drawer-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ft-drawer-title-wrap {
  flex: 1;
  min-width: 0;
}

.ft-drawer-title-wrap h6 {
  margin: 0 0 2px;
  font-weight: 700;
  font-size: 1.02rem;
}

.ft-drawer-dates {
  font-size: 0.8rem;
  color: var(--ft-muted);
}

.ft-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}

.ft-drawer-section {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.ft-drawer-section h6 {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ft-muted);
  margin: 0 0 8px;
}

.ft-drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ft-rel-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--ft-border);
  border-radius: 6px;
  margin-bottom: 5px;
  font-size: 0.85rem;
  background: #f8fafc;
}

.ft-rel-chip a {
  font-weight: 600;
  color: #1e40af;
  cursor: pointer;
}

/* Modals & Helpers */
.ft-modal-wide {
  width: 82% !important;
  max-width: 960px !important;
}

.ft-copy-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 10px 0;
}

.ft-copy-row input {
  flex: 1;
  margin: 0 !important;
  padding: 0 10px !important;
  border: 1px solid var(--ft-border) !important;
  border-radius: 6px !important;
  background: #f8fafc !important;
  font-family: monospace;
  font-size: 0.85rem !important;
}

.ft-checkbox-col {
  padding-top: 24px !important;
}

.ft-existing-list {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--ft-border);
  border-radius: 6px;
  background: #fff;
  margin-top: 6px;
}

.ft-existing-option {
  padding: 7px 10px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.86rem;
}

.ft-existing-option:hover,
.ft-existing-option.selected {
  background: #dbeafe;
}

.ft-conflict-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.ft-conflict-card {
  border: 1px solid var(--ft-border);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.ft-kinship-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

.ft-kinship-result {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.ft-kinship-headline {
  font-size: 1.35rem;
  font-weight: 700;
  color: #0f766e;
  margin-bottom: 4px;
}

.ft-chain-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 10px 0;
}

.ft-chain-node {
  padding: 5px 10px;
  background: #fff;
  border: 1px solid var(--ft-border);
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 600;
}

.ft-chain-node.is-lca {
  border-color: var(--ft-gold);
  background: #fef3c7;
}

.ft-chain-arrow {
  font-size: 0.78rem;
  color: var(--ft-muted);
}

.ft-export-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.ft-danger-zone {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid #fecaca;
}

@media (max-width: 820px) {
  .ft-nav-wrapper {
    flex-wrap: wrap;
    padding: 6px 10px;
  }

  .ft-navbar {
    height: auto;
    line-height: 1.4;
  }

  .ft-person-drawer {
    position: fixed;
    top: 58px;
    right: 0;
    bottom: 0;
    z-index: 150;
  }

  .ft-modal-wide {
    width: 96% !important;
  }

  .ft-conflict-grid {
    grid-template-columns: 1fr;
  }
}