:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --ink: #1c2233;
  --muted: #6b7080;
  --line: #e7e4dc;
  --brand: #23365c;        /* azul-noite */
  --brand-ink: #1a2947;
  --accent: #b7862c;       /* dourado */
  --accent-ink: #8a6215;
  --link: #2f5aa8;
  --danger: #c0392b;
  --warn: #b45309;
  --ok: #15803d;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(28,34,51,.06), 0 8px 24px rgba(28,34,51,.05);
}

* { box-sizing: border-box; }
body { margin: 0; font-family: "Plus Jakarta Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .4em; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }

/* ---------- App shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 236px; background: var(--brand-ink); color: #c9d1e3; padding: 18px 12px;
  position: sticky; top: 0; height: 100vh; flex-shrink: 0; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; color: #fff;
  font-size: 1.22rem; padding: 6px 10px 18px; letter-spacing: -.02em; }
.brand .mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; color: #fff; font-size: 1rem; }
.brand-row { display: flex; align-items: center; justify-content: space-between; }
.menu { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.menu-btn { display: none; }
.nav { flex: 1; overflow-y: auto; }
.nav .sec { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #7d89a6;
  padding: 14px 12px 4px; font-weight: 700; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: #c9d1e3; font-weight: 500; margin-bottom: 1px; font-size: .93rem; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(183,134,44,.18); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav .ico { width: 20px; text-align: center; }
.sidebar .foot { font-size: .8rem; color: #8a94ad; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar .foot strong { color: #dfe4ef; display: block; }
.sidebar .foot a { color: #8a94ad; }

.main { flex: 1; min-width: 0; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); padding: 13px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar .who { font-size: .8rem; color: var(--muted); }
.content { padding: 26px 28px 60px; max-width: 1140px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: 10px 12px; }
  .brand { padding: 4px 6px; }
  .menu { display: block; padding-top: 8px; }
  /* Menu recolhido atrás do botão: a tela pequena fica para o conteúdo. */
  .sidebar.recolhido .menu { display: none; }
  .menu-btn { display: inline-flex; align-items: center; background: rgba(255,255,255,.1); color: #fff;
    border: 1px solid rgba(255,255,255,.18); border-radius: 9px; padding: 9px 16px; font: inherit;
    font-weight: 600; cursor: pointer; }
  .menu-btn[hidden] { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav a { padding: 11px 12px; }
  .nav .sec { display: none; }
  .content { padding: 18px 14px 40px; }
  .topbar { padding: 11px 14px; }
}

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
/* Dentro da grade o espaço vem do gap; a margem acima empurraria todas as caixas menos a primeira. */
.grid > .card + .card { margin-top: 0; }
.card.flush { padding: 0; overflow-x: auto; }
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.side { grid-template-columns: minmax(0,2fr) minmax(0,1fr); align-items: start; }
@media (max-width: 860px) { .grid.cols-2, .grid.cols-3, .grid.cols-4, .grid.side { grid-template-columns: 1fr; } }
.mt { margin-top: 16px; }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.stat .value { font-size: 1.75rem; font-weight: 800; margin-top: 2px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: .8rem; color: var(--muted); }
.pos { color: var(--ok); } .neg { color: var(--danger); }

.btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; border: 1px solid transparent;
  border-radius: 9px; padding: 8px 15px; font-weight: 600; font-size: .9rem; font-family: inherit;
  background: var(--brand); color: #fff; text-decoration: none; transition: filter .15s; white-space: nowrap; }
.btn:hover { filter: brightness(1.12); text-decoration: none; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.accent { background: var(--accent); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: .82rem; }
.btn.link { background: none; color: var(--link); padding: 0; border: none; font-weight: 500; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #faf9f6; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
tr.struck td { color: var(--muted); text-decoration: line-through; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700; background: #efede7; color: var(--muted); white-space: nowrap; }
.badge.visitante { background: #fef3c7; color: #92400e; }
.badge.congregado { background: #e0ecff; color: #1e4fa8; }
.badge.membro { background: #dcfce7; color: #166534; }
.badge.afastado { background: #f3e8ff; color: #6b21a8; }
.badge.desligado { background: #efede7; color: #6b7080; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.gold { background: #fbf0d9; color: var(--accent-ink); }
.badge.blue { background: #e0ecff; color: #1e4fa8; }

.pagehead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.pagehead .sub { color: var(--muted); margin: -4px 0 0; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .em { font-size: 2rem; margin-bottom: 6px; }

label { display: block; font-weight: 600; font-size: .84rem; margin: 12px 0 5px; }
input, select, textarea { width: 100%; padding: 8px 11px; border: 1px solid #d9d5cb; border-radius: 9px;
  font: inherit; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
textarea { min-height: 72px; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 14px; }
.form-row.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
@media (max-width: 640px) { .form-row, .form-row.three { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 12px 0 0; }
.check input { width: auto; }
.help { font-size: .8rem; color: var(--muted); margin-top: 4px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 4px 16px 16px; margin: 16px 0 0; }
legend { font-weight: 700; font-size: .85rem; padding: 0 6px; color: var(--brand); }
.form-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }

.flash { padding: 11px 15px; border-radius: 9px; margin-bottom: 12px; font-weight: 500; }
.flash.success { background: #dcfce7; color: #166534; }
.flash.danger  { background: #fee2e2; color: #991b1b; }
.flash.warning { background: #fef3c7; color: #92400e; }
.flash.info    { background: #e0ecff; color: #1e4fa8; }

.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 200px; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 6px 13px; border-radius: 8px; font-weight: 600; font-size: .86rem; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line); }
.tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tabs a:hover { text-decoration: none; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 600; font-size: .86rem; }
.kv dd { margin: 0; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 9px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.list li:last-child { border-bottom: none; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0 10px 18px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent); }
.timeline .meta { font-size: .78rem; color: var(--muted); }

.datebox { width: 52px; text-align: center; border-radius: 9px; background: #f3efe5; padding: 4px 0; flex-shrink: 0; }
.datebox .d { font-weight: 800; font-size: 1.2rem; line-height: 1.1; }
.datebox .m { font-size: .68rem; text-transform: uppercase; color: var(--accent-ink); font-weight: 700; }
.evrow { display: flex; gap: 14px; align-items: center; }

.attend { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.attend label { margin: 0; display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 9px; cursor: pointer; font-weight: 500; background: #fff; }
.attend input { width: 18px; height: 18px; }
.attend label:has(input:checked) { border-color: var(--ok); background: #f0fdf4; }

.meter { height: 6px; background: #efede7; border-radius: 99px; overflow: hidden; min-width: 60px; }
.meter > span { display: block; height: 100%; background: var(--accent); }

.tithe-row { display: grid; grid-template-columns: minmax(0,3fr) minmax(0,1.3fr) minmax(0,1.3fr) 36px; gap: 8px; margin-bottom: 8px; }

/* auth & público */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 20% 10%, #fbf0d9, transparent 40%), linear-gradient(160deg, #f5f4f0, #e8ecf4); }
.auth-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 32px; width: 100%; max-width: 430px; }
.auth-card .brand { color: var(--ink); justify-content: center; padding: 0 0 14px; }

/* impressão (recibo, informe, relatórios) */
.paper { background: #fff; max-width: 760px; margin: 0 auto; padding: 40px; border: 1px solid var(--line); border-radius: 8px; }
/* ---------- Foto da pessoa ---------- */
.avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  object-fit: cover; background: #e3e7f0; color: var(--brand); font-weight: 700; font-size: .85rem;
  vertical-align: middle; flex: none; overflow: hidden; }
.avatar[hidden], .btn[hidden] { display: none; }
.avatar.sm { width: 30px; height: 30px; font-size: .7rem; }
.avatar.lg { width: 64px; height: 64px; font-size: 1.2rem; }
.avatar.xl { width: 112px; height: 112px; font-size: 1.8rem; }
.com-avatar { display: flex; align-items: center; gap: 14px; }
.foto-campo { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.foto-campo input[type="file"] { max-width: 100%; }

/* ---------- Cadastro rápido (celular e tablet) ---------- */
.rapido { max-width: 620px; }
.rapido-ultimo { margin: 0 0 12px; color: var(--muted); }
/* 16px evita o zoom automático do iPhone ao tocar no campo; alvos de toque maiores. */
.rapido input:not([type="checkbox"]):not([type="file"]), .rapido select { font-size: 16px; padding: 12px 13px; }
.rapido input[type="file"] { font-size: 16px; padding: 12px 13px; }
.rapido label { font-size: .92rem; }
.rapido .check input { width: 22px; height: 22px; flex: none; }
.rapido .form-actions .btn { padding: 13px 18px; font-size: 1rem; }
@media (max-width: 640px) {
  .rapido .form-actions .btn { width: 100%; justify-content: center; }
}

@media print {
  .sidebar, .topbar, .no-print, .flash { display: none !important; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; }
  .paper, .card { border: none; box-shadow: none; }
}
