:root {
  --bg: #f2f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #3b82f6;
  --border: rgba(59, 130, 246, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #f8fafc 0%, #eff6ff 100%);
  color: var(--text);
}

.container {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  padding: 32px 0 16px;
  background: radial-gradient(circle at top left, rgba(59, 130, 246, 0.12), transparent 35%);
}

.site-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
}

.site-header p {
  margin: 12px 0 0;
  color: var(--muted);
}

.intro {
  padding: 24px 0 16px;
}

.tabs-section {
  padding-bottom: 64px;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab-button {
  background: none;
  border: none;
  padding: 12px 24px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.tab-button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-button:hover {
  color: var(--text);
}

.tab-content {
  /* No specific styles, just for switching */
}

.card-panel,
.editor-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.06);
}

.panel-title h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.panel-title p {
  margin: 0;
  color: var(--muted);
}

#treeControls {
  margin-bottom: 20px;
}

#treeWrapper {
  position: relative;
  overflow-x: auto;
  overflow-y: visible;
  width: 100%;
}

#connectorSvg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

#tree {
  display: flex;
  flex-direction: column;
  gap: 40px;
  position: relative;
  width: max-content; /* Changed from min-width to width */
  padding: 20px;
}

.tree-node-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.children-container {
  display: flex;
  flex-direction: row;
  gap: 20px;
  margin-top: 40px;
  flex-wrap: nowrap;
  min-width: max-content;
  overflow-x: auto;
  padding-bottom: 10px; /* Space for scrollbar */
}

.button-container {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-top: 10px;
}

.expand-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
}

.expand-btn:hover {
  background: var(--accent-hover);
}

.highlight-btn {
  background: #8b5cf6;
  color: white;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
}

.highlight-btn:hover {
  background: #7c3aed;
}

.hide-siblings-btn {
  background: #f59e0b;
  color: white;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
  margin-left: 4px;
}

.hide-siblings-btn:hover {
  background: #d97706;
}

.tree-node {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  font-size: 0.9rem;
}

.tree-node:hover {
  transform: translateY(-2px);
  border-color: rgba(59, 130, 246, 0.3);
}

.tree-node.active {
  border-color: var(--accent);
  box-shadow: 0 20px 48px rgba(59, 130, 246, 0.18);
}

.tree-node.focused {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.08);
  box-shadow: 0 22px 50px rgba(16, 185, 129, 0.15);
}

.tree-node.related {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.08);
}

.tree-node.ancestor-highlighted {
  border-color: #8b5cf6;
  background: rgba(139, 92, 246, 0.08);
  box-shadow: 0 20px 48px rgba(139, 92, 246, 0.18);
}

.tree-node.search-highlight {
  border-color: #2563eb;
  background: rgba(59, 130, 246, 0.12);
  box-shadow: 0 20px 48px rgba(59, 130, 246, 0.16);
}

.tree-search-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.tree-controls-right {
  display: flex;
  gap: 10px;
  align-items: center;
}

.tree-search-box {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  flex: 1;
}

.map-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
}

.map-wrapper {
  margin-top: 18px;
  width: 100%;
  min-height: 500px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.blog-panel {
  margin-top: 24px;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
}

.blog-panel .panel-title h3 {
  margin: 0 0 8px;
}

.blog-panel .panel-title p {
  margin: 0 0 18px;
  color: var(--muted);
}

.blog-panel label.field-group {
  margin-bottom: 18px;
}

.blog-panel textarea {
  min-height: 160px;
}

.map-wrapper iframe {
  width: 100%;
  height: 100%;
  min-height: 500px;
  border: none;
}

.tree-search-box input {
  flex: 1;
  min-width: 220px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.tree-search-box button {
  padding: 10px 14px;
}

.tree-search-row p.form-message {
  margin: 0;
  width: 100%;
}

.relationship-search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.relationship-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.tree-search-results {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.tree-search-results p {
  margin: 0;
  width: 100%;
  font-weight: 600;
}

.search-result-button {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.search-result-button:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.tree-node h3 {
  margin: 0 0 4px 0;
  font-size: 1rem;
  font-weight: 600;
}

.tree-node .card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 12px;
}

.tree-node .card-info {
  flex: 1;
  min-width: 0;
}

.tree-node .card-info h3 {
  margin: 0 0 2px 0;
}

.tree-node .card-info .birth-death {
  margin: 2px 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.tree-node .card-info p {
  margin: 2px 0;
  font-size: 0.85rem;
}

.tree-node .profile-picture {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--border);
}

.tree-node .profile-placeholder {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--card);
  font-size: 24px;
}

.tree-node .card-details {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.tree-node .card-details p {
  margin: 2px 0 4px 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.tree-node p {
  margin: 2px 0;
  line-height: 1.3;
  color: var(--muted);
}

.tree-node .card-details .relation {
  margin-top: 4px;
  font-size: 0.8rem;
}

.tree-node .card-details .relation div {
  margin: 2px 0;
}

.connector-line {
  opacity: 0.35;
  transition: opacity 0.2s ease, stroke-width 0.2s ease;
}

.connector-line.highlighted {
  opacity: 1;
  stroke-width: 4;
}

.tree-node h3 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.tree-node p {
  margin: 6px 0;
  color: var(--muted);
}

.tree-node .relation {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.relation strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

label.field-group {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

label.field-group span {
  font-weight: 600;
}

.field-help {
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 4px;
}

.file-upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(59, 130, 246, 0.05);
  border-radius: 8px;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.file-upload-row span {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 500;
}

.file-upload-row input[type="file"] {
  flex: 1;
  font-size: 0.9rem;
}

textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  font-size: 0.98rem;
  min-height: 80px;
  resize: vertical;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--card);
  border-radius: 24px;
  padding: 24px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header-content {
  display: flex;
  align-items: center;
  gap: 16px;
}

#modal-profile-picture {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--border);
  flex-shrink: 0;
}

#modal-profile-picture img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.modal-header h2 {
  margin: 0;
}

.close-button {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--muted);
}

.close-button:hover {
  color: var(--text);
}

.modal-body {
  display: grid;
  gap: 20px;
}

select[multiple] {
  min-height: 120px;
}

.form-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.save-button,
.secondary-button,
button.reset-button,
.delete-button {
  padding: 12px 18px;
  border: none;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
}

.save-button {
  background: var(--accent);
  color: white;
}

.secondary-button {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}

.save-button:hover {
  background: #2563eb;
}

.secondary-button:hover {
  background: #f8fafc;
}

.delete-button {
  background: #dc2626;
  color: white;
  border: none;
}

.delete-button:hover {
  background: #b91c1c;
}

.form-message {
  margin-top: 14px;
  color: var(--muted);
}

.form-message.error {
  color: #b91c1c;
}
