:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1f26;
  --muted: #6b7280;
  --border: #e3e5e9;
  --accent: #15616d;
  --accent-contrast: #ffffff;
  --radius: 14px;

  /* diverging: positivo/negativo */
  --positive: #2a78d6;
  --negative: #e34948;

  /* status (fixo, nunca re-temático) */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;

  /* categórico: identidade (categorias de gasto, cartões) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c;
    --surface: #1a2028;
    --text: #e7e9ee;
    --muted: #9aa3af;
    --border: #2a313c;
    --accent: #3fa9b8;
    --accent-contrast: #0b1016;

    --positive: #3987e5;
    --negative: #e66767;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #0ca30c;
    --series-7: #9085e9;
    --series-8: #e66767;

    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }

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

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

.auth-card h1 {
  font-size: 1.25rem;
  margin: 0 0 18px;
  text-align: center;
}

.auth-card .qrcode {
  display: block;
  margin: 0 auto 12px;
  border-radius: 8px;
}

form label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 14px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

button {
  font-family: inherit;
  cursor: pointer;
}

form button[type="submit"],
.btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 1rem;
  font-weight: 600;
}

.alert {
  background: color-mix(in srgb, var(--negative) 15%, var(--surface));
  color: var(--negative);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar .muted { display: block; font-size: 0.8rem; color: var(--muted); }

.topbar nav a {
  margin-left: 14px;
  font-size: 0.85rem;
  text-decoration: none;
}

.content {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.month-switch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}

.month-switch button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  color: var(--text);
}

.cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.card .label { font-size: 0.78rem; color: var(--muted); }
.card .value { font-size: 1.25rem; font-weight: 700; margin-top: 4px; }
.card .value.income { color: var(--positive); }
.card .value.expense { color: var(--negative); }

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

.panel h2 {
  font-size: 1rem;
  margin: 0 0 12px;
}

.list { display: flex; flex-direction: column; gap: 10px; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.row:last-child { border-bottom: none; padding-bottom: 0; }

.row .row-main { flex: 1; min-width: 0; }
.row .row-title { font-weight: 600; font-size: 0.95rem; }
.row .row-sub { font-size: 0.8rem; color: var(--muted); }
.row .row-amount { font-weight: 700; white-space: nowrap; }
.row .row-amount.expense { color: var(--negative); }
.row .row-amount.income { color: var(--positive); }
.row .row-amount.overdue { color: var(--status-critical); }

.pill {
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
}

.pill.paid { background: color-mix(in srgb, var(--status-good) 20%, var(--surface)); color: var(--status-good); }
.pill.due { background: color-mix(in srgb, var(--status-warning) 25%, var(--surface)); color: #8a6200; }
@media (prefers-color-scheme: dark) {
  .pill.due { color: var(--status-warning); }
}

.bars { display: flex; flex-direction: column; gap: 10px; }

.bar-row .bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.bar-svg { width: 100%; height: 8px; display: block; overflow: visible; }
.bar-track-fill { fill: var(--border); }
.bar-value-fill { fill: var(--accent); }

.card-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  color: #ffffff;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.card-chip.slot-1 { background: var(--series-1); }
.card-chip.slot-2 { background: var(--series-2); }
.card-chip.slot-3 { background: var(--series-3); }
.card-chip.slot-4 { background: var(--series-4); color: #0b0b0b; }
.card-chip.slot-5 { background: var(--series-5); }
.card-chip.slot-6 { background: var(--series-6); }
.card-chip.slot-7 { background: var(--series-7); }
.card-chip.slot-8 { background: var(--series-8); }

.card-row { align-items: center; }
.card-row .row-main { display: flex; align-items: center; gap: 10px; }
.card-row .row-text { min-width: 0; }

.card-detail {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  display: none;
  flex-direction: column;
  gap: 6px;
}
.card-detail.open { display: flex; }

.card-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
}
.card-item span:last-child { color: var(--text); font-weight: 600; }

.card-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.78rem;
  padding: 0;
}

.trend-chart {
  display: flex;
  gap: 10px;
  height: 140px;
  padding-top: 8px;
}

.trend-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.trend-bars {
  height: 108px;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.trend-svg { width: 28px; height: 100%; overflow: visible; }
.trend-fill-income { fill: var(--positive); }
.trend-fill-expense { fill: var(--negative); }

.trend-label { font-size: 0.72rem; color: var(--muted); }

.trend-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 10px;
}

.trend-legend span { display: inline-flex; align-items: center; gap: 6px; }

.trend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}
.trend-swatch.income { background: var(--positive); }
.trend-swatch.expense { background: var(--negative); }

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 0 0;
}

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

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

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

.modal {
  background: var(--surface);
  width: 100%;
  max-width: 420px;
  border-radius: 18px 18px 0 0;
  padding: 20px;
  max-height: 85dvh;
  overflow-y: auto;
}

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

.modal h3 { margin-top: 0; }

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

.modal-actions button { flex: 1; }

.btn-secondary {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
}

.btn-danger { color: var(--negative); background: none; border: none; font-size: 0.85rem; }
