/* 族谱站点：墨绿纸感 + 移动优先，大屏加宽版心 */
:root {
  --bg: #f4f1ea;
  --bg-card: #fffdf8;
  --ink: #1c2418;
  --ink-muted: #5c6658;
  --accent: #2d5a3d;
  --accent-hover: #234a30;
  --border: #d8d0c4;
  --shadow: 0 4px 24px rgba(28, 36, 24, 0.08);
  --radius: 12px;
  --font: "Source Han Serif SC", "Noto Serif SC", "Songti SC", Georgia, "Times New Roman", serif;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  --space: clamp(1rem, 4vw, 1.75rem);
  --maxw: 72rem;
}

*,
*::before,
*::after { box-sizing: border-box; }

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: clamp(0.95rem, 2.8vw, 1.05rem);
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -20%, rgba(45, 90, 61, 0.06), transparent),
    linear-gradient(180deg, #ebe6dc 0%, var(--bg) 32%);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  z-index: 999;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
}
.skip-link:focus { left: var(--space); top: var(--space); }

/* ----- 顶栏 ----- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 253, 248, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.header-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0.65rem var(--space);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand-mark {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), #1e4028);
  color: #fff;
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

.brand-text { min-width: 0; }
.brand-title {
  display: block;
  font-family: var(--font);
  font-weight: 700;
  font-size: clamp(1rem, 4vw, 1.2rem);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70vw;
}
.brand-tagline {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 75vw;
}

.nav-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  cursor: pointer;
}
.nav-toggle-bar {
  display: block;
  height: 2px;
  width: 1.25rem;
  margin: 0 auto;
  background: var(--ink);
  border-radius: 1px;
}

@media (min-width: 768px) {
  .nav-toggle { display: none; }
}

.site-nav {
  display: none;
  width: 100%;
  flex-direction: column;
  gap: 0.25rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.site-nav.is-open { display: flex; }
@media (max-width: 767px) {
  .site-nav.is-open {
    position: fixed;
    inset: 0;
    top: 4.25rem;
    z-index: 99;
    background: var(--bg-card);
    padding: var(--space);
    border-top: 1px solid var(--border);
    overflow-y: auto;
  }
}

.site-nav a {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 500;
}
.site-nav a:hover { background: rgba(45, 90, 61, 0.08); color: var(--accent); }
.nav-api { font-family: ui-monospace, monospace; font-size: 0.9em; }
.nav-admin { color: var(--accent); }

@media (min-width: 768px) {
  .site-nav {
    display: flex !important;
    flex-direction: row;
    flex-wrap: wrap;
    width: auto;
    padding-top: 0;
    border-top: none;
    align-items: center;
    gap: 0.15rem;
  }
  .site-nav a { padding: 0.45rem 0.75rem; }
}

/* ----- 主区 ----- */
.main-content {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--space);
  padding-bottom: calc(var(--space) * 2);
}

/* Hero */
.hero {
  margin: 0 calc(-1 * var(--space)) var(--space);
  padding: clamp(1.5rem, 6vw, 3rem) var(--space);
  background: linear-gradient(160deg, #2d5a3d 0%, #1a3324 55%, #152a1e 100%);
  color: #f0ebe3;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
}
@media (min-width: 768px) {
  .hero {
    margin: 0 0 var(--space);
    border-radius: var(--radius);
  }
}

.hero-inner { max-width: 40rem; }
.hero-heading {
  margin: 0 0 0.35rem;
  font-family: var(--font);
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 700;
  line-height: 1.2;
}
.hero-lead {
  margin: 0 0 1.25rem;
  opacity: 0.9;
  font-size: 0.95rem;
}

.hero-search {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
@media (min-width: 480px) {
  .hero-search { flex-direction: row; flex-wrap: wrap; align-items: stretch; }
  .hero-search input { flex: 1; min-width: 12rem; }
}

.hero-search input {
  padding: 0.75rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
  color: #fff;
  font-size: 1rem;
}
.hero-search input::placeholder { color: rgba(255, 255, 255, 0.55); }

.hero-stats {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}
.stat-chip {
  font-size: 0.88rem;
  opacity: 0.92;
}
.stat-chip strong { font-weight: 700; }

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.1rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary {
  background: #e8dfd0;
  color: #1a3324;
}
.btn-primary:hover { background: #fff; }
.btn-ghost {
  background: transparent;
  color: #f0ebe3;
  border: 1px solid rgba(255, 255, 255, 0.4);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }

/* 内容块 */
.content-section {
  margin-bottom: clamp(1.25rem, 4vw, 2rem);
}
.section-inner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1rem, 4vw, 1.75rem);
  box-shadow: var(--shadow);
}
.section-title {
  margin: 0 0 0.5rem;
  font-family: var(--font);
  font-size: clamp(1.2rem, 3.5vw, 1.45rem);
  color: var(--accent);
}
.section-subtitle {
  margin: 0 0 1rem;
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.prose {
  font-family: var(--font);
  line-height: 1.8;
}
.prose h2, .prose h3 { margin-top: 1.25em; color: var(--accent); }
.prose a { color: var(--accent); }
.prose-plain { white-space: pre-wrap; }

.muted { color: var(--ink-muted); }
.small { font-size: 0.88rem; }
.empty-hint { padding: 1rem 0; }

/* 功能卡片 */
.card-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 560px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); }
}

.feature-card {
  display: block;
  padding: 1.15rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.feature-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: rgba(45, 90, 61, 0.35);
}
.feature-card h3 {
  margin: 0.35rem 0 0.25rem;
  font-size: 1.05rem;
  color: var(--accent);
}
.feature-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-muted);
}
.feature-card-icon {
  font-size: 1.5rem;
  line-height: 1;
}

/* 列表页 */
.page-head {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
@media (min-width: 640px) {
  .page-head {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
  }
}
.page-title {
  margin: 0;
  font-family: var(--font);
  font-size: clamp(1.35rem, 4vw, 1.75rem);
  color: var(--accent);
}

.inline-search {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.inline-search input {
  flex: 1;
  min-width: 10rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
}

.person-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
}
.person-list li { border-bottom: 1px solid var(--border); }
.person-list li:last-child { border-bottom: none; }
.person-list a {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  text-decoration: none;
  color: inherit;
}
.person-list a:hover { background: rgba(45, 90, 61, 0.06); }
.person-name { font-weight: 600; font-family: var(--font); }
.person-meta { font-size: 0.85rem; color: var(--ink-muted); }

.pagination {
  margin-top: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.pagination a {
  color: var(--accent);
  font-weight: 600;
}
.page-current { color: var(--ink-muted); }

/* 人物详情 */
.person-article { max-width: 52rem; }
.person-header { margin-bottom: 1.5rem; }
.person-brief { margin: 0.5rem 0 0; color: var(--ink-muted); }

.person-section {
  margin-bottom: 1.5rem;
  padding: 1rem 1.15rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.person-section h2 {
  margin: 0 0 0.65rem;
  font-size: 1.05rem;
  color: var(--accent);
  font-family: var(--font);
}
.relation-list {
  margin: 0;
  padding-left: 1.25rem;
}
.relation-list li { margin: 0.35rem 0; }
.relation-list a { color: var(--accent); font-weight: 500; }

.mermaid-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* iOS Safari 惯性滚动 */
  padding: 0.5rem 0;
  white-space: nowrap;   /* 阻止容器压缩内部 SVG 宽度 */
  /* 在 iOS Safari 上强制开启硬件加速，避免滚动区域被裁切 */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}
.mermaid-wrap .mermaid {
  margin: 0;
  display: inline-block; /* 跟随 SVG 自然宽度，让父容器触发横向滚动 */
  min-width: 100%;
  white-space: normal;
  vertical-align: top;
}
/* JS 会覆盖 Mermaid 注入的 width=100% / max-width；
   此处 CSS 仅做兜底：阻止 SVG 自动拉伸超出自然宽 */
.mermaid-wrap .mermaid svg {
  display: block;
  height: auto;
  max-width: none !important; /* 清除 Mermaid 内联 max-width */
}

/* 页脚 */
.site-footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.25rem var(--space) 2rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
  text-align: center;
}
.site-footer a { color: var(--accent); }
.footer-meta {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 1.25rem;
}

/* 触摸目标 */
@media (max-width: 767px) {
  .site-nav a { min-height: 44px; display: flex; align-items: center; }
  .btn { min-height: 44px; }
}

/* ----- 前台表单（人员 / 内容块） ----- */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.1rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  border: 1px solid var(--border);
  cursor: pointer;
  font-family: inherit;
  background: var(--bg-card);
  color: var(--ink);
}
.btn-secondary:hover {
  border-color: rgba(45, 90, 61, 0.45);
  color: var(--accent);
}
.btn-form { margin-top: 0.25rem; }

.flash-messages { margin-bottom: 1rem; }
.flash {
  margin: 0 0 0.5rem;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 0.95rem;
}
.flash-success { border-color: rgba(45, 90, 61, 0.45); background: rgba(45, 90, 61, 0.08); }
.flash-error { border-color: #c45c4a; background: rgba(196, 92, 74, 0.1); }
.flash-warning { border-color: #c9a227; background: rgba(201, 162, 39, 0.12); }
.flash-info, .flash-debug { color: var(--ink-muted); }

.form-page .form-hint { margin-top: -0.35rem; margin-bottom: 1.25rem; max-width: 48rem; }
.form-page .form-hint a { color: var(--accent); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem 1.25rem;
  max-width: 48rem;
}
@media (min-width: 640px) {
  .form-grid { grid-template-columns: repeat(2, 1fr); }
}
.form-grid .form-row.full,
.form-grid .form-actions.full { grid-column: 1 / -1; }

.form-row label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 0.35rem;
  color: var(--ink);
}
.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="search"],
.form-row select,
.form-row textarea {
  width: 100%;
  max-width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
}
.form-row textarea { resize: vertical; min-height: 6rem; }
.mono-textarea { font-family: ui-monospace, monospace; font-size: 0.88rem; line-height: 1.5; }
.form-row .errorlist {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
  color: #a33;
  font-size: 0.88rem;
}
.checkbox-row .checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  cursor: pointer;
}
.checkbox-row input[type="checkbox"] { width: auto; }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-top: 0.5rem;
}

.person-actions { margin: 0.75rem 0 0; }
.gen-tag { font-weight: 500; color: var(--accent); }

/* ─── 新增：按钮尺寸变体 ─────────────────────────────────────────────────────── */
.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.88rem;
  border-radius: 8px;
}
.btn-accent {
  background: var(--accent);
  color: #fff;
  border: none;
}
.btn-accent:hover { background: var(--accent-hover); }

/* ─── 列表页头部操作区 ───────────────────────────────────────────────────────── */
.page-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* ─── 高级筛选面板 ───────────────────────────────────────────────────────────── */
.filter-panel {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: hidden;
}
.filter-toggle {
  padding: 0.65rem 1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent);
  list-style: none;
  user-select: none;
}
.filter-toggle::-webkit-details-marker { display: none; }
.filter-toggle::before { content: '▶ '; font-size: 0.7em; }
details[open] .filter-toggle::before { content: '▼ '; }

.filter-form { padding: 0.75rem 1rem 1rem; border-top: 1px solid var(--border); }
.filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem 1.25rem;
}
@media (min-width: 640px) {
  .filter-grid { grid-template-columns: repeat(3, 1fr); }
}
.filter-row label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--ink);
}
.filter-row select,
.filter-row input[type="number"] {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
}
.range-inputs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.range-inputs input { flex: 1; }
.range-sep { color: var(--ink-muted); font-size: 0.9rem; }
.filter-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* ─── 统计看板 ───────────────────────────────────────────────────────────────── */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
@media (min-width: 560px) {
  .stats-summary { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 900px) {
  .stats-summary { grid-template-columns: repeat(5, 1fr); }
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card-num {
  display: block;
  font-family: var(--font);
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}
.stat-card-label {
  display: block;
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-top: 0.25rem;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}
@media (min-width: 900px) {
  .charts-grid { grid-template-columns: 1fr 2fr; }
}
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
}
.chart-card--wide {
  grid-column: 1 / -1;
}
@media (min-width: 900px) {
  .chart-card--wide { grid-column: 2 / 3; }
}
.chart-title {
  margin: 0 0 0.65rem;
  font-size: 1rem;
  color: var(--accent);
  font-family: var(--font);
}
.chart-body { height: 260px; }

/* ─── 人员详情：图谱区块标题 ─────────────────────────────────────────────────── */
.chart-section-title {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  color: var(--accent);
  font-family: var(--font);
}

/* 后代枝状图标题行：标题+导出按钮左右排布 */
.chart-section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.chart-section-header > div { flex: 1; min-width: 0; }

/* ─── 人员详情：头部编辑按钮布局 ────────────────────────────────────────────── */
.person-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.person-edit-action { flex-shrink: 0; }

/* ─── 前台表单页 ─────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}
.form-section-title {
  margin: 0 0 0.85rem;
  font-size: 1rem;
  color: var(--accent);
  font-family: var(--font);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}
.person-form .form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem 1.25rem;
}
@media (min-width: 640px) {
  .person-form .form-grid { grid-template-columns: repeat(2, 1fr); }
}
.person-form .form-row.full { grid-column: 1 / -1; }
.person-form .form-row label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 0.3rem;
}
.person-form .form-row input,
.person-form .form-row select,
.person-form .form-row textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
}
.person-form .form-row textarea { resize: vertical; min-height: 5rem; }
.person-form .form-actions { margin-top: 0.5rem; }

/* ─── 导航新增链接 ───────────────────────────────────────────────────────────── */
.nav-add {
  background: var(--accent);
  color: #fff !important;
  border-radius: 8px;
  padding: 0.35rem 0.75rem !important;
  font-size: 0.88rem;
}
.nav-add:hover { background: var(--accent-hover) !important; }


/* 图谱加载中提示 */
.chart-loading {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted, #888);
  font-size: 0.9rem;
}

/* 批量录入表格 */
.batch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.batch-table th,
.batch-table td {
  padding: 4px 6px;
  border: 1px solid #ddd;
  white-space: nowrap;
}
.batch-table th {
  background: #f0f0f0;
  font-weight: 600;
  text-align: center;
}
.batch-table td input[type="text"],
.batch-table td input[type="number"] {
  width: 90px;
  padding: 3px 6px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 12px;
}
.batch-table td select {
  padding: 3px 4px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 12px;
}
