:root {
  --color-primary: #6d5bff;
  --color-primary-dark: #4c3bd6;
  --color-accent: #ff8fc7;
  --color-text: #21243a;
  --color-text-muted: #6b7185;
  --color-border: rgba(120, 120, 160, 0.18);
  --color-danger: #e0447a;
  --color-warning: #b45309;
  --glass-surface: rgba(255, 255, 255, 0.55);
  --glass-surface-strong: rgba(255, 255, 255, 0.72);
  --glass-blur: 20px;
  --radius: 16px;
  --shadow: 0 8px 30px rgba(80, 70, 160, 0.12);
  --shadow-soft: 0 2px 10px rgba(80, 70, 160, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--color-text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(120deg, #dfe6ff, #f3e2ff, #e0fff2, #fff1e0);
  background-size: 400% 400%;
  animation: auroraDrift 22s ease-in-out infinite alternate;
}

@keyframes auroraDrift {
  0%   { background-position: 0% 40%; }
  50%  { background-position: 100% 60%; }
  100% { background-position: 40% 100%; }
}

@media (prefers-reduced-motion: reduce) {
  body {
    animation: none;
  }
}

a {
  color: var(--color-primary);
}

/* ---------- Auth (login) page: no sidebar, centered card ---------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
}

.auth-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  margin-bottom: 0;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--color-text);
  margin-bottom: 1.5rem;
}

/* ---------- Shell layout: sidebar + main ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.1rem;
  background: var(--glass-surface);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border-right: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: var(--shadow);
  z-index: 20;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.4rem 0.5rem 1.25rem;
  text-decoration: none;
  color: var(--color-text);
}

.sidebar-brand-mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(109, 91, 255, 0.35);
}

.sidebar-brand-text {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
}

.sidebar-brand-text small {
  font-weight: 500;
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  margin-top: 0.5rem;
}

.sidebar-section {
  margin: 0.9rem 0 0.15rem 0.75rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.75rem;
  border-radius: 12px;
  color: var(--color-text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
}

.nav-link svg {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-link:hover {
  background: rgba(109, 91, 255, 0.1);
  color: var(--color-primary-dark);
  transform: translateX(2px);
}

.nav-link.active {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: #fff;
  box-shadow: 0 6px 16px rgba(109, 91, 255, 0.35);
}

.nav-link-danger:hover {
  background: rgba(224, 68, 122, 0.12);
  color: var(--color-danger);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(120, 120, 160, 0.18);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.5rem 0.75rem;
}

.sidebar-user-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(109, 91, 255, 0.15);
  color: var(--color-primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(30, 25, 60, 0.35);
  z-index: 15;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 0.9rem;
  left: 0.9rem;
  z-index: 30;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: var(--glass-surface-strong);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  box-shadow: var(--shadow-soft);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
}

.sidebar-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: var(--color-text);
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 2rem 2.25rem;
}

/* ---------- Glass content card ---------- */

.page-card {
  background: var(--glass-surface-strong);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.85rem 2.1rem;
  margin-bottom: 2rem;
  animation: cardFadeIn 0.4s ease both;
}

@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .page-card {
    animation: none;
  }
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--color-text);
}

h2 {
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- Lists ---------- */

.list-clean {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.list-clean > li {
  padding: 0.8rem 1.05rem;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.4);
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}

.list-clean > li:hover {
  background: rgba(255, 255, 255, 0.65);
  border-color: var(--color-primary);
  transform: translateY(-1px);
}

.list-clean a {
  color: var(--color-primary-dark);
  text-decoration: none;
  font-weight: 600;
}

.list-clean a:hover {
  text-decoration: underline;
}

/* A row that's just one link (e.g. a lineage/menu list) — the whole card
   is clickable, not only the text, matching the hover feedback the card
   itself already gives. Not applied to .list-clean generally since some
   rows (like a search result) mix a link with other inline text where a
   block-level anchor would break the layout. */
.list-clean-linked > li {
  padding: 0;
}

.list-clean-linked > li > a {
  display: block;
  padding: 0.8rem 1.05rem;
}

.list-clean-linked > li > a:hover {
  text-decoration: none;
}

/* ---------- Buttons ---------- */

.btn {
  transition: transform 0.12s ease, box-shadow 0.18s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  border: none;
  box-shadow: 0 4px 14px rgba(109, 91, 255, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 8px 22px rgba(109, 91, 255, 0.42);
  transform: translateY(-1px);
}

.btn:active {
  transform: scale(0.97);
}

.form-control, .form-select {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(120, 120, 160, 0.25);
}

.form-control:focus, .form-select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 0.2rem rgba(109, 91, 255, 0.2);
}

/* ---------- Misc ---------- */

.empty-state {
  color: var(--color-text-muted);
  font-style: italic;
  padding: 1.5rem 0;
  text-align: center;
}

.badge-count {
  display: inline-block;
  background: rgba(109, 91, 255, 0.15);
  color: var(--color-primary-dark);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.table {
  background: rgba(255, 255, 255, 0.35);
  border-color: rgba(120, 120, 160, 0.18) !important;
}

.table th {
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  border-bottom-width: 1px !important;
}

/* ---------- Family tree visualization ---------- */

.tree-canvas {
  width: 100%;
  height: 640px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.3);
  cursor: grab;
  position: relative;
}

.tree-canvas:active {
  cursor: grabbing;
}

.tree-hint {
  position: absolute;
  bottom: 0.6rem;
  right: 0.85rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  background: var(--glass-surface-strong);
  backdrop-filter: blur(8px);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  pointer-events: none;
}

.tree-node rect {
  fill: rgba(255, 255, 255, 0.85);
  stroke: var(--color-primary);
  stroke-width: 1.4;
  filter: drop-shadow(0 3px 8px rgba(109, 91, 255, 0.25));
  transition: filter 0.15s ease;
}

.tree-node:hover rect {
  filter: drop-shadow(0 5px 14px rgba(109, 91, 255, 0.4));
}

.tree-node-match rect {
  stroke: var(--color-accent);
  stroke-width: 3;
  filter: drop-shadow(0 0 10px rgba(255, 145, 0, 0.55));
}

.tree-node-name {
  font-size: 13px;
  font-weight: 700;
  fill: var(--color-text);
}

.tree-node-spouse {
  font-size: 11px;
  fill: var(--color-text-muted);
}

.tree-link {
  fill: none;
  stroke: rgba(109, 91, 255, 0.35);
  stroke-width: 1.6;
}

.tree-node-action {
  font-size: 10px;
  fill: var(--color-primary-dark);
  cursor: pointer;
  font-weight: 600;
}

.tree-node-action:hover {
  fill: var(--color-danger);
  text-decoration: underline;
}

.tree-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-muted);
}

/* ---------- Responsive: off-canvas sidebar on small screens ---------- */

@media (max-width: 900px) {
  .sidebar-toggle {
    display: flex;
  }

  .sidebar-overlay.visible {
    display: block;
    opacity: 1;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .app-main {
    padding: 4.5rem 1.1rem 2rem;
  }

  .page-card {
    padding: 1.4rem 1.3rem;
  }
}
