:root {
  --bg: #0f172a;
  --bg-card: #141a2c;
  --bg-card-alt: #111726;
  --border: #232c42;
  --text: #e7e9f0;
  --text-dim: #838ba0;
  --green: #7fa88f;
  --green-dim: #4d6b5c;
  --red: #bd7b70;
  --yellow: #b99f6c;
  --blue: #7488ad;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

#app { display: none; }
#app.ready { display: block; }

header.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: calc(16px + env(safe-area-inset-top)) 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header.topbar h1 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: 500;
  letter-spacing: -0.01em;
}

header.topbar .brand { display: flex; align-items: center; gap: 8px; }

main.view { padding: 18px; max-width: 720px; margin: 0 auto; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.card h3 {
  margin: 0 0 12px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.stat { text-align: left; }
.stat .label { font-size: 0.68rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.stat .value { font-size: 1.25rem; font-weight: 600; margin-top: 4px; color: var(--text); }
.stat .value.green { color: var(--green); }
.stat .value.red { color: var(--red); }
.stat .value.yellow { color: var(--yellow); }

.progress-bar {
  height: 6px;
  background: var(--bg-card-alt);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}
.progress-bar > div {
  height: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.debt-item, .reserve-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  background: var(--bg-card-alt);
}

.debt-item .row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge.atrasada { color: var(--red); }
.badge.negociada { color: var(--yellow); }
.badge.quitada { color: var(--green); }
.badge.sagrada { color: var(--blue); margin-left: 8px; }

.parcelas-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.parcela-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border-radius: 6px;
  background: var(--bg-card);
  cursor: pointer;
  border: 1px solid transparent;
  font-size: 0.9rem;
}
.parcela-row.paga { opacity: 0.5; text-decoration: line-through; }
.parcela-row:active { border-color: var(--border); }

button, .btn {
  background: var(--text);
  color: var(--bg);
  border: 1px solid var(--text);
  border-radius: 6px;
  padding: 12px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.01em;
}
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
button.big { width: 100%; padding: 16px; font-size: 0.95rem; }
button:active { transform: scale(0.98); }

input, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card-alt);
  color: var(--text);
  font-size: 1rem;
  margin-top: 4px;
}
label { font-size: 0.85rem; color: var(--text-dim); display: block; margin-top: 10px; }

nav.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
nav.tabbar button {
  flex: 1;
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-radius: 0;
  padding: 14px 4px 12px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  box-shadow: inset 0 1px 0 transparent;
}
nav.tabbar button.active { color: var(--text); font-weight: 600; box-shadow: inset 0 1px 0 var(--text); }
nav.tabbar button .icon { display: none; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#auth-screen {
  position: relative;
  overflow: hidden;
  background: var(--bg);
}
#auth-screen::before {
  content: "";
  position: absolute;
  width: 480px;
  height: 480px;
  border: 1px solid var(--border);
  border-radius: 50%;
  top: -160px;
  right: -160px;
}
#auth-screen::after {
  content: "";
  position: absolute;
  width: 320px;
  height: 320px;
  border: 1px solid var(--border);
  border-radius: 50%;
  bottom: -120px;
  left: -100px;
}

.auth-box {
  max-width: 360px;
  width: 100%;
  animation: auth-in 0.9s ease both;
}
@keyframes auth-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-card { text-align: center; padding: 8px 12px; }

.auth-eyebrow {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 20px;
}

.auth-card h1 {
  font-size: 2.2rem;
  font-weight: 300;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--text);
}
.auth-card h1 em { font-style: italic; font-weight: 500; }

.auth-divider { width: 36px; height: 1px; background: var(--border); margin: 24px auto; }

.auth-card .muted { margin-bottom: 30px; }
.auth-card .error { color: var(--red); font-size: 0.8rem; min-height: 1.2em; margin-top: 16px; }

#auth-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  text-align: center;
  padding: 10px 4px;
  transition: border-color 0.2s ease;
}
#auth-input:focus {
  outline: none;
  border-bottom-color: var(--text);
  box-shadow: none;
}

#auth-submit.big {
  background: transparent;
  border: 1px solid var(--text);
  color: var(--text);
  border-radius: 0;
  padding: 14px 18px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
  box-shadow: none;
  transition: background 0.2s ease, color 0.2s ease;
}
#auth-submit.big:hover { background: var(--text); color: var(--bg); }
#auth-submit.big:active { transform: none; }

@media (prefers-reduced-motion: reduce) {
  .auth-box { animation: none; }
}

.empty-state { text-align: center; color: var(--text-dim); padding: 24px 12px; font-size: 0.9rem; }

.fab-add {
  width: 100%;
  margin-top: 6px;
}

.toast {
  position: fixed;
  bottom: calc(76px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 30;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

.celebration-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.celebration-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px 24px;
  text-align: center;
  max-width: 320px;
}
.celebration-box h2 { font-size: 1.1rem; font-weight: 600; margin: 0 0 8px; }

.tag-pill { font-size: 0.68rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-dim); }
.tag-pill.PJ { border-color: var(--blue); color: var(--blue); }
.tag-pill.PF { border-color: var(--green); color: var(--green); }

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  font-size: 0.9rem;
}
.list-row:last-child { border-bottom: none; }

.muted { color: var(--text-dim); font-size: 0.85rem; }

.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; margin-top: 12px; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-chart .bar { width: 100%; background: var(--green); border-radius: 3px 3px 0 0; min-height: 2px; }
.bar-chart .bar-label { font-size: 0.6rem; color: var(--text-dim); margin-top: 4px; text-align: center; }
