/* --- General Setup --- */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f7f6;
    color: #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    overflow: hidden; 
}

/* --- Header --- */
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    text-align: center;
    border-bottom: 2px solid #ddd;
    padding: 10px 0;
    background: #fff;
    z-index: 1000; 
    transition: transform 0.3s ease-in-out; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
header.header-hidden { transform: translateY(-100%); }

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding: 0 10px; /* Add side padding so buttons don't touch edges */
}
.separator { color: #ccc; font-size: 1.2rem; }

/* Buttons */
.view-toggle-btn, .action-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    color: white;
    white-space: nowrap; /* Prevent text splitting weirdly */
}
.view-toggle-btn { background-color: #6c757d; }
.view-toggle-btn:hover { background-color: #5a6268; }
.action-btn { background-color: #17a2b8; }
.action-btn:hover { background-color: #138496; }

/* New Reset Button */
.btn-reset { background-color: #fd7e14; }
.btn-reset:hover { background-color: #e67e22; }

/* --- Containers --- */
#tree-container {
    display: block;
    position: relative;
    width: 100%;
    height: 100vh; 
    padding-top: 140px; /* Default desktop padding */
    overflow: auto; 
    background-color: #f4f7f6;
    box-sizing: border-box;
}

#card-container {
    display: inline-block; 
    position: relative; 
    z-index: 2; 
    min-width: 100%;
    padding: 40px; 
    transform-origin: top center;
}

#line-canvas {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0; 
    pointer-events: none;
    fill: none; 
}

/* --- LINE STYLES (ALL BLACK) --- */
path {
    fill: none;
    stroke: #000;
    stroke-width: 1px;
}
path.line-parent, path.line-married, path.line-divorced, path.line-widowed {
    stroke: #000;
    stroke-width: 1px;
    stroke-dasharray: none;
}
path.line-divorced, path.line-widowed {
    stroke-dasharray: 4 4; 
}

/* --- STATUS SYMBOLS --- */
circle.status-bg {
    fill: #fff;
    stroke: #000;
    stroke-width: 1px;
}
text.status-marker {
    font-size: 10px;
    font-family: sans-serif;
    font-weight: bold;
    fill: #000;
    text-anchor: middle;
    dominant-baseline: middle;
}

/* --- Legend --- */
#legend {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: white;
    border: 1px solid #000;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 2000;
    font-size: 0.85rem;
}
#legend h4 { margin: 0 0 10px 0; font-size: 0.9rem; }
.legend-item { margin-bottom: 5px; display: flex; align-items: center; }
.legend-symbol {
    display: inline-block; width: 14px; height: 14px; border: 1px solid #000; border-radius: 50%;
    text-align: center; line-height: 12px; font-size: 9px; font-weight: bold; margin-right: 8px; background: #fff; color: #000;
}

/* --- Layouts --- */
.generation { display: flex; justify-content: center; align-items: center; position: relative; padding: 30px 0; margin: 10px 0; }
.tree-branch { display: flex; flex-direction: column; align-items: center; margin: 0 30px; }
.tree-family-row { display: flex; justify-content: center; align-items: center; margin-bottom: 60px; position: relative; gap: 40px; }
.tree-children-row { display: flex; justify-content: center; align-items: flex-start; gap: 20px; }

/* --- Person Node --- */
.person-node {
    border: 1px solid #ccc;
    border-radius: 8px;
    background-color: #ffffff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
    padding: 25px 15px 10px 15px; 
    margin: 0 10px; 
    width: fit-content;
    min-width: 140px;
    max-width: none;
    white-space: nowrap;
    text-align: center;
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    z-index: 3; 
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.person-node:hover { transform: translateY(-3px); box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1); z-index: 10; }
.person-node.current-focus { border: 2px solid #007bff; background-color: #f0f8ff; box-shadow: 0 0 15px rgba(0, 123, 255, 0.3); }

.node-name { font-weight: 700; font-size: 1.1rem; color: #333; margin-bottom: 4px; padding: 0 5px; }
.node-dates { font-size: 0.85rem; color: #666; font-style: italic; margin-bottom: 8px; }
.node-actions { margin-top: auto; }

.details-btn { font-size: 0.75rem; padding: 3px 8px; background-color: #f0f0f0; border: 1px solid #ccc; border-radius: 4px; cursor: pointer; }
.details-btn:hover { background-color: #e0e0e0; }

.add-btn { position: absolute; width: 24px; height: 24px; color: white; border: none; border-radius: 50%; font-size: 16px; font-weight: bold; line-height: 24px; text-align: center; cursor: pointer; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); transition: all 0.2s; z-index: 10; }
.add-btn:hover { transform: scale(1.1); }
.add-btn.add-parent { background-color: #007bff; left: 50%; transform: translateX(-50%); top: -12px; }
.add-btn.add-child { background-color: #28a745; left: 50%; transform: translateX(-50%); bottom: -12px; }
.add-btn.add-spouse { background-color: #dc3545; right: -12px; top: 50%; transform: translateY(-50%); }

.delete-btn { position: absolute; top: 5px; left: 5px; background: none; border: none; cursor: pointer; color: #aaa; opacity: 0.5; transition: all 0.2s; padding: 3px; line-height: 1; }
.delete-btn:hover { color: #dc3545; opacity: 1; transform: scale(1.2); }
.delete-btn svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; fill: none; }

.inactive-spouse-btn { background-color: #f8f9fa; border: 1px dashed #ccc; color: #007bff; padding: 8px 12px; margin: 0 10px; border-radius: 8px; cursor: pointer; font-size: 0.85rem; font-weight: 500; transition: all 0.2s; z-index: 3; position: relative; }
.inactive-spouse-btn:hover { background-color: #e2e6ea; border-style: solid; }
.inactive-spouse-btn.single { color: #6c757d; }

.children-checkbox-list { max-height: 150px; overflow-y: auto; border: 1px solid #ccc; border-radius: 4px; padding: 10px; }
.children-checkbox-list label { display: block; margin-bottom: 5px; font-weight: normal; }
.children-checkbox-list label input { margin-right: 8px; }

/* --- Modal Styles --- */
.modal-overlay { display: none; position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); justify-content: center; align-items: center; }
.modal { background-color: #fff; border-radius: 8px; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); width: 90%; max-width: 600px; animation: slide-down 0.3s ease-out; position: relative; z-index: 2001; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; border-bottom: 1px solid #eee; }
.modal-close-btn { background: none; border: none; font-size: 2rem; line-height: 1; cursor: pointer; color: #aaa; }
.modal-close-btn:hover { color: #333; }
.modal-content { padding: 20px; }
.form-row { display: flex; gap: 15px; }
.form-group { margin-bottom: 15px; }
.form-group.half { flex: 1; }
.form-group label, .form-group .input-label { display: block; margin-bottom: 5px; font-weight: 500; font-size: 0.9rem; }
.form-control { width: calc(100% - 20px); padding: 8px 10px; font-size: 0.95rem; border: 1px solid #ccc; border-radius: 4px; }
select.form-control { width: 100%; height: 38px; }
textarea.form-control { resize: vertical; }
.btn-save { background-color: #007bff; color: white; padding: 10px 15px; border: none; border-radius: 4px; cursor: pointer; font-size: 1rem; width: 100%; }
.btn-save:hover { background-color: #0056b3; }
.btn-save.btn-danger { background-color: #dc3545; }
.btn-save.btn-danger:hover { background-color: #c82333; }
.rel-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; border-bottom: 1px solid #eee; }
.rel-row:last-child { border-bottom: none; }
.rel-row select { padding: 2px; font-size: 0.9rem; }
@keyframes slide-down { from { transform: translateY(-30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }


/* ==========================================
   MOBILE RESPONSIVENESS
   ========================================== */
@media (max-width: 768px) {
    header {
        /* Allow header to grow if buttons wrap */
        height: auto;
        padding: 5px 0;
    }
    
    .controls {
        flex-wrap: wrap; /* Stack buttons */
        justify-content: center;
        gap: 5px;
    }

    .view-toggle-btn, .action-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
        /* Make buttons easier to tap */
        flex: 1 1 auto; 
    }
    
    /* Hide separators on mobile to save space */
    .separator {
        display: none;
    }
    
    /* Push the tree down further because the header is taller */
    #tree-container {
        padding-top: 160px; 
    }

    /* Adjust legend position so it doesn't block content */
    #legend {
        bottom: 10px;
        right: 10px;
        padding: 10px;
        font-size: 0.75rem;
    }
}
