:root {
    --ink: #202124;
    --muted: #6b7280;
    --line: #d8ded8;
    --paper: #f7f4ed;
    --white: #fff;
    --accent: #315c48;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: #f5f7f6;
    font-family: Arial, Helvetica, sans-serif;
}

a {
    text-decoration: none;
}

.app-navbar {
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid #e5e7eb;
}

.page-head,
.tree-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-head.compact {
    margin-bottom: 1rem;
}

.eyebrow {
    margin: 0 0 .25rem;
    color: var(--accent);
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(1.7rem, 2.8vw, 2.6rem);
    font-weight: 800;
}

h2 {
    font-size: 1.2rem;
    font-weight: 800;
}

.auth-wrap {
    min-height: calc(100vh - 112px);
    display: grid;
    place-items: center;
}

.auth-panel,
.form-shell,
.empty-state,
.panel-form,
.app-table {
    background: var(--white);
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 18px 45px rgba(25, 38, 34, .08);
}

.auth-panel {
    width: min(430px, 100%);
    padding: 2rem;
}

.form-shell {
    width: min(720px, 100%);
    padding: 1.5rem;
    margin: 0 auto;
}

.form-shell.wide {
    width: min(1040px, 100%);
}

.stacked-form,
.panel-form {
    display: grid;
    gap: 1rem;
}

.member-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

label {
    display: grid;
    gap: .4rem;
    color: #374151;
    font-size: .92rem;
    font-weight: 700;
}

.check-row {
    display: flex;
    align-items: center;
    gap: .55rem;
    font-weight: 700;
}

.check-row input {
    width: 18px;
    height: 18px;
}

.span-2 {
    grid-column: span 2;
}

.family-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

.family-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1.5rem;
    min-height: 180px;
    padding: 1.25rem;
    background: var(--white);
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.family-card p {
    color: var(--muted);
}

.family-card span {
    color: var(--accent);
    font-weight: 700;
}

.card-actions,
.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

.role-form {
    min-width: 120px;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: .75rem;
    padding: 1rem;
    margin-bottom: 1rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.filter-bar label {
    min-width: 180px;
    flex: 1 1 180px;
}

.empty-state {
    padding: 2rem;
    max-width: 720px;
}

.empty-state p {
    color: var(--muted);
}

.split-layout {
    display: grid;
    grid-template-columns: minmax(260px, 360px) 1fr;
    gap: 1rem;
}

.panel-form {
    padding: 1.25rem;
    align-self: start;
}

.wide-panel {
    width: min(980px, 100%);
}

.form-hint {
    margin: 0;
    color: var(--muted);
    font-size: .9rem;
}

.app-table {
    overflow: hidden;
}

.profile-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2rem;
    max-width: 980px;
}

.profile-photo img,
.avatar-placeholder {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    object-fit: cover;
}

.avatar-placeholder {
    display: grid;
    place-items: center;
    background: #dfe8e2;
    color: var(--accent);
    font-size: 5rem;
    font-weight: 800;
}

.profile-detail dl {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: .55rem 1rem;
    margin: 1.2rem 0;
}

.profile-detail dt {
    color: var(--muted);
}

.tree-toolbar {
    align-items: end;
}

.theme-select {
    width: 150px;
}

.print-size-select {
    width: 170px;
}

.tree-stage {
    position: relative;
    min-height: 68vh;
    overflow: auto;
    padding: 1rem;
    background: #e9eeeb;
    border: 1px solid #dce3df;
    border-radius: 8px;
    cursor: grab;
    user-select: none;
}

.tree-stage.is-dragging {
    cursor: grabbing;
}

.zoom-controls {
    position: sticky;
    top: .5rem;
    z-index: 4;
    display: flex;
    gap: .35rem;
}

.tree-canvas {
    width: max-content;
    min-width: 100%;
    min-height: 560px;
    padding: 2rem;
    transform-origin: top left;
    transition: transform .18s ease;
}

.tree-canvas.tree-compact .family-tree,
.tree-canvas.tree-compact .family-tree ul {
    gap: .7rem;
}

.tree-canvas.tree-compact .person-card {
    width: 150px;
    min-height: 190px;
    padding: .65rem;
}

.tree-canvas.tree-compact .person-photo,
.tree-canvas.tree-compact .person-initial {
    width: 72px;
    height: 72px;
}

.tree-canvas.tree-compact .person-bio,
.tree-canvas.tree-compact .person-meta,
.tree-canvas.tree-compact .person-place {
    display: none;
}

.tree-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .2rem;
    margin-bottom: 1.5rem;
}

.tree-title strong {
    font-size: 1.35rem;
}

.tree-title span {
    color: var(--muted);
}

.family-tree,
.family-tree ul {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 2rem;
    padding: 2rem 0 0;
    margin: 0;
    list-style: none;
}

.family-tree ul::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    width: 1px;
    height: 2rem;
    background: var(--line);
}

.family-tree ul::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--line);
}

.family-tree ul > li:first-child::after,
.family-tree ul > li:last-child::after {
    content: "";
    position: absolute;
    top: -2rem;
    height: 1px;
    background: var(--line);
}

.family-tree ul > li:first-child::after {
    left: 0;
    width: 50%;
}

.family-tree ul > li:last-child::after {
    right: 0;
    width: 50%;
}

.family-tree ul > li:only-child::after {
    display: none;
}

.family-tree li {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 2rem;
}

.family-tree li::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    width: 1px;
    height: 2rem;
    background: var(--line);
    z-index: 0;
}

.family-tree > li::before {
    display: none;
}

.couple-node {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.spouse-link {
    color: var(--muted);
    font-weight: 800;
    font-size: 1.45rem;
}

.person-card {
    display: grid;
    justify-items: center;
    align-content: start;
    gap: .45rem;
    width: 240px;
    min-height: 300px;
    padding: 1rem;
    color: var(--ink);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 16px 34px rgba(30, 41, 36, .12);
    transition: transform .16s ease, box-shadow .16s ease;
}

.person-card:hover {
    color: var(--ink);
    transform: translateY(-2px);
    box-shadow: 0 22px 44px rgba(30, 41, 36, .16);
}

.person-photo-wrap {
    display: grid;
    place-items: center;
    width: 116px;
    height: 116px;
    margin-bottom: .25rem;
}

.person-photo,
.person-initial {
    width: 112px;
    height: 112px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid #f4efe5;
    box-shadow: 0 8px 18px rgba(24, 35, 31, .15);
}

.person-initial {
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--accent);
    font-weight: 800;
    font-size: 2.4rem;
}

.person-name {
    max-width: 100%;
    overflow-wrap: anywhere;
    text-align: center;
    line-height: 1.15;
    font-size: 1.25rem;
    font-weight: 800;
}

.person-years {
    color: #4b5563;
    font-size: .95rem;
    font-weight: 700;
}

.person-place,
.person-meta,
.person-bio {
    color: var(--muted);
    font-size: .82rem;
    text-align: center;
    line-height: 1.3;
}

.person-place {
    color: #3f4d5f;
}

.person-meta {
    padding: .2rem .45rem;
    color: #294335;
    background: #edf6f0;
    border-radius: 999px;
    font-weight: 700;
}

.person-bio {
    display: -webkit-box;
    max-width: 100%;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.relation-badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    margin: .15rem .25rem .15rem 0;
    padding: .25rem .55rem;
    color: #1f3d31;
    background: #e4eee8;
    border: 1px solid #bfd3c7;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 700;
}

.duplicate-list {
    display: grid;
    gap: 1rem;
}

.duplicate-group {
    padding: 1.25rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.duplicate-members {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: .75rem;
}

.mini-member-card {
    display: grid;
    gap: .35rem;
    padding: .85rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
}

.mini-member-card span {
    color: var(--muted);
    font-size: .9rem;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: .75rem;
    margin-bottom: 1rem;
}

.metric-card {
    display: grid;
    gap: .2rem;
    padding: 1rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.metric-card strong {
    font-size: 1.7rem;
}

.metric-card span {
    color: var(--muted);
    font-weight: 700;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 800;
}

.status-pill.ok {
    color: #24533f;
    background: #e3f3ea;
    border: 1px solid #b7dcc5;
}

.status-pill.warn {
    color: #7a4c16;
    background: #fff2d8;
    border: 1px solid #e7c682;
}

.theme-classic {
    --line: #b99f6c;
    --accent: #7a5526;
    background: #fbf2df;
}

.theme-modern {
    --line: #b9c4d6;
    --accent: #345f8c;
    background: #f8fbff;
}

.theme-royal {
    --line: #c8a44d;
    --accent: #762f3d;
    background: #fff8e8;
}

.theme-nature {
    --line: #8fb49b;
    --accent: #315c48;
    background: #f2f8ef;
}

.theme-royal .person-card {
    border-color: #c8a44d;
}

@media (max-width: 900px) {
    .page-head,
    .tree-toolbar,
    .split-layout,
    .profile-layout {
        grid-template-columns: 1fr;
        display: grid;
        align-items: start;
    }

    .member-form {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: auto;
    }
}

@media (max-width: 640px) {
    main.container-fluid {
        padding-left: .75rem !important;
        padding-right: .75rem !important;
    }

    .auth-panel,
    .form-shell,
    .empty-state,
    .panel-form {
        padding: 1rem;
    }

    .button-row {
        width: 100%;
    }

    .button-row .btn,
    .theme-select,
    .print-size-select {
        flex: 1 1 150px;
    }

    .tree-stage {
        padding: .5rem;
    }

    .tree-canvas {
        padding: 1rem;
    }

    .person-card {
        width: 190px;
        min-height: 250px;
        padding: .85rem;
    }

    .person-photo-wrap {
        width: 94px;
        height: 94px;
    }

    .person-photo,
    .person-initial {
        width: 90px;
        height: 90px;
    }

    .person-name {
        font-size: 1.05rem;
    }

    .couple-node {
        gap: .5rem;
    }
}

@media print {
    @page {
        size: auto;
        margin: 8mm;
    }

    @page a4Landscape {
        size: A4 landscape;
        margin: 8mm;
    }

    @page a4Portrait {
        size: A4 portrait;
        margin: 8mm;
    }

    @page a3Landscape {
        size: A3 landscape;
        margin: 8mm;
    }

    @page a3Portrait {
        size: A3 portrait;
        margin: 8mm;
    }

    body {
        background: #fff;
    }

    body.print-a4-landscape {
        page: a4Landscape;
    }

    body.print-a4-portrait {
        page: a4Portrait;
    }

    body.print-a3-landscape {
        page: a3Landscape;
    }

    body.print-a3-portrait {
        page: a3Portrait;
    }

    .app-navbar,
    .tree-toolbar,
    .zoom-controls,
    .alert {
        display: none !important;
    }

    main.container-fluid {
        padding: 0 !important;
    }

    .tree-stage {
        min-height: auto;
        overflow: visible;
        padding: 0;
        border: 0;
        background: #fff;
    }

    .tree-canvas {
        transform: none !important;
        padding: 1rem;
        min-height: auto;
    }

    .person-card {
        break-inside: avoid;
        box-shadow: none;
    }
}
