/* Family Tree Visualization Styles */

.tree-page {
    background-color: #f8f9fa;
    min-height: calc(100vh - 200px);
    padding: 2rem 0;
}

/* Tree Container Layout */
.tree-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Tree Search and Header */
.tree-search {
    margin: 1rem 0;
}

.tree-search input {
    padding: 10px 15px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 25px;
    width: 300px;
    max-width: 100%;
}

/* Table-based Tree Layout */
.family-tree-table {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 2rem;
    overflow-x: auto;
}

.tree-table {
    border-collapse: separate;
    border-spacing: 5px;
    margin: 0 auto;
    font-size: 0.85rem;
}

/* Person Cells */
.person-cell {
    border: 2px solid #ddd;
    border-radius: 6px;
    padding: 0.8rem;
    text-align: center;
    vertical-align: middle;
    background: white;
    width: 120px;
    height: 140px;
    transition: all 0.3s ease;
    position: relative;
}

.person-cell:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.15);
    z-index: 10;
}

.person-cell.male {
    border-color: #2196f3;
    background: #e3f2fd;
}

.person-cell.female {
    border-color: #e91e63;
    background: #fce4ec;
}

.person-cell.focus {
    border-color: var(--accent-color);
    border-width: 3px;
    background: #fff3e0;
    box-shadow: 0 5px 20px rgba(255, 152, 0, 0.4);
    transform: scale(1.05);
}

.person-cell.spouse {
    border-style: dashed;
    opacity: 0.95;
}

.empty-cell {
    width: 120px;
    height: 140px;
    border: none;
    background: transparent;
}

/* Connection Lines */
.connection-cell {
    width: 20px;
    height: 20px;
    background: transparent;
    border: none;
    position: relative;
}

.connection-cell.vertical-line {
    background: linear-gradient(to bottom, transparent 45%, #999 45%, #999 55%, transparent 55%);
    height: 30px;
}

.connection-cell.horizontal-line {
    background: linear-gradient(to right, transparent 45%, #999 45%, #999 55%, transparent 55%);
    width: 30px;
}

.connection-cell.corner-down-right::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 50%;
    height: 50%;
    border-right: 2px solid #999;
    border-bottom: 2px solid #999;
}

.connection-cell.corner-down-left::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    width: 50%;
    height: 50%;
    border-left: 2px solid #999;
    border-bottom: 2px solid #999;
}

.connection-cell.t-junction::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 50%;
    border-left: 2px solid #999;
    border-right: 2px solid #999;
    border-bottom: 2px solid #999;
}

/* Person Photo in Tree Cell */
.person-cell .person-photo {
    margin-bottom: 0.3rem;
}

.person-cell .person-photo img {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid white;
}

.person-cell .photo-placeholder {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-color), #e67e22);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    margin: 0 auto;
    border: 2px solid white;
}

/* Person Name and Details in Tree Cell */
.person-cell .person-name {
    font-weight: bold;
    margin-bottom: 0.2rem;
    font-size: 0.75rem;
    line-height: 1.1;
}

.person-cell .person-name a {
    color: var(--primary-color);
    text-decoration: none;
}

.person-cell .person-name a:hover {
    color: var(--accent-color);
}

.person-cell .person-year {
    font-size: 0.65rem;
    color: #666;
    margin-bottom: 0.1rem;
}

.person-cell .person-actions {
    margin-top: 0.3rem;
}

.btn-center {
    padding: 2px 6px;
    font-size: 0.6rem;
    border-radius: 3px;
    text-decoration: none;
    font-weight: 600;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    background: white;
    transition: all 0.3s ease;
}

.btn-center:hover {
    background: var(--primary-color);
    color: white;
}

/* Tree Legend */
.tree-legend {
    margin-bottom: 1rem;
    text-align: center;
    font-size: 0.9rem;
    color: #666;
}

.legend-item {
    display: inline-block;
    margin: 0 1rem;
}

.legend-color {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    margin-right: 0.3rem;
    vertical-align: middle;
}

.legend-male { 
    background: #e3f2fd; 
    border: 1px solid #2196f3; 
}

.legend-female { 
    background: #fce4ec; 
    border: 1px solid #e91e63; 
}

.legend-focus { 
    background: #fff3e0; 
    border: 2px solid var(--accent-color); 
}

/* Navigation Links */
.navigation-links {
    text-align: center;
    margin-top: 2rem;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.navigation-links a {
    display: inline-block;
    margin: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 4px;
    transition: background 0.3s;
}

.navigation-links a:hover {
    background: #1565c0;
}

.tree-header {
    background: white;
    padding: 2rem 0;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.tree-header h1 {
    color: var(--primary-color);
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.tree-header p {
    color: #666;
    font-size: 1.1rem;
}

.tree-controls {
    background: white;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.controls-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.search-person {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.search-person input {
    width: 100%;
    padding: 10px 15px;
    border: 2px solid var(--border-color);
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.search-person input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 5px 5px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.search-results.show {
    display: block;
}

.search-result-item {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s ease;
}

.search-result-item:hover {
    background-color: #f8f9fa;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-name {
    font-weight: 600;
    color: var(--primary-color);
}

.search-result-details {
    font-size: 0.9rem;
    color: #666;
    margin-top: 2px;
}

.tree-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tree-actions .btn {
    padding: 8px 12px;
    font-size: 0.9rem;
    white-space: nowrap;
}

/* Tree Container */
.tree-container {
    position: relative;
    width: 100%;
    height: 80vh;
    min-height: 600px;
    background: white;
    border: 1px solid var(--border-color);
    overflow: hidden;
    cursor: grab;
    touch-action: pan-x pan-y;
}

.tree-container:active {
    cursor: grabbing;
}

/* Mobile Tree Controls */
.mobile-tree-controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: none;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

.mobile-control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
}

.mobile-control-btn:hover,
.mobile-control-btn:focus {
    background: var(--accent-color);
    transform: scale(1.1);
    outline: none;
}

.mobile-control-btn:active {
    transform: scale(0.95);
}

/* Touch-friendly improvements */
.tree-node {
    cursor: pointer;
    transition: all 0.3s ease;
    touch-action: manipulation;
}

/* Larger touch targets for mobile */
@media (max-width: 768px) {
    .mobile-tree-controls {
        display: flex;
    }
    
    .tree-node {
        transform-origin: center;
    }
    
    .node-circle {
        stroke-width: 2px;
        r: 25;
    }
    
    .node-circle:hover,
    .node-circle:focus {
        stroke-width: 3px;
        r: 28;
    }
}

#familyTree {
    width: 100%;
    height: 100%;
}

/* Tree Nodes */
.tree-node {
    cursor: pointer;
    transition: all 0.3s ease;
}

.tree-node:hover {
    transform: scale(1.1);
}

.tree-node.focus {
    stroke: var(--accent-color);
    stroke-width: 4px;
}

.node-circle {
    stroke: #fff;
    stroke-width: 3px;
    transition: all 0.3s ease;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.node-circle.male {
    fill: #2980b9;
}

.node-circle.female {
    fill: #c0392b;
}

.node-circle.unknown {
    fill: #7f8c8d;
}

.node-circle:hover {
    stroke-width: 4px;
    stroke: var(--primary-color);
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

.node-text {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    font-weight: 700;
    text-anchor: middle;
    pointer-events: none;
    fill: #fff;
    stroke: rgba(0,0,0,0.5);
    stroke-width: 0.5px;
    paint-order: stroke fill;
}

.node-dates {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 11px;
    font-weight: 600;
    text-anchor: middle;
    pointer-events: none;
    fill: #fff;
    stroke: rgba(0,0,0,0.7);
    stroke-width: 0.5px;
    paint-order: stroke fill;
}

/* Tree Links */
.tree-link {
    fill: none;
    stroke-width: 2px;
    transition: all 0.3s ease;
}

.tree-link.parent-child {
    stroke: var(--primary-color);
}

.tree-link.marriage {
    stroke: var(--accent-color);
    stroke-dasharray: 5,5;
}

.tree-link:hover {
    stroke-width: 3px;
    stroke-opacity: 0.8;
}

/* Person Tooltip */
.person-tooltip {
    position: absolute;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    padding: 1rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1000;
    max-width: 300px;
}

.person-tooltip.show {
    opacity: 1;
}

.tooltip-content {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.tooltip-photo {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    background-color: var(--border-color);
    flex-shrink: 0;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.tooltip-photo.placeholder {
    background: linear-gradient(135deg, var(--accent-color), #e67e22);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.2rem;
}

.tooltip-info {
    flex: 1;
}

.tooltip-name {
    margin: 0 0 0.5rem 0;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.tooltip-dates, .tooltip-place {
    margin: 0 0 0.25rem 0;
    color: #666;
    font-size: 0.9rem;
}

/* Tree Legend */
.tree-legend {
    background: white;
    padding: 1.5rem 0;
    border-top: 1px solid var(--border-color);
}

.legend-items {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: #666;
}

.legend-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid white;
}

.legend-icon.male {
    background-color: #3498db;
}

.legend-icon.female {
    background-color: #e74c3c;
}

.legend-icon.unknown {
    background-color: #95a5a6;
}

.legend-line {
    width: 30px;
    height: 3px;
    border-radius: 2px;
}

.legend-line.parent-child {
    background-color: var(--primary-color);
}

.legend-line.marriage {
    background: repeating-linear-gradient(
        90deg,
        var(--accent-color),
        var(--accent-color) 5px,
        transparent 5px,
        transparent 10px
    );
}

.tree-info {
    text-align: center;
    color: #888;
    font-size: 0.9rem;
}

/* Loading State */
.tree-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 1.1rem;
    color: #666;
}

.tree-loading::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error State */
.tree-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 2rem;
}

.tree-error h3 {
    color: var(--accent-color);
    margin-bottom: 1rem;
}

.tree-error p {
    color: #666;
    margin-bottom: 2rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .tree-page {
        padding: 1rem 0;
    }
    
    .tree-container {
        padding: 0 0.5rem;
    }
    
    .tree-table {
        font-size: 0.7rem;
    }
    
    .person-cell {
        width: 100px;
        height: 120px;
        padding: 0.5rem;
    }
    
    .person-cell .person-photo img,
    .person-cell .photo-placeholder {
        width: 30px;
        height: 30px;
    }
    
    .person-cell .photo-placeholder {
        font-size: 0.7rem;
    }
    
    .tree-search input {
        width: 250px;
    }
    
    .family-tree-table {
        padding: 1rem;
    }
    
    .controls-panel {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .search-person {
        max-width: none;
    }
    
    .tree-actions {
        justify-content: center;
    }
    
    .tree-container {
        height: 70vh;
        min-height: 500px;
    }
    
    .legend-items {
        gap: 1rem;
    }
    
    .tooltip-content {
        flex-direction: column;
        text-align: center;
    }
    
    .person-tooltip {
        max-width: 250px;
    }
    
    .node-text {
        font-size: 12px;
        font-weight: 700;
    }
    
    .node-dates {
        font-size: 10px;
        font-weight: 600;
    }
}

@media (max-width: 480px) {
    .tree-header h1 {
        font-size: 2rem;
    }
    
    .tree-container {
        height: 60vh;
        min-height: 400px;
    }
    
    .legend-items {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }
    
    .tree-actions .btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
}