:root {
    color-scheme: light dark;
    --bg: #f2ead9;
    --card-bg: #fffcf5;
    --text: #2b2013;
    --muted: #7a6a52;
    --border: #ddceac;
    --stripe: #efe6d1;
    --wash: #f7f1e2;

    /* brand palette - a fixed identity, not theme-dependent */
    --ink: #221a10;
    --forest: #3f5d3a;
    --forest-light: #547a4d;
    --maroon: #7a2e2e;
    --gold: #b8860b;

    --heading: var(--text);
    --warn: #8a5a00;

    --btn-bg: var(--forest);
    --btn-bg-hover: var(--forest-light);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #16140f;
        --card-bg: #211d15;
        --text: #ece3d1;
        --muted: #b3a488;
        --border: #3c3423;
        --stripe: #29241a;
        --wash: #1c1911;

        --forest-light: #6b9762;
        --heading: #ece3d1;
        --warn: #e0b23d;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    background: var(--ink);
    color: #f2ecdd;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    padding: 0.55rem 1.5rem;
}

.masthead {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    background: linear-gradient(135deg, var(--forest), #2c4429);
    color: #fdf8ec;
    padding: 1.1rem 1.5rem;
}

.brand-badge {
    flex-shrink: 0;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: #fdf8ec;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.masthead-eyebrow {
    margin: 0;
    font-size: 0.75rem;
    font-style: italic;
    opacity: 0.9;
}

.masthead-title {
    margin: 0.15rem 0 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.5rem;
    font-weight: 700;
}

.main-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 1.1rem;
    margin-left: auto;
}

.main-nav a {
    color: #fdf8ec;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
}

.main-nav a:hover {
    text-decoration: underline;
}

.nav-logout {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
    color: rgba(253, 248, 236, 0.85);
    font-size: 0.85rem;
}

.nav-logout button {
    width: auto;
    padding: 0.35rem 0.9rem;
}

.page {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 2.5rem 1.25rem;
}

.wide {
    width: 100%;
    max-width: 60rem;
}

.card {
    width: 100%;
    max-width: 32rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 1.75rem;
    box-shadow: 0 1px 3px rgba(34, 26, 16, 0.08);
    margin-bottom: 1.5rem;
}

.wide .card {
    max-width: none;
}

.card-narrow {
    max-width: 26rem;
}

.card-title {
    margin: 0 0 0.5rem;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--heading);
}

.subtitle {
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.5;
    margin: 0 0 1.25rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.page-header h2 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    color: var(--heading);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.muted-count {
    color: var(--muted);
    font-weight: 400;
    font-size: 0.85em;
}

fieldset {
    border: none;
    padding: 0;
    margin: 0 0 1.1rem;
}

legend {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 0.4rem;
    padding: 0;
}

.field-row {
    display: flex;
    gap: 1rem;
}

.field-row fieldset {
    flex: 1;
    min-width: 0;
}

.radio-row {
    display: flex;
    gap: 1rem;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.9rem;
    cursor: pointer;
}

input[type="text"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    background: var(--card-bg);
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
}

textarea {
    resize: vertical;
}

button,
.btn-primary-link {
    width: 100%;
    display: inline-block;
    text-align: center;
    padding: 0.7rem;
    border: none;
    border-radius: 0.25rem;
    background: var(--btn-bg);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    box-sizing: border-box;
}

button:hover,
.btn-primary-link:hover {
    background: var(--btn-bg-hover);
}

.btn-primary-link {
    width: auto;
    padding: 0.55rem 1.1rem;
    font-size: 0.9rem;
}

.btn-secondary,
.btn-danger {
    display: inline-block;
    width: auto;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.btn-secondary {
    background: var(--forest);
    color: #fff;
}

.btn-secondary:hover {
    background: var(--forest-light);
}

.btn-danger {
    background: var(--maroon);
    color: #fff;
}

.btn-danger:hover {
    opacity: 0.85;
}

.btn-small {
    padding: 0.3rem 0.7rem;
    font-size: 0.75rem;
}

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

.error-banner {
    background: var(--wash);
    border: 1px solid var(--gold);
    color: var(--warn);
    border-radius: 0.25rem;
    padding: 0.6rem 0.9rem;
    font-size: 0.85rem;
    margin: 0 0 1rem;
}

.site-footer {
    background: var(--ink);
    color: #cabfa4;
    font-size: 0.75rem;
    line-height: 1.6;
    text-align: center;
    padding: 1rem 1.5rem;
}

/* --- stats -------------------------------------------------------------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-tile {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 1.1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-number {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--forest-light);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--muted);
}

/* --- search / tables ------------------------------------------------------ */

.search-form {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
    align-items: center;
}

.search-form input {
    flex: 1;
}

.search-form button {
    width: auto;
}

.btn-clear {
    color: var(--muted);
    font-size: 0.85rem;
    text-decoration: none;
}

.table-wrap {
    overflow-x: auto;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
    text-align: left;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
}

.admin-table tbody tr:nth-child(even) {
    background: var(--stripe);
}

.admin-row-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.25rem;
    margin-top: 1.25rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.pagination a {
    color: var(--forest-light);
    text-decoration: none;
    font-weight: 600;
}

/* --- person profile -------------------------------------------------------- */

.detail-list {
    display: grid;
    grid-template-columns: 8rem 1fr;
    gap: 0.5rem 1rem;
    margin: 0;
}

.detail-list dt {
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding-top: 0.15rem;
}

.detail-list dd {
    margin: 0;
}

.detail-list dd.notes {
    white-space: pre-wrap;
}

.people-links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-panel {
    background: var(--stripe);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 1.1rem 1.1rem 0.1rem;
    margin-top: 0.75rem;
}

details.add-union summary {
    cursor: pointer;
    color: var(--forest-light);
    font-weight: 600;
    font-size: 0.9rem;
}

/* --- ancestor / descendant tree --------------------------------------------- */

.tree-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

@media (max-width: 42rem) {
    .tree-columns {
        grid-template-columns: 1fr;
    }
}

ul.tree {
    list-style: none;
    margin: 0;
    padding-left: 0;
}

ul.tree ul {
    list-style: none;
    margin: 0.35rem 0 0.35rem 1rem;
    padding-left: 1rem;
    border-left: 1px dashed var(--border);
}

ul.tree li {
    margin: 0.3rem 0;
}

ul.tree a {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
}

ul.tree a:hover {
    color: var(--forest-light);
    text-decoration: underline;
}
