:root {
  --bg: #f6f4ef;
  --surface: #fffdfa;
  --surface-2: #ebe7dd;
  --text: #26302c;
  --muted: #6d756f;
  --line: #d9d4c9;
  --accent: #47685a;
  --accent-2: #9b6f45;
  --danger: #a84a42;
  --shadow: 0 18px 40px rgba(40, 48, 44, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(18px, 4vw, 52px);
  background: rgba(255,253,250,.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.brand { color: var(--text); font-weight: 750; font-size: 1.16rem; }
.nav { display: flex; align-items: center; gap: 8px; }
.nav a {
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 620;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-toggle { display: none; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 8px 10px; }
.page { width: min(1180px, calc(100% - 32px)); margin: 34px auto 64px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.kicker { margin: 0 0 4px; color: var(--accent-2); text-transform: uppercase; letter-spacing: .08em; font-size: .76rem; font-weight: 750; }
h1, h2 { margin: 0; line-height: 1.15; letter-spacing: 0; }
h1 { font-size: clamp(2rem, 4vw, 3.4rem); }
h2 { font-size: 1.08rem; margin-bottom: 14px; }
.stats-grid, .grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card, .panel, .profile-card, .auth-box, .filter-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.stat-card { padding: 22px; }
.stat-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, #fffdfa 0%, #f8f4ec 100%);
}
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--accent);
  opacity: .72;
}
.stat-card span, .muted { color: var(--muted); }
.stat-card strong { display: block; margin-top: 8px; font-size: 2rem; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 18px; }
.panel { padding: 22px; overflow: hidden; }
.tag-list { display: flex; flex-wrap: wrap; gap: 10px; }
.tag-list span { padding: 8px 10px; border: 1px solid var(--line); border-radius: 999px; background: #faf8f3; }
.metric-list {
  display: grid;
  gap: 12px;
}
.metric-list div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.metric-list div:last-child { border-bottom: 0; }
.metric-list span { color: var(--muted); }
.metric-list strong { font-size: 1.25rem; }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 100px 1fr 36px; align-items: center; gap: 10px; }
.bar-row i { height: 10px; min-width: 4px; background: var(--accent); border-radius: 999px; }
.filter-panel, .inline-search {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto;
  gap: 10px;
  padding: 14px;
  margin-bottom: 18px;
}
.inline-search { display: flex; padding: 0; margin: 0; background: transparent; border: 0; box-shadow: none; }
input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
}
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
  resize: vertical;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 9px 14px;
  font-weight: 720;
  cursor: pointer;
}
.button:hover { text-decoration: none; filter: brightness(.96); }
.button.ghost { background: transparent; color: var(--accent); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; min-width: 820px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f2efe8; color: var(--muted); font-size: .84rem; }
.profile-card { display: flex; justify-content: space-between; gap: 24px; padding: 28px; margin-bottom: 18px; }
.life { color: var(--muted); margin: 8px 0 0; }
.life-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}
.life-facts div {
  min-width: 190px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
}
.life-facts span,
.life-facts small {
  display: block;
  color: var(--muted);
}
.life-facts strong {
  display: block;
  margin: 2px 0;
  font-size: 1.05rem;
}
.profile-meta { display: grid; gap: 10px; min-width: 220px; align-content: start; }
.link-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.timeline { padding: 0; margin: 0; list-style: none; display: grid; gap: 13px; }
.timeline li { display: grid; grid-template-columns: 64px 90px 1fr; gap: 10px; align-items: baseline; border-left: 2px solid var(--line); padding-left: 12px; }
.timeline small { color: var(--muted); }
.notes { white-space: normal; color: var(--muted); }
.map-panel { margin-top: 18px; }
.person-map {
  width: 100%;
  height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}
.map-credit {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: .84rem;
}
.map-head {
  align-items: center;
}
.map-summary {
  display: grid;
  min-width: 170px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.map-summary strong {
  font-size: 1.5rem;
}
.map-summary span {
  color: var(--muted);
}
.map-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: -6px 0 16px;
}
.map-filters .button.is-active {
  background: var(--accent);
  color: #fff;
}
.archive-map-panel {
  width: min(1500px, calc(100vw - 32px));
  margin-left: calc((100% - min(1500px, calc(100vw - 32px))) / 2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--surface);
}
.archive-map {
  width: 100%;
  height: min(760px, calc(100vh - 210px));
  min-height: 520px;
}
.dashboard-map-card {
  min-height: 330px;
  margin-top: 18px;
}
.dashboard-map-wide {
  width: 100%;
}
.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-title-row h2 { margin-bottom: 0; }
.dashboard-map {
  height: 238px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}
.dashboard-map-wide .dashboard-map {
  height: 340px;
}
.map-popup {
  display: grid;
  gap: 7px;
  min-width: 240px;
}
.map-popup strong {
  font-size: .98rem;
}
.map-popup small,
.map-popup-more {
  color: var(--muted);
}
.map-popup ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.map-popup li {
  display: grid;
  gap: 1px;
  padding-top: 6px;
  border-top: 1px solid #ece7dc;
}
.map-popup li span {
  color: var(--muted);
  font-size: .82rem;
}
.map-popup-more {
  margin: 0;
  font-size: .84rem;
}
.tree-board {
  overflow: auto;
  padding: 26px;
  background: linear-gradient(180deg, #fffdfa 0%, #f7f4ed 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.tree-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.tree-toolbar div { display: grid; gap: 3px; }
.tree-toolbar span { color: var(--muted); }
.tree-generation {
  position: relative;
  min-width: 760px;
  margin: 0 auto;
}
.tree-generation-label {
  margin: 0 auto 10px;
  width: max-content;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,253,250,.92);
  color: var(--accent-2);
  font-size: .78rem;
  font-weight: 760;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.tree-row {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), minmax(128px, 1fr));
  gap: 14px;
  align-items: stretch;
}
.columns-1 { --cols: 1; }
.columns-2 { --cols: 2; }
.columns-3 { --cols: 3; }
.columns-4 { --cols: 4; }
.columns-5 { --cols: 5; }
.columns-6 { --cols: 6; }
.columns-7 { --cols: 7; }
.columns-8 { --cols: 8; }
.tree-card {
  position: relative;
  display: grid;
  align-content: center;
  gap: 4px;
  min-height: 78px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,253,250,.96);
  color: var(--text);
  text-align: center;
  box-shadow: 0 8px 18px rgba(40,48,44,.055);
}
.tree-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  border-radius: 8px 0 0 8px;
  background: transparent;
}
.tree-card.is-paternal::before { background: #6f8f99; }
.tree-card.is-maternal::before { background: #b58a75; }
.tree-card:hover {
  border-color: var(--accent);
  text-decoration: none;
  transform: translateY(-1px);
}
.tree-card span {
  font-weight: 760;
  overflow-wrap: anywhere;
}
.tree-card small {
  color: var(--muted);
  font-size: .82rem;
}
.tree-card.is-focus {
  min-width: 250px;
  min-height: 92px;
  border: 2px solid var(--accent);
  background: #f3f7f2;
  font-size: 1.05rem;
}
.tree-card.is-spouse {
  min-width: 210px;
  background: #fbf7ee;
}
.tree-card.is-child { background: #fffaf1; }
.tree-connector {
  width: 1px;
  height: 28px;
  margin: 10px auto;
  background: var(--line);
}
.tree-connector::before,
.tree-connector::after {
  content: "";
  display: block;
  width: min(520px, 58vw);
  height: 1px;
  background: var(--line);
  transform: translateX(calc(-50% + .5px));
}
.tree-connector::before { margin-top: 0; }
.tree-connector::after { margin-top: 28px; }
.tree-connector.down::before { display: none; }
.focus-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.focus-row.has-spouses::before {
  content: "";
  width: 34px;
  height: 1px;
  order: 1;
  background: var(--line);
}
.focus-row .tree-card.is-focus { order: 0; }
.spouse-wrap {
  order: 2;
  display: grid;
  gap: 7px;
  justify-items: center;
}
.spouse-wrap > span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 720;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.tree-generation.is-collapsed { display: none; }
.alert { padding: 13px 15px; border-radius: 8px; margin-bottom: 16px; border: 1px solid var(--line); }
.alert.success { background: #eef6ef; color: #285337; }
.alert.error { background: #fff0ee; color: var(--danger); }
.auth-box { width: min(440px, 100%); margin: 80px auto; padding: 28px; }
.auth-box form, .import-form { display: grid; gap: 14px; }
.edit-form { display: grid; gap: 18px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.span-2 { grid-column: span 2; }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; min-height: auto; }
.empty { padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.lineage ol { margin: 0; padding-left: 22px; }
.lineage li { margin: 9px 0; }
.quality-overview { margin-bottom: 18px; }
.quality-panel { margin-top: 18px; }
.quality-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.quality-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.quality-list li:last-child { border-bottom: 0; }
.quality-list span { color: var(--muted); }

@media (max-width: 900px) {
  .stats-grid, .grid-4, .two-col { grid-template-columns: 1fr 1fr; }
  .filter-panel { grid-template-columns: 1fr 1fr; }
  .page-head, .profile-card { align-items: stretch; flex-direction: column; }
}

@media (max-width: 680px) {
  .site-header { align-items: flex-start; }
  .nav-toggle { display: inline-block; }
  .nav { display: none; position: absolute; top: 62px; left: 16px; right: 16px; flex-direction: column; align-items: stretch; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px; box-shadow: var(--shadow); }
  .nav.is-open { display: flex; }
  .stats-grid, .grid-4, .two-col, .filter-panel { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .table-wrap {
    overflow: visible;
    background: transparent;
    border: 0;
    box-shadow: none;
  }
  table, tbody, tr, td { display: block; width: 100%; min-width: 0; }
  thead { display: none; }
  tr {
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }
  td {
    display: grid;
    grid-template-columns: 112px 1fr;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
  }
  td:last-child { border-bottom: 0; }
  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 720;
  }
  .quality-list li {
    display: grid;
    gap: 3px;
  }
  .inline-search { flex-direction: column; width: 100%; }
  .archive-map-panel { width: 100%; margin-left: 0; }
  .archive-map { min-height: 420px; height: 62vh; }
  .dashboard-map-wide .dashboard-map { height: 300px; }
  .tree-board { padding: 16px; }
  .tree-toolbar { align-items: stretch; flex-direction: column; }
  .tree-generation { min-width: 0; }
  .tree-row { grid-template-columns: 1fr; }
  .focus-row { display: grid; justify-items: stretch; }
  .focus-row.has-spouses::before { display: none; }
  .tree-card.is-focus, .tree-card.is-spouse { min-width: 0; }
  .tree-connector::before,
  .tree-connector::after { width: 1px; transform: none; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  .person-map { height: 300px; }
}

@media print {
  @page { size: A4 landscape; margin: 12mm; }
  .site-header, .no-print, .button, .nav-toggle { display: none !important; }
  body { background: #fff; font-size: 11px; }
  .page { width: 100%; margin: 0; }
  .panel, .profile-card, .table-wrap, .tree-board { box-shadow: none; border-color: #aaa; break-inside: avoid; }
  .map-panel { display: none; }
  .page-head { margin-bottom: 12px; }
  .page-head h1 { font-size: 26px; }
  .tree-board { overflow: visible; padding: 12px; background: #fff; }
  .tree-toolbar { margin-bottom: 12px; padding-bottom: 8px; }
  .tree-generation { min-width: 0; break-inside: avoid; }
  .tree-row { gap: 7px; }
  .tree-card { min-height: 48px; padding: 7px 8px; box-shadow: none; }
  .tree-card.is-focus { min-height: 58px; min-width: 180px; }
  .tree-card.is-spouse { min-width: 160px; }
  .tree-generation-label { font-size: 9px; padding: 3px 7px; margin-bottom: 6px; }
  .tree-connector { height: 16px; margin: 5px auto; }
  .tree-connector::after { margin-top: 16px; }
  a { color: #000; }
}
