
:root {
    --fh-bg: #f5f7fb;
    --fh-card: #ffffff;
    --fh-text: #182230;
    --fh-muted: #667085;
    --fh-primary: #3157a4;
    --fh-line: #a9b8d0;
    --fh-border: #e5eaf2;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--fh-bg);
    color: var(--fh-text);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input {
    font: inherit;
}

.fh-container {
    width: min(1200px, calc(100% - 36px));
    margin: 0 auto;
}

/* HEADER */

.fh-header {
    padding: 22px 0;
    background: white;
    border-bottom: 1px solid var(--fh-border);
}

.fh-brand {
    font-size: 21px;
    font-weight: 800;
    color: var(--fh-primary);
}

/* HERO */

.fh-hero {
    padding: 48px 0 30px;
}

.fh-hero h1 {
    margin: 0 0 10px;
    font-size: clamp(28px, 5vw, 42px);
}

.fh-hero p {
    color: var(--fh-muted);
    max-width: 650px;
    line-height: 1.7;
}

/* STATISTIK */

.fh-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin: 20px 0 36px;
}

.fh-stat,
.fh-panel {
    background: var(--fh-card);
    border: 1px solid var(--fh-border);
    border-radius: 16px;
    padding: 20px;
}

.fh-stat span {
    display: block;
    color: var(--fh-muted);
    font-size: 13px;
}

.fh-stat strong {
    display: block;
    margin-top: 8px;
    font-size: 28px;
}

/* SECTION */

.fh-section {
    margin: 32px 0;
}

.fh-section-heading {
    margin-bottom: 16px;
}

.fh-section-heading h2 {
    margin: 0 0 6px;
    font-size: 23px;
}

.fh-section-heading p {
    margin: 0;
    color: var(--fh-muted);
    font-size: 14px;
    line-height: 1.6;
}

/* SEARCH */

.fh-search {
    width: 100%;
    max-width: 420px;
    padding: 12px 14px;
    border: 1px solid var(--fh-border);
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    background: white;
}

.fh-search:focus {
    border-color: var(--fh-primary);
    box-shadow: 0 0 0 3px #3157a41a;
}

/* DAFTAR ANGGOTA */

.fh-member-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 14px;
    margin-top: 18px;
}

.fh-member-card {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 16px;
    background: white;
    border: 1px solid var(--fh-border);
    border-radius: 13px;
    cursor: pointer;
    transition: .2s;
}

.fh-member-card:hover {
    border-color: var(--fh-primary);
    transform: translateY(-2px);
}

.fh-member-card strong {
    display: block;
    margin-bottom: 7px;
}

.fh-member-card small {
    color: var(--fh-muted);
    line-height: 1.6;
}

/* FOTO ANGGOTA */

.fh-photo-wrapper {
    position: relative;
    display: block;
    flex-shrink: 0;
    width: 46px;
    height: 46px;
}

.fh-person-photo {
    display: block;
    width: 46px;
    height: 46px;
    object-fit: cover;
    border-radius: 50%;
    border: 2px solid var(--fh-border);
}

.fh-photo-fallback {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #e8edf7;
    color: var(--fh-primary);
    font-weight: 800;
}

.fh-person-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #e8edf7;
    color: var(--fh-primary);
    font-weight: 800;
}

/* POHON SILSILAH */

.fh-tree-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.fh-tree-controls {
    display: flex;
    gap: 8px;
}

.fh-tree-controls button {
    border: 1px solid var(--fh-border);
    background: white;
    border-radius: 9px;
    padding: 9px 13px;
    cursor: pointer;
    font-size: 14px;
}

.fh-tree-controls button:hover {
    border-color: var(--fh-primary);
    color: var(--fh-primary);
}

.fh-tree-help {
    color: var(--fh-muted);
    font-size: 12px;
}

#treeViewport {
    position: relative;
    height: 650px;
    overflow: hidden;
    background-color: #fbfcff;
    background-image: radial-gradient(#dce3ef 1px, transparent 1px);
    background-size: 20px 20px;
    border: 1px solid var(--fh-border);
    border-radius: 16px;
    cursor: grab;
    touch-action: none;
}

#treeViewport.is-dragging {
    cursor: grabbing;
}

#treeCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: max-content;
    min-width: 100%;
    padding: 35px;
    transform-origin: 0 0;
}

.fh-tree-roots {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 70px;
    width: max-content;
    min-width: 100%;
}

.fh-family {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.fh-couple {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 8px;
    position: relative;
    padding-bottom: 28px;
}

.fh-couple::after {
    content: "";
    position: absolute;
    width: 2px;
    height: 20px;
    background: var(--fh-line);
    bottom: 0;
    left: 50%;
}

.fh-person {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 175px;
    min-height: 86px;
    padding: 10px;
    border: 1px solid var(--fh-border);
    border-radius: 12px;
    background: white;
    box-shadow: 0 3px 10px #1822300a;
    cursor: pointer;
    text-align: left;
    transition: .2s;
}

.fh-person:hover {
    border-color: var(--fh-primary);
    box-shadow: 0 4px 15px #3157a420;
}

.fh-person .fh-photo-wrapper,
.fh-person .fh-person-avatar {
    width: 42px;
    height: 42px;
}

.fh-person .fh-person-photo {
    width: 42px;
    height: 42px;
}

.fh-person-info {
    min-width: 0;
}

.fh-person .fh-person-name {
    display: block;
    font-size: 13px;
    font-weight: 750;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.fh-person .fh-person-meta {
    display: block;
    margin-top: 7px;
    color: var(--fh-muted);
    font-size: 11px;
}

.fh-person.male {
    border-top: 3px solid #5284ce;
}

.fh-person.female {
    border-top: 3px solid #c47ba7;
}

.fh-person.unknown {
    border-top: 3px solid #9aa4b2;
}

/* LABEL PERNIKAHAN */

.fh-marriage-label {
    display: none;
}

/* ANAK */

.fh-children {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 28px;
    position: relative;
    padding-top: 24px;
    border-top: 2px solid var(--fh-line);
    margin-top: 0;
}

.fh-children:empty {
    display: none;
}

.fh-child-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding-top: 0;
}

.fh-child-branch::before {
    content: "";
    width: 2px;
    height: 24px;
    background: var(--fh-line);
    position: absolute;
    top: -25px;
    left: 50%;
}

.fh-child-person {
    margin-bottom: 14px;
}

.fh-descendant-families {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 25px;
    padding-top: 10px;
}

.fh-descendant-families .fh-family {
    transform: scale(.94);
    transform-origin: top center;
}

.fh-empty-tree {
    padding: 50px 20px;
    color: var(--fh-muted);
    text-align: center;
}

/* HUBUNGAN KELUARGA */

.fh-relation-list {
    display: grid;
    gap: 10px;
}

.fh-relation-item {
    background: white;
    border: 1px solid var(--fh-border);
    border-radius: 10px;
    padding: 14px;
    font-size: 14px;
}

.fh-relation-item small {
    display: block;
    margin-top: 6px;
    color: var(--fh-muted);
}

/* MODAL */

.fh-modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: #10182880;
}

.fh-modal-backdrop.show {
    display: flex;
}

.fh-modal {
    width: min(430px, 100%);
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 15px 50px #0002;
}

.fh-modal h3 {
    margin-top: 0;
}

.fh-modal p {
    color: var(--fh-muted);
    font-size: 14px;
    line-height: 1.7;
}

.fh-modal button {
    padding: 9px 15px;
    border: 0;
    border-radius: 8px;
    background: var(--fh-primary);
    color: white;
    cursor: pointer;
}

.fh-modal button:hover {
    background: #244582;
}

/* FOOTER */

.fh-footer {
    padding: 30px 0;
    color: var(--fh-muted);
    text-align: center;
    font-size: 13px;
}

/* RESPONSIVE */

@media (max-width: 650px) {
    .fh-container {
        width: calc(100% - 24px);
    }

    .fh-stats {
        grid-template-columns: 1fr;
    }

    #treeViewport {
        height: 540px;
    }

    .fh-tree-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .fh-tree-roots {
        justify-content: flex-start;
    }

    .fh-member-grid {
        grid-template-columns: 1fr;
    }
}


.fh-member-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 5px;
}

.fh-member-info strong {
    margin-bottom: 0;
}

.fh-member-info small {
    line-height: 1.6;
}


/* Foto anggota pada pohon keluarga */
.fh-photo-wrapper {
    position: relative;
    display: block;
    flex-shrink: 0;
    width: 48px;
    height: 48px;
}

.fh-person-photo {
    display: block;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center;
    border: 2px solid #e5eaf2;
}

.fh-photo-fallback {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
}

/* Susunan foto dan informasi anggota */
.fh-person {
    display: flex;
    align-items: center;
    gap: 10px;
}

.fh-person-info {
    min-width: 0;
    flex: 1;
}
