/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #222;
  min-height: 100vh;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ───────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: #1e3a5f;
  color: #fff;
  padding: 0 1.5rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.nav-brand { font-size: 1.2rem; font-weight: 700; letter-spacing: .5px; }

.nav-links { display: flex; gap: .25rem; flex: 1; }

.nav-links a {
  color: #cbd5e1;
  padding: .4rem .85rem;
  border-radius: 6px;
  font-size: .9rem;
  transition: background .15s;
}
.nav-links a:hover, .nav-links a.active {
  background: rgba(255,255,255,.15);
  color: #fff;
  text-decoration: none;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .875rem;
  color: #cbd5e1;
}

.badge-admin {
  background: #f59e0b;
  color: #fff;
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}

.btn-logout {
  background: rgba(255,255,255,.15);
  color: #fff !important;
  padding: .35rem .85rem;
  border-radius: 6px;
  font-size: .85rem;
}
.btn-logout:hover { background: rgba(255,255,255,.28); text-decoration: none; }

/* ── Container ────────────────────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 1.75rem 1.5rem; }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: .9rem;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: .5rem 1.1rem;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
  transition: opacity .15s, transform .1s;
  text-align: center;
}
.btn:hover { opacity: .88; text-decoration: none; }
.btn:active { transform: scale(.97); }

.btn-primary   { background: #2563eb; color: #fff; }
.btn-secondary { background: #e2e8f0; color: #334155; }
.btn-success   { background: #16a34a; color: #fff; }
.btn-warning   { background: #d97706; color: #fff; }
.btn-danger    { background: #dc2626; color: #fff; }
.btn-ghost     { background: transparent; color: #64748b; border: 1px solid #cbd5e1; }
.btn-block     { display: block; width: 100%; }
.btn-sm        { padding: .3rem .75rem; font-size: .82rem; }

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
h2 { font-size: 1.4rem; color: #1e3a5f; }
h3 { font-size: 1.1rem; margin: 1.5rem 0 .75rem; color: #1e3a5f; }

/* ── Stats grid ───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: #fff;
  border-radius: 10px;
  padding: 1.25rem;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  border-top: 4px solid #2563eb;
}
.stat-card.blue  { border-top-color: #0ea5e9; }
.stat-card.pink  { border-top-color: #ec4899; }
.stat-card.green { border-top-color: #16a34a; }
.stat-card.gray  { border-top-color: #6b7280; }
.stat-number { font-size: 2rem; font-weight: 700; color: #1e3a5f; }
.stat-label  { font-size: .85rem; color: #64748b; margin-top: .25rem; }

.dashboard-actions { display: flex; gap: .75rem; margin-bottom: 1.5rem; }

/* ── Table ────────────────────────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  font-size: .9rem;
}
.table th {
  background: #1e3a5f;
  color: #fff;
  padding: .75rem 1rem;
  text-align: left;
  font-weight: 500;
}
.table td { padding: .7rem 1rem; border-bottom: 1px solid #f1f5f9; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f8fafc; }
.row-inactive td { opacity: .55; }
.text-center { text-align: center; }
.text-muted  { color: #94a3b8; font-size: .85rem; }
.text-link   { font-size: .875rem; }
.actions     { white-space: nowrap; }
.actions .btn + .btn { margin-left: .35rem; }

/* ── Status & Badges ──────────────────────────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
}
.status-living   { background: #d1fae5; color: #065f46; }
.status-deceased { background: #e5e7eb; color: #374151; }
.status-unknown  { background: #fef9c3; color: #713f12; }
.row-deceased td { opacity: .65; }

.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 99px;
  background: #e2e8f0;
  color: #334155;
  font-size: .78rem;
}
.badge-admin   { background: #fef3c7; color: #92400e; }
.badge-regular { background: #e0f2fe; color: #0c4a6e; }
.badge-add_member, .badge-edit_member { background: #dcfce7; color: #166534; }
.badge-toggle_status { background: #fef9c3; color: #713f12; }
.badge-login, .badge-logout { background: #ede9fe; color: #4c1d95; }
.badge-add_user, .badge-edit_user, .badge-delete_user { background: #fee2e2; color: #991b1b; }

/* ── Search bar ───────────────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.search-bar input[type=text] {
  flex: 1;
  min-width: 200px;
  padding: .5rem .85rem;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: .9rem;
}
.search-bar select {
  padding: .5rem .75rem;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: .9rem;
  background: #fff;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-card {
  background: #fff;
  border-radius: 10px;
  padding: 1.75rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  max-width: 900px;
}
.form-card-narrow { max-width: 480px; }

.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: .25rem;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  flex: 1;
  min-width: 180px;
  margin-bottom: .85rem;
}
.form-group-wide { flex: 2; }
.form-group label { font-size: .875rem; font-weight: 500; color: #374151; }
.form-group input, .form-group select, .form-group textarea {
  padding: .5rem .75rem;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: .9rem;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.input-disabled { background: #f8fafc; color: #94a3b8; }
.form-actions { display: flex; gap: .75rem; margin-top: .5rem; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 40px);
}
.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 2.5rem 2rem;
  width: 380px;
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
  text-align: center;
}
.login-logo { font-size: 3rem; margin-bottom: .5rem; }
.login-card h1 { font-size: 1.5rem; color: #1e3a5f; margin-bottom: .25rem; }
.login-subtitle { color: #94a3b8; margin-bottom: 1.5rem; font-size: .9rem; }
.login-card .form-group { text-align: left; }

/* ── Tree ─────────────────────────────────────────────────────────────────── */
#tree-container {
  width: 100%;
  height: calc(100vh - 240px);
  min-height: 500px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  border: 1px solid #e2e8f0;
}

.tree-controls { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }

.tree-legend {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  font-size: .82rem;
  color: #64748b;
}
.legend-item { display: flex; align-items: center; gap: .35rem; }
.legend-box {
  width: 18px; height: 18px; border-radius: 4px; border: 2px solid #555;
}
.legend-box.male    { background: #aed6f1; }
.legend-box.female  { background: #f9a8d4; }
.legend-box.unknown { background: #d5dbdb; }
.legend-line {
  width: 24px; height: 2px;
}
.legend-line.solid  { background: #555; }
.legend-line.dashed { background: repeating-linear-gradient(90deg, #e74c3c 0 4px, transparent 4px 8px); }
.legend-box.legend-living   { border: 3px solid #555; background: #aed6f1; }
.legend-box.legend-deceased { border: 2px dashed #555; background: #b0b0b0; }

/* ── Navbar tree indicator ────────────────────────────────────────────────── */
.nav-tree-name {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: rgba(255,255,255,.12);
  padding: .25rem .75rem;
  border-radius: 99px;
  font-size: .85rem;
  color: #e2e8f0;
}
.nav-switch-tree {
  color: #93c5fd;
  font-size: .78rem;
  font-weight: 500;
  border-left: 1px solid rgba(255,255,255,.3);
  padding-left: .4rem;
  margin-left: .1rem;
}
.nav-switch-tree:hover { color: #fff; text-decoration: none; }

/* ── Tree selection page ──────────────────────────────────────────────────── */
.trees-wrapper {
  max-width: 760px;
  margin: 0 auto;
}
.trees-header {
  text-align: center;
  margin-bottom: 2rem;
}
.trees-logo { font-size: 3.5rem; margin-bottom: .5rem; }
.trees-header h2 { font-size: 1.8rem; color: #1e3a5f; margin-bottom: .4rem; }

.tree-cards {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-bottom: 2rem;
}
.tree-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: #fff;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem 1.25rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  transition: border-color .15s;
}
.tree-card:hover { border-color: #93c5fd; }
.tree-card-active { border-color: #2563eb; background: #eff6ff; }
.tree-card-icon { font-size: 2rem; flex-shrink: 0; }
.tree-card-body { flex: 1; }
.tree-card-name { font-size: 1.05rem; font-weight: 600; color: #1e3a5f; }
.tree-card-actions { display: flex; gap: .5rem; align-items: center; flex-shrink: 0; }

.create-tree-box {
  background: #fff;
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
}
.create-tree-box h3 { margin-bottom: 1rem; color: #1e3a5f; }
.create-tree-form {
  display: flex;
  gap: .75rem;
  justify-content: center;
  flex-wrap: wrap;
}
.create-tree-form input[type=text] {
  padding: .55rem 1rem;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: .95rem;
  width: 300px;
  max-width: 100%;
}
.create-tree-form input[type=text]:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 2rem;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal-box h3 { margin-bottom: 1rem; color: #1e3a5f; }
.modal-box input[type=text] {
  width: 100%;
  padding: .55rem .85rem;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: .95rem;
}
.modal-box input[type=text]:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

/* ── Member form sections ─────────────────────────────────────────────────── */
.form-section-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #64748b;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: .4rem;
  margin: 1.25rem 0 .75rem;
}
.form-section-hint {
  font-size: .85rem;
  color: #64748b;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  padding: .65rem .9rem;
  margin-bottom: .85rem;
}

/* ── Link context banner ──────────────────────────────────────────────────── */
.link-context-banner {
  display: flex;
  align-items: flex-start;
  gap: .85rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  font-size: .92rem;
  color: #1e40af;
}
.link-context-icon { font-size: 1.4rem; flex-shrink: 0; }

/* ── Add & Link section ───────────────────────────────────────────────────── */
.add-link-section {
  margin-top: 1.75rem;
  background: #fff;
  border: 2px solid #bfdbfe;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 900px;
}
.add-link-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
}
.btn-link-add {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  padding: .5rem 1rem;
  border-radius: 8px;
  font-size: .88rem;
  font-weight: 500;
  transition: background .15s;
  text-decoration: none;
  display: inline-block;
}
.btn-link-add:hover { background: #dbeafe; text-decoration: none; }

/* ── Children chips ───────────────────────────────────────────────────────── */
.children-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.child-chip {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
  padding: .3rem .75rem;
  border-radius: 99px;
  font-size: .85rem;
  text-decoration: none;
}
.child-chip:hover { background: #dcfce7; text-decoration: none; }

/* ── Add note (shown on new member form) ──────────────────────────────────── */
.add-link-note {
  margin-top: 1rem;
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: .75rem 1rem;
  font-size: .875rem;
  color: #713f12;
  max-width: 900px;
}

/* ── Field hints ──────────────────────────────────────────────────────────── */
.field-hint {
  font-size: .78rem;
  color: #94a3b8;
  margin-top: .15rem;
  line-height: 1.3;
}

/* ── Duplicate name warning ───────────────────────────────────────────────── */
.duplicate-warning {
  background: #fef9c3;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: .75rem 1rem;
  font-size: .875rem;
  color: #713f12;
  margin-bottom: 1rem;
}

/* ── Member status legend box ─────────────────────────────────────────────── */
.legend-box.inactive { background: #e5e7eb; border: 2px dashed #9ca3af; }

/* ── Status actions section ───────────────────────────────────────────────── */
.status-actions-section {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: .85rem 1.25rem;
}

/* ── Password link in nav ─────────────────────────────────────────────────── */
.nav-links-inline {
  color: #cbd5e1;
  padding: .4rem .65rem;
  border-radius: 6px;
  font-size: .85rem;
  transition: background .15s;
  white-space: nowrap;
}
.nav-links-inline:hover {
  background: rgba(255,255,255,.15);
  color: #fff;
  text-decoration: none;
}

/* ── Download dropdown ────────────────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  min-width: 140px;
  z-index: 100;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  display: block;
  padding: .5rem 1rem;
  color: #334155;
  font-size: .9rem;
  text-decoration: none;
}
.dropdown-item:hover { background: #f1f5f9; }

/* ── Relationship dropdown + goto button ─────────────────────────────────── */
.select-with-goto {
  display: flex;
  align-items: center;
  gap: .4rem;
}
.select-with-goto select {
  flex: 1;
}
.btn-goto {
  flex-shrink: 0;
  padding: .3rem .6rem;
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  font-size: .9rem;
  line-height: 1;
  color: #334155;
  transition: background .15s;
}
.btn-goto:hover:not(:disabled) {
  background: #3b82f6;
  color: #fff;
  border-color: #3b82f6;
}
.btn-goto:disabled {
  opacity: .35;
  cursor: not-allowed;
}

/* ── Sortable table headers ──────────────────────────────────────────────── */
th[data-sort]:hover { background: #16305a; }
.sort-icon { font-size: .7rem; opacity: .6; margin-left: .25rem; }

/* ── Members table link colours ──────────────────────────────────────────── */
.link-name   { color: #111 !important; }
.link-father { color: #1e40af !important; }
.link-mother { color: #b91c1c !important; }
.link-name:hover, .link-father:hover, .link-mother:hover { text-decoration: underline; }

/* ── Sibling chips (matches child-chip style, distinct colour) ────────────── */
.sibling-chip {
  background: #f5f3ff;
  color: #5b21b6;
  border: 1px solid #ddd6fe;
  padding: .3rem .75rem;
  border-radius: 99px;
  font-size: .85rem;
  text-decoration: none;
}
.sibling-chip:hover { background: #ede9fe; text-decoration: none; }

/* ── Family members section (Children + Siblings box) ────────────────────── */
.family-members-section {
  margin-top: 1.75rem;
  background: #fff;
  border: 2px solid #d1fae5;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 900px;
}
.family-members-section strong { font-size: .95rem; color: #1e3a5f; }

/* ── Tree button in Members table ────────────────────────────────────────── */
.btn-tree {
  background: #16a34a;
  color: #fff;
  border: 1px solid #15803d;
  padding: .25rem .65rem;
  border-radius: 6px;
  font-size: .8rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.btn-tree:hover { background: #15803d; color: #fff; text-decoration: none; }

/* ── Help page ────────────────────────────────────────────────────────────── */
.help-card {
  background: #fff;
  border-radius: 10px;
  padding: 1.75rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  max-width: 860px;
}
.help-card h3 { font-size: 1.05rem; margin-bottom:1rem; color:#1e3a5f; }
.help-list { padding-left: 1.4rem; display: flex; flex-direction: column; gap: .65rem; }
.help-list li { font-size: .9rem; line-height: 1.55; color: #374151; }
.help-list code { background:#f1f5f9; padding:.1rem .35rem; border-radius:4px; font-size:.85em; }
.help-contact-form { max-width: 560px; }

/* ── Descendant tree page ─────────────────────────────────────────────────── */
.dt-tree {
  background: #fff;
  border-radius: 10px;
  padding: 1.5rem 2rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  overflow-x: auto;
}
.dt-node { display: flex; flex-direction: column; align-items: flex-start; }
.dt-couple { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.dt-card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: .45rem .8rem;
  border-radius: 8px;
  border: 2px solid #cbd5e1;
  text-decoration: none;
  color: #1e3a5f;
  min-width: 90px;
  text-align: center;
  transition: border-color .15s, box-shadow .15s;
}
.dt-card:hover { border-color: #3b82f6; box-shadow: 0 0 0 2px #bfdbfe; text-decoration: none; }
.dt-card.dt-male    { background: #dbeafe; border-color: #93c5fd; }
.dt-card.dt-female  { background: #fce7f3; border-color: #f9a8d4; }
.dt-card.dt-unknown { background: #f1f5f9; border-color: #cbd5e1; }
.dt-card.dt-root    { border-width: 3px; background: #16a34a !important; border-color: #15803d !important; }
.dt-card.dt-spouse  { border-style: dashed; }
.dt-name  { font-size: .85rem; font-weight: 600; }
.dt-root .dt-name { color: #000 !important; font-weight: 800; }
.dt-years { font-size: .72rem; color: #64748b; margin-top: .1rem; }
.dt-heart { color: #f43f5e; font-size: .9rem; flex-shrink: 0; }
.dt-children {
  margin-top: .35rem;
  margin-left: 2.5rem;
  padding-left: 1.5rem;
  border-left: 2px solid #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  padding-top: .4rem;
  padding-bottom: .2rem;
}
.dt-children > .dt-node { position: relative; padding-top: .1rem; }
.dt-children > .dt-node::before {
  content: '';
  position: absolute;
  left: -1.5rem;
  top: 1.05rem;
  width: 1.5rem;
  height: 2px;
  background: #cbd5e1;
}

/* ── Descendant tree parents section ─────────────────────────────────────── */
.dt-parents-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: .25rem;
}
.dt-parents-row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; justify-content: center; }
.dt-parents-connector { color: #94a3b8; font-size: 1.1rem; margin-top: .2rem; line-height: 1; }

/* ── Hamburger button (hidden on desktop) ─────────────────────────────────── */
.hamburger {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: .25rem .5rem;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Mobile & tablet responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Nav */
  .navbar { flex-wrap: wrap; padding: 0 1rem; height: auto; min-height: 56px; position: relative; }
  .nav-brand { flex: 1; line-height: 56px; }
  .hamburger { display: flex; align-items: center; height: 56px; }
  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    background: #1e3a5f;
    padding: .5rem 0 1rem;
    gap: 0;
    order: 10;
  }
  .nav-links.mobile-open { display: flex; }
  .nav-links a {
    padding: .65rem 1.25rem;
    border-radius: 0;
    font-size: 1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
  }
  .nav-user {
    width: 100%;
    order: 11;
    background: #16305a;
    padding: .5rem 1.25rem;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: .5rem;
    font-size: .82rem;
  }
  .nav-tree-name { display: none; }

  /* Container */
  .container { padding: 1rem .75rem; }

  /* Page header */
  .page-header { flex-direction: column; align-items: flex-start; gap: .6rem; }

  /* Tables – horizontal scroll */
  .table-wrapper, .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.table { min-width: 600px; }

  /* Form */
  .form-card { padding: 1.25rem 1rem; }
  .form-row { flex-direction: column; gap: 0; }
  .form-group { min-width: 100%; }
  .form-actions { flex-wrap: wrap; gap: .5rem; }
  .form-actions .btn { flex: 1 1 auto; text-align: center; }

  /* Buttons */
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .btn-sm { min-height: 36px; }

  /* Stats grid */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Search bar */
  .search-bar { flex-direction: column; align-items: stretch; }
  .search-bar input[type=text], .search-bar select { min-width: 100%; }

  /* Modals */
  .modal-box { width: 92vw; padding: 1.5rem 1rem; }

  /* Add-link section */
  .add-link-section, .family-members-section { padding: 1rem; }
  .add-link-buttons { gap: .4rem; }
  .btn-link-add { font-size: .82rem; padding: .4rem .75rem; }

  /* Descendant tree */
  .dt-tree { padding: 1rem .5rem; }
  .dt-children { margin-left: 1.25rem; padding-left: .75rem; }

  /* Help */
  .help-card { padding: 1.25rem 1rem; }
  .help-contact-form { max-width: 100%; }
}

@media (max-width: 480px) {
  h2 { font-size: 1.15rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-number { font-size: 1.5rem; }
  .table th, .table td { padding: .5rem .6rem; font-size: .82rem; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  /* Tablet – minor adjustments */
  .container { padding: 1.5rem 1rem; }
  .form-row { flex-wrap: wrap; }
  .form-group { min-width: 200px; }
  table.table { font-size: .85rem; }
}

/* ── Print styles ─────────────────────────────────────────────────────────── */
@media print {
  .no-print { display: none !important; }
  .container { padding: 0; max-width: 100%; }
  #tree-container {
    height: 100vh;
    width: 100%;
    box-shadow: none;
    border: none;
    border-radius: 0;
    page-break-inside: avoid;
  }
  body { background: #fff; }
}
