:root {
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #172033;
    background: #e9eef6;
    font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { font: inherit; }
button {
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: 9px;
    background: #176f65;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 700;
    line-height: 1.2;
    padding: 0.65rem 0.9rem;
    transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}
button:hover:not(:disabled) { background: #0e5c54; box-shadow: 0 3px 10px #115e5940; transform: translateY(-1px); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid #e6b44c99;
    outline-offset: 2px;
}
button:disabled { cursor: not-allowed; opacity: 0.42; }
button.needs-saving {
    background: #c47611;
    animation: save-fill-pulse 1.8s ease-in-out infinite;
}
button.needs-saving:hover:not(:disabled) { background: #a85f08; }
button.secondary { background: #fff; border-color: #c9d2df; color: #334155; }
button.secondary:hover:not(:disabled) { background: #f8fafc; border-color: #94a3b8; box-shadow: none; }
button.danger { background: #fff5f5; border-color: #fecaca; color: #b42318; }
button.danger:hover:not(:disabled) { background: #fee2e2; border-color: #fca5a5; box-shadow: none; }
a { color: #176f65; }
.page { min-height: 100vh; }
.contact-email {
    position: fixed;
    z-index: 11;
    right: 1rem;
    bottom: 0.35rem;
    margin: 0;
    border-radius: 999px;
    background: #fffffff0;
    box-shadow: 0 3px 10px #1720331a;
    color: #526777;
    font-size: 0.75rem;
    font-style: normal;
    padding: 0.35rem 0.6rem;
}
.hidden { display: none !important; }
.card {
    background: #fff;
    border: 1px solid #dce3ed;
    border-radius: 14px;
    box-shadow: 0 8px 24px #3341550d;
    padding: 1.5rem;
}
.narrow {
    margin: 0 auto;
    max-width: 31rem;
    min-height: 100vh;
    padding-top: max(6rem, 16vh);
    border: 0;
    border-radius: 0;
    box-shadow: none;
}
.brand-mark {
    display: grid;
    width: 3.4rem;
    height: 3.4rem;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(145deg, #2a8e81, #125f57);
    box-shadow: 0 10px 20px #176f6538;
    color: #fff;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}
.brand-mark.compact { width: 2.6rem; height: 2.6rem; border-radius: 9px; font-size: 0.75rem; }
.eyebrow {
    margin: 0 0 0.32rem;
    color: #5b6b82;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.1em;
}
.narrow .eyebrow { margin-top: 1.5rem; color: #176f65; }
.narrow h1 { margin: 0; font-size: clamp(2rem, 4vw, 2.55rem); letter-spacing: -0.045em; }
.login-intro { color: #607089; line-height: 1.6; }
.error { min-height: 1.2rem; margin: 0; color: #b42318; font-size: 0.875rem; }
#login-form { display: grid; gap: 0.9rem; margin-top: 1.75rem; }
label { display: grid; gap: 0.42rem; color: #3d4a5d; font-size: 0.79rem; font-weight: 700; }
input, select, textarea {
    width: 100%;
    border: 1px solid #c9d2df;
    border-radius: 8px;
    background: #fff;
    color: #172033;
    font-size: 0.925rem;
    font-weight: 400;
    padding: 0.65rem 0.72rem;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}
input:hover, select:hover, textarea:hover { border-color: #94a3b8; }
input:focus, select:focus, textarea:focus { border-color: #208577; box-shadow: 0 0 0 3px #2085771f; outline: 0; }
input[readonly] { background: #f4f7fa; color: #64748b; }
textarea { min-height: 7rem; resize: vertical; }
.editor-comment-field { margin-top: 1rem; }

#editor-view:not(.hidden) {
    display: grid;
    height: 100vh;
    height: 100dvh;
    grid-template-rows: auto auto minmax(0, 1fr);
    overflow: hidden;
}
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 5.25rem;
    padding: 0.85rem clamp(1rem, 3vw, 3rem);
    border-bottom: 1px solid #dbe3ed;
    background: #fff;
}
.app-title, .header-actions, .toolbar-context, .toolbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.app-title h1 { margin: 0; font-size: 1.28rem; letter-spacing: -0.035em; }
.app-title .eyebrow { color: #176f65; }
#save-status { margin: 0 0 0 0.45rem; color: #9a6700; font-size: 0.78rem; }
.header-actions { margin-left: auto; }
.public-link { color: #475569; font-size: 0.875rem; font-weight: 700; text-decoration: none; }
.public-link:hover { color: #176f65; text-decoration: underline; }
.toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem clamp(1rem, 3vw, 3rem);
    border-bottom: 1px solid #dbe3ed;
    background: #f8fafc;
}
.toolbar-context { flex: 1; min-width: 0; }
.toolbar-context > label:first-child { width: min(16rem, 100%); }
.search { width: min(24rem, 100%); }
.toolbar-actions { flex-wrap: wrap; justify-content: flex-end; }
.toolbar-actions button:last-of-type { margin-left: 0.4rem; }

.editor-layout {
    display: grid;
    grid-template-columns: minmax(17rem, 23rem) minmax(0, 1fr);
    gap: 1.25rem;
    min-height: 0;
    overflow: hidden;
    padding: 1.25rem clamp(1rem, 3vw, 3rem) clamp(1rem, 3vw, 2.25rem);
}
.person-sidebar {
    display: flex;
    min-height: 0;
    flex-direction: column;
    border: 1px solid #dce3ed;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 8px 24px #3341550d;
    overflow: hidden;
}
.sidebar-heading, .section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.sidebar-heading { padding: 1.25rem 1.25rem 1rem; border-bottom: 1px solid #edf1f5; }
.sidebar-heading h2, .section-heading h2 { margin: 0; font-size: 1.05rem; letter-spacing: -0.025em; }
.person-count {
    display: grid;
    width: 2rem;
    height: 2rem;
    place-items: center;
    border-radius: 50%;
    background: #ecfdf8;
    color: #176f65;
}
#person-list { flex: 1; list-style: none; margin: 0; padding: 0.65rem; overflow-y: auto; }
#person-list li + li { margin-top: 0.2rem; }
#person-list button {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    width: 100%;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #334155;
    font-weight: 600;
    text-align: left;
    padding: 0.72rem 0.78rem;
    box-shadow: none;
}
#person-list button:hover:not(.selected) { background: #f1f5f9; color: #0f172a; transform: none; }
#person-list button.selected { background: #dff7f1; color: #0e665d; box-shadow: inset 3px 0 #178174; }
.person-label-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.person-label-id {
    flex: 0 0 auto;
    color: #8291a6;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}
#person-list button.selected .person-label-id { color: #318b80; }
.person-card { min-width: 0; min-height: 0; overflow: auto; }
.section-heading { margin-bottom: 1.5rem; }
.autosave-note { padding: 0.35rem 0.55rem; border-radius: 999px; background: #f0f4f8; color: #64748b; font-size: 0.72rem; font-weight: 700; }
#selection-hint { display: grid; min-height: 16rem; place-items: center; margin: 0; border: 1px dashed #c9d2df; border-radius: 10px; color: #64748b; text-align: center; }
.field-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.1rem; }
.relationships { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.relationships > div, .sibling-relationships {
    padding: 1rem;
    border: 1px solid #e1e7ef;
    border-radius: 10px;
    background: #fafcff;
}
.relationships h3, .sibling-relationships h3 { margin: 0 0 0.75rem; color: #475569; font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; }
.relationships ul, .sibling-relationships ul { list-style: none; margin: 0; padding: 0; }
.relationships button, .sibling-relationships button {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    width: 100%;
    margin-bottom: 0.35rem;
    border-color: #d7e1eb;
    background: #fff;
    color: #334155;
    text-align: left;
    box-shadow: none;
}
.relationships button:hover:not(:disabled), .sibling-relationships button:hover:not(:disabled) { background: #f0fdf9; border-color: #99d8cc; box-shadow: none; transform: none; }
.relationships .empty, .sibling-relationships .empty { margin: 0; color: #94a3b8; font-size: 0.875rem; }
.sibling-relationships { margin-top: 1rem; }
.document-attachments { margin-top: 1.5rem; }
.document-attachments > h3 { margin: 0 0 0.8rem; color: #334155; font-size: 1rem; }
.document-category-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.document-category-grid article {
    min-width: 0;
    padding: 1rem;
    border: 1px solid #e1e7ef;
    border-radius: 10px;
    background: #fafcff;
}
.document-category-grid h4 { margin: 0 0 0.75rem; color: #475569; font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; }
.document-category-grid input { margin-bottom: 0.8rem; background: #fff; }
.document-category-grid ul { display: grid; gap: 0.45rem; margin: 0; padding: 0; list-style: none; }
.document-category-grid li:not(.empty) { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.document-category-grid a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem; }
.document-category-grid .empty { color: #94a3b8; font-size: 0.85rem; }
.document-category-grid .document-delete { flex: 0 0 auto; padding: 0.35rem 0.55rem; border-color: #fecaca; background: #fff5f5; color: #b42318; font-size: 0.75rem; }
#new-family-form:not(.hidden), #sibling-form:not(.hidden), #sibling-details:not(.hidden) {
    position: fixed;
    z-index: 10;
    top: 50%;
    left: 50%;
    width: min(52rem, calc(100vw - 2rem));
    max-height: calc(100dvh - 2rem);
    margin: 0;
    overflow: auto;
    transform: translate(-50%, -50%);
    box-shadow: 0 20px 48px #17203340;
}

@keyframes save-fill-pulse {
    0%, 100% {
        background-color: #b85f08;
        box-shadow: 0 2px 5px #92400e38;
    }
    50% {
        background-color: #f59e0b;
        box-shadow: 0 5px 14px #f59e0b80;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
    button.needs-saving { animation: none; }
}

@media (max-width: 1100px) {
    .toolbar { align-items: stretch; flex-direction: column; }
    .toolbar-context, .toolbar-actions { width: 100%; }
    .toolbar-actions { justify-content: flex-start; }
    .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
    .app-header { align-items: flex-start; flex-wrap: wrap; }
    .header-actions { width: 100%; margin-left: 0; flex-wrap: wrap; }
    .toolbar-context { align-items: stretch; flex-direction: column; }
    .toolbar-context > label:first-child, .search { width: 100%; }
    .editor-layout { grid-template-columns: 1fr; overflow-y: auto; }
    .person-sidebar { min-height: 15rem; max-height: 22rem; }
    .person-card { min-height: 30rem; overflow: visible; }
    .field-grid, .relationships, .document-category-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
    .header-actions { align-items: stretch; flex-direction: column; }
    .toolbar-actions button { flex: 1 1 calc(50% - 0.75rem); }
    .toolbar-actions button:last-of-type { margin-left: 0; }
    .autosave-note { display: none; }
    .person-label-id { font-size: 0.65rem; }
}
