:root {
  color-scheme: light dark;
  --bg: #f6f2eb;
  --card: #fffdf9;
  --text: #1a1410;
  --muted: #6b6056;
  --accent: #2d6b4f;
  --border: #dfd6c9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --card: #1c1814;
    --text: #f0eae2;
    --muted: #a89b8c;
    --accent: #6dc99a;
    --border: #3a342c;
  }
}

* {
  box-sizing: border-box;
}

body.shell {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, var(--card), var(--bg));
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--accent);
  text-decoration: none;
}

.nav {
  display: flex;
  gap: 1rem;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
}

.nav a:hover {
  color: var(--accent);
}

.wrap {
  max-width: 56rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.foot {
  text-align: center;
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.hero h1 {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.tiny {
  font-size: 0.75rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.search {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.search input {
  flex: 1;
  min-width: 12rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.search button {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list li {
  padding: 0.35rem 0;
  border-bottom: 1px dashed var(--border);
}

.list li:last-child {
  border-bottom: none;
}

.list.cols {
  columns: 2;
  gap: 1rem;
}

@media (max-width: 40rem) {
  .list.cols {
    columns: 1;
  }
}

.accent {
  color: var(--accent);
}

a.accent:hover {
  text-decoration: underline;
}

.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1rem;
}

@media (max-width: 40rem) {
  .pair {
    grid-template-columns: 1fr;
  }
}

.person-head {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 1.5rem;
}

@media (max-width: 40rem) {
  .person-head {
    grid-template-columns: 1fr;
    text-align: center;
  }
}

.person-photo img {
  width: 100%;
  max-height: 14rem;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.photo-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.btn-photo-upload {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.btn-photo-upload:hover {
  background: var(--border);
}

.btn-photo-delete {
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid #e88;
  background: transparent;
  color: #c44;
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-photo-delete:hover {
  background: #fee;
}

.ph-empty {
  display: grid;
  place-items: center;
  aspect-ratio: 3/4;
  border-radius: 10px;
  border: 1px dashed var(--border);
  font-size: 0.85rem;
}

.tag {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  background: var(--border);
}

.person-website-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.88rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.person-website-link:hover {
  text-decoration: underline;
}

.kv {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 0.35rem 0.75rem;
  margin: 1rem 0;
}

@media (max-width: 40rem) {
  .kv {
    grid-template-columns: 1fr;
  }

  .kv dt {
    color: var(--muted);
    font-size: 0.8rem;
  }
}

.kv dt {
  font-weight: 600;
}

.kv dd {
  min-height: 1.4em;
}

.relbox {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.gallery {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.75rem;
  scroll-behavior: smooth;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.gallery::-webkit-scrollbar {
  height: 6px;
}

.gallery::-webkit-scrollbar-track {
  background: transparent;
}

.gallery::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.gallery::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.gallery img {
  flex: 0 0 96px;
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.note,
.raw {
  white-space: pre-wrap;
  font-size: 0.82rem;
  overflow-x: auto;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.rel-title {
  margin: 0 0 0.75rem;
}

.rel-scroll {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.75rem;
  -webkit-overflow-scrolling: touch;
}

.rel-scroll::-webkit-scrollbar {
  height: 6px;
}

.rel-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.rel-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.rel-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.rel-card {
  flex: 0 0 auto;
  width: 160px;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.rel-card--spouse {
  border-color: var(--accent);
}

.rel-spouse-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.75rem;
  margin-bottom: 0.75rem;
}

.children-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.child-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: grab;
}

.child-row:active {
  cursor: grabbing;
}

.child-drag-handle {
  font-size: 1rem;
  line-height: 1;
  cursor: grab;
  user-select: none;
}

.child-row--dragging {
  opacity: 0.35;
}

.child-row--over {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.rc-type {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.rc-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent);
  text-decoration: none;
  word-break: break-word;
}

.rc-name:hover {
  text-decoration: underline;
}

.rc-dates,
.rc-children {
  font-size: 0.75rem;
  line-height: 1.4;
}

.list.inline {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem 1rem;
  overflow-x: auto;
  padding-bottom: 0.75rem;
  scroll-behavior: smooth;
  min-height: 1.5em;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.list.inline::-webkit-scrollbar {
  height: 6px;
}

/* --- Өмірбаян бөлімі (person.ejs) --- */
.bio-sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.bio-sec-head .rel-title {
  margin: 0;
}

.bio-content {
  line-height: 1.65;
  max-width: 52rem;
}

.bio-content h2,
.bio-content h3,
.bio-content h4 {
  margin: 1rem 0 0.4rem;
  line-height: 1.3;
}

.bio-content p {
  margin: 0.5rem 0;
}

.bio-content ul,
.bio-content ol {
  margin: 0.5rem 0;
  padding-left: 1.4rem;
}

.bio-content img {
  max-width: 100%;
  border-radius: 8px;
  margin: 0.5rem 0;
}

.bio-content a {
  color: var(--accent, #2d6b4f);
}

#bio-text {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  padding: 0.6rem;
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  resize: vertical;
  background: var(--card, #fff);
  color: inherit;
}

.bio-editor-actions {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0;
  flex-wrap: wrap;
}

.bio-save {
  font-weight: 600;
}

.bio-preview {
  border: 1px dashed var(--border, #ccc);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
  background: var(--bg, #fafafa);
}

/* --- Кітап бөлімі --- */
.book-toc {
  margin: 0.5rem 0 0;
  padding-left: 1.6rem;
  line-height: 1.9;
}

.book-toc a {
  color: var(--accent, #2d6b4f);
  text-decoration: none;
}

.book-toc a:hover {
  text-decoration: underline;
}

.book-content {
  font-size: 1rem;
  line-height: 1.75;
}

.book-content img {
  display: block;
  max-width: min(100%, 560px);
  margin: 0.75rem auto;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.book-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.book-nav-link {
  color: var(--accent, #2d6b4f);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.book-nav-link:hover {
  text-decoration: underline;
}

/* --- Жеті ата --- */
.zheti-title {
  margin-bottom: 0.5rem;
}

.zheti-ata {
  margin: 0;
  padding-left: 1.6rem;
  line-height: 2;
  counter-reset: none;
}

.zheti-ata li {
  padding-left: 0.2rem;
}

.zheti-label {
  display: inline-block;
  min-width: 6.5rem;
}

.zheti-ata a {
  color: var(--accent, #2d6b4f);
  text-decoration: none;
  font-weight: 600;
}

.zheti-ata a:hover {
  text-decoration: underline;
}

/* --- 💾 Сақтық көшірме виджеті (footer) --- */
.backup-widget {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 1rem;
}

.backup-btn {
  font: inherit;
  font-size: 0.78rem;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border, #ddd);
  border-radius: 6px;
  background: var(--card, #fff);
  color: var(--accent, #2d6b4f);
  cursor: pointer;
}

.backup-btn:hover {
  background: var(--accent, #2d6b4f);
  color: #fff;
}

.backup-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.backup-btn--dirty {
  border-color: #d98324;
  color: #d98324;
  font-weight: 600;
}

.backup-btn--dirty:hover {
  background: #d98324;
  color: #fff;
}

.backup-status {
  font-size: 0.72rem;
  color: var(--muted, #999);
}

/* --- Статистика беті --- */
.stat-tiles {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.7rem 1.1rem;
  border: 1px solid var(--border, #e5e5e5);
  border-radius: 10px;
  background: var(--bg, #fafafa);
  min-width: 7rem;
}

.stat-num {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent, #2d6b4f);
}

.stat-cap {
  font-size: 0.75rem;
  color: var(--muted, #888);
}

.stat-list {
  margin: 0.5rem 0 0;
  padding-left: 1.5rem;
  line-height: 1.9;
}

.stat-list a {
  color: var(--accent, #2d6b4f);
  text-decoration: none;
  font-weight: 600;
}

.stat-list a:hover {
  text-decoration: underline;
}

.stat-table {
  border-collapse: collapse;
  margin-top: 0.5rem;
}

.stat-table td {
  padding: 0.2rem 0.9rem 0.2rem 0;
  border-bottom: 1px dashed var(--border, #eee);
}

.stat-decades {
  width: 100%;
  max-width: 34rem;
}

.stat-bar-cell {
  width: 60%;
}

.stat-bar {
  height: 0.8rem;
  min-width: 2px;
  background: var(--accent, #2d6b4f);
  opacity: 0.75;
  border-radius: 3px;
}

/* --- Туыстық калькуляторы --- */
.kin-form {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.kin-field {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.kin-input {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  width: 240px;
  background: var(--card, #fff);
  color: inherit;
}

.kin-label {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent, #2d6b4f);
}

.kin-path {
  margin: 0.35rem 0;
  line-height: 1.9;
}

.kin-path a {
  color: var(--accent, #2d6b4f);
  text-decoration: none;
  font-weight: 600;
}

.kin-path a:hover {
  text-decoration: underline;
}

.kin-arrow {
  color: #aaa;
  margin: 0 0.3rem;
}

/* kinship бетіндегі іздеу тізімі (tree-chart.css-тегімен үйлес) */
.kin-field .root-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 300;
  background: var(--card, #fff);
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.13);
  list-style: none;
  margin: 2px 0 0;
  padding: 0.3rem 0;
  min-width: 240px;
  max-height: 320px;
  overflow-y: auto;
}

.kin-field .root-dropdown--hidden {
  display: none;
}

.kin-field .root-dd-item {
  padding: 0.45rem 0.85rem;
  font-size: 0.88rem;
  cursor: pointer;
}

.kin-field .root-dd-item:hover {
  background: #f0f7f4;
}

.kin-field .root-dd-num {
  font-size: 0.72rem;
  color: #aaa;
}

.book-mentions {
  margin: 0.5rem 0 0;
  padding-left: 1.4rem;
  line-height: 1.8;
}

.book-mentions a {
  color: var(--accent, #2d6b4f);
  text-decoration: none;
}

.book-mentions a:hover {
  text-decoration: underline;
}

.list.inline::-webkit-scrollbar-track {
  background: transparent;
}

.list.inline::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.list.inline::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.list.inline li {
  border-bottom: none;
  flex: 0 0 auto;
  white-space: nowrap;
}

details summary {
  cursor: pointer;
}

.tree-root article.tree-node {
  border-left: 2px solid var(--accent);
  padding-left: 0.85rem;
  margin: 0.75rem 0;
}

.tree-node header.tn-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.person-pill {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--accent);
  text-decoration: none;
}

.tn-img img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.tree-parents {
  margin: 0.85rem 0 0;
  padding: 0.75rem;
  border-radius: 8px;
  background: rgba(45, 107, 79, 0.06);
  border: 1px solid var(--border);
}

.tp-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin-top: 0.5rem;
}

.tree-fam {
  margin-top: 0.85rem;
  padding-left: 0.5rem;
}

.tree-kids {
  list-style: disc;
  margin: 0.35rem 0 0;
  padding-left: 1.25rem;
}

.tree-kids .tree-node {
  border-left: none;
  padding-left: 0;
  margin-left: -0.5rem;
}

.tree-spouse {
  font-weight: 600;
}

code {
  font-size: 0.85rem;
}
