/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #faf8f5;
    --bg-card: #ffffff;
    --text: #2c2c2c;
    --text-muted: #6b6b6b;
    --accent: #5b7a5e;
    --accent-light: #e8f0e8;
    --accent-dark: #3d5a3f;
    --border: #e2ddd5;
    --shadow: 0 2px 12px rgba(0,0,0,0.06);
    --shadow-hover: 0 4px 20px rgba(0,0,0,0.10);
    --radius: 10px;
    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'Inter', -apple-system, sans-serif;
    --max-width: 1200px;
}

html { scroll-behavior: smooth; }
body {
    font-family: var(--font-body);
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; }
main { flex: 1; }

/* ===== NAV ===== */
.site-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.nav-brand {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-dark);
}
.nav-brand:hover { text-decoration: none; }
.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}
.nav-links a {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: color 0.2s;
}
.nav-links a:hover { color: var(--accent-dark); text-decoration: none; }

/* Search */
.search-box { position: relative; }
.search-box input {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.85rem;
    font-family: var(--font-body);
    width: 200px;
    transition: border-color 0.2s, width 0.3s;
}
.search-box input:focus {
    outline: none;
    border-color: var(--accent);
    width: 260px;
}
.search-results {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-hover);
    display: none;
    min-width: 260px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 200;
}
.search-results.active { display: block; }
.search-result-item {
    display: block;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover {
    background: var(--accent-light);
    text-decoration: none;
}
.search-result-item small { color: var(--text-muted); }

/* ===== HERO ===== */
.hero {
    text-align: center;
    padding: 4rem 2rem 3rem;
    background: linear-gradient(135deg, var(--accent-light) 0%, var(--bg) 100%);
}
.hero h1 {
    font-size: 2.8rem;
    color: var(--accent-dark);
    margin-bottom: 0.5rem;
}
.hero-desc {
    font-size: 1.1rem;
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto;
}
.hero-stats {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--accent);
    font-weight: 500;
}

/* ===== TREE ===== */
.tree-section {
    max-width: var(--max-width);
    margin: 2rem auto;
    padding: 0 2rem;
}
.tree-section h2 { margin-bottom: 1rem; }
.tree-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.tree-controls button {
    padding: 0.3rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    cursor: pointer;
    font-size: 1rem;
    font-family: var(--font-body);
    transition: background 0.2s;
}
.tree-controls button:hover { background: var(--accent-light); }

.tree-container {
    width: 100%;
    min-height: 500px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.tree-container svg { width: 100%; height: 100%; }

/* D3 tree styling */
.node circle {
    stroke-width: 2.5px;
    cursor: pointer;
    transition: all 0.2s;
}
.node circle:hover {
    stroke-width: 3.5px;
    filter: brightness(0.9);
}
.node text {
    font-family: var(--font-body);
    font-size: 12px;
    fill: var(--text);
}
.node .dates {
    font-size: 10px;
    fill: var(--text-muted);
}
.link {
    fill: none;
    stroke: var(--border);
    stroke-width: 1.5px;
}

/* ===== PEOPLE GRID ===== */
.people-grid-section {
    max-width: var(--max-width);
    margin: 3rem auto;
    padding: 0 2rem;
}
.people-grid-section h2 { margin-bottom: 1.5rem; }
.people-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.25rem;
}
.person-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
    color: var(--text);
}
.person-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
    text-decoration: none;
}
.person-card-photo {
    width: 100%;
    aspect-ratio: 1;
    background-size: cover;
    background-position: center;
    background-color: var(--accent-light);
}
.person-card-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
}
.person-card-placeholder span {
    font-family: var(--font-display);
    font-size: 3rem;
    color: var(--accent);
    opacity: 0.6;
}
.person-card-info { padding: 0.75rem 1rem; }
.person-card-info h3 {
    font-size: 1rem;
    margin-bottom: 0.15rem;
}
.person-dates {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== PERSON PAGE ===== */
.person-page {
    max-width: var(--max-width);
    margin: 2rem auto;
    padding: 0 2rem;
}
.person-header {
    display: flex;
    gap: 2rem;
    margin-bottom: 2.5rem;
    align-items: flex-start;
}
.person-portrait {
    width: 250px;
    height: 250px;
    border-radius: var(--radius);
    background-size: cover;
    background-position: center;
    background-color: var(--accent-light);
    flex-shrink: 0;
    box-shadow: var(--shadow);
}
.person-portrait-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
}
.person-portrait-placeholder span {
    font-family: var(--font-display);
    font-size: 5rem;
    color: var(--accent);
    opacity: 0.5;
}
.person-details { flex: 1; }
.person-details h1 {
    font-size: 2.2rem;
    color: var(--accent-dark);
    margin-bottom: 0.5rem;
}
.person-meta {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.meta-item {
    font-size: 0.9rem;
    color: var(--text-muted);
}
.person-bio {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text);
}

/* Relationships */
.relationships {
    margin-bottom: 2.5rem;
    padding: 1.5rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.relationships h2 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
}
.relationship-groups {
    display: flex;
    gap: 2.5rem;
    flex-wrap: wrap;
}
.rel-group h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}
.rel-link {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: var(--accent-light);
    border-radius: 20px;
    font-size: 0.9rem;
    margin: 0.2rem 0.2rem 0.2rem 0;
    transition: background 0.2s;
}
.rel-link:hover {
    background: var(--accent);
    color: white;
    text-decoration: none;
}

/* ===== MEDIA GRID ===== */
.person-gallery { margin-bottom: 3rem; }
.person-gallery h2 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
}
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}
.media-item {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-card);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.media-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}
.media-item img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    display: block;
}
.media-video video {
    width: 100%;
    aspect-ratio: 16/9;
    object-fit: cover;
    display: block;
    background: #000;
}
.media-caption {
    display: block;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    color: var(--text);
}
.media-date {
    display: block;
    padding: 0 0.6rem 0.4rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.media-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.6));
    padding: 2rem 0.6rem 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
}
.media-item:hover .media-overlay { opacity: 1; }
.media-overlay .media-caption,
.media-overlay .media-date,
.media-overlay .media-event {
    color: #fff;
    padding: 0;
    font-size: 0.8rem;
}

/* ===== GALLERY PAGE ===== */
.gallery-page {
    max-width: var(--max-width);
    margin: 2rem auto;
    padding: 0 2rem;
}
.gallery-page h1 {
    font-size: 2rem;
    margin-bottom: 1rem;
}
.gallery-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1.5rem;
}
.filter-btn {
    padding: 0.35rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-card);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: var(--font-body);
    transition: all 0.2s;
    color: var(--text-muted);
}
.filter-btn:hover, .filter-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* ===== DOCUMENTS / PDF ===== */
.documents-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.media-document {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: var(--text);
}
.media-document:hover { text-decoration: none; }
.doc-thumb {
    width: 100%;
    aspect-ratio: 3/4;
    overflow: hidden;
    background: #f5f0eb;
    display: flex;
    align-items: center;
    justify-content: center;
}
.doc-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    aspect-ratio: auto;
}
.doc-icon-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #f5f0eb, #e8e0d5);
}
.doc-icon {
    display: inline-block;
    padding: 0.4rem 1rem;
    background: #c0392b;
    color: #fff;
    border-radius: 4px;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.05em;
}
.doc-info {
    padding: 0.6rem 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.doc-info .media-caption {
    padding: 0;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
}
.doc-type {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.doc-info .media-date {
    padding: 0;
}

/* ===== LIGHTBOX ===== */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    cursor: pointer;
}
.lightbox.active { display: flex; }
.lightbox img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
}
.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 2rem;
    color: #fff;
    cursor: pointer;
}
.lightbox-caption {
    color: #ccc;
    margin-top: 0.75rem;
    font-size: 0.9rem;
    text-align: center;
}

/* ===== FOOTER ===== */
.site-footer {
    text-align: center;
    padding: 2rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: 3rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .hero h1 { font-size: 2rem; }
    .person-header { flex-direction: column; align-items: center; text-align: center; }
    .person-portrait { width: 180px; height: 180px; }
    .person-meta { justify-content: center; }
    .relationship-groups { flex-direction: column; gap: 1rem; }
    .media-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .people-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .nav-links { gap: 0.75rem; }
    .search-box input { width: 140px; }
    .search-box input:focus { width: 180px; }
}
