/* Modern Family Tree Styles */

/* Tree Container */
.tree-container {
    background: white;
    border-radius: var(--border-radius-xl);
    padding: 40px;
    box-shadow: var(--shadow-lg);
    overflow: auto;
    min-height: 500px;
    position: relative;
    background-image: 
        radial-gradient(circle at 20% 80%, rgba(212, 17, 37, 0.02) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(0, 33, 125, 0.02) 0%, transparent 50%);
}

body.dark-mode .tree-container {
    background: var(--gray-100);
}

/* Tree Wrapper */
.tree-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-width: 100%;
    padding: 40px 20px;
}

/* Tree Structure */
.tree {
    display: inline-block;
    position: relative;
}

/* Tree Roots Container */
.tree-roots {
    display: flex;
    gap: 80px;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
}

/* Individual Tree Root */
.tree-root {
    position: relative;
}

/* Tree Node */
.tree-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* Members Container (Couple) */
.tree-members {
    display: flex;
    gap: 20px;
    align-items: center;
    position: relative;
    z-index: 2;
}

/* Connection Line Between Spouses */
.tree-members::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: calc(100% - 120px);
    height: 2px;
    background: linear-gradient(90deg, 
        transparent 0%, 
        var(--gray-300) 20%, 
        var(--gray-300) 80%, 
        transparent 100%);
    transform: translate(-50%, -50%);
    z-index: -1;
}

/* Enhanced Member Card in Tree */
.tree-node .member-card {
    width: 160px;
    padding: 16px;
    background: white;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: visible;
    text-align: center;
}

.tree-node .member-card::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: var(--border-radius-lg);
    background: linear-gradient(135deg, 
        var(--primary-blue) 0%, 
        var(--primary-red) 100%);
    opacity: 0;
    z-index: -1;
    transition: opacity var(--transition-base);
}

.tree-node .member-card:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: var(--shadow-xl);
}

.tree-node .member-card:hover::before {
    opacity: 0.1;
}

/* Gender-based Card Styling */
.tree-node .member-card.male {
    border: 2px solid var(--primary-blue);
}

.tree-node .member-card.female {
    border: 2px solid var(--primary-red);
}

.tree-node .member-card.unknown {
    border: 2px solid var(--gray-300);
}

/* Member Photo in Tree */
.tree-node .member-photo {
    width: 80px;
    height: 80px;
    margin: 0 auto 12px;
    border-radius: 50%;
    background: var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-size: cover;
    background-position: center;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-base);
}

.tree-node .member-photo .material-icons {
    font-size: 36px;
    color: var(--gray-400);
}

.tree-node .member-card:hover .member-photo {
    transform: scale(1.1);
}

/* Member Name in Tree */
.tree-node .member-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 4px;
    line-height: 1.3;
}

/* Member Year in Tree */
.tree-node .member-year {
    font-size: 12px;
    color: var(--gray-600);
    font-weight: 500;
}

/* Children Container */
.tree-children {
    display: flex;
    gap: 40px;
    justify-content: center;
    position: relative;
    margin-top: 80px;
}

/* Vertical Line from Parents to Children */
.tree-children::before {
    content: '';
    position: absolute;
    top: -80px;
    left: 50%;
    width: 2px;
    height: 40px;
    background: var(--gray-300);
    transform: translateX(-50%);
}

/* Horizontal Line Connecting Children */
.tree-children::after {
    content: '';
    position: absolute;
    top: -40px;
    left: 20px;
    right: 20px;
    height: 2px;
    background: var(--gray-300);
}

/* Individual Child Wrapper */
.tree-child {
    position: relative;
}

/* Vertical Line from Horizontal to Each Child */
.tree-child::before {
    content: '';
    position: absolute;
    top: -40px;
    left: 50%;
    width: 2px;
    height: 40px;
    background: var(--gray-300);
    transform: translateX(-50%);
}

/* Single Child - No Horizontal Line */
.tree-children:has(.tree-child:only-child)::after {
    display: none;
}

/* Curved Connection Lines (Modern Look) */
.curved-lines .tree-children::before,
.curved-lines .tree-children::after,
.curved-lines .tree-child::before {
    background: none;
    border: 2px solid var(--gray-300);
}

.curved-lines .tree-children::before {
    border-radius: 0 0 8px 8px;
    border-top: none;
    border-left: none;
    border-right: none;
}

.curved-lines .tree-child::before {
    border-radius: 8px 8px 0 0;
    border-bottom: none;
}

/* Tree Controls */
.tree-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 12px;
    z-index: 10;
}

.tree-control-btn {
    background: white;
    border: 2px solid var(--gray-200);
    color: var(--gray-700);
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.tree-control-btn:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.tree-control-btn.active {
    background: var(--primary-blue);
    border-color: var(--primary-blue);
    color: white;
}

/* Zoom Controls */
.tree-zoom {
    transition: transform var(--transition-base);
}

/* Generation Labels */
.generation-label {
    position: absolute;
    left: -80px;
    top: 50%;
    transform: translateY(-50%) rotate(-90deg);
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

/* Tree Statistics */
.tree-stats {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 16px 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    font-size: 14px;
}

body.dark-mode .tree-stats {
    background: rgba(39, 39, 42, 0.95);
}

.tree-stats-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

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

.tree-stats-label {
    font-weight: 600;
    color: var(--gray-700);
}

.tree-stats-value {
    color: var(--primary-blue);
    font-weight: 700;
}

/* Relationship Lines Animation */
@keyframes drawLine {
    from {
        stroke-dashoffset: 1000;
    }
    to {
        stroke-dashoffset: 0;
    }
}

.tree-svg-connections {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.tree-svg-connections path {
    fill: none;
    stroke: var(--gray-300);
    stroke-width: 2;
    stroke-dasharray: 1000;
    animation: drawLine 2s ease-out forwards;
}

/* Interactive Features */
.member-card.selected {
    box-shadow: 0 0 0 4px var(--primary-blue);
}

.member-card.highlighted {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: var(--shadow-md);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(0, 33, 125, 0.4);
    }
}

/* Compact View */
.tree-compact .tree-node .member-card {
    width: 120px;
    padding: 12px;
}

.tree-compact .tree-node .member-photo {
    width: 60px;
    height: 60px;
}

.tree-compact .tree-node .member-name {
    font-size: 12px;
}

.tree-compact .tree-children {
    gap: 20px;
    margin-top: 60px;
}

/* Mobile Tree View */
@media (max-width: 768px) {
    .tree-container {
        padding: 20px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .tree-wrapper {
        padding: 20px 10px;
    }
    
    .tree-roots {
        gap: 40px;
    }
    
    .tree-node .member-card {
        width: 120px;
        padding: 12px;
    }
    
    .tree-node .member-photo {
        width: 60px;
        height: 60px;
    }
    
    .tree-node .member-name {
        font-size: 12px;
    }
    
    .tree-node .member-year {
        font-size: 11px;
    }
    
    .tree-children {
        gap: 20px;
        margin-top: 60px;
    }
    
    .tree-controls {
        position: fixed;
        bottom: 80px;
        right: 20px;
        top: auto;
        flex-direction: column;
    }
    
    .tree-stats {
        position: relative;
        top: auto;
        left: auto;
        margin-bottom: 20px;
    }
}

/* Print Styles */
@media print {
    .tree-container {
        box-shadow: none;
        border: 1px solid #ddd;
        background: white;
    }
    
    .tree-controls,
    .tree-stats {
        display: none;
    }
    
    .tree-node .member-card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    .tree-node .member-card:hover {
        transform: none;
    }
}

/* Accessibility */
.tree-node .member-card:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

.tree-node .member-card[aria-expanded="true"] {
    box-shadow: 0 0 0 4px rgba(0, 33, 125, 0.2);
}

/* Loading State for Tree */
.tree-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.tree-loading-spinner {
    width: 60px;
    height: 60px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Tree Legend */
.tree-legend {
    display: flex;
    gap: 24px;
    justify-content: center;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--gray-200);
}

.tree-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--gray-600);
}

.tree-legend-color {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid;
}

.tree-legend-color.male {
    border-color: var(--primary-blue);
}

.tree-legend-color.female {
    border-color: var(--primary-red);
}

.tree-legend-color.unknown {
    border-color: var(--gray-300);
}