:root {
  --primary: #f59e0b;
  --primary-dark: #d97706;
  --bg: #faf6ef;
  --panel: #ffffff;
  --text: #2d2a26;
  --muted: #8a857d;
  --border: #e8e1d6;
  --male: #3b82f6;
  --female: #ec4899;
  --neutered: #10b981;
  --unneutered: #f59e0b;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

body { display: flex; flex-direction: column; }

/* ---------- 头部与标签页 ---------- */
.app-header {
  background: linear-gradient(135deg, #fff7ed, #ffedd5);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 10;
}

.app-title { font-size: 18px; font-weight: 700; }

.tab-bar { display: flex; gap: 6px; }

.tab-btn {
  border: 1px solid transparent;
  background: transparent;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}
.tab-btn:hover { background: #fff; color: var(--text); }
.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(245, 158, 11, .4);
}

/* ---------- 主区域 ---------- */
.app-main { flex: 1; position: relative; overflow: hidden; }

.view {
  position: absolute;
  inset: 0;
  display: none;
}
.view.active { display: flex; }

/* ---------- 地图视图 ---------- */
#map-view { flex-direction: row; }

.map-container { flex: 1; min-width: 0; background: #e5e0d8; }

.sidebar {
  width: 320px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-title {
  font-size: 14px;
  font-weight: 600;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.cat-list { flex: 1; overflow-y: auto; padding: 8px; }

/* 列表项 */
.cat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s;
}
.cat-item:hover, .cat-item:focus-visible {
  background: #fff7ed;
  border-color: #fde6c4;
  outline: none;
}

.cat-item-photo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: #ffd9a8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  position: relative;
}
.cat-item-photo img { width: 100%; height: 100%; object-fit: cover; }
.cat-item-fallback-icon,
.marker-fallback-icon { display: none; }
.cat-item-fallback .cat-item-fallback-icon { display: block; }
.cat-item-fallback img { display: none; }

.cat-item-info { min-width: 0; }
.cat-item-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.cat-item-area { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- 地图圆形标记 ---------- */
.cat-marker-wrapper { background: transparent; border: none; }
.cat-marker {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  background: #ffd9a8; /* 照片失败兜底底色 */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  position: relative;
}
.cat-marker img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cat-marker.marker-fallback img { display: none; }
.cat-marker.marker-fallback .marker-fallback-icon { display: block; }
.cat-marker:hover { transform: scale(1.08); box-shadow: 0 3px 10px rgba(0,0,0,.45); }

/* ---------- 关系图视图 ---------- */
#graph-view { flex-direction: column; }
.graph-container { flex: 1; min-height: 0; background: #fff; }

/* ---------- 详情弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal.open { display: flex; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  background: #fff;
  border-radius: 16px;
  width: min(460px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #f3eee6;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
.modal-close:hover { background: #e8e0d4; color: var(--text); }

.modal-header { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; }
.modal-photo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  background: #ffd9a8;
  flex-shrink: 0;
}
.modal-name { font-size: 20px; font-weight: 700; }
.modal-tags { display: flex; gap: 6px; margin-top: 6px; }
.modal-desc { color: var(--muted); font-size: 14px; margin-bottom: 12px; }

.modal-info {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-bottom: 12px;
}
.modal-info-row {
  display: flex;
  gap: 8px;
  padding: 3px 0;
  font-size: 13px;
}
.modal-info-key { color: var(--muted); width: 70px; flex-shrink: 0; }
.modal-info-val { flex: 1; }

.modal-section-title { font-size: 15px; margin-bottom: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.modal-relations { display: flex; flex-direction: column; gap: 6px; }
.relation-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  background: #faf6ef;
  border-radius: 8px;
  padding: 6px 10px;
  flex-wrap: wrap;
}
.relation-type { font-weight: 600; color: var(--primary-dark); }
.relation-other { font-weight: 500; }
.relation-note { color: var(--muted); font-size: 12px; }
.relation-empty { color: var(--muted); font-size: 13px; padding: 4px 0; }

/* ---------- 标签 ---------- */
.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  line-height: 1.6;
}
.tag-male { background: var(--male); }
.tag-female { background: var(--female); }
.tag-neutered { background: var(--neutered); }
.tag-unneutered { background: var(--unneutered); }
.tag-past { background: #9ca3af; }
.cat-item-nick { font-weight: 400; font-size: 12px; color: var(--muted); }
.cat-marker-past { filter: grayscale(0.85) opacity(0.75); }

/* ---------- 加载提示 ---------- */
.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .9);
  z-index: 2000;
  font-size: 16px;
  color: var(--muted);
}
.loading-error { color: #dc2626; }

/* ---------- 右下角 toast 提示 ---------- */
.toast {
  position: fixed;
  right: 20px;
  bottom: 24px;
  max-width: 320px;
  background: rgba(40, 40, 40, .92);
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 3000;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- 响应式：<768px 纵向布局 ---------- */
@media (max-width: 768px) {
  .app-header { flex-direction: column; align-items: stretch; text-align: center; }
  .tab-bar { justify-content: center; }

  #map-view { flex-direction: column; }
  .map-container { flex: 1; min-height: 0; }
  .sidebar {
    width: 100%;
    height: 38%;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
