/* Expenses: feito primeiro para o celular. No desktop (>= 900px) a barra de abas vira um trilho lateral. */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1b1f24;
  --muted: #667085;
  --accent: #2f6feb;
  --accent-text: #ffffff;
  --accent-soft: #e6eefd;
  --ok: #1a7f37;
  --warn: #9a6700;
  --err: #cf222e;
  --err-soft: #ffebe9;
  --income: #1a7f37;
  /* Paleta categórica (ordem fixa, validada para daltonismo nos dois temas; ver skill dataviz). */
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
  /* Tipos de lançamento: as mesmas cores dos gráficos (receita = 3, despesa = 2, transferência = 1). */
  --kind-expense: var(--series-2);
  --kind-income: var(--series-3);
  --kind-transfer: var(--series-1);
  --track: #eceef1;
  --grid: #eceef1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --radius: 14px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --panel: #151b23;
    --panel-2: #1c232d;
    --border: #2a323d;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #4c8dff;
    --accent-text: #0d1117;
    --accent-soft: #15233d;
    --ok: #3fb950;
    --warn: #d29922;
    --err: #f85149;
    --err-soft: #3a1d1f;
    --income: #3fb950;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --track: #262d37;
    --grid: #232a34;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* senão classes com display (ex.: .field) venceriam o atributo */

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2 { margin: 0; line-height: 1.2; }
h2 { font-size: 15px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.boot { min-height: 100vh; }

/* ---------------------------------------------------------------- formulários e botões */

.field { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; width: 100%;
  min-height: 48px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.button {
  font: inherit; font-weight: 600; border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel); color: var(--text); padding: 12px 18px; min-height: 48px; cursor: pointer;
}
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.block { width: 100%; }
.button:disabled { opacity: .6; cursor: progress; }
.form-error { color: var(--err); margin: 0; font-size: 14px; }
.form-error:empty { display: none; }

/* ---------------------------------------------------------------- login */

.login {
  min-height: 100vh; display: grid; place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.login-card {
  width: 100%; max-width: 380px; display: grid; gap: 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 28px 22px;
  box-shadow: var(--shadow);
}
.login-card .muted { margin: 0; font-size: 14px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.brand img { border-radius: 14px; }
.brand h1 { font-size: 24px; }

/* ---------------------------------------------------------------- casca */

.app { min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
}
.topbar h1 { font-size: 22px; font-weight: 700; }
.topbar .title { display: flex; align-items: center; gap: 4px; min-width: 0; }
.topbar .title h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar #back { margin-left: -12px; color: var(--accent); }

/* Páginas de Mais */
.menu .row.link .icon:last-child { margin-left: auto; color: var(--muted); width: 18px; }
.intro { margin: 0; }
.segmented.two { grid-template-columns: 1fr 1fr; }
.entry.budget-entry { display: grid; gap: 0; } /* botão em block encolhe o conteúdo; em grid o filho ocupa a largura toda */
.budget-entry > * { width: 100%; }
.budget-body { display: grid; gap: 6px; padding: 4px 0; }
.budget-entry .upcoming { font-size: 12px; padding-bottom: 4px; }
.edited { font-style: italic; }
.notice { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 14px; background: var(--accent-soft); color: var(--text); }
.changes > li { padding: 8px 0; display: grid; gap: 4px; }
.changes ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 14px; }
.changes .from { text-decoration: line-through; color: var(--muted); }
.history h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 4px 0 0; }
.avatar.small { width: 36px; height: 36px; font-size: 15px; flex: none; }
.link-button.danger { color: var(--err); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--panel-2); color: var(--muted);
}
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.import-line { display: grid; gap: 6px; padding: 10px 0; }
.import-line select { min-height: 40px; padding: 8px 10px; flex: 1; }
.actions { margin-top: 12px; }
.secret { margin-top: 12px; display: grid; gap: 8px; }
.secret summary { color: var(--accent); cursor: pointer; font-weight: 600; font-size: 14px; }
.code { display: block; font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel-2); padding: 8px 10px; border-radius: 8px; word-break: break-all; margin-bottom: 8px; }
.wrap { word-break: break-all; }
input[type="file"] { padding: 10px; }

.live { display: inline-flex; padding: 8px; }
.live .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); transition: background .2s; }
.live.on .dot { background: var(--ok); }

.page {
  padding: 4px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto; display: grid; gap: 14px;
}
.loading { text-align: center; padding: 32px 0; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--panel); border-top: 1px solid var(--border);
}
.tab {
  display: grid; justify-items: center; align-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tab[aria-current="page"] { color: var(--accent); }
.tab .icon { height: 32px; } /* mesma altura do botão de Lançar: rótulos na mesma linha */
.tab.primary .icon {
  width: 40px; height: 32px; padding: 5px 9px; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); stroke-width: 2.4;
}

@media (min-width: 900px) {
  .tabbar {
    top: 0; right: auto; width: 96px; height: auto;
    grid-template-columns: 1fr; grid-auto-rows: 76px; align-content: start;
    padding: 24px 0 0; border-top: 0; border-right: 1px solid var(--border);
  }
  .app { padding-left: 96px; }
  /* Faixa inteira (fundo translúcido), conteúdo alinhado com a coluna de 720px da .page */
  .topbar { padding: 22px max(32px, calc((100% - 720px) / 2)) 14px; }
  .page { padding: 4px 32px 32px; max-width: 784px; }
}

/* ---------------------------------------------------------------- conteúdo */

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.empty-state { text-align: center; padding: 32px 20px; }
.empty-state h2 { color: var(--text); font-size: 17px; }
.empty-state p { margin: 0; }
.empty-state .button { margin-top: 16px; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--border); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 6px 0; }
.list .empty { color: var(--muted); padding: 8px 0; }
.amount { font-variant-numeric: tabular-nums; }
.amount.negative { color: var(--err); }

.menu .row.link {
  justify-content: flex-start; width: 100%; font: inherit; color: var(--text); text-decoration: none;
  background: none; border: 0; cursor: pointer; text-align: left;
}
.menu .row.link.danger { color: var(--err); }

.user { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 18px;
}

.small { font-size: 13px; }
.positive { color: var(--income); }
.negative { color: var(--err); }
.empty { color: var(--muted); padding: 4px 0; margin: 0; }
.empty .button { margin-top: 10px; }
.empty p { margin: 0; }

.card-head { display: flex; align-items: baseline; justify-content: space-between; }
.link-button {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--accent); background: none; border: 0;
  padding: 6px 0 6px 12px; cursor: pointer; min-height: 32px;
}
.icon-button {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  background: none; border: 0; color: var(--text); cursor: pointer;
}
.icon-button:disabled { opacity: .3; cursor: default; }
.button.danger { color: var(--err); border-color: var(--err); background: var(--err-soft); }

/* ---------------------------------------------------------------- painel do mês */

.month-nav { display: flex; align-items: center; justify-content: space-between; margin: -4px -10px 0; }
.month-nav .month-label { margin: 0; color: var(--text); font-size: 17px; }

.big { font-size: 30px; font-weight: 700; margin: 0; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.summary-currency + .summary-currency { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 14px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.split > div { display: grid; gap: 2px; background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.split .muted { font-size: 13px; }
.split strong { font-variant-numeric: tabular-nums; }

.budgets .budget { padding: 10px 0; display: grid; gap: 6px; }
.row.tight { min-height: 0; padding: 0; }
.bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--ok); transition: width .3s; }
.bar.warn > span { background: var(--warn); }
.bar.over > span { background: var(--err); }
.percent { font-weight: 700; font-variant-numeric: tabular-nums; }
.percent.warn { color: var(--warn); }
.percent.over { color: var(--err); }

.statement .day + .day { margin-top: 10px; }
.statement h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 6px 0 2px; }
.statement h3::first-letter { text-transform: uppercase; }
.entry {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 0;
  font: inherit; color: var(--text); background: none; border: 0; text-align: left; cursor: pointer;
}
.entry-text { display: grid; flex: 1; min-width: 0; }
.entry-text strong, .entry-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.entry .amount { white-space: nowrap; }
.entry-value { display: grid; justify-items: end; gap: 2px; }
.entry-value small { font-size: 12px; white-space: nowrap; }
.dot-kind { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--kind-expense); }
.dot-kind.income { background: var(--kind-income); }
.dot-kind.transfer { background: var(--kind-transfer); }

/* ---------------------------------------------------------------- relatórios e gráficos */

.segmented.compact { grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); }
.segmented.compact button { min-height: 34px; }

.chart { margin: 4px -4px 0; overflow: hidden; }
.chart svg { display: block; max-width: 100%; height: auto; touch-action: pan-y; }
.chart text { fill: var(--muted); font: 11px var(--sans); }
.chart .label { fill: var(--text); font-weight: 600; }
.chart .grid-line { stroke: var(--grid); }
.chart .zero-line { stroke: var(--muted); stroke-opacity: .5; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:focus-visible { outline: none; stroke: var(--accent); stroke-width: 1; }
.chart .crosshair { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .dot { stroke: var(--panel); stroke-width: 2; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 4px 0 2px; color: var(--muted); font-size: 13px; }
.legend-key { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.line-key { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }

.bar-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.bar-list li { display: grid; gap: 4px; outline-offset: 4px; border-radius: 6px; }
.bar-head { display: flex; justify-content: space-between; gap: 12px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1); }
.bar-list small { font-size: 12px; }

.table-view { margin-top: 10px; font-size: 13px; }
.table-view summary { color: var(--accent); cursor: pointer; padding: 6px 0; font-weight: 600; }
.table-wrap { overflow-x: auto; }
.table-view table { border-collapse: collapse; width: 100%; }
.table-view th, .table-view td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table-view th { color: var(--muted); font-weight: 600; }
.table-view .num { text-align: right; font-variant-numeric: tabular-nums; }

.forecast-totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 6px; }
.forecast-totals > div { display: grid; gap: 2px; background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.forecast-totals .muted { font-size: 12px; text-transform: capitalize; }
.forecast-totals strong { font-variant-numeric: tabular-nums; font-size: 15px; }
.forecast-totals small { font-size: 12px; }

.tooltip {
  position: fixed; z-index: 40; pointer-events: none; max-width: 260px;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}
.tooltip .tt-title { color: var(--muted); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-row strong { font-variant-numeric: tabular-nums; }
.tooltip .name { color: var(--muted); }

/* ---------------------------------------------------------------- formulários */

.form { display: grid; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field > span { color: var(--muted); }
.field small { font-weight: 400; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); min-height: 32px; }
.check input { width: 20px; height: 20px; min-height: 0; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--panel-2); }
.segmented button {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--muted); background: none; border: 0;
  border-radius: 9px; min-height: 40px; cursor: pointer;
}
.segmented button[aria-selected="true"] { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

.amount-field {
  display: flex; align-items: baseline; gap: 8px; padding: 14px 4px 10px; border-bottom: 2px solid var(--border);
}
.amount-field:focus-within { border-color: var(--accent); }
.amount-field .currency { font-size: 22px; font-weight: 600; color: var(--muted); }
.amount-input {
  font-size: 40px; font-weight: 700; border: 0; background: none; padding: 0; min-height: 0;
  letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}
.amount-input:focus-visible { outline: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px; min-height: 40px; cursor: pointer;
}
.chip[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.add { color: var(--accent); border-style: dashed; }

/* ---------------------------------------------------------------- painel que sobe (dialog) */

.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 92vh;
  border-radius: 20px 20px 0 0; background: var(--panel); color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 0 20px; }
.sheet-head h2 { margin: 0; color: var(--text); font-size: 17px; }
.sheet-body { padding: 8px 20px 24px; display: grid; gap: 14px; }
.details { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; text-align: right; }

@media (min-width: 900px) {
  .sheet { margin: auto; border-radius: 20px; }
}

/* ---------------------------------------------------------------- aviso */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--err); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
