:root {
  color-scheme: light;
  --surface: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.1);
  --card-bg: #ffffff;
  --brand: #2a78d6;
  --brand-dark: #184f95;
  --good: #0ca30c;
  --critical: #d03b3b;
  --warning: #fab219;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(11, 11, 11, 0.08), 0 1px 2px rgba(11, 11, 11, 0.06);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);
    --card-bg: #201f1e;
    --brand: #3987e5;
    --brand-dark: #86b6ef;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: 72px; /* espaço para a barra inferior */
  min-height: 100vh;
}

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

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

input, select, textarea, button {
  font-size: 16px; /* evita zoom automático no iOS */
}

[hidden] { display: none !important; }

/* ---------- Tela de autenticação ---------- */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

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

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.auth-logo .badge {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

.auth-logo h1 { font-size: 18px; margin: 0; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: none;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}
.btn.secondary { background: transparent; color: var(--brand); border: 1px solid var(--border); }
.btn.danger { background: var(--critical); }
.btn.small { width: auto; padding: 8px 14px; font-size: 14px; }
.btn:disabled { opacity: 0.6; }

.switch-mode { text-align: center; margin-top: 14px; font-size: 14px; color: var(--text-secondary); }
.switch-mode button { background: none; border: none; color: var(--brand); font-weight: 600; padding: 0; }

.error-banner {
  background: rgba(208, 59, 59, 0.12);
  color: var(--critical);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- App shell ---------- */
#app-screen { max-width: 640px; margin: 0 auto; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 10px;
  background: var(--page);
}
.topbar h2 { margin: 0; font-size: 20px; }
.topbar .month-nav { display: flex; align-items: center; gap: 8px; }
.topbar .month-nav button { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; width: 32px; height: 32px; color: var(--text-primary); }

main.view { padding: 4px 18px 24px; }

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

.card h3 { margin: 0 0 10px; font-size: 15px; color: var(--text-secondary); font-weight: 600; }

.stat-row { display: flex; gap: 12px; }
.stat-tile { flex: 1; }
.stat-tile .value { font-size: 26px; font-weight: 700; font-variant-numeric: proportional-nums; }
.stat-tile .label { font-size: 12px; color: var(--text-muted); }
.stat-tile .delta { font-size: 12px; margin-top: 2px; }
.delta.up { color: var(--critical); }
.delta.down { color: var(--good); }

.legend-list { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.legend-item { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.legend-item .dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-item .name { flex: 1; color: var(--text-primary); }
.legend-item .amount { font-weight: 600; }
.legend-item .pct { color: var(--text-muted); font-size: 12px; width: 42px; text-align: right; }

.tip-card { background: linear-gradient(135deg, rgba(42,120,214,0.12), rgba(27,175,122,0.10)); border: 1px solid var(--border); }
.tip-card h3 { color: var(--brand); }

.expense-list { display: flex; flex-direction: column; gap: 2px; }
.expense-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--gridline);
}
.expense-item:last-child { border-bottom: none; }
.expense-item .icon-dot {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.expense-item .info { flex: 1; min-width: 0; }
.expense-item .info .desc { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-item .info .meta { font-size: 12px; color: var(--text-muted); }
.expense-item .amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.expense-item .actions { display: flex; gap: 6px; }
.expense-item .actions button { background: none; border: none; color: var(--text-muted); font-size: 16px; padding: 4px; }

.fab {
  position: fixed; right: 18px; bottom: 84px; z-index: 20;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--brand); color: #fff; border: none;
  font-size: 26px; box-shadow: 0 4px 12px rgba(42,120,214,0.4);
  display: flex; align-items: center; justify-content: center;
}

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
}
.bottom-nav button {
  background: none; border: none; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10px; padding: 4px 8px; flex: 1;
}
.bottom-nav button .ic { font-size: 19px; }
.bottom-nav button.active { color: var(--brand); }

/* ---------- Formulários / modais ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-sheet {
  background: var(--card-bg); width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
}
.modal-sheet h3 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.close-x { position: absolute; top: 14px; right: 14px; background: none; border: none; font-size: 20px; color: var(--text-muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip {
  padding: 7px 12px; border-radius: 20px; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
}
.chip.selected { background: var(--brand); color: #fff; border-color: var(--brand); }

.segmented { display: flex; background: var(--surface); border-radius: 10px; padding: 3px; border: 1px solid var(--border); }
.segmented button { flex: 1; background: none; border: none; padding: 8px; border-radius: 8px; color: var(--text-secondary); font-size: 13px; }
.segmented button.active { background: var(--brand); color: #fff; }

.mic-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--brand); font-size: 18px; flex-shrink: 0;
}
.mic-btn.recording { background: var(--critical); color: #fff; border-color: var(--critical); animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(208,59,59,0.5); } 70% { box-shadow: 0 0 0 10px rgba(208,59,59,0); } 100% { box-shadow: 0 0 0 0 rgba(208,59,59,0); } }

.text-entry-row { display: flex; gap: 8px; align-items: center; }
.text-entry-row input { flex: 1; }

.family-code {
  font-family: ui-monospace, monospace; font-size: 22px; letter-spacing: 3px;
  text-align: center; padding: 14px; border-radius: 10px;
  background: var(--surface); border: 1px dashed var(--border); margin: 10px 0;
}

.member-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--gridline); }
.member-row:last-child { border-bottom: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }

.empty-state { text-align: center; padding: 30px 10px; color: var(--text-muted); }
.empty-state .ic { font-size: 32px; margin-bottom: 8px; }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--text-primary); color: var(--page);
  padding: 10px 18px; border-radius: 30px; font-size: 13px; z-index: 40;
  box-shadow: var(--shadow);
}

.section-title { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 18px 4px 8px; }

.priority-alta { color: var(--critical); }
.priority-media { color: var(--warning); }
.priority-baixa { color: var(--good); }

canvas#category-chart { max-height: 220px; }
canvas#trend-chart { max-height: 180px; }

.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
