/* ═══════════════════════════════════════════
   style.css — 程氏家族电子族谱样式
   设计理念：传统中国风 + 现代简约
   配色：深红 #8B1A2B  金色 #D4A574  象牙白 #F5F0E8
   ═══════════════════════════════════════════ */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #8B1A2B;
  --primary-light: #B84A5A;
  --primary-dark: #5C0F1B;
  --gold: #D4A574;
  --gold-light: #E8D5B7;
  --gold-dark: #C9A96E;
  --ivory: #F5F0E8;
  --ivory-dark: #E8DFD0;
  --bg: #FBF8F4;
  --bg-dark: #1a1a2e;
  --text: #2C1810;
  --text-light: #6B5B4F;
  --text-muted: #9B8B7F;
  --white: #FFFFFF;
  --male-blue: #1a3a5c;
  --male-blue-light: #2c5f8a;
  --female-red: #8B1A2B;
  --deceased: #555;
  --border: #E0D5C1;
  --shadow: 0 2px 12px rgba(139, 26, 43, 0.08);
  --shadow-lg: 0 8px 32px rgba(139, 26, 43, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── App Layout ── */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ── Sidebar ── */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: linear-gradient(180deg, #2C1810 0%, #3D2317 100%);
  color: var(--gold-light);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(212, 165, 116, 0.2);
  user-select: none;
}

.sidebar-header {
  padding: 24px 20px 20px;
  text-align: center;
  border-bottom: 1px solid rgba(212, 165, 116, 0.15);
}

.sidebar-logo {
  font-size: 36px;
  margin-bottom: 8px;
}

.sidebar-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 2px;
  font-family: "STKaiti", "KaiTi", "楷体", serif;
}

.sidebar-header .subtitle {
  font-size: 11px;
  color: var(--gold-light);
  opacity: 0.6;
  margin-top: 4px;
  letter-spacing: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  color: rgba(232, 213, 183, 0.7);
  cursor: pointer;
  transition: var(--transition);
  border-left: 3px solid transparent;
  font-size: 14px;
}

.nav-tab:hover {
  background: rgba(212, 165, 116, 0.08);
  color: var(--gold-light);
}

.nav-tab.active {
  background: rgba(212, 165, 116, 0.12);
  color: var(--gold);
  border-left-color: var(--gold);
  font-weight: 600;
}

.nav-tab .nav-icon { font-size: 18px; width: 24px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(212, 165, 116, 0.15);
  font-size: 12px;
}

.admin-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(212, 165, 116, 0.15);
  border-radius: var(--radius-sm);
  color: var(--gold);
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition);
}

.admin-badge:hover { background: rgba(212, 165, 116, 0.25); }

.admin-actions { display: flex; gap: 6px; margin-top: 8px; }

.admin-actions .btn-text {
  background: none; border: none; color: rgba(232, 213, 183, 0.6);
  cursor: pointer; font-size: 11px; padding: 4px 8px; border-radius: 4px;
  transition: var(--transition);
}
.admin-actions .btn-text:hover { color: var(--gold); background: rgba(255,255,255,0.05); }

/* ── Main Content ── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 10;
  gap: 12px;
}

.toolbar-left { display: flex; align-items: center; gap: 12px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }

.toolbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: 1px;
  font-family: "STKaiti", "KaiTi", "楷体", serif;
}

.toolbar-stats { font-size: 12px; color: var(--text-muted); }

.toolbar-divider {
  width: 1px; height: 24px;
  background: var(--border);
  margin: 0 8px;
}

.zoom-group {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--ivory);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.zoom-group .btn-icon {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: var(--text-light); font-size: 16px; border-radius: 6px;
  transition: var(--transition);
}
.zoom-group .btn-icon:hover { background: var(--ivory-dark); color: var(--text); }
.zoom-level { font-size: 11px; color: var(--text-muted); width: 40px; text-align: center; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: var(--transition); font-family: inherit;
}

.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(139, 26, 43, 0.3); }

.btn-gold { background: linear-gradient(135deg, var(--gold-dark), var(--gold)); color: var(--text); }
.btn-gold:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(201, 169, 110, 0.4); }

.btn-outline { background: var(--white); color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: var(--ivory); }

.btn-danger-outline { background: var(--white); color: #d32f2f; border: 1px solid #d32f2f; }
.btn-danger-outline:hover { background: #fff5f5; }

.btn-sm { padding: 4px 12px; font-size: 12px; }

.btn-text { background: none; border: none; cursor: pointer; color: var(--primary); font-size: 12px; padding: 4px 8px; font-family: inherit; }
.btn-text:hover { text-decoration: underline; }
.btn-text.danger { color: #d32f2f; }

.btn-icon { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px; border-radius: 4px; transition: var(--transition); }
.btn-icon:hover { background: var(--ivory); }

/* ── View Panels ── */
.view-panel { display: none; flex: 1; overflow: hidden; }
.view-panel.active { display: flex; }

/* ── Tree View ── */
.tree-layout { display: flex; flex: 1; overflow: hidden; }

.tree-viewport {
  flex: 1; overflow: hidden; position: relative;
  background:
    radial-gradient(circle at 20% 30%, rgba(212,165,116,0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(139,26,43,0.03) 0%, transparent 50%),
    var(--ivory);
}

.tree-viewport-inner {
  width: 100%; height: 100%; overflow: hidden;
}

.detail-panel {
  width: 320px; min-width: 320px;
  background: var(--white);
  border-left: 1px solid var(--border);
  box-shadow: -2px 0 12px rgba(0,0,0,0.04);
  overflow-y: auto;
  padding: 20px;
}

.detail-panel h3 {
  font-size: 15px; color: var(--primary);
  margin-bottom: 16px; padding-bottom: 12px;
  border-bottom: 2px solid var(--gold-light);
  font-family: "STKaiti", "KaiTi", "楷体", serif;
  letter-spacing: 1px;
}

/* ── Member Detail ── */
.member-detail { }

.detail-header {
  display: flex; align-items: center; gap: 16px;
  padding: 16px; border-radius: var(--radius);
  margin-bottom: 16px;
}

.detail-header.male { background: linear-gradient(135deg, #f0f4f8, #dbe6f0); }
.detail-header.female { background: linear-gradient(135deg, #fdf0f3, #f8dbe0); }
.member-detail.deceased .detail-header { background: #f0f0f0; opacity: 0.85; }

.detail-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.detail-name h2 { font-size: 20px; color: var(--text); }
.detail-role { font-size: 12px; color: var(--text-light); }

.detail-body { }

.detail-row {
  display: flex; align-items: baseline; padding: 8px 0;
  border-bottom: 1px solid var(--ivory-dark);
  font-size: 13px;
}

.detail-row .label {
  width: 48px; min-width: 48px;
  color: var(--text-muted); font-size: 12px;
}

.detail-row .link {
  color: var(--primary); cursor: pointer;
  transition: var(--transition);
}
.detail-row .link:hover { color: var(--gold-dark); text-decoration: underline; }

.detail-bio {
  margin-top: 12px; padding: 12px;
  background: var(--ivory); border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text-light); line-height: 1.7;
}

.detail-actions {
  margin-top: 16px; display: flex; flex-wrap: wrap; gap: 6px;
  padding-top: 12px; border-top: 1px solid var(--border);
}

/* ── Member List ── */
.member-view { flex: 1; overflow-y: auto; padding: 20px 24px; }

.search-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--white);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.search-input {
  flex: 1; border: none; outline: none;
  font-size: 14px; background: transparent;
  font-family: inherit;
}

.gen-section { margin-bottom: 24px; }

.gen-title {
  font-size: 16px; font-weight: 600; color: var(--primary);
  margin-bottom: 12px; padding-left: 12px;
  border-left: 3px solid var(--gold);
  font-family: "STKaiti", "KaiTi", "楷体", serif;
  display: flex; align-items: baseline; gap: 8px;
}

.gen-count { font-size: 12px; color: var(--text-muted); font-weight: 400; }

.member-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 8px;
}

.member-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--white);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  cursor: pointer; transition: var(--transition);
  border: 1px solid transparent;
}

.member-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--gold-light);
}

.member-card.deceased { opacity: 0.75; }

.card-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}

.card-avatar.male { background: #e8f0f8; }
.card-avatar.female { background: #fde8ec; }

.card-info { flex: 1; min-width: 0; }
.card-name-line { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.card-name { font-size: 14px; font-weight: 600; color: var(--text); }
.card-spouse-name { font-size: 11px; font-weight: 400; color: var(--gold-dark); margin-left: 2px; }
.card-gen { font-size: 10px; color: var(--primary); background: rgba(139,26,43,0.06); padding: 1px 6px; border-radius: 3px; white-space: nowrap; }
.card-parentage { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.card-sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-years { font-size: 11px; color: var(--text-muted); }
.card-children { font-size: 11px; color: var(--text-light); }
.card-children-names { font-size: 11px; color: var(--text-muted); margin-top: 2px; line-height: 1.5; }
.card-role { font-size: 10px; color: var(--primary-light); background: rgba(184,74,90,0.08); padding: 0 5px; border-radius: 3px; }

.card-actions { flex-shrink: 0; }

/* ── Events Timeline ── */
.events-view { flex: 1; overflow-y: auto; padding: 20px 24px; }

.timeline {
  position: relative;
  padding-left: 32px;
}

.timeline::before {
  content: '';
  position: absolute; left: 12px; top: 0; bottom: 0;
  width: 2px; background: linear-gradient(180deg, var(--gold), var(--primary), var(--gold));
}

.timeline-item {
  position: relative; margin-bottom: 24px;
}

.timeline-dot {
  position: absolute; left: -26px; top: 6px;
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--white);
  box-shadow: 0 0 0 2px currentColor;
}

.timeline-dot.founding { color: var(--primary); background: var(--primary); }
.timeline-dot.birthday { color: #4CAF50; background: #4CAF50; }
.timeline-dot.wedding { color: #FF9800; background: #FF9800; }
.timeline-dot.death { color: #795548; background: #795548; }
.timeline-dot.other { color: #607D8B; background: #607D8B; }

.timeline-content {
  background: var(--white); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow);
  transition: var(--transition);
}

.timeline-item.latest .timeline-content {
  border-left: 3px solid var(--gold);
}

.timeline-date { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.timeline-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.timeline-type { font-size: 12px; color: var(--primary); margin-bottom: 4px; }
.timeline-member { font-size: 12px; color: var(--text-light); }
.timeline-desc { font-size: 13px; color: var(--text-light); margin-top: 8px; line-height: 1.6; }
.timeline-actions { margin-top: 8px; display: flex; gap: 8px; }

/* ── Settings View ── */
.settings-view { flex: 1; overflow-y: auto; padding: 20px 24px; }

.settings-section {
  background: var(--white); border-radius: var(--radius);
  padding: 20px 24px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.settings-section h3 {
  font-size: 15px; color: var(--primary);
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 1px solid var(--ivory-dark);
  font-family: "STKaiti", "KaiTi", "楷体", serif;
}

.stats-grid {
  display: flex; gap: 16px; flex-wrap: wrap;
}

.stat-item {
  flex: 1; min-width: 80px;
  text-align: center; padding: 12px;
  background: var(--ivory); border-radius: var(--radius-sm);
}

.stat-val {
  display: block; font-size: 24px; font-weight: 700;
  color: var(--primary);
}

.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.settings-field {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px;
}

.settings-field label {
  width: 100px; font-size: 13px; color: var(--text-light); flex-shrink: 0;
}

.settings-field input {
  flex: 1; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; font-family: inherit; outline: none;
  transition: var(--transition);
}
.settings-field input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212,165,116,0.15); }

.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Modal ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(44, 24, 16, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100; align-items: center; justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal-dialog {
  width: 480px; max-width: 90vw; max-height: 85vh;
  background: var(--white); border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  overflow: hidden; display: flex; flex-direction: column;
  animation: modalIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 16px; color: var(--primary);
  font-family: "STKaiti", "KaiTi", "楷体", serif;
}

.modal-close {
  width: 32px; height: 32px; border: none; background: none;
  cursor: pointer; font-size: 20px; color: var(--text-muted);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.modal-close:hover { background: var(--ivory); color: var(--text); }

.modal-body { padding: 20px; overflow-y: auto; flex: 1; }

.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

/* ── Form ── */
.modal-form { }

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block; font-size: 12px; color: var(--text-light);
  margin-bottom: 4px; font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; font-family: inherit; outline: none;
  background: var(--white); transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212, 165, 116, 0.12);
}

.form-group textarea { resize: vertical; min-height: 60px; }

.form-row { display: flex; gap: 12px; }
.flex-1 { flex: 1; }

.login-icon { text-align: center; font-size: 36px; margin-bottom: 8px; }

.confirm-content { text-align: center; }
.confirm-msg { color: var(--text-light); font-size: 13px; margin-top: 8px; line-height: 1.6; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%) translateY(100px);
  padding: 10px 24px; border-radius: 24px;
  font-size: 13px; font-weight: 500;
  color: var(--white); z-index: 200;
  pointer-events: none; opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.active { opacity: 1; transform: translateX(-50%) translateY(0); }

.toast-success { background: rgba(76, 175, 80, 0.9); backdrop-filter: blur(10px); }
.toast-error { background: rgba(211, 47, 47, 0.9); backdrop-filter: blur(10px); }

/* ── Empty State ── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; text-align: center;
}

.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }

.empty-state h3 { font-size: 16px; color: var(--text-light); margin-bottom: 8px; }

.empty-state p { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

/* ── Text helpers ── */
.text-muted { color: var(--text-muted); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ivory-dark); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* ── SVG Tree ── */
.tree-svg { display: block; }

.tree-node { transition: opacity 0.2s; }
.tree-node:hover { opacity: 0.9; }
.tree-line { transition: stroke-opacity 0.2s; }

.gen-label {
  font-family: "STKaiti", "KaiTi", "楷体", serif;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .sidebar { width: 60px; min-width: 60px; }
  .sidebar-header { padding: 12px 8px; }
  .sidebar-header h1, .sidebar-header .subtitle { display: none; }
  .sidebar-logo { font-size: 24px; }
  .nav-tab { padding: 12px 8px; justify-content: center; }
  .nav-tab span:not(.nav-icon) { display: none; }
  .sidebar-footer { padding: 12px 8px; text-align: center; }
  .admin-badge span { display: none; }
  .detail-panel { width: 280px; min-width: 280px; }
  .toolbar { padding: 10px 16px; }
  .toolbar-title { display: none; }
}
