/* =============================================
   Kinship Tree Styles — Shared between Chat & Search
   ============================================= */

/* Result wrapper */
.kinship-result {
    margin: 0.5rem 0;
}

.kinship-label {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1f2937;
    background: linear-gradient(135deg, #dbeafe, #ede9fe);
    border: 1px solid #93c5fd;
    border-radius: 12px;
    padding: 0.75rem 1.2rem;
    text-align: center;
    margin-bottom: 1rem;
    font-family: 'Cairo', sans-serif;
}

.kinship-link-names {
    display: inline-block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #831843;
    background: linear-gradient(135deg, #fce7f3, #f9a8d4);
    border: 1px solid #f472b6;
    border-radius: 8px;
    padding: 0.2rem 0.6rem;
    margin-top: 0.35rem;
    font-family: 'Cairo', sans-serif;
}

.kinship-section-title {
    font-size: 0.85rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
    font-family: 'Cairo', sans-serif;
}

/* ============================================
   Hierarchy Tree (fork at common ancestor)
   ============================================ */
.kt-tree {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    margin: 1rem 0;
    padding: 0.5rem 0.5rem;
    min-width: 0;
    /* Break out of narrow containers to use full viewport width */
    width: 96vw;
    max-width: 96vw;
    margin-left: calc(-50vw + 50%);
    margin-right: calc(-50vw + 50%);
    padding-left: 2vw;
    padding-right: 2vw;
    box-sizing: border-box;
}

.kt-tree-inner {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    min-width: 100%;
}

/* Person node (generic) */
.kt-person {
    background: #f9fafb;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    padding: 0.3rem 0.65rem;
    font-size: 0.76rem;
    color: #374151;
    font-weight: 600;
    white-space: nowrap;
    text-align: center;
    font-family: 'Cairo', sans-serif;
    flex-shrink: 0;
}

/* Common ancestor (amber) */
.kt-person.kt-ancestor {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-color: #f59e0b;
    color: #78350f;
    font-size: 0.8rem;
    padding: 0.4rem 0.9rem;
    box-shadow: 0 2px 10px rgba(245, 158, 11, 0.2);
}

/* Person A highlight (blue) */
.kt-person.kt-highlight-a {
    background: linear-gradient(135deg, #dbeafe, #93c5fd);
    border-color: #2563eb;
    color: #1e3a5f;
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.2);
}

/* Person B highlight (purple) */
.kt-person.kt-highlight-b {
    background: linear-gradient(135deg, #ede9fe, #c4b5fd);
    border-color: #7c3aed;
    color: #3b1f7a;
    box-shadow: 0 2px 10px rgba(124, 58, 237, 0.2);
}

/* Marriage link person highlight (rose/pink) */
.kt-person.kt-highlight-link {
    background: linear-gradient(135deg, #fce7f3, #f9a8d4);
    border-color: #db2777;
    color: #831843;
    box-shadow: 0 2px 10px rgba(219, 39, 119, 0.2);
}

/* Spouse card — wife (rose) */
.kt-person.kt-spouse-a {
    background: linear-gradient(135deg, #fce7f3, #fbcfe8);
    border: 2px solid #ec4899;
    color: #831843;
    box-shadow: 0 3px 12px rgba(236, 72, 153, 0.25);
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
}

/* Spouse card — husband (teal) */
.kt-person.kt-spouse-b {
    background: linear-gradient(135deg, #ccfbf1, #99f6e4);
    border: 2px solid #14b8a6;
    color: #134e4a;
    box-shadow: 0 3px 12px rgba(20, 184, 166, 0.25);
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
}

/* Link icon between spouse cards */
.kt-spouse-heart {
    font-size: 1.4rem;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.5rem;
}

/* Vertical line from ancestor to horizontal bar */
.kt-fork {
    width: 2px;
    height: 20px;
    background: #d1d5db;
}

/* Container for the two branches — uses border-top as the horizontal bar */
.kt-branches {
    display: flex;
    justify-content: center;
    border-top: 2px solid #d1d5db;
    gap: 0;
}

/* Each branch column */
.kt-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 1.25rem;
    min-width: 90px;
    flex-shrink: 0;
}

/* Vertical drop from horizontal bar to first node */
.kt-drop {
    width: 2px;
    height: 16px;
    background: #d1d5db;
}

/* Vertical connector between nodes in a branch */
.kt-stem {
    width: 2px;
    height: 16px;
    background: #d1d5db;
}

/* Labeled vertical stem (shows relationship label like والد, ابن) */
.kt-stem-labeled {
    width: 2px;
    height: 28px;
    background: #d1d5db;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kt-stem-labeled span {
    position: absolute;
    right: 8px;
    background: #ffffff;
    padding: 0.1rem 0.35rem;
    font-size: 0.6rem;
    color: #6b7280;
    white-space: nowrap;
    font-family: 'Cairo', sans-serif;
    border-radius: 5px;
    border: 1px solid #e5e7eb;
    font-weight: 600;
}

/* ============================================
   Marriage Tree (spouse branches)
   ============================================ */

/* Dual tree layout for mid-path spouse connections */
.km-dual-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 1rem 0;
    gap: 0;
    /* Break out like kt-tree */
    width: 96vw;
    max-width: 96vw;
    margin-left: calc(-50vw + 50%);
    margin-right: calc(-50vw + 50%);
    padding-left: 2vw;
    padding-right: 2vw;
    box-sizing: border-box;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Nested kt-tree inside dual-tree should not break out again */
.km-dual-tree .kt-tree {
    width: auto;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
    padding-left: 0;
    padding-right: 0;
}

/* Marriage connector between the two trees */
.km-mid-connector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0;
}

.km-mid-connector span {
    font-size: 0.72rem;
    font-weight: 700;
    color: #92400e;
    font-family: 'Cairo', sans-serif;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border: 1.5px solid #f59e0b;
    border-radius: 8px;
    padding: 0.25rem 0.75rem;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.15);
}

.km-mid-line {
    width: 40px;
    height: 2px;
    background: #f59e0b;
    flex-shrink: 0;
}

.km-pair {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    gap: 0;
    position: relative;
}

.km-spouse-arm {
    display: flex;
    direction: ltr;
    align-items: center;
    gap: 0;
    white-space: nowrap;
    flex-shrink: 0;
    order: -1;
    margin-top: 0;
    align-self: center;
}

.km-spouse-arm.km-arm-right {
    direction: rtl;
    order: 1;
}

.km-hline {
    width: 50px;
    height: 2px;
    background: #f59e0b;
    position: relative;
    flex-shrink: 0;
    align-self: center;
}

.km-hline span {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.58rem;
    color: #92400e;
    white-space: nowrap;
    font-family: 'Cairo', sans-serif;
    border-radius: 5px;
    border: 1px solid #fcd34d;
    background: #ffffff;
    padding: 0.1rem 0.35rem;
    font-weight: 600;
    line-height: 1;
}

.km-main {
    border-color: #f59e0b !important;
    background: linear-gradient(135deg, #fef3c7, #fde68a) !important;
    color: #78350f !important;
    box-shadow: 0 2px 10px rgba(245, 158, 11, 0.2);
}

/* ============================================
   Linear Chain (fallback for simple paths)
   ============================================ */
.kinship-chain {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0;
    margin: 1rem 0;
    direction: rtl;
    overflow-x: auto;
    padding: 0.75rem 2vw;
    -webkit-overflow-scrolling: touch;
    width: 96vw;
    max-width: 96vw;
    margin-left: calc(-50vw + 50%);
    margin-right: calc(-50vw + 50%);
    box-sizing: border-box;
}

.kinship-chain::-webkit-scrollbar {
    height: 4px;
}

.kinship-chain::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

.kc-node {
    background: #f9fafb;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
    color: #374151;
    font-weight: 600;
    white-space: nowrap;
    text-align: center;
    font-family: 'Cairo', sans-serif;
    flex-shrink: 0;
}

.kc-node.kc-start {
    background: linear-gradient(135deg, #dbeafe, #93c5fd);
    border-color: #2563eb;
    color: #1e3a5f;
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.2);
}

.kc-node.kc-end {
    background: linear-gradient(135deg, #ede9fe, #c4b5fd);
    border-color: #7c3aed;
    color: #3b1f7a;
    box-shadow: 0 2px 10px rgba(124, 58, 237, 0.2);
}

.kc-arrow {
    width: 40px;
    height: 2px;
    background: #d1d5db;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kc-arrow span {
    position: absolute;
    top: -20px;
    background: #ffffff;
    padding: 0.1rem 0.35rem;
    font-size: 0.6rem;
    color: #6b7280;
    white-space: nowrap;
    font-family: 'Cairo', sans-serif;
    border-radius: 5px;
    border: 1px solid #e5e7eb;
}

/* Scrollbar styling */
.kt-tree::-webkit-scrollbar {
    height: 4px;
}

.kt-tree::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

/* Mobile adjustments */
@media (max-width: 600px) {
    .kt-tree {
        padding: 0.5rem 0.5rem;
    }

    .kt-branch {
        padding: 0 0.5rem;
        min-width: 70px;
    }

    .kt-person {
        font-size: 0.68rem;
        padding: 0.25rem 0.4rem;
    }

    .kt-person.kt-ancestor {
        font-size: 0.72rem;
    }

    .kc-node {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
    }

    .kc-arrow {
        width: 28px;
    }

    .km-spouse-arm {
        transform: scale(0.9);
        transform-origin: center center;
    }

    .km-mid-connector span {
        font-size: 0.65rem;
        padding: 0.2rem 0.5rem;
    }

    .km-mid-line {
        width: 28px;
    }
}
