/* --- ARBRE GÉNÉALOGIQUE --- */
.tree-container {
    width: 100%;
    max-width: 100vw;
    /* Limit container to screen width */
    overflow-x: auto;
    overflow-y: hidden;
    /* Show horizontal scrollbar, hide vertical */
    cursor: grab;
    padding: 0;
    /* Remove all padding */
    /* Reduced top padding to 0 */
    /* Reduced vertical padding */
    /* Colorful gradient background */
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.3));
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    /* Center the trees horizontally */
    /* REMOVED justify-content: center; to avoid conflict with JS PanZoomController */
    display: flex;
}

.tree-container:active {
    cursor: grabbing;
}

.tree {
    display: inline-block;
    white-space: nowrap;
    padding: 0;
    /* Removed padding */
    width: max-content;
    /* Ensure width matches content exactly */
}

/* Specific: Remove top padding for the very first UL (Root) */
.tree>ul {
    padding-top: 0;
}

.tree ul {
    padding-top: 20px;
    padding-left: 0;
    /* Removing default browser padding for perfect centering */
    position: relative;
    transition: all 0.5s;
    display: flex;
    justify-content: center;
}

.tree li {
    float: left;
    text-align: center;
    list-style-type: none;
    position: relative;
    padding: 20px 5px 0 5px;
    transition: all 0.5s;
}

/* Connectors - GOLD */
.tree li::before,
.tree li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    border-top: 3px solid var(--gold);
    /* Gold connectors */
    width: 50%;
    height: 20px;
    opacity: 0.8;
}

.tree li::after {
    right: auto;
    left: 50%;
    border-left: 3px solid var(--gold);
}

.tree li:only-child::after,
.tree li:only-child::before {
    display: none;
}

.tree li:only-child {
    padding-top: 0;
}

.tree li:first-child::before,
.tree li:last-child::after {
    border: 0 none;
}

.tree li:last-child::before {
    border-right: 3px solid var(--gold);
    border-radius: 0 10px 0 0;
}

.tree li:first-child::after {
    border-radius: 10px 0 0 0;
}

.tree ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: 3px solid var(--gold);
    width: 0;
    height: 20px;
    opacity: 0.8;
}

/* Node Styles - Colorful Card */
.tree li .node {
    background: #c0c0c0;
    /* Medium Grey */
    border: 2px solid var(--gold);
    /* Uniform Gold Border */
    padding: 15px 20px;
    text-decoration: none;
    color: var(--primary);
    /* Dark text for contrast */
    font-family: var(--font-heading);
    font-size: 0.95rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    border-radius: 12px;
    /* Softer round */
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Bouncy transition */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    /* Softer shadow */
    min-width: 150px;
    z-index: 2;
    position: relative;
}

.tree li .node:hover {
    background: var(--primary);
    /* Pop-up background color */
    color: #fff;
    /* White text for contrast */
    border-color: var(--gold);
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15), 0 5px 10px rgba(0, 0, 0, 0.05);
    z-index: 10;
}

/* --- War Categories --- */
.tree li .node.grande-guerre {
    background: #5D8AA8 !important;
    /* Bleu Horizon 14-18 */
    color: white !important;
    border-color: #fff !important;
}

.tree li .node.guerre-1870 {
    background: #a91b2a !important;
    /* Rouge Garance 1870 */
    color: white !important;
    border-color: #fff !important;
}

.tree li .node.guerre-1940 {
    background: #6b8e23 !important;
    /* Olive Drab 39-45 */
    color: white !important;
    border-color: #fff !important;
}

/* Image styles within the tree */
.tree .tree-img {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--gold);
    /* Gold border for images */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    transition: all 0.3s;
}

.tree li .node:hover .tree-img {
    transform: scale(1.1);
    border-color: var(--accent);
}

/* Text styles */
.tree li .node span {
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Force H2 (Branch Title) to white on hover */
.tree li .node:hover h2 {
    color: #fff !important;
}

/* Connector styles on hover - Highlight path */
.tree li .node:hover+ul li::after,
.tree li .node:hover+ul li::before,
.tree li .node:hover+ul::before,
.tree li .node:hover+ul ul::before {
    border-color: var(--accent);
    opacity: 1;
    border-width: 2px;
}

/* TOOLTIP STYLES */
.tree li .node .info-box {
    display: none;
    /* Changed from visibility: hidden to remove from layout flow */
    width: 180px;
    max-width: 300px;
    background-color: var(--primary);
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 10px;
    position: fixed;
    /* Fixed position prevents affecting tree width */
    z-index: 2147483647;
    /* Maximum possible z-index */
    bottom: 110%;
    /* Position above the element */
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    font-size: 0.85rem;
    pointer-events: none;
    /* Let clicks pass through if needed */
}

/* Arrow for the tooltip */
.tree li .node .info-box::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: var(--primary) transparent transparent transparent;
}

/* .tree li a:hover .info-box {
    visibility: visible;
    opacity: 1;
} REMOVED FOR JS HANDLING */

.tree li .node .info-box strong {
    display: block;
    color: var(--gold);
    margin-bottom: 4px;
    font-size: 0.95rem;
}

@media (max-width: 768px) {
    .tree-container {
        overflow: auto;
        /* Ensure scrolling is always enabled on mobile */
        justify-content: flex-start;
        /* Start from left so first items are visible */
    }

    .tree li {
        padding: 20px 0;
    }
}

/* --- DARK MODE ADAPTATIONS --- */
[data-theme="dark"] .tree-container {
    background: linear-gradient(to bottom, rgba(44, 62, 80, 0.9), rgba(44, 62, 80, 0.4));
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .tree li .node {
    background: var(--white);
    /* Restore dark background (from variable) */
    color: var(--text);
    /* Restore text color */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .tree li .node:hover {
    background: #2c3e50;
    /* Darker hover */
    border-color: var(--gold);
}

/* --- GLOBAL TOOLTIP STYLES (Moved from JS) --- */
#global-tooltip {
    position: absolute;
    background: var(--primary);
    /* Deep Blue in Light, Light Grey in Dark? No, let's fix this */
    color: #fff;
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    z-index: 2147483647;
    pointer-events: auto;
    opacity: 0;
    transition: opacity 0.2s;
    max-width: 350px;
    word-wrap: break-word;
    font-size: 0.9rem;
    text-align: left;
}

/* Fix Tooltip for Dark Mode: We want a high contrast tooltip */
[data-theme="dark"] #global-tooltip {
    background: #fff;
    color: #2c3e50;
    border: 1px solid var(--gold);
}

/* Tooltip Text Colors */
.info-address {
    color: #ccc;
}

.info-military {
    color: #ddd;
}

[data-theme="dark"] .info-address {
    color: #555;
}

[data-theme="dark"] .info-military {
    color: #000;
}