/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 280px;
  --bg: #f7f5f1;
  --surface: #ffffff;
  --border: #e5e0d8;
  --accent: #5c4a32;
  --accent-light: #8b6f47;
  --accent-muted: #f0ebe3;
  --text: #2c2416;
  --text-muted: #7d6e5a;
  --male: #3b6cb7;
  --female: #b7465a;
  --unknown: #6b7280;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.14);
  --font-body: 'Inter', system-ui, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
}

html, body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Layout ─────────────────────────────────────────────────── */
body { display: flex; overflow: hidden; }

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

#main {
  flex: 1;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar header ─────────────────────────────────────────── */
#sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

#home-link {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 8px;
  transition: color 0.1s;
}
#home-link:hover { color: var(--accent); }

#site-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
}

#search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
#search:focus { border-color: var(--accent-light); }

#search-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  min-height: 1rem;
}

/* ── Person list ────────────────────────────────────────────── */
#person-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 6px 0;
}

#person-list li {
  padding: 9px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
  line-height: 1.3;
}

#person-list li:hover { background: var(--accent-muted); }

#person-list li.active {
  background: var(--accent-muted);
  border-left-color: var(--accent);
}

.list-name {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text);
}

.list-years {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ── Splash ─────────────────────────────────────────────────── */
#splash {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

#splash-inner {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}

#splash-icon { font-size: 4rem; margin-bottom: 16px; }

#splash-inner h2 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--accent);
  margin-bottom: 8px;
}

#splash-inner p { font-size: 0.95rem; }

/* ── Detail view ────────────────────────────────────────────── */
#detail-view {
  height: 100%;
  overflow-y: auto;
  padding: 24px 24px 80px;
}

#detail-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

#detail-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

#detail-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 600;
  color: #fff;
}

#detail-avatar.male   { background: var(--male); }
#detail-avatar.female { background: var(--female); }
#detail-avatar.unknown { background: var(--unknown); }

#detail-name {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 4px;
}

#detail-dates {
  font-size: 0.875rem;
  color: var(--text-muted);
}

#detail-place {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

#detail-facts { margin-top: 8px; }

.fact-row {
  display: flex;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}

.fact-label {
  width: 90px;
  flex-shrink: 0;
  color: var(--text-muted);
  font-weight: 500;
}

.fact-value { color: var(--text); }

#detail-note {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--accent-muted);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  border-left: 3px solid var(--accent-light);
}

/* ── Family sections ────────────────────────────────────────── */
.family-section {
  margin-bottom: 16px;
}

.family-section:empty { display: none; }

.section-heading {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding: 0 2px;
}

.family-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.family-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.1s;
  min-width: 180px;
  flex: 1 1 180px;
  max-width: 280px;
  box-shadow: var(--shadow);
}

.family-card:hover {
  border-color: var(--accent-light);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.family-card-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
}

.family-card-avatar.male   { background: var(--male); }
.family-card-avatar.female { background: var(--female); }
.family-card-avatar.unknown { background: var(--unknown); }

.family-card-name {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text);
  line-height: 1.2;
}

.family-card-years {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.marriage-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding: 0 2px;
}

/* ── View toggle button ─────────────────────────────────────── */
#view-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 4px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

.toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 24px;
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.toggle-btn:hover { background: var(--accent-muted); color: var(--accent); }

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── Tree view ──────────────────────────────────────────────── */
#tree-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#tree-toolbar {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

#tree-name-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

#tree-canvas-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
  cursor: grab;
  user-select: none;
}
#tree-canvas-wrap:active { cursor: grabbing; }

#tree-svg {
  width: 100%;
  height: 100%;
}

/* ── Tree nodes ─────────────────────────────────────────────── */
.tree-node { cursor: pointer; }

.tree-node rect {
  rx: 8;
  ry: 8;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
  transition: filter 0.15s;
}

.tree-node:hover rect {
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.2));
}

.tree-node.focus rect { stroke-width: 2.5; }

.tree-link {
  fill: none;
  stroke: var(--border);
  stroke-width: 1.5;
}

.tree-link.marriage {
  stroke: var(--accent-light);
  stroke-dasharray: 4 3;
}

.tree-toggle-btn circle {
  transition: fill 0.15s;
}
.tree-toggle-btn:hover circle {
  fill: var(--accent-muted);
}

/* ── Tooltip ────────────────────────────────────────────────── */
#tree-tooltip {
  position: fixed;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  max-width: 300px;
  transition: opacity 0.1s;
}

#tt-name {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

#tt-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

#tt-facts { display: flex; flex-direction: column; gap: 3px; }

.tt-fact {
  font-size: 0.775rem;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
}

.tt-fact span {
  color: var(--accent-light);
  font-weight: 500;
  flex-shrink: 0;
  width: 68px;
}

/* ── Context menu ───────────────────────────────────────────── */
#tree-context-menu {
  position: fixed;
  z-index: 300;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 0;
  box-shadow: var(--shadow-lg);
  min-width: 180px;
}

.cm-item {
  padding: 7px 16px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
}

.cm-item:hover { background: var(--accent-muted); }

.cm-item:empty { display: none; }

.cm-item.disabled {
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
}

.cm-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ── Utility ────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-light); }

/* ── Mobile sidebar toggle & overlay ────────────────────────── */
#sidebar-toggle {
  display: none;
}

#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 390;
}

#sidebar-overlay.visible { display: block; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 700px) {
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 400;
    width: min(280px, 85vw);
    min-width: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }

  #sidebar.open { transform: translateX(0); }

  #sidebar-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 100;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    box-shadow: var(--shadow);
  }

  #sidebar-toggle:active { background: var(--accent-muted); }

  #splash { padding-top: 56px; }
  #tree-toolbar { padding-left: 100px; }
  #detail-view { padding: 60px 16px 80px; }
  #view-toggle { bottom: 16px; right: 16px; }
  .family-card { min-width: 140px; }
}
