/* office_hierarchy.css – tree view styles for office hierarchy */

.hierarchy-tree {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.hierarchy-tree ul {
    list-style: none;
    padding-left: 1.5rem;
    margin: 0;
    border-left: 1px solid #dee2e6;
}

.hierarchy-node {
    margin: 0;
    padding: 0;
}

.hierarchy-node-content {
    display: flex;
    align-items: center;
    padding: 0.4rem 0.5rem;
    border-radius: 0.25rem;
    transition: background-color 0.15s;
}

.hierarchy-node-content:hover {
    background-color: #f8f9fa;
}

.hierarchy-node.highlighted > .hierarchy-node-content {
    background-color: #e8f5e9;
    border-left: 3px solid #5e9f5c;
    padding-left: calc(0.5rem - 3px);
}

.hierarchy-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.2rem;
    min-width: 1.2rem;
    height: 1.2rem;
    font-size: 0.6rem;
    cursor: pointer;
    color: #6c757d;
    transition: transform 0.15s;
    user-select: none;
    margin-right: 0.35rem;
}

.hierarchy-toggle.expanded {
    transform: rotate(90deg);
}

.hierarchy-toggle.no-children {
    visibility: hidden;
}

.hierarchy-node-link {
    text-decoration: none;
    color: #185642;
    font-size: 0.95rem;
}

.hierarchy-node-link:hover {
    text-decoration: underline;
    color: #124434;
}

.hierarchy-org-link {
    font-weight: 600;
    font-size: 1rem;
}

.hierarchy-date {
    font-size: 0.82rem;
    color: #6c757d;
    margin-left: 0.5rem;
    white-space: nowrap;
}

/* Occupation title (e.g. Lord Deputy, Lord Justice) – list view */
.hierarchy-title {
    font-size: 0.8rem;
    color: #7b6b4e;
    margin-left: 0.4rem;
    font-style: italic;
    white-space: nowrap;
}

/* Estimated date indicator */
.hierarchy-estimated {
    font-style: italic;
}

/* Holders toggle label */
.hierarchy-toggle-holders {
    cursor: pointer;
    font-size: 0.85rem;
    color: #6c757d;
    user-select: none;
}
.hierarchy-toggle-holders input {
    cursor: pointer;
}

.hierarchy-node.date-hidden,
.td-branch.date-hidden {
    display: none;
}

.hierarchy-loading {
    padding: 1rem;
    color: #6c757d;
    font-size: 0.9rem;
}

.hierarchy-empty {
    padding: 1rem;
    color: #6c757d;
    font-style: italic;
    font-size: 0.9rem;
}

.hierarchy-show-more {
    background: none;
    border: none;
    color: #5e9f5c;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.3rem 0.5rem;
}

.hierarchy-show-more:hover {
    text-decoration: underline;
}

.hierarchy-expand-all {
    background: none;
    border: 1px solid #dee2e6;
    border-radius: 0.25rem;
    padding: 0.2rem 0.6rem;
    font-size: 0.8rem;
    color: #6c757d;
    cursor: pointer;
    transition: background-color 0.15s;
}

.hierarchy-expand-all:hover {
    background-color: #f8f9fa;
}

/* View toggle button group */
.hierarchy-view-toggle .btn {
    font-size: 0.8rem;
    padding: 0.2rem 0.6rem;
}
.hierarchy-view-toggle .btn.active {
    background-color: #185642;
    border-color: #185642;
    color: #fff;
}
.hierarchy-view-toggle .btn:not(.active) {
    color: #6c757d;
}

/* ====================================================================
 *  TOP-DOWN TREE VIEW
 * ==================================================================== */

.td-tree-wrapper {
    overflow-x: auto;
    padding: 1rem 0;
}

.td-tree-scroll {
    min-width: fit-content;
}

.td-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Connector: vertical line from parent to children row */
.td-tree > .td-children {
    position: relative;
    padding-top: 2rem;
}

/* Line from org node bottom to the horizontal connector (lands at 1rem = padding minus branch::before offset) */
.td-tree > .td-children::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-1px);
    width: 2px;
    height: 1rem;
    background-color: #bcd4c4;
}

/* Children row: horizontal layout */
.td-children {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    /* No gap – use padding on branches so ::before spans the full width including inter-node spacing */
    position: relative;
}

/* Each branch: a single column (node + its children) */
.td-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding: 0 0.4rem; /* horizontal spacing replaces gap */
}

/* Horizontal connector line across children */
.td-children > .td-branch:not(.td-overflow-branch)::before {
    content: '';
    position: absolute;
    top: -1rem;
    height: 2px;
    background-color: #bcd4c4;
    left: 0;
    right: 0;
}

/* Extend line to left for first, to right for last */
.td-children > .td-branch:not(.td-overflow-branch):first-child::before {
    left: 50%;
}
/* Last real branch (or last before overflow) clips the horizontal line */
.td-children > .td-branch:not(.td-overflow-branch):last-child::before,
.td-children > .td-branch:not(.td-overflow-branch):nth-last-child(2):has(+ .td-overflow-branch)::before {
    right: 50%;
}
.td-children > .td-branch:not(.td-overflow-branch):only-child::before {
    display: none;
}

/* Vertical stub from horizontal line down to node */
.td-children > .td-branch:not(.td-overflow-branch)::after {
    content: '';
    position: absolute;
    top: -1rem;
    left: 50%;
    width: 2px;
    height: 1rem;
    background-color: #bcd4c4;
    transform: translateX(-1px);
}

/* Connector between office and its holders */
.td-holder-children {
    padding-top: 1.5rem;
    position: relative;
}

/* Line ends at the holder horizontal connector level (0.75rem into padding) */
.td-holder-children::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 0.75rem;
    background-color: #bcd4c4;
    transform: translateX(-1px);
}

/* Horizontal connector in holder row */
.td-holder-children > .td-branch:not(.td-overflow-branch)::before {
    top: -0.75rem;
}
.td-holder-children > .td-branch:not(.td-overflow-branch)::after {
    top: -0.75rem;
    height: 0.75rem;
}

/* ---- Node boxes ---- */

.td-node {
    background: #ffffff;
    border: 1.5px solid #dee2e6;
    border-radius: 0.5rem;
    padding: 0.6rem 1rem;
    text-align: center;
    min-width: 140px;
    max-width: 220px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    transition: box-shadow 0.15s, border-color 0.15s;
    position: relative;
    z-index: 1;
}

.td-node:hover {
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
    border-color: #aab4bc;
}

.td-org-node {
    background: linear-gradient(135deg, #e8f5e9 0%, #f1f8f2 100%);
    border-color: #5e9f5c;
    min-width: 180px;
    max-width: 280px;
    padding: 0.8rem 1.2rem;
}

.td-office-node {
    background: #fff;
    border-color: #c5d6cc;
    cursor: default;
}

.td-office-node.td-expanded {
    border-color: #5e9f5c;
    box-shadow: 0 2px 8px rgba(94, 159, 92, 0.15);
}

.td-holder-node {
    background: #fafcfb;
    border-color: #e0e8e3;
    min-width: 120px;
    max-width: 200px;
    padding: 0.4rem 0.75rem;
    font-size: 0.88rem;
}

.td-highlighted {
    background: #e8f5e9 !important;
    border-color: #5e9f5c !important;
    box-shadow: 0 0 0 3px rgba(94, 159, 92, 0.2);
}

.td-node-link {
    text-decoration: none;
    color: #185642;
    font-weight: 600;
    font-size: 0.9rem;
    display: block;
    word-wrap: break-word;
    line-height: 1.3;
}

.td-node-link:hover {
    text-decoration: underline;
    color: #124434;
}

.td-org-node .td-node-link {
    font-size: 1rem;
    font-weight: 700;
}

.td-node-badge {
    display: block;
    font-size: 0.75rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

.td-node-date {
    display: block;
    font-size: 0.75rem;
    color: #6c757d;
    margin-top: 0.15rem;
    white-space: nowrap;
}

/* Occupation title – tree view (below name, above date) */
.td-node-title {
    display: block;
    font-size: 0.72rem;
    color: #7b6b4e;
    font-style: italic;
    margin-top: 0.1rem;
}

/* Estimated date styling for tree view */
.td-estimated {
    font-style: italic;
}

.td-show-more {
    font-size: 0.8rem;
    margin-top: 0.5rem;
}

.td-overflow-branch {
    align-self: center;
}

/* Responsive / small screens */
@media (max-width: 768px) {
    .hierarchy-tree ul {
        padding-left: 1rem;
    }

    .td-node {
        min-width: 100px;
        max-width: 160px;
        padding: 0.4rem 0.6rem;
        font-size: 0.82rem;
    }

    .td-node-link {
        font-size: 0.82rem;
    }

    .td-children {
        gap: 0.25rem;
    }
}
