/* =========================================================
   ÁRBOL GENEALÓGICO
   Todos los estilos están limitados a .genealogy-page
   ========================================================= */

.genealogy-page {
    --tree-blue: #315fae;
    --tree-blue-dark: #244b91;
    --tree-ink: #172033;
    --tree-line: #18202c;
    --tree-paper: #f6f3ec;
    --tree-card: #ffffff;
    --tree-border: #d9d4c8;
    --tree-scale: 1;

    position: relative;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;

    color: var(--tree-ink);
    background: var(--tree-paper);
    font-family: Inter, Arial, Helvetica, sans-serif;
}

.genealogy-page,
.genealogy-page * {
    box-sizing: border-box;
}

/* =========================================================
   CABECERA DEL ÁRBOL
   ========================================================= */

.genealogy-page .tree-header {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;

    width: 100%;
    margin: 0;
    padding: 32px clamp(20px, 5vw, 72px) 24px;

    color: var(--tree-ink);
    background: #ffffff;
    border: 0;
    border-bottom: 1px solid var(--tree-border);
    box-shadow: none;
}

.genealogy-page .tree-header > div {
    margin: 0;
    padding: 0;
}

.genealogy-page .eyebrow {
    display: block;
    margin: 0 0 8px;
    padding: 0;

    color: var(--tree-blue);
    font-size: 11px;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.genealogy-page .tree-header h1 {
    margin: 0 0 10px;
    padding: 0;

    color: var(--tree-ink);
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(34px, 4vw, 60px);
    font-weight: 500;
    line-height: 1;
    letter-spacing: -0.04em;
    text-transform: none;
}

.genealogy-page .tree-header p {
    margin: 0;
    padding: 0;

    color: #667085;
    font-size: 16px;
    font-weight: 400;
    line-height: 1.5;
}

/* =========================================================
   CONTENIDO
   ========================================================= */

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

    width: 100%;
    margin: 0;
    padding: 0;

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

/* =========================================================
   BARRA DE CONTROLES
   ========================================================= */

.genealogy-page .toolbar {
    position: relative;
    z-index: 10;

    display: flex;
    align-items: center;
    gap: 8px;

    width: 100%;
    min-height: 58px;
    margin: 0;
    padding: 8px clamp(12px, 3vw, 38px);

    background: #f9f7f1;
    border: 0;
    border-bottom: 1px solid var(--tree-border);
    box-shadow: none;
}

.genealogy-page .toolbar .hint {
    flex: 1;
    margin: 0;
    padding: 0;

    color: #667085;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.4;
}

.genealogy-page .toolbar button {
    appearance: none;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-width: 40px;
    min-height: 38px;
    margin: 0;
    padding: 7px 12px;

    color: var(--tree-ink);
    background: #ffffff;
    border: 1px solid #c9c3b7;
    border-radius: 4px;
    box-shadow: none;

    font-family: Inter, Arial, Helvetica, sans-serif;
    font-size: 15px;
    font-weight: 500;
    line-height: 1;

    cursor: pointer;
    transition:
        color 0.15s ease,
        background-color 0.15s ease,
        border-color 0.15s ease;
}

.genealogy-page .toolbar button:hover {
    color: #ffffff;
    background: var(--tree-blue);
    border-color: var(--tree-blue);
}

.genealogy-page .toolbar button:focus-visible {
    outline: 3px solid rgba(49, 95, 174, 0.25);
    outline-offset: 2px;
}

.genealogy-page .toolbar output {
    display: inline-block;
    width: 56px;
    margin: 0;
    padding: 0;

    color: var(--tree-ink);
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    text-align: center;
}

/* =========================================================
   ÁREA DESPLAZABLE
   ========================================================= */

.genealogy-page #viewport {
    position: relative;

    display: block;
    width: 100%;
    max-width: 100%;
    height: 72vh;
    min-height: 520px;
    margin: 0;
    padding: 0;

    overflow: auto;
    overscroll-behavior: contain;

    background-color: var(--tree-paper);
    background-image:
        radial-gradient(
            circle,
            rgba(49, 95, 174, 0.25) 1px,
            transparent 1px
        );
    background-position: 0 0;
    background-size: 24px 24px;

    cursor: grab;
    touch-action: pan-x pan-y;
    scrollbar-color: #a8a29a #eeeae2;
    scrollbar-width: thin;
}

.genealogy-page #viewport.dragging {
    cursor: grabbing;
    user-select: none;
}

.genealogy-page #viewport:focus {
    outline: none;
}

.genealogy-page #viewport::-webkit-scrollbar {
    width: 11px;
    height: 11px;
}

.genealogy-page #viewport::-webkit-scrollbar-track {
    background: #eeeae2;
}

.genealogy-page #viewport::-webkit-scrollbar-thumb {
    background: #a8a29a;
    border: 3px solid #eeeae2;
    border-radius: 10px;
}

/* =========================================================
   LIENZO DEL ÁRBOL
   ========================================================= */

.genealogy-page #canvas {
    position: relative;

    width: max-content;
    min-width: 100%;
    min-height: 100%;
    margin: 0;
    padding: 50px 70px;

    transform: scale(var(--scale, 1));
    transform-origin: top left;
}

.genealogy-page #generations {
    position: relative;
    z-index: 2;

    display: flex;
    flex-direction: column;
    gap: 115px;

    width: max-content;
    min-width: calc(100vw - 140px);
}

.genealogy-page .generation {
    position: relative;

    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 70px;

    width: 100%;
    min-height: 112px;
    margin: 0;
    padding: 0;
}

/* =========================================================
   FAMILIAS Y UNIONES
   ========================================================= */

.genealogy-page .family {
    position: relative;

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

    margin: 0;
    padding: 0;
}

.genealogy-page .single {
    display: flex;
    justify-content: center;

    margin: 0 18px;
    padding: 0;
}

.genealogy-page .union-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    flex: 0 0 auto;
    width: 20px;
    margin: 0;
    padding: 0;

    color: var(--tree-blue);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 24px;
    font-weight: 400;
    line-height: 1;
}

/* =========================================================
   TARJETAS DE PERSONAS
   ========================================================= */

.genealogy-page .person {
    appearance: none;

    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;

    flex: 0 0 220px;
    width: 220px;
    min-width: 220px;
    min-height: 92px;

    margin: 0;
    padding: 13px 15px;

    color: var(--tree-ink);
    background: var(--tree-card);
    border: 2px solid var(--tree-blue);
    border-radius: 0;
    box-shadow: 0 5px 18px rgba(27, 42, 67, 0.06);

    font-family: Inter, Arial, Helvetica, sans-serif;
    line-height: 1.2;
    text-align: center;
    white-space: normal;

    cursor: pointer;
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        background-color 0.18s ease;
}

.genealogy-page .person:hover {
    transform: translateY(-3px);
    box-shadow: 0 9px 24px rgba(27, 42, 67, 0.16);
}

.genealogy-page .person:focus {
    outline: none;
}

.genealogy-page .person:focus-visible {
    outline: 3px solid rgba(49, 95, 174, 0.3);
    outline-offset: 4px;
}

.genealogy-page .person.primary {
    color: #ffffff;
    background: var(--tree-blue);
    border-color: var(--tree-blue);
}

.genealogy-page .person.primary:hover {
    background: var(--tree-blue-dark);
    border-color: var(--tree-blue-dark);
}

.genealogy-page .person strong {
    display: block;
    margin: 0;
    padding: 0;

    color: inherit;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.15;
    text-transform: none;
}

.genealogy-page .person small {
    display: block;
    margin: 5px 0 0;
    padding: 0;

    color: inherit;
    font-size: 11px;
    font-weight: 400;
    line-height: 1.2;
}

.genealogy-page .person em {
    display: block;
    margin: 4px 0 0;
    padding: 0;

    color: inherit;
    font-size: 11px;
    font-style: normal;
    font-weight: 400;
    line-height: 1.2;
    opacity: 0.78;
}

/* =========================================================
   LÍNEAS DE PARENTESCO
   ========================================================= */

.genealogy-page #lines {
    position: absolute;
    z-index: 1;
    inset: 0;

    display: block;
    width: 100%;
    height: 100%;

    margin: 0;
    padding: 0;
    overflow: visible;

    pointer-events: none;
}

.genealogy-page #lines path {
    fill: none;
    stroke: var(--tree-line);
    stroke-width: 3;
    stroke-linecap: square;
    stroke-linejoin: miter;
    vector-effect: non-scaling-stroke;
}

/* =========================================================
   MENSAJE DE CARGA
   ========================================================= */

.genealogy-page #loading {
    position: absolute;
    z-index: 5;
    inset: 0;

    display: grid;
    place-items: center;

    margin: 0;
    padding: 20px;

    color: #667085;
    background: var(--tree-paper);

    font-size: 15px;
    text-align: center;
}

.genealogy-page #loading[hidden] {
    display: none !important;
}

/* =========================================================
   VENTANA DE DETALLES
   ========================================================= */

.genealogy-page #details {
    position: fixed;

    width: min(520px, calc(100% - 32px));
    max-width: 520px;
    max-height: calc(100vh - 40px);

    margin: auto;
    padding: 30px;

    color: var(--tree-ink);
    background: #ffffff;
    border: 0;
    border-top: 6px solid var(--tree-blue);
    border-radius: 2px;
    box-shadow: 0 25px 70px rgba(23, 32, 51, 0.35);

    font-family: Inter, Arial, Helvetica, sans-serif;
    overflow: auto;
}

.genealogy-page #details::backdrop {
    background: rgba(23, 32, 51, 0.55);
}

.genealogy-page #details .close {
    appearance: none;

    position: absolute;
    top: 10px;
    right: 12px;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 38px;
    height: 38px;
    margin: 0;
    padding: 0;

    color: var(--tree-ink);
    background: transparent;
    border: 0;
    border-radius: 50%;
    box-shadow: none;

    font-size: 28px;
    font-weight: 400;
    line-height: 1;

    cursor: pointer;
}

.genealogy-page #details .close:hover {
    color: #ffffff;
    background: var(--tree-blue);
}

.genealogy-page #details h2 {
    margin: 10px 42px 8px 0;
    padding: 0;

    color: var(--tree-ink);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 32px;
    font-weight: 500;
    line-height: 1.15;
    text-transform: none;
}

.genealogy-page #details .years {
    margin: 0 0 12px;
    padding: 0;

    color: var(--tree-blue);
    font-size: 15px;
    font-weight: 700;
}

.genealogy-page #details .title {
    margin: 0 0 12px;
    padding: 0;

    color: var(--tree-ink);
    font-size: 15px;
    font-weight: 700;
    line-height: 1.5;
}

.genealogy-page #details .bio {
    margin: 0;
    padding: 0;

    color: #4b5563;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.65;
}

/* =========================================================
   TABLET
   ========================================================= */

@media (max-width: 992px) {
    .genealogy-page .tree-header {
        padding: 26px 30px 20px;
    }

    .genealogy-page #viewport {
        height: 68vh;
    }

    .genealogy-page #canvas {
        padding: 45px 50px;
    }

    .genealogy-page .generation {
        gap: 55px;
    }
}

/* =========================================================
   MÓVIL
   ========================================================= */

@media (max-width: 700px) {
    .genealogy-page .tree-header {
        display: block;
        padding: 20px 18px 16px;
    }

    .genealogy-page .tree-header h1 {
        margin-bottom: 6px;
        font-size: 34px;
        line-height: 1.05;
    }

    .genealogy-page .tree-header p {
        font-size: 14px;
    }

    .genealogy-page .toolbar {
        position: relative;
        min-height: 56px;
        gap: 6px;
        padding: 8px 10px;
    }

    .genealogy-page .toolbar .hint {
        font-size: 0;
    }

    .genealogy-page .toolbar .hint::after {
        content: "Desliza para explorar";
        font-size: 12px;
    }

    .genealogy-page .toolbar button {
        min-width: 38px;
        min-height: 38px;
        padding: 6px 9px;
        font-size: 14px;
    }

    .genealogy-page .toolbar output {
        width: 44px;
        font-size: 12px;
    }

    .genealogy-page #viewport {
        height: 70vh;
        min-height: 480px;
    }

    .genealogy-page #canvas {
        min-width: max-content;
        padding: 38px 35px;
    }

    .genealogy-page #generations {
        gap: 95px;
        min-width: max-content;
    }

    .genealogy-page .generation {
        gap: 46px;
        min-height: 100px;
    }

    .genealogy-page .family {
        gap: 9px;
    }

    .genealogy-page .person {
        flex-basis: 190px;
        width: 190px;
        min-width: 190px;
        min-height: 86px;
        padding: 11px 12px;
    }

    .genealogy-page .person strong {
        font-size: 15px;
    }

    .genealogy-page .person small,
    .genealogy-page .person em {
        font-size: 10px;
    }

    .genealogy-page .union-mark {
        width: 17px;
        font-size: 21px;
    }

    .genealogy-page #details {
        width: calc(100% - 24px);
        padding: 24px 20px;
    }

    .genealogy-page #details h2 {
        font-size: 27px;
    }
}

/* =========================================================
   PANTALLAS MUY PEQUEÑAS
   ========================================================= */

@media (max-width: 420px) {
    .genealogy-page .tree-header h1 {
        font-size: 30px;
    }

    .genealogy-page .tree-header p {
        display: none;
    }

    .genealogy-page .toolbar .hint {
        display: none;
    }

    .genealogy-page .toolbar {
        justify-content: center;
    }

    .genealogy-page #viewport {
        height: 72vh;
    }
}

/* Coloca el árbol debajo del menú principal */
.genealogy-page {
    margin-top: 190px;
}

/* Tablet */
@media (max-width: 992px) {
    .genealogy-page {
        margin-top: 150px;
    }
}

/* Móvil */
@media (max-width: 700px) {
    .genealogy-page {
        margin-top: 105px;
    }
}