/* Family Tree — all styles */
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #0f172a; color: #e2e8f0; overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: #111827; border-bottom: 1px solid #1f2937;
  flex-shrink: 0; z-index: 20; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon {
  width: 36px; height: 36px; background: linear-gradient(135deg, #3b82f6, #6366f1);
  border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}
.brand-text { min-width: 0; }
.brand-text .label { font-size: 10px; color: #64748b; font-weight: 600; letter-spacing: 0.1em; }
.tree-name {
  font-size: 16px; font-weight: 600; color: #f1f5f9;
  background: transparent; border: none; padding: 2px 6px; margin-left: -6px;
  border-radius: 4px; outline: none; min-width: 180px; max-width: 300px;
  font-family: inherit; user-select: text;
}
.tree-name:hover, .tree-name:focus { background: #1f2937; }

.toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.btn {
  padding: 7px 12px; background: #1f2937; color: #e2e8f0; border: 1px solid #374151;
  border-radius: 6px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.15s; font-weight: 500; font-family: inherit; white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: #374151; border-color: #4b5563; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: #3b82f6; border-color: #3b82f6; color: white; }
.btn-primary:hover { background: #2563eb; border-color: #2563eb; }
.btn-danger { color: #f87171; }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; color: white; }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.divider { width: 1px; height: 22px; background: #374151; margin: 0 4px; }

.save-status {
  font-size: 12px; color: #64748b; margin-left: 8px;
  display: inline-flex; align-items: center; gap: 6px;
}
.save-status .dot { width: 6px; height: 6px; border-radius: 50%; background: #10b981; }
.save-status.saving .dot { background: #fbbf24; animation: pulse 1s infinite; }
.save-status.error .dot { background: #ef4444; }
@keyframes pulse { 50% { opacity: 0.4; } }

main { flex: 1; overflow: hidden; position: relative; background: #0f172a; }
.viewport { width: 100%; height: 100%; position: relative; overflow: hidden; cursor: grab; }
.viewport.dragging { cursor: grabbing; }
.canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
#svg-lines { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; }

.person {
  position: absolute; text-align: center;
  transform: translate(-50%, -34px);
  width: 120px; cursor: pointer; z-index: 2;
}
.person:hover .avatar-frame { transform: scale(1.06); }
.avatar-frame {
  width: 68px; height: 68px; border-radius: 50%; margin: 0 auto;
  padding: 3px; background: #0f172a; border: 3px solid var(--ring);
  box-sizing: border-box; transition: transform 0.15s;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3); position: relative; overflow: hidden;
}
.person.selected .avatar-frame {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.35), 0 3px 10px rgba(0, 0, 0, 0.3);
}
.avatar {
  width: 100%; height: 100%; border-radius: 50%; overflow: hidden; position: relative;
  background: var(--bg); color: white; font-weight: 600; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.avatar img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  border-radius: 50%; background: var(--bg);
}
.person .name { margin-top: 6px; font-size: 12px; font-weight: 600; color: #f1f5f9; line-height: 1.2; }

/* Dates + notes toggle row */
.person .dates-row {
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
}
.person .dates { font-size: 10px; color: var(--ring); font-weight: 500; }

/* Notes toggle button */
.person .notes-toggle {
  background: transparent;
  border: 1px solid var(--ring);
  border-radius: 3px;
  color: var(--ring);
  cursor: pointer;
  padding: 0 5px;
  font-size: 9px;
  line-height: 1.5;
  font-family: inherit;
  transition: all 0.15s;
}
.person .notes-toggle:hover { background: var(--ring); color: white; }
.person.notes-open .notes-toggle { background: var(--ring); color: white; }

/* Notes panel — overlays, doesn't affect layout */
.person .notes-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 8px 10px;
  min-width: 160px;
  max-width: 240px;
  z-index: 10;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  text-align: left;
  cursor: default;
}
.person.notes-open .notes-panel { display: block; }
.person .notes-content {
  font-size: 11px;
  color: #cbd5e1;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  user-select: text;
}

.heart {
  position: absolute; transform: translate(-50%, -50%);
  z-index: 3; background: #0f172a; border-radius: 50%;
  padding: 2px; line-height: 0; pointer-events: none;
}

.fab-toolbar {
  position: absolute; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 6px; z-index: 10;
}
.fab {
  width: 40px; height: 40px; border-radius: 8px;
  background: #1e293b; border: 1px solid #334155; color: #e2e8f0;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.fab:hover { background: #334155; }
.fab svg { width: 16px; height: 16px; }

.selection-bar {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1e293b; border: 1px solid #334155; border-radius: 10px;
  padding: 8px; display: none; gap: 4px; z-index: 15;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); align-items: center; flex-wrap: wrap;
  max-width: calc(100vw - 40px);
}
.selection-bar.visible { display: flex; }
.sel-info {
  padding: 4px 12px; display: flex; align-items: center; gap: 8px;
  border-right: 1px solid #334155; margin-right: 4px;
}
.sel-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: white;
  background: var(--bg); border: 2px solid var(--ring); box-sizing: border-box;
}
.sel-info .name { font-size: 13px; font-weight: 500; color: #f1f5f9; }
.selection-bar .btn { padding: 6px 10px; font-size: 12px; }

.empty-state {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px; pointer-events: none; z-index: 5;
}
.empty-state h3 { color: #cbd5e1; font-size: 20px; margin: 0; }
.empty-state p { color: #64748b; margin: 0; max-width: 400px; text-align: center; }
.empty-state .btn { pointer-events: auto; }

#toast-container {
  position: fixed; bottom: 80px; right: 20px;
  display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none;
}
.toast {
  background: #1e293b; color: #f1f5f9; padding: 12px 18px; border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4); font-size: 14px;
  border-left: 3px solid #3b82f6; animation: slideIn 0.2s ease-out;
  max-width: 340px;
}
.toast.error { border-left-color: #ef4444; }
.toast.success { border-left-color: #10b981; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center; z-index: 200;
  animation: fadeIn 0.15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #1e293b; border: 1px solid #334155; border-radius: 10px;
  padding: 24px; min-width: 380px; max-width: 90vw; max-height: 90vh; overflow: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4); user-select: text;
}
.modal h2 { margin: 0 0 4px 0; font-size: 18px; color: #f1f5f9; }
.modal .description { color: #94a3b8; margin: 0 0 20px 0; font-size: 13px; line-height: 1.5; }
.modal label { display: block; font-size: 12px; font-weight: 500; color: #94a3b8; margin-bottom: 6px; }
.modal .field { margin-bottom: 14px; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 9px 12px; background: #0f172a; border: 1px solid #334155;
  border-radius: 6px; color: #f1f5f9; font-size: 14px; font-family: inherit; outline: none;
}
.modal textarea { resize: vertical; min-height: 60px; line-height: 1.4; }
.modal input:focus, .modal textarea:focus { border-color: #3b82f6; }
.modal .row { display: flex; gap: 10px; }
.modal .row > * { flex: 1; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.radio-group { display: flex; gap: 8px; }
.radio-group label {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 9px; background: #0f172a; border: 1px solid #334155;
  border-radius: 6px; cursor: pointer; font-size: 14px; color: #f1f5f9; margin: 0;
}
.radio-group input { display: none; }
.radio-group label.checked { background: #3b82f6; border-color: #3b82f6; }

/* Avatar upload row in modal */
.avatar-upload-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #0f172a;
  border: 2px dashed #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  font-size: 24px;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.link { stroke: #475569; stroke-width: 1.5; fill: none; }

@media (max-width: 768px) {
  .btn-label { display: none; }
  .tree-name { min-width: 120px; font-size: 14px; }
  .brand-text .label { display: none; }
}
