:root {
    --ink: #24332f;
    --ink-soft: #5d6c67;
    --forest: #325c51;
    --forest-dark: #24473f;
    --sage: #dfe9e3;
    --sage-light: #edf3ef;
    --cream: #f7f3ec;
    --paper: #fffdf9;
    --gold: #d8a85e;
    --rose: #a94f4f;
    --line: rgba(50, 92, 81, .16);
    --shadow: 0 18px 55px rgba(37, 54, 49, .12);
    --shadow-small: 0 8px 25px rgba(37, 54, 49, .10);
    --radius: 24px;
    --radius-small: 15px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: var(--cream); }
body {
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 15% 0%, rgba(216,168,94,.12), transparent 24rem),
        linear-gradient(180deg, #faf7f1, var(--cream));
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
body.sheet-open { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
.icon { width: 1.25em; height: 1.25em; flex: 0 0 auto; }

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.12; letter-spacing: -.035em; }
h1 { font-size: clamp(2.2rem, 7vw, 4.5rem); margin-bottom: .6rem; }
h2 { font-size: clamp(1.45rem, 4vw, 2.25rem); margin-bottom: .5rem; }
h3 { font-size: 1.15rem; }
.eyebrow { display: block; color: var(--forest); font-size: .76rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; margin-bottom: .45rem; }
.muted { color: var(--ink-soft); }
.centered { text-align: center; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    min-height: calc(70px + var(--safe-top));
    padding: calc(10px + var(--safe-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(250, 247, 241, .86);
    backdrop-filter: blur(18px) saturate(1.3);
    border-bottom: 1px solid rgba(50, 92, 81, .09);
}
.brand, .auth-brand { display: inline-flex; align-items: center; gap: .75rem; text-decoration: none; font-weight: 800; letter-spacing: -.02em; }
.brand-mark { width: 43px; height: 43px; border-radius: 15px; background: var(--forest); color: white; display: grid; place-items: center; box-shadow: 0 7px 18px rgba(50,92,81,.22); }
.brand-mark.large { width: 62px; height: 62px; border-radius: 22px; }
.brand-mark .icon { width: 25px; height: 25px; }
.top-actions { display: flex; gap: .45rem; }
.icon-button {
    border: 0;
    width: 43px;
    height: 43px;
    border-radius: 14px;
    background: rgba(255,255,255,.72);
    color: var(--forest);
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    text-decoration: none;
    box-shadow: inset 0 0 0 1px rgba(50,92,81,.10);
}
.icon-button:hover { background: white; box-shadow: var(--shadow-small); }
.icon-button.danger { color: var(--rose); }

.button {
    min-height: 46px;
    border: 0;
    border-radius: 14px;
    padding: .72rem 1.05rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    text-decoration: none;
    font-weight: 750;
    cursor: pointer;
    transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { color: white; background: var(--forest); box-shadow: 0 10px 24px rgba(50,92,81,.23); }
.button.primary:hover { background: var(--forest-dark); }
.button.secondary { color: var(--forest); background: var(--sage-light); box-shadow: inset 0 0 0 1px rgba(50,92,81,.10); }
.button.ghost { color: var(--forest); background: transparent; }
.button.danger { color: white; background: var(--rose); }
.button.small { min-height: 38px; padding: .52rem .78rem; font-size: .86rem; }
.button.wide { width: 100%; }
.button:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.flash-stack { position: fixed; z-index: 100; top: calc(78px + var(--safe-top)); right: 1rem; left: 1rem; display: grid; gap: .6rem; pointer-events: none; }
.flash { max-width: 34rem; margin-left: auto; pointer-events: auto; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .9rem 1rem; border-radius: 15px; box-shadow: var(--shadow); background: white; border: 1px solid var(--line); }
.flash-success { border-left: 5px solid var(--forest); }
.flash-error { border-left: 5px solid var(--rose); }
.flash button { background: none; border: 0; color: inherit; display: grid; place-items: center; cursor: pointer; }

.page-shell, .home-shell, .person-shell, .tree-shell { width: min(1180px, calc(100% - 28px)); margin: 0 auto; }
.page-shell, .home-shell { padding: 2.5rem 0 4rem; }
.page-heading { margin-bottom: 2rem; }
.page-heading p { color: var(--ink-soft); max-width: 44rem; }
.split-heading { display: flex; justify-content: space-between; gap: 1.25rem; align-items: flex-start; }
.back-link { display: inline-flex; align-items: center; gap: .35rem; color: var(--forest); font-weight: 700; text-decoration: none; margin-bottom: 1.5rem; }
.back-link .icon { transform: rotate(0); }

/* Access and login */
.access-page, .auth-page { background: var(--forest); color: white; }
.access-shell, .auth-shell { min-height: calc(100vh - 55px); padding: max(24px, var(--safe-top)) 18px max(40px, var(--safe-bottom)); display: grid; place-items: center; }
.access-card, .auth-card { width: min(100%, 540px); color: var(--ink); background: var(--paper); border-radius: 32px; padding: clamp(1.5rem, 6vw, 3rem); box-shadow: 0 35px 90px rgba(10,24,20,.3); }
.access-card { text-align: center; }
.access-card > p { color: var(--ink-soft); font-size: 1.05rem; }
.access-card > small { display: block; color: var(--ink-soft); margin-top: 1.25rem; }
.access-illustration { width: 150px; height: 100px; margin: 0 auto 1rem; position: relative; }
.access-illustration > span { width: 64px; height: 64px; border-radius: 23px; background: var(--sage); color: var(--forest); display: grid; place-items: center; margin: auto; position: relative; z-index: 2; }
.access-illustration .icon { width: 35px; height: 35px; }
.access-illustration i { position: absolute; width: 24px; height: 24px; border-radius: 50%; background: var(--gold); opacity: .72; }
.access-illustration i:nth-child(2) { left: 0; bottom: 0; }
.access-illustration i:nth-child(3) { left: 38px; bottom: -3px; background: var(--forest); }
.access-illustration i:nth-child(4) { right: 38px; bottom: -3px; background: #90afa4; }
.access-illustration i:nth-child(5) { right: 0; bottom: 0; background: var(--gold); }
.access-form { margin-top: 1.5rem; text-align: left; }
.access-form > label { font-weight: 700; display: block; margin-bottom: .45rem; }
.access-form > div { display: flex; gap: .6rem; }
.access-form input { min-width: 0; flex: 1; text-transform: uppercase; letter-spacing: .08em; }
.auth-shell { align-content: center; gap: 1.5rem; }
.auth-brand { color: white; }
.auth-card h1 { font-size: 2.4rem; }
.notice { padding: 1rem; border-radius: 14px; background: #f5e5e2; color: #7c3c35; margin-top: 1.5rem; }

/* Forms */
.stack-form { display: grid; gap: 1rem; }
.stack-form label, .access-form label { font-weight: 700; color: var(--ink); }
.stack-form label small { color: var(--ink-soft); font-weight: 500; }
input, textarea, select {
    width: 100%;
    border: 1px solid rgba(50,92,81,.18);
    border-radius: 13px;
    background: white;
    color: var(--ink);
    padding: .82rem .9rem;
    outline: none;
    margin-top: .38rem;
    transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--forest); box-shadow: 0 0 0 4px rgba(50,92,81,.10); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.form-note { color: var(--ink-soft); font-size: .84rem; margin: -.2rem 0 0; }
.switch-row { display: flex !important; align-items: flex-start; gap: .8rem; border-radius: 15px; padding: 1rem; background: var(--sage-light); cursor: pointer; }
.switch-row input { width: 22px; height: 22px; margin: 0; accent-color: var(--forest); }
.switch-row span { display: grid; gap: .12rem; }
.switch-row small { color: var(--ink-soft); }

/* Home */
.welcome-card { position: relative; overflow: hidden; min-height: 390px; display: grid; grid-template-columns: 1.2fr .8fr; align-items: center; gap: 2rem; padding: clamp(1.6rem, 5vw, 4rem); color: white; background: var(--forest); border-radius: 34px; box-shadow: var(--shadow); }
.welcome-card:before { content: ""; position: absolute; width: 30rem; height: 30rem; right: -15rem; top: -16rem; border-radius: 50%; background: rgba(255,255,255,.08); }
.welcome-copy { position: relative; z-index: 2; }
.welcome-copy .eyebrow { color: #d9e9e2; }
.welcome-copy h1 { max-width: 12ch; }
.welcome-copy p { max-width: 42rem; color: rgba(255,255,255,.8); font-size: 1.08rem; }
.welcome-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.5rem; }
.welcome-card .button.primary { background: white; color: var(--forest); box-shadow: none; }
.welcome-card .button.secondary { background: rgba(255,255,255,.12); color: white; box-shadow: inset 0 0 0 1px rgba(255,255,255,.17); }
.welcome-tree { min-height: 240px; position: relative; display: grid; place-items: center; }
.welcome-tree span { width: 105px; height: 105px; display: grid; place-items: center; border-radius: 38px; background: rgba(255,255,255,.12); position: relative; z-index: 2; }
.welcome-tree .icon { width: 58px; height: 58px; }
.welcome-tree i { position: absolute; width: 54px; height: 54px; border-radius: 20px; background: var(--gold); box-shadow: 0 12px 25px rgba(0,0,0,.12); }
.welcome-tree i:nth-child(2) { left: 2%; top: 15%; }
.welcome-tree i:nth-child(3) { right: 2%; top: 12%; background: #90afa4; }
.welcome-tree i:nth-child(4) { left: 12%; bottom: 5%; background: #d8e1dc; }
.welcome-tree i:nth-child(5) { right: 12%; bottom: 4%; background: #c58172; }
.welcome-tree i:nth-child(6) { left: 50%; top: 0; width: 40px; height: 40px; border-radius: 15px; background: #d8e1dc; }
.home-section { padding-top: 3.2rem; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.section-heading h2 { margin-bottom: 0; }
.people-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.featured-person { display: flex; align-items: center; gap: 1rem; padding: 1rem; background: rgba(255,255,255,.62); border-radius: var(--radius); border: 1px solid var(--line); }
.featured-person .person-card { flex: 1; }
.featured-person .button .icon { transform: rotate(180deg); }
.privacy-note { margin-top: 3.5rem; border-radius: var(--radius); padding: 1.2rem; display: flex; gap: 1rem; background: var(--sage-light); color: var(--forest-dark); }
.privacy-note > .icon { width: 26px; height: 26px; margin-top: .1rem; }
.privacy-note p { margin: .2rem 0 0; color: var(--ink-soft); }

/* Cards */
.person-card { min-width: 0; display: flex; align-items: center; gap: .9rem; padding: .82rem; border-radius: 19px; background: rgba(255,255,255,.82); border: 1px solid rgba(50,92,81,.10); text-decoration: none; box-shadow: 0 7px 24px rgba(37,54,49,.06); transition: transform .18s, box-shadow .18s, border-color .18s; }
.person-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-small); border-color: rgba(50,92,81,.22); }
.person-photo { width: 68px; height: 68px; flex: 0 0 auto; border-radius: 20px; overflow: hidden; position: relative; background: var(--sage); display: grid; place-items: center; }
.person-photo img { width: 100%; height: 100%; object-fit: cover; }
.person-initials { color: var(--forest); font-size: 1.25rem; font-weight: 850; letter-spacing: .03em; }
.photo-count { position: absolute; right: 3px; bottom: 3px; display: flex; align-items: center; gap: 2px; border-radius: 8px; padding: 2px 5px; background: rgba(25,39,35,.78); color: white; font-size: .64rem; }
.photo-count .icon { width: 11px; }
.person-card-copy { min-width: 0; display: grid; gap: .15rem; }
.person-card-copy strong { overflow: hidden; text-overflow: ellipsis; }
.person-card-copy small { color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-card.featured { background: white; }
.empty-relation { min-height: 94px; display: flex; align-items: center; gap: .8rem; padding: 1rem; border: 1px dashed rgba(50,92,81,.28); border-radius: 18px; color: var(--ink-soft); }
.empty-icon { width: 50px; height: 50px; border-radius: 16px; display: grid; place-items: center; background: var(--sage-light); color: var(--forest); }
.empty-state { text-align: center; padding: 2rem; border: 1px dashed rgba(50,92,81,.25); border-radius: var(--radius); color: var(--ink-soft); }
.empty-state.large { padding: 4rem 1.5rem; }
.empty-state > span { width: 64px; height: 64px; display: grid; place-items: center; margin: 0 auto 1rem; border-radius: 22px; background: var(--sage); color: var(--forest); }
.empty-state .icon { width: 34px; height: 34px; }

/* Person */
.person-shell { padding-bottom: 4rem; }
.person-hero { display: grid; grid-template-columns: minmax(320px, .85fr) 1.15fr; align-items: center; gap: clamp(2rem, 6vw, 5rem); padding: 2rem 0 3rem; }
.person-gallery { width: 100%; aspect-ratio: 1/1; position: relative; overflow: hidden; border-radius: 34px; background: var(--sage); box-shadow: var(--shadow); }
.person-gallery .slide { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transform: scale(1.025); transition: opacity .55s, transform .7s; }
.person-gallery .slide.active { opacity: 1; transform: scale(1); }
.hero-initials { height: 100%; display: grid; place-items: center; font-size: clamp(4rem, 14vw, 9rem); font-weight: 850; color: var(--forest); background: radial-gradient(circle at 30% 25%, white, var(--sage)); }
.slide-dots { position: absolute; z-index: 3; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; gap: 7px; padding: 7px; border-radius: 20px; background: rgba(20,31,28,.35); backdrop-filter: blur(8px); }
.slide-dots button { width: 7px; height: 7px; border: 0; border-radius: 50%; padding: 0; background: rgba(255,255,255,.55); }
.slide-dots button.active { width: 20px; border-radius: 8px; background: white; }
.camera-fab { position: absolute; z-index: 4; right: 18px; bottom: 18px; width: 54px; height: 54px; border: 0; border-radius: 18px; background: var(--forest); color: white; display: grid; place-items: center; cursor: pointer; box-shadow: 0 12px 30px rgba(26,47,41,.35); }
.camera-fab .icon { width: 25px; height: 25px; }
.person-title h1 { max-width: 12ch; }
.person-title .years { font-size: 1.25rem; color: var(--forest); font-weight: 700; }
.person-title .nickname { color: var(--ink-soft); }
.hero-actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.6rem; }
.relations-section { display: grid; gap: 1.3rem; }
.relation-block { background: rgba(255,255,255,.62); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1rem, 3vw, 1.5rem); }
.relation-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }
.round-add { width: 44px; height: 44px; border-radius: 15px; border: 0; display: grid; place-items: center; background: var(--forest); color: white; cursor: pointer; box-shadow: 0 8px 18px rgba(50,92,81,.20); }

/* Sheets and search */
.sheet, .search-sheet { position: fixed; z-index: 90; inset: 0; display: grid; align-items: end; }
.sheet-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(21,34,30,.48); backdrop-filter: blur(4px); cursor: pointer; }
.sheet-panel { position: relative; z-index: 2; width: min(100%, 680px); max-height: min(88vh, 850px); overflow: auto; margin: 0 auto; padding: .6rem clamp(1rem, 4vw, 2rem) calc(1.5rem + var(--safe-bottom)); border-radius: 30px 30px 0 0; background: var(--paper); box-shadow: 0 -20px 70px rgba(16,29,25,.22); animation: sheetIn .25s ease-out; }
@keyframes sheetIn { from { transform: translateY(35px); opacity: .6; } }
.sheet-handle { width: 44px; height: 5px; border-radius: 5px; background: rgba(36,51,47,.2); margin: .15rem auto 1rem; }
.sheet-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.sheet-heading h2 { margin-bottom: .25rem; }
.sheet-heading p { margin-bottom: 0; }
.search-input-wrap { display: flex; align-items: center; gap: .65rem; padding: 0 .9rem; border-radius: 16px; background: var(--sage-light); color: var(--forest); }
.search-input-wrap input { border: 0; margin: 0; padding-left: 0; background: transparent; box-shadow: none; }
.search-results { min-height: 130px; padding: 1rem 0; display: grid; gap: .6rem; }
.search-result { display: flex; align-items: center; gap: .8rem; text-decoration: none; padding: .7rem; border-radius: 15px; border: 1px solid var(--line); background: white; }
.search-avatar, .mini-avatar { width: 50px; height: 50px; border-radius: 15px; overflow: hidden; flex: 0 0 auto; display: grid; place-items: center; background: var(--sage); color: var(--forest); font-weight: 800; }
.search-avatar img, .mini-avatar img { width: 100%; height: 100%; object-fit: cover; }
.search-result span:nth-child(2) { min-width: 0; display: grid; }
.search-result small { color: var(--ink-soft); }
.duplicate-results { margin-top: .5rem; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; background: white; }
.duplicate-results:before { content: "Findes personen allerede?"; display: block; padding: .65rem .8rem .35rem; font-size: .75rem; font-weight: 800; color: var(--forest); text-transform: uppercase; letter-spacing: .08em; }
.duplicate-option { width: 100%; border: 0; border-top: 1px solid var(--line); padding: .7rem .8rem; background: white; display: flex; align-items: center; gap: .7rem; text-align: left; cursor: pointer; }
.duplicate-option:hover { background: var(--sage-light); }
.duplicate-option span { display: grid; }
.duplicate-option small { color: var(--ink-soft); }
.selected-existing { display: flex; justify-content: space-between; align-items: center; gap: .8rem; border-radius: 14px; background: var(--sage-light); padding: .85rem; color: var(--forest); font-weight: 700; }
.selected-existing button { border: 0; background: transparent; color: var(--forest); text-decoration: underline; cursor: pointer; }
.photo-picker { display: block; cursor: pointer; }
.photo-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.photo-picker > span { min-height: 150px; border: 2px dashed rgba(50,92,81,.28); border-radius: 20px; display: grid; place-items: center; align-content: center; gap: .35rem; color: var(--forest); background: var(--sage-light); text-align: center; padding: 1rem; }
.photo-picker .icon { width: 34px; height: 34px; }
.photo-picker small { color: var(--ink-soft); }
.photo-preview { display: grid; grid-template-columns: repeat(4, 1fr); gap: .55rem; }
.photo-preview img { aspect-ratio: 1; width: 100%; object-fit: cover; border-radius: 13px; }
.upload-status { display: flex; align-items: center; justify-content: center; gap: .7rem; color: var(--forest); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid rgba(50,92,81,.18); border-top-color: var(--forest); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Tree */
.tree-shell { width: min(1500px, 100%); padding: 1.4rem 0 3rem; }
.tree-toolbar { width: min(1180px, calc(100% - 28px)); margin: 0 auto 1rem; display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.tree-toolbar h1 { font-size: clamp(2rem, 5vw, 3.5rem); margin: 0; }
.tree-controls { display: flex; background: white; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow-small); }
.tree-controls button { min-width: 42px; height: 42px; border: 0; border-right: 1px solid var(--line); background: white; color: var(--forest); font-weight: 800; cursor: pointer; }
.tree-controls button:last-child { border-right: 0; }
.tree-help { width: min(1180px, calc(100% - 28px)); margin: 0 auto .8rem; color: var(--ink-soft); font-size: .85rem; }
.family-tree-viewport { height: calc(100vh - 205px); min-height: 520px; overflow: auto; overscroll-behavior: contain; background-color: rgba(255,255,255,.62); background-image: radial-gradient(rgba(50,92,81,.12) 1px, transparent 1px); background-size: 24px 24px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); position: relative; }
.tree-loading { height: 100%; display: grid; place-items: center; align-content: center; gap: .7rem; color: var(--forest); }
.tree-stage { position: relative; transform-origin: top left; min-width: 100%; min-height: 100%; transition: transform .15s ease; }
.tree-lines { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.tree-lines path { fill: none; stroke: rgba(50,92,81,.42); stroke-width: 2; vector-effect: non-scaling-stroke; }
.tree-lines path.partner { stroke: rgba(169,79,79,.58); stroke-dasharray: 6 5; }
.tree-person { position: absolute; width: 190px; height: 108px; padding: .65rem; border-radius: 19px; background: rgba(255,253,249,.96); border: 1px solid rgba(50,92,81,.17); box-shadow: var(--shadow-small); display: grid; grid-template-columns: 54px 1fr; grid-template-rows: 1fr auto; gap: .25rem .65rem; }
.tree-person.focus { border: 2px solid var(--forest); box-shadow: 0 16px 40px rgba(50,92,81,.20); }
.tree-person-main { grid-row: 1 / 3; grid-column: 1 / 3; border: 0; background: none; padding: 0 0 22px; display: grid; grid-template-columns: 54px 1fr; gap: .65rem; text-align: left; cursor: pointer; color: inherit; }
.tree-person-avatar { width: 54px; height: 54px; border-radius: 16px; background: var(--sage); display: grid; place-items: center; overflow: hidden; color: var(--forest); font-weight: 850; }
.tree-person-avatar img { width: 100%; height: 100%; object-fit: cover; }
.tree-person-copy { min-width: 0; display: grid; align-content: center; }
.tree-person-copy strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-person-copy small { color: var(--ink-soft); }
.tree-profile-link { position: absolute; right: .65rem; bottom: .55rem; font-size: .73rem; color: var(--forest); font-weight: 750; text-decoration: none; }
.tree-role { position: absolute; left: .65rem; bottom: .55rem; font-size: .65rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .07em; }

/* Admin */
.admin-page { background: #f3f1eb; }
.admin-shell { max-width: 1250px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.stat-grid article { padding: 1.3rem; border-radius: var(--radius); background: var(--forest); color: white; display: grid; }
.stat-grid strong { font-size: 2.3rem; line-height: 1; }
.stat-grid span { color: rgba(255,255,255,.72); }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1rem, 3vw, 1.5rem); box-shadow: 0 8px 30px rgba(37,54,49,.05); }
.panel h2 { font-size: 1.45rem; }
.admin-wide { grid-column: 1 / -1; }
.qr-panel { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto; gap: 2rem; align-items: center; }
.qr-box { min-width: 210px; min-height: 210px; background: white; padding: 12px; border-radius: 18px; box-shadow: inset 0 0 0 1px var(--line); display: grid; place-items: center; }
.qr-box canvas, .qr-box img { max-width: 190px; }
.copy-field { display: flex; gap: .5rem; margin: 1rem 0; }
.copy-field input { margin: 0; }
.admin-person-table { display: grid; grid-template-columns: repeat(2, 1fr); gap: .55rem; }
.admin-person-table > a { min-width: 0; display: grid; grid-template-columns: 50px 1fr auto; align-items: center; gap: .75rem; padding: .65rem; border-radius: 16px; text-decoration: none; border: 1px solid var(--line); }
.admin-person-table > a:hover { background: var(--sage-light); }
.admin-person-table > a > span:nth-child(2) { min-width: 0; display: grid; }
.admin-person-table strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-person-table small { color: var(--ink-soft); }
.admin-list { display: grid; gap: .5rem; margin-bottom: 1rem; }
.admin-list-item { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .65rem .75rem; border-radius: 13px; background: var(--sage-light); }
.admin-photo-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .8rem; }
.admin-photo-grid figure { margin: 0; position: relative; }
.admin-photo-grid img { aspect-ratio: 1; object-fit: cover; width: 100%; border-radius: 16px; }
.admin-photo-grid form { position: absolute; right: 6px; bottom: 6px; }
.danger-zone { border-color: rgba(169,79,79,.25); }
.correction-list { display: grid; gap: .8rem; }
.correction-list article { border-radius: 16px; padding: 1rem; background: var(--sage-light); }
.correction-list article > div { display: flex; justify-content: space-between; gap: 1rem; }
.correction-list time { font-size: .78rem; color: var(--ink-soft); }
.inline-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.inline-actions input { width: auto; flex: 1 1 220px; margin: 0; }
.activity-list { display: grid; }
.activity-list > div { display: grid; grid-template-columns: 150px 1fr 120px; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--line); font-size: .86rem; }
.activity-list time, .activity-list span { color: var(--ink-soft); }

.site-footer { min-height: 55px; display: flex; align-items: center; justify-content: center; gap: 1rem; padding: 1rem 16px calc(1rem + var(--safe-bottom)); color: var(--ink-soft); font-size: .78rem; }
.site-footer a { color: inherit; }
.access-page .site-footer, .auth-page .site-footer { color: rgba(255,255,255,.65); }

@media (max-width: 950px) {
    .people-grid { grid-template-columns: repeat(2, 1fr); }
    .relation-grid { grid-template-columns: repeat(2, 1fr); }
    .person-hero { grid-template-columns: minmax(280px, .8fr) 1fr; gap: 2.5rem; }
    .admin-photo-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 720px) {
    h1 { font-size: clamp(2.15rem, 11vw, 3.3rem); }
    .topbar { min-height: calc(64px + var(--safe-top)); }
    .brand-mark { width: 40px; height: 40px; border-radius: 14px; }
    .brand > span:last-child { max-width: 48vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .page-shell, .home-shell, .person-shell { width: min(100% - 22px, 1180px); }
    .home-shell { padding-top: 1rem; }
    .welcome-card { min-height: 480px; grid-template-columns: 1fr; align-content: space-between; padding: 1.5rem; border-radius: 27px; }
    .welcome-tree { min-height: 170px; order: -1; }
    .welcome-tree span { width: 80px; height: 80px; border-radius: 28px; }
    .welcome-tree .icon { width: 44px; }
    .welcome-tree i { width: 42px; height: 42px; border-radius: 15px; }
    .home-section { padding-top: 2.3rem; }
    .people-grid { grid-template-columns: 1fr; }
    .featured-person { display: grid; }
    .person-hero { grid-template-columns: 1fr; gap: 1.7rem; padding-top: 1rem; }
    .person-gallery { border-radius: 27px; }
    .person-title { padding: 0 .35rem; }
    .person-title h1 { max-width: none; }
    .hero-actions { display: grid; grid-template-columns: 1fr; }
    .relation-grid { grid-template-columns: 1fr; }
    .relation-block { border-radius: 21px; }
    .field-row { grid-template-columns: 1fr 1fr; }
    .photo-preview { grid-template-columns: repeat(3, 1fr); }
    .split-heading { display: grid; }
    .admin-grid { grid-template-columns: 1fr; }
    .admin-wide, .qr-panel { grid-column: auto; }
    .qr-panel { grid-template-columns: 1fr; }
    .qr-box { width: 100%; }
    .stat-grid { gap: .55rem; }
    .stat-grid article { padding: 1rem .8rem; }
    .stat-grid strong { font-size: 1.8rem; }
    .stat-grid span { font-size: .75rem; }
    .admin-person-table { grid-template-columns: 1fr; }
    .admin-photo-grid { grid-template-columns: repeat(3, 1fr); }
    .activity-list > div { grid-template-columns: 1fr; gap: .1rem; }
    .tree-toolbar { align-items: center; }
    .tree-toolbar .eyebrow { display: none; }
    .tree-toolbar h1 { font-size: 1.65rem; }
    .family-tree-viewport { height: calc(100vh - 165px); min-height: 500px; }
}

@media (max-width: 430px) {
    .field-row { grid-template-columns: 1fr; }
    .access-form > div { display: grid; }
    .top-actions { gap: .25rem; }
    .icon-button { width: 40px; height: 40px; }
    .section-heading { align-items: center; }
    .person-photo { width: 62px; height: 62px; }
    .copy-field { display: grid; }
    .photo-preview, .admin-photo-grid { grid-template-columns: repeat(2, 1fr); }
    .inline-actions { display: grid; }
    .inline-actions input { width: 100%; }
    .tree-controls button { min-width: 38px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *:before, *:after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
.person-photo .card-photo-slide { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .55s ease; }
.person-photo .card-photo-slide.active { opacity: 1; }
.tree-person-avatar { position: relative; }
.tree-person-avatar .tree-avatar-slide { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .55s ease; }
.tree-person-avatar .tree-avatar-slide.active { opacity: 1; }
.tree-stage-wrapper { position: relative; margin: 0 auto; }
@media print {
    body.print-qr * { visibility: hidden !important; }
    body.print-qr .qr-panel, body.print-qr .qr-panel * { visibility: visible !important; }
    body.print-qr .qr-panel { position: absolute; inset: 0; width: 100%; display: grid; grid-template-columns: 1fr; place-items: center; border: 0; box-shadow: none; }
    body.print-qr .qr-panel > div:first-child { text-align: center; }
    body.print-qr .qr-panel .copy-field, body.print-qr .qr-panel .inline-actions, body.print-qr .qr-panel .muted { display: none !important; }
    body.print-qr .qr-box { width: 260px; height: 260px; }
    body.print-qr .qr-box canvas, body.print-qr .qr-box img { max-width: 235px; width: 235px; height: 235px; }
}
