:root {
  --bg: #faf6ee; --card: #ffffff; --ink: #1d1a16; --muted: #6b635a; --line: #e6ddcf;
  --gold: #e7b04a; --gold-ink: #1d1a16; --ok: #2f7a4f; --warn: #a15c00; --bad: #b3261e;
  --chip: #f3ecdf; --chip-on: #1d1a16; --chip-on-ink: #faf6ee;
  --radius: 14px; --pad: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15130f; --card: #211e19; --ink: #f3ece0; --muted: #b3a998; --line: #3a342b;
    --chip: #2c2821; --chip-on: #e7b04a; --chip-on-ink: #1d1a16; --ok: #6cc38f; --bad: #ff8a80; --warn: #f0b35a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15130f; --card: #211e19; --ink: #f3ece0; --muted: #b3a998; --line: #3a342b;
  --chip: #2c2821; --chip-on: #e7b04a; --chip-on-ink: #1d1a16; --ok: #6cc38f; --bad: #ff8a80; --warn: #f0b35a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.45 Karla, system-ui, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
body.public { padding-bottom: 32px; }
h1, h2 { font-family: Fraunces, Georgia, serif; font-weight: 600; line-height: 1.15; margin: 0 0 8px; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.2rem; }
h2.section { margin: 24px 0 8px; color: var(--muted); font-family: Karla, sans-serif; font-size: .95rem; text-transform: uppercase; letter-spacing: .06em; }
p { margin: 0 0 8px; }
a { color: inherit; }
.hint { color: var(--muted); font-size: .92rem; }
.center { text-align: center; }
.error-text { color: var(--bad); min-height: 1em; }

.beta {
  background: var(--gold); color: var(--gold-ink); text-align: center; font-weight: 600;
  font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; padding: 4px 8px;
  padding-top: calc(4px + env(safe-area-inset-top));
}
header.top { display: flex; justify-content: space-between; align-items: center; padding: 10px var(--pad); border-bottom: 1px solid var(--line); }
.brand { font-family: Fraunces, serif; font-weight: 600; }
.sync { font-size: .85rem; color: var(--muted); }
.sync[data-state="pending"] { color: var(--warn); }
.sync[data-state="offline"] { color: var(--bad); }

main { max-width: 640px; margin: 0 auto; padding: var(--pad); outline: none; }
.loading { color: var(--muted); padding: 32px 0; text-align: center; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--pad); margin: 0 0 12px; }
.card.center { text-align: center; padding: 32px var(--pad); }
.card.event.live { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset; }
.card.sticky { position: sticky; top: 8px; z-index: 2; }
.badge { display: inline-block; background: var(--ok); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: .8rem; margin-bottom: 8px; }
.count { font-size: 1.05rem; margin-top: 8px; }
.count strong { font-size: 1.6rem; font-family: Fraunces, serif; }

.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

button, .button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: 600 1rem Karla, sans-serif; text-decoration: none; cursor: pointer;
}
button.primary, .button.primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
button.danger { color: var(--bad); }
button.small, .button.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
button.wide, .button.wide { display: flex; width: 100%; margin-top: 8px; }
.list-row > .pill { flex: none; }
button:disabled { opacity: .6; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.field { display: block; margin: 0 0 14px; }
.field .label { display: block; font-weight: 600; margin-bottom: 4px; }
.field .hint { display: block; margin-top: 4px; }
input, select {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: 1.05rem Karla, sans-serif;
}
input[type="radio"], input[type="checkbox"] { width: auto; min-height: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; }
.chip span { display: inline-block; padding: 9px 14px; border-radius: 999px; background: var(--chip); border: 1px solid var(--line); cursor: pointer; }
.chip input:checked + span { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); }
.chip input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: 2px; }
.checks { display: grid; gap: 6px; }
.check { display: flex; gap: 10px; align-items: center; padding: 6px 0; }

details.more { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
details.more summary { font-weight: 600; cursor: pointer; padding: 6px 0 10px; }

.list-row {
  display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 12px; text-align: left;
  padding: 12px 14px; margin: 0 0 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  text-decoration: none; color: var(--ink); font: 1rem Karla, sans-serif; min-height: 52px;
}
.list-row small { display: block; color: var(--muted); font-size: .85rem; }
.list-row > a { text-decoration: none; }
.list-row.add { color: var(--muted); border-style: dashed; justify-content: flex-start; }
.results { margin-top: 10px; }
.results:empty { display: none; }
.pill { display: inline-block; min-width: 28px; text-align: center; padding: 2px 10px; border-radius: 999px; background: var(--chip); font-size: .85rem; }
.pill.ok { background: var(--ok); color: #fff; }

dialog.sheet {
  width: min(560px, 100%); max-height: 90vh; margin: auto auto 0; border: none; border-radius: 18px 18px 0 0;
  padding: var(--pad); background: var(--card); color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
nav.tabs a { flex: 1; text-align: center; padding: 14px 0; text-decoration: none; font-weight: 600; color: var(--muted); }
nav.tabs a.on { color: var(--ink); box-shadow: 0 -3px 0 var(--gold) inset; }
body[data-route="setup"] nav.tabs { display: none; }

.setup { text-align: center; }
.setup .card { text-align: left; }
.logo { display: block; margin: 8px auto 12px; border-radius: 50%; }
.public-head { text-align: center; margin: 8px 0 16px; }
.public-head img { border-radius: 50%; }

.poster { text-align: center; }
.qr { background: #fff; padding: 12px; border-radius: 16px; width: min(340px, 86vw); margin: 12px auto; }
.qr svg { display: block; width: 100%; height: auto; }
.event-line { font-size: 1.1rem; }
.poster .row { justify-content: center; margin-top: 12px; }
.poster .small { font-size: .85rem; opacity: .8; max-width: 34ch; margin: 8px auto 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }


.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { text-align: center; }
.stat-value { display: block; font-family: Fraunces, serif; font-size: 1.25rem; font-weight: 600; }
.stat-label { display: block; color: var(--muted); font-size: .8rem; }
.segs { display: flex; gap: 6px; margin: 4px 0 12px; }
.segs button { flex: 1; min-height: 40px; padding: 6px 8px; font-size: .95rem; background: var(--chip); }
.segs button.on { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); }
.pill.warn { background: var(--gold); color: var(--gold-ink); }
.pill.bad { background: var(--bad); color: #fff; }
.warn-text { color: var(--warn); font-weight: 600; }
.advice { background: var(--chip); }
.sigpad { width: 100%; aspect-ratio: 400 / 160; background: #fff; border: 1px dashed var(--line); border-radius: 10px; touch-action: none; display: block; }
.sig-view { width: 100%; max-width: 400px; background: #fff; border-radius: 10px; color: #1d1a16; }
.head select { width: auto; min-height: 40px; }
.flags:empty { display: none; }

textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: 1rem Karla, sans-serif; }
h3 { font-family: Karla, sans-serif; font-size: .95rem; margin: 12px 0 6px; color: var(--muted); }
.row.between { justify-content: space-between; }
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: .95rem; }
.bar-track { display: block; height: 10px; background: var(--chip); border-radius: 999px; overflow: hidden; }
.bar-track.big { height: 14px; margin-top: 6px; }
.bar-fill { display: block; height: 100%; background: var(--gold); border-radius: 999px; }
.bar-fill.done { background: var(--ok); }
.bar-num { min-width: 2.5em; text-align: right; font-weight: 600; }
.bar-num small { color: var(--muted); font-weight: 400; }
.target { margin: 8px 0 12px; }
.report-page { background: #fff; color: #1d1a16; padding: 24px; border-radius: var(--radius); max-width: 720px; margin: 0 auto; }
.report-page header { text-align: center; margin-bottom: 16px; }
.report-page h1 { font-size: 1.6rem; margin: 8px 0 0; }
.report-title { font-size: 1.1rem; color: #6b635a; }
.report-page section { margin: 18px 0; }
.report-page h2 { font-size: 1.15rem; border-bottom: 1px solid #e6ddcf; padding-bottom: 4px; }
.report-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.report-table { table-layout: fixed; width: 100%; }
.report-table td { overflow-wrap: anywhere; vertical-align: top; }
.report-table td { padding: 5px 4px; border-bottom: 1px solid #f0e9dc; vertical-align: top; }
.report-table td:last-child { text-align: right; white-space: nowrap; }
.report-page footer { margin-top: 24px; font-size: .85rem; color: #6b635a; text-align: center; }

.gear { text-decoration: none; font-size: 1.3rem; margin-left: 10px; color: var(--muted); }
.list-row.muted { opacity: .7; }
.alerts { border-color: var(--gold); }
.sheet .letter { border-top: 1px dashed #e6ddcf; padding-top: 16px; margin-top: 16px; break-before: page; }
.sheet .copy { background: #fff; color: #1d1a16; border-color: #e6ddcf; }
.sheet ul, .card ul { padding-left: 20px; }
body.report nav.tabs, body.report header.top, body.report .beta { display: none; }

@media print {
  .beta, header.top, nav.tabs, .screen-only, #toast { display: none !important; }
  body { background: #fff; color: #000; padding: 0; }
  .poster h1 { font-size: 44pt; }
  .qr { width: 12cm; }
  main { max-width: none; padding: 0; }
  .report-page { border-radius: 0; padding: 0; max-width: none; }
  .report-page section { break-inside: avoid; }
  main > :not(.sheet):not(.report-page):not(.poster) { display: none !important; }
  .poster { text-align: center; }
  .poster .qr canvas, .poster .qr svg, .poster .qr img { width: 12cm; height: 12cm; }
  .sheet, .sheet .letter { break-inside: auto; }
}
/* Motion (after React Bits): page titles blur in, cards catch a spotlight under the mouse, stats count up (js/ui/fx.js). */
main h1 { animation: fx-blur-in .45s ease both; }
@keyframes fx-blur-in { from { opacity: 0; filter: blur(6px); transform: translateY(6px); } }
.stat-value { font-variant-numeric: tabular-nums; }
@media (hover: hover) and (pointer: fine) {
  .card, .list-row { transition: border-color .2s; }
  .card:hover, .list-row:hover {
    background-image: radial-gradient(340px circle at var(--mx, 50%) var(--my, 50%), rgba(231, 176, 74, .13), transparent 45%);
    border-color: rgba(231, 176, 74, .55);
  }
}
@media print { main h1 { animation: none; } .card, .list-row { background-image: none !important; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } main h1 { animation: none; } }

/* Photos */
.drop { display: grid; gap: 4px; padding: 22px 16px; border: 2px dashed var(--line); border-radius: var(--radius); text-align: center; cursor: pointer; }
.drop.over { border-color: var(--gold); background: rgba(231, 176, 74, .08); }
.drop strong { font-size: 1.1rem; }
.drop span { font-size: .9rem; opacity: .8; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.photo { margin: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.photo img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.photo figcaption { display: grid; gap: 8px; padding: 10px; }
.photo figcaption input[type="month"] { width: auto; }
.photo .row { align-items: center; flex-wrap: wrap; }
@media (max-width: 640px) { .report-table td:last-child { white-space: normal; } }

/* ---- Two layouts: the app layout on phones (above), a desktop layout on wide screens (below) ---- */
.side-brand, .side-more, .side-only { display: none; }
.cols, .col { display: block; }

@media (min-width: 960px) {
  :root { --side: 232px; }
  body:not(.public) { padding-bottom: 32px; padding-left: var(--side); }
  body[data-route="setup"], body.report { padding-left: 0; }

  /* Bottom tab bar becomes a left sidebar with every section */
  nav.tabs {
    top: 0; right: auto; width: var(--side); flex-direction: column; gap: 2px;
    padding: 18px 12px; border-top: 0; border-right: 1px solid var(--line); overflow-y: auto;
  }
  nav.tabs a { flex: none; text-align: left; padding: 10px 14px; border-radius: 10px; color: var(--muted); }
  nav.tabs a:hover { background: var(--chip); color: var(--ink); }
  nav.tabs a.on { background: var(--chip); color: var(--ink); box-shadow: inset 3px 0 0 var(--gold); }
  nav.tabs .side-brand {
    display: flex; align-items: center; gap: 10px; margin: 0 0 18px; padding: 4px 8px;
    font-family: Fraunces, serif; font-size: 1.15rem; color: var(--ink);
  }
  nav.tabs .side-brand:hover { background: none; }
  nav.tabs .side-brand img { border-radius: 50%; }
  nav.tabs .side-more { display: block; margin: 18px 14px 6px; font-size: .78rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
  nav.tabs .side-only { display: block; }

  /* The top bar keeps the sync status; the sidebar has the name and Settings */
  header.top { padding: 12px 32px; justify-content: flex-end; }
  header.top .brand, header.top .gear { display: none; }

  /* Wider pages; forms stay at a comfortable reading width */
  main { max-width: 1120px; padding: 28px 32px; }
  h1 { font-size: 2rem; margin-bottom: 16px; }
  body[data-route="books"] main, body[data-route="events"] main, body[data-route="filings"] main,
  body[data-route="followups"] main, body[data-route="resources"] main, body[data-route="door"] main { max-width: 960px; }
  body[data-route="event"] main, body[data-route="donation"] main, body[data-route="expense"] main,
  body[data-route="pay"] main, body[data-route="payee"] main, body[data-route="filing"] main,
  body[data-route="website"] main, body[data-route="qr"] main { max-width: 760px; }
  body.report main { max-width: 820px; }

  /* Two columns where a page has two kinds of content */
  .cols { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 20px; align-items: start; }
  body[data-route="settings"] .cols { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
  body[data-route="settings"] .cols > .col { position: sticky; top: 16px; }
  .card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
  .card-grid > .card { margin: 0; }
  .card-grid > .button.wide { grid-column: 1 / -1; margin-top: 0; }
  .stat-value { font-size: 1.6rem; }

  /* Pop-up forms open in the middle of the screen instead of sliding up from the bottom */
  dialog.sheet { margin: auto; border-radius: 18px; }
  #toast { bottom: 28px; left: calc(50% + var(--side) / 2); }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}
@media print { body:not(.public) { padding-left: 0 !important; } }

/* Payroll */
.three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.pay-line { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.pay-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.pay-grid .field { margin-bottom: 8px; }
.pay-grid .label { font-size: .85rem; }
.slip .report-table { margin-top: 4px; }
@media (max-width: 640px) { .three { grid-template-columns: 1fr 1fr; } .pay-grid { grid-template-columns: 1fr 1fr; } }
