/* ============================================================ tokens */
:root {
  --bg: #f3f6f5; --surface: #fff; --card: #fff; --ink: #14343a; --muted: #62767a;
  --line: #e0e9e7; --line-strong: #9cc4bf; --brand: #0f7f7a; --brand-ink: #fff; --brand-soft: #e2f3f1;
  --accent: #e2705c; --male: #2f8fb5; --female: #e0678a; --other: #8a7bd1;
  --band: #eef5f4; --avatar-bg: #e3f1ef; --danger: #c0392b; --focus: #0f7f7a55;
  --shadow: 0 1px 2px rgba(20, 52, 58, .06), 0 6px 20px rgba(20, 52, 58, .07);
  --shadow-lg: 0 10px 40px rgba(20, 52, 58, .18);
  --radius: 14px;
  --topbar: 60px; --tabbar: 56px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1618; --surface: #132023; --card: #19292c; --ink: #e7f1ef; --muted: #8fa6a9;
    --line: #25383b; --line-strong: #3d6c6b; --brand: #35b3ac; --brand-ink: #062a29; --brand-soft: #16393a;
    --accent: #f08a76; --band: #122124; --avatar-bg: #1d3a3b; --danger: #ff7b6b; --focus: #35b3ac66;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

/* ============================================================== base */
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: .5; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
img:not([src]) { visibility: hidden; }

/* ============================================================ controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 11px; padding: 9px 16px; font-weight: 650; font-size: 14px; min-height: 40px; transition: background .15s, transform .05s; white-space: nowrap; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover:not(:disabled) { background: var(--brand-soft); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.sm { min-height: 32px; padding: 5px 11px; font-size: 13px; }
.btn.block { width: 100%; }
.danger-text { color: var(--danger) !important; }
.icon-btn { width: 40px; height: 40px; border-radius: 11px; border: 1px solid transparent; background: transparent; font-size: 20px; line-height: 1; display: inline-grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--brand-soft); color: var(--ink); }
.icon-btn.sm { width: 30px; height: 30px; font-size: 15px; }
.link-btn { background: none; border: 0; color: var(--brand); font-weight: 600; text-decoration: underline; padding: 8px; }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); border: 0; padding: 0; margin: 0; min-width: 0; }
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; min-height: 42px; color: var(--ink); font-weight: 450; width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 3px solid var(--focus); border-color: var(--brand); }
.field small { font-weight: 400; }
.field legend { padding: 0; margin-bottom: 5px; }
.req { color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; color: var(--muted); min-height: 30px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-error { color: var(--danger); font-size: 13px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-opt input { position: absolute; opacity: 0; pointer-events: none; }
.chip-opt span { display: inline-block; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; font-weight: 550; color: var(--ink); cursor: pointer; background: var(--surface); }
.chip-opt input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip-opt input:focus-visible + span { outline: 3px solid var(--focus); }

.seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--line); border-radius: 12px; }
.seg.scroll { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg.scroll::-webkit-scrollbar { display: none; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; font-weight: 600; font-size: 13.5px; color: var(--muted); white-space: nowrap; min-height: 34px; }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.menu-host { position: relative; }
.menu { position: absolute; top: calc(100% + 6px); left: 0; min-width: 230px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 60; }
.menu.right { left: auto; right: 0; }
.menu.up { top: auto; bottom: calc(100% + 6px); }
.menu button, .menu .menu-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; font-size: 14px; min-height: 40px; }
.menu button:hover:not(:disabled) { background: var(--brand-soft); }
.menu button.current { font-weight: 700; color: var(--brand); }
.menu-title { padding: 8px 12px 6px; display: flex; flex-direction: column; }
.menu-title small, .menu-sep { color: var(--muted); font-size: 12px; }
.menu-sep { padding: 8px 12px 2px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; font-size: 10.5px; border-top: 1px solid var(--line); margin-top: 4px; }
.menu-sep:empty { padding: 0; }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; opacity: 0; transition: .25s; z-index: 200; max-width: min(92vw, 520px); box-shadow: var(--shadow-lg); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind=error] { background: var(--danger); color: #fff; }

/* ============================================================ boot/auth */
.boot { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--bg); color: var(--muted); z-index: 300; text-align: center; padding: 20px; }
.boot svg { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); opacity: .8; } }
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1100px 500px at 50% -10%, var(--brand-soft), transparent), var(--bg); }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 26px; box-shadow: var(--shadow-lg); display: grid; gap: 16px; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand b { font-size: 21px; display: block; letter-spacing: -.02em; }
.auth-brand span { color: var(--muted); font-size: 13px; }
.auth-tabs { display: flex; } .auth-tabs button { flex: 1; }
#authForm { display: grid; gap: 13px; }
.auth-head h2 { font-size: 20px; letter-spacing: -.02em; }
.auth-head p { margin-top: 4px; font-size: 14px; }
.otp-input { text-align: center; font-size: 26px !important; letter-spacing: .5em; font-weight: 700 !important; }
.form-ok { color: var(--brand); font-size: 13px; font-weight: 600; }
.auth-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px; margin-top: -4px; }
.auth-links .link-btn { font-size: 13.5px; padding: 6px 2px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 12.5px; }
.auth-card .link-btn { justify-self: center; font-size: 13.5px; }

/* ============================================================== layout */
#app { height: 100dvh; display: flex; flex-direction: column; }
.topbar { height: calc(var(--topbar) + var(--safe-t)); padding: var(--safe-t) 14px 0; display: flex; align-items: center; gap: 14px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 30; flex: none; }
.brand { display: flex; align-items: center; gap: 9px; font-size: 17px; letter-spacing: -.02em; }
.title-block { display: flex; flex-direction: column; min-width: 0; padding-left: 14px; border-left: 1px solid var(--line); }
.title-line { display: flex; align-items: center; gap: 2px; min-width: 0; }
.title-block h1 { font-size: 18px; font-weight: 750; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-block .eyebrow { line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.search { display: flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 11px; padding: 0 10px; min-height: 40px; }
.search input { border: 0; background: transparent; outline: 0; width: 180px; min-width: 0; }
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus); }
.avatar-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink); font-weight: 750; font-size: 14px; }

.tabbar { display: flex; gap: 2px; margin-left: 8px; }
.tabbar button { display: flex; align-items: center; gap: 7px; border: 0; background: none; padding: 8px 14px; font-weight: 650; font-size: 14px; color: var(--muted); border-radius: 10px; }
.tabbar button:hover { background: var(--brand-soft); }
.tabbar button.active { color: var(--brand); background: var(--brand-soft); }
.tabbar .ti { font-size: 16px; }

main { flex: 1; min-height: 0; position: relative; }
.page { height: 100%; display: flex; flex-direction: column; min-height: 0; }
#pageAlbums, #pageAccess { overflow: auto; padding: 22px max(16px, calc((100% - 1000px) / 2)) 90px; display: block; }
.page-head { margin-bottom: 18px; }
.page-head h2 { font-size: 22px; letter-spacing: -.02em; }
.page-head p { color: var(--muted); margin-top: 3px; }

.view-bar { display: flex; align-items: center; gap: 14px; padding: 10px 14px; flex: none; flex-wrap: wrap; }
.kpis { display: flex; gap: 14px; margin-left: auto; color: var(--muted); font-size: 13px; }
.kpis b { color: var(--ink); font-size: 15px; }

/* ============================================================== canvas */
.stage-area { position: relative; flex: 1; min-height: 0; margin: 0 14px 14px; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: var(--surface); }
.stage-area:fullscreen { margin: 0; border-radius: 0; }
.viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
  background: radial-gradient(var(--line) 1px, transparent 1.2px) 0 0 / 24px 24px, var(--bg); }
.viewport.dragging { cursor: grabbing; }
.viewport:focus-visible { outline-offset: -3px; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.stage.anim { transition: transform .38s cubic-bezier(.2, .7, .2, 1); }
.links { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.link { fill: none; stroke: var(--line-strong); stroke-width: 2; stroke-linecap: round; }
.link.spouse { stroke: var(--accent); stroke-width: 2.5; }
.link.alt { stroke-dasharray: 6 5; opacity: .7; }
.join { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.band { position: absolute; background: var(--band); border-radius: 18px; pointer-events: none; }
.band-label { position: absolute; left: 16px; top: 11px; font-size: 12.5px; color: var(--muted); letter-spacing: .01em; }
.band-label b { color: var(--ink); font-size: 13.5px; }

.card { position: absolute; display: flex; align-items: center; gap: 11px; padding: 0 12px 0 16px; text-align: left; border: 1px solid var(--line); border-radius: 14px; background: var(--card); box-shadow: var(--shadow); overflow: hidden; transition: box-shadow .15s, transform .15s, opacity .2s; touch-action: none; }
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--other); }
.card.male::before { background: var(--male); } .card.female::before { background: var(--female); }
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.card.kin { border-color: var(--line-strong); }
.card.selected { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus), var(--shadow-lg); }
.card.dim { opacity: .22; }
.card .meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.card .name { font-size: 14.5px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .rel { font-style: normal; font-size: 12.5px; color: var(--brand); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .life { font-style: normal; font-size: 12px; color: var(--muted); white-space: nowrap; }
.card .count { position: absolute; top: 6px; right: 8px; font-size: 10.5px; font-weight: 700; background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 1px 7px; }

.photo { position: relative; display: block; flex: none; width: 52px; height: 52px; border-radius: 50%; overflow: hidden; background: var(--avatar-bg); }
.photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .8s ease; }
.photo img.on { opacity: 1; }
.photo .ini { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 750; color: var(--brand); font-size: 17px; transition: opacity .4s; }
.photo.has-photo .ini { opacity: 0; }
.photo.hero { width: 100%; height: 100%; border-radius: 0; }
.photo.hero .ini { font-size: 56px; }
.photo.cover { width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 14px 14px 0 0; }
.photo.cover .ini { font-size: 40px; }

.zoom-controls { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; z-index: 5; }
.zoom-controls button { width: 42px; height: 40px; border: 0; background: none; font-size: 18px; border-bottom: 1px solid var(--line); }
.zoom-controls button:last-child { border-bottom: 0; }
.zoom-controls button:hover { background: var(--brand-soft); }
.zoom-controls .fit { font-size: 12px; font-weight: 700; }
.canvas-hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 12.5px; color: var(--muted); pointer-events: none; transition: opacity .6s; white-space: nowrap; z-index: 4; }
.canvas-hint.faded { opacity: 0; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; text-align: center; gap: 12px; padding: 24px; z-index: 6; background: var(--bg); }
.empty p { color: var(--muted); max-width: 420px; }
.empty h2 { font-size: 22px; letter-spacing: -.02em; }

/* round portraits: Ancestors + Portrait views */
.links.pedigree .link.child { stroke: #2b3a3d; stroke-width: 3.5; }
.links.portrait .link.branch { stroke: #8a5a3c; stroke-width: 7; }
.links.portrait .link.spouse { stroke: var(--accent); stroke-width: 4; }
.bubble > * { flex: none; }
.bubble { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0; border: 0; background: none; color: inherit; touch-action: none; text-align: center; }
.bubble .photo { width: 76px; height: 76px; border: 4px solid var(--other); background: #fff; box-shadow: 0 3px 10px rgba(20, 52, 58, .22); transition: transform .15s, box-shadow .15s; }
.bubble.male .photo { border-color: var(--male); } .bubble.female .photo { border-color: var(--female); }
.bubble .ini { color: #0f7f7a; font-size: 24px; }
.bubble:hover .photo { transform: scale(1.06); }
.bubble.selected .photo { box-shadow: 0 0 0 4px var(--brand), 0 6px 18px rgba(0, 0, 0, .3); }
.bubble.dim { opacity: .25; }
.b-name { max-width: 100%; background: #fff; color: #14343a; border: 1px solid #d6dedc; border-radius: 999px; padding: 2px 10px; font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: var(--shadow); }
.b-rel { font-size: 11px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.ped-title { position: absolute; left: 16px; top: 12px; display: flex; flex-direction: column; font-size: 15px; background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; }
.ped-title small { color: var(--muted); font-size: 11.5px; }

/* =============================================================== lists */
.list-host { flex: 1; min-height: 0; overflow: auto; }
.list-page { padding: 4px 14px 90px; display: grid; gap: 14px; max-width: 1100px; margin: 0 auto; }
.list-page.timeline { grid-template-columns: minmax(260px, 340px) 1fr; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel h2, .panel h3 { font-size: 16px; margin-bottom: 12px; letter-spacing: -.01em; }
.panel.info p { margin: 6px 0 14px; }
.mini-row, .tl-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: 0; padding: 8px 6px; border-radius: 10px; }
.mini-row:hover, .tl-item:hover { background: var(--brand-soft); }
.mini-row .photo, .tl-item .photo { width: 40px; height: 40px; } .mini-row .ini, .tl-item .ini { font-size: 13px; }
.mini-row > span:nth-child(2), .tl-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.mini-row small, .tl-text small { color: var(--muted); font-size: 12.5px; }
.chip { font-size: 12px; font-weight: 700; background: var(--brand-soft); color: var(--brand); padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.chip.hot { background: var(--accent); color: #fff; }
.tl-year { font-size: 20px; color: var(--brand); margin: 14px 0 4px; letter-spacing: -.02em; }
.tl-year:first-of-type { margin-top: 0; }
.tl-item { border-left: 3px solid var(--line-strong); border-radius: 0 10px 10px 0; margin-left: 6px; }
.tl-item.death { border-left-color: var(--muted); }
.table-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.people-table { border-collapse: collapse; width: 100%; min-width: 760px; font-size: 14px; }
.people-table th { position: sticky; top: 0; background: var(--surface); text-align: left; border-bottom: 1px solid var(--line); z-index: 1; }
.people-table th button { background: none; border: 0; padding: 12px 12px; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); width: 100%; text-align: left; white-space: nowrap; }
.people-table th button.sorted { color: var(--brand); }
.people-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.people-table tbody tr { cursor: pointer; } .people-table tbody tr:hover { background: var(--brand-soft); }
.cell-person { display: flex; align-items: center; gap: 10px; }
.cell-person .photo { width: 34px; height: 34px; } .cell-person .ini { font-size: 12px; }

.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.album { border: 1px solid var(--line); background: var(--surface); border-radius: 14px; overflow: hidden; text-align: left; padding: 0; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; }
.album:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.album-meta { display: flex; flex-direction: column; padding: 10px 12px 12px; }
.album-meta small { color: var(--muted); }

.members { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.member { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.member:last-child { border-bottom: 0; }
.avatar-s { width: 38px; height: 38px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 750; flex: none; }
.m-info { display: flex; flex-direction: column; flex: 1; min-width: 140px; } .m-info small { color: var(--muted); }
.m-actions { display: flex; align-items: center; gap: 8px; }
.m-actions select { border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 6px 8px; min-height: 34px; }
.role-pill { font-size: 12px; font-weight: 700; padding: 3px 11px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); text-transform: capitalize; }
#accessHost { display: grid; gap: 16px; max-width: 760px; }
.invite-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.field.grow { flex: 1; min-width: 220px; }

/* =============================================================== profile */
.profile { position: fixed; top: calc(var(--topbar) + var(--safe-t)); right: 0; bottom: 0; width: 400px; max-width: 100%; background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg); z-index: 40; display: flex; flex-direction: column; transform: translateX(104%); transition: transform .24s cubic-bezier(.2, .7, .2, 1); }
.profile.open { transform: none; }
.p-head { position: absolute; top: 8px; right: 8px; z-index: 3; }
.p-head .icon-btn { background: rgba(0, 0, 0, .45); color: #fff; backdrop-filter: blur(6px); }
.p-hero { position: relative; height: 250px; flex: none; background: var(--avatar-bg); }
.p-thumbs { position: absolute; left: 0; right: 0; bottom: 8px; display: flex; justify-content: center; gap: 6px; }
.p-thumbs button { width: 10px; height: 10px; border-radius: 50%; padding: 0; border: 0; background: rgba(255, 255, 255, .65); box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); }
.p-thumbs button.active { background: #fff; transform: scale(1.35); }
.p-thumbs .play { width: auto; height: auto; border-radius: 999px; padding: 1px 8px; font-size: 11px; background: #fff; color: #000; }
.p-body { padding: 18px 20px; overflow: auto; flex: 1; }
.p-body h2 { font-size: 24px; letter-spacing: -.02em; }
.p-body .sub { color: var(--brand); font-weight: 650; margin-bottom: 14px; }
.facts { margin: 0 0 12px; display: grid; gap: 10px; }
.facts > div { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: start; }
.facts dt { color: var(--muted); font-size: 12.5px; font-weight: 600; padding-top: 4px; }
.facts dd { margin: 0; font-weight: 550; }
.rel-chip { display: inline-flex; align-items: baseline; gap: 6px; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 4px 11px; font-size: 13.5px; font-weight: 600; }
.rel-chip small { color: var(--muted); font-weight: 450; }
.rel-chip:hover { border-color: var(--brand); }
.notes { background: var(--bg); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; white-space: pre-wrap; }
.p-actions { display: flex; gap: 8px; padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); flex: none; align-items: center; }
.p-actions .menu-host { flex: 1; } .p-actions .menu-host .btn { width: 100%; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 35; }
.fab { position: fixed; right: 16px; bottom: calc(18px + var(--safe-b)); width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink); font-size: 28px; box-shadow: var(--shadow-lg); z-index: 25; display: none; }

/* =============================================================== dialogs */
.dialog { border: 0; padding: 0; border-radius: 20px; background: var(--surface); color: var(--ink); width: min(680px, 96vw); max-height: 94dvh; box-shadow: var(--shadow-lg); }
.dialog::backdrop { background: rgba(8, 24, 26, .55); backdrop-filter: blur(2px); }
.dialog.small { width: min(420px, 94vw); padding: 22px; }
.dialog.small h2 { font-size: 19px; margin-bottom: 8px; } .dialog.small p { color: var(--muted); margin-bottom: 18px; }
.dialog-actions, .dlg-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.dialog.small .field { margin-bottom: 18px; }
#pForm { display: flex; flex-direction: column; max-height: 94dvh; }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 20px 8px; }
.dlg-head h2 { font-size: 21px; letter-spacing: -.02em; }
.dlg-body { padding: 8px 20px 12px; overflow: auto; display: grid; gap: 18px; }
.dlg-actions { padding: 12px 20px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); }
.dlg-actions .form-error { margin-right: auto; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid .wide { grid-column: 1 / -1; }
.photo-manager { background: var(--bg); border: 1px dashed var(--line-strong); border-radius: 14px; padding: 12px; }
.pm-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.pm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.pm-empty { grid-column: 1 / -1; padding: 10px 0; text-align: center; }
.pm-item { position: relative; margin: 0; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--line); }
.pm-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pm-cover { position: absolute; top: 4px; left: 4px; font-size: 10px; font-weight: 700; background: var(--brand); color: var(--brand-ink); padding: 1px 7px; border-radius: 999px; }
.pm-item figcaption { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; background: linear-gradient(transparent, rgba(0, 0, 0, .65)); padding: 12px 2px 2px; }
.pm-item figcaption button { border: 0; background: none; color: #fff; font-size: 13px; width: 28px; height: 28px; }
.pm-item figcaption button:disabled { opacity: .3; }
.pm-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }

/* ============================================================ responsive */
@media (max-width: 1100px) { .search input { width: 120px; } }
@media (max-width: 820px) {
  :root { --topbar: 56px; }
  .brand b { display: none; }
  .title-block { border: 0; padding-left: 0; flex: 1; }
  .search { position: relative; width: 40px; padding: 0; justify-content: center; }
  .search input { position: absolute; inset: 0; width: 100%; opacity: 0; }
  .search:focus-within { position: fixed; left: 10px; right: 10px; top: calc(var(--safe-t) + 8px); z-index: 80; width: auto; justify-content: flex-start; padding: 0 12px; background: var(--surface); box-shadow: var(--shadow-lg); }
  .search:focus-within input { position: static; opacity: 1; }
  #addBtn { display: none; }
  .fab { display: grid; place-items: center; }
  .top-actions { gap: 4px; }
  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; justify-content: space-around; padding: 0 0 var(--safe-b); background: var(--surface); border-top: 1px solid var(--line); z-index: 50; }
  .tabbar button { flex-direction: column; gap: 1px; font-size: 11.5px; padding: 8px 18px; border-radius: 0; border-top: 3px solid transparent; flex: 1; align-items: center; }
  .tabbar button.active { border-top-color: var(--brand); background: none; }
  main { padding-bottom: calc(var(--tabbar) + var(--safe-b)); }
  .view-bar { padding: 8px 10px; gap: 8px; } .kpis { display: none; }
  .stage-area { margin: 0 8px 8px; border-radius: 14px; }
  .fab { bottom: calc(var(--tabbar) + var(--safe-b) + 16px); }
  .zoom-controls { bottom: 78px; right: 10px; } .zoom-controls button { width: 44px; height: 44px; }
  .zoom-controls .fs { display: none; }
  .canvas-hint { bottom: auto; top: 10px; }
  .profile { top: auto; left: 0; width: 100%; height: min(72dvh, 620px); border-left: 0; border-radius: 22px 22px 0 0; transform: translateY(104%); z-index: 60; }
  .profile.open { transform: none; }
  .p-hero { height: 190px; }
  .scrim { z-index: 55; }
  .list-page.timeline { grid-template-columns: 1fr; }
  #pageAlbums, #pageAccess { padding: 16px 14px 90px; }
  .grid { grid-template-columns: 1fr; }
  .dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  #pForm { max-height: 100dvh; height: 100%; }
  .dlg-body { flex: 1; }
  .album-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
@media print {
  .topbar, .tabbar, .fab, .profile, .zoom-controls, .view-bar { display: none !important; }
}
