/* Family tree page — editorial layout aligned with about + blogs */

.family-tree-page {
    background: var(--color-cream);
    direction: rtl;
}

main:has(.family-tree-main) {
    gap: 0 !important;
}

/* ── Hero grid (image left, text right on desktop) ── */
.tree-hero__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(1.25rem, 3vw, 2rem);
    align-items: center;
    direction: ltr;
}

.tree-hero__content {
    order: 1;
    min-width: 0;
    direction: rtl;
    text-align: right;
}

.tree-hero__media {
    order: 2;
    min-width: 0;
    justify-self: center;
    width: 100%;
    max-width: 420px;
}

@media (min-width: 900px) {
    .tree-hero__grid {
        grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
        gap: clamp(1.5rem, 3vw, 2.5rem);
    }

    .tree-hero__media {
        order: 1;
        justify-self: start;
    }

    .tree-hero__content {
        order: 2;
    }
}

.tree-hero__title {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 600;
    color: var(--color-black-light);
    line-height: 1.3;
    margin: 0 0 var(--space-3);
}

.tree-hero__meta {
    font-size: var(--font-size-small);
    color: var(--color-ray);
    margin: 0 0 var(--space-4);
    letter-spacing: 0.01em;
}

.tree-hero__prose {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.tree-hero__prose p {
    font-size: var(--font-size-large);
    line-height: 1.75;
    color: var(--color-ray);
    margin: 0;
    text-align: justify;
}

.tree-hero__prose strong {
    font-weight: 500;
    color: var(--color-black-light);
}

.tree-hero__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-6);
}

.tree-hero__actions .clean-button {
    min-width: 180px;
    justify-content: center;
}

.tree-hero__register {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-4);
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--color-author);
    text-decoration: none;
    cursor: pointer;
    transition: opacity var(--duration-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
    .tree-hero__register:hover {
        opacity: 0.75;
        text-decoration: underline;
        text-underline-offset: 3px;
    }
}

.tree-hero__preview {
    display: block;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    transition: transform var(--duration-fast) var(--ease-out);
    cursor: pointer;
}

@media (hover: hover) and (pointer: fine) {
    .tree-hero__preview:hover {
        transform: scale(1.02);
    }
}

.tree-hero__preview:active {
    transform: scale(0.98);
}

.tree-hero__preview img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 12px;
}

/* ── Interactive section wrap ── */
.family-tree-wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 clamp(2rem, 5vw, 4rem) clamp(2rem, 5vw, 4rem);
}

.interactive-tree {
    position: relative;
}

.interactive-tree__head {
    margin-bottom: var(--space-6);
}

.interactive-tree__title {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 600;
    color: var(--color-black-light);
    margin: 0 0 var(--space-2);
    transition: opacity var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}

.interactive-tree__hint {
    font-size: var(--font-size-base);
    color: var(--color-ray);
    margin: 0;
    line-height: 1.5;
}

.interactive-tree__hint--touch {
    display: none;
}

@media (pointer: coarse), (max-width: 768px) {
    .interactive-tree__hint--desktop {
        display: none;
    }

    .interactive-tree__hint--touch {
        display: block;
    }
}

@media (min-width: 769px) {
    .interactive-tree__title.hidden {
        opacity: 0;
        transform: scale(0.95);
        pointer-events: none;
    }
}

@media (max-width: 768px) {
    .interactive-tree__title.hidden {
        display: none !important;
    }
}

/* Card container */
.interactive-tree-container {
    position: relative;
    width: 100%;
    background: var(--color-white);
    border: 1px solid var(--color-gray-light);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    overscroll-behavior: contain;
    opacity: 1;
    transform: none;
}

/* الشجرة التفاعلية تُعرض فوراً — لا نخفيها بانتظار scroll-reveal */
.interactive-tree-container.section-animate-child {
    opacity: 1;
    transform: none;
}

@media (pointer: coarse), (max-width: 768px) {
    .interactive-tree-container {
        opacity: 1;
        transform: none;
    }
}

/* Control bar */
.control-bar {
    position: relative;
    z-index: 100;
    background: var(--color-white);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-gray-light);
}

.control-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.control-container .title {
    display: none;
}

.controls {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    flex-wrap: wrap;
}

.controls-zoom {
    display: inline-flex;
    gap: var(--space-2);
    align-items: center;
}

.control-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 45px;
    height: 45px;
    padding: 0;
    border: 1.5px solid var(--color-gray-light);
    border-radius: 10px;
    font-size: var(--font-size-large);
    cursor: pointer;
    color: var(--color-black-light);
    background: var(--color-white);
    position: relative;
    overflow: hidden;
    transition:
        transform var(--duration-fast) var(--ease-out),
        background-color var(--duration-fast) var(--ease-out),
        border-color var(--duration-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
    .control-btn:hover {
        border-color: var(--color-black-light);
        background-color: var(--color-white);
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    }
}

.control-btn:active {
    transform: scale(0.97);
}

.search-control-wrap {
    position: relative;
}

/* Search */
.search-btn {
    position: relative;
    transition:
        width var(--duration-normal) var(--ease-out),
        padding var(--duration-normal) var(--ease-out);
}

.search-btn.expanded {
    width: 280px;
    justify-content: flex-start;
    padding: 0 12px;
}

.search-btn.expanded .fa-search {
    margin-left: 8px;
    flex-shrink: 0;
}

.search-input-expanded {
    display: none;
    flex: 1;
    align-items: center;
}

.search-btn.expanded .search-input-expanded {
    display: flex;
}

#searchInputExpanded {
    flex: 1;
    padding: 8px;
    border: none;
    font-size: var(--font-size-base);
    outline: none;
    background: transparent;
    color: var(--color-black-light);
    width: 100%;
    font-family: inherit;
}

#searchInputExpanded::placeholder {
    color: var(--color-ray);
}

.search-results {
    position: absolute;
    top: calc(100% + 5px);
    right: 0;
    width: 280px;
    background: var(--color-white);
    border-radius: 8px;
    border: 1px solid var(--color-gray-light);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1001;
    display: none;
    text-align: right;
}

.search-results.show {
    display: block;
}

.search-result-item {
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--color-gray-bg);
    transition: background-color var(--duration-fast) var(--ease-out);
    color: var(--color-black-light);
    font-size: var(--font-size-base);
}

@media (hover: hover) and (pointer: fine) {
    .search-result-item:hover {
        background-color: var(--color-gray-bg);
    }
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item.no-results {
    color: var(--color-ray);
    cursor: default;
}

/* SVG area — dotted canvas */
.TreeSvg-container {
    position: relative;
    width: 100%;
    min-height: 380px;
    height: 420px;
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: auto;
    background-color: var(--color-cream);
    background-image: radial-gradient(rgba(63, 53, 41, 0.10) 1px, transparent 1px);
    background-size: 22px 22px;
}

@supports (height: 1dvh) {
    .TreeSvg-container {
        min-height: clamp(380px, 58dvh, 800px);
        height: clamp(420px, 62dvh, 800px);
    }
}

#familyTreeSvg {
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
    display: block;
}

#familyTreeSvg:active {
    cursor: grabbing;
}

.node {
    cursor: pointer;
}

/* HTML overlay layer — replaces foreignObject for mobile compatibility */
.tree-html-nodes-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    pointer-events: none;
    transform-origin: 0 0;
}

.tree-html-nodes-layer .tree-node-card {
    position: absolute;
    pointer-events: auto;
}

/* ── Links ── */
.link {
    fill: none;
    stroke: #c9bfb1;
    stroke-width: 1.5px;
    stroke-opacity: 0.55;
    transition: stroke var(--duration-fast) var(--ease-out), stroke-opacity var(--duration-fast) var(--ease-out);
}

.link--path {
    stroke: var(--color-cinnabar, #c45c26);
    stroke-width: 2.5px;
    stroke-opacity: 1;
}

/* ── Node card ── */
.tree-node-card {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    min-height: 92px;
    padding: 12px 14px 10px;
    background: var(--color-white, #fff);
    border: 1.5px solid var(--color-gray-light);
    border-radius: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
    user-select: none;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    touch-action: manipulation;
    transition: transform var(--duration-fast) var(--ease-out),
        border-color var(--duration-fast) var(--ease-out),
        box-shadow var(--duration-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
    .tree-node-card:hover {
        transform: scale(1.02);
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    }
}

.tree-node-card:active {
    transform: scale(0.99);
}

.tree-node-card__bar {
    position: absolute;
    inset: 0 0 auto 0;
    height: 5px;
    border-radius: 14px 14px 0 0;
}

.tree-node-card--male {
    border-color: #b9dcf5;
}

.tree-node-card--male .tree-node-card__bar {
    background: #2196f3;
}

.tree-node-card--female {
    border-color: #f6c3d4;
}

.tree-node-card--female .tree-node-card__bar {
    background: #e91e63;
}

.tree-node-card--root {
    border-color: #e6c878;
}

.tree-node-card--root .tree-node-card__bar {
    background: linear-gradient(90deg, #d4a017, #e6c878);
}

.tree-node-card--path {
    border-color: var(--color-cinnabar, #c45c26);
    box-shadow: 0 4px 16px rgba(196, 92, 38, 0.22);
}

.tree-node-card--selected {
    border-width: 2px;
    box-shadow: 0 6px 20px rgba(196, 92, 38, 0.32);
}

.tree-node-card__main {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 2px;
}

.tree-node-card__photo {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    background-color: var(--color-gray-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-ray);
    font-size: 14px;
    border: 1.5px solid var(--color-gray-light);
}

.tree-node-card__name {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--color-black-light);
    line-height: 1.35;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.tree-node-card__add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    margin-top: auto;
    font-family: inherit;
    font-size: var(--font-size-x-small);
    font-weight: 600;
    color: #1d7a43;
    background: #e7f6ec;
    border: 1px solid #bce3cb;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
    .tree-node-card__add:hover {
        background: #d6efe0;
    }
}

.tree-node-card__add:active {
    transform: scale(0.97);
}

.tree-node-card__foot {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tree-node-card__badge {
    font-size: var(--font-size-x-small);
    font-weight: 500;
    color: #6b7280;
    background: #f0f0f0;
    border-radius: 6px;
    padding: 2px 8px;
}

.tree-node-card__detail {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: inherit;
    font-size: var(--font-size-x-small);
    font-weight: 500;
    color: var(--color-author);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px 4px;
    min-height: 36px;
    touch-action: manipulation;
    transition: opacity var(--duration-fast) var(--ease-out);
}

.tree-node-card__detail:active {
    transform: scale(0.97);
}

@media (hover: hover) and (pointer: fine) {
    .tree-node-card__detail:hover {
        opacity: 0.7;
        text-decoration: underline;
        text-underline-offset: 2px;
    }
}

.tree-node-card__toggle {
    margin-inline-start: auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: inherit;
    font-size: var(--font-size-x-small);
    color: var(--color-ray);
    background: var(--color-gray-bg);
    border: none;
    border-radius: 999px;
    padding: 6px 10px;
    min-height: 36px;
    min-width: 36px;
    cursor: pointer;
    touch-action: manipulation;
    transition: background-color var(--duration-fast) var(--ease-out);
}

.tree-node-card__toggle:active {
    transform: scale(0.95);
}

.tree-node-card__count {
    font-weight: 600;
}

/* ── Admin tools ── */
.tree-node-card__tools {
    position: absolute;
    top: 6px;
    inset-inline-end: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
    pointer-events: none;
}

.tree-node-card:hover .tree-node-card__tools,
.tree-node-card:focus-within .tree-node-card__tools {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.tnc-tool {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    border: 1px solid var(--color-gray-light);
    background: var(--color-white);
    color: var(--color-black-light);
    border-radius: 6px;
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
    .tnc-tool:hover {
        background: var(--color-gray-bg);
    }

    .tnc-tool--danger:hover {
        background: #fdecea;
        color: #c0392b;
        border-color: #f5c6cb;
    }
}

.tnc-tool:active {
    transform: scale(0.92);
}

@media (prefers-reduced-motion: reduce) {

    .tree-node-card,
    .tree-node-card__tools,
    .link {
        transition: none;
    }
}

/* Legend */
.legend {
    position: absolute;
    top: 20px;
    left: 20px;
    background: var(--color-white);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--color-gray-light);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: 10;
}

.legend-toggle {
    display: none;
}

.legend-content {
    display: block;
}

.legend h3 {
    margin: 0 0 12px;
    color: var(--color-black-light);
    font-size: var(--font-size-base);
    font-weight: 500;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
    font-size: var(--font-size-small);
    color: var(--color-black-light);
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-color {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 1px solid;
    flex-shrink: 0;
}

.male-color {
    background: #e3f2fd;
    border-color: #2196f3;
}

.female-color {
    background: #fce4ec;
    border-color: #e91e63;
}

.highlight-color {
    background: #fff9c4;
    border-color: #f39c12;
}

/* Loading skeleton */
.loading-screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-5);
    z-index: 999;
    background: rgba(253, 251, 247, 0.92);
    color: var(--color-ray);
}

.loading-screen__text {
    margin: 0;
    font-size: var(--font-size-base);
}

.tree-skeleton {
    width: min(320px, 80%);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.tree-skeleton__bar,
.tree-skeleton__node {
    border-radius: 8px;
    background: linear-gradient(
        90deg,
        var(--color-gray-bg) 0%,
        rgba(255, 255, 255, 0.9) 50%,
        var(--color-gray-bg) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

.tree-skeleton__bar {
    height: 12px;
    width: 60%;
    align-self: center;
}

.tree-skeleton__nodes {
    display: flex;
    justify-content: center;
    gap: var(--space-4);
}

.tree-skeleton__node {
    width: 72px;
    height: 36px;
}

.tree-skeleton__node--sm {
    width: 56px;
    height: 28px;
    opacity: 0.7;
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .tree-skeleton__bar,
    .tree-skeleton__node {
        animation: none;
        background: var(--color-gray-bg);
    }
}

/* Fullscreen */
.interactive-tree.fullscreen {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: var(--vh-full) !important;
    z-index: var(--z-tree-fullscreen) !important;
    background: var(--color-white) !important;
    margin: 0 !important;
    padding: clamp(0.5rem, 2vw, 1rem) !important;
    box-sizing: border-box;
}

.interactive-tree.fullscreen .interactive-tree__head {
    display: none;
}

.interactive-tree.fullscreen .interactive-tree-container {
    border: none;
    border-radius: 0;
    height: var(--vh-full);
    display: flex;
    flex-direction: column;
}

.interactive-tree.fullscreen .control-bar {
    flex-shrink: 0;
}

.interactive-tree.fullscreen .TreeSvg-container {
    flex: 1;
    min-height: 0;
    max-height: none !important;
    height: auto !important;
}

.fullscreen-hint {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.75);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    z-index: calc(var(--z-tree-fullscreen) + 1);
    opacity: 0;
    animation: fadeInOut 3s ease-in-out;
    pointer-events: none;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    10%, 90% { opacity: 1; }
}

.fullscreen-hint kbd {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: bold;
}

/* Performance */
.node,
.link {
    will-change: transform;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
    .family-tree-wrap {
        padding: 0 clamp(1rem, 3vw, 2rem) clamp(1.5rem, 4vw, 2.5rem);
    }

    .interactive-tree-container {
        border-radius: 14px;
    }
}

@media (max-width: 768px) {
    .tree-hero__actions {
        flex-direction: column;
        align-items: stretch;
    }

    .tree-hero__actions .clean-button {
        width: 100%;
        min-width: 0;
    }

    .control-bar {
        padding: var(--space-3) var(--space-3);
    }

    .control-container {
        gap: var(--space-3);
    }

    .controls {
        width: 100%;
        justify-content: flex-start;
    }

    .control-btn {
        width: var(--touch-target);
        height: var(--touch-target);
        font-size: var(--font-size-base);
        flex-shrink: 0;
    }

    .controls-zoom .control-btn {
        width: 44px;
        height: 44px;
    }

    .search-control-wrap {
        flex: 1 1 100%;
        min-width: 0;
        order: 10;
    }

    .search-btn.expanded {
        width: 100%;
        max-width: none;
    }

    .search-results {
        width: 100%;
        max-width: none;
        inset-inline: 0;
    }

    .TreeSvg-container {
        min-height: 360px;
        height: 400px;
    }

    @supports (height: 1dvh) {
        .TreeSvg-container {
            min-height: clamp(360px, 50dvh, 640px);
            height: clamp(400px, 54dvh, 600px);
        }
    }

    .tree-node-card {
        padding: 10px 12px 8px;
        gap: 6px;
        border-radius: 12px;
    }

    .tree-node-card__name {
        font-size: var(--font-size-small);
        -webkit-line-clamp: 3;
    }

    .tree-node-card__photo {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }

    .legend {
        left: 10px;
        top: 15px;
        padding: 0;
        width: var(--touch-target);
        height: var(--touch-target);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        background: var(--color-white);
    }

    .legend-toggle {
        display: block;
        font-size: var(--font-size-large);
        color: var(--color-black-light);
    }

    .legend-content {
        display: none;
        position: absolute;
        top: 50px;
        left: 0;
        background: var(--color-white);
        padding: 12px;
        border-radius: 12px;
        border: 1px solid var(--color-gray-light);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        min-width: 150px;
        z-index: 100;
    }

    .legend-content.show {
        display: block;
    }

    .interactive-tree.fullscreen .TreeSvg-container {
        height: calc(var(--vh-full) - 120px) !important;
    }

    .fullscreen-hint {
        bottom: 10px;
        font-size: var(--font-size-x-small);
    }
}

@media (max-width: 480px) {
    .family-tree-wrap {
        padding: 0 1rem 1.5rem;
    }

    .interactive-tree__title {
        font-size: clamp(1.35rem, 6vw, 1.75rem);
    }

    .TreeSvg-container {
        min-height: 340px;
        height: 380px;
        border-radius: 0 0 12px 12px;
    }

    @supports (height: 1dvh) {
        .TreeSvg-container {
            min-height: clamp(340px, 48dvh, 520px);
            height: clamp(380px, 50dvh, 520px);
        }
    }

    .controls-zoom {
        order: 5;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .search-control-wrap {
        flex: 1 1 auto;
        order: 0;
    }

    .search-btn.expanded {
        width: min(280px, calc(100vw - 8rem));
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .TreeSvg-container {
        min-height: 400px;
        height: 440px;
    }

    @supports (height: 1dvh) {
        .TreeSvg-container {
            min-height: clamp(400px, 55dvh, 700px);
            height: clamp(440px, 58dvh, 720px);
        }
    }
}

@media (min-width: 769px) {
    .legend-content {
        display: block !important;
        position: static;
        padding: 0;
        border: none;
        box-shadow: none;
        min-width: auto;
    }
}

/* ──────────────────────────────────────────────
   Detail modal (Alpine)
   ────────────────────────────────────────────── */
[x-cloak] {
    display: none !important;
}

.tree-detail-modal {
    position: fixed;
    inset: 0;
    /* فوق طبقة ملء الشاشة (--z-tree-fullscreen: 700) حتى تظهر البطاقة في وضع ملء الشاشة */
    z-index: calc(var(--z-tree-fullscreen, 700) + 20);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.tree-detail-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(31, 26, 20, 0.45);
    backdrop-filter: blur(2px);
}

.tree-detail-modal__panel {
    position: relative;
    z-index: 1;
    width: min(440px, calc(100vw - 2rem));
    max-height: 85vh;
    overflow-y: auto;
    background-color: var(--color-white, #fff);
    border-radius: 18px;
    padding: clamp(1.25rem, 3vw, 1.75rem);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    direction: rtl;
    text-align: right;
    isolation: isolate;
}

.tree-detail-modal__close {
    position: absolute;
    top: 14px;
    inset-inline-start: 14px;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: var(--color-gray-bg);
    color: var(--color-black-light);
    cursor: pointer;
    font-size: 15px;
    transition: background-color var(--duration-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
    .tree-detail-modal__close:hover {
        background: var(--color-gray-light);
    }
}

.tree-detail-modal__close:active {
    transform: scale(0.97);
}

.tree-detail__head {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: var(--space-4);
    padding-inline-end: 28px;
}

.tree-detail__photo {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    background-color: var(--color-gray-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-ray);
    font-size: 24px;
    border: 2px solid var(--color-gray-light);
}

.tree-detail__name {
    font-size: var(--font-size-x-large);
    font-weight: 600;
    color: var(--color-black-light);
    margin: 0 0 4px;
}

.tree-detail__lineage {
    font-size: var(--font-size-small);
    color: var(--color-ray);
    margin: 0;
    line-height: 1.5;
}

.tree-detail__status {
    display: inline-block;
    font-size: var(--font-size-x-small);
    font-weight: 500;
    border-radius: 999px;
    padding: 3px 12px;
    margin-bottom: var(--space-4);
}

.tree-detail__status.is-alive {
    background: #e7f6ec;
    color: #1d7a43;
}

.tree-detail__status.is-deceased {
    background: #f0f0f0;
    color: #6b7280;
}

.tree-detail__status.is-unknown {
    background: #f3f4f6;
    color: #6b7280;
}

.tree-detail__grid {
    margin: 0 0 var(--space-4);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tree-detail__row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 2px;
    border-bottom: 1px solid var(--color-gray-bg);
}

.tree-detail__row dt {
    color: var(--color-ray);
    font-size: var(--font-size-small);
}

.tree-detail__row dd {
    margin: 0;
    color: var(--color-black-light);
    font-weight: 500;
    font-size: var(--font-size-small);
}

.tree-detail__sub {
    color: var(--color-ray);
    font-weight: 400;
}

.tree-detail__bio h4 {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--color-black-light);
    margin: 0 0 6px;
}

.tree-detail__bio p {
    font-size: var(--font-size-small);
    line-height: 1.7;
    color: var(--color-ray);
    margin: 0;
}

/* Admin controls inside detail modal */
.tree-detail__admin {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-gray-bg);
}

.tree-detail__admin h4 {
    font-size: var(--font-size-small);
    font-weight: 600;
    color: var(--color-ray);
    margin: 0 0 10px;
}

.tree-detail__admin-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.btn-detail-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    font-size: var(--font-size-small);
    font-weight: 500;
    color: var(--color-black-light);
    background: var(--color-gray-bg);
    border: 1px solid var(--color-gray-light);
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
    .btn-detail-action:hover {
        background: var(--color-white);
        border-color: var(--color-ray);
    }
}

.btn-detail-action:active {
    transform: scale(0.97);
}

.btn-detail-action--danger {
    color: #c0392b;
    background: #fdecea;
    border-color: #f5c6cb;
}

@media (hover: hover) and (pointer: fine) {
    .btn-detail-action--danger:hover {
        background: #fbddd8;
        border-color: #e9a8a1;
    }
}

/* Mobile: keep centered modal; stack admin actions */
@media (max-width: 600px) {
    .tree-detail__admin-actions {
        grid-template-columns: 1fr;
    }

    .tree-detail__head {
        gap: 12px;
    }

    .tree-detail__photo {
        width: 54px;
        height: 54px;
        font-size: 20px;
    }
}

/* Modal transitions (Emil: ease-out enter, faster leave) */
.ftm-fade-enter {
    transition: opacity 200ms ease-out;
}

.ftm-fade-leave {
    transition: opacity 160ms ease-out;
}

.ftm-fade-start {
    opacity: 0;
}

.ftm-fade-end {
    opacity: 1;
}

.ftm-panel-enter {
    transition: transform 200ms cubic-bezier(0.23, 1, 0.32, 1);
}

.ftm-panel-leave {
    transition: transform 160ms ease-out;
}

.ftm-panel-start {
    transform: scale(0.95) translateY(8px);
}

.ftm-panel-end {
    transform: none;
}

@media (prefers-reduced-motion: reduce) {

    .ftm-panel-enter,
    .ftm-panel-leave,
    .ftm-fade-enter,
    .ftm-fade-leave {
        transition: opacity 120ms linear;
    }

    .ftm-panel-start {
        transform: none;
    }
}

/* ──────────────────────────────────────────────
   شريط التحكم الجديد: بحث مفتوح + قائمة إجراءات + ملء الشاشة
   ────────────────────────────────────────────── */
.tree-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
}

.tree-search {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 45px;
    padding: 0 12px;
    border: 1.5px solid var(--color-gray-light);
    border-radius: 10px;
    background: var(--color-white);
    transition: border-color var(--duration-fast) var(--ease-out);
}

.tree-search:focus-within {
    border-color: var(--color-black-light);
}

.tree-search__icon {
    flex-shrink: 0;
    color: var(--color-ray);
    font-size: var(--font-size-base);
}

/* الحقل يعيد استخدام #searchInputExpanded الموجود (بلا حدود/خلفية) */
.tree-search .search-results {
    width: 100%;
    inset-inline: 0;
    right: auto;
}

.tree-actions {
    position: relative;
    flex-shrink: 0;
}

.actions-menu {
    position: absolute;
    top: calc(100% + 6px);
    inset-inline-end: 0;
    min-width: 230px;
    background: var(--color-white);
    border: 1px solid var(--color-gray-light);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 6px;
    z-index: 1002;
    display: none;
    text-align: right;
}

.actions-menu.show {
    display: block;
}

.actions-menu__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 11px 12px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: var(--font-size-base);
    color: var(--color-black-light);
    text-align: right;
    transition: background-color var(--duration-fast) var(--ease-out);
}

.actions-menu__item i {
    width: 18px;
    text-align: center;
    color: var(--color-ray);
    flex-shrink: 0;
}

@media (hover: hover) and (pointer: fine) {
    .actions-menu__item:hover {
        background: var(--color-gray-bg);
    }
}

.actions-menu__item:active {
    transform: scale(0.99);
}

/* أزرار التكبير/التصغير الطافية */
.tree-zoom-floating {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 50;
}

.tree-zoom-btn {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-gray-light);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--color-black-light);
    cursor: pointer;
    font-size: var(--font-size-large);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    transition:
        transform var(--duration-fast) var(--ease-out),
        background-color var(--duration-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
    .tree-zoom-btn:hover {
        background: #fff;
    }
}

.tree-zoom-btn:active {
    transform: scale(0.94);
}

/* ──────────────────────────────────────────────
   مودال تحليل صلة القرابة (يعيد استخدام .tree-detail-modal)
   ────────────────────────────────────────────── */
.rel-modal__panel {
    width: min(480px, calc(100vw - 2rem));
    overflow: visible;
    max-height: none;
}

.rel-modal #relForm {
    overflow: visible;
}

.rel-modal .tree-detail-modal__close {
    left: 14px;
    right: auto;
    inset-inline-start: auto;
    inset-inline-end: auto;
}

.rel-modal__title {
    margin: 0 0 6px;
    padding-inline: 44px;
    font-size: var(--font-size-large);
    font-weight: 600;
    color: var(--color-black-light);
    text-align: center;
}

.rel-modal__hint {
    margin: 0 0 18px;
    color: var(--color-ray);
    font-size: var(--font-size-small);
}

.rel-field {
    margin-bottom: 14px;
    position: relative;
}

.rel-field:focus-within {
    z-index: 4;
}

.rel-field__label {
    display: block;
    margin-bottom: 6px;
    font-size: var(--font-size-small);
    font-weight: 500;
    color: var(--color-black-light);
}

.rel-picker {
    position: relative;
}

.rel-picker__input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--color-gray-light);
    border-radius: 10px;
    font-family: inherit;
    font-size: var(--font-size-base);
    color: var(--color-black-light);
    background: var(--color-white);
    outline: none;
    transition: border-color var(--duration-fast) var(--ease-out);
}

.rel-picker__input:focus {
    border-color: var(--color-black-light);
}

.rel-picker__results {
    position: absolute;
    top: calc(100% + 4px);
    inset-inline: 0;
    background: var(--color-white, #fff);
    border: 1px solid var(--color-gray-light);
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    max-height: 200px;
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 20;
    display: none;
}

.rel-picker__results.show {
    display: block;
}

.rel-picker__item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: var(--font-size-small);
    color: var(--color-black-light);
    border-bottom: 1px solid var(--color-gray-bg);
}

.rel-picker__item:last-child {
    border-bottom: none;
}

@media (hover: hover) and (pointer: fine) {
    .rel-picker__item:hover {
        background: var(--color-gray-bg);
    }
}

.rel-picker__item.is-empty {
    color: var(--color-ray);
    cursor: default;
}

.rel-actions {
    display: flex;
    justify-content: center;
    margin-top: 22px;
}

.rel-analyze-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    border: none;
    border-radius: 12px;
    background: var(--color-black-light, #3f3529);
    color: #fff;
    font-family: inherit;
    font-size: var(--font-size-base);
    cursor: pointer;
    transition:
        opacity var(--duration-fast) var(--ease-out),
        transform var(--duration-fast) var(--ease-out);
}

.rel-analyze-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.rel-analyze-btn:not(:disabled):active {
    transform: scale(0.98);
}

@media (max-width: 1024px) {
    .rel-modal__panel {
        width: min(560px, calc(100vw - 1.25rem));
        padding: clamp(1.5rem, 4vw, 2rem);
    }

    .rel-modal__title {
        font-size: clamp(1.125rem, 3.5vw, 1.35rem);
        margin-bottom: 8px;
    }

    .rel-modal__hint {
        margin-bottom: 22px;
        line-height: 1.65;
    }

    .rel-field {
        margin-bottom: 18px;
    }

    .rel-field__label {
        margin-bottom: 8px;
    }

    .rel-picker__input {
        padding: 14px 14px;
        min-height: 48px;
        font-size: 16px;
        border-radius: 12px;
    }

    .rel-picker__item {
        padding: 12px 14px;
        min-height: 44px;
    }

    .rel-actions {
        margin-top: 26px;
    }

    .rel-analyze-btn {
        width: 100%;
        justify-content: center;
        min-height: 50px;
        padding: 14px 20px;
        border-radius: 14px;
        font-size: var(--font-size-large);
    }
}

@media (max-width: 768px) {
    .rel-modal__panel {
        width: 100%;
        max-width: none;
        padding: 1.5rem 1.25rem 1.75rem;
        border-radius: 16px;
    }

    .rel-picker__results {
        max-height: min(168px, 34dvh);
    }

    .tree-detail-modal.rel-modal {
        padding: var(--space-3);
        align-items: center;
    }
}

/* حالة التحميل */
.rel-step--loading {
    text-align: center;
    padding: 44px 10px;
}

.rel-spinner {
    width: 46px;
    height: 46px;
    margin: 0 auto 18px;
    border: 4px solid var(--color-gray-light);
    border-top-color: var(--color-black-light);
    border-radius: 50%;
    animation: rel-spin 0.8s linear infinite;
}

@keyframes rel-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .rel-spinner {
        animation-duration: 1.6s;
    }
}

.rel-loading__text {
    margin: 0;
    color: var(--color-ray);
    font-size: var(--font-size-base);
}

/* حالة النتيجة */
.rel-step--result {
    padding-inline-end: 28px;
    max-height: min(68vh, 520px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.rel-result__badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--color-cream);
    color: var(--color-black-light);
    font-size: var(--font-size-small);
    margin-bottom: 14px;
}

.rel-result__headline {
    margin: 0 0 6px;
    font-size: var(--font-size-large);
    color: var(--color-black-light);
}

.rel-result__degree {
    margin: 0 0 16px;
    color: var(--color-ray);
    font-size: var(--font-size-small);
}

.rel-result__ancestor {
    background: var(--color-gray-bg);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 18px;
    font-size: var(--font-size-small);
    color: var(--color-black-light);
}

.rel-result__ancestor strong {
    font-weight: 600;
}

.rel-chain {
    margin-bottom: 16px;
}

.rel-chain__title {
    margin: 0 0 8px;
    font-size: var(--font-size-small);
    color: var(--color-ray);
}

.rel-chain__flow {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.rel-chain__node {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--color-white);
    border: 1.5px solid var(--color-gray-light);
    font-size: var(--font-size-small);
    color: var(--color-black-light);
    white-space: nowrap;
}

.rel-chain__node--lca {
    border-color: #c9a227;
    background: #fdf6e3;
    font-weight: 600;
}

.rel-chain__arrow {
    color: var(--color-ray);
    font-size: 12px;
}

.rel-result__actions {
    display: flex;
    justify-content: center;
    margin-top: 18px;
}

.rel-result__back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 20px;
    border: 1.5px solid var(--color-gray-light);
    border-radius: 10px;
    background: var(--color-white);
    color: var(--color-black-light);
    font-family: inherit;
    font-size: var(--font-size-small);
    cursor: pointer;
}

@media (hover: hover) and (pointer: fine) {
    .rel-result__back:hover {
        background: var(--color-gray-bg);
    }
}

/* ──────────────────────────────────────────────
   مودال تأكيد تصدير PDF
   ────────────────────────────────────────────── */
.pdf-modal__panel {
    width: min(400px, calc(100vw - 2rem));
    text-align: center;
}

.pdf-modal__icon {
    font-size: 46px;
    color: #d9534f;
    margin-bottom: 12px;
}

.pdf-modal__title {
    margin: 0 0 8px;
    font-size: var(--font-size-large);
    color: var(--color-black-light);
}

.pdf-modal__msg {
    margin: 0 0 22px;
    color: var(--color-ray);
    font-size: var(--font-size-small);
    line-height: 1.7;
}

.pdf-modal__actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.pdf-modal__btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 22px;
    border-radius: 10px;
    border: 1.5px solid transparent;
    cursor: pointer;
    font-family: inherit;
    font-size: var(--font-size-base);
    transition: transform var(--duration-fast) var(--ease-out);
}

.pdf-modal__btn--ghost {
    background: var(--color-white);
    border-color: var(--color-gray-light);
    color: var(--color-black-light);
}

@media (hover: hover) and (pointer: fine) {
    .pdf-modal__btn--ghost:hover {
        background: var(--color-gray-bg);
    }
}

.pdf-modal__btn--primary {
    background: var(--color-black-light, #3f3529);
    color: #fff;
}

.pdf-modal__btn:active {
    transform: scale(0.98);
}

/* تجاوب الشريط الجديد على الجوال */
@media (max-width: 480px) {
    .actions-menu {
        min-width: min(240px, calc(100vw - 40px));
    }

    .tree-zoom-floating {
        bottom: 12px;
        right: 12px;
    }
}
