/* ============================================================
   Lineage — Modern Genealogy App
   Light theme inspired by reference family-tree mockup
   ============================================================ */

:root {
  /* Surfaces */
  --bg-page: #eef3f9;
  --bg-canvas: #e6eef7;
  --bg-card: #ffffff;
  --bg-soft: #f5f8fc;
  --bg-sidebar: #ffffff;

  /* Text */
  --text-primary: #1f2a44;
  --text-secondary: #5b6b86;
  --text-muted: #94a3b8;
  --text-on-accent: #ffffff;

  /* Brand / accents */
  --accent: #4a7fb8;
  --accent-dark: #2f5f96;
  --accent-soft: #dbe7f4;

  /* Tree */
  --tree-card: #ffffff;
  --tree-card-border: #d8e3f0;
  --tree-card-shadow: 0 4px 14px rgba(31, 42, 68, 0.08);
  --tree-connector: #b6c7dc;
  --tree-connector-spouse: #f0a5a5;

  /* Status */
  --danger: #d65d5d;
  --danger-dark: #b94646;
  --success: #4caf83;

  /* Lines / borders */
  --border: #d8e3f0;
  --border-soft: #e7eef6;

  /* Avatar palette (soft, photo-like backgrounds) */
  --av-1: #f6c7b7; --av-2: #c9d8e8; --av-3: #d8c9e8; --av-4: #b7d6c4;
  --av-5: #f1d6a4; --av-6: #c8c0e3; --av-7: #f3b9b9; --av-8: #a9c9d6;

  /* Radii / shadow */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --shadow-card: 0 6px 24px rgba(31, 42, 68, 0.06);
  --shadow-pop: 0 10px 30px rgba(31, 42, 68, 0.10);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; color: var(--text-primary); }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
.muted { color: var(--text-secondary); font-size: 0.875rem; }

.hidden { display: none !important; }

/* ============ Buttons ============ */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--r-sm);
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  transition: transform 0.06s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: 0 2px 8px rgba(74, 127, 184, 0.25);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }

.btn-soft {
  background: var(--bg-soft);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-soft:hover:not(:disabled) { background: #eef3fa; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
}
.btn-ghost:hover:not(:disabled) { color: var(--accent); background: var(--accent-soft); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-dark); }

.btn-mini {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  border-radius: 6px;
  background: var(--bg-soft);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-mini.danger { color: var(--danger); border-color: #f1c4c4; background: #fdf2f2; }
.btn-mini:hover:not(:disabled) { background: #eef3fa; }

/* ============ Form fields ============ */
input, select, textarea {
  width: 100%;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-primary);
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74, 127, 184, 0.15);
}
label { display: block; margin-bottom: 0.35rem; color: var(--text-secondary); font-size: 0.8rem; font-weight: 500; }

/* ============ Auth screen ============ */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(1200px 600px at 80% -10%, #d5e2f4 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #e2d6ef 0%, transparent 55%),
    var(--bg-page);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border-radius: var(--r-xl);
  padding: 2rem;
  box-shadow: var(--shadow-pop);
}
.auth-brand { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.5rem; }
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: "Playfair Display", serif;
  font-weight: 700;
  font-size: 1.3rem;
  box-shadow: 0 4px 12px rgba(74, 127, 184, 0.35);
}
.brand-mark.sm { width: 32px; height: 32px; border-radius: 9px; font-size: 1rem; }
.brand-name { font-family: "Playfair Display", serif; font-size: 1.25rem; font-weight: 700; }
.brand-tag { font-size: 0.78rem; color: var(--text-muted); }

.auth-form label { margin-top: 0.85rem; }
.auth-form .btn-primary { width: 100%; margin-top: 1.25rem; padding: 0.75rem; }

/* ============ App layout ============ */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
  background: var(--bg-page);
}

/* ----- Sidebar ----- */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-soft);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 0.65rem;
  font-family: "Playfair Display", serif;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 0 0.5rem;
}
.side-nav { display: flex; flex-direction: column; gap: 0.3rem; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.85rem;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 10px;
  text-align: left;
  font-weight: 500;
}
.nav-item:hover { background: var(--bg-soft); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}
.nav-ico { width: 18px; text-align: center; opacity: 0.8; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-soft);
  border-radius: var(--r-md);
}
.user-block {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 500;
  word-break: break-word;
}
.role-pill {
  align-self: flex-start;
  font-size: 0.7rem;
  padding: 0.2rem 0.55rem;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ----- Content ----- */
.content {
  padding: 1.5rem 2rem;
  min-width: 0;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.topbar-left h1 { font-family: "Playfair Display", serif; }
.topbar-right { display: flex; gap: 0.5rem; }

.view { display: block; }

/* ============ Tree view ============ */
.tree-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  padding: 0.75rem;
  box-shadow: var(--shadow-card);
}
.tree-toolbar-left, .tree-toolbar-right { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.tree-toolbar select { width: auto; min-width: 220px; max-width: 320px; }

.search-field {
  position: relative;
  display: flex;
  align-items: center;
}
.search-field input {
  padding-left: 2rem;
  min-width: 220px;
}
.search-field.grow { flex: 1; }
.search-field.grow input { width: 100%; }
.search-ico {
  position: absolute;
  left: 0.65rem;
  color: var(--text-muted);
  font-size: 1rem;
  pointer-events: none;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.zoom-controls button { padding: 0.4rem 0.7rem; font-size: 1rem; }
.zoom-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-width: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.tree-card {
  background:
    radial-gradient(800px 400px at 50% -10%, #f3f7fc 0%, transparent 60%),
    var(--bg-canvas);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
  overflow: hidden;
}

.tree-view {
  position: relative;
  overflow: scroll;          /* force both scroll bars to be visible */
  min-height: 480px;
  max-height: 72vh;
  /* Firefox */
  scrollbar-width: thin;
  scrollbar-color: #95b8d8 #eef3f9;
}
/* WebKit / Blink — visible, on-brand scroll bars */
.tree-view::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}
.tree-view::-webkit-scrollbar-track {
  background: #eef3f9;
  border-radius: 8px;
}
.tree-view::-webkit-scrollbar-thumb {
  background: #c4d7eb;
  border: 2px solid #eef3f9;
  border-radius: 8px;
}
.tree-view::-webkit-scrollbar-thumb:hover {
  background: #95b8d8;
}
.tree-view::-webkit-scrollbar-corner {
  background: #eef3f9;
}
.tree-canvas {
  position: relative;
  display: inline-block;
  min-width: 100%;
  padding: 1rem 1.5rem;
  transform-origin: top left;
}
.tree-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

/* ----- Generation columns (horizontal layout) ----- */
.tree-grid {
  display: flex;
  gap: 80px;
  align-items: center;
  position: relative;
  z-index: 1;
}
.tree-generation {
  display: flex;
  flex-direction: column;
  gap: 28px;
  justify-content: center;
}
.tree-generation[data-label]::before {
  content: attr(data-label);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 0.25rem;
}

/* ----- Couple grouping (husband + wife pill) ----- */
.tree-couple {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: linear-gradient(180deg, rgba(218, 231, 244, 0.6), rgba(218, 231, 244, 0.35));
  border: 2px solid var(--accent-soft);
  border-radius: 999px;
  position: relative;
  box-shadow: 0 4px 14px rgba(74, 127, 184, 0.08);
}
.tree-couple::before {
  content: "♥";
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 20px;
  background: #fff;
  border: 1px solid var(--accent-soft);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--tree-connector-spouse);
  line-height: 1;
}
.tree-couple .tree-node {
  border-color: transparent;
  box-shadow: 0 2px 6px rgba(31, 42, 68, 0.06);
}
.tree-couple .tree-node:hover {
  border-color: var(--accent);
}

/* ----- Person node ----- */
.tree-node {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--tree-card);
  border: 1px solid var(--tree-card-border);
  border-radius: 14px;
  padding: 0.55rem 0.85rem 0.55rem 0.55rem;
  box-shadow: var(--tree-card-shadow);
  min-width: 175px;
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.tree-node:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-pop);
  border-color: var(--accent);
}
.tree-node.is-root {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74, 127, 184, 0.15), var(--tree-card-shadow);
}

/* Gender-tinted surfaces for living members */
.tree-node.is-male {
  background: #dfecf8;          /* soft pale blue */
  border-color: #c4d7eb;
}
.tree-node.is-female {
  background: #fbe1ea;          /* soft pale rose */
  border-color: #ecc6d3;
}
/* Inside a couple-box, keep gender colours visible */
.tree-couple .tree-node.is-male   { background: #dfecf8; border-color: #c4d7eb; }
.tree-couple .tree-node.is-female { background: #fbe1ea; border-color: #ecc6d3; }

/* Deceased — soft red wash overrides the gender background.
   The M/F badge in the top-left preserves the gender signal. */
.tree-node.is-deceased,
.tree-node.is-male.is-deceased,
.tree-node.is-female.is-deceased,
.tree-couple .tree-node.is-deceased {
  background: #fdecec;
  border-color: #f1c4c4;
}
.tree-node.is-deceased .tree-name { color: #8a3b3b; }
.tree-node.is-deceased .tree-dates { color: #a96565; }
/* Root + deceased combo: keep root's accent ring, tint the surface red */
.tree-node.is-root.is-deceased {
  border-color: var(--accent);
  background: #fdecec;
}

/* M/F badge shown on deceased members so gender is still legible */
.gender-badge {
  position: absolute;
  top: 4px;
  left: 6px;
  min-width: 16px;
  padding: 1px 5px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 5px;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.35;
  text-align: center;
  z-index: 2;
  box-shadow: 0 1px 2px rgba(31, 42, 68, 0.12);
}
.gender-badge.male   { color: #2f5f96; }   /* blue */
.gender-badge.female { color: #b94f7a; }   /* rose */

/* Clergy badge — small cross sitting at the top-right of the card.
   Sits opposite the M/F deceased badge so the two never collide. */
.clergy-cross {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: #6b4f9f;            /* ecclesiastical purple */
  border: 1px solid #d4cce4;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(31, 42, 68, 0.14);
}

.tree-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: #3b4a66;
  flex-shrink: 0;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(31, 42, 68, 0.12);
  position: relative;
  overflow: hidden;
}
.tree-avatar.deceased::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(31, 42, 68, 0.06);
}

.tree-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.tree-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.tree-dates {
  font-size: 0.7rem;
  color: var(--text-secondary);
  line-height: 1.35;
}
.tree-dates span { display: block; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
  height: 100%;
}
.empty-ico {
  font-size: 3rem;
  color: var(--accent-soft);
  margin-bottom: 0.75rem;
}
.empty-state h3 { color: var(--text-primary); margin-bottom: 0.25rem; }

/* ----- Legend ----- */
.legend {
  display: flex;
  gap: 1.25rem;
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  font-size: 0.78rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
}
.legend-item { display: inline-flex; align-items: center; gap: 0.45rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend-line {
  width: 22px;
  height: 0;
  border-top: 2px solid var(--tree-connector);
  display: inline-block;
}
.legend-line.spouse { border-top-style: dashed; border-top-color: var(--tree-connector-spouse); }

/* ============ Members view ============ */
.members-toolbar {
  margin-bottom: 1rem;
  display: flex;
  gap: 0.75rem;
}

.members-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.25rem;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
}
.panel-head { margin-bottom: 1rem; }
.panel-head p { margin-top: 0.15rem; }

.member-form .field { margin-bottom: 0.75rem; }
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.inline-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.inline-actions button { flex: 1; min-width: 100px; }

/* ----- Members table ----- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--r-md);
  border: 1px solid var(--border-soft);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
th, td {
  padding: 0.75rem 0.85rem;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-soft);
}
th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  background: var(--bg-soft);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-soft); }

.member-cell {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.member-cell .avatar-sm {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #3b4a66;
  flex-shrink: 0;
}
.member-cell .meta {
  display: flex; flex-direction: column; min-width: 0;
}
.member-cell .meta strong {
  font-size: 0.88rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.member-cell .meta small {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.row-actions { display: flex; gap: 0.4rem; }

/* Member ID cell — monospace + muted so technical refs are visually distinct */
.id-cell {
  font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: var(--bg-soft);
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  white-space: nowrap;
}

/* ============ Responsive ============ */
@media (max-width: 1100px) {
  .members-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    overflow-x: auto;
  }
  .sidebar-brand { flex: 1; }
  .side-nav { flex-direction: row; }
  .sidebar-footer { flex-direction: row; align-items: center; margin-top: 0; flex-shrink: 0; }
  .content { padding: 1rem; }
  .field-row { grid-template-columns: 1fr; }
}
