﻿* {
  box-sizing: border-box;
}

:root {
  --bg: #d7d8c8;
  --panel: #eceee3;
  --line: #80857a;
  --male: #c8deef;
  --male-border: #7aa4c3;
  --female: #e8c5da;
  --female-border: #c883ad;
  --unknown: #e2e2e2;
  --unknown-border: #b9b9b9;
  --text: #222831;
}

body {
  margin: 0;
  font-family: Tahoma, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 0%, #e6e8da 0%, var(--bg) 62%);
  padding-top: 104px;
}

.topbar {
  padding: 14px 18px;
  border-bottom: 1px solid #bfc3b5;
  background: #f2f4ea;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 1000;
}

h1 {
  margin: 0 0 10px;
  font-size: 21px;
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  align-items: center;
  overflow-x: auto;
}

.top-link {
  color: #2b3a66;
  text-decoration: none;
  border: 1px solid #9ca594;
  border-radius: 6px;
  padding: 8px 10px;
  background: #fefefb;
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
}

.authbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
  margin-left: auto;
}

.lang-switch {
  margin-left: 8px;
  white-space: nowrap;
  font-size: 13px;
  color: #3f4b3c;
}

.lang-switch a {
  color: #2b3a66;
  text-decoration: none;
  padding: 2px 3px;
  border-radius: 4px;
}

.lang-switch a:hover {
  text-decoration: underline;
}

.lang-switch a.active {
  font-weight: 700;
  color: #1b2f1a;
  background: #dfe9d5;
}

.authbar input {
  min-width: 130px;
}

#authStatus {
  font-weight: 600;
  margin-right: 4px;
}

input,
button {
  border: 1px solid #9ca594;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  background: #fefefb;
}

button {
  cursor: pointer;
  background: #4c6a46;
  color: #fff;
}

button:hover {
  background: #40583b;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 39%) 8px minmax(320px, 1fr);
  gap: 0;
  padding: 10px;
}

.layout.schema-only {
  grid-template-columns: 1fr;
  gap: 0;
}

.layout.schema-only .full {
  width: 100%;
}

.layout.people-only {
  grid-template-columns: 1fr;
  gap: 0;
}

.layout.people-only .full {
  width: 100%;
}

.layout .left {
  margin-right: 6px;
}

.layout .right {
  margin-left: 6px;
}

.panel {
  background: var(--panel);
  border: 1px solid #bfc3b5;
  border-radius: 8px;
  padding: 10px;
  min-height: 72vh;
}

.layout-splitter {
  width: 8px;
  min-height: 72vh;
  background: linear-gradient(180deg, #b9bfaf 0%, #aeb5a5 50%, #b9bfaf 100%);
  border: 1px solid #a2aa98;
  border-radius: 5px;
  cursor: col-resize;
}

.layout-splitter:hover {
  background: linear-gradient(180deg, #aab29f 0%, #9ea794 50%, #aab29f 100%);
}

.panel h2 {
  margin: 4px 0 8px;
  font-size: 17px;
}

.hint,
.meta {
  font-size: 13px;
  color: #4f574c;
}

.table-filters {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.table-filters input {
  min-width: 105px;
  padding: 6px 8px;
  font-size: 12px;
}

.table-filters button {
  padding: 6px 10px;
  font-size: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

th,
td {
  border-bottom: 1px solid #cfd3c6;
  text-align: left;
  padding: 6px;
  font-size: 12px;
}

th[data-sort] {
  cursor: pointer;
  user-select: none;
}

th[data-sort].sort-active::after {
  content: " ▲";
  color: #2f4630;
  font-size: 11px;
}

th[data-sort].sort-active.sort-desc::after {
  content: " ▼";
}

tr:hover {
  background: #f4f7ec;
  cursor: pointer;
}

tr.kinship-picked-row {
  background: #d6e1cf !important;
}

.pager {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.tree {
  margin-top: 10px;
  overflow: auto;
  border: 1px solid #bfc3b5;
  border-radius: 6px;
  background: #d3d6c5;
  min-height: 500px;
  cursor: grab;
  touch-action: auto;
  -webkit-overflow-scrolling: touch;
}

.tree.dragging {
  cursor: grabbing;
}

.pedigree {
  cursor: default;
}

.pedigree-canvas {
  position: relative;
  min-width: max-content;
  min-height: 320px;
}

.pedigree-lines {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.pedigree-lines path {
  fill: none;
  stroke: #6d7467;
  stroke-width: 1.4;
}

.ped-node {
  position: absolute;
  z-index: 1;
}

.pedigree .person-card {
  box-shadow: inset 0 0 0 1px #d4ddd1;
}

.pedigree .person-card.ped-empty {
  background: #efefef;
  border: 2px solid #222;
  box-shadow: none;
  min-height: 72px;
}

.tree-canvas {
  position: relative;
  min-width: max-content;
  padding: 12px 16px 30px;
}

.generation-overlay {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 0;
}

.generation-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed #98a393;
  opacity: 0.75;
}

.generation-label {
  position: absolute;
  font-size: 11px;
  color: #4d5a4d;
  background: rgba(235, 239, 227, 0.92);
  border: 1px solid #bac4b5;
  border-radius: 4px;
  padding: 1px 5px;
  white-space: nowrap;
  transform: translateY(-50%);
}

.generation-label.left {
  left: 2px;
}

.generation-label.right {
  right: 2px;
}

.graph-wrap {
  position: relative;
}

.graph-lines {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
}

.graph-line.blood {
  stroke: #4f5c4c;
  stroke-width: 1;
  stroke-linecap: round;
}

.graph-line.spouse {
  stroke: #61686b;
  stroke-width: 1;
  stroke-linecap: round;
  stroke-dasharray: 0;
}

.graph-node {
  position: absolute;
  z-index: 2;
}

.tree-root,
.tree-root ul {
  padding-top: 18px;
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  gap: 12px;
}

.tree-root {
  margin: 0;
  padding-left: 0;
}

.tree-root li {
  list-style-type: none;
  position: relative;
  padding: 18px 4px 0;
  text-align: center;
}

.tree-root li::before,
.tree-root li::after {
  content: "";
  position: absolute;
  top: 0;
  right: 50%;
  width: 50%;
  height: 17px;
  border-top: 1px solid var(--line);
}

.tree-root li::after {
  right: auto;
  left: 50%;
  border-left: 1px solid var(--line);
}

.tree-root li:only-child::before,
.tree-root li:only-child::after {
  display: none;
}

.tree-root li:only-child {
  padding-top: 0;
}

.tree-root li:first-child::before,
.tree-root li:last-child::after {
  border: 0;
}

.tree-root li:last-child::before {
  border-right: 1px solid var(--line);
  border-radius: 0 6px 0 0;
}

.tree-root li:first-child::after {
  border-radius: 6px 0 0 0;
}

.tree-root ul::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 0;
  height: 18px;
  border-left: 1px solid var(--line);
}

.couple-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: stretch;
}

.person-card {
  position: relative;
  width: 185px;
  min-height: 74px;
  border: 2px solid #91a29b;
  background: #f1f4eb;
  box-shadow: inset 0 0 0 1px #d4ddd1;
}

.person-card.kinship-picked {
  filter: brightness(0.78);
  box-shadow: inset 0 0 0 2px #2a3f29, 0 0 0 1px #2a3f29;
}

.kinship-modal[hidden] {
  display: none !important;
}

.person-card.male {
  background: var(--male);
  border-color: var(--male-border);
}

.person-card.female {
  background: var(--female);
  border-color: var(--female-border);
}

.person-card.unknown {
  background: var(--unknown);
  border-color: var(--unknown-border);
}

.person-card.spouse {
  box-shadow: inset 0 0 0 1px #c8c8c8;
}

.blood-badge {
  position: absolute;
  top: 1px;
  right: 4px;
  font-size: 14px;
  line-height: 1;
  color: #1f9d3a;
}

.relation-plus {
  position: absolute;
  top: auto;
  bottom: 2px;
  left: 2px;
  z-index: 20;
  width: 16px;
  height: 16px;
  line-height: 14px;
  text-align: center;
  border: 1px solid #3f5568;
  background: #ffffffdd;
  color: #1f2937;
  border-radius: 50%;
  cursor: pointer;
  font-weight: 700;
  padding: 0;
}

.relation-edit {
  position: absolute;
  top: auto;
  bottom: 2px;
  left: 22px;
  z-index: 20;
  width: 16px;
  height: 16px;
  line-height: 14px;
  text-align: center;
  border: 1px solid #3f5568;
  background: #ffffffdd;
  color: #1f2937;
  border-radius: 50%;
  cursor: pointer;
  font-weight: 700;
  padding: 0;
}

.ancestor-plus {
  position: absolute;
  right: 4px;
  bottom: 2px;
  z-index: 20;
  font-size: 14px;
  line-height: 1;
  color: #49525c;
  font-weight: 700;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.menu {
  position: fixed;
  z-index: 1000;
  background: #fff;
  border: 1px solid #b8c3d7;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  padding: 6px;
  display: grid;
  gap: 4px;
}

.menu[hidden] {
  display: none !important;
}

.menu button {
  background: #f4f7fb;
  color: #1f2937;
  border: 1px solid #ccd6e5;
  text-align: left;
}

.menu button:hover {
  background: #e8f0ff;
}

.kinship-modal {
  position: fixed;
  right: 14px;
  top: 82px;
  z-index: 1200;
}

.kinship-box {
  width: 360px;
  max-width: calc(100vw - 20px);
  min-width: 280px;
  min-height: 180px;
  max-height: calc(100vh - 120px);
  background: #f9fbf5;
  border: 1px solid #b9c2b1;
  border-radius: 10px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18);
  padding: 10px;
  position: relative;
  overflow: auto;
}

.kinship-resizer {
  position: absolute;
  z-index: 5;
}

.kinship-resizer.n,
.kinship-resizer.s {
  left: 10px;
  right: 10px;
  height: 8px;
  cursor: ns-resize;
}

.kinship-resizer.n { top: -4px; }
.kinship-resizer.s { bottom: -4px; }

.kinship-resizer.w,
.kinship-resizer.e {
  top: 10px;
  bottom: 10px;
  width: 8px;
  cursor: ew-resize;
}

.kinship-resizer.w { left: -4px; }
.kinship-resizer.e { right: -4px; }

.kinship-resizer.nw,
.kinship-resizer.ne,
.kinship-resizer.sw,
.kinship-resizer.se {
  width: 12px;
  height: 12px;
}

.kinship-resizer.nw { left: -5px; top: -5px; cursor: nwse-resize; }
.kinship-resizer.se { right: -5px; bottom: -5px; cursor: nwse-resize; }
.kinship-resizer.ne { right: -5px; top: -5px; cursor: nesw-resize; }
.kinship-resizer.sw { left: -5px; bottom: -5px; cursor: nesw-resize; }

.kinship-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 8px;
}

.kinship-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 13px;
}

.kinship-result {
  margin-top: 8px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid #d2dacb;
  background: #fff;
  border-radius: 6px;
  padding: 8px;
  font-size: 13px;
  line-height: 1.35;
}

.kinship-chain {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 8px;
  border-bottom: 1px dashed #d5ddd0;
}

.kinship-node {
  min-width: 160px;
  max-width: 220px;
  border: 1px solid #b9c7b2;
  background: #edf3e7;
  border-radius: 6px;
  padding: 6px 8px;
}

.kn-name {
  font-weight: 600;
  color: #243428;
  line-height: 1.2;
  white-space: normal;
  word-break: break-word;
}

.kn-code {
  font-size: 12px;
  color: #4f5e52;
}

.kn-dates {
  margin-top: 2px;
  font-size: 11px;
  color: #5a625d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kinship-link {
  flex: 0 0 auto;
  color: #5f6e62;
  font-size: 16px;
  line-height: 1;
}

.kinship-list {
  display: grid;
  gap: 2px;
}

.person-main {
  display: flex;
  gap: 6px;
  padding: 5px 5px 18px 5px;
}

.avatar {
  width: 46px;
  min-width: 46px;
  height: 58px;
  border: 1px solid #a9b1aa;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 60% 28%, #acb0b4 0 16px, transparent 17px),
    radial-gradient(ellipse at 50% 100%, #b9bec2 0 24px, transparent 25px),
    #d9dee1;
}

.avatar.deceased::after {
  content: "";
  position: absolute;
  width: 46px;
  height: 4px;
  left: -16px;
  bottom: 10px;
  background: #111;
  transform: rotate(56deg);
  opacity: 0.95;
}

.person-text {
  text-align: left;
  width: 100%;
  position: relative;
  padding-bottom: 12px;
}

.person-surname,
.person-given,
.person-patronymic {
  font-size: 13px;
  line-height: 1.08;
  max-height: 14px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.person-dates,
.person-code {
  font-size: 11px;
  color: #2f3a43;
}

.person-dates {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  font-size: 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.person-code {
  position: absolute;
  right: 34px;
  bottom: 2px;
  white-space: nowrap;
}

.empty-spouse {
  width: 185px;
  min-height: 74px;
  border: 2px dashed #a2a89a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #5a6457;
  background: #edf0e4;
}

@media (max-width: 1200px) {
  .controls {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .authbar {
    margin-left: 0;
    flex-wrap: wrap;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .layout .left,
  .layout .right {
    margin-left: 0;
    margin-right: 0;
  }

  .layout-splitter {
    display: none;
    min-height: 0;
  }

  .panel {
    min-height: auto;
  }

  .tree {
    min-height: 172vh;
    max-height: 172vh;
  }
}

@media (max-width: 768px) {
  body {
    padding-top: 92px;
  }

  .layout {
    padding: 6px;
  }

  .tree {
    min-height: 168vh;
    max-height: 168vh;
  }

  .pedigree-canvas {
    min-height: 240px;
  }
}
