/* genealogia record reader — tokens first, nothing raw outside this block */
:root {
  --bg: #e7ebe9; --card: #eef1ef; --surface: #e3e8e5; --line: rgba(31, 52, 45, .10);
  --text: #18221f; --muted: #52605b; --accent: #2a6a59; --accent-ink: #ffffff; --accent-soft: rgba(42, 106, 89, .12);
  --warn: #8a5a00; --warn-soft: rgba(196, 140, 20, .14); --danger: #a83a2e; --danger-soft: rgba(168, 58, 46, .10);
  --hi: rgba(255, 255, 255, .85); --lo: rgba(117, 140, 131, .35);
  --e1: 5px 5px 12px var(--lo), -5px -5px 12px var(--hi);
  --e2: 9px 9px 22px var(--lo), -9px -9px 22px var(--hi);
  --in: inset 3px 3px 7px var(--lo), inset -3px -3px 7px var(--hi);
  --ring: 0 0 0 3px rgba(42, 106, 89, .45);
  --ctl-h: 44px; --ctl-r: 12px; --ctl-fs: 16px; --ctl-px: 14px; --btn-px: 18px;
  --r-card: 20px; --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.16, 1, .3, 1);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1e1e1e; --card: #252526; --surface: #2d2d2d; --line: #3c3c3c;
  --text: #e8e8e8; --muted: #a6a6a6; --accent: #6cc3a9; --accent-ink: #121316; --accent-soft: rgba(108, 195, 169, .14);
  --warn: #e5b45c; --warn-soft: rgba(229, 180, 92, .12); --danger: #f08a7e; --danger-soft: rgba(240, 138, 126, .12);
  --hi: rgba(255, 255, 255, .035); --lo: rgba(0, 0, 0, .45);
  --e1: 0 2px 6px rgba(0, 0, 0, .35), inset 0 0 0 1px var(--line);
  --e2: 0 10px 28px rgba(0, 0, 0, .5), inset 0 0 0 1px var(--line);
  --in: inset 0 2px 4px rgba(0, 0, 0, .45), inset 0 0 0 1px var(--line);
  --ring: 0 0 0 3px rgba(108, 195, 169, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); }
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
a { color: var(--accent); }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.login-card { max-width: 420px; }
.row-ph { height: 72px; }
.stack.tight { gap: 10px; }
.m0 { margin: 0; }
h2.mt { margin-top: 22px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--ring); }
.ico { width: 20px; height: 20px; flex: none; }
.flag { width: 24px; height: 16px; border-radius: 3px; flex: none; box-shadow: 0 0 0 1px var(--line); }

#app { min-height: 100dvh; display: flex; flex-direction: column; max-width: 1080px; margin: 0 auto; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
#view { flex: 1 0 auto; outline: none; }

/* header */
.bar { position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; gap: 12px; padding: 12px 0; background: var(--bg); }
.brand { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: var(--ctl-h); color: var(--text); text-decoration: none; font-weight: 700; font-size: 18px; }
.brand .ico { width: 26px; height: 26px; color: var(--accent); }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-actions { display: flex; flex-wrap: nowrap; gap: 10px; flex: 0 0 auto; }
.bar-actions > * { flex: 0 0 auto; }
.lang { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 1001; min-width: 168px; padding: 6px; border-radius: 14px; background: var(--card); box-shadow: var(--e2); }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: var(--ctl-h); padding: 0 12px; border: 0; border-radius: 10px; background: none; color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.menu button:hover, .menu button[aria-current="true"] { background: var(--accent-soft); }

/* controls: one system, one height */
.ctl { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--ctl-h); min-width: var(--ctl-h); padding: 0 var(--btn-px); border: 0; border-radius: var(--ctl-r); background: var(--card); color: var(--text); box-shadow: var(--e1); font: 600 var(--ctl-fs)/1 var(--font); white-space: nowrap; cursor: pointer; text-decoration: none; transition: box-shadow .18s var(--ease), transform .18s var(--ease), background-color .18s var(--ease); }
.ctl:hover { transform: translateY(-1px); box-shadow: var(--e2); }
.ctl:active { transform: none; box-shadow: var(--in); }
.ctl:focus-visible, .ctl:has(input:focus-visible) { box-shadow: var(--e1), var(--ring); }
.ctl.icon { padding: 0; width: var(--ctl-h); }
.ctl.primary { background: var(--accent); color: var(--accent-ink); }
.ctl.danger { color: var(--danger); }
.ctl.danger-fill { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .ctl.danger-fill { color: #121316; }
.ctl[disabled] { opacity: .55; cursor: progress; transform: none; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; color: var(--muted); }
input, select, textarea { width: 100%; height: var(--ctl-h); padding: 0 var(--ctl-px); border: 0; border-radius: var(--ctl-r); background: var(--surface); color: var(--text); box-shadow: var(--in); font: 400 var(--ctl-fs)/1.2 var(--font); }
select { appearance: none; -webkit-appearance: none; padding-right: 40px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%2378857f' stroke-width='2' stroke-linecap='round' d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; text-overflow: ellipsis; }
input:focus-visible, select:focus-visible { box-shadow: var(--in), var(--ring); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 12px; }

/* cards */
.card { background: var(--card); border-radius: var(--r-card); padding: 20px; box-shadow: var(--e2); min-width: 0; }
h1 { font-size: clamp(24px, 4vw, 30px); line-height: 1.15; margin: 8px 0 6px; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0 0 14px; }
.lead { color: var(--muted); margin: 0 0 20px; max-width: 60ch; }
.muted { color: var(--muted); font-size: 14px; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }

/* upload */
.drop { container-type: inline-size; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 28px 16px; border-radius: 16px; box-shadow: var(--in); background: var(--surface); text-align: center; transition: background-color .18s var(--ease); }
.drop.on { background: var(--accent-soft); }
.drop .row-actions { justify-content: center; }
@container (max-width: 300px) { .drop .ctl { padding: 0 12px; gap: 6px; } .drop .ctl .ico { display: none; } }
.drop p { margin: 0; color: var(--muted); font-size: 14px; }
.row-actions { display: flex; flex-wrap: nowrap; gap: 10px; align-items: center; }
.row-actions > * { flex: 0 0 auto; }
.row-actions .push { margin-left: auto; }

/* list */
.docs { list-style: none; margin: 0; padding: 0; }
.doc { display: flex; align-items: center; gap: 14px; min-height: 72px; padding: 10px 8px; border-radius: 14px; color: var(--text); text-decoration: none; }
.doc + .doc { margin-top: 4px; }
.doc:hover { background: var(--accent-soft); }
.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); flex: none; }
.doc-main { flex: 1 1 auto; min-width: 0; }
.doc-title { font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; line-height: 1.3; }
.pill { flex: none; display: inline-flex; align-items: center; gap: 6px; max-width: 46%; padding: 4px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--surface); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.s-extracted { background: var(--warn-soft); color: var(--warn); }
.s-applied { background: var(--accent-soft); color: var(--accent); }
.s-error { background: var(--danger-soft); color: var(--danger); }
.s-uploading, .s-queued, .s-processing { color: var(--muted); }
.s-processing::before, .s-uploading::before { animation: pulse 1.2s var(--ease) infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px 8px; text-align: center; color: var(--muted); }
.empty .ico { width: 40px; height: 40px; color: var(--accent); }

/* steps (signature element) */
.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 0 0 18px; padding: 0; list-style: none; counter-reset: s; }
.steps li { position: relative; padding-top: 12px; font-size: 13px; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.steps li::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 5px; border-radius: 5px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.steps li.done { color: var(--text); }
.steps li.done::before { background: var(--accent); box-shadow: none; }
.steps li.now { color: var(--text); font-weight: 600; }
.steps li.now::before { background: linear-gradient(90deg, var(--accent) 50%, var(--surface) 50%); }

/* detail */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: stretch; }
.pages-in { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 12px; }
.pages img { width: 100%; height: auto; border-radius: 12px; box-shadow: inset 0 0 0 1px var(--line); background: var(--surface); }
.page-ph { aspect-ratio: 3 / 4; border-radius: 12px; background: var(--surface); }
.panel { display: flex; flex-direction: column; container-type: inline-size; }
@container (max-width: 400px) { .actions-bar .ctl.danger { width: var(--ctl-h); padding: 0; } .actions-bar .ctl.danger span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); } }
.person { margin-top: 14px; padding: 16px; border-radius: 16px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.person-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.role { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.person .grid2 + .grid2, .person .grid2 + .field, .person .field + .grid2 { margin-top: 10px; }
.match { margin-top: 12px; }
.note { display: flex; gap: 10px; padding: 12px 14px; border-radius: 14px; font-size: 14px; }
.note .ico { margin-top: 1px; }
.note ul { margin: 0; padding-left: 18px; }
.note.warn { background: var(--warn-soft); color: var(--text); }
.note.warn .ico { color: var(--warn); }
.note.err { background: var(--danger-soft); }
.note.err .ico { color: var(--danger); }
.actions-bar { margin-top: auto; padding-top: 18px; }
.log { list-style: none; margin: 0; padding: 0; }
.log li { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px; min-width: 0; }
.log li:first-child { border-top: 0; }
.log .ico { width: 16px; height: 16px; color: var(--accent); align-self: center; }
.log span { min-width: 0; overflow-wrap: anywhere; }
.top-actions { display: flex; flex-wrap: nowrap; align-items: center; gap: 10px; margin: 4px 0 16px; }
.top-actions h1 { flex: 1 1 auto; min-width: 0; margin: 0; font-size: clamp(20px, 3.4vw, 26px); overflow-wrap: anywhere; }

.loading { height: 40vh; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 3000; transform: translate(-50%, 12px); max-width: min(92vw, 480px); padding: 12px 18px; border-radius: 14px; background: var(--text); color: var(--bg); font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s var(--ease), transform .2s var(--ease); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.modal { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, .28); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.modal-card { width: min(420px, 100%); }
.modal-card p { margin: 0 0 18px; font-size: 17px; }
.modal-card .row-actions { justify-content: flex-end; }
.update { position: fixed; top: 0; left: 0; right: 0; z-index: 3000; display: flex; align-items: center; justify-content: center; gap: 14px; padding: 8px 16px; background: var(--card); box-shadow: var(--e2); font-size: 15px; }

@media (max-width: 760px) {
  .detail { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 16px; }
}
@media (max-width: 440px) {
  .bar-actions { gap: 8px; }
  .row-actions .ctl { padding: 0 14px; }
}
@media (max-width: 360px) { .brand-name { display: none; } }
@media (pointer: coarse) { input, select, textarea { font-size: 16px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
