/* ===== 设计令牌 ===== */
:root {
  --bg: #f7f5ef;
  --bg-grad: radial-gradient(1200px 600px at 0% 0%, #efe9dc 0%, transparent 60%),
             radial-gradient(900px 600px at 100% 0%, #e7eee9 0%, transparent 55%),
             #f7f5ef;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --border: #e6e1d6;
  --border-strong: #cfc7b3;
  --text: #1f2024;
  --text-muted: #6b6a63;
  --text-faint: #98968d;

  --primary: #2f5a52;
  --primary-hover: #3a6e64;
  --primary-soft: #e2ece9;
  --accent: #b78a4d;
  --accent-soft: #f4ead7;

  --danger: #b3382f;
  --danger-soft: #f7e2df;
  --male: #3d6996;
  --male-soft: #e3edf7;
  --female: #b14b76;
  --female-soft: #fae3ee;
  --other: #6b6a63;
  --other-soft: #ececea;

  --avatar-male: linear-gradient(135deg, #4d7eaf, #3d6996);
  --avatar-female: linear-gradient(135deg, #c75d8a, #b14b76);
  --avatar-other: linear-gradient(135deg, #8a8a82, #6b6a63);

  --shadow-sm: 0 1px 2px rgba(31,32,36,0.04), 0 1px 1px rgba(31,32,36,0.04);
  --shadow-md: 0 4px 12px rgba(31,32,36,0.06), 0 2px 4px rgba(31,32,36,0.05);
  --shadow-lg: 0 16px 40px rgba(31,32,36,0.12), 0 6px 16px rgba(31,32,36,0.06);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --header-h: 64px;
  --tabs-h: 48px;
}

/* ===== 暗色主题 ===== */
[data-theme="dark"] {
  --bg: #161513;
  --bg-grad: radial-gradient(1200px 600px at 0% 0%, #1f1d1a 0%, transparent 60%),
             radial-gradient(900px 600px at 100% 0%, #1a201f 0%, transparent 55%),
             #161513;
  --surface: #232220;
  --surface-2: #2b2926;
  --border: #3a3833;
  --border-strong: #4d4a44;
  --text: #ece9e0;
  --text-muted: #a8a39a;
  --text-faint: #7a766f;

  --primary: #62a89a;
  --primary-hover: #74bdaf;
  --primary-soft: #2a4541;
  --accent: #d4a877;
  --accent-soft: #4a3d28;

  --danger: #d65448;
  --danger-soft: #4a2826;
  --male: #6a9bcc;
  --male-soft: #2a3a4d;
  --female: #d676a3;
  --female-soft: #4a2a3a;
  --other: #a09a8e;
  --other-soft: #3a3833;

  --avatar-male: linear-gradient(135deg, #5e84a8, #4d6e8c);
  --avatar-female: linear-gradient(135deg, #b8628a, #9a4a72);
  --avatar-other: linear-gradient(135deg, #9a9a92, #7b7a73);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
  --shadow-lg: 0 16px 40px rgba(0,0,0,0.5);
}

[data-theme="dark"] .app-header {
  background: rgba(35,34,32,0.85);
}
[data-theme="dark"] .tree-container {
  background:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,0.04) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--surface-2);
}
[data-theme="dark"] .tree-edges path.edge { stroke: #5a5246; }
[data-theme="dark"] .tree-edges path.edge.spouse { stroke: #8a7240; }
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,0.6); }
[data-theme="dark"] .tooltip { background: rgba(0,0,0,0.92); }
[data-theme="dark"] mark { background: var(--accent-soft) !important; color: var(--accent) !important; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Hiragino Sans GB", "Source Han Sans CN", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; }

/* ===== 顶栏 ===== */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(160%) blur(8px);
  -webkit-backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.brand-icon {
  width: 28px; height: 28px;
  color: var(--primary);
}
.brand h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.5px;
}
.brand-sub {
  color: var(--text-faint);
  font-size: 11px;
  letter-spacing: 1px;
  font-weight: 500;
  text-transform: uppercase;
  margin-left: 2px;
}

.search {
  position: relative;
  flex: 1;
  max-width: 480px;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 14px;
  height: 38px;
  transition: box-shadow .15s, border-color .15s;
}
.search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.search svg {
  width: 16px; height: 16px;
  color: var(--text-faint);
  flex-shrink: 0;
}
.search input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  margin-left: 8px;
  color: var(--text);
}
.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 360px;
  overflow-y: auto;
  z-index: 200;
}
.search-dropdown .search-item {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.search-dropdown .search-item:last-child { border-bottom: none; }
.search-dropdown .search-item:hover { background: var(--surface-2); }
.search-dropdown .search-item .si-name { font-weight: 500; }
.search-dropdown .search-item .si-sub { color: var(--text-muted); font-size: 12px; margin-left: auto; }
.search-dropdown .search-empty { padding: 14px; color: var(--text-muted); text-align: center; }

.header-actions { display: flex; align-items: center; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s ease;
  white-space: nowrap;
  text-decoration: none;
}
.btn svg { width: 14px; height: 14px; }
.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger-soft);
}
.btn-danger:hover { background: var(--danger-soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== 标签页 ===== */
.tabs {
  height: var(--tabs-h);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--header-h);
  z-index: 90;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 32px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
}
.tab svg { width: 14px; height: 14px; }
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active {
  background: var(--primary-soft);
  color: var(--primary);
}
.tabs-status {
  margin-left: auto;
  color: var(--text-faint);
  font-size: 12px;
}

/* ===== 主区域 ===== */
.app-main {
  min-height: calc(100vh - var(--header-h) - var(--tabs-h) - 36px);
  position: relative;
}
.view {
  display: none;
  min-height: calc(100vh - var(--header-h) - var(--tabs-h) - 36px);
  overflow: hidden;
}
.view.active { display: block; }

/* ===== 列表视图 ===== */
#view-list { overflow-y: auto; padding: 28px 32px 60px; }

.members-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

.member-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  cursor: pointer;
  transition: all .2s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}
.member-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--border-strong);
}
.member-card.deceased { opacity: 0.85; }

.mc-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ===== 头像 ===== */
.avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  color: white;
  flex-shrink: 0;
  background-color: var(--other);
  background-image: var(--avatar-other);
  background-size: cover;
  background-position: center;
}
.avatar.male {
  background-color: var(--male);
  background-image: var(--avatar-male);
}
.avatar.female {
  background-color: var(--female);
  background-image: var(--avatar-female);
}
.avatar.other {
  background-color: var(--other);
  background-image: var(--avatar-other);
}
.avatar.large { width: 64px; height: 64px; font-size: 22px; }

/* 关键修复：上传过头像后，渐变色被覆盖为图片，文字隐去。
   原来旧 CSS 用 background 简写来设置颜色，简写会重置 background-image / position / size，
   导致暗模式下头像缩成左上角小图甚至看不到。
   现在统一改用 background-image + background-color 长写法（见上面的 .avatar.male/female/other），
   让内联的 style="background-image:url(...)" 始终生效；
   下面这条只负责裁剪/对齐和把首字母文字隐藏。 */
.avatar.has-photo {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: transparent;
}

.mc-name-row {
  flex: 1;
  min-width: 0;
}
.mc-name {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 2px;
}
.gender-pill {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 500;
}
.gender-pill.male { background: var(--male-soft); color: var(--male); }
.gender-pill.female { background: var(--female-soft); color: var(--female); }
.gender-pill.other { background: var(--other-soft); color: var(--other); }
.deceased-tag {
  font-size: 11px;
  color: var(--text-faint);
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.mc-sub {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mc-info {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mc-info .row {
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.mc-info .row .lbl { color: var(--text-faint); flex-shrink: 0; min-width: 56px; }
.mc-info .row .val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mc-relations {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--text-faint);
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}
.mc-relations span b { color: var(--text-muted); font-weight: 600; }

/* ===== 空状态 ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
}
.empty-illust { font-size: 64px; margin-bottom: 16px; }
.empty-state h2 { margin: 0 0 8px; font-size: 22px; font-weight: 600; }
.empty-state p { color: var(--text-muted); margin: 0 0 24px; max-width: 360px; }

/* ===== 树视图 ===== */
.tree-toolbar {
  height: 44px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tree-toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tree-toolbar-group .hint { color: var(--text-faint); font-size: 12px; margin-left: 8px; }
.tree-toolbar-group:nth-child(2) { flex: 1; }

.icon-btn {
  height: 30px;
  min-width: 30px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }

.tree-container {
  position: relative;
  width: 100%;
  height: calc(100vh - var(--header-h) - var(--tabs-h) - 44px - 36px);
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.06) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--surface-2);
  cursor: grab;
}
.tree-container.dragging { cursor: grabbing; }

.tree-canvas {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.tree-edges {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  overflow: visible;
}
.tree-edges path.edge {
  fill: none;
  stroke: #b8ad97;
  stroke-width: 1.5;
  transition: stroke .2s, opacity .2s, stroke-width .2s;
}
.tree-edges path.edge.spouse {
  stroke: #d6b97f;
  stroke-dasharray: 4 4;
}
.tree-edges path.edge.dim { opacity: 0.15; }
.tree-edges path.edge.highlight {
  stroke: var(--primary);
  stroke-width: 2.5;
  opacity: 1;
}

.tree-nodes { position: relative; }

.tree-node {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  width: 160px;
  min-height: 64px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all .2s ease, opacity .2s;
  display: flex;
  align-items: center;
  gap: 10px;
}
.tree-node:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  border-color: var(--border-strong);
}
.tree-node .avatar { width: 36px; height: 36px; font-size: 14px; }
.tree-node .tn-info { flex: 1; min-width: 0; }
.tree-node .tn-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-node .tn-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-node.male { border-left: 3px solid var(--male); }
.tree-node.female { border-left: 3px solid var(--female); }
.tree-node.other { border-left: 3px solid var(--other); }
.tree-node.deceased { opacity: 0.8; }
.tree-node.deceased .tn-name::after {
  content: " ✦";
  color: var(--text-faint);
  font-weight: normal;
}

.tree-node.dim { opacity: 0.18; filter: grayscale(0.6); }
.tree-node.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(47,90,82,0.18), var(--shadow-md);
  transform: translateY(-1px);
}
.tree-node.path-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow-md);
}

.tree-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  pointer-events: none;
}

.tooltip {
  position: fixed;
  background: rgba(31,32,36,0.96);
  color: white;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.6;
  pointer-events: none;
  z-index: 300;
  max-width: 240px;
  box-shadow: var(--shadow-lg);
}
.tooltip .tt-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; gap: 6px; }
.tooltip .tt-row .lbl { color: rgba(255,255,255,0.6); min-width: 40px; }
.tooltip .tt-row .val.unknown { color: rgba(255,255,255,0.5); font-style: italic; }

.relationship-banner {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 12px 22px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 50;
  max-width: 90%;
}
.relationship-banner .rb-name { font-weight: 600; color: var(--primary); }
.relationship-banner .rb-arrow { color: var(--text-faint); }
.relationship-banner .rb-rel {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 500;
  font-size: 13px;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(31,32,36,0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeIn .15s ease;
}
.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-xl);
  width: 92%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: popIn .18s cubic-bezier(.4,1.6,.6,1);
}
.modal-content.modal-large { max-width: 820px; }
.modal-content.modal-small { max-width: 400px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-close {
  border: none;
  background: transparent;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
}
.footer-spacer { flex: 1; }

/* ===== 表单 ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px 18px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.field .required { color: var(--danger); }
.field .hint-inline { color: var(--text-faint); font-weight: normal; }
.field input[type="text"],
.field input[type="tel"],
.field input[type="date"],
.field input[type="number"],
.field input[type="password"],
.field textarea,
.field select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field textarea { resize: vertical; }

.radio-group { display: flex; gap: 10px; padding-top: 4px; }
.radio-group label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.radio-group input { margin: 0; }

.section-title {
  margin-top: 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.section-desc {
  color: var(--text-muted);
  font-size: 12px;
  margin: 6px 0 12px;
}

.relations-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.relation-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.relation-head {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}
.relation-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
  margin-bottom: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px 3px 10px;
  font-size: 12px;
}
.chip .chip-x {
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
}
.chip .chip-x:hover { color: var(--danger); }
.relation-picker select {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

/* ===== 详情 ===== */
.detail-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}
.detail-head .name-block h3 {
  margin: 0;
  font-size: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.detail-head .name-block .sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}
.detail-section { margin-top: 16px; }
.detail-section .ds-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.detail-rows .row {
  display: flex;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.detail-rows .row:last-child { border-bottom: none; }
.detail-rows .lbl {
  color: var(--text-muted);
  min-width: 80px;
  font-size: 13px;
}
.detail-rows .val { flex: 1; font-size: 13px; }
.detail-rows .val.unknown { color: var(--text-faint); font-style: italic; }
.detail-rel-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.detail-rel-list .chip { cursor: pointer; }
.detail-rel-list .chip:hover { background: var(--primary-soft); border-color: var(--primary); }
.detail-rel-list .empty { color: var(--text-faint); font-size: 12px; font-style: italic; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, -8px); }

/* ===== 提示横幅（提交说明）===== */
.submit-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 18px;
}
.submit-banner svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ===== 头像上传器 ===== */
.photo-uploader {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 18px;
}
.photo-preview {
  width: 88px; height: 88px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px dashed var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
  transition: border-color .15s, background .15s;
}
.photo-preview:hover { border-color: var(--primary); }
.photo-preview.drag-over {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.photo-preview img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.photo-placeholder {
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  padding: 4px;
  pointer-events: none;
}
.photo-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
.photo-hint { font-size: 11px; color: var(--text-faint); }

/* ===== 自动填充提示动画 ===== */
.field input.auto-filled {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
  animation: autoFillFlash 1.8s ease-out;
}
@keyframes autoFillFlash {
  0%   { background: var(--accent); color: white; }
  20%  { background: var(--accent-soft); }
  100% { background: var(--surface); }
}

/* ===== 生日提醒 ===== */
.birthdays-wrap { position: relative; }
.icon-bell {
  position: relative;
  width: 36px; height: 36px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.icon-bell svg { width: 18px; height: 18px; }
.icon-bell:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.icon-bell.has-items { color: var(--accent); }
.icon-bell.has-items:hover { background: var(--accent-soft); }
.icon-bell .badge {
  position: absolute;
  top: 2px; right: 2px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 600;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.birthdays-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 320px;
  max-height: 420px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 200;
}
.bp-head {
  padding: 12px 16px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.bp-list {
  overflow-y: auto;
  flex: 1;
}
.bd-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}
.bd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.bd-item:last-child { border-bottom: none; }
.bd-item:hover { background: var(--surface-2); }
.bd-item.today {
  background: linear-gradient(90deg, var(--accent-soft), transparent);
}
.bd-item .avatar {
  width: 36px; height: 36px;
  font-size: 13px;
}
.bd-info { flex: 1; min-width: 0; }
.bd-name {
  font-weight: 500;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.bd-turning {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 500;
}
.bd-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== 状态栏标签 ===== */
.storage-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}
.storage-tag.file {
  background: var(--primary-soft);
  color: var(--primary);
}

/* ===== 阴历输入 ===== */
.lunar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.lunar-row input[type="text"] { flex: 1; max-width: 200px; }
.lunar-leap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.lunar-leap input { margin: 0; }
.lunar-hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.lunar-hint.ok { color: var(--primary); }
.lunar-hint.warn { color: var(--accent); }
.lunar-hint.err { color: var(--danger); }

/* ===== 主题切换按钮 ===== */
.icon-btn-round {
  width: 36px; height: 36px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.icon-btn-round svg { width: 18px; height: 18px; }
.icon-btn-round:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

/* ===== 页面底部 - 管理员入口 ===== */
.page-footer {
  display: flex;
  justify-content: center;
  padding: 18px 20px;
  margin-top: 20px;
}
.admin-entry {
  color: var(--text-faint);
  font-size: 11px;
  text-decoration: none;
  letter-spacing: 0.5px;
  transition: color .15s;
}
.admin-entry:hover {
  color: var(--text-muted);
  text-decoration: underline;
}

/* ===== Modal 消息支持换行 ===== */
#confirm-message { white-space: pre-line; }

/* ===== 通用 ===== */
.hidden { display: none !important; }

/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.3); background-clip: padding-box; border: 2px solid transparent; }

/* ===== 响应式 ===== */

/* 让搜索框和品牌可以正常收缩，避免把右侧按钮挤出屏幕 */
.search { min-width: 0; }
.brand { min-width: 0; }
.brand h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { flex-shrink: 0; }

/* 中等屏幕（小型笔记本 / 平板）：缩短搜索框，隐藏品牌副标题 */
@media (max-width: 960px) {
  .search { max-width: 360px; }
  .brand-sub { display: none; }
}

/* 手机：紧凑头部，把"提交新成员"按钮缩成圆形图标按钮 */
@media (max-width: 720px) {
  /* 头部整体压缩 */
  .app-header {
    padding: 0 10px;
    gap: 8px;
  }
  .brand { gap: 6px; }
  .brand h1 { font-size: 16px; }
  .brand-icon { width: 24px; height: 24px; }

  /* 搜索框可被压缩到很窄 */
  .search {
    max-width: none;
    height: 36px;
    padding: 0 12px;
  }
  .search input {
    font-size: 13px;
    margin-left: 6px;
    min-width: 0;
    width: 100%;
  }

  /* 操作按钮紧凑化 */
  .header-actions { gap: 4px; }
  .icon-btn-round,
  .icon-bell {
    width: 34px;
    height: 34px;
  }
  .icon-btn-round svg,
  .icon-bell svg { width: 16px; height: 16px; }

  /* 关键修复：把"提交新成员"按钮收成圆形图标按钮，文字隐藏 */
  .header-actions .btn-primary {
    padding: 0;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    justify-content: center;
    flex-shrink: 0;
  }
  .header-actions .btn-primary svg {
    width: 16px;
    height: 16px;
  }
  .header-actions .btn-primary .btn-text {
    display: none;
  }

  /* 标签页 */
  .tabs { padding: 0 10px; }
  .tab { padding: 0 10px; font-size: 12px; }
  .tabs-status { display: none; }

  /* 列表 */
  #view-list { padding: 16px 12px 60px; }
  .members-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
  }

  /* 表单单列 */
  .form-grid { grid-template-columns: 1fr; }
  .relations-grid { grid-template-columns: 1fr; }

  /* 阴历输入允许换行 */
  .lunar-row { flex-wrap: wrap; gap: 8px; }
  .lunar-row > * { margin-left: 0 !important; }
  .lunar-row input,
  .lunar-row select { width: auto !important; flex: 1 1 90px; min-width: 90px; }
  .lunar-leap { flex: 1 1 auto; }

  /* 树视图工具栏可横向滚动，避免内容被裁掉 */
  .tree-toolbar {
    padding: 0 10px;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tree-toolbar-group:nth-child(2) .hint { display: none; }

  /* 树节点稍微缩小 */
  .tree-node {
    width: 140px;
    padding: 8px 10px;
  }
  .tree-node .avatar { width: 32px; height: 32px; font-size: 12px; }

  /* 生日浮窗：避免超出屏幕 */
  .birthdays-panel {
    width: calc(100vw - 20px);
    max-width: 320px;
    right: -4px;
  }

  /* Modal：占满更大比例，footer 允许换行 */
  .modal-content {
    width: 96%;
    max-height: 92vh;
    border-radius: 16px;
  }
  .modal-header { padding: 16px 18px 12px; }
  .modal-header h2 { font-size: 16px; }
  .modal-body { padding: 16px 18px; }
  .modal-footer {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 6px;
  }
  .footer-spacer { flex: 1 0 100%; height: 0; }

  /* 头像上传器 */
  .photo-uploader { gap: 12px; padding: 12px; }
  .photo-preview { width: 72px; height: 72px; }

  /* 关系横幅，避免遮挡 */
  .relationship-banner {
    padding: 8px 14px;
    font-size: 12px;
    bottom: 12px;
    max-width: calc(100% - 24px);
    flex-wrap: wrap;
    justify-content: center;
  }
}

/* 极窄屏（≤380px，老款手机 / 折叠机外屏） */
@media (max-width: 380px) {
  .app-header { padding: 0 8px; gap: 6px; }
  .brand h1 { font-size: 15px; }
  .brand-icon { width: 22px; height: 22px; }
  .search { padding: 0 10px; }
  .icon-btn-round,
  .icon-bell,
  .header-actions .btn-primary { width: 32px; height: 32px; }
}
