/* Family Tree V2 - Premium Interactive Tree Styling */

:root {
    --tree-bg: #f4f7fa;
    --tree-primary: #1e3a8a;
    --tree-secondary: #d97706;
    --tree-accent: #2563eb;
    --node-bg: #ffffff;
    --node-border: #cbd5e1;
    --node-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --line-color: #94a3b8;
    --alive-color: #10b981;
    --married-color: #3b82f6;
    --deceased-color: #6b7280;
    --single-color: #f59e0b;
}

.tree-v2-container {
    direction: rtl;
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    position: relative;
    background-color: var(--tree-bg);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    margin-bottom: 40px;
    border: 1px solid #e2e8f0;
}

/* Header & Controls Toolbar */
.tree-header-toolbar {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    color: #ffffff;
    padding: 18px 24px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.tree-title-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tree-title-section h3 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
    color: #f8fafc;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tree-title-section .subtitle {
    font-size: 0.85rem;
    color: #94a3b8;
    margin-top: 2px;
}

/* Search Box Component */
.tree-search-wrapper {
    position: relative;
    flex: 1;
    max-width: 380px;
    min-width: 260px;
}

.tree-search-input {
    width: 100%;
    padding: 10px 42px 10px 16px;
    border-radius: 25px;
    border: 1px solid #334155;
    background-color: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.3s ease;
}

.tree-search-input:focus {
    outline: none;
    background-color: rgba(255, 255, 255, 0.18);
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.25);
}

.tree-search-icon {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    pointer-events: none;
}

.tree-search-results {
    position: absolute;
    top: 110%;
    right: 0;
    left: 0;
    background: #ffffff;
    color: #1e293b;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    z-index: 100;
    max-height: 320px;
    overflow-y: auto;
    display: none;
    border: 1px solid #e2e8f0;
}

.tree-search-results.active {
    display: block;
}

.search-result-item {
    padding: 10px 16px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.search-result-item:hover {
    background-color: #eff6ff;
    color: #2563eb;
}

.search-result-item .item-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.search-result-item .item-status {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Quick Branch Navigator Bar - Multi-line wrap without scrollbar */
.tree-branches-bar {
    background-color: #ffffff;
    padding: 14px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    flex-wrap: wrap; /* Wraps onto new lines automatically */
    align-items: center;
    gap: 8px 10px; /* Space between pills vertically and horizontally */
    overflow-x: visible; /* No scrollbar */
}

.branch-label {
    font-weight: 700;
    color: #1e293b;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
    padding-left: 12px;
    margin-left: 5px;
    border-left: 2px solid #cbd5e1;
}

.branch-pill {
    background-color: #f1f5f9;
    color: #334155;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
    border: 1px solid #cbd5e1;
    cursor: pointer;
}

.branch-pill:hover, .branch-pill.active {
    background-color: var(--tree-primary);
    color: #ffffff;
    border-color: var(--tree-primary);
    box-shadow: 0 2px 8px rgba(30, 58, 138, 0.25);
}

/* Main Viewport & SVG Container */
.tree-viewport {
    width: 100%;
    height: 750px;
    position: relative;
    overflow: hidden;
    cursor: grab;
    background-color: #f8fafc;
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 24px 24px;
}

.tree-viewport:active {
    cursor: grabbing;
}

/* Zoom & Action Floating Controls */
.tree-floating-controls {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #1e293b;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    transition: all 0.2s ease;
}

.control-btn:hover {
    background: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
    transform: scale(1.08);
}

/* Tree Nodes SVG Styles */
.node-card {
    cursor: pointer;
    transition: all 0.3s ease;
}

.node-card rect {
    fill: #ffffff;
    stroke: #cbd5e1;
    stroke-width: 2px;
    rx: 12px;
    ry: 12px;
    filter: drop-shadow(0px 4px 8px rgba(0, 0, 0, 0.06));
    transition: all 0.25s ease;
}

.node-card:hover rect {
    stroke: var(--tree-accent);
    stroke-width: 3px;
    filter: drop-shadow(0px 8px 16px rgba(37, 99, 235, 0.2));
}

.node-card.focused rect {
    stroke: #f59e0b;
    stroke-width: 4px;
    fill: #fffbeb;
    animation: pulse-glow 1.5s infinite alternate;
}

@keyframes pulse-glow {
    0% {
        filter: drop-shadow(0px 0px 8px rgba(245, 158, 11, 0.5));
    }
    100% {
        filter: drop-shadow(0px 0px 20px rgba(245, 158, 11, 0.9));
    }
}

.node-card text.node-name {
    font-size: 14px;
    font-weight: 700;
    fill: #1e293b;
    font-family: 'Cairo', sans-serif;
    text-anchor: middle;
}

.node-card text.node-info {
    font-size: 11px;
    fill: #64748b;
    text-anchor: middle;
}

/* Dedicated Info Button Icon styling */
.node-info-btn {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.node-info-btn:hover circle {
    fill: #2563eb;
    stroke: #1d4ed8;
}

.node-info-btn:hover text {
    fill: #ffffff;
}

/* Badge on Nodes */
.badge-count {
    fill: #2563eb;
    rx: 10px;
    ry: 10px;
}

.badge-text {
    fill: #ffffff;
    font-size: 10px;
    font-weight: bold;
    text-anchor: middle;
}

/* Links / Connections */
.tree-link {
    fill: none;
    stroke: #94a3b8;
    stroke-width: 2.5px;
    stroke-linecap: round;
    transition: stroke 0.3s ease;
}

.tree-link.active-path {
    stroke: #f59e0b;
    stroke-width: 3.5px;
}

/* Person Details Drawer / Modal */
.person-modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.person-modal.active {
    display: flex;
}

.person-modal-content {
    background: #ffffff;
    border-radius: 20px;
    max-width: 550px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
    direction: rtl;
    position: relative;
    animation: modal-slide 0.3s ease-out;
}

@keyframes modal-slide {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e293b 100%);
    color: #ffffff;
    padding: 24px;
    border-radius: 20px 20px 0 0;
    position: relative;
}

.modal-close-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.modal-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.modal-body {
    padding: 24px;
}

.lineage-badge {
    background-color: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1d4ed8;
    padding: 12px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 20px;
    line-height: 1.6;
}

.detail-section-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.family-tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.family-tag {
    background-color: #f1f5f9;
    color: #334155;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
}

.family-tag.clickable {
    cursor: pointer;
    background-color: #e0e7ff;
    color: #3730a3;
    transition: all 0.2s ease;
}

.family-tag.clickable:hover {
    background-color: #4f46e5;
    color: #ffffff;
}

/* Status Indicator Colors */
.status-pill {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-m, .status-c {
    background-color: #dbeafe;
    color: #1e40af;
}

.status-s {
    background-color: #fef3c7;
    color: #92400e;
}

.status-dc, .status-d {
    background-color: #f3f4f6;
    color: #4b5563;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .tree-header-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .tree-search-wrapper {
        max-width: 100%;
    }
    .tree-viewport {
        height: 550px;
    }
}
