:root {
  --bg: #f4f6f2;
  --surface: #ffffff;
  --ink: #1d2a25;
  --muted: #66746e;
  --line: #dde5dc;
  --green: #1f6b4a;
  --green-2: #2e8a61;
  --blue: #315c96;
  --gold: #b48128;
  --red: #b4443f;
  --shadow: 0 18px 48px rgba(29, 42, 37, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

body.logged-out {
  display: block;
}

body.logged-out .sidebar,
body.logged-out .shell {
  display: none;
}

body.logged-in .login-screen {
  display: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(244, 246, 242, 0.9), rgba(244, 246, 242, 0.94)),
    url("assets/logo-semadeb.jpg") center / min(70vw, 680px) no-repeat;
}

.login-card {
  width: min(100%, 420px);
  display: grid;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-logo {
  width: 88px;
  height: 88px;
  object-fit: contain;
}

.form-message {
  min-height: 20px;
  color: var(--red);
  font-weight: 800;
  font-size: 0.9rem;
}

.sidebar {
  min-height: 100vh;
  padding: 24px;
  background: #17231f;
  color: #f7fbf7;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-logo {
  width: 58px;
  height: 58px;
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
  padding: 4px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.side-note span {
  color: #b9c8c0;
  font-size: 0.84rem;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-btn {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  color: #e9f1ed;
  background: transparent;
  text-align: left;
}

.nav-btn:hover,
.nav-btn.active {
  background: #263730;
}

.side-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.side-note strong {
  display: block;
  margin-top: 4px;
}

.shell {
  padding: 28px;
  min-width: 0;
}

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.title-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.title-logo {
  width: 58px;
  height: 58px;
  object-fit: contain;
}

.eyebrow {
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 4px;
  font-size: 2rem;
}

h2 {
  font-size: 1.05rem;
}

p {
  color: var(--muted);
  margin-top: 4px;
}

.period-control {
  display: grid;
  gap: 6px;
  min-width: 190px;
}

.user-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-control span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.kpi,
.panel,
.receipt {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi {
  padding: 18px;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
}

.kpi strong {
  display: block;
  margin-top: 10px;
  font-size: 1.55rem;
}

.dashboard-grid,
.split {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
  gap: 14px;
}

.other-income-panel {
  margin-top: 14px;
}

.annual-panel {
  margin-top: 14px;
}

.annual-ranking-block {
  margin-top: 18px;
}

.panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-head span {
  color: var(--muted);
  font-size: 0.85rem;
}

.primary,
.ghost,
.danger {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
  white-space: nowrap;
}

.primary {
  background: var(--green);
  color: #fff;
}

.ghost {
  background: #eef4f0;
  color: var(--green);
}

.danger {
  background: #f7e8e7;
  color: var(--red);
}

.table-tools,
.actions,
.tabs {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.tab-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.tab-btn.active {
  border-color: var(--green);
  background: #e8f2ee;
  color: var(--green);
}

.table-tools input {
  flex: 1;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f5f8f5;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td input {
  width: 110px;
  padding: 8px;
}

.bar-list,
.ranking,
.list,
.missionary-grid,
.report-summary {
  display: grid;
  gap: 10px;
}

.report-summary {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-bottom: 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: 96px 1fr 110px;
  gap: 10px;
  align-items: center;
}

.bar-track {
  height: 12px;
  border-radius: 8px;
  background: #e7eee9;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--green-2), var(--blue));
}

.rank-item,
.list-item,
.report-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfb;
}

.rank-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.muted {
  color: var(--muted);
}

.form-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.inline-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  padding: 16px;
  margin-bottom: 18px;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.inline-form h2,
.inline-form button {
  align-self: end;
}

.inline-form h2 {
  grid-column: 1 / -1;
}

.compact-inline-form {
  grid-template-columns: minmax(220px, 1fr) 180px 180px auto;
}

.missionary-workspace {
  display: grid;
  gap: 12px;
}

.subhead {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.subhead-total {
  color: var(--green);
  font-weight: 900;
  white-space: nowrap;
}

.area-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.list-item {
  display: grid;
  gap: 8px;
}

.scroll-list {
  max-height: calc(100vh - 285px);
  overflow-y: auto;
  padding-right: 6px;
}

.scroll-list::-webkit-scrollbar {
  width: 8px;
}

.scroll-list::-webkit-scrollbar-thumb {
  background: #c8d8cf;
  border-radius: 8px;
}

.list-item header,
.missionary-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.list-item small,
.missionary-card small {
  color: var(--muted);
}

.receipt {
  padding: 28px;
  min-height: 420px;
}

.receipt-head {
  text-align: center;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 14px;
  margin-bottom: 18px;
}

.receipt-head img {
  display: block;
  width: 82px;
  height: 82px;
  object-fit: contain;
  margin: 0 auto 10px;
}

.receipt-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 12px;
  margin: 12px 0;
}

.receipt-sign {
  margin-top: 54px;
  text-align: center;
}

.beneficiary-sign {
  margin-top: 46px;
}

.receipt-sign::before {
  content: "";
  display: block;
  width: 260px;
  border-top: 1px solid var(--ink);
  margin: 0 auto 8px;
}

.receipt-verse {
  margin: 24px 0 10px;
  padding: 14px;
  border-left: 4px solid var(--green);
  background: #f5f8f5;
  color: var(--ink);
  font-style: italic;
  line-height: 1.45;
}

.receipt-download {
  display: block;
  background: #fff;
  padding: 24px;
}

.receipt-download .receipt {
  max-width: 820px;
  margin: 0 auto;
}

.print-footer {
  margin-top: 28px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
  text-align: center;
}

.missionary-grid {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.missionary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdfb;
  display: grid;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  background: #e8f2ee;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.payroll-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf5f0;
  padding: 12px;
  margin-bottom: 12px;
}

.payroll-strip span {
  color: var(--green);
  font-weight: 900;
}

.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.permission-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 14px;
}

.permission-box legend {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  padding: 0 6px;
}

.backup-import-label {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px;
}

.summary-sheet {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.sheet-title {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  border-bottom: 2px solid var(--ink);
}

.sheet-title img {
  width: 70px;
  height: 70px;
  object-fit: contain;
}

.sheet-title strong,
.sheet-title span {
  display: block;
}

.sheet-title strong {
  font-size: 1.2rem;
}

.sheet-title span {
  color: var(--muted);
  text-transform: capitalize;
}

.summary-sheet table {
  min-width: 0;
}

.summary-sheet thead th {
  background: #edf5f0;
  color: var(--ink);
}

.total-row td {
  background: #f3f7f4;
  font-weight: 800;
}

.balance-row td {
  background: #e6f0f8;
  color: var(--blue);
  font-weight: 900;
}

.detail-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-list span {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
  padding: 8px 10px;
  font-size: 0.86rem;
}

@media print {
  @page {
    margin: 0;
  }

  body {
    display: block;
    background: #fff;
    padding: 12mm;
  }

  a[href]::after {
    content: "" !important;
  }

  .sidebar,
  .topbar,
  .view:not(#recibos),
  #recibos .form-panel {
    display: none !important;
  }

  body:has(#relatorios.active) .sidebar,
  body:has(#relatorios.active) .topbar,
  body:has(#relatorios.active) .view:not(#relatorios),
  body:has(#relatorios.active) .panel-head,
  body:has(#relatorios.active) .tabs,
  body:has(#relatorios.active) .actions {
    display: none !important;
  }

  body:has(#relatorios.active) #relatorios {
    display: block !important;
  }

  .shell {
    padding: 0;
  }

  #recibos,
  #recibos.active,
  .split {
    display: block;
  }

  .receipt {
    border: 0;
    box-shadow: none;
  }

  .print-footer {
    color: #111;
    break-inside: avoid;
  }

  .report-print,
  .summary-sheet,
  #relatorios .panel {
    border: 0;
    box-shadow: none;
  }
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    min-height: auto;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topbar,
  .panel-head,
  .user-control,
  .table-tools,
  .actions,
  .tabs {
    flex-direction: column;
    align-items: stretch;
  }

  .kpi-grid,
  .dashboard-grid,
  .split,
  .report-summary,
  .inline-form,
  .compact-inline-form {
    grid-template-columns: 1fr;
  }

  .subhead {
    flex-direction: column;
  }

  .scroll-list {
    max-height: 55vh;
  }
}

@media (max-width: 560px) {
  .shell,
  .sidebar {
    padding: 18px;
  }

  .nav {
    grid-template-columns: 1fr 1fr;
  }

  .kpi strong {
    font-size: 1.25rem;
  }
}
