:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e1e3e8;
  --text: #1b1d22;
  --text-muted: #6b7078;
  --primary: #2f6feb;
  --primary-text: #ffffff;
  --green: #1a9c5a;
  --green-bg: #e5f7ee;
  --red: #d33a3a;
  --red-bg: #fceaea;
  --amber: #b8790a;
  --amber-bg: #fdf1de;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 20, 30, 0.08), 0 1px 2px rgba(20, 20, 30, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --surface-2: #23262d;
    --border: #2d313a;
    --text: #e9eaed;
    --text-muted: #9198a3;
    --primary: #5b8cf2;
    --primary-text: #0b1220;
    --green: #38c785;
    --green-bg: #143324;
    --red: #f0605f;
    --red-bg: #3a1c1e;
    --amber: #e0a83e;
    --amber-bg: #3a2f14;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

header.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

header.app-header h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 700;
}

nav.tabs {
  position: sticky;
  top: 49px;
  z-index: 19;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 10px;
}

nav.tabs button {
  flex: none;
  background: none;
  border: none;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

nav.tabs button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 60px;
}

.view { display: none; }
.view.active { display: block; }

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

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.stat .label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.stat .value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 4px;
}

.stat.gastos .value { color: var(--red); }
.stat.recebimentos .value { color: var(--green); }
.stat.pago .value { color: var(--text); }
.stat.faltam .value { color: var(--amber); }

.month-switcher {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.month-switcher .month-label {
  flex: 1;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 16px;
  cursor: pointer;
  color: var(--text);
}

section.group { margin-bottom: 22px; }
section.group.subview { display: none; }
section.group.subview.active { display: block; }

section.group h2 {
  font-size: 15px;
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

section.group h2 .totals {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  margin-bottom: 8px;
}

.item-row .info { flex: 1; min-width: 0; }
.item-row .desc { font-weight: 600; font-size: 14px; }
.item-row .meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.item-row .valor { font-weight: 700; font-size: 14px; white-space: nowrap; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge.pago { background: var(--green-bg); color: var(--green); }
.badge.apagar { background: var(--amber-bg); color: var(--amber); }
.badge.vencido { background: var(--red-bg); color: var(--red); }

.row-actions { display: flex; gap: 6px; }

.row-actions button {
  border: none;
  background: var(--surface-2);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}

.row-actions button.danger { color: var(--red); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: var(--primary-text);
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }

.empty-hint {
  color: var(--text-muted);
  font-size: 13px;
  padding: 14px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}

.modal {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 18px;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
}

@media (min-width: 640px) {
  .modal { border-radius: 16px; }
}

.modal h3 { margin: 0 0 14px; font-size: 17px; }

.field { margin-bottom: 12px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.field input, .field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

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

.chart-wrap {
  position: relative;
  height: 260px;
  margin-bottom: 10px;
}

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

.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px 6px 12px;
  font-size: 13px;
}

.chip button {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px;
}

.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin: 10px 0;
}

.progress-bar .fill {
  height: 100%;
  background: var(--green);
  border-radius: 999px;
}

.fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-text);
  border: none;
  font-size: 26px;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 15;
}

.fatura-mes { margin-bottom: 20px; }

.fatura-mes-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 10px;
  margin-bottom: 8px;
}

.fatura-mes-titulo {
  font-weight: 700;
  font-size: 14px;
  flex: 1;
}

.fatura-mes-valor {
  font-weight: 700;
  font-size: 14px;
}

.card-select {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 14px;
}

.card-select button {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.card-select button.active {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

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

.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.auth-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}

.auth-box h1 {
  font-size: 20px;
  text-align: center;
  margin: 0 0 22px;
}

.auth-form .field { margin-bottom: 14px; }

.auth-form .btn { margin-top: 6px; }

.support-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  font-size: 14px;
}

.support-row a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.support-row a:hover { text-decoration: underline; }

.auth-error {
  color: var(--red);
  font-size: 13px;
  min-height: 16px;
  margin-bottom: 4px;
}
