/* Stammbaum – Gestaltung
   Tinte auf kühlem Papier: Indigo für Verbindungen und Auswahl, Ocker für die Startperson. */

:root {
  --bg: #ECEEF1;
  --surface: #F9FAFB;
  --raised: #FFFFFF;
  --ink: #1A2131;
  --muted: #5D6677;
  --faint: #8B93A3;
  --line: #A9B1C0;
  --rule: #D7DBE2;
  --accent: #34479C;
  --accent-ink: #FFFFFF;
  --accent-soft: #DFE4F4;
  --ochre: #A86F12;
  --danger: #A2382A;
  --dead: #E4E6EA;
  --shadow: 0 1px 2px rgba(26, 33, 49, .08), 0 4px 14px rgba(26, 33, 49, .06);
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r-card: 10px;
  --r-ctl: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141B;
    --surface: #181C25;
    --raised: #1E2330;
    --ink: #E5E8EF;
    --muted: #A0A8B8;
    --faint: #727B8D;
    --line: #4A5366;
    --rule: #2B3140;
    --accent: #95A5F2;
    --accent-ink: #11141B;
    --accent-soft: #252C47;
    --ochre: #DDA64A;
    --danger: #EE8A7A;
    --dead: #1A1E26;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Grundaufbau ---------- */

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  padding-top: env(safe-area-inset-top, 0px);
}

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  position: relative;
  z-index: 20;
}
.tree-title {
  background: none;
  border: 0;
  padding: 4px 6px;
  font: 600 19px/1.2 var(--serif);
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 34vw;
  border-radius: var(--r-ctl);
}
.tree-title:hover { color: var(--accent); }

.search { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search-icon { position: absolute; left: 11px; top: 50%; width: 17px; height: 17px; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
}
.search input:focus { outline: none; border-color: var(--accent); }
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 60vh;
  overflow: auto;
}
.search-results li { border-radius: 8px; }
.search-results button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  background: none;
  border: 0;
  text-align: left;
  border-radius: 8px;
}
.search-results li[aria-selected="true"] button,
.search-results button:hover { background: var(--accent-soft); }
.search-results .sr-empty { padding: 10px; color: var(--muted); }

.view-switch {
  display: flex;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 999px;
}
.view-switch button {
  border: 0;
  background: none;
  padding: 5px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
}
.view-switch button[aria-selected="true"] { background: var(--ink); color: var(--bg); }

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  flex: none;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { border-color: var(--line); }

.stage { position: relative; overflow: hidden; min-height: 0; }

/* ---------- Baum ---------- */

.tree-view, .tree-vp { position: absolute; inset: 0; }
.tree-vp {
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  background-image: radial-gradient(circle, var(--rule) 1px, transparent 1.2px);
  background-size: 26px 26px;
}
.tree-vp.is-dragging { cursor: grabbing; }
.tree-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.tree-world.is-moving { transition: transform .36s cubic-bezier(.2, .7, .2, 1); }
.tree-lines { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.tree-lines path { fill: none; stroke: var(--line); stroke-width: 1.6; }
.tree-lines path.couple { stroke: var(--accent); stroke-width: 2; }
.tree-lines path.ghost-line { stroke-dasharray: 3 5; }

.card {
  position: absolute;
  width: 172px;
  height: 66px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 8px;
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  text-align: left;
  transition: border-color .15s;
}
.card:hover { border-color: var(--line); }
.card.is-focus {
  border: 2px solid var(--accent);
  padding: 7px 9px 7px 7px;
  box-shadow: 0 0 0 5px var(--accent-soft), var(--shadow);
}
.card.is-dead { background: var(--dead); box-shadow: none; }
.card.is-dead .avatar { filter: grayscale(1); opacity: .85; }
.card.is-sibling { opacity: .92; }

.avatar {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent-soft);
}
.avatar-initials {
  display: grid;
  place-items: center;
  font: 600 15px/1 var(--serif);
  color: var(--accent);
}
.card-text { display: grid; min-width: 0; line-height: 1.2; }
.card-first, .card-last { font-family: var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-first { font-size: 15px; font-weight: 600; }
.card-last { font-size: 14px; color: var(--muted); }
.card-years { font-size: 12px; color: var(--faint); margin-top: 2px; font-variant-numeric: tabular-nums; }
.home-mark { color: var(--ochre); margin-left: 5px; font-family: var(--sans); font-weight: 600; }
.more {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 14px;
  display: grid;
  place-items: center;
  font-size: 11px;
  line-height: 1;
  color: var(--muted);
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 999px;
}
.more-up { top: -8px; }
.more-down { bottom: -8px; }

.card.ghost {
  background: transparent;
  border: 1.5px dashed var(--line);
  box-shadow: none;
  color: var(--muted);
  justify-content: center;
  gap: 8px;
  font-weight: 500;
  font-size: 14px;
}
.card.ghost:hover { border-color: var(--accent); color: var(--accent); }
.ghost-plus { font-size: 20px; line-height: 1; }

.zoom {
  position: absolute;
  left: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}
.zoom .icon-btn { background: var(--raised); box-shadow: var(--shadow); }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 24px;
  gap: 14px;
}
.empty h2 { margin: 0; font: 600 26px/1.2 var(--serif); }
.empty p { margin: 0 auto; color: var(--muted); max-width: 34ch; }

/* ---------- Buttons & Formulare ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { border-color: var(--line); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-danger { color: var(--danger); }
.btn-primary.btn-danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small { min-height: 30px; padding: 0 12px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 500; }

.fab {
  position: absolute;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 15;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 48px;
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(52, 71, 156, .35);
}
.fab svg { width: 20px; height: 20px; stroke-width: 2.2; }

.field { display: grid; gap: 4px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--rule);
  border-radius: var(--r-ctl);
  background: var(--raised);
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field small { color: var(--faint); font-size: 12px; }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.stack { display: grid; gap: 14px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: inline-block;
  padding: 6px 13px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-size: 14px;
  background: var(--raised);
}
.seg input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.check { display: flex; align-items: center; gap: 9px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.form-error { color: var(--danger); font-size: 14px; margin: 0; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }

/* ---------- Dialog ---------- */

.dlg {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px);
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.dlg::backdrop { background: rgba(17, 20, 27, .45); }
.dlg form { display: flex; flex-direction: column; max-height: calc(100dvh - 42px); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 10px; }
.dlg-head h2 { margin: 0; flex: 1; font: 600 21px/1.25 var(--serif); }
.dlg-body { padding: 6px 18px 18px; overflow: auto; }
.dlg-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--rule);
}
.dlg-close { width: 34px; height: 34px; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--rule); }
.tabs button {
  border: 0;
  background: none;
  padding: 8px 4px;
  margin-right: 14px;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

.pick-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; max-height: 46vh; overflow: auto; }
.pick-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
}
.pick-list input { position: absolute; opacity: 0; }
.pick-list input:checked + .pick-row { }
.pick-list label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.pick-list label:hover { background: var(--accent-soft); }

.mini-avatar {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  font: 600 12px/1 var(--serif);
  color: var(--accent);
}
.row-text { display: grid; line-height: 1.25; min-width: 0; }
.row-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); }

/* ---------- Personen-Panel ---------- */

.panel {
  position: fixed;
  z-index: 30;
  top: calc(59px + env(safe-area-inset-top, 0px));
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 100vw;
  overflow: auto;
  background: var(--surface);
  border-left: 1px solid var(--rule);
  box-shadow: -8px 0 30px rgba(0, 0, 0, .08);
  padding: 0 0 calc(30px + env(safe-area-inset-bottom, 0px));
  overscroll-behavior: contain;
}
.panel-grip { display: none; }
.panel-head { position: relative; padding: 22px 22px 16px; display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.panel-close { position: absolute; top: 12px; right: 12px; }
.panel-photo { position: relative; width: 88px; height: 88px; }
.panel-photo .avatar { width: 88px; height: 88px; font-size: 28px; }
.photo-btn {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--ink);
  color: var(--bg);
  display: grid;
  place-items: center;
}
.photo-btn svg { width: 15px; height: 15px; }
.panel h2 { margin: 0; font: 600 24px/1.15 var(--serif); letter-spacing: -.01em; padding-right: 30px; }
.panel .born-as { color: var(--muted); font-family: var(--serif); font-size: 15px; }
.kin-line { margin-top: 6px; font-size: 14px; color: var(--ochre); font-weight: 500; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 22px 18px; }
.facts { margin: 0; padding: 4px 22px 14px; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; }
.facts .age { color: var(--muted); }

.rel-section { padding: 14px 22px 6px; border-top: 1px solid var(--rule); }
.rel-section header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.rel-section h3 { margin: 0; font: 600 16px/1.3 var(--serif); }
.rel-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rel-item { display: flex; align-items: center; gap: 4px; }
.rel-item > button.rel-go {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  margin-left: -8px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
}
.rel-item > button.rel-go:hover { background: var(--accent-soft); }
.rel-item .icon-btn { width: 32px; height: 32px; border-color: transparent; background: none; color: var(--faint); }
.rel-item .icon-btn:hover { color: var(--ink); border-color: var(--rule); }
.rel-empty { color: var(--faint); font-size: 14px; padding: 2px 0 8px; }
.add-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.notes { padding: 14px 22px; border-top: 1px solid var(--rule); white-space: pre-wrap; }
.notes h3 { margin: 0 0 6px; font: 600 16px/1.3 var(--serif); }
.meta { padding: 10px 22px 0; color: var(--faint); font-size: 12px; }

/* ---------- Liste ---------- */

.list-view { position: absolute; inset: 0; overflow: auto; padding: 18px 16px calc(90px + env(safe-area-inset-bottom, 0px)); }
.list-inner { max-width: 760px; margin: 0 auto; }
.list-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 10px; }
.list-tools .field { flex: 1; min-width: 160px; }
.list-count { color: var(--muted); font-size: 14px; margin: 6px 0 14px; }
.letter { position: sticky; top: -18px; z-index: 1; margin: 18px 0 4px; padding: 6px 0; background: var(--bg); font: 600 22px/1 var(--serif); color: var(--accent); }
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--rule); }
.list button {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 6px;
  border: 0;
  background: none;
  text-align: left;
  border-radius: 10px;
}
.list button:hover { background: var(--surface); }
.list .years { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }

/* ---------- Anmeldung ---------- */

.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); }
.auth-mark { width: 56px; height: 56px; color: var(--accent); margin-bottom: 14px; }
.auth-mark svg { width: 56px; height: 56px; stroke-width: 1.5; }
.auth h1 { margin: 0 0 6px; font: 600 32px/1.15 var(--serif); letter-spacing: -.015em; }
.auth p.lead { margin: 0 0 22px; color: var(--muted); }
.auth form { display: grid; gap: 14px; }
.auth .btn-primary { min-height: 44px; margin-top: 4px; }

/* ---------- Menü & Sonstiges ---------- */

.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list li + li { border-top: 1px solid var(--rule); }
.menu-list button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 2px;
  border: 0;
  background: none;
  text-align: left;
  font-weight: 500;
}
.menu-list button small { color: var(--muted); font-weight: 400; }
.menu-group { margin: 18px 0 4px; font: 600 15px/1.3 var(--serif); color: var(--muted); }
.menu-group:first-child { margin-top: 0; }
.depth-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper output { min-width: 22px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

.bday-list { list-style: none; margin: 0; padding: 0; }
.bday-list li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--rule); }
.bday-list li:first-child { border-top: 0; }
.bday-when { color: var(--muted); text-align: right; white-space: nowrap; }

.user-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 10px 0; border-top: 1px solid var(--rule); }
.user-row:first-child { border-top: 0; }
.user-row .actions { display: flex; gap: 6px; align-items: center; }
.user-row select { min-height: 32px; padding: 3px 8px; border-radius: 8px; border: 1px solid var(--rule); background: var(--raised); }

.result-box { margin-top: 12px; padding: 14px; border-radius: 12px; background: var(--accent-soft); font-family: var(--serif); font-size: 18px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 100;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 500;
  box-shadow: var(--shadow);
}
.toast.is-error { background: var(--danger); color: #fff; }

.share-row { display: grid; gap: 8px; padding: 12px 0; border-top: 1px solid var(--rule); }
.share-row:first-child { border-top: 0; padding-top: 0; }
.share-row .actions { display: flex; gap: 6px; }
.share-url {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--r-ctl);
  background: var(--raised);
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Mobil ---------- */

@media (max-width: 720px) {
  .bar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .tree-title { max-width: none; flex: 1; font-size: 18px; text-align: left; }
  .search { order: 5; flex-basis: 100%; max-width: none; }
  .view-switch button { padding: 5px 11px; }

  .panel {
    top: auto;
    left: 0;
    width: 100%;
    height: 56dvh;
    border-left: 0;
    border-top: 1px solid var(--rule);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .14);
  }
  .panel-grip { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--rule); margin: 8px auto 0; }
  .panel-head { padding-top: 12px; }
  .panel.is-full { height: calc(100dvh - 20px - env(safe-area-inset-top, 0px)); }

  .dlg { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; border-bottom: 0; max-height: 92dvh; }
  .dlg form { max-height: 92dvh; }
  .grid2 { grid-template-columns: 1fr; }
  .fab span { display: none; }
  .fab { padding: 0; width: 52px; height: 52px; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
