:root {
    --bg-color: #0f172a;
    /* Slate 900 */
    --sidebar-bg: #1e293b;
    /* Slate 800 */
    --card-bg: #334155;
    /* Slate 700 */
    --text-primary: #f8fafc;
    /* Slate 50 */
    --text-secondary: #94a3b8;
    /* Slate 400 */
    --accent-color: #8b5cf6;
    /* Violet 500 */
    --accent-hover: #7c3aed;
    /* Violet 600 */
    --success-color: #10b981;
    --border-color: #475569;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

/* Global Form Inputs */
input,
select,
textarea,
.form-input {
    background-color: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    outline: none;
    width: 100%;
}

select option {
    background-color: var(--bg-color);
    color: var(--text-primary);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent-color);
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    /* App-like feel */
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.logo h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 3rem;
    letter-spacing: -0.5px;
}

.highlight {
    color: var(--accent-color);
}

.nav-links li {
    margin-bottom: 0.5rem;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    font-size: 0.95rem;
}

.nav-links a:hover,
.nav-links li.active a {
    background-color: rgba(139, 92, 246, 0.1);
    color: var(--accent-color);
}

.nav-links i {
    font-size: 1.2rem;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.top-bar {
    height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    background-color: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.search-bar {
    display: flex;
    align-items: center;
    background-color: var(--sidebar-bg);
    padding: 10px 20px;
    border-radius: 50px;
    border: 1px solid var(--border-color);
    width: 300px;
}

.search-bar i {
    color: var(--text-secondary);
    margin-right: 10px;
}

.search-bar input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    width: 100%;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-profile img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--accent-color);
}

.content-wrapper {
    padding: 2rem;
}

/* Dashboard Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background-color: var(--sidebar-bg);
    border-radius: 16px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease;
}

.card:hover {
    transform: translateY(-5px);
    border-color: var(--accent-color);
}

.card h3 {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    font-weight: 400;
}

.card .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.card .icon-wrapper {
    float: right;
    background: rgba(139, 92, 246, 0.1);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: var(--accent-color);
    font-size: 1.2rem;
}

/* Family Tree specific styles */
.tree-container {
    width: 100%;
    overflow-x: auto;
    padding: 20px;
    text-align: center;
}

.tree {
    display: inline-block;
    white-space: nowrap;
}

.tree ul {
    padding-top: 20px;
    position: relative;
    transition: all 0.5s;
    display: flex;
    justify-content: center;
}

.tree li {
    float: left;
    text-align: center;
    list-style-type: none;
    position: relative;
    padding: 20px 5px 0 5px;
    transition: all 0.5s;
}

/* We will use ::before and ::after to draw the connectors */
.tree li::before,
.tree li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    border-top: 1px solid var(--text-secondary);
    width: 50%;
    height: 20px;
}

.tree li::after {
    right: auto;
    left: 50%;
    border-left: 1px solid var(--text-secondary);
}

/* We need to remove left-right connectors from elements without any siblings */
.tree li:only-child::after,
.tree li:only-child::before {
    display: none;
}

/* Remove space from the top of single children */
.tree li:only-child {
    padding-top: 0;
}

/* Remove left connector from first child and right connector from last child */
.tree li:first-child::before,
.tree li:last-child::after {
    border: 0 none;
}

/* Adding back the vertical connector to the last nodes */
.tree li:last-child::before {
    border-right: 1px solid var(--text-secondary);
    border-radius: 0 5px 0 0;
}

.tree li:first-child::after {
    border-radius: 5px 0 0 0;
}

/* Time to add downward connectors from parents */
.tree ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: 1px solid var(--text-secondary);
    width: 0;
    height: 20px;
}

.tree-member-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 8px;
    display: inline-block;
    min-width: 120px;
    position: relative;
    z-index: 2;
    transition: all 0.3s;
    text-decoration: none;
    color: var(--text-primary);
}

.tree-member-card:hover {
    background-color: var(--sidebar-bg);
    border-color: var(--accent-color);
    transform: scale(1.05);
}

.tree-member-card img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-bottom: 5px;
    border: 2px solid var(--accent-color);
}

.tree-member-card .name {
    font-weight: 600;
    font-size: 0.9rem;
    display: block;
}

.tree-member-card .dates {
    font-size: 0.7rem;
    color: var(--text-secondary);
    display: block;
}

.spouse-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.spouse-connector {
    height: 2px;
    width: 20px;
    background-color: #ef4444;
}

/* Visual Updates for Tree Nodes */
.tree-member-card.is-dead img {
    filter: grayscale(100%);
    border-color: #64748b;
}

.rip-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: black;
    color: white;
    font-size: 0.6rem;
    padding: 2px 5px;
    border-radius: 4px;
    font-weight: bold;
}

.social-icons {
    margin-top: 5px;
    display: flex;
    justify-content: center;
    gap: 5px;
    opacity: 0.7;
}

.social-icons i {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        padding: 1rem;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        position: relative;
    }

    .logo h2 {
        margin-bottom: 1rem;
        text-align: center;
    }

    /* Toggleable menu concept or simpler horizontal scroll for nav */
    .nav-links {
        display: flex;
        overflow-x: auto;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .nav-links li {
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .nav-links a {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .main-content {
        height: calc(100vh - 120px);
        /* Adjust based on sidebar height */
    }

    .top-bar {
        padding: 0 1rem;
        height: 60px;
    }

    .search-bar {
        width: 180px;
    }

    .content-wrapper {
        padding: 1rem;
    }

    /* Adjust grid forms to single column */
    /* ... existing comments ... */
}

/* Horizontal Tree Layout */
.tree-horizontal .tree {
    display: flex;
    justify-content: center;
}

.tree-horizontal .tree ul {
    flex-direction: column;
    /* Stack children vertically */
    padding-top: 0;
    padding-left: 20px;
    /* Space for connectors on left */
    align-items: flex-start;
}

.tree-horizontal .tree li {
    float: none;
    text-align: left;
    padding: 10px 0 10px 20px;
    /* Space between nodes vertically */
    display: flex;
    align-items: center;
}

/* Connectors for Horizontal */
.tree-horizontal .tree li::before,
.tree-horizontal .tree li::after {
    top: 50%;
    left: 0;
    width: 20px;
    height: 50%;
    border-top: 1px solid var(--text-secondary);
    border-left: 1px solid var(--text-secondary);
    right: auto;
}

.tree-horizontal .tree li::after {
    top: 50%;
    left: 0;
    height: 100%;
    border-top: 0;
}

/* Remove connectors for single children */
.tree-horizontal .tree li:only-child::after,
.tree-horizontal .tree li:only-child::before {
    display: none;
    /* Or maybe just a single dash? */
}

/* Revert standard specific rules */
.tree-horizontal .tree li:first-child::before,
.tree-horizontal .tree li:last-child::after {
    border: 0 none;
}

/* Adjust connector specific to horizontal */
.tree-horizontal .tree li:only-child {
    padding-left: 0;
    /* No connector space needed if root? No, children need it */
}

/* Fix connectors logic for horizontal is distinct. 
   Top-down: Parent -> Children (row). Connectors above.
   Left-Right: Parent -> Children (column). Connectors on left.
*/

/* Resetting default tree styles for horizontal override */
.tree-horizontal .tree li::before {
    right: auto;
    top: 0;
    bottom: 50%;
    height: 50%;
    width: 20px;
    border-top: 0;
    border-bottom: 1px solid var(--text-secondary);
    border-left: 1px solid var(--text-secondary);
}

.tree-horizontal .tree li::after {
    right: auto;
    top: 50%;
    bottom: 0;
    height: 100%;
    width: 20px;
    border-top: 0;
    border-left: 1px solid var(--text-secondary);
}

.tree-horizontal .tree li:first-child::before {
    border-left: 0;
}

.tree-horizontal .tree li:last-child::after {
    border-left: 0;
}

.tree-horizontal .tree li:only-child::after,
.tree-horizontal .tree li:only-child::before {
    display: none;
}

/* Parent Connector (Right side of parent to Left side of children group) */
.tree-horizontal .tree ul ul::before {
    top: 50%;
    left: 0;
    width: 20px;
    height: 0;
    border-left: 0;
    border-top: 1px solid var(--text-secondary);
}

.tree-horizontal .tree-member-card {
    margin-right: 20px;
}

/* Fix spouse container for horizontal */
.tree-horizontal .spouse-container {
    flex-direction: row;
    /* Keep spouses side-by-side */
}

/* Collapsed Sidebar */
@media (min-width: 769px) {
    .sidebar {
        transition: width 0.3s ease;
    }

    .sidebar.collapsed {
        width: 80px;
    }

    .sidebar.collapsed .logo-text {
        display: none;
    }

    .sidebar.collapsed .logo {
        justify-content: center;
    }

    .sidebar.collapsed .logo img {
        margin-right: 0;
    }

    .sidebar.collapsed .link-text {
        display: none;
    }

    .sidebar.collapsed .nav-links a {
        justify-content: center;
        padding: 12px;
    }

    .sidebar.collapsed .nav-links a i {
        margin-right: 0;
    }
}