/* Family Tree Styles */
/* ============================================================================
 * family_tree.css
 * Companion stylesheet for family_tree.js (dabeng/OrgChart family-tree mode).
 * Include this AFTER orgchart's own dist/css/orgchart.css so these rules win.
 * ============================================================================ */

 /* Family Tree Card */
 .family-tree-card {
   overflow: hidden;
}

.family-tree-alert {
   margin-bottom: 1rem;
}

/* ---- Chart title (Requirement: Set Family name as Org Chart title) -------- */
#family-tree-title {
    margin: 0 0 12px;
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
    color: #1F3327;
}

/* ---- Hide the default dotted/grid background ------------------------------ */
#family-tree-chart {
    position: relative;
    padding-top: 44px;
}
#family-tree-chart .orgchart,
#family-tree-chart.orgchart-container {
    background-image: none !important;
}

/* ---- Export button placement/style ----------------------------------------- */
.oc-export-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #A65A34;
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 8px 16px 8px 14px;
    font-size: 12.5px;
    font-weight: 600;
    font-family: 'Work Sans', -apple-system, sans-serif;
    letter-spacing: .01em;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(43, 33, 24, 0.22);
    transition: background-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.oc-export-btn::before {
    content: "\2913"; /* download glyph */
    font-size: 14px;
    line-height: 1;
}
.oc-export-btn:hover {
    background-color: #8F4B2A;
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(43, 33, 24, 0.28);
}
.oc-export-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(43, 33, 24, 0.22);
}

/* ---- Base node sizing so the photo + actions fit --------------------------- */
#family-tree-chart .node {
    width: 168px;
    min-height: 78px;
    padding: 30px 8px 8px;
    margin: 0 10px 52px 0;
    position: relative;
    border-width: 2px;
    border-style: solid;
    border-radius: 14px;
    background: linear-gradient(145deg, #ffffff 0%, #fbf8f2 100%);
    text-align: center;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: visible;
    box-shadow: 0 5px 14px rgba(43, 33, 24, .12);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
#family-tree-chart .node::before {
    content: "";
    position: absolute;
    top: 0;
    left: 2px;
    right: 2px;
    height: 9px;
    z-index: 1;
}
#family-tree-chart .node:focus,
#family-tree-chart .node:hover {
    outline: none;
    transform: translateY(-2px);
    box-shadow: 0 9px 20px rgba(43, 33, 24, .18), 0 0 0 3px rgba(79,112,88,.2);
}

/* ---- Profile photo ---------------------------------------------------------- */
.ft-node-photo-wrap {
    position: absolute;
    top: -23px;
    left: 50%;
    z-index: 0;
    transform: translateX(-50%);
}
.ft-node-photo {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #fff;
    box-shadow: 0 4px 12px rgba(43, 33, 24, .2), 0 0 0 2px rgba(255, 255, 255, .9);
    background: #eee;
}
.ft-node-photo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6B5D4C;
    font-size: 22px;
}
.ft-online-dot {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #4F7058;
    border: 2px solid #fff;
}

/* ---- Gender styling (node accent / photo ring) ------------------------------ */
#family-tree-chart .node.gender-male .ft-node-photo { box-shadow: 0px 2px 8px 0px #4F7058; }
#family-tree-chart .node.gender-male .title { color: #4F7058; }
#family-tree-chart .node.gender-male .content { border-color: #1F3327; }
#family-tree-chart .node.gender-female .ft-node-photo { box-shadow: 0px 2px 8px 0px #A65A34; }
#family-tree-chart .node.gender-female .title { color: #A65A34; }
#family-tree-chart .node.gender-female .content { border-color: #8F4B2A; }
#family-tree-chart .node.gender-other .ft-node-photo { box-shadow: 0px 2px 8px 0px #C0923F; }
#family-tree-chart .node.gender-other .title { color: #8F6B28; }
#family-tree-chart .node.gender-other .content { border-color: #8F6B28; }

/* Compact text hierarchy: the member name is prominent, while the relationship
   remains visible as a small label below it. */
#family-tree-chart .node .title,
#family-tree-chart .node .content {
    display: block;
    width: auto;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    background: transparent;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#family-tree-chart .node .content {
    order: 2;
    color: #6B5D4C;
    font-size: 9px;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: .02em;
    text-transform: uppercase;
}
#family-tree-chart .node .title {
    order: 1;
    color: #1F3327;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
}
#family-tree-chart .node .title::after {
    margin-left: 4px;
}
#family-tree-chart .node .ft-node-actions {
    order: 3;
}

/* Keep more of the family tree visible at once on phones. */
@media (max-width: 576px) {
    #family-tree-chart {
        padding-top: 36px;
    }
    #family-tree-chart .node {
        width: 136px;
        min-height: 68px;
        padding: 25px 6px 6px;
        margin: 0 6px 42px 0;
        border-radius: 11px;
    }
    #family-tree-chart .node .ft-node-photo {
        width: 38px;
        height: 38px;
    }
    #family-tree-chart .node .ft-node-photo-icon {
        font-size: 18px;
    }
    #family-tree-chart .node .title {
        font-size: 11px;
    }
    #family-tree-chart .node .content {
        font-size: 8px;
    }
}

/* ---- Status color coding ---------------------------------------------------- */
/* Deceased -> gold */
#family-tree-chart .node.status-deceased { border-color: #B08028; background: #F6EBD3; }

/* Alive but inactive -> grey */
#family-tree-chart .node.status-inactive { border-color: #9C8A73; background: #F1E9DA; }
#family-tree-chart .node.inactive-member .content { opacity: 0.75; font-style: italic; }

/* Active -> red */
#family-tree-chart .node.status-active { border-color: #1F3327; background: #fffaf3; }

/* Online -> green */
#family-tree-chart .node.status-online { border-color: #4F7058; background: #f6ead9;; }

/* Base member -> blue highlight ring, layered on top of the status color */
#family-tree-chart .node.base-member {
    border-color: #A65A34;
    background: linear-gradient(145deg, #fffaf3 0%, #f6ead9 100%);
    box-shadow: 0 7px 18px rgba(143, 75, 42, .2), 0 0 0 3px rgba(166, 90, 52, .22);
}
#family-tree-chart .node.base-member .content {
    color: #8F4B2A;
}

/* ---- Node action bar ---------------------------------------------------------- */
.ft-node-actions {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    width: max-content;
    max-width: 168px;
    margin: 0;
    padding: 5px;
    border: 1px solid #E4D9C4;
    border-radius: 10px;
    background: rgba(255, 255, 255, .97);
    box-shadow: 0 5px 14px rgba(43, 33, 24, .18);
    transform: translateX(-50%);
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    overflow: visible;
    pointer-events: none;
    transition: opacity .12s ease, visibility .12s ease;
}
#family-tree-chart .node:hover .ft-node-actions,
#family-tree-chart .node:focus-within .ft-node-actions,
#family-tree-chart .node.ft-actions-open .ft-node-actions {
    opacity: 1;
    visibility: visible;
    max-height: none;
    pointer-events: auto;
}
.ft-btn {
    font-size: 11px;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 3px;
    border: 1px solid #E4D9C4;
    background: #fff;
    color: #2F4A3A;
    cursor: pointer;
}
.ft-btn:hover { background: #F1E9DA; }
.ft-btn-info {
    width: 18px;
    height: 18px;
    padding: 0;
    border-radius: 50%;
    font-style: italic;
    font-weight: 700;
}
.ft-btn-invite { border-color: #9C8A73; }
.ft-btn-contact { border-color: #A65A34; color: #A65A34; }
 
/* ---- Popovers (Info, Add Member, Contact, toast) ------------------------------ */
.ft-popover {
    position: absolute;
    z-index: 2000;
    min-width: 160px;
    max-width: 260px;
    background: #fff;
    border: 1px solid #E4D9C4;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
    padding: 8px;
    font-size: 13px;
}
.ft-popover-title {
    font-weight: 600;
    margin-bottom: 6px;
    color: #1F3327;
}
.ft-info-list {
    margin: 0;
}
.ft-info-list dt {
    font-size: 11px;
    color: #6B5D4C;
    margin-top: 4px;
}
.ft-info-list dd {
    margin: 0 0 4px;
    color: #1F3327;
}
.ft-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 6px 8px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 4px;
    color: #1F3327;
}
.ft-menu-item:hover { background: #F1E9DA; }
.ft-menu-item .bi { margin-right: 6px; }
.ft-toast-popover { font-size: 12px; }
.ft-edit-relationship-popover { width: 320px; max-width: min(360px, calc(100vw - 16px)); }
.ft-edit-relationship-label { display: block; margin: 7px 0; color: #6B5D4C; font-size: 11px; }
.ft-edit-relationship-label select { display: block; width: 100%; margin-top: 3px; padding: 5px 7px; border: 1px solid #D8CCB7; border-radius: 4px; background: #fff; color: #1F3327; font: inherit; font-size: 12px; }
.ft-edit-relationship-save { margin-top: 8px; background: #1F6B46; color: #fff; text-align: center; }
.ft-edit-relationship-save:hover { background: #185638; color: #fff; }
.ft-edit-relationship-save:disabled { opacity: .6; cursor: wait; }
.ft-edit-relationship-message { margin-top: 6px; color: #A22; font-size: 12px; }
.ft-add-member-form-popover { width: min(380px, calc(100vw - 16px)); max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow-y: auto; }
.ft-add-member-label { display: block; margin: 7px 0; color: #6B5D4C; font-size: 11px; }
.ft-add-member-label input,
.ft-add-member-label select,
.ft-add-member-label textarea { display: block; width: 100%; margin-top: 3px; padding: 6px 8px; border: 1px solid #D8CCB7; border-radius: 4px; background: #fff; color: #1F3327; font: inherit; font-size: 13px; }
.ft-add-member-label textarea { resize: vertical; }
.ft-add-member-order-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ft-add-member-alive { display: flex; align-items: center; gap: 6px; margin: 8px 0; color: #1F3327; }
.ft-add-member-relationship-details { border-top: 1px solid #E4D9C4; margin-top: 10px; padding-top: 8px; }
.ft-add-member-save { margin-top: 8px; background: #1F6B46; color: #fff; text-align: center; }
.ft-add-member-save:hover { background: #185638; color: #fff; }
.ft-add-member-save:disabled { opacity: .6; cursor: wait; }
.ft-add-member-message { margin-top: 6px; color: #A22; font-size: 12px; }

/* ============================================================================
 * Dark theme support for Family Tree
 * ============================================================================ */
html[data-theme="dark"] #family-tree-title,
html[data-theme="dark"] .ft-popover-title,
html[data-theme="dark"] .ft-info-list dd,
html[data-theme="dark"] .ft-menu-item {
    color: var(--ink);
}
html[data-theme="dark"] .ft-edit-relationship-label { color: var(--muted); }
html[data-theme="dark"] .ft-edit-relationship-label select { background: var(--surface); color: var(--ink); border-color: var(--border); }
html[data-theme="dark"] .ft-add-member-label { color: var(--muted); }
html[data-theme="dark"] .ft-add-member-label input,
html[data-theme="dark"] .ft-add-member-label select,
html[data-theme="dark"] .ft-add-member-label textarea { background: var(--surface); color: var(--ink); border-color: var(--border); }
html[data-theme="dark"] .ft-add-member-alive { color: var(--ink); }

html[data-theme="dark"] #family-tree-chart .node {
    background: var(--surface);
    border-color: var(--line);
    color: var(--ink);
}

html[data-theme="dark"] #family-tree-chart .node .content {
    color: var(--ink-soft);
}

html[data-theme="dark"] .ft-popover {
    background: var(--surface);
    border-color: var(--line);
    color: var(--ink);
}

html[data-theme="dark"] .ft-menu-item:hover {
    background: var(--bg-alt);
}

@media (prefers-color-scheme: dark) {
    html[data-theme="system"] #family-tree-title,
    html:not([data-theme="light"]):not([data-theme="dark"]) #family-tree-title,
    html[data-theme="system"] .ft-popover-title,
    html:not([data-theme="light"]):not([data-theme="dark"]) .ft-popover-title,
    html[data-theme="system"] .ft-info-list dd,
    html:not([data-theme="light"]):not([data-theme="dark"]) .ft-info-list dd,
    html[data-theme="system"] .ft-menu-item,
    html:not([data-theme="light"]):not([data-theme="dark"]) .ft-menu-item {
        color: var(--ink);
    }

    html[data-theme="system"] #family-tree-chart .node,
    html:not([data-theme="light"]):not([data-theme="dark"]) #family-tree-chart .node {
        background: var(--surface);
        border-color: var(--line);
        color: var(--ink);
    }

    html[data-theme="system"] #family-tree-chart .node .content,
    html:not([data-theme="light"]):not([data-theme="dark"]) #family-tree-chart .node .content {
        color: var(--ink-soft);
    }

    html[data-theme="system"] .ft-popover,
    html:not([data-theme="light"]):not([data-theme="dark"]) .ft-popover {
        background: var(--surface);
        border-color: var(--line);
        color: var(--ink);
    }

    html[data-theme="system"] .ft-menu-item:hover,
    html:not([data-theme="light"]):not([data-theme="dark"]) .ft-menu-item:hover {
        background: var(--bg-alt);
    }
}

