:root {
  --green: #3d5a40;
  --green-dark: #2c432f;
  --cream: #f4efe6;
  --paper: #fffdf8;
  --gold: #c9a35b;
  --ink: #2b2b2b;
  --muted: #6f6a60;
  --line: #e3dccd;
  --danger: #a3402e;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(43, 43, 43, .08);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Source Sans 3', 'Segoe UI', Arial, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--cream); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--green); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; color: var(--green-dark); line-height: 1.15; margin: 0 0 .5em; }
h1 { font-size: 2.4rem; }
h2 { font-size: 1.7rem; }
h3 { font-size: 1.3rem; }
img { max-width: 100%; }

/* ---- Header / footer -------------------------------------------------------------- */
.site-header { background: var(--green); color: var(--cream); display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 24px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--cream); text-decoration: none; font-family: var(--serif); font-size: 1.5rem; font-weight: 600; }
.brand img { width: 34px; height: 34px; }
.main-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.main-nav a { color: var(--cream); text-decoration: none; padding: 6px 12px; border-radius: 6px; font-weight: 600; font-size: .95rem; }
.main-nav a:hover, .main-nav a.active { background: rgba(255,255,255,.12); }
.main-nav a.nav-muted { opacity: .7; font-weight: 400; }
.main-nav a.btn { background: var(--gold); color: var(--green-dark); }
.site-footer { margin-top: auto; text-align: center; color: var(--muted); font-size: .85rem; padding: 24px; }

/* ---- Layout ----------------------------------------------------------------------- */
.page { width: 100%; max-width: 1180px; margin: 0 auto; padding: 28px 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.muted { color: var(--muted); }
.notice { background: #fff6dd; border: 1px solid #ecd9a3; padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.notice.error { background: #fbe9e5; border-color: #e8b9ae; color: var(--danger); }
.notice.ok { background: #e7f1e6; border-color: #b8d3b5; color: var(--green-dark); }

/* ---- Buttons & forms -------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--green); color: #fff; border: 0; border-radius: 7px; padding: 9px 18px; font: 600 .95rem var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--green-dark); }
.btn-small { padding: 5px 12px; font-size: .85rem; }
.btn-light { background: #fff; color: var(--green-dark); border: 1px solid var(--line); }
.btn-light:hover { background: var(--cream); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #82311f; }
.btn:disabled { opacity: .55; cursor: default; }
label { display: block; font-weight: 600; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #cfc6b4; border-radius: 7px; background: #fff; font: 1rem var(--sans); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(61,90,64,.35); border-color: var(--green); }
textarea { min-height: 120px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 18px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-section { margin-bottom: 26px; }
.form-section h3 { border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 14px; }
.check-row { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); }
.status-choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.status-choice label { display: flex; align-items: center; gap: 12px; margin: 0; padding: 14px 16px; border: 2px solid var(--line); border-radius: var(--radius); background: #fff; cursor: pointer; color: var(--ink); font-size: 1rem; }
.status-choice label:has(input:checked) { border-color: var(--green); background: #f1f6f0; }
.status-choice input { width: 18px; height: 18px; accent-color: var(--green); flex-shrink: 0; }
.status-choice strong { display: block; }
.status-choice small { display: block; color: var(--muted); font-weight: 400; }
.badge.account { background: #e7f1e6; color: var(--green-dark); }
.badge.noemail { background: #f3ece0; color: #8a6d2e; }
.form-actions { display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap; }

/* ---- People directory ------------------------------------------------------------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar input[type=search] { max-width: 340px; }
.toolbar select { width: auto; }
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 18px; }
.person-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: inherit; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; display: flex; flex-direction: column; }
.person-card:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(43,43,43,.12); }
.person-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--line); }
.person-card .info { padding: 10px 12px 14px; }
.person-card .name { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; color: var(--green-dark); line-height: 1.15; }
.person-card .years { color: var(--muted); font-size: .88rem; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }

/* ---- Profile ---------------------------------------------------------------------- */
.profile-top { display: grid; grid-template-columns: 300px 1fr; gap: 28px; align-items: start; }
.profile-photo { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); border: 4px solid #fff; box-shadow: var(--shadow); background: var(--line); cursor: zoom-in; }
.profile-name { font-size: 2.6rem; margin-bottom: 2px; }
.profile-sub { color: var(--muted); font-size: 1.05rem; margin-bottom: 16px; }
.badge { display: inline-block; background: var(--line); color: var(--green-dark); border-radius: 20px; padding: 2px 10px; font-size: .8rem; font-weight: 700; margin-right: 6px; vertical-align: middle; }
.badge.memorial { background: #2b2b2b; color: #f4efe6; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 24px; margin: 0; }
.facts div { border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.facts dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.facts dd { margin: 0; font-size: 1.02rem; }
.profile-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0 0; }
.section { margin-top: 28px; }
.bio { white-space: pre-wrap; font-size: 1.05rem; }
.rel-group { margin-bottom: 14px; }
.rel-group h4 { margin: 0 0 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.rel-list { display: flex; flex-wrap: wrap; gap: 10px; }
.rel-chip { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 40px; padding: 4px 14px 4px 4px; text-decoration: none; color: var(--ink); font-weight: 600; }
.rel-chip img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.rel-chip small { color: var(--muted); font-weight: 400; display: block; font-size: .78rem; }
.rel-chip .x { margin-left: 6px; color: var(--danger); background: none; border: 0; cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0 2px; }

/* ---- Gallery ---------------------------------------------------------------------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.gallery figure { margin: 0; position: relative; background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; cursor: zoom-in; }
.gallery figcaption { font-size: .82rem; padding: 6px 8px; color: var(--muted); min-height: 30px; }
.gallery .is-main { position: absolute; top: 6px; left: 6px; background: var(--gold); color: var(--green-dark); font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 10px; }
.gallery .photo-tools { display: flex; gap: 4px; padding: 0 6px 6px; flex-wrap: wrap; }
.gallery .photo-tools button { font-size: .75rem; padding: 3px 8px; }
.dropzone { border: 2px dashed #cfc6b4; border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); margin-bottom: 14px; cursor: pointer; transition: background .15s, border-color .15s; }
.dropzone.over { background: #fff; border-color: var(--green); color: var(--green); }
.upload-progress { font-size: .9rem; color: var(--muted); margin-bottom: 10px; }

/* ---- Lightbox & modal ------------------------------------------------------------- */
.lightbox { position: fixed; inset: 0; background: rgba(20,20,20,.88); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 30px; flex-direction: column; }
.lightbox.open { display: flex; }
.lightbox img { max-height: 82vh; max-width: 92vw; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.lightbox .cap { color: #eee; margin-top: 12px; text-align: center; }
.lightbox .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.15); color: #fff; border: 0; font-size: 2rem; width: 52px; height: 52px; border-radius: 50%; cursor: pointer; }
.lightbox .prev { left: 18px; } .lightbox .next { right: 18px; }
.lightbox .close { position: absolute; top: 14px; right: 18px; background: none; border: 0; color: #fff; font-size: 2rem; cursor: pointer; }
.modal-back { position: fixed; inset: 0; background: rgba(20,20,20,.5); display: none; align-items: center; justify-content: center; z-index: 900; padding: 16px; }
.modal-back.open { display: flex; }
.modal { background: var(--paper); border-radius: var(--radius); width: 100%; max-width: 520px; padding: 22px; box-shadow: 0 12px 40px rgba(0,0,0,.25); max-height: 92vh; overflow: auto; }
.modal .row { margin-bottom: 12px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---- SweetAlert2 popups, matched to the site --------------------------------------- */
.swal2-popup.fam-swal { font-family: var(--sans); border-radius: var(--radius); background: var(--paper); }
.swal2-popup.fam-swal .swal2-title { font-family: var(--serif); color: var(--green-dark); font-weight: 600; }
.swal2-popup.fam-swal .swal2-html-container { color: var(--ink); }
.swal2-popup.fam-swal .swal2-styled { font-family: var(--sans); font-weight: 600; border-radius: 7px; }
.swal2-popup.fam-swal.swal2-toast .swal2-title { font-family: var(--sans); font-size: .95rem; color: var(--ink); }

/* ---- Login ------------------------------------------------------------------------ */
.login-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 30px 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { text-align: center; }
.login-card .row { margin-bottom: 14px; }

/* ---- Tree canvas (viewer + builder) ---------------------------------------------- */
body.tree-page { height: 100vh; overflow: hidden; }
body.tree-page .site-footer { display: none; }
.tree-layout { flex: 1; display: flex; min-height: 0; }
.tree-side { width: 270px; background: var(--paper); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tree-side .side-head { padding: 14px; border-bottom: 1px solid var(--line); }
.tree-side .side-head h3 { margin-bottom: 8px; }
.tree-side .side-list { flex: 1; overflow-y: auto; padding: 8px; }
.side-person { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: grab; user-select: none; border: 1px solid transparent; }
.side-person:hover { background: var(--cream); border-color: var(--line); }
.side-person img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; pointer-events: none; }
.side-person .nm { font-weight: 600; line-height: 1.15; }
.side-person .yr { font-size: .8rem; color: var(--muted); }
.side-person.on-canvas { opacity: .45; }
.side-person.on-canvas::after { content: "on tree"; margin-left: auto; font-size: .7rem; color: var(--muted); }
.side-help { font-size: .82rem; color: var(--muted); padding: 10px 14px; border-top: 1px solid var(--line); line-height: 1.4; }
.side-help b { color: var(--ink); }
.tree-main { flex: 1; position: relative; min-width: 0; }
.tree-viewport { position: absolute; inset: 0; overflow: hidden; background-color: #f7f3ea; background-image: radial-gradient(#ddd3bf 1px, transparent 1px); background-size: 22px 22px; cursor: grab; touch-action: none; }
.tree-viewport.panning { cursor: grabbing; }
.tree-viewport.drop-target { outline: 3px dashed var(--green); outline-offset: -6px; }
.tree-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.tree-lines { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.tree-lines path { fill: none; stroke: #8a7f69; stroke-width: 2.2; pointer-events: stroke; }
.tree-lines path.spouse { stroke: var(--gold); stroke-width: 3; }
.tree-lines path.hit { stroke: transparent; stroke-width: 14; cursor: pointer; }
.tree-lines path.selected { stroke: var(--danger); }
.tree-lines path.temp { stroke: var(--green); stroke-dasharray: 6 5; pointer-events: none; }
.tree-marquee { position: absolute; border: 2px dashed var(--green); background: rgba(61, 90, 64, .08); border-radius: 4px; pointer-events: none; z-index: 4; }
.tree-viewport.box-mode { cursor: crosshair; }
.btn.is-on { background: var(--green); color: #fff; border-color: var(--green); }
.arrange-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.arrange-grid .btn { font-size: .8rem; padding: 6px 8px; white-space: normal; line-height: 1.2; }
.tree-lines .bend-handle { fill: #fff; stroke: var(--danger); stroke-width: 3; pointer-events: all; cursor: ns-resize; }
.tree-lines .bend-handle:hover { fill: #fbe9e5; }
.style-picker { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.style-picker button { font-size: .78rem; padding: 4px 9px; }
.style-picker button.on { background: var(--green); color: #fff; border-color: var(--green); }
.tree-topbar select { width: auto; padding: 5px 8px; font-size: .85rem; border-radius: 7px; }
.tree-node { position: absolute; width: 130px; margin-left: -65px; text-align: center; user-select: none; cursor: pointer; }
.tree-node .ph { width: 86px; height: 86px; border-radius: 50%; object-fit: cover; border: 4px solid #fff; box-shadow: 0 3px 10px rgba(0,0,0,.18); background: var(--line); display: block; margin: 0 auto; pointer-events: none; }
.tree-node.female .ph { border-color: #f1dede; }
.tree-node.male .ph { border-color: #dde6f1; }
.tree-node.deceased .ph { filter: grayscale(.6); }
.tree-node .lbl { margin-top: 4px; background: rgba(255,253,248,.92); border-radius: 8px; padding: 2px 6px; display: inline-block; }
.tree-node .nm { font-family: var(--serif); font-weight: 700; font-size: 1.05rem; line-height: 1.1; color: var(--green-dark); }
.tree-node .yr { font-size: .78rem; color: var(--muted); }
.tree-node.selected .ph { box-shadow: 0 0 0 4px var(--gold), 0 3px 10px rgba(0,0,0,.2); }
.tree-node.link-target .ph { box-shadow: 0 0 0 4px var(--green), 0 3px 10px rgba(0,0,0,.2); }
.tree-node .handle { position: absolute; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; display: none; cursor: crosshair; box-shadow: 0 1px 4px rgba(0,0,0,.3); font-size: 12px; line-height: 18px; color: #fff; font-weight: 700; }
.tree-node .handle.parent { background: var(--green); top: -10px; left: 54px; }
.tree-node .handle.spouse { background: var(--gold); top: 32px; right: 8px; }
.editable .tree-node:hover .handle, .editable .tree-node.selected .handle { display: block; }
.editable .tree-node { cursor: move; }
.tree-controls { position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 6px; z-index: 5; }
.tree-controls button { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-size: 1.2rem; cursor: pointer; box-shadow: var(--shadow); }
.tree-topbar { position: absolute; left: 14px; top: 14px; right: 14px; display: flex; gap: 8px; align-items: center; z-index: 5; pointer-events: none; flex-wrap: wrap; }
.tree-topbar > * { pointer-events: auto; }
.tree-status { background: rgba(255,253,248,.95); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: .88rem; color: var(--muted); }
.tree-panel { position: absolute; top: 64px; right: 14px; width: 270px; z-index: 6; display: none; }
.tree-panel.open { display: block; }
.tree-panel img { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; float: left; margin-right: 12px; }
.tree-panel .nm { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; color: var(--green-dark); line-height: 1.1; }
.tree-panel .btns { clear: both; display: flex; flex-wrap: wrap; gap: 6px; padding-top: 12px; }
.tree-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; color: var(--muted); text-align: center; font-size: 1.1rem; padding: 20px; }

/* ---- Mobile ----------------------------------------------------------------------- */
@media (max-width: 800px) {
  .profile-top { grid-template-columns: 1fr; }
  .profile-photo { max-width: 300px; }
  .page { padding: 20px 16px; }
  h1, .profile-name { font-size: 2rem; }
  .tree-side { position: absolute; z-index: 8; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .tree-side.open { transform: none; }
  .tree-layout { position: relative; }
  .tree-panel { left: 14px; right: 14px; width: auto; }
}
@media (min-width: 801px) { .only-mobile { display: none !important; } }
