/* =========================================================
   CONNEXIONS SVG
========================================================= */

.tree-connections {
    position: absolute;

    z-index: 1;

    top: 0;
    left: 0;

    width: 100%;
    height: 100%;

    overflow: visible;

    pointer-events: none;
}


.tree-connection-path {
    fill: none;

    stroke: var(--tree-line);
    stroke-width: 2;

    stroke-linecap: round;
    stroke-linejoin: round;

    vector-effect: non-scaling-stroke;
}


/*
 * Les cartes restent devant les connexions
 */

.tree-person-card {
    position: relative;
    z-index: 5;
}

/* ========================================================= CONTENU PRINCIPAL ========================================================= */
.tree-page-content {
    min-height: 65vh;
    background-color: var(--tree-light);
}

.tree-content-card {
    position: relative;
    overflow: hidden;
    padding: 28px;
    border: 1px solid var(--tree-border);
    border-radius: 24px;
    background: linear-gradient(rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.96)), radial-gradient(circle, rgba(82, 120, 83, 0.08) 1px, transparent 1px);
    background-size: auto, 24px 24px;
    box-shadow: 0 16px 40px rgba(48, 77, 48, 0.1);
}

.tree-content-heading {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 24px;
}

.tree-content-heading-icon {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    color: var(--tree-primary);
    font-size: 1.55rem;
    border-radius: 16px;
    background-color: rgba(82, 120, 83, 0.12);
}

/* ========================================================= AIDE AU DÉFILEMENT ========================================================= */
.tree-scroll-help {
    display: none;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 12px 15px;
    color: var(--tree-primary-dark);
    border: 1px solid var(--tree-border);
    border-radius: 13px;
    background-color: var(--tree-light);
    font-size: 0.86rem;
}

.tree-scroll-help i {
    color: var(--tree-primary);
    font-size: 1.15rem;
}

/* =========================================================
   CONTENEUR GLOBAL DE L'ARBRE
========================================================= */

.genealogy-tree-page {
    width: 100%;
    min-height: 100vh;
    overflow-x: hidden;
}

.genealogy-tree-scroll {
    position: relative;

    width: 100%;
    max-width: 100%;
    min-height: 470px;

    padding: 40px 30px 100px;

    /* Défilement horizontal */
    overflow-x: auto;
    overflow-y: visible;

    /* Déplacement à la souris */
    cursor: grab;

    user-select: none;
    -webkit-user-select: none;

    scroll-behavior: auto;

    scrollbar-width: thin;
    scrollbar-color: var(--tree-secondary) var(--tree-light);

    -webkit-overflow-scrolling: touch;
}

/* Souris maintenue */
.genealogy-tree-scroll.is-dragging {
    cursor: grabbing;
}

/* Empêche la sélection pendant le déplacement */
.genealogy-tree-scroll.is-dragging,
.genealogy-tree-scroll.is-dragging * {
    user-select: none !important;
    -webkit-user-select: none !important;
}

/* Empêche les images de se déplacer nativement */
.genealogy-tree-scroll img {
    -webkit-user-drag: none;
    user-drag: none;
}

/* Scrollbar */
.genealogy-tree-scroll::-webkit-scrollbar {
    height: 12px;
}

.genealogy-tree-scroll::-webkit-scrollbar-track {
    border-radius: 20px;
    background-color: var(--tree-light);
}

.genealogy-tree-scroll::-webkit-scrollbar-thumb {
    border: 3px solid var(--tree-light);
    border-radius: 20px;
    background-color: var(--tree-secondary);
}

.genealogy-tree-scroll::-webkit-scrollbar-thumb:hover {
    background-color: var(--tree-primary);
}


/* =========================================================
   ARBRE
========================================================= */

.genealogy-tree {
    position: relative;
    display: block;

    width: max-content;
    min-width: 100%;

    padding: 20px 60px;

    text-align: center;
}

.tree-root {
    display: flex;
    justify-content: center;

    width: max-content;
    min-width: 100%;

    margin: 0 auto;
    padding: 0;
}

/* ========================================================= LISTES ET NŒUDS DE L'ARBRE ========================================================= */
.genealogy-tree ul {
    margin: 0;
    padding-left: 0;
    list-style: none;
}

.tree-node {
    position: relative;
    display: flex;
    justify-content: center;
    min-width: max-content;
}

.tree-node-content {
    position: relative;
    display: flex;
    align-items: center;
    flex-direction: column;
}

/* ========================================================= CARTE PERSONNE ========================================================= */
.tree-person-card {
    position: relative;
    z-index: 5;
    width: 180px;
    min-height: 225px;
    overflow: hidden;
    border: 1px solid var(--tree-border);
    border-radius: 17px;
    background-color: var(--tree-white);
    box-shadow: 0 8px 22px rgba(48, 77, 48, 0.11);
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.tree-person-card:hover {
    z-index: 20;
    border-color: rgba(82, 120, 83, 0.5);
    transform: translateY(-5px);
    box-shadow: 0 15px 32px rgba(48, 77, 48, 0.18);
}

.tree-person-card:focus-within {
    border-color: var(--tree-primary);
    box-shadow: 0 15px 32px rgba(48, 77, 48, 0.18), 0 0 0 4px rgba(82, 120, 83, 0.12);
}

.tree-person-link {
    display: block;
    height: 100%;
    padding: 15px 13px;
    color: var(--tree-text);
    text-decoration: none;
}

.tree-person-link:hover, .tree-person-link:focus {
    color: var(--tree-text);
}

.tree-person-photo-wrapper {
    display: flex;
    justify-content: center;
}

.tree-person-photo {
    width: 96px;
    height: 96px;
    border: 4px solid rgba(82, 120, 83, 0.17);
    border-radius: 50%;
    object-fit: cover;
    object-position: center;
    background-color: var(--tree-light);
    box-shadow: 0 7px 17px rgba(48, 77, 48, 0.1);
}

.tree-person-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tree-secondary);
    font-size: 2.5rem;
    background: linear-gradient(145deg, var(--tree-light), var(--tree-cream));
}

.tree-person-content {
    margin-top: 11px;
}

.tree-person-name {
    margin: 0;
    color: var(--tree-primary-dark);
    font-size: 0.98rem;
    font-weight: 700;
    line-height: 1.3;
}

.tree-person-birth-name {
    margin-top: 4px;
    color: var(--tree-muted);
    font-size: 0.75rem;
    line-height: 1.35;
}

.tree-person-dates {
    margin-top: 8px;
    color: var(--tree-muted);
    font-size: 0.78rem;
    line-height: 1.5;
}

.tree-date-symbol {
    display: inline-block;
    min-width: 14px;
    color: var(--tree-primary);
    font-weight: 700;
}

/* =========================================================
   IMPRESSION DE L'ARBRE
========================================================= */

@media print {

    /* Format paysage */
    @page {
        size: A4 landscape;
        margin: 10mm;
    }

    /* Cache les éléments inutiles */
    header,
    footer,
    .genealogy-navbar-wrapper,
    .tree-actions-section,
    .tree-scroll-help,
    .tree-content-heading {
        display: none !important;
    }

    /* Page */
    html,
    body {
        width: auto !important;
        height: auto !important;

        margin: 0 !important;
        padding: 0 !important;

        background: #ffffff !important;
    }

    /* Section principale */
    .tree-page-content {
        min-height: 0 !important;

        margin: 0 !important;
        padding: 0 !important;

        background: #ffffff !important;
    }

    .tree-page-content .container-fluid {
        width: auto !important;
        max-width: none !important;

        margin: 0 !important;
        padding: 0 !important;
    }

    /* Carte */
    .tree-content-card {
        width: auto !important;

        margin: 0 !important;
        padding: 0 !important;

        overflow: visible !important;

        border: 0 !important;
        border-radius: 0 !important;

        background: #ffffff !important;

        box-shadow: none !important;
    }

    /* Zone scrollable */
    .genealogy-tree-scroll {
        width: max-content !important;
        max-width: none !important;
        min-height: 0 !important;

        margin: 0 !important;
        padding: 10mm !important;

        overflow: visible !important;

        cursor: default !important;
    }

    /* Arbre complet */
    .genealogy-tree {
        width: max-content !important;
        min-width: 0 !important;

        margin: 0 auto !important;
        padding: 0 !important;
    }

    .tree-root {
        width: max-content !important;
        min-width: 0 !important;

        margin: 0 auto !important;
    }

}

/* ========================================================= PERSONNE PRINCIPALE ========================================================= */
.tree-main-person {
    position: relative;
    display: flex;
    align-items: center;
    flex-direction: column;
}

.tree-main-person > .tree-person-card {
    border-color: rgba(82, 120, 83, 0.42);
    box-shadow: 0 12px 28px rgba(48, 77, 48, 0.15), 0 0 0 5px rgba(82, 120, 83, 0.07);
}

.tree-main-person > .tree-person-card::before {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 5px;
    content: "";
    background: linear-gradient(90deg, var(--tree-primary), var(--tree-secondary));
}

.tree-stop-indicator {
    margin-top: 9px;
    padding: 5px 10px;
    color: #74520b;
    font-size: 0.72rem;
    font-weight: 600;
    border: 1px solid rgba(200, 139, 38, 0.2);
    border-radius: 8px;
    background-color: rgba(255, 193, 7, 0.15);
}

/* ========================================================= FAMILLES ========================================================= */
.tree-families {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 55px;
    margin-top: 45px;
}

.tree-families::before {
    position: absolute;
    top: -45px;
    left: 50%;
    height: 45px;
    content: "";
    border-left: 2px solid var(--tree-line);
}

.tree-family {
    position: relative;
    display: flex;
    align-items: center;
    flex-direction: column;
    min-width: max-content;
    padding-top: 25px;
}

.tree-family::before {
    position: absolute;
    top: 0;
    left: 50%;
    height: 25px;
    content: "";
    border-left: 2px solid var(--tree-line);
}

.tree-family::after {
    position: absolute;
    top: 0;
    right: -27.5px;
    left: -27.5px;
    content: "";
    border-top: 2px solid var(--tree-line);
}

.tree-family:first-child::after {
    left: 50%;
}

.tree-family:last-child::after {
    right: 50%;
}

.tree-family:only-child::after {
    display: none;
}

/* ========================================================= COUPLE ET UNION ========================================================= */
.tree-couple-row {
    display: flex;
    align-items: center;
    justify-content: center;
}

.tree-current-person-reference {
    display: none;
}

.tree-union-connector {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 85px;
}

.tree-union-line {
    width: 28px;
    border-top: 2px solid var(--tree-union);
}

.tree-union-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 31px;
    height: 31px;
    color: var(--tree-union);
    font-size: 0.9rem;
    border: 1px solid rgba(181, 107, 130, 0.35);
    border-radius: 50%;
    background-color: var(--tree-white);
    box-shadow: 0 4px 10px rgba(181, 107, 130, 0.12);
}

.tree-unknown-parent {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    width: 160px;
    min-height: 115px;
    margin-left: 45px;
    padding: 12px;
    color: var(--tree-muted);
    font-size: 0.8rem;
    border: 1px dashed rgba(82, 120, 83, 0.42);
    border-radius: 14px;
    background-color: var(--tree-light);
}

.tree-unknown-parent i {
    margin-bottom: 6px;
    color: var(--tree-secondary);
    font-size: 1.5rem;
}

/* ========================================================= INFORMATIONS SUR L'UNION ========================================================= */
.tree-union-details {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 14px;
    max-width: 370px;
    margin-top: 11px;
    padding: 7px 11px;
    color: var(--tree-muted);
    font-size: 0.72rem;
    border: 1px solid rgba(181, 107, 130, 0.14);
    border-radius: 9px;
    background-color: var(--tree-union-soft);
}

.tree-union-details i {
    color: var(--tree-union);
}

/* ========================================================= DESCENDANCE ET ENFANTS ========================================================= */
.tree-descent-line {
    height: 35px;
    margin-top: 10px;
    border-left: 2px solid var(--tree-line);
}

.tree-children {
    position: relative;
    display: flex;
    justify-content: center;
    gap: 38px;
    padding-top: 35px !important;
}

.tree-children::before {
    position: absolute;
    top: 0;
    left: 50%;
    height: 35px;
    content: "";
    border-left: 2px solid var(--tree-line);
}

.tree-children > .tree-node {
    padding-top: 35px;
}

.tree-children > .tree-node::before, .tree-children > .tree-node::after {
    position: absolute;
    top: 0;
    width: 50%;
    height: 35px;
    content: "";
    border-top: 2px solid var(--tree-line);
}

.tree-children > .tree-node::before {
    right: 50%;
}

.tree-children > .tree-node::after {
    left: 50%;
    border-left: 2px solid var(--tree-line);
}

.tree-children > .tree-node:first-child::before {
    border-top: 0;
}

.tree-children > .tree-node:last-child::after {
    border-top: 0;
}

.tree-children > .tree-node:only-child::before, .tree-children > .tree-node:only-child::after {
    display: none;
}

.tree-children > .tree-node:only-child {
    padding-top: 0;
}

.tree-no-child {
    margin-top: 14px;
    color: var(--tree-muted);
    font-size: 0.75rem;
    font-style: italic;
}

/* ========================================================= AMÉLIORATION DES LIGNES DANS LES ANGLES ========================================================= */
.tree-family:first-child::after, .tree-children > .tree-node:first-child::after {
    border-radius: 8px 0 0 0;
}

.tree-family:last-child::before, .tree-children > .tree-node:last-child::before {
    border-radius: 0 8px 0 0;
}

/* ========================================================= RESPONSIVE TABLETTE ========================================================= */
@media screen and (max-width: 991px) {
    .tree-page-header {
        text-align: center;
    }

    .tree-actions-card {
        align-items: stretch;
        flex-direction: column;
    }

    .tree-actions-buttons {
        justify-content: center;
    }

    .tree-scroll-help {
        display: flex;
    }

    .tree-content-card {
        padding-right: 18px;
        padding-left: 18px;
    }
}

/* ========================================================= RESPONSIVE MOBILE ========================================================= */
@media screen and (max-width: 768px) {
    .tree-content-card {
        padding: 22px 10px;
        border-radius: 18px;
    }

    .tree-content-heading {
        padding-right: 10px;
        padding-left: 10px;
    }

    .tree-actions-information {
        align-items: flex-start;
    }

    .tree-actions-buttons {
        align-items: stretch;
        flex-direction: column;
    }

    .tree-actions-buttons .btn {
        width: 100%;
    }

    .genealogy-tree-scroll {
        min-height: 420px;
        padding-right: 5px;
        padding-left: 5px;
    }

    .genealogy-tree {
        padding-right: 25px;
        padding-left: 25px;
    }

    .tree-person-card {
        width: 150px;
        min-height: 195px;
        border-radius: 14px;
    }

    .tree-person-link {
        padding: 12px 10px;
    }

    .tree-person-photo {
        width: 76px;
        height: 76px;
    }

    .tree-person-name {
        font-size: 0.9rem;
    }

    .tree-person-birth-name, .tree-person-dates {
        font-size: 0.7rem;
    }

    .tree-families {
        gap: 30px;
    }

    .tree-family::after {
        right: -15px;
        left: -15px;
    }

    .tree-family:first-child::after {
        left: 50%;
    }

    .tree-family:last-child::after {
        right: 50%;
    }

    .tree-union-connector {
        min-width: 58px;
    }

    .tree-union-line {
        width: 14px;
    }

    .tree-union-icon {
        width: 28px;
        height: 28px;
        font-size: 0.78rem;
    }

    .tree-children {
        gap: 22px;
    }

    .tree-unknown-parent {
        width: 135px;
        min-height: 100px;
        margin-left: 25px;
    }
}

/* ========================================================= TRÈS PETITS ÉCRANS ========================================================= */
@media screen and (max-width: 576px) {
    .tree-page-logo-wrapper {
        width: 195px;
        height: 195px;
    }

    .tree-page-logo {
        width: 145px;
        height: 145px;
    }

    .tree-page-title {
        font-size: 2.2rem;
    }

    .tree-actions-card {
        padding: 20px 17px;
    }

    .tree-actions-information {
        flex-direction: column;
    }

    .tree-content-heading {
        align-items: flex-start;
    }

    .tree-content-heading-icon {
        width: 49px;
        height: 49px;
        font-size: 1.35rem;
    }

    .genealogy-tree {
        padding-right: 18px;
        padding-left: 18px;
    }

    .tree-person-card {
        width: 140px;
        min-height: 188px;
    }

    .tree-person-photo {
        width: 70px;
        height: 70px;
    }

    .tree-families {
        gap: 24px;
    }

    .tree-children {
        gap: 18px;
    }

    .tree-union-connector {
        min-width: 48px;
    }

    .tree-union-line {
        width: 10px;
    }

    .tree-unknown-parent {
        width: 125px;
        margin-left: 18px;
    }
}

/* =========================================================
   COEUR UNION
========================================================= */

/* Union actuelle */
.tree-union-heart {
    color: var(--tree-union);
}

.tree-union-heart i {
    color: inherit;
}


/* Union terminée / ex */
.tree-union-ended .tree-union-heart {
    color: #b85c6b;
}


/* Traits de l'union terminée */
.tree-union-ended .tree-union-line {
    border-color: #b85c6b;
}

/* =========================================================
   CONNEXIONS GÉRÉES PAR JAVASCRIPT
========================================================= */

.tree-children::before,
.tree-children > .tree-node::before,
.tree-children > .tree-node::after {
    content: none !important;

    display: none !important;

    border: 0 !important;
}

/* =========================================================
   DÉCORATION DE LA ZONE ARBRE
========================================================= */

.tree-content-card {
    position: relative;
    isolation: isolate;
}


/* =========================================================
   DÉCORATION DE LA ZONE ARBRE
========================================================= */

.tree-content-card {
    position: relative;
    isolation: isolate;
}


/* =========================================================
   DÉCOR VÉGÉTAL
========================================================= */

.tree-natural-scene {
    position: relative;
    overflow: hidden;
}

.tree-nature-decoration {
    position: absolute;
    z-index: 0;
    inset: 0;

    overflow: hidden;
    pointer-events: none;
}

/* Le vrai contenu reste devant */
.tree-content-heading,
.tree-scroll-help,
.genealogy-tree-scroll {
    position: relative;
    z-index: 2;
}


/* =========================================================
   FEUILLAGES LATÉRAUX
========================================================= */

.tree-foliage {
    position: absolute;

    width: 180px;
    height: 240px;

    opacity: 0.16;
}

.tree-foliage-left {
    bottom: 20px;
    left: 10px;
}

.tree-foliage-right {
    top: 70px;
    right: 10px;

    transform: scaleX(-1);
}


/* Petite branche */
.tree-foliage::before {
    position: absolute;

    bottom: 0;
    left: 50%;

    width: 3px;
    height: 210px;

    content: "";

    border-radius: 50%;

    background: rgba(82, 120, 83, 0.55);

    transform: rotate(32deg);
    transform-origin: bottom;
}


/* =========================================================
   FEUILLES
========================================================= */

.nature-leaf,
.tree-floating-leaf {
    position: absolute;

    display: block;

    width: 32px;
    height: 18px;

    border-radius: 100% 0 100% 0;

    background: #527853;
}


/* Feuilles de la branche */

.tree-foliage .leaf-a {
    bottom: 35px;
    left: 76px;

    transform: rotate(-35deg);
}

.tree-foliage .leaf-b {
    bottom: 75px;
    left: 100px;

    transform: rotate(30deg);
}

.tree-foliage .leaf-c {
    bottom: 115px;
    left: 58px;

    transform: rotate(-40deg);
}

.tree-foliage .leaf-d {
    bottom: 150px;
    left: 92px;

    transform: rotate(25deg);
}

.tree-foliage .leaf-e {
    bottom: 185px;
    left: 50px;

    transform: rotate(-35deg);
}


/* =========================================================
   FEUILLES INDÉPENDANTES
========================================================= */

.tree-floating-leaf {
    width: 24px;
    height: 13px;

    opacity: 0.09;
}

.floating-leaf-1 {
    top: 25%;
    left: 8%;

    transform: rotate(35deg);
}

.floating-leaf-2 {
    top: 15%;
    right: 15%;

    transform: rotate(-25deg);
}

.floating-leaf-3 {
    bottom: 15%;
    left: 25%;

    transform: rotate(65deg);
}

.floating-leaf-4 {
    right: 25%;
    bottom: 8%;

    transform: rotate(-45deg);
}


/* =========================================================
   SOL TRÈS LÉGER
========================================================= */

.tree-ground {
    position: absolute;

    right: 5%;
    bottom: -35px;
    left: 5%;

    height: 70px;

    border-radius: 50%;

    background:
        radial-gradient(
            ellipse at center,
            rgba(82, 120, 83, 0.10) 0%,
            rgba(82, 120, 83, 0) 70%
        );
}

/* L'arbre reste au-dessus */
.genealogy-tree-scroll {
    position: relative;
    z-index: 1;
}


/* =========================================================
   ZOOM DE L'ARBRE
========================================================= */

.tree-zoom-toolbar {
    position: relative;
    z-index: 10;

    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;

    margin: 12px 20px;
}

.tree-zoom-button,
.tree-zoom-value {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    height: 38px;

    border: 1px solid var(--tree-border);
    border-radius: 10px;

    background: var(--tree-white);
    color: var(--tree-primary-dark);

    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        transform 0.2s ease;
}

.tree-zoom-button {
    width: 38px;
}

.tree-zoom-value {
    min-width: 70px;
    padding: 0 12px;

    font-size: 0.85rem;
    font-weight: 700;
}

.tree-zoom-button:hover,
.tree-zoom-value:hover {
    border-color: var(--tree-primary);

    background: var(--tree-light);
}

.tree-zoom-button:active,
.tree-zoom-value:active {
    transform: scale(0.95);
}

.tree-zoom-separator {
    width: 1px;
    height: 24px;

    margin: 0 4px;

    background: var(--tree-border);
}

.tree-center-button {
    width: auto;
    padding: 0 13px;

    gap: 7px;
}

@media (max-width: 767.98px) {

    .tree-zoom-toolbar {
        justify-content: center;
    }

    .tree-center-button span {
        display: none;
    }

    .tree-center-button {
        width: 38px;
        padding: 0;
    }
}

/* =========================================================
   SURVOL D'UNE PERSONNE
========================================================= */

.tree-person-card {
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease,
        border-color 0.2s ease;
}

.tree-person-card:hover {
    z-index: 20;

    border-color: rgba(82, 120, 83, 0.45);

    box-shadow:
        0 10px 28px rgba(48, 77, 48, 0.16);

    transform: translateY(-3px);
}

/* =========================================================
   MISE EN ÉVIDENCE D'UNE BRANCHE
========================================================= */

.tree-connection-path {
    transition:
        stroke 0.18s ease,
        stroke-width 0.18s ease,
        opacity 0.18s ease;
}

.tree-connection-highlight {
    stroke: var(--tree-primary-dark) !important;
    stroke-width: 3.5 !important;
    opacity: 1 !important;
}
