:root {
  --bg: #f2f5f4;
  --bg-elev: #ffffff;
  --ink: #142322;
  --muted: #5c6e6c;
  --line: #d5e0de;
  --brand: #0f3d3e;
  --brand-2: #1a5c5e;
  --accent: #c45c26;
  --accent-soft: #f8e8de;
  --ok: #1b7a4a;
  --ok-bg: #e6f5ec;
  --danger: #b42318;
  --danger-bg: #fdeceb;
  --pend: #9a6700;
  --pend-bg: #fff6db;
  --shadow: 0 8px 24px rgba(20, 35, 34, 0.08);
  --radius: 12px;
  --nav-h: 64px;
  --top-h: 52px;
  --font: "Segoe UI", "Helvetica Neue", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d9ebea 0%, transparent 55%),
    linear-gradient(180deg, #e8efee 0%, var(--bg) 40%);
}

body {
  min-width: 360px;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.brand {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: -0.03em;
  color: var(--brand);
}

.brand-sm {
  color: var(--brand);
  font-size: 1rem;
}

/* Login */
.view-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.login-card {
  width: min(100%, 400px);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: grid;
  gap: 0.85rem;
}

/* Shell */
.shell {
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: var(--top-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  background: rgba(242, 245, 244, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.user-name {
  display: block;
  font-size: 0.8rem;
}

.content {
  max-width: 920px;
  margin: 0 auto;
  padding: 1rem 1rem 1.5rem;
}

.view h2 {
  margin: 0 0 0.85rem;
  font-size: 1.25rem;
}

.comp-title {
  margin: 0;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.row-gap {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.flex-1 {
  flex: 1;
  min-width: 0;
}

/* Forms */
label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.65rem;
}

.field-inline {
  margin-bottom: 0.85rem;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(26, 92, 94, 0.35);
  border-color: var(--brand-2);
}

.form-stack,
.form-filters {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem;
  margin-bottom: 1rem;
}

.form-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.65rem;
}

.form-filters label {
  margin: 0;
}

.form-filters .btn {
  grid-column: 1 / -1;
  margin-top: 0.35rem;
}

/* Buttons */
.btn {
  border: 0;
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  cursor: pointer;
  background: #e7eeed;
  color: var(--ink);
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.btn-secondary {
  background: #d9e7e6;
  color: var(--brand);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
  margin: 0.5rem 0 1rem;
}

.btn-accent.is-quiet {
  background: var(--accent-soft);
  color: #8a3d14;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.btn-sm {
  padding: 0.4rem 0.65rem;
  font-size: 0.85rem;
}

.btn-icon {
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border-radius: 999px;
}

.btn-block {
  width: 100%;
}

.btn-tiny {
  padding: 0.28rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 8px;
}

/* Cards */
.cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.card .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card .value {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 0.2rem;
}

.valor-receita {
  color: var(--ok);
}

.valor-despesa {
  color: var(--danger);
}

/* Lista / grupos */
.lista {
  display: grid;
  gap: 0.65rem;
}

.grupo {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.grupo-head {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 0.85rem;
  background: #eef4f3;
  border: 0;
  cursor: pointer;
  text-align: left;
  font-weight: 700;
}

.grupo-body {
  display: grid;
}

.grupo.collapsed .grupo-body {
  display: none;
}

.item {
  padding: 0.75rem 0.85rem;
  border-top: 1px solid var(--line);
}

.item-top {
  display: flex;
  justify-content: space-between;
  gap: 0.65rem;
  align-items: flex-start;
}

.item-desc {
  font-weight: 600;
  margin: 0 0 0.2rem;
}

.item-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

.item-valor {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  margin-top: 0.25rem;
}

.badge-pendente {
  background: var(--pend-bg);
  color: var(--pend);
}

.badge-pago {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge-cancelado {
  background: #eee;
  color: #666;
}

.badge-atrasado {
  background: var(--danger-bg);
  color: var(--danger);
}

.item-acoes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.item.atrasado {
  background: #fff8f7;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 1.5rem 0.5rem;
}

/* Tabs / nav */
.tabs {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  margin-bottom: 0.85rem;
  padding-bottom: 0.15rem;
}

.tab {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  white-space: nowrap;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0));
  padding: 0.35rem 0.4rem env(safe-area-inset-bottom, 0);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.15rem;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.bottom-nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  border-radius: 10px;
  padding: 0.35rem 0.15rem;
}

.bottom-nav a.active {
  color: var(--brand);
  background: #e4efee;
}

/* Relatórios */
.moeda-bloco {
  margin-bottom: 1.25rem;
}

.moeda-bloco h3 {
  margin: 0 0 0.65rem;
  font-size: 1rem;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  min-width: 520px;
}

table.data th,
table.data td {
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

table.data th:first-child,
table.data td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: #fff;
}

table.data th {
  background: #eef4f3;
  font-weight: 700;
}

.serie-title {
  margin: 1rem 0 0.4rem;
  font-size: 0.95rem;
}

.cfg-list {
  display: grid;
  gap: 0.5rem;
}

.cfg-item {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.8rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
}

.code {
  background: #142322;
  color: #d7eceb;
  padding: 0.75rem;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.8rem;
}

/* Modal */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 35, 34, 0.45);
}

.modal {
  position: relative;
  width: min(100%, 520px);
  max-height: min(88vh, 720px);
  overflow: auto;
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 1rem 1rem 1.25rem;
  box-shadow: var(--shadow);
}

.modal h3 {
  margin: 0 0 0.75rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.modal-actions .btn {
  flex: 1;
}

@media (min-width: 720px) {
  .modal-root {
    place-items: center;
  }

  .modal {
    border-radius: 16px;
  }

  .cards-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .form-filters {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Toast / loading */
.toast-root {
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  top: 0.75rem;
  z-index: 80;
  display: grid;
  gap: 0.45rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: #142322;
  color: #fff;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}

.toast.ok {
  background: var(--ok);
}

.toast.err {
  background: var(--danger);
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(242, 245, 244, 0.35);
}

.spinner {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: 3px solid #c5d5d3;
  border-top-color: var(--brand);
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.paginacao {
  margin-top: 0.75rem;
}

.check-list {
  display: grid;
  gap: 0.45rem;
  max-height: 50vh;
  overflow: auto;
}

.check-item {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.check-item strong {
  display: block;
}
