/* ============================================================================
   Our Family Tree — heirloom design system
   Fonts: Fraunces (display serif) + Inter (UI sans)
============================================================================ */
:root {
  --paper:      #f6f1e7;
  --paper-2:    #efe7d7;
  --ink:        #2c2620;
  --ink-soft:   #6b6356;
  --line:       #d8cdb8;
  --card:       #fffdf8;
  --accent:     #9a3b2e;   /* terracotta */
  --accent-2:   #b9543f;
  --gold:       #b9923f;
  --sage:       #5d6b54;
  --blue:       #3f5b6b;
  --shadow:     0 1px 2px rgba(44,38,32,.06), 0 8px 24px rgba(44,38,32,.10);
  --shadow-lg:  0 2px 6px rgba(44,38,32,.08), 0 24px 60px rgba(44,38,32,.18);
  --radius:     16px;
  --radius-sm:  10px;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans:  "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; }

/* paper texture via layered gradients */
.tree-body, .profile-body, .admin-body, .login-body {
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(185,146,63,.10), transparent 60%),
    radial-gradient(1000px 700px at 110% 10%, rgba(154,59,46,.08), transparent 55%),
    var(--paper);
}

/* ---- buttons --------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: .4em;
  font: 600 14px/1 var(--sans);
  padding: 10px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  cursor: pointer; transition: .15s ease; white-space: nowrap; text-decoration: none;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: #c9b6b0; color: var(--accent); }
.btn-danger:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-block { width: 100%; justify-content: center; padding: 13px; }

/* ============================================================================
   Top bar (public)
============================================================================ */
.site-bar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  background: rgba(246,241,231,.82); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.site-brand-group { display: flex; flex-direction: column; }
.site-brand { font-family: var(--serif); font-weight: 700; font-size: 22px; color: var(--ink); }
.site-tagline { font-size: 12.5px; color: var(--ink-soft); }
.site-tools { display: flex; align-items: center; gap: 10px; }
#search {
  font: 500 14px var(--sans); padding: 10px 14px; width: 220px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--ink);
}
#search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(154,59,46,.12); }

/* ============================================================================
   Tree stage
============================================================================ */
.tree-body { overflow: hidden; }
.tree-stage {
  position: relative; width: 100vw; height: calc(100vh - 67px);
  overflow: hidden; cursor: grab; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(108,99,86,.16) 1px, transparent 0);
  background-size: 26px 26px;
}
.tree-stage.grabbing { cursor: grabbing; }
.tree-viewport { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.tree-links { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; }
.tree-nodes { position: absolute; top: 0; left: 0; }

.link { fill: none; stroke: #c2b49a; stroke-width: 2.5; stroke-linecap: round; }
.link-marriage { stroke: var(--gold); stroke-width: 3; stroke-linecap: round; }

/* collapse / expand toggles (positioned by their centre) */
.tree-toggle {
  position: absolute; transform: translate(-50%, -50%);
  font: 700 13px/1 var(--sans); cursor: pointer; padding: 0;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-soft);
  box-shadow: var(--shadow); z-index: 4; transition: transform .12s ease, opacity .12s ease, background .12s;
}
.tree-toggle:hover { color: var(--ink); border-color: var(--accent); transform: translate(-50%, -50%) scale(1.1); }

/* children (down): circle showing − when open, a count when collapsed */
.tt-children { width: 26px; height: 26px; border-radius: 999px; display: grid; place-items: center; }
.tt-children.is-collapsed { background: var(--accent); border-color: var(--accent); color: #fff; }
.tt-children.is-collapsed:hover { background: var(--accent-2); color: #fff; }

/* parents (up): a faint caret when open, a clear chip when ancestors are hidden */
.tt-parents { border-radius: 999px; }
.tt-parents.up-hide { width: 22px; height: 22px; display: grid; place-items: center; font-size: 14px; opacity: .38; }
.tt-parents.up-hide:hover { opacity: 1; }
.tt-parents.up-show {
  height: 22px; padding: 0 11px; font-size: 11px; font-weight: 600; letter-spacing: .01em;
  background: var(--gold); border-color: var(--gold); color: #fff; white-space: nowrap;
}
.tt-parents.up-show:hover { color: #fff; border-color: var(--gold); filter: brightness(1.05); }

/* person card */
.node {
  position: absolute; width: 150px; height: 164px;
  display: flex; flex-direction: column; gap: 8px; align-items: center; text-align: center;
  padding: 14px 10px 12px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line);
  box-shadow: var(--shadow); color: var(--ink) !important;
  text-decoration: none !important; transition: transform .15s ease, box-shadow .15s ease, opacity .2s;
  overflow: hidden;
}
.node::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--ink-soft); }
.node-male::before   { background: var(--blue); }
.node-female::before { background: var(--accent); }
.node-other::before  { background: var(--sage); }
.node:hover { transform: translateY(-3px) scale(1.015); box-shadow: var(--shadow-lg); z-index: 5; }
.node.dim { opacity: .25; }
.node.hit { box-shadow: 0 0 0 3px var(--gold), var(--shadow-lg); z-index: 6; }

.node-avatar {
  flex: 0 0 56px; width: 56px; height: 56px; border-radius: 12px; overflow: hidden;
  background: var(--paper-2); display: grid; place-items: center;
  font-family: var(--serif); font-weight: 600; font-size: 22px; color: var(--ink-soft);
}
.node-avatar img { width: 100%; height: 100%; object-fit: cover; }
.node-body { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; width: 100%; }
.node-name { font-family: var(--serif); font-weight: 600; font-size: 15px; line-height: 1.15;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.node-span { font-size: 12.5px; color: var(--accent); font-weight: 600; }
.node-place { font-size: 11.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* controls + hints */
.tree-controls {
  position: absolute; right: 20px; bottom: 20px; z-index: 20;
  display: flex; flex-direction: column; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
}
.tree-controls button {
  width: 44px; height: 44px; border: none; background: var(--card); color: var(--ink);
  font-size: 20px; cursor: pointer; border-bottom: 1px solid var(--line);
}
.tree-controls button:last-child { border-bottom: none; }
.tree-controls button:hover { background: var(--paper-2); }
.tree-hint {
  position: absolute; left: 20px; bottom: 22px; z-index: 20;
  font-size: 12px; color: var(--ink-soft); background: rgba(255,253,248,.7);
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
}
.tree-loading, .tree-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; text-align: center; color: var(--ink-soft);
}
.tree-empty h2 { color: var(--ink); margin: 0; font-size: 26px; }
.spinner {
  width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================================
   Profile page
============================================================================ */
.profile-wrap { max-width: 860px; margin: 0 auto; padding: 28px 20px 80px; display: grid; gap: 20px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px;
}
.profile-hero { display: flex; gap: 26px; align-items: center; }
.profile-portrait {
  flex: 0 0 150px; width: 150px; height: 150px; border-radius: 20px; overflow: hidden;
  background: var(--paper-2); display: grid; place-items: center; box-shadow: var(--shadow);
}
.profile-portrait img { width: 100%; height: 100%; object-fit: cover; }
.portrait-initials { font-family: var(--serif); font-size: 52px; color: var(--ink-soft); }
.profile-head h1 { margin: 0 0 4px; font-size: 36px; }
.profile-span { margin: 0 0 14px; color: var(--accent); font-weight: 600; font-size: 16px; }
.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.facts li { font-size: 14.5px; color: var(--ink); }
.facts li span { display: inline-block; min-width: 74px; color: var(--ink-soft); font-weight: 600;
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.prose h2, .card h2 { margin: 0 0 12px; font-size: 21px; }
.prose p { margin: 0; line-height: 1.7; font-size: 15.5px; }
.relations { display: grid; gap: 20px; grid-template-columns: 1fr; }
.chips { display: flex; flex-wrap: wrap; gap: 12px; }
.chip {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 8px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 999px; color: var(--ink) !important;
  text-decoration: none !important; transition: .15s;
}
.chip:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.chip span:last-child { display: flex; flex-direction: column; }
.chip strong { font-family: var(--serif); font-weight: 600; font-size: 14.5px; }
.chip em { font-style: normal; font-size: 11.5px; color: var(--accent); }

.avatar { border-radius: 50%; overflow: hidden; background: var(--paper-2);
  display: inline-grid; place-items: center; font-family: var(--serif); color: var(--ink-soft); flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-xs { width: 34px; height: 34px; font-size: 13px; }
.avatar-sm { width: 44px; height: 44px; font-size: 16px; border-radius: 12px; }
.avatar-lg { width: 96px; height: 96px; font-size: 34px; border-radius: 18px; }

/* ============================================================================
   Login
============================================================================ */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 22px; box-shadow: var(--shadow-lg); padding: 36px 32px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-logo { font-size: 28px; margin: 0; text-align: center; }
.login-sub { margin: -6px 0 8px; text-align: center; color: var(--ink-soft); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.login-card input { font: 500 15px var(--sans); padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--paper); color: var(--ink); }
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(154,59,46,.12); }
.login-back { text-align: center; font-size: 13px; margin-top: 4px; }

/* ============================================================================
   Admin
============================================================================ */
.admin-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--ink); color: #f3ead9;
}
.admin-brand { color: #fff !important; font-family: var(--serif); font-weight: 700; font-size: 18px; text-decoration: none !important; }
.admin-brand span { color: var(--gold); font-weight: 600; }
.admin-nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.admin-nav a { color: #e9dcc4 !important; font-size: 14px; font-weight: 500; text-decoration: none !important; }
.admin-nav a:hover { color: #fff !important; }
.admin-who { color: var(--gold); font-size: 13px; }
.admin-logout { color: #fff !important; border: 1px solid rgba(255,255,255,.25); padding: 6px 12px; border-radius: 999px; }
.admin-main { max-width: 920px; margin: 0 auto; padding: 28px 20px 80px; }
.admin-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.admin-head h1 { margin: 0; font-size: 30px; }
.admin-head h2 { margin: 0; font-size: 22px; }
.admin-section { margin-top: 40px; }
.muted { color: var(--ink-soft); }
.small { font-size: 12.5px; }
.empty { color: var(--ink-soft); padding: 16px 0; }

.searchbar { display: flex; gap: 10px; margin-bottom: 20px; }
.searchbar input { flex: 1; font: 500 15px var(--sans); padding: 11px 16px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.searchbar input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(154,59,46,.12); }

.people-grid { display: grid; gap: 10px; }
.person-row, .union-row {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--ink) !important; text-decoration: none !important; transition: .15s;
}
.person-row:hover, .union-row:hover { box-shadow: var(--shadow); transform: translateY(-1px); border-color: #c9bda4; }
.person-row-body { display: flex; flex-direction: column; }
.person-row-body strong { font-family: var(--serif); font-weight: 600; font-size: 16px; }
.row-edit { margin-left: auto; color: var(--accent); font-weight: 600; font-size: 13px; }
.union-list { display: grid; gap: 10px; }
.union-row strong { font-family: var(--serif); font-weight: 600; font-size: 15.5px; }
.union-row .amp { color: var(--gold); }
.union-row .muted { margin-left: 4px; }

/* forms */
.form .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.form .span-2 { grid-column: 1 / -1; }
.form input, .form select, .form textarea {
  font: 500 15px var(--sans); padding: 11px 13px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--paper); color: var(--ink); width: 100%;
}
.form textarea { resize: vertical; font-family: var(--sans); }
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(154,59,46,.12); }
.form-photo { display: flex; gap: 20px; align-items: center; margin-bottom: 22px; }
.file-label { font-size: 13px; }
.file-label input { padding: 8px 0; border: none; background: none; }
.check { flex-direction: row !important; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); }
.check input { width: auto; }
.form-actions { display: flex; gap: 12px; margin-top: 24px; }
.children-pick { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px; margin-top: 22px; }
.children-pick legend { font-family: var(--serif); font-weight: 600; padding: 0 8px; font-size: 16px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px 18px; margin-top: 8px; max-height: 320px; overflow: auto; }
.danger-form { margin-top: 26px; padding-top: 22px; border-top: 1px dashed var(--line); }

.form-error { background: #fbe9e6; border: 1px solid #e6b7ae; color: #8a2c20;
  padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }
.form-ok { background: #e9f0e4; border: 1px solid #b9cdaa; color: #41552f;
  padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }

/* ---- admin: repeatable contact rows ---------------------------------------- */
.contacts-edit { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px; margin-top: 22px; }
.contacts-edit legend { font-family: var(--serif); font-weight: 600; padding: 0 8px; font-size: 16px; }
.contact-row { display: grid; grid-template-columns: 130px 160px 1fr auto; gap: 10px; align-items: start; margin-top: 10px; }
.contact-row textarea { min-height: 44px; }
.contact-remove { padding: 10px 12px; line-height: 1; }
#contact-add { margin-top: 14px; }

/* ---- profile: contact details ---------------------------------------------- */
.contact-card .contact-group + .contact-group { margin-top: 16px; }
.contact-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); margin: 0 0 6px; }
.contact-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.contact-list li { font-size: 14.5px; color: var(--ink); }
.contact-label { display: inline-block; min-width: 64px; vertical-align: top; color: var(--ink-soft); font-weight: 600; font-size: 12.5px; margin-right: 6px; }
.contact-address { display: inline-block; vertical-align: top; }

/* ============================================================================
   Responsive
============================================================================ */
@media (max-width: 720px) {
  .site-tagline { display: none; }
  #search { width: 150px; }
  .profile-hero { flex-direction: column; text-align: center; }
  .facts li span { display: block; }
  .form .grid-2 { grid-template-columns: 1fr; }
  .admin-head { flex-direction: column; align-items: flex-start; }
  .contact-row { grid-template-columns: 1fr 1fr; }
  .contact-row textarea { grid-column: 1 / -1; }
}

/* change request form */
.request-wrap { max-width: 680px; }
.request-wrap h1 { margin-top: 0; }
.request-lead { color: var(--ink-soft); margin: -4px 0 20px; }
.field-hint { font-weight: 400; font-size: 12px; color: var(--ink-soft); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
@media (max-width: 640px) { .request-wrap .grid-2 { grid-template-columns: 1fr; } }

/* admin: change requests */
.nav-count { display: inline-block; min-width: 20px; padding: 1px 6px; margin-left: 2px; border-radius: 999px;
  background: var(--gold); color: #fff; font-size: 12px; font-weight: 700; text-align: center; }
.req-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.req-tabs a { padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--card);
  color: var(--ink-soft); font-size: 14px; font-weight: 600; text-decoration: none; }
.req-tabs a span { color: var(--ink-soft); font-weight: 500; margin-left: 4px; }
.req-tabs a.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.req-tabs a.is-active span { color: #fff; }
.req-list { display: grid; gap: 14px; }
.req.is-done { opacity: .7; }
.req-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.req-meta { font-size: 13px; margin-top: 3px; }
.req-warn { color: var(--accent); font-weight: 600; }
.req-badge { padding: 3px 10px; border-radius: 999px; background: #e9f0e4; color: #41552f; font-size: 12px; font-weight: 700; }
.req-body { display: flex; gap: 18px; align-items: flex-start; margin: 14px 0; }
.req-details { flex: 1; margin: 0; white-space: normal; line-height: 1.55; }
.req-image { flex: 0 0 140px; }
.req-image img { width: 140px; max-height: 140px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.req-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.req-actions form { display: flex; gap: 10px; margin: 0; }
@media (max-width: 640px) { .req-body { flex-direction: column; } .req-image, .req-image img { width: 100%; max-height: none; } }
