/* Minimalist B&W Design */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-color: #ffffff;
    --text-primary: #000000;
    --text-secondary: #555555;
    --text-input: #111111;
    --border-color: #e5e5e5;
    --border-dark: #000000;
    --accent: #000000;

    --card-bg: #ffffff;
    --hover-bg: #f5f5f5;
    --selected-bg: #000000;
    --selected-text: #ffffff;

    /* Font */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Sizes */
    --header-height: 60px;
    --sidebar-width: 320px;
    --radius: 6px;
}

body {
    font-family: var(--font-family);
    background: #fafafa;
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

button {
    font-family: inherit;
}

/* ===== HEADER ===== */
#family-roots-wrapper .fr-header {
    background: #ffffff !important;
    border-bottom: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    padding: 0 24px !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    height: var(--header-height) !important;
    position: relative !important;
    z-index: 100 !important;
    width: 100% !important;
    box-sizing: border-box !important;
    flex-wrap: nowrap !important;
}

#family-roots-wrapper .fr-header .logo {
    flex: 0 0 auto;
}

#family-roots-wrapper .fr-header .header-actions {
    flex: 0 0 auto;
    margin-left: auto;
    display: flex !important;
    gap: 12px !important;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.logo-icon {
    font-size: 1.4rem;
}

/* ===== VIEW SWITCHER ===== */
.view-switcher {
    display: flex;
    background: #f5f5f5;
    border-radius: var(--radius);
    padding: 4px;
    gap: 4px;
    border: 1px solid var(--border-color);
}

.view-btn {
    background: transparent;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.view-btn:hover {
    color: var(--text-primary);
}

.view-btn.active {
    background: white;
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    font-weight: 600;
}

.view-btn i {
    font-size: 1.1rem;
}

@media (max-width: 768px) {
    .view-btn span {
        display: none;
        /* Hide text on mobile for the switcher */
    }
}

.header-actions {
    display: flex;
    gap: 12px;
}

/* ===== INDENTED LIST VIEW ===== */
.indented-list-container {
    padding: 24px;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    background: #fafafa;
    display: flex;
    flex-direction: column;
}

.list-rows-container {
    flex: 1;
    min-height: 100vh;
}

.list-toolbar {
    display: flex;
    justify-content: flex-end;
    padding: 12px 24px;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
    background: #f8fafc;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .list-toolbar {
        justify-content: center;
        padding: 8px 12px;
    }
}

.list-node-group {
    position: relative;
}

.list-children {
    position: relative;
}

/* List Nodes */
.list-node {
    position: relative;
    padding-left: calc(var(--depth) * 40px);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 2. Enhanced Tree Tracks (L-Shapes) */
.tree-line-vertical {
    position: absolute;
    left: calc((var(--depth) - 1) * 40px + 16px);
    top: -12px;
    /* Connect to previous sibling's vertical segment */
    bottom: 0;
    width: 2px;
    background: #ccc;
    z-index: 1;
}

/* Ensure the line terminates at the horizontal connector for the last child */
.list-node-group:last-child>.list-node .tree-line-vertical {
    bottom: 50%;
}

.tree-line-horizontal {
    position: absolute;
    left: calc((var(--depth) - 1) * 40px + 16px);
    top: 50%;
    width: 24px;
    height: 2px;
    background: #ccc;
    z-index: 1;
}

.tree-line-tail {
    position: absolute;
    left: calc(var(--depth) * 40px + 16px);
    top: 50%;
    bottom: -15px;
    /* Drop below the card to meet the children */
    width: 2px;
    background: #ccc;
    z-index: 1;
}

.tree-dot {
    position: absolute;
    left: calc((var(--depth) - 1) * 40px + 15px);
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 4px;
    background: #ccc;
    border-radius: 50%;
    z-index: 2;
}

/* Active Path Highlighting */
.active-path-line {
    background: #666 !important;
    box-shadow: none;
}

.active-path-border {
    border-color: #333 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
}

.active-path-line.tree-dot {
    transform: translateY(-50%) scale(1.3);
    background: #444 !important;
}

.list-caret {
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    color: #444;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.list-caret:hover {
    background: #f8fafc;
    color: #0f172a;
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.list-caret.collapsed i {
    transform: rotate(-90deg);
}

.list-caret i {
    transition: transform 0.2s;
    font-size: 1rem;
}

/* 3. Card Design & Generational Colors */
.list-node-card {
    flex: 1;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 4px;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    transition: all 0.2s ease;
    background: white;
    position: relative;
    z-index: 5;
}

/* Tiered Backgrounds */
.list-node-card.depth-0 {
    background: #222;
    border-color: #000;
    color: white;
}

.list-node-card.depth-0 .list-node-name {
    color: white !important;
}

.list-node-card.depth-0 .list-node-meta {
    color: #94a3b8 !important;
}

.list-node-card.depth-0 .couple-divider {
    color: #666;
}

.list-node-card.depth-1 {
    background: white;
}

.list-node-card.depth-2 {
    background: #f9f9f9;
}

.list-node-card.depth-3 {
    background: #f5f5f5;
}

.list-node-card:hover {
    border-color: #cbd5e1;
    transform: translateX(4px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.couple-member {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    border-radius: 10px;
    transition: background 0.2s;
    cursor: pointer;
    flex: 1;
    min-width: 250px;
}

.couple-member:hover {
    background: rgba(0, 0, 0, 0.03);
}

.couple-divider {
    color: #888;
    margin: 0 4px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    opacity: 0.8;
}

/* 4. Typography & Info Hierarchy */
.list-node-info {
    flex: 1;
    overflow: hidden;
}

.list-node-name {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.01em;
    color: #0f172a;
    margin-bottom: 2px;
}

.is-spouse .list-node-name {
    font-weight: 500;
    font-size: 0.95rem;
    color: #64748b;
}

.list-node-meta {
    font-size: 0.8rem;
    color: #64748b;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 5. Status Indicators (Leaf/Check) */
.status-indicator {
    margin-left: 8px;
    display: flex;
    align-items: center;
}

.child-badge {
    background: #555;
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    margin-right: 12px;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.child-badge:hover {
    background: #222;
    transform: scale(1.05);
}

.list-quick-actions {
    padding-right: 12px;
}



/* ===== BUTTONS ===== */
.btn {
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.btn i {
    font-size: 1.1em;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: 1px solid var(--accent);
}

.btn-primary:hover {
    background: #333;
    border-color: #333;
    transform: translateY(-1px);
}

.btn-secondary {
    background: white;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--hover-bg);
    border-color: #ccc;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-dark);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--text-primary);
    color: white;
}

.btn-danger {
    background: white;
    color: #cc0000;
    border: 1px solid #ffcccc;
}

.btn-danger:hover {
    background: #fff5f5;
    border-color: #cc0000;
}

.btn.sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn.full-width {
    width: 100%;
}

.btn-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s;
    color: var(--text-primary);
    padding: 0;
}

.btn-icon:hover {
    background: var(--hover-bg);
    border-color: #aaa;
}

/* ===== LAYOUT ===== */
.app-layout {
    display: flex;
    height: calc(100vh - var(--header-height));
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s ease, transform 0.3s ease;
    position: relative;
    overflow: visible;
}

.sidebar.collapsed {
    width: 0 !important;
    border-right: none !important;
}

.sidebar.collapsed * {
    display: none !important;
}

.collapsed-handle {
    display: none;
    position: absolute;
    left: 100%;
    top: 20px;
    width: 32px;
    height: 48px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    z-index: 1001;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
    color: var(--text-secondary);
    transition: all 0.2s;
}

.sidebar.collapsed .collapsed-handle {
    display: flex !important;
}

.collapsed-handle:hover {
    color: #000;
    width: 36px;
}

.sidebar-header {
    padding: 20px 20px 10px;
}

.sidebar-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.sidebar-header h2 {
    font-size: 0.95rem !important;
    font-weight: 600 !important;
    margin: 0 !important;
    color: #000 !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    line-height: 1.4 !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
}

.sidebar-toggle-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle-btn:hover {
    background: #f0f0f0;
    color: #000;
}

.search-wrapper {
    position: relative;
    width: 100%;
}

.search-wrapper i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-box {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
    background: #fafafa;
}

.search-box:focus {
    border-color: var(--border-dark);
    background: white;
}

.member-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 20px;
}

.member-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.member-card:hover {
    border-color: #000;
}

.member-card.active {
    border-color: #000;
    background: transparent;
    box-shadow: none;
    border-width: 1px;
}

.avatar {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    background: white;
    color: var(--text-primary);
    position: relative;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.list-node-card .avatar {
    width: 44px;
    height: 44px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

@media (max-width: 768px) {
    .list-node-card .avatar {
        width: 38px;
        height: 38px;
    }
}


.avatar.male {
    background: var(--male-color);
    border-color: var(--male-color);
    border-radius: 50%;
}

.avatar.female {
    background: var(--female-color);
    border-color: var(--female-color);
    border-radius: 50%;
}

.member-info h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.member-info p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 0;
}

.stat-box {
    text-align: center;
    background: #f9f9f9;
    border: 1px solid #eee;
    padding: 16px 10px;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.stat-box:hover {
    border-color: #ddd;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.stat-box .num {
    font-weight: 700;
    font-size: 1.4rem;
    line-height: 1;
    margin-bottom: 6px;
    color: #111;
}

.stat-box .label {
    color: var(--text-secondary);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* ===== MAIN AREA ===== */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: #fcfcfc;
}

/* Toolbar sits at top of canvas area */
.toolbar {
    background: white;
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 4px;
}

.zoom-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    width: 40px;
    text-align: center;
}

.canvas-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative;
    cursor: grab;
    background-color: #fafafa;
    background-image: radial-gradient(#e1e1e1 1px, transparent 1px);
    background-size: 20px 20px;
    touch-action: none;
}

.canvas-wrapper:active {
    cursor: grabbing;
}

.canvas-inner {
    position: absolute;
    transform-origin: top left;
}

/* ===== TREE NODES ===== */
.tree-node {
    position: absolute;
    width: 180px;
    background: white;
    border: 1px solid var(--border-dark);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.05);
    border-radius: 2px;
}

.tree-node:hover {
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
    z-index: 10;
}

.tree-node.selected {
    transform: translateY(-2px);
    z-index: 11;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.tree-node.selected.male {
    background: var(--male-color);
    border-color: #aebfd6;
}

.tree-node.selected.female {
    background: var(--female-color);
    border-color: #dbb8c5;
}

.tree-node.selected .node-name,
.tree-node.selected .node-dates,
.tree-node.selected .node-relation {
    color: var(--text-primary);
}

.tree-node.selected .node-avatar {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
}

/* Gender colors */
:root {
    --male-color: #C5D7EF;
    --female-color: #F5CFDD;
}

/* Gender shapes on nodes - UNIFIED to circle */
.tree-node.male .node-avatar,
.tree-node.female .node-avatar {
    border-radius: 50%;
    border: none;
}

/* Male Styling */
.tree-node.male {
    border: 2px solid var(--male-color);
}

.tree-node.male .node-avatar {
    background: var(--male-color);
    color: #111;
}

/* Female Styling */
.tree-node.female {
    border: 2px solid var(--female-color);
}

.tree-node.female .node-avatar {
    background: var(--female-color);
    color: #111;
}

.node-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.node-avatar {
    width: 40px;
    height: 40px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
}

.node-name {
    font-weight: 700 !important;
    font-size: 0.9rem !important;
    margin-bottom: 4px !important;
    line-height: 1.2 !important;
    color: #111 !important;
}

.node-dates {
    font-size: 0.75rem !important;
    color: #444 !important;
}

.node-age {
    font-size: 0.7rem;
    color: #444;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.05);
    display: inline-block;
    padding: 2px 6px;
    border-radius: 10px;
    margin: 4px 0;
}

.node-relation {
    font-size: 0.7rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    margin-top: 6px !important;
    font-weight: 600 !important;
    color: #555 !important;
}

/* ===== CONNECTIONS ===== */
#connections-svg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    overflow: visible;
}

.connection-line {
    fill: none;
    stroke: #000;
    stroke-width: 1px;
}

.couple-line {
    fill: none;
    stroke: #000;
    stroke-width: 1px;
    stroke-dasharray: 4, 4;
}

/* ===== LEGEND ===== */
.legend-container {
    position: absolute;
    bottom: 24px;
    left: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    z-index: 100;
}

.legend-toggle {
    background: white;
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: all 0.2s;
    font-weight: 500;
}

.legend-toggle:hover {
    background: #f9f9f9;
    border-color: #000;
}

.legend {
    display: none;
    background: white;
    border: 1px solid var(--border-dark);
    padding: 16px;
    font-size: 0.75rem;
    border-radius: var(--radius);
    margin-top: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.legend.active {
    display: block;
}

.legend h4 {
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.legend-line {
    width: 24px;
    height: 1px;
    background: black;
}

.legend-line.dashed {
    background: transparent;
    border-top: 1px dashed black;
    height: 1px;
}

/* Legend Updates */
.legend-box {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    /* Only circles now */
    border: none;
}

.legend-box.square {
    background: var(--male-color);
}

.legend-box.round {
    background: var(--female-color);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-secondary);
}

.empty-state .icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.2;
    color: black;
}

.empty-state h3 {
    color: var(--text-primary);
    margin-bottom: 8px;
}

/* ===== DETAIL PANEL ===== */
.detail-panel {
    width: 300px;
    background: white;
    border-left: 1px solid var(--border-color);
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    z-index: 200;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.1);
}

.detail-panel.open {
    transform: translateX(0);
}

.detail-header {
    background: white;
    padding: 30px 20px 20px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    text-align: center;
}

.detail-name {
    font-size: 1.05rem !important;
    font-weight: 700 !important;
    color: #000 !important;
    margin-bottom: 4px !important;
}

.detail-relation {
    font-size: 0.8rem !important;
    color: #555 !important;
    font-weight: 500 !important;
    text-transform: capitalize !important;
}

.detail-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.detail-close:hover {
    color: black;
}

.detail-avatar {
    width: 80px;
    height: 80px;
    margin: 0 auto 16px;
    border: 2px solid transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 300;
}

.detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

.key {
    color: #777;
    font-size: 0.85rem;
}

.value {
    font-weight: 600;
    color: #000;
    text-align: right;
}

.detail-actions {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.detail-actions .btn {
    width: 100%;
    justify-content: center;
    padding: 12px;
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: white;
    width: 480px;
    border: 1px solid black;
    box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.05);
    max-height: 90vh;
    overflow-y: auto;
}

.modal.small {
    width: 360px;
}

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

.modal-close {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
}

.modal-body {
    padding: 24px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full {
    grid-column: 1 / -1;
}

label {
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    color: #555 !important;
    display: block !important;
}

input,
select,
textarea {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
    background: #fafafa;
    color: var(--text-input);
}

input:focus,
select:focus,
textarea:focus {
    border-color: black;
    background: white;
}

textarea {
    min-height: 80px;
    resize: vertical;
}

.gender-selector {
    display: flex;
    gap: 10px;
}

.gender-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border-color);
    background: white;
    cursor: pointer;
    transition: all 0.2s;
}

.gender-btn:hover {
    border-color: #999;
}

.gender-btn.selected-male {
    background: black;
    color: white;
    border-color: black;
}

.gender-btn.selected-female {
    background: black;
    color: white;
    border-color: black;
    border-radius: 50px;
    /* Slight nod to circle shape */
}

.gender-btn.selected-male {
    border-radius: 0px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.relation-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.chip {
    padding: 4px 12px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
}

.chip:hover {
    border-color: black;
}

.chip.active {
    background: black;
    color: white;
    border-color: black;
}

/* ===== TOAST ===== */
.toast-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 2000;
}

.toast {
    background: white;
    color: black;
    padding: 12px 20px;
    border: 1px solid black;
    margin-top: 10px;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 768px) {

    /* Layout shifts to column */
    .app-layout {
        flex-direction: column;
    }

    /* Sidebar becomes a bottom sheet or hidden menu - for now, hide to prioritize canvas space */
    .sidebar {
        display: none;
        position: absolute;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        width: 280px;
        z-index: 1000;
        background: #fff;
        border-right: 1px solid var(--border-color);
        box-shadow: 10px 0 20px rgba(0, 0, 0, 0.1);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.mobile-open {
        display: flex !important;
        transform: translateX(0);
    }

    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: #fff;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin-right: 12px;
        cursor: pointer;
        font-size: 1.2rem;
    }

    /* Adjust Header */
    header {
        padding: 0 16px;
        font-size: 0.9rem;
    }

    .logo {
        font-size: 1rem;
    }

    .header-actions .btn {
        padding: 6px 12px;
        font-size: 0.75rem;
    }

    .header-actions .btn span {
        display: none;
        /* Hide text on small screens */
    }

    .header-actions .btn i {
        margin: 0;
    }

    /* Toolbar moves to bottom for easier reach */
    .toolbar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 90;
        border-top: 1px solid var(--border-color);
        justify-content: space-around;
        padding: 10px;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    }

    .toolbar-group {
        width: 100%;
        justify-content: space-evenly;
    }

    .toolbar-divider {
        display: none;
    }

    /* Adjust Main Canvas Area to account for bottom toolbar */
    .main-area {
        padding-bottom: 60px;
    }

    /* Modals need to fit screen */
    .modal {
        width: 95%;
        max-height: 85vh;
    }

    .form-grid {
        grid-template-columns: 1fr;
        /* Stack form inputs */
    }

    /* Detail Panel covers full screen on mobile */
    .detail-panel {
        width: 100%;
        transform: translateY(100%);
        /* Slide form bottom */
        top: 60px;
        /* Below header */
    }

    .detail-panel.open {
        transform: translateY(0);
    }
}

/* ===== SOCIAL MEDIA ===== */
.social-inputs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.social-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.social-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #333;
    flex-shrink: 0;
}

.social-input-row input {
    flex: 1;
}

/* ===== IMAGE UPLOAD ===== */
.image-upload-wrapper {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 4px;
    background: #fbfbfb;
    padding: 12px;
    border-radius: 8px;
    border: 1px dashed #ddd;
}

.image-preview {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #eee;
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.image-preview:empty::before {
    content: '\f14e';
    /* ph-image icon code or placeholder */
    font-family: 'Phosphor';
    color: #aaa;
    font-size: 1.5rem;
}

.image-upload-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-sm {
    padding: 6px 12px !important;
    font-size: 0.75rem !important;
}

/* Detail Avatar support */
.detail-avatar {
    width: 80px;
    height: 80px;
    background-size: cover;
    background-position: center;
    border-radius: 50%;
    margin-bottom: 16px;
    border: 3px solid #fff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    overflow: hidden;
}

.detail-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Mobile Tweaks */
@media (max-width: 768px) {
    .list-node {
        padding-left: calc(var(--depth) * 16px);
    }

    .tree-line-vertical {
        left: calc((var(--depth)) * 16px + 16px);
    }

    .tree-line-horizontal {
        left: calc((var(--depth) - 1) * 16px + 16px);
        width: 12px;
    }

    .tree-dot {
        left: calc((var(--depth) - 1) * 16px + 14px);
    }

    .couple-member {
        padding: 6px 12px;
        min-width: 0;
        width: 100%;
        flex: none;
    }

    .list-node-card {
        flex-direction: column;
        align-items: flex-start;
        padding: 8px;
    }

    .couple-divider {
        margin: 4px 0 4px 16px;
        font-size: 1rem;
        opacity: 0.8;
        color: #888;
    }

    .child-badge {
        margin: 8px 0 8px 12px;
    }
}