:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-2: #f1ece4;
  --text: #221d19;
  --muted: #6f655c;
  --line: #e4ddd2;
  --accent: #7a1f2b;
  --accent-ink: #ffffff;
  --btn: #7a1f2b; --btn-ink: #ffffff;
  --gold: #b0842f;
  --ready: #1f7a4d;
  --ready-bg: #e3f2ea;
  --progress: #8a5a00;
  --progress-bg: #fbf0d9;
  --idle: #6f655c;
  --idle-bg: #eee9e1;
  --fail: #b3261e;
  --fail-bg: #fbe5e3;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 16px rgba(40, 30, 20, .05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171412; --surface: #211d1a; --surface-2: #2a2521; --text: #f1ebe3; --muted: #a89d92; --line: #3a332d;
    --accent: #d06a77; --accent-ink: #1a1210; --btn: #8c2534; --btn-ink: #ffffff; --gold: #d9b26a;
    --ready: #6fd1a0; --ready-bg: #173126; --progress: #e8b75c; --progress-bg: #362a14;
    --idle: #a89d92; --idle-bg: #2e2924; --fail: #f08a82; --fail-bg: #3a1d1b;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #171412; --surface: #211d1a; --surface-2: #2a2521; --text: #f1ebe3; --muted: #a89d92; --line: #3a332d;
  --accent: #d06a77; --accent-ink: #1a1210; --btn: #8c2534; --btn-ink: #ffffff; --gold: #d9b26a;
  --ready: #6fd1a0; --ready-bg: #173126; --progress: #e8b75c; --progress-bg: #362a14;
  --idle: #a89d92; --idle-bg: #2e2924; --fail: #f08a82; --fail-bg: #3a1d1b;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 Inter, system-ui, -apple-system, sans-serif; }
h1, h2, .brand { font-family: Fraunces, Georgia, serif; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0; }
.muted { color: var(--muted); }
.loadbar { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin: 0 0 16px; }
.loadbar-top, .loadbar-bottom { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.loadbar-top #load-pct { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.loadbar-track { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 10px 0 8px; }
.loadbar-fill { height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width .9s linear; }
.small { font-size: 13px; }
[hidden] { display: none !important; }

.btn { font: inherit; font-weight: 500; border-radius: 999px; padding: 10px 18px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.btn.primary { background: var(--btn); color: var(--btn-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.signin-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 40px 32px; max-width: 380px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.signin-card h1 { margin: 8px 0 4px; font-size: 26px; }
.signin-card .btn { margin-top: 20px; width: 100%; }
.signin-card .btn + .btn { margin-top: 10px; }
.email-form { margin-top: 16px; text-align: left; }
.signin-help { margin-top: 18px; text-align: left; font-size: 14px; color: var(--text); }
.signin-help summary { cursor: pointer; color: var(--accent); font-weight: 600; text-align: center; list-style: none; }
.signin-help summary::-webkit-details-marker { display: none; }
.signin-help p, .signin-help ol { margin: 10px 0 0; line-height: 1.45; }
.signin-help ol { padding-left: 20px; }
.signin-help a { color: var(--accent); }
.email-form .field { display: block; }
.email-form input { width: 100%; box-sizing: border-box; }
#code-input { font-size: 22px; letter-spacing: 6px; text-align: center; }
.signin-msg { background: var(--fail-bg); color: var(--fail); border-radius: 8px; padding: 10px; font-size: 14px; }
.mark { color: var(--gold); font-size: 22px; }
.signin-card .mark { font-size: 34px; }
.signin-card .diocese { margin: 10px 0 0; font-family: Fraunces, Georgia, serif; font-size: 15px; line-height: 1.4; color: var(--text); }
.signin-card .department { margin: 6px 0 18px; font-size: 11px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--gold); }

/* layout */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-size: 19px; display: flex; align-items: center; gap: 8px; }
.who { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.role { background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 2px 8px; font-size: 12px; text-transform: capitalize; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 24px 40px; }

.banner { border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.banner.info { background: var(--surface-2); color: var(--muted); }
.banner.warn { background: var(--progress-bg); color: var(--progress); }
.banner.warn ul { margin: 4px 0 0; padding-left: 18px; }

.controls { display: flex; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; min-width: 200px; }
.field.grow { flex: 1; }
.field select, .field input { font: inherit; font-size: 15px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 18px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; overflow-x: auto; max-width: 100%; }
.seg button { font: inherit; font-size: 13px; font-weight: 500; border: 0; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); text-align: left; font: inherit; color: inherit; cursor: pointer; }
.tile:hover { border-color: var(--accent); }
.tile .num { font-family: Fraunces, Georgia, serif; font-size: 30px; font-weight: 600; line-height: 1.1; }
.tile .num small { font-size: 15px; color: var(--muted); font-weight: 500; }
.tile .lbl { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tile.ready .num { color: var(--ready); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.panel h2 { margin-bottom: 8px; }

.table-wrap { overflow-x: auto; }
table.churches { width: 100%; border-collapse: collapse; font-size: 14px; }
.churches th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.churches td { padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.churches tr:last-child td { border-bottom: 0; }
.churches tbody tr { cursor: pointer; }
.churches tbody tr:hover td { background: var(--surface-2); }
.churches td.name { font-weight: 500; }
.bar { display: inline-block; vertical-align: middle; width: 70px; height: 6px; border-radius: 3px; background: var(--idle-bg); margin-left: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ready); }

.people { list-style: none; margin: 0; padding: 0; }
.person { display: flex; gap: 12px; align-items: center; padding: 12px 6px; border-top: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
.person:first-child { border-top: 0; }
.person:hover { background: var(--surface-2); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2); color: var(--accent); display: grid; place-items: center; font-weight: 600; font-size: 14px; flex: none; }
.p-main { flex: 1; min-width: 0; }
.p-name { font-weight: 600; }
.p-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-tracks { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill.ready { background: var(--ready-bg); color: var(--ready); }
.pill.in_progress { background: var(--progress-bg); color: var(--progress); }
.pill.not_started { background: var(--idle-bg); color: var(--idle); }
.pill .t { opacity: .75; }
.flag { color: var(--fail); font-size: 12px; }
.pill.ordained { background: #f6ebd3; color: #8a6420; }
.tile.ordained .num { color: var(--gold); }
.rank-badge { display: inline-block; margin: 2px 0 6px; padding: 3px 10px; border-radius: 999px; background: #f6ebd3; color: #8a6420; font-size: 13px; font-weight: 600; }
.rank-mini { font-size: 11px; font-weight: 600; color: #8a6420; background: #f6ebd3; border-radius: 999px; padding: 1px 7px; margin-left: 4px; vertical-align: 2px; }
.btn.gold { background: var(--gold); color: #fff; border-color: transparent; }
.btn.gold:disabled { opacity: .6; }
.ord { margin: 12px 0 4px; }
.ord > .btn { width: 100%; }
.ordained-line { background: #f6ebd3; color: #6e4f17; border-radius: 10px; padding: 10px 12px; font-size: 14px; font-weight: 500; }
.ord-actions { display: block; margin-top: 6px; }
.link { font: inherit; font-size: 13px; background: none; border: 0; padding: 0; margin-right: 14px; color: var(--accent); cursor: pointer; font-weight: 600; }
.link.danger { color: var(--fail); }
.ord-form { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.ord-form .field { min-width: 0; }
.ord-warn { margin: 0; font-size: 13px; color: var(--progress); background: var(--progress-bg); border-radius: 8px; padding: 8px 10px; }
.ord-buttons { display: flex; gap: 8px; }
.ord-buttons .btn { flex: 1; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pill.ordained, :root:not([data-theme="light"]) .rank-badge, :root:not([data-theme="light"]) .rank-mini, :root:not([data-theme="light"]) .ordained-line { background: #3a2e17; color: #e8c983; }
}

.empty { text-align: center; color: var(--muted); padding: 24px 0; }
.foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

/* drawer */
.drawer { position: fixed; inset: 0; z-index: 20; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(20, 14, 10, .35); }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--bg); overflow-y: auto; padding: 24px; box-shadow: -8px 0 30px rgba(0, 0, 0, .15); }
.close { position: absolute; top: 14px; right: 14px; border: 0; background: var(--surface-2); color: var(--text); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 14px; }
.d-head { margin-bottom: 16px; padding-right: 40px; }
.d-head h1 { font-size: 24px; margin: 0 0 2px; }
.track-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.track-card .tc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.track-card h2 { font-size: 17px; margin: 0; }
.steps { list-style: none; margin: 10px 0 0; padding: 0; }
.step { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.step:first-child { border-top: 0; }
.ico { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; margin-top: 1px; }
.ico.complete { background: var(--ready); color: var(--surface); }
.ico.in_progress, .ico.pending { background: var(--progress-bg); color: var(--progress); border: 1.5px solid var(--progress); }
.ico.failed { background: var(--fail-bg); color: var(--fail); border: 1.5px solid var(--fail); }
.ico.not_started { border: 1.5px solid var(--line); background: transparent; }
.step-body { flex: 1; min-width: 0; }
.step-label { font-weight: 500; }
.step-detail { font-size: 13px; color: var(--muted); }
.step-note { font-size: 13px; color: var(--fail); }
details.sub { margin-top: 6px; font-size: 13px; }
details.sub summary { cursor: pointer; color: var(--accent); }
details.sub ul { list-style: none; padding: 0; margin: 6px 0 0; }
details.sub li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; color: var(--muted); }
details.sub li .st { font-size: 12px; }
details.sub li .st.complete, details.sub li .st.completed { color: var(--ready); }
details.sub li .st.failed { color: var(--fail); }

.controls { align-items: flex-end; }
.reports { position: relative; }
.reports .btn { padding: 10px 18px; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; width: 290px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(40, 30, 20, .15); padding: 6px; }
.menu button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left; font: inherit; background: none; border: 0; border-radius: 8px; padding: 10px 12px; color: var(--text); cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); }
.menu button span { font-size: 12px; color: var(--muted); }
.menu-note { font-size: 12px; color: var(--muted); margin: 4px 12px 6px; }
.churches tr.region-row td { background: var(--surface-2); font-weight: 600; }
.churches tr.region-row td.name { font-family: Fraunces, Georgia, serif; }
.churches tbody tr:not(.region-row) td.name { padding-left: 20px; }

@media (max-width: 640px) {
  .reports { flex: 1 1 100%; }
  .reports .btn { width: 100%; }
  .menu { left: 0; right: 0; width: auto; }
  .topbar { padding: 12px 16px; }
  .brand { font-size: 17px; }
  #who-name { display: none; }
  .wrap { padding: 16px 16px 32px; }
  .field { min-width: 0; flex: 1 1 100%; }
  .filters { flex-direction: column; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .p-tracks .t { display: none; }
  .drawer-panel { padding: 20px 16px; }
}

/* bulk ordain */
.head-right { display: inline-flex; align-items: center; gap: 12px; }
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 14, 10, .4); }
.modal-panel { position: relative; width: min(620px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--bg); border-radius: 18px; padding: 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal-panel h1 { margin: 0 0 2px; font-size: 24px; }
.modal-panel > p { margin: 0 0 14px; }
.bulk-controls { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.bulk-controls .field { min-width: 180px; }
.bulk-tools { margin: 14px 0 6px; }
.bulk-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 120px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.bulk-list li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.bulk-list li:first-child { border-top: 0; }
.bulk-list li.disabled { cursor: default; opacity: .55; }
.bulk-list li:not(.disabled):hover { background: var(--surface-2); }
.bulk-list input { width: 18px; height: 18px; accent-color: var(--gold); flex: none; }
.bulk-list .b-main { flex: 1; min-width: 0; }
.bulk-list .b-name { font-weight: 600; }
.bulk-list .b-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bulk-list .b-empty { justify-content: center; color: var(--muted); cursor: default; }
.bulk-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40; background: #3a2e17; color: #f6ebd3; padding: 12px 18px; border-radius: 999px; font-weight: 500; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
@media (max-width: 640px) {
  .modal { padding: 0; place-items: end stretch; }
  .modal-panel { width: 100%; max-height: 92vh; border-radius: 18px 18px 0 0; padding: 20px 16px; }
  .bulk-footer .btn { flex: 1; }
}

/* servants */
:root { --servant: #2f5d8a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --servant: #8db4e0; } }
.tile.servants { cursor: default; }
.tile.servants:hover { border-color: var(--line); }
.tile.servants .num { color: var(--servant); }
.bar.servant i { background: var(--servant); }

.addr { font-weight: 400; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 340px; }

/* How-to guide */
.guide { width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 64px); border: 1px solid var(--line); border-radius: 18px; padding: 28px; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.guide::backdrop { background: rgba(20, 12, 10, .45); }
.guide-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.guide h1 { font-size: 26px; margin: 2px 0 0; }
.guide-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--gold); }
.guide-intro { color: var(--muted); line-height: 1.55; margin: 12px 0 18px; }
.guide details { border-top: 1px solid var(--line); padding: 12px 0; }
.guide details:last-of-type { border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.guide summary { cursor: pointer; font-weight: 600; font-size: 16px; list-style: none; display: flex; justify-content: space-between; }
.guide summary::after { content: "+"; color: var(--accent); font-weight: 600; }
.guide details[open] summary::after { content: "–"; }
.guide summary::-webkit-details-marker { display: none; }
.guide ol { margin: 10px 0 4px; padding-left: 22px; line-height: 1.6; }
.guide li { margin: 4px 0; }
.guide .tip { margin: 8px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--progress-bg); font-size: 14px; }
.guide a { color: var(--accent); }

/* installed app (Android home screen) and small phones */
.brand .short { display: none; }
.install-btn { white-space: nowrap; }
#install-signin { margin-top: 12px; width: 100%; }
.install-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); }
.install-banner[hidden] { display: none; }
.install-actions { display: inline-flex; gap: 8px; }
.brand, .who .btn { white-space: nowrap; }
.seg { scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
@media (display-mode: standalone) {
  .topbar { padding-top: max(14px, env(safe-area-inset-top)); }
  .wrap { padding-bottom: max(32px, env(safe-area-inset-bottom)); }
}
@media (max-width: 480px) {
  #who-role { display: none; }
  .brand { font-size: 16px; }
  .brand .full { display: none; }
  .brand .short { display: inline; }
  .who { gap: 6px; }
  .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .controls > .field.grow, .controls > .reports, #region-field[hidden] + #church-field { grid-column: 1 / -1; }
}

/* ---------- servant stewards ---------- */
/* A steward sees only their church's servants: hide the reader/subdeacon parts of the page. */
.is-steward #people-panel, .is-steward .filters, .is-steward #by-church, .is-steward #region-field, .is-steward #church-field,
.is-steward #reports-menu [data-report="ordination"], .is-steward #reports-menu button[data-report="church"]:not([data-track]) { display: none !important; }
.tile.servants.alt { background: var(--surface); }
.pill.certified { background: var(--servant-bg, #e3ecf5); color: var(--servant, #2f5d8a); }
.pill.not_certified { background: var(--idle-bg); color: var(--idle); }
.stewards { list-style: none; margin: 8px 0 14px; padding: 0; }
.stewards li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.stewards li:first-child { border-top: 0; }
.stewards .s-main { flex: 1; min-width: 0; }
.stewards .s-name { font-weight: 500; }
.stewards .s-sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.stewards .none { color: var(--muted); font-size: 14px; padding: 6px 0; border-top: 0; }
.steward-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.steward-form .field { min-width: 180px; }
.steward-intro { margin: 0 0 4px; }
#steward-msg.ok { color: var(--ready); }
@media (max-width: 640px) {
  .steward-form .field, .steward-form .btn { width: 100%; min-width: 0; }
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill.certified { background: #1c2a38; color: #8db4e0; } }
.btn.danger-text { color: var(--fail); }
