/*
Theme Name:  FamilyWiki
Theme URI:   https://yoursite.com
Description: A Wikipedia-inspired family history theme with a visual family tree, profiles directory, and per-person history pages. Uses ACF for structured genealogy data and Gutenberg for article content.
Version:     1.1.1
Author:      Your Name
Author URI:  https://yoursite.com
License:     GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: familywiki
Requires at least: 6.4
Tested up to: 6.7
Requires PHP: 8.0
*/

/* ============================================================
   BASE RESETS & GLOBAL
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

/* WordPress injects overflow-x:hidden on .wp-site-blocks via
   useRootPaddingAwareAlignments. We can't override a parent's
   overflow from a child, so on mobile we bleed the table wrapper
   outside its padding container and use its own scroll. */
body {
  margin: 0;
  background-color: var(--wp--preset--color--parchment);
  color: var(--wp--preset--color--ink);
  font-family: var(--wp--preset--font-family--source-sans);
  font-size: var(--wp--preset--font-size--base);
  line-height: 1.75;
}

img { max-width: 100%; height: auto; display: block; }

a {
  color: var(--wp--preset--color--link-blue);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ============================================================
   SITE CHROME
   ============================================================ */
.site-header {
  background: var(--wp--preset--color--surface);
  border-bottom: 1px solid var(--wp--preset--color--border);
  position: sticky;
  top: 0;
  z-index: 200;
}

.site-header__inner {
  max-width: var(--wp--style--global--wide-size);
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 2rem;
}

.site-header__logo {
  font-family: var(--wp--preset--font-family--libertine-display);
  font-size: 1.35rem;
  font-weight: 400;
  color: var(--wp--preset--color--ink);
  text-decoration: none;
  white-space: nowrap;
}
.site-header__logo span { color: var(--wp--preset--color--link-blue); }

.site-header__nav { display: flex; gap: 0; list-style: none; margin: 0; padding: 0; }
.site-header__nav a {
  display: flex;
  align-items: center;
  height: 52px;
  padding: 0 1rem;
  font-size: 0.9rem;
  color: var(--wp--preset--color--muted);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  text-decoration: none;
}
.site-header__nav a:hover,
.site-header__nav .current-menu-item a,
.site-header__nav .current-page-ancestor a {
  color: var(--wp--preset--color--link-blue);
  border-bottom-color: var(--wp--preset--color--link-blue);
}

.site-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--wp--preset--color--border);
  padding: 1.5rem 1.25rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--wp--preset--color--muted);
  background: var(--wp--preset--color--surface);
}

/* ============================================================
   WIKI LAYOUT WRAPPER
   ============================================================ */
.wiki-page {
  max-width: var(--wp--style--global--content-size);
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}

.wiki-page--wide {
  max-width: var(--wp--style--global--wide-size);
}

.wiki-page__title {
  font-family: var(--wp--preset--font-family--libertine-display);
  font-size: clamp(26px, 4vw, 36px);
  font-weight: 400;
  line-height: 1.2;
  margin: 0 0 0.25rem;
  border-bottom: 1px solid var(--wp--preset--color--border);
  padding-bottom: 0.4rem;
}

/* ============================================================
   INFOBOX (sidebar on person profiles)
   ============================================================ */
.infobox {
  background: var(--wp--preset--color--surface);
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 4px;
  font-size: 0.85rem;
  overflow: hidden;
  float: right;
  clear: right;
  width: 260px;
  margin: 0 0 1.25rem 1.75rem;
}

@media (max-width: 660px) {
  .infobox {
    float: none;
    width: 100%;
    margin: 0 0 1.5rem;
  }
}

.infobox__header {
  background: var(--wp--preset--color--header-blue);
  color: var(--wp--preset--color--ink);
  font-family: var(--wp--preset--font-family--libertine);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  text-align: center;
}

.infobox__photo {
  display: block;
  width: 100%;
  height: auto;
}

.infobox__photo-placeholder {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--wp--preset--color--header-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.4rem;
  color: var(--wp--preset--color--muted);
  font-size: 0.75rem;
}

.infobox__photo-placeholder svg { width: 48px; height: 48px; opacity: 0.4; }

.infobox__table { width: 100%; border-collapse: collapse; }
.infobox__table td {
  padding: 0.35rem 0.65rem;
  vertical-align: top;
  border-top: 0.5px solid var(--wp--preset--color--border);
  line-height: 1.4;
  font-size: 0.82rem;
}
.infobox__table td:first-child {
  color: var(--wp--preset--color--muted);
  font-weight: 600;
  white-space: nowrap;
  width: 42%;
}

/* ============================================================
   ARTICLE BODY (person profile content area)
   ============================================================ */
.article-body { overflow: hidden; }

.article-toc {
  background: var(--wp--preset--color--surface);
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 4px;
  padding: 0.65rem 0.9rem;
  display: inline-block;
  min-width: 200px;
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
}

.article-toc__title {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

.article-toc ol { margin: 0; padding-left: 1.25rem; }
.article-toc li { margin: 0.2rem 0; }
.article-toc a { color: var(--wp--preset--color--link-blue); font-size: 0.85rem; }

.article-section { margin-bottom: 1.75rem; }

.article-section h2 {
  font-family: var(--wp--preset--font-family--libertine);
  font-size: 1.3rem;
  font-weight: 400;
  border-bottom: 1px solid var(--wp--preset--color--border);
  padding-bottom: 0.2rem;
  margin: 0 0 0.65rem;
}

.birth-notice {
  background: var(--wp--preset--color--surface);
  border-left: 3px solid var(--wp--preset--color--link-blue);
  padding: 0.5rem 0.75rem;
  font-size: 0.88rem;
  color: var(--wp--preset--color--muted);
  margin-bottom: 1rem;
  border-radius: 0 4px 4px 0;
  font-style: italic;
}

/* ============================================================
   PROFILES DIRECTORY
   ============================================================ */
.profiles-search-wrap {
  position: relative;
  margin-bottom: 0.85rem;
}

.profiles-search-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--wp--preset--color--muted);
  pointer-events: none;
}

.profiles-search {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  font-size: 0.9rem;
  font-family: var(--wp--preset--font-family--source-sans);
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 6px;
  background: var(--wp--preset--color--surface);
  color: var(--wp--preset--color--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.profiles-search:focus {
  border-color: var(--wp--preset--color--link-blue);
  box-shadow: 0 0 0 2px rgba(58, 110, 165, 0.15);
}

.profiles-table-wrap {
  background: var(--wp--preset--color--surface);
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* On mobile, hide lower-priority columns so the table fits without scrolling */
@media (max-width: 600px) {
  .profiles-table th:nth-child(3),
  .profiles-table td:nth-child(3),
  .profiles-table th:nth-child(4),
  .profiles-table td:nth-child(4),
  .profiles-table th:nth-child(5),
  .profiles-table td:nth-child(5) {
    display: none;
  }
  .profiles-table th,
  .profiles-table td {
    padding: 0.5rem 0.6rem;
  }
}


.profiles-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.profiles-table thead tr { background: var(--wp--preset--color--parchment); }

.profiles-table th {
  text-align: left;
  padding: 0.6rem 0.9rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--wp--preset--color--muted);
  border-bottom: 1px solid var(--wp--preset--color--border);
  white-space: nowrap;
}

.profiles-table th.sortable { cursor: pointer; user-select: none; }
.profiles-table th.sortable:hover { color: var(--wp--preset--color--ink); }
.sort-arrow { margin-left: 3px; opacity: 0.4; font-size: 0.7rem; }
.sort-arrow.active { opacity: 1; color: var(--wp--preset--color--link-blue); }

.profiles-table td {
  padding: 0.6rem 0.9rem;
  border-bottom: 0.5px solid var(--wp--preset--color--border);
  vertical-align: middle;
}

.profiles-table tbody tr:last-child td { border-bottom: none; }
.profiles-table tbody tr { cursor: pointer; transition: background 0.1s; }
.profiles-table tbody tr:hover { background: var(--wp--preset--color--header-blue); }
.profiles-table__name { font-family: var(--wp--preset--font-family--libertine); font-size: 1rem; font-weight: 600; color: var(--wp--preset--color--link-blue); }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 2px 9px;
  border-radius: 10px;
  font-weight: 600;
}
.badge--male    { background: #deeaf8; color: #1a4a7a; }
.badge--female  { background: #f0e8f5; color: #6a2a8a; }
.badge--living  { background: #e6f4ea; color: #1a6a2a; }
.badge--deceased{ background: #eeebe4; color: #5a5248; }

.no-results {
  padding: 2rem;
  text-align: center;
  color: var(--wp--preset--color--muted);
  font-size: 0.88rem;
  display: none;
}

/* ============================================================
   FAMILY TREE
   ============================================================ */
.tree-legend {
  display: flex;
  gap: 1.25rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.tree-legend__item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--wp--preset--color--muted);
}

.tree-legend__line {
  width: 28px;
  height: 2px;
}
.tree-legend__line--parent { background: var(--wp--preset--color--link-blue); }
.tree-legend__line--spouse {
  background: repeating-linear-gradient(
    90deg, var(--wp--preset--color--accent-rust) 0, var(--wp--preset--color--accent-rust) 4px, transparent 4px, transparent 8px
  );
}

.tree-canvas-wrap {
  background: var(--wp--preset--color--surface);
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 6px;
  overflow: hidden;
  padding: 1rem;
  position: relative;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  min-height: 50vh;
}
.tree-canvas-wrap:active { cursor: grabbing; }

#family-tree-svg { display: block; overflow: visible; }

.tree-node { cursor: pointer; }
.tree-node rect {
  fill: var(--wp--preset--color--surface);
  stroke: var(--wp--preset--color--link-blue);
  stroke-width: 1.5;
}
.tree-node:hover rect { fill: var(--wp--preset--color--header-blue); }
.tree-node--deceased rect { stroke: var(--wp--preset--color--border); fill: var(--wp--preset--color--parchment); }

.tree-node__name {
  font-family: 'Linux Libertine', Georgia, serif;
  font-size: 13px;
  font-weight: 600;
  fill: var(--wp--preset--color--ink);
  pointer-events: none;
}
.tree-node__years {
  font-size: 11px;
  fill: var(--wp--preset--color--muted);
  pointer-events: none;
}

.tree-edge--parent { stroke: var(--wp--preset--color--link-blue); stroke-width: 1.5; fill: none; }
.tree-edge--spouse { stroke: var(--wp--preset--color--accent-rust); stroke-width: 1.5; stroke-dasharray: 5,3; fill: none; }

/* ============================================================
   GENERATION LABELS (tree)
   ============================================================ */
.tree-gen-label {
  font-size: 11px;
  fill: var(--wp--preset--color--border);
  font-style: italic;
}

/* ============================================================
   UTILITY
   ============================================================ */
.screen-reader-text {
  border: 0; clip: rect(1px,1px,1px,1px); clip-path: inset(50%);
  height: 1px; margin: -1px; overflow: hidden; padding: 0;
  position: absolute; width: 1px; word-wrap: normal;
}

/* ============================================================
   PROFILES: VIEW TOGGLE + GRID
   ============================================================ */

.profiles-toolbar {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 0.4rem;
  position: relative;
  z-index: 10;
}

.profiles-view-toggle {
  display: flex;
  gap: 3px;
}

.profiles-view-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--wp--preset--color--border);
  background: var(--wp--preset--color--surface);
  border-radius: 6px;
  cursor: pointer;
  color: var(--wp--preset--color--muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  user-select: none;
  -webkit-user-select: none;
}

.profiles-view-btn svg {
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.profiles-view-btn:hover {
  background: var(--wp--preset--color--header-blue);
  color: var(--wp--preset--color--ink);
  border-color: var(--wp--preset--color--link-blue);
}

.profiles-view-btn.active {
  background: var(--wp--preset--color--link-blue);
  color: var(--wp--preset--color--surface);
  border-color: var(--wp--preset--color--link-blue);
}



/* Grid container — hidden by default; JS switches display */
.profiles-grid {
  display: none;
  grid-template-columns: repeat(3, 1fr) !important;
  grid-auto-rows: 1fr;
  gap: 1rem;
  align-items: stretch;
}

@media (max-width: 600px) {
  .profiles-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}
/* Card */
.profile-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  background: var(--wp--preset--color--surface);
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: var(--wp--preset--color--ink);
  transition: box-shadow 0.18s, border-color 0.18s, transform 0.18s;
}

.profile-card:hover {
  border-color: var(--wp--preset--color--link-blue);
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  transform: translateY(-2px);
  text-decoration: none;
}

.profile-card__img-wrap {
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: var(--wp--preset--color--header-blue);
  flex-shrink: 0;
  position: relative;
}

.profile-card__photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
}

.profile-card__photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--wp--preset--color--muted);
  opacity: 0.5;
}

.profile-card__body {
  padding: 0.65rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  border-top: 1px solid var(--wp--preset--color--border);
  background: var(--wp--preset--color--surface);
  flex: 1;
}

.profile-card__name {
  font-family: var(--wp--preset--font-family--libertine);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--wp--preset--color--link-blue);
  line-height: 1.3;
}

.profile-card__dates {
  font-size: 0.72rem;
  color: var(--wp--preset--color--muted);
  line-height: 1.3;
}

.profile-card__birthplace {
  font-size: 0.72rem;
  color: var(--wp--preset--color--muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-card__badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 0.15rem;
}

/* Pagination */
.profiles-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 1rem 0 0.5rem;
  grid-column: 1 / -1; /* span full grid width when inside .profiles-grid */
}

.profiles-page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  border: 1px solid var(--wp--preset--color--border);
  background: var(--wp--preset--color--surface);
  border-radius: 5px;
  font-size: 0.82rem;
  font-family: var(--wp--preset--font-family--source-sans);
  color: var(--wp--preset--color--ink);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.profiles-page-btn:hover:not([disabled]) {
  background: var(--wp--preset--color--header-blue);
  border-color: var(--wp--preset--color--link-blue);
}

.profiles-page-btn.current {
  background: var(--wp--preset--color--link-blue);
  border-color: var(--wp--preset--color--link-blue);
  color: var(--wp--preset--color--surface);
  font-weight: 600;
}

.profiles-page-btn[disabled] {
  opacity: 0.35;
  cursor: default;
}

.profiles-page-ellipsis {
  font-size: 0.82rem;
  color: var(--wp--preset--color--muted);
  padding: 0 2px;
  line-height: 32px;
}
