:root,
[data-theme="light"] {
  --bg-primary: #f6f3ec;
  --bg-secondary: #ede7db;
  --bg-surface: #ffffff;
  --bg-elevated: #fcfaf5;
  --bg-canvas: #f2ede2;
  --canvas-grid: rgba(114, 98, 74, 0.09);

  --text-primary: #1d2420;
  --text-secondary: #4f5852;
  --text-muted: #7a827c;

  --accent-primary: #235340;
  --accent-primary-hover: #193e2f;
  --accent-soft: rgba(35, 83, 64, 0.11);
  --accent-gold: #a6762b;
  --accent-gold-soft: rgba(166, 118, 43, 0.14);

  --male-accent: #2563eb;
  --male-soft: rgba(37, 99, 235, 0.1);
  --female-accent: #c02669;
  --female-soft: rgba(192, 38, 105, 0.1);

  --border-subtle: #dcd4c4;
  --border-strong: #c4b9a3;
  --line-connector: #8f826d;
  --line-highlight: #a6762b;

  --shadow-sm: 0 2px 6px rgba(29, 36, 32, 0.06);
  --shadow-md: 0 8px 24px rgba(29, 36, 32, 0.1);
  --shadow-lg: 0 18px 42px rgba(29, 36, 32, 0.16);
}

[data-theme="dark"] {
  --bg-primary: #0f1512;
  --bg-secondary: #161f1b;
  --bg-surface: #1b2621;
  --bg-elevated: #223029;
  --bg-canvas: #121916;
  --canvas-grid: rgba(212, 175, 112, 0.06);

  --text-primary: #eef2ef;
  --text-secondary: #b4c0b8;
  --text-muted: #7c8b82;

  --accent-primary: #3b8a6b;
  --accent-primary-hover: #4ca381;
  --accent-soft: rgba(59, 138, 107, 0.18);
  --accent-gold: #d8a657;
  --accent-gold-soft: rgba(216, 166, 87, 0.18);

  --male-accent: #60a5fa;
  --male-soft: rgba(96, 165, 250, 0.15);
  --female-accent: #f472b6;
  --female-soft: rgba(244, 114, 182, 0.15);

  --border-subtle: #293830;
  --border-strong: #3b4f45;
  --line-connector: #586c61;
  --line-highlight: #d8a657;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.65);
}

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

html,
body {
  height: 100%;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ================= AUTH GATE ================= */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(circle at 50% 25%, var(--bg-secondary), var(--bg-primary));
}

.auth-backdrop-pattern {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--canvas-grid) 1.5px, transparent 1.5px);
  background-size: 24px 24px;
  pointer-events: none;
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 2.5rem 2.25rem 2rem;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.auth-lang-bar {
  position: absolute;
  top: 1.1rem;
  right: 1.1rem;
  display: flex;
  gap: 0.4rem;
}

.chip-btn {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip-btn:hover {
  border-color: var(--accent-gold);
  color: var(--text-primary);
}

.crest-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent-gold-soft);
  color: var(--accent-gold);
  margin-bottom: 1rem;
}

.auth-eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--accent-gold);
  margin-bottom: 0.35rem;
}

.auth-title {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-primary);
  margin-bottom: 0.65rem;
}

.auth-subtitle {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text-secondary);
  margin-bottom: 1.6rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.input-password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.auth-input {
  width: 100%;
  padding: 0.85rem 2.8rem 0.85rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  border-radius: 12px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.pass-vis-btn {
  position: absolute;
  right: 0.65rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.05rem;
  opacity: 0.65;
  padding: 0.25rem;
}

.pass-vis-btn:hover {
  opacity: 1;
}

.remember-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.auth-error {
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: rgba(220, 38, 38, 0.12);
  border: 1px solid rgba(220, 38, 38, 0.35);
  color: #dc2626;
  font-size: 0.84rem;
  font-weight: 500;
}

.primary-btn {
  padding: 0.9rem 1.25rem;
  border-radius: 12px;
  border: none;
  background: var(--accent-primary);
  color: #ffffff;
  font-size: 0.96rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.primary-btn:hover {
  background: var(--accent-primary-hover);
}

.primary-btn:active {
  transform: translateY(1px);
}

.auth-footer-note {
  margin-top: 1.35rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ================= MAIN APP SHELL ================= */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1.25rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 40;
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.brand-emblem {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.1;
}

.brand-meta {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Global Search */
.global-search-container {
  position: relative;
  flex: 1;
  max-width: 390px;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 0.8rem;
  font-size: 0.88rem;
  pointer-events: none;
  opacity: 0.65;
}

.global-search-input {
  width: 100%;
  padding: 0.55rem 2.2rem 0.55rem 2.25rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.86rem;
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
}

.global-search-input:focus {
  border-color: var(--accent-primary);
  background: var(--bg-surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-Shortcut {
  position: absolute;
  right: 0.75rem;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  background: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  pointer-events: none;
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 380px;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  padding: 0.4rem;
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s;
}

.search-result-item:hover {
  background: var(--bg-secondary);
}

.sr-main {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}

.sr-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.sr-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sr-badges {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

/* Navigation Tabs */
.main-nav {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg-primary);
  padding: 0.25rem;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.83rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--text-primary);
}

.nav-tab.active {
  background: var(--bg-surface);
  color: var(--accent-primary);
  box-shadow: var(--shadow-sm);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.icon-action-btn {
  height: 36px;
  min-width: 36px;
  padding: 0 0.6rem;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.icon-action-btn:hover {
  border-color: var(--accent-gold);
  background: var(--bg-secondary);
}

/* ================= VIEW SECTIONS ================= */
.view-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Tree Toolbar */
.tree-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 1.25rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.branches-scroll-wrap {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}

.branches-scroll-wrap::-webkit-scrollbar {
  display: none;
}

.toolbar-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}

.branch-pills {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.branch-pill {
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.77rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.branch-pill:hover {
  border-color: var(--accent-gold);
  color: var(--text-primary);
}

.branch-pill.active {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

.tree-controls-group {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.control-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 0.77rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.control-pill select {
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-weight: 700;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  outline: none;
}

.control-pill-btn {
  padding: 0.34rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--accent-gold);
  background: var(--accent-gold-soft);
  color: var(--accent-gold);
  font-size: 0.77rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.control-pill-btn:hover {
  background: var(--accent-gold);
  color: #fff;
}

/* Focus Banner */
.focus-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.42rem 1.25rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  flex-shrink: 0;
}

.focus-info {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.focus-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  background: var(--accent-gold-soft);
  color: var(--accent-gold);
}

.focused-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.focus-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.mini-btn {
  padding: 0.26rem 0.65rem;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.76rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.mini-btn:hover:not(:disabled) {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.mini-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Tree Viewport & Canvas */
.tree-viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  background-color: var(--bg-canvas);
  background-image: radial-gradient(var(--canvas-grid) 1.5px, transparent 1.5px);
  background-size: 24px 24px;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.tree-viewport.dragging {
  cursor: grabbing;
}

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

.tree-svg {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}

.tree-nodes-layer {
  position: absolute;
  top: 0;
  left: 0;
}

/* SVG Connector Paths */
.tree-link {
  fill: none;
  stroke: var(--line-connector);
  stroke-width: 2px;
  stroke-linecap: round;
  transition: stroke 0.2s;
}

.tree-link.ancestor-link {
  stroke-dasharray: none;
}

.tree-link.spouse-link {
  stroke: var(--accent-gold);
  stroke-width: 2.2px;
}

/* Tree Node Cards */
.tree-node-group {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: stretch;
  gap: 6px;
  z-index: 2;
}

.person-node {
  width: 194px;
  min-height: 76px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-subtle);
  border-left-width: 4px;
  border-radius: 12px;
  padding: 0.55rem 0.68rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
  position: relative;
}

.person-node:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-gold);
}

.person-node.sex-M {
  border-left-color: var(--male-accent);
}

.person-node.sex-F {
  border-left-color: var(--female-accent);
}

.person-node.is-focused {
  border: 2px solid var(--accent-gold);
  border-left-width: 5px;
  background: var(--bg-elevated);
  box-shadow: 0 0 0 4px var(--accent-gold-soft), var(--shadow-md);
}

.person-node.is-spouse {
  width: 174px;
  opacity: 0.95;
}

.node-top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.3rem;
}

.node-name {
  font-size: 0.81rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.25;
  word-break: break-word;
}

.node-surname {
  display: inline-block;
  font-size: 0.67rem;
  font-weight: 700;
  color: var(--accent-primary);
  background: var(--accent-soft);
  padding: 0.08rem 0.38rem;
  border-radius: 5px;
  margin-top: 0.18rem;
}

.node-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.4rem;
  font-size: 0.71rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.node-focus-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: 5px;
  padding: 0.1rem 0.35rem;
  font-size: 0.66rem;
  font-weight: 700;
  cursor: pointer;
}

.node-focus-btn:hover {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

.spouse-connector-badge {
  align-self: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-gold-soft);
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 700;
}

.expand-branch-badge {
  position: absolute;
  bottom: -11px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-primary);
  color: #fff;
  font-size: 0.64rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  cursor: pointer;
  z-index: 4;
}

.expand-ancestor-badge {
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-gold);
  color: #fff;
  font-size: 0.64rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  cursor: pointer;
  z-index: 4;
}

/* Floating HUD */
.canvas-hud {
  position: absolute;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: var(--bg-surface);
  padding: 0.35rem;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-md);
  z-index: 15;
}

.hud-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s;
}

.hud-btn:hover {
  background: var(--bg-secondary);
}

.canvas-legend {
  position: absolute;
  bottom: 1.25rem;
  left: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
  z-index: 15;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.dot-male {
  background: var(--male-accent);
}
.dot-female {
  background: var(--female-accent);
}
.dot-focus {
  background: var(--accent-gold);
}

.legend-symbol {
  color: var(--accent-gold);
  font-weight: 700;
}

/* ================= DIRECTORY, KINSHIP & STATS VIEWS ================= */
.section-container {
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem;
  overflow-y: auto;
  height: 100%;
}

.narrow-container {
  max-width: 920px;
}

.section-title {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.section-subtitle {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

.directory-header {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  margin-bottom: 1.5rem;
}

.directory-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.filter-input,
.filter-select {
  padding: 0.58rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
}

.filter-input {
  min-width: 220px;
  flex: 1;
}

.full-width {
  width: 100%;
}

.directory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
  gap: 0.9rem;
}

.dir-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--border-strong);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: transform 0.14s, box-shadow 0.14s, border-color 0.14s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.6rem;
}

.dir-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.dir-card.sex-M {
  border-left-color: var(--male-accent);
}
.dir-card.sex-F {
  border-left-color: var(--female-accent);
}

.dir-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.dir-card-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.dir-card-dates {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.dir-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
}

/* Kinship View */
.kinship-header {
  margin-bottom: 1.5rem;
}

.kinship-selector-card {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 1.35rem;
  box-shadow: var(--shadow-sm);
}

.kinship-person-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.kinship-person-box label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.autocomplete-wrap {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  z-index: 60;
}

.selected-person-pill {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-primary);
  font-size: 0.84rem;
  font-weight: 700;
}

.swap-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 1.1rem;
  cursor: pointer;
}

.swap-btn:hover {
  background: var(--accent-gold-soft);
  border-color: var(--accent-gold);
}

.kinship-result-area {
  margin-top: 1.5rem;
}

.kinship-summary-banner {
  background: var(--bg-surface);
  border: 1.5px solid var(--accent-gold);
  border-radius: 14px;
  padding: 1.25rem;
  text-align: center;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.kinship-summary-title {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--accent-gold);
}

.kinship-steps-chain {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.kinship-step-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  cursor: pointer;
}

.kinship-step-card:hover {
  border-color: var(--accent-primary);
}

.kinship-arrow-row {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-gold);
  padding: 0.15rem 0;
}

/* Statistics View */
.stats-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0 1.75rem;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

.kpi-value {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--accent-primary);
  line-height: 1.1;
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  font-weight: 600;
}

.stats-charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 1.25rem;
}

.stats-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 1.35rem;
  box-shadow: var(--shadow-sm);
}

.stats-card.full-span {
  grid-column: 1 / -1;
}

.stats-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.stats-card-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.bar-chart-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 44px;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 6px;
}

.bar-row:hover {
  background: var(--bg-secondary);
}

.bar-label {
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-secondary);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-gold));
}

.bar-count {
  text-align: right;
  font-weight: 700;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.roots-rank-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.root-rank-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: border-color 0.15s;
}

.root-rank-item:hover {
  border-color: var(--accent-gold);
}

.decades-chart {
  display: flex;
  align-items: flex-end;
  gap: 0.65rem;
  height: 190px;
  padding-top: 1.5rem;
  overflow-x: auto;
}

.decade-col {
  flex: 1;
  min-width: 44px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 0.35rem;
}

.decade-bar {
  width: 100%;
  max-width: 38px;
  background: var(--accent-primary);
  border-radius: 6px 6px 0 0;
  min-height: 4px;
  transition: height 0.3s ease;
}

.decade-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.decade-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ================= PERSON DRAWER ================= */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 21, 18, 0.42);
  backdrop-filter: blur(2px);
  z-index: 80;
}

.person-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 430px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  z-index: 90;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.gender-pill,
.status-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  margin-right: 0.35rem;
}

.gender-pill.sex-M {
  background: var(--male-soft);
  color: var(--male-accent);
}
.gender-pill.sex-F {
  background: var(--female-soft);
  color: var(--female-accent);
}

.status-pill {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.drawer-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.95rem;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.35rem 1.25rem 2.5rem;
}

.drawer-person-title {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.15;
  margin-bottom: 0.35rem;
}

.drawer-dates-line {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.drawer-action-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.drawer-btn {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
}

.drawer-btn.primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}

.drawer-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.35rem;
}

.drawer-stat-box {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 0.6rem;
  text-align: center;
}

.drawer-stat-num {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-primary);
}

.drawer-stat-lbl {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.drawer-rel-group {
  margin-top: 1.15rem;
}

.drawer-rel-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.drawer-rel-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.drawer-rel-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.58rem 0.75rem;
  border-radius: 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s;
}

.drawer-rel-item:hover {
  border-color: var(--accent-gold);
  background: var(--bg-secondary);
}

/* Responsive adjustments */
@media (max-width: 960px) {
  .topbar {
    flex-wrap: wrap;
    padding: 0.55rem 0.85rem;
  }
  .global-search-container {
    order: 3;
    max-width: 100%;
    flex: 1 1 100%;
  }
  .main-nav {
    order: 4;
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
  }
  .tree-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .kinship-selector-card {
    grid-template-columns: 1fr;
  }
  .swap-btn {
    margin: 0 auto;
  }
  .stats-charts-grid {
    grid-template-columns: 1fr;
  }
}

/* ================= EDITOR MODE, FAN CHART, TIMELINE & MODALS ================= */
.mode-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 36px;
  padding: 0 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.mode-pill-btn.is-editor {
  background: var(--accent-gold-soft);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.add-person-top-btn {
  height: 36px;
  padding: 0 0.85rem;
  border-radius: 9px;
  border: none;
  background: var(--accent-primary);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.add-person-top-btn:hover {
  background: var(--accent-primary-hover);
}

.dir-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.85rem;
}

.dir-action-btns {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.small-btn {
  padding: 0.5rem 0.9rem;
  font-size: 0.82rem;
  border-radius: 9px;
}

/* Fan Chart */
.fan-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-canvas);
  overflow: hidden;
  padding: 1rem;
}

.fan-svg {
  width: 100%;
  height: 100%;
  max-width: 860px;
  max-height: 860px;
}

.fan-sector {
  cursor: pointer;
  transition: opacity 0.15s;
}

.fan-sector:hover {
  opacity: 0.85;
}

.fan-label {
  font-size: 9.5px;
  font-weight: 700;
  fill: var(--text-primary);
  pointer-events: none;
}

/* Timeline */
.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  position: relative;
  padding-left: 1.25rem;
  border-left: 2px solid var(--accent-gold);
}

.timeline-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  position: relative;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -1.68rem;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-gold);
}

.timeline-year {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent-primary);
  min-width: 58px;
}

/* Backup Grid */
.backup-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.1rem;
  margin-top: 1.25rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 21, 18, 0.55);
  backdrop-filter: blur(3px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.35rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.45rem;
  font-weight: 700;
}

.modal-body {
  padding: 1.35rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-field label {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.form-field input,
.form-field select,
.form-field textarea {
  padding: 0.55rem 0.75rem;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.86rem;
  outline: none;
}

.form-field textarea {
  min-height: 74px;
  resize: vertical;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 0.5rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-subtle);
}

.danger-btn {
  padding: 0.55rem 0.95rem;
  border-radius: 9px;
  border: 1px solid rgba(220, 38, 38, 0.45);
  background: rgba(220, 38, 38, 0.1);
  color: #dc2626;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.danger-btn:hover {
  background: #dc2626;
  color: #fff;
}

.notes-box {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 0.75rem;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--text-secondary);
  white-space: pre-wrap;
  margin-bottom: 1rem;
}
