/* Church CRM — mobile-first, accessible. No external fonts or CDNs (strict CSP). */
:root {
  --brand: #2f5d50;
  --brand-dark: #234a3f;
  --brand-tint: #e8f0ed;
  --ink: #1d2422;
  --muted: #5d6965;
  --line: #d9e0dd;
  --bg: #f6f7f5;
  --card: #fff;
  --ok: #1f7a4a;     --ok-bg: #e3f4ea;
  --warn: #8a5a00;   --warn-bg: #fff2d6;
  --bad: #a3271f;    --bad-bg: #fbe5e3;
  --radius: 12px;
  --tap: 48px;
  --nav-h: 64px;
  font-size: 17px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); background: var(--bg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}
body.has-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); font-weight: normal; }
.hint { color: var(--muted); font-size: .9rem; margin: .5rem 0 0; }
.small { font-size: .9rem; }
.center { text-align: center; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: #fff; padding: .5rem 1rem; z-index: 99; }
.skip:focus { left: .5rem; }
:focus-visible { outline: 3px solid #f0a400; outline-offset: 2px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem; padding-top: calc(.6rem + env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topnav { display: none; gap: .25rem; }
.topnav a { color: #fff; text-decoration: none; padding: .5rem .75rem; border-radius: 8px; }
.topnav a[aria-current="page"], .topnav a:hover { background: rgba(255,255,255,.15); }
.logout { display: flex; align-items: center; gap: .5rem; margin: 0; }
.logout .who { display: none; opacity: .9; font-size: .9rem; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.5); }

/* Bottom nav (mobile) */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: var(--nav-h); color: var(--muted); text-decoration: none; font-size: .8rem;
}
.bottomnav .ico { font-size: 1.35rem; line-height: 1; }
.bottomnav a[aria-current="page"] { color: var(--brand); font-weight: 600; }

.container { max-width: 960px; margin: 0 auto; padding: 1rem; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin: .5rem 0 1rem; flex-wrap: wrap; }
.page-head p { margin: .25rem 0 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: 0 1.1rem; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; touch-action: manipulation; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { background: #9db3ab; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--brand); border-color: var(--line); }
.btn-danger { background: #fff; color: var(--bad); border-color: var(--bad); }
.btn-sm { min-height: 38px; padding: 0 .8rem; font-size: .9rem; }
.btn-lg { min-height: 56px; font-size: 1.05rem; }
.btn-block { width: 100%; }

/* Forms */
.form fieldset { border: 0; padding: 0; margin: 0 0 1.25rem; }
.form legend { font-weight: 700; margin-bottom: .5rem; font-size: 1.05rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .3rem; }
.req { color: var(--bad); }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=search], input:not([type]), select {
  width: 100%; min-height: var(--tap); padding: .6rem .8rem;
  font: inherit; font-size: 16px; /* prevents iOS zoom */
  color: var(--ink); background: #fff; border: 1px solid #b9c4c0; border-radius: 10px;
}
input:focus, select:focus { border-color: var(--brand); outline: 3px solid rgba(47,93,80,.25); }
[aria-invalid="true"] { border-color: var(--bad) !important; }
.error { color: var(--bad); font-size: .9rem; margin: .3rem 0 0; }
.otp { font-size: 1.6rem !important; letter-spacing: .5em; text-align: center; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); cursor: pointer; }
.check input, .toggle-card input { width: 24px; height: 24px; accent-color: var(--brand); flex: none; }
.grid-2 { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
.actions { display: flex; gap: .75rem; flex-wrap: wrap; justify-content: flex-end; margin-top: .5rem; }
.sticky-actions {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: var(--card);
  padding: .75rem 0; margin: 0 -1.1rem -1.1rem; padding-inline: 1.1rem; border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
}
.sticky-actions .btn { flex: 1; }
details.optional { border-top: 1px solid var(--line); padding-top: .75rem; margin-top: .75rem; }
details.optional > summary { cursor: pointer; font-weight: 700; min-height: var(--tap); display: flex; align-items: center; gap: .4rem; }

.toggle-card {
  display: flex; gap: .9rem; align-items: flex-start; padding: 1rem; margin-bottom: .75rem;
  border: 2px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.toggle-card:has(input:checked) { border-color: var(--brand); background: var(--brand-tint); }
.tc-body { display: flex; flex-direction: column; gap: .2rem; }
.tc-body span { font-size: .95rem; }

/* Alerts & badges */
.alert { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-weight: 500; }
.alert-success { background: var(--ok-bg); color: var(--ok); }
.alert-error { background: var(--bad-bg); color: var(--bad); }
.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #eef1f0; color: var(--muted); white-space: nowrap; }
.badge-granted { background: var(--ok-bg); color: var(--ok); }
.badge-partial, .badge-pending { background: var(--warn-bg); color: var(--warn); }
.badge-declined, .badge-none { background: var(--bad-bg); color: var(--bad); }

/* Search & lists */
.search { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.search input { flex: 1 1 200px; }
.search select { flex: 0 1 150px; width: auto; }
.member-list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.member-list > li + li { border-top: 1px solid var(--line); }
.member-list a, .member-list summary {
  display: flex; align-items: center; gap: .8rem; padding: .75rem 1rem; min-height: 64px;
  color: inherit; text-decoration: none; cursor: pointer;
}
.member-list a:hover, .member-list summary:hover { background: var(--brand-tint); }
.member-list .meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.member-list .meta small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row form { padding: 0 1rem 1rem; }
.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-tint); color: var(--brand); font-weight: 700; font-size: .9rem;
}
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); padding: .6rem 0; }
.list > li:first-child { border-top: 0; }
.list a { display: flex; justify-content: space-between; align-items: center; gap: .5rem; min-height: 40px; }
.list .row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.list .row form { margin: 0; }
.dl { display: grid; grid-template-columns: 7.5rem 1fr; gap: .5rem 1rem; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }
.dl dd a { display: inline-block; min-height: 32px; }
.scope { list-style: none; padding: 0; margin: .5rem 0 1rem; }
.scope li { padding: .25rem 0; }
.scope .yes span { color: var(--ok); font-weight: 700; }
.scope .no { color: var(--muted); }
.scope .no span { color: var(--bad); font-weight: 700; }
.consent-send { border-top: 1px solid var(--line); padding-top: .75rem; }
.consent-send .actions { justify-content: flex-start; }
.danger-zone { margin: 2rem 0; text-align: center; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; }
.stat .num { font-size: 1.8rem; font-weight: 700; color: var(--brand); }
.stat-warn .num { color: var(--bad); }

/* Tables collapse into cards on mobile */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.pager { display: flex; justify-content: space-between; }
@media (max-width: 699px) {
  .table thead { display: none; }
  .table tr { display: block; padding: .6rem 0; border-bottom: 1px solid var(--line); }
  .table td { display: flex; gap: .75rem; border: 0; padding: .15rem 0; }
  .table td::before { content: attr(data-label); flex: 0 0 5rem; color: var(--muted); }
}

/* Guest pages (login, consent) */
.guest-wrap { max-width: 480px; margin: 0 auto; padding: 1.5rem 1rem calc(2rem + env(safe-area-inset-bottom)); }
.guest-brand { text-align: center; font-weight: 700; color: var(--brand); font-size: 1.2rem; margin: 1rem 0 1.5rem; }
.resend { margin-top: .75rem; }

/* Tablet / desktop */
@media (min-width: 700px) {
  :root { font-size: 16px; }
  body.has-nav { padding-bottom: 0; }
  .bottomnav { display: none; }
  .topnav { display: flex; }
  .brand { flex: 0 0 auto; margin-right: 1rem; }
  .logout { margin-left: auto; }
  .logout .who { display: inline; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .sticky-actions { bottom: 0; }
  .sticky-actions .btn { flex: 0 0 auto; }
  .container { padding: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
