:root {
  --red: #9e2b25;
  --red-dark: #7a1f1a;
  --gold: #c9a227;
  --gold-light: #f3e6c2;
  --paper: #faf6ee;
  --ink: #3a2f28;
  --muted: #8a7c6f;
  --green: #4a7c59;
  --card: #ffffff;
  --border: #e6dccb;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
}

.hidden { display: none !important; }

button {
  cursor: pointer; border: none; border-radius: 8px;
  font-size: 14px; padding: 10px 18px; transition: all .15s;
}
button.primary { background: var(--red); color: #fff; }
button.primary:hover { background: var(--red-dark); }
button.small { padding: 7px 14px; font-size: 13px; }
button.ghost { background: #f0ece3; color: var(--muted); margin-left: 8px; }
button.approve { background: var(--green); color: #fff; padding: 7px 14px; font-size: 13px; }
button.reject { background: #b04030; color: #fff; padding: 7px 14px; font-size: 13px; }

input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; background: #fff; margin: 6px 0 14px;
  font-family: inherit;
}
textarea { resize: vertical; }
label { font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 10px; }

/* ---------- 顶栏 ---------- */
#topbar {
  display: flex; align-items: center; gap: 24px;
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  color: #fff; padding: 0 24px; height: 60px; position: sticky; top: 0; z-index: 20;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.brand { font-size: 18px; font-weight: 700; white-space: nowrap; }
#nav { display: flex; gap: 6px; flex: 1; }
.nav-btn {
  background: rgba(255,255,255,.12); color: #f5e9d0; padding: 8px 16px;
  border-radius: 20px; font-size: 14px;
}
.nav-btn.active, .nav-btn:hover { background: var(--gold); color: #4a3900; }
.nav-badge {
  display: inline-block; min-width: 18px; text-align: center;
  background: #fff; color: var(--red); border-radius: 10px;
  font-size: 11px; font-weight: 700; padding: 0 5px; margin-left: 4px; line-height: 17px;
}
.nav-btn.active .nav-badge, .nav-btn:hover .nav-badge { background: var(--red); color: #fff; }
#userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; }
#userbox .avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); }
#userbox .uname { font-weight: 600; }
#userbox button { background: rgba(0,0,0,.25); color: #fff; padding: 6px 12px; font-size: 12px; }

/* ---------- 登录 ---------- */
#view-auth {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 30%, rgba(201,162,39,.15), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(158,43,37,.12), transparent 40%),
    var(--paper);
  padding: 20px;
}
.auth-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 36px 40px; width: 420px; max-width: 96vw;
  box-shadow: 0 12px 40px rgba(90,60,30,.12);
}
.auth-card h1 { font-size: 22px; color: var(--red); text-align: center; }
.auth-card .subtitle { text-align: center; color: var(--gold); letter-spacing: 4px; font-size: 12px; margin: 8px 0 20px; }
.auth-card h2 { font-size: 16px; margin-bottom: 12px; color: var(--ink); }
.hint { font-size: 12px; color: var(--muted); background: var(--gold-light); padding: 8px 10px; border-radius: 6px; margin-bottom: 12px; line-height: 1.6; }
.switch { text-align: center; font-size: 13px; margin-top: 12px; color: var(--muted); }
.switch a { color: var(--red); cursor: pointer; font-weight: 600; }
.error { background: #fdecea; color: #b04030; padding: 10px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.file-row { align-items: center; }
.file-label { background: #f0ece3; padding: 10px 16px; border-radius: 8px; cursor: pointer; white-space: nowrap; font-size: 14px; }
#reg-photo { display: none; }
#photo-preview { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); }

/* ---------- 认祖归宗 ---------- */
.claim-wrap { max-width: 1400px; margin: 0 auto; padding: 24px; }
.claim-head h2 { color: var(--red); margin-bottom: 8px; }
.claim-head p { background: var(--gold-light); padding: 12px 16px; border-radius: 10px; line-height: 1.7; font-size: 14px; }
.claim-body { display: flex; gap: 20px; margin-top: 18px; align-items: flex-start; flex-wrap: wrap; }
.tree-panel { flex: 1.6; min-width: 480px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.tree-panel h3, .claim-form-panel h3 { margin-bottom: 10px; font-size: 15px; }
.claim-form-panel { flex: 1; min-width: 340px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.selected-box {
  background: var(--gold-light); border: 1px dashed var(--gold); border-radius: 8px;
  padding: 10px 12px; font-size: 14px; margin-bottom: 10px; min-height: 40px;
}
#claim-status { margin-top: 14px; }

.claim-item {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin-top: 10px; font-size: 13px; line-height: 1.7;
}
.claim-item .st { font-weight: 700; }
.st.pending { color: var(--gold); }
.st.approved { color: var(--green); }
.st.rejected { color: #b04030; }

/* ---------- 主布局 ---------- */
.tab-page { max-width: 1400px; margin: 0 auto; padding: 24px; }
.toolbar { display: flex; align-items: center; gap: 20px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar h2 { color: var(--red); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex: 1; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.d-member { background: var(--red); }
.d-placeholder { background: #c8bda8; }
.d-me { background: var(--gold); }

/* ---------- 生日提醒跑马灯 ---------- */
#birthday-bar {
  overflow: hidden;
  background: linear-gradient(90deg, #f7ecc8, #faf3dd, #f7ecc8);
  border: 1px solid var(--gold);
  border-radius: 10px;
  margin-bottom: 14px;
}
.bday-track {
  display: inline-flex;
  white-space: nowrap;
  animation: bday-scroll 28s linear infinite;
  will-change: transform;
}
.bday-track span {
  padding: 9px 0;
  font-size: 14px;
  color: #8a6d00;
  font-weight: 600;
  letter-spacing: .5px;
}
.bday-track b { color: var(--red); }
#birthday-bar:hover .bday-track { animation-play-state: paused; }
@keyframes bday-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

/* ---------- 家族树 ---------- */
.tree-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  overflow: auto; max-height: 72vh; padding: 10px;
}
.tree-svg text { font-family: inherit; }
.node-g { cursor: pointer; }
.node-g rect.node-card { fill: #fffdf7; stroke: #c8bda8; stroke-width: 1.5; rx: 10; }
.node-g.placeholder rect.node-card { stroke-dasharray: 4 3; }
.node-g.member rect.node-card { stroke: var(--red); stroke-width: 2; }
.node-g.me rect.node-card { stroke: var(--gold); stroke-width: 3; }
.node-g text.n-name { font-size: 13px; font-weight: 700; fill: var(--ink); }
.node-g.placeholder text.n-name { fill: #9a8f7d; }
.node-g text.n-sub { font-size: 10px; fill: var(--muted); }
.node-g.selected rect.node-card { stroke: var(--gold); stroke-width: 3.5; }
.edge { stroke: #b8ab93; stroke-width: 1.5; fill: none; }
.edge.spouse-line { stroke: var(--red); stroke-dasharray: none; stroke-width: 2; }
.gen-badge { font-size: 10px; fill: #fff; }

.detail-panel {
  position: fixed; right: 20px; top: 76px; width: 320px; z-index: 30;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; box-shadow: 0 8px 30px rgba(90,60,30,.18);
}
.detail-panel h3 { color: var(--red); margin-bottom: 8px; }
.detail-panel .kv { font-size: 13px; line-height: 2; }
.detail-panel .kv b { color: var(--muted); font-weight: 400; display: inline-block; width: 60px; }
.detail-panel .photo-big { width: 100%; border-radius: 10px; margin-bottom: 10px; max-height: 200px; object-fit: cover; }
.detail-panel .ops { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 10px; margin-left: 6px; }
.badge.b-member { background: #fdeaea; color: var(--red); }
.badge.b-ph { background: #f0ece3; color: var(--muted); }

/* ---------- 聊天 ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 140px); background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; }
.msg { display: flex; gap: 10px; margin-bottom: 16px; }
.msg .m-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--gold-light); display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--red); flex-shrink: 0; overflow: hidden; }
.msg .m-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg .m-body { max-width: 70%; }
.msg .m-name { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg .m-bubble { background: #f5f0e6; padding: 10px 14px; border-radius: 4px 12px 12px 12px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .m-body { text-align: right; }
.msg.mine .m-bubble { background: var(--red); color: #fff; border-radius: 12px 4px 12px 12px; }
.chat-input { display: flex; gap: 12px; padding: 14px; border-top: 1px solid var(--border); background: #fcfaf5; }
.chat-input textarea { margin: 0; flex: 1; }
.chat-input button { margin: 0; align-self: flex-end; }

/* ---------- 活动 ---------- */
.act-layout { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.act-form { width: 320px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; position: sticky; top: 84px; }
.act-form h3 { margin-bottom: 8px; }
.act-list { flex: 1; min-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.act-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.act-card .act-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.act-card h4 { font-size: 16px; }
.tag { font-size: 11px; padding: 3px 10px; border-radius: 10px; color: #fff; }
.tag.record { background: var(--green); }
.tag.invite { background: var(--red); }
.act-meta { font-size: 12px; color: var(--muted); margin: 8px 0; line-height: 1.8; }
.act-desc { font-size: 14px; line-height: 1.7; white-space: pre-wrap; background: #faf7f0; padding: 10px 12px; border-radius: 8px; margin-top: 6px; }
.act-comments { margin-top: 14px; border-top: 1px dashed var(--border); padding-top: 12px; }
.cmt { display: flex; gap: 8px; font-size: 13px; margin-bottom: 10px; }
.cmt .c-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--gold-light); color: var(--red); display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; overflow: hidden; }
.cmt .c-avatar img { width: 100%; height: 100%; object-fit: cover; }
.cmt .c-body b { color: var(--red); font-weight: 600; margin-right: 6px; }
.cmt .c-body .c-time { color: var(--muted); font-size: 11px; margin-left: 6px; }
.cmt .c-body p { margin-top: 2px; line-height: 1.6; }
.cmt-input { display: flex; gap: 8px; margin-top: 8px; }
.cmt-input input { margin: 0; }
.cmt-input button { padding: 8px 14px; font-size: 13px; white-space: nowrap; }

/* ---------- 个人资料 ---------- */
.profile-layout { display: flex; gap: 24px; margin-top: 16px; align-items: flex-start; flex-wrap: wrap; }
.profile-photo-box {
  width: 240px; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; text-align: center;
}
#profile-avatar { width: 140px; height: 140px; margin: 0 auto 14px; border-radius: 50%; overflow: hidden; background: var(--gold-light); display: flex; align-items: center; justify-content: center; font-size: 46px; font-weight: 700; color: var(--red); }
#profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
#profile-photo { display: none; }
.profile-photo-box .file-label { display: inline-block; }
.profile-form { flex: 1; min-width: 340px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.profile-form .sec-title { margin: 22px 0 6px; font-size: 15px; color: var(--red); }
.profile-form button.primary { margin-top: 6px; }

/* ---------- 管理端 ---------- */
#tab-admin h3 { margin: 18px 0 10px; font-size: 15px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sec-head h3 { margin: 18px 0 10px; }
.admin-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; font-size: 13px; line-height: 1.8; }
.admin-card .flex { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.admin-card .uinfo { display: flex; gap: 10px; align-items: center; }
.admin-card .uinfo img { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; }
.admin-card .uinfo .avatar-ph { width: 44px; height: 44px; border-radius: 8px; background: var(--gold-light); color: var(--red); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; }
.admin-card .fields span { margin-right: 14px; color: var(--muted); }
.admin-card .fields b { color: var(--ink); font-weight: 500; }
.st-chip { font-size: 11px; padding: 2px 10px; border-radius: 10px; }
.st-chip.pending { background: var(--gold-light); color: #8a6d00; }
.st-chip.active { background: #e5f2e8; color: var(--green); }
.st-chip.rejected { background: #fdecea; color: #b04030; }
/* 人员审核区：待处理事项高亮 */
.admin-card.review { border-left: 4px solid var(--gold); background: #fffdf6; }
.admin-card .sub-h, #tab-admin .sub-h {
  margin: 14px 0 8px; font-size: 13px; color: #8a6d00; font-weight: 600;
}
.admin-empty {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; font-size: 13px; color: var(--muted);
}
.admin-card .admin-ops { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.admin-card .admin-ops button { margin-left: 0; }

/* ---------- 图片上传：尺寸约束 + 移动端防遮挡 ---------- */
/* 任何预览图都不得超出容器，避免大图把页面/表单按钮挤出屏幕 */
#app img { max-width: 100%; }
input[type=file] { max-width: 100%; font-size: 12px; }
.file-row img, #photo-preview, #pe-photo-preview { max-width: 120px; max-height: 120px; object-fit: cover; }
.modal-card { max-height: 92vh; overflow-y: auto; }

/* ---------- 弹窗 / 提示 ---------- */
.modal { position: fixed; inset: 0; background: rgba(40,25,15,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: #fff; border-radius: 14px; padding: 24px; width: 380px; max-width: 94vw; }
.modal-card.wide { width: 460px; max-height: 92vh; overflow-y: auto; }
#pe-photo { display: none; }
#pe-photo-preview { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); }
.chk-line { display: flex; align-items: center; gap: 8px; margin: 4px 0 14px; font-size: 13px; color: var(--ink); }
.chk-line input { width: auto; margin: 0; }
.modal-card h3 { margin-bottom: 12px; color: var(--red); }
#toast {
  position: fixed; left: 50%; top: 76px; transform: translateX(-50%);
  background: rgba(58,47,40,.92); color: #fff; padding: 10px 22px;
  border-radius: 24px; font-size: 14px; z-index: 99; max-width: 80vw;
}
#toast.err { background: #b04030; }

/* ---------- 头像 / 已故黑白 ---------- */
.deceased { filter: grayscale(100%); }
.avatar-ph {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--gold-light); color: var(--red); font-weight: 700;
  border-radius: 50%; overflow: hidden;
}
.avatar-ph.deceased { background: #dcd7cf; color: #6f6a63; filter: grayscale(100%); }
.msg .m-avatar .avatar-ph { width: 100%; height: 100%; font-size: 15px; border-radius: 50%; }
.cmt .c-avatar .avatar-ph { width: 100%; height: 100%; font-size: 12px; border-radius: 50%; }
.peer-item .avatar-ph { width: 26px; height: 26px; font-size: 12px; flex-shrink: 0; }
.act-meta .who { display: inline-flex; align-items: center; gap: 4px; vertical-align: middle; }
.act-meta .who img, .act-meta .who .avatar-ph { width: 22px; height: 22px; }
.gone {
  font-style: normal; font-size: 10px; background: #6b6b6b; color: #fff;
  padding: 1px 6px; border-radius: 8px; margin-left: 6px;
}
.badge.b-gone { background: #e8e5e0; color: #5f5a54; }

/* ---------- 图片网格 / 大图查看 ---------- */
.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.photo-grid img {
  width: 96px; height: 96px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border); cursor: zoom-in;
}
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.86); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 8px; }
#act-photos { display: none; }
.cmt-input input[type=file] { display: none; }
.file-label.sm { padding: 8px 10px; font-size: 15px; margin: 0; }

/* ---------- 聊天（聊天室 + 私聊） ---------- */
.chat-layout { display: flex; gap: 16px; align-items: stretch; }
.chat-side {
  width: 220px; flex-shrink: 0; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px;
}
.side-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.peer-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: 8px; cursor: pointer; font-size: 14px; margin-bottom: 4px;
}
.peer-item:hover { background: #f5f0e6; }
.peer-item.active { background: var(--gold-light); font-weight: 600; }
.peer-item img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.peer-item .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-main { flex: 1; min-width: 0; }
.chat-title {
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 14px; background: #fcfaf5;
}

/* ---------- 移动端适配 ---------- */
@media (max-width: 768px) {
  #topbar { height: auto; padding: 8px 12px; flex-wrap: wrap; gap: 8px; }
  .brand { font-size: 15px; }
  #nav { order: 3; width: 100%; overflow-x: auto; gap: 4px; }
  .nav-btn { padding: 6px 12px; font-size: 13px; white-space: nowrap; }
  #userbox { font-size: 12px; margin-left: auto; }
  .tab-page { padding: 12px; }
  .auth-card { padding: 24px 20px; width: 100%; }
  .claim-body { flex-direction: column; }
  .tree-panel, .claim-form-panel { min-width: 0; width: 100%; }
  .act-layout { flex-direction: column; }
  .act-form { width: 100%; position: static; }
  .act-list { min-width: 0; width: 100%; }
  .profile-layout { flex-direction: column; }
  .profile-photo-box, .profile-form { width: 100%; }
  .row { flex-wrap: wrap; }
  .chat-layout { flex-direction: column; gap: 10px; }
  .chat-side { width: 100%; display: flex; gap: 6px; overflow-x: auto; padding: 8px; }
  .side-title { display: none; }
  .peer-item { margin-bottom: 0; white-space: nowrap; flex-shrink: 0; }
  .chat-wrap { height: calc(100vh - 210px); }
  .chat-input textarea { min-height: 44px; }
  .msg .m-body { max-width: 82%; }
  .detail-panel {
    position: fixed; left: 8px; right: 8px; bottom: 8px; top: auto;
    width: auto; max-height: 58vh; overflow: auto;
  }
  .modal-card, .modal-card.wide { width: 94vw; padding: 18px; }
  .admin-card .flex { flex-direction: column; align-items: flex-start; }
  .admin-card .ops { margin-left: 0 !important; }
  .photo-grid img { width: 76px; height: 76px; }
  .tree-box { max-height: 58vh; }
  .cmt-input { flex-wrap: wrap; }
  .toolbar { gap: 10px; }
  .legend { width: 100%; flex: none; }
  /* 上传：按钮与预览同行不换行，避免撑出屏幕 */
  .file-row { flex-wrap: wrap; }
  .file-label { width: 100%; text-align: center; }
  .admin-card .admin-ops { flex-direction: column; }
  .admin-card .admin-ops button { width: 100%; }
  .modal-card { max-height: 88vh; }
}
