:root {
    --saffron: #FF9933;
    --saffron-dark: #F15A24;
    --navy: #001F3F;
    --navy-dark: #000080;
    --white: #FFFFFF;
    --light-grey: #F8F9FA;
    --border-grey: #E9ECEF;
    --success-green: #28A745;
    --text-dark: #212529;
    --text-muted: #6C757D;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.12);
    --border-radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans Devanagari', 'Segoe UI', 'Poppins', 'Roboto', system-ui, -apple-system, sans-serif;
    background: var(--light-grey);
    color: var(--text-dark);
    line-height: 1.5;
}

a, a:hover, a:focus, a:active, button, .btn, .nav-btn, .print-btn,
.action-buttons a, .btn-edit, .btn-delete, .node-actions a,
.family-card-link, .tree-node a, .container a, .hero a {
    text-decoration: none !important;
}

.lang-switcher {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: var(--white);
    padding: 6px 12px;
    border-radius: 40px;
    box-shadow: var(--shadow);
    display: flex;
    gap: 5px;
    border: 1px solid var(--border-grey);
}

.lang-btn {
    background: none;
    border: none;
    padding: 6px 16px;
    border-radius: 40px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s;
    color: var(--text-dark);
}

.lang-btn.active {
    background: var(--saffron);
    color: var(--white);
}

.lang-btn:hover:not(.active) {
    background: var(--border-grey);
}

.header {
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
    color: var(--white);
    padding: 35px 0;
    text-align: center;
    margin-bottom: 30px;
    position: relative;
    border-bottom: 4px solid var(--saffron);
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
}

.header h1 i {
    margin-right: 12px;
    color: var(--saffron);
}

.header p {
    opacity: 0.9;
    margin-top: 8px;
    font-size: 0.95rem;
}

.container {
    max-width: 1500px;
    margin: 0 auto;
    padding: 0 24px 40px;
}

.nav-bar {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    margin-bottom: 30px;
}

.nav-btn {
    background: var(--white);
    color: var(--navy);
    padding: 12px 28px;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-grey);
}

.nav-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    background: var(--saffron);
    color: var(--white);
    border-color: var(--saffron);
}

.search-box {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 28px;
    margin-bottom: 30px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-grey);
}

.search-box h3 {
    color: var(--navy);
    margin-bottom: 18px;
    font-size: 1.2rem;
    font-weight: 600;
}

.search-box h3 i {
    color: var(--saffron);
    margin-right: 10px;
}

.search-input-group {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.search-input-group input {
    flex: 1;
    min-width: 220px;
    padding: 12px 20px;
    border: 1px solid var(--border-grey);
    border-radius: 50px;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.search-input-group input:focus {
    outline: none;
    border-color: var(--saffron);
    box-shadow: 0 0 0 3px rgba(255, 153, 51, 0.1);
}

.btn {
    background: var(--saffron);
    color: var(--white);
    padding: 10px 24px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}

.btn:hover {
    background: var(--saffron-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.btn-secondary {
    background: var(--text-muted);
}

.btn-secondary:hover {
    background: #5a6268;
}

.form-container {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 35px;
    max-width: 550px;
    margin: 0 auto;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-grey);
}

.person-details-box {
    max-width: 1000px;
}

.family-header {
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
    color: var(--white);
    padding: 24px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
    text-align: center;
    border-bottom: 3px solid var(--saffron);
}

.family-header h2 {
    font-size: 1.6rem;
    margin-bottom: 8px;
}

.family-header h2 i {
    color: var(--saffron);
    margin-right: 12px;
}

.family-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.family-card-link {
    display: block;
}

.family-card {
    background: var(--white);
    padding: 24px;
    border-radius: 12px;
    transition: all 0.2s;
    border-left: 4px solid var(--saffron);
    box-shadow: var(--shadow);
    display: block;
}

.family-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
}

.family-card i {
    font-size: 2rem;
    color: var(--saffron);
}

.family-card h4 {
    margin-top: 12px;
    color: var(--navy);
    font-size: 1.1rem;
}

.family-card p {
    color: var(--text-muted);
    margin-top: 8px;
}

.section-title {
    margin-bottom: 20px;
    color: var(--navy);
    font-size: 1.2rem;
}

.section-title i {
    color: var(--saffron);
    margin-right: 8px;
}

.section-count {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.tree-container {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 30px;
    box-shadow: var(--shadow);
    min-height: 500px;
    overflow-x: auto;
    border: 1px solid var(--border-grey);
    text-align: center;
}

.tree-root-wrap {
    display: inline-block;
    min-width: max-content;
    padding: 10px 20px 40px;
}

.tree-node {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    min-width: 210px;
    padding: 0 12px;
    vertical-align: top;
}

.node-card {
    background: var(--white);
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: var(--shadow);
    border-top: 4px solid var(--saffron);
    border-left: 1px solid var(--border-grey);
    border-right: 1px solid var(--border-grey);
    border-bottom: 1px solid var(--border-grey);
    transition: all 0.2s;
    width: 230px;
    max-width: 230px;
    position: relative;
    z-index: 2;
}

.node-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
}

.node-card.male {
    background: #F0F8FF;
    border-top-color: #3498db;
}

.node-card.female {
    background: #FFF0F5;
    border-top-color: #e91e63;
}

.node-name {
    font-weight: bold;
    font-size: 0.98rem;
    color: var(--navy);
    margin-bottom: 6px;
    word-break: break-word;
}

.node-name i {
    margin-right: 6px;
    color: var(--saffron);
}

.spouse-name {
    margin-top: 6px;
    font-size: 0.82rem;
    color: #c0392b;
    font-weight: 600;
    word-break: break-word;
}

.spouse-name i {
    margin-right: 4px;
    color: #e74c3c;
}

.node-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.node-meta i {
    margin-right: 3px;
}

.action-buttons {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    padding-top: 8px;
    border-top: 1px solid var(--border-grey);
}

.action-buttons a {
    font-size: 0.7rem;
    padding: 6px 10px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
}

.btn-edit {
    background: #3498db;
    color: white;
}

.btn-edit:hover {
    background: #2980b9;
}

.children-wrap {
    position: relative;
    margin-top: 26px;
    padding-top: 26px;
    display: block;
}

.children-wrap::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 26px;
    transform: translateX(-50%);
    background: var(--saffron);
}

.children-row {
    position: relative;
    display: inline-flex;
    align-items: flex-start;
    justify-content: center;
    gap: 10px;
    padding-top: 22px;
}

.children-row::before {
    content: '';
    position: absolute;
    top: 0;
    left: 30px;
    right: 30px;
    height: 2px;
    background: var(--saffron);
}

.children-row > .tree-node::before {
    content: '';
    position: absolute;
    top: -22px;
    left: 50%;
    width: 2px;
    height: 22px;
    transform: translateX(-50%);
    background: var(--saffron);
}

.loading-box {
    background: #fff8ef;
    border: 1px solid #ffd9b3;
    color: var(--navy);
    padding: 12px 18px;
    border-radius: 10px;
    display: inline-block;
    font-weight: 600;
}

.person-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
    margin-top: 20px;
}

.detail-item {
    background: var(--white);
    border: 1px solid var(--border-grey);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.detail-item-full {
    grid-column: 1 / -1;
}

.child-list {
    margin: 10px 0 0 20px;
    padding: 0;
}

.child-list li {
    margin-bottom: 8px;
}

.child-list a {
    color: var(--navy);
    font-weight: 600;
}

.child-list a:hover {
    color: var(--saffron-dark);
}

.alert {
    padding: 12px 18px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 500;
    animation: slideIn 0.2s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.alert-success {
    background: #E8F5E9;
    color: #2E7D32;
    border-left: 4px solid var(--success-green);
}

.alert-error {
    background: #FFEBEE;
    color: #C62828;
    border-left: 4px solid #e74c3c;
}

.table-container {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 20px;
    overflow-x: auto;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-grey);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-grey);
}

th {
    background: var(--navy);
    color: var(--white);
    font-weight: 600;
}

tr:hover {
    background: var(--light-grey);
}

.footer {
    background: var(--navy);
    color: var(--white);
    text-align: center;
    padding: 30px 0;
    margin-top: 50px;
    border-top: 3px solid var(--saffron);
}

.footer p {
    opacity: 0.8;
    font-size: 0.85rem;
}

.footer i {
    color: var(--saffron);
}

@media print {
    body {
        background: white;
        padding: 0;
        margin: 0;
    }

    .lang-switcher, .nav-bar, .search-box, .action-buttons, .footer {
        display: none !important;
    }

    .tree-container {
        box-shadow: none;
        padding: 0;
        background: white;
        overflow: visible;
    }

    .node-card {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    @page {
        size: landscape;
        margin: 1cm;
    }
}

@media (max-width: 900px) {
    .node-card {
        width: 210px;
        max-width: 210px;
    }

    .children-row {
        gap: 6px;
    }
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 1.5rem;
    }

    .container {
        padding: 0 14px 30px;
    }

    .tree-container {
        padding: 18px 10px;
    }

    .tree-root-wrap {
        padding: 8px 10px 20px;
    }

    .node-card {
        width: 190px;
        max-width: 190px;
        padding: 12px 14px;
    }

    .node-name {
        font-size: 0.85rem;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons a {
        justify-content: center;
    }

    .person-detail-grid {
        grid-template-columns: 1fr;
    }

    .search-input-group {
        flex-direction: column;
    }

    .lang-switcher {
        top: 10px;
        right: 10px;
        transform: scale(0.9);
        transform-origin: top right;
    }
}

.node-card.compact {
    width: 170px;
    max-width: 170px;
    padding: 10px 10px 8px;
    font-size: 11px;
    border-radius: 10px;
}

.compact .node-name {
    font-size: 12px;
    line-height: 1.2;
    margin-bottom: 2px;
}

.compact .node-meta {
    font-size: 10px;
    gap: 4px;
}

.compact-actions a {
    font-size: 10px;
    padding: 4px 7px;
}

.marker-badge {
    position: absolute;
    top: -8px;
    left: 8px;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    border-radius: 999px;
    background: #fff3d9;
    border: 1px solid #f0c27a;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #8a5200;
    z-index: 5;
}

.couple-wrap {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 0;
    margin-top: 8px;
}

.person-half {
    flex: 1 1 0;
    padding: 0 4px;
}

.spouse-half .node-name,
.spouse-inline {
    color: #b03052;
}

.couple-divider {
    width: 1px;
    background: #e3d6d6;
    margin: 0 2px;
}

.compact-meta {
    margin-top: 6px;
}

.search-results {
    margin-top: 12px;
}

.search-result-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.search-result-item {
    background: #fff;
    border: 1px solid var(--border-grey);
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.search-result-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.node-highlight .node-card {
    outline: 3px solid #ffb74d;
    box-shadow: 0 0 0 4px rgba(255, 183, 77, 0.25);
}

.print-landscape .tree-container,
.print-portrait .tree-container {
    background: white;
}

@media print {
    body {
        background: white !important;
    }

    .lang-switcher,
    .nav-bar,
    .search-box,
    .action-buttons {
        display: none !important;
    }

    .tree-container {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    .tree-root-wrap {
        transform-origin: top left;
    }

    body.print-landscape .tree-root-wrap {
        transform: scale(0.80);
    }

    body.print-portrait .tree-root-wrap {
        transform: scale(0.68);
    }

    .node-card.compact {
        width: 145px;
        max-width: 145px;
        padding: 8px 8px 6px;
    }

    .compact .node-name {
        font-size: 10px;
    }

    .compact .node-meta {
        font-size: 8px;
    }

    .marker-badge {
        min-width: 18px;
        height: 18px;
        font-size: 9px;
        top: -6px;
    }

    @page {
        size: A4 landscape;
        margin: 8mm;
    }
}

.tree-container {
    overflow: auto;
    max-width: 100%;
    max-height: 78vh;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.tree-root-wrap {
    display: inline-block;
    min-width: max-content;
    padding: 10px 14px 30px;
    --print-scale: 1;
}

.children-row {
    position: relative;
    display: inline-flex;
    align-items: flex-start;
    justify-content: center;
    gap: 6px 10px;
    padding-top: 18px;
    flex-wrap: wrap;
    max-width: min(100%, 1200px);
}

.tree-node {
    min-width: 138px;
    padding: 0 4px;
}

.node-card.compact {
    width: 132px;
    max-width: 132px;
    min-height: 68px;
    padding: 7px 6px 5px;
}

.compact .node-name {
    font-size: 9.5px;
    line-height: 1.15;
    margin-bottom: 1px;
    word-break: break-word;
}

.compact .node-meta {
    font-size: 8px;
    gap: 3px;
    margin-top: 5px;
}

.compact-actions {
    margin-top: 7px;
    gap: 4px;
}

.compact-actions a {
    font-size: 7px;
    padding: 3px 5px;

    line-height: 1.1;
}

.marker-badge {
    position: absolute;
    top: -7px;
    left: 6px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: #fff3d9;
    border: 1px solid #f0c27a;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    color: #8a5200;
    z-index: 5;
}

.couple-wrap {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 0;
    margin-top: 5px;
}

.person-half {
    flex: 1 1 0;
    padding: 0 3px;
}

.couple-divider {
    width: 1px;
    background: #dfd4d4;
    margin: 0 1px;
}

.spouse-inline {
    color: #b03052;
}

.tree-status {
    margin-bottom: 12px;
    display: inline-block;
    background: #fff8ef;
    border: 1px solid #ffd9b3;
    color: var(--navy);
    padding: 8px 12px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
}

.search-results {
    margin-top: 12px;
}

.search-result-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.search-result-item {
    background: #fff;
    border: 1px solid var(--border-grey);
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.search-result-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.node-highlight .node-card {
    outline: 3px solid #ffb74d;
    box-shadow: 0 0 0 4px rgba(255, 183, 77, 0.25);
}

@media (max-width: 900px) {
    .tree-container {
        max-height: 72vh;
    }

    .tree-node {
        min-width: 142px;
    }

    .node-card.compact {
        width: 138px;
        max-width: 138px;
        padding: 7px 7px 5px;
    }

    .compact .node-name {
        font-size: 10px;
    }

    .compact-actions a {
        font-size: 7px;
        padding: 3px 5px;
    }
}

@media print {
    body {
        background: white !important;
    }

    .lang-switcher,
    .nav-bar,
    .search-box,
    .action-buttons,
    .tree-status {
        display: none !important;
    }

    .container {
        max-width: none !important;
        padding: 0 !important;
    }

.tree-container {
    overflow-x: hidden;
    overflow-y: auto;
    max-width: 100%;
    max-height: 78vh;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    text-align: center;
}

    .tree-root-wrap {
        transform-origin: top left;
        transform: scale(var(--print-scale));
        width: max-content;
        padding: 0 !important;
    }

    .tree-node {
        min-width: 130px;
        padding: 0 4px;
    }

    .children-row {
        gap: 4px;
        padding-top: 14px;
    }

    .node-card.compact {
        width: 122px;
        max-width: 122px;
        min-height: 62px;
        padding: 6px 6px 5px;
        box-shadow: none !important;
    }

    .compact .node-name {
        font-size: 8.2px;
        line-height: 1.1;
    }

    .compact .node-meta {
        font-size: 6.8px;
        gap: 2px;
        margin-top: 4px;
    }

    .marker-badge {
        min-width: 16px;
        height: 16px;
        font-size: 7px;
        top: -5px;
        left: 5px;
    }

    .couple-divider {
        margin: 0 1px;
    }
    @page {
        size: A4;
        margin: 6mm;
    }