/* ============ 五代家族信息简历管理系统 · 视觉风格（暖色古籍风 · 移动端优先） ============ */
:root {
  --bg: #f3ede0;
  --bg-grain: #efe7d6;
  --surface: #fffdf8;
  --surface-2: #faf5ea;
  --ink: #3a2f22;
  --ink-soft: #5c4b36;
  --muted: #998a72;
  --line: #e7ddc7;
  --line-strong: #d8caa9;
  --primary: #8a5e28;       /* 古铜 */
  --primary-d: #6f4a1e;
  --accent: #c2912f;        /* 金 */
  --accent-d: #a87a2e;
  --male: #3b6ea8;
  --female: #b5476e;
  --danger: #c0392b;
  --ok: #2e8b57;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 18px rgba(80, 56, 22, .10);
  --shadow-sm: 0 2px 8px rgba(80, 56, 22, .08);
  --tab-h: 60px;
  --header-h: 56px;
  /* 代际色（深→浅） */
  --g1: #6f4a22; --g2: #8a5e28; --g3: #a87a2e; --g4: #c2912f; --g5: #d4a94a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(194,145,47,.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(138,94,40,.08), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
}
body::before{
  content:""; position:fixed; inset:0; pointer-events:none; z-index:0;
  background-image: repeating-linear-gradient(45deg, rgba(120,90,40,.018) 0 2px, transparent 2px 9px);
}

/* ---------- 顶部栏 ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-d));
  color: #fdf6e6;
  box-shadow: 0 3px 14px rgba(80,56,22,.22);
}
.app-header h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: 1.5px; display:flex; align-items:center; gap:8px; }
.app-header h1::before { content:"❖"; color: var(--accent); font-size:15px; }
.app-header .sub { font-size: 11px; opacity: .82; margin-top: 1px; letter-spacing:.5px; }
.header-actions { display: flex; gap: 8px; align-items:center; }
.icon-btn {
  background: rgba(255,255,255,.16); border: none; color: #fff;
  width: 38px; height: 38px; border-radius: 11px; font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: background .15s, transform .1s;
}
.icon-btn:active { background: rgba(255,255,255,.3); transform: scale(.94); }
.hdr-user {
  font-size: 12px; color: #fdf6e6; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .95;
  background: rgba(0,0,0,.12); padding: 4px 10px; border-radius: 20px;
}

/* ---------- 内容区 ---------- */
.content { padding: 14px 14px 8px; max-width: 1180px; margin: 0 auto; position: relative; z-index: 1; }
.page { display: none; }
.page.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px);} to { opacity:1; transform:none; } }

/* ---------- 搜索 ---------- */
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; position: sticky; top: var(--header-h); z-index: 20; background: transparent; padding: 8px 0; }
.search-bar .sbox {
  flex: 1; position: relative; display:flex; align-items:center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-sm);
}
.search-bar .sbox::before { content:"🔍"; position:absolute; left:12px; font-size:14px; opacity:.6; }
.search-bar input {
  flex: 1; border: none; background: transparent; padding: 11px 12px 11px 36px;
  font-size: 15px; color: var(--ink); outline: none; min-height: 44px;
}
.search-bar select {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--surface);
  min-height: 44px; font-size: 14px; color: var(--ink-soft); box-shadow: var(--shadow-sm);
}

/* ---------- 代际分组 ---------- */
.gen-group { margin-bottom: 20px; }
.gen-title {
  display: flex; align-items: center; gap: 10px; margin: 4px 0 12px;
  font-size: 16px; font-weight: 700; color: var(--primary-d);
  padding: 7px 12px; border-radius: 12px; background: linear-gradient(90deg, rgba(194,145,47,.16), rgba(194,145,47,0));
}
.gen-title .bar { width: 6px; height: 20px; border-radius: 3px; background: var(--accent); }
.gen-title .count { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: auto; }

/* ---------- 成员卡片 ---------- */
.member-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.member-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px; display: flex; gap: 13px; align-items: center; box-shadow: var(--shadow-sm);
  cursor: pointer; transition: transform .08s, box-shadow .15s, border-color .15s; position: relative; overflow: hidden;
}
.member-card::before { content:""; position:absolute; left:0; top:0; bottom:0; width:5px; background: var(--accent); opacity:.85; }
.member-card:active { transform: scale(.99); box-shadow: var(--shadow); }
.member-card:hover { border-color: var(--line-strong); }
.avatar {
  width: 50px; height: 50px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; font-size: 19px; color: #fff; font-weight: 600;
  background: var(--male); box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.avatar.f { background: var(--female); }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.member-main { flex: 1; min-width: 0; }
.member-main .nm { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; color: var(--ink); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: #f1e8d4; color: var(--primary-d); font-weight: 600; white-space: nowrap; }
.tag.dead { background: #ece7dd; color: #9a8e78; }
.tag.g { background: rgba(194,145,47,.15); color: var(--accent-d); }
.member-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.member-sub b { color: var(--ink-soft); font-weight: 600; }
.member-sub .occ { color: var(--primary-d); }
.card-ops { display: flex; flex-direction: column; gap: 6px; }
.mini-btn { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 6px 10px; font-size: 12px; cursor: pointer; color: var(--ink-soft); transition: background .12s; }
.mini-btn.danger { color: var(--danger); border-color: #eccfca; }
.mini-btn:active { background: #f3eee2; }

/* ---------- 添加浮动按钮 ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom, 0px));
  z-index: 40; width: 58px; height: 58px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-d)); color: #fff; font-size: 30px;
  box-shadow: 0 6px 18px rgba(168,122,46,.5); cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .12s;
}
.fab:active { transform: scale(.92); }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(255,253,248,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); display: flex; box-shadow: 0 -3px 14px rgba(80,45,20,.08);
}
.tab {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 11px; padding: 7px 0; transition: color .15s;
}
.tab .ic { font-size: 20px; line-height: 1; filter: grayscale(.3); }
.tab.active { color: var(--accent-d); font-weight: 700; }
.tab.active .ic { filter: none; transform: translateY(-1px); }

/* ---------- 抽屉 / 模态表单 ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(40,28,12,.5); z-index: 50; display: none;
  align-items: flex-end; justify-content: center; backdrop-filter: blur(2px);
}
.overlay.show { display: flex; }
.drawer {
  background: var(--surface); width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 18px 18px calc(22px + env(safe-area-inset-bottom,0px));
  animation: slideUp .22s ease; box-shadow: 0 -10px 40px rgba(0,0,0,.25);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.drawer h2 { margin: 0 0 14px; font-size: 18px; color: var(--primary-d); display: flex; justify-content: space-between; align-items: center; }
.drawer .close { border: none; background: #f1e8d4; width: 34px; height: 34px; border-radius: 50%; font-size: 19px; cursor: pointer; color: var(--muted); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; font-size: 15px;
  background: var(--surface-2); min-height: 46px; font-family: inherit; color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(194,145,47,.15); background:#fff;
}
.field textarea { min-height: 72px; resize: vertical; }
.gender-toggle { display: flex; gap: 8px; }
.gender-toggle button {
  flex: 1; border: 1px solid var(--line); background: var(--surface-2); border-radius: 11px; padding: 11px; cursor: pointer; font-size: 15px; min-height: 46px; color: var(--ink-soft); transition: all .15s;
}
.gender-toggle button.sel.m { background: var(--male); color: #fff; border-color: var(--male); }
.gender-toggle button.sel.f { background: var(--female); color: #fff; border-color: var(--female); }

/* 头像上传 */
.photo-field { display:flex; align-items:center; gap:12px; }
.photo-field .avatar-lg { width:64px; height:64px; border-radius:14px; background:var(--surface-2); border:1px solid var(--line); display:flex; align-items:center; justify-content:center; font-size:28px; color:var(--muted); overflow:hidden; flex:0 0 auto; }
.photo-field .avatar-lg img { width:100%; height:100%; object-fit:cover; }
.photo-field .photo-btns { display:flex; flex-direction:column; gap:6px; }
.photo-field .mini-btn { font-size:12px; padding:7px 11px; }

.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn {
  flex: 1; border: none; border-radius: 12px; padding: 14px; font-size: 15px; cursor: pointer; font-weight: 700; min-height: 50px; transition: opacity .15s, transform .1s;
}
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-d)); color: #fff; box-shadow: 0 4px 12px rgba(168,122,46,.3); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line-strong); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:active { opacity: .85; transform: translateY(1px); }
.btn:disabled { opacity: .5; }

/* ---------- 世系图 ---------- */
.tree-wrap { position: relative; }
.tree-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.tree-toolbar .legend { display:flex; gap:10px; flex-wrap:wrap; margin-left:auto; font-size:11px; color:var(--muted); }
.tree-toolbar .legend i { width:10px; height:10px; border-radius:3px; display:inline-block; margin-right:4px; vertical-align:-1px; }
.tree-zoom { display:flex; gap:6px; }
.tree-zoom button {
  width:38px; height:38px; border-radius:10px; border:1px solid var(--line); background:var(--surface);
  font-size:17px; cursor:pointer; color:var(--primary-d); box-shadow: var(--shadow-sm);
}
.tree-zoom button:active { background: var(--surface-2); }
.tree-viewport {
  overflow: hidden; position: relative; background:
    linear-gradient(0deg, rgba(194,145,47,.04), rgba(194,145,47,.04));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0; box-shadow: var(--shadow-sm);
  touch-action: none; height: 62vh; min-height: 360px; cursor: grab;
}
.tree-viewport.grabbing { cursor: grabbing; }
.tree-canvas { transform-origin: 0 0; will-change: transform; }
.tree-hint { font-size: 12px; color: var(--muted); margin: 2px 2px 10px; }
.tree-node-box { transition: filter .15s; }
.tnode { cursor: pointer; }
.tnode:hover .tn-box { filter: brightness(1.05); }
.tlink { stroke: #c9bfa3; stroke-width: 1.6; fill: none; }
.tlink.spouse { stroke: #d8a0b8; stroke-dasharray: 5 4; }
.tlink.mother { stroke: #d8a0b8; stroke-dasharray: 4 3; }
.gen-band { fill: rgba(194,145,47,.06); }
.gen-band-label { font-size: 13px; font-weight: 700; fill: var(--primary-d); }

/* ---------- 详情弹层 ---------- */
.detail .d-head { display:flex; gap:12px; align-items:center; margin-bottom:8px; }
.detail .d-head .avatar { width:56px; height:56px; }
.detail .d-name { font-size:19px; font-weight:700; color:var(--ink); }
.detail .d-sub { font-size:12px; color:var(--muted); }
.detail .row { display: flex; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.detail .row .k { width: 84px; color: var(--muted); flex: 0 0 auto; font-weight:600; }
.detail .row .v { flex:1; color: var(--ink-soft); word-break: break-word; }
.detail .bio { margin-top: 12px; font-size: 14px; color: var(--ink-soft); white-space: pre-wrap; background: var(--surface-2); border-radius:12px; padding:12px; border:1px solid var(--line); }
.detail .rel-grid { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:12px; }
.detail .rel-grid .rel { background: var(--surface-2); border:1px solid var(--line); border-radius:10px; padding:9px 11px; }
.detail .rel-grid .rel .t { font-size:11px; color:var(--muted); }
.detail .rel-grid .rel .n { font-size:14px; font-weight:600; color:var(--ink); margin-top:2px; }

/* ---------- 导出 / 设置 ---------- */
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.export-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 14px; text-align: center; box-shadow: var(--shadow-sm); cursor: pointer; transition: transform .1s, box-shadow .15s, border-color .15s;
}
.export-card:active { transform: scale(.97); }
.export-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.export-card .ic { font-size: 32px; }
.export-card .t { font-weight: 700; margin-top: 8px; color: var(--ink); }
.export-card .d { font-size: 12px; color: var(--muted); margin-top: 3px; }
.section-title { font-size: 15px; font-weight: 700; color: var(--primary-d); margin: 20px 0 10px; display:flex; align-items:center; gap:8px; }
.section-title::before { content:""; width:5px; height:16px; background:var(--accent); border-radius:3px; }
.setting-field { margin-bottom: 12px; }
.setting-field label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 5px; font-weight:600; }
.setting-field input, .setting-field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; font-size: 15px; font-family: inherit; background: var(--surface-2); box-sizing: border-box; transition: border-color .15s, box-shadow .15s;
}
.setting-field input:focus, .setting-field textarea:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 3px rgba(194,145,47,.15); background:#fff; }
.danger-zone { border: 1px solid #eccfca; border-radius: var(--radius); padding: 16px; margin-top: 20px; background: #fff6f4; }
.danger-zone h3 { color: var(--danger); margin: 0 0 10px; font-size: 14px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: 72px; transform: translateX(-50%) translateY(-8px); z-index: 99;
  background: rgba(40,28,12,.94); color: #fff; padding: 11px 20px; border-radius: 24px; font-size: 14px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; max-width: 86%; box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 空状态 ---------- */
.empty { text-align: center; color: var(--muted); padding: 44px 20px; font-size: 14px; }
.empty .big { font-size: 44px; margin-bottom: 12px; opacity:.8; }
.empty .act { margin-top: 14px; }

/* ---------- 概览仪表盘 ---------- */
.dash-hero {
  background: linear-gradient(135deg, var(--primary), var(--primary-d)); color:#fdf6e6;
  border-radius: 18px; padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; position:relative; overflow:hidden;
}
.dash-hero::after{ content:"家"; position:absolute; right:-10px; bottom:-30px; font-size:140px; opacity:.08; font-weight:700; }
.dash-hero .dh-name { font-size: 22px; font-weight: 800; letter-spacing:1px; }
.dash-hero .dh-sub { font-size: 13px; opacity:.85; margin-top:4px; }
.dash-hero .dh-stats { display:flex; gap:16px; margin-top:16px; flex-wrap:wrap; }
.dash-hero .dh-stat .n { font-size: 26px; font-weight:800; }
.dash-hero .dh-stat .l { font-size: 12px; opacity:.85; }
.dash-cards { display:grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.dash-card { background: var(--surface); border:1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-sm); }
.dash-card .dc-t { font-size:12px; color:var(--muted); font-weight:600; }
.dash-card .dc-n { font-size: 24px; font-weight:800; color:var(--primary-d); margin-top:4px; }
.dash-card .dc-bar { height:8px; border-radius:5px; background:var(--surface-2); overflow:hidden; margin-top:10px; display:flex; }
.dash-card .dc-bar i { display:block; height:100%; }
.dash-gen { background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); padding:14px 16px; box-shadow:var(--shadow-sm); }
.dash-gen .dg-row { display:flex; align-items:center; gap:10px; padding:7px 0; }
.dash-gen .dg-dot { width:12px; height:12px; border-radius:4px; flex:0 0 auto; }
.dash-gen .dg-label { font-size:14px; color:var(--ink-soft); width:110px; }
.dash-gen .dg-bar { flex:1; height:10px; border-radius:6px; background:var(--surface-2); overflow:hidden; }
.dash-gen .dg-bar i { display:block; height:100%; border-radius:6px; }
.dash-gen .dg-num { font-size:13px; font-weight:700; color:var(--primary-d); width:34px; text-align:right; }

/* ---------- 登录 / 注册 ---------- */
.overlay.login { background: linear-gradient(160deg,#f3e7cf,#e7d4ad); z-index: 200; align-items: center; }
.login-box {
  width: min(380px, 92vw); background: #fff; border-radius: 22px; padding: 30px 26px;
  box-shadow: 0 22px 60px rgba(80,60,20,.28); text-align: center; border: 1px solid rgba(216,202,169,.6);
}
.login-logo { font-size: 48px; filter: drop-shadow(0 4px 8px rgba(168,122,46,.3)); }
.login-box h1 { font-size: 23px; margin: 8px 0 2px; color: var(--ink); letter-spacing:1px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.login-box input {
  width: 100%; box-sizing: border-box; padding: 13px 14px; margin-bottom: 12px;
  border: 1px solid #e0d6bd; border-radius: 11px; font-size: 15px; background: #faf7ef; transition: border-color .15s, box-shadow .15s;
}
.login-box input:focus { outline: none; border-color: var(--accent); box-shadow:0 0 0 3px rgba(194,145,47,.15); }
.login-box .btn { width: 100%; padding: 13px; font-size: 16px; margin-bottom: 8px; }
.login-msg { min-height: 18px; font-size: 13px; margin: 2px 0 6px; }
.login-msg.err { color: var(--danger); }
.login-msg.ok { color: var(--ok); }
.link { background: none; border: none; color: var(--accent-d); font-size: 13px; cursor: pointer; text-decoration: underline; padding: 4px; }
.reg-divider { color: var(--muted); font-size: 12px; margin: 10px 0; }

/* ---------- 用户管理（管理员） ---------- */
.user-add { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.user-add input, .user-add select {
  padding: 11px 12px; border: 1px solid #e0d6bd; border-radius: 11px; font-size: 14px; background: #faf7ef; box-sizing: border-box; width: 100%;
}
.user-add #nuAdd { grid-column: 1 / -1; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px; border: 1px solid #ece3cc; border-radius: 13px; margin-bottom: 10px; background: #fff; flex-wrap: wrap; box-shadow: var(--shadow-sm); }
.user-row .u-main { font-size: 14px; }
.user-row .u-ops { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-row .u-role { padding: 7px 9px; border-radius: 9px; border: 1px solid #e0d6bd; background: #faf7ef; font-size: 13px; }
.tag.me { background: var(--accent); color: #fff; }
.role-badge { font-size:11px; padding:2px 9px; border-radius:20px; font-weight:600; }
.role-badge.admin { background: rgba(138,94,40,.15); color: var(--primary-d); }
.role-badge.editor { background: rgba(59,110,168,.15); color: var(--male); }
.role-badge.viewer { background: rgba(153,138,114,.18); color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; line-height: 1.7; margin-top: 12px; }

/* 未登录时仅显示登录层，隐藏应用主体 */
body:not(.logged-in) .app-header,
body:not(.logged-in) .content,
body:not(.logged-in) .tabbar,
body:not(.logged-in) .fab { display: none !important; }

/* ---------- 平板及以上 ---------- */
@media (min-width: 640px) {
  .member-grid { grid-template-columns: 1fr 1fr; }
  .export-grid { grid-template-columns: repeat(4, 1fr); }
  .dash-cards { grid-template-columns: repeat(4, 1fr); }
  .overlay { align-items: center; }
  .drawer { border-radius: 20px; }
  .tree-viewport { height: 70vh; }
}
@media (min-width: 980px) {
  .member-grid { grid-template-columns: 1fr 1fr 1fr; }
}
