/* assets/css/family-tree.css */
:root {
    --ft-primary: #1f4d3a;
    --ft-primary-light: #2c6e53;
    --ft-bg: #fdfcf8; /* Light beige / cream */
    --ft-card-bg: #ffffff;
    --ft-text: #2c3e50;
    --ft-text-light: #7f8c8d;
    --ft-border: #e2e8f0;
    --ft-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    --ft-shadow-hover: 0 10px 30px rgba(31, 77, 58, 0.15);
    --ft-line: #cbd5e1;
    --ft-line-active: #1f4d3a;
    --ft-accent: #d4af37; /* Gold accent for special nodes/status */
}

body {
    overflow: hidden; /* Prevent scrolling on the page when using the tree */
}

.family-tree-wrapper {
    display: flex;
    height: calc(100vh - 80px); /* Adjust based on your header height */
    width: 100%;
    background-color: var(--ft-bg);
    position: relative;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Toolbar */
.ft-toolbar {
    width: 300px;
    background: var(--ft-card-bg);
    border-right: 1px solid var(--ft-border);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 2px 0 10px rgba(0,0,0,0.02);
    z-index: 10;
}

.ft-toolbar h2 {
    color: var(--ft-primary);
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.ft-search {
    position: relative;
}

.ft-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ft-text-light);
}

.ft-search input {
    width: 100%;
    padding: 12px 12px 12px 36px;
    border: 1px solid var(--ft-border);
    border-radius: 8px;
    background: var(--ft-bg);
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.ft-search input:focus {
    outline: none;
    border-color: var(--ft-primary);
    box-shadow: 0 0 0 3px rgba(31, 77, 58, 0.1);
}

.ft-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ft-btn {
    padding: 6px 12px;
    border: 1px solid var(--ft-border);
    background: var(--ft-card-bg);
    color: var(--ft-text);
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ft-btn.active, .ft-btn:hover {
    background: var(--ft-primary);
    color: white;
    border-color: var(--ft-primary);
}

.ft-actions {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ft-action-btn {
    padding: 12px;
    background: var(--ft-card-bg);
    border: 1px solid var(--ft-border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--ft-primary);
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.ft-action-btn:hover {
    background: var(--ft-bg);
    border-color: var(--ft-primary);
}

#btn-add-node {
    background: var(--ft-primary);
    color: white;
    border: none;
}
#btn-add-node:hover {
    background: var(--ft-primary-light);
}

.zoom-controls {
    display: flex;
    gap: 10px;
}
.zoom-controls button {
    flex: 1;
}

/* Main Tree Area */
.tree-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    cursor: grab;
    background-image: radial-gradient(var(--ft-border) 1px, transparent 1px);
    background-size: 20px 20px;
}

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

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

.tree-svg path {
    fill: none;
    stroke: var(--ft-line);
    stroke-width: 2px;
    transition: stroke 0.3s ease, stroke-width 0.3s ease;
}

.tree-svg path.active {
    stroke: var(--ft-primary);
    stroke-width: 3px;
}

.tree-canvas {
    position: absolute;
    transform-origin: 0 0;
    z-index: 2;
    /* We need to define a large area to allow panning freely, but panzoom handles bounds */
}

/* Node Styling */
.ft-node {
    position: absolute;
    width: 220px;
    background: var(--ft-card-bg);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--ft-shadow);
    border: 1px solid var(--ft-border);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
    transform: translate(-50%, -50%); /* Center based on left/top pos */
}

.ft-node:hover, .ft-node.active {
    box-shadow: var(--ft-shadow-hover);
    border-color: var(--ft-primary);
    transform: translate(-50%, -50%) scale(1.02);
}

.ft-node-img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--ft-bg);
    border: 2px solid var(--ft-border);
}

.ft-node-info {
    flex: 1;
    overflow: hidden;
}

.ft-node-name {
    font-weight: 600;
    color: var(--ft-text);
    margin: 0 0 4px 0;
    font-size: 0.95rem;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.ft-node-dates {
    font-size: 0.75rem;
    color: var(--ft-text-light);
    margin: 0;
}

/* Detail Panel */
.ft-detail-panel {
    position: absolute;
    right: -400px;
    top: 0;
    width: 380px;
    height: 100%;
    background: var(--ft-card-bg);
    box-shadow: -4px 0 20px rgba(0,0,0,0.05);
    transition: right 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 20;
    display: flex;
    flex-direction: column;
}

.ft-detail-panel.open {
    right: 0;
}

.ft-panel-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--ft-border);
    display: flex;
    justify-content: flex-end;
}

.ft-close-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--ft-text-light);
    cursor: pointer;
    transition: color 0.2s ease;
}

.ft-close-btn:hover {
    color: var(--ft-primary);
}

.ft-panel-content {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.dp-hero {
    text-align: center;
    margin-bottom: 24px;
}

.dp-img {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--ft-bg);
    box-shadow: var(--ft-shadow);
    margin-bottom: 16px;
}

.dp-name {
    font-size: 1.4rem;
    color: var(--ft-primary);
    margin: 0 0 8px 0;
    font-weight: 600;
}

.dp-dates {
    color: var(--ft-text-light);
    font-size: 0.9rem;
}

.dp-section {
    margin-bottom: 24px;
}

.dp-section h4 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--ft-text-light);
    margin: 0 0 12px 0;
    border-bottom: 1px solid var(--ft-border);
    padding-bottom: 8px;
}

.dp-bio {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--ft-text);
}

.dp-relationships {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dp-rel-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: 8px;
    background: var(--ft-bg);
    cursor: pointer;
    transition: background 0.2s ease;
}

.dp-rel-item:hover {
    background: var(--ft-border);
}

.dp-rel-item img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.dp-rel-info {
    flex: 1;
}

.dp-rel-name {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--ft-text);
}

.dp-rel-type {
    font-size: 0.75rem;
    color: var(--ft-text-light);
}

/* Modal */
.ft-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.ft-modal.open {
    opacity: 1;
    pointer-events: auto;
}

.ft-modal-content {
    background: var(--ft-card-bg);
    width: 100%;
    max-width: 500px;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.ft-modal.open .ft-modal-content {
    transform: translateY(0);
}

.ft-modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--ft-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ft-modal-header h3 {
    margin: 0;
    color: var(--ft-primary);
}

.ft-modal-body {
    padding: 24px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--ft-text-light);
    font-weight: 500;
}

.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--ft-border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--ft-primary);
}

.form-row {
    display: flex;
    gap: 16px;
}
.form-row .form-group {
    flex: 1;
}

.ft-submit-btn {
    width: 100%;
    padding: 14px;
    background: var(--ft-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

.ft-submit-btn:hover {
    background: var(--ft-primary-light);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .family-tree-wrapper {
        flex-direction: column;
    }
    .ft-toolbar {
        width: 100%;
        height: auto;
        padding: 16px;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
    }
    .ft-toolbar h2 {
        display: none;
    }
    .ft-search {
        flex: 1;
    }
    .ft-actions {
        flex-direction: row;
        margin-top: 0;
    }
    .ft-detail-panel {
        width: 100%;
        right: -100%;
    }
}
