:root {
  --verde: #0f9d58;
  --verde-esc: #0b7a44;
  --verde-fundo: #e7f6ee;
  --fundo: #f2f4f7;
  --card: #ffffff;
  --texto: #1b1f24;
  --cinza: #6b7280;
  --borda: #e5e7eb;
  --ambar-fundo: #fdf3e0;
  --ambar: #b45309;
  --azul-fundo: #e8f0fe;
  --azul: #1d4ed8;
  --vermelho: #dc2626;
  --raio: 16px;
  --sombra: 0 1px 3px rgba(0, 0, 0, .05), 0 4px 14px rgba(15, 60, 40, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--fundo);
  color: var(--texto);
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

/* ---------- topo ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(135deg, #12a55e 0%, #0b7a44 100%);
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  box-shadow: 0 2px 12px rgba(11, 122, 68, .25);
}
#topbar h1 { margin: 0; font-size: 22px; line-height: 1.2; color: #fff; }
#topbar .sub { color: rgba(255, 255, 255, .82); font-size: 13px; margin-top: 3px; text-transform: capitalize; }

/* ---------- views ---------- */
main, #bottomnav, #fab { display: none; }
body.logado main { display: block; }
body.logado #bottomnav { display: flex; }
body.logado #fab { display: block; }

.view { display: none; }
.view.active { display: block; animation: fadeIn .22s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- blocos e cards ---------- */
.bloco { margin: 14px 12px 0; }
.titulo-secao {
  display: flex; align-items: center; gap: 8px;
  margin: 0 4px 8px;
  font-size: 12px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .6px;
  color: var(--cinza);
}
.titulo-secao .qtd {
  background: var(--verde-fundo); color: var(--verde-esc);
  font-size: 11px; font-weight: 800;
  border-radius: 999px; padding: 2px 8px;
}
.cards {
  display: grid; grid-template-columns: 1fr;
  gap: 10px;
}
.card {
  background: var(--card);
  border-radius: var(--raio);
  padding: 14px 16px;
  box-shadow: var(--sombra);
  position: relative;
  animation: cardIn .28s ease both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.card.atrasada { border: 1.5px solid #fca5a5; }
.card.feita { opacity: .78; }
.card-topo { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-nome { font-size: 17px; font-weight: 700; }
.card-chips { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.card-del {
  position: absolute; top: 8px; right: 8px;
  border: 0; background: none; color: var(--cinza);
  font-size: 14px; width: 30px; height: 30px; border-radius: 8px;
}
.card-meio { display: flex; align-items: center; gap: 14px; margin-top: 10px; }
.hora {
  font-size: 30px; font-weight: 800; color: var(--verde-esc);
  min-width: 76px; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.card.atrasada .hora { color: var(--vermelho); }
.card-info { flex: 1; min-width: 0; }
.notas { color: var(--cinza); font-size: 13px; margin-top: 2px; }

.chip {
  font-size: 11px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  text-transform: capitalize;
  flex-shrink: 0;
}
.chip.ambar { background: var(--ambar-fundo); color: var(--ambar); }
.chip.azul  { background: var(--azul-fundo);  color: var(--azul); }
.chip.cinza { background: #eef0f2; color: #4b5563; }
.chip.verde { background: var(--verde-fundo); color: var(--verde-esc); }
.chip.vermelho { background: #fee2e2; color: var(--vermelho); }

.btn-limpei {
  width: 100%; margin-top: 12px;
  border: 0;
  background: linear-gradient(135deg, #12a55e, #0b7a44);
  color: #fff;
  font-size: 16px; font-weight: 700;
  padding: 13px; border-radius: 12px;
  box-shadow: 0 4px 12px rgba(15, 157, 88, .28);
  transition: transform .12s, box-shadow .12s;
}
.btn-limpei:active { transform: scale(.97); box-shadow: 0 2px 6px rgba(15, 157, 88, .2); }
.btn-limpei:disabled { opacity: .6; }

.feita-info {
  margin-top: 10px; color: var(--verde-esc); font-weight: 600; font-size: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.btn-reabrir {
  border: 1.5px solid var(--borda); background: #fff; color: var(--cinza);
  font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px;
  font-family: inherit; transition: background .12s;
}
.btn-reabrir:active { background: var(--fundo); }

.vazio { text-align: center; color: var(--cinza); padding: 70px 24px; font-size: 15px; line-height: 1.6; }
.vazio .grande { font-size: 46px; display: block; margin-bottom: 12px; }

/* ---------- tela de login / cadastro ---------- */
#auth-screen {
  position: fixed; inset: 0; z-index: 100;
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(15, 157, 88, .22), transparent 60%),
    radial-gradient(ellipse 70% 50% at 90% 110%, rgba(29, 78, 216, .12), transparent 60%),
    linear-gradient(160deg, #eefaf3 0%, var(--fundo) 55%, #f2f6fd 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
#auth-screen[hidden] { display: none; }
.auth-card {
  width: 100%; max-width: 380px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 26px;
  padding: 34px 26px 26px;
  box-shadow: 0 18px 50px rgba(15, 60, 40, .16), 0 2px 8px rgba(0, 0, 0, .05);
  border: 1px solid rgba(255, 255, 255, .8);
  animation: cardIn .3s ease both;
}
.auth-logo {
  width: 68px; height: 68px; border-radius: 20px;
  background: linear-gradient(135deg, #16a75f, #0b7a44);
  color: #fff;
  font-size: 36px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  box-shadow: 0 10px 24px rgba(15, 157, 88, .4), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.auth-card h2 { text-align: center; margin: 0; font-size: 22px; }
.auth-sub {
  text-align: center; color: var(--cinza);
  font-size: 14px; margin: 6px 0 20px;
}
.auth-msg {
  text-align: center; color: var(--vermelho);
  font-size: 13px; margin: 0 0 14px;
  background: #fee2e2; border-radius: 10px; padding: 8px 10px;
}
.auth-msg[hidden] { display: none; }
.lembrar {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--cinza);
  margin: 0 0 14px; cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.lembrar input { width: 18px; height: 18px; accent-color: var(--verde); }

/* ---------- navegação inferior ---------- */
#bottomnav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px;
  display: flex;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--borda);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
#bottomnav button {
  flex: 1; border: 0; background: none;
  padding: 10px 0 8px;
  font-size: 11px; color: var(--cinza);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: inherit;
  transition: color .15s;
}
#bottomnav button .ic { font-size: 22px; line-height: 1; transition: transform .15s; }
#bottomnav button.active { color: var(--verde-esc); font-weight: 700; }
#bottomnav button.active .ic { transform: translateY(-2px); }

/* ---------- botão flutuante ---------- */
#fab {
  position: fixed;
  right: max(16px, calc((100vw - 520px) / 2 + 16px));
  bottom: calc(92px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%;
  border: 0;
  background: linear-gradient(135deg, #12a55e, #0b7a44);
  color: #fff;
  font-size: 32px; line-height: 1;
  box-shadow: 0 8px 20px rgba(15, 157, 88, .45);
  z-index: 30;
  transition: transform .12s;
  animation: cardIn .3s ease both;
}
#fab:active { transform: scale(.9); }

/* ---------- histórico ---------- */
.mes-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 12px; }
.mes-nav button {
  border: 1.5px solid var(--borda); background: #fff;
  width: 40px; height: 40px; border-radius: 50%;
  font-size: 17px; color: var(--texto);
  box-shadow: var(--sombra);
  font-family: inherit;
}
.mes-nav button:active { background: var(--fundo); }
.mes-botao {
  flex: 1; border: 1.5px solid var(--borda); background: #fff;
  height: 40px; border-radius: 999px;
  font-size: 15px; font-weight: 700; color: var(--texto);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  box-shadow: var(--sombra);
  font-family: inherit;
  text-transform: capitalize;
}
.mes-botao:active { background: var(--fundo); }
.mes-icone { font-size: 14px; }
.resumo { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 12px 4px; }
.resumo .chip { font-size: 12px; padding: 6px 12px; }
.dia-grupo { margin: 14px 12px 0; }
.dia-titulo {
  display: flex; align-items: center; gap: 6px;
  margin: 0 4px 8px;
  font-size: 13px; font-weight: 800;
  color: var(--cinza); text-transform: capitalize;
  cursor: pointer;
  border-radius: 8px; padding: 2px 4px;
}
.dia-titulo:active { background: var(--fundo); }
.cal-link { font-size: 12px; opacity: .8; }
.dia-titulo.flash { background: var(--verde-fundo); color: var(--verde-esc); }
.btn-opcoes {
  border: 0; background: none; color: var(--cinza);
  font-size: 18px; width: 34px; height: 34px; border-radius: 10px;
  flex-shrink: 0; line-height: 1;
}
.btn-opcoes:active { background: var(--fundo); }
.card .card-opcoes { position: absolute; top: 8px; right: 8px; }
.card .card-topo { padding-right: 26px; }
.card-historico {
  background: var(--card); border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--sombra);
  display: flex; align-items: center; gap: 10px;
}
.card-historico .info { flex: 1; min-width: 0; }
.card-historico .nome { font-weight: 700; font-size: 15px; }
.card-historico .detalhe { color: var(--cinza); font-size: 12px; margin-top: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card-historico .hora-concluida { color: var(--verde-esc); font-weight: 700; font-size: 13px; flex-shrink: 0; display: flex; align-items: center; gap: 6px; }
.btn-reabrir-mini { border: 0; background: none; color: var(--cinza); font-size: 15px; padding: 4px; border-radius: 8px; }
.btn-reabrir-mini:active { background: var(--fundo); }

/* ---------- calendário ---------- */
.cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.cal-nav button {
  border: 1.5px solid var(--borda); background: #fff;
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 16px; color: var(--texto);
  font-family: inherit;
}
.cal-nav button:active { background: var(--fundo); }
.cal-nav-centro { display: flex; align-items: center; gap: 8px; }
.cal-titulo { font-weight: 700; font-size: 15px; text-transform: capitalize; }
.cal-ano {
  border: 1.5px solid var(--borda); background: #fff;
  border-radius: 10px; padding: 6px 8px;
  font-size: 14px; font-weight: 700; color: var(--texto);
  font-family: inherit;
}
.cal-semana {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  margin-bottom: 6px;
}
.cal-semana span {
  text-align: center; font-size: 11px; font-weight: 800;
  color: var(--cinza); text-transform: uppercase;
}
.cal-grade { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-vazio { aspect-ratio: 1; }
.cal-dia {
  aspect-ratio: 1;
  border: 0; border-radius: 12px;
  background: var(--fundo);
  font-size: 15px; font-weight: 600; color: var(--texto);
  font-family: inherit;
  transition: background .12s, transform .12s;
}
.cal-dia:active { transform: scale(.92); }
.cal-dia.hoje { border: 1.5px solid var(--verde); background: var(--verde-fundo); color: var(--verde-esc); font-weight: 800; }
.cal-dia.sel { background: var(--verde); color: #fff; font-weight: 800; }

/* ---------- apartamentos ---------- */
.apto-add {
  margin: 12px; background: var(--card);
  border-radius: var(--raio); padding: 14px;
  box-shadow: var(--sombra);
}
.apto-add input {
  width: 100%; padding: 12px;
  border: 1.5px solid var(--borda); border-radius: 12px;
  font-size: 15px; margin-bottom: 8px; font-family: inherit;
}
.apto-lista { display: grid; grid-template-columns: 1fr; gap: 10px; padding: 0 12px; }
.apto-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--sombra);
}
.apto-item .info { flex: 1; min-width: 0; }
.apto-item .nome { font-weight: 700; font-size: 16px; }
.apto-item .end { color: var(--cinza); font-size: 12px; margin-top: 2px; }
.apto-item .apto-nota {
  color: #8a6d1a; font-size: 12px; margin-top: 4px;
  background: #fdf6e3; border-radius: 8px; padding: 5px 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.apto-item button {
  border: 0; background: none; font-size: 17px;
  width: 40px; height: 40px; border-radius: 10px;
  color: var(--cinza);
}
.apto-item button:active { background: var(--fundo); }

/* ---------- modais (bottom sheet) ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: none; }
.modal.open { display: block; }
.modal .backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.modal .sheet {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px;
  background: #fff; border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow-y: auto;
  animation: subir .25s ease;
}
@keyframes subir {
  from { transform: translateX(-50%) translateY(40px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}
.modal h2 { margin: 0 0 14px; font-size: 18px; }

.campo { margin-bottom: 14px; }
.campo label {
  display: block; font-size: 11px; font-weight: 700;
  color: var(--cinza); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: .4px;
}
.campo select,
.campo input[type=date],
.campo input[type=time],
.campo input[type=text],
.campo input[type=password],
.campo textarea {
  width: 100%; padding: 13px 12px;
  border: 1.5px solid var(--borda); border-radius: 12px;
  font-size: 16px; background: #fff; color: var(--texto);
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.campo textarea { resize: vertical; min-height: 76px; line-height: 1.4; }
.campo input:focus, .campo select:focus, .campo textarea:focus {
  outline: none; border-color: var(--verde);
  box-shadow: 0 0 0 3px rgba(15, 157, 88, .14);
}
.campo input:disabled { background: var(--fundo); color: var(--cinza); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-opt {
  border: 1.5px solid var(--borda); background: #fff;
  padding: 10px 14px; border-radius: 999px;
  font-size: 14px; font-weight: 600; color: var(--cinza);
  font-family: inherit;
  transition: all .15s;
}
.chip-opt.sel { border-color: var(--verde); background: var(--verde-fundo); color: var(--verde-esc); }

.btn-prim {
  width: 100%; border: 0;
  background: linear-gradient(135deg, #12a55e, #0b7a44);
  color: #fff;
  font-size: 16px; font-weight: 700;
  padding: 14px; border-radius: 12px; font-family: inherit;
  box-shadow: 0 4px 14px rgba(15, 157, 88, .3);
  transition: transform .12s;
}
.btn-prim:active { transform: scale(.98); }
.btn-sec {
  width: 100%; border: 1.5px solid var(--borda); background: #fff;
  padding: 12px; border-radius: 12px;
  font-size: 15px; color: var(--cinza); margin-top: 8px; font-family: inherit;
}
.btn-perigo {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  box-shadow: 0 4px 14px rgba(220, 38, 38, .3);
}

/* ---------- action sheet de opções ---------- */
.opcoes-sheet { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.opcoes-titulo {
  text-align: center; color: var(--cinza);
  font-size: 13px; font-weight: 600;
  margin: 0 0 8px;
}
.opcoes-lista {
  margin: 0 -18px 14px;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--sombra);
}
.opcoes-item {
  width: 100%; border: 0; background: #fff;
  padding: 15px 18px; font-size: 16px;
  display: flex; align-items: center; gap: 12px;
  font-family: inherit; color: var(--texto);
  border-bottom: 1px solid var(--fundo);
  text-align: left;
  transition: background .1s;
}
.opcoes-item:last-child { border-bottom: 0; }
.opcoes-item:active { background: var(--fundo); }
.opcoes-item .ic { font-size: 18px; width: 26px; text-align: center; flex-shrink: 0; }
.opcoes-item.perigo { color: var(--vermelho); font-weight: 600; }
.opcoes-cancelar {
  width: 100%; border: 0; background: var(--fundo);
  padding: 15px; border-radius: 16px;
  font-size: 16px; font-weight: 700; color: var(--texto);
  font-family: inherit;
  box-shadow: var(--sombra);
  transition: opacity .1s;
}
.opcoes-cancelar:active { opacity: .75; }

/* ---------- gastos ---------- */
.gasto-total-box {
  margin: 0 12px 12px;
  background: linear-gradient(135deg, #12a55e, #0b7a44);
  border-radius: 18px; padding: 18px 20px;
  color: #fff; box-shadow: 0 6px 18px rgba(15, 157, 88, .3);
}
.gasto-total-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; opacity: .85; }
.gasto-total { font-size: 30px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.gasto-filtro { margin: 0 12px 8px; }
.gasto-card {
  display: flex; align-items: center; gap: 10px;
}
.gasto-info { flex: 1; min-width: 0; }
.gasto-desc { font-weight: 700; font-size: 15px; }
.gasto-meta { display: flex; align-items: center; gap: 8px; color: var(--cinza); font-size: 12px; margin-top: 3px; }
.gasto-valor {
  font-weight: 800; font-size: 16px; color: var(--verde-esc);
  font-variant-numeric: tabular-nums; flex-shrink: 0;
}

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%;
  transform: translateX(-50%) translateY(20px);
  bottom: calc(104px + env(safe-area-inset-bottom));
  background: #1f2937; color: #fff;
  padding: 12px 16px; border-radius: 12px;
  display: flex; align-items: center; gap: 12px;
  font-size: 14px; z-index: 60;
  opacity: 0; pointer-events: none; transition: .25s;
  max-width: 90%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
#toast button {
  background: none; border: 0; color: #6ee7b7;
  font-weight: 700; font-size: 14px; font-family: inherit;
}

/* ---------- responsivo (tablet / desktop) ---------- */
@media (min-width: 640px) {
  body { max-width: 920px; }
  #bottomnav, .modal .sheet { max-width: 920px; }
  #fab {
    right: max(20px, calc((100vw - 920px) / 2 + 20px));
    width: 64px; height: 64px; font-size: 34px;
  }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .apto-lista { grid-template-columns: repeat(2, 1fr); }
  .dia-grupo .cards { grid-template-columns: repeat(2, 1fr); }
  .vazio { padding: 90px 40px; }
}

@media (min-width: 1024px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
  .apto-lista { grid-template-columns: repeat(3, 1fr); }
  .dia-grupo .cards { grid-template-columns: repeat(3, 1fr); }
  .auth-card { max-width: 420px; }
}

/* telas muito estreitas: hora menor e nav compacta */
@media (max-width: 380px) {
  .hora { font-size: 26px; min-width: 64px; }
  .card-nome { font-size: 16px; }
  #bottomnav button { font-size: 10px; }
  #bottomnav button .ic { font-size: 20px; }
}
