/* === Main Family Tree Container === */
.bp-family-tree {
    text-align: center;
    margin: 20px auto;
    padding: 20px;
    max-width: 1200px;
    position: relative;
}

/* Family Tree Viewport */
.family-tree-viewport {
    position: relative;
    overflow: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #f9f9f9;
    padding: 40px 20px;
    height: 600px;
    width: 100%;
    cursor: grab;
}

.family-tree-viewport:active {
    cursor: grabbing;
}

.bp-family-tree-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    min-height: 100%;
    min-width: fit-content;
}

/* === Family Generations === */
.family-generation {
    position: relative;
    margin: 15px 0;
    z-index: 2;
}

.family-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    flex-wrap: nowrap;
    position: relative;
}

/* === Individual Member Cards === */
.family-member-card {
    position: relative;
    display: inline-block;
    z-index: 3;
}

.family-member,
.family-member.no-profile {
    display: block;
    text-align: center;
    text-decoration: none;
    padding: 15px;
    background: #ffffff;
    border: 2px solid #e1e5e9;
    border-radius: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    position: relative;
    min-width: 120px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.family-member:hover {
    background: #f8f9fa;
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    border-color: #007cba;
}

/* Avatar styling */
.family-member img {
    border-radius: 50%;
    margin-bottom: 8px;
    border: 3px solid #ffffff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.family-member .fm-avatar {
    font-size: 40px;
    margin-bottom: 8px;
    opacity: 0.6;
}

/* Text styling */
.family-member .fm-name {
    display: block;
    font-weight: 600;
    font-size: 14px;
    color: #2c3e50;
    margin: 5px 0;
    line-height: 1.2;
}

.family-member .fm-birthday {
    display: block;
    font-size: 11px;
    color: #6c757d;
    margin-top: 3px;
}

.family-member .fm-marriage {
    display: block;
    font-size: 10px;
    color: #e74c3c;
    margin-top: 3px;
    font-style: italic;
}

/* === Connector Lines === */
.family-connector {
    background: #bdc3c7;
    position: relative;
    z-index: 1;
}

.vertical-down {
    width: 2px;
    height: 40px;
    margin: 0 auto;
    background: #bdc3c7;
}

/* === Generation-specific Styling === */

/* Parents / Ancestor generations shared base */
.parents-generation {
    margin-bottom: 20px;
}

/*
 * Row that holds all couple groups side by side for one generation.
 * Groups are fully independent — no connecting line runs between them.
 */
.parents-groups-row {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 80px;
}

/*
 * A single couple group within a generation.
 * The horizontal line inside only spans this couple's two cards.
 */
.parent-group {
    position: relative;
}

.parent-group .family-row {
    position: relative;
}

/* ── Ancestor generation visual differentiation ─────────────────────────── */

/*
 * Cards get progressively smaller and slightly more muted as generations
 * go further back, giving a natural visual "depth" to the tree.
 */

/* Great-great-grandparents — most distant, smallest, most muted */
.generation-great-great-grandparents .family-member {
    min-width: 88px;
    min-height: 88px;
    padding: 8px;
    border-color: #c8bfb0;
    background: #faf7f2;
    opacity: 0.82;
}
.generation-great-great-grandparents .family-member img {
    width: 44px;
    height: 44px;
}
.generation-great-great-grandparents .family-member .fm-name {
    font-size: 11px;
}
.generation-great-great-grandparents .family-member .fm-birthday {
    font-size: 9px;
}
.generation-great-great-grandparents .family-member .fm-avatar {
    font-size: 28px;
}

/* Great-grandparents */
.generation-great-grandparents .family-member {
    min-width: 100px;
    min-height: 100px;
    padding: 10px;
    border-color: #b8c4cc;
    background: #f4f7f9;
    opacity: 0.88;
}
.generation-great-grandparents .family-member img {
    width: 54px;
    height: 54px;
}
.generation-great-grandparents .family-member .fm-name {
    font-size: 12px;
}
.generation-great-grandparents .family-member .fm-birthday {
    font-size: 10px;
}
.generation-great-grandparents .family-member .fm-avatar {
    font-size: 32px;
}

/* Grandparents */
.generation-grandparents .family-member {
    min-width: 110px;
    min-height: 110px;
    padding: 12px;
    border-color: #a8bccf;
    background: #f0f4f8;
    opacity: 0.93;
}
.generation-grandparents .family-member img {
    width: 64px;
    height: 64px;
}
.generation-grandparents .family-member .fm-name {
    font-size: 13px;
}
.generation-grandparents .family-member .fm-avatar {
    font-size: 36px;
}

/* Horizontal line connecting the two parents within ONE group */
.parent-group .family-row::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: #bdc3c7;
    z-index: 1;
    transform: translateY(-1px);
}

/* Hide the line when the group has only one parent card */
.parent-group .family-row:has(.family-member-card:only-child)::after {
    display: none;
}

/* Make sure parent cards sit on top of their group's connector line */
.parent-group .family-member-card {
    z-index: 3;
    background: #fff;
    border-radius: 15px;
}

/* ── Main row: root user branch + spouse(s) ─────────────────────────────── */

/*
 * The main row holds two things side by side:
 *   1. .root-user-branch  — ancestor chain stacked above the root user's card
 *   2. Direct .family-member-card children  — the spouse card(s)
 *
 * align-items: flex-end aligns the bottoms, so the spouse card's vertical
 * midpoint matches the root user card's midpoint (both sit at the same
 * floor level).  The couple connecting line is drawn by JavaScript, which
 * can measure the exact card positions after render.
 */
.main-row {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 30px;
    position: relative;
}

/* Couple connector line — injected by JS as a .couple-line div */
.couple-line {
    position: absolute;
    height: 2px;
    background: #bdc3c7;
    z-index: 0;
    pointer-events: none;
}

/*
 * Root user branch: all ancestor generations stack here,
 * then the root user's own card sits at the very bottom.
 * Everything inside is centred, so ancestor rows are always
 * centred directly above the root user's card — not above the
 * midpoint of the whole couple.
 */
.root-user-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
}

/* Ancestor chain: the vertical stack of generation rows + connectors */
.ancestor-chain {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Root user card styling — the focal person */
.root-user-branch > .family-member-card .family-member {
    background: #e3f2fd;
    border-color: #2196f3;
    font-weight: bold;
}

.root-user-branch > .family-member-card .family-member:hover {
    background: #bbdefb;
    border-color: #1976d2;
}

/* Spouse cards in the main row sit above the couple line */
.main-row > .family-member-card {
    position: relative;
    z-index: 1;
}

/* Children Generation */
.children-generation {
    margin-top: 20px;
}

.children-generation .family-row {
    position: relative;
    gap: 60px; /* More space between children */
}

/* Style for child cards */
.children-generation .family-member {
    background: #fff3e0;
    border-color: #ff9800;
}

.children-generation .family-member:hover {
    background: #ffe0b2;
    border-color: #f57c00;
}

/* Child branches with connecting lines */
.child-branch {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Vertical line from parent level to child */
.child-branch::before {
    content: '';
    position: absolute;
    top: -40px; /* Height of the vertical-down connector */
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 40px;
    background: #bdc3c7;
    z-index: 1;
}

/* Horizontal line connecting all children */
.children-generation .family-row::after {
    content: '';
    position: absolute;
    top: -40px; /* Same as child-branch::before top */
    left: 0;
    right: 0;
    height: 2px;
    background: #bdc3c7;
    z-index: 1;
}

/* Hide horizontal line if only one child */
.children-generation .family-row:has(.child-branch:only-child)::after {
    display: none;
}

/* Parent information styling */
.family-member .fm-parents {
    display: block;
    font-size: 9px;
    color: #9c27b0;
    margin-top: 3px;
    font-style: italic;
}

/* === Special Cases === */

/* No profile styling */
.family-member.no-profile {
    background: #f8f9fa;
    border-color: #dee2e6;
    opacity: 0.8;
}

.family-member.no-profile:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

/* === Tree Controls === */
.family-tree-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.9);
    padding: 5px;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.tree-control-btn {
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.tree-control-btn:hover {
    background: #f5f5f5;
    border-color: #999;
}

.tree-control-btn:active {
    transform: translateY(1px);
}

.tree-control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Zoom levels - transform origin set to top center to keep top cards visible */
.zoom-level-50 .bp-family-tree-container {
    transform: scale(0.5);
    transform-origin: top center;
}
.zoom-level-75 .bp-family-tree-container {
    transform: scale(0.75);
    transform-origin: top center;
}
.zoom-level-100 .bp-family-tree-container {
    transform: scale(1.0);
    transform-origin: top center;
}
.zoom-level-125 .bp-family-tree-container {
    transform: scale(1.25);
    transform-origin: top center;
}
.zoom-level-150 .bp-family-tree-container {
    transform: scale(1.5);
    transform-origin: top center;
}
.zoom-level-200 .bp-family-tree-container {
    transform: scale(2.0);
    transform-origin: top center;
}

/* Fullscreen styles */
.bp-family-tree.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    max-width: none;
    margin: 0;
    padding: 0;
    z-index: 9999;
    background: white;
}

.bp-family-tree.fullscreen .family-tree-viewport {
    height: 100vh;
    border: none;
    border-radius: 0;
}

/* Fullscreen overlay elements - only visible in fullscreen */
.fullscreen-overlay {
    display: none;
}

.bp-family-tree.fullscreen .fullscreen-overlay {
    display: block;
    position: absolute;
    z-index: 10001;
}

.fullscreen-logo {
    top: 20px;
    left: 20px;
    animation: slideInFromLeft 0.8s ease-out;
}

.fullscreen-logo .site-logo-wrapper {
    max-width: 200px;
    opacity: 0.9;
}

.fullscreen-copyright {
    bottom: 20px;
    right: 20px;
    color: #999;
    font-size: 12px;
    font-family: Arial, sans-serif;
    animation: slideInFromRight 0.8s ease-out;
}

/* Animations for fullscreen elements */
@keyframes slideInFromLeft {
    from {
        transform: translateX(-100px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 0.9;
    }
}

@keyframes slideInFromRight {
    from {
        transform: translateX(100px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ── Profile "Family Tree" button ───────────────────────────────────────── */

.family-tree-profile-btn {
    background: #ffffff;
    border: 2px solid #2196f3;
    color: #2196f3;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.family-tree-profile-btn:hover {
    background: #2196f3;
    color: #ffffff;
}

/* ── Profile family tree modal ──────────────────────────────────────────── */

/*
 * Full-screen modal overlay.
 * Hidden by default; JavaScript toggles aria-hidden and display.
 */
.ft-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
}

.ft-modal[aria-hidden="false"] {
    display: block;
}

/* Semi-transparent backdrop */
.ft-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
}

/* Inner panel — near-fullscreen with a small safe margin */
.ft-modal-inner {
    position: absolute;
    inset: 20px;
    background: #f9f9f9;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

/* Header bar */
.ft-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: #ffffff;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.ft-modal-title {
    font-size: 16px;
    font-weight: 700;
    color: #2c3e50;
}

.ft-modal-close {
    background: none;
    border: 1px solid #ccc;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: #555;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ft-modal-close:hover {
    background: #f44336;
    border-color: #f44336;
    color: #ffffff;
}

/* Scrollable tree viewport — fills remaining height */
.ft-modal-viewport {
    flex: 1;
    overflow: auto;
    padding: 30px 20px;
    cursor: grab;
    position: relative;
}

.ft-modal-viewport:active {
    cursor: grabbing;
}

/* Footer bar */
.ft-modal-footer {
    padding: 10px 20px;
    background: #ffffff;
    border-top: 1px solid #e0e0e0;
    font-size: 12px;
    color: #999;
    text-align: right;
    flex-shrink: 0;
}

/* Tree inside the modal uses same container/card styles as the shortcode tree */
.ft-modal-viewport .bp-family-tree-container {
    min-width: fit-content;
}

/* ── Responsive Design ───────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .ft-modal-inner {
        inset: 0;
        border-radius: 0;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .bp-family-tree {
        padding: 10px;
    }

    .family-tree-viewport {
        height: 400px;
        padding: 20px 10px;
    }

    .family-row {
        gap: 20px;
    }

    .parents-groups-row {
        gap: 40px;
    }

    .children-generation .family-row {
        gap: 40px;
    }

    .family-member,
    .family-member.no-profile {
        min-width: 100px;
        min-height: 100px;
        padding: 10px;
    }

    .family-tree-controls {
        position: relative;
        top: auto;
        right: auto;
        justify-content: center;
        margin-top: 10px;
    }
}
