/* Frontend Container */
.ft-frontend-container {
    --ft-accent: #2271b1;
    --ft-line-color: #d4d4d8;
    --ft-line-style: solid;
    --ft-line-width: 2px;
    width: 100%;
    overflow: hidden;
    position: relative;
    background: #fff;
    padding: 20px 0;
    cursor: grab;
}

.ft-frontend-container.active {
    cursor: grabbing;
}

/* Connector style helpers */
.ft-connect-soft {
    --ft-line-color: #e5e7eb;
    --ft-line-width: 1.5px;
}

.ft-connect-dashed {
    --ft-line-style: dashed;
}

.ft-member-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}

.ft-member-modal.is-open {
    display: flex;
}

.ft-member-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(3px);
}

.ft-member-modal-dialog {
    position: relative;
    max-width: 640px;
    width: 92%;
    background: linear-gradient(135deg, #ffffff, #f9fafb);
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
    padding: 22px 24px 20px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    z-index: 1;
    transform: translateY(10px) scale(0.97);
    opacity: 0;
    transition: transform 0.22s ease, opacity 0.22s ease, box-shadow 0.22s ease;
}

.ft-member-modal.is-open .ft-member-modal-dialog {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.ft-member-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: none;
    background: #f3f4f6;
    color: #4b5563;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.ft-member-modal-close:hover {
    background: #e5e7eb;
}

.ft-member-modal-header {
    display: flex;
    align-items: center;
    gap: 18px;
    text-align: left;
    margin-bottom: 18px;
}

.ft-member-modal-heading {
    flex: 1;
}

.ft-member-modal-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 999px;
    background: rgba(34, 113, 177, 0.08);
    color: var(--ft-accent);
    border: 1px solid rgba(34, 113, 177, 0.25);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.ft-member-modal-photo {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    object-fit: cover;
    margin: 0;
    border: 3px solid var(--ft-accent);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.25);
}

.ft-member-modal-title {
    margin: 0 0 4px 0;
    font-size: 22px;
    font-weight: 700;
    color: #111827;
}

.ft-member-modal-subtitle {
    margin: 0;
    font-size: 13px;
    color: #6b7280;
}

.ft-member-modal-meta {
    font-size: 12px;
    color: #4b5563;
    margin: 0 0 14px;
    text-align: left;
    padding: 6px 10px;
    background: rgba(15, 23, 42, 0.03);
    border-radius: 999px;
    display: inline-block;
}

.ft-member-modal-location {
    font-size: 13px;
    color: #111827;
    margin: 4px 0 10px;
    font-weight: 500;
}

.ft-member-modal-link {
    display: inline-flex;
    align-items: center;
    margin-top: 14px;
    padding: 7px 14px;
    border-radius: 999px;
    background: #ffffff;
    color: var(--ft-accent);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid rgba(148, 163, 184, 0.7);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.12);
}

.ft-member-modal-link:hover {
    opacity: 0.9;
}

.ft-member-modal-link::after {
    content: '↗';
    font-size: 12px;
    margin-left: 6px;
}

.ft-member-modal-description {
    font-size: 14px;
    line-height: 1.6;
    color: #374151;
    max-height: 260px;
    overflow: auto;
    padding-right: 4px;
    padding-top: 14px;
    margin-top: 10px;
    border-top: 1px solid #e5e7eb;
}

.ft-member-modal-description p {
    margin: 0 0 10px 0;
}

@media (max-width: 640px) {
    .ft-member-modal-dialog {
        padding: 18px 16px 18px;
        border-radius: 16px;
    }

    .ft-member-modal-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .ft-member-modal-photo {
        margin-bottom: 8px;
    }

    .ft-member-modal-meta {
        text-align: center;
    }
}

/* Canvas & Tree Wrapper */
.ft-frontend-canvas {
    overflow-x: auto;
    padding: 40px;
    display: flex;
    /* justify-content: center;  <-- Removed to prevent cutting off left side on overflow */
    min-width: 100%;
    /* Hide scrollbar visually but keep functionality */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none;  /* IE 10+ */
}

.ft-frontend-canvas::-webkit-scrollbar { 
    display: none; /* Chrome/Safari */
}

.ft-tree-wrapper {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin: 0 auto; /* Centers the tree when smaller than viewport, allows scroll when larger */
}

/* Header above tree */
.ft-tree-header {
    max-width: 800px;
    margin: 0 auto 20px auto;
    text-align: center;
}

.ft-tree-title {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 8px 0;
    color: #111827;
}

.ft-tree-summary,
.ft-tree-description {
    font-size: 14px;
    color: #4b5563;
}

.ft-tree-header {
    text-align: center;
    margin-bottom: 20px;
}

.ft-tree-title {
    margin: 0 0 6px 0;
    font-size: 20px;
    font-weight: 700;
    color: #1f2933;
}

.ft-tree-summary {
    font-size: 13px;
    color: #4b5563;
}

/* Nodes & Connectors */
.ft-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding-top: 20px;
}

/* Vertical line from top of node (connecting to parent) */
.ft-node::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: var(--ft-line-width) var(--ft-line-style) var(--ft-line-color);
    width: 0;
    height: 20px;
}

/* Remove line for root nodes */
.ft-tree-wrapper > .ft-node::before {
    display: none;
}

.ft-children {
    display: flex;
    flex-direction: row;
    justify-content: center;
    padding-top: 20px;
    position: relative;
}

/* Vertical line from bottom of card to children container */
.ft-children::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: var(--ft-line-width) var(--ft-line-style) var(--ft-line-color);
    width: 0;
    height: 20px;
}

.ft-child-wrapper {
    position: relative;
    padding: 20px 10px 0 10px;
}

/* Horizontal connectors */
.ft-child-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    left: 0;
    border-top: var(--ft-line-width) var(--ft-line-style) var(--ft-line-color);
    height: 20px;
}

.ft-child-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 50%;
    border-top: var(--ft-line-width) var(--ft-line-style) var(--ft-line-color);
    height: 20px;
}

.ft-child-wrapper:first-child::before { display: none; }
.ft-child-wrapper:last-child::after { display: none; }
.ft-child-wrapper:first-child:last-child::after { display: none; }
.ft-child-wrapper:first-child:last-child::before { display: none; }


/* Card Styling */
@keyframes ftFadeInUp {
    0% {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ft-animate-cards .ft-card {
    animation: ftFadeInUp 0.45s ease forwards;
}

.ft-card {
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    width: 220px;
    padding: 15px 10px;
    text-align: center;
    position: relative;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 5; /* Ensure card and its children (toggle button) stay above connectors */
}

.ft-card-root {
    border-color: #e5e7eb;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
}

.ft-design-modern .ft-card {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    width: 260px;
    padding: 14px 16px;
    border-radius: 12px;
    border: none;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

.ft-design-modern .ft-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 14px;
    bottom: 14px;
    width: 3px;
    border-radius: 3px;
    background: var(--ft-accent);
}

.ft-design-left .ft-card {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    width: 260px;
    padding: 14px 16px;
}

.ft-design-left .ft-photo,
.ft-design-left .ft-photo-placeholder {
    margin: 0;
}

.ft-design-right .ft-card {
    display: flex;
    align-items: center;
    flex-direction: row-reverse;
    gap: 12px;
    text-align: left;
    width: 260px;
    padding: 14px 16px;
}

.ft-design-modern .ft-card,
.ft-design-left .ft-card,
.ft-design-right .ft-card {
    align-items: flex-start;
}

.ft-design-right .ft-photo,
.ft-design-right .ft-photo-placeholder {
    margin: 0;
}

.ft-design-banner .ft-card {
    width: 260px;
    padding: 14px 16px;
    text-align: left;
}

.ft-design-banner .ft-photo,
.ft-design-banner .ft-photo-placeholder {
    margin-bottom: 8px;
}

.ft-design-minimal .ft-card {
    background: transparent;
    border-color: #e5e7eb;
    box-shadow: none;
}

.ft-design-compact .ft-card {
    width: 190px;
    padding: 10px 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}

.ft-theme-blue .ft-card {
    border-color: #2563eb;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.15);
}

.ft-theme-blue .ft-age-line {
    color: #2563eb;
}

.ft-theme-soft .ft-card {
    background: #f9fafb;
    border-color: #e5e7eb;
}

.ft-theme-soft .ft-age-line {
    color: #111827;
}

.ft-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 15px rgba(0,0,0,0.1);
}

.ft-photo {
    width: 70px !important;
    height: 70px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    margin-bottom: 10px;
    border: 3px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.ft-card-root .ft-photo {
    border-color: var(--ft-accent);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.28);
}

.ft-photo-placeholder {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: #f0f0f1;
    margin: 0 auto 10px auto;
}

.ft-design-modern .ft-photo,
.ft-design-modern .ft-photo-placeholder {
    margin: 0;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.18);
}

.ft-design-left .ft-photo,
.ft-design-left .ft-photo-placeholder,
.ft-design-right .ft-photo,
.ft-design-right .ft-photo-placeholder {
    margin: 4px 0 0 0;
}

.ft-details h4 {
    margin: 0 0 6px 0;
    font-size: 15px;
    font-weight: 700;
    color: #333;
    line-height: 1.3;
}

.ft-design-modern .ft-details,
.ft-design-left .ft-details,
.ft-design-right .ft-details,
.ft-design-banner .ft-details {
    text-align: left;
}

.ft-date-line {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
    display: flex;
    justify-content: center;
    gap: 5px;
}

.ft-design-modern .ft-date-line,
.ft-design-left .ft-date-line,
.ft-design-right .ft-date-line,
.ft-design-banner .ft-date-line {
    justify-content: flex-start;
}

.ft-label {
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    font-size: 10px;
    min-width: 15px; /* Align labels slightly */
    text-align: right;
}

.ft-age-line {
    font-size: 12px;
    font-weight: 600;
    color: var(--ft-accent);
    margin-top: 8px;
    border-top: 1px solid #f0f0f1;
    padding-top: 6px;
}

.ft-design-modern .ft-age-line {
    display: inline-block;
    margin-top: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    border-top: none;
    background: rgba(37, 99, 235, 0.08);
    font-size: 11px;
}

/* Theme variations */
.ft-theme-blue .ft-card {
    border-color: #1d4ed8;
    box-shadow: 0 6px 12px rgba(37, 99, 235, 0.12);
}

.ft-theme-blue .ft-age-line {
    color: #1d4ed8;
}

.ft-theme-blue .ft-photo-placeholder {
    background: #dbeafe;
}

.ft-theme-soft .ft-card {
    background: #f9fafb;
    border-color: #e5e7eb;
}

.ft-theme-soft .ft-age-line {
    color: #0f766e;
}


/* Responsive Handling - Keep Horizontal but allow scroll */
@media (max-width: 768px) {
    .ft-frontend-container {
        cursor: default; /* Use native touch scroll */
    }
    
    .ft-frontend-canvas {
        justify-content: flex-start; /* Align left to allow scrolling */
        padding: 20px;
        -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    }

    /* Adjust Card Size for Mobile */
    .ft-card {
        width: 160px;
        padding: 10px 5px;
    }

    .ft-design-modern .ft-card,
    .ft-design-left .ft-card,
    .ft-design-right .ft-card,
    .ft-design-banner .ft-card {
        width: 200px;
    }

    .ft-photo, .ft-photo-placeholder {
        width: 50px;
        height: 50px;
    }

    .ft-details h4 {
        font-size: 13px;
    }

    .ft-date-line, .ft-age-line {
        font-size: 11px;
    }
}

/* Toggle Button */
.ft-toggle-btn {
    position: absolute;
    top: 100%; /* Below the card */
    left: 50%;
    transform: translateX(-50%);
    margin-top: 8px; /* Center in the 40px gap (20px center - 12px half-height) */
    width: 24px;
    height: 24px;
    background: #fff;
    border: 2px solid var(--ft-line-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    color: #666;
    line-height: 1;
    z-index: 10;
}

.ft-toggle-btn:hover {
    color: var(--ft-accent);
    border-color: var(--ft-accent);
}

.ft-toggle-btn.collapsed {
    background: #f0f0f1;
}

/* Line connecting Card to Button (Persistent) */
.ft-toggle-btn::before {
    content: '';
    position: absolute;
    top: -10px; /* Reach up to card */
    left: 50%;
    margin-left: -1px;
    border-left: var(--ft-line-width) var(--ft-line-style) var(--ft-line-color);
    height: 12px; /* Enough to touch the card */
    width: 0;
    z-index: -1;
}

/* Adjust Children Container */
.ft-children {
    display: flex;
    flex-direction: row;
    justify-content: center;
    padding-top: 40px; /* Increased gap for button */
    position: relative;
}

.ft-children.hidden {
    display: none !important;
}

/* Vertical line from children container UP to parent */
.ft-children::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: var(--ft-line-width) var(--ft-line-style) var(--ft-line-color);
    width: 0;
    height: 40px; /* Cover the full gap */
}

/* ----------------------------------------------------
   HORIZONTAL LAYOUT (Left-to-Right)
   Applied when .ft-layout-horizontal is present
---------------------------------------------------- */
.ft-layout-horizontal .ft-tree-wrapper {
    flex-direction: column; /* Root at top left, but multiple roots stack vertically */
    gap: 20px;
    align-items: flex-start;
}

.ft-layout-horizontal .ft-node {
    flex-direction: row; /* Children to the right of parent */
    align-items: center; /* Center vertically relative to children branch */
    padding-top: 0;
    padding-left: 20px; /* Space for connector from parent */
}

/* Connectors for Horizontal Layout */

/* 1. Line from Parent (Left) to Node (Right) */
.ft-layout-horizontal .ft-node::before {
    top: 50%;
    left: 0;
    width: 20px;
    height: 0;
    border-left: none;
    border-top: var(--ft-line-width) var(--ft-line-style) var(--ft-line-color);
    transform: translateY(-50%); /* Center vertically */
}

/* Remove connector for root in Horizontal */
.ft-layout-horizontal .ft-tree-wrapper > .ft-node {
    padding-left: 0;
}
.ft-layout-horizontal .ft-tree-wrapper > .ft-node::before {
    display: none;
}

/* 2. Children Container */
.ft-layout-horizontal .ft-children {
    flex-direction: column; /* Stack children vertically */
    padding-top: 0;
    padding-left: 40px; /* Space for the button and line */
    /* position: relative; already set */
    align-items: flex-start; /* Align children to left */
}

/* 3. Line from Parent Card to Children Container (Horizontal) */
.ft-layout-horizontal .ft-children::before {
    top: 50%;
    left: 0;
    width: 40px;
    height: 0;
    border-left: none;
    border-top: var(--ft-line-width) var(--ft-line-style) var(--ft-line-color);
    transform: translateY(-50%);
}

/* 4. Toggle Button Position in Horizontal */
.ft-layout-horizontal .ft-toggle-btn {
    top: 50%;
    left: 100%; /* Right side of card */
    transform: translate(-50%, -50%); /* Center on the edge/line */
    margin-top: 0;
    margin-left: 20px; /* Push out into the gap (20px is half of 40px padding-left of children) */
}

/* 5. Persistent line for toggle button (Horizontal) */
.ft-layout-horizontal .ft-toggle-btn::before {
    /* Line connecting card to button */
    top: 50%;
    right: 100%; /* Go left to the card */
    left: auto;
    width: 12px;
    height: 0;
    border-left: none;
    border-top: var(--ft-line-width) var(--ft-line-style) var(--ft-line-color);
    margin-left: 0;
    margin-top: -1px;
}

/* 6. Child Wrapper (The item in the vertical stack) */
.ft-layout-horizontal .ft-child-wrapper {
    padding: 10px 0 10px 20px; /* Padding left for connector */
    position: relative;
    display: flex;
    align-items: center;
}

/* 7. Vertical Spine Line (Connecting siblings) */
/* In horizontal tree, the spine is Vertical on the Left of the children group */

/* We need a vertical line spanning the children */
/* But structure is: .ft-children > .ft-child-wrapper > .ft-node */
/* The vertical spine should be drawn by .ft-child-wrapper elements relative to each other */

/* Upper half of connector */
.ft-layout-horizontal .ft-child-wrapper::before {
    top: 0;
    bottom: 50%;
    left: 0;
    right: auto;
    width: 0;
    height: auto; /* Span half height */
    border-top: none;
    border-left: var(--ft-line-width) var(--ft-line-style) var(--ft-line-color);
}

/* Lower half of connector */
.ft-layout-horizontal .ft-child-wrapper::after {
    top: 50%;
    bottom: 0;
    left: 0;
    right: auto;
    width: 0;
    height: auto;
    border-top: none;
    border-left: 2px solid #ccc;
}

/* Horizontal line from spine to node */
/* We can use a pseudo element on .ft-node or reuse one of the above if we adjust structure */
/* Actually, we need a horizontal connector from the spine (left:0) to the node (padding-left:20px) */
/* We can use ::after on .ft-child-wrapper for the vertical, and something else for horizontal? */
/* Wait, existing .ft-child-wrapper::before is Top Horizontal. ::after is Top Horizontal (right side). */
/* In Horizontal mode, we repurpose them. */

/* Let's be precise: */
/* Vertical Spine */
.ft-layout-horizontal .ft-child-wrapper::before {
    /* Top vertical segment */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 50%;
    width: 0;
    border-left: 2px solid #ccc;
    border-top: none;
    right: auto;
    height: auto;
}

.ft-layout-horizontal .ft-child-wrapper::after {
    /* Bottom vertical segment */
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    bottom: 0;
    width: 0;
    border-left: 2px solid #ccc;
    border-top: none;
    right: auto;
    height: auto;
}

/* Horizontal connector from spine to child node */
/* We need a 3rd pseudo-element? No, CSS only has 2. */
/* We can use the .ft-node::before (which we set to left line) */
/* In .ft-layout-horizontal .ft-node::before, we set width: 20px. That connects child to the spine (padding-left of wrapper). */
/* Actually, .ft-child-wrapper has padding-left: 20px. */
/* The .ft-node is inside. */
/* So .ft-node::before (left line) connects to the spine at left:0 of wrapper? */
/* No, .ft-node is a child of wrapper. */
/* If .ft-node has margin-left, its ::before extends left. */
/* Let's set .ft-node::before to be the horizontal connector from spine. */

.ft-layout-horizontal .ft-child-wrapper > .ft-node::before {
    content: '';
    position: absolute;
    top: 50%;
    left: -20px; /* Reach back to the spine (wrapper padding is 20px) */
    width: 20px;
    height: 0;
    border-top: 2px solid #ccc;
    border-left: none;
}

/* Hide spine parts for first/last children */
.ft-layout-horizontal .ft-child-wrapper:first-child::before {
    display: none; /* No line going up from first child center */
}
.ft-layout-horizontal .ft-child-wrapper:last-child::after {
    display: none; /* No line going down from last child center */
}
/* Exception: Single child */
.ft-layout-horizontal .ft-child-wrapper:only-child::before,
.ft-layout-horizontal .ft-child-wrapper:only-child::after {
    display: none;
}
/* But we still need the horizontal connector for single child! */
/* The horizontal connector is on .ft-node::before. It persists. */
/* BUT, if it's a single child, the parent line comes straight to it? */
/* In horizontal tree: Parent -> Line -> Children Container -> Child. */
/* If multiple children, we have a spine. */
/* If single child, Parent -> Line -> Children Container -> Child. */
/* The spine is at the left edge of Children Container. */
/* So strictly speaking, for single child, we just need the horizontal line. */

/* Responsive Mobile Override for Horizontal Layout */
/* On mobile, we likely want to revert to Vertical Stack (the mobile view) regardless of layout setting? */
/* Or user wants Horizontal scrollable on mobile too? */
/* Usually "Responsive" means stacking. */
/* Let's keep the @media (max-width: 768px) overriding everything to Vertical List. */

@media (max-width: 768px) {
    .ft-layout-horizontal .ft-tree-wrapper {
        flex-direction: column;
    }
    .ft-layout-horizontal .ft-node {
        flex-direction: column;
        align-items: stretch;
        padding-left: 0;
    }
    .ft-layout-horizontal .ft-children {
        padding-left: 0;
        margin-left: 25px;
    }
    /* ... rest of mobile styles handle the rest ... */
}

/* ----------------------------------------------------
   END HORIZONTAL LAYOUT
---------------------------------------------------- */

/* Mobile adjustments for toggle (Existing) */
@media (max-width: 768px) {
    .ft-children {
        padding-top: 15px;
    }
    .ft-children::before {
        display: none;
    }
    .ft-toggle-btn {
        margin-top: 0;
        width: 22px;
        height: 22px;
        font-size: 14px;
        /* Adjust position if needed, keeping centered for now */
    }
    .ft-toggle-btn::before {
        display: none;
    }
}
