/* Antenati Veneziani: the logged-in app.
   Main readers: older people looking for their ancestors, often on old
   phones. So: large type, high contrast, big tap targets (≥ 48 px), little
   text. It must look like the public landing page (landing/landing.css):
   same tokens, Manrope, same buttons and floating nav pill, in plain CSS.
   Avoid CSS that older Safari / Android browsers lack (flex `gap`,
   `aspect-ratio`, `:has`) on the list and account pages; backdrop-filter
   only as an enhancement over a solid background.

   Sections:
     1. TOKENS / BASE        shared: colours, font, headings, helpers
     2. HEADER               the floating nav pill (layout() / bare() in html.rs)
     3. BUTTONS, FORMS & CARDS  shared: .btn, .icon-btn, .form, .card, .msg
     4. LIST PAGES           parishes, types, books (html.rs)
     5. SEARCH               search box, results, drawer
     6. BOOK READER          body.reader
     7. ACCOUNT / ADMIN      login, account, user management (accounts.rs) */

/* ======================================================================
   1. TOKENS / BASE
   ====================================================================== */

/* Manrope 400/500/600: the landing's files, already public (/static/landing/). */
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 400; font-display: swap; src: url(/static/landing/manrope-400.woff2) format("woff2"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 500; font-display: swap; src: url(/static/landing/manrope-500.woff2) format("woff2"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 600; font-display: swap; src: url(/static/landing/manrope-600.woff2) format("woff2"); }

:root {
  /* Light: warm paper (same values as the landing). */
  --paper: #f7f4ee;          /* page background */
  --card: #ffffff;           /* cards, rows, inputs on paper */
  --raised: #ffffff;         /* surfaces above cards (menus, sheets) */
  --ink: #1b1915;            /* text */
  --muted: #5f5950;          /* secondary text */
  --line: #e3ddd2;           /* borders, dividers */
  --line-strong: #cbc3b5;    /* input borders: must be visible to older eyes */
  --accent: #8a2f1d;         /* rosso veneziano */
  --accent-hover: #73261a;
  --on-accent: #ffffff;      /* text on --accent */
  --accent-soft: rgba(138, 47, 29, .10);  /* tinted backgrounds, tags */
  --hover: rgba(27, 25, 21, .06);         /* ghost / icon button hover */
  --danger: #a3261f;
  --focus: #e0a526;          /* focus ring, as on the landing */
  --nav-bg: rgba(247, 244, 238, .9);     /* nav pill when backdrop-filter works */
  --logo-filter: invert(1);  /* the logo is white: dark on paper */

  --font: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);  /* the landing's soft ease-out */
  --r-lg: 8px;               /* buttons, inputs, small boxes */
  --r-2xl: 16px;             /* cards, rows, nav pill */
  --wrap: 672px;             /* content width of the list / account pages */
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131209;        /* night */
    --card: #1f1f1f;         /* night-card */
    --raised: #272727;       /* night-raised */
    --ink: #f2eee6;
    --muted: #a9a297;
    --line: #313131;
    --line-strong: #4a4740;
    --accent: #e39478;
    --accent-hover: #eeab93;
    --on-accent: #131209;
    --accent-soft: rgba(227, 148, 120, .16);
    --hover: rgba(255, 255, 255, .10);
    --danger: #ff8a80;
    --nav-bg: rgba(31, 31, 31, .9);
    --logo-filter: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  color: var(--ink);
  font: 400 19px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
svg { display: block; }
p { margin: 0 4px 16px; }

/* Headings: Manrope 600, tight tracking (landing heading-*). */
h1, h2, h3 { font-weight: 600; text-wrap: balance; }
h1 { margin: 16px 4px 24px; font-size: 34px; line-height: 1.12; letter-spacing: -.02em; }
h2 { margin: 40px 4px 14px; font-size: 26px; line-height: 1.2; letter-spacing: -.01em; }
h3 { margin: 24px 4px 10px; font-size: 21px; line-height: 1.3; }
@media (min-width: 560px) { h1 { font-size: 40px; } }

/* ======================================================================
   2. HEADER: the landing's floating nav pill.
   <header class="top">
     <nav class="nav">
       <a class="nav-logo"><img></a>        logo, to /parrocchie
       <a class="back"><svg><span>label</span></a>   (not on /parrocchie)
       … head_extra (reader title + Atti) or <span class="nav-fill"> …
       <a class="icon-btn account-btn">     /account
       <a class="btn secondary search-btn"><svg><span class="lbl">Cerca</span></a>
     </nav>
   </header>
   bare() (login, set password) uses the same pill with the logo (to /) and
   a .btn.ghost "Torna alla home".
   ====================================================================== */
header.top {
  position: -webkit-sticky; position: sticky; top: 0; z-index: 20;
  padding: 12px 12px 0;
  pointer-events: none;  /* only the pill takes clicks, not the gap above it */
}
.nav {
  display: flex; align-items: center;
  max-width: var(--wrap); margin: 0 auto;
  padding: 5px; padding-left: 8px;
  background: var(--paper);  /* solid fallback */
  border: 1px solid var(--line); border-radius: var(--r-2xl);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  pointer-events: auto;
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .nav {
    background: var(--nav-bg);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    backdrop-filter: blur(24px) saturate(1.4);
  }
}
.nav-logo {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; margin-right: 4px;
  border-radius: var(--r-lg);
}
.nav-logo img { display: block; width: 40px; height: 40px; filter: var(--logo-filter); }
.nav-fill { flex: 1 1 auto; }
/* logo + site name (/parrocchie, login): the landing's wordmark */
.nav-brand { width: auto; padding-right: 8px; color: var(--ink); text-decoration: none; }
.nav-brand span { margin-left: 10px; font-size: 19px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.home-link svg { width: 22px; height: 22px; margin-left: -4px; }
.home-link .long { display: none; }
@media (min-width: 480px) {
  .home-link .long { display: inline; }
  .home-link .short { display: none; }
}
.back {
  flex: 0 1 auto; min-width: 0;
  display: inline-flex; align-items: center;
  min-height: 48px; padding: 0 14px 0 6px; margin-right: 4px;
  color: var(--ink); text-decoration: none; font-weight: 600;
  border-radius: var(--r-lg);
  transition: background-color 300ms var(--ease);
}
.back svg { flex: none; width: 24px; height: 24px; margin-right: 4px; }
.back span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.back:hover { background: var(--hover); }
.nav .account-btn { margin-right: 4px; }
.nav .search-btn { flex: none; padding: 0; width: 48px; }
.nav .search-btn .lbl { display: none; }
/* In the dark reader the scan comes first: search is a quiet icon, not a light block. */
body.reader .nav .search-btn { background: transparent; color: var(--ink); }
body.reader .nav .search-btn:hover { background: var(--hover); }
@media (min-width: 480px) {
  header.top { padding: 16px 16px 0; }
  .nav .search-btn { width: auto; padding: 0 18px 0 14px; }
  .nav .search-btn .lbl { display: inline; margin-left: 8px; }
}

/* ======================================================================
   3. BUTTONS, FORMS & CARDS (shared by all pages)
   .btn               primary: accent filled (landing "Esplora archivio")
   .btn.secondary     ink filled (landing nav "Accedi")
   .btn.ghost         no fill, ink text (landing "Torna alla home")
   .btn.outline       no fill, ink text, 2 px border (lesser actions in lists)
   .btn.danger        outlined red, for destructive actions
   .btn.small         less padding, smaller text, still 48 px tall
   .btn.block         full width
   .icon-btn          48 × 48 square icon button, no fill
   An <svg> inside a .btn gets 8 px of space from the text (no flex gap).
   ====================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 10px 24px;
  font: 600 19px/1.3 var(--font); text-decoration: none; white-space: nowrap;
  color: var(--on-accent); background: var(--accent);
  border: 0; border-radius: var(--r-lg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 500ms var(--ease), background-color 300ms var(--ease), opacity 300ms var(--ease);
}
.btn:hover { background: var(--accent-hover); -webkit-transform: translateY(-2px); transform: translateY(-2px); }
.btn:active { -webkit-transform: scale(.98); transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: default; transform: none; }
.btn svg { flex: none; width: 22px; height: 22px; }
.btn svg + span, .btn span + svg { margin-left: 8px; }
.btn.secondary { color: var(--paper); background: var(--ink); }
.btn.secondary:hover { background: var(--ink); opacity: .9; }
.btn.ghost { color: var(--ink); background: transparent; }
.btn.ghost:hover { background: var(--hover); transform: none; }
.btn.outline { color: var(--ink); background: transparent; box-shadow: inset 0 0 0 2px var(--line-strong); }
.btn.outline:hover { background: var(--hover); }
.btn.danger { color: var(--danger); background: transparent; box-shadow: inset 0 0 0 2px var(--danger); }
.btn.danger:hover { background: transparent; }
.btn.small { padding: 8px 16px; font-size: 17px; }
.btn.block { display: flex; width: 100%; }

.icon-btn {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; padding: 0;
  color: var(--ink);
  background: transparent; border: 0; border-radius: var(--r-lg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 300ms var(--ease);
}
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:hover { background: var(--hover); }
.icon-btn:disabled { opacity: .3; cursor: default; background: transparent; }

/* Card: white box on paper (landing rounded-2xl border bg-card). */
.card {
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r-2xl);
  padding: 4px 20px; margin: 0 0 20px;
}

/* Forms: label above a large field. */
.form > div { margin: 16px 0; }
.form label { display: block; font-weight: 600; margin: 0 0 6px 2px; }
.form input[type=text], .form input[type=email], .form input[type=password], .form select {
  display: block; width: 100%; min-height: 56px; padding: 12px 14px;
  font: 400 19px/1.3 var(--font); color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  -webkit-appearance: none; appearance: none;
  transition: border-color 300ms var(--ease), box-shadow 300ms var(--ease);
}
.form input:focus, .form select:focus { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); outline: none; }
.form input[aria-invalid=true] { border-color: var(--accent); }
.form input[readonly] { color: var(--muted); }
.form .hint { margin: 6px 2px 0; font-size: 16px; }
.hint { color: var(--muted); }

/* Status message (role=status): .msg, or .msg.err for errors. */
.msg { margin: 16px 0 20px; padding: 14px 16px; border-radius: var(--r-lg); background: var(--accent-soft); font-weight: 600; list-style: none; }
.msg.err { background: rgba(190, 40, 30, .12); color: #8f1d16; }
@media (prefers-color-scheme: dark) { .msg.err { color: #ffb4ab; } }

/* ======================================================================
   4. LIST PAGES: parishes (/parrocchie), types (/<parish>), books
   Like the landing: white rounded-2xl cards on paper, Manrope 600 titles
   with tight tracking, accent kicker labels, the hero's gradient title,
   and the landing's photos of the three kinds of register.
   ====================================================================== */
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 16px 16px 56px; }
.wrap > h1:first-child:not(.title) { margin-top: 24px; }

/* accent label above a title (landing caption-3, larger for older eyes) */
.kicker {
  margin: 28px 4px -16px;
  color: var(--accent);
  font-size: 16px; line-height: 1.3; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
}

/* /parrocchie: the landing hero's title, gradient ink to grey */
.home { padding-top: 0; }
.home > .search:first-of-type, .home > h1 + * { margin-top: 24px; }
.title {
  margin: 0; padding: 28px 4px 28px;
  font-size: 44px; line-height: 1; letter-spacing: -.025em;
}
.title span { display: inline-block; padding-bottom: .08em; }
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .title span {
    color: transparent;
    background-image: linear-gradient(90deg, #000 0%, #666 100%);
    -webkit-background-clip: text; background-clip: text;
  }
  @media (prefers-color-scheme: dark) {
    .title span { background-image: linear-gradient(90deg, #fff 0%, #9b9b9b 100%); }
  }
}
@media (min-width: 560px) { .title { padding: 56px 4px 36px; font-size: 60px; } }
.home h2 { margin-top: 36px; }

/* rows: one big card per choice */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li + li { margin-top: 12px; }
.row {
  display: flex; align-items: center;
  min-height: 88px; padding: 14px 12px 14px 20px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r-2xl);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 300ms var(--ease), box-shadow 300ms var(--ease), transform 500ms var(--ease);
}
.row:hover {
  border-color: var(--line-strong);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
  -webkit-transform: translateY(-2px); transform: translateY(-2px);
}
.row:active { -webkit-transform: scale(.985); transform: scale(.985); }
.row .info { flex: 1; min-width: 0; }
.row .name { display: block; font-size: 26px; line-height: 1.15; font-weight: 600; letter-spacing: -.02em; }
.row .years { display: block; font-size: 21px; line-height: 1.3; font-weight: 600; font-variant-numeric: tabular-nums; }
.row .name + .years { margin-top: 6px; font-size: 19px; font-weight: 500; color: var(--muted); }
.row .meta { display: block; margin-top: 2px; color: var(--muted); font-size: 17px; }
.row .recs { color: var(--accent); font-weight: 600; }
.row .chev { flex: none; width: 22px; height: 22px; margin-left: 8px; color: var(--muted); transition: transform 500ms var(--ease); }
.row:hover .chev { -webkit-transform: translateX(3px); transform: translateX(3px); }

/* parish: a real book cover */
.row .cover {
  flex: none; width: 88px; height: 116px; margin: -2px 18px -2px -8px;
  border-radius: 6px; object-fit: cover; object-position: 50% 0;
  background: #3a332b; box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
@media (min-width: 560px) { .row .cover { width: 100px; height: 132px; } }

/* type: the landing's photo of those registers, on a paper inset
   (the landing's nested card) */
.types .row { padding: 8px 12px 8px 8px; }
.row .pic {
  flex: none; display: block;
  width: 120px; height: 96px; margin-right: 16px; padding: 8px 6px 6px;
  background: var(--paper); border-radius: var(--r-lg);
}
.row .pic img {
  display: block; width: 100%; height: 100%;
  object-fit: contain; object-position: 50% 100%;
  -webkit-filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .22)); filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .22));
}
@media (min-width: 560px) {
  .row .pic { width: 200px; height: 128px; margin-right: 24px; padding: 12px 12px 10px; }
}

/* books */
.books .row { min-height: 80px; }
.books .row .years { font-size: 24px; letter-spacing: -.01em; }
h2.group {
  margin: 36px 4px 12px;
  color: var(--muted);
  font-size: 16px; line-height: 1.3; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
}

/* ======================================================================
   5. SEARCH: box, results, drawer
   ====================================================================== */
.search { margin: 0 0 8px; }
.search label { display: block; margin: 0 0 10px 4px; font-size: 21px; line-height: 1.3; font-weight: 600; letter-spacing: -.01em; }
.field {
  display: flex; align-items: center;
  background: var(--card);
  border: 1px solid var(--line-strong); border-radius: var(--r-2xl);
  padding: 6px 6px 6px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  transition: border-color 300ms var(--ease), box-shadow 300ms var(--ease);
}
.field:focus-within { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.field input {
  flex: 1; min-width: 0; height: 48px; padding: 0;
  border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 20px;
  outline: none;
  -webkit-appearance: none; appearance: none;
}
.field input::placeholder { color: var(--muted); opacity: .8; }
.field input::-webkit-search-cancel-button { display: none; }
.field button {
  flex: none; width: 52px; height: 48px; padding: 0; margin-left: 8px;
  border: 0; border-radius: var(--r-lg);
  background: var(--accent); color: var(--on-accent);
  cursor: pointer;
  transition: background-color 300ms var(--ease);
}
.field button:hover { background: var(--accent-hover); }
.field button svg { width: 26px; height: 26px; margin: 0 auto; }

/* results */
.results:empty { display: none; }
.results { margin-bottom: 8px; }
.summary { margin: 24px 4px 12px; font-weight: 600; }
.hits { list-style: none; margin: 0; padding: 0; }
.hits li + li { margin-top: 10px; }
.hit {
  display: block;
  padding: 16px 20px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r-2xl);
  text-decoration: none;
  transition: border-color 300ms var(--ease), box-shadow 300ms var(--ease);
}
.hit:hover { border-color: var(--line-strong); box-shadow: 0 2px 4px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06); }
.hit .who { display: block; font-size: 22px; line-height: 1.25; font-weight: 600; letter-spacing: -.02em; }
.hit .what { display: block; margin-top: 4px; font-weight: 500; font-size: 17px; font-variant-numeric: tabular-nums; }
.hit .kind { color: var(--accent); font-weight: 600; }
.hit .details { display: block; margin-top: 6px; color: var(--muted); font-size: 17px; line-height: 1.45; }
.hit .lbl { font-weight: 600; }
mark { background: rgba(224, 165, 38, .35); color: inherit; border-radius: 3px; padding: 0 .05em; }
.more { margin: 20px 0; text-align: center; }

/* drawer (opened by the header search button): a sidebar on wide screens,
   full screen on phones. Its head is a pill in the nav pill's place (same
   offsets and size) holding the search field and, where the search button
   was, the close button. */
.sp[hidden] { display: none; }
.sp { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 50; }
.sp-backdrop { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(10, 10, 8, .45); animation: fade .15s ease-out; }
.sp-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 100%; max-width: 560px;
  padding: 0 16px 24px;
  background: var(--paper); color: var(--ink);
  box-shadow: -10px 0 40px rgba(0,0,0,.25);
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  animation: slide-in .3s var(--ease);
}
.sp-head {
  position: -webkit-sticky; position: sticky; top: 0; z-index: 1;
  margin: 0 -16px; padding: 12px 12px 4px;
  background: var(--paper);
}
.sp-pill {
  display: flex; align-items: center;
  padding: 5px; padding-left: 8px;
  background: var(--card);
  border: 1px solid var(--line-strong); border-radius: var(--r-2xl);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  transition: border-color 300ms var(--ease), box-shadow 300ms var(--ease);
}
.sp-pill:focus-within { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.sp-pill .search { flex: 1 1 auto; min-width: 0; margin: 0; }
.sp-pill .field { padding: 0 0 0 6px; background: transparent; border: 0; border-radius: 0; box-shadow: none; }
.sp-pill .field:focus-within { box-shadow: none; }
.sp-pill .field button { margin-left: 4px; }
.sp-pill .sp-close { margin-left: 4px; }
.sp .results { padding-top: 4px; }
.sp .summary { margin-top: 16px; }
@media (min-width: 480px) { .sp-head { padding: 16px 16px 4px; } }
body.search-open { overflow: hidden; }
@keyframes slide-in { from { transform: translateX(2rem); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ======================================================================
   6. BOOK READER: always dark (the landing's night palette) so the scan
   stands out. Two floating pills like the landing nav: the header (back,
   title, Atti, account, search) at the top and the bar (‹ page zoom ›) at
   the bottom; one scan per screen between them. The records panel is a
   floating card at the right (a bottom sheet on phones).
   book.js measures the pills into --top / --bar (the stage sits between).
   ====================================================================== */
body.reader {
  /* the landing's dark palette, whatever the system setting */
  --paper: #131209;
  --card: #1f1f1f;
  --raised: #272727;
  --ink: #f2eee6;
  --muted: #a9a297;
  --line: #313131;
  --line-strong: #4a4740;
  --accent: #e39478;
  --accent-hover: #eeab93;
  --on-accent: #131209;
  --accent-soft: rgba(227, 148, 120, .16);
  --hover: rgba(255, 255, 255, .10);
  --nav-bg: rgba(31, 31, 31, .82);
  --logo-filter: none;
  --top: 68px;
  --bar: 80px;
  --panel: 24rem;
  --inset: 8px;              /* space between the screen edge and the pills / panel */
  overflow: hidden;
  height: 100vh; height: 100dvh;
  background: var(--paper); color: var(--ink);
}

/* top pill: fixed over the top of the stage */
body.reader header.top { position: fixed; top: 0; left: 0; right: 0; z-index: 10; padding: var(--inset) var(--inset) 0; }
body.reader .nav { max-width: none; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
body.reader .back { margin-right: 6px; padding: 0; width: 48px; flex: none; justify-content: center; }
body.reader .back svg { margin: 0; }
body.reader .back span { display: none; }
.tb-title { flex: 1 1 auto; min-width: 0; margin-right: 6px; line-height: 1.2; white-space: nowrap; overflow: hidden; }
.tb-title strong, .tb-title span { overflow: hidden; text-overflow: ellipsis; }
.tb-title strong { font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.tb-title span { margin-left: 8px; font-size: 18px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Atti: icon, label (hidden on phones), count of the records on this scan */
.notes-btn {
  flex: none;
  display: inline-flex; align-items: center;
  height: 48px; padding: 0 10px 0 12px; margin-right: 6px;
  font: 600 18px/1 var(--font);
  color: var(--ink); background: var(--raised);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 300ms var(--ease), border-color 300ms var(--ease), color 300ms var(--ease);
}
.notes-btn svg { flex: none; width: 24px; height: 24px; }
.notes-btn .lbl { margin-left: 8px; }
.notes-btn:hover { background: #303030; }
.notes-btn[hidden] { display: none; }
.notes-btn[aria-expanded="true"] { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.badge {
  min-width: 28px; margin-left: 8px; padding: 4px 7px;
  border-radius: 999px; text-align: center; font-size: 16px; line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--muted); background: rgba(255, 255, 255, .10);
}
.notes-btn.has .badge { background: var(--accent); color: var(--on-accent); }

/* bottom pill: previous, page picker, zoom, next (accent: the main action) */
.bar {
  position: fixed; z-index: 10;
  left: var(--inset); right: var(--inset);
  bottom: var(--inset); bottom: calc(var(--inset) + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r-2xl);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .bar {
    background: var(--nav-bg);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    backdrop-filter: blur(24px) saturate(1.4);
  }
}
.bar .icon-btn { width: 56px; height: 56px; border-radius: 12px; }
.bar .icon-btn svg { width: 30px; height: 30px; }
#next { color: var(--on-accent); background: var(--accent); transition: background-color 300ms var(--ease), transform 500ms var(--ease); }
#next:hover { background: var(--accent-hover); }
#next:active, #prev:active { -webkit-transform: scale(.96); transform: scale(.96); }
#next:disabled { color: var(--muted); background: var(--raised); opacity: .6; }
#zoom[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
#zoom[aria-pressed="true"] .zplus { display: none; }
.pick { flex: 1 1 auto; min-width: 0; max-width: 260px; margin: 0 6px; position: relative; }
.pick::after {
  content: ""; position: absolute; right: 18px; top: 50%;
  width: 9px; height: 9px; margin-top: -7px;
  border: solid var(--muted); border-width: 0 2px 2px 0;
  transform: rotate(45deg); pointer-events: none;
}
.pick select {
  display: block; width: 100%; height: 56px; padding: 0 40px 0 16px;
  font: 600 19px var(--font); color: var(--ink);
  background: var(--raised);
  border: 1px solid var(--line); border-radius: 12px;
  -webkit-appearance: none; appearance: none;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: border-color 300ms var(--ease);
}
.pick select:hover { border-color: var(--line-strong); }
.pick select option { background: var(--raised); color: var(--ink); }

/* horizontal pager: one scan per screen */
.stage { position: fixed; left: 0; right: 0; top: var(--top); bottom: var(--bar); }
body.reader .book {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  display: flex;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  outline: none;
}
body.reader .book::-webkit-scrollbar { display: none; }
.spread {
  flex: 0 0 100%;
  height: 100%;
  margin: 0;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  container-type: size;
  display: flex;
  overflow: hidden;
}
body.reader:not([data-zoom="fit"]) .spread { overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
/* margin:auto centres the page and still lets an oversized one scroll from its edge */
.page { margin: auto; padding: 16px; }
.sheet {
  position: relative;
  flex: none;
  aspect-ratio: var(--r);
  width: calc(var(--z, 1) * (100cqw - 32px));
  background: var(--raised);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0,0,0,.55), 0 3px 8px rgba(0,0,0,.3);
}
body.reader[data-zoom="fit"] .sheet { width: min(100cqw - 32px, (100cqh - 32px) * var(--r)); }
.sheet img {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  display: block;
  opacity: 0;
  transition: opacity .4s var(--ease);
  user-select: none; -webkit-user-drag: none;
}
.sheet.loaded img { opacity: 1; }
/* placeholder while loading: the page label under the spinner */
.sheet::before {
  content: attr(data-label);
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  display: grid; place-items: center;
  padding-top: 6rem;
  font: 600 19px var(--font);
  color: var(--muted);
  background: var(--raised);
  border: 1px solid var(--line); border-radius: 4px;
}
.sheet.loaded::before { display: none; }
.sheet.error::before { content: "Impossibile caricare l’immagine"; padding: 0 16px; text-align: center; }
.spinner {
  position: absolute; left: 50%; top: 50%; z-index: 1;
  width: 48px; height: 48px; margin: -24px 0 0 -24px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .12);
  border-top-color: var(--accent);
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
.sheet.loading .spinner { opacity: 1; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* gutter shading for two-page spreads (G toggles it) */
.sheet.twopage::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; pointer-events: none;
  background: linear-gradient(90deg,
    rgba(0,0,0,.10) 0%, transparent 4%,
    transparent 46%, rgba(0,0,0,.14) 49.6%, rgba(0,0,0,.14) 50.4%, transparent 54%,
    transparent 96%, rgba(0,0,0,.10) 100%);
  mix-blend-mode: multiply;
}
body.no-gutter .sheet.twopage::after { display: none; }
/* page turn (book.js pageTurn): an overlay over the stage; the script places
   every piece in pixels */
.turn { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 2; pointer-events: none; }
.turn .leaf, .turn .face { position: absolute; }
.turn .leaf { transform-style: preserve-3d; will-change: transform; }
.turn .face {
  background: var(--raised);
  overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
/* the face's image is the whole scan; a half shows the matching half of it */
.turn .face img { position: absolute; top: 0; left: 0; width: 200%; height: 100%; display: block; }
.turn .face.r img { left: -100%; }
.turn .face.w img { width: 100%; }
.turn .face.l { border-radius: 4px 0 0 4px; }
.turn .face.r { border-radius: 0 4px 4px 0; }
.turn .face.w { border-radius: 4px; }
.turn .back { transform: rotateY(180deg); }
.turn .shade { position: absolute; z-index: 1; top: 0; right: 0; bottom: 0; left: 0; background: #000; opacity: 0; }
/* the fold: shading at the spine side of each half, like the gutter */
.turn .face.l::after, .turn .face.r::after {
  content: ""; position: absolute; z-index: 1; top: 0; bottom: 0; width: 10%; pointer-events: none;
}
.turn .face.l::after { right: 0; background: linear-gradient(90deg, transparent, rgba(0,0,0,.16)); }
.turn .face.r::after { left: 0; background: linear-gradient(270deg, transparent, rgba(0,0,0,.16)); }
body.no-gutter .turn .face::after { display: none; }
body.reader:not([data-zoom="fit"]) .spread { cursor: grab; }
body.reader.dragging .spread { cursor: grabbing; }
body.reader.dragging { user-select: none; }

/* records panel: a floating card at the right on wide screens, a bottom
   sheet above the bar on phones */
body.notes-open .stage { right: calc(var(--panel) + var(--inset)); }
body.notes-open .bar { right: calc(var(--panel) + var(--inset) * 2); }  /* centred under the page */
.notes {
  position: fixed; z-index: 9;
  right: var(--inset); top: var(--top); bottom: var(--bar);
  width: var(--panel);
  margin: 4px 0 8px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r-2xl);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.notes[hidden] { display: none; }
.notes-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 6px 6px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.notes-head h2 { margin: 0; font-size: 21px; }
.notes-list, .notes-loose ol { list-style: none; margin: 0; padding: 0 16px; }
.note { padding: 16px 4px; border-bottom: 1px solid var(--line); }
.note:last-child { border-bottom: 0; }
.note .who { display: block; font-size: 21px; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
.note .what { display: block; margin-top: 4px; font-weight: 600; font-size: 17px; color: var(--accent); }
.note dl { margin: 8px 0 0; font-size: 17px; line-height: 1.45; }
.note dt { float: left; clear: left; margin-right: 6px; color: var(--muted); }
.note dt::after { content: ":"; }
.note dd { margin: 0 0 2px; }
.note .cit { display: block; margin-top: 8px; font-size: 15px; color: var(--muted); }
.note.wanted {
  margin: 8px -8px; padding: 14px 12px;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--r-lg);
}
.notes-empty { margin: 20px; color: var(--muted); }
.notes-loose { margin: 8px 0 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 17px; }
.notes-loose summary { cursor: pointer; min-height: 48px; padding: 12px 20px; }
.notes-source { margin: 16px 20px 20px; font-size: 15px; color: var(--muted); }

@media (max-width: 640px) {
  body.reader { --inset: 6px; --sheet: 46vh; --sheet: 46dvh; }
  body.reader .nav-logo { display: none; }
  body.reader .back { margin-right: 2px; }
  /* title on two lines: what, then the years */
  .tb-title strong { display: block; font-size: 18px; }
  .tb-title span { display: block; margin: 0; font-size: 16px; }
  .notes-btn { padding: 0 8px 0 10px; }
  .notes-btn .lbl {  /* still read out by screen readers */
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .page { padding: 8px; }
  .sheet { width: calc(var(--z, 1) * (100cqw - 16px)); }
  body.reader[data-zoom="fit"] .sheet { width: min(100cqw - 16px, (100cqh - 16px) * var(--r)); }
  .bar, body.notes-open .bar { right: var(--inset); max-width: none; padding: 4px; }
  .pick { max-width: none; }
  body.notes-open .stage { right: 0; bottom: calc(var(--bar) + var(--sheet)); }
  .notes { top: auto; left: var(--inset); width: auto; height: var(--sheet); margin: 0 0 6px; }
}
/* the smallest phones: the account link (reachable from every other page)
   makes room for the book title */
@media (max-width: 400px) {
  body.reader .account-btn { display: none; }
}

/* ======================================================================
   7. ACCOUNT / ADMIN: login, account, user management
   ====================================================================== */
   7. ACCOUNT / ADMIN: login, account, user management, error pages
   .auth   one centred card (login, set password, invalid link, link to send),
           as in protodeck/accedi: heading, one muted .lead line, the form
   .oops   404 and error pages, centred, as in protodeck/404
   .account / .admin   own account; user management (accounts.rs)
   ====================================================================== */
.lead { margin: 12px 0 0; color: var(--muted); }

/* centred card */
.auth { max-width: 480px; padding-top: 32px; }
.auth .card { padding: 24px 20px; }
.auth h1 { margin: 0; font-size: 28px; line-height: 1.2; letter-spacing: -.01em; }
.auth p { margin-left: 0; margin-right: 0; }
.auth .lead + p { margin-top: 16px; }
.auth .msg { margin: 20px 0 0; }
.auth .form { margin-top: 24px; }
.auth .form > div:first-of-type { margin-top: 0; }
.auth .btn.block { margin-top: 24px; }
.auth .foot { margin: 24px 0 0; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 17px; }
@media (min-width: 560px) {
  .auth { padding-top: 64px; }
  .auth .card { padding: 32px; }
}
/* the set-password link, with Copia under it */
.linkbox { margin: 20px 0 0; }
.linkbox input {
  display: block; width: 100%; min-height: 56px; padding: 12px 14px;
  font: 16px/1.4 ui-monospace, Menlo, Consolas, monospace; color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line-strong); border-radius: var(--r-lg);
}
.linkbox input:focus { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); outline: none; }
.linkbox .btn.block { margin-top: 10px; }
.linkbox + .btn.block { margin-top: 12px; }

/* 404 and errors */
.oops { padding-top: 64px; text-align: center; }
.eyebrow { margin: 0 0 12px; color: var(--accent); font-size: 15px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.oops h1 { margin: 0 auto 32px; max-width: 15em; }
.oops .lead { margin: -16px auto 32px; max-width: 26em; }
@media (min-width: 560px) { .oops { padding-top: 112px; } }

/* tags: accent pills; .plain = outlined (parish names); .warn = pending */
.tag {
  display: inline-block; margin: 6px 6px 0 0; padding: 2px 12px;
  border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 15px; line-height: 1.5; font-weight: 600; vertical-align: middle;
}
.tag.plain { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
.tag.warn { background: rgba(224, 165, 38, .22); color: #7a5205; }
@media (prefers-color-scheme: dark) {
  .tag.warn { color: #f3c560; }
}

/* own account */
.account .card { padding: 20px; }
.account h2 { margin: 0 0 16px; font-size: 22px; }
.account h2 label { margin: 0; }
.account .form > div:first-of-type { margin-top: 0; }
.account .form .btn { margin-top: 8px; }
.me-name { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; overflow-wrap: anywhere; }
.me-email { margin: 2px 0 0; color: var(--muted); overflow-wrap: anywhere; }
.me .tags { margin: 8px 0 0; }
.manage { margin: 0 0 20px; }
.logout { margin: 32px 0 0; }

/* user management */
.admin h2 { margin: 40px 4px 12px; }
.count {
  display: inline-block; min-width: 34px; margin-left: 6px; padding: 0 10px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--muted);
  font-size: 17px; line-height: 30px; text-align: center; vertical-align: middle;
  letter-spacing: 0;
}
.add { padding: 0; margin: 0 0 12px; overflow: hidden; }
.add summary {
  display: flex; align-items: center;
  min-height: 60px; padding: 0 20px;
  color: var(--accent); font-weight: 600;
  list-style: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 300ms var(--ease);
}
.add summary::-webkit-details-marker { display: none; }
.add summary:hover { background: var(--hover); }
.add summary svg { flex: none; width: 24px; height: 24px; margin-right: 10px; transition: transform 300ms var(--ease); }
.add[open] summary { border-bottom: 1px solid var(--line); }
.add[open] summary svg { transform: rotate(45deg); }
.add .form { padding: 4px 20px 20px; }
.add .hint { margin: 0 2px 16px; font-size: 16px; }
.opt { font-weight: 400; color: var(--muted); }

.members { list-style: none; margin: 0; padding: 0; }
.members > li {
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r-2xl);
  overflow: hidden;
}
.members > li + li { margin-top: 10px; }
.members > li.empty { padding: 16px 20px; background: transparent; border-style: dashed; border-color: var(--line-strong); color: var(--muted); }
/* a member: the head is a <summary> that opens the actions */
.m-head { display: block; position: relative; padding: 14px 20px; }
summary.m-head {
  padding-right: 56px;
  list-style: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 300ms var(--ease);
}
summary.m-head::-webkit-details-marker { display: none; }
summary.m-head:hover { background: var(--hover); }
.m-head .chev {
  position: absolute; right: 18px; top: 50%; width: 24px; height: 24px; margin-top: -12px;
  color: var(--muted); transition: transform 300ms var(--ease);
}
details[open] > .m-head .chev { transform: rotate(180deg); }
.m-body { padding: 0 20px 16px; border-top: 1px solid var(--line); }
.members .who { display: block; font-size: 21px; line-height: 1.3; font-weight: 600; letter-spacing: -.01em; overflow-wrap: anywhere; }
.members .email { display: block; color: var(--muted); font-size: 16px; overflow-wrap: anywhere; }
.members .tags { display: block; margin-top: 2px; }
.members .note { display: block; margin-top: 12px; color: var(--muted); font-size: 16px; }
.actions { margin-top: 4px; }
.actions form { display: inline-block; margin: 8px 8px 0 0; vertical-align: top; }
