:root {
  --navy: #1f3a5f;
  --navy-2: #2c4f7c;
  --gold: #c8962e;
  --gold-soft: #fbf3e2;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2430;
  --muted: #667085;
  --line: #e3e7ee;
  --green: #1e8e5a;
  --green-soft: #e6f5ee;
  --amber: #b26b00;
  --amber-soft: #fff3df;
  --red: #c0392b;
  --red-soft: #fdecea;
  --blue-soft: #e8f0fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
a { color: var(--navy-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy); color: #fff;
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem 1rem;
}
.topbar .brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: .5rem; }
.topbar .brand small { font-weight: 400; opacity: .75; font-size: .78rem; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .82rem; opacity: .85; text-align: right; }
.topbar button.link { color: #fff; opacity: .85; }
.nav {
  background: #fff; border-bottom: 1px solid var(--line);
  display: flex; gap: .25rem; overflow-x: auto; padding: 0 .5rem;
  position: sticky; top: 48px; z-index: 19;
}
.nav a {
  padding: .7rem .8rem; white-space: nowrap; color: var(--muted); font-weight: 500;
  border-bottom: 3px solid transparent;
}
.nav a.active { color: var(--navy); border-bottom-color: var(--gold); }
.nav a:hover { text-decoration: none; color: var(--navy); }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; padding-bottom: 5rem; }

/* ---------- cards & grids ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: .75rem; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: .85rem 1rem; }
.stat .n { font-size: 1.7rem; font-weight: 700; color: var(--navy); line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .82rem; }
.stat.warn .n { color: var(--amber); }
.stat.bad .n { color: var(--red); }
.stat.good .n { color: var(--green); }
a.stat:hover { text-decoration: none; outline: 2px solid var(--gold-soft); }

.page-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; flex: 1; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- forms ---------- */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; font-weight: 500; }
input, select, textarea {
  width: 100%; font: inherit; padding: .6rem .7rem; border: 1px solid #cfd5df; border-radius: 9px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: .95rem; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .75rem 1rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 600; color: var(--navy); padding: 0 .3rem; }

button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 9px; padding: .6rem 1rem; cursor: pointer;
  background: var(--navy); color: #fff; display: inline-flex; align-items: center; gap: .4rem; text-decoration: none;
}
button:hover, .btn:hover { background: var(--navy-2); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.secondary, .btn.secondary { background: #fff; color: var(--navy); border: 1px solid #cfd5df; }
button.secondary:hover { background: #f0f3f8; }
button.gold { background: var(--gold); }
button.gold:hover { background: #b5841f; }
button.danger { background: var(--red); }
button.small, .btn.small { padding: .35rem .65rem; font-size: .85rem; }
button.link { background: none; color: var(--navy-2); padding: 0; font-weight: 500; }
button.link:hover { text-decoration: underline; background: none; }

/* ---------- pills & tags ---------- */
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 600; background: #eef1f5; color: #475467; white-space: nowrap; }
.pill.good { background: var(--green-soft); color: var(--green); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.bad { background: var(--red-soft); color: var(--red); }
.pill.blue { background: var(--blue-soft); color: var(--navy-2); }
.pill.gold { background: var(--gold-soft); color: #8a6414; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .3px; background: #fafbfc; }
tr:hover td { background: #fafbfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- avatar ---------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--blue-soft); color: var(--navy); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .9rem; flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 72px; height: 72px; font-size: 1.3rem; }

/* ---------- roll ---------- */
.roll-bar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; }
.roll-bar > div { flex: 1; min-width: 140px; }
.roll-count { font-size: 1.1rem; font-weight: 700; color: var(--navy); }
.roll-list { display: flex; flex-direction: column; gap: .4rem; }
.roll-item {
  display: flex; align-items: center; gap: .75rem; background: #fff; border-radius: 12px; padding: .55rem .7rem;
  box-shadow: var(--shadow); border: 2px solid transparent; user-select: none;
}
.roll-item .who { flex: 1; min-width: 0; cursor: pointer; }
.roll-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roll-item .sub { font-size: .8rem; color: var(--muted); }
.roll-item.present { border-color: var(--green); background: var(--green-soft); }
.roll-item.absent { border-color: #f0c2bc; }
.roll-item.coded { border-color: #f3d39b; background: var(--amber-soft); }
.mark-btns { display: flex; gap: .3rem; }
.mark-btns button { padding: .45rem .7rem; font-size: .85rem; }
.mark-btns .on-present { background: var(--green); }
.mark-btns .off { background: #fff; color: var(--muted); border: 1px solid #cfd5df; }
.mark-btns .on-absent { background: var(--red); }
.mark-btns .on-code { background: var(--amber); }
.sync-note { font-size: .82rem; padding: .4rem .7rem; border-radius: 8px; background: var(--amber-soft); color: var(--amber); }
.banner { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: .92rem; }
.banner.info { background: var(--blue-soft); color: var(--navy); }
.banner.warn { background: var(--amber-soft); color: #7a4a00; }
.banner.good { background: var(--green-soft); color: #145c3b; }
.banner.bad { background: var(--red-soft); color: #8e2a1f; }

/* ---------- task cards ---------- */
.task { border-left: 4px solid var(--line); }
.task.l1 { border-left-color: #8fb3e6; }
.task.l2 { border-left-color: var(--gold); }
.task.l3 { border-left-color: var(--red); }
.task.care { border-left-color: var(--green); }
.task .head { display: flex; gap: .6rem; align-items: start; }
.task .head .who { flex: 1; }
.area-head { margin: 1.25rem 0 .5rem; color: var(--navy); font-weight: 700; display: flex; align-items: center; gap: .5rem; }

/* ---------- months strip ---------- */
.months { display: flex; gap: .35rem; flex-wrap: wrap; }
.month { min-width: 64px; text-align: center; padding: .4rem .45rem; border-radius: 9px; background: #eef1f5; font-size: .8rem; }
.month b { display: block; font-size: .95rem; }
.month.good { background: var(--green-soft); color: var(--green); }
.month.bad { background: var(--red-soft); color: var(--red); }
.dots { display: flex; gap: 3px; flex-wrap: wrap; }
.dot { width: 14px; height: 14px; border-radius: 4px; background: #e3e7ee; font-size: 9px; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.dot.present { background: var(--green); }
.dot.absent { background: var(--red); }
.dot.code { background: var(--amber); }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal-back { align-items: center; } }
.modal { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 1.1rem 1.1rem 1.4rem; }
@media (min-width: 640px) { .modal { border-radius: 16px; } }
.modal .actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
.code-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.code-grid button { justify-content: center; padding: .8rem; }
#toast-root { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: .4rem; align-items: center; }
.toast { background: #1d2430; color: #fff; padding: .6rem 1rem; border-radius: 10px; font-size: .9rem; box-shadow: var(--shadow); max-width: 90vw; }
.toast.bad { background: var(--red); }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(160deg, var(--navy) 0%, #13273f 100%); }
.auth-card { background: #fff; border-radius: 16px; padding: 1.6rem; width: 100%; max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.auth-card .logo { width: 48px; height: 48px; margin-bottom: .5rem; }
.auth-card form > div { margin-bottom: .8rem; }
.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; background: #eef1f5; padding: .25rem; border-radius: 10px; }
.tabs button { flex: 1; background: transparent; color: var(--muted); padding: .45rem; justify-content: center; }
.tabs button.active { background: #fff; color: var(--navy); box-shadow: var(--shadow); }

/* ---------- chart ---------- */
.chart svg { width: 100%; height: auto; display: block; }

/* ---------- print ---------- */
.print-only { display: none; }
@media print {
  .topbar, .nav, .no-print, #toast-root, button { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; padding: 0; }
  .certificate { page-break-after: always; }
}
.certificate {
  border: 6px double var(--gold); padding: 3rem 2rem; text-align: center; margin: 1rem 0; background: #fffdf8; min-height: 520px;
  display: flex; flex-direction: column; justify-content: center; gap: .6rem;
}
.certificate .church { font-size: 1rem; letter-spacing: 2px; text-transform: uppercase; color: var(--navy); }
.certificate .title { font-size: 2rem; font-family: Georgia, serif; color: var(--navy); }
.certificate .name { font-size: 2.2rem; font-family: Georgia, serif; color: #8a6414; margin: .6rem 0; }
.certificate .sig { display: flex; justify-content: space-around; margin-top: 2.5rem; }
.certificate .sig div { border-top: 1px solid #555; padding-top: .3rem; min-width: 200px; font-size: .9rem; }

/* ---------- small phones ---------- */
@media (max-width: 600px) {
  .topbar { padding: .55rem .75rem; }
  .topbar .brand small, .topbar .who small { display: none; }
  .topbar .who { font-size: .78rem; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav { position: static; }
  main { padding: .75rem; }
  .mark-btns button { padding: .5rem .6rem; }
  .page-head h1 { font-size: 1.2rem; }
}
